Sfoglia il codice sorgente

Define a DEBUG_INFO request in the request handler

jonathanvdc 8 anni fa
parent
commit
8ac72c4e9e
1 ha cambiato i file con 13 aggiunte e 1 eliminazioni
  1. 13 1
      kernel/modelverse_kernel/request_handler.py

+ 13 - 1
kernel/modelverse_kernel/request_handler.py

@@ -8,6 +8,8 @@ class GeneratorStackEntry(object):
     """An entry in the generator stack of a request handles."""
     def __init__(self, generator):
         self.generator = generator
+        self.function_name = None
+        self.source_map = None
         self.pending_requests = None
         self.finished_requests = True
         self.replies = []
@@ -54,7 +56,8 @@ class RequestHandler(object):
             'TAIL_CALL_KWARGS' : self.execute_tail_call_kwargs,
             'TRY' : self.execute_try,
             'CATCH' : self.execute_catch,
-            'END_TRY' : self.execute_end_try
+            'END_TRY' : self.execute_end_try,
+            'DEBUG_INFO' : self.execute_debug_info
         }
 
     def is_active(self):
@@ -339,3 +342,12 @@ class RequestHandler(object):
         # Everything seems to be in order. Pop the exception handler.
         self.exception_handlers.pop()
 
+    def execute_debug_info(self, request_args):
+        """Executes a DEBUG_INFO-request with the given argument list."""
+        # DEBUG_INFO updates the function name and source map for the top-of-stack generator.
+        # These two things allow us to unwind the stack neatly if an unhandled exception is
+        # encountered.
+        # Format: ("DEBUG_INFO", [function_name, source_map])
+        top_entry = self.generator_stack[-1]
+        top_entry.function_name, top_entry.source_map = request_args
+