[BACKEND] Optimize script interpreter

This commit is contained in:
Jesse Bannon 2025-11-27 01:38:26 -08:00
parent 24e71ce733
commit b0055d59da

View file

@ -58,26 +58,28 @@ class CustomFunction(Function, NamedCustomFunction):
# Should be validated in the Script # Should be validated in the Script
raise UNREACHABLE raise UNREACHABLE
resolved_variables_with_args = copy.deepcopy(resolved_variables) function_args: List[FunctionArgument] = []
for i, arg in enumerate(resolved_args): for i, arg in enumerate(resolved_args):
function_arg = FunctionArgument.from_idx(idx=i, custom_function_name=self.name) function_arg = FunctionArgument.from_idx(idx=i, custom_function_name=self.name)
if function_arg in resolved_variables_with_args: if function_arg in resolved_variables:
# function args should always be unique since they are only defined once # function args should always be unique since they are only defined once
# in the custom function as %custom_function_name___idx # in the custom function as %custom_function_name___idx
# and returned as a set from each custom function. # and returned as a set from each custom function.
raise UNREACHABLE raise UNREACHABLE
resolved_variables_with_args[function_arg] = arg resolved_variables[function_arg] = arg
function_args.append(function_arg)
return custom_functions[self.name].resolve( out = custom_functions[self.name].resolve(
resolved_variables=resolved_variables_with_args, resolved_variables=resolved_variables,
custom_functions=custom_functions, custom_functions=custom_functions,
) )
# Implies the custom function does not exist. This should have for function_arg in function_args:
# been checked in the parser with del resolved_variables[function_arg]
raise UNREACHABLE
return out
class BuiltInFunction(Function, BuiltInFunctionType): class BuiltInFunction(Function, BuiltInFunctionType):