]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
u. um*
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 11 Mar 2023 21:24:25 +0000 (16:24 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 11 Mar 2023 21:24:25 +0000 (16:24 -0500)
Makefile
README.md
alee-standalone.cpp
alee.cpp
compat.txt
forth/core.fth
forth/test/core.fr
libalee/corewords.cpp
libalee/corewords.hpp
libalee/parser.cpp
msp430/alee-msp430.cpp

index d8c11ba936641e3382388941f26d7b40a3190b7f..04791712df23942a747317417a8e5ea8fafe54e8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -42,7 +42,7 @@ core.fth.h: alee.dat
        sed -i "s/unsigned /static const &/" $@
 
 alee.dat: alee forth/core.fth
-       echo "2 sys" | ./alee forth/core.fth
+       echo "3 sys" | ./alee forth/core.fth
 
 clean: clean-lib
        rm -f alee alee-standalone msp430/alee-msp430
index d57ae3a099add1ff25efec5b31182d80961a5157..c8fb465b1a189dbde4405d866bced729071061cf 100644 (file)
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Running Alee without `core.fth` or `core-ext.fth` passed as arguments will leave
 
 **Missing** core features:  
 * Pictured numeric output conversion (e.g. `<# #>`)
-* Words for unsigned integers: `U. U< UM* UM/MOD`
+* Some words for unsigned integers: `U. U< UM/MOD`
 * `>NUMBER`
 
 **Missing** core extensions:  
index 2c971ce4bb0aa40c0ab897994a7daf1976992177..5c9f8a89936c9f2c98188dc3ae13d7709680f15c 100644 (file)
@@ -89,16 +89,7 @@ void user_sys(State& state)
                       state.dict.read(Dictionary::Base));
         std::cout << buf << ' ';
         break;
-    case 1: // emit
-        std::cout << static_cast<char>(state.pop());
-        break;
-    case 2: // save
-        save(state);
-        break;
-    case 3: // load
-        load(state);
-        break;
-    case 4: // u.
+    case 1: // u.
         {
         Addr ucell = static_cast<Addr>(state.pop());
         std::to_chars(buf, buf + sizeof(buf), ucell,
@@ -106,6 +97,15 @@ void user_sys(State& state)
         std::cout << buf << ' ';
         }
         break;
+    case 2: // emit
+        std::cout << static_cast<char>(state.pop());
+        break;
+    case 3: // save
+        save(state);
+        break;
+    case 4: // load
+        load(state);
+        break;
     default:
         break;
     }
index 92af96960148688a706fe7a7e4d04e511bd9cb94..dfe85d1c417bf1d7fa09aaae802ed17074c5ebed 100644 (file)
--- a/alee.cpp
+++ b/alee.cpp
@@ -90,16 +90,7 @@ void user_sys(State& state)
                       state.dict.read(Dictionary::Base));
         std::cout << buf << ' ';
         break;
-    case 1: // emit
-        std::cout << static_cast<char>(state.pop());
-        break;
-    case 2: // save
-        save(state);
-        break;
-    case 3: // load
-        load(state);
-        break;
-    case 4: // u.
+    case 1: // u.
         {
         Addr ucell = static_cast<Addr>(state.pop());
         std::to_chars(buf, buf + sizeof(buf), ucell,
@@ -107,6 +98,15 @@ void user_sys(State& state)
         std::cout << buf << ' ';
         }
         break;
+    case 2: // emit
+        std::cout << static_cast<char>(state.pop());
+        break;
+    case 3: // save
+        save(state);
+        break;
+    case 4: // load
+        load(state);
+        break;
     default:
         break;
     }
index 2410bd52997e1d6d50db4d53dd1bf27f749f6217..1ebf10c5ad689fe9d10d5bbde653539930c8a862 100644 (file)
@@ -119,9 +119,9 @@ yes 6.1.2250 STATE
 yes 6.1.2260 SWAP
 yes 6.1.2270 THEN
 yes 6.1.2310 TYPE
-    6.1.2320 U.
+yes 6.1.2320 U.
     6.1.2340 U<
-    6.1.2360 UM*
+yes 6.1.2360 UM*
     6.1.2370 UM/MOD
 yes 6.1.2380 UNLOOP
 yes 6.1.2390 UNTIL
index a8ccb9d3d3c359318b9942ab851152903563909a..bbaa67dfdd874c5f8d7f24a780042baae46bd3b1 100644 (file)
@@ -7,8 +7,8 @@
 : cells    2 * ;
 
 : .        0 sys ;
-: emit     1 sys ;
-: u.       4 sys ;
+: u.       1 sys ;
+: emit     2 sys ;
 
 : 1+       1 + ;
 : 1-       1 - ;
index d2724e1d81d88889fdd444f56ee93337dae9cb58..519124d1dae375ee2a586013af77a389e54096f3 100644 (file)
@@ -328,19 +328,18 @@ T{ MID-UINT+1 1 RSHIFT 2 * -> MID-UINT+1 }T
 T{ MID-UINT+1 2 RSHIFT 4 * -> MID-UINT+1 }T
 T{ MID-UINT+1 1 RSHIFT MID-UINT+1 OR 2 * -> MID-UINT+1 }T
 
-." HEY! UM* IS NOT IMPLEMENTED!" CR
-\ T{ 0 0 UM* -> 0 0 }T
-\ T{ 0 1 UM* -> 0 0 }T
-\ T{ 1 0 UM* -> 0 0 }T
-\ T{ 1 2 UM* -> 2 0 }T
-\ T{ 2 1 UM* -> 2 0 }T
-\ T{ 3 3 UM* -> 9 0 }T
-\ 
-\ T{ MID-UINT+1 1 RSHIFT 2 UM* -> MID-UINT+1 0 }T
-\ T{ MID-UINT+1 2 UM* -> 0 1 }T
-\ T{ MID-UINT+1 4 UM* -> 0 2 }T
-\ T{ 1S 2 UM* -> 1S 1 LSHIFT 1 }T
-\ T{ MAX-UINT MAX-UINT UM* -> 1 1 INVERT }T
+T{ 0 0 UM* -> 0 0 }T
+T{ 0 1 UM* -> 0 0 }T
+T{ 1 0 UM* -> 0 0 }T
+T{ 1 2 UM* -> 2 0 }T
+T{ 2 1 UM* -> 2 0 }T
+T{ 3 3 UM* -> 9 0 }T
+
+T{ MID-UINT+1 1 RSHIFT 2 UM* -> MID-UINT+1 0 }T
+T{ MID-UINT+1 2 UM* -> 0 1 }T
+T{ MID-UINT+1 4 UM* -> 0 2 }T
+T{ 1S 2 UM* -> 1S 1 LSHIFT 1 }T
+T{ MAX-UINT MAX-UINT UM* -> 1 1 INVERT }T
 
 \ ------------------------------------------------------------------------
 ." TESTING DIVIDE: FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD" CR
index f22772cd80d96cfaf5f5371562e2c1b713f6523a..136619cff8689797ca68768e3d14af8491022c0c 100644 (file)
@@ -222,6 +222,14 @@ execute:
         find(state, word);
         }
         break;
+    case 34: // um*
+        cell = state.pop();
+        dcell = static_cast<DoubleCell>(
+            static_cast<Addr>(state.pop()) *
+            static_cast<Addr>(cell));
+        state.push(dcell);
+        state.push(dcell >> (sizeof(Cell) * 8));
+        break;
     default:
         state.push(index - WordCount);
         break;
index 684b94b6dbef2c931262908276a1986097f9a3de..c08c4cdf9662e0d263dfbf0995c68c9fdde0d726 100644 (file)
@@ -31,7 +31,7 @@ void user_sys(State&);
 class CoreWords
 {
 public:
-    constexpr static std::size_t WordCount = 34;
+    constexpr static std::size_t WordCount = 35;
     constexpr static int Semicolon = 26;
 
     /**
@@ -53,7 +53,8 @@ public:
         "<\0&\0|\0^\0"
         "<<\0>>\0:\0_'\0execute\0"
         "exit\0;\0_jmp0\0_jmp\0"
-        "depth\0_rdepth\0_in\0_ev\0find\0";
+        "depth\0_rdepth\0_in\0_ev\0find\0"
+        "um*\0";
 };
 
 #endif // ALEEFORTH_COREWORDS_HPP
index 9981b3e6bf581854a0a6c2f0c0a5deb918329acb..464bc2fb0e883709f15f19bdea3cce04dcab2d54 100644 (file)
@@ -95,7 +95,7 @@ Error Parser::parseNumber(State& state, Word word)
             result += c - '0';
         } else if (isalpha(c) && base > 10) {
             result *= base;
-            result += 10 + (c > 'a' ? c - 'a' : c - 'A');
+            result += 10 + c - (isupper(c) ? 'A' : 'a');
         } else {
             return Error::noword;
         }
index ca00026f823dd419871caba5f49840d5d24e6c18..0ec6c886ecdfb429c7124d0f5acbffe6b424817c 100644 (file)
@@ -29,7 +29,7 @@ static char strbuf[32];
 static void readchar(State& state);
 static void serput(int c);
 static void serputs(const char *s);
-static void printint(int n, char *buf);
+static void printint(DoubleCell n, char *buf);
 
 int main()
 {
@@ -118,7 +118,7 @@ void serputs(const char *s)
         serput(*s++);
 }
 
-void printint(int n, char *buf)
+void printint(DoubleCell n, char *buf)
 {
     char *ptr = buf;
     bool neg = n < 0;
@@ -146,13 +146,16 @@ void user_sys(State& state)
         printint(state.pop(), strbuf);
         break;
     case 1:
-        serput(state.pop());
+        printint(static_cast<Addr>(state.pop()), strbuf);
         break;
     case 2:
+        serput(state.pop());
+        break;
+    case 3:
         { auto addr = state.pop();
           *reinterpret_cast<uint8_t *>(addr) = state.pop(); }
         break;
-    case 3:
+    case 4:
         state.push(*reinterpret_cast<uint8_t *>(state.pop()));
         break;
     default: