finish colon/semic; compile native words better

main
Clyne 1 month ago
parent 461581a84e
commit b975575ebc
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

2
.gitignore vendored

@ -1,5 +1,5 @@
main main
.sw* *.sw*
# ---> C # ---> C
# Prerequisites # Prerequisites

@ -23,8 +23,21 @@
#define END EXIT, }; #define END EXIT, };
#define W(name, tname, prev) WORD(name, tname, prev, 0) #define W(name, tname, prev) WORD(name, tname, prev, 0)
#define N(name, tname, prev) WORD(name, tname, prev, ATTR_NATIVE)
#define I(name, tname, prev) WORD(name, tname, prev, ATTR_IMMEDIATE) #define I(name, tname, prev) WORD(name, tname, prev, ATTR_IMMEDIATE)
#define N(name, tname, prev) \
extern const void *name##_body[]; \
struct word_t w_##name = { \
name##_body, prev, \
ATTR_NATIVE + sizeof(tname) - 1, tname \
}; \
const void *name##_body[] = { name, EXIT };
#define C(name, tname, prev) \
extern const void *name##_body[]; \
struct word_t w_##name = { \
name##_body, prev, \
(ATTR_NATIVE | ATTR_IMMEDIATE) + sizeof(tname) - 1, tname \
}; \
const void *name##_body[] = { name, EXIT };
struct word_t struct word_t
{ {
@ -56,8 +69,8 @@ void push()
NAKED NAKED
void sp_at() void sp_at()
{ {
*sp = (intptr_t)sp;
sp = sp - 1; sp = sp - 1;
*sp = (intptr_t)(sp + 1);
NEXT; NEXT;
} }
@ -128,40 +141,54 @@ NAKED void colon()
} }
RESTORE; RESTORE;
here += *(unsigned char *)here;
here = (intptr_t *)(((intptr_t)here + sizeof(intptr_t) - 1) here = (intptr_t *)(((intptr_t)here + sizeof(intptr_t) - 1)
& ~(sizeof(intptr_t) - 1)); & ~(sizeof(intptr_t) - 1));
*(intptr_t *)tmp = (intptr_t)here; *(intptr_t *)tmp = (intptr_t)here;
*--sp = tmp;
state = -1;
NEXT;
}
NAKED void semic()
{
extern struct word_t *latest;
*here++ = (intptr_t)doexit;
latest = (struct word_t *)*sp++;
state = 0;
NEXT; NEXT;
} }
//W(two, "2", &w_dup) LIT(2), FTH(dup), END //W(two, "2", &w_dup) LIT(2), FTH(dup), END
W(dup, "dup", 0) sp_at, peek, END W(dup, "dup", 0) sp_at, peek, END
W(drop, "drop", &w_dup) drop, END N(drop, "drop", &w_dup)
W(swap, "swap", &w_drop) swap, END N(swap, "swap", &w_drop)
W(peek, "@", &w_swap) peek, END N(peek, "@", &w_swap)
W(poke, "!", &w_peek) poke, END N(poke, "!", &w_peek)
W(cpeek, "c@", &w_poke) cpeek, END N(cpeek, "c@", &w_poke)
W(cpoke, "c!", &w_cpeek) cpoke, END N(cpoke, "c!", &w_cpeek)
W(add, "+", &w_cpoke) add, END N(add, "+", &w_cpoke)
W(sub, "-", &w_add) sub, END N(sub, "-", &w_add)
W(mul, "*", &w_sub) mul, END N(mul, "*", &w_sub)
W(div, "/", &w_mul) div, END N(div, "/", &w_mul)
W(mod, "mod", &w_div) mod, END N(mod, "mod", &w_div)
W(and, "and", &w_mod) and, END N(and, "and", &w_mod)
W(or, "or", &w_and) or, END N(or, "or", &w_and)
W(xor, "xor", &w_or) xor, END N(xor, "xor", &w_or)
W(cell, "cell", &w_xor) cell, END N(cell, "cell", &w_xor)
W(cellp, "cell+", &w_cell) cell, add, END W(cellp, "cell+", &w_cell) cell, add, END
W(cells, "cells", &w_cellp) cell, mul, END W(cells, "cells", &w_cellp) cell, mul, END
W(dict, "_d", &w_cells) LIT(dict), END W(dict, "_d", &w_cells) LIT(dict), END
W(here, "here", &w_dict) LIT(&here), peek, END W(here, "here", &w_dict) LIT(&here), peek, END
I(intr, "[", &w_here) intr, END C(intr, "[", &w_here)
W(comp, "]", &w_intr) comp, END N(comp, "]", &w_intr)
W(dot, ".", &w_comp) dot, END N(dot, ".", &w_comp)
W(colon, ":", &w_dot) colon, END N(colon, ":", &w_dot)
W(align, "align", &w_colon) align, END C(semic, ";", &w_colon)
W(comma, ",", &w_align) comma, END N(align, "align", &w_semic)
N(comma, ",", &w_align)
struct word_t *latest = &w_comma; struct word_t *latest = &w_comma;
void init() void init()
@ -260,7 +287,12 @@ int main()
} }
} else { } else {
if (state && !(l->attr & ATTR_IMMEDIATE)) { if (state && !(l->attr & ATTR_IMMEDIATE)) {
if (!(l->attr & ATTR_NATIVE)) {
*here++ = (intptr_t)enter;
*here++ = (intptr_t)l->body; *here++ = (intptr_t)l->body;
} else {
*here++ = (intptr_t)l->body[0];
}
} else { } else {
call(l->body); call(l->body);
} }

Loading…
Cancel
Save