diff --git a/dust-lang/src/vm.rs b/dust-lang/src/vm.rs index d24b25a..3f96787 100644 --- a/dust-lang/src/vm.rs +++ b/dust-lang/src/vm.rs @@ -16,6 +16,7 @@ pub fn run(source: &str) -> Result, DustError> { pub struct Vm { chunk: Chunk, ip: usize, + last_modified: u8, register_stack: Vec>, } @@ -26,6 +27,7 @@ impl Vm { Self { chunk, ip: 0, + last_modified: 0, register_stack: Vec::new(), } } @@ -303,7 +305,7 @@ impl Vm { } } - let final_value = self.pop(Span(0, 0))?; + let final_value = self.take(self.last_modified, Span(0, 0))?; Ok(Some(final_value)) } @@ -312,6 +314,8 @@ impl Vm { if self.register_stack.len() == Self::STACK_LIMIT { Err(VmError::StackOverflow { position }) } else { + self.last_modified = index; + let index = index as usize; while index >= self.register_stack.len() { diff --git a/dust-lang/tests/operations.rs b/dust-lang/tests/operations.rs index 5053870..3d33c76 100644 --- a/dust-lang/tests/operations.rs +++ b/dust-lang/tests/operations.rs @@ -4,7 +4,7 @@ use dust_lang::*; fn long_math() { assert_eq!( run("1 + 2 * 3 - 4 / 2"), - Ok(Some(Value::integer(2).into_reference())) + Ok(Some(Value::integer(5).into_reference())) ); }