[pypy-svn] r75734 - pypy/branch/fast-forward/pypy/annotation

benjamin at codespeak.net benjamin at codespeak.net
Thu Jul 1 20:50:04 CEST 2010


Author: benjamin
Date: Thu Jul  1 20:50:02 2010
New Revision: 75734

Modified:
   pypy/branch/fast-forward/pypy/annotation/builtin.py
   pypy/branch/fast-forward/pypy/annotation/unaryop.py
Log:
teach the annotator about the isinstance operation

Modified: pypy/branch/fast-forward/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/fast-forward/pypy/annotation/builtin.py	(original)
+++ pypy/branch/fast-forward/pypy/annotation/builtin.py	Thu Jul  1 20:50:02 2010
@@ -175,17 +175,7 @@
                                                    # from bool to int, notice that isinstance( , bool|int)
                                                    # is quite border case for RPython
                 r.const = False
-        # XXX HACK HACK HACK
-        # XXX HACK HACK HACK
-        # XXX HACK HACK HACK
         bk = getbookkeeper()
-        if variables is None:
-            fn, block, i = bk.position_key
-            op = block.operations[i]
-            assert op.opname == "simple_call" 
-            assert len(op.args) == 3
-            assert op.args[0] == Constant(isinstance)
-            variables = [op.args[1]]
         for variable in variables:
             assert bk.annotator.binding(variable) == s_obj
         r.knowntypedata = {}

Modified: pypy/branch/fast-forward/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/fast-forward/pypy/annotation/unaryop.py	(original)
+++ pypy/branch/fast-forward/pypy/annotation/unaryop.py	Thu Jul  1 20:50:02 2010
@@ -23,6 +23,7 @@
 UNARY_OPERATIONS = set(['len', 'is_true', 'getattr', 'setattr', 'delattr',
                         'simple_call', 'call_args', 'str', 'repr',
                         'iter', 'next', 'invert', 'type', 'issubtype',
+                        'isinstance',
                         'pos', 'neg', 'nonzero', 'abs', 'hex', 'oct',
                         'ord', 'int', 'float', 'long',
                         'hash', 'id',    # <== not supported any more
@@ -66,6 +67,13 @@
             return immutablevalue(issubclass(obj.const, s_cls.const))
         return s_Bool
 
+    def isinstance(obj, s_cls):
+        bk = getbookkeeper()
+        fn, block, i = bk.position_key
+        op = block.operations[i]
+        v = op.args[0]
+        return builtin.builtin_isinstance(obj, s_cls, [v])
+
     def len(obj):
         return SomeInteger(nonneg=True)
 



More information about the Pypy-commit mailing list