[pypy-svn] commit/pypy: 3 new changesets

Bitbucket commits-noreply at bitbucket.org
Mon Dec 20 13:20:40 CET 2010


3 new changesets in pypy:

http://bitbucket.org/pypy/pypy/changeset/8d6652c4c2a5/
changeset:   r40141:8d6652c4c2a5
branch:      jit-tagged
user:        arigo
date:        2010-12-20 10:05:16
summary:     Fix this file, which is not fully tested and not really used any more.
(Fix it anyway to prevent source code rotting.)
affected #:  2 files (636 bytes)

--- a/pypy/objspace/std/smallintobject.py	Sun Dec 19 17:36:20 2010 +0100
+++ b/pypy/objspace/std/smallintobject.py	Mon Dec 20 10:05:16 2010 +0100
@@ -5,7 +5,6 @@
 from pypy.objspace.std import intobject
 from pypy.objspace.std.model import registerimplementation, W_Object
 from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.noneobject import W_NoneObject
 from pypy.objspace.std.intobject import W_IntObject
 from pypy.rlib.objectmodel import UnboxedValue
 from pypy.tool.sourcetools import func_with_new_name
@@ -40,11 +39,22 @@
         if "__Int" in name:
             new_name = name.replace("Int", "SmallInt")
             # Copy the function, so the annotator specializes it for
-            # W_SmallIntObject.
-            ns[new_name] = func_with_new_name(func, new_name)
+            # W_SmallIntObject.  Also replaces the func_globals with ns.
+            # The effect we get is as if the source code of the function
+            # was copied in smallintobject.py.
+            ns[new_name] = func_with_new_name(func, new_name, globals=ns)
     ns["get_integer"] = ns["pos__SmallInt"] = ns["int__SmallInt"]
     ns["get_negint"] = ns["neg__SmallInt"]
 
 copy_multimethods(globals())
 
+# extra imports needed because we switch the func_globals above
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.multimethod import FailedToImplementArgs
+from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT, r_uint
+from pypy.objspace.std.inttype import wrapint
+from pypy.objspace.std.intobject import _impl_int_int_pow
+from pypy.objspace.std.noneobject import W_NoneObject
+from pypy.rlib.rbigint import rbigint
+
 register_all(vars())


--- a/pypy/tool/sourcetools.py	Sun Dec 19 17:36:20 2010 +0100
+++ b/pypy/tool/sourcetools.py	Mon Dec 20 10:05:16 2010 +0100
@@ -216,9 +216,11 @@
 
 # ____________________________________________________________
 
-def func_with_new_name(func, newname):
+def func_with_new_name(func, newname, globals=None):
     """Make a renamed copy of a function."""
-    f = new.function(func.func_code, func.func_globals,
+    if globals is None:
+        globals = func.func_globals
+    f = new.function(func.func_code, globals,
                         newname, func.func_defaults,
                         func.func_closure)
     if func.func_dict:


http://bitbucket.org/pypy/pypy/changeset/b02753f75fa8/
changeset:   r40142:b02753f75fa8
branch:      jit-tagged
user:        arigo
date:        2010-12-20 10:06:45
summary:     For use of erasing by the JIT, we need at least one oopspec,
because is_integer(x) should not force x if it is a virtual.
affected #:  3 files (230 bytes)

--- a/pypy/rlib/rerased.py	Mon Dec 20 10:05:16 2010 +0100
+++ b/pypy/rlib/rerased.py	Mon Dec 20 10:06:45 2010 +0100
@@ -18,7 +18,8 @@
 def erase(x):
     """Creates an 'erased' object that contains a reference to 'x'. Nothing can
     be done with this object, except calling unerase(y, <type>) on it.
-    x needs to be either an instance or an integer fitting into 31/63 bits."""
+    x needs to be either an instance or an integer (in the latter case,
+    you get reliably an OverflowError if it doesn't fit into 31/63 bits)."""
     if isinstance(x, int):
         res = 2 * x + 1
         if res > sys.maxint or res < -sys.maxint - 1:
@@ -50,6 +51,7 @@
 def is_integer(e):
     """Gives information whether the erased argument is a tagged integer or not."""
     return isinstance(e._x, int)
+is_integer.oopspec = 'rerased.is_integer(e)'
 
 
 # ---------- implementation-specific ----------


--- a/pypy/rlib/test/test_rerased.py	Mon Dec 20 10:05:16 2010 +0100
+++ b/pypy/rlib/test/test_rerased.py	Mon Dec 20 10:06:45 2010 +0100
@@ -118,13 +118,13 @@
         try:
             e = erase(i)
         except OverflowError:
-            return -1
+            return -42
         assert is_integer(e)
         return unerase(e, int)
     x = interpret(f, [16])
     assert x == 16
     x = interpret(f, [sys.maxint])
-    assert x == -1
+    assert x == -42
 
 def test_none():
     def foo():


--- a/pypy/rpython/lltypesystem/rtagged.py	Mon Dec 20 10:05:16 2010 +0100
+++ b/pypy/rpython/lltypesystem/rtagged.py	Mon Dec 20 10:06:45 2010 +0100
@@ -141,6 +141,9 @@
         return hop.gendirectcall(ll_unboxed_isinstance_const, v_obj,
                                  minid, maxid, c_answer_if_unboxed)
 
+def ll_is_integer(instance):
+    return (lltype.cast_ptr_to_int(instance) & 1) != 0
+ll_is_integer.oopspec = 'rerased.is_integer(instance)'
 
 def ll_int_to_unboxed(PTRTYPE, value):
     return lltype.cast_int_to_ptr(PTRTYPE, value*2+1)
@@ -154,14 +157,14 @@
     return lltype.nullptr(lltype.typeOf(instance).TO.typeptr.TO)
 
 def ll_unboxed_getclass(instance, class_if_unboxed):
-    if lltype.cast_ptr_to_int(instance) & 1:
+    if ll_is_integer(instance):
         return class_if_unboxed
     return instance.typeptr
 
 def ll_unboxed_isinstance_const(obj, minid, maxid, answer_if_unboxed):
     if not obj:
         return False
-    if lltype.cast_ptr_to_int(obj) & 1:
+    if ll_is_integer(obj):
         return answer_if_unboxed
     else:
         return ll_issubclass_const(obj.typeptr, minid, maxid)


http://bitbucket.org/pypy/pypy/changeset/805e5d981821/
changeset:   r40143:805e5d981821
branch:      jit-tagged
user:        arigo
date:        2010-12-20 10:36:09
summary:     In progress.
affected #:  6 files (1.6 KB)

--- a/pypy/jit/codewriter/support.py	Mon Dec 20 10:06:45 2010 +0100
+++ b/pypy/jit/codewriter/support.py	Mon Dec 20 10:36:09 2010 +0100
@@ -174,6 +174,10 @@
 def _ll_1_jit_force_virtual(inst):
     return llop.jit_force_virtual(lltype.typeOf(inst), inst)
 
+def _ll_1_rerased_is_integer(inst):
+    from pypy.rlib import rerased
+    return rerased.is_integer(inst)
+
 
 def _ll_2_int_floordiv_ovf_zer(x, y):
     if y == 0:


--- a/pypy/jit/metainterp/blackhole.py	Mon Dec 20 10:06:45 2010 +0100
+++ b/pypy/jit/metainterp/blackhole.py	Mon Dec 20 10:36:09 2010 +0100
@@ -866,6 +866,14 @@
         pass
 
     # ----------
+    # tagged pointers
+
+    @arguments("r", returns="i")
+    def bhimpl_rerased_is_integer(a):
+        from pypy.rlib.rerased import is_integer
+        return is_integer(a)
+
+    # ----------
     # list operations
 
     @arguments("cpu", "r", "d", "i", returns="i")


--- a/pypy/jit/metainterp/resoperation.py	Mon Dec 20 10:06:45 2010 +0100
+++ b/pypy/jit/metainterp/resoperation.py	Mon Dec 20 10:36:09 2010 +0100
@@ -440,6 +440,7 @@
     'GETARRAYITEM_GC_PURE/2d',
     'UNICODELEN/1',
     'UNICODEGETITEM/2',
+    'RERASED_IS_INTEGER/1',
     #
     # ootype operations
     #'INSTANCEOF/1db',


--- a/pypy/jit/metainterp/simple_optimize.py	Mon Dec 20 10:06:45 2010 +0100
+++ b/pypy/jit/metainterp/simple_optimize.py	Mon Dec 20 10:36:09 2010 +0100
@@ -20,6 +20,9 @@
         op = ResOperation(rop.SAME_AS, [op.getarg(0)], op.result)
     elif op.getopnum() == rop.VIRTUAL_REF_FINISH:
         return []
+    elif op.getopnum() == rop.RERASED_IS_INTEGER:
+        xxx
+        return []
     return [op]
 
 def optimize_loop(metainterp_sd, old_loops, loop):


--- a/pypy/jit/metainterp/test/test_basic.py	Mon Dec 20 10:06:45 2010 +0100
+++ b/pypy/jit/metainterp/test/test_basic.py	Mon Dec 20 10:36:09 2010 +0100
@@ -1885,5 +1885,36 @@
 
         self.meta_interp(main, [])
 
+    def test_rerased_is_integer(self):
+        from pypy.rlib import rerased
+        driver = JitDriver(greens = [], reds = ['n', 'm'])
+        class X:
+            pass
+        def g(n):
+            if n > 5:
+                return rerased.erase(X())
+            else:
+                return rerased.erase(42)
+        def h(x):
+            return rerased.is_integer(x)
+        def f(n, m):
+            while True:
+                driver.jit_merge_point(n=n, m=m)
+                x = g(n)
+                res = h(x)
+                m -= 1
+                if m < 0:
+                    return res
+
+        res = self.meta_interp(f, [10, 10], optimizer=OPTIMIZER_SIMPLE)
+        assert res == False
+        res = self.meta_interp(f, [3, 10], optimizer=OPTIMIZER_SIMPLE)
+        assert res == True
+
+        res = self.meta_interp(f, [10, 10])
+        assert res == False
+        self.check_loops(new_with_vtable=0)
+
+
 class TestLLtype(BaseLLtypeTests, LLJitMixin):
     pass


--- a/pypy/rlib/rerased.py	Mon Dec 20 10:06:45 2010 +0100
+++ b/pypy/rlib/rerased.py	Mon Dec 20 10:36:09 2010 +0100
@@ -5,6 +5,7 @@
 import sys
 from pypy.annotation import model as annmodel
 from pypy.tool.pairtype import pairtype
+from pypy.rlib.objectmodel import we_are_translated
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.rpython.rclass import getinstancerepr
 from pypy.rpython.rmodel import Repr
@@ -48,10 +49,14 @@
         assert isinstance(y._x[0], type)
     return y._x
 
-def is_integer(e):
+def ll_is_integer(e):
     """Gives information whether the erased argument is a tagged integer or not."""
-    return isinstance(e._x, int)
-is_integer.oopspec = 'rerased.is_integer(e)'
+    if we_are_translated():
+        return (llop.cast_ptr_to_int(lltype.Signed, e) & 1) != 0
+    else:
+        return isinstance(e._x, int)
+ll_is_integer.oopspec = 'rerased.is_integer(e)'
+is_integer = ll_is_integer
 
 
 # ---------- implementation-specific ----------
@@ -118,21 +123,6 @@
         v, t = hop.inputargs(hop.args_r[0], lltype.Void)
         return hop.genop('cast_opaque_ptr', [v], resulttype = hop.r_result)
 
-
-class Entry(ExtRegistryEntry):
-    _about_ = is_integer
-
-    def compute_result_annotation(self, s_obj):
-        return annmodel.SomeBool()
-
-    def specialize_call(self, hop):
-        v, = hop.inputargs(hop.args_r[0])
-        c_one = hop.inputconst(lltype.Signed, 1)
-        vi = hop.genop('cast_ptr_to_int', [v], resulttype=lltype.Signed)
-        vb = hop.genop('int_and', [vi, c_one], resulttype=lltype.Signed)
-        return hop.genop('int_is_true', [vb], resulttype=lltype.Bool)
-
-
 class Entry(ExtRegistryEntry):
     _type_ = Erased

Repository URL: https://bitbucket.org/pypy/pypy/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the Pypy-commit mailing list