1
0

Fix bugs in binary parsing

This commit is contained in:
Jeff 2024-09-18 08:24:57 -04:00
parent fa4c2d48a3
commit 89573e81b9
2 changed files with 23 additions and 3 deletions

View File

@ -313,7 +313,7 @@ impl<'src> Parser<'src> {
_ => { _ => {
push_back_left = true; push_back_left = true;
self.current_register left_instruction.destination()
} }
}; };
@ -348,7 +348,7 @@ impl<'src> Parser<'src> {
_ => { _ => {
push_back_right = true; 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)?; 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; let end = self.previous_position.1;
self.emit_instruction(Instruction::r#return(), Span(start, end)); self.emit_instruction(Instruction::r#return(), Span(start, end));

View File

@ -2,6 +2,26 @@ use crate::Local;
use super::*; 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] #[test]
fn block_scope() { fn block_scope() {
let source = " let source = "