llvm
Clyne 2 years ago
parent f186ff2a22
commit bf7fe756a1

@ -42,7 +42,7 @@ core.fth.h: alee.dat
sed -i "s/unsigned /static const &/" $@ sed -i "s/unsigned /static const &/" $@
alee.dat: alee forth/core.fth alee.dat: alee forth/core.fth
echo "2 sys" | ./alee forth/core.fth echo "3 sys" | ./alee forth/core.fth
clean: clean-lib clean: clean-lib
rm -f alee alee-standalone msp430/alee-msp430 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: **Missing** core features:
* Pictured numeric output conversion (e.g. `<# #>`) * 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` * `>NUMBER`
**Missing** core extensions: **Missing** core extensions:

@ -89,16 +89,7 @@ void user_sys(State& state)
state.dict.read(Dictionary::Base)); state.dict.read(Dictionary::Base));
std::cout << buf << ' '; std::cout << buf << ' ';
break; break;
case 1: // emit case 1: // u.
std::cout << static_cast<char>(state.pop());
break;
case 2: // save
save(state);
break;
case 3: // load
load(state);
break;
case 4: // u.
{ {
Addr ucell = static_cast<Addr>(state.pop()); Addr ucell = static_cast<Addr>(state.pop());
std::to_chars(buf, buf + sizeof(buf), ucell, std::to_chars(buf, buf + sizeof(buf), ucell,
@ -106,6 +97,15 @@ void user_sys(State& state)
std::cout << buf << ' '; std::cout << buf << ' ';
} }
break; 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: default:
break; break;
} }

@ -90,16 +90,7 @@ void user_sys(State& state)
state.dict.read(Dictionary::Base)); state.dict.read(Dictionary::Base));
std::cout << buf << ' '; std::cout << buf << ' ';
break; break;
case 1: // emit case 1: // u.
std::cout << static_cast<char>(state.pop());
break;
case 2: // save
save(state);
break;
case 3: // load
load(state);
break;
case 4: // u.
{ {
Addr ucell = static_cast<Addr>(state.pop()); Addr ucell = static_cast<Addr>(state.pop());
std::to_chars(buf, buf + sizeof(buf), ucell, std::to_chars(buf, buf + sizeof(buf), ucell,
@ -107,6 +98,15 @@ void user_sys(State& state)
std::cout << buf << ' '; std::cout << buf << ' ';
} }
break; 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: default:
break; break;
} }

@ -119,9 +119,9 @@ yes 6.1.2250 STATE
yes 6.1.2260 SWAP yes 6.1.2260 SWAP
yes 6.1.2270 THEN yes 6.1.2270 THEN
yes 6.1.2310 TYPE yes 6.1.2310 TYPE
6.1.2320 U. yes 6.1.2320 U.
6.1.2340 U< 6.1.2340 U<
6.1.2360 UM* yes 6.1.2360 UM*
6.1.2370 UM/MOD 6.1.2370 UM/MOD
yes 6.1.2380 UNLOOP yes 6.1.2380 UNLOOP
yes 6.1.2390 UNTIL yes 6.1.2390 UNTIL

@ -7,8 +7,8 @@
: cells 2 * ; : cells 2 * ;
: . 0 sys ; : . 0 sys ;
: emit 1 sys ; : u. 1 sys ;
: u. 4 sys ; : emit 2 sys ;
: 1+ 1 + ; : 1+ 1 + ;
: 1- 1 - ; : 1- 1 - ;

@ -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 2 RSHIFT 4 * -> MID-UINT+1 }T
T{ MID-UINT+1 1 RSHIFT MID-UINT+1 OR 2 * -> 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 0 UM* -> 0 0 }T T{ 0 1 UM* -> 0 0 }T
\ T{ 0 1 UM* -> 0 0 }T T{ 1 0 UM* -> 0 0 }T
\ T{ 1 0 UM* -> 0 0 }T T{ 1 2 UM* -> 2 0 }T
\ T{ 1 2 UM* -> 2 0 }T T{ 2 1 UM* -> 2 0 }T
\ T{ 2 1 UM* -> 2 0 }T T{ 3 3 UM* -> 9 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 1 RSHIFT 2 UM* -> MID-UINT+1 0 }T T{ MID-UINT+1 2 UM* -> 0 1 }T
\ T{ MID-UINT+1 2 UM* -> 0 1 }T T{ MID-UINT+1 4 UM* -> 0 2 }T
\ T{ MID-UINT+1 4 UM* -> 0 2 }T T{ 1S 2 UM* -> 1S 1 LSHIFT 1 }T
\ T{ 1S 2 UM* -> 1S 1 LSHIFT 1 }T T{ MAX-UINT MAX-UINT UM* -> 1 1 INVERT }T
\ T{ MAX-UINT MAX-UINT UM* -> 1 1 INVERT }T
\ ------------------------------------------------------------------------ \ ------------------------------------------------------------------------
." TESTING DIVIDE: FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD" CR ." TESTING DIVIDE: FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD" CR

@ -222,6 +222,14 @@ execute:
find(state, word); find(state, word);
} }
break; 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: default:
state.push(index - WordCount); state.push(index - WordCount);
break; break;

@ -31,7 +31,7 @@ void user_sys(State&);
class CoreWords class CoreWords
{ {
public: public:
constexpr static std::size_t WordCount = 34; constexpr static std::size_t WordCount = 35;
constexpr static int Semicolon = 26; constexpr static int Semicolon = 26;
/** /**
@ -53,7 +53,8 @@ public:
"<\0&\0|\0^\0" "<\0&\0|\0^\0"
"<<\0>>\0:\0_'\0execute\0" "<<\0>>\0:\0_'\0execute\0"
"exit\0;\0_jmp0\0_jmp\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 #endif // ALEEFORTH_COREWORDS_HPP

@ -95,7 +95,7 @@ Error Parser::parseNumber(State& state, Word word)
result += c - '0'; result += c - '0';
} else if (isalpha(c) && base > 10) { } else if (isalpha(c) && base > 10) {
result *= base; result *= base;
result += 10 + (c > 'a' ? c - 'a' : c - 'A'); result += 10 + c - (isupper(c) ? 'A' : 'a');
} else { } else {
return Error::noword; return Error::noword;
} }

@ -29,7 +29,7 @@ static char strbuf[32];
static void readchar(State& state); static void readchar(State& state);
static void serput(int c); static void serput(int c);
static void serputs(const char *s); static void serputs(const char *s);
static void printint(int n, char *buf); static void printint(DoubleCell n, char *buf);
int main() int main()
{ {
@ -118,7 +118,7 @@ void serputs(const char *s)
serput(*s++); serput(*s++);
} }
void printint(int n, char *buf) void printint(DoubleCell n, char *buf)
{ {
char *ptr = buf; char *ptr = buf;
bool neg = n < 0; bool neg = n < 0;
@ -146,13 +146,16 @@ void user_sys(State& state)
printint(state.pop(), strbuf); printint(state.pop(), strbuf);
break; break;
case 1: case 1:
serput(state.pop()); printint(static_cast<Addr>(state.pop()), strbuf);
break; break;
case 2: case 2:
serput(state.pop());
break;
case 3:
{ auto addr = state.pop(); { auto addr = state.pop();
*reinterpret_cast<uint8_t *>(addr) = state.pop(); } *reinterpret_cast<uint8_t *>(addr) = state.pop(); }
break; break;
case 3: case 4:
state.push(*reinterpret_cast<uint8_t *>(state.pop())); state.push(*reinterpret_cast<uint8_t *>(state.pop()));
break; break;
default: default:

Loading…
Cancel
Save