[pypy-svn] r21966 - in pypy/dist/pypy/rpython/l3interp: . test
mwh at codespeak.net
mwh at codespeak.net
Wed Jan 11 18:43:12 CET 2006
Author: mwh
Date: Wed Jan 11 18:43:11 2006
New Revision: 21966
Modified:
pypy/dist/pypy/rpython/l3interp/l3interp.py
pypy/dist/pypy/rpython/l3interp/test/test_convert.py
Log:
some more convertgraph tests and one more operation.
Modified: pypy/dist/pypy/rpython/l3interp/l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/l3interp.py (original)
+++ pypy/dist/pypy/rpython/l3interp/l3interp.py Wed Jan 11 18:43:11 2006
@@ -157,6 +157,13 @@
y = self.getint()
self.stack_int.append(x + y)
+ def op_int_is_true(self):
+ x = self.getint()
+ if x:
+ self.stack_int.append(1)
+ else:
+ self.stack_int.append(0)
+
def op_direct_call(self):
block = self.block
assert block.called_graphs is not None
Modified: pypy/dist/pypy/rpython/l3interp/test/test_convert.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/test/test_convert.py (original)
+++ pypy/dist/pypy/rpython/l3interp/test/test_convert.py Wed Jan 11 18:43:11 2006
@@ -2,14 +2,42 @@
from pypy.rpython.l3interp import convertgraph, l3interp
from pypy.translator.translator import TranslationContext
-def test_convert_add():
- def f(x):
- return x + 4
+def l3ify(f, inputargs):
t = TranslationContext()
- t.buildannotator().build_types(f, [int])
+ t.buildannotator().build_types(f, inputargs)
t.buildrtyper().specialize()
conv = convertgraph.LL2L3Converter()
- l3graph = conv.convert_graph(t.graphs[0])
+ return conv.convert_graph(t.graphs[0])
+
+
+def test_convert_add():
+ def f(x):
+ return x + 4
+ l3graph = l3ify(f, [int])
result = l3interp.l3interpret(l3graph, [42], [], [])
assert isinstance(result, l3interp.L3Integer)
assert result.intval == 46
+
+def test_convert_simple():
+ def f():
+ return 3 + 4
+ l3graph = l3ify(f, [])
+ result = l3interp.l3interpret(l3graph, [], [], [])
+ assert isinstance(result, l3interp.L3Integer)
+ assert result.intval == 7
+
+def test_convert_branch():
+ def f(x):
+ if x:
+ return x
+ return 1
+ l3graph = l3ify(f, [int])
+ result = l3interp.l3interpret(l3graph, [2], [], [])
+ assert isinstance(result, l3interp.L3Integer)
+ assert result.intval == 2
+
+ result = l3interp.l3interpret(l3graph, [0], [], [])
+ assert isinstance(result, l3interp.L3Integer)
+ assert result.intval == 1
+
+
More information about the Pypy-commit
mailing list