feat(vm): reset origin id before calling <origin,ptr,atom>

This commit is contained in:
Alain Zscheile 2022-09-27 17:28:34 +02:00
parent 7580ba28bb
commit 9c0ad2fa15
3 changed files with 8 additions and 1 deletions

View file

@ -98,6 +98,11 @@ impl Pointer {
}
}
#[inline]
pub fn set_origin(&mut self, origin: u16) {
self.0[8..10].copy_from_slice(&origin.to_be_bytes());
}
#[inline]
pub fn origin(&self) -> u16 {
u16::from_be_bytes(self.0[8..10].try_into().unwrap())

View file

@ -136,7 +136,7 @@ impl Process {
tracing::error!("`call-r` invoked on empty stack @ {}", previptr);
break;
}
Some(StackEntValue::Pointer(wp)) => {
Some(StackEntValue::Pointer(mut wp)) => {
let ssl = self.stack.len();
let mut args = self.stack.drain(ssl - usize::from(arity)..).collect();
let origin_id = usize::from(wp.origin());
@ -144,6 +144,7 @@ impl Process {
match origin {
Ok(origin) => match origin.as_ref() {
Some(origin) => {
wp.set_origin(0);
self.instrp = origin.call(&wp, &atom, &mut args);
self.stack.extend(args);
}

1
docs/TODO.md Normal file
View file

@ -0,0 +1 @@
* reduce stack item size (see `fogtix_vm::tests::stack_item_size`)