Commits

Anonymous committed 38cf806

moved op_assert and op_assert_not to interp-level.

  • Participants
  • Parent commits 3c674aa

Comments (0)

Files changed (2)

File pypy/module/_sre/app_sre.py

             repeat.count = count - 1
             ctx.state.string_position = ctx.string_position
         yield True
-
-    def op_assert(self, ctx):
-        # assert subpattern
-        # <ASSERT> <skip> <back> <pattern>
-        #self._log(ctx, "ASSERT", ctx.peek_code(2))
-        ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
-        if ctx.state.string_position < 0:
-            ctx.has_matched = NOT_MATCHED
-            yield True
-        child_context = ctx.push_new_context(3)
-        yield False
-        if child_context.has_matched == MATCHED:
-            ctx.skip_code(ctx.peek_code(1) + 1)
-        else:
-            ctx.has_matched = NOT_MATCHED
-        yield True
-
-    def op_assert_not(self, ctx):
-        # assert not subpattern
-        # <ASSERT_NOT> <skip> <back> <pattern>
-        #self._log(ctx, "ASSERT_NOT", ctx.peek_code(2))
-        ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
-        if ctx.state.string_position >= 0:
-            child_context = ctx.push_new_context(3)
-            yield False
-            if child_context.has_matched == MATCHED:
-                ctx.has_matched = NOT_MATCHED
-                yield True
-        ctx.skip_code(ctx.peek_code(1) + 1)
-        yield True
         
     def unknown(self, ctx):
         #self._log(ctx, "UNKNOWN", ctx.peek_code())

File pypy/module/_sre/interp_sre.py

         if not has_finished:
             context.resume_at_opcode = opcode
             return context.UNDECIDED
+        context.resume_at_opcode = -1
     if context.has_matched == context.UNDECIDED:
         context.has_matched = context.NOT_MATCHED
     return context.has_matched
     # <GROUPREF_IGNORE> <zero-based group index>
     return general_op_groupref(space, ctx, ignore=True)
 
-def op_groupref_exists(self, ctx):
+def op_groupref_exists(space, ctx):
     # <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ...
     group_start, group_end = ctx.state.get_marks(ctx.peek_code(1))
     if group_start == -1 or group_end == -1 or group_end < group_start:
         ctx.skip_code(3)
     return True
 
+def op_assert(space, ctx):
+    # assert subpattern
+    # <ASSERT> <skip> <back> <pattern>
+    if not ctx.is_resumed():
+        ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
+        if ctx.state.string_position < 0:
+            ctx.has_matched = ctx.NOT_MATCHED
+            return True
+        ctx.push_new_context(3)
+        return False
+    else:
+        if ctx.child_context.has_matched == ctx.MATCHED:
+            ctx.skip_code(ctx.peek_code(1) + 1)
+        else:
+            ctx.has_matched = ctx.NOT_MATCHED
+        return True
+
+def op_assert_not(space, ctx):
+    # assert not subpattern
+    # <ASSERT_NOT> <skip> <back> <pattern>
+    if not ctx.is_resumed():
+        ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
+        if ctx.state.string_position >= 0:
+            ctx.push_new_context(3)
+            return False
+    else:
+        if ctx.child_context.has_matched == ctx.MATCHED:
+            ctx.has_matched = ctx.NOT_MATCHED
+            return True
+    ctx.skip_code(ctx.peek_code(1) + 1)
+    return True
+
 def count_repetitions(space, ctx, maxcount):
     """Returns the number of repetitions of a single item, starting from the
     current string position. The code pointer is expected to point to a
 opcode_dispatch_table = [
     op_failure, op_success,
     op_any, op_any_all,
-    None, None, #ASSERT, ASSERT_NOT,
+    op_assert, op_assert_not,
     op_at,
     op_branch,
     None, #CALL,