[pypy-svn] r17448 - pypy/dist/pypy/annotation

ludal at codespeak.net ludal at codespeak.net
Sun Sep 11 02:06:11 CEST 2005


Author: ludal
Date: Sun Sep 11 02:06:09 2005
New Revision: 17448

Modified:
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/annotation/unaryop.py
Log:

Propagate not None info accross :
 if string:
    xxx  # string is true implies string is not None
 else:
    yyy
I needed to ignore knowntypedata for SomeBool comparison ( not sure it's the correct fix )
this is needed because of the assertion in setbinding and the way contains is implemented
pypy still annotate and compile correctly with this

We could do the same with 'if SomeInstance(): xxx'



Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Sun Sep 11 02:06:09 2005
@@ -171,6 +171,20 @@
     unsigned = False
     def __init__(self):
         pass
+    def __eq__(self, other):
+        if self.__class__ is not other.__class__:
+            return False
+        if 'knowntypedata' in self.__dict__:
+            selfdic = self.__dict__.copy()
+            del selfdic['knowntypedata']
+        else:
+            selfdic = self.__dict__
+        if 'knowntypedata' in other.__dict__:
+            otherdic = other.__dict__.copy()
+            del otherdic['knowntypedata']
+        else:
+            otherdic = other.__dict__
+        return selfdic == otherdic
 
 class SomeString(SomeObject):
     "Stands for an object which is known to be a string."

Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Sun Sep 11 02:06:09 2005
@@ -14,6 +14,7 @@
 from pypy.annotation.model import SomeExternalObject
 from pypy.annotation.model import SomeTypedAddressAccess, SomeAddress
 from pypy.annotation.model import unionof, set, setunion, missing_operation
+from pypy.annotation.model import add_knowntypedata
 from pypy.annotation.bookkeeper import getbookkeeper, RPythonCallsSpace
 from pypy.annotation.classdef import isclassdef
 from pypy.annotation import builtin
@@ -369,6 +370,24 @@
     def method_upper(str):
         return SomeString()
 
+    def is_true(str):
+        r = SomeObject.is_true(str)
+        if not isinstance(r, SomeBool):
+            return r
+        bk = getbookkeeper()
+        knowntypedata = r.knowntypedata = {}
+        fn, block, i = bk.position_key
+
+        annotator = bk.annotator
+        op = block.operations[i]
+        assert op.opname == "is_true" or op.opname == "nonzero"
+        assert len(op.args) == 1
+        arg = op.args[0]
+        add_knowntypedata(knowntypedata, False, [arg], str)
+        add_knowntypedata(knowntypedata, True, [arg], str.nonnoneify())
+        return r
+
+
 
 class __extend__(SomeChar):
 



More information about the Pypy-commit mailing list