1
0

Pass tests

This commit is contained in:
Jeff 2024-09-19 18:07:11 -04:00
parent d4a8a65096
commit 31bb7eaffc
3 changed files with 15 additions and 5 deletions

View File

@ -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,
);

View File

@ -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> {

View File

@ -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]