From 88684f49b6771e44950158a060a1bdb149fd2ee8 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 27 Sep 2024 13:16:41 -0400 Subject: [PATCH] Small refactor to jump position --- dust-lang/src/parser/mod.rs | 10 ++++------ dust-lang/src/parser/tests.rs | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/dust-lang/src/parser/mod.rs b/dust-lang/src/parser/mod.rs index 4714fc2..da53ee8 100644 --- a/dust-lang/src/parser/mod.rs +++ b/dust-lang/src/parser/mod.rs @@ -752,7 +752,7 @@ impl<'src> Parser<'src> { ); } - let jump_position = if matches!( + if matches!( self.chunk.get_last_n_operations(), [ Some(Operation::LoadBoolean), @@ -760,13 +760,11 @@ impl<'src> Parser<'src> { Some(Operation::Jump) ] ) { + self.chunk.pop_instruction(self.current_position)?; self.chunk.pop_instruction(self.current_position)?; self.chunk.pop_instruction(self.current_position)?; self.decrement_register()?; - self.chunk.pop_instruction(self.current_position)?.1 - } else { - self.current_position - }; + } let jump_start = self.chunk.len(); @@ -791,7 +789,7 @@ impl<'src> Parser<'src> { self.chunk.insert_instruction( jump_start, Instruction::jump(jump_distance as u8, true), - jump_position, + self.current_position, ); if self.allow(TokenKind::Else)? { diff --git a/dust-lang/src/parser/tests.rs b/dust-lang/src/parser/tests.rs index 84a3b34..c01c1f4 100644 --- a/dust-lang/src/parser/tests.rs +++ b/dust-lang/src/parser/tests.rs @@ -191,7 +191,7 @@ fn equality_assignment_long() { .set_c_is_constant(), Span(13, 15) ), - (Instruction::jump(1, true), Span(13, 15)), + (Instruction::jump(1, true), Span(27, 31)), (Instruction::load_boolean(0, true, false), Span(20, 24)), (Instruction::load_boolean(0, false, false), Span(34, 39)), (Instruction::define_local(0, 0, false), Span(4, 5)), @@ -241,7 +241,7 @@ fn if_expression() { .set_c_is_constant(), Span(5, 7) ), - (Instruction::jump(1, true), Span(5, 7)), + (Instruction::jump(1, true), Span(15, 15)), (Instruction::load_constant(0, 2, false), Span(12, 13)), ], vec![Value::integer(1), Value::integer(1), Value::integer(2)], @@ -264,7 +264,7 @@ fn if_else_expression() { .set_c_is_constant(), Span(5, 7) ), - (Instruction::jump(1, true), Span(5, 7)), + (Instruction::jump(1, true), Span(16, 20)), (Instruction::load_constant(0, 2, true), Span(12, 13)), (Instruction::load_constant(0, 3, false), Span(23, 24)), ],