[pypy-svn] r10707 - in pypy/dist/pypy: annotation annotation/test translator
arigo at codespeak.net
arigo at codespeak.net
Fri Apr 15 20:26:00 CEST 2005
Author: arigo
Date: Fri Apr 15 20:26:00 2005
New Revision: 10707
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/annotation/dictdef.py
pypy/dist/pypy/annotation/listdef.py
pypy/dist/pypy/annotation/test/test_model.py
pypy/dist/pypy/translator/annrpython.py
Log:
Removed a hack about isinstance(_,list). This required a bit of clean-up to
ensure that a call to contains(SomeList(MOST_GENERAL_LISTDEF), s_lst) doesn't
actually generalize the items of s_lst to SomeObject().
It's still a bit fragile, because union() -- as used by contains() -- wasn't
really meant to have side-effects in the first place.
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Fri Apr 15 20:26:00 2005
@@ -130,10 +130,8 @@
bk = getbookkeeper()
if bk is not None: # for testing
if hasattr(obj1,'is_type_of') and obj2.is_constant():
- if obj2.const != list: # in list case we are most likely bound to lose info
- # we would also generate a factory-less list, not good either
- r.knowntypedata = (obj1.is_type_of, bk.valueoftype(obj2.const))
- return r
+ r.knowntypedata = (obj1.is_type_of, bk.valueoftype(obj2.const))
+ return r
fn, block, i = bk.position_key
annotator = bk.annotator
op = block.operations[i]
@@ -226,8 +224,7 @@
class __extend__(pairtype(SomeList, SomeList)):
def union((lst1, lst2)):
- lst1.listdef.merge(lst2.listdef)
- return lst1
+ return SomeList(lst1.listdef.union(lst2.listdef))
add = union
@@ -259,8 +256,7 @@
class __extend__(pairtype(SomeDict, SomeDict)):
def union((dic1, dic2)):
- dic1.dictdef.merge(dic2.dictdef)
- return dic1
+ return SomeDict(dic1.dictdef.union(dic2.dictdef))
class __extend__(pairtype(SomeDict, SomeObject)):
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Fri Apr 15 20:26:00 2005
@@ -84,9 +84,7 @@
variables = [op.args[1]]
for variable in variables:
assert bk.annotator.binding(variable) == s_obj
- if typ != list: # in the list case we are most likely bound to lose info,
- # we would also generate a factory-less list, not good either
- r.knowntypedata = (variables, bk.valueoftype(typ))
+ r.knowntypedata = (variables, bk.valueoftype(typ))
return r
def builtin_hasattr(s_obj, s_attr):
Modified: pypy/dist/pypy/annotation/dictdef.py
==============================================================================
--- pypy/dist/pypy/annotation/dictdef.py (original)
+++ pypy/dist/pypy/annotation/dictdef.py Fri Apr 15 20:26:00 2005
@@ -51,9 +51,14 @@
return (self.dictkey is other.dictkey and
self.dictvalue is other.dictvalue)
- def merge(self, other):
- self.dictkey.merge(other.dictkey)
- self.dictvalue.merge(other.dictvalue)
+ def union(self, other):
+ if (self.same_as(MOST_GENERAL_DICTDEF) or
+ other.same_as(MOST_GENERAL_DICTDEF)):
+ return MOST_GENERAL_DICTDEF # without merging
+ else:
+ self.dictkey.merge(other.dictkey)
+ self.dictvalue.merge(other.dictvalue)
+ return self
def generalize_key(self, s_key):
self.dictkey.generalize(s_key)
Modified: pypy/dist/pypy/annotation/listdef.py
==============================================================================
--- pypy/dist/pypy/annotation/listdef.py (original)
+++ pypy/dist/pypy/annotation/listdef.py Fri Apr 15 20:26:00 2005
@@ -52,8 +52,13 @@
def same_as(self, other):
return self.listitem is other.listitem
- def merge(self, other):
- self.listitem.merge(other.listitem)
+ def union(self, other):
+ if (self.same_as(MOST_GENERAL_LISTDEF) or
+ other.same_as(MOST_GENERAL_LISTDEF)):
+ return MOST_GENERAL_LISTDEF # without merging
+ else:
+ self.listitem.merge(other.listitem)
+ return self
def generalize(self, s_value):
self.listitem.generalize(s_value)
Modified: pypy/dist/pypy/annotation/test/test_model.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_model.py (original)
+++ pypy/dist/pypy/annotation/test/test_model.py Fri Apr 15 20:26:00 2005
@@ -1,7 +1,7 @@
import autopath
from pypy.annotation.model import *
-from pypy.annotation.listdef import ListDef
+from pypy.annotation.listdef import ListDef, MOST_GENERAL_LISTDEF
listdef1 = ListDef(None, SomeTuple([SomeInteger(nonneg=True), SomeString()]))
@@ -91,6 +91,16 @@
s3 = unionof(s1, s2)
assert s1 == s2 == s3
+def test_list_contains():
+ listdef1 = ListDef(None, SomeInteger(nonneg=True))
+ s1 = SomeList(listdef1)
+ s2 = SomeList(MOST_GENERAL_LISTDEF)
+ assert s1 != s2
+ assert s2.contains(s1)
+ assert s1 != s2
+ assert not s1.contains(s2)
+ assert s1 != s2
+
if __name__ == '__main__':
for name, value in globals().items():
if name.startswith('test_'):
Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py (original)
+++ pypy/dist/pypy/translator/annrpython.py Fri Apr 15 20:26:00 2005
@@ -204,7 +204,7 @@
self.binding_caused_by[arg] = called_from
- #___ interface for annotator.factory _______
+ #___ interface for annotator.bookkeeper _______
def recursivecall(self, func, position_key, inputcells):
override = self.overrides.get(func, None)
More information about the Pypy-commit
mailing list