Example #1
0
def wrap(cpu, value, in_const_box=False):
    if isinstance(lltype.typeOf(value), lltype.Ptr):
        if lltype.typeOf(value).TO._gckind == 'gc':
            value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
            if in_const_box:
                return history.ConstPtr(value)
            else:
                return history.BoxPtr(value)
        else:
            adr = llmemory.cast_ptr_to_adr(value)
            value = cpu.cast_adr_to_int(adr)
            # fall through to the end of the function
    elif isinstance(lltype.typeOf(value), ootype.OOType):
        value = ootype.cast_to_object(value)
        if in_const_box:
            return history.ConstObj(value)
        else:
            return history.BoxObj(value)
    elif isinstance(value, float):
        if in_const_box:
            return history.ConstFloat(value)
        else:
            return history.BoxFloat(value)
    else:
        value = intmask(value)
    if in_const_box:
        return history.ConstInt(value)
    else:
        return history.BoxInt(value)
Example #2
0
    def __init__(self, hrtyper, DICT):
        RGenOp = hrtyper.RGenOp
        rtyper = hrtyper.rtyper
        bk = rtyper.annotator.bookkeeper
        self.DICT = DICT
        self.DICTPTR = lltype.Ptr(DICT)
        self.ptrkind = RGenOp.kindToken(self.DICTPTR)

        argtypes = [bk.immutablevalue(DICT)]
        ll_newdict_ptr = rtyper.annotate_helper_fn(rdict.ll_newdict,
                                                   argtypes)
        self.gv_ll_newdict = RGenOp.constPrebuiltGlobal(ll_newdict_ptr)
        self.tok_ll_newdict = RGenOp.sigToken(lltype.typeOf(ll_newdict_ptr).TO)

        argtypes = [self.DICTPTR, DICT.KEY, DICT.VALUE, HASH]
        ll_insertclean = rtyper.annotate_helper_fn(rdict.ll_dict_insertclean,
                                                    argtypes)
        self.gv_ll_insertclean = RGenOp.constPrebuiltGlobal(ll_insertclean)
        self.tok_ll_insertclean = RGenOp.sigToken(
            lltype.typeOf(ll_insertclean).TO)

        # XXX some fishing that only works if the DICT does not come from
        # an r_dict
        if DICT.keyeq is None:
            keyeq = operator.eq
        else:
            assert isinstance(DICT.keyeq, lltype.staticAdtMethod)
            keyeq = DICT.keyeq.__get__(42)
        assert isinstance(DICT.keyhash, lltype.staticAdtMethod)
        keyhash = DICT.keyhash.__get__(42)
        keydesc = LLEqDesc(DICT.KEY, keyeq, keyhash)
        self.VirtualDict = keydesc.VirtualDict
Example #3
0
 def foo():
     # a bit hard to test, really
     a = llop.get_exception_addr(llmemory.Address)
     assert lltype.typeOf(a) is llmemory.Address
     a = llop.get_exc_value_addr(llmemory.Address)
     assert lltype.typeOf(a) is llmemory.Address
     return 42
Example #4
0
def generic_initializationexpr(db, value, access_expr, decoration):
    if isinstance(typeOf(value), ContainerType):
        node = db.getcontainernode(value)
        lines = list(node.initializationexpr(decoration + "."))
        lines[-1] += ","
        return lines
    else:
        comma = ","
        if typeOf(value) == Ptr(PyObject) and value:
            # cannot just write 'gxxx' as a constant in a structure :-(
            node = db.getcontainernode(value._obj)
            expr = "NULL /*%s*/" % node.name
            node.where_to_copy_me.append("&%s" % access_expr)
        elif typeOf(value) == Float and not isfinite(value):
            db.late_initializations.append(("%s" % access_expr, db.get(value)))
            expr = "0.0 /* patched later by %sinfinity */" % ("-+"[value > 0])
        else:
            expr = db.get(value)
            if typeOf(value) is Void:
                comma = ""
        expr += comma
        i = expr.find("\n")
        if i < 0:
            i = len(expr)
        expr = "%s\t/* %s */%s" % (expr[:i], decoration, expr[i:])
        return expr.split("\n")
Example #5
0
def wrap(cpu, value, in_const_box=False):
    if isinstance(lltype.typeOf(value), lltype.Ptr):
        if lltype.typeOf(value).TO._gckind == 'gc':
            value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
            if in_const_box:
                return history.ConstPtr(value)
            else:
                return history.BoxPtr(value)
        else:
            adr = llmemory.cast_ptr_to_adr(value)
            value = heaptracker.adr2int(adr)
            # fall through to the end of the function
    elif isinstance(lltype.typeOf(value), ootype.OOType):
        value = ootype.cast_to_object(value)
        if in_const_box:
            return history.ConstObj(value)
        else:
            return history.BoxObj(value)
    elif isinstance(value, float):
        value = longlong.getfloatstorage(value)
        if in_const_box:
            return history.ConstFloat(value)
        else:
            return history.BoxFloat(value)
    elif isinstance(value, str) or isinstance(value, unicode):
        assert len(value) == 1     # must be a character
        value = ord(value)
    else:
        value = intmask(value)
    if in_const_box:
        return history.ConstInt(value)
    else:
        return history.BoxInt(value)
Example #6
0
 def setinterior(self,
                 toplevelcontainer,
                 inneraddr,
                 INNERTYPE,
                 newvalue,
                 offsets=()):
     if (lltype.typeOf(toplevelcontainer).TO._gckind == 'gc'
             and isinstance(INNERTYPE, lltype.Ptr)
             and INNERTYPE.TO._gckind == 'gc'):
         #
         wb = True
         if self.has_write_barrier_from_array:
             for index in offsets:
                 if type(index) is not str:
                     assert (type(index) is int  # <- fast path
                             or lltype.typeOf(index) == lltype.Signed)
                     self.gc.write_barrier_from_array(
                         llmemory.cast_ptr_to_adr(newvalue),
                         llmemory.cast_ptr_to_adr(toplevelcontainer), index)
                     wb = False
                     break
         #
         if wb:
             self.gc.write_barrier(
                 llmemory.cast_ptr_to_adr(newvalue),
                 llmemory.cast_ptr_to_adr(toplevelcontainer))
     llheap.setinterior(toplevelcontainer, inneraddr, INNERTYPE, newvalue)
Example #7
0
def generic_initializationexpr(db, value, access_expr, decoration):
    if isinstance(typeOf(value), ContainerType):
        node = db.getcontainernode(value)
        lines = list(node.initializationexpr(decoration+'.'))
        lines[-1] += ','
        return lines
    else:
        comma = ','
        if typeOf(value) == Ptr(PyObject) and value:
            # cannot just write 'gxxx' as a constant in a structure :-(
            node = db.getcontainernode(value._obj)
            expr = 'NULL /*%s*/' % node.name
            node.where_to_copy_me.append('&%s' % access_expr)
        elif typeOf(value) == Float and (isinf(value) or isnan(value)):
            db.late_initializations.append(('%s' % access_expr, db.get(value)))
            expr = '0.0 /* patched later by %sinfinity */' % (
                '-+'[value > 0])
        else:
            expr = db.get(value)
            if typeOf(value) is Void:
                comma = ''
        expr += comma
        i = expr.find('\n')
        if i<0: i = len(expr)
        expr = '%s\t/* %s */%s' % (expr[:i], decoration, expr[i:])
        return expr.split('\n')
Example #8
0
File: rgc.py Project: ieure/pypy
def ll_arraycopy(source, dest, source_start, dest_start, length):
    from pypy.rpython.lltypesystem.lloperation import llop
    from pypy.rlib.objectmodel import keepalive_until_here

    # supports non-overlapping copies only
    if not we_are_translated():
        if source == dest:
            assert (source_start + length <= dest_start or
                    dest_start + length <= source_start)

    TP = lltype.typeOf(source).TO
    assert TP == lltype.typeOf(dest).TO
    if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
        # perform a write barrier that copies necessary flags from
        # source to dest
        if not llop.gc_writebarrier_before_copy(lltype.Bool, source, dest):
            # if the write barrier is not supported, copy by hand
            for i in range(length):
                dest[i + dest_start] = source[i + source_start]
            return
    source_addr = llmemory.cast_ptr_to_adr(source)
    dest_addr   = llmemory.cast_ptr_to_adr(dest)
    cp_source_addr = (source_addr + llmemory.itemoffsetof(TP, 0) +
                      llmemory.sizeof(TP.OF) * source_start)
    cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP, 0) +
                    llmemory.sizeof(TP.OF) * dest_start)
    
    llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
                         llmemory.sizeof(TP.OF) * length)
    keepalive_until_here(source)
    keepalive_until_here(dest)
Example #9
0
    def setup(self):
        for value in self._getvalues():
            self.db.prepare_constant(lltype.typeOf(value), value)

        p, c = lltype.parentlink(self.value)
        if p is not None:
            self.db.prepare_constant(lltype.typeOf(p), p)
 def finish_rtype(self):
     rtyper = self.rtyper
     translator = rtyper.annotator.translator
     original_graph_count = len(translator.graphs)
     rtyper.type_system.perform_normalizations(rtyper)
     for r in self.delayedreprs:
         r.set_setup_delayed(False)
     rtyper.call_all_setups()
     for p, repr, obj in self.delayedconsts:
         p._become(repr.convert_const(obj))
     rtyper.call_all_setups()
     for p, graph in self.delayedfuncs:
         self.newgraphs[graph] = True
         real_p = rtyper.getcallable(graph)
         REAL = get_functype(lltype.typeOf(real_p))
         FUNCTYPE = get_functype(lltype.typeOf(p))
         if isinstance(FUNCTYPE, (lltype.ForwardReference, ootype.ForwardReference)):
             FUNCTYPE.become(REAL)
         assert FUNCTYPE == REAL
         p._become(real_p)
     rtyper.specialize_more_blocks()
     self.delayedreprs.clear()
     del self.delayedconsts[:]
     del self.delayedfuncs[:]
     for graph in translator.graphs[original_graph_count:]:
         self.newgraphs[graph] = True
Example #11
0
    def enum_content(self, o, name='', with_header=True):
        # XXX clean up
        T = lltype.typeOf(o)
        if (self.size_gc_header is not None and with_header
            and isinstance(T, lltype.ContainerType) and T._gckind == 'gc'):
            adr = llmemory.cast_ptr_to_adr(o._as_ptr())
            adr -= self.size_gc_header
            o = adr.get()._obj
            T = lltype.typeOf(o)
        if isinstance(T, lltype.Struct):
            try:
                gcobjptr = header2obj[o]
                fmt = '(%s)'
            except KeyError:
                gcobjptr = None
                fmt = '%s'
            for name in T._names:
                for name, value in self.enum_content(getattr(o, name), name,
                                                     with_header=False):
                    yield fmt % (name,), value
            if gcobjptr:
                GCT = lltype.typeOf(gcobjptr)
                if self.size_gc_header is not None:
                    for sub in self.enum_content(gcobjptr._obj,
                                                 with_header=False):
                        yield sub
                else:
                    # display as a link to avoid the same data showing up
                    # twice in the graph
                    yield 'header of', gcobjptr._obj
        elif isinstance(T, lltype.Array):
            for index, o1 in enumerate(o.items):
                for sub in self.enum_content(o1, str(index)):
                    yield sub
        elif isinstance(T, lltype.Ptr):
            if not o:
                yield name, 'null'
            else:
                yield name, self.normalize(lltype.normalizeptr(o)._obj)
        elif isinstance(T, lltype.OpaqueType) and hasattr(o, 'container'):
            T = lltype.typeOf(o.container)
            yield 'container', '<%s>' % (shorttypename(T),)
            for sub in self.enum_content(o.container, name, with_header=False):
                yield sub
        elif T == llmemory.Address:
            if not o:
                yield name, 'NULL'
            else:
                addrof = o.ref()
                T1 = lltype.typeOf(addrof)
                if (isinstance(T1, lltype.Ptr) and
                    isinstance(T1.TO, lltype.Struct) and
                    addrof._obj in header2obj):
                    yield name + ' @hdr', self.normalize(addrof._obj)
                else:
                    yield name + ' @', self.normalize(o.ptr._obj)
##                     if o.offset:
##                         yield '... offset', str(o.offset)
        else:
            yield name, str(o)
Example #12
0
 def _get_offset(self, cppinstance):
     if cppinstance:
         assert lltype.typeOf(cppinstance.cppclass.handle) == lltype.typeOf(self.scope.handle)
         offset = self.offset + capi.c_base_offset(cppinstance.cppclass, self.scope, cppinstance.get_rawobject(), 1)
     else:
         offset = self.offset
     return offset
Example #13
0
def op_gc_writebarrier_before_copy(source, dest):
    A = lltype.typeOf(source)
    assert A == lltype.typeOf(dest)
    assert isinstance(A.TO, lltype.GcArray)
    assert isinstance(A.TO.OF, lltype.Ptr)
    assert A.TO.OF.TO._gckind == 'gc'
    return True
Example #14
0
File: rpbc.py Project: ieure/pypy
 def dispatcher(self, shape, index, argtypes, resulttype):
     key = shape, index, tuple(argtypes), resulttype
     if key in self._dispatch_cache:
         return self._dispatch_cache[key]
     from pypy.translator.unsimplify import varoftype
     from pypy.objspace.flow.model import FunctionGraph, Link, Block, SpaceOperation
     inputargs = [varoftype(t) for t in [Char] + argtypes]
     startblock = Block(inputargs)
     startblock.exitswitch = inputargs[0]
     graph = FunctionGraph("dispatcher", startblock, varoftype(resulttype))
     row_of_graphs = self.callfamily.calltables[shape][index]
     links = []
     descs = list(self.s_pbc.descriptions)
     if self.s_pbc.can_be_None:
         descs.insert(0, None)
     for desc in descs:
         if desc is None:
             continue
         args_v = [varoftype(t) for t in argtypes]
         b = Block(args_v)
         llfn = self.rtyper.getcallable(row_of_graphs[desc])
         v_fn = inputconst(typeOf(llfn), llfn)
         v_result = varoftype(resulttype)
         b.operations.append(
             SpaceOperation("direct_call", [v_fn] + args_v, v_result))
         b.closeblock(Link([v_result], graph.returnblock))
         i = self.descriptions.index(desc)
         links.append(Link(inputargs[1:], b, chr(i)))
         links[-1].llexitcase = chr(i)
     startblock.closeblock(*links)
     self.rtyper.annotator.translator.graphs.append(graph)
     ll_ret = self.rtyper.type_system.getcallable(graph)
     #FTYPE = FuncType
     c_ret = self._dispatch_cache[key] = inputconst(typeOf(ll_ret), ll_ret)
     return c_ret
Example #15
0
def setup_externs(c_db, db):
    rtyper = db.translator.rtyper
    from pypy.translator.c.extfunc import predeclare_all

    # hacks to make predeclare_all work    
    decls = list(predeclare_all(c_db, rtyper))

    for c_name, obj in decls:
        if isinstance(obj, lltype.LowLevelType):
            db.prepare_type(obj)
        elif isinstance(obj, FunctionGraph):
            funcptr = rtyper.getcallable(obj)
            c = inputconst(lltype.typeOf(funcptr), funcptr)
            db.prepare_arg_value(c)
        elif isinstance(lltype.typeOf(obj), lltype.Ptr):
            db.prepare_constant(lltype.typeOf(obj), obj)
        elif type(c_name) is str and type(obj) is int:
            pass    #define c_name obj
        else:
            assert False, "unhandled predeclare %s %s %s" % (c_name, type(obj), obj)

    def annotatehelper(func, *argtypes):
        graph = db.translator.rtyper.annotate_helper(func, argtypes)
        fptr = rtyper.getcallable(graph)
        c = inputconst(lltype.typeOf(fptr), fptr)
        db.prepare_arg_value(c)
        decls.append(("ll_" + func.func_name, graph))
        return graph.name

    return decls
Example #16
0
File: rtyper.py Project: ieure/pypy
    def gendirectcall(self, ll_function, *args_v):
        rtyper = self.rtyper
        args_s = []
        newargs_v = []
        for v in args_v:
            if v.concretetype is Void:
                s_value = rtyper.binding(v, default=annmodel.s_None)
                if not s_value.is_constant():
                    raise TyperError("non-constant variable of type Void")
                if not isinstance(s_value, annmodel.SomePBC):
                    raise TyperError("non-PBC Void argument: %r", (s_value,))
                args_s.append(s_value)
            else:
                args_s.append(annmodel.lltype_to_annotation(v.concretetype))
            newargs_v.append(v)
        
        self.rtyper.call_all_setups()  # compute ForwardReferences now

        # hack for bound methods
        if hasattr(ll_function, 'im_func'):
            bk = rtyper.annotator.bookkeeper
            args_s.insert(0, bk.immutablevalue(ll_function.im_self))
            newargs_v.insert(0, inputconst(Void, ll_function.im_self))
            ll_function = ll_function.im_func

        graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s,
                                         rtyper.lowlevel_ann_policy)
        self.record_extra_call(graph)

        # build the 'direct_call' operation
        f = self.rtyper.getcallable(graph)
        c = inputconst(typeOf(f), f)
        fobj = self.rtyper.type_system_deref(f)
        return self.genop('direct_call', [c]+newargs_v,
                          resulttype = typeOf(fobj).RESULT)
Example #17
0
def reccopy(source, dest):
    # copy recursively a structure or array onto another.
    T = lltype.typeOf(source).TO
    assert T == lltype.typeOf(dest).TO
    if isinstance(T, (lltype.Array, lltype.FixedSizeArray)):
        assert source._obj.getlength() == dest._obj.getlength()
        ITEMTYPE = T.OF
        for i in range(source._obj.getlength()):
            if isinstance(ITEMTYPE, lltype.ContainerType):
                subsrc = source[i]
                subdst = dest[i]
                reccopy(subsrc, subdst)
            else:
                # this is a hack XXX de-hack this
                llvalue = source._obj.getitem(i, uninitialized_ok=True)
                dest._obj.setitem(i, llvalue)
    elif isinstance(T, lltype.Struct):
        for name in T._names:
            FIELDTYPE = getattr(T, name)
            if isinstance(FIELDTYPE, lltype.ContainerType):
                subsrc = getattr(source, name)
                subdst = getattr(dest,   name)
                reccopy(subsrc, subdst)
            else:
                # this is a hack XXX de-hack this
                llvalue = source._obj._getattr(name, uninitialized_ok=True)
                setattr(dest._obj, name, llvalue)
    else:
        raise TypeError(T)
Example #18
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) 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 #19
0
    def get(self, obj, funcgen=None):
        if isinstance(obj, CConstant):
            return obj.c_name  # without further checks
        T = typeOf(obj)
        if isinstance(T, Primitive) or T == GCREF:
            return PrimitiveName[T](obj, self)
        elif isinstance(T, Ptr):
            if (isinstance(T.TO, OpaqueType) and
                T.TO.hints.get('c_pointer_typedef') is not None):
                if obj._obj is not None:
                    value = rffi.cast(rffi.SSIZE_T, obj)
                    return '((%s) %s)' % (cdecl(self.gettype(T), ''),
                                          self.get(value))
            if obj:   # test if the ptr is non-NULL
                try:
                    container = obj._obj
                except lltype.DelayedPointer:
                    # hack hack hack
                    name = obj._obj0
                    assert name.startswith('delayed!')
                    n = len('delayed!')
                    if len(name) == n:
                        raise
                    if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
                        if obj in self.idelayedfunctionnames:
                            return self.idelayedfunctionnames[obj][0]
                        funcname = name[n:]
                        funcname = self.namespace.uniquename('g_'+funcname)
                        self.idelayedfunctionnames[obj] = funcname, obj
                    else:
                        funcname = None      # can't use the name of a
                                             # delayed non-function ptr
                    self.delayedfunctionptrs.append(obj)
                    return funcname
                    # /hack hack hack
                else:
                    # hack hack hack
                    if obj in self.idelayedfunctionnames:
                        # this used to be a delayed function,
                        # make sure we use the same name
                        forcename = self.idelayedfunctionnames[obj][0]
                        node = self.getcontainernode(container,
                                                     forcename=forcename)
                        assert node.getptrname() == forcename
                        return forcename
                    # /hack hack hack

                if isinstance(container, int):
                    # special case for tagged odd-valued pointers
                    return '((%s) %d)' % (cdecl(self.gettype(T), ''),
                                          obj._obj)
                node = self.getcontainernode(container)
                if node._funccodegen_owner is None:
                    node._funccodegen_owner = funcgen
                return node.getptrname()
            else:
                return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
        else:
            raise Exception("don't know about %r" % (obj,))
Example #20
0
    def __init__(self, db, value):
        assert isinstance(lltype.typeOf(value), lltype.Array)
        self.db = db
        self.value = value
        self.arraytype = lltype.typeOf(value).OF

        name = '' #str(value).split()[1]
        self.make_name(name)
Example #21
0
 def op_check_and_clear_exc(self):
     exc_data = self.llinterpreter.get_transformed_exc_data(self.graph)
     assert exc_data
     etype  = exc_data.exc_type
     evalue = exc_data.exc_value
     exc_data.exc_type  = lltype.typeOf(etype )._defl()
     exc_data.exc_value = lltype.typeOf(evalue)._defl()
     return bool(etype)
Example #22
0
 def __init__(self, db, value):
     assert isinstance(lltype.typeOf(value), lltype.Array)
     self.db = db
     self.value = value
     self.arraytype = lltype.typeOf(value).OF
     prefix = '%arrayinstance'
     name = '' #str(value).split()[1]
     self.ref = self.make_ref(prefix, name)
Example #23
0
    def setup(self):
        for value in self.db.gcpolicy.gcheader_initdata(self.value):
            self.db.prepare_constant(lltype.typeOf(value), value)
        for item in self.value.items:
            self.db.prepare_constant(self.arraytype, item)

        p, c = lltype.parentlink(self.value)
        if p is not None:
            self.db.prepare_constant(lltype.typeOf(p), p)
Example #24
0
def cast_weakrefptr_to_ptr(PTRTYPE, pwref):
    assert lltype.typeOf(pwref) == WeakRefPtr
    if pwref:
        assert isinstance(pwref._obj, _gctransformed_wref)
        if PTRTYPE is not None:
            assert PTRTYPE == lltype.typeOf(pwref._obj._ptr)
        return pwref._obj._ptr
    else:
        return lltype.nullptr(PTRTYPE.TO)
Example #25
0
 def __init__(self, adrvalue, cpu):
     "NOT_RPYTHON"
     assert not we_are_translated()
     if isinstance(lltype.typeOf(adrvalue), lltype.Ptr):
         adrvalue = llmemory.cast_ptr_to_adr(adrvalue)    # convenience
     else:
         assert lltype.typeOf(adrvalue) == llmemory.Address
     self.value = adrvalue
     self.cpu = cpu
Example #26
0
def setintfield(pdst, fieldname, value):
    """Maybe temporary: a helper to set an integer field into a structure,
    transparently casting between the various integer types.
    """
    STRUCT = lltype.typeOf(pdst).TO
    TSRC = lltype.typeOf(value)
    TDST = getattr(STRUCT, fieldname)
    assert isinstance(TSRC, lltype.Number)
    assert isinstance(TDST, lltype.Number)
    setattr(pdst, fieldname, cast(TDST, value))
Example #27
0
def _next_section(reader, *expected):
    bh = MyBlackholeInterp(map(lltype.typeOf, expected))
    reader.consume_one_section(bh)
    expected_i = [x for x in expected if lltype.typeOf(x) == lltype.Signed]
    expected_r = [x for x in expected if lltype.typeOf(x) == llmemory.GCREF]
    expected_f = [x for x in expected if lltype.typeOf(x) ==
                                                      longlong.FLOATSTORAGE]
    assert bh.written_i == expected_i
    assert bh.written_r == expected_r
    assert bh.written_f == expected_f
Example #28
0
 def op_oosend(self, message, inst, *args):
     checkinst(inst)
     assert isinstance(message, str)
     bm = getattr(inst, message)
     inst = bm.inst
     m = bm.meth
     args = m._checkargs(args, check_callable=False)
     if getattr(m, 'abstract', False):
         raise RuntimeError("calling abstract method %r" % (m,))
     return self.perform_call(m, (lltype.typeOf(inst),)+lltype.typeOf(m).ARGS, [inst]+args)
Example #29
0
def setparentstructure(container, chain):
    TP = lltype.typeOf(container)
    current = container
    for i, elem in enumerate(chain):
        if lltype.typeOf(elem[0]) == TP:
            chain = chain[i + 1:]
            break
    for elem in chain:
        current._setparentstructure(*elem)
        current = elem[0]
Example #30
0
def test_ptradd():
    data = "hello, world!"
    a = lltype.malloc(ARRAY_OF_CHAR, len(data), flavor='raw')
    for i in xrange(len(data)):
        a[i] = data[i]
    a2 = ptradd(a, 2)
    assert lltype.typeOf(a2) == lltype.typeOf(a) == lltype.Ptr(ARRAY_OF_CHAR)
    for i in xrange(len(data) - 2):
        assert a2[i] == a[i + 2]
    lltype.free(a, flavor='raw')