diff --git a/README.md b/README.md index c8fb465..90cfaaf 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/compat.txt b/compat.txt index 1ebf10c..3de92fb 100644 --- a/compat.txt +++ b/compat.txt @@ -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 > -> }T T{ MAX-INT MIN-INT > -> }T T{ MAX-INT 0 > -> }T -." HEY! U< IS NOT IMPLEMENTED!" CR -\ T{ 0 1 U< -> }T -\ T{ 1 2 U< -> }T -\ T{ 0 MID-UINT U< -> }T -\ T{ 0 MAX-UINT U< -> }T -\ T{ MID-UINT MAX-UINT U< -> }T -\ T{ 0 0 U< -> }T -\ T{ 1 1 U< -> }T -\ T{ 1 0 U< -> }T -\ T{ 2 1 U< -> }T -\ T{ MID-UINT 0 U< -> }T -\ T{ MAX-UINT 0 U< -> }T -\ T{ MAX-UINT MID-UINT U< -> }T +T{ 0 1 U< -> }T +T{ 1 2 U< -> }T +T{ 0 MID-UINT U< -> }T +T{ 0 MAX-UINT U< -> }T +T{ MID-UINT MAX-UINT U< -> }T +T{ 0 0 U< -> }T +T{ 1 1 U< -> }T +T{ 1 0 U< -> }T +T{ 2 1 U< -> }T +T{ MID-UINT 0 U< -> }T +T{ MAX-UINT 0 U< -> }T +T{ MAX-UINT MID-UINT U< -> }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(state.top()) < + static_cast(cell) ? -1 : 0; + break; + case 36: // um/mod + cell = state.pop(); + dcell = state.pop(); + dcell <<= sizeof(Cell) * 8; + dcell |= static_cast(state.pop()); + + state.push(static_cast(dcell) % + static_cast(cell)); + state.push(static_cast(dcell) / + static_cast(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;