commit fbc2832fa5316af243fffadaa57547ef91274f56
parent cd8f5c8841d67357f4c6b91c74b14aac0a1d89e6
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Wed, 1 Jun 2022 13:51:40 -0400
Allow calling subword. Also, this Forth is STC now.
Diffstat:
4 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/asm.py b/asm.py
@@ -38,10 +38,13 @@ def newword():
prevword = pc()
words[name] = prevword
+
while tokens:
t = nextt()
if t in ops:
out('b', ops[t])
+ elif t in words:
+ out('<bi', ops[b'CALLi'], words[t])
elif t == b':':
newword()
elif t.startswith(b'lbl'):
diff --git a/dusk.c b/dusk.c
@@ -23,7 +23,7 @@ static void stack_push(struct stack *s, cell x) {
byte mem[MEMSIZE];
struct stack ps, rs;
-cell ip, pc;
+cell pc;
byte running;
/* Utilities */
@@ -44,18 +44,16 @@ static void pushRS(cell x) { stack_push(&rs, x); }
static cell pc32() { cell n = gc(pc); pc+=4; return n; }
/* Native words */
-/* core routines - idx 0 */
-static void lblnext() { pc = gc(ip); ip += 4; }
-static void lblxt() { pushRS(ip); ip = pop(); lblnext(); }
-
-/* stack - idx 2 */
+/* stack */
static void PUSHi() { push(pc32()); }
-/* flow - idx 3 */
+/* flow */
static void JMPi() { pc = gc(pc); }
+static void CALLi() { pushRS(pc+4); JMPi(); }
+static void exit() { pc = popRS(); }
static void bye() { running = 0; }
-/* I/O - idx 5 */
+/* I/O */
static void emit() { putchar(pop()); }
static void key() { push(getchar()); }
diff --git a/forth.txt b/forth.txt
@@ -1,2 +1,3 @@
JMPi lblboot
-: BOOT 'f' emit 'o' emit 'o' emit bye
+: foo 'f' emit 'o' emit 'o' emit exit
+: BOOT foo bye
diff --git a/ops.txt b/ops.txt
@@ -1,4 +1,3 @@
-lblnext, lblxt,
PUSHi,
-JMPi, bye,
+JMPi, CALLi, exit, bye,
emit, key