6 include term-colours.4th
9 1 constant boolean-type
10 : istype? ( obj -- obj b )
16 variable dummy-parse-idx
19 parse-idx @ dummy-parse-idx ! ;
22 dummy-parse-idx @ parse-idx ! ;
26 : charavailable? ( -- bool )
27 parse-str @ @ parse-idx @ >
30 : nextchar ( -- char )
32 parse-str @ 1+ parse-idx @ + @
38 : whitespace? ( -- bool )
45 nextchar [char] ( = or
46 nextchar [char] ) = or
66 digit? minus? or false = if
78 delim? charavailable? false = or if
87 : boolean? ( -- bool )
88 nextchar [char] # <> if false exit then
94 and if 1 parse-idx -! false exit then
100 : readnum ( -- num-atom )
108 10 * nextchar [char] 0 - +
117 : readbool ( -- bool-atom )
120 nextchar [char] f = if
129 \ Parse a counted string into a scheme expression
144 bold fg red ." Error parsing string starting at character '"
146 ." '. Aborting." reset-term cr
152 : self-evaluating? ( obj -- obj bool )
153 number-type istype? if true exit then
154 boolean-type istype? if true exit then
162 bold fg red ." Error evaluating expression - unrecognized type. Aborting." reset-term cr
168 : printnum ( numobj -- ) drop . ;
169 : printbool ( numobj -- )
179 number-type istype? if printnum exit then
180 boolean-type istype? if printbool exit then
185 create repl-buffer 161 allot
186 repl-buffer parse-str !
189 repl-buffer 1+ 160 expect cr span @ repl-buffer ! ;
192 repl-buffer @ 0= if false exit then
193 repl-buffer 1+ @ 4 <> if false exit then
197 cr ." Welcome to scheme.forth.jl!" cr
198 ." Use Ctrl-D to exit." cr
201 cr bold fg green ." => " reset-term
205 bold fg blue ." Moriturus te saluto." reset-term
213 fg cyan print reset-term