Adding remember + revive.

This commit is contained in:
Brad Nelson
2021-02-25 22:32:17 -08:00
parent a5fa681de4
commit 808b6e1086
6 changed files with 35 additions and 9 deletions

View File

@ -124,7 +124,7 @@ $(GEN):
POSIX_BOOT = common/boot.fs common/vocabulary.fs common/hide_calls.fs common/ansi.fs \ 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 \ 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/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 common/fini.fs
$(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN) $(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN)
echo "ok" | cat $(POSIX_BOOT) - | $< boot $(VERSION) $(REVISION) >$@ echo "ok" | cat $(POSIX_BOOT) - | $< boot $(VERSION) $(REVISION) >$@

View File

@ -1,9 +1,18 @@
internals definitions internals definitions
( Change default block source on arduino ) ( Change default block source on arduino )
: arduino-default-use s" /spiffs/blocks.fb" open-blocks ; : arduino-default-use s" /spiffs/blocks.fb" open-blocks ;
' arduino-default-use is default-use ' arduino-default-use is default-use
( Check for autoexec.fs and run if present ) ( Setup remember file )
: autoexec ( a n -- ) s" /spiffs/autoexec.fs" ['] included catch 2drop drop ; : 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 ) ' autoexec ( leave on the stack for fini.fs )
forth definitions forth definitions

View File

@ -17,6 +17,8 @@
: -rot ( a b c -- b c a ) swap >r swap r> ; : -rot ( a b c -- b c a ) swap >r swap r> ;
: < ( a b -- a<b ) - 0< ; : < ( a b -- a<b ) - 0< ;
: > ( a b -- a>b ) swap - 0< ; : > ( a b -- a>b ) swap - 0< ;
: <= ( a b -- a>b ) swap - 0< 0= ;
: >= ( a b -- a<b ) - 0< 0= ;
: = ( a b -- a!=b ) - 0= ; : = ( a b -- a!=b ) - 0= ;
: <> ( a b -- a!=b ) = 0= ; : <> ( a b -- a!=b ) = 0= ;
: 0<> ( n -- n) 0= 0= ; : 0<> ( n -- n) 0= 0= ;

View File

@ -10,6 +10,7 @@ $4000 constant growth-gap
here growth-gap + growth-gap 1- + growth-gap 1- invert and constant saving-base here growth-gap + growth-gap 1- + growth-gap 1- invert and constant saving-base
: park-heap ( -- a ) saving-base ; : park-heap ( -- a ) saving-base ;
: park-forth ( -- a ) saving-base cell+ ; : park-forth ( -- a ) saving-base cell+ ;
: bootword ( -- a ) saving-base 2 cells + ; 0 bootword !
: save-name : save-name
'heap @ park-heap ! '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 saving-base r@ file-size throw r@ read-file throw drop
r> close-file throw r> close-file throw
park-heap @ 'heap ! 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 forth definitions also internals
: save ( "name" -- ) bl parse save-name ; : save ( "name" -- ) bl parse save-name ;
: restore ( "name" -- ) bl parse restore-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 only forth definitions

View File

@ -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

10
ueforth/posix/autoexec.fs Normal file
View File

@ -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