duskos

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

commit 4696d352b148baf5cfeab7825d3f6f8593f63487
parent adb8198d5db206a5a71b34634a830ea37e6d1cb5
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed, 27 Jul 2022 21:14:21 -0400

Replace "with" with "to@!"

It's slightly more verbose to use, but I think its semantics is clearer. The
meaning of "with" is clear too, but how it does it is less clear. With "to@!"
semantics, it's clear where the "old" value goes.

Also, using such a core english word for a rather unimportant function felt like
a waste of opportunity.

Also, when you think about it, the with[ ]with words were unnecessary complex by
their insistence on reusing "with". No need for this "ahead" nonsense: one
"to@! >r" at the beginning, one "r> to" at the end and it's done.

I've also removed sys/filter because it had a "with" usage that had to be
changed and it had no tests. I don't use it, don't need it for now, it's dead
weight. Maybe later, it can be brought back.

Diffstat:
Mfs/cc/ast.fs | 5+++--
Dfs/lib/with.fs | 6------
Mfs/sys/file.fs | 6+++---
Dfs/sys/filter.fs | 36------------------------------------
Mfs/tests/harness.fs | 6+++---
Mfs/tests/lib/all.fs | 1-
Dfs/tests/lib/with.fs | 12------------
Mfs/xcomp/bootlo.fs | 3++-
8 files changed, 11 insertions(+), 64 deletions(-)

diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -2,7 +2,6 @@ \ An abstract syntax tree, AST, is a hierarchical structure of nodes \ representing the nodes found in a C source file. See tree.fs for structure. ?f<< lib/str.fs -?f<< lib/with.fs ?f<< lib/wordtbl.fs ?f<< cc/tok.fs ?f<< cc/tree.fs @@ -200,7 +199,9 @@ ASTIDCNT wordtbl astdatatbl ( node -- node ) -1 value _pslvl \ PS level at last #[ : runmacro - ['] cc< to' in< with[ begin word runword _pslvl 0< until ]with ; + ['] cc< to@! in< >r + begin word runword _pslvl 0< until + r> to in< ; : #[0 scnt to _pslvl runmacro ; : #[1 scnt 1+ to _pslvl runmacro ; diff --git a/fs/lib/with.fs b/fs/lib/with.fs @@ -1,6 +0,0 @@ -\\ helper word to save and restore a variable across a function call. -: with ( w u addr -- ) dup >r dup @ >r ! execute r> r> ! ; -\ inline variant of with -\ ( u addr ) with[ ... ]with -: with[ [compile] ahead here swap ; immediate -: ]with exit, [compile] then litn compile rot> compile with ; immediate diff --git a/fs/sys/file.fs b/fs/sys/file.fs @@ -32,7 +32,6 @@ create _buf $100 allot : fseek ( pos hdl -- ) dup 12 + @ execute ; ?f<< /lib/scratch.fs -?f<< /lib/with.fs \ We need a private scratchpad here because some cursors can be quite \ long-lived. If we use the system scratchpad, short-lived data will overwrite @@ -42,8 +41,9 @@ $200 scratchpad$ filespad \ This creates a "f<" reader with the file descriptor embedded in it. This \ allows for a straightforward override of input/output words. : [f<] ( curfd -- word ) - filespad to' Scratchpad with[ - scratch[ litn compile getc exit, ]scratch ]with ; + filespad to@! Scratchpad >r + scratch[ litn compile getc exit, ]scratch + r> to Scratchpad ; : require word dup findpath# floaded? not if stype abort" required" else drop then ; diff --git a/fs/sys/filter.fs b/fs/sys/filter.fs @@ -1,36 +0,0 @@ -\ filter executes a word and filters its output based on a substring match. -\ it parses first the word to execute, the the substring search to filter -\ the output by. - -?f<< lib/str.fs -?f<< lib/with.fs - -SPC value filter-delim - -\ internal state -create filter-buf $100 allot -0 value filter-str -alias abort filter-out - -: filter-chunk - filter-buf filter-str scontains if - filter-buf ['] stype to' filter-out @ to' emit with - filter-delim filter-out - then - 0 filter-buf c! ; - -: filter-char ( c -- ) - dup filter-delim = if drop - filter-chunk - else - filter-buf sappend - then ; - -: with-filter-str ( w str -- ) - \ TODO: replace emit with stdout when it is added - to filter-str - 0 filter-buf c! - to' emit @ to filter-out - ['] filter-char to' emit with filter-chunk ; - -: filter ( "word" "query" -- ) ' word with-filter-str ; diff --git a/fs/tests/harness.fs b/fs/tests/harness.fs @@ -1,5 +1,3 @@ -?f<< /lib/with.fs - \ # means "assert" : # ( f -- ) not if abort" assertion failed" then ; : #eq ( n n -- ) 2dup = if 2drop else swap .x ." != " .x abort then ; @@ -13,7 +11,9 @@ create _buf $100 allot \ capture is called with one word to call with capture on. It returns the \ captured string. $ff bytes max. : capture ( -- str ) - word ['] _emit to' emit with[ 0 to _sz runword ]with + word ['] _emit to@! emit >r + 0 to _sz runword + r> to emit _sz _buf c! _buf ; : #s= ( s1 s2 -- ) 2dup s= if 2drop else swap stype ." != " stype abort then ; diff --git a/fs/tests/lib/all.fs b/fs/tests/lib/all.fs @@ -3,6 +3,5 @@ f<< /tests/lib/core.fs f<< /tests/lib/str.fs f<< /tests/lib/xdict.fs f<< /tests/lib/struct.fs -f<< /tests/lib/with.fs f<< /tests/lib/crc.fs f<< /tests/lib/io.fs diff --git a/fs/tests/lib/with.fs b/fs/tests/lib/with.fs @@ -1,12 +0,0 @@ -?f<< lib/with.fs -?f<< tests/harness.fs -testbegin -\ testing lib/with -create cell1 7 , -: foo cell1 @ 55 #eq ; -: bar ['] foo 55 cell1 with ; -bar cell1 @ 7 #eq -: _ 0 cell1 with[ 77 . ]with ; _ -: baz $77 cell1 with[ cell1 @ $77 #eq $99 cell1 ! ]with cell1 @ 7 #eq 8 cell1 ! ; -baz cell1 @ 8 #eq -testend diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -4,10 +4,11 @@ : to+ ['] +! [to] ; : to' ['] noop [to] ; : to@ ['] @ [to] ; +: @! dup @ rot> ! ; +: to@! ['] @! [to] ; : allot to+ here ; : compile ' litn ['] execute, execute, ; immediate : if compile (?br) here 4 allot ; immediate -: ahead compile (br) here 4 allot ; immediate : then here swap ! ; immediate : else compile (br) here 4 allot here rot ! ; immediate : begin here ; immediate