duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 0338cd91589ffa991b193f283047226ecfb0125c
parent 20a77f4c07cb29fdeaed7a1bfdcedde427659f2a
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sat,  7 Jan 2023 15:04:03 -0500

Remove alias chaining

It's too complex for its own good and not used enough (only used in sys/rdln).
Moreover, I want to change how aliases work and this change is incompatible with
chaining. Let's look at this problem again when it grows bigger.

Diffstat:
Mfs/doc/dict.txt | 2--
Mfs/doc/usage.txt | 26--------------------------
Mfs/sys/rdln.fs | 4++--
Mfs/tests/kernel.fs | 11-----------
Mfs/xcomp/bootlo.fs | 9---------
5 files changed, 2 insertions(+), 50 deletions(-)

diff --git a/fs/doc/dict.txt b/fs/doc/dict.txt @@ -344,8 +344,6 @@ alias "x y" -- Find word "x" in system dictionary and create entry "y" of ialias a "x" -- Create a new entry of type "indirect alias" with a being the address holding the pointer to the word to execute. S" x" -- *IC* Yield string literal with contents "x". -chain "x y" -- Create a new "chain" targeting alias "x" and chaining "y" to - it. ## "to" words diff --git a/fs/doc/usage.txt b/fs/doc/usage.txt @@ -179,32 +179,6 @@ Warning: this variable is global. any usage of "to" will affect the next value or alias that pops up. To avoid problems, always put your "to" call very, very close to your value/alias call. -## Chain - -It's a common pattern to want to "chain" behaviors in aliases. For example, one -could want to set the "emit" alias to a word that calls the previous "emit" -routine and add behavior to it. - -One could manually set up a variable holding the old value and then call it, but -this gets verbose after a while. - -The "chain" word does so with minimal boilerplate: - - chain emit myemitroutine - -This reads the current target of the alias "emit" and writes a new word that -calls "myemitroutine" with this address at the top of PS. Then, it sets the -"emit" alias' target to "myemitroutine". If, for example, you wanted to override -"emit" so that every character emitted was preceded by 'X', you would write: - - : myemitroutine ( c 'emit -- ) 'X' over execute execute ; - chain emit myemitroutine - -This word works both in compiling mode and outside of it. For example, this -would work too: - - : moduleinit chain emit myemitroutine ; - ## Linked lists Linked lists are a fundamental data structure in Dusk. They are simply addresses diff --git a/fs/sys/rdln.fs b/fs/sys/rdln.fs @@ -26,7 +26,7 @@ create _buf 1 allot 2drop rdln< dup 0< if drop 0 else _buf c! _buf 1 then ; create RdlnIn 0 , ' _readbuf , ' _ioerr , ' _ioerr , : rdlnreset RdlnIn to ConsoleIn in) to in> ; -: rdlnmain ( 'oldmain -- ) rdlnreset execute ; +: rdlnmain rdlnreset begin word runword again ; : rdln$ ['] (abort) to abort \ we have a read loop, we can have regular abort. - rdlnreset chain main rdlnmain ; + rdlnreset ['] rdlnmain to main ; diff --git a/fs/tests/kernel.fs b/fs/tests/kernel.fs @@ -20,17 +20,6 @@ foo 43 #eq foo 48 #eq to' foo @ 48 #eq -\ alias chaining -alias 1+ foo -: myfoo ( n 'foo -- n ) execute << ; \ (n+1)*2 -chain foo myfoo -42 foo 86 #eq \ (42+1)*2 -' 1+ to foo -: fooinit chain foo myfoo ; -42 foo 43 #eq -fooinit -42 foo 86 #eq \ (42+1)*2 - \ [if]..then 1 [if] 42 42 #eq [then] 0 [if] abort [then] diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -175,15 +175,6 @@ alias noop [then] \ a \\ comment goes before the creation of the word it comments : \\ nextmeta lladd drop EMETA_DOCLINE , begin IN< @ execute dup c, LF = until ; -\ Alias chaining. See doc/usage. -: _ ( 'target 'alias -- ) - here swap [compile] to@! execute ( 'tgt 'prevtgt ) - litn execute, exit, ; -: chain - ' ' ( 'alias 'target ) compiling if - litn litn compile _ else - swap _ then ; immediate - \ Structures 0 value _extends