diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2023-03-11 16:24:25 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2023-03-11 16:24:25 -0500 |
commit | bf7fe756a175a90dd82e970e5d620c6d8c459c17 (patch) | |
tree | 82dab52271f35db08177410ab1ef94cfe1d66be7 | |
parent | f186ff2a22459ebf2fd83b63b66370d018dcbbef (diff) |
u. um*
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | alee-standalone.cpp | 20 | ||||
-rw-r--r-- | alee.cpp | 20 | ||||
-rw-r--r-- | compat.txt | 4 | ||||
-rw-r--r-- | forth/core.fth | 4 | ||||
-rw-r--r-- | forth/test/core.fr | 25 | ||||
-rw-r--r-- | libalee/corewords.cpp | 8 | ||||
-rw-r--r-- | libalee/corewords.hpp | 5 | ||||
-rw-r--r-- | libalee/parser.cpp | 2 | ||||
-rw-r--r-- | msp430/alee-msp430.cpp | 11 |
11 files changed, 57 insertions, 46 deletions
@@ -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 @@ -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: diff --git a/alee-standalone.cpp b/alee-standalone.cpp index 2c971ce..5c9f8a8 100644 --- a/alee-standalone.cpp +++ b/alee-standalone.cpp @@ -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; } @@ -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; } @@ -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 diff --git a/forth/core.fth b/forth/core.fth index a8ccb9d..bbaa67d 100644 --- a/forth/core.fth +++ b/forth/core.fth @@ -7,8 +7,8 @@ : cells 2 * ; : . 0 sys ; -: emit 1 sys ; -: u. 4 sys ; +: u. 1 sys ; +: emit 2 sys ; : 1+ 1 + ; : 1- 1 - ; diff --git a/forth/test/core.fr b/forth/test/core.fr index d2724e1..519124d 100644 --- a/forth/test/core.fr +++ b/forth/test/core.fr @@ -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 diff --git a/libalee/corewords.cpp b/libalee/corewords.cpp index f22772c..136619c 100644 --- a/libalee/corewords.cpp +++ b/libalee/corewords.cpp @@ -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; diff --git a/libalee/corewords.hpp b/libalee/corewords.hpp index 684b94b..c08c4cd 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 = 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 diff --git a/libalee/parser.cpp b/libalee/parser.cpp index 9981b3e..464bc2f 100644 --- a/libalee/parser.cpp +++ b/libalee/parser.cpp @@ -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; } diff --git a/msp430/alee-msp430.cpp b/msp430/alee-msp430.cpp index ca00026..0ec6c88 100644 --- a/msp430/alee-msp430.cpp +++ b/msp430/alee-msp430.cpp @@ -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: |