diff options
| author | Brian Cully <bjc@spork.org> | 2025-08-25 10:24:00 -0400 |
|---|---|---|
| committer | Brian Cully <bjc@spork.org> | 2025-08-25 10:24:00 -0400 |
| commit | 275ee10822d8d5108e34166dbaf486ddb5a56a59 (patch) | |
| tree | 26473e7154bbf03ed63ff0699f274a8db05a64c6 /src/forth/compiler.rs | |
| parent | b059c2364d54c34d85ce791546aeeefd0a3c43b6 (diff) | |
| download | automathon-275ee10822d8d5108e34166dbaf486ddb5a56a59.tar.gz automathon-275ee10822d8d5108e34166dbaf486ddb5a56a59.zip | |
add rot and swap
Diffstat (limited to 'src/forth/compiler.rs')
| -rw-r--r-- | src/forth/compiler.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/forth/compiler.rs b/src/forth/compiler.rs index 97e94a9..89964e1 100644 --- a/src/forth/compiler.rs +++ b/src/forth/compiler.rs @@ -199,6 +199,8 @@ impl<'a> Compiler<'a> { "/" => self.bc_push(OpCode::Div, anno), "dup" => self.bc_push(OpCode::Dup, anno), "drop" => self.bc_push(OpCode::Drop, anno), + "rot" => self.bc_push(OpCode::Rot, anno), + "swap" => self.bc_push(OpCode::Swap, anno), "=" => self.bc_push(OpCode::EQ, anno), ">" => self.bc_push(OpCode::GT, anno), ">=" => self.bc_push(OpCode::GTE, anno), @@ -258,6 +260,20 @@ mod tests { } #[test] + fn rot_opcode() { + let comp = compiler_for("rot\n"); + let main = &comp.wordlist.0[0]; + assert_eq!(main, vec![OpCode::Rot]); + } + + #[test] + fn swap_opcode() { + let comp = compiler_for("swap\n"); + let main = &comp.wordlist.0[0]; + assert_eq!(main, vec![OpCode::Swap]); + } + + #[test] fn def_word() { let comp = compiler_for(": add2 2 + ; 3 add2\n"); let main = &comp.wordlist.0[0]; |
