From bf88a73336e60c8237375c81f396aadcb4ab7340 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 27 Feb 2022 21:23:37 -0800 Subject: [PATCH] Added ?DUP. --- common/base_tests.fs | 7 +++++++ common/extra_opcodes.h | 1 + common/forth_namespace_tests.fs | 1 + 3 files changed, 9 insertions(+) diff --git a/common/base_tests.fs b/common/base_tests.fs index 38a85e0..c8a3f09 100644 --- a/common/base_tests.fs +++ b/common/base_tests.fs @@ -122,3 +122,10 @@ e: test-empty-string : test s" " ; test 0 =assert drop ;e + +e: test-?dup + 123 ?dup 123 =assert 123 =assert + depth 0 =assert + 0 ?dup 0 =assert + depth 0 =assert +;e diff --git a/common/extra_opcodes.h b/common/extra_opcodes.h index 831fcb6..a0fae87 100644 --- a/common/extra_opcodes.h +++ b/common/extra_opcodes.h @@ -25,6 +25,7 @@ X("-", MINUS, tos = (*sp--) - tos) \ Y(rot, w = sp[-1]; sp[-1] = *sp; *sp = tos; tos = w) \ X("-rot", MROT, w = tos; tos = *sp; *sp = sp[-1]; sp[-1] = w) \ + X("?dup", QDUP, if (tos) DUP) \ X("<", LESS, tos = (*sp--) < tos ? -1 : 0) \ X(">", GREATER, tos = (*sp--) > tos ? -1 : 0) \ X("<=", LESSEQ, tos = (*sp--) <= tos ? -1 : 0) \ diff --git a/common/forth_namespace_tests.fs b/common/forth_namespace_tests.fs index e88af7e..5f36027 100644 --- a/common/forth_namespace_tests.fs +++ b/common/forth_namespace_tests.fs @@ -152,6 +152,7 @@ e: check-extra-opcodes out: - out: rot out: -rot + out: ?dup out: < out: > out: <=