From a9832c2a419acae33a7a2a1b752d427e4cdf0b86 Mon Sep 17 00:00:00 2001 From: kitty Date: Tue, 21 Apr 2026 23:40:06 +1000 Subject: =?UTF-8?q?words=20now=20Working=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanctuary.fs | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'sanctuary.fs') diff --git a/sanctuary.fs b/sanctuary.fs index 70bc8cf..b542b64 100644 --- a/sanctuary.fs +++ b/sanctuary.fs @@ -414,7 +414,10 @@ variable #order create context #vocs cells allot variable current -: wordlist here 0 , ; +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 @@ -455,8 +458,8 @@ forth-wordlist (vocabulary) forth : visible? ( ht -- ? ) >ffa c@ 1 and 0= ; -\ todo handle smudge : search-wordlist ( a u wid -- 0 | ht -1 ) + dup empty-wordlist? if drop 2drop 0 exit then ( wid ) @ begin ( a u ht ) >r 2dup r@ ( a u a u ht ; backup str for next loop ) >nfa count ( a1 u1 a2 u2 ) @@ -470,6 +473,7 @@ forth-wordlist (vocabulary) forth until 2drop 0 ; +private{ : (find) ( a u -- a u 0 | ht -1 ) #order @ 0 ?do 2dup i cells context + @ ( a u a u wid ) @@ -484,14 +488,18 @@ forth-wordlist (vocabulary) forth : (immediate) latest @ >ffa dup c@ [ hex ] 02 [ decimal ] or swap c! ; : (compile-only) latest @ >ffa dup c@ [ hex ] 04 [ decimal ] or swap c! ; +: place-latest get-current empty-wordlist? if 0 else latest @ then , ; + : ((header)) here >r - latest @ , + place-latest 0 c, dup c, cmove, r> ; + : (:) parse-name (header) latest ! smudge postpone ] ; : (latest) ( -- a ) get-current ; +}private \ the actual setup is in a compiled word to prevent \ the system from shitfucking itself when its only halfway done setting up :noname [ latest @ ] literal forth-wordlist ! @@ -504,7 +512,7 @@ forth-wordlist (vocabulary) forth ['] (:) is : ['] (latest) is latest ; execute -\ drop +privatise \ }}} \ TEST SUITE {{{ @@ -512,7 +520,7 @@ execute \ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS. \ modified tho: \ - put into lowercase -\ - { } → T{ }T +\ - { } → t{ }t hex @@ -564,11 +572,27 @@ create actual-results 20 cells allot decimal \ }}} -\ PROGRAMMING TOOLS {{{ -\ should write top of stack on right -\ : .s ; -\ gonna need to be rewritten when/if i add vocabulary/wordlist support -\ : words ; +\ TOOLS {{{ +\ write top of stack on right (as stack notation does) +: .s sp >r + sp0 8 - @ begin + dup r@ >= + while + dup @ . + cell- + repeat + rdrop drop ; + +\ my idea is: words does all words, vlist is an internal word that takes a wid +\ todo ignore smudged words +: vlist ( wid -- ) dup empty-wordlist? if drop exit then + @ begin ( ht ) + dup >nfa count type space + @ ?dup 0= + until cr ; +\ doesn't work when there are multiple vocabularies, +\ for some reason the header of the last word is printed +: words get-order 0 ?do .s vlist loop ; \ }}} \ todo doc -- cgit v1.2.3