예제 #1
0
 def __init__(self, typeobj, elemall=None):
     self.elemall = CompoundTypeNode()
     if elemall:
         elemall.connect(self.elemall.recv)
     self.iter = None
     BuiltinAggregateObject.__init__(self, typeobj)
     return
예제 #2
0
 def __init__(self, frame, anchor, target, func):
   self.frame = frame
   self.anchor = anchor
   self.target = target
   CompoundTypeNode.__init__(self)
   func.connect(self.recv_func)
   return
예제 #3
0
 def __init__(self, frame, anchor, target, func):
     self.frame = frame
     self.anchor = anchor
     self.target = target
     CompoundTypeNode.__init__(self)
     func.connect(self.recv_func)
     return
예제 #4
0
 def __init__(self, frame, anchor, spec):
     self.checker = TypeChecker(frame, [TypeType.get_typeobj()], 'typespec')
     self.tuplechecker = SequenceTypeChecker(frame, anchor,
                                             [TypeType.get_typeobj()],
                                             'typespec')
     CompoundTypeNode.__init__(self)
     spec.connect(self.recv)
     return
예제 #5
0
 def __init__(self, frame, anchor, target):
   self.frame = frame
   self.anchor = anchor
   self.target = target
   self.received = set()
   CompoundTypeNode.__init__(self)
   target.connect(self.recv_target)
   return
예제 #6
0
 def __init__(self, frame, anchor, target):
     self.frame = frame
     self.anchor = anchor
     self.target = target
     self.received = set()
     CompoundTypeNode.__init__(self)
     target.connect(self.recv_target)
     return
예제 #7
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
예제 #8
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
예제 #9
0
 def __init__(self, frame, anchor, exctype, excargs):
   self.frame = frame
   self.anchor = anchor
   self.exctype = exctype
   self.excargs = excargs
   self.processed = set()
   CompoundTypeNode.__init__(self)
   exctype.connect(self.recv_type)
   return
예제 #10
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
예제 #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 __init__(self, typeobj, elemall=None, elements=None):
     IterObject.__init__(self, typeobj, elemall=elemall)
     self.sent = CompoundTypeNode()
     if elements:
         for obj in elements:
             if isinstance(obj, GeneratorSlot):
                 self.sent.connect(obj.received.recv)
             obj.connect(self.elemall.recv)
     return
예제 #13
0
 def __init__(self, frame, anchor, target, src1, src2):
     self.frame = frame
     self.anchor = anchor
     self.target = target
     self.types1 = CompoundTypeNode()
     self.types2 = CompoundTypeNode()
     CompoundTypeNode.__init__(self)
     src1.connect(self.recv1)
     src2.connect(self.recv2)
     return
예제 #14
0
 def __init__(self, frame, anchor, name, klass, instance):
   self.frame = frame
   self.anchor = anchor
   self.name = name
   self.klass = klass
   self.instance = instance
   self.processed = set()
   CompoundTypeNode.__init__(self)
   klass.connect(self.recv_klass)
   return
예제 #15
0
 def __init__(self, frame, anchor, name, klass, klasses=None):
   self.frame = frame
   self.anchor = anchor
   self.name = name
   self.klass = klass
   self.processed = set()
   CompoundTypeNode.__init__(self)
   if klasses:
     klasses.connect(self.recv_klass)
   return
예제 #16
0
 def __init__(self, frame, anchor, target, src1, src2):
   self.frame = frame
   self.anchor = anchor
   self.target = target
   self.types1 = CompoundTypeNode()
   self.types2 = CompoundTypeNode()
   CompoundTypeNode.__init__(self)
   src1.connect(self.recv1)
   src2.connect(self.recv2)
   return
예제 #17
0
class GeneratorObject(IterObject):

    # Send
    class Send(BuiltinConstMethod):
        def __init__(self,
                     name,
                     target,
                     retobj=NoneType.get_object(),
                     args=None,
                     expts=None):
            self.target = target
            BuiltinConstMethod.__init__(self,
                                        name,
                                        retobj,
                                        args=args,
                                        expts=expts)
            return

        def accept_arg(self, frame, anchor, i, arg1):
            arg1.connect(self.target.sent.recv)
            return

    # GeneratorObject
    def __init__(self, typeobj, elemall=None, elements=None):
        IterObject.__init__(self, typeobj, elemall=elemall)
        self.sent = CompoundTypeNode()
        if elements:
            for obj in elements:
                if isinstance(obj, GeneratorSlot):
                    self.sent.connect(obj.received.recv)
                obj.connect(self.elemall.recv)
        return

    def create_attr(self, frame, anchor, name):
        if name == 'send':
            return self.Send(
                'generator.send',
                self,
                self.elemall, [ANY],
                expts=[StopIterationType.maybe('might raise StopIteration')])
        if name == 'next':
            NoneType.get_object().connect(self.sent.recv)
            return self.Send(
                'generator.next',
                self,
                self.elemall,
                expts=[StopIterationType.maybe('might raise StopIteration')])
        if name == 'throw':
            # XXX do nothing for now
            return BuiltinConstMethod('generator.throw', NoneType.get_object(),
                                      [ANY], [ANY, ANY])
        if name == 'close':
            return self.Send('generator.close', self, NoneType.get_object(),
                             [ANY])
        return IterObject.create_attr(self, frame, anchor, name)
예제 #18
0
 def __init__(self, parent, expt):
   self.received = set()
   self.reraise = False
   self.var = CompoundTypeNode()
   if expt:
     self.expt = CompoundTypeNode()
     expt.connect(self.recv_expt)
   else:
     self.expt = None
   ExecutionFrame.__init__(self, parent, None)
   return
예제 #19
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
예제 #20
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
예제 #21
0
 def __init__(self, typeobj, items=None, key=None, value=None):
   if items != None:
     assert key == None and value == None
     self.key = CompoundTypeNode( k for (k,v) in items )
     self.value = CompoundTypeNode( v for (k,v) in items )
   else:
     self.key = CompoundTypeNode(key)
     self.value = CompoundTypeNode(value)
   self.default = CompoundTypeNode([NoneType.get_object()])
   self.value.connect(self.default.recv)
   self.iter = None
   BuiltinAggregateObject.__init__(self, typeobj)
   return
예제 #22
0
 def __init__(self, parent, tree):
   self.parent = parent
   self.raised = set()
   if tree:
     self.loc = (tree._module, tree.lineno)
   else:
     self.loc = None
   CompoundTypeNode.__init__(self)
   if parent:
     assert isinstance(parent, ExecutionFrame), parent
     if self.expt_debug:
       print >>sys.stderr, 'connect_expt: %r <- %r' % (parent, self)
     self.connect(parent.recv)
   return
예제 #23
0
 def __init__(self, frame, anchor, target, fcmp, fkey):
   self.frame = frame
   self.anchor = anchor
   self.target = target
   self.received_fkey = set()
   self.received_fcmp = set()
   self.key = CompoundTypeNode()
   CompoundTypeNode.__init__(self)
   if fkey:
     fkey.connect(self.recv_fkey)
   else:
     target.elemall.connect(self.key.recv)
   if fcmp:
     fcmp.connect(self.recv_fcmp)
   return
예제 #24
0
 def __init__(self, frame, anchor, target, fcmp, fkey):
     self.frame = frame
     self.anchor = anchor
     self.target = target
     self.received_fkey = set()
     self.received_fcmp = set()
     self.key = CompoundTypeNode()
     CompoundTypeNode.__init__(self)
     if fkey:
         fkey.connect(self.recv_fkey)
     else:
         target.elemall.connect(self.key.recv)
     if fcmp:
         fcmp.connect(self.recv_fcmp)
     return
예제 #25
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])
예제 #26
0
 def __init__(self, typeobj, elemall=None):
   self.elemall = CompoundTypeNode()
   if elemall:
     elemall.connect(self.elemall.recv)
   self.iter = None
   BuiltinAggregateObject.__init__(self, typeobj)
   return
예제 #27
0
 def __init__(self, typeobj, items=None, key=None, value=None):
     if items != None:
         assert key == None and value == None
         self.key = CompoundTypeNode(k for (k, v) in items)
         self.value = CompoundTypeNode(v for (k, v) in items)
     else:
         self.key = CompoundTypeNode(key)
         self.value = CompoundTypeNode(value)
     self.default = CompoundTypeNode([NoneType.get_object()])
     self.value.connect(self.default.recv)
     self.iter = None
     BuiltinAggregateObject.__init__(self, typeobj)
     return
예제 #28
0
    class Get(BuiltinConstMethod):
        def __init__(self, dictobj, name):
            self.dictobj = dictobj
            self.found = CompoundTypeNode([dictobj.value])
            BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
            return

        def process_args(self, frame, anchor, args, kwargs):
            if len(args) == 1:
                self.found.update_type(NoneType.get_object())
            return BuiltinConstMethod.process_args(self, frame, anchor, args,
                                                   kwargs)

        def accept_arg(self, frame, anchor, i, arg1):
            if i != 0:
                arg1.connect(self.found.recv)
            return
예제 #29
0
 def __init__(self, frame, anchor, tupobj, nelements, strict=True):
     self.tupobj = tupobj
     self.elements = [CompoundTypeNode() for _ in xrange(nelements)]
     self.strict = strict
     self.received = set()
     ExpressionNode.__init__(self, frame, anchor)
     self.tupobj.connect(self.recv_tupobj)
     return
예제 #30
0
 class Get(BuiltinConstMethod):
   
   def __init__(self, dictobj, name):
     self.dictobj = dictobj
     self.found = CompoundTypeNode([dictobj.value])
     BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
     return
   
   def process_args(self, frame, anchor, args, kwargs):
     if len(args) == 1:
       self.found.update_type(NoneType.get_object())
     return BuiltinConstMethod.process_args(self, frame, anchor, args, kwargs)
   
   def accept_arg(self, frame, anchor, i, arg1):
     if i != 0:
       arg1.connect(self.found.recv)
     return
예제 #31
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)
예제 #32
0
 def __init__(self, typeobj, elemall=None, elements=None):
   IterObject.__init__(self, typeobj, elemall=elemall)
   self.sent = CompoundTypeNode()
   if elements:
     for obj in elements:
       if isinstance(obj, GeneratorSlot):
         self.sent.connect(obj.received.recv)
       obj.connect(self.elemall.recv)
   return
예제 #33
0
 def __init__(self, name, bases):
   self.name = name
   self.bases = bases
   self.attrs = {}
   self.boundmethods = {}
   self.frames = set()
   BuiltinType.__init__(self)
   self.klasses = CompoundTypeNode(bases+[self])
   self.instance = InstanceObject(self)
   return
예제 #34
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
예제 #35
0
class IterObject(BuiltinAggregateObject):
    def __init__(self, typeobj, elemall=None):
        self.elemall = CompoundTypeNode()
        if elemall:
            elemall.connect(self.elemall.recv)
        BuiltinAggregateObject.__init__(self, typeobj)
        return

    def __repr__(self):
        return '(%r, ...)' % self.elemall

    def __str__(self):
        return self.desctxt({})

    def desctxt(self, done):
        if self in done:
            return '...'
        else:
            done[self] = len(done)
            return '(%s, ...)' % self.elemall.desctxt(done)

    def descxml(self, done):
        if self in done:
            e = Element('ref', id=str(done[self]))
        else:
            done[self] = len(done)
            e = Element('iter', id=str(done[self]))
            e.append(self.elemall.descxml(done))
        return e

    def get_iter(self, frame, anchor):
        return self

    def create_attr(self, frame, anchor, name):
        if name == 'next':
            return BuiltinConstMethod(
                'iter.next',
                self.elemall,
                expts=[StopIterationType.maybe('might raise StopIteration')])
        raise NodeAttrError(name)
예제 #36
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
예제 #37
0
class GeneratorObject(IterObject):

  # Send
  class Send(BuiltinConstMethod):
    
    def __init__(self, name, target, retobj=NoneType.get_object(), args=None, expts=None):
      self.target = target
      BuiltinConstMethod.__init__(self, name, retobj, args=args, expts=expts)
      return
    
    def accept_arg(self, frame, anchor, i, arg1):
      arg1.connect(self.target.sent.recv)
      return

  # GeneratorObject
  def __init__(self, typeobj, elemall=None, elements=None):
    IterObject.__init__(self, typeobj, elemall=elemall)
    self.sent = CompoundTypeNode()
    if elements:
      for obj in elements:
        if isinstance(obj, GeneratorSlot):
          self.sent.connect(obj.received.recv)
        obj.connect(self.elemall.recv)
    return

  def create_attr(self, frame, anchor, name):
    if name == 'send':
      return self.Send('generator.send', self, self.elemall, [ANY],
                       expts=[StopIterationType.maybe('might raise StopIteration')])
    if name == 'next':
      NoneType.get_object().connect(self.sent.recv)
      return self.Send('generator.next', self, self.elemall,
                       expts=[StopIterationType.maybe('might raise StopIteration')])
    if name == 'throw':
      # XXX do nothing for now
      return BuiltinConstMethod('generator.throw', NoneType.get_object(), [ANY], [ANY, ANY])
    if name == 'close':
      return self.Send('generator.close', self, NoneType.get_object(), [ANY])
    return IterObject.create_attr(self, frame, anchor, name)
예제 #38
0
class IterObject(BuiltinAggregateObject):

  def __init__(self, typeobj, elemall=None):
    self.elemall = CompoundTypeNode()
    if elemall:
      elemall.connect(self.elemall.recv)
    BuiltinAggregateObject.__init__(self, typeobj)
    return
  
  def __repr__(self):
    return '(%r, ...)' % self.elemall
  def __str__(self):
    return self.desctxt({})

  def desctxt(self, done):
    if self in done:
      return '...'
    else:
      done[self] = len(done)
      return '(%s, ...)' % self.elemall.desctxt(done)
    
  def descxml(self, done):
    if self in done:
      e = Element('ref', id=str(done[self]))
    else:
      done[self] = len(done)
      e = Element('iter', id=str(done[self]))
      e.append(self.elemall.descxml(done))
    return e

  def get_iter(self, frame, anchor):
    return self

  def create_attr(self, frame, anchor, name):
    if name == 'next':
      return BuiltinConstMethod('iter.next', self.elemall,
                                expts=[StopIterationType.maybe('might raise StopIteration')])
    raise NodeAttrError(name)
예제 #39
0
class BuiltinSequenceObject(BuiltinAggregateObject):

  # SequenceExtender
  class SequenceExtender(BuiltinConstMethod):
    
    def __init__(self, name, target, retobj=NoneType.get_object(), args=None, optargs=None):
      self.target = target
      self.cache_extend = {}
      BuiltinConstMethod.__init__(self, name, retobj, args=args, optargs=optargs)
      return
    
    def __repr__(self):
      return '%r.extend' % self.target
    
    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

  # SequenceAppender
  class SequenceAppender(BuiltinConstMethod):
    
    def __init__(self, name, target, retobj=NoneType.get_object(), args=None, optargs=None):
      self.target = target
      BuiltinConstMethod.__init__(self, name, retobj, args=args, optargs=optargs)
      return
    
    def __repr__(self):
      return '%r.append' % self.target
    
    def accept_arg(self, frame, anchor, i, arg1):
      arg1.connect(self.target.elemall.recv)
      return

  # BuiltinSequenceObject
  def __init__(self, typeobj, elemall=None):
    self.elemall = CompoundTypeNode()
    if elemall:
      elemall.connect(self.elemall.recv)
    self.iter = None
    BuiltinAggregateObject.__init__(self, typeobj)
    return
  
  def get_iter(self, frame, anchor):
    if not self.iter:
      self.iter = IterType.create_iter(self.elemall)
    return self.iter

  def get_length(self, frame, anchor):
    return IntType.get_object()

  get_reversed = get_iter

  def connect_element(self, seqobj):
    assert isinstance(seqobj, BuiltinSequenceObject)
    self.elemall.connect(seqobj.elemall.recv)
    return
예제 #40
0
 def __init__(self, frame, anchor, target):
   self.frame = frame
   self.anchor = anchor
   self.target = target
   CompoundTypeNode.__init__(self)
   return
예제 #41
0
파일: expression.py 프로젝트: euske/pyntch
 def __init__(self, frame, anchor):
   self.frame = frame
   self.anchor = anchor
   CompoundTypeNode.__init__(self)
   return
예제 #42
0
 def __init__(self, value):
   self.received = CompoundTypeNode()
   CompoundTypeNode.__init__(self, [value])
   return
예제 #43
0
class BuiltinSequenceObject(BuiltinAggregateObject):

    # SequenceExtender
    class SequenceExtender(BuiltinConstMethod):
        def __init__(self,
                     name,
                     target,
                     retobj=NoneType.get_object(),
                     args=None,
                     optargs=None):
            self.target = target
            self.cache_extend = {}
            BuiltinConstMethod.__init__(self,
                                        name,
                                        retobj,
                                        args=args,
                                        optargs=optargs)
            return

        def __repr__(self):
            return '%r.extend' % self.target

        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

    # SequenceAppender
    class SequenceAppender(BuiltinConstMethod):
        def __init__(self,
                     name,
                     target,
                     retobj=NoneType.get_object(),
                     args=None,
                     optargs=None):
            self.target = target
            BuiltinConstMethod.__init__(self,
                                        name,
                                        retobj,
                                        args=args,
                                        optargs=optargs)
            return

        def __repr__(self):
            return '%r.append' % self.target

        def accept_arg(self, frame, anchor, i, arg1):
            arg1.connect(self.target.elemall.recv)
            return

    # BuiltinSequenceObject
    def __init__(self, typeobj, elemall=None):
        self.elemall = CompoundTypeNode()
        if elemall:
            elemall.connect(self.elemall.recv)
        self.iter = None
        BuiltinAggregateObject.__init__(self, typeobj)
        return

    def get_iter(self, frame, anchor):
        if not self.iter:
            self.iter = IterType.create_iter(self.elemall)
        return self.iter

    def get_length(self, frame, anchor):
        return IntType.get_object()

    get_reversed = get_iter

    def connect_element(self, seqobj):
        assert isinstance(seqobj, BuiltinSequenceObject)
        self.elemall.connect(seqobj.elemall.recv)
        return
예제 #44
0
 def __init__(self, frame, anchor, target):
     self.frame = frame
     self.anchor = anchor
     self.target = target
     CompoundTypeNode.__init__(self)
     return
예제 #45
0
class DictObject(BuiltinAggregateObject):

    # convert
    class DictConverter(CompoundTypeNode):
        def __init__(self, frame, anchor, target):
            self.frame = frame
            self.anchor = anchor
            self.target = target
            CompoundTypeNode.__init__(self)
            return

        def __repr__(self):
            return 'convert(%r)' % self.target

        def recv(self, src):
            for obj in src:
                IterElement(self.frame, self.anchor,
                            obj).connect(self.recv_pair)
            return

        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

    # fromkeys
    class DictConverterFromKeys(CompoundTypeNode):
        def __init__(self, frame, anchor, target):
            self.frame = frame
            self.anchor = anchor
            self.target = target
            CompoundTypeNode.__init__(self)
            return

        def recv(self, src):
            for obj in src:
                IterElement(self.frame, self.anchor,
                            obj).connect(self.target.key.recv)
            return

    # dict.get
    class Get(BuiltinConstMethod):
        def __init__(self, dictobj, name):
            self.dictobj = dictobj
            self.found = CompoundTypeNode([dictobj.value])
            BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
            return

        def process_args(self, frame, anchor, args, kwargs):
            if len(args) == 1:
                self.found.update_type(NoneType.get_object())
            return BuiltinConstMethod.process_args(self, frame, anchor, args,
                                                   kwargs)

        def accept_arg(self, frame, anchor, i, arg1):
            if i != 0:
                arg1.connect(self.found.recv)
            return

    # dict.pop
    class Pop(BuiltinConstMethod):
        def __init__(self, dictobj, name):
            self.dictobj = dictobj
            self.found = CompoundTypeNode([dictobj.value])
            BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
            return

        def process_args(self, frame, anchor, args, kwargs):
            if len(args) == 1:
                frame.raise_expt(ErrorConfig.MaybeKeyNotFound())
            return BuiltinConstMethod.process_args(self, frame, anchor, args,
                                                   kwargs)

        def accept_arg(self, frame, anchor, i, arg1):
            if i != 0:
                arg1.connect(self.found.recv)
            return

    # dict.setdefault
    class SetDefault(BuiltinConstMethod):
        def __init__(self, dictobj, name):
            self.dictobj = dictobj
            self.found = CompoundTypeNode([dictobj.value])
            BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
            return

        def __repr__(self):
            return '%r.setdefault' % self.dictobj

        def process_args(self, frame, anchor, args, kwargs):
            if len(args) == 1:
                self.found.update_type(NoneType.get_object())
            return BuiltinConstMethod.process_args(self, frame, anchor, args,
                                                   kwargs)

        def accept_arg(self, frame, anchor, i, arg1):
            if i == 0:
                arg1.connect(self.dictobj.value.recv)
            else:
                arg1.connect(self.found.recv)
            return

    # dict.update
    class Update(BuiltinConstMethod):
        def __init__(self, dictobj, name):
            self.cache_update = {}
            self.dictobj = dictobj
            BuiltinConstMethod.__init__(self, name, NoneType.get_object(),
                                        [ANY])
            return

        def process_args(self, frame, anchor, args, kwargs):
            v = args[0]
            if v not in self.cache_update:
                converter = DictObject.DictConverterFromKeys(
                    frame, anchor, self.dictobj)
                self.cache_update[v] = converter
                v.connect(converter.recv)
            return NoneType.get_object()

    # DictObject
    def __init__(self, typeobj, items=None, key=None, value=None):
        if items != None:
            assert key == None and value == None
            self.key = CompoundTypeNode(k for (k, v) in items)
            self.value = CompoundTypeNode(v for (k, v) in items)
        else:
            self.key = CompoundTypeNode(key)
            self.value = CompoundTypeNode(value)
        self.default = CompoundTypeNode([NoneType.get_object()])
        self.value.connect(self.default.recv)
        self.iter = None
        BuiltinAggregateObject.__init__(self, typeobj)
        return

    def __repr__(self):
        return '{%r: %r}' % (self.key, self.value)

    def __str__(self):
        return self.desctxt({})

    def desctxt(self, done):
        if self in done:
            return '...'
        else:
            done[self] = len(done)
            return '{%s: %s}' % (self.key.desctxt(done),
                                 self.value.desctxt(done))

    def descxml(self, done):
        if self in done:
            e = Element('ref', id=str(done[self]))
        else:
            done[self] = len(done)
            e = Element('dict', id=str(done[self]))
            e.append(self.key.descxml(done))
            e.append(self.value.descxml(done))
        return e

    def create_attr(self, frame, anchor, name):
        if name == 'clear':
            return BuiltinConstMethod('dict.clear', NoneType.get_object())
        elif name == 'copy':
            dictobj = self.get_type().create_copy(frame, anchor, self)
            return BuiltinConstMethod('dict.copy', dictobj)
        elif name == 'fromkeys':
            return DictType.FromKeys('dict.fromkeys')
        elif name == 'get':
            return DictObject.Get(self, 'dict.get')
        elif name == 'has_key':
            return BuiltinConstMethod('dict.has_key', BoolType.get_object(),
                                      [ANY])
        elif name == 'keys':
            return BuiltinConstMethod('dict.keys',
                                      ListType.create_list(self.key))
        elif name == 'values':
            return BuiltinConstMethod('dict.values',
                                      ListType.create_list(self.value))
        elif name == 'items':
            return BuiltinConstMethod(
                'dict.items',
                ListType.create_list(
                    TupleType.create_tuple([self.key, self.value])))
        elif name == 'iterkeys':
            return BuiltinConstMethod('dict.iterkeys',
                                      IterType.create_iter(self.key))
        elif name == 'itervalues':
            return BuiltinConstMethod('dict.itervalues',
                                      IterType.create_iter(self.value))
        elif name == 'iteritems':
            return BuiltinConstMethod(
                'dict.iteritems',
                IterType.create_iter(
                    TupleType.create_tuple([self.key, self.value])))
        elif name == 'pop':
            return DictObject.Pop(self, 'dict.pop')
        elif name == 'popitem':
            return BuiltinConstMethod(
                'dict.popitem',
                TupleType.create_tuple([self.key, self.value]),
                expts=[ErrorConfig.MaybeElementNotFound()])
        elif name == 'setdefault':
            return DictObject.SetDefault(self, 'dict.setdefault')
        elif name == 'update':
            return DictObject.Update(self, 'dict.update')
        raise NodeAttrError(name)

    def get_element(self, frame, anchor, key, write=False):
        if write:
            key.connect(self.key.recv)
        else:
            frame.raise_expt(ErrorConfig.MaybeKeyNotFound())
        return self.value

    def get_iter(self, frame, anchor):
        if not self.iter:
            self.iter = IterType.create_iter(self.key)
        return self.iter

    def get_length(self, frame, anchor):
        return IntType.get_object()
예제 #46
0
 def __init__(self, value):
     self.received = CompoundTypeNode()
     CompoundTypeNode.__init__(self, [value])
     return
예제 #47
0
파일: function.py 프로젝트: euske/pyntch
 def __init__(self, name):
   self.name = name
   CompoundTypeNode.__init__(self)
   return
예제 #48
0
파일: basic_types.py 프로젝트: euske/pyntch
 def __init__(self, typeobj, wrapper, obj):
   self.typeobj = typeobj
   self.wrapper = wrapper
   self.received = set()
   CompoundTypeNode.__init__(self, [obj])
   return
예제 #49
0
 def __init__(self, frame, anchor, spec):
   self.checker = TypeChecker(frame, [TypeType.get_typeobj()], 'typespec')
   self.tuplechecker = SequenceTypeChecker(frame, anchor, [TypeType.get_typeobj()], 'typespec')
   CompoundTypeNode.__init__(self)
   spec.connect(self.recv)
   return
예제 #50
0
class DictObject(BuiltinAggregateObject):

  # convert
  class DictConverter(CompoundTypeNode):
    
    def __init__(self, frame, anchor, target):
      self.frame = frame
      self.anchor = anchor
      self.target = target
      CompoundTypeNode.__init__(self)
      return
    
    def __repr__(self):
      return 'convert(%r)' % self.target
    
    def recv(self, src):
      for obj in src:
        IterElement(self.frame, self.anchor, obj).connect(self.recv_pair)
      return
  
    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
    
  # fromkeys
  class DictConverterFromKeys(CompoundTypeNode):
    
    def __init__(self, frame, anchor, target):
      self.frame = frame
      self.anchor = anchor
      self.target = target
      CompoundTypeNode.__init__(self)
      return
    
    def recv(self, src):
      for obj in src:
        IterElement(self.frame, self.anchor, obj).connect(self.target.key.recv)
      return

  # dict.get
  class Get(BuiltinConstMethod):
    
    def __init__(self, dictobj, name):
      self.dictobj = dictobj
      self.found = CompoundTypeNode([dictobj.value])
      BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
      return
    
    def process_args(self, frame, anchor, args, kwargs):
      if len(args) == 1:
        self.found.update_type(NoneType.get_object())
      return BuiltinConstMethod.process_args(self, frame, anchor, args, kwargs)
    
    def accept_arg(self, frame, anchor, i, arg1):
      if i != 0:
        arg1.connect(self.found.recv)
      return

  # dict.pop
  class Pop(BuiltinConstMethod):
    
    def __init__(self, dictobj, name):
      self.dictobj = dictobj
      self.found = CompoundTypeNode([dictobj.value])
      BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
      return
    
    def process_args(self, frame, anchor, args, kwargs):
      if len(args) == 1:
        frame.raise_expt(ErrorConfig.MaybeKeyNotFound())
      return BuiltinConstMethod.process_args(self, frame, anchor, args, kwargs)
    
    def accept_arg(self, frame, anchor, i, arg1):
      if i != 0:
        arg1.connect(self.found.recv)
      return

  # dict.setdefault
  class SetDefault(BuiltinConstMethod):
    
    def __init__(self, dictobj, name):
      self.dictobj = dictobj
      self.found = CompoundTypeNode([dictobj.value])
      BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
      return
    
    def __repr__(self):
      return '%r.setdefault' % self.dictobj
    
    def process_args(self, frame, anchor, args, kwargs):
      if len(args) == 1:
        self.found.update_type(NoneType.get_object())
      return BuiltinConstMethod.process_args(self, frame, anchor, args, kwargs)
    
    def accept_arg(self, frame, anchor, i, arg1):
      if i == 0:
        arg1.connect(self.dictobj.value.recv)
      else:
        arg1.connect(self.found.recv)
      return

  # dict.update
  class Update(BuiltinConstMethod):
    
    def __init__(self, dictobj, name):
      self.cache_update = {}
      self.dictobj = dictobj
      BuiltinConstMethod.__init__(self, name, NoneType.get_object(), [ANY])
      return
    
    def process_args(self, frame, anchor, args, kwargs):
      v = args[0]
      if v not in self.cache_update:
        converter = DictObject.DictConverterFromKeys(frame, anchor, self.dictobj)
        self.cache_update[v] = converter
        v.connect(converter.recv)
      return NoneType.get_object()

  # DictObject
  def __init__(self, typeobj, items=None, key=None, value=None):
    if items != None:
      assert key == None and value == None
      self.key = CompoundTypeNode( k for (k,v) in items )
      self.value = CompoundTypeNode( v for (k,v) in items )
    else:
      self.key = CompoundTypeNode(key)
      self.value = CompoundTypeNode(value)
    self.default = CompoundTypeNode([NoneType.get_object()])
    self.value.connect(self.default.recv)
    self.iter = None
    BuiltinAggregateObject.__init__(self, typeobj)
    return
  
  def __repr__(self):
    return '{%r: %r}' % (self.key, self.value)
  def __str__(self):
    return self.desctxt({})

  def desctxt(self, done):
    if self in done:
      return '...'
    else:
      done[self] = len(done)
      return '{%s: %s}' % (self.key.desctxt(done), self.value.desctxt(done))
    
  def descxml(self, done):
    if self in done:
      e = Element('ref', id=str(done[self]))
    else:
      done[self] = len(done)
      e = Element('dict', id=str(done[self]))
      e.append(self.key.descxml(done))
      e.append(self.value.descxml(done))
    return e

  def create_attr(self, frame, anchor, name):
    if name == 'clear':
      return BuiltinConstMethod('dict.clear', NoneType.get_object())
    elif name == 'copy':
      dictobj = self.get_type().create_copy(frame, anchor, self)
      return BuiltinConstMethod('dict.copy', dictobj)
    elif name == 'fromkeys':
      return DictType.FromKeys('dict.fromkeys')
    elif name == 'get':
      return DictObject.Get(self, 'dict.get')
    elif name == 'has_key':
      return BuiltinConstMethod('dict.has_key', BoolType.get_object(), [ANY])
    elif name == 'keys':
      return BuiltinConstMethod('dict.keys',
                                  ListType.create_list(self.key))
    elif name == 'values':
      return BuiltinConstMethod('dict.values',
                                  ListType.create_list(self.value))
    elif name == 'items':
      return BuiltinConstMethod('dict.items',
                                  ListType.create_list(TupleType.create_tuple([self.key, self.value])))
    elif name == 'iterkeys':
      return BuiltinConstMethod('dict.iterkeys',
                                  IterType.create_iter(self.key))
    elif name == 'itervalues':
      return BuiltinConstMethod('dict.itervalues',
                                  IterType.create_iter(self.value))
    elif name == 'iteritems':
      return BuiltinConstMethod('dict.iteritems',
                                  IterType.create_iter(TupleType.create_tuple([self.key, self.value])))
    elif name == 'pop':
      return DictObject.Pop(self, 'dict.pop')
    elif name == 'popitem':
      return BuiltinConstMethod('dict.popitem', TupleType.create_tuple([self.key, self.value]),
                                expts=[ErrorConfig.MaybeElementNotFound()])
    elif name == 'setdefault':
      return DictObject.SetDefault(self, 'dict.setdefault')
    elif name == 'update':
      return DictObject.Update(self, 'dict.update')
    raise NodeAttrError(name)

  def get_element(self, frame, anchor, key, write=False):
    if write:
      key.connect(self.key.recv)
    else:
      frame.raise_expt(ErrorConfig.MaybeKeyNotFound())
    return self.value

  def get_iter(self, frame, anchor):
    if not self.iter:
      self.iter = IterType.create_iter(self.key)
    return self.iter

  def get_length(self, frame, anchor):
    return IntType.get_object()
예제 #51
0
파일: basic_types.py 프로젝트: euske/pyntch
 def __init__(self, frame, value):
   self.frame = frame
   self.received = set()
   CompoundTypeNode.__init__(self, [value])
   return
예제 #52
0
 def __init__(self, dictobj, name):
     self.dictobj = dictobj
     self.found = CompoundTypeNode([dictobj.value])
     BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
     return
예제 #53
0
파일: namespace.py 프로젝트: euske/pyntch
 def __init__(self, space, name):
   self.space = space
   self.name = name
   CompoundTypeNode.__init__(self)
   return
예제 #54
0
 def __init__(self, dictobj, name):
   self.dictobj = dictobj
   self.found = CompoundTypeNode([dictobj.value])
   BuiltinConstMethod.__init__(self, name, self.found, [ANY], [ANY])
   return