Maciej Fijalkowski committed 5696e15

weakref "support" in the JIT

Comments (0)

Files changed (4)


     rewrite_op_convert_float_bytes_to_longlong = _noop_rewrite
     rewrite_op_convert_longlong_bytes_to_float = _noop_rewrite
+    cast_ptr_to_weakrefptr = _noop_rewrite
+    cast_weakrefptr_to_ptr = _noop_rewrite
     # ----------
     # Various kinds of calls
                                                    resulttype, extra, extrakey)
         return SpaceOperation('direct_call', [c_func] + args, op.result)
     def _do_builtin_call(self, op, oopspec_name=None, args=None,
                          extra=None, extrakey=None):
         if oopspec_name is None: oopspec_name = op.opname
     rewrite_op_uint_mod        = _do_builtin_call
     rewrite_op_cast_float_to_uint = _do_builtin_call
     rewrite_op_cast_uint_to_float = _do_builtin_call
+    rewrite_op_weakref_create = _do_builtin_call
+    rewrite_op_weakref_deref = _do_builtin_call
     # ----------
     # getfield/setfield/mallocs etc.


 import sys
-from pypy.rpython.lltypesystem import lltype, rclass, rffi
+from pypy.rpython.lltypesystem import lltype, rclass, rffi, llmemory
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython import rlist
 from pypy.rpython.lltypesystem import rstr as ll_rstr, rdict as ll_rdict
-from pypy.rpython.lltypesystem import rlist as lltypesystem_rlist
 from pypy.rpython.lltypesystem.module import ll_math
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.ootypesystem import rdict as oo_rdict
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rpython.extregistry import ExtRegistryEntry
-from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
 from pypy.translator.simplify import get_funcobj
 from pypy.translator.unsimplify import split_block
 from pypy.objspace.flow.model import Constant
     build_ll_1_raw_free_no_track_allocation = (
+    def _ll_1_weakref_create(obj):
+        return llop.weakref_create(llmemory.WeakRefPtr, obj)
+    def _ll_1_weakref_deref(TP, obj):
+        return llop.weakref_deref(lltype.Ptr(TP), obj)
+    _ll_1_weakref_deref.need_result_type = True
 class OOtypeHelpers:


-import math
 import sys
 import py
-from pypy import conftest
-from pypy.jit.codewriter import longlong
-from pypy.jit.codewriter.policy import JitPolicy, StopAtXPolicy
-from pypy.jit.metainterp import pyjitpl, history
-from pypy.jit.metainterp.optimizeopt import ALL_OPTS_DICT
+from pypy.jit.codewriter.policy import StopAtXPolicy
+from pypy.jit.metainterp import history
 from import LLJitMixin, OOJitMixin, noConst
-from pypy.jit.metainterp.typesystem import LLTypeHelper, OOTypeHelper
 from pypy.jit.metainterp.warmspot import get_stats
 from pypy.rlib import rerased
 from pypy.rlib.jit import (JitDriver, we_are_jitted, hint, dont_look_inside,
     loop_invariant, elidable, promote, jit_debug, assert_green,
     AssertGreenFailed, unroll_safe, current_trace_length, look_inside_iff,
-    isconstant, isvirtual, promote_string, set_param, record_known_class)
+    isconstant, isvirtual, set_param, record_known_class)
 from pypy.rlib.longlong2float import float2longlong, longlong2float
 from pypy.rlib.rarithmetic import ovfcheck, is_valid_int
-from pypy.rpython.lltypesystem import lltype, llmemory, rffi
+from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rpython.ootypesystem import ootype
             return 42
         self.interp_operations(f, [1, 2, 3])
         self.check_operations_history(call=1, guard_no_exception=0)
+    def test_weakref(self):
+        import weakref
+        class A(object):
+            def __init__(self, x):
+                self.x = x
+        def f(i):
+            a = A(i)
+            w = weakref.ref(a)
+            return w().x + a.x
+        assert self.interp_operations(f, [3]) == 6


         return _ptr(Ptr(self._TYPE), self, True)
     def _as_obj(self, check=True):
         return self
-    def _normalizedcontainer(self):
+    def _normalizedcontainer(self, check=True):
         return self
     def _getid(self):
         return id(self)