commit ab600cc4ab7e3844d4a945da62cf3e7c947efbe2
parent 1942a2380658130cbb1d59ccb9960fe79f79b98f
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Tue, 28 Jun 2022 14:54:44 -0400
Move a few words from boot.fs to lib/core
Diffstat:
2 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/boot.fs b/boot.fs
@@ -1,11 +1,5 @@
-: 2drop drop drop ;
-: 2dup over over ;
-: leave r> r~ 1 >r >r ;
: = - not ;
-: > swap < ;
-: 0< <<c nip ; : 0>= 0< not ;
-: >= < not ; : <= > not ;
-: -^ swap - ;
+: 0< <<c nip ;
: immediate current 1- dup c@ $80 or swap c! ;
: ['] ' litn ; immediate
diff --git a/fs/lib/core.fs b/fs/lib/core.fs
@@ -9,6 +9,10 @@
: doer code compile (does) CELLSZ allot ;
: does> r> ( exit current definition ) current 5 + ! ;
+\ Stack
+: 2drop drop drop ;
+: 2dup over over ;
+
\ Memory
: c@+ dup 1+ swap c@ ;
: c!+ tuck c! 1+ ;
@@ -18,6 +22,11 @@
: allot0 ( n -- ) here over 0 fill allot ;
\ Arithmetic
+: > swap < ;
+: 0>= 0< not ;
+: >= < not ;
+: <= > not ;
+: -^ swap - ;
: / /mod nip ;
: mod /mod drop ;
: << <<c drop ;
@@ -39,6 +48,29 @@ $08 const BS $04 const EOF
: ." [compile] S" compile stype ; immediate
: abort" [compile] ." compile abort ; immediate
+\ Flow control
+: leave r> r~ 1 >r >r ;
+
+\ while..repeat
+: while [compile] if swap ; immediate
+: repeat [compile] again [compile] then ; immediate
+
+\ case..endcase
+\ The case statement is very similar to what we see in other forths, but with
+\ one major difference: the "of" word specifies the thruth word. So, the
+\ "of" we see in other forths is equivalent to "of =" in Dusk OS. The comparator
+\ has to be a single word following "of".
+\ case x of = ... endof y of < ... endof ... endcase
+\ is syntactic sugar for:
+\ >r x r@ = if ... else y r@ < if ... else ... then then r~
+\ NOTE: if you want to access your reference value in the final "else", you
+\ need to use "r@".
+: case ( -- then-stopgap ) 0 compile >r ; immediate
+: of ( -- jump-addr ) compile r@ ' call, [compile] if ; immediate
+alias else endof immediate
+: endcase ( then-stopgap jump1? jump2? ... jumpn? -- )
+ ?dup if begin [compile] then ?dup not until then compile r~ ; immediate
+
\ Sequences
: [c]? ( c a u -- i )
?dup not if 2drop -1 exit then A>r over >r >r >A ( c )
@@ -47,10 +79,6 @@ $08 const BS $04 const EOF
\ Return whether strings s1 and s2 are equal
: s= ( s1 s2 -- f ) over c@ 1+ []= ;
-\ while..repeat
-: while [compile] if swap ; immediate
-: repeat [compile] again [compile] then ; immediate
-
\ Dictionary
: preventry ( w -- w ) 5 - @ ;
: preventry! ( w w -- ) 5 - ! ;
@@ -67,22 +95,6 @@ $08 const BS $04 const EOF
lastword begin dup while dup .word spc> prevword repeat drop ;
-\ case..endcase
-\ The case statement is very similar to what we see in other forths, but with
-\ one major difference: the "of" word specifies the thruth word. So, the
-\ "of" we see in other forths is equivalent to "of =" in Dusk OS. The comparator
-\ has to be a single word following "of".
-\ case x of = ... endof y of < ... endof ... endcase
-\ is syntactic sugar for:
-\ >r x r@ = if ... else y r@ < if ... else ... then then r~
-\ NOTE: if you want to access your reference value in the final "else", you
-\ need to use "r@".
-: case ( -- then-stopgap ) 0 compile >r ; immediate
-: of ( -- jump-addr ) compile r@ ' call, [compile] if ; immediate
-alias else endof immediate
-: endcase ( then-stopgap jump1? jump2? ... jumpn? -- )
- ?dup if begin [compile] then ?dup not until then compile r~ ; immediate
-
\ Number formatting
\ hexadecimal
create _ ," 0123456789abcdef"