From 7bd9090913b546cf0944739a3e3d69c9212244e8 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 6 Feb 2022 17:18:11 -0800 Subject: [PATCH] Builtins now vlisting. --- ueforth/common/core.h | 3 ++- ueforth/common/interp.h | 1 + ueforth/common/opcodes.h | 1 + ueforth/common/utils.fs | 20 ++++++++++++++++---- ueforth/windows/interp.h | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ueforth/common/core.h b/ueforth/common/core.h index 4c30d86..3257d5e 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -59,6 +59,7 @@ static struct { // Layout not used by Forth. cell_t *rp; // spot to park main thread cell_t DOLIT_XT, DOFLIT_XT, DOEXIT_XT, YIELD_XT; + void *DOCREATE_OP; const BUILTIN_WORD *builtins; } g_sys; @@ -260,7 +261,7 @@ static void forth_init(int argc, char *argv[], void *heap, forth_run(0); #define V(name) \ create(#name "-builtins", sizeof(#name "-builtins") - 1, \ - BUILTIN_FORK, 0); \ + BUILTIN_FORK, g_sys.DOCREATE_OP); \ *g_sys.heap++ = VOC_ ## name; VOCABULARY_LIST #undef V diff --git a/ueforth/common/interp.h b/ueforth/common/interp.h index cdd1b4a..140d2de 100644 --- a/ueforth/common/interp.h +++ b/ueforth/common/interp.h @@ -31,6 +31,7 @@ static cell_t *forth_run(cell_t *init_rp) { }; if (!init_rp) { + g_sys.DOCREATE_OP = ADDR_DOCREATE; g_sys.builtins = builtins; return 0; } diff --git a/ueforth/common/opcodes.h b/ueforth/common/opcodes.h index 4f37503..8ebb2ff 100644 --- a/ueforth/common/opcodes.h +++ b/ueforth/common/opcodes.h @@ -125,4 +125,5 @@ typedef struct { sp = evaluate1(sp, &tfp); \ fp = tfp; w = *sp--; DROP; if (w) JMPW) \ Y(EXIT, ip = (cell_t *) *rp--) \ + XV(internals, "'builtins", TBUILTINS, DUP; tos = (cell_t) g_sys.builtins) \ XV(forth_immediate, ";", SEMICOLON, COMMA(g_sys.DOEXIT_XT); UNSMUDGE(); g_sys.state = 0) diff --git a/ueforth/common/utils.fs b/ueforth/common/utils.fs index 0a3508d..8aaeb7f 100644 --- a/ueforth/common/utils.fs +++ b/ueforth/common/utils.fs @@ -59,6 +59,7 @@ internals definitions dup @ ['] see-loop @ = if ['] : see. dup see. space see-loop ['] ; see. cr exit then + dup >flags BUILTIN_FORK and if ." Built-in fork: " see. exit then dup @ ['] input-buffer @ = if ." CREATE/VARIABLE: " see. cr exit then dup @ ['] SMUDGE @ = if ." DOES>/CONSTANT: " see. cr exit then dup >params 0= if ." Built-in: " see. cr exit then @@ -102,11 +103,22 @@ only forth definitions ( List words in Dictionary / Vocabulary ) internals definitions 70 value line-width -: onlines ( n xt -- n xt ) - swap dup line-width > if drop 0 cr then over >name nip + 1+ swap ; +0 value line-pos +: onlines ( xt -- xt ) + line-pos line-width > if cr 0 to line-pos then + dup >name nip 1+ line-pos + to line-pos ; +: vins. ( voc -- ) + >r 'builtins 2 cells + begin dup 2 cells - @ while + dup >params r@ = if dup onlines see. then + 3 cells + + repeat drop rdrop ; +: ins. ( n xt -- n ) cell+ @ vins. ; +: ?ins. ( xt -- xt ) dup >flags BUILTIN_FORK and if dup ins. then ; forth definitions also internals -: vlist 0 context @ @ begin dup nonvoc? while onlines dup see. >link repeat 2drop cr ; -: words 0 context @ @ begin dup while onlines dup see. >link repeat 2drop cr ; +: vlist 0 to line-pos context @ @ + begin dup nonvoc? while onlines dup ?ins. see. >link repeat drop cr ; +: words 0 to line-pos context @ @ + begin dup while onlines dup see. >link repeat drop cr ; only forth definitions ( Extra Task Utils ) diff --git a/ueforth/windows/interp.h b/ueforth/windows/interp.h index 1f617dc..b830b0a 100644 --- a/ueforth/windows/interp.h +++ b/ueforth/windows/interp.h @@ -41,6 +41,7 @@ static cell_t *forth_run(cell_t *init_rp) { }; if (!init_rp) { + g_sys.DOCREATE_OP = ADDR_DOCREATE; g_sys.builtins = builtins; return 0; }