]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
u< um/mod
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 11 Mar 2023 21:32:48 +0000 (16:32 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 11 Mar 2023 21:32:48 +0000 (16:32 -0500)
README.md
compat.txt
forth/test/core.fr
libalee/corewords.cpp
libalee/corewords.hpp
libalee/types.hpp

index c8fb465b1a189dbde4405d866bced729071061cf..90cfaafa07353e218e113d0c45844eab276c7ebe 100644 (file)
--- 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:  
index 1ebf10c5ad689fe9d10d5bbde653539930c8a862..3de92fbea058aae910dadf60e84e3584a6f088b6 100644 (file)
@@ -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
index 519124d1dae375ee2a586013af77a389e54096f3..42fff2585960110feb329643d0ffc8facef71aaa 100644 (file)
@@ -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 ;
index 136619cff8689797ca68768e3d14af8491022c0c..b12f53b0ca82de23e0f34bffe4123b1dcb22b5d8 100644 (file)
@@ -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;
index c08c4cdf9662e0d263dfbf0995c68c9fdde0d726..f6465c46fca0938a03e7f5adb013b0d4ac0a25db 100644 (file)
@@ -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
index 29c93e8998068d2e2ab316efebb065729be6b8ea..f23f92e285feb395533d3e5f2e6a1181bb6a462e 100644 (file)
@@ -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;