Exemplo n.º 1
0
def reraise(lle):
    if we_are_translated():
        e = cast_base_ptr_to_instance(Exception, lle)
        raise e
    else:
        etype = rclass.ll_type(lle)
        raise LLException(etype, lle)
Exemplo n.º 2
0
def do_force_quasi_immutable(cpu, p, mutatefielddescr):
    qmut_ref = cpu.bh_getfield_gc_r(p, mutatefielddescr)
    if qmut_ref:
        cpu.bh_setfield_gc_r(p, cpu.ts.NULLREF, mutatefielddescr)
        qmut_ptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, qmut_ref)
        qmut = cast_base_ptr_to_instance(QuasiImmut, qmut_ptr)
        qmut.invalidate()
Exemplo n.º 3
0
def do_force_quasi_immutable(cpu, p, mutatefielddescr):
    qmut_ref = cpu.bh_getfield_gc_r(p, mutatefielddescr)
    if qmut_ref:
        cpu.bh_setfield_gc_r(p, cpu.ts.NULLREF, mutatefielddescr)
        qmut_ptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, qmut_ref)
        qmut = cast_base_ptr_to_instance(QuasiImmut, qmut_ptr)
        qmut.invalidate()
Exemplo n.º 4
0
def reraise(lle):
    if we_are_translated():
        e = cast_base_ptr_to_instance(Exception, lle)
        raise e
    else:
        etype = rclass.ll_type(lle)
        raise LLException(etype, lle)
Exemplo n.º 5
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) == OBJECTPTR
     y = annlowlevel.cast_base_ptr_to_instance(X, ptr)
     assert y is x
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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) == OBJECTPTR
     y = annlowlevel.cast_base_ptr_to_instance(X, ptr)
     assert y is x
Exemplo n.º 9
0
 def get():
     if we_are_translated():
         from rpython.rtyper import rclass
         from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
         _threadlocalref_seeme(self)
         ptr = llop.threadlocalref_get(rclass.OBJECTPTR, offset)
         return cast_base_ptr_to_instance(Cls, ptr)
     else:
         return getattr(self.local, 'value', None)
Exemplo n.º 10
0
 def get():
     if we_are_translated():
         from rpython.rtyper import rclass
         from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
         _threadlocalref_seeme(self)
         ptr = llop.threadlocalref_get(rclass.OBJECTPTR, offset)
         return cast_base_ptr_to_instance(Cls, ptr)
     else:
         return getattr(self.local, 'value', None)
Exemplo n.º 11
0
def method_from_greenkey(space, jitdriver, greenkey):
    if greenkey is None:
        return space.w_nil
    jitdriver_name = jitdriver.name
    if jitdriver_name == jit_driver_name:
        ll_method = lltype.cast_opaque_ptr(lltype.Ptr(OBJECT), greenkey[2].getref_base())
        w_method = cast_base_ptr_to_instance(W_CompiledMethod, ll_method)
        return w_method
    else:
        return space.w_nil
Exemplo n.º 12
0
def method_from_greenkey(space, jitdriver, greenkey):
    if greenkey is None:
        return space.w_nil
    jitdriver_name = jitdriver.name
    if jitdriver_name == jit_driver_name:
        ll_method = lltype.cast_opaque_ptr(lltype.Ptr(OBJECT),
                                           greenkey[2].getref_base())
        w_method = cast_base_ptr_to_instance(W_CompiledMethod, ll_method)
        return w_method
    else:
        return space.w_nil
Exemplo n.º 13
0
 def next_dead(self):
     if we_are_translated():
         from rpython.rtyper.lltypesystem.lloperation import llop
         from rpython.rtyper.rclass import OBJECTPTR
         from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
         tag = FinalizerQueue._get_tag(self)
         ptr = llop.gc_fq_next_dead(OBJECTPTR, tag)
         return cast_base_ptr_to_instance(self.Class, ptr)
     try:
         return self._queue.popleft()
     except (AttributeError, IndexError):
         return None
Exemplo n.º 14
0
def wrap_greenkey(space, jitdriver, greenkey, greenkey_repr):
    if greenkey is None:
        return space.w_None
    jitdriver_name = jitdriver.name
    if jitdriver_name == "pypyjit":
        next_instr = greenkey[0].getint()
        is_being_profiled = greenkey[1].getint()
        ll_code = lltype.cast_opaque_ptr(lltype.Ptr(OBJECT), greenkey[2].getref_base())
        pycode = cast_base_ptr_to_instance(PyCode, ll_code)
        return space.newtuple([space.wrap(pycode), space.wrap(next_instr), space.newbool(bool(is_being_profiled))])
    else:
        return space.wrap(greenkey_repr)
Exemplo n.º 15
0
 def next_dead(self):
     if we_are_translated():
         from rpython.rtyper.lltypesystem.lloperation import llop
         from rpython.rtyper.rclass import OBJECTPTR
         from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
         tag = FinalizerQueue._get_tag(self)
         ptr = llop.gc_fq_next_dead(OBJECTPTR, tag)
         return cast_base_ptr_to_instance(self.Class, ptr)
     try:
         return self._queue.popleft()
     except (AttributeError, IndexError):
         return None
Exemplo n.º 16
0
def wrap_greenkey(space, jitdriver, greenkey, greenkey_repr):
    if greenkey is None:
        return space.w_None
    jitdriver_name = jitdriver.name
    if jitdriver_name == 'pypyjit':
        next_instr = greenkey[0].getint()
        is_being_profiled = greenkey[1].getint()
        ll_code = lltype.cast_opaque_ptr(lltype.Ptr(OBJECT),
                                         greenkey[2].getref_base())
        pycode = cast_base_ptr_to_instance(PyCode, ll_code)
        return space.newtuple([pycode, space.newint(next_instr),
                               space.newbool(bool(is_being_profiled))])
    else:
        return space.newtext(greenkey_repr)
Exemplo n.º 17
0
 def handle_jitexception(e):
     # XXX there are too many exceptions all around...
     while True:
         if isinstance(e, EnterJitAssembler):
             try:
                 return e.execute()
             except jitexc.JitException as e:
                 continue
         #
         if isinstance(e, jitexc.ContinueRunningNormally):
             args = ()
             for ARGTYPE, attrname, count in portalfunc_ARGS:
                 x = getattr(e, attrname)[count]
                 x = specialize_value(ARGTYPE, x)
                 args = args + (x,)
             try:
                 result = support.maybe_on_top_of_llinterp(rtyper,
                                                     portal_ptr)(*args)
             except jitexc.JitException as e:
                 continue
             if result_kind != 'void':
                 result = unspecialize_value(result)
             return result
         #
         if result_kind == 'void':
             if isinstance(e, jitexc.DoneWithThisFrameVoid):
                 return None
         if result_kind == 'int':
             if isinstance(e, jitexc.DoneWithThisFrameInt):
                 return e.result
         if result_kind == 'ref':
             if isinstance(e, jitexc.DoneWithThisFrameRef):
                 return e.result
         if result_kind == 'float':
             if isinstance(e, jitexc.DoneWithThisFrameFloat):
                 return e.result
         #
         if isinstance(e, jitexc.ExitFrameWithExceptionRef):
             value = ts.cast_to_baseclass(e.value)
             if not we_are_translated():
                 raise LLException(ts.get_typeptr(value), value)
             else:
                 value = cast_base_ptr_to_instance(Exception, value)
                 assert value is not None
                 raise value
         #
         raise AssertionError("all cases should have been handled")
Exemplo n.º 18
0
 def handle_jitexception(e):
     # XXX there are too many exceptions all around...
     while True:
         if isinstance(e, EnterJitAssembler):
             try:
                 return e.execute()
             except jitexc.JitException as e:
                 continue
         #
         if isinstance(e, jitexc.ContinueRunningNormally):
             args = ()
             for ARGTYPE, attrname, count in portalfunc_ARGS:
                 x = getattr(e, attrname)[count]
                 x = specialize_value(ARGTYPE, x)
                 args = args + (x, )
             try:
                 result = support.maybe_on_top_of_llinterp(
                     rtyper, portal_ptr)(*args)
             except jitexc.JitException as e:
                 continue
             if result_kind != 'void':
                 result = unspecialize_value(result)
             return result
         #
         if result_kind == 'void':
             if isinstance(e, jitexc.DoneWithThisFrameVoid):
                 return None
         if result_kind == 'int':
             if isinstance(e, jitexc.DoneWithThisFrameInt):
                 return e.result
         if result_kind == 'ref':
             if isinstance(e, jitexc.DoneWithThisFrameRef):
                 return e.result
         if result_kind == 'float':
             if isinstance(e, jitexc.DoneWithThisFrameFloat):
                 return e.result
         #
         if isinstance(e, jitexc.ExitFrameWithExceptionRef):
             value = ts.cast_to_baseclass(e.value)
             if not we_are_translated():
                 raise LLException(ts.get_typeptr(value), value)
             else:
                 value = cast_base_ptr_to_instance(Exception, value)
                 assert value is not None
                 raise value
         #
         raise AssertionError("all cases should have been handled")
Exemplo n.º 19
0
def try_cast_gcref_to_instance(Class, gcref):
    # Before translation, unwraps the RPython instance contained in a _GcRef.
    # After translation, it is a type-check performed by the GC.
    if we_are_translated():
        from rpython.rtyper.rclass import OBJECTPTR, ll_isinstance
        from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
        if _is_rpy_instance(gcref):
            objptr = lltype.cast_opaque_ptr(OBJECTPTR, gcref)
            if objptr.typeptr:  # may be NULL, e.g. in rdict's dummykeyobj
                clsptr = _get_llcls_from_cls(Class)
                if ll_isinstance(objptr, clsptr):
                    return cast_base_ptr_to_instance(Class, objptr)
        return None
    else:
        if isinstance(gcref._x, Class):
            return gcref._x
        return None
Exemplo n.º 20
0
Arquivo: rgc.py Projeto: Qointum/pypy
def try_cast_gcref_to_instance(Class, gcref):
    # Before translation, unwraps the RPython instance contained in a _GcRef.
    # After translation, it is a type-check performed by the GC.
    if we_are_translated():
        from rpython.rtyper.rclass import OBJECTPTR, ll_isinstance
        from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
        if _is_rpy_instance(gcref):
            objptr = lltype.cast_opaque_ptr(OBJECTPTR, gcref)
            if objptr.typeptr:   # may be NULL, e.g. in rdict's dummykeyobj
                clsptr = _get_llcls_from_cls(Class)
                if ll_isinstance(objptr, clsptr):
                    return cast_base_ptr_to_instance(Class, objptr)
        return None
    else:
        if isinstance(gcref._x, Class):
            return gcref._x
        return None
Exemplo n.º 21
0
 def execute_frame(frame, w_inputvalue=None, operr=None):
     # go through the asm trampoline ONLY if we are translated but not being JITted.
     #
     # If we are not translated, we obviously don't want to go through the
     # trampoline because there is no C function it can call.
     #
     # If we are being JITted, we want to skip the trampoline, else the JIT
     # cannot see throug it
     if we_are_translated() and not jit.we_are_jitted():
         # if we are translated, call the trampoline
         gc_frame = cast_instance_to_gcref(frame)
         gc_inputvalue = cast_instance_to_gcref(w_inputvalue)
         gc_operr = cast_instance_to_gcref(operr)
         unique_id = frame.pycode._unique_id
         gc_result = pypy_execute_frame_trampoline(gc_frame, gc_inputvalue,
                                                   gc_operr, unique_id)
         return cast_base_ptr_to_instance(W_Root, gc_result)
     else:
         return original_execute_frame(frame, w_inputvalue, operr)
 def execute_frame(frame, w_inputvalue=None, operr=None):
     # go through the asm trampoline ONLY if we are translated but not being JITted.
     #
     # If we are not translated, we obviously don't want to go through the
     # trampoline because there is no C function it can call.
     #
     # If we are being JITted, we want to skip the trampoline, else the JIT
     # cannot see throug it
     if we_are_translated() and not jit.we_are_jitted():
         # if we are translated, call the trampoline
         gc_frame = cast_instance_to_gcref(frame)
         gc_inputvalue = cast_instance_to_gcref(w_inputvalue)
         gc_operr = cast_instance_to_gcref(operr)
         unique_id = frame.pycode._unique_id
         gc_result = pypy_execute_frame_trampoline(gc_frame, gc_inputvalue,
                                                   gc_operr, unique_id)
         return cast_base_ptr_to_instance(W_Root, gc_result)
     else:
         return original_execute_frame(frame, w_inputvalue, operr)
Exemplo n.º 23
0
 def decorated_function(*args):
     # go through the asm trampoline ONLY if we are translated but not
     # being JITted.
     #
     # If we are not translated, we obviously don't want to go through
     # the trampoline because there is no C function it can call.
     #
     # If we are being JITted, we want to skip the trampoline, else the
     # JIT cannot see through it.
     #
     if we_are_translated() and not jit.we_are_jitted():
         # if we are translated, call the trampoline
         unique_id = get_code_fn(*args)._vmprof_unique_id
         ll_args, token = lower(*args)
         ll_trampoline = get_ll_trampoline(token)
         ll_result = ll_trampoline(*ll_args + (unique_id, ))
         if result_class is not None:
             return cast_base_ptr_to_instance(result_class, ll_result)
         else:
             return ll_result
     else:
         return func(*args)
Exemplo n.º 24
0
 def decorated_function(*args):
     # go through the asm trampoline ONLY if we are translated but not
     # being JITted.
     #
     # If we are not translated, we obviously don't want to go through
     # the trampoline because there is no C function it can call.
     #
     # If we are being JITted, we want to skip the trampoline, else the
     # JIT cannot see through it.
     #
     if we_are_translated() and not jit.we_are_jitted():
         # if we are translated, call the trampoline
         unique_id = get_code_fn(*args)._vmprof_unique_id
         ll_args, token = lower(*args)
         ll_trampoline = get_ll_trampoline(token)
         ll_result = ll_trampoline(*ll_args + (unique_id,))
         if result_class is not None:
             return cast_base_ptr_to_instance(result_class, ll_result)
         else:
             return ll_result
     else:
         return func(*args)
Exemplo n.º 25
0
 def get_jitcell(build, *greenargs):
     fn = support.maybe_on_top_of_llinterp(rtyper, get_jitcell_at_ptr)
     cellref = fn(*greenargs)
     # <hacks>
     if we_are_translated():
         BASEJITCELL = lltype.typeOf(cellref)
         cell = cast_base_ptr_to_instance(JitCell, cellref)
     else:
         if isinstance(cellref, (BaseJitCell, type(None))):
             BASEJITCELL = None
             cell = cellref
         else:
             BASEJITCELL = lltype.typeOf(cellref)
             if cellref:
                 cell = lltohlhack[rtyper.type_system.deref(cellref)]
             else:
                 cell = None
     if not build:
         return cell
     if cell is None:
         cell = JitCell()
         # <hacks>
         if we_are_translated():
             cellref = cast_object_to_ptr(BASEJITCELL, cell)
         else:
             if BASEJITCELL is None:
                 cellref = cell
             else:
                 if isinstance(BASEJITCELL, lltype.Ptr):
                     cellref = lltype.malloc(BASEJITCELL.TO)
                 else:
                     assert False, "no clue"
                 lltohlhack[rtyper.type_system.deref(cellref)] = cell
         # </hacks>
         fn = support.maybe_on_top_of_llinterp(rtyper,
                                               set_jitcell_at_ptr)
         fn(cellref, *greenargs)
     return cell
Exemplo n.º 26
0
def _cast_to_resop(llref):
    from rpython.jit.metainterp.resoperation import AbstractResOp

    ptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, llref)
    return cast_base_ptr_to_instance(AbstractResOp, ptr)
Exemplo n.º 27
0
 def show(cpu, descr_gcref):
     from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
     descr_ptr = cpu.ts.cast_to_baseclass(descr_gcref)
     return cast_base_ptr_to_instance(AbstractDescr, descr_ptr)
Exemplo n.º 28
0
 def show(cpu, qmut_gcref):
     qmut_ptr = cpu.ts.cast_to_baseclass(qmut_gcref)
     return cast_base_ptr_to_instance(QuasiImmut, qmut_ptr)
Exemplo n.º 29
0
def _cast_to_box(llref):
    from rpython.jit.metainterp.history import AbstractValue

    ptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, llref)
    return cast_base_ptr_to_instance(AbstractValue, ptr)
Exemplo n.º 30
0
 def _invalidate_now(p):
     qmut_ptr = getattr(p, mutatefieldname)
     setattr(p, mutatefieldname, lltype.nullptr(rclass.OBJECT))
     qmut = cast_base_ptr_to_instance(QuasiImmut, qmut_ptr)
     qmut.invalidate()
Exemplo n.º 31
0
 def _invalidate_now(p):
     qmut_ptr = getattr(p, mutatefieldname)
     setattr(p, mutatefieldname, lltype.nullptr(rclass.OBJECT))
     qmut = cast_base_ptr_to_instance(QuasiImmut, qmut_ptr)
     qmut.invalidate(descr_repr)
Exemplo n.º 32
0
 def get_location_str(boxes):
     ll_code = lltype.cast_opaque_ptr(lltype.Ptr(OBJECT),
                                      boxes[2].getref_base())
     pycode = cast_base_ptr_to_instance(PyCode, ll_code)
     return pycode.co_name
Exemplo n.º 33
0
 def get_exception_obj(self, evaluebox):
     # only works when translated
     obj = evaluebox.getref(lltype.Ptr(rclass.OBJECT))
     return cast_base_ptr_to_instance(Exception, obj)
Exemplo n.º 34
0
                    return
                except jitexc.DoneWithThisFrameInt, e:
                    assert result_kind == 'int'
                    return specialize_value(RESULT, e.result)
                except jitexc.DoneWithThisFrameRef, e:
                    assert result_kind == 'ref'
                    return specialize_value(RESULT, e.result)
                except jitexc.DoneWithThisFrameFloat, e:
                    assert result_kind == 'float'
                    return specialize_value(RESULT, e.result)
                except jitexc.ExitFrameWithExceptionRef, e:
                    value = ts.cast_to_baseclass(e.value)
                    if not we_are_translated():
                        raise LLException(ts.get_typeptr(value), value)
                    else:
                        value = cast_base_ptr_to_instance(Exception, value)
                        raise Exception, value

        def handle_jitexception(e):
            # XXX the bulk of this function is mostly a copy-paste from above
            try:
                raise e
            except jitexc.ContinueRunningNormally, e:
                args = ()
                for ARGTYPE, attrname, count in portalfunc_ARGS:
                    x = getattr(e, attrname)[count]
                    x = specialize_value(ARGTYPE, x)
                    args = args + (x, )
                result = ll_portal_runner(*args)
                if result_kind != 'void':
                    result = unspecialize_value(result)
Exemplo n.º 35
0
                    return
                except jitexc.DoneWithThisFrameInt, e:
                    assert result_kind == 'int'
                    return specialize_value(RESULT, e.result)
                except jitexc.DoneWithThisFrameRef, e:
                    assert result_kind == 'ref'
                    return specialize_value(RESULT, e.result)
                except jitexc.DoneWithThisFrameFloat, e:
                    assert result_kind == 'float'
                    return specialize_value(RESULT, e.result)
                except jitexc.ExitFrameWithExceptionRef, e:
                    value = ts.cast_to_baseclass(e.value)
                    if not we_are_translated():
                        raise LLException(ts.get_typeptr(value), value)
                    else:
                        value = cast_base_ptr_to_instance(Exception, value)
                        raise Exception, value

        def handle_jitexception(e):
            # XXX the bulk of this function is mostly a copy-paste from above
            try:
                raise e
            except jitexc.ContinueRunningNormally, e:
                args = ()
                for ARGTYPE, attrname, count in portalfunc_ARGS:
                    x = getattr(e, attrname)[count]
                    x = specialize_value(ARGTYPE, x)
                    args = args + (x,)
                result = ll_portal_runner(*args)
                if result_kind != 'void':
                    result = unspecialize_value(result)
Exemplo n.º 36
0
 def show(cpu, gcref):
     from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
     ptr = cpu.ts.cast_to_baseclass(gcref)
     return cast_base_ptr_to_instance(AllVirtuals, ptr)
Exemplo n.º 37
0
 def show(cpu, qmut_gcref):
     qmut_ptr = cpu.ts.cast_to_baseclass(qmut_gcref)
     return cast_base_ptr_to_instance(QuasiImmut, qmut_ptr)
Exemplo n.º 38
0
def _cast_to_resop(llref):
    from rpython.jit.metainterp.resoperation import AbstractResOp

    ptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, llref)
    return cast_base_ptr_to_instance(AbstractResOp, ptr)
Exemplo n.º 39
0
 def show(cpu, gcref):
     from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
     ptr = cpu.ts.cast_to_baseclass(gcref)
     return cast_base_ptr_to_instance(AllVirtuals, ptr)
Exemplo n.º 40
0
 def show(cpu, descr_gcref):
     from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
     descr_ptr = cpu.ts.cast_to_baseclass(descr_gcref)
     return cast_base_ptr_to_instance(AbstractDescr, descr_ptr)
Exemplo n.º 41
0
def _cast_to_box(llref):
    from rpython.jit.metainterp.history import AbstractValue

    ptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, llref)
    return cast_base_ptr_to_instance(AbstractValue, ptr)
Exemplo n.º 42
0
 def get_location_str(boxes):
     ll_code = lltype.cast_opaque_ptr(lltype.Ptr(OBJECT),
                                      boxes[2].getref_base())
     pycode = cast_base_ptr_to_instance(PyCode, ll_code)
     return pycode.co_name