From 71de5645e1a1ea16ea459b58c84b747fda5f8af8 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sun, 5 Nov 2023 00:52:29 +0000 Subject: [PATCH] fix: resolve another wrap crash issue --- compiler/src/compiler.rs | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 9019fccc..28cd725d 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -867,15 +867,14 @@ impl<'id> CompilationOutputs<'id> { if wrapped.flags.is_callback() { // make sure only one remains a callback wrapped.flags = wrapped.flags.with_is_callback(false); - let new_flags = wrapped.flags.with_is_callback(true); - - // the game crashes when parameter names are not aligned in callback methods - let from_params = pool[wrapped_idx].parameters.clone(); - let to_params = pool[last_wrapper_idx].parameters.clone(); - pool[last_wrapper_idx].flags = new_flags; - for (&from, &to) in from_params.iter().zip(&to_params) { - pool.rename(to, pool.def_name_idx(from).unwrap()); - } + pool[last_wrapper_idx].flags = wrapped.flags.with_is_callback(true); + } + + // the game crashes when parameter names are not aligned sometimes + let from_params = pool[wrapped_idx].parameters.clone(); + let to_params = pool[last_wrapper_idx].parameters.clone(); + for (&from, &to) in from_params.iter().zip(&to_params) { + pool.rename(to, pool.def_name_idx(from).unwrap()); } Self::remap_locals(last_wrapper_idx, wrapped_idx, pool); @@ -1028,27 +1027,12 @@ impl<'id> CompilationOutputs<'id> { mapped_locals.insert(local_idx, pool.add_definition(local)); } - let params = pool[target].parameters.clone(); - let mut mapped_params = HashMap::new(); - for param_idx in params { - let mut param = pool.definition(param_idx).unwrap().clone(); - param.parent = proxy.cast(); - mapped_params.insert(param_idx, pool.add_definition(param)); - } - let fun = &mut pool[target]; fun.locals = mapped_locals.values().copied().collect(); - fun.parameters = mapped_params.values().copied().collect(); for instr in &mut fun.code.0 { - match instr { - Instr::Local(local) => { - *instr = Instr::Local(*mapped_locals.get(local).expect("mapped local should exist")); - } - Instr::Param(param) => { - *instr = Instr::Param(*mapped_params.get(param).expect("mapped local should exist")); - } - _ => {} + if let Instr::Local(local) = instr { + *instr = Instr::Local(*mapped_locals.get(local).expect("mapped local should exist")); } } }