[pypy-svn] r65805 - pypy/branch/pyjitpl5/pypy/jit/metainterp/test

antocuni at codespeak.net antocuni at codespeak.net
Wed Jun 17 18:19:24 CEST 2009


Author: antocuni
Date: Wed Jun 17 18:19:24 2009
New Revision: 65805

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/oparser.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_oparser.py
Log:
add the possibility to specify your own prefix/boxclass pairs when parsing, in
addition to the standard 'i' for BoxInt and 'p' for BoxPtr/BoxObj



Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/oparser.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/oparser.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/oparser.py	Wed Jun 17 18:19:24 2009
@@ -48,12 +48,13 @@
             getattr(boxes, name).value = value
 
 class OpParser(object):
-    def __init__(self, descr, cpu, namespace, type_system):
+    def __init__(self, descr, cpu, namespace, type_system, boxkinds):
         self.descr = descr
         self.vars = {}
         self.cpu = cpu
         self.consts = namespace
         self.type_system = type_system
+        self.boxkinds = boxkinds or {}
 
     def box_for_var(self, elem):
         try:
@@ -67,7 +68,12 @@
             # pointer
             box = BoxPtr()
         else:
-            raise ParseError("Unknown variable type: %s" % elem)
+            for prefix, boxclass in self.boxkinds.iteritems():
+                if elem.startswith(prefix):
+                    box = boxclass()
+                    break
+            else:
+                raise ParseError("Unknown variable type: %s" % elem)
         _cache[elem] = box
         box._str = elem
         return box
@@ -196,5 +202,6 @@
         inpargs = self.parse_header_line(line[1:-1])
         return base_indent, inpargs
 
-def parse(descr, cpu=None, namespace={}, type_system='lltype'):
-    return OpParser(descr, cpu, namespace, type_system).parse()
+def parse(descr, cpu=None, namespace={}, type_system='lltype',
+          boxkinds=None):
+    return OpParser(descr, cpu, namespace, type_system, boxkinds).parse()

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_oparser.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_oparser.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_oparser.py	Wed Jun 17 18:19:24 2009
@@ -3,7 +3,7 @@
 
 from pypy.jit.metainterp.test.oparser import parse
 from pypy.jit.metainterp.resoperation import rop
-from pypy.jit.metainterp.history import AbstractDescr
+from pypy.jit.metainterp.history import AbstractDescr, BoxInt
 
 def test_basic_parse():
     x = """
@@ -93,3 +93,11 @@
     loop.setvalues(i0=32, i1=42)
     assert loop.inputargs[0].value == 32
     assert loop.operations[0].result.value == 42
+
+def test_boxkind():
+    x = """
+    [sum0]
+    """
+    loop = parse(x, None, {}, boxkinds={'sum': BoxInt})
+    b = loop.getboxes()
+    assert isinstance(b.sum0, BoxInt)



More information about the Pypy-commit mailing list