Exemplo n.º 1
0
 def execute(self) -> None:
     try:
         ExecutionUnit.execute(self)
     except RuntimeException as e:
         e.set_statement(self.stmt)
         raise AttributeException(self.stmt, self.instance,
                                  self.stmt.attribute_name, e)
Exemplo n.º 2
0
 def __init__(self, queue_scheduler: QueueScheduler, resolver: Resolver,
              result: ResultVariable, requires: typing.Dict[object,
                                                            ResultVariable],
              expression: ExpressionStatement, stmt: Statement,
              instance: Instance) -> None:
     ExecutionUnit.__init__(self, queue_scheduler, resolver, result,
                            requires, expression)
     self.stmt = stmt
     self.instance = instance
Exemplo n.º 3
0
def test_slots_rt():
    ns = Namespace("root", None)
    rs = Resolver(ns)
    e = Entity("xx", ns)
    qs = QueueScheduler(None, [], [], None, set())
    r = RelationAttribute(e, None, "xx", Location("", 1))
    i = Instance(e, rs, qs)

    assert_slotted(ResultVariable())
    assert_slotted(AttributeVariable(None, None))
    assert_slotted(Promise(None, None))
    assert_slotted(ListVariable(r, i, qs))
    assert_slotted(OptionVariable(r, i, qs))

    assert_slotted(qs)
    assert_slotted(DelegateQueueScheduler(qs, None))

    assert_slotted(Waiter(qs))

    assert_slotted(
        ExecutionUnit(qs, r, ResultVariable(), {}, Literal(""), None))
    assert_slotted(HangUnit(qs, r, {}, None, Resumer()))
    assert_slotted(RawUnit(qs, r, {}, Resumer()))

    assert_slotted(FunctionUnit(qs, rs, ResultVariable(), {}, None))

    assert_slotted(i)
Exemplo n.º 4
0
    def resume(self, requires: Dict[object, ResultVariable],
               resolver: Resolver, queue_scheduler: QueueScheduler,
               target: ResultVariable) -> None:
        """
            Instance is ready to execute, do it and see if the attribute is already present
        """
        # get the Instance
        obj = self.instance.execute(requires, resolver, queue_scheduler)

        if isinstance(obj, list):
            raise RuntimeException(
                self, "can not get a attribute %s, %s is a list" %
                (self.attribute, obj))

        if not isinstance(obj, Instance):
            raise RuntimeException(
                self, "can not get a attribute %s, %s not an entity" %
                (self.attribute, obj))

        # get the attribute result variable
        attr = obj.get_attribute(self.attribute)
        # Cache it
        self.attr = attr

        if attr.is_ready():
            # go ahead
            # i.e. back to the AttributeReference itself
            self.target.set_value(attr.get_value(), self.location)
        else:
            # reschedule on the attribute, XU will assign it to the target variable
            if self.resultcollector is not None:
                attr.listener(self.resultcollector, self.location)
            ExecutionUnit(queue_scheduler, resolver, self.target, {"x": attr},
                          self)
Exemplo n.º 5
0
    def requires_emit_gradual(
        self, resolver: Resolver, queue: QueueScheduler, resultcollector: Optional[ResultCollector]
    ) -> typing.Dict[object, ResultVariable]:

        if resultcollector is None:
            return self.requires_emit(resolver, queue)

        # if we are in gradual mode, transform to a list of assignments instead of assignment of a list
        # to get more accurate gradual execution
        # temp variable is required get all heuristics right

        # ListVariable to hold all the stuff. Used as a proxy for gradual execution and to track promises.
        # Freezes itself once all promises have been fulfilled, at which point it represents the full list literal created by
        # this statement.
        temp = ListLiteral(queue)

        # add listener for gradual execution
        temp.listener(resultcollector, self.location)

        # Assignments, wired for gradual
        for expr in self.items:
            ExecutionUnit(queue, resolver, temp, expr.requires_emit_gradual(resolver, queue, temp), expr, self)

        if not self.items:
            # empty: just close
            temp.freeze()

        # pass temp
        return {self: temp}
Exemplo n.º 6
0
 def resume(self, requires, resolver, queue, target):
     result = self.children[0].execute(requires, resolver, queue)
     if self._is_final(result):
         target.set_value(result, self.location)
     else:
         ExecutionUnit(queue, resolver, target,
                       self.children[1].requires_emit(resolver, queue),
                       self.children[1])
Exemplo n.º 7
0
 def resume(self, requires: Dict[object, object], resolver: Resolver, queue: QueueScheduler, target: ResultVariable) -> None:
     result = self.children[0].execute(requires, resolver, queue)
     self._validate_value(result, 0)
     assert isinstance(result, bool)
     if self._is_final(result):
         target.set_value(result, self.location)
     else:
         ExecutionUnit(
             queue, resolver, target, self.children[1].requires_emit(resolver, queue), self.children[1], owner=self
         )
Exemplo n.º 8
0
 def emit_expression(self, stmt):
     """
         Add a new statement
     """
     self.owner.copy_location(stmt)
     stmt.normalize(self.resolver)
     reqs = stmt.requires_emit(self.resolver, self.queue)
     ExecutionUnit(self.queue,
                   self.resolver,
                   self.result,
                   reqs,
                   stmt,
                   provides=False)
Exemplo n.º 9
0
 def emit(self, resolver: Resolver, queue: QueueScheduler) -> None:
     target = resolver.lookup(self.name)
     reqs = self.value.requires_emit(resolver, queue)
     ExecutionUnit(queue, resolver, target, reqs, self.value)
Exemplo n.º 10
0
 def emit(self, resolver: Resolver, queue: QueueScheduler) -> None:
     target = ResultVariable()
     reqs = self.requires_emit(resolver, queue)
     ExecutionUnit(queue, resolver, target, reqs, self)
Exemplo n.º 11
0
 def emit(self, resolver: Resolver, queue: QueueScheduler) -> None:
     for rv, exp in self.annotation_expression:
         reqs = exp.requires_emit(resolver, queue)
         ExecutionUnit(queue, resolver, rv, reqs, exp)
Exemplo n.º 12
0
 def emit(self, resolver: Resolver, queue: QueueScheduler) -> None:
     self._add_to_dataflow_graph(resolver.dataflow_graph)
     target = resolver.lookup(str(self.name))
     assert isinstance(target, ResultVariable)
     reqs = self.value.requires_emit(resolver, queue)
     ExecutionUnit(queue, resolver, target, reqs, self.value, owner=self)