( ispell.tal ) ( ) ( note that this is not a production spell-checker and is currently ) ( kind of brittle in the same ways as `ispell -a` on raw input ) |10 @Console [ &vector $2 &stdin $1 &pad1 $4 &type $1 &stdout $1 &stderr $1 &proc-put $1 &pad2 $1 ¶m $2 &opts $1 &host-put $1 ] |0000 @ready $1 ( ; are we ready? or still reading ispell startup banner? ) @correct $1 ( ; was the last word spelled ok? ) |0100 ( -> BRK ) ;on-console-read .Console/vector DEO2 ( ; set up console vector callback ) word-reset ( ; initialize word buffer ) #31 .Console/opts DEO ( ; child 1: write child.in, read child.out ) ;ispell-cmd .Console/param DEO2 ( ; set up `ispell -a` to run ) #01 .Console/host-put DEO BRK ( ; run the command now and return ) @word-reset ( -> ) ;word-buf ;word-pos STA2 ( ; reset word-pos pointer ) #00 ;word-buf STA JMP2r ( ; write zero into word buffer ) @word-append ( c^ -> BRK ) ;word-pos LDA2 STA ( ; pos<-c ) ;word-pos LDA2 INC2 ;word-pos STA2 ( ; pos<-pos+1 ) #00 ;word-pos LDA2 STA BRK ( ; pos<-00 ) @on-console-read .Console/type DEI ( ; what kind of input is this? ) DUP #21 NEQ ?{ POP !on-ispell-input } ( ; input from ispell process ) DUP #01 NEQ ?{ POP !on-stdin } ( ; input from stdin, i.e. user ) POP BRK ( ; otherwise skip ) @on-stdin .Console/stdin DEI #0a EQU ?check ( ; if newline, check spelling ) .Console/stdin DEI DUP !word-append ( ; if not newline, append to buffer ) @on-ispell-input ( -> BRK ) .ready LDZ ?{ !on-console-init } ( ; if not ready, parse ispell banner ) .Console/stdin DEI LIT "* EQU ( ; line starting with "*" means ok ) .Console/stdin DEI LIT "+ EQU ORA ( ; line starting with "+" means ok too ) .correct STZ ( ; store spelling result ) #20 print ( ; print a space ) LIT "0 .correct LDZ ADD println ( ; print 1 if ok, 0 otherwise ) #00 ;on-ispell-drain/done STA ( ; drain two lines ) ;on-ispell-drain .Console/vector DEO2 ( ; ignore rest of line ) BRK @on-console-init ( -- BRK ) .Console/stdin DEI #0a EQU ?{ BRK } ( ; skip ispell's one line banner ) #01 .ready STZ ( ; after newline we are ready ) LIT "> print BRK ( ; print simple prompt and return ) @on-ispell-drain ( -> BRK ) .Console/type DEI #21 EQU ?{ BRK } ( ; 0x21 signals input from child 1 ) .Console/stdin DEI #0a EQU ?{ BRK } ( ; skip ispell's outupt ) LIT &done $1 ?{ #01 ,&done STR BRK } ( ; only exit if second newline ) ;on-console-read .Console/vector DEO2 ( ; drain finished, checker is ready ) word-reset LIT "> print BRK ( ; reset buffer, print prompt, return ) @check ( word* -> BRK ) .ready LDZ ?{ !check-not-ready } ;word-buf #01 .Console/opts DEO ( ; prepare buffer, act on child 1 ) &loop LDAk ?{ POP2 #0a send BRK } ( ; when we read \0 we are done ) LDAk DUP print send INC2 !&loop ( ; send byte to child 1 and loop ) @check-not-ready #20 print LIT "? println ( ; print " ?\n" ) word-reset LIT "> print BRK ( ; reset the buffer, print prompt, return ) @send ( c^ -> ) .Console/proc-put DEO JMP2r ( ; send character to ispell process ) @print ( c^ -> ) .Console/stdout DEO JMP2r ( ; send character to stdout ) @println ( c^ -> ) print #0a .Console/stdout DEO JMP2r ( ; send character and newline to stdout ) @ispell-cmd "ispell 20 "-a 00 ( ; "ispell -a" ) @word-pos $2 ( ; position in word-buf ) @word-buf $100 ( ; buffer for input characters )