]> code.bitgloo.com Git - clyne/foci.git/commitdiff
add foci getchar, setchar hooks
authorClyne Sullivan <clyne@bitgloo.com>
Fri, 24 Jan 2025 23:27:47 +0000 (18:27 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Fri, 24 Jan 2025 23:27:47 +0000 (18:27 -0500)
foci.c
foci.h
main.c

diff --git a/foci.c b/foci.c
index 2ca054ff8e00cdab99daa31ca21a454a0eea22f6..d957c5737460ca22f6a04989f11d127a0f3f5be2 100644 (file)
--- a/foci.c
+++ b/foci.c
@@ -16,7 +16,6 @@
 
 #include "foci.h"
 
-#include <stdio.h> // puts
 #include <stdlib.h> // strtol
 #include <string.h> // strncmp
 
@@ -48,8 +47,7 @@ NAKED void compname(void)
 
     STASH;
     for (;;) {
-        extern int getchar(void);
-        ch = getchar();
+        ch = foci_getchar();
 
         if (ch <= 0x20)
             break;
@@ -105,8 +103,7 @@ N(b,      "_b",     &w_literal) { ++pp; pp = (intptr_t **)*pp; NEXT; }
 N(bz,     "_bz",    &w_literal) { ++pp; if (!*sp++) { pp = (intptr_t **)*pp; } NEXT; }
 I(fif,    "if",     &w_b)       LIT(bz), comma, FTH(here), LIT(0), comma, END
 I(then,   "then",   &w_fif)     FTH(here), LIT(sizeof(intptr_t)), sub, swap, poke, END
-I(felse,  "else",   &w_then)    LIT(b), comma, FTH(here), LIT(0), comma, swap,
-                                FTH(here), LIT(sizeof(intptr_t)), sub, swap, poke, END
+I(felse,  "else",   &w_then)    LIT(b), comma, FTH(here), LIT(0), comma, swap, FTH(then), END
 #define LATEST      &w_felse
 
 void call(void *ptr)
@@ -141,7 +138,9 @@ void parse_word(const char *buf, const char *s)
                 *--sp = n;
             }
         } else {
-            puts("word not found");
+            const char *err = "word not found";
+            while (*err)
+                foci_putchar(*err++);
         }
     } else {
         if (state && !(l->attr & ATTR_IMMEDIATE)) {
diff --git a/foci.h b/foci.h
index 6a96f32c0df3ed68976a209927ae8e1cd27f19dd..9a87723a11fb5006214571d458c0d1c6aa78b55b 100644 (file)
--- a/foci.h
+++ b/foci.h
@@ -75,6 +75,9 @@ register intptr_t     tmp asm("r15");
 #define STASH             asm("push %r12; push %r13; push %r14")
 #define RESTORE           asm("pop %r14; pop %r13; pop %r12")
 
+extern void foci_putchar(int);
+extern int  foci_getchar(void);
+
 void init(void);
 int depth(void);
 int compiling(void);
diff --git a/main.c b/main.c
index 2e903ae127a73a51383da6a03cdf4609aa51c52f..66d908ef731727fd1de0e6359d16891914c3906e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -28,6 +28,16 @@ N(dot, ".", 0) {
     NEXT;
 }
 
+void foci_putchar(int ch)
+{
+    putchar(ch);
+}
+
+int foci_getchar(void)
+{
+    return getchar();
+}
+
 int main()
 {
     char buf[128];