diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/forth/vm.rs | 9 | ||||
| -rwxr-xr-x | src/lib.rs | 4 |
2 files changed, 5 insertions, 8 deletions
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<String>, + pub out: Option<DataStackType>, 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] @@ -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()); |
