From 573e5ae47081f15a710f40bf26f8e496f8c61e50 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 22 Sep 2024 12:57:58 -0400 Subject: [PATCH] Change VM's final value to last modified register --- dust-lang/src/vm.rs | 6 +++++- dust-lang/tests/operations.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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())) ); }