Example #1
0
 def ref(self, firstitemptr):
     A = lltype.typeOf(firstitemptr).TO
     if A == self.TYPE:
         # for array of containers
         parent, index = lltype.parentlink(firstitemptr._obj)
         assert parent, "%r is not within a container" % (firstitemptr,)
         assert isinstance(lltype.typeOf(parent),
                           (lltype.Array, lltype.FixedSizeArray)), (
             "%r is not within an array" % (firstitemptr,))
         if isinstance(index, str):
             assert index.startswith('item')    # itemN => N
             index = int(index[4:])
         index += self.repeat
         if index == parent.getlength():
             # for references exactly to the end of the array
             try:
                 endmarker = _end_markers[parent]
             except KeyError:
                 endmarker = _endmarker_struct(A, parent=parent,
                                               parentindex=index)
                 _end_markers[parent] = endmarker
             return endmarker._as_ptr()
         else:
             return parent.getitem(index)._as_ptr()
     elif ((isinstance(A, lltype.FixedSizeArray)
            or (isinstance(A, lltype.Array) and A._hints.get('nolength',
                                                             False)))
           and array_item_type_match(A.OF, self.TYPE)):
         # for array of primitives or pointers
         return lltype.direct_ptradd(firstitemptr, self.repeat)
     else:
         raise TypeError('got %r, expected %r' % (A, self.TYPE))
Example #2
0
 def ref(self, firstitemptr):
     A = lltype.typeOf(firstitemptr).TO
     if A == self.TYPE:
         # for array of containers
         parent, index = lltype.parentlink(firstitemptr._obj)
         assert parent, "%r is not within a container" % (firstitemptr, )
         assert isinstance(
             lltype.typeOf(parent),
             (lltype.Array,
              lltype.FixedSizeArray)), ("%r is not within an array" %
                                        (firstitemptr, ))
         if isinstance(index, str):
             assert index.startswith('item')  # itemN => N
             index = int(index[4:])
         index += self.repeat
         if index == parent.getlength():
             # for references exactly to the end of the array
             try:
                 endmarker = _end_markers[parent]
             except KeyError:
                 endmarker = _endmarker_struct(A,
                                               parent=parent,
                                               parentindex=index)
                 _end_markers[parent] = endmarker
             return endmarker._as_ptr()
         else:
             return parent.getitem(index)._as_ptr()
     elif (
         (isinstance(A, lltype.FixedSizeArray) or
          (isinstance(A, lltype.Array) and A._hints.get('nolength', False)))
             and array_item_type_match(A.OF, self.TYPE)):
         # for array of primitives or pointers
         return lltype.direct_ptradd(firstitemptr, self.repeat)
     else:
         raise TypeError('got %r, expected %r' % (A, self.TYPE))
Example #3
0
def reccollect(constants, llvalue):
    if (isinstance(llvalue, lltype._abstract_ptr)
        and llvalue._obj is not None and llvalue._obj not in constants
        and not isinstance(llvalue._obj, int)):
        TYPE = llvalue._T
        constants[llvalue._obj] = True
        if isinstance(TYPE, lltype.Struct):
            for name in TYPE._names:
                reccollect(constants, getattr(llvalue, name))
        elif isinstance(TYPE, lltype.Array):
            for llitem in llvalue:
                reccollect(constants, llitem)
        parent, parentindex = lltype.parentlink(llvalue._obj)
        if parent is not None:
            reccollect(constants, parent._as_ptr())
Example #4
0
def reccollect(constants, llvalue):
    if (isinstance(llvalue, lltype._abstract_ptr) and llvalue._obj is not None
            and llvalue._obj not in constants
            and not isinstance(llvalue._obj, int)):
        TYPE = llvalue._T
        constants[llvalue._obj] = True
        if isinstance(TYPE, lltype.Struct):
            for name in TYPE._names:
                reccollect(constants, getattr(llvalue, name))
        elif isinstance(TYPE, lltype.Array):
            for llitem in llvalue:
                reccollect(constants, llitem)
        parent, parentindex = lltype.parentlink(llvalue._obj)
        if parent is not None:
            reccollect(constants, parent._as_ptr())
Example #5
0
 def __init__(self, db, T, obj):
     Node.__init__(self, db)
     self.obj = obj
     self.typename = db.gettype(T)  # , who_asks=self)
     self.implementationtypename = db.gettype(T, varlength=self.getvarlength())
     parent, parentindex = parentlink(obj)
     if obj in exports.EXPORTS_obj2name:
         self.name = exports.EXPORTS_obj2name[obj]
         self.globalcontainer = 2  # meh
     elif parent is None:
         self.name = db.namespace.uniquename("g_" + self.basename())
         self.globalcontainer = True
     else:
         self.globalcontainer = False
         parentnode = db.getcontainernode(parent)
         defnode = db.gettypedefnode(parentnode.getTYPE())
         self.name = defnode.access_expr(parentnode.name, parentindex)
     if self.typename != self.implementationtypename:
         if db.gettypedefnode(T).extra_union_for_varlength:
             self.name += ".b"
     self._funccodegen_owner = None
Example #6
0
 def __init__(self, db, T, obj):
     Node.__init__(self, db)
     self.obj = obj
     self.typename = db.gettype(T)  #, who_asks=self)
     self.implementationtypename = db.gettype(
         T, varlength=self.getvarlength())
     parent, parentindex = parentlink(obj)
     if obj in exports.EXPORTS_obj2name:
         self.name = exports.EXPORTS_obj2name[obj]
         self.globalcontainer = 2    # meh
     elif parent is None:
         self.name = db.namespace.uniquename('g_' + self.basename())
         self.globalcontainer = True
     else:
         self.globalcontainer = False
         parentnode = db.getcontainernode(parent)
         defnode = db.gettypedefnode(parentnode.getTYPE())
         self.name = defnode.access_expr(parentnode.name, parentindex)
     if self.typename != self.implementationtypename:
         if db.gettypedefnode(T).extra_union_for_varlength:
             self.name += '.b'
     self._funccodegen_owner = None