From 31bb7eaffc1a4abbbf4d6abe89820884d4618bb2 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 19 Sep 2024 18:07:11 -0400 Subject: [PATCH] Pass tests --- dust-lang/src/parser/mod.rs | 11 ++++++++--- dust-lang/src/vm.rs | 4 +++- dust-lang/tests/operations.rs | 5 ++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/dust-lang/src/parser/mod.rs b/dust-lang/src/parser/mod.rs index e956826..ed0735a 100644 --- a/dust-lang/src/parser/mod.rs +++ b/dust-lang/src/parser/mod.rs @@ -478,6 +478,9 @@ impl<'src> Parser<'src> { ) -> Result<(), ParseError> { let token = self.current_token; let start_position = self.current_position; + + self.advance()?; + let local_index = self.parse_identifier_from(token, start_position)?; let is_mutable = self.chunk.get_local(local_index, start_position)?.mutable; @@ -516,11 +519,11 @@ impl<'src> Parser<'src> { start_position, ); } else { - self.increment_register()?; self.emit_instruction( Instruction::get_local(self.current_register, local_index), self.previous_position, ); + self.increment_register()?; } Ok(()) @@ -663,6 +666,8 @@ impl<'src> Parser<'src> { } }; + self.allow(TokenKind::Semicolon)?; + Ok(()) } @@ -742,7 +747,7 @@ impl<'src> Parser<'src> { if let Some(prefix_parser) = ParseRule::from(&self.current_token.kind()).prefix { log::trace!( - "Parsing \"{}\" with prefix parser at precedence {precedence}", + "Parsing \"{}\" as prefix at precedence {precedence}", self.current_token, ); @@ -754,7 +759,7 @@ impl<'src> Parser<'src> { while precedence <= infix_rule.precedence { if let Some(infix_parser) = infix_rule.infix { log::trace!( - "Parsing \"{}\" with infix parser at precedence {precedence}", + "Parsing \"{}\" as infix at precedence {precedence}", self.current_token, ); diff --git a/dust-lang/src/vm.rs b/dust-lang/src/vm.rs index 22975ba..d24b25a 100644 --- a/dust-lang/src/vm.rs +++ b/dust-lang/src/vm.rs @@ -303,7 +303,9 @@ impl Vm { } } - Ok(None) + let final_value = self.pop(Span(0, 0))?; + + Ok(Some(final_value)) } fn insert(&mut self, value: Value, index: u8, position: Span) -> Result<(), VmError> { diff --git a/dust-lang/tests/operations.rs b/dust-lang/tests/operations.rs index 4fb7417..5053870 100644 --- a/dust-lang/tests/operations.rs +++ b/dust-lang/tests/operations.rs @@ -2,7 +2,10 @@ use dust_lang::*; #[test] fn long_math() { - assert_eq!(run("1 + 2 * 3 - 4 / 2"), Ok(Some(Value::integer(5)))); + assert_eq!( + run("1 + 2 * 3 - 4 / 2"), + Ok(Some(Value::integer(2).into_reference())) + ); } #[test]