aboutsummaryrefslogtreecommitdiffstats
path: root/foci.c
diff options
context:
space:
mode:
Diffstat (limited to 'foci.c')
-rw-r--r--foci.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/foci.c b/foci.c
index 2488c9c..fdf7d76 100644
--- a/foci.c
+++ b/foci.c
@@ -32,7 +32,10 @@ static intptr_t ***saved_rp;
NAKED void enter(void) { *--rp = ++pp; pp = (intptr_t **)*pp; goto *(*pp); }
NAKED void push(void) { *--sp = (intptr_t)*++pp; NEXT; }
- void fexit(void) { if (rp < END_OF(rstack)) { pp = *rp++; NEXT; } }
+NAKED void fexit(void) { pp = *rp++; NEXT; }
+
+void fend(void) {}
+static const void * const fend_b[2] = { 0, fend };
NAKED void compname(void)
{
@@ -161,7 +164,23 @@ N(pushr2, "2>r", &w_popr) { *--rp = (intptr_t **)sp[1];
*--rp = (intptr_t **)sp[0]; sp += 2; NEXT; }
N(popr2, "2r>", &w_pushr2) { *--sp = (intptr_t)rp[1];
*--sp = (intptr_t)rp[0]; rp += 2; NEXT; }
-#define LATEST_INIT &w_popr2
+N(rpeek, "r@", &w_popr2) { *--sp = (intptr_t)*rp; NEXT; }
+N(i, "i", &w_rpeek) { *--sp = (intptr_t)*rp; NEXT; }
+I(fdo, "do", &w_i) LIT(pushr2), comma, FTH(begin), END
+I(loop, "loop", &w_fdo) LIT(popr), comma,
+ LIT(enter), comma,
+ LIT(inc_body), comma,
+ LIT(rpeek), comma,
+ LIT(over), comma,
+ LIT(eq), comma,
+ LIT(swap), comma,
+ LIT(pushr), comma,
+ FTH(until),
+ LIT(popr2), comma,
+ LIT(drop), comma, LIT(drop), comma, END
+W(immediate, "immediate", &w_loop) FTH(latest), LIT(2 * sizeof(intptr_t)), add,
+ LIT(ATTR_IMMEDIATE), over, cpeek, or, swap, cpoke, END
+#define LATEST_INIT &w_immediate
void enter_forth(const void *ptr)
{
@@ -170,6 +189,7 @@ void enter_forth(const void *ptr)
rp = saved_rp;
pp = ptr;
+ *--rp = (intptr_t **)fend_b;
((void (*)())*pp)();
saved_sp = sp;
@@ -303,6 +323,11 @@ int depth(void)
return END_OF(dstack) - saved_sp;
}
+int rdepth(void)
+{
+ return END_OF(rstack) - saved_rp;
+}
+
int compiling(void)
{
return STATE;