Ejemplo n.º 1
0
 def process_args_nokwd(self, frame, anchor, args):
     checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0')
     args[0].connect(checker.recv)
     checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 1')
     args[1].connect(checker.recv)
     obj = CompoundTypeNode(args)
     return TupleType.create_tuple([obj, obj])
Ejemplo n.º 2
0
 def process_args_nokwd(self, frame, anchor, args):
   checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0')
   args[0].connect(checker.recv)
   checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 1')
   args[1].connect(checker.recv)
   obj = CompoundTypeNode(args)
   return TupleType.create_tuple([obj, obj])
Ejemplo n.º 3
0
 def process_args_nokwd(self, frame, anchor, args):
   checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0')
   args[0].connect(checker.recv)
   checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 1')
   args[1].connect(checker.recv)
   if 3 <= len(args):
     checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 2')
     args[2].connect(checker.recv)
   return CompoundTypeNode(args)
Ejemplo n.º 4
0
 def process_args_nokwd(self, frame, anchor, args):
     checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0')
     args[0].connect(checker.recv)
     checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 1')
     args[1].connect(checker.recv)
     if 3 <= len(args):
         checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 2')
         args[2].connect(checker.recv)
     return CompoundTypeNode(args)
Ejemplo n.º 5
0
 def recv_value(self, src):
   from pyntch.basic_types import NumberType
   from pyntch.klass import InstanceObject
   for obj in src:
     if obj in self.received: continue
     self.received.add(obj)
     if obj.is_type(NumberType.get_typeobj()):
       obj.connect(self.recv)
     elif isinstance(obj, InstanceObject):
       OptMethodCall(self.frame, self.anchor, obj, self.METHOD[self.op]).connect(self.recv)
   return
Ejemplo n.º 6
0
 def recv_value(self, src):
     from pyntch.basic_types import NumberType
     from pyntch.klass import InstanceObject
     for obj in src:
         if obj in self.received: continue
         self.received.add(obj)
         if obj.is_type(NumberType.get_typeobj()):
             obj.connect(self.recv)
         elif isinstance(obj, InstanceObject):
             OptMethodCall(self.frame, self.anchor, obj,
                           self.METHOD[self.op]).connect(self.recv)
     return
Ejemplo n.º 7
0
 def process_args_nokwd(self, frame, anchor, args):
   checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0')
   args[0].connect(checker.recv)
   return args[0]
Ejemplo n.º 8
0
 def process_args_nokwd(self, frame, anchor, args):
     checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0')
     args[0].connect(checker.recv)
     return args[0]
Ejemplo n.º 9
0
 def update_op(self, lobj, robj):
     from pyntch.basic_types import NumberType, IntType, BaseStringType, BUILTIN_OBJECT
     from pyntch.aggregate_types import ListType, ListObject, TupleType
     from pyntch.klass import InstanceObject
     if (lobj, robj) in self.received: return
     self.received.add((lobj, robj))
     # special handling for a formatting (%) operator
     ltype = lobj.get_type()
     rtype = robj.get_type()
     if (lobj.is_type(BaseStringType.get_typeobj()) and self.op == 'Mod'):
         self.computed.add((lobj, robj))
         lobj.connect(self.recv)
         return
     # for numeric operation, the one with a higher rank is chosen.
     if (lobj.is_type(NumberType.get_typeobj())
             and robj.is_type(NumberType.get_typeobj())
             and self.op in ('Add', 'Sub', 'Mul', 'Div', 'Mod', 'FloorDiv',
                             'Power', 'LeftShift', 'RightShift')):
         self.computed.add((lobj, robj))
         if ltype.get_rank() < rtype.get_rank():
             robj.connect(self.recv)
         else:
             lobj.connect(self.recv)
         return
     if (lobj.is_type(IntType.get_typeobj())
             and robj.is_type(IntType.get_typeobj())
             and self.op in ('Bitand', 'Bitor', 'Bitxor')):
         self.computed.add((lobj, robj))
         robj.connect(self.recv)
         return
     # for string operation, only Add is supported.
     if (lobj.is_type(BaseStringType.get_typeobj())
             and robj.is_type(BaseStringType.get_typeobj())
             and self.op == 'Add'):
         self.computed.add((lobj, robj))
         robj.connect(self.recv)
         return
     # adding lists.
     if (self.op == 'Add' and (lobj.is_type(ListType.get_typeobj())
                               and robj.is_type(ListType.get_typeobj()))):
         if not self.listobj:
             self.listobj = ListType.create_list()
             self.listobj.connect(self.recv)
         self.computed.add((lobj, robj))
         lobj.connect_element(self.listobj)
         robj.connect_element(self.listobj)
         return
     # multiplying a list by an integer.
     if self.op == 'Mul':
         if lobj.is_type(ListType.get_typeobj()) and robj.is_type(
                 IntType.get_typeobj()):
             self.computed.add((lobj, robj))
             lobj.connect(self.recv)
             return
         elif lobj.is_type(IntType.get_typeobj()) and robj.is_type(
                 ListType.get_typeobj()):
             self.computed.add((lobj, robj))
             robj.connect(self.recv)
             return
     # adding tuples.
     if (self.op == 'Add' and (lobj.is_type(TupleType.get_typeobj())
                               and robj.is_type(TupleType.get_typeobj()))):
         if not self.tupleobj:
             self.tupleobj = TupleType.create_tuple()
             self.tupleobj.connect(self.recv)
         self.computed.add((lobj, robj))
         lobj.connect_element(self.tupleobj)
         robj.connect_element(self.tupleobj)
         return
     # multiplying a tuple by an integer.
     if self.op == 'Mul':
         if lobj.is_type(TupleType.get_typeobj()) and robj.is_type(
                 IntType.get_typeobj()):
             self.computed.add((lobj, robj))
             lobj.connect(self.recv)
             return
         elif lobj.is_type(IntType.get_typeobj()) and robj.is_type(
                 TupleType.get_typeobj()):
             self.computed.add((lobj, robj))
             robj.connect(self.recv)
             return
     # other valid operations.
     k = (ltype.typename(), self.op, rtype.typename())
     if k in self.VALID_TYPES:
         self.computed.add((lobj, robj))
         BUILTIN_OBJECT[self.VALID_TYPES[k]].connect(self.recv)
         return
     # Handle optional methods.
     if isinstance(lobj, InstanceObject):
         result = OptMethodCall(self.frame, self.anchor, lobj,
                                self.LMETHOD[self.op], [robj])
         result.connect(lambda src: self.recv_result(src, (lobj, robj)))
     if isinstance(robj, InstanceObject):
         result = OptMethodCall(self.frame, self.anchor, robj,
                                self.RMETHOD[self.op], [lobj])
         result.connect(lambda src: self.recv_result(src, (lobj, robj)))
     return
Ejemplo n.º 10
0
 def update_op(self, lobj, robj):
   from pyntch.basic_types import NumberType, IntType, BaseStringType, BUILTIN_OBJECT
   from pyntch.aggregate_types import ListType, ListObject, TupleType
   from pyntch.klass import InstanceObject
   if (lobj,robj) in self.received: return
   self.received.add((lobj,robj))
   # special handling for a formatting (%) operator
   ltype = lobj.get_type()
   rtype = robj.get_type()
   if (lobj.is_type(BaseStringType.get_typeobj()) and
       self.op == 'Mod'):
     self.computed.add((lobj,robj))
     lobj.connect(self.recv)
     return
   # for numeric operation, the one with a higher rank is chosen.
   if (lobj.is_type(NumberType.get_typeobj()) and robj.is_type(NumberType.get_typeobj()) and
       self.op in ('Add','Sub','Mul','Div','Mod','FloorDiv','Power','LeftShift','RightShift')):
     self.computed.add((lobj,robj))
     if ltype.get_rank() < rtype.get_rank():
       robj.connect(self.recv)
     else:
       lobj.connect(self.recv)
     return
   if (lobj.is_type(IntType.get_typeobj()) and robj.is_type(IntType.get_typeobj()) and
       self.op in ('Bitand','Bitor','Bitxor')):
     self.computed.add((lobj,robj))
     robj.connect(self.recv)
     return
   # for string operation, only Add is supported.
   if (lobj.is_type(BaseStringType.get_typeobj()) and robj.is_type(BaseStringType.get_typeobj()) and
       self.op == 'Add'):
     self.computed.add((lobj,robj))
     robj.connect(self.recv)
     return
   # adding lists.
   if (self.op == 'Add' and
       (lobj.is_type(ListType.get_typeobj()) and robj.is_type(ListType.get_typeobj()))):
     if not self.listobj:
       self.listobj = ListType.create_list()
       self.listobj.connect(self.recv)
     self.computed.add((lobj,robj))
     lobj.connect_element(self.listobj)
     robj.connect_element(self.listobj)
     return
   # multiplying a list by an integer.
   if self.op == 'Mul':
     if lobj.is_type(ListType.get_typeobj()) and robj.is_type(IntType.get_typeobj()):
       self.computed.add((lobj,robj))
       lobj.connect(self.recv)
       return
     elif lobj.is_type(IntType.get_typeobj()) and robj.is_type(ListType.get_typeobj()):
       self.computed.add((lobj,robj))
       robj.connect(self.recv)
       return
   # adding tuples.
   if (self.op == 'Add' and
       (lobj.is_type(TupleType.get_typeobj()) and robj.is_type(TupleType.get_typeobj()))):
     if not self.tupleobj:
       self.tupleobj = TupleType.create_tuple()
       self.tupleobj.connect(self.recv)
     self.computed.add((lobj,robj))
     lobj.connect_element(self.tupleobj)
     robj.connect_element(self.tupleobj)
     return
   # multiplying a tuple by an integer.
   if self.op == 'Mul':
     if lobj.is_type(TupleType.get_typeobj()) and robj.is_type(IntType.get_typeobj()):
       self.computed.add((lobj,robj))
       lobj.connect(self.recv)
       return
     elif lobj.is_type(IntType.get_typeobj()) and robj.is_type(TupleType.get_typeobj()):
       self.computed.add((lobj,robj))
       robj.connect(self.recv)
       return
   # other valid operations.
   k = (ltype.typename(), self.op, rtype.typename())
   if k in self.VALID_TYPES:
     self.computed.add((lobj,robj))
     BUILTIN_OBJECT[self.VALID_TYPES[k]].connect(self.recv)
     return
   # Handle optional methods.
   if isinstance(lobj, InstanceObject):
     result = OptMethodCall(self.frame, self.anchor, lobj, self.LMETHOD[self.op], [robj])
     result.connect(lambda src: self.recv_result(src, (lobj, robj)))
   if isinstance(robj, InstanceObject):
     result = OptMethodCall(self.frame, self.anchor, robj, self.RMETHOD[self.op], [lobj])
     result.connect(lambda src: self.recv_result(src, (lobj, robj)))
   return