[pypy-svn] r66281 - in pypy/branch/pyjitpl5/pypy/jit: backend backend/cli backend/llgraph metainterp metainterp/test

antocuni at codespeak.net antocuni at codespeak.net
Thu Jul 16 15:13:46 CEST 2009


Author: antocuni
Date: Thu Jul 16 15:13:45 2009
New Revision: 66281

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/cli/method.py
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/model.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py
Log:
- hack test_subclassof until it really emits a subclassof operation and can be
  run by zrpy_* tests

- move do_subclassof to executor.py, as its implementation is backend indipendent

- implement llimpl.op_subclassof for the llgraph backend

- implement emit_op_subclassof for the cli backend



Modified: pypy/branch/pyjitpl5/pypy/jit/backend/cli/method.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/cli/method.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/cli/method.py	Thu Jul 16 15:13:45 2009
@@ -20,6 +20,7 @@
 DelegateHolder = CLR.pypy.runtime.DelegateHolder
 InputArgs = CLR.pypy.runtime.InputArgs
 ListOfVoid = CLR.pypy.runtime.ListOfVoid
+Utils = CLR.pypy.runtime.Utils
 
 cVoid = ootype.nullruntimeclass
 
@@ -498,7 +499,12 @@
         self.store_result(op)
 
     def emit_op_subclassof(self, op):
-        raise NotImplementedError
+        clitype_utils = dotnet.typeof(Utils)
+        methinfo = clitype_utils.GetMethod('SubclassOf')
+        op.args[0].load(self)
+        op.args[1].load(self)
+        self.il.Emit(OpCodes.Call, methinfo)
+        self.store_result(op)
 
     def emit_op_ooidentityhash(self, op):
         raise NotImplementedError

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	Thu Jul 16 15:13:45 2009
@@ -768,8 +768,10 @@
         inst = ootype.cast_from_object(ootype.ROOT, obj)
         return ootype.instanceof(inst, typedescr.TYPE)
 
-    def op_subclassof(self, *args):
-        raise NotImplementedError
+    def op_subclassof(self, _, obj1, obj2):
+        cls1 = ootype.cast_from_object(ootype.Class, obj1)
+        cls2 = ootype.cast_from_object(ootype.Class, obj2)
+        return ootype.subclassof(cls1, cls2)
 
     def _cast_exception(self, exception):
         return ootype.cast_from_object(ootype.Class, exception)

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py	Thu Jul 16 15:13:45 2009
@@ -469,14 +469,6 @@
         assert len(args) == 1
         return typedescr.instanceof(args[0])
 
-    def do_subclassof(self, args, descr):
-        assert len(args) == 2
-        box1, box2 = args
-        cls1 = ootype.cast_from_object(ootype.Class, box1.getobj())
-        cls2 = ootype.cast_from_object(ootype.Class, box2.getobj())
-        res = ootype.subclassof(cls1, cls2)
-        return history.BoxInt(res)
-
     def do_getfield_gc(self, args, fielddescr):
         assert isinstance(fielddescr, FieldDescr)
         return fielddescr.getfield(args[0])

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/model.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/model.py	Thu Jul 16 15:13:45 2009
@@ -171,6 +171,3 @@
 
     def do_instanceof(self, args, descr=None):
         raise NotImplementedError
-
-    def do_subclassof(self, args, descr=None):
-        raise NotImplementedError

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py	Thu Jul 16 15:13:45 2009
@@ -149,6 +149,16 @@
     obj = args[0].getobj()
     return ConstInt(ootype.ooidentityhash(obj))
 
+
+def do_subclassof(self, args, descr=None):
+    assert len(args) == 2
+    box1, box2 = args
+    cls1 = ootype.cast_from_object(ootype.Class, box1.getobj())
+    cls2 = ootype.cast_from_object(ootype.Class, box2.getobj())
+    res = ootype.subclassof(cls1, cls2)
+    return BoxInt(res)
+
+
 # ----------
 # the following operations just delegate to the cpu:
 

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py	Thu Jul 16 15:13:45 2009
@@ -782,22 +782,38 @@
 
 
     def test_subclassof(self):
+        from pypy.jit.metainterp import simple_optimize
         A = ootype.Instance("A", ootype.ROOT)
         B = ootype.Instance("B", A)
         clsA = ootype.runtimeClass(A)
         clsB = ootype.runtimeClass(B)
-        def f(n):
-            if n:
-                obj = ootype.ooupcast(A, ootype.new(B))
+        myjitdriver = JitDriver(greens = [], reds = ['n', 'flag', 'res'])
+
+        def getcls(flag):
+            if flag:
+                return clsA
             else:
-                obj = ootype.new(A)
-            cls = ootype.classof(obj)
-            return ootype.subclassof(cls, clsB)
+                return clsB
 
-        res = self.interp_operations(f, [True])
-        assert res
-        res = self.interp_operations(f, [False])
+        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),
+                               optimizer=simple_optimize)
         assert not res
+        
+        res = self.meta_interp(f, [0, 100],
+                               policy=StopAtXPolicy(getcls),
+                               optimizer=simple_optimize)
+        assert res
 
 
 



More information about the Pypy-commit mailing list