fix recursive function calls leading to stack overflow

This commit is contained in:
Moritz Hölting 2025-03-15 00:20:40 +01:00
parent 7290806a2b
commit 8a9db43424
1 changed files with 10 additions and 10 deletions

View File

@ -334,9 +334,6 @@ impl Transpiler {
let statements = function_data.statements.clone(); let statements = function_data.statements.clone();
let commands =
self.transpile_function(&statements, program_identifier, &function_scope, handler)?;
let modified_name = function_data.annotations.get("deobfuscate").map_or_else( let modified_name = function_data.annotations.get("deobfuscate").map_or_else(
|| { || {
let hash_data = program_identifier.to_string() + "\0" + identifier_span.str(); let hash_data = program_identifier.to_string() + "\0" + identifier_span.str();
@ -370,6 +367,16 @@ impl Transpiler {
}, },
)?; )?;
let function_location = format!(
"{namespace}:{modified_name}",
namespace = function_data.namespace
);
function_path.set(function_location.clone()).unwrap();
let commands =
self.transpile_function(&statements, program_identifier, &function_scope, handler)?;
let namespace = self.datapack.namespace_mut(&function_data.namespace); let namespace = self.datapack.namespace_mut(&function_data.namespace);
if namespace.function(&modified_name).is_some() { if namespace.function(&modified_name).is_some() {
@ -384,19 +391,12 @@ impl Transpiler {
let function = namespace.function_mut(&modified_name); let function = namespace.function_mut(&modified_name);
function.get_commands_mut().extend(commands); function.get_commands_mut().extend(commands);
let function_location = format!(
"{namespace}:{modified_name}",
namespace = function_data.namespace
);
if function_data.annotations.contains_key("tick") { if function_data.annotations.contains_key("tick") {
self.datapack.add_tick(&function_location); self.datapack.add_tick(&function_location);
} }
if function_data.annotations.contains_key("load") { if function_data.annotations.contains_key("load") {
self.datapack.add_load(&function_location); self.datapack.add_load(&function_location);
} }
function_path.set(function_location.clone()).unwrap();
} }
let parameters = &function_data.parameters; let parameters = &function_data.parameters;