Jelajahi Sumber

Refactor jit_compile into three functions

jonathanvdc 8 tahun lalu
induk
melakukan
2bcaa5a199
1 mengubah file dengan 17 tambahan dan 5 penghapusan
  1. 17 5
      kernel/modelverse_jit/jit.py

+ 17 - 5
kernel/modelverse_jit/jit.py

@@ -285,10 +285,9 @@ class ModelverseJit(object):
         self.bytecode_graphs[body_id] = result
         raise primitive_functions.PrimitiveFinished(result)
 
-    def jit_compile(self, user_root, body_id, suggested_name=None):
-        """Tries to jit the function defined by the given entry point id and parameter list."""
-        # The comment below makes pylint shut up about our (hopefully benign) use of exec here.
-        # pylint: disable=I0011,W0122
+    def check_jittable(self, body_id, suggested_name=None):
+        """Checks if the function with the given body id is obviously non-jittable. If it's
+           non-jittable, then a `JitCompilationFailedException` exception is thrown."""
         if body_id is None:
             raise ValueError('body_id cannot be None')
         elif body_id in self.jitted_entry_points:
@@ -308,9 +307,15 @@ class ModelverseJit(object):
                     '' if suggested_name is None else "'" + suggested_name + "'",
                     body_id))
 
+    def jit_recompile(self, user_root, body_id, function_name):
+        """Replaces the function with the given name by compiling the bytecode at the given
+           body id."""
+        # The comment below makes pylint shut up about our (hopefully benign) use of exec here.
+        # pylint: disable=I0011,W0122
+        self.check_jittable(body_id, function_name)
+
         # Generate a name for the function we're about to analyze, and pretend that
         # it already exists. (we need to do this for recursive functions)
-        function_name = self.generate_function_name(body_id, suggested_name)
         self.jitted_entry_points[body_id] = function_name
         self.jit_globals[function_name] = None
 
@@ -400,3 +405,10 @@ class ModelverseJit(object):
             self.jit_code_log_function(constructed_function)
 
         raise primitive_functions.PrimitiveFinished(compiled_function)
+
+    def jit_compile(self, user_root, body_id, suggested_name=None):
+        """Tries to jit the function defined by the given entry point id and parameter list."""
+        # Generate a name for the function we're about to analyze, and pretend that
+        # it already exists. (we need to do this for recursive functions)
+        function_name = self.generate_function_name(body_id, suggested_name)
+        yield [("TAIL_CALL_ARGS", [self.jit_recompile, (user_root, body_id, function_name)])]