[pypy-svn] r10378 - pypy/branch/pypy-normalize-exception/annotation

arigo at codespeak.net arigo at codespeak.net
Wed Apr 6 23:23:52 CEST 2005


Author: arigo
Date: Wed Apr  6 23:23:52 2005
New Revision: 10378

Modified:
   pypy/branch/pypy-normalize-exception/annotation/binaryop.py
   pypy/branch/pypy-normalize-exception/annotation/builtin.py
   pypy/branch/pypy-normalize-exception/annotation/unaryop.py
Log:
Completed the issubtype() operation support.
Merged the issubtype operation with the issubclass built-in.
(Should do the same with type and type, btw)


Modified: pypy/branch/pypy-normalize-exception/annotation/binaryop.py
==============================================================================
--- pypy/branch/pypy-normalize-exception/annotation/binaryop.py	(original)
+++ pypy/branch/pypy-normalize-exception/annotation/binaryop.py	Wed Apr  6 23:23:52 2005
@@ -24,7 +24,7 @@
                          'getitem', 'setitem',
                          'inplace_add', 'inplace_sub',
                          'lt', 'le', 'eq', 'ne', 'gt', 'ge', 'is_',
-                         'union', 'issubtype',
+                         'union',
                          'lshift',
                          ])
 
@@ -350,15 +350,3 @@
 class __extend__(pairtype(SomePBC, SomeList    )):
     def union((pbc, lst)):
         return pair(lst, pbc).union()
-
-
-class __extend__(pairtype(SomeObject, SomePBC)):
-    def issubtype((obj, pbc)):
-        s = SomeBool()
-        if obj.is_constant() and pbc.is_constant():
-            s.const = issubclass(obj.const, pbc.const)
-        if hasattr(obj,'is_type_of') and pbc.is_constant():
-            bk = getbookkeeper()
-            s.knowntypedata = (obj.is_type_of, bk.valueoftype(pbc.const))
-        return s
-

Modified: pypy/branch/pypy-normalize-exception/annotation/builtin.py
==============================================================================
--- pypy/branch/pypy-normalize-exception/annotation/builtin.py	(original)
+++ pypy/branch/pypy-normalize-exception/annotation/builtin.py	Wed Apr  6 23:23:52 2005
@@ -70,7 +70,7 @@
     """ we're going to try to be less silly in the face of old-style classes"""
     return cls2 is object or issubclass(cls1, cls2)
 
-def builtin_isinstance(s_obj, s_type):
+def builtin_isinstance(s_obj, s_type, variable=None):
     s = SomeBool() 
     if s_type.is_constant():
         typ = s_type.const
@@ -87,21 +87,25 @@
         # XXX HACK HACK HACK
         # XXX HACK HACK HACK
         bk = getbookkeeper()
-        fn, block, i = bk.position_key
-        annotator = bk.annotator
-        op = block.operations[i]
-        assert op.opname == "simple_call" 
-        assert len(op.args) == 3
-        assert op.args[0] == Constant(isinstance)
-        assert annotator.binding(op.args[1]) == s_obj
-        s.knowntypedata = ([op.args[1]], bk.valueoftype(typ))
+        if variable 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)
+            variable = op.args[1]
+        assert bk.annotator.binding(variable) == s_obj
+        s.knowntypedata = ([variable], bk.valueoftype(typ))
     return s 
 
 def builtin_issubclass(s_cls1, s_cls2):
     if s_cls1.is_constant() and s_cls2.is_constant():
         return immutablevalue(issubclass(s_cls1.const, s_cls2.const))
-    else:
-        return SomeBool()
+    if hasattr(s_cls1, 'is_type_of') and len(s_cls1.is_type_of) == 1:
+        var = s_cls1.is_type_of[0]
+        annotator = getbookkeeper().annotator
+        return builtin_isinstance(annotator.binding(var), s_cls2, var)
+    return SomeBool()
 
 def builtin_getattr(s_obj, s_attr, s_default=None):
     if not s_attr.is_constant() or not isinstance(s_attr.const, str):

Modified: pypy/branch/pypy-normalize-exception/annotation/unaryop.py
==============================================================================
--- pypy/branch/pypy-normalize-exception/annotation/unaryop.py	(original)
+++ pypy/branch/pypy-normalize-exception/annotation/unaryop.py	Wed Apr  6 23:23:52 2005
@@ -14,6 +14,7 @@
 from pypy.annotation.factory import BlockedInference, generalize, ListFactory
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.annotation.classdef import isclassdef
+from pypy.annotation.builtin import builtin_issubclass
 
 # convenience only!
 def immutablevalue(x):
@@ -21,7 +22,7 @@
 
 UNARY_OPERATIONS = set(['len', 'is_true', 'getattr', 'setattr',
                         'simple_call', 'call_args',
-                        'iter', 'next', 'invert', 'type'])
+                        'iter', 'next', 'invert', 'type', 'issubtype'])
 
 for opname in UNARY_OPERATIONS:
     missing_operation(SomeObject, opname)
@@ -43,7 +44,10 @@
         assert annotator.binding(op.args[0]) == obj
         r.is_type_of = [op.args[0]]
         return r
-    
+
+    def issubtype(obj, s_cls):
+        return builtin_issubclass(obj, s_cls)
+
     def len(obj):
         return SomeInteger(nonneg=True)
 



More information about the Pypy-commit mailing list