Adding vocabularies.

This commit is contained in:
Brad Nelson
2021-02-06 15:05:49 -08:00
parent c53307380b
commit 1a628074ce
5 changed files with 26 additions and 3 deletions

View File

@ -113,7 +113,7 @@ unit_tests: $(POSIX)/ueforth common/all_tests.fs
$(GEN):
mkdir -p $@
POSIX_BOOT = common/boot.fs common/ansi.fs \
POSIX_BOOT = common/boot.fs common/vocabulary.fs common/ansi.fs \
posix/posix.fs posix/posix_highlevel.fs \
common/highlevel.fs common/filetools.fs posix/posix_desktop.fs \
common/tasks.fs common/streams.fs common/blocks.fs posix/args.fs \
@ -121,14 +121,14 @@ POSIX_BOOT = common/boot.fs common/ansi.fs \
$(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN)
echo "ok" | cat $(POSIX_BOOT) - | $< boot >$@
WINDOWS_BOOT = common/boot.fs common/ansi.fs \
WINDOWS_BOOT = common/boot.fs common/vocabulary.fs common/ansi.fs \
windows/windows.fs windows/windows_highlevel.fs common/highlevel.fs \
common/tasks.fs common/streams.fs common/blocks.fs \
common/utils.fs
$(GEN)/windows_boot.h: common/source_to_string.js $(WINDOWS_BOOT) | $(GEN)
echo "ok" | cat $(WINDOWS_BOOT) - | $< boot >$@
ARDUINO_BOOT = common/boot.fs arduino/arduino.fs \
ARDUINO_BOOT = common/boot.fs common/vocabulary.fs arduino/arduino.fs \
posix/posix_highlevel.fs common/highlevel.fs common/filetools.fs \
common/tasks.fs common/streams.fs arduino/arduino_server.fs \
arduino/esp_camera.fs common/blocks.fs common/utils.fs \

View File

@ -2,4 +2,5 @@ include common/testing.fs
include common/utils.fs
include common/base_tests.fs
include common/utils_tests.fs
include common/vocabulary_tests.fs
run-tests

View File

@ -127,8 +127,13 @@ static void ueforth_init(int argc, char *argv[], void *heap,
g_sys.heap = (cell_t *) heap + 4; // Leave a little room.
cell_t *sp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
cell_t *rp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
// FORTH vocabulary
*g_sys.heap++ = 0;
g_sys.current = (cell_t **) g_sys.heap;
g_sys.context = (cell_t **) g_sys.heap; ++g_sys.heap;
*g_sys.heap++ = 0; *g_sys.heap++ = 0; *g_sys.heap++ = 0;
ueforth_run(0);
(*g_sys.current)[-1] = 1; // Make last word ; IMMEDIATE
g_sys.DOLIT_XT = FIND("DOLIT");

View File

@ -0,0 +1,4 @@
( Implement Vocabularies )
: forth [ current @ ] literal context ! ;
: vocabulary ( "name" ) create 0 , current @ 2 cells + , does> cell+ context ! ;
: definitions context @ current ! ;

View File

@ -0,0 +1,13 @@
e: test-vocabularies
vocabulary foo
vocabulary bar
foo definitions : test ." AAAA" cr ;
bar definitions : test ." BBBB" cr ;
forth definitions
foo test
bar test
foo test
out: AAAA
out: BBBB
out: AAAA
;e