[pypy-commit] pypy cleanup-llgraph-backend: Whack whack whack. Also start to remove the forever-skipped OO tests.

arigo noreply at buildbot.pypy.org
Wed Oct 17 16:05:44 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: cleanup-llgraph-backend
Changeset: r58171:39f1ae8df9a4
Date: 2012-10-17 16:01 +0200
http://bitbucket.org/pypy/pypy/changeset/39f1ae8df9a4/

Log:	Whack whack whack. Also start to remove the forever-skipped OO
	tests.

diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py
--- a/pypy/jit/backend/llgraph/runner.py
+++ b/pypy/jit/backend/llgraph/runner.py
@@ -44,12 +44,20 @@
         self.RESULT = RESULT
         self.ARGS = ARGS
         self.extrainfo = extrainfo
-    def get_extra_info(self):
-        return self.extrainfo
+
     def __repr__(self):
         return 'CallDescr(%r, %r, %r)' % (self.RESULT, self.ARGS,
                                           self.extrainfo)
 
+    def get_extra_info(self):
+        return self.extrainfo
+
+    def get_arg_types(self):
+        return ''.join([getkind(ARG)[0] for ARG in self.ARGS])
+
+    def get_result_type(self):
+        return getkind(self.RESULT)[0]
+
 class SizeDescr(AbstractDescr):
     def __init__(self, S):
         self.S = S
@@ -289,29 +297,18 @@
 
     # ------------------------------------------------------------
 
-    def call(self, func, args, RESULT, calldescr):
-        try:
-            res = func(*args)
-            self.last_exception = None
-        except LLException, lle:
-            self.last_exception = lle
-            d = {'void': None,
-                 'ref': lltype.nullptr(llmemory.GCREF.TO),
-                 'int': 0,
-                 'float': 0.0}
-            res = d[getkind(RESULT)]
+    def maybe_on_top_of_llinterp(self, func, args, RESULT):
+        ptr = llmemory.cast_int_to_adr(func).ptr
+        if hasattr(ptr._obj, 'graph'):
+            res = self.llinterp.eval_graph(ptr._obj.graph, args)
+        else:
+            res = ptr._obj._callable(*args)
         return support.cast_result(RESULT, res)
 
     def _do_call(self, func, args_i, args_r, args_f, calldescr):
         TP = llmemory.cast_int_to_adr(func).ptr._obj._TYPE
         args = support.cast_call_args(TP.ARGS, args_i, args_r, args_f)
-        ptr = llmemory.cast_int_to_adr(func).ptr
-        if hasattr(ptr._obj, 'graph'):
-            def func(*args):
-                return self.llinterp.eval_graph(ptr._obj.graph, args)
-        else:
-            func = ptr._obj._callable
-        return self.call(func, args, TP.RESULT, calldescr)
+        return self.maybe_on_top_of_llinterp(func, args, TP.RESULT)
 
     bh_call_i = _do_call
     bh_call_r = _do_call
@@ -485,6 +482,11 @@
         array = lltype.malloc(arraydescr.A, length, zero=True)
         return lltype.cast_opaque_ptr(llmemory.GCREF, array)
 
+    def bh_classof(self, struct):
+        struct = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
+        result_adr = llmemory.cast_ptr_to_adr(struct.typeptr)
+        return heaptracker.adr2int(result_adr)
+
     def bh_read_timestamp(self):
         return read_timestamp()
 
@@ -695,16 +697,27 @@
             if oopspecindex == EffectInfo.OS_MATH_SQRT:
                 return self._do_math_sqrt(args[0])
         TP = llmemory.cast_int_to_adr(func).ptr._obj._TYPE
-        ARGS = TP.ARGS
-        call_args = support.cast_call_args_in_order(ARGS, args)
-        func = llmemory.cast_int_to_adr(func).ptr._obj._callable
-        return self.cpu.call(func, call_args, TP.RESULT, calldescr)
+        call_args = support.cast_call_args_in_order(TP.ARGS, args)
+        try:
+            res = self.cpu.maybe_on_top_of_llinterp(func, call_args, TP.RESULT)
+            self.cpu.last_exception = None
+        except LLException, lle:
+            self.cpu.last_exception = lle
+            d = {'void': None,
+                 'ref': lltype.nullptr(llmemory.GCREF.TO),
+                 'int': 0,
+                 'float': 0.0}
+            res = d[getkind(TP.RESULT)]
+        return res
+
+    execute_call_may_force = execute_call
 
     def execute_call_release_gil(self, descr, func, *args):
         call_args = support.cast_call_args_in_order(descr.ARGS, args)
         FUNC = lltype.FuncType(descr.ARGS, descr.RESULT)
         func_to_call = rffi.cast(lltype.Ptr(FUNC), func)
-        return self.cpu.call(func_to_call, call_args, descr.RESULT, descr)
+        result = func_to_call(*call_args)
+        return support.cast_result(descr.RESULT, result)
 
     def execute_call_assembler(self, descr, *args):
         faildescr = self.cpu._execute_token(descr, *args)
diff --git a/pypy/jit/backend/llgraph/support.py b/pypy/jit/backend/llgraph/support.py
--- a/pypy/jit/backend/llgraph/support.py
+++ b/pypy/jit/backend/llgraph/support.py
@@ -136,13 +136,22 @@
 
 def cast_call_args_in_order(ARGS, args):
     call_args = []
-    for ARG, arg in zip(ARGS, args):
+    i = 0
+    for ARG in ARGS:
         kind = getkind(ARG)
         if kind == 'int':
-            n = cast_from_int(ARG, arg)
+            n = cast_from_int(ARG, args[i])
+            i += 1
         elif kind == 'ref':
-            n = cast_from_ptr(ARG, arg)
+            n = cast_from_ptr(ARG, args[i])
+            i += 1
+        elif kind == 'float':
+            n = cast_from_floatstorage(ARG, args[i])
+            i += 1
+        elif kind == 'void':
+            n = None
         else:
-            n = cast_from_floatstorage(ARG, arg)
+            raise AssertionError(kind)
         call_args.append(n)
+    assert i == len(args)
     return call_args
diff --git a/pypy/jit/metainterp/executor.py b/pypy/jit/metainterp/executor.py
--- a/pypy/jit/metainterp/executor.py
+++ b/pypy/jit/metainterp/executor.py
@@ -49,28 +49,28 @@
     rettype = descr.get_result_type()
     if rettype == INT or rettype == 'S':       # *S*ingle float
         try:
-            result = cpu.bh_call_i(func, descr, args_i, args_r, args_f)
+            result = cpu.bh_call_i(func, args_i, args_r, args_f, descr)
         except Exception, e:
             metainterp.execute_raised(e)
             result = 0
         return BoxInt(result)
     if rettype == REF:
         try:
-            result = cpu.bh_call_r(func, descr, args_i, args_r, args_f)
+            result = cpu.bh_call_r(func, args_i, args_r, args_f, descr)
         except Exception, e:
             metainterp.execute_raised(e)
             result = NULL
         return BoxPtr(result)
     if rettype == FLOAT or rettype == 'L':     # *L*ong long
         try:
-            result = cpu.bh_call_f(func, descr, args_i, args_r, args_f)
+            result = cpu.bh_call_f(func, args_i, args_r, args_f, descr)
         except Exception, e:
             metainterp.execute_raised(e)
             result = longlong.ZEROF
         return BoxFloat(result)
     if rettype == VOID:
         try:
-            cpu.bh_call_v(func, descr, args_i, args_r, args_f)
+            cpu.bh_call_v(func, args_i, args_r, args_f, descr)
         except Exception, e:
             metainterp.execute_raised(e)
         return None
@@ -83,42 +83,42 @@
     array = arraybox.getref_base()
     index = indexbox.getint()
     if arraydescr.is_array_of_pointers():
-        return BoxPtr(cpu.bh_getarrayitem_gc_r(arraydescr, array, index))
+        return BoxPtr(cpu.bh_getarrayitem_gc_r(array, index, arraydescr))
     elif arraydescr.is_array_of_floats():
-        return BoxFloat(cpu.bh_getarrayitem_gc_f(arraydescr, array, index))
+        return BoxFloat(cpu.bh_getarrayitem_gc_f(array, index, arraydescr))
     else:
-        return BoxInt(cpu.bh_getarrayitem_gc_i(arraydescr, array, index))
+        return BoxInt(cpu.bh_getarrayitem_gc_i(array, index, arraydescr))
 
 def do_getarrayitem_raw(cpu, _, arraybox, indexbox, arraydescr):
     array = arraybox.getint()
     index = indexbox.getint()
     assert not arraydescr.is_array_of_pointers()
     if arraydescr.is_array_of_floats():
-        return BoxFloat(cpu.bh_getarrayitem_raw_f(arraydescr, array, index))
+        return BoxFloat(cpu.bh_getarrayitem_raw_f(array, index, arraydescr))
     else:
-        return BoxInt(cpu.bh_getarrayitem_raw_i(arraydescr, array, index))
+        return BoxInt(cpu.bh_getarrayitem_raw_i(array, index, arraydescr))
 
 def do_setarrayitem_gc(cpu, _, arraybox, indexbox, itembox, arraydescr):
     array = arraybox.getref_base()
     index = indexbox.getint()
     if arraydescr.is_array_of_pointers():
-        cpu.bh_setarrayitem_gc_r(arraydescr, array, index,
-                                 itembox.getref_base())
+        cpu.bh_setarrayitem_gc_r(array, index,
+                                 itembox.getref_base(), arraydescr)
     elif arraydescr.is_array_of_floats():
-        cpu.bh_setarrayitem_gc_f(arraydescr, array, index,
-                                 itembox.getfloatstorage())
+        cpu.bh_setarrayitem_gc_f(array, index,
+                                 itembox.getfloatstorage(), arraydescr)
     else:
-        cpu.bh_setarrayitem_gc_i(arraydescr, array, index, itembox.getint())
+        cpu.bh_setarrayitem_gc_i(array, index, itembox.getint(), arraydescr)
 
 def do_setarrayitem_raw(cpu, _, arraybox, indexbox, itembox, arraydescr):
     array = arraybox.getint()
     index = indexbox.getint()
     assert not arraydescr.is_array_of_pointers()
     if arraydescr.is_array_of_floats():
-        cpu.bh_setarrayitem_raw_f(arraydescr, array, index,
-                                  itembox.getfloatstorage())
+        cpu.bh_setarrayitem_raw_f(array, index,
+                                  itembox.getfloatstorage(), arraydescr)
     else:
-        cpu.bh_setarrayitem_raw_i(arraydescr, array, index, itembox.getint())
+        cpu.bh_setarrayitem_raw_i(array, index, itembox.getint(), arraydescr)
 
 def do_getinteriorfield_gc(cpu, _, arraybox, indexbox, descr):
     array = arraybox.getref_base()
@@ -134,14 +134,14 @@
     array = arraybox.getref_base()
     index = indexbox.getint()
     if descr.is_pointer_field():
-        cpu.bh_setinteriorfield_gc_r(array, index, descr,
-                                     valuebox.getref_base())
+        cpu.bh_setinteriorfield_gc_r(array, index,
+                                     valuebox.getref_base(), descr)
     elif descr.is_float_field():
-        cpu.bh_setinteriorfield_gc_f(array, index, descr,
-                                     valuebox.getfloatstorage())
+        cpu.bh_setinteriorfield_gc_f(array, index,
+                                     valuebox.getfloatstorage(), descr)
     else:
-        cpu.bh_setinteriorfield_gc_i(array, index, descr,
-                                     valuebox.getint())
+        cpu.bh_setinteriorfield_gc_i(array, index,
+                                     valuebox.getint(), descr)
 
 def do_getfield_gc(cpu, _, structbox, fielddescr):
     struct = structbox.getref_base()
@@ -165,20 +165,20 @@
 def do_setfield_gc(cpu, _, structbox, itembox, fielddescr):
     struct = structbox.getref_base()
     if fielddescr.is_pointer_field():
-        cpu.bh_setfield_gc_r(struct, fielddescr, itembox.getref_base())
+        cpu.bh_setfield_gc_r(struct, itembox.getref_base(), fielddescr)
     elif fielddescr.is_float_field():
-        cpu.bh_setfield_gc_f(struct, fielddescr, itembox.getfloatstorage())
+        cpu.bh_setfield_gc_f(struct, itembox.getfloatstorage(), fielddescr)
     else:
-        cpu.bh_setfield_gc_i(struct, fielddescr, itembox.getint())
+        cpu.bh_setfield_gc_i(struct, itembox.getint(), fielddescr)
 
 def do_setfield_raw(cpu, _, structbox, itembox, fielddescr):
     struct = structbox.getint()
     if fielddescr.is_pointer_field():
-        cpu.bh_setfield_raw_r(struct, fielddescr, itembox.getref_base())
+        cpu.bh_setfield_raw_r(struct, itembox.getref_base(), fielddescr)
     elif fielddescr.is_float_field():
-        cpu.bh_setfield_raw_f(struct, fielddescr, itembox.getfloatstorage())
+        cpu.bh_setfield_raw_f(struct, itembox.getfloatstorage(), fielddescr)
     else:
-        cpu.bh_setfield_raw_i(struct, fielddescr, itembox.getint())
+        cpu.bh_setfield_raw_i(struct, itembox.getint(), fielddescr)
 
 def do_raw_store(cpu, _, addrbox, offsetbox, valuebox, arraydescr):
     addr = addrbox.getint()
@@ -186,9 +186,10 @@
     if arraydescr.is_array_of_pointers():
         raise AssertionError("cannot store GC pointers in raw store")
     elif arraydescr.is_array_of_floats():
-        cpu.bh_raw_store_f(addr, offset, arraydescr,valuebox.getfloatstorage())
+        cpu.bh_raw_store_f(addr, offset, valuebox.getfloatstorage(),
+                           arraydescr)
     else:
-        cpu.bh_raw_store_i(addr, offset, arraydescr, valuebox.getint())
+        cpu.bh_raw_store_i(addr, offset, valuebox.getint(), arraydescr)
 
 def do_raw_load(cpu, _, addrbox, offsetbox, arraydescr):
     addr = addrbox.getint()
@@ -204,7 +205,7 @@
     from pypy.jit.codewriter import heaptracker
     vtable = clsbox.getint()
     descr = heaptracker.vtable2descr(cpu, vtable)
-    return cpu.bh_new_with_vtable(descr, vtable)
+    return cpu.bh_new_with_vtable(vtable, descr)
 
 def do_new_with_vtable(cpu, _, clsbox):
     return BoxPtr(exec_new_with_vtable(cpu, clsbox))
diff --git a/pypy/jit/metainterp/resume.py b/pypy/jit/metainterp/resume.py
--- a/pypy/jit/metainterp/resume.py
+++ b/pypy/jit/metainterp/resume.py
@@ -1142,7 +1142,7 @@
         return self.cpu.bh_new(typedescr)
 
     def allocate_array(self, arraydescr, length):
-        return self.cpu.bh_new_array(arraydescr, length)
+        return self.cpu.bh_new_array(length, arraydescr)
 
     def allocate_string(self, length):
         return self.cpu.bh_newstr(length)
@@ -1201,36 +1201,36 @@
     def setfield(self, descr, struct, fieldnum):
         if descr.is_pointer_field():
             newvalue = self.decode_ref(fieldnum)
-            self.cpu.bh_setfield_gc_r(struct, descr, newvalue)
+            self.cpu.bh_setfield_gc_r(struct, newvalue, descr)
         elif descr.is_float_field():
             newvalue = self.decode_float(fieldnum)
-            self.cpu.bh_setfield_gc_f(struct, descr, newvalue)
+            self.cpu.bh_setfield_gc_f(struct, newvalue, descr)
         else:
             newvalue = self.decode_int(fieldnum)
-            self.cpu.bh_setfield_gc_i(struct, descr, newvalue)
+            self.cpu.bh_setfield_gc_i(struct, newvalue, descr)
 
     def setinteriorfield(self, index, descr, array, fieldnum):
         if descr.is_pointer_field():
             newvalue = self.decode_ref(fieldnum)
-            self.cpu.bh_setinteriorfield_gc_r(array, index, descr, newvalue)
+            self.cpu.bh_setinteriorfield_gc_r(array, index, newvalue, descr)
         elif descr.is_float_field():
             newvalue = self.decode_float(fieldnum)
-            self.cpu.bh_setinteriorfield_gc_f(array, index, descr, newvalue)
+            self.cpu.bh_setinteriorfield_gc_f(array, index, newvalue, descr)
         else:
             newvalue = self.decode_int(fieldnum)
-            self.cpu.bh_setinteriorfield_gc_i(array, index, descr, newvalue)
+            self.cpu.bh_setinteriorfield_gc_i(array, index, newvalue, descr)
 
     def setarrayitem_int(self, arraydescr, array, index, fieldnum):
         newvalue = self.decode_int(fieldnum)
-        self.cpu.bh_setarrayitem_gc_i(arraydescr, array, index, newvalue)
+        self.cpu.bh_setarrayitem_gc_i(array, index, newvalue, arraydescr)
 
     def setarrayitem_ref(self, arraydescr, array, index, fieldnum):
         newvalue = self.decode_ref(fieldnum)
-        self.cpu.bh_setarrayitem_gc_r(arraydescr, array, index, newvalue)
+        self.cpu.bh_setarrayitem_gc_r(array, index, newvalue, arraydescr)
 
     def setarrayitem_float(self, arraydescr, array, index, fieldnum):
         newvalue = self.decode_float(fieldnum)
-        self.cpu.bh_setarrayitem_gc_f(arraydescr, array, index, newvalue)
+        self.cpu.bh_setarrayitem_gc_f(array, index, newvalue, arraydescr)
 
     def decode_int(self, tagged):
         num, tag = untag(tagged)
diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py
--- a/pypy/jit/metainterp/test/support.py
+++ b/pypy/jit/metainterp/test/support.py
@@ -256,38 +256,6 @@
         NODE.become(lltype.GcStruct('NODE', ('value', lltype.Signed),
                                             ('next', lltype.Ptr(NODE))))
         return NODE
-    
-class OOJitMixin(JitMixin):
-    type_system = 'ootype'
-    #CPUClass = runner.OOtypeCPU
-
-    def setup_class(cls):
-        py.test.skip("ootype tests skipped for now")
-
-    @staticmethod
-    def Ptr(T):
-        return T
-
-    @staticmethod
-    def GcStruct(name, *fields, **kwds):
-        if 'hints' in kwds:
-            kwds['_hints'] = kwds['hints']
-            del kwds['hints']
-        I = ootype.Instance(name, ootype.ROOT, dict(fields), **kwds)
-        return I
-
-    malloc = staticmethod(ootype.new)
-    nullptr = staticmethod(ootype.null)
-
-    @staticmethod
-    def malloc_immortal(T):
-        return ootype.new(T)
-
-    def _get_NODE(self):
-        NODE = ootype.Instance('NODE', ootype.ROOT, {})
-        NODE._add_fields({'value': ootype.Signed,
-                          'next': NODE})
-        return NODE
 
 # ____________________________________________________________
 
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
@@ -8,7 +8,7 @@
 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.metainterp.test.support import LLJitMixin, OOJitMixin, noConst
+from pypy.jit.metainterp.test.support import LLJitMixin, noConst
 from pypy.jit.metainterp.typesystem import LLTypeHelper, OOTypeHelper
 from pypy.jit.metainterp.warmspot import get_stats
 from pypy.rlib import rerased
@@ -3053,86 +3053,6 @@
         assert res == f(32)
 
 
-class TestOOtype(BasicTests, OOJitMixin):
-
-    def test_oohash(self):
-        def f(n):
-            s = ootype.oostring(n, -1)
-            return s.ll_hash()
-        res = self.interp_operations(f, [5])
-        assert res == ootype.oostring(5, -1).ll_hash()
-
-    def test_identityhash(self):
-        A = ootype.Instance("A", ootype.ROOT)
-        def f():
-            obj1 = ootype.new(A)
-            obj2 = ootype.new(A)
-            return ootype.identityhash(obj1) == ootype.identityhash(obj2)
-        assert not f()
-        res = self.interp_operations(f, [])
-        assert not res
-
-    def test_oois(self):
-        A = ootype.Instance("A", ootype.ROOT)
-        def f(n):
-            obj1 = ootype.new(A)
-            if n:
-                obj2 = obj1
-            else:
-                obj2 = ootype.new(A)
-            return obj1 is obj2
-        res = self.interp_operations(f, [0])
-        assert not res
-        res = self.interp_operations(f, [1])
-        assert res
-
-    def test_oostring_instance(self):
-        A = ootype.Instance("A", ootype.ROOT)
-        B = ootype.Instance("B", ootype.ROOT)
-        def f(n):
-            obj1 = ootype.new(A)
-            obj2 = ootype.new(B)
-            s1 = ootype.oostring(obj1, -1)
-            s2 = ootype.oostring(obj2, -1)
-            ch1 = s1.ll_stritem_nonneg(1)
-            ch2 = s2.ll_stritem_nonneg(1)
-            return ord(ch1) + ord(ch2)
-        res = self.interp_operations(f, [0])
-        assert res == ord('A') + ord('B')
-
-    def test_subclassof(self):
-        A = ootype.Instance("A", ootype.ROOT)
-        B = ootype.Instance("B", A)
-        clsA = ootype.runtimeClass(A)
-        clsB = ootype.runtimeClass(B)
-        myjitdriver = JitDriver(greens = [], reds = ['n', 'flag', 'res'])
-
-        def getcls(flag):
-            if flag:
-                return clsA
-            else:
-                return clsB
-
-        def f(flag, n):
-            res = True
-            while n > -100:
-                myjitdriver.can_enter_jit(n=n, flag=flag, res=res)
-                myjitdriver.jit_merge_point(n=n, flag=flag, res=res)
-                cls = getcls(flag)
-                n -= 1
-                res = ootype.subclassof(cls, clsB)
-            return res
-
-        res = self.meta_interp(f, [1, 100],
-                               policy=StopAtXPolicy(getcls),
-                               enable_opts='')
-        assert not res
-
-        res = self.meta_interp(f, [0, 100],
-                               policy=StopAtXPolicy(getcls),
-                               enable_opts='')
-        assert res
-
 class BaseLLtypeTests(BasicTests):
 
     def test_identityhash(self):
diff --git a/pypy/objspace/flow/model.py b/pypy/objspace/flow/model.py
--- a/pypy/objspace/flow/model.py
+++ b/pypy/objspace/flow/model.py
@@ -33,6 +33,9 @@
 
 
 class FunctionGraph(object):
+    __slots__ = ('startblock', '__dict__')
+    # xxx the __slots__ is for try_show(), to make get_referrers() work. HACK
+
     def __init__(self, name, startblock, return_var=None):
         self.name        = name    # function name (possibly mangled already)
         self.startblock  = startblock


More information about the pypy-commit mailing list