From 808b6e1086a3f7b605328baeaf7510a3d08b6fe8 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Thu, 25 Feb 2021 22:32:17 -0800 Subject: [PATCH] Adding remember + revive. --- ueforth/Makefile | 2 +- ueforth/arduino/autoboot.fs | 13 +++++++++++-- ueforth/common/boot.fs | 2 ++ ueforth/common/filetools.fs | 12 +++++++++++- ueforth/posix/args.fs | 5 ----- ueforth/posix/autoexec.fs | 10 ++++++++++ 6 files changed, 35 insertions(+), 9 deletions(-) delete mode 100644 ueforth/posix/args.fs create mode 100644 ueforth/posix/autoexec.fs diff --git a/ueforth/Makefile b/ueforth/Makefile index 441b764..834e53e 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -124,7 +124,7 @@ $(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/autoexec.fs \ common/fini.fs $(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN) echo "ok" | cat $(POSIX_BOOT) - | $< boot $(VERSION) $(REVISION) >$@ diff --git a/ueforth/arduino/autoboot.fs b/ueforth/arduino/autoboot.fs index 00faf4d..777aad8 100644 --- a/ueforth/arduino/autoboot.fs +++ b/ueforth/arduino/autoboot.fs @@ -1,9 +1,18 @@ internals definitions + ( Change default block source on arduino ) : arduino-default-use s" /spiffs/blocks.fb" open-blocks ; ' arduino-default-use is default-use -( Check for autoexec.fs and run if present ) -: autoexec ( a n -- ) s" /spiffs/autoexec.fs" ['] included catch 2drop drop ; +( Setup remember file ) +: arduino-remember-filename s" /spiffs/myforth" ; +' arduino-remember-filename is remember-filename + +( Check for autoexec.fs and run if present. + Failing that, try to revive save image. ) +: autoexec + s" /spiffs/autoexec.fs" ['] included catch 2drop drop + ['] revive catch drop ; ' autoexec ( leave on the stack for fini.fs ) + forth definitions diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 8cc7f49..d110f66 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -17,6 +17,8 @@ : -rot ( a b c -- b c a ) swap >r swap r> ; : < ( a b -- a ( a b -- a>b ) swap - 0< ; +: <= ( a b -- a>b ) swap - 0< 0= ; +: >= ( a b -- a ( a b -- a!=b ) = 0= ; : 0<> ( n -- n) 0= 0= ; diff --git a/ueforth/common/filetools.fs b/ueforth/common/filetools.fs index ce54964..6566365 100644 --- a/ueforth/common/filetools.fs +++ b/ueforth/common/filetools.fs @@ -10,6 +10,7 @@ $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+ ; +: bootword ( -- a ) saving-base 2 cells + ; 0 bootword ! : save-name 'heap @ park-heap ! @@ -23,11 +24,20 @@ here growth-gap + growth-gap 1- + growth-gap 1- invert and constant saving-base saving-base r@ file-size throw r@ read-file throw drop r> close-file throw park-heap @ 'heap ! - park-forth @ forth-wordlist ! ; + park-forth @ forth-wordlist ! + bootword @ dup if execute else drop then ; + +defer remember-filename +: default-remember-filename s" myforth" ; +' default-remember-filename is remember-filename forth definitions also internals : save ( "name" -- ) bl parse save-name ; : restore ( "name" -- ) bl parse restore-name ; +: remember remember-filename save-name ; +: startup: ( "name" ) ' bootword ! remember ; +: revive remember-filename restore-name ; +: reset remember-filename delete-file throw ; only forth definitions diff --git a/ueforth/posix/args.fs b/ueforth/posix/args.fs deleted file mode 100644 index 46b2e31..0000000 --- a/ueforth/posix/args.fs +++ /dev/null @@ -1,5 +0,0 @@ -( Include first argument if any ) -internals definitions -: optional-args argc 2 < if exit then 1 argv included ; -' optional-args ( leave on dstack for fini.fs ) -forth definitions diff --git a/ueforth/posix/autoexec.fs b/ueforth/posix/autoexec.fs new file mode 100644 index 0000000..558930b --- /dev/null +++ b/ueforth/posix/autoexec.fs @@ -0,0 +1,10 @@ +( Include first argument if any ) +internals definitions +: autoexec + ( Open passed file if any. ) + argc 2 >= if 1 argv included exit then + ( Open remembered file if any. ) + ['] revive catch drop +; +' autoexec ( leave on dstack for fini.fs ) +forth definitions