|
@@ -3,11 +3,15 @@ import modelverse_jit.tree_ir as tree_ir
|
|
|
import modelverse_jit.runtime as jit_runtime
|
|
|
import keyword
|
|
|
|
|
|
+# Import JitCompilationFailedException because it used to be defined
|
|
|
+# in this module.
|
|
|
+JitCompilationFailedException = jit_runtime.JitCompilationFailedException
|
|
|
+
|
|
|
KWARGS_PARAMETER_NAME = "kwargs"
|
|
|
"""The name of the kwargs parameter in jitted functions."""
|
|
|
|
|
|
-INTERPRET_FUNCTION_NAME = "__interpret_function"
|
|
|
-"""The name of the '__interpret_function' function, in the jitted function scope."""
|
|
|
+CALL_FUNCTION_NAME = "__call_function"
|
|
|
+"""The name of the '__call_function' function, in the jitted function scope."""
|
|
|
|
|
|
def get_parameter_names(compiled_function):
|
|
|
"""Gets the given compiled function's parameter names."""
|
|
@@ -79,10 +83,6 @@ def optimize_tree_ir(instruction):
|
|
|
"""Optimizes an IR tree."""
|
|
|
return map_and_simplify_generator(expand_constant_read, instruction)
|
|
|
|
|
|
-class JitCompilationFailedException(Exception):
|
|
|
- """A type of exception that is raised when the jit fails to compile a function."""
|
|
|
- pass
|
|
|
-
|
|
|
class ModelverseJit(object):
|
|
|
"""A high-level interface to the modelverse JIT compiler."""
|
|
|
def __init__(self, max_instructions=None, compiled_function_lookup=None):
|
|
@@ -92,7 +92,7 @@ class ModelverseJit(object):
|
|
|
self.jitted_parameters = {}
|
|
|
self.jit_globals = {
|
|
|
'PrimitiveFinished' : primitive_functions.PrimitiveFinished,
|
|
|
- INTERPRET_FUNCTION_NAME : jit_runtime.interpret_function
|
|
|
+ CALL_FUNCTION_NAME : jit_runtime.call_function
|
|
|
}
|
|
|
self.jit_count = 0
|
|
|
self.max_instructions = max_instructions
|
|
@@ -938,15 +938,15 @@ class AnalysisState(object):
|
|
|
except primitive_functions.PrimitiveFinished as ex:
|
|
|
named_args = ex.result
|
|
|
|
|
|
- # Call the __interpret_function function to run the interpreter, like so:
|
|
|
+ # Call the __call_function function to run the interpreter, like so:
|
|
|
#
|
|
|
- # __interpret_function(function_id, { first_param_name : first_param_val, ... }, **kwargs)
|
|
|
+ # __call_function(function_id, { first_param_name : first_param_val, ... }, **kwargs)
|
|
|
#
|
|
|
dict_literal = tree_ir.DictionaryLiteralInstruction(
|
|
|
[(tree_ir.LiteralInstruction(key), val) for key, val in named_args])
|
|
|
raise primitive_functions.PrimitiveFinished(
|
|
|
tree_ir.JitCallInstruction(
|
|
|
- tree_ir.LoadGlobalInstruction(INTERPRET_FUNCTION_NAME),
|
|
|
+ tree_ir.LoadGlobalInstruction(CALL_FUNCTION_NAME),
|
|
|
[('function_id', func_val), ('named_arguments', dict_literal)],
|
|
|
tree_ir.LoadLocalInstruction(KWARGS_PARAMETER_NAME)))
|
|
|
|