Author: Armin Rigo <[email protected]>
Branch: partial-virtualizable
Changeset: r44324:40e43c0fdb55
Date: 2011-05-20 13:22 +0200
http://bitbucket.org/pypy/pypy/changeset/40e43c0fdb55/
Log: Add a test checking that the code generated by
compile_tmp_callback() behaves correctly.
diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -650,6 +650,7 @@
raise metainterp_sd.ExitFrameWithExceptionRef(cpu, exception)
propagate_exception_descr = PropagateExceptionDescr()
+_compile_bogus_code = False # for test_compile_tmp_callback_and_using_it
def compile_tmp_callback(cpu, jitdriver_sd, greenboxes, redboxes,
memory_manager=None):
@@ -691,6 +692,11 @@
ResOperation(rop.FINISH, finishargs, None, descr=jd.portal_finishtoken)
]
operations[1].setfailargs([])
+ if _compile_bogus_code: # testing only
+ operations.insert(0, ResOperation(rop.INT_FLOORDIV,
+ [history.ConstInt(42),
+ history.ConstInt(0)],
+ history.BoxInt()))
operations = get_deep_immutable_oplist(operations)
cpu.compile_loop(inputargs, operations, loop_token, log=False)
if memory_manager is not None: # for tests
diff --git a/pypy/jit/metainterp/test/test_recursive.py
b/pypy/jit/metainterp/test/test_recursive.py
--- a/pypy/jit/metainterp/test/test_recursive.py
+++ b/pypy/jit/metainterp/test/test_recursive.py
@@ -655,8 +655,9 @@
i = 1
while 1:
driver.jit_merge_point(codeno=codeno, i=i, frame=frame)
+ assert frame.j >= 100
if (i >> 1) == 1:
- if frame.j == 0:
+ if frame.j == 100:
return
portal(2, Frame(frame.j - 1))
elif i == 5:
@@ -665,7 +666,7 @@
driver.can_enter_jit(codeno=codeno, i=i, frame=frame)
def main(codeno, j):
- portal(codeno, Frame(j))
+ portal(codeno, Frame(j + 100))
main(2, 5)
@@ -695,6 +696,35 @@
print redirected
assert redirected.keys() == trace
+ def test_compile_tmp_callback_and_using_it(self):
+ # unlike the previous tests, this test calls compile_tmp_callback()
+ # and actually invokes the compiled temporary callback
+ driver = JitDriver(greens = ['codeno'], reds = ['i'])
+
+ def main(codeno):
+ i = 1
+ while i < 7:
+ driver.jit_merge_point(codeno=codeno, i=i)
+ if codeno == 1:
+ return 42
+ if i >= 3:
+ main(1)
+ i += 1
+ return i
+
+ from pypy.rpython.llinterp import LLException
+ from pypy.jit.metainterp import compile
+ compile._compile_bogus_code = True
+ try:
+ e = py.test.raises(LLException, self.meta_interp,
+ main, [2], inline=True)
+ finally:
+ compile._compile_bogus_code = False
+ assert e.value.args[2][0] is ZeroDivisionError
+
+ res = self.meta_interp(main, [2], inline=True)
+ assert res == 7
+
def test_directly_call_assembler_return(self):
driver = JitDriver(greens = ['codeno'], reds = ['i', 'k'],
get_printable_location = lambda codeno :
str(codeno))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit