|
@@ -355,8 +355,6 @@ class ModelverseJit(object):
|
|
|
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
|
|
@@ -408,9 +406,7 @@ class ModelverseJit(object):
|
|
|
(function_name, parameter_list, param_dict, body_param_dict, constructed_body)])]
|
|
|
|
|
|
# Convert the function definition to Python code, and compile it.
|
|
|
- exec(str(constructed_function), self.jit_globals)
|
|
|
- # Extract the compiled function from the JIT global state.
|
|
|
- compiled_function = self.jit_globals[function_name]
|
|
|
+ compiled_function = self.jit_define_function(function_name, constructed_function)
|
|
|
|
|
|
if self.jit_success_log_function is not None:
|
|
|
self.jit_success_log_function(
|
|
@@ -421,6 +417,21 @@ class ModelverseJit(object):
|
|
|
|
|
|
raise primitive_functions.PrimitiveFinished(compiled_function)
|
|
|
|
|
|
+ def jit_define_function(self, function_name, function_def):
|
|
|
+ """Converts the given tree-IR function definition to Python code, defines it,
|
|
|
+ and extracts the resulting function."""
|
|
|
+ # The comment below makes pylint shut up about our (hopefully benign) use of exec here.
|
|
|
+ # pylint: disable=I0011,W0122
|
|
|
+
|
|
|
+ # Convert the function definition to Python code, and compile it.
|
|
|
+ exec(str(function_def), self.jit_globals)
|
|
|
+ # Extract the compiled function from the JIT global state.
|
|
|
+ return self.jit_globals[function_name]
|
|
|
+
|
|
|
+ def jit_delete_function(self, function_name):
|
|
|
+ """Deletes the function with the given function name."""
|
|
|
+ del self.jit_globals[function_name]
|
|
|
+
|
|
|
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
|