diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2023-03-11 16:32:48 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2023-03-11 16:32:48 -0500 |
commit | c46f531b6bb62d7dd947504a1c731efb5eb57ef5 (patch) | |
tree | a54fc62ce1bf6dad5d5b90124a9cadf6eb4feb15 | |
parent | bf7fe756a175a90dd82e970e5d620c6d8c459c17 (diff) |
u< um/mod
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | compat.txt | 4 | ||||
-rw-r--r-- | forth/test/core.fr | 39 | ||||
-rw-r--r-- | libalee/corewords.cpp | 16 | ||||
-rw-r--r-- | libalee/corewords.hpp | 4 | ||||
-rw-r--r-- | libalee/types.hpp | 1 |
6 files changed, 40 insertions, 25 deletions
@@ -18,7 +18,6 @@ Running Alee without `core.fth` or `core-ext.fth` passed as arguments will leave **Missing** core features: * Pictured numeric output conversion (e.g. `<# #>`) -* Some words for unsigned integers: `U. U< UM/MOD` * `>NUMBER` **Missing** core extensions: @@ -120,9 +120,9 @@ yes 6.1.2260 SWAP yes 6.1.2270 THEN yes 6.1.2310 TYPE yes 6.1.2320 U. - 6.1.2340 U< +yes 6.1.2340 U< yes 6.1.2360 UM* - 6.1.2370 UM/MOD +yes 6.1.2370 UM/MOD yes 6.1.2380 UNLOOP yes 6.1.2390 UNTIL yes 6.1.2410 VARIABLE diff --git a/forth/test/core.fr b/forth/test/core.fr index 519124d..42fff25 100644 --- a/forth/test/core.fr +++ b/forth/test/core.fr @@ -160,19 +160,18 @@ T{ 0 MIN-INT > -> <TRUE> }T T{ MAX-INT MIN-INT > -> <TRUE> }T T{ MAX-INT 0 > -> <TRUE> }T -." HEY! U< IS NOT IMPLEMENTED!" CR -\ T{ 0 1 U< -> <TRUE> }T -\ T{ 1 2 U< -> <TRUE> }T -\ T{ 0 MID-UINT U< -> <TRUE> }T -\ T{ 0 MAX-UINT U< -> <TRUE> }T -\ T{ MID-UINT MAX-UINT U< -> <TRUE> }T -\ T{ 0 0 U< -> <FALSE> }T -\ T{ 1 1 U< -> <FALSE> }T -\ T{ 1 0 U< -> <FALSE> }T -\ T{ 2 1 U< -> <FALSE> }T -\ T{ MID-UINT 0 U< -> <FALSE> }T -\ T{ MAX-UINT 0 U< -> <FALSE> }T -\ T{ MAX-UINT MID-UINT U< -> <FALSE> }T +T{ 0 1 U< -> <TRUE> }T +T{ 1 2 U< -> <TRUE> }T +T{ 0 MID-UINT U< -> <TRUE> }T +T{ 0 MAX-UINT U< -> <TRUE> }T +T{ MID-UINT MAX-UINT U< -> <TRUE> }T +T{ 0 0 U< -> <FALSE> }T +T{ 1 1 U< -> <FALSE> }T +T{ 1 0 U< -> <FALSE> }T +T{ 2 1 U< -> <FALSE> }T +T{ MID-UINT 0 U< -> <FALSE> }T +T{ MAX-UINT 0 U< -> <FALSE> }T +T{ MAX-UINT MID-UINT U< -> <FALSE> }T T{ 0 1 MIN -> 0 }T T{ 1 2 MIN -> 1 }T @@ -411,13 +410,13 @@ T{ MIN-INT MAX-INT M* MAX-INT SM/REM -> 0 MIN-INT }T T{ MAX-INT MAX-INT M* MAX-INT SM/REM -> 0 MAX-INT }T -\ T{ 0 0 1 UM/MOD -> 0 0 }T -\ T{ 1 0 1 UM/MOD -> 0 1 }T -\ T{ 1 0 2 UM/MOD -> 1 0 }T -\ T{ 3 0 2 UM/MOD -> 1 1 }T -\ T{ MAX-UINT 2 UM* 2 UM/MOD -> 0 MAX-UINT }T -\ T{ MAX-UINT 2 UM* MAX-UINT UM/MOD -> 0 2 }T -\ T{ MAX-UINT MAX-UINT UM* MAX-UINT UM/MOD -> 0 MAX-UINT }T +T{ 0 0 1 UM/MOD -> 0 0 }T +T{ 1 0 1 UM/MOD -> 0 1 }T +T{ 1 0 2 UM/MOD -> 1 0 }T +T{ 3 0 2 UM/MOD -> 1 1 }T +T{ MAX-UINT 2 UM* 2 UM/MOD -> 0 MAX-UINT }T +T{ MAX-UINT 2 UM* MAX-UINT UM/MOD -> 0 2 }T +T{ MAX-UINT MAX-UINT UM* MAX-UINT UM/MOD -> 0 MAX-UINT }T : IFFLOORED [ -3 2 / -2 = INVERT ] LITERAL IF POSTPONE \ THEN ; diff --git a/libalee/corewords.cpp b/libalee/corewords.cpp index 136619c..b12f53b 100644 --- a/libalee/corewords.cpp +++ b/libalee/corewords.cpp @@ -230,6 +230,22 @@ execute: state.push(dcell); state.push(dcell >> (sizeof(Cell) * 8)); break; + case 35: // u< + cell = state.pop(); + state.top() = static_cast<Addr>(state.top()) < + static_cast<Addr>(cell) ? -1 : 0; + break; + case 36: // um/mod + cell = state.pop(); + dcell = state.pop(); + dcell <<= sizeof(Cell) * 8; + dcell |= static_cast<Addr>(state.pop()); + + state.push(static_cast<DoubleAddr>(dcell) % + static_cast<Addr>(cell)); + state.push(static_cast<DoubleAddr>(dcell) / + static_cast<Addr>(cell)); + break; default: state.push(index - WordCount); break; diff --git a/libalee/corewords.hpp b/libalee/corewords.hpp index c08c4cd..f6465c4 100644 --- a/libalee/corewords.hpp +++ b/libalee/corewords.hpp @@ -31,7 +31,7 @@ void user_sys(State&); class CoreWords { public: - constexpr static std::size_t WordCount = 35; + constexpr static std::size_t WordCount = 37; constexpr static int Semicolon = 26; /** @@ -54,7 +54,7 @@ public: "<<\0>>\0:\0_'\0execute\0" "exit\0;\0_jmp0\0_jmp\0" "depth\0_rdepth\0_in\0_ev\0find\0" - "um*\0"; + "um*\0u<\0um/mod\0"; }; #endif // ALEEFORTH_COREWORDS_HPP diff --git a/libalee/types.hpp b/libalee/types.hpp index 29c93e8..f23f92e 100644 --- a/libalee/types.hpp +++ b/libalee/types.hpp @@ -28,6 +28,7 @@ using Addr = uint16_t; using Cell = int16_t; using DoubleCell = int32_t; +using DoubleAddr = uint32_t; // Only used for um/mod. struct Dictionary; struct State; |