about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-21 21:21:36 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-21 21:21:39 -0800
commit7e9e65eece359d6bb28d202eec035cf7acc5118a (patch)
treebc342dbee0f97e684aabed0c415e6a6722c16da1
parentd7c7488398474d8310539e850edd0c3de2030d3d (diff)
downloadmu-7e9e65eece359d6bb28d202eec035cf7acc5118a.tar.gz
7771
We might not scan directly through the gap buffer after all. Premature
optimization?
-rw-r--r--baremetal/shell/cell.mu12
-rw-r--r--baremetal/shell/eval.mu19
-rw-r--r--baremetal/shell/main.mu5
-rw-r--r--baremetal/shell/sandbox.mu9
4 files changed, 42 insertions, 3 deletions
diff --git a/baremetal/shell/cell.mu b/baremetal/shell/cell.mu
new file mode 100644
index 00000000..c4f3311e
--- /dev/null
+++ b/baremetal/shell/cell.mu
@@ -0,0 +1,12 @@
+type cell {
+  type: int
+  # type 0: pair
+  left: (handle cell)
+  right: (handle cell)
+  # type 1: number
+  number-data: float
+  # type 2: symbol
+  # type 3: string
+  text-data: (handle array byte)
+  # TODO: array, (associative) table, stream
+}
diff --git a/baremetal/shell/eval.mu b/baremetal/shell/eval.mu
new file mode 100644
index 00000000..8af64a95
--- /dev/null
+++ b/baremetal/shell/eval.mu
@@ -0,0 +1,19 @@
+type interpreter {
+  # tokenize
+  # insert parens
+  # transform infix
+  # token tree
+  # syntax tree
+}
+
+fn evaluate _self: (addr interpreter), in: (addr stream byte), out: (addr stream byte) {
+  clear-stream out
+  {
+    var done?/eax: boolean <- stream-empty? in
+    compare done?, 0/false
+    break-if-!=
+    var g/eax: grapheme <- read-grapheme in
+    write-grapheme out, g
+    loop
+  }
+}
diff --git a/baremetal/shell/main.mu b/baremetal/shell/main.mu
index 262b9829..f3f6240c 100644
--- a/baremetal/shell/main.mu
+++ b/baremetal/shell/main.mu
@@ -2,6 +2,9 @@
 # A Lisp with indent-sensitivity and infix, no macros. Commas are ignored.
 
 fn main {
+  var interpreter-storage: interpreter
+  var interpreter/edi: (addr interpreter) <- address interpreter-storage
+#?   initialize-interpreter interpreter
   var sandbox-storage: sandbox
   var sandbox/esi: (addr sandbox) <- address sandbox-storage
   initialize-sandbox sandbox
@@ -12,7 +15,7 @@ fn main {
       compare key, 0
       loop-if-=
       # no way to quit right now; just reboot
-      edit-sandbox sandbox, key
+      edit-sandbox sandbox, key, interpreter
     }
     loop
   }
diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu
index 26646cbe..d1a24c47 100644
--- a/baremetal/shell/sandbox.mu
+++ b/baremetal/shell/sandbox.mu
@@ -59,7 +59,7 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), _x: int, _y: int
   var dummy/eax: int <- draw-stream-rightward screen, value, _x, 0x30/xmax, y, 7/fg=grey, 0/bg
 }
 
-fn edit-sandbox _self: (addr sandbox), key: byte {
+fn edit-sandbox _self: (addr sandbox), key: byte, interpreter: (addr interpreter) {
   var self/esi: (addr sandbox) <- copy _self
   var g/edx: grapheme <- copy key
   {
@@ -72,9 +72,14 @@ fn edit-sandbox _self: (addr sandbox), key: byte {
     compare g, 0x13/ctrl-s
     break-if-!=
     # ctrl-s: run sandbox(es)
+    var buffer-storage: (stream byte 0x1000)
+    var buffer/edi: (addr stream byte) <- address buffer-storage
+    var data-ah/eax: (addr handle gap-buffer) <- get self, data
+    var data/eax: (addr gap-buffer) <- lookup *data-ah
+    emit-gap-buffer data, buffer
     var value-ah/eax: (addr handle stream byte) <- get self, value
     var value/eax: (addr stream byte) <- lookup *value-ah
-    write value, "=> LISP"
+    evaluate interpreter, buffer, value
     return
   }
   add-grapheme-to-sandbox self, g
revision' href='/akkartik/mu/blame/html/subx/036global_variables.cc.html?h=main&id=a6517ed821ff39fa56eb3b975799d22497d78a48'>^
5a2cb154 ^
608a7fa8 ^
9c1056f5 ^
91624dba ^
c504ca56 ^
52daf072 ^
9c1056f5 ^
52daf072 ^
9c1056f5 ^


91624dba ^
52daf072 ^
9c1056f5 ^


c504ca56 ^

9c1056f5 ^
91624dba ^
9c1056f5 ^



91624dba ^


9c1056f5 ^


c504ca56 ^


52daf072 ^




c504ca56 ^



52daf072 ^



91624dba ^
52daf072 ^
91624dba ^

52daf072 ^
c504ca56 ^
91624dba ^
c504ca56 ^

91624dba ^
52daf072 ^

c504ca56 ^

52daf072 ^





91624dba ^
c504ca56 ^


52daf072 ^


91624dba ^
c504ca56 ^



91624dba ^
52daf072 ^
91624dba ^
52daf072 ^


91624dba ^
c504ca56 ^




52daf072 ^

91624dba ^
c504ca56 ^
52daf072 ^


91624dba ^
52daf072 ^



c504ca56 ^
52daf072 ^



91624dba ^
c504ca56 ^




52daf072 ^
c504ca56 ^
52daf072 ^






91624dba ^
52daf072 ^
91624dba ^
52daf072 ^
91624dba ^
52daf072 ^
c504ca56 ^
52daf072 ^

91624dba ^
c504ca56 ^
52daf072 ^


c504ca56 ^
52daf072 ^

c504ca56 ^
52daf072 ^



91624dba ^
52daf072 ^







c504ca56 ^

52daf072 ^
91624dba ^
c504ca56 ^
52daf072 ^
c504ca56 ^



52daf072 ^








91624dba ^
52daf072 ^



91624dba ^
c504ca56 ^
52daf072 ^



91624dba ^
52daf072 ^
c504ca56 ^
52daf072 ^





91624dba ^
52daf072 ^





91624dba ^
52daf072 ^
c504ca56 ^
52daf072 ^





91624dba ^
52daf072 ^





91624dba ^
c504ca56 ^
52daf072 ^








91624dba ^
52daf072 ^




91624dba ^
52daf072 ^

91624dba ^
c504ca56 ^
52daf072 ^






91624dba ^
52daf072 ^




91624dba ^
52daf072 ^

91624dba ^
52daf072 ^
c504ca56 ^
52daf072 ^






91624dba ^
52daf072 ^



91624dba ^
c504ca56 ^
52daf072 ^





91624dba ^
52daf072 ^

91624dba ^
52daf072 ^





91624dba ^
52daf072 ^

91624dba ^
52daf072 ^
c504ca56 ^
52daf072 ^
c504ca56 ^


52daf072 ^


608a7fa8 ^



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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370