[pypy-svn] r74708 - in pypy/branch/blackhole-improvement/pypy/jit: backend backend/llgraph metainterp/test

arigo at codespeak.net arigo at codespeak.net
Mon May 24 16:16:49 CEST 2010


Author: arigo
Date: Mon May 24 16:16:48 2010
New Revision: 74708

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/model.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_executor.py
Log:
Pass test_executor.


Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py	Mon May 24 16:16:48 2010
@@ -1091,9 +1091,9 @@
     if _last_exception is not None:
         result = _last_exception.args[1]
         _last_exception = None
-        return  lltype.cast_opaque_ptr(llmemory.GCREF, result)
+        return result
     else:
-        return lltype.nullptr(llmemory.GCREF.TO)
+        return lltype.nullptr(rclass.OBJECTPTR.TO)
 
 ##_pseudo_exceptions = {}
 

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/model.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/model.py	Mon May 24 16:16:48 2010
@@ -101,7 +101,9 @@
         raise NotImplementedError
 
     def grab_exc_value(self):
-        """Return and clear the exception set by the latest execute_token()."""
+        """Return and clear the exception set by the latest execute_token(),
+        when it exits due to a failure of a GUARD_EXCEPTION or
+        GUARD_NO_EXCEPTION."""        # XXX remove me
         raise NotImplementedError
 
     @staticmethod
@@ -212,5 +214,18 @@
     def bh_cast_ptr_to_int(self, ptr):
         raise NotImplementedError
 
+    def bh_strlen(self, string):
+        raise NotImplementedError
+    def bh_strgetitem(self, string, index):
+        raise NotImplementedError
+    def bh_unicodelen(self, string):
+        raise NotImplementedError
+    def bh_unicodegetitem(self, string, index):
+        raise NotImplementedError
+    def bh_strsetitem(self, string, index, newvalue):
+        raise NotImplementedError
+    def bh_unicodesetitem(self, string, index, newvalue):
+        raise NotImplementedError
+
     def force(self, force_token):
         raise NotImplementedError

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_executor.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_executor.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_executor.py	Mon May 24 16:16:48 2010
@@ -1,60 +1,90 @@
 import py
 import sys, random
 from pypy.rlib.rarithmetic import r_uint, intmask
-from pypy.jit.metainterp.executor import make_execute_list, execute
+from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.jit.metainterp.executor import execute
 from pypy.jit.metainterp.executor import execute_varargs, execute_nonspec
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.history import BoxInt, ConstInt
+from pypy.jit.metainterp.history import BoxPtr, ConstPtr
 from pypy.jit.metainterp.history import BoxFloat, ConstFloat
 from pypy.jit.metainterp.history import AbstractDescr, Box
+from pypy.jit.metainterp import history
 from pypy.jit.backend.model import AbstractCPU
 
 
 class FakeDescr(AbstractDescr):
     pass
 
-class FakeBox(Box):
+class FakeCallDescr(FakeDescr):
+    def get_return_type(self):
+        return history.FLOAT
+
+class FakeFieldDescr(FakeDescr):
+    def is_pointer_field(self):
+        return False
+    def is_float_field(self):
+        return True
+
+class FakeArrayDescr(FakeDescr):
+    def is_array_of_pointers(self):
+        return False
+    def is_array_of_floats(self):
+        return True
+
+class FakeResultR:
+    _TYPE = llmemory.GCREF
     def __init__(self, *args):
-        self.args = args
+        self.fakeargs = args
+
+class FakeMetaInterp:
+    def execute_did_not_raise(self):
+        self.didraise = False
 
 class FakeCPU(AbstractCPU):
     supports_floats = True
 
-    def do_new(self, descr):
-        return FakeBox('new', descr)
-
-    def do_arraylen_gc(self, box1, descr):
-        return FakeBox('arraylen_gc', box1, descr)
-
-    def do_setfield_gc(self, box1, box2, descr):
-        return FakeBox('setfield_gc', box1, box2, descr)
+    def bh_new(self, descr):
+        return FakeResultR('new', descr)
 
-    def do_setarrayitem_gc(self, box1, box2, box3, descr):
-        return FakeBox('setarrayitem_gc', box1, box2, box3, descr)
+    def bh_arraylen_gc(self, descr, array):
+        assert not array
+        assert isinstance(descr, FakeDescr)
+        return 55
+
+    def bh_setfield_gc_f(self, struct, fielddescr, newvalue):
+        self.fakesetfield = (struct, newvalue, fielddescr)
+
+    def bh_setarrayitem_gc_f(self, arraydescr, array, index, newvalue):
+        self.fakesetarrayitem = (array, index, newvalue, arraydescr)
+
+    def bh_call_f(self, func, calldescr, args_i, args_r, args_f):
+        self.fakecalled = (func, calldescr, args_i, args_r, args_f)
+        return 42.5
 
-    def do_call(self, args, descr):
-        return FakeBox('call', args, descr)
-
-    def do_strsetitem(self, box1, box2, box3):
-        return FakeBox('strsetitem', box1, box2, box3)
-
-make_execute_list(FakeCPU)
+    def bh_strsetitem(self, string, index, newvalue):
+        self.fakestrsetitem = (string, index, newvalue)
 
 
 def test_execute():
     cpu = FakeCPU()
     descr = FakeDescr()
-    box = execute(cpu, rop.INT_ADD, None, BoxInt(40), ConstInt(2))
+    box = execute(cpu, None, rop.INT_ADD, None, BoxInt(40), ConstInt(2))
     assert box.value == 42
-    box = execute(cpu, rop.NEW, descr)
-    assert box.args == ('new', descr)
+    box = execute(cpu, None, rop.NEW, descr)
+    assert box.value.fakeargs == ('new', descr)
 
 def test_execute_varargs():
     cpu = FakeCPU()
-    descr = FakeDescr()
-    argboxes = [BoxInt(321), ConstInt(123)]
-    box = execute_varargs(cpu, rop.CALL, argboxes, descr)
-    assert box.args == ('call', argboxes, descr)
+    metainterp = FakeMetaInterp()
+    descr = FakeCallDescr()
+    argboxes = [BoxInt(99999), BoxInt(321), ConstFloat(2.25), ConstInt(123),
+                BoxPtr(), BoxFloat(5.5)]
+    box = execute_varargs(cpu, metainterp, rop.CALL, argboxes, descr)
+    assert box.value == 42.5
+    assert cpu.fakecalled == (99999, descr, [321, 123],
+                              [ConstPtr.value], [2.25, 5.5])
+    assert not metainterp.didraise
 
 def test_execute_nonspec():
     cpu = FakeCPU()
@@ -62,33 +92,38 @@
     # cases with a descr
     # arity == -1
     argboxes = [BoxInt(321), ConstInt(123)]
-    box = execute_nonspec(cpu, rop.CALL, argboxes, descr)
-    assert box.args == ('call', argboxes, descr)
+    box = execute_nonspec(cpu, FakeMetaInterp(), rop.CALL,
+                          argboxes, FakeCallDescr())
+    assert box.value == 42.5
     # arity == 0
-    box = execute_nonspec(cpu, rop.NEW, [], descr)
-    assert box.args == ('new', descr)
+    box = execute_nonspec(cpu, None, rop.NEW, [], descr)
+    assert box.value.fakeargs == ('new', descr)
     # arity == 1
-    box1 = BoxInt(515)
-    box = execute_nonspec(cpu, rop.ARRAYLEN_GC, [box1], descr)
-    assert box.args == ('arraylen_gc', box1, descr)
+    box1 = BoxPtr()
+    box = execute_nonspec(cpu, None, rop.ARRAYLEN_GC, [box1], descr)
+    assert box.value == 55
     # arity == 2
-    box2 = BoxInt(222)
-    box = execute_nonspec(cpu, rop.SETFIELD_GC, [box1, box2], descr)
-    assert box.args == ('setfield_gc', box1, box2, descr)
+    box2 = BoxFloat(222.2)
+    fielddescr = FakeFieldDescr()
+    execute_nonspec(cpu, None, rop.SETFIELD_GC, [box1, box2], fielddescr)
+    assert cpu.fakesetfield == (box1.value, box2.value, fielddescr)
     # arity == 3
-    box3 = BoxInt(-33)
-    box = execute_nonspec(cpu, rop.SETARRAYITEM_GC, [box1, box2, box3], descr)
-    assert box.args == ('setarrayitem_gc', box1, box2, box3, descr)
+    box3 = BoxInt(33)
+    arraydescr = FakeArrayDescr()
+    execute_nonspec(cpu, None, rop.SETARRAYITEM_GC, [box1, box3, box2],
+                    arraydescr)
+    assert cpu.fakesetarrayitem == (box1.value, box3.value, box2.value,
+                                    arraydescr)
     # cases without descr
     # arity == 1
-    box = execute_nonspec(cpu, rop.INT_INVERT, [box1])
-    assert box.value == ~515
+    box = execute_nonspec(cpu, None, rop.INT_INVERT, [box3])
+    assert box.value == ~33
     # arity == 2
-    box = execute_nonspec(cpu, rop.INT_LSHIFT, [box1, BoxInt(3)])
-    assert box.value == 515 << 3
+    box = execute_nonspec(cpu, None, rop.INT_LSHIFT, [box3, BoxInt(3)])
+    assert box.value == 33 << 3
     # arity == 3
-    box = execute_nonspec(cpu, rop.STRSETITEM, [box1, box2, box3])
-    assert box.args == ('strsetitem', box1, box2, box3)
+    execute_nonspec(cpu, None, rop.STRSETITEM, [box1, BoxInt(3), box3])
+    assert cpu.fakestrsetitem == (box1.value, 3, box3.value)
 
 # ints
 
@@ -181,7 +216,7 @@
         (rop.INT_IS_TRUE, [(0, 0), (1, 1), (2, 1), (-1, 1), (minint, 1)]),
         (rop.INT_NEG, [(0, 0), (123, -123), (-23127, 23127)]),
         (rop.INT_INVERT, [(0, ~0), (-1, ~(-1)), (123, ~123)]),
-        (rop.BOOL_NOT, [(0, 1), (1, 0)]),
+        (rop.INT_IS_ZERO, [(0, 1), (1, 0), (2, 0), (-1, 0), (minint, 0)]),
         ]:
         for x, y in testcases:
             yield opnum, [x], y
@@ -204,7 +239,7 @@
 def test_int_ops():
     cpu = FakeCPU()
     for opnum, boxargs, retvalue in get_int_tests():
-        box = execute_nonspec(cpu, opnum, boxargs)
+        box = execute_nonspec(cpu, None, opnum, boxargs)
         assert box.getint() == retvalue
 
 # floats
@@ -242,9 +277,6 @@
     yield (rop.FLOAT_NEG, [15.9], 'float', -15.9)
     yield (rop.FLOAT_ABS, [-5.9], 'float', 5.9)
     yield (rop.FLOAT_ABS, [15.9], 'float', 15.9)
-    yield (rop.FLOAT_IS_TRUE, [-5.9], 'int', 1)
-    yield (rop.FLOAT_IS_TRUE, [0.0], 'int', 0)
-    yield (rop.FLOAT_IS_TRUE, [-0.0], 'int', 0)
     yield (rop.CAST_FLOAT_TO_INT, [-5.9], 'int', -5)
     yield (rop.CAST_FLOAT_TO_INT, [5.9], 'int', 5)
     yield (rop.CAST_INT_TO_FLOAT, [123], 'float', 123.0)
@@ -276,7 +308,7 @@
 def test_float_ops():
     cpu = FakeCPU()
     for opnum, boxargs, rettype, retvalue in get_float_tests(cpu):
-        box = execute_nonspec(cpu, opnum, boxargs)
+        box = execute_nonspec(cpu, None, opnum, boxargs)
         if rettype == 'float':
             assert box.getfloat() == retvalue
         elif rettype == 'int':



More information about the Pypy-commit mailing list