2020-11-23 19:58:51 +01:00
|
|
|
# RETRO on Unix - Listener and Extensions
|
2017-10-20 05:05:43 +02:00
|
|
|
|
2019-02-05 21:22:17 +01:00
|
|
|
In this file I am implementing the interactive listener that
|
2020-11-23 19:58:51 +01:00
|
|
|
RETRO will run when started with `-i`, `-i,c`, or `-i,fs`.
|
2019-03-29 21:03:05 +01:00
|
|
|
|
2019-05-22 16:20:01 +02:00
|
|
|
~~~
|
2021-04-22 15:45:32 +02:00
|
|
|
:image:save (s-) #1000 io:scan-for io:invoke ;
|
2019-05-22 16:20:01 +02:00
|
|
|
~~~
|
2017-10-20 05:05:43 +02:00
|
|
|
|
2019-02-05 21:22:17 +01:00
|
|
|
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.
|
2017-10-20 05:05:43 +02:00
|
|
|
|
2019-02-05 21:22:17 +01:00
|
|
|
~~~
|
|
|
|
{{
|
2020-11-23 19:58:51 +01:00
|
|
|
(c-cf) :edit? dup [ ASCII:BS eq? ] [ ASCII:DEL eq? ] bi or ;
|
2024-08-05 20:48:57 +02:00
|
|
|
(-f) :ended? buffer:size @TempStringMax gteq? ;
|
|
|
|
(c-) :add ended? &drop &buffer:add choose ;
|
|
|
|
(c-) :gather edit? &drop &add choose ;
|
2020-11-23 19:58:51 +01:00
|
|
|
(q-qc) :cycle repeat c:get dup-pair swap call not 0; drop gather again ;
|
2019-02-05 21:22:17 +01:00
|
|
|
---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.
|
|
|
|
|
|
|
|
~~~
|
2021-07-07 19:30:54 +02:00
|
|
|
:s:get (-s) [ [ ASCII:CR eq? ]
|
2023-04-12 02:34:17 +02:00
|
|
|
[ ASCII:LF eq? ] bi or ] parse-until ;
|
2019-02-05 21:22:17 +01:00
|
|
|
~~~
|
|
|
|
|
2019-03-29 19:46:22 +01:00
|
|
|
~~~
|
2020-11-23 19:58:51 +01:00
|
|
|
:clear '\^[2J\^[0;0H s:format s:put ;
|
2019-03-29 19:46:22 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
Hide the support words.
|
|
|
|
|
|
|
|
# Standard Interactive Listener
|
2019-02-05 21:22:17 +01:00
|
|
|
|
|
|
|
The main part of this file is the *listener*, an interactive
|
2021-04-30 17:09:01 +02:00
|
|
|
read-eval-print loop.
|
2019-02-05 21:22:17 +01:00
|
|
|
|
|
|
|
RRE's C part will access a couple parts of this, based on the
|
|
|
|
startup flags passed.
|
2017-11-15 20:57:17 +01:00
|
|
|
|
|
|
|
~~~
|
2023-12-15 15:10:08 +01:00
|
|
|
:// script:ignore-to-eol &Ignoring v:on ; immediate
|
2023-10-03 18:43:41 +02:00
|
|
|
~~~
|
|
|
|
|
2021-08-23 15:23:10 +02:00
|
|
|
## 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
|
|
|
|
~~~
|