Author: Hakan Ardo <[email protected]>
Branch: jit-usable_retrace_3
Changeset: r60059:d86fb2edebc7
Date: 2013-01-13 18:19 +0100
http://bitbucket.org/pypy/pypy/changeset/d86fb2edebc7/

Log:    while loops

diff --git a/pypy/jit/metainterp/test/test_random_loops.py 
b/pypy/jit/metainterp/test/test_random_loops.py
--- a/pypy/jit/metainterp/test/test_random_loops.py
+++ b/pypy/jit/metainterp/test/test_random_loops.py
@@ -14,9 +14,16 @@
     def sub(self, other):
         return IntBox(self.value() - other.value())
 
+class UnknonwOpCode(Exception):
+    pass
+
 class RandomLoopBase(object):
     def check(self, bytecode, args=(0,0,0,0,0), **kwargs):
-        myjitdriver = JitDriver(greens = ['pc'], reds = ['a', 'b', 'c', 'd', 
'e', 'value', 'prev'])
+        offsets = self.offsets(bytecode)
+        def get_printable_location(pc):
+            return bytecode[pc]
+        myjitdriver = JitDriver(greens = ['pc'], reds = ['a', 'b', 'c', 'd', 
'e', 'value', 'prev'],
+                                get_printable_location=get_printable_location)
         def interpreter(_a, _b, _c, _d, _e):
             pc = 0
             value = prev = IntBox(0)
@@ -56,8 +63,14 @@
                     value = prev.add(value)
                 elif op == '-':
                     value = prev.sub(value)
+                elif op == '{':
+                    pass
+                elif op == '}':
+                    if value.value():
+                        pc -= offsets[pc]
+                        myjitdriver.can_enter_jit(pc=pc, a=a, b=b, c=c, d=d, 
e=e, value=value, prev=prev)
                 else:
-                    assert False
+                    raise UnknonwOpCode
 
                 prev = current
                 pc += 1
@@ -73,6 +86,18 @@
             assert res[var] == val
         return res
 
+    def offsets(self, bytecode):
+        offsets = [0] * len(bytecode)
+        stack = []
+        for pc, op in enumerate(bytecode):
+            if op in '{[(':
+                stack.append((pc, op))
+            elif op in ')]}':
+                start_pc, start_op = stack.pop()
+                assert start_op + op in ('()', '[]', '{}')
+                offsets[start_pc] = offsets[pc] = pc - start_pc
+        return offsets
+
 
 
 class BaseTests(RandomLoopBase):
@@ -82,5 +107,8 @@
         self.check('1a+A2b+B3c+C4d+D5e+E', [6,7,8,9,0], a=7, b=9, c=11, d=13, 
e=5)
         self.check('ea+Eeb+Eec+Eed+E', [6,7,8,9,0], a=6, b=7, c=8, d=9, e=30)
 
+    def test_loop(self):
+        self.check('0A9B{ab+Ab1-Bb}', a=45)
+
 class TestLLtype(BaseTests, LLJitMixin):
     pass
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to