diff options
| author | kitty <nepeta@canaglie.net> | 2026-04-22 11:53:30 +1000 |
|---|---|---|
| committer | kitty <nepeta@canaglie.net> | 2026-04-22 11:53:30 +1000 |
| commit | 1a5dfab8ccc62b806c9abb53940f4e806d76f3da (patch) | |
| tree | 42a1f681c3d15610433301caf07c38c50a5159ab | |
| parent | 6975cd610ac3a32050e337b04d3f8c3f492cd28b (diff) | |
fix forth vocabulary word, add terminal vocabulary
| -rw-r--r-- | readme.md | 10 | ||||
| -rw-r--r-- | sanctuary.fs | 92 | ||||
| -rw-r--r-- | test.fs | 1 |
3 files changed, 93 insertions, 10 deletions
@@ -470,10 +470,8 @@ set the smudge bit on the given word. ### `hijacks ( xt "word" -- )` 'hijack' an existing definition to perform the action of xt. -this word *will* corrupt the dictionary if used outside -its very specific context (replacing core assembly words -with better versions in forth), so it should be avoided -in favour of `defer` and friends. +this word *will* corrupt the dictionary if used wrong, +so it should be avoided in favour of `defer` and friends. ### `hld ( -- a )` the address of the beginning of the used section of the pad buffer. @@ -814,5 +812,5 @@ but it diverges in a few notable places: public domain. although: a modified version of john hayes' test suite is used -which is under 'distribute but you have to include the copyright notice' -it's included in the source +which is under 'distribute but you have to include the copyright notice'. +it's included in the source. diff --git a/sanctuary.fs b/sanctuary.fs index ac71042..dc2fc8c 100644 --- a/sanctuary.fs +++ b/sanctuary.fs @@ -424,10 +424,8 @@ hex b16b0065cafebabe constant empty-voc-magic decimal : empty-wordlist? ( wid -- ? ) @ cell- @ empty-voc-magic = ; : wordlist empty-voc-magic , here 0 , ; -wordlist constant forth-wordlist defer default-wordlist -:noname forth-wordlist 1 ; is default-wordlist \ the most recent is stored toward high memory : get-order ( -- widn ... wid1 n ) @@ -446,10 +444,17 @@ defer default-wordlist i cells context + ! loop ; +\ Bad Thing: using one of these words on their own +\ will make it the only vocabulary which breaks things +\ maybe vocabulary should perform `also`? : (vocabulary) create , does> >r get-order swap drop r> swap set-order ; : vocabulary wordlist (vocabulary) ; +vocabulary forth +' forth 21 + constant forth-wordlist \ hack; depends on create +:noname forth-wordlist 1 ; is default-wordlist + : get-current ( -- wid ) current @ ; : set-current ( wid -- ) current ! ; @@ -459,7 +464,6 @@ defer default-wordlist : only -1 set-order ; : also get-order over swap 1+ set-order ; -forth-wordlist (vocabulary) forth -1 set-order : visible? ( ht -- ? ) >ffa c@ 1 and 0= ; @@ -488,7 +492,12 @@ private{ >r >r 2drop r> r> ( ht -1 ) unloop exit then - loop 0 ; + loop ( 0 ; ) + \ prevent having Nothing in the dictionary + \ should do something in `vocabulary` to fix this really + 2dup forth-wordlist search-wordlist dup 0<> if + >r >r 2drop r> r> exit + then ; : (smudge) latest @ >ffa dup c@ [ hex ] 01 [ decimal ] xor swap c! ; : (immediate) latest @ >ffa dup c@ [ hex ] 02 [ decimal ] or swap c! ; @@ -598,14 +607,89 @@ decimal \ doesn't work when there are multiple vocabularies, \ for some reason the header of the last word is printed : words get-order 0 ?do vlist loop ; + +: bytes-allocated dp$ @ dp0 @ - ; +: bytes-used here dp0 @ - ; +: bytes-free bytes-allocated bytes-used - ; + \ }}} \ TERMINAL CONTROL {{{ +\ todo doc vocabulary terminal also terminal definitions 60 constant termios# create termios termios# allot +create old-termios termios# allot + +: termios.c_iflag ; +: termios.c_oflag 4 + ; +: termios.c_cflag 8 + ; +: termios.c_lflag 12 + ; +: termios.c_line 16 + ; +: termios.c_cc 17 + ; + +\ consts {{{ +hex +5401 constant TCGETS +5402 constant TCSETS +5403 constant TCSETSW +5404 constant TCSETSF + +1 constant IGNBRK 2 constant BRKINT 4 constant IGNPAR +8 constant PARMRK 10 constant INPCK 20 constant ISTRIP +40 constant INLCR 80 constant IGNCR 100 constant ICRNL +200 constant IUCLC 400 constant IXON 800 constant IXANY +1000 constant IXOFF 2000 constant IMAXBEL 4000 constant IUTF8 + +1 constant OPOST + +1 constant ISIG 2 constant ICANON 8 constant ECHO +40 constant ECHONL 8000 constant IEXTEN + +30 constant CSIZE 30 constant CS8 100 constant PARENB +decimal +\ }}} + +: ioctl 16 syscall3 ; + +: ESC 27 emit ; +: CSI ESC ." [" ; + +: CSIm ( n -- ) CSI (.) type ." m" ; + +: foreground 30 + CSIm ; +: background 40 + CSIm ; + +0 constant black 1 constant red 2 constant green +3 constant yellow 4 constant blue 5 constant magenta +6 constant cyan 7 constant white 9 constant default + +: bold 1 CSIm ; : normal 0 CSIm ; + +: at-xy ( x y -- ) CSI 1+ (.) type ." ;" 1+ (.) type ." H" ; +: page CSI ." 2J" 0 0 at-xy ; + +: restore-termios old-termios TCSETSF stdin ioctl ; +: backup-termios old-termios TCGETS stdin ioctl ; +: cooked restore-termios ; +\ SETTING RAW MODE FLAGS {{{ +\ see termios(3) +: raw-iflag ( tios -- ) termios.c_iflag dup @ + IGNBRK BRKINT or PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or + negate and swap ! ; +: raw-oflag ( tios -- ) termios.c_oflag dup @ OPOST negate and swap ! ; +: raw-lflag ( tios -- ) termios.c_lflag dup @ + ECHO ECHONL or ICANON or ISIG or IEXTEN or negate and swap ! ; +: raw-cflag ( tios -- ) termios.c_cflag dup @ + CSIZE PARENB or negate and CS8 or swap ! ; +\ }}} +: raw backup-termios termios dup raw-iflag dup raw-oflag dup raw-lflag + dup raw-cflag TCSETSF stdin ioctl ; + +: altscr CSI ." ?1049h" ; +: normscr CSI ." ?1049l" ; previous definitions \ }}} @@ -518,5 +518,6 @@ t{ get-current empty-wordlist? -> <true> }t t{ : testicle 67 ; -> }t t{ get-current empty-wordlist? -> <false> }t t{ testicle -> 67 }t +t{ previous definitions -> }t decimal |
