-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtakawiri.retro
More file actions
executable file
·273 lines (215 loc) · 7.29 KB
/
takawiri.retro
File metadata and controls
executable file
·273 lines (215 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env retro
================================================================
_ _ _ _
| |_ __ _| | ____ ___ _(_)_ __(_) crc's new listener for
| __/ _` | |/ / _` \ \ /\ / / | '__| | RetroForth
| || (_| | < (_| |\ V V /| | | | |
\__\__,_|_|\_\__,_| \_/\_/ |_|_| |_| ** UNDER DEVELOPMENT **
================================================================
# Background
The current generation of RetroForth did not start off as a
traditional, interactive Forth. A minimal (and lightly expanded)
REPL simply called the listener has existed, but it is not a
user friendly system.
Takawiri is a new listener. I've been slowly working on it,
with a goal of growing it into something useful. At present it
is functional, but many pieces remain. (See the end of this
document for a partial list).
# The Interface
Takawiri presents a fullscreen interface. This has a large area
for the display (the "text output buffer", or TOB) with a set
of introspection views on the right. At the bottom is the text
input area.
+-----------------------------------------+----------------+
| Text Output Buffer | Introspection |
| | |
| | |
| +----------------+
| | Stack Display |
| | |
| | |
| +----------------+
| | String Preview |
| | |
| | |
| +----------------+
| | Watched Vars |
| | |
| | |
+-----------------------------------------+----------------+
| input area |
+----------------------------------------------------------+
# Startup & Dependencies
Takawiri requires RetroForth 2024.9 or newer, with the ioctl
device enabled. It also requires a terminal with 100 or more
columns and at least 27 rows.
I do the initial configuration, and check these, reporting any
errors and exiting if necessary.
~~~
@Version #202409 lt?
[ 'Requires_RetroForth_2024.9_or_newer s:put nl bye ] if
~~~
Setup the local terminal dimensions. This uses the `ioctl:`
words added in RetroForth 2024.9.
~~~
ioctl:term-size (rows,cols) 'LT:W const 'LT:H const
LT:W #100 lt? [ 'Terminal_too_narrow! s:put nl bye ] if
LT:H #27 lt? [ 'Terminal_too_short! s:put nl bye ] if
~~~
Setup the text output buffer dimensions. The width is currently
fixed at 80 columns; the height is set based on the terminal
height.
~~~
#80 'TOB:W const (:-n)
LT:H #2 - 'TOB:H const (:-n)
~~~
Load dependencies from the library.
~~~
{ 'konilo 'termina 'tob } &library:load a:for-each
~~~
# Configure UI Colors
~~~
:dss:label (:-) fg:red ;
:dss:value (:-) fg:yellow ;
:dss:sep (:-) fg:cyan ;
:dss:prompt (:-) bg:blue fg:white ;
~~~
# Utilities
I intend for takawiri to provide a variety of useful tools to
aid in using RetroForth interactively.
~~~
:,stack (:s-) d:lookup d:stack fetch s:put nl ;
~~~
# UI
First are words to display the text output buffer.
~~~
:bar:right (:-) dss:sep TOB:H n:inc [ I n:inc TOB:W #2 n:add vt:row,col $| c:put ] indexed-times vt:reset ;
:bar:bottom (:-) dss:sep TOB:H n:inc #1 vt:row,col TOB:W n:inc [ $= c:put ] times $+ c:put vt:reset ;
:display:tob (:-) tob:display bar:right bar:bottom ;
~~~
Draw the section separators.
~~~
:length (:-n) LT:W TOB:W #4 n:add n:sub ;
:--- (:n-) [ $- c:put ] times sp ;
:sections (:-)
dss:sep
#3 [ I n:inc #6 n:mul TOB:W #4 n:add vt:row,col length --- ]
indexed-times
vt:reset ;
~~~
~~~
'Items d:create #0 comma #32 allot
:tos? (:nm-nmf) over n:zero? ;
:dss (:-)
[ depth #5 n:min !Items
&Items fetch-next &store-next times drop
&Items a:reverse [ ] a:for-each
#0 &Items [
over n:inc #6 n:add #84 vt:row,col
dss:label
tos? [ 'TOS:___ s:put ] [ '_______ s:put ] choose
vt:reset
n:put
n:inc ] a:for-each
drop ] gc ;
~~~
## String Preview
This is the start of code to display temporary strings on the
data stack. The plan is to have it show below the stack values,
in a format like:
<depth> <first XX characters>
The <depth> data will match up to the values in the stack disp.
Note: this won't be useful until after the alternate `s:evaluate`
is done.
~~~
{{
:string? (v-vf) dup STRINGS gt? ;
:display
over n:inc #12 n:add #84 vt:row,col
fg:red
tos? [ 'TOS:___ s:put ] [ '_______ s:put ] choose
vt:reset
s:put ;
:not-string
over n:inc #12 n:add #84 vt:row,col
fg:blue '_______n/a s:put drop vt:reset ;
---reveal---
:strings (:-)
#0 &Items [ string? &display ¬-string choose n:inc ]
a:for-each drop ;
}}
~~~
~~~
:layout:stat,col (:-n) #84 ;
:layout:stat (:sn-) layout:stat,col vt:row,col dss:label s:put dss:value ;
:stats (:-)
'HERE:__ #1 layout:stat here n:put
'FREE:__ #2 layout:stat FREE n:put
'DEPTH:_ #3 layout:stat depth n:put
'ROW:___ #4 layout:stat @TY n:put
'COL:___ #5 layout:stat @TX n:put
vt:reset
;
:prompt (:-)
dss:prompt
LT:H #1 vt:row,col LT:W [ sp ] times
LT:H #1 vt:row,col '>>_ s:put ;
~~~
~~~
:quit (:-) ioctl:set-lbreak vt:reset bye ;
:bye (:-) quit ;
~~~
# Watchlist
The watchlist will allow monitoring a small number of addresses
in the right panel of the interface. A use case might be to
do something like:
&Base 'Base watch
&Compiler 'Compiler watch
~~~
'Watchlist d:create #5 , #-1 , #-1 , #-1 , #-1 , #-1 ,
'WatchlistLabels d:create #5 , #-1 , #-1 , #-1 , #-1 , #-1 ,
:watchlist:find (:a-n)
dup &Watchlist a:contains? [ drop #-1 ] -if;
&Watchlist swap a:index ;
:watchlist:make-label (:s-s)
dup s:length #8 gt? [ #8 s:left ] if
dup s:length #8 lt?
[ dup s:length #8 swap n:sub [ '_ s:append ] times ] if
s:keep ;
:watch (:as-)
watchlist:make-label
#-1 watchlist:find &Watchlist &WatchlistLabels
'abcde 'adcbec reorder a:store a:store ;
:unwatch (:a-)
watchlist:find dup n:positive? &drop -if
[ &Watchlist #-1 'abc 'acab reorder a:store ]
[ &WatchlistLabels #-1 'abc 'acab reorder a:store ] bi ;
:watchlist (:-)
#19 #5 [ dup #84 vt:row,col
dss:label &WatchlistLabels over #19 n:sub a:fetch
dup #-1 -eq? [ s:put sp ] [ drop '_________ s:put ] choose
dss:value &Watchlist over #19 n:sub a:fetch
dup n:positive? [ fetch ] [ drop #0 ] choose
n:put n:inc vt:reset ] times drop ;
~~~
~~~
:ui (:-)
&err:notfound unhook
ioctl:set-cbreak
&banner tob:with
[ vt:reset vt:clear vt:home
display:tob
sections
stats dss strings watchlist
prompt s:get-word vt:reset
[ dup s:put sp interpret ] tob:with
] forever ;
ui
~~~
================================================================
Things needed:
- termios device & words (or add termios to unix device?)
- colors for interface elements
- refactor & document everything
- line editing
================================================================