[pypy-svn] r36578 - in pypy/dist/pypy/annotation: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Jan 12 15:51:27 CET 2007
Author: fijal
Date: Fri Jan 12 15:51:03 2007
New Revision: 36578
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/test/test_annrpython.py
Log:
(arigo, fijal) Improve a test and rewrite a bit SomeGenericCallable, kill _known_annotation_
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Fri Jan 12 15:51:03 2007
@@ -685,12 +685,18 @@
class __extend__(pairtype(SomeGenericCallable, SomePBC)):
def union((gencall, pbc)):
- unique_key = (gencall, pbc.const)
- s_result = getbookkeeper().emulate_pbc_call(unique_key, pbc,
- gencall.args_s)
- assert gencall.s_result.contains(s_result)
+ unique_key = "unionof(SomeGenericCallable, SomePBC)"
+ if len(pbc.descriptions):
+ bk = pbc.descriptions.iterkeys().next().bookkeeper
+ s_result = bk.emulate_pbc_call(unique_key, pbc, gencall.args_s)
+ s_result = unionof(s_result, gencall.s_result)
+ assert gencall.s_result.contains(s_result)
return gencall
+class __extend__(pairtype(SomePBC, SomeGenericCallable)):
+ def union((pbc, gencall)):
+ return pair(gencall, pbc).union()
+
class __extend__(pairtype(SomeImpossibleValue, SomeObject)):
def union((imp1, obj2)):
return obj2
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Fri Jan 12 15:51:03 2007
@@ -391,10 +391,6 @@
elif extregistry.is_registered(x, self.policy):
entry = extregistry.lookup(x, self.policy)
result = entry.compute_annotation_bk(self)
-## elif hasattr(x, "compute_result_annotation"):
-## result = SomeBuiltin(x.compute_result_annotation, methodname=x.__name__)
-## elif hasattr(tp, "compute_annotation"):
-## result = tp.compute_annotation()
elif tp in EXTERNAL_TYPE_ANALYZERS:
result = SomeExternalObject(tp)
elif isinstance(x, lltype._ptr):
@@ -409,8 +405,6 @@
result = SomeOOClass(x._INSTANCE) # NB. can be None
elif isinstance(x, ootype.instance_impl): # XXX
result = SomeOOInstance(ootype.typeOf(x))
- elif hasattr(x, '_known_annotation_'):
- result = x._known_annotation_
elif callable(x):
if hasattr(x, '__self__') and x.__self__ is not None:
# for cases like 'l.append' where 'l' is a global constant list
Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py Fri Jan 12 15:51:03 2007
@@ -2451,45 +2451,30 @@
assert s.const == 0
def test_some_generic_function_call(self):
- def g(a):
- pass
- g._known_annotation_ = annmodel.SomeGenericCallable(
- args=(annmodel.SomeInteger(),), result=annmodel.SomeInteger())
+ def h(x):
+ return int(x)
- def fun():
- return g(1)
-
- a = self.RPythonAnnotator(policy=policy.AnnotatorPolicy())
- s = a.build_types(fun, [])
- assert isinstance(s, annmodel.SomeInteger)
- assert not hasattr(s, 'const')
-
- def test_some_generic_function_callback(self):
- def g(a):
- pass
- g._known_annotation_ = annmodel.SomeGenericCallable(
- args=[annmodel.SomeGenericCallable(args=[annmodel.SomeInteger()],
- result=annmodel.SomeInteger())],
- result=annmodel.SomeInteger())
+ def c(x):
+ return int(x)
+
+ def g(a, x):
+ if x == -1:
+ a = None
+ if x < 0:
+ if x == -1:
+ a = h
+ else:
+ a = c
+ return a(x)
- def fun2(x):
- return x
+ #def fun(x):
- def fun():
- return g(fun2)
-
a = self.RPythonAnnotator(policy=policy.AnnotatorPolicy())
- s = a.build_types(fun, [])
+ s = a.build_types(g, [annmodel.SomeGenericCallable(
+ args=[annmodel.SomeFloat()], result=annmodel.SomeInteger()),
+ annmodel.SomeFloat()])
assert isinstance(s, annmodel.SomeInteger)
- graphs = a.annotated.values()
- found = False
- for graph in graphs:
- if graph.name == "fun2":
- found = True
- inputcells = graph.startblock.inputargs
- assert len(inputcells) == 1
- assert isinstance(a.bindings[inputcells[0]], annmodel.SomeInteger)
- assert found
+ assert not hasattr(s, 'const')
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list