예제 #1
0
    def setup_class(cls):
        if option.runappdirect:
            py.test.skip("Can't run this test with -A")
        space = gettestobjspace(usemodules=('pypyjit',))
        cls.space = space
        w_f = space.appexec([], """():
        def f():
            pass
        return f
        """)
        ll_code = cast_instance_to_base_ptr(w_f.code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2]
        i3 = int_add(i1, i2)
        guard_true(i3) []
        """, namespace={'ptr0': 3}).operations

        def interp_on_compile():
            pypyjitdriver.on_compile(logger, LoopToken(), oplist, 'loop',
                                     0, False, ll_code)

        def interp_on_compile_bridge():
            pypyjitdriver.on_compile_bridge(logger, LoopToken(), oplist, 0)
        
        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
예제 #2
0
 def f(x, y):
     if x > 20:
         a = None
     else:
         a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     return a1
예제 #3
0
 def f(x, y):
     if x > 20:
         a = None
     else:
         a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     return a1
예제 #4
0
파일: ll_thread.py 프로젝트: chyyuu/pygirl
def ll_start_new_thread(l_func, arg):
    l_arg = cast_instance_to_base_ptr(arg)
    l_arg = rffi.cast(rffi.VOIDP, l_arg)
    ident = c_thread_start(l_func, l_arg)
    if ident == -1:
        raise error("can't start new thread")
    return ident
예제 #5
0
    def setup_class(cls):
        if option.runappdirect:
            py.test.skip("Can't run this test with -A")
        space = gettestobjspace(usemodules=('pypyjit',))
        cls.space = space
        w_f = space.appexec([], """():
        def function():
            pass
        return function
        """)
        cls.w_f = w_f
        ll_code = cast_instance_to_base_ptr(w_f.code)
        code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2, p2]
        i3 = int_add(i1, i2)
        debug_merge_point(0, 0, 0, 0, 0, ConstPtr(ptr0))
        guard_nonnull(p2) []
        guard_true(i3) []
        """, namespace={'ptr0': code_gcref}).operations
        greenkey = [ConstInt(0), ConstInt(0), ConstPtr(code_gcref)]
        offset = {}
        for i, op in enumerate(oplist):
            if i != 1:
               offset[op] = i

        di_loop = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                               oplist, 'loop', greenkey)
        di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                        oplist, 'loop', greenkey)
        di_loop.asminfo = AsmInfo(offset, 0, 0)
        di_bridge = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                 oplist, 'bridge', fail_descr_no=0)
        di_bridge.asminfo = AsmInfo(offset, 0, 0)

        def interp_on_compile():
            di_loop.oplist = cls.oplist
            pypy_hooks.after_compile(di_loop)

        def interp_on_compile_bridge():
            pypy_hooks.after_compile_bridge(di_bridge)

        def interp_on_optimize():
            di_loop_optimize.oplist = cls.oplist
            pypy_hooks.before_compile(di_loop_optimize)

        def interp_on_abort():
            pypy_hooks.on_abort(ABORT_TOO_LONG, pypyjitdriver, greenkey,
                                'blah')

        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
        cls.w_on_abort = space.wrap(interp2app(interp_on_abort))
        cls.w_int_add_num = space.wrap(rop.INT_ADD)
        cls.w_dmp_num = space.wrap(rop.DEBUG_MERGE_POINT)
        cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize))
        cls.orig_oplist = oplist
예제 #6
0
 def f():
     s = T()
     ls = cast_instance_to_base_ptr(s)
     as_num = rffi.cast(lltype.Signed, ls)
     # --- around this point, only 'as_num' is passed
     t = rffi.cast(rclass.OBJECTPTR, as_num)
     u = cast_base_ptr_to_instance(S, t)
     return u.x
예제 #7
0
 def test_cast_instance_to_base_ptr(self):
     class X(object):
         pass
     x = X()
     ptr = annlowlevel.cast_instance_to_base_ptr(x)
     assert lltype.typeOf(ptr) == annlowlevel.base_ptr_lltype()
     y = annlowlevel.cast_base_ptr_to_instance(X, ptr)
     assert y is x
예제 #8
0
 def f(x, y):
     if x > 20:
         a = None
     else:
         a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     b = cast_base_ptr_to_instance(A, a1)
     return a is b
예제 #9
0
 def f(x, y):
     if x > 20:
         a = None
     else:
         a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     b = cast_base_ptr_to_instance(A, a1)
     return a is b
예제 #10
0
파일: llmodel.py 프로젝트: purepython/pypy
 def save_exception_memoryerr():
     from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
     save_exception()
     if not self.saved_exc_value:
         exc = MemoryError()
         exc = cast_instance_to_base_ptr(exc)
         exc = lltype.cast_opaque_ptr(llmemory.GCREF, exc)
         self.saved_exc_value = exc
예제 #11
0
 def f():
     s = T()
     ls = cast_instance_to_base_ptr(s)
     as_num = rffi.cast(lltype.Signed, ls)
     # --- around this point, only 'as_num' is passed
     t = rffi.cast(rclass.OBJECTPTR, as_num)
     u = cast_base_ptr_to_instance(S, t)
     return u.x
예제 #12
0
    def test_cast_instance_to_base_ptr(self):
        class X(object):
            pass

        x = X()
        ptr = annlowlevel.cast_instance_to_base_ptr(x)
        assert lltype.typeOf(ptr) == annlowlevel.base_ptr_lltype()
        y = annlowlevel.cast_base_ptr_to_instance(X, ptr)
        assert y is x
예제 #13
0
파일: jitexc.py 프로젝트: Debug-Orz/Sypy
def get_llexception(cpu, e):
    if we_are_translated():
        return cast_instance_to_base_ptr(e)
    assert not isinstance(e, JitException)
    if isinstance(e, LLException):
        return e.args[1]    # ok
    if isinstance(e, OverflowError):
        return _get_standard_error(cpu.rtyper, OverflowError)
    raise   # leave other exceptions to be propagated
예제 #14
0
파일: rgc.py 프로젝트: ieure/pypy
def cast_instance_to_gcref(x):
    # Before translation, casts an RPython instance into a _GcRef.
    # After translation, it is a variant of cast_object_to_ptr(GCREF).
    if we_are_translated():
        from pypy.rpython import annlowlevel
        x = annlowlevel.cast_instance_to_base_ptr(x)
        return lltype.cast_opaque_ptr(llmemory.GCREF, x)
    else:
        return _GcRef(x)
예제 #15
0
 def f(v0, v1):
     B(0)
     vinst = C(v0, v1)
     vobj = cast_instance_to_base_ptr(vinst)
     gptr(vobj)
     x = vinst.v0
     y = vinst.v1
     vinst.x
     return x + y + len(vinst.x)
예제 #16
0
def get_llexception(cpu, e):
    if we_are_translated():
        return cast_instance_to_base_ptr(e)
    assert not isinstance(e, JitException)
    if isinstance(e, LLException):
        return e.args[1]  # ok
    if isinstance(e, OverflowError):
        return _get_standard_error(cpu.rtyper, OverflowError)
    raise  # leave other exceptions to be propagated
 def f(v0, v1):
     B(0)
     vinst = C(v0, v1)
     vobj = cast_instance_to_base_ptr(vinst)
     gptr(vobj)
     x = vinst.v0
     y = vinst.v1
     vinst.x
     return x+y+len(vinst.x)
예제 #18
0
파일: rgc.py 프로젝트: purepython/pypy
def cast_instance_to_gcref(x):
    # Before translation, casts an RPython instance into a _GcRef.
    # After translation, it is a variant of cast_object_to_ptr(GCREF).
    if we_are_translated():
        from pypy.rpython import annlowlevel
        x = annlowlevel.cast_instance_to_base_ptr(x)
        return lltype.cast_opaque_ptr(llmemory.GCREF, x)
    else:
        return _GcRef(x)
예제 #19
0
 def f(n):
     s = S()
     s.x = n
     ls = cast_instance_to_base_ptr(s)
     as_num = rffi.cast(lltype.Signed, ls)
     # --- around this point, only 'as_num' is passed
     r = rffi.cast(llmemory.GCREF, as_num)
     t = lltype.cast_opaque_ptr(rclass.OBJECTPTR, r)
     u = cast_base_ptr_to_instance(S, t)
     return u.x
예제 #20
0
 def f(n):
     s = S()
     s.x = n
     ls = cast_instance_to_base_ptr(s)
     as_num = rffi.cast(lltype.Signed, ls)
     # --- around this point, only 'as_num' is passed
     r = rffi.cast(llmemory.GCREF, as_num)
     t = lltype.cast_opaque_ptr(rclass.OBJECTPTR, r)
     u = cast_base_ptr_to_instance(S, t)
     return u.x
예제 #21
0
 def prepare_for_residual_call(self, jitstate, gv_base, vable_rti):
     typedesc = self.typedesc
     assert isinstance(typedesc, VirtualizableStructTypeDesc)
     builder = jitstate.curbuilder
     gv_outside = self.content_boxes[-1].genvar
     base_desc = typedesc.base_desc
     base_token = base_desc.fieldtoken
     builder.genop_setfield(base_token, gv_outside, gv_base)
     vable_rti_ptr = cast_instance_to_base_ptr(vable_rti)
     gv_vable_rti = builder.rgenop.genconst(vable_rti_ptr)
     rti_token = typedesc.rti_desc.fieldtoken
     builder.genop_setfield(rti_token, gv_outside, gv_vable_rti)
     access_token = typedesc.access_desc.fieldtoken
     builder.genop_setfield(access_token, gv_outside, typedesc.gv_access)
예제 #22
0
 def prepare_for_residual_call(self, jitstate, gv_base, vable_rti):
     typedesc = self.typedesc
     assert isinstance(typedesc, VirtualizableStructTypeDesc)        
     builder = jitstate.curbuilder
     gv_outside = self.content_boxes[-1].genvar
     base_desc = typedesc.base_desc
     base_token = base_desc.fieldtoken
     builder.genop_setfield(base_token, gv_outside, gv_base)
     vable_rti_ptr = cast_instance_to_base_ptr(vable_rti)
     gv_vable_rti = builder.rgenop.genconst(vable_rti_ptr)
     rti_token = typedesc.rti_desc.fieldtoken
     builder.genop_setfield(rti_token, gv_outside, gv_vable_rti)
     access_token = typedesc.access_desc.fieldtoken
     builder.genop_setfield(access_token, gv_outside, typedesc.gv_access)
예제 #23
0
 def _add_pending_fields(self, pending_setfields):
     rd_pendingfields = lltype.nullptr(PENDINGFIELDSP.TO)
     if pending_setfields:
         n = len(pending_setfields)
         rd_pendingfields = lltype.malloc(PENDINGFIELDSP.TO, n)
         for i in range(n):
             descr, box, fieldbox, itemindex = pending_setfields[i]
             lldescr = annlowlevel.cast_instance_to_base_ptr(descr)
             num = self._gettagged(box)
             fieldnum = self._gettagged(fieldbox)
             # the index is limited to 2147483647 (64-bit machines only)
             if itemindex > 2147483647:
                 from pypy.jit.metainterp import compile
                 compile.giveup()
             itemindex = rffi.cast(rffi.INT, itemindex)
             #
             rd_pendingfields[i].lldescr  = lldescr
             rd_pendingfields[i].num      = num
             rd_pendingfields[i].fieldnum = fieldnum
             rd_pendingfields[i].itemindex= itemindex
     self.storage.rd_pendingfields = rd_pendingfields
예제 #24
0
 def f(v):
     vinst = V(v)
     vobj = cast_instance_to_base_ptr(vinst)
     gptr(vobj)
     vinst.v = 33
예제 #25
0
def _cast_to_gcref(obj):
    return lltype.cast_opaque_ptr(llmemory.GCREF,
                                  cast_instance_to_base_ptr(obj))
예제 #26
0
 def f(x, y):
     a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     return a1
예제 #27
0
 def g():
     e = OverflowError()
     lle = cast_instance_to_base_ptr(e)
     raise lle  # instead, must cast back from a base ptr to an instance
예제 #28
0
def _cast_to_gcref(obj):
    return lltype.cast_opaque_ptr(llmemory.GCREF,
                                  cast_instance_to_base_ptr(obj))
예제 #29
0
 def hide(self):
     ptr = cast_instance_to_base_ptr(self)
     return lltype.cast_opaque_ptr(llmemory.GCREF, ptr)
 def f(v):
     vinst = V(v)
     vobj = cast_instance_to_base_ptr(vinst)
     gptr(vobj)
     vinst.v = 33
 def f(v):
     vinst = V(v)
     vobj = cast_instance_to_base_ptr(vinst)
     gptr(vobj)
     x = vinst.v
     return x
예제 #32
0
 def f(v):
     vinst = V(v)
     vobj = cast_instance_to_base_ptr(vinst)
     gptr(vobj)
     x = vinst.v
     return x
예제 #33
0
 def f(x, y):
     a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     return a1
예제 #34
0
    def setup_class(cls):
        if option.runappdirect:
            py.test.skip("Can't run this test with -A")
        space = gettestobjspace(usemodules=('pypyjit', ))
        cls.space = space
        w_f = space.appexec([], """():
        def function():
            pass
        return function
        """)
        cls.w_f = w_f
        ll_code = cast_instance_to_base_ptr(w_f.code)
        code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2, p2]
        i3 = int_add(i1, i2)
        debug_merge_point(0, 0, 0, 0, ConstPtr(ptr0))
        guard_nonnull(p2) []
        guard_true(i3) []
        """,
                       namespace={
                           'ptr0': code_gcref
                       }).operations
        greenkey = [ConstInt(0), ConstInt(0), ConstPtr(code_gcref)]
        offset = {}
        for i, op in enumerate(oplist):
            if i != 1:
                offset[op] = i

        di_loop = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(), oplist,
                               'loop', greenkey)
        di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger,
                                        JitCellToken(), oplist, 'loop',
                                        greenkey)
        di_loop.asminfo = AsmInfo(offset, 0, 0)
        di_bridge = JitDebugInfo(MockJitDriverSD,
                                 logger,
                                 JitCellToken(),
                                 oplist,
                                 'bridge',
                                 fail_descr_no=0)
        di_bridge.asminfo = AsmInfo(offset, 0, 0)

        def interp_on_compile():
            di_loop.oplist = cls.oplist
            pypy_hooks.after_compile(di_loop)

        def interp_on_compile_bridge():
            pypy_hooks.after_compile_bridge(di_bridge)

        def interp_on_optimize():
            di_loop_optimize.oplist = cls.oplist
            pypy_hooks.before_compile(di_loop_optimize)

        def interp_on_abort():
            pypy_hooks.on_abort(ABORT_TOO_LONG, pypyjitdriver, greenkey,
                                'blah')

        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(
            interp2app(interp_on_compile_bridge))
        cls.w_on_abort = space.wrap(interp2app(interp_on_abort))
        cls.w_int_add_num = space.wrap(rop.INT_ADD)
        cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize))
        cls.orig_oplist = oplist