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

antocuni at codespeak.net antocuni at codespeak.net
Tue May 5 17:11:01 CEST 2009


Author: antocuni
Date: Tue May  5 17:11:00 2009
New Revision: 65064

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/model.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py
Log:
implement instanceof for ootype


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	Tue May  5 17:11:00 2009
@@ -453,6 +453,11 @@
         res = ootype.runtimenew(classobj)
         return history.BoxObj(ootype.cast_to_object(res))
 
+    def do_instanceof(self, args, typedescr):
+        assert isinstance(typedescr, TypeDescr)
+        assert len(args) == 1
+        return typedescr.instanceof(args[0])
+
     def do_getfield_gc(self, args, fielddescr):
         assert isinstance(fielddescr, FieldDescr)
         return fielddescr.getfield(args[0])
@@ -614,11 +619,16 @@
             array = ootype.cast_from_object(ARRAY, arraybox.getobj())
             return boxresult(ootype.Signed, array.ll_length())
 
+        def instanceof(box):
+            obj = ootype.cast_from_object(ootype.ROOT, box.getobj())
+            return history.BoxInt(ootype.instanceof(obj, TYPE))
+
         self.create = create
         self.create_array = create_array
         self.getarrayitem = getarrayitem
         self.setarrayitem = setarrayitem
         self.getarraylength = getarraylength
+        self.instanceof = instanceof
 
 class FieldDescr(OODescr):
 

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	Tue May  5 17:11:00 2009
@@ -168,3 +168,6 @@
 
     def do_oosend(self, args, descr=None):
         raise NotImplementedError
+
+    def do_instanceof(self, args, descr=None):
+        raise NotImplementedError

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	Tue May  5 17:11:00 2009
@@ -707,6 +707,15 @@
         self.emit(self.var_position(op.args[1]))
         self.register_var(op.result)
 
+    def serialize_op_instanceof(self, op):
+        v, c_TYPE = op.args
+        TYPE = c_TYPE.value
+        typedescr = self.cpu.typedescrof(TYPE)
+        self.emit('instanceof')
+        self.emit(self.var_position(v))
+        self.emit(self.get_position(typedescr))
+        self.register_var(op.result)
+
     def serialize_op_zero_gc_pointers_inside(self, op):
         pass   # XXX assume Boehm for now
 

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Tue May  5 17:11:00 2009
@@ -363,6 +363,10 @@
     def opimpl_runtimenew(self, classbox):
         self.execute(rop.RUNTIMENEW, [classbox])
 
+    @arguments("box", "descr")
+    def opimpl_instanceof(self, box, typedescr):
+        self.execute(rop.INSTANCEOF, [box], descr=typedescr)
+
     @arguments("descr", "box")
     def opimpl_new_array(self, itemsize, countbox):
         self.execute(rop.NEW_ARRAY, [countbox], descr=itemsize)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py	Tue May  5 17:11:00 2009
@@ -154,6 +154,7 @@
     UNICODEGETITEM         = 84
     #
     # ootype operations
+    INSTANCEOF             = 86
     OOSEND_PURE            = 87
     #
     _ALWAYS_PURE_LAST = 87  # ----- end of always_pure operations -----

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	Tue May  5 17:11:00 2009
@@ -557,6 +557,21 @@
         res = self.interp_operations(f, [0])
         assert res == -667
 
+    def test_isinstance(self):
+        class A:
+            pass
+        class B(A):
+            pass
+        def fn(n):
+            if n:
+                obj = A()
+            else:
+                obj = B()
+            return isinstance(obj, B)
+        res = self.interp_operations(fn, [0])
+        assert res
+        res = self.interp_operations(fn, [1])
+        assert not res
 
 class TestOOtype(BasicTests, OOJitMixin):
 



More information about the Pypy-commit mailing list