From e8952f6bf66af375b8b215a134cfa3ddc33dddd8 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 4 Feb 2022 19:22:00 -0800 Subject: [PATCH] Inline min/max/abs. --- ueforth/common/boot.fs | 5 ----- ueforth/common/extra.fs | 5 +++++ ueforth/common/extra_opcodes.h | 5 ++++- ueforth/common/forth_namespace_tests.fs | 7 ++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 58f69e8..e7f5d68 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -68,11 +68,6 @@ ( Recursion ) : recurse current @ @ aliteral ['] execute , ; immediate -( Compound words requiring conditionals ) -: min 2dup < if drop else nip then ; -: max 2dup < if nip else drop then ; -: abs ( n -- +n ) dup 0< if negate then ; - ( Dictionary Format ) : >flags& ( xt -- a ) cell - ; : >flags ( xt -- flags ) >flags& c@ ; : >name-length ( xt -- n ) >flags& 1+ c@ ; diff --git a/ueforth/common/extra.fs b/ueforth/common/extra.fs index 742d648..3c3948b 100644 --- a/ueforth/common/extra.fs +++ b/ueforth/common/extra.fs @@ -54,3 +54,8 @@ : cmove> ( a a n -- ) for aft 2dup swap r@ + c@ swap r@ + c! then next 2drop ; : fill ( a n ch -- ) swap for swap aft 2dup c! 1 + then next 2drop ; : erase ( a n -- ) 0 fill ; : blank ( a n -- ) bl fill ; + +( Compound words requiring conditionals ) +: min 2dup < if drop else nip then ; +: max 2dup < if nip else drop then ; +: abs ( n -- +n ) dup 0< if negate then ; diff --git a/ueforth/common/extra_opcodes.h b/ueforth/common/extra_opcodes.h index 048194b..ec8fded 100644 --- a/ueforth/common/extra_opcodes.h +++ b/ueforth/common/extra_opcodes.h @@ -53,4 +53,7 @@ X("cmove>", cmove2, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \ Y(fill, memset((void *) sp[-1], tos, *sp); sp -= 2; DROP) \ Y(erase, memset((void *) *sp, 0, tos); NIP; DROP) \ - Y(blank, memset((void *) *sp, ' ', tos); NIP; DROP) + Y(blank, memset((void *) *sp, ' ', tos); NIP; DROP) \ + Y(min, tos = tos < *sp ? tos : *sp; NIP) \ + Y(max, tos = tos > *sp ? tos : *sp; NIP) \ + Y(abs, tos = tos < 0 ? -tos : tos) diff --git a/ueforth/common/forth_namespace_tests.fs b/ueforth/common/forth_namespace_tests.fs index dcde57c..65d52db 100644 --- a/ueforth/common/forth_namespace_tests.fs +++ b/ueforth/common/forth_namespace_tests.fs @@ -125,9 +125,6 @@ e: check-boot out: >name-length out: >flags out: >flags& - out: abs - out: max - out: min out: recurse out: aft out: repeat @@ -170,6 +167,10 @@ e: check-boot ;e e: check-extra-opcodes + out: abs + out: max + out: min + out: blank out: erase out: fill