From 89573e81b93ba4c893aa380385d35f7cf089ec98 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 18 Sep 2024 08:24:57 -0400 Subject: [PATCH] Fix bugs in binary parsing --- dust-lang/src/parser/mod.rs | 6 +++--- dust-lang/src/parser/tests.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dust-lang/src/parser/mod.rs b/dust-lang/src/parser/mod.rs index 90871bd..8f89591 100644 --- a/dust-lang/src/parser/mod.rs +++ b/dust-lang/src/parser/mod.rs @@ -313,7 +313,7 @@ impl<'src> Parser<'src> { _ => { push_back_left = true; - self.current_register + left_instruction.destination() } }; @@ -348,7 +348,7 @@ impl<'src> Parser<'src> { _ => { push_back_right = true; - self.current_register + right_instruction.destination() } }; @@ -573,7 +573,7 @@ impl<'src> Parser<'src> { }; let has_semicolon = self.allow(TokenKind::Semicolon)?; - if (!has_semicolon || is_expression) && self.is_eof() { + if (!has_semicolon && is_expression) && self.is_eof() { let end = self.previous_position.1; self.emit_instruction(Instruction::r#return(), Span(start, end)); diff --git a/dust-lang/src/parser/tests.rs b/dust-lang/src/parser/tests.rs index eccf2f6..e4501c6 100644 --- a/dust-lang/src/parser/tests.rs +++ b/dust-lang/src/parser/tests.rs @@ -2,6 +2,26 @@ use crate::Local; use super::*; +#[test] +fn list() { + let source = "[1, 2, 3]"; + + assert_eq!( + parse(source), + Ok(Chunk::with_data( + vec![ + (Instruction::load_constant(0, 0), Span(1, 2)), + (Instruction::load_constant(1, 1), Span(4, 5)), + (Instruction::load_constant(2, 2), Span(7, 8)), + (Instruction::load_list(3, 3), Span(0, 9)), + (Instruction::r#return(), Span(0, 9)), + ], + vec![Value::integer(1), Value::integer(2), Value::integer(3),], + vec![] + )), + ); +} + #[test] fn block_scope() { let source = "