From d38abb73774981bfb8d1c476e11c58472b2a02f8 Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Tue, 4 Jul 2023 22:50:13 +1000 Subject: [PATCH] Collapse jump to jump --- valuescript_compiler/src/optimization/simplify_jumps.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/valuescript_compiler/src/optimization/simplify_jumps.rs b/valuescript_compiler/src/optimization/simplify_jumps.rs index 66e1f5f..fd519ad 100644 --- a/valuescript_compiler/src/optimization/simplify_jumps.rs +++ b/valuescript_compiler/src/optimization/simplify_jumps.rs @@ -67,7 +67,11 @@ fn simplify_jumps_fn(fn_: &mut Function) { // Instead of jumping to `end`, just end substitutions.insert(i, FnLine::Instruction(Instruction::End)); } - FnLine::Instruction(_) => {} // TODO: Collapse jump to jump + FnLine::Instruction(Instruction::Jmp(label_ref)) => { + // Instead of jumping to another jump, jump directly to where that one goes + substitutions.insert(i, FnLine::Instruction(Instruction::Jmp(label_ref.clone()))); + } + FnLine::Instruction(_) => {} FnLine::Label(_) | FnLine::Empty | FnLine::Comment(_) | FnLine::Release(_) => { panic!("Jump to non-instruction") }