|
|
@ -33,59 +33,59 @@ static void discard() { auto v = pop(); (void)v; }
|
|
|
|
static void tobool() { if (*sp()) *sp() = -1; }
|
|
|
|
static void tobool() { if (*sp()) *sp() = -1; }
|
|
|
|
|
|
|
|
|
|
|
|
constinit WordSet words (
|
|
|
|
constinit WordSet words (
|
|
|
|
Word("[", WordWrap<[] { STATE = 0; }>()).markImmediate(),
|
|
|
|
Word("[", WordWrap<[] { STATE = 0; }>).markImmediate(),
|
|
|
|
Word("]", WordWrap<[] { STATE = -1; }>()),
|
|
|
|
Word("]", WordWrap<[] { STATE = -1; }>),
|
|
|
|
Word("@", WordWrap<peek>()),
|
|
|
|
Word("@", WordWrap<peek>),
|
|
|
|
Word("c@", WordWrap<peek, [] { *sp() &= 0xFF; }>()),
|
|
|
|
Word("c@", WordWrap<peek, [] { *sp() &= 0xFF; }>),
|
|
|
|
Word("!", WordWrap<[] { auto a = (Cell *)pop(); *a = pop(); }>()),
|
|
|
|
Word("!", WordWrap<[] { auto a = (Cell *)pop(); *a = pop(); }>),
|
|
|
|
Word("c!", WordWrap<[] { auto a = (char *)pop(); *a = pop(); }>()),
|
|
|
|
Word("c!", WordWrap<[] { auto a = (char *)pop(); *a = pop(); }>),
|
|
|
|
Word("_d", WordWrap<[] { *sp() += (Cell)DICT.data(); }>()),
|
|
|
|
Word("_d", WordWrap<[] { *sp() += (Cell)DICT.data(); }>),
|
|
|
|
Word("_jmp", WordWrap<[] { jump((FuncList)*++IP); }>()),
|
|
|
|
Word("_jmp", WordWrap<[] { jump((FuncList)*++IP); }>),
|
|
|
|
Word("_jmp0", WordWrap<[] {
|
|
|
|
Word("_jmp0", WordWrap<[] {
|
|
|
|
++IP;
|
|
|
|
++IP;
|
|
|
|
if (pop() == 0)
|
|
|
|
if (pop() == 0)
|
|
|
|
jump((FuncList)*IP);
|
|
|
|
jump((FuncList)*IP);
|
|
|
|
}>()),
|
|
|
|
}>),
|
|
|
|
Word(",", WordWrap<commaSP>()),
|
|
|
|
Word(",", WordWrap<commaSP>),
|
|
|
|
Word("emit", WordWrap<[] { std::putchar(pop()); }>()),
|
|
|
|
Word("emit", WordWrap<[] { std::putchar(pop()); }>),
|
|
|
|
Word("key", WordWrap<[] { push(key()); }>()),
|
|
|
|
Word("key", WordWrap<[] { push(key()); }>),
|
|
|
|
Word("key?", WordWrap<[] { push(haskey()); }, tobool>()),
|
|
|
|
Word("key?", WordWrap<[] { push(haskey()); }, tobool>),
|
|
|
|
Word("execute", WordWrap<[] { (void)executor((FuncList *)pop()); }>()),
|
|
|
|
Word("execute", WordWrap<[] { (void)executor((FuncList *)pop()); }>),
|
|
|
|
Word(":", WordWrap<colon>()),
|
|
|
|
Word(":", WordWrap<colon>),
|
|
|
|
Word(";", WordWrap<semic>()).markImmediate(),
|
|
|
|
Word(";", WordWrap<semic>).markImmediate(),
|
|
|
|
Word("exit", fexit),
|
|
|
|
Word("exit", fexit),
|
|
|
|
Word("drop", WordWrap<discard>()),
|
|
|
|
Word("drop", WordWrap<discard>),
|
|
|
|
Word("dup", WordWrap<[] { push(*sp()); }>()),
|
|
|
|
Word("dup", WordWrap<[] { push(*sp()); }>),
|
|
|
|
Word("swap", WordWrap<[] { std::swap(*sp(), *(sp() - 1)); }>()),
|
|
|
|
Word("swap", WordWrap<[] { std::swap(*sp(), *(sp() - 1)); }>),
|
|
|
|
Word("pick", WordWrap<[] { auto t = *(sp() - *sp() - 1); *sp() = t; }>()),
|
|
|
|
Word("pick", WordWrap<[] { auto t = *(sp() - *sp() - 1); *sp() = t; }>),
|
|
|
|
Word("cells", WordWrap<[] { *sp() *= sizeof(Cell); }>()),
|
|
|
|
Word("cells", WordWrap<[] { *sp() *= sizeof(Cell); }>),
|
|
|
|
Word("+", WordWrap<[] { *(sp() - 1) += *sp(); }, discard>()),
|
|
|
|
Word("+", WordWrap<[] { *(sp() - 1) += *sp(); }, discard>),
|
|
|
|
Word("-", WordWrap<[] { *(sp() - 1) -= *sp(); }, discard>()),
|
|
|
|
Word("-", WordWrap<[] { *(sp() - 1) -= *sp(); }, discard>),
|
|
|
|
Word("*", WordWrap<[] { *(sp() - 1) *= *sp(); }, discard>()),
|
|
|
|
Word("*", WordWrap<[] { *(sp() - 1) *= *sp(); }, discard>),
|
|
|
|
Word("/", WordWrap<[] { *(sp() - 1) /= *sp(); }, discard>()),
|
|
|
|
Word("/", WordWrap<[] { *(sp() - 1) /= *sp(); }, discard>),
|
|
|
|
Word("mod", WordWrap<[] { *(sp() - 1) %= *sp(); }, discard>()),
|
|
|
|
Word("mod", WordWrap<[] { *(sp() - 1) %= *sp(); }, discard>),
|
|
|
|
Word("=", WordWrap<[] { *(sp() - 1) = *(sp() - 1) == *sp(); }, discard, tobool>()),
|
|
|
|
Word("=", WordWrap<[] { *(sp() - 1) = *(sp() - 1) == *sp(); }, discard, tobool>),
|
|
|
|
Word("<", WordWrap<[] { *(sp() - 1) = *(sp() - 1) < *sp(); }, discard, tobool>()),
|
|
|
|
Word("<", WordWrap<[] { *(sp() - 1) = *(sp() - 1) < *sp(); }, discard, tobool>),
|
|
|
|
Word("or", WordWrap<[] { *(sp() - 1) |= *sp(); }, discard>()),
|
|
|
|
Word("or", WordWrap<[] { *(sp() - 1) |= *sp(); }, discard>),
|
|
|
|
Word("and", WordWrap<[] { *(sp() - 1) &= *sp(); }, discard>()),
|
|
|
|
Word("and", WordWrap<[] { *(sp() - 1) &= *sp(); }, discard>),
|
|
|
|
Word("xor", WordWrap<[] { *(sp() - 1) ^= *sp(); }, discard>()),
|
|
|
|
Word("xor", WordWrap<[] { *(sp() - 1) ^= *sp(); }, discard>),
|
|
|
|
Word("lshift", WordWrap<[] { *(sp() - 1) <<= *sp(); }, discard>()),
|
|
|
|
Word("lshift", WordWrap<[] { *(sp() - 1) <<= *sp(); }, discard>),
|
|
|
|
Word("rshift", WordWrap<[] { *(sp() - 1) >>= *sp(); }, discard>()),
|
|
|
|
Word("rshift", WordWrap<[] { *(sp() - 1) >>= *sp(); }, discard>),
|
|
|
|
Word(">r", WordWrap<[] { rpush(pop()); }>()),
|
|
|
|
Word(">r", WordWrap<[] { rpush(pop()); }>),
|
|
|
|
Word("r>", WordWrap<[] { push(rpop()); }>()),
|
|
|
|
Word("r>", WordWrap<[] { push(rpop()); }>),
|
|
|
|
Word("immediate", WordWrap<[] { ((Word *)LATEST)->markImmediate(); }>()),
|
|
|
|
Word("immediate", WordWrap<[] { ((Word *)LATEST)->markImmediate(); }>),
|
|
|
|
Word("aligned", WordWrap<[] { *sp() = aligned(*sp()); }>()),
|
|
|
|
Word("aligned", WordWrap<[] { *sp() = aligned(*sp()); }>),
|
|
|
|
Word("align", WordWrap<align>()),
|
|
|
|
Word("align", WordWrap<align>),
|
|
|
|
Word("literal", WordWrap<[] { if (STATE) compileliteral(); }>()).markImmediate(),
|
|
|
|
Word("literal", WordWrap<[] { if (STATE) compileliteral(); }>).markImmediate(),
|
|
|
|
Word("\'", WordWrap<tick>()),
|
|
|
|
Word("\'", WordWrap<tick>),
|
|
|
|
Word("_i", WordWrap<[] { *sp() = ((Word *)*sp())->immediate(); }, tobool>()),
|
|
|
|
Word("_i", WordWrap<[] { *sp() = ((Word *)*sp())->immediate(); }, tobool>),
|
|
|
|
Word("[']", WordWrap<tick, compileliteral>()).markImmediate(),
|
|
|
|
Word("[']", WordWrap<tick, compileliteral>).markImmediate(),
|
|
|
|
Word("compile,", WordWrap<peek, commaSP>()),
|
|
|
|
Word("compile,", WordWrap<peek, commaSP>),
|
|
|
|
Word("word", WordWrap<word>()),
|
|
|
|
Word("word", WordWrap<word>),
|
|
|
|
Word("_b", WordWrap<[] {
|
|
|
|
Word("_b", WordWrap<[] {
|
|
|
|
std::putchar('#'); // Gives a good breakpoint spot for gdb
|
|
|
|
std::putchar('#'); // Gives a good breakpoint spot for gdb
|
|
|
|
}>()),
|
|
|
|
}>),
|
|
|
|
Word(".", WordWrap<[] { std::cout << pop() << ' '; }>())
|
|
|
|
Word(".", WordWrap<[] { std::cout << pop() << ' '; }>)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void getinput()
|
|
|
|
void getinput()
|
|
|
|