Add double-stack words (2dup, 2drop, 2swap, 2over) and forget

This commit is contained in:
2026-02-02 07:46:39 +01:00
parent 3e8076e416
commit 2af0b67714
6 changed files with 186 additions and 0 deletions

View File

@@ -95,6 +95,46 @@ fn tuck_underflow() {
expect_error("1 tuck", "stack underflow");
}
#[test]
fn dup2() {
expect_stack("1 2 2dup", &[int(1), int(2), int(1), int(2)]);
}
#[test]
fn dup2_underflow() {
expect_error("1 2dup", "stack underflow");
}
#[test]
fn drop2() {
expect_stack("1 2 3 2drop", &[int(1)]);
}
#[test]
fn drop2_underflow() {
expect_error("1 2drop", "stack underflow");
}
#[test]
fn swap2() {
expect_stack("1 2 3 4 2swap", &[int(3), int(4), int(1), int(2)]);
}
#[test]
fn swap2_underflow() {
expect_error("1 2 3 2swap", "stack underflow");
}
#[test]
fn over2() {
expect_stack("1 2 3 4 2over", &[int(1), int(2), int(3), int(4), int(1), int(2)]);
}
#[test]
fn over2_underflow() {
expect_error("1 2 3 2over", "stack underflow");
}
#[test]
fn stack_persists() {
let f = forth();