[pypy-commit] pypy stmgc-c7: Fix: handle optional operation 'guard_not_invalidated?' as the last one in the list

arigo noreply at buildbot.pypy.org
Fri Mar 27 18:42:03 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r76596:9a7d81e36d6f
Date: 2015-03-27 18:42 +0100
http://bitbucket.org/pypy/pypy/changeset/9a7d81e36d6f/

Log:	Fix: handle optional operation 'guard_not_invalidated?' as the last
	one in the list

diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py
--- a/pypy/module/pypyjit/test_pypy_c/model.py
+++ b/pypy/module/pypyjit/test_pypy_c/model.py
@@ -273,6 +273,7 @@
     @classmethod
     def parse_ops(cls, src):
         ops = [cls.parse_op(line) for line in src.splitlines()]
+        ops.append(('--end--', None, [], '...', True))
         return [op for op in ops if op is not None]
 
     @classmethod
@@ -423,6 +424,10 @@
             raise InvalidMatch(message, frame=sys._getframe(1))
 
     def match_op(self, op, (exp_opname, exp_res, exp_args, exp_descr, _)):
+        if exp_opname == '--end--':
+            self._assert(op == '--end--', 'got more ops than expected')
+            return
+        self._assert(op != '--end--', 'got less ops than expected')
         self._assert(op.name == exp_opname, "operation mismatch")
         self.match_var(op.res, exp_res)
         if exp_args[-1:] == ['...']:      # exp_args ends with '...'
@@ -435,18 +440,15 @@
         self.match_descr(op.descr, exp_descr)
 
 
-    def _next_op(self, iter_ops, assert_raises=False, ignore_ops=set()):
+    def _next_op(self, iter_ops, ignore_ops=set()):
         try:
             while True:
                 op = iter_ops.next()
                 if op.name not in ignore_ops:
                     break
         except StopIteration:
-            self._assert(assert_raises, "not enough operations")
-            return
-        else:
-            self._assert(not assert_raises, "operation list too long")
-            return op
+            return '--end--'
+        return op
 
     def try_match(self, op, exp_op):
         try:
@@ -513,16 +515,17 @@
                     continue
                 else:
                     op = self._next_op(iter_ops, ignore_ops=ignore_ops)
-                self.match_op(op, exp_op)
-            except InvalidMatch, e:
-                if type(exp_op) is not str and exp_op[4] is False:    # optional operation
+                try:
+                    self.match_op(op, exp_op)
+                except InvalidMatch:
+                    if type(exp_op) is str or exp_op[4] is not False:
+                        raise
+                    #else: optional operation
                     iter_ops.revert_one()
                     continue       # try to match with the next exp_op
+            except InvalidMatch, e:
                 e.opindex = iter_ops.index - 1
                 raise
-        #
-        # make sure we exhausted iter_ops
-        self._next_op(iter_ops, assert_raises=True, ignore_ops=ignore_ops)
 
     def match(self, expected_src, ignore_ops=[]):
         def format(src, opindex=None):
@@ -565,9 +568,9 @@
         return self
     def next(self):
         index = self.index
-        if index == len(self.sequence):
+        self.index = index + 1
+        if index >= len(self.sequence):
             raise StopIteration
-        self.index = index + 1
         return self.sequence[index]
     def revert_one(self):
         self.index -= 1


More information about the pypy-commit mailing list