From 511beade910e5115f46d79342af76b81f85cf336 Mon Sep 17 00:00:00 2001 From: brian cully Date: Tue, 23 Dec 2025 15:24:24 -0500 Subject: change out to a single datum it can only get, at most, one item per tick, so only represent that. --- src/forth/vm.rs | 9 ++++----- src/lib.rs | 4 +--- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/forth/vm.rs b/src/forth/vm.rs index 25ed516..6bab8b9 100644 --- a/src/forth/vm.rs +++ b/src/forth/vm.rs @@ -126,7 +126,7 @@ pub struct VM { pub wordlist: WordList, pub ip: InstructionPointer, - pub out: Vec, + pub out: Option, pub heading: DataStackType, pub speed: DataStackType, pub doppler: DataStackType, @@ -153,7 +153,7 @@ impl VM { ip: InstructionPointer::new(), wordlist, - out: vec![], + out: None, heading: 0, speed: 0, doppler: 0, @@ -313,7 +313,7 @@ impl VM { } OpCode::Say => { let v = self.stack.0.pop().ok_or(RuntimeError::StackUnderflow)?; - self.out.push(format!("{}", v)); + let _ = self.out.insert(v); } OpCode::Heading => { self.stack.0.push(self.heading); @@ -829,8 +829,7 @@ mod tests { let mut vm = VM::new(wordlist); vm.run().expect("should run to completion"); assert_eq!(vm.stack.0.len(), 0, "empty stack"); - assert_eq!(vm.out.len(), 1, "output length"); - assert_eq!(vm.out[0], "-1", "output value"); + assert_eq!(vm.out.expect("output is set"), -1, "output value"); } #[test] diff --git a/src/lib.rs b/src/lib.rs index 240acf1..fc4a95b 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,9 +171,7 @@ impl ExportedVM { res.set(&"callstack".into(), &(&vm.callstack).into()); let vars = js_sys::Map::new(); - let mut out = vec![]; - std::mem::swap(&mut out, &mut vm.out); - vars.set(&"out".into(), &out.into()); + vars.set(&"out".into(), &vm.out.take().into()); vars.set(&"heading".into(), &vm.heading.into()); vars.set(&"speed".into(), &vm.speed.into()); vars.set(&"doppler".into(), &vm.doppler.into()); -- cgit v1.3