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: <=