about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-11-06 13:03:09 -0800
committerKartik Agaram <vc@akkartik.com>2020-11-06 13:39:46 -0800
commit9a0412b8587f6b153be2d7d63cd9da2600345e86 (patch)
tree7d12b248f1fb1d021c8d1403d427792a7533e72d /apps
parent0181e9eeb6444eeeca4d442c630dd98c13da34ec (diff)
downloadmu-9a0412b8587f6b153be2d7d63cd9da2600345e86.tar.gz
7194
Diffstat (limited to 'apps')
-rw-r--r--apps/tile/environment.mu4
-rw-r--r--apps/tile/rpn.mu92
2 files changed, 51 insertions, 45 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index d6e3a421..5266b1fb 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -763,6 +763,7 @@ fn copy-unbound-words-to-args _functions: (addr handle function) {
 fn bound-function? w: (addr word), functions-ah: (addr handle function) -> _/ebx: boolean {
   var result/ebx: boolean <- copy 1  # true
   {
+    ## numbers
     # if w == "+" return true
     var subresult/eax: boolean <- word-equal? w, "+"
     compare subresult, 0  # false
@@ -775,10 +776,12 @@ fn bound-function? w: (addr word), functions-ah: (addr handle function) -> _/ebx
     subresult <- word-equal? w, "*"
     compare subresult, 0  # false
     break-if-!=
+    ## strings/arrays
     # if w == "len" return true
     subresult <- word-equal? w, "len"
     compare subresult, 0  # false
     break-if-!=
+    ## files
     # if w == "open" return true
     subresult <- word-equal? w, "open"
     compare subresult, 0  # false
@@ -795,6 +798,7 @@ fn bound-function? w: (addr word), functions-ah: (addr handle function) -> _/ebx
     subresult <- word-equal? w, "lines"
     compare subresult, 0  # false
     break-if-!=
+    ## hacks
     # if w == "dup" return true
     subresult <- word-equal? w, "dup"
     compare subresult, 0  # false
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index 0a8f9fc5..ff6dc10c 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -14,7 +14,8 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
 #?     print-stream-to-real-screen curr-stream
 #?     print-string-to-real-screen "\n"
     $evaluate:process-word: {
-      # if curr-stream is an operator, perform it
+      ### if curr-stream is an operator, perform it
+      ## numbers
       {
         var is-add?/eax: boolean <- stream-data-equal? curr-stream, "+"
         compare is-add?, 0
@@ -48,6 +49,7 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         push-int-to-value-stack out, a
         break $evaluate:process-word
       }
+      ## strings/arrays
       {
         var is-len?/eax: boolean <- stream-data-equal? curr-stream, "len"
         compare is-len?, 0
@@ -102,6 +104,7 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
           break $evaluate:process-word
         }
       }
+      ## files
       {
         var is-open?/eax: boolean <- stream-data-equal? curr-stream, "open"
         compare is-open?, 0
@@ -255,45 +258,7 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         copy-handle empty-text, target-text-ah
         break $evaluate:process-word
       }
-      # if curr-stream defines a binding, save top of stack to bindings
-      {
-        var done?/eax: boolean <- stream-empty? curr-stream
-        compare done?, 0  # false
-        break-if-!=
-        var new-byte/eax: byte <- read-byte curr-stream
-        compare new-byte, 0x3d  # '='
-        break-if-!=
-        # pop target-val from out
-        var out2/esi: (addr value-stack) <- copy out
-        var top-addr/ecx: (addr int) <- get out2, top
-        compare *top-addr, 0
-        break-if-<=
-        var data-ah/eax: (addr handle array value) <- get out2, data
-        var data/eax: (addr array value) <- lookup *data-ah
-        var top/edx: int <- copy *top-addr
-        top <- decrement
-        var dest-offset/edx: (offset value) <- compute-offset data, top
-        var target-val/edx: (addr value) <- index data, dest-offset
-        # create binding from curr-stream to target-val
-        var key-h: (handle array byte)
-        var key/ecx: (addr handle array byte) <- address key-h
-        stream-to-array curr-stream, key
-        bind-in-table bindings, key, target-val
-        break $evaluate:process-word
-      }
-      rewind-stream curr-stream
-      # if curr-stream is a known function name, call it appropriately
-      {
-        var callee-h: (handle function)
-        var callee-ah/eax: (addr handle function) <- address callee-h
-        find-function functions, curr-stream, callee-ah
-        var callee/eax: (addr function) <- lookup *callee-ah
-        compare callee, 0
-        break-if-=
-        perform-call callee, out, functions
-        break $evaluate:process-word
-      }
-      # HACKS: we're trying to avoid turning this into Forth
+      ## HACKS: we're trying to avoid turning this into Forth
       {
         var is-dup?/eax: boolean <- stream-data-equal? curr-stream, "dup"
         compare is-dup?, 0
@@ -346,8 +311,45 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         copy-object tmp-a, pen-top-val
         break $evaluate:process-word
       }
-      # END HACKS
-      # if it's a name, push its value
+      ### if curr-stream defines a binding, save top of stack to bindings
+      {
+        var done?/eax: boolean <- stream-empty? curr-stream
+        compare done?, 0  # false
+        break-if-!=
+        var new-byte/eax: byte <- read-byte curr-stream
+        compare new-byte, 0x3d  # '='
+        break-if-!=
+        # pop target-val from out
+        var out2/esi: (addr value-stack) <- copy out
+        var top-addr/ecx: (addr int) <- get out2, top
+        compare *top-addr, 0
+        break-if-<=
+        var data-ah/eax: (addr handle array value) <- get out2, data
+        var data/eax: (addr array value) <- lookup *data-ah
+        var top/edx: int <- copy *top-addr
+        top <- decrement
+        var dest-offset/edx: (offset value) <- compute-offset data, top
+        var target-val/edx: (addr value) <- index data, dest-offset
+        # create binding from curr-stream to target-val
+        var key-h: (handle array byte)
+        var key/ecx: (addr handle array byte) <- address key-h
+        stream-to-array curr-stream, key
+        bind-in-table bindings, key, target-val
+        break $evaluate:process-word
+      }
+      rewind-stream curr-stream
+      ### if curr-stream is a known function name, call it appropriately
+      {
+        var callee-h: (handle function)
+        var callee-ah/eax: (addr handle function) <- address callee-h
+        find-function functions, curr-stream, callee-ah
+        var callee/eax: (addr function) <- lookup *callee-ah
+        compare callee, 0
+        break-if-=
+        perform-call callee, out, functions
+        break $evaluate:process-word
+      }
+      ### if it's a name, push its value
       {
         compare bindings, 0
         break-if-=
@@ -364,7 +366,7 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         push-value-stack out, val
         break $evaluate:process-word
       }
-      # if the word starts with a quote and ends with a quote, turn it into a string
+      ### if the word starts with a quote and ends with a quote, turn it into a string
       {
         var start/eax: byte <- stream-first curr-stream
         compare start, 0x22  # double-quote
@@ -378,7 +380,7 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         push-string-to-value-stack out, *s
         break $evaluate:process-word
       }
-      # if the word starts with a '[' and ends with a ']', turn it into an array
+      ### if the word starts with a '[' and ends with a ']', turn it into an array
       {
         var start/eax: byte <- stream-first curr-stream
         compare start, 0x5b  # '['
@@ -422,7 +424,7 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         }
         break $evaluate:process-word
       }
-      # otherwise assume it's a literal int and push it
+      ### otherwise assume it's a literal number and push it
       {
         var n/eax: int <- parse-decimal-int-from-stream curr-stream
         push-int-to-value-stack out, n
title='Blame the previous revision' href='/akkartik/mu/blame/build4?h=main&id=3ecee22a8a440b5f299729cbe49aede7e270c67c'>^
07147a67 ^








129a9f71 ^
07147a67 ^









129a9f71 ^
07147a67 ^








129a9f71 ^
07147a67 ^


















07147a67 ^
129a9f71 ^
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