Fix bugs in binary parsing
This commit is contained in:
parent
fa4c2d48a3
commit
89573e81b9
@ -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));
|
||||
|
@ -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 = "
|
||||
|
Loading…
Reference in New Issue
Block a user