diff --git a/ueforth/Makefile b/ueforth/Makefile index 74805e5..441b764 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -124,13 +124,15 @@ $(GEN): POSIX_BOOT = common/boot.fs common/vocabulary.fs common/hide_calls.fs common/ansi.fs \ posix/posix.fs posix/posix_highlevel.fs posix/termios.fs common/locals.fs \ common/utils.fs common/highlevel.fs common/filetools.fs posix/posix_desktop.fs \ - common/tasks.fs common/streams.fs common/blocks.fs posix/args.fs + common/tasks.fs common/streams.fs common/blocks.fs posix/args.fs \ + common/fini.fs $(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN) echo "ok" | cat $(POSIX_BOOT) - | $< boot $(VERSION) $(REVISION) >$@ WINDOWS_BOOT = common/boot.fs common/vocabulary.fs common/hide_calls.fs common/ansi.fs \ windows/windows.fs windows/windows_highlevel.fs common/highlevel.fs \ - common/utils.fs common/tasks.fs common/streams.fs common/blocks.fs common/locals.fs + common/utils.fs common/tasks.fs common/streams.fs common/blocks.fs common/locals.fs \ + common/fini.fs $(GEN)/windows_boot.h: common/source_to_string.js $(WINDOWS_BOOT) | $(GEN) echo "ok" | cat $(WINDOWS_BOOT) - | $< boot $(VERSION) $(REVISION) >$@ @@ -141,7 +143,8 @@ ARDUINO_BOOT = common/boot.fs common/vocabulary.fs \ common/tasks.fs common/streams.fs arduino/arduino_server.fs \ arduino/arduino_bterm.fs \ arduino/esp_camera.fs common/blocks.fs \ - arduino/autoboot.fs + arduino/autoboot.fs \ + common/fini.fs $(GEN)/arduino_boot.h: common/source_to_string.js $(ARDUINO_BOOT) | $(GEN) echo "ok" | cat $(ARDUINO_BOOT) - | $< boot $(VERSION) $(REVISION) >$@ diff --git a/ueforth/arduino/autoboot.fs b/ueforth/arduino/autoboot.fs index 9377f60..00faf4d 100644 --- a/ueforth/arduino/autoboot.fs +++ b/ueforth/arduino/autoboot.fs @@ -5,6 +5,5 @@ internals definitions ( Check for autoexec.fs and run if present ) : autoexec ( a n -- ) s" /spiffs/autoexec.fs" ['] included catch 2drop drop ; -' autoexec +' autoexec ( leave on the stack for fini.fs ) forth definitions -execute diff --git a/ueforth/common/core.h b/ueforth/common/core.h index db2d1bf..07767f3 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -130,7 +130,7 @@ static cell_t *forth_run(cell_t *initrp); static void forth_init(int argc, char *argv[], void *heap, const char *src, cell_t src_len) { - g_sys.heap = (cell_t *) heap + 4; // Leave a little room. + 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; diff --git a/ueforth/common/filetools.fs b/ueforth/common/filetools.fs index d9bc8ba..3790b58 100644 --- a/ueforth/common/filetools.fs +++ b/ueforth/common/filetools.fs @@ -3,3 +3,27 @@ >r r@ write-file if r> drop ." failed write-file" exit then r> close-file drop ; + +internals definitions +( Leave some room for growth of starting system. ) +$4000 constant growth-gap +here growth-gap + growth-gap 1- + growth-gap 1- invert and constant saving-base +: park-heap ( -- a ) saving-base ; +: park-forth ( -- a ) saving-base cell+ ; +forth definitions also internals + +: save ( "name" -- ) + 'heap @ park-heap ! + forth-wordlist @ park-forth ! + bl parse w/o create-file throw >r + saving-base here over - r@ write-file throw + r> close-file throw ; + +: restore ( "name" -- ) + bl parse r/o open-file throw >r + saving-base r@ file-size throw r@ read-file throw drop + r> close-file throw + park-heap @ 'heap ! + park-forth @ forth-wordlist ! ; + +only forth definitions diff --git a/ueforth/common/fini.fs b/ueforth/common/fini.fs new file mode 100644 index 0000000..c86e62e --- /dev/null +++ b/ueforth/common/fini.fs @@ -0,0 +1,7 @@ +internals +( Bring a forth to the top of the vocabulary. ) +transfer forth +( Move heap to save point, with a gap. ) +saving-base 16 cells + 'heap ! +forth +execute ( assumes an xt for autoboot is on the dstack ) diff --git a/ueforth/posix/args.fs b/ueforth/posix/args.fs index 0d49182..46b2e31 100644 --- a/ueforth/posix/args.fs +++ b/ueforth/posix/args.fs @@ -1,6 +1,5 @@ ( Include first argument if any ) internals definitions : optional-args argc 2 < if exit then 1 argv included ; -' optional-args +' optional-args ( leave on dstack for fini.fs ) forth definitions -execute diff --git a/ueforth/posix/posix_main.c b/ueforth/posix/posix_main.c index 2a1ce03..a7fdaf2 100644 --- a/ueforth/posix/posix_main.c +++ b/ueforth/posix/posix_main.c @@ -6,7 +6,7 @@ #include "common/calls.h" #define HEAP_SIZE (10 * 1024 * 1024) -#define STACK_SIZE (16 * 1024) +#define STACK_SIZE (64 * 1024) #define PLATFORM_OPCODE_LIST \ Y(DLSYM, tos = (cell_t) dlsym(a1, a0); --sp) \ diff --git a/ueforth/windows/windows.fs b/ueforth/windows/windows.fs index 22787e1..989238c 100644 --- a/ueforth/windows/windows.fs +++ b/ueforth/windows/windows.fs @@ -147,3 +147,4 @@ forth ( Setup entry ) : ok ." uEforth v{{VERSION}} - rev {{REVISION}}" cr prompt refill drop quit ; +' forth ( leave on stack for fini.fs )