diff --git a/ueforth/Makefile b/ueforth/Makefile index d2d16ac..e4faa21 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -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 \ diff --git a/ueforth/common/all_tests.fs b/ueforth/common/all_tests.fs index 8e4bdb9..7d9d80a 100644 --- a/ueforth/common/all_tests.fs +++ b/ueforth/common/all_tests.fs @@ -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 diff --git a/ueforth/common/core.h b/ueforth/common/core.h index c435aaf..2bcd428 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -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"); diff --git a/ueforth/common/vocabulary.fs b/ueforth/common/vocabulary.fs new file mode 100644 index 0000000..7b79887 --- /dev/null +++ b/ueforth/common/vocabulary.fs @@ -0,0 +1,4 @@ +( Implement Vocabularies ) +: forth [ current @ ] literal context ! ; +: vocabulary ( "name" ) create 0 , current @ 2 cells + , does> cell+ context ! ; +: definitions context @ current ! ; diff --git a/ueforth/common/vocabulary_tests.fs b/ueforth/common/vocabulary_tests.fs new file mode 100644 index 0000000..858b157 --- /dev/null +++ b/ueforth/common/vocabulary_tests.fs @@ -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