mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
3962c08662
FossilOrigin-Name: 9a36cf9d0e7ddd0131df3867aa4285f0c26ccde64ef7c193729932647d8829a3
66 lines
1.7 KiB
Forth
66 lines
1.7 KiB
Forth
# RETRO on Unix - Listener and Extensions
|
|
|
|
In this file I am implementing the interactive listener that
|
|
RETRO will run when started with `-i`, `-i,c`, or `-i,fs`.
|
|
|
|
~~~
|
|
:image:save (:s-) #1000 io:scan-for io:invoke ;
|
|
~~~
|
|
|
|
Now that I can read characters, it's time to support reading
|
|
strings. I do this via two words. The first is `parse-until`.
|
|
This will setup a temporary string as an input buffer, then
|
|
read input, passing each character ot a provided quote. When
|
|
the quote returns `TRUE`, it ends and returns the string. When
|
|
not `TRUE` it will add the character to the buffer.
|
|
|
|
~~~
|
|
{{
|
|
(c-cf) :edit? dup [ ASCII:BS eq? ] [ ASCII:DEL eq? ] bi or ;
|
|
(-f) :ended? buffer:size @TempStringMax gteq? ;
|
|
(c-) :add ended? &drop &buffer:add choose ;
|
|
(c-) :gather edit? &drop &add choose ;
|
|
(q-qc) :cycle repeat c:get dup-pair swap call not 0; drop gather again ;
|
|
---reveal---
|
|
:parse-until (:q-s)
|
|
[ s:empty buffer:set cycle drop-pair buffer:start ] buffer:preserve ;
|
|
}}
|
|
~~~
|
|
|
|
Using this, a simple `s:get` can be implemented very easily as
|
|
a quote which looks for an end of line character.
|
|
|
|
~~~
|
|
:s:get (:-s) [ [ ASCII:CR eq? ]
|
|
[ ASCII:LF eq? ] bi or ] parse-until ;
|
|
~~~
|
|
|
|
~~~
|
|
:clear (:-) '\^[2J\^[0;0H s:format s:put ;
|
|
~~~
|
|
|
|
Hide the support words.
|
|
|
|
# Standard Interactive Listener
|
|
|
|
The main part of this file is the *listener*, an interactive
|
|
read-eval-print loop.
|
|
|
|
RRE's C part will access a couple parts of this, based on the
|
|
startup flags passed.
|
|
|
|
~~~
|
|
:// (:-) script:ignore-to-eol &Ignoring v:on ; immediate
|
|
~~~
|
|
|
|
## d:source
|
|
|
|
~~~
|
|
'interface/retro-unix.retro s:keep
|
|
dup '// d:lookup d:source store
|
|
dup 'clear d:lookup d:source store
|
|
dup 's:get d:lookup d:source store
|
|
dup 'parse-until d:lookup d:source store
|
|
dup 'image:save d:lookup d:source store
|
|
drop
|
|
~~~
|