Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r76598:cada63adf489 Date: 2015-03-27 18:42 +0100 http://bitbucket.org/pypy/pypy/changeset/cada63adf489/
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 @@ -271,6 +271,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 @@ -403,6 +404,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 '...' @@ -415,18 +420,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: @@ -493,16 +495,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): @@ -545,9 +548,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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit