Commits

Devin Jeanpierre committed 115718c

Extra debugger facilities

  • Participants
  • Parent commits 515139a

Comments (0)

Files changed (2)

File re0/test/test_debug.py

     def __init__(self, mocklist):
         self.mocklist = mocklist
     
+    def match_begin(self, bytecode, in_s, sp):
+        self.mocklist.append(('match_begin', in_s, sp))
+    
     def spawn_thread(self, thread):
         self.mocklist.append('spawned')
     
     def thread_matched(self, thread):
         self.mocklist.append('matched')
     
+    def threads_irrelevant(self, threads):
+        self.mocklist.append(('irrelevant', len(threads)))
+    
     def threadlist_replaced(self, old, new):
         self.mocklist.append(('threadlist-computed', old and len(old.threadlist), len(new.threadlist)))
 
         moves = []
         self.assertTrue(vm.pike_vm(bytecode, [0], debugger=MockDebugger(moves)))
         self.assertEqual(moves, [
+            ('match_begin', [0], 0),
             'spawned',
             ('seeked', 1),
             ('threadlist-computed', None, 1),
             'merged',
             ('threadlist-computed', 1, 1),
             'matched',
+            ('irrelevant', 0),
         ])
 
 if __name__ == '__main__':
         # saved is exactly like cox paper; too lazy to preallicate some list.
         # (Realistically, will I use array.array? Hmmm...)
         returned_saved = {}
+    
+    if debugger is not None:
+        debugger.match_begin(bytecode, in_s, sp)
+    
     # Thompson NFA handles input in lockstep;
     # current_states haven't received input yet,
     # processed_states have.
         current_states = next_states
         next_states = ThreadList(bytecode, sp + 1, in_s, debugger=debugger)
         
-        for thread in current_states:
+        for idx, thread in enumerate(current_states):
             pc, saved = thread
             op = bytecode[pc]
             if op.opcode in [CHAR, NOT_CHAR, IGNORE_CHAR, NOT_IGNORE_CHAR]:
                         next_states.add_thread(thread.increment())
                 
             elif op.opcode == MATCH:
+                best_match = saved # overwrite all previous matches
                 if debugger is not None:
                     debugger.thread_matched(thread)
-                best_match = saved # overwrite all previous matches
+                    debugger.threads_irrelevant(
+                        current_states.threadlist[idx+1:])
                 break # ignore all later (lower-priority) matches
                 # together, those lines mean that lower-priority matches are
                 # fine, but will always be overwritten by higher-priority