Пример #1
0
    class ReduceCaller(CompoundTypeNode):
        def __init__(self, frame, anchor, func, seq, initial):
            self.frame = frame
            self.anchor = anchor
            self.received = set()
            self.elem = IterElement(frame, anchor, seq)
            self.result = CompoundTypeNode()
            if initial:
                initial.connect(self.result.recv)
            else:
                self.elem.connect(self.result.recv)
            self.args = (self.result, self.elem)
            CompoundTypeNode.__init__(self, [self.result])
            func.connect(self.recv_func)
            return

        def recv_func(self, src):
            for obj in src:
                if obj in self.received: continue
                self.received.add(obj)
                try:
                    result = obj.call(self.frame, self.anchor, self.args, {})
                    result.connect(self.recv)
                    result.connect(self.result.recv)
                except NodeTypeError:
                    self.frame.raise_expt(ErrorConfig.NotCallable(obj))
            return
Пример #2
0
  class ReduceCaller(CompoundTypeNode):
    
    def __init__(self, frame, anchor, func, seq, initial):
      self.frame = frame
      self.anchor = anchor
      self.received = set()
      self.elem = IterElement(frame, anchor, seq)
      self.result = CompoundTypeNode()
      if initial:
        initial.connect(self.result.recv)
      else:
        self.elem.connect(self.result.recv)
      self.args = (self.result, self.elem)
      CompoundTypeNode.__init__(self, [self.result])
      func.connect(self.recv_func)
      return

    def recv_func(self, src):
      for obj in src:
        if obj in self.received: continue
        self.received.add(obj)
        try:
          result = obj.call(self.frame, self.anchor, self.args, {})
          result.connect(self.recv)
          result.connect(self.result.recv)
        except NodeTypeError:
          self.frame.raise_expt(ErrorConfig.NotCallable(obj))
      return
Пример #3
0
 def accept_arg(self, frame, anchor, i, arg1):
   if arg1 in self.cache_extend:
     elem = self.cache_extend[arg1]
   else:
     elem = IterElement(frame, anchor, arg1)
     self.cache_extend[arg1] = elem
   elem.connect(self.target.elemall.recv)
   return
Пример #4
0
 def accept_arg(self, frame, anchor, i, arg1):
     if arg1 in self.cache_extend:
         elem = self.cache_extend[arg1]
     else:
         elem = IterElement(frame, anchor, arg1)
         self.cache_extend[arg1] = elem
     elem.connect(self.target.elemall.recv)
     return
Пример #5
0
 def __init__(self, frame, anchor, seq, initial):
     self.frame = frame
     self.anchor = anchor
     self.received = set()
     self.elem = IterElement(frame, anchor, seq)
     self.result = CompoundTypeNode()
     if initial:
         initial.connect(self.result.recv)
     else:
         self.elem.connect(self.result.recv)
     CompoundTypeNode.__init__(self, [self.result])
     IterElement(frame, anchor, seq).connect(self.recv_elem)
     return
Пример #6
0
 def recv_pair(self, src):
   for obj in src:
     if obj.is_type(TupleType.get_typeobj()) and obj.elements:
       if len(obj.elements) == 2:
         (k,v) = obj.elements
         k.connect(self.target.key.recv)
         v.connect(self.target.value.recv)
       else:
         self.frame.raise_expt(ErrorConfig.NotConvertable('(key,value)'))
       continue
     elem = IterElement(self.frame, self.anchor, obj)
     elem.connect(self.target.key.recv)
     elem.connect(self.target.value.recv)
     self.frame.raise_expt(ErrorConfig.NotConvertable('dict'))
   return
Пример #7
0
 def recv(self, src):
   from pyntch.expression import IterElement
   for obj in src:
     if obj in self.received: continue
     self.received.add(obj)
     IterElement(self.parent_frame, self.anchor, obj).connect(self.elemchecker.recv)
   return
Пример #8
0
 def create_sequence(klass, frame, anchor, src):
     k = ('sequence', anchor)
     if k in klass.CACHE:
         return klass.CACHE[k]
     setobj = klass.create_set()
     IterElement(frame, anchor, src).connect(setobj.elemall.recv)
     klass.CACHE[k] = setobj
     return setobj
Пример #9
0
 def process_args(self, frame, anchor, args, kwargs):
     if kwargs:
         frame.raise_expt(ErrorConfig.NoKeywordArgs())
         return UndefinedTypeNode.get_object()
     elemall = TupleType.create_tuple(
         [IntType.get_object(),
          IterElement(frame, anchor, args[0])])
     return IterObject(self.get_typeobj(), elemall=elemall)
Пример #10
0
 def __init__(self, frame, anchor, func, seq):
     self.frame = frame
     self.anchor = anchor
     self.received = set()
     self.elem = IterElement(frame, anchor, seq)
     CompoundTypeNode.__init__(self, [seq])
     func.connect(self.recv_func)
     return
Пример #11
0
 def __init__(self, frame, anchor, func, objs):
     self.frame = frame
     self.anchor = anchor
     self.received = set()
     self.args = tuple(IterElement(frame, anchor, obj) for obj in objs)
     self.listobj = ListType.create_list()
     CompoundTypeNode.__init__(self, [self.listobj])
     func.connect(self.recv_func)
     return
Пример #12
0
 def call(self, frame, anchor, args, kwargs):
     if kwargs:
         frame.raise_expt(ErrorConfig.NoKeywordArgs())
         return UndefinedTypeNode.get_object()
     elems = [CompoundTypeNode() for arg1 in args]
     zipelem = TupleType.create_tuple(elements=elems)
     seq = ListType.create_list(elemall=zipelem)
     for (i, arg1) in enumerate(args):
         IterElement(frame, anchor, arg1).connect(elems[i].recv)
     return seq
Пример #13
0
 def __init__(self, frame, anchor, seq, initial):
   self.frame = frame
   self.anchor = anchor
   self.received = set()
   self.elem = IterElement(frame, anchor, seq)
   self.result = CompoundTypeNode()
   if initial:
     initial.connect(self.result.recv)
   else:
     self.elem.connect(self.result.recv)
   CompoundTypeNode.__init__(self, [self.result])
   IterElement(frame, anchor, seq).connect(self.recv_elem)
   return
Пример #14
0
  class SumCaller(CompoundTypeNode):
    
    def __init__(self, frame, anchor, seq, initial):
      self.frame = frame
      self.anchor = anchor
      self.received = set()
      self.elem = IterElement(frame, anchor, seq)
      self.result = CompoundTypeNode()
      if initial:
        initial.connect(self.result.recv)
      else:
        self.elem.connect(self.result.recv)
      CompoundTypeNode.__init__(self, [self.result])
      IterElement(frame, anchor, seq).connect(self.recv_elem)
      return

    def recv_elem(self, src):
      for obj in src:
        if obj in self.received: continue
        self.received.add(obj)
        BinaryOp(self.frame, self.anchor, 'Add', obj, self.result).connect(self.result.recv)
      return
Пример #15
0
    class SumCaller(CompoundTypeNode):
        def __init__(self, frame, anchor, seq, initial):
            self.frame = frame
            self.anchor = anchor
            self.received = set()
            self.elem = IterElement(frame, anchor, seq)
            self.result = CompoundTypeNode()
            if initial:
                initial.connect(self.result.recv)
            else:
                self.elem.connect(self.result.recv)
            CompoundTypeNode.__init__(self, [self.result])
            IterElement(frame, anchor, seq).connect(self.recv_elem)
            return

        def recv_elem(self, src):
            for obj in src:
                if obj in self.received: continue
                self.received.add(obj)
                BinaryOp(self.frame, self.anchor, 'Add', obj,
                         self.result).connect(self.result.recv)
            return
Пример #16
0
 def call(self, frame, anchor, args, kwargs):
     if kwargs:
         frame.raise_expt(ErrorConfig.NoKeywordArgs())
         return UndefinedTypeNode.get_object()
     retobj = CompoundTypeNode()
     if len(args) == 1:
         IterElement(frame, anchor, args[0]).connect(retobj.recv)
     else:
         for arg1 in args:
             arg1.connect(retobj.recv)
     if 'key' in kwargs:
         IterFuncChecker(frame, anchor, retobj, kwargs['key'])
     return retobj
Пример #17
0
 def recv_pair(self, src):
     for obj in src:
         if obj.is_type(TupleType.get_typeobj()) and obj.elements:
             if len(obj.elements) == 2:
                 (k, v) = obj.elements
                 k.connect(self.target.key.recv)
                 v.connect(self.target.value.recv)
             else:
                 self.frame.raise_expt(
                     ErrorConfig.NotConvertable('(key,value)'))
             continue
         elem = IterElement(self.frame, self.anchor, obj)
         elem.connect(self.target.key.recv)
         elem.connect(self.target.value.recv)
         self.frame.raise_expt(ErrorConfig.NotConvertable('dict'))
     return
Пример #18
0
 def recv2(self, src):
     for obj in src:
         IterElement(self.frame, self.anchor,
                     obj).connect(self.types2.recv)
     self.update_intersection()
     return
Пример #19
0
 def recv(self, src):
     for obj in src:
         IterElement(self.frame, self.anchor,
                     obj).connect(self.recv_pair)
     return
Пример #20
0
 def process_args(self, frame, anchor, args, kwargs):
     seq = ListType.create_list(elemall=IterElement(frame, anchor, args[0]))
     ListObject.SortMethod('sorted',
                           seq).process_args(frame, anchor, args[1:],
                                             kwargs)
     return seq
Пример #21
0
 def recv(self, src):
     for obj in src:
         IterElement(self.frame, self.anchor,
                     obj).connect(self.target.key.recv)
     return
Пример #22
0
 def accept_arg(self, frame, anchor, i, arg1):
     IterElement(frame, anchor, arg1)
     return