[pypy-svn] rev 2470 - in pypy/trunk/src/pypy/annotation: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Dec 18 10:44:20 CET 2003
Author: arigo
Date: Thu Dec 18 10:44:20 2003
New Revision: 2470
Modified:
pypy/trunk/src/pypy/annotation/annset.py
pypy/trunk/src/pypy/annotation/model.py
pypy/trunk/src/pypy/annotation/test/test_annset.py
Log:
Added better support for constants.
Modified: pypy/trunk/src/pypy/annotation/annset.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/annset.py (original)
+++ pypy/trunk/src/pypy/annotation/annset.py Thu Dec 18 10:44:20 2003
@@ -1,6 +1,6 @@
from __future__ import generators
import types
-from model import Annotation, SomeValue, QueryArgument, ANN
+from model import Annotation, SomeValue, QueryArgument, ANN, ConstPredicate
from model import immutable_types, blackholevalue, basicannotations
QUERYARG = QueryArgument()
@@ -96,6 +96,15 @@
else:
return None
+ def queryconstant(self, cell):
+ "Return the list of all 'x' such that ANN.constant(x)[cell] is set."
+ cell = self.normalized(cell)
+ result = []
+ for ann in self.annlist:
+ if isinstance(ann.predicate, ConstPredicate) and ann.args[0] is cell:
+ result.append(ann.predicate.value)
+ return result
+
def record(self, recfunc, *args):
""" invoke the given 'recording' function by passing it a new
Recorder instance and letting it use its modification API. This API will
@@ -260,6 +269,11 @@
if knowntype in immutable_types:
self.set(ANN.immutable[someval])
+ def newconstant(self, value):
+ cell = SomeValue()
+ self.set(ANN.constant(value)[cell])
+ return cell
+
'''
class XXXTransaction:
"""A transaction contains methods to look for annotations in the
Modified: pypy/trunk/src/pypy/annotation/model.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/model.py (original)
+++ pypy/trunk/src/pypy/annotation/model.py Thu Dec 18 10:44:20 2003
@@ -103,3 +103,7 @@
basicannotations.append(ANN.type[_val, _tval])
basicannotations.append(ANN.constant(_type)[_tval])
basicannotations.append(ANN.immutable[_val])
+
+# 'any immutable value'
+immutablevalue = SomeValue()
+basicannotations.append(ANN.immutable[immutablevalue])
Modified: pypy/trunk/src/pypy/annotation/test/test_annset.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/test/test_annset.py (original)
+++ pypy/trunk/src/pypy/annotation/test/test_annset.py Thu Dec 18 10:44:20 2003
@@ -88,6 +88,23 @@
clist = a.query(ANN.constant(42)[QUERYARG])
self.assertEquals(clist, [c1])
+ def test_newconstant(self):
+ a = AnnotationSet([])
+ def f(rec):
+ return rec.newconstant(42)
+ c = a.record(f)
+ self.assertSameSet(a, [ANN.constant(42)[c]])
+
+ def test_queryconstant(self):
+ lst = [
+ ANN.constant(42)[c1],
+ ]
+ a = AnnotationSet(lst)
+ vlist = a.queryconstant(c1)
+ self.assertEquals(vlist, [42])
+ vlist = a.queryconstant(c2)
+ self.assertEquals(vlist, [])
+
def test_query_blackholevalue(self):
lst = [
ANN.add[c1, c3, c2],
More information about the Pypy-commit
mailing list