Author: Maciej Fijalkowski <fij...@gmail.com> Branch: missing-jit-operations Changeset: r59635:5696e15f0709 Date: 2012-12-31 13:14 +0200 http://bitbucket.org/pypy/pypy/changeset/5696e15f0709/
Log: weakref "support" in the JIT diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py --- a/pypy/jit/codewriter/jtransform.py +++ b/pypy/jit/codewriter/jtransform.py @@ -304,6 +304,8 @@ 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 @@ -450,6 +452,7 @@ 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 @@ -482,6 +485,8 @@ 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. diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py --- a/pypy/jit/codewriter/support.py +++ b/pypy/jit/codewriter/support.py @@ -1,15 +1,13 @@ 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 @@ -648,6 +646,12 @@ build_ll_1_raw_free_no_track_allocation = ( build_raw_free_builder(track_allocation=False)) + 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: diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -1,24 +1,19 @@ -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 pypy.jit.metainterp.test.support 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 @@ -3962,3 +3957,17 @@ 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 diff --git a/pypy/rpython/lltypesystem/lltype.py b/pypy/rpython/lltypesystem/lltype.py --- a/pypy/rpython/lltypesystem/lltype.py +++ b/pypy/rpython/lltypesystem/lltype.py @@ -1456,7 +1456,7 @@ 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) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit