From dd60a1d73c8017fd3d80ccf91e4549fc47a90760 Mon Sep 17 00:00:00 2001
From: Kartik Agaram
1 type environment {
2 screen: (handle screen)
- 3 functions: (handle function)
- 4 sandboxes: (handle sandbox)
+ 3 functions: (handle function)
+ 4 sandboxes: (handle sandbox)
5 nrows: int
6 ncols: int
7 code-separator-col: int
@@ -70,13 +70,13 @@ if ('onhashchange' in window) {
10 fn initialize-environment _env: (addr environment) {
11 var env/esi: (addr environment) <- copy _env
12 # initialize some predefined function definitions
- 13 var functions/eax: (addr handle function) <- get env, functions
- 14 create-primitive-functions functions
+ 13 var functions/eax: (addr handle function) <- get env, functions
+ 14 create-primitive-functions functions
15 # initialize first sandbox
- 16 var sandbox-ah/eax: (addr handle sandbox) <- get env, sandboxes
+ 16 var sandbox-ah/eax: (addr handle sandbox) <- get env, sandboxes
17 allocate sandbox-ah
- 18 var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
- 19 initialize-sandbox sandbox
+ 18 var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
+ 19 initialize-sandbox sandbox
20 # initialize screen
21 var screen-ah/eax: (addr handle screen) <- get env, screen
22 var _screen/eax: (addr screen) <- lookup *screen-ah
@@ -122,115 +122,115 @@ if ('onhashchange' in window) {
62 fn process _self: (addr environment), key: grapheme {
63 $process:body: {
64 var self/esi: (addr environment) <- copy _self
- 65 var sandbox-ah/eax: (addr handle sandbox) <- get self, sandboxes
- 66 var _sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
- 67 var sandbox/edi: (addr sandbox) <- copy _sandbox
- 68 var rename-word-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-cursor-word
- 69 var rename-word-mode?/eax: (addr word) <- lookup *rename-word-mode-ah?
+ 65 var sandbox-ah/eax: (addr handle sandbox) <- get self, sandboxes
+ 66 var _sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
+ 67 var sandbox/edi: (addr sandbox) <- copy _sandbox
+ 68 var rename-word-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-cursor-word
+ 69 var rename-word-mode?/eax: (addr word) <- lookup *rename-word-mode-ah?
70 compare rename-word-mode?, 0
71 {
72 break-if-=
73 #? print-string 0, "processing sandbox rename\n"
- 74 process-sandbox-rename sandbox, key
+ 74 process-sandbox-rename sandbox, key
75 break $process:body
76 }
- 77 var define-function-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-function
- 78 var define-function-mode?/eax: (addr word) <- lookup *define-function-mode-ah?
+ 77 var define-function-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-function
+ 78 var define-function-mode?/eax: (addr word) <- lookup *define-function-mode-ah?
79 compare define-function-mode?, 0
80 {
81 break-if-=
82 #? print-string 0, "processing function definition\n"
- 83 var functions/ecx: (addr handle function) <- get self, functions
- 84 process-sandbox-define sandbox, functions, key
+ 83 var functions/ecx: (addr handle function) <- get self, functions
+ 84 process-sandbox-define sandbox, functions, key
85 break $process:body
86 }
87 #? print-string 0, "processing sandbox\n"
- 88 process-sandbox self, sandbox, key
+ 88 process-sandbox self, sandbox, key
89 }
90 }
91
- 92 fn process-sandbox _self: (addr environment), _sandbox: (addr sandbox), key: grapheme {
+ 92 fn process-sandbox _self: (addr environment), _sandbox: (addr sandbox), key: grapheme {
93 $process-sandbox:body: {
94 var self/esi: (addr environment) <- copy _self
- 95 var sandbox/edi: (addr sandbox) <- copy _sandbox
- 96 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 97 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 98 var cursor-word-ah/ebx: (addr handle word) <- get cursor-call-path, word
- 99 var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
- 100 var cursor-word/ecx: (addr word) <- copy _cursor-word
+ 95 var sandbox/edi: (addr sandbox) <- copy _sandbox
+ 96 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 97 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 98 var cursor-word-ah/ebx: (addr handle word) <- get cursor-call-path, word
+ 99 var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+ 100 var cursor-word/ecx: (addr word) <- copy _cursor-word
101 compare key, 0x445b1b # left-arrow
102 $process-sandbox:key-left-arrow: {
103 break-if-!=
104 #? print-string 0, "left-arrow\n"
105 # if not at start, move left within current word
- 106 var at-start?/eax: boolean <- cursor-at-start? cursor-word
+ 106 var at-start?/eax: boolean <- cursor-at-start? cursor-word
107 compare at-start?, 0 # false
108 {
109 break-if-!=
110 #? print-string 0, "cursor left within word\n"
- 111 cursor-left cursor-word
+ 111 cursor-left cursor-word
112 break $process-sandbox:body
113 }
114 # if current word is expanded, move to the rightmost word in its body
115 {
- 116 var cursor-call-path/esi: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 117 var expanded-words/edx: (addr handle call-path) <- get sandbox, expanded-words
- 118 var curr-word-is-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
+ 116 var cursor-call-path/esi: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 117 var expanded-words/edx: (addr handle call-path) <- get sandbox, expanded-words
+ 118 var curr-word-is-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
119 compare curr-word-is-expanded?, 0 # false
120 break-if-=
121 # update cursor-call-path
122 #? print-string 0, "curr word is expanded\n"
123 var self/ecx: (addr environment) <- copy _self
- 124 var functions/ecx: (addr handle function) <- get self, functions
- 125 var body: (handle line)
- 126 var body-ah/eax: (addr handle line) <- address body
- 127 function-body functions, cursor-word-ah, body-ah
- 128 var body-addr/eax: (addr line) <- lookup *body-ah
- 129 var first-word-ah/edx: (addr handle word) <- get body-addr, data
- 130 var final-word-h: (handle word)
- 131 var final-word-ah/eax: (addr handle word) <- address final-word-h
- 132 final-word first-word-ah, final-word-ah
- 133 push-to-call-path-element cursor-call-path, final-word-ah
+ 124 var functions/ecx: (addr handle function) <- get self, functions
+ 125 var body: (handle line)
+ 126 var body-ah/eax: (addr handle line) <- address body
+ 127 function-body functions, cursor-word-ah, body-ah
+ 128 var body-addr/eax: (addr line) <- lookup *body-ah
+ 129 var first-word-ah/edx: (addr handle word) <- get body-addr, data
+ 130 var final-word-h: (handle word)
+ 131 var final-word-ah/eax: (addr handle word) <- address final-word-h
+ 132 final-word first-word-ah, final-word-ah
+ 133 push-to-call-path-element cursor-call-path, final-word-ah
134 # move cursor to end of word
- 135 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 136 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 137 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
- 138 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
- 139 cursor-to-end cursor-word
+ 135 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 136 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 137 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
+ 138 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+ 139 cursor-to-end cursor-word
140 break $process-sandbox:body
141 }
142 # if at first word, look for a caller to jump to
143 $process-sandbox:key-left-arrow-first-word: {
- 144 var prev-word-ah/edx: (addr handle word) <- get cursor-word, prev
- 145 var prev-word/eax: (addr word) <- lookup *prev-word-ah
+ 144 var prev-word-ah/edx: (addr handle word) <- get cursor-word, prev
+ 145 var prev-word/eax: (addr word) <- lookup *prev-word-ah
146 compare prev-word, 0
147 break-if-!=
148 $process-sandbox:key-left-arrow-first-word-and-caller: {
149 #? print-string 0, "return\n"
150 {
- 151 var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 152 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 153 var next-cursor-element-ah/edx: (addr handle call-path-element) <- get cursor-call-path, next
- 154 var next-cursor-element/eax: (addr call-path-element) <- lookup *next-cursor-element-ah
+ 151 var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 152 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 153 var next-cursor-element-ah/edx: (addr handle call-path-element) <- get cursor-call-path, next
+ 154 var next-cursor-element/eax: (addr call-path-element) <- lookup *next-cursor-element-ah
155 compare next-cursor-element, 0
156 break-if-= $process-sandbox:key-left-arrow-first-word-and-caller
157 copy-object next-cursor-element-ah, cursor-call-path-ah
158 }
- 159 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 160 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 161 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
- 162 var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+ 159 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 160 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 161 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
+ 162 var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
163 cursor-word <- copy _cursor-word
164 }
165 }
166 # then move to end of previous word
- 167 var prev-word-ah/edx: (addr handle word) <- get cursor-word, prev
- 168 var prev-word/eax: (addr word) <- lookup *prev-word-ah
+ 167 var prev-word-ah/edx: (addr handle word) <- get cursor-word, prev
+ 168 var prev-word/eax: (addr word) <- lookup *prev-word-ah
169 {
170 compare prev-word, 0
171 break-if-=
172 #? print-string 0, "move to previous word\n"
- 173 cursor-to-end prev-word
+ 173 cursor-to-end prev-word
174 #? {
175 #? var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
176 #? var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
@@ -241,8 +241,8 @@ if ('onhashchange' in window) {
181 #? print-word 0, cursor-word
182 #? print-string 0, "\n"
183 #? }
- 184 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 185 decrement-final-element cursor-call-path
+ 184 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 185 decrement-final-element cursor-call-path
186 #? {
187 #? var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
188 #? var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
@@ -260,65 +260,65 @@ if ('onhashchange' in window) {
200 $process-sandbox:key-right-arrow: {
201 break-if-!=
202 # if not at end, move right within current word
- 203 var at-end?/eax: boolean <- cursor-at-end? cursor-word
+ 203 var at-end?/eax: boolean <- cursor-at-end? cursor-word
204 compare at-end?, 0 # false
205 {
206 break-if-!=
207 #? print-string 0, "a\n"
- 208 cursor-right cursor-word
+ 208 cursor-right cursor-word
209 break $process-sandbox:body
210 }
211 # if at final word, look for a caller to jump to
212 {
- 213 var next-word-ah/edx: (addr handle word) <- get cursor-word, next
- 214 var next-word/eax: (addr word) <- lookup *next-word-ah
+ 213 var next-word-ah/edx: (addr handle word) <- get cursor-word, next
+ 214 var next-word/eax: (addr word) <- lookup *next-word-ah
215 compare next-word, 0
216 break-if-!=
- 217 var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 218 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 219 var next-cursor-element-ah/ecx: (addr handle call-path-element) <- get cursor-call-path, next
- 220 var next-cursor-element/eax: (addr call-path-element) <- lookup *next-cursor-element-ah
+ 217 var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 218 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 219 var next-cursor-element-ah/ecx: (addr handle call-path-element) <- get cursor-call-path, next
+ 220 var next-cursor-element/eax: (addr call-path-element) <- lookup *next-cursor-element-ah
221 compare next-cursor-element, 0
222 break-if-=
223 copy-object next-cursor-element-ah, cursor-call-path-ah
224 break $process-sandbox:body
225 }
226 # otherwise, move to the next word
- 227 var next-word-ah/edx: (addr handle word) <- get cursor-word, next
- 228 var next-word/eax: (addr word) <- lookup *next-word-ah
+ 227 var next-word-ah/edx: (addr handle word) <- get cursor-word, next
+ 228 var next-word/eax: (addr word) <- lookup *next-word-ah
229 {
230 compare next-word, 0
231 break-if-=
232 #? print-string 0, "b\n"
- 233 cursor-to-start next-word
+ 233 cursor-to-start next-word
234 # . . cursor-word now out of date
- 235 var cursor-call-path/ecx: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 236 increment-final-element cursor-call-path
+ 235 var cursor-call-path/ecx: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 236 increment-final-element cursor-call-path
237 # Is the new cursor word expanded? If so, it's a function call. Add a
238 # new level to the cursor-call-path for the call's body.
239 $process-sandbox:key-right-arrow-next-word-is-call-expanded: {
240 #? print-string 0, "c\n"
241 {
- 242 var expanded-words/eax: (addr handle call-path) <- get sandbox, expanded-words
- 243 var curr-word-is-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
+ 242 var expanded-words/eax: (addr handle call-path) <- get sandbox, expanded-words
+ 243 var curr-word-is-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
244 compare curr-word-is-expanded?, 0 # false
245 break-if-= $process-sandbox:key-right-arrow-next-word-is-call-expanded
246 }
- 247 var callee-h: (handle function)
- 248 var callee-ah/edx: (addr handle function) <- address callee-h
- 249 var functions/ebx: (addr handle function) <- get self, functions
+ 247 var callee-h: (handle function)
+ 248 var callee-ah/edx: (addr handle function) <- address callee-h
+ 249 var functions/ebx: (addr handle function) <- get self, functions
250 callee functions, next-word, callee-ah
- 251 var callee/eax: (addr function) <- lookup *callee-ah
- 252 var callee-body-ah/eax: (addr handle line) <- get callee, body
- 253 var callee-body/eax: (addr line) <- lookup *callee-body-ah
- 254 var callee-body-first-word/edx: (addr handle word) <- get callee-body, data
- 255 push-to-call-path-element cursor-call-path, callee-body-first-word
+ 251 var callee/eax: (addr function) <- lookup *callee-ah
+ 252 var callee-body-ah/eax: (addr handle line) <- get callee, body
+ 253 var callee-body/eax: (addr line) <- lookup *callee-body-ah
+ 254 var callee-body-first-word/edx: (addr handle word) <- get callee-body, data
+ 255 push-to-call-path-element cursor-call-path, callee-body-first-word
256 # position cursor at left
- 257 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 258 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 259 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
- 260 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
- 261 cursor-to-start cursor-word
+ 257 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 258 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 259 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
+ 260 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+ 261 cursor-to-start cursor-word
262 #? print-string 0, "d\n"
263 break $process-sandbox:body
264 }
@@ -329,14 +329,14 @@ if ('onhashchange' in window) {
269 {
270 break-if-!=
271 # toggle display of subsidiary stack
- 272 toggle-cursor-word sandbox
+ 272 toggle-cursor-word sandbox
273 break $process-sandbox:body
274 }
275 compare key, 0xc # ctrl-l
276 $process-sandbox:new-line: {
277 break-if-!=
278 # new line in sandbox
- 279 append-line sandbox
+ 279 append-line sandbox
280 break $process-sandbox:body
281 }
282 # word-based motions
@@ -344,34 +344,34 @@ if ('onhashchange' in window) {
284 $process-sandbox:prev-word: {
285 break-if-!=
286 # jump to previous word at same level
- 287 var prev-word-ah/edx: (addr handle word) <- get cursor-word, prev
- 288 var prev-word/eax: (addr word) <- lookup *prev-word-ah
+ 287 var prev-word-ah/edx: (addr handle word) <- get cursor-word, prev
+ 288 var prev-word/eax: (addr word) <- lookup *prev-word-ah
289 {
290 compare prev-word, 0
291 break-if-=
- 292 cursor-to-end prev-word
- 293 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 294 decrement-final-element cursor-call-path
+ 292 cursor-to-end prev-word
+ 293 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 294 decrement-final-element cursor-call-path
295 break $process-sandbox:body
296 }
297 # if previous word doesn't exist, try to bump up one level
298 {
- 299 var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 300 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 301 var caller-cursor-element-ah/ecx: (addr handle call-path-element) <- get cursor-call-path, next
- 302 var caller-cursor-element/eax: (addr call-path-element) <- lookup *caller-cursor-element-ah
+ 299 var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 300 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 301 var caller-cursor-element-ah/ecx: (addr handle call-path-element) <- get cursor-call-path, next
+ 302 var caller-cursor-element/eax: (addr call-path-element) <- lookup *caller-cursor-element-ah
303 compare caller-cursor-element, 0
304 break-if-=
305 # check if previous word exists in caller
- 306 var caller-word-ah/eax: (addr handle word) <- get caller-cursor-element, word
- 307 var caller-word/eax: (addr word) <- lookup *caller-word-ah
- 308 var word-before-caller-ah/eax: (addr handle word) <- get caller-word, prev
- 309 var word-before-caller/eax: (addr word) <- lookup *word-before-caller-ah
+ 306 var caller-word-ah/eax: (addr handle word) <- get caller-cursor-element, word
+ 307 var caller-word/eax: (addr word) <- lookup *caller-word-ah
+ 308 var word-before-caller-ah/eax: (addr handle word) <- get caller-word, prev
+ 309 var word-before-caller/eax: (addr word) <- lookup *word-before-caller-ah
310 compare word-before-caller, 0
311 break-if-=
312 # if so jump to it
- 313 drop-from-call-path-element cursor-call-path-ah
- 314 decrement-final-element cursor-call-path-ah
+ 313 drop-from-call-path-element cursor-call-path-ah
+ 314 decrement-final-element cursor-call-path-ah
315 break $process-sandbox:body
316 }
317 }
@@ -380,23 +380,23 @@ if ('onhashchange' in window) {
320 break-if-!=
321 #? print-string 0, "AA\n"
322 # jump to previous word at same level
- 323 var next-word-ah/edx: (addr handle word) <- get cursor-word, next
- 324 var next-word/eax: (addr word) <- lookup *next-word-ah
+ 323 var next-word-ah/edx: (addr handle word) <- get cursor-word, next
+ 324 var next-word/eax: (addr word) <- lookup *next-word-ah
325 {
326 compare next-word, 0
327 break-if-=
328 #? print-string 0, "BB\n"
- 329 cursor-to-end next-word
- 330 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 331 increment-final-element cursor-call-path
+ 329 cursor-to-end next-word
+ 330 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 331 increment-final-element cursor-call-path
332 break $process-sandbox:body
333 }
334 # if next word doesn't exist, try to bump up one level
335 #? print-string 0, "CC\n"
- 336 var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 337 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 338 var caller-cursor-element-ah/ecx: (addr handle call-path-element) <- get cursor-call-path, next
- 339 var caller-cursor-element/eax: (addr call-path-element) <- lookup *caller-cursor-element-ah
+ 336 var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 337 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 338 var caller-cursor-element-ah/ecx: (addr handle call-path-element) <- get cursor-call-path, next
+ 339 var caller-cursor-element/eax: (addr call-path-element) <- lookup *caller-cursor-element-ah
340 compare caller-cursor-element, 0
341 break-if-=
342 #? print-string 0, "DD\n"
@@ -408,14 +408,14 @@ if ('onhashchange' in window) {
348 $process-sandbox:start-of-line: {
349 break-if-!=
350 # move cursor up past all calls and to start of line
- 351 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 352 drop-nested-calls cursor-call-path-ah
- 353 move-final-element-to-start-of-line cursor-call-path-ah
+ 351 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 352 drop-nested-calls cursor-call-path-ah
+ 353 move-final-element-to-start-of-line cursor-call-path-ah
354 # move cursor to start of word
- 355 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 356 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
- 357 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
- 358 cursor-to-start cursor-word
+ 355 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 356 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
+ 357 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+ 358 cursor-to-start cursor-word
359 # this works as long as the first word isn't expanded
360 # but we don't expect to see zero-arg functions first-up
361 break $process-sandbox:body
@@ -424,14 +424,14 @@ if ('onhashchange' in window) {
364 $process-sandbox:end-of-line: {
365 break-if-!=
366 # move cursor up past all calls and to start of line
- 367 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 368 drop-nested-calls cursor-call-path-ah
- 369 move-final-element-to-end-of-line cursor-call-path-ah
+ 367 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 368 drop-nested-calls cursor-call-path-ah
+ 369 move-final-element-to-end-of-line cursor-call-path-ah
370 # move cursor to end of word
- 371 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 372 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
- 373 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
- 374 cursor-to-end cursor-word
+ 371 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 372 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
+ 373 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+ 374 cursor-to-end cursor-word
375 # this works because expanded words lie to the right of their bodies
376 # so the final word is always guaranteed to be at the top-level
377 break $process-sandbox:body
@@ -440,14 +440,14 @@ if ('onhashchange' in window) {
380 $process-sandbox:clear-line: {
381 break-if-!=
382 # clear line in sandbox
- 383 initialize-sandbox sandbox
+ 383 initialize-sandbox sandbox
384 break $process-sandbox:body
385 }
386 # if cursor is within a call, disable editing hotkeys below
- 387 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 388 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 389 var next-cursor-element-ah/eax: (addr handle call-path-element) <- get cursor-call-path, next
- 390 var next-cursor-element/eax: (addr call-path-element) <- lookup *next-cursor-element-ah
+ 387 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 388 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 389 var next-cursor-element-ah/eax: (addr handle call-path-element) <- get cursor-call-path, next
+ 390 var next-cursor-element/eax: (addr call-path-element) <- lookup *next-cursor-element-ah
391 compare next-cursor-element, 0
392 break-if-!= $process-sandbox:body
393 # - remaining keys only work at the top row outside any function calls
@@ -455,23 +455,23 @@ if ('onhashchange' in window) {
395 $process-sandbox:backspace: {
396 break-if-!=
397 # if not at start of some word, delete grapheme before cursor within current word
- 398 var at-start?/eax: boolean <- cursor-at-start? cursor-word
+ 398 var at-start?/eax: boolean <- cursor-at-start? cursor-word
399 compare at-start?, 0 # false
400 {
401 break-if-!=
- 402 delete-before-cursor cursor-word
+ 402 delete-before-cursor cursor-word
403 break $process-sandbox:body
404 }
405 # otherwise delete current word and move to end of prev word
- 406 var prev-word-ah/eax: (addr handle word) <- get cursor-word, prev
- 407 var prev-word/eax: (addr word) <- lookup *prev-word-ah
+ 406 var prev-word-ah/eax: (addr handle word) <- get cursor-word, prev
+ 407 var prev-word/eax: (addr word) <- lookup *prev-word-ah
408 {
409 compare prev-word, 0
410 break-if-=
- 411 cursor-to-end prev-word
- 412 delete-next prev-word
- 413 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 414 decrement-final-element cursor-call-path
+ 411 cursor-to-end prev-word
+ 412 delete-next prev-word
+ 413 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 414 decrement-final-element cursor-call-path
415 }
416 break $process-sandbox:body
417 }
@@ -481,22 +481,22 @@ if ('onhashchange' in window) {
421 #? print-string 0, "space\n"
422 # if cursor is at start of word, insert word before
423 {
- 424 var at-start?/eax: boolean <- cursor-at-start? cursor-word
+ 424 var at-start?/eax: boolean <- cursor-at-start? cursor-word
425 compare at-start?, 0 # false
426 break-if-=
- 427 var prev-word-ah/eax: (addr handle word) <- get cursor-word, prev
- 428 append-word prev-word-ah
- 429 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 430 decrement-final-element cursor-call-path
+ 427 var prev-word-ah/eax: (addr handle word) <- get cursor-word, prev
+ 428 append-word prev-word-ah
+ 429 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 430 decrement-final-element cursor-call-path
431 break $process-sandbox:body
432 }
433 # if start of word is quote and grapheme before cursor is not, just insert it as usual
434 # TODO: support string escaping
435 {
- 436 var first-grapheme/eax: grapheme <- first-grapheme cursor-word
- 437 compare first-grapheme, 0x22 # double quote
+ 436 var first-grapheme/eax: grapheme <- first-grapheme cursor-word
+ 437 compare first-grapheme, 0x22 # double quote
438 break-if-!=
- 439 var final-grapheme/eax: grapheme <- grapheme-before-cursor cursor-word
+ 439 var final-grapheme/eax: grapheme <- grapheme-before-cursor cursor-word
440 compare final-grapheme, 0x22 # double quote
441 break-if-=
442 break $process-sandbox:space
@@ -504,37 +504,37 @@ if ('onhashchange' in window) {
444 # if start of word is '[' and grapheme before cursor is not ']', just insert it as usual
445 # TODO: support nested arrays
446 {
- 447 var first-grapheme/eax: grapheme <- first-grapheme cursor-word
- 448 compare first-grapheme, 0x5b # '['
+ 447 var first-grapheme/eax: grapheme <- first-grapheme cursor-word
+ 448 compare first-grapheme, 0x5b # '['
449 break-if-!=
- 450 var final-grapheme/eax: grapheme <- grapheme-before-cursor cursor-word
+ 450 var final-grapheme/eax: grapheme <- grapheme-before-cursor cursor-word
451 compare final-grapheme, 0x5d # ']'
452 break-if-=
453 break $process-sandbox:space
454 }
455 # otherwise insert word after and move cursor to it for the next key
456 # (but we'll continue to track the current cursor-word for the rest of this function)
- 457 append-word cursor-word-ah
- 458 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 459 increment-final-element cursor-call-path
+ 457 append-word cursor-word-ah
+ 458 var cursor-call-path/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 459 increment-final-element cursor-call-path
460 # if cursor is at end of word, that's all
- 461 var at-end?/eax: boolean <- cursor-at-end? cursor-word
+ 461 var at-end?/eax: boolean <- cursor-at-end? cursor-word
462 compare at-end?, 0 # false
463 break-if-!= $process-sandbox:body
464 # otherwise we're in the middle of a word
465 # move everything after cursor to the (just created) next word
- 466 var next-word-ah/eax: (addr handle word) <- get cursor-word, next
- 467 var _next-word/eax: (addr word) <- lookup *next-word-ah
- 468 var next-word/ebx: (addr word) <- copy _next-word
+ 466 var next-word-ah/eax: (addr handle word) <- get cursor-word, next
+ 467 var _next-word/eax: (addr word) <- lookup *next-word-ah
+ 468 var next-word/ebx: (addr word) <- copy _next-word
469 {
- 470 var at-end?/eax: boolean <- cursor-at-end? cursor-word
+ 470 var at-end?/eax: boolean <- cursor-at-end? cursor-word
471 compare at-end?, 0 # false
472 break-if-!=
- 473 var g/eax: grapheme <- pop-after-cursor cursor-word
- 474 add-grapheme-to-word next-word, g
+ 473 var g/eax: grapheme <- pop-after-cursor cursor-word
+ 474 add-grapheme-to-word next-word, g
475 loop
476 }
- 477 cursor-to-start next-word
+ 477 cursor-to-start next-word
478 break $process-sandbox:body
479 }
480 compare key, 0xe # ctrl-n
@@ -542,20 +542,20 @@ if ('onhashchange' in window) {
482 break-if-!=
483 # TODO: ensure current word is not a function
484 # rename word at cursor
- 485 var new-name-ah/eax: (addr handle word) <- get sandbox, partial-name-for-cursor-word
+ 485 var new-name-ah/eax: (addr handle word) <- get sandbox, partial-name-for-cursor-word
486 allocate new-name-ah
- 487 var new-name/eax: (addr word) <- lookup *new-name-ah
- 488 initialize-word new-name
+ 487 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 488 initialize-word new-name
489 break $process-sandbox:body
490 }
491 compare key, 4 # ctrl-d
492 $process:define-function: {
493 break-if-!=
494 # define function out of line at cursor
- 495 var new-name-ah/eax: (addr handle word) <- get sandbox, partial-name-for-function
+ 495 var new-name-ah/eax: (addr handle word) <- get sandbox, partial-name-for-function
496 allocate new-name-ah
- 497 var new-name/eax: (addr word) <- lookup *new-name-ah
- 498 initialize-word new-name
+ 497 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 498 initialize-word new-name
499 break $process-sandbox:body
500 }
501 # otherwise insert key within current word
@@ -564,7 +564,7 @@ if ('onhashchange' in window) {
504 $process-sandbox:real-grapheme: {
505 compare print?, 0 # false
506 break-if-=
- 507 add-grapheme-to-word cursor-word, g
+ 507 add-grapheme-to-word cursor-word, g
508 break $process-sandbox:body
509 }
510 # silently ignore other hotkeys
@@ -574,10 +574,10 @@ if ('onhashchange' in window) {
514 # collect new name in partial-name-for-cursor-word, and then rename the word
515 # at cursor to it
516 # Precondition: cursor-call-path is a singleton (not within a call)
- 517 fn process-sandbox-rename _sandbox: (addr sandbox), key: grapheme {
+ 517 fn process-sandbox-rename _sandbox: (addr sandbox), key: grapheme {
518 $process-sandbox-rename:body: {
- 519 var sandbox/esi: (addr sandbox) <- copy _sandbox
- 520 var new-name-ah/edi: (addr handle word) <- get sandbox, partial-name-for-cursor-word
+ 519 var sandbox/esi: (addr sandbox) <- copy _sandbox
+ 520 var new-name-ah/edi: (addr handle word) <- get sandbox, partial-name-for-cursor-word
521 # if 'esc' pressed, cancel rename
522 compare key, 0x1b # esc
523 $process-sandbox-rename:cancel: {
@@ -591,26 +591,26 @@ if ('onhashchange' in window) {
531 break-if-!=
532 #? print-string 0, "rename\n"
533 # new line
- 534 var new-line-h: (handle line)
- 535 var new-line-ah/eax: (addr handle line) <- address new-line-h
+ 534 var new-line-h: (handle line)
+ 535 var new-line-ah/eax: (addr handle line) <- address new-line-h
536 allocate new-line-ah
- 537 var new-line/eax: (addr line) <- lookup *new-line-ah
- 538 initialize-line new-line
- 539 var new-line-word-ah/ecx: (addr handle word) <- get new-line, data
+ 537 var new-line/eax: (addr line) <- lookup *new-line-ah
+ 538 initialize-line new-line
+ 539 var new-line-word-ah/ecx: (addr handle word) <- get new-line, data
540 {
541 # move word at cursor to new line
- 542 var cursor-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 543 var cursor/eax: (addr call-path-element) <- lookup *cursor-ah
- 544 var word-at-cursor-ah/eax: (addr handle word) <- get cursor, word
+ 542 var cursor-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 543 var cursor/eax: (addr call-path-element) <- lookup *cursor-ah
+ 544 var word-at-cursor-ah/eax: (addr handle word) <- get cursor, word
545 #? print-string 0, "cursor before at word "
546 #? {
547 #? var cursor-word/eax: (addr word) <- lookup *word-at-cursor-ah
548 #? print-word 0, cursor-word
549 #? print-string 0, "\n"
550 #? }
- 551 move-word-contents word-at-cursor-ah, new-line-word-ah
+ 551 move-word-contents word-at-cursor-ah, new-line-word-ah
552 # copy name to word at cursor
- 553 copy-word-contents-before-cursor new-name-ah, word-at-cursor-ah
+ 553 copy-word-contents-before-cursor new-name-ah, word-at-cursor-ah
554 #? print-string 0, "cursor after at word "
555 #? {
556 #? var cursor-word/eax: (addr word) <- lookup *word-at-cursor-ah
@@ -632,15 +632,15 @@ if ('onhashchange' in window) {
572 }
573 # prepend '=' to name
574 {
- 575 var new-name/eax: (addr word) <- lookup *new-name-ah
- 576 cursor-to-start new-name
- 577 add-grapheme-to-word new-name, 0x3d # '='
+ 575 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 576 cursor-to-start new-name
+ 577 add-grapheme-to-word new-name, 0x3d # '='
578 }
579 # append name to new line
- 580 chain-words new-line-word-ah, new-name-ah
+ 580 chain-words new-line-word-ah, new-name-ah
581 # new-line->next = sandbox->data
- 582 var new-line-next/ecx: (addr handle line) <- get new-line, next
- 583 var sandbox-slot/edx: (addr handle line) <- get sandbox, data
+ 582 var new-line-next/ecx: (addr handle line) <- get new-line, next
+ 583 var sandbox-slot/edx: (addr handle line) <- get sandbox, data
584 copy-object sandbox-slot, new-line-next
585 # sandbox->data = new-line
586 copy-handle new-line-h, sandbox-slot
@@ -665,13 +665,13 @@ if ('onhashchange' in window) {
605 $process-sandbox-rename:backspace: {
606 break-if-!=
607 # if not at start, delete grapheme before cursor
- 608 var new-name/eax: (addr word) <- lookup *new-name-ah
- 609 var at-start?/eax: boolean <- cursor-at-start? new-name
+ 608 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 609 var at-start?/eax: boolean <- cursor-at-start? new-name
610 compare at-start?, 0 # false
611 {
612 break-if-!=
- 613 var new-name/eax: (addr word) <- lookup *new-name-ah
- 614 delete-before-cursor new-name
+ 613 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 614 delete-before-cursor new-name
615 }
616 break $process-sandbox-rename:body
617 }
@@ -680,8 +680,8 @@ if ('onhashchange' in window) {
620 $process-sandbox-rename:real-grapheme: {
621 compare print?, 0 # false
622 break-if-=
- 623 var new-name/eax: (addr word) <- lookup *new-name-ah
- 624 add-grapheme-to-word new-name, key
+ 623 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 624 add-grapheme-to-word new-name, key
625 break $process-sandbox-rename:body
626 }
627 # silently ignore other hotkeys
@@ -692,10 +692,10 @@ if ('onhashchange' in window) {
632 # of the sandbox to be a new function with that name. Replace the last line
633 # with a call to the appropriate function.
634 # Precondition: cursor-call-path is a singleton (not within a call)
- 635 fn process-sandbox-define _sandbox: (addr sandbox), functions: (addr handle function), key: grapheme {
+ 635 fn process-sandbox-define _sandbox: (addr sandbox), functions: (addr handle function), key: grapheme {
636 $process-sandbox-define:body: {
- 637 var sandbox/esi: (addr sandbox) <- copy _sandbox
- 638 var new-name-ah/edi: (addr handle word) <- get sandbox, partial-name-for-function
+ 637 var sandbox/esi: (addr sandbox) <- copy _sandbox
+ 638 var new-name-ah/edi: (addr handle word) <- get sandbox, partial-name-for-function
639 # if 'esc' pressed, cancel define
640 compare key, 0x1b # esc
641 $process-sandbox-define:cancel: {
@@ -709,43 +709,43 @@ if ('onhashchange' in window) {
649 break-if-!=
650 #? print-string 0, "define\n"
651 # create new function
- 652 var new-function: (handle function)
- 653 var new-function-ah/ecx: (addr handle function) <- address new-function
+ 652 var new-function: (handle function)
+ 653 var new-function-ah/ecx: (addr handle function) <- address new-function
654 allocate new-function-ah
- 655 var _new-function/eax: (addr function) <- lookup *new-function-ah
- 656 var new-function/ebx: (addr function) <- copy _new-function
- 657 var dest/edx: (addr handle function) <- get new-function, next
+ 655 var _new-function/eax: (addr function) <- lookup *new-function-ah
+ 656 var new-function/ebx: (addr function) <- copy _new-function
+ 657 var dest/edx: (addr handle function) <- get new-function, next
658 copy-object functions, dest
659 copy-object new-function-ah, functions
660 # set function name to new-name
- 661 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 661 var new-name/eax: (addr word) <- lookup *new-name-ah
662 var dest/edx: (addr handle array byte) <- get new-function, name
- 663 word-to-string new-name, dest
+ 663 word-to-string new-name, dest
664 # move final line to body
- 665 var body-ah/eax: (addr handle line) <- get new-function, body
+ 665 var body-ah/eax: (addr handle line) <- get new-function, body
666 allocate body-ah
- 667 var body/eax: (addr line) <- lookup *body-ah
- 668 var body-contents/ecx: (addr handle word) <- get body, data
- 669 var final-line-storage: (handle line)
- 670 var final-line-ah/eax: (addr handle line) <- address final-line-storage
- 671 final-line sandbox, final-line-ah
- 672 var final-line/eax: (addr line) <- lookup *final-line-ah
- 673 var final-line-contents/eax: (addr handle word) <- get final-line, data
+ 667 var body/eax: (addr line) <- lookup *body-ah
+ 668 var body-contents/ecx: (addr handle word) <- get body, data
+ 669 var final-line-storage: (handle line)
+ 670 var final-line-ah/eax: (addr handle line) <- address final-line-storage
+ 671 final-line sandbox, final-line-ah
+ 672 var final-line/eax: (addr line) <- lookup *final-line-ah
+ 673 var final-line-contents/eax: (addr handle word) <- get final-line, data
674 copy-object final-line-contents, body-contents
675 #
676 copy-unbound-words-to-args functions
677 #
- 678 var empty-word: (handle word)
+ 678 var empty-word: (handle word)
679 copy-handle empty-word, final-line-contents
680 construct-call functions, final-line-contents
681 # clear partial-name-for-function
- 682 var empty-word: (handle word)
+ 682 var empty-word: (handle word)
683 copy-handle empty-word, new-name-ah
684 # update cursor
- 685 var final-line/eax: (addr line) <- lookup final-line-storage
- 686 var cursor-call-path-ah/ecx: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 685 var final-line/eax: (addr line) <- lookup final-line-storage
+ 686 var cursor-call-path-ah/ecx: (addr handle call-path-element) <- get sandbox, cursor-call-path
687 allocate cursor-call-path-ah # leak
- 688 initialize-path-from-line final-line, cursor-call-path-ah
+ 688 initialize-path-from-line final-line, cursor-call-path-ah
689 break $process-sandbox-define:body
690 }
691 #
@@ -753,13 +753,13 @@ if ('onhashchange' in window) {
693 $process-sandbox-define:backspace: {
694 break-if-!=
695 # if not at start, delete grapheme before cursor
- 696 var new-name/eax: (addr word) <- lookup *new-name-ah
- 697 var at-start?/eax: boolean <- cursor-at-start? new-name
+ 696 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 697 var at-start?/eax: boolean <- cursor-at-start? new-name
698 compare at-start?, 0 # false
699 {
700 break-if-!=
- 701 var new-name/eax: (addr word) <- lookup *new-name-ah
- 702 delete-before-cursor new-name
+ 701 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 702 delete-before-cursor new-name
703 }
704 break $process-sandbox-define:body
705 }
@@ -768,8 +768,8 @@ if ('onhashchange' in window) {
708 $process-sandbox-define:real-grapheme: {
709 compare print?, 0 # false
710 break-if-=
- 711 var new-name/eax: (addr word) <- lookup *new-name-ah
- 712 add-grapheme-to-word new-name, key
+ 711 var new-name/eax: (addr word) <- lookup *new-name-ah
+ 712 add-grapheme-to-word new-name, key
713 break $process-sandbox-define:body
714 }
715 # silently ignore other hotkeys
@@ -779,26 +779,26 @@ if ('onhashchange' in window) {
719 # extract from the body of the first function in 'functions' all words that
720 # aren't defined in the rest of 'functions'. Prepend them in reverse order.
721 # Assumes function body is a single line for now.
- 722 fn copy-unbound-words-to-args _functions: (addr handle function) {
+ 722 fn copy-unbound-words-to-args _functions: (addr handle function) {
723 # target
- 724 var target-ah/eax: (addr handle function) <- copy _functions
- 725 var _target/eax: (addr function) <- lookup *target-ah
- 726 var target/esi: (addr function) <- copy _target
- 727 var dest-ah/edi: (addr handle word) <- get target, args
+ 724 var target-ah/eax: (addr handle function) <- copy _functions
+ 725 var _target/eax: (addr function) <- lookup *target-ah
+ 726 var target/esi: (addr function) <- copy _target
+ 727 var dest-ah/edi: (addr handle word) <- get target, args
728 # next
- 729 var functions-ah/edx: (addr handle function) <- get target, next
+ 729 var functions-ah/edx: (addr handle function) <- get target, next
730 # src
- 731 var line-ah/eax: (addr handle line) <- get target, body
- 732 var line/eax: (addr line) <- lookup *line-ah
- 733 var curr-ah/eax: (addr handle word) <- get line, data
- 734 var curr/eax: (addr word) <- lookup *curr-ah
+ 731 var line-ah/eax: (addr handle line) <- get target, body
+ 732 var line/eax: (addr line) <- lookup *line-ah
+ 733 var curr-ah/eax: (addr handle word) <- get line, data
+ 734 var curr/eax: (addr word) <- lookup *curr-ah
735 {
736 compare curr, 0
737 break-if-=
738 $copy-unbound-words-to-args:loop-iter: {
739 # is it a number?
740 {
- 741 var is-int?/eax: boolean <- word-is-decimal-integer? curr
+ 741 var is-int?/eax: boolean <- word-is-decimal-integer? curr
742 compare is-int?, 0 # false
743 break-if-!= $copy-unbound-words-to-args:loop-iter
744 }
@@ -811,128 +811,128 @@ if ('onhashchange' in window) {
751 compare dup?, 0 # false
752 break-if-!= $copy-unbound-words-to-args:loop-iter
753 # push copy of curr before dest-ah
- 754 var rest-h: (handle word)
- 755 var rest-ah/ecx: (addr handle word) <- address rest-h
+ 754 var rest-h: (handle word)
+ 755 var rest-ah/ecx: (addr handle word) <- address rest-h
756 copy-object dest-ah, rest-ah
- 757 copy-word curr, dest-ah
- 758 chain-words dest-ah, rest-ah
+ 757 copy-word curr, dest-ah
+ 758 chain-words dest-ah, rest-ah
759 }
- 760 var next-ah/ecx: (addr handle word) <- get curr, next
+ 760 var next-ah/ecx: (addr handle word) <- get curr, next
761 curr <- lookup *next-ah
762 loop
763 }
764 }
765
- 766 fn bound-function? w: (addr word), functions-ah: (addr handle function) -> _/ebx: boolean {
- 767 var result/ebx: boolean <- copy 1 # true
+ 766 fn bound-function? w: (addr word), functions-ah: (addr handle function) -> _/ebx: boolean {
+ 767 var result/ebx: boolean <- copy 1 # true
768 {
769 ## numbers
770 # if w == "+" return true
- 771 var subresult/eax: boolean <- word-equal? w, "+"
+ 771 var subresult/eax: boolean <- word-equal? w, "+"
772 compare subresult, 0 # false
773 break-if-!=
774 # if w == "-" return true
- 775 subresult <- word-equal? w, "-"
+ 775 subresult <- word-equal? w, "-"
776 compare subresult, 0 # false
777 break-if-!=
778 # if w == "*" return true
- 779 subresult <- word-equal? w, "*"
+ 779 subresult <- word-equal? w, "*"
780 compare subresult, 0 # false
781 break-if-!=
782 ## strings/arrays
783 # if w == "len" return true
- 784 subresult <- word-equal? w, "len"
+ 784 subresult <- word-equal? w, "len"
785 compare subresult, 0 # false
786 break-if-!=
787 ## files
788 # if w == "open" return true
- 789 subresult <- word-equal? w, "open"
+ 789 subresult <- word-equal? w, "open"
790 compare subresult, 0 # false
791 break-if-!=
792 # if w == "read" return true
- 793 subresult <- word-equal? w, "read"
+ 793 subresult <- word-equal? w, "read"
794 compare subresult, 0 # false
795 break-if-!=
796 # if w == "slurp" return true
- 797 subresult <- word-equal? w, "slurp"
+ 797 subresult <- word-equal? w, "slurp"
798 compare subresult, 0 # false
799 break-if-!=
800 # if w == "lines" return true
- 801 subresult <- word-equal? w, "lines"
+ 801 subresult <- word-equal? w, "lines"
802 compare subresult, 0 # false
803 break-if-!=
804 ## screens
805 # if w == "fake-screen" return true
- 806 subresult <- word-equal? w, "fake-screen"
+ 806 subresult <- word-equal? w, "fake-screen"
807 compare subresult, 0 # false
808 break-if-!=
809 # if w == "print" return true
- 810 subresult <- word-equal? w, "print"
+ 810 subresult <- word-equal? w, "print"
811 compare subresult, 0 # false
812 break-if-!=
813 # if w == "move" return true
- 814 subresult <- word-equal? w, "move"
+ 814 subresult <- word-equal? w, "move"
815 compare subresult, 0 # false
816 break-if-!=
817 # if w == "up" return true
- 818 subresult <- word-equal? w, "up"
+ 818 subresult <- word-equal? w, "up"
819 compare subresult, 0 # false
820 break-if-!=
821 # if w == "down" return true
- 822 subresult <- word-equal? w, "down"
+ 822 subresult <- word-equal? w, "down"
823 compare subresult, 0 # false
824 break-if-!=
825 # if w == "left" return true
- 826 subresult <- word-equal? w, "left"
+ 826 subresult <- word-equal? w, "left"
827 compare subresult, 0 # false
828 break-if-!=
829 # if w == "right" return true
- 830 subresult <- word-equal? w, "right"
+ 830 subresult <- word-equal? w, "right"
831 compare subresult, 0 # false
832 break-if-!=
833 ## hacks
834 # if w == "dup" return true
- 835 subresult <- word-equal? w, "dup"
+ 835 subresult <- word-equal? w, "dup"
836 compare subresult, 0 # false
837 break-if-!=
838 # if w == "swap" return true
- 839 subresult <- word-equal? w, "swap"
+ 839 subresult <- word-equal? w, "swap"
840 compare subresult, 0 # false
841 break-if-!=
842 # return w in functions
- 843 var out-h: (handle function)
- 844 var out/eax: (addr handle function) <- address out-h
+ 843 var out-h: (handle function)
+ 844 var out/eax: (addr handle function) <- address out-h
845 callee functions-ah, w, out
- 846 var found?/eax: (addr function) <- lookup *out
- 847 result <- copy found?
+ 846 var found?/eax: (addr function) <- lookup *out
+ 847 result <- copy found?
848 }
- 849 return result
+ 849 return result
850 }
851
- 852 fn arg-exists? _f-ah: (addr handle function), arg: (addr word) -> _/ebx: boolean {
- 853 var f-ah/eax: (addr handle function) <- copy _f-ah
- 854 var f/eax: (addr function) <- lookup *f-ah
- 855 var args-ah/eax: (addr handle word) <- get f, args
- 856 var result/ebx: boolean <- word-exists? args-ah, arg
- 857 return result
+ 852 fn arg-exists? _f-ah: (addr handle function), arg: (addr word) -> _/ebx: boolean {
+ 853 var f-ah/eax: (addr handle function) <- copy _f-ah
+ 854 var f/eax: (addr function) <- lookup *f-ah
+ 855 var args-ah/eax: (addr handle word) <- get f, args
+ 856 var result/ebx: boolean <- word-exists? args-ah, arg
+ 857 return result
858 }
859
860 # construct a call to `f` with copies of exactly its args
- 861 fn construct-call _f-ah: (addr handle function), _dest-ah: (addr handle word) {
- 862 var f-ah/eax: (addr handle function) <- copy _f-ah
- 863 var _f/eax: (addr function) <- lookup *f-ah
- 864 var f/esi: (addr function) <- copy _f
+ 861 fn construct-call _f-ah: (addr handle function), _dest-ah: (addr handle word) {
+ 862 var f-ah/eax: (addr handle function) <- copy _f-ah
+ 863 var _f/eax: (addr function) <- lookup *f-ah
+ 864 var f/esi: (addr function) <- copy _f
865 # append args in reverse
- 866 var args-ah/eax: (addr handle word) <- get f, args
- 867 var dest-ah/edi: (addr handle word) <- copy _dest-ah
- 868 copy-words-in-reverse args-ah, dest-ah
+ 866 var args-ah/eax: (addr handle word) <- get f, args
+ 867 var dest-ah/edi: (addr handle word) <- copy _dest-ah
+ 868 copy-words-in-reverse args-ah, dest-ah
869 # append name
870 var name-ah/eax: (addr handle array byte) <- get f, name
871 var name/eax: (addr array byte) <- lookup *name-ah
- 872 append-word-at-end-with dest-ah, name
+ 872 append-word-at-end-with dest-ah, name
873 }
874
- 875 fn word-index _words: (addr handle word), _n: int, out: (addr handle word) {
+ 875 fn word-index _words: (addr handle word), _n: int, out: (addr handle word) {
876 $word-index:body: {
877 var n/ecx: int <- copy _n
878 {
@@ -941,30 +941,30 @@ if ('onhashchange' in window) {
881 copy-object _words, out
882 break $word-index:body
883 }
- 884 var words-ah/eax: (addr handle word) <- copy _words
- 885 var words/eax: (addr word) <- lookup *words-ah
- 886 var next/eax: (addr handle word) <- get words, next
+ 884 var words-ah/eax: (addr handle word) <- copy _words
+ 885 var words/eax: (addr word) <- lookup *words-ah
+ 886 var next/eax: (addr handle word) <- get words, next
887 n <- decrement
888 word-index next, n, out
889 }
890 }
891
- 892 fn toggle-cursor-word _sandbox: (addr sandbox) {
+ 892 fn toggle-cursor-word _sandbox: (addr sandbox) {
893 $toggle-cursor-word:body: {
- 894 var sandbox/esi: (addr sandbox) <- copy _sandbox
- 895 var expanded-words/edi: (addr handle call-path) <- get sandbox, expanded-words
- 896 var cursor-call-path/ecx: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 894 var sandbox/esi: (addr sandbox) <- copy _sandbox
+ 895 var expanded-words/edi: (addr handle call-path) <- get sandbox, expanded-words
+ 896 var cursor-call-path/ecx: (addr handle call-path-element) <- get sandbox, cursor-call-path
897 #? print-string 0, "cursor call path: "
898 #? dump-call-path-element 0, cursor-call-path
899 #? print-string 0, "expanded words:\n"
900 #? dump-call-paths 0, expanded-words
- 901 var already-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
+ 901 var already-expanded?/eax: boolean <- find-in-call-paths expanded-words, cursor-call-path
902 compare already-expanded?, 0 # false
903 {
904 break-if-!=
905 #? print-string 0, "expand\n"
906 # if not already-expanded, insert
- 907 insert-in-call-path expanded-words cursor-call-path
+ 907 insert-in-call-path expanded-words cursor-call-path
908 #? print-string 0, "expanded words now:\n"
909 #? dump-call-paths 0, expanded-words
910 break $toggle-cursor-word:body
@@ -972,36 +972,36 @@ if ('onhashchange' in window) {
912 {
913 break-if-=
914 # otherwise delete
- 915 delete-in-call-path expanded-words cursor-call-path
+ 915 delete-in-call-path expanded-words cursor-call-path
916 }
917 }
918 }
919
- 920 fn append-line _sandbox: (addr sandbox) {
- 921 var sandbox/esi: (addr sandbox) <- copy _sandbox
- 922 var line-ah/ecx: (addr handle line) <- get sandbox, data
+ 920 fn append-line _sandbox: (addr sandbox) {
+ 921 var sandbox/esi: (addr sandbox) <- copy _sandbox
+ 922 var line-ah/ecx: (addr handle line) <- get sandbox, data
923 {
- 924 var line/eax: (addr line) <- lookup *line-ah
- 925 var next-line-ah/edx: (addr handle line) <- get line, next
- 926 var next-line/eax: (addr line) <- lookup *next-line-ah
+ 924 var line/eax: (addr line) <- lookup *line-ah
+ 925 var next-line-ah/edx: (addr handle line) <- get line, next
+ 926 var next-line/eax: (addr line) <- lookup *next-line-ah
927 compare next-line, 0
928 break-if-=
929 line-ah <- copy next-line-ah
930 loop
931 }
- 932 var line/eax: (addr line) <- lookup *line-ah
- 933 var final-line-ah/edx: (addr handle line) <- get line, next
+ 932 var line/eax: (addr line) <- lookup *line-ah
+ 933 var final-line-ah/edx: (addr handle line) <- get line, next
934 allocate final-line-ah
- 935 var final-line/eax: (addr line) <- lookup *final-line-ah
- 936 initialize-line final-line
- 937 var final-prev/eax: (addr handle line) <- get final-line, prev
+ 935 var final-line/eax: (addr line) <- lookup *final-line-ah
+ 936 initialize-line final-line
+ 937 var final-prev/eax: (addr handle line) <- get final-line, prev
938 copy-object line-ah, final-prev
939 # clear cursor
- 940 var final-line/eax: (addr line) <- lookup *final-line-ah
- 941 var word-ah/ecx: (addr handle word) <- get final-line, data
- 942 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
- 943 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
- 944 var dest/eax: (addr handle word) <- get cursor-call-path, word
+ 940 var final-line/eax: (addr line) <- lookup *final-line-ah
+ 941 var word-ah/ecx: (addr handle word) <- get final-line, data
+ 942 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+ 943 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+ 944 var dest/eax: (addr handle word) <- get cursor-call-path, word
945 copy-object word-ah, dest
946 }
947
@@ -1009,17 +1009,17 @@ if ('onhashchange' in window) {
949 # Visualize
950 #############
951
- 952 fn evaluate-environment _env: (addr environment), stack: (addr value-stack) {
+ 952 fn evaluate-environment _env: (addr environment), stack: (addr value-stack) {
953 var env/esi: (addr environment) <- copy _env
954 # functions
- 955 var functions/edx: (addr handle function) <- get env, functions
+ 955 var functions/edx: (addr handle function) <- get env, functions
956 # line
- 957 var sandbox-ah/esi: (addr handle sandbox) <- get env, sandboxes
- 958 var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
- 959 var line-ah/eax: (addr handle line) <- get sandbox, data
- 960 var _line/eax: (addr line) <- lookup *line-ah
- 961 var line/esi: (addr line) <- copy _line
- 962 evaluate functions, 0, line, 0, stack
+ 957 var sandbox-ah/esi: (addr handle sandbox) <- get env, sandboxes
+ 958 var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
+ 959 var line-ah/eax: (addr handle line) <- get sandbox, data
+ 960 var _line/eax: (addr line) <- lookup *line-ah
+ 961 var line/esi: (addr line) <- copy _line
+ 962 evaluate functions, 0, line, 0, stack
963 }
964
965 fn render _env: (addr environment) {
@@ -1035,25 +1035,25 @@ if ('onhashchange' in window) {
975 var repl-col/ecx: int <- copy *_repl-col
976 repl-col <- add 2 # repl-margin-left
977 # functions
- 978 var functions/edx: (addr handle function) <- get env, functions
+ 978 var functions/edx: (addr handle function) <- get env, functions
979 # sandbox
- 980 var sandbox-ah/eax: (addr handle sandbox) <- get env, sandboxes
- 981 var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
+ 980 var sandbox-ah/eax: (addr handle sandbox) <- get env, sandboxes
+ 981 var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
982 # bindings
- 983 var bindings-storage: table
- 984 var bindings/ebx: (addr table) <- address bindings-storage
- 985 initialize-table bindings, 0x10
+ 983 var bindings-storage: table
+ 984 var bindings/ebx: (addr table) <- address bindings-storage
+ 985 initialize-table bindings, 0x10
986 #? print-string 0, "render-sandbox {\n"
- 987 render-sandbox screen, functions, bindings, sandbox, 3, repl-col
+ 987 render-sandbox screen, functions, bindings, sandbox, 3, repl-col
988 #? print-string 0, "render-sandbox }\n"
989 }
990
- 991 fn render-sandbox screen: (addr screen), functions: (addr handle function), bindings: (addr table), _sandbox: (addr sandbox), top-row: int, left-col: int {
- 992 var sandbox/esi: (addr sandbox) <- copy _sandbox
+ 991 fn render-sandbox screen: (addr screen), functions: (addr handle function), bindings: (addr table), _sandbox: (addr sandbox), top-row: int, left-col: int {
+ 992 var sandbox/esi: (addr sandbox) <- copy _sandbox
993 # line
- 994 var curr-line-ah/eax: (addr handle line) <- get sandbox, data
- 995 var _curr-line/eax: (addr line) <- lookup *curr-line-ah
- 996 var curr-line/ecx: (addr line) <- copy _curr-line
+ 994 var curr-line-ah/eax: (addr handle line) <- get sandbox, data
+ 995 var _curr-line/eax: (addr line) <- lookup *curr-line-ah
+ 996 var curr-line/ecx: (addr line) <- copy _curr-line
997 #
998 var curr-row/edx: int <- copy top-row
999 # cursor row, col
@@ -1068,15 +1068,15 @@ if ('onhashchange' in window) {
1008 # render all but final line without stack
1009 #? print-string 0, "render all but final line\n"
1010 {
-1011 var next-line-ah/eax: (addr handle line) <- get curr-line, next
-1012 var next-line/eax: (addr line) <- lookup *next-line-ah
+1011 var next-line-ah/eax: (addr handle line) <- get curr-line, next
+1012 var next-line/eax: (addr line) <- lookup *next-line-ah
1013 compare next-line, 0
1014 break-if-=
1015 {
-1016 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
-1017 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
-1018 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
-1019 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+1016 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+1017 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+1018 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
+1019 var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
1020 # it's enough to pass in the first word of the path, because if the path isn't a singleton the word is guaranteed to be unique
1021 render-line-without-stack screen, curr-line, curr-row, left-col, cursor-word, cursor-row-addr, cursor-col-addr
1022 }
@@ -1085,57 +1085,57 @@ if ('onhashchange' in window) {
1025 loop
1026 }
1027 #
-1028 render-final-line-with-stack screen, functions, bindings, sandbox, curr-row, left-col, cursor-row-addr, cursor-col-addr
+1028 render-final-line-with-stack screen, functions, bindings, sandbox, curr-row, left-col, cursor-row-addr, cursor-col-addr
1029 # at most one of the following dialogs will be rendered
-1030 render-rename-dialog screen, sandbox, cursor-row, cursor-col
-1031 render-define-dialog screen, sandbox, cursor-row, cursor-col
+1030 render-rename-dialog screen, sandbox, cursor-row, cursor-col
+1031 render-define-dialog screen, sandbox, cursor-row, cursor-col
1032 move-cursor screen, cursor-row, cursor-col
1033 }
1034
-1035 fn render-final-line-with-stack screen: (addr screen), functions: (addr handle function), bindings: (addr table), _sandbox: (addr sandbox), top-row: int, left-col: int, cursor-row-addr: (addr int), cursor-col-addr: (addr int) {
-1036 var sandbox/esi: (addr sandbox) <- copy _sandbox
+1035 fn render-final-line-with-stack screen: (addr screen), functions: (addr handle function), bindings: (addr table), _sandbox: (addr sandbox), top-row: int, left-col: int, cursor-row-addr: (addr int), cursor-col-addr: (addr int) {
+1036 var sandbox/esi: (addr sandbox) <- copy _sandbox
1037 # expanded-words
-1038 var expanded-words/edi: (addr handle call-path) <- get sandbox, expanded-words
+1038 var expanded-words/edi: (addr handle call-path) <- get sandbox, expanded-words
1039 # cursor-word
-1040 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
-1041 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
-1042 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
-1043 var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
-1044 var cursor-word/ebx: (addr word) <- copy _cursor-word
+1040 var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+1041 var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah
+1042 var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word
+1043 var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+1044 var cursor-word/ebx: (addr word) <- copy _cursor-word
1045 #? print-string 0, "word at cursor: "
1046 #? print-word 0, cursor-word
1047 #? print-string 0, "\n"
1048 # cursor-call-path
-1049 var cursor-call-path: (addr handle call-path-element)
+1049 var cursor-call-path: (addr handle call-path-element)
1050 {
-1051 var src/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
+1051 var src/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path
1052 copy-to cursor-call-path, src
1053 }
1054 # first line
-1055 var first-line-ah/eax: (addr handle line) <- get sandbox, data
-1056 var _first-line/eax: (addr line) <- lookup *first-line-ah
-1057 var first-line/edx: (addr line) <- copy _first-line
+1055 var first-line-ah/eax: (addr handle line) <- get sandbox, data
+1056 var _first-line/eax: (addr line) <- lookup *first-line-ah
+1057 var first-line/edx: (addr line) <- copy _first-line
1058 # final line
-1059 var final-line-storage: (handle line)
-1060 var final-line-ah/eax: (addr handle line) <- address final-line-storage
-1061 final-line sandbox, final-line-ah
-1062 var final-line/eax: (addr line) <- lookup *final-line-ah
+1059 var final-line-storage: (handle line)
+1060 var final-line-ah/eax: (addr handle line) <- address final-line-storage
+1061 final-line sandbox, final-line-ah
+1062 var final-line/eax: (addr line) <- lookup *final-line-ah
1063 # curr-path
-1064 var curr-path-storage: (handle call-path-element)
-1065 var curr-path/ecx: (addr handle call-path-element) <- address curr-path-storage
+1064 var curr-path-storage: (handle call-path-element)
+1065 var curr-path/ecx: (addr handle call-path-element) <- address curr-path-storage
1066 allocate curr-path # leak
-1067 initialize-path-from-line final-line, curr-path
+1067 initialize-path-from-line final-line, curr-path
1068 #
1069 var dummy/ecx: int <- render-line screen, functions, bindings, first-line, final-line, expanded-words, top-row, left-col, curr-path, cursor-word, cursor-call-path, cursor-row-addr, cursor-col-addr
1070 }
1071
-1072 fn final-line _sandbox: (addr sandbox), out: (addr handle line) {
-1073 var sandbox/esi: (addr sandbox) <- copy _sandbox
-1074 var curr-line-ah/ecx: (addr handle line) <- get sandbox, data
+1072 fn final-line _sandbox: (addr sandbox), out: (addr handle line) {
+1073 var sandbox/esi: (addr sandbox) <- copy _sandbox
+1074 var curr-line-ah/ecx: (addr handle line) <- get sandbox, data
1075 {
-1076 var curr-line/eax: (addr line) <- lookup *curr-line-ah
-1077 var next-line-ah/edx: (addr handle line) <- get curr-line, next
-1078 var next-line/eax: (addr line) <- lookup *next-line-ah
+1076 var curr-line/eax: (addr line) <- lookup *curr-line-ah
+1077 var next-line-ah/edx: (addr handle line) <- get curr-line, next
+1078 var next-line/eax: (addr line) <- lookup *next-line-ah
1079 compare next-line, 0
1080 break-if-=
1081 curr-line-ah <- copy next-line-ah
@@ -1144,10 +1144,10 @@ if ('onhashchange' in window) {
1084 copy-object curr-line-ah, out
1085 }
1086
-1087 fn render-rename-dialog screen: (addr screen), _sandbox: (addr sandbox), cursor-row: int, cursor-col: int {
-1088 var sandbox/edi: (addr sandbox) <- copy _sandbox
-1089 var rename-word-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-cursor-word
-1090 var rename-word-mode?/eax: (addr word) <- lookup *rename-word-mode-ah?
+1087 fn render-rename-dialog screen: (addr screen), _sandbox: (addr sandbox), cursor-row: int, cursor-col: int {
+1088 var sandbox/edi: (addr sandbox) <- copy _sandbox
+1089 var rename-word-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-cursor-word
+1090 var rename-word-mode?/eax: (addr word) <- lookup *rename-word-mode-ah?
1091 compare rename-word-mode?, 0
1092 break-if-=
1093 # clear a space for the dialog
@@ -1159,8 +1159,8 @@ if ('onhashchange' in window) {
1099 left-col <- subtract 0x10
1100 var right-col/ebx: int <- copy cursor-col
1101 right-col <- add 0x10
-1102 clear-rect screen, top-row, left-col, bottom-row, right-col
-1103 draw-box screen, top-row, left-col, bottom-row, right-col
+1102 clear-rect screen, top-row, left-col, bottom-row, right-col
+1103 draw-box screen, top-row, left-col, bottom-row, right-col
1104 # render a little menu for the dialog
1105 var menu-row/ecx: int <- copy bottom-row
1106 menu-row <- decrement
@@ -1177,19 +1177,19 @@ if ('onhashchange' in window) {
1117 print-string screen, " rename "
1118 # draw the word, positioned appropriately around the cursor
1119 var start-col/ecx: int <- copy cursor-col
-1120 var word-ah?/edx: (addr handle word) <- get sandbox, partial-name-for-cursor-word
-1121 var word/eax: (addr word) <- lookup *word-ah?
-1122 var cursor-index/eax: int <- cursor-index word
-1123 start-col <- subtract cursor-index
+1120 var word-ah?/edx: (addr handle word) <- get sandbox, partial-name-for-cursor-word
+1121 var word/eax: (addr word) <- lookup *word-ah?
+1122 var cursor-index/eax: int <- cursor-index word
+1123 start-col <- subtract cursor-index
1124 move-cursor screen, cursor-row, start-col
-1125 var word/eax: (addr word) <- lookup *word-ah?
-1126 print-word screen, word
+1125 var word/eax: (addr word) <- lookup *word-ah?
+1126 print-word screen, word
1127 }
1128
-1129 fn render-define-dialog screen: (addr screen), _sandbox: (addr sandbox), cursor-row: int, cursor-col: int {
-1130 var sandbox/edi: (addr sandbox) <- copy _sandbox
-1131 var define-function-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-function
-1132 var define-function-mode?/eax: (addr word) <- lookup *define-function-mode-ah?
+1129 fn render-define-dialog screen: (addr screen), _sandbox: (addr sandbox), cursor-row: int, cursor-col: int {
+1130 var sandbox/edi: (addr sandbox) <- copy _sandbox
+1131 var define-function-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-function
+1132 var define-function-mode?/eax: (addr word) <- lookup *define-function-mode-ah?
1133 compare define-function-mode?, 0
1134 break-if-=
1135 # clear a space for the dialog
@@ -1201,8 +1201,8 @@ if ('onhashchange' in window) {
1141 left-col <- subtract 0x10
1142 var right-col/ebx: int <- copy cursor-col
1143 right-col <- add 0x10
-1144 clear-rect screen, top-row, left-col, bottom-row, right-col
-1145 draw-box screen, top-row, left-col, bottom-row, right-col
+1144 clear-rect screen, top-row, left-col, bottom-row, right-col
+1145 draw-box screen, top-row, left-col, bottom-row, right-col
1146 # render a little menu for the dialog
1147 var menu-row/ecx: int <- copy bottom-row
1148 menu-row <- decrement
@@ -1219,22 +1219,22 @@ if ('onhashchange' in window) {
1159 print-string screen, " define "
1160 # draw the word, positioned appropriately around the cursor
1161 var start-col/ecx: int <- copy cursor-col
-1162 var word-ah?/edx: (addr handle word) <- get sandbox, partial-name-for-function
-1163 var word/eax: (addr word) <- lookup *word-ah?
-1164 var cursor-index/eax: int <- cursor-index word
-1165 start-col <- subtract cursor-index
+1162 var word-ah?/edx: (addr handle word) <- get sandbox, partial-name-for-function
+1163 var word/eax: (addr word) <- lookup *word-ah?
+1164 var cursor-index/eax: int <- cursor-index word
+1165 start-col <- subtract cursor-index
1166 move-cursor screen, cursor-row, start-col
-1167 var word/eax: (addr word) <- lookup *word-ah?
-1168 print-word screen, word
+1167 var word/eax: (addr word) <- lookup *word-ah?
+1168 print-word screen, word
1169 }
1170
1171 # Render just the words in 'line'.
-1172 fn render-line-without-stack screen: (addr screen), _line: (addr line), curr-row: int, left-col: int, cursor-word: (addr word), cursor-row-addr: (addr int), cursor-col-addr: (addr int) {
+1172 fn render-line-without-stack screen: (addr screen), _line: (addr line), curr-row: int, left-col: int, cursor-word: (addr word), cursor-row-addr: (addr int), cursor-col-addr: (addr int) {
1173 # curr-word
-1174 var line/eax: (addr line) <- copy _line
-1175 var first-word-ah/eax: (addr handle word) <- get line, data
-1176 var _curr-word/eax: (addr word) <- lookup *first-word-ah
-1177 var curr-word/esi: (addr word) <- copy _curr-word
+1174 var line/eax: (addr line) <- copy _line
+1175 var first-word-ah/eax: (addr handle word) <- get line, data
+1176 var _curr-word/eax: (addr word) <- lookup *first-word-ah
+1177 var curr-word/esi: (addr word) <- copy _curr-word
1178 #
1179 # loop-carried dependency
1180 var curr-col/ecx: int <- copy left-col
@@ -1251,9 +1251,9 @@ if ('onhashchange' in window) {
1191 var old-col/edx: int <- copy curr-col
1192 reset-formatting screen
1193 move-cursor screen, curr-row, curr-col
-1194 print-word screen, curr-word
+1194 print-word screen, curr-word
1195 {
-1196 var max-width/eax: int <- word-length curr-word
+1196 var max-width/eax: int <- word-length curr-word
1197 curr-col <- add max-width
1198 curr-col <- add 1 # margin-right
1199 }
@@ -1279,50 +1279,50 @@ if ('onhashchange' in window) {
1219 copy-to *dest, src
1220 dest <- copy cursor-col-addr
1221 copy-to *dest, old-col
-1222 var cursor-index-in-word/eax: int <- cursor-index curr-word
+1222 var cursor-index-in-word/eax: int <- cursor-index curr-word
1223 add-to *dest, cursor-index-in-word
1224 }
1225 # loop update
-1226 var next-word-ah/edx: (addr handle word) <- get curr-word, next
-1227 var _curr-word/eax: (addr word) <- lookup *next-word-ah
+1226 var next-word-ah/edx: (addr handle word) <- get curr-word, next
+1227 var _curr-word/eax: (addr word) <- lookup *next-word-ah
1228 curr-word <- copy _curr-word
1229 loop
1230 }
1231 }
1232
-1233 fn call-depth-at-cursor _sandbox: (addr sandbox) -> _/eax: int {
-1234 var sandbox/esi: (addr sandbox) <- copy _sandbox
-1235 var cursor-call-path/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
-1236 var result/eax: int <- call-path-element-length cursor-call-path
-1237 result <- add 2 # input-row - 1
-1238 return result
+1233 fn call-depth-at-cursor _sandbox: (addr sandbox) -> _/eax: int {
+1234 var sandbox/esi: (addr sandbox) <- copy _sandbox
+1235 var cursor-call-path/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path
+1236 var result/eax: int <- call-path-element-length cursor-call-path
+1237 result <- add 2 # input-row - 1
+1238 return result
1239 }
1240
-1241 fn call-path-element-length _x: (addr handle call-path-element) -> _/eax: int {
-1242 var curr-ah/ecx: (addr handle call-path-element) <- copy _x
-1243 var result/edi: int <- copy 0
+1241 fn call-path-element-length _x: (addr handle call-path-element) -> _/eax: int {
+1242 var curr-ah/ecx: (addr handle call-path-element) <- copy _x
+1243 var result/edi: int <- copy 0
1244 {
-1245 var curr/eax: (addr call-path-element) <- lookup *curr-ah
+1245 var curr/eax: (addr call-path-element) <- lookup *curr-ah
1246 compare curr, 0
1247 break-if-=
1248 curr-ah <- get curr, next
-1249 result <- increment
+1249 result <- increment
1250 loop
1251 }
-1252 return result
+1252 return result
1253 }
1254
1255 # Render the line of words in line, along with the state of the stack under each word.
1256 # Also render any expanded function calls using recursive calls.
1257 #
1258 # Along the way, compute the column the cursor should be positioned at (cursor-col-addr).
-1259 fn render-line screen: (addr screen), functions: (addr handle function), bindings: (addr table), first-line: (addr line), _line: (addr line), expanded-words: (addr handle call-path), top-row: int, left-col: int, curr-path: (addr handle call-path-element), cursor-word: (addr word), cursor-call-path: (addr handle call-path-element), cursor-row-addr: (addr int), cursor-col-addr: (addr int) -> _/ecx: int {
+1259 fn render-line screen: (addr screen), functions: (addr handle function), bindings: (addr table), first-line: (addr line), _line: (addr line), expanded-words: (addr handle call-path), top-row: int, left-col: int, curr-path: (addr handle call-path-element), cursor-word: (addr word), cursor-call-path: (addr handle call-path-element), cursor-row-addr: (addr int), cursor-col-addr: (addr int) -> _/ecx: int {
1260 #? print-string 0, "render-line\n"
1261 #? dump-table bindings
1262 # curr-word
-1263 var line/esi: (addr line) <- copy _line
-1264 var first-word-ah/eax: (addr handle word) <- get line, data
-1265 var curr-word/eax: (addr word) <- lookup *first-word-ah
+1263 var line/esi: (addr line) <- copy _line
+1264 var first-word-ah/eax: (addr handle word) <- get line, data
+1265 var curr-word/eax: (addr word) <- lookup *first-word-ah
1266 #
1267 # loop-carried dependency
1268 var curr-col/ecx: int <- copy left-col
@@ -1337,62 +1337,62 @@ if ('onhashchange' in window) {
1277 $render-line:subsidiary: {
1278 {
1279 #? print-string 0, "check sub\n"
-1280 var display-subsidiary-stack?/eax: boolean <- find-in-call-paths expanded-words, curr-path
+1280 var display-subsidiary-stack?/eax: boolean <- find-in-call-paths expanded-words, curr-path
1281 compare display-subsidiary-stack?, 0 # false
1282 break-if-= $render-line:subsidiary
1283 }
1284 #? print-string 0, "render subsidiary stack\n"
1285 # does function exist?
-1286 var callee/edi: (addr function) <- copy 0
+1286 var callee/edi: (addr function) <- copy 0
1287 {
-1288 var callee-h: (handle function)
-1289 var callee-ah/ecx: (addr handle function) <- address callee-h
+1288 var callee-h: (handle function)
+1289 var callee-ah/ecx: (addr handle function) <- address callee-h
1290 callee functions, curr-word, callee-ah
-1291 var _callee/eax: (addr function) <- lookup *callee-ah
+1291 var _callee/eax: (addr function) <- lookup *callee-ah
1292 callee <- copy _callee
1293 compare callee, 0
1294 break-if-= $render-line:subsidiary
1295 }
1296 move-cursor screen, top-row, curr-col
1297 start-color screen, 8, 7
-1298 print-word screen, curr-word
+1298 print-word screen, curr-word
1299 {
-1300 var word-len/eax: int <- word-length curr-word
+1300 var word-len/eax: int <- word-length curr-word
1301 curr-col <- add word-len
1302 curr-col <- add 2
1303 increment top-row
1304 }
1305 # obtain stack at call site
-1306 var stack-storage: value-stack
-1307 var stack/edx: (addr value-stack) <- address stack-storage
-1308 initialize-value-stack stack, 0x10
+1306 var stack-storage: value-stack
+1307 var stack/edx: (addr value-stack) <- address stack-storage
+1308 initialize-value-stack stack, 0x10
1309 {
-1310 var prev-word-ah/eax: (addr handle word) <- get curr-word, prev
-1311 var prev-word/eax: (addr word) <- lookup *prev-word-ah
+1310 var prev-word-ah/eax: (addr handle word) <- get curr-word, prev
+1311 var prev-word/eax: (addr word) <- lookup *prev-word-ah
1312 compare prev-word, 0
1313 break-if-=
-1314 var bindings2-storage: table
-1315 var bindings2/ebx: (addr table) <- address bindings2-storage
-1316 deep-copy-table bindings, bindings2
-1317 evaluate functions, bindings2, first-line, prev-word, stack
+1314 var bindings2-storage: table
+1315 var bindings2/ebx: (addr table) <- address bindings2-storage
+1316 deep-copy-table bindings, bindings2
+1317 evaluate functions, bindings2, first-line, prev-word, stack
1318 }
1319 # construct new bindings
-1320 var callee-bindings-storage: table
-1321 var callee-bindings/esi: (addr table) <- address callee-bindings-storage
-1322 initialize-table callee-bindings, 0x10
-1323 bind-args callee, stack, callee-bindings
+1320 var callee-bindings-storage: table
+1321 var callee-bindings/esi: (addr table) <- address callee-bindings-storage
+1322 initialize-table callee-bindings, 0x10
+1323 bind-args callee, stack, callee-bindings
1324 # obtain body
-1325 var callee-body-ah/eax: (addr handle line) <- get callee, body
-1326 var callee-body/eax: (addr line) <- lookup *callee-body-ah
-1327 var callee-body-first-word/edx: (addr handle word) <- get callee-body, data
+1325 var callee-body-ah/eax: (addr handle line) <- get callee, body
+1326 var callee-body/eax: (addr line) <- lookup *callee-body-ah
+1327 var callee-body-first-word/edx: (addr handle word) <- get callee-body, data
1328 # - render subsidiary stack
-1329 push-to-call-path-element curr-path, callee-body-first-word # leak
+1329 push-to-call-path-element curr-path, callee-body-first-word # leak
1330 #? print-string 0, "subsidiary {\n"
1331 #? dump-table callee-bindings
1332 #? syscall_exit
1333 curr-col <- render-line screen, functions, callee-bindings, callee-body, callee-body, expanded-words, top-row, curr-col, curr-path, cursor-word, cursor-call-path, cursor-row-addr, cursor-col-addr
1334 #? print-string 0, "}\n"
-1335 drop-from-call-path-element curr-path
+1335 drop-from-call-path-element curr-path
1336 #
1337 move-cursor screen, top-row, curr-col
1338 print-code-point screen, 0x21d7 # ⇗
@@ -1402,18 +1402,18 @@ if ('onhashchange' in window) {
1342 }
1343 # render main column
1344 var old-col/edx: int <- copy curr-col
-1345 var bindings2-storage: table
-1346 var bindings2/ebx: (addr table) <- address bindings2-storage
+1345 var bindings2-storage: table
+1346 var bindings2/ebx: (addr table) <- address bindings2-storage
1347 #? print-string 0, "deep-copy {\n"
-1348 deep-copy-table bindings, bindings2
+1348 deep-copy-table bindings, bindings2
1349 #? print-string 0, "}\n"
1350 #? print-string 0, "render column {\n"
-1351 curr-col <- render-column screen, functions, bindings2, first-line, line, curr-word, top-row, curr-col
+1351 curr-col <- render-column screen, functions, bindings2, first-line, line, curr-word, top-row, curr-col
1352 #? print-string 0, "}\n"
1353 # cache cursor column if necessary
1354 $render-line:cache-cursor-column: {
1355 {
-1356 var found?/eax: boolean <- call-path-element-match? curr-path, cursor-call-path
+1356 var found?/eax: boolean <- call-path-element-match? curr-path, cursor-call-path
1357 compare found?, 0 # false
1358 break-if-= $render-line:cache-cursor-column
1359 }
@@ -1424,29 +1424,29 @@ if ('onhashchange' in window) {
1364 }
1365 dest <- copy cursor-col-addr
1366 copy-to *dest, old-col
-1367 var cursor-index-in-word/eax: int <- cursor-index curr-word
+1367 var cursor-index-in-word/eax: int <- cursor-index curr-word
1368 add-to *dest, cursor-index-in-word
1369 }
1370 # loop update
1371 #? print-string 0, "next word\n"
-1372 var next-word-ah/edx: (addr handle word) <- get curr-word, next
+1372 var next-word-ah/edx: (addr handle word) <- get curr-word, next
1373 curr-word <- lookup *next-word-ah
1374 #? {
1375 #? var foo/eax: int <- copy curr-word
1376 #? print-int32-hex 0, foo
1377 #? print-string 0, "\n"
1378 #? }
-1379 increment-final-element curr-path
+1379 increment-final-element curr-path
1380 loop
1381 }
1382 return curr-col
1383 }
1384
-1385 fn callee functions: (addr handle function), word: (addr word), out: (addr handle function) {
+1385 fn callee functions: (addr handle function), word: (addr word), out: (addr handle function) {
1386 var stream-storage: (stream byte 0x10)
1387 var stream/esi: (addr stream byte) <- address stream-storage
-1388 emit-word word, stream
-1389 find-function functions, stream, out
+1388 emit-word word, stream
+1389 find-function functions, stream, out
1390 }
1391
1392 # Render:
@@ -1454,42 +1454,42 @@ if ('onhashchange' in window) {
1394 # - starting somewhere below at left-col: the stack result from interpreting first-world to final-word (inclusive)
1395 #
1396 # Return the farthest column written.
-1397 fn render-column screen: (addr screen), functions: (addr handle function), bindings: (addr table), first-line: (addr line), line: (addr line), final-word: (addr word), top-row: int, left-col: int -> _/ecx: int {
+1397 fn render-column screen: (addr screen), functions: (addr handle function), bindings: (addr table), first-line: (addr line), line: (addr line), final-word: (addr word), top-row: int, left-col: int -> _/ecx: int {
1398 #? print-string 0, "render-column\n"
1399 #? dump-table bindings
1400 var max-width/esi: int <- copy 0
1401 {
1402 # compute stack
-1403 var stack: value-stack
-1404 var stack-addr/edi: (addr value-stack) <- address stack
-1405 initialize-value-stack stack-addr, 0x10 # max-words
+1403 var stack: value-stack
+1404 var stack-addr/edi: (addr value-stack) <- address stack
+1405 initialize-value-stack stack-addr, 0x10 # max-words
1406 # copy bindings
-1407 var bindings2-storage: table
-1408 var bindings2/ebx: (addr table) <- address bindings2-storage
+1407 var bindings2-storage: table
+1408 var bindings2/ebx: (addr table) <- address bindings2-storage
1409 #? print-string 0, "deep copy table {\n"
-1410 deep-copy-table bindings, bindings2
+1410 deep-copy-table bindings, bindings2
1411 #? print-string 0, "}\n"
-1412 evaluate functions, bindings2, first-line, final-word, stack-addr
+1412 evaluate functions, bindings2, first-line, final-word, stack-addr
1413 # indent stack
1414 var indented-col/ebx: int <- copy left-col
1415 indented-col <- add 1 # margin-right
1416 # render stack
1417 var curr-row/edx: int <- copy top-row
1418 curr-row <- add 2 # stack-margin-top
-1419 var _max-width/eax: int <- value-stack-max-width stack-addr
+1419 var _max-width/eax: int <- value-stack-max-width stack-addr
1420 max-width <- copy _max-width
1421 {
1422 var top-addr/ecx: (addr int) <- get stack-addr, top
1423 compare *top-addr, 0
1424 break-if-<=
1425 decrement *top-addr
-1426 var data-ah/eax: (addr handle array value) <- get stack-addr, data
-1427 var data/eax: (addr array value) <- lookup *data-ah
+1426 var data-ah/eax: (addr handle array value) <- get stack-addr, data
+1427 var data/eax: (addr array value) <- lookup *data-ah
1428 var top/ecx: int <- copy *top-addr
-1429 var dest-offset/ecx: (offset value) <- compute-offset data, top
-1430 var val/eax: (addr value) <- index data, dest-offset
-1431 render-value-at screen, curr-row, indented-col, val, max-width
-1432 var height/eax: int <- value-height val
+1429 var dest-offset/ecx: (offset value) <- compute-offset data, top
+1430 var val/eax: (addr value) <- index data, dest-offset
+1431 render-value-at screen, curr-row, indented-col, val, max-width
+1432 var height/eax: int <- value-height val
1433 curr-row <- add height
1434 loop
1435 }
@@ -1500,9 +1500,9 @@ if ('onhashchange' in window) {
1440 # render word, initialize result
1441 reset-formatting screen
1442 move-cursor screen, top-row, left-col
-1443 print-word screen, final-word
+1443 print-word screen, final-word
1444 {
-1445 var size/eax: int <- word-length final-word
+1445 var size/eax: int <- word-length final-word
1446 compare size, max-width
1447 break-if-<=
1448 max-width <- copy size
@@ -1528,7 +1528,7 @@ if ('onhashchange' in window) {
1468 var nrows/eax: (addr int) <- get env, nrows
1469 var _repl-col/ecx: (addr int) <- get env, code-separator-col
1470 var repl-col/ecx: int <- copy *_repl-col
-1471 draw-vertical-line screen, 1, *nrows, repl-col
+1471 draw-vertical-line screen, 1, *nrows, repl-col
1472 # wordstar-style cheatsheet of shortcuts
1473 move-cursor screen, *nrows, 0
1474 start-reverse-video screen
@@ -1545,11 +1545,11 @@ if ('onhashchange' in window) {
1485 start-reverse-video screen
1486 print-string screen, " ctrl-b "
1487 reset-formatting screen
-1488 print-string screen, " â—€ word "
+1488 print-string screen, " â—€ word "
1489 start-reverse-video screen
1490 print-string screen, " ctrl-f "
1491 reset-formatting screen
-1492 print-string screen, " word â–¶ "
+1492 print-string screen, " word â–¶ "
1493 start-reverse-video screen
1494 print-string screen, " ctrl-e "
1495 reset-formatting screen
@@ -1557,7 +1557,7 @@ if ('onhashchange' in window) {
1497 start-reverse-video screen
1498 print-string screen, " ctrl-l "
1499 reset-formatting screen
-1500 print-string screen, " new line "
+1500 print-string screen, " new line "
1501 start-reverse-video screen
1502 print-string screen, " ctrl-u "
1503 reset-formatting screen
@@ -1565,11 +1565,11 @@ if ('onhashchange' in window) {
1505 start-reverse-video screen
1506 print-string screen, " ctrl-n "
1507 reset-formatting screen
-1508 print-string screen, " name value "
+1508 print-string screen, " name value "
1509 start-reverse-video screen
1510 print-string screen, " ctrl-d "
1511 reset-formatting screen
-1512 print-string screen, " define function "
+1512 print-string screen, " define function "
1513 # primitives
1514 var dummy/eax: int <- render-primitives screen, *nrows, repl-col
1515 # currently defined functions
@@ -1631,9 +1631,9 @@ if ('onhashchange' in window) {
1571 var row/ecx: int <- copy 1
1572 var dummy-col/edx: int <- copy right-col
1573 var env/esi: (addr environment) <- copy _env
-1574 var functions/esi: (addr handle function) <- get env, functions
+1574 var functions/esi: (addr handle function) <- get env, functions
1575 {
-1576 var curr/eax: (addr function) <- lookup *functions
+1576 var curr/eax: (addr function) <- lookup *functions
1577 compare curr, 0
1578 break-if-=
1579 row, dummy-col <- render-function-right-aligned screen, row, right-col, curr
@@ -1645,19 +1645,19 @@ if ('onhashchange' in window) {
1585
1586 # print function starting at row, right-aligned before right-col
1587 # return row, col printed until
-1588 fn render-function-right-aligned screen: (addr screen), row: int, right-col: int, f: (addr function) -> _/ecx: int, _/edx: int {
+1588 fn render-function-right-aligned screen: (addr screen), row: int, right-col: int, f: (addr function) -> _/ecx: int, _/edx: int {
1589 var col/edx: int <- copy right-col
1590 col <- subtract 1 # function-right-margin
1591 var col2/ebx: int <- copy col
-1592 var width/eax: int <- function-width f
+1592 var width/eax: int <- function-width f
1593 col <- subtract width
1594 var new-row/ecx: int <- copy row
-1595 var height/eax: int <- function-height f
+1595 var height/eax: int <- function-height f
1596 new-row <- add height
1597 new-row <- decrement
1598 col <- subtract 1 # function-left-padding
1599 start-color screen, 0, 0xf7
-1600 clear-rect screen, row, col, new-row, col2
+1600 clear-rect screen, row, col, new-row, col2
1601 col <- add 1
1602 #? var dummy/eax: grapheme <- read-key-from-real-keyboard
1603 render-function screen, row, col, f
@@ -1670,11 +1670,11 @@ if ('onhashchange' in window) {
1610
1611 # render function starting at row, col
1612 # only single-line functions supported for now
-1613 fn render-function screen: (addr screen), row: int, col: int, _f: (addr function) {
-1614 var f/esi: (addr function) <- copy _f
-1615 var args/ecx: (addr handle word) <- get f, args
+1613 fn render-function screen: (addr screen), row: int, col: int, _f: (addr function) {
+1614 var f/esi: (addr function) <- copy _f
+1615 var args/ecx: (addr handle word) <- get f, args
1616 move-cursor screen, row, col
-1617 print-words-in-reverse screen, args
+1617 print-words-in-reverse screen, args
1618 var name-ah/eax: (addr handle array byte) <- get f, name
1619 var name/eax: (addr array byte) <- lookup *name-ah
1620 start-bold screen
@@ -1685,10 +1685,10 @@ if ('onhashchange' in window) {
1625 add-to col, 2
1626 move-cursor screen, row, col
1627 print-string screen, "≡ "
-1628 var body-ah/eax: (addr handle line) <- get f, body
-1629 var body/eax: (addr line) <- lookup *body-ah
-1630 var body-words-ah/eax: (addr handle word) <- get body, data
-1631 print-words screen, body-words-ah
+1628 var body-ah/eax: (addr handle line) <- get f, body
+1629 var body/eax: (addr line) <- lookup *body-ah
+1630 var body-words-ah/eax: (addr handle word) <- get body, data
+1631 print-words screen, body-words-ah
1632 }
1633
1634 fn real-grapheme? g: grapheme -> _/eax: boolean {
diff --git a/html/apps/tile/gap-buffer.mu.html b/html/apps/tile/gap-buffer.mu.html
index 873992ef..028667b1 100644
--- a/html/apps/tile/gap-buffer.mu.html
+++ b/html/apps/tile/gap-buffer.mu.html
@@ -58,16 +58,16 @@ if ('onhashchange' in window) {
https://github.com/akkartik/mu/blob/master/apps/tile/gap-buffer.mu
1 type gap-buffer {
- 2 left: grapheme-stack
- 3 right: grapheme-stack
+ 2 left: grapheme-stack
+ 3 right: grapheme-stack
4 }
5
6 fn initialize-gap-buffer _self: (addr gap-buffer) {
7 var self/esi: (addr gap-buffer) <- copy _self
- 8 var left/eax: (addr grapheme-stack) <- get self, left
- 9 initialize-grapheme-stack left, 0x10 # max-word-size
- 10 var right/eax: (addr grapheme-stack) <- get self, right
- 11 initialize-grapheme-stack right, 0x10 # max-word-size
+ 8 var left/eax: (addr grapheme-stack) <- get self, left
+ 9 initialize-grapheme-stack left, 0x10 # max-word-size
+ 10 var right/eax: (addr grapheme-stack) <- get self, right
+ 11 initialize-grapheme-stack right, 0x10 # max-word-size
12 }
13
14 # just for tests
@@ -96,15 +96,15 @@ if ('onhashchange' in window) {
37 fn emit-gap-buffer _self: (addr gap-buffer), out: (addr stream byte) {
38 var self/esi: (addr gap-buffer) <- copy _self
39 clear-stream out
- 40 var left/eax: (addr grapheme-stack) <- get self, left
+ 40 var left/eax: (addr grapheme-stack) <- get self, left
41 emit-stack-from-bottom left, out
- 42 var right/eax: (addr grapheme-stack) <- get self, right
+ 42 var right/eax: (addr grapheme-stack) <- get self, right
43 emit-stack-from-top right, out
44 }
45
46 # dump stack from bottom to top
- 47 fn emit-stack-from-bottom _self: (addr grapheme-stack), out: (addr stream byte) {
- 48 var self/esi: (addr grapheme-stack) <- copy _self
+ 47 fn emit-stack-from-bottom _self: (addr grapheme-stack), out: (addr stream byte) {
+ 48 var self/esi: (addr grapheme-stack) <- copy _self
49 var data-ah/edi: (addr handle array grapheme) <- get self, data
50 var _data/eax: (addr array grapheme) <- lookup *data-ah
51 var data/edi: (addr array grapheme) <- copy _data
@@ -121,8 +121,8 @@ if ('onhashchange' in window) {
62 }
63
64 # dump stack from top to bottom
- 65 fn emit-stack-from-top _self: (addr grapheme-stack), out: (addr stream byte) {
- 66 var self/esi: (addr grapheme-stack) <- copy _self
+ 65 fn emit-stack-from-top _self: (addr grapheme-stack), out: (addr stream byte) {
+ 66 var self/esi: (addr grapheme-stack) <- copy _self
67 var data-ah/edi: (addr handle array grapheme) <- get self, data
68 var _data/eax: (addr array grapheme) <- lookup *data-ah
69 var data/edi: (addr array grapheme) <- copy _data
@@ -141,28 +141,28 @@ if ('onhashchange' in window) {
82
83 fn render-gap-buffer screen: (addr screen), _gap: (addr gap-buffer) {
84 var gap/esi: (addr gap-buffer) <- copy _gap
- 85 var left/eax: (addr grapheme-stack) <- get gap, left
- 86 render-stack-from-bottom left, screen
- 87 var right/eax: (addr grapheme-stack) <- get gap, right
- 88 render-stack-from-top right, screen
+ 85 var left/eax: (addr grapheme-stack) <- get gap, left
+ 86 render-stack-from-bottom left, screen
+ 87 var right/eax: (addr grapheme-stack) <- get gap, right
+ 88 render-stack-from-top right, screen
89 }
90
91 fn gap-buffer-length _gap: (addr gap-buffer) -> _/eax: int {
92 var gap/esi: (addr gap-buffer) <- copy _gap
- 93 var left/eax: (addr grapheme-stack) <- get gap, left
+ 93 var left/eax: (addr grapheme-stack) <- get gap, left
94 var tmp/eax: (addr int) <- get left, top
95 var left-length/ecx: int <- copy *tmp
- 96 var right/esi: (addr grapheme-stack) <- get gap, right
+ 96 var right/esi: (addr grapheme-stack) <- get gap, right
97 tmp <- get right, top
- 98 var result/eax: int <- copy *tmp
- 99 result <- add left-length
-100 return result
+ 98 var result/eax: int <- copy *tmp
+ 99 result <- add left-length
+100 return result
101 }
102
103 fn add-grapheme-at-gap _self: (addr gap-buffer), g: grapheme {
104 var self/esi: (addr gap-buffer) <- copy _self
-105 var left/eax: (addr grapheme-stack) <- get self, left
-106 push-grapheme-stack left, g
+105 var left/eax: (addr grapheme-stack) <- get self, left
+106 push-grapheme-stack left, g
107 }
108
109 fn gap-to-start self: (addr gap-buffer) {
@@ -183,28 +183,28 @@ if ('onhashchange' in window) {
124
125 fn gap-at-start? _self: (addr gap-buffer) -> _/eax: boolean {
126 var self/esi: (addr gap-buffer) <- copy _self
-127 var left/eax: (addr grapheme-stack) <- get self, left
-128 var result/eax: boolean <- grapheme-stack-empty? left
-129 return result
+127 var left/eax: (addr grapheme-stack) <- get self, left
+128 var result/eax: boolean <- grapheme-stack-empty? left
+129 return result
130 }
131
132 fn gap-at-end? _self: (addr gap-buffer) -> _/eax: boolean {
133 var self/esi: (addr gap-buffer) <- copy _self
-134 var right/eax: (addr grapheme-stack) <- get self, right
-135 var result/eax: boolean <- grapheme-stack-empty? right
-136 return result
+134 var right/eax: (addr grapheme-stack) <- get self, right
+135 var result/eax: boolean <- grapheme-stack-empty? right
+136 return result
137 }
138
139 fn gap-right _self: (addr gap-buffer) -> _/eax: grapheme {
140 var self/esi: (addr gap-buffer) <- copy _self
141 var g/eax: grapheme <- copy 0
-142 var right/ecx: (addr grapheme-stack) <- get self, right
-143 g <- pop-grapheme-stack right
+142 var right/ecx: (addr grapheme-stack) <- get self, right
+143 g <- pop-grapheme-stack right
144 compare g, -1
145 {
146 break-if-=
-147 var left/ecx: (addr grapheme-stack) <- get self, left
-148 push-grapheme-stack left, g
+147 var left/ecx: (addr grapheme-stack) <- get self, left
+148 push-grapheme-stack left, g
149 }
150 return g
151 }
@@ -213,30 +213,30 @@ if ('onhashchange' in window) {
154 var self/esi: (addr gap-buffer) <- copy _self
155 var g/eax: grapheme <- copy 0
156 {
-157 var left/ecx: (addr grapheme-stack) <- get self, left
-158 g <- pop-grapheme-stack left
+157 var left/ecx: (addr grapheme-stack) <- get self, left
+158 g <- pop-grapheme-stack left
159 }
160 compare g, -1
161 {
162 break-if-=
-163 var right/ecx: (addr grapheme-stack) <- get self, right
-164 push-grapheme-stack right, g
+163 var right/ecx: (addr grapheme-stack) <- get self, right
+164 push-grapheme-stack right, g
165 }
166 return g
167 }
168
169 fn gap-index _self: (addr gap-buffer) -> _/eax: int {
170 var self/eax: (addr gap-buffer) <- copy _self
-171 var left/eax: (addr grapheme-stack) <- get self, left
+171 var left/eax: (addr grapheme-stack) <- get self, left
172 var top-addr/eax: (addr int) <- get left, top
-173 var result/eax: int <- copy *top-addr
-174 return result
+173 var result/eax: int <- copy *top-addr
+174 return result
175 }
176
177 fn first-grapheme-in-gap-buffer _self: (addr gap-buffer) -> _/eax: grapheme {
178 var self/esi: (addr gap-buffer) <- copy _self
179 # try to read from left
-180 var left/eax: (addr grapheme-stack) <- get self, left
+180 var left/eax: (addr grapheme-stack) <- get self, left
181 var top-addr/ecx: (addr int) <- get left, top
182 compare *top-addr, 0
183 {
@@ -247,7 +247,7 @@ if ('onhashchange' in window) {
188 return *result-addr
189 }
190 # try to read from right
-191 var right/eax: (addr grapheme-stack) <- get self, right
+191 var right/eax: (addr grapheme-stack) <- get self, right
192 top-addr <- get right, top
193 compare *top-addr, 0
194 {
@@ -266,14 +266,14 @@ if ('onhashchange' in window) {
207 fn grapheme-before-cursor-in-gap-buffer _self: (addr gap-buffer) -> _/eax: grapheme {
208 var self/esi: (addr gap-buffer) <- copy _self
209 # try to read from left
-210 var left/ecx: (addr grapheme-stack) <- get self, left
+210 var left/ecx: (addr grapheme-stack) <- get self, left
211 var top-addr/edx: (addr int) <- get left, top
212 compare *top-addr, 0
213 {
214 break-if-<=
-215 var result/eax: grapheme <- pop-grapheme-stack left
-216 push-grapheme-stack left, result
-217 return result
+215 var result/eax: grapheme <- pop-grapheme-stack left
+216 push-grapheme-stack left, result
+217 return result
218 }
219 # give up
220 return -1
@@ -281,15 +281,15 @@ if ('onhashchange' in window) {
222
223 fn delete-before-gap _self: (addr gap-buffer) {
224 var self/eax: (addr gap-buffer) <- copy _self
-225 var left/eax: (addr grapheme-stack) <- get self, left
-226 var dummy/eax: grapheme <- pop-grapheme-stack left
+225 var left/eax: (addr grapheme-stack) <- get self, left
+226 var dummy/eax: grapheme <- pop-grapheme-stack left
227 }
228
229 fn pop-after-gap _self: (addr gap-buffer) -> _/eax: grapheme {
230 var self/eax: (addr gap-buffer) <- copy _self
-231 var right/eax: (addr grapheme-stack) <- get self, right
-232 var result/eax: grapheme <- pop-grapheme-stack right
-233 return result
+231 var right/eax: (addr grapheme-stack) <- get self, right
+232 var result/eax: grapheme <- pop-grapheme-stack right
+233 return result
234 }
235
236 fn gap-buffer-equal? _self: (addr gap-buffer), s: (addr array byte) -> _/eax: boolean {
@@ -301,24 +301,24 @@ if ('onhashchange' in window) {
242 var expected-stream/ecx: (addr stream byte) <- address stream-storage
243 write expected-stream, s
244 # compare left
-245 var left/edx: (addr grapheme-stack) <- get self, left
-246 var result/eax: boolean <- prefix-match? left, expected-stream
-247 compare result, 0 # false
+245 var left/edx: (addr grapheme-stack) <- get self, left
+246 var result/eax: boolean <- prefix-match? left, expected-stream
+247 compare result, 0 # false
248 {
249 break-if-!=
-250 return result
+250 return result
251 }
252 # compare right
-253 var right/edx: (addr grapheme-stack) <- get self, right
-254 result <- suffix-match? right, expected-stream
-255 compare result, 0 # false
+253 var right/edx: (addr grapheme-stack) <- get self, right
+254 result <- suffix-match? right, expected-stream
+255 compare result, 0 # false
256 {
257 break-if-!=
-258 return result
+258 return result
259 }
260 # ensure there's nothing left over
-261 result <- stream-empty? expected-stream
-262 return result
+261 result <- stream-empty? expected-stream
+262 return result
263 }
264
265 fn test-gap-buffer-equal-from-end? {
@@ -332,8 +332,8 @@ if ('onhashchange' in window) {
273 add-grapheme-at-gap g, c
274 # gap is at end (right is empty)
275 var _result/eax: boolean <- gap-buffer-equal? g, "aaa"
-276 var result/eax: int <- copy _result
-277 check-ints-equal result, 1, "F - test-gap-buffer-equal-from-end?"
+276 var result/eax: int <- copy _result
+277 check-ints-equal result, 1, "F - test-gap-buffer-equal-from-end?"
278 }
279
280 fn test-gap-buffer-equal-from-middle? {
@@ -348,8 +348,8 @@ if ('onhashchange' in window) {
289 var dummy/eax: grapheme <- gap-left g
290 # gap is in the middle
291 var _result/eax: boolean <- gap-buffer-equal? g, "aaa"
-292 var result/eax: int <- copy _result
-293 check-ints-equal result, 1, "F - test-gap-buffer-equal-from-middle?"
+292 var result/eax: int <- copy _result
+293 check-ints-equal result, 1, "F - test-gap-buffer-equal-from-middle?"
294 }
295
296 fn test-gap-buffer-equal-from-start? {
@@ -366,8 +366,8 @@ if ('onhashchange' in window) {
307 dummy <- gap-left g
308 # gap is at the start
309 var _result/eax: boolean <- gap-buffer-equal? g, "aaa"
-310 var result/eax: int <- copy _result
-311 check-ints-equal result, 1, "F - test-gap-buffer-equal-from-start?"
+310 var result/eax: int <- copy _result
+311 check-ints-equal result, 1, "F - test-gap-buffer-equal-from-start?"
312 }
313
314 fn copy-gap-buffer _src-ah: (addr handle gap-buffer), _dest-ah: (addr handle gap-buffer) {
@@ -379,26 +379,26 @@ if ('onhashchange' in window) {
320 var _dest-a/eax: (addr gap-buffer) <- lookup *dest-ah
321 var dest-a/edi: (addr gap-buffer) <- copy _dest-a
322 # copy left grapheme-stack
-323 var src/ecx: (addr grapheme-stack) <- get src-a, left
-324 var dest/edx: (addr grapheme-stack) <- get dest-a, left
-325 copy-grapheme-stack src, dest
+323 var src/ecx: (addr grapheme-stack) <- get src-a, left
+324 var dest/edx: (addr grapheme-stack) <- get dest-a, left
+325 copy-grapheme-stack src, dest
326 # copy right grapheme-stack
327 src <- get src-a, right
328 dest <- get dest-a, right
-329 copy-grapheme-stack src, dest
+329 copy-grapheme-stack src, dest
330 }
331
332 fn gap-buffer-is-decimal-integer? _self: (addr gap-buffer) -> _/eax: boolean {
333 var self/esi: (addr gap-buffer) <- copy _self
-334 var curr/ecx: (addr grapheme-stack) <- get self, left
-335 var result/eax: boolean <- grapheme-stack-is-decimal-integer? curr
+334 var curr/ecx: (addr grapheme-stack) <- get self, left
+335 var result/eax: boolean <- grapheme-stack-is-decimal-integer? curr
336 {
-337 compare result, 0 # false
+337 compare result, 0 # false
338 break-if-=
339 curr <- get self, right
-340 result <- grapheme-stack-is-decimal-integer? curr
+340 result <- grapheme-stack-is-decimal-integer? curr
341 }
-342 return result
+342 return result
343 }
- 1 fn evaluate functions: (addr handle function), bindings: (addr table), scratch: (addr line), end: (addr word), out: (addr value-stack) { - 2 var line/eax: (addr line) <- copy scratch - 3 var word-ah/eax: (addr handle word) <- get line, data - 4 var curr/eax: (addr word) <- lookup *word-ah + 1 fn evaluate functions: (addr handle function), bindings: (addr table), scratch: (addr line), end: (addr word), out: (addr value-stack) { + 2 var line/eax: (addr line) <- copy scratch + 3 var word-ah/eax: (addr handle word) <- get line, data + 4 var curr/eax: (addr word) <- lookup *word-ah 5 var curr-stream-storage: (stream byte 0x10) 6 var curr-stream/edi: (addr stream byte) <- address curr-stream-storage - 7 clear-value-stack out + 7 clear-value-stack out 8 $evaluate:loop: { 9 # precondition (should never hit) 10 compare curr, 0 11 break-if-= 12 # update curr-stream - 13 emit-word curr, curr-stream + 13 emit-word curr, curr-stream 14 #? print-string-to-real-screen "eval: " 15 #? print-stream-to-real-screen curr-stream 16 #? print-string-to-real-screen "\n" @@ -81,33 +81,33 @@ if ('onhashchange' in window) { 21 var is-add?/eax: boolean <- stream-data-equal? curr-stream, "+" 22 compare is-add?, 0 23 break-if-= - 24 var _b/eax: int <- pop-int-from-value-stack out + 24 var _b/eax: int <- pop-int-from-value-stack out 25 var b/edx: int <- copy _b - 26 var a/eax: int <- pop-int-from-value-stack out + 26 var a/eax: int <- pop-int-from-value-stack out 27 a <- add b - 28 push-int-to-value-stack out, a + 28 push-int-to-value-stack out, a 29 break $evaluate:process-word 30 } 31 { 32 var is-sub?/eax: boolean <- stream-data-equal? curr-stream, "-" 33 compare is-sub?, 0 34 break-if-= - 35 var _b/eax: int <- pop-int-from-value-stack out + 35 var _b/eax: int <- pop-int-from-value-stack out 36 var b/edx: int <- copy _b - 37 var a/eax: int <- pop-int-from-value-stack out + 37 var a/eax: int <- pop-int-from-value-stack out 38 a <- subtract b - 39 push-int-to-value-stack out, a + 39 push-int-to-value-stack out, a 40 break $evaluate:process-word 41 } 42 { 43 var is-mul?/eax: boolean <- stream-data-equal? curr-stream, "*" 44 compare is-mul?, 0 45 break-if-= - 46 var _b/eax: int <- pop-int-from-value-stack out + 46 var _b/eax: int <- pop-int-from-value-stack out 47 var b/edx: int <- copy _b - 48 var a/eax: int <- pop-int-from-value-stack out + 48 var a/eax: int <- pop-int-from-value-stack out 49 a <- multiply b - 50 push-int-to-value-stack out, a + 50 push-int-to-value-stack out, a 51 break $evaluate:process-word 52 } 53 ## strings/arrays @@ -117,17 +117,17 @@ if ('onhashchange' in window) { 57 break-if-= 58 #? print-string 0, "is len\n" 59 # pop target-val from out - 60 var out2/esi: (addr value-stack) <- copy out + 60 var out2/esi: (addr value-stack) <- copy out 61 var top-addr/ecx: (addr int) <- get out2, top 62 compare *top-addr, 0 63 break-if-<= 64 #? print-string 0, "stack has stuff\n" - 65 var data-ah/eax: (addr handle array value) <- get out2, data - 66 var data/eax: (addr array value) <- lookup *data-ah + 65 var data-ah/eax: (addr handle array value) <- get out2, data + 66 var data/eax: (addr array value) <- lookup *data-ah 67 var top/edx: int <- copy *top-addr 68 top <- decrement - 69 var dest-offset/edx: (offset value) <- compute-offset data, top - 70 var target-val/edx: (addr value) <- index data, dest-offset + 69 var dest-offset/edx: (offset value) <- compute-offset data, top + 70 var target-val/edx: (addr value) <- index data, dest-offset 71 # check target-val is a string or array 72 var target-type-addr/eax: (addr int) <- get target-val, type 73 compare *target-type-addr, 1 # string @@ -136,30 +136,30 @@ if ('onhashchange' in window) { 76 # compute length 77 var src-ah/eax: (addr handle array byte) <- get target-val, text-data 78 var src/eax: (addr array byte) <- lookup *src-ah - 79 var result/ebx: int <- length src + 79 var result/ebx: int <- length src 80 # save result into target-val 81 var type-addr/eax: (addr int) <- get target-val, type 82 copy-to *type-addr, 0 # int 83 var target-string-ah/eax: (addr handle array byte) <- get target-val, text-data 84 clear-object target-string-ah 85 var target/eax: (addr int) <- get target-val, int-data - 86 copy-to *target, result + 86 copy-to *target, result 87 break $evaluate:process-word 88 } 89 compare *target-type-addr, 2 # array of ints 90 { 91 break-if-!= 92 # compute length - 93 var src-ah/eax: (addr handle array value) <- get target-val, array-data - 94 var src/eax: (addr array value) <- lookup *src-ah - 95 var result/ebx: int <- length src + 93 var src-ah/eax: (addr handle array value) <- get target-val, array-data + 94 var src/eax: (addr array value) <- lookup *src-ah + 95 var result/ebx: int <- length src 96 # save result into target-val 97 var type-addr/eax: (addr int) <- get target-val, type 98 copy-to *type-addr, 0 # int - 99 var target-array-ah/eax: (addr handle array value) <- get target-val, array-data + 99 var target-array-ah/eax: (addr handle array value) <- get target-val, array-data 100 clear-object target-array-ah 101 var target/eax: (addr int) <- get target-val, int-data -102 copy-to *target, result +102 copy-to *target, result 103 break $evaluate:process-word 104 } 105 } @@ -169,16 +169,16 @@ if ('onhashchange' in window) { 109 compare is-open?, 0 110 break-if-= 111 # pop target-val from out -112 var out2/esi: (addr value-stack) <- copy out +112 var out2/esi: (addr value-stack) <- copy out 113 var top-addr/ecx: (addr int) <- get out2, top 114 compare *top-addr, 0 115 break-if-<= -116 var data-ah/eax: (addr handle array value) <- get out2, data -117 var data/eax: (addr array value) <- lookup *data-ah +116 var data-ah/eax: (addr handle array value) <- get out2, data +117 var data/eax: (addr array value) <- lookup *data-ah 118 var top/edx: int <- copy *top-addr 119 top <- decrement -120 var dest-offset/edx: (offset value) <- compute-offset data, top -121 var target-val/edx: (addr value) <- index data, dest-offset +120 var dest-offset/edx: (offset value) <- compute-offset data, top +121 var target-val/edx: (addr value) <- index data, dest-offset 122 # check target-val is a string 123 var target-type-addr/eax: (addr int) <- get target-val, type 124 compare *target-type-addr, 1 # string @@ -202,16 +202,16 @@ if ('onhashchange' in window) { 142 compare is-read?, 0 143 break-if-= 144 # pop target-val from out -145 var out2/esi: (addr value-stack) <- copy out +145 var out2/esi: (addr value-stack) <- copy out 146 var top-addr/ecx: (addr int) <- get out2, top 147 compare *top-addr, 0 148 break-if-<= -149 var data-ah/eax: (addr handle array value) <- get out2, data -150 var data/eax: (addr array value) <- lookup *data-ah +149 var data-ah/eax: (addr handle array value) <- get out2, data +150 var data/eax: (addr array value) <- lookup *data-ah 151 var top/edx: int <- copy *top-addr 152 top <- decrement -153 var dest-offset/edx: (offset value) <- compute-offset data, top -154 var target-val/edx: (addr value) <- index data, dest-offset +153 var dest-offset/edx: (offset value) <- compute-offset data, top +154 var target-val/edx: (addr value) <- index data, dest-offset 155 # check target-val is a file 156 var target-type-addr/eax: (addr int) <- get target-val, type 157 compare *target-type-addr, 3 # file @@ -237,16 +237,16 @@ if ('onhashchange' in window) { 177 compare is-slurp?, 0 178 break-if-= 179 # pop target-val from out -180 var out2/esi: (addr value-stack) <- copy out +180 var out2/esi: (addr value-stack) <- copy out 181 var top-addr/ecx: (addr int) <- get out2, top 182 compare *top-addr, 0 183 break-if-<= -184 var data-ah/eax: (addr handle array value) <- get out2, data -185 var data/eax: (addr array value) <- lookup *data-ah +184 var data-ah/eax: (addr handle array value) <- get out2, data +185 var data/eax: (addr array value) <- lookup *data-ah 186 var top/edx: int <- copy *top-addr 187 top <- decrement -188 var dest-offset/edx: (offset value) <- compute-offset data, top -189 var target-val/edx: (addr value) <- index data, dest-offset +188 var dest-offset/edx: (offset value) <- compute-offset data, top +189 var target-val/edx: (addr value) <- index data, dest-offset 190 # check target-val is a file 191 var target-type-addr/eax: (addr int) <- get target-val, type 192 compare *target-type-addr, 3 # file @@ -272,16 +272,16 @@ if ('onhashchange' in window) { 212 compare is-lines?, 0 213 break-if-= 214 # pop target-val from out -215 var out2/esi: (addr value-stack) <- copy out +215 var out2/esi: (addr value-stack) <- copy out 216 var top-addr/ecx: (addr int) <- get out2, top 217 compare *top-addr, 0 218 break-if-<= -219 var data-ah/eax: (addr handle array value) <- get out2, data -220 var data/eax: (addr array value) <- lookup *data-ah +219 var data-ah/eax: (addr handle array value) <- get out2, data +220 var data/eax: (addr array value) <- lookup *data-ah 221 var top/edx: int <- copy *top-addr 222 top <- decrement -223 var dest-offset/edx: (offset value) <- compute-offset data, top -224 var target-val/edx: (addr value) <- index data, dest-offset +223 var dest-offset/edx: (offset value) <- compute-offset data, top +224 var target-val/edx: (addr value) <- index data, dest-offset 225 # check target-val is a file 226 var target-type-addr/eax: (addr int) <- get target-val, type 227 compare *target-type-addr, 3 # file @@ -303,8 +303,8 @@ if ('onhashchange' in window) { 243 var ah/edx: (addr handle array (handle array byte)) <- address h 244 split-string tmp, 0xa, ah 245 } -246 var target/eax: (addr handle array value) <- get target-val, array-data -247 save-lines h, target +246 var target/eax: (addr handle array value) <- get target-val, array-data +247 save-lines h, target 248 # save result into target-val 249 var type-addr/eax: (addr int) <- get target-val, type 250 copy-to *type-addr, 2 # array @@ -321,14 +321,14 @@ if ('onhashchange' in window) { 261 var is-fake-screen?/eax: boolean <- stream-data-equal? curr-stream, "fake-screen" 262 compare is-fake-screen?, 0 263 break-if-= -264 var out2/esi: (addr value-stack) <- copy out +264 var out2/esi: (addr value-stack) <- copy out 265 var top-addr/ecx: (addr int) <- get out2, top 266 compare *top-addr, 0 267 break-if-<= 268 # pop width and height from out -269 var _nrows/eax: int <- pop-int-from-value-stack out2 +269 var _nrows/eax: int <- pop-int-from-value-stack out2 270 var nrows/edx: int <- copy _nrows -271 var _ncols/eax: int <- pop-int-from-value-stack out2 +271 var _ncols/eax: int <- pop-int-from-value-stack out2 272 var ncols/ebx: int <- copy _ncols 273 # define a new screen with those dimensions 274 var screen-h: (handle screen) @@ -337,12 +337,12 @@ if ('onhashchange' in window) { 277 var screen/eax: (addr screen) <- lookup screen-h 278 initialize-screen screen, nrows, ncols 279 # push screen to stack -280 var data-ah/eax: (addr handle array value) <- get out2, data -281 var data/eax: (addr array value) <- lookup *data-ah +280 var data-ah/eax: (addr handle array value) <- get out2, data +281 var data/eax: (addr array value) <- lookup *data-ah 282 var top/edx: int <- copy *top-addr 283 increment *top-addr -284 var dest-offset/edx: (offset value) <- compute-offset data, top -285 var target-val/edx: (addr value) <- index data, dest-offset +284 var dest-offset/edx: (offset value) <- compute-offset data, top +285 var target-val/edx: (addr value) <- index data, dest-offset 286 var type/eax: (addr int) <- get target-val, type 287 copy-to *type, 4 # screen 288 var dest/eax: (addr handle screen) <- get target-val, screen-data @@ -353,7 +353,7 @@ if ('onhashchange' in window) { 293 var is-print?/eax: boolean <- stream-data-equal? curr-stream, "print" 294 compare is-print?, 0 295 break-if-= -296 var out2/esi: (addr value-stack) <- copy out +296 var out2/esi: (addr value-stack) <- copy out 297 var top-addr/ecx: (addr int) <- get out2, top 298 compare *top-addr, 0 299 break-if-<= @@ -362,19 +362,19 @@ if ('onhashchange' in window) { 302 compare *top-addr, 0 303 break-if-<= 304 decrement *top-addr -305 var data-ah/eax: (addr handle array value) <- get out2, data -306 var _data/eax: (addr array value) <- lookup *data-ah -307 var data/edi: (addr array value) <- copy _data +305 var data-ah/eax: (addr handle array value) <- get out2, data +306 var _data/eax: (addr array value) <- lookup *data-ah +307 var data/edi: (addr array value) <- copy _data 308 var top/eax: int <- copy *top-addr -309 var dest-offset/edx: (offset value) <- compute-offset data, top -310 var s/esi: (addr value) <- index data, dest-offset +309 var dest-offset/edx: (offset value) <- compute-offset data, top +310 var s/esi: (addr value) <- index data, dest-offset 311 # select target screen from top of out (but don't pop it) 312 compare *top-addr, 0 313 break-if-<= 314 var top/eax: int <- copy *top-addr 315 top <- decrement -316 var dest-offset/edx: (offset value) <- compute-offset data, top -317 var target-val/edx: (addr value) <- index data, dest-offset +316 var dest-offset/edx: (offset value) <- compute-offset data, top +317 var target-val/edx: (addr value) <- index data, dest-offset 318 var type/eax: (addr int) <- get target-val, type 319 compare *type, 4 # screen 320 break-if-!= @@ -383,30 +383,30 @@ if ('onhashchange' in window) { 323 var dest/eax: (addr screen) <- lookup *dest-ah 324 var r/ecx: (addr int) <- get dest, cursor-row 325 var c/edx: (addr int) <- get dest, cursor-col -326 render-value-at dest, *r, *c, s, 0 +326 render-value-at dest, *r, *c, s, 0 327 break $evaluate:process-word 328 } 329 { 330 var is-move?/eax: boolean <- stream-data-equal? curr-stream, "move" 331 compare is-move?, 0 332 break-if-= -333 var out2/esi: (addr value-stack) <- copy out +333 var out2/esi: (addr value-stack) <- copy out 334 # pop args -335 var _r/eax: int <- pop-int-from-value-stack out2 +335 var _r/eax: int <- pop-int-from-value-stack out2 336 var r/ecx: int <- copy _r -337 var _c/eax: int <- pop-int-from-value-stack out2 +337 var _c/eax: int <- pop-int-from-value-stack out2 338 var c/edx: int <- copy _c 339 # select screen from top of out (but don't pop it) 340 var top-addr/ebx: (addr int) <- get out2, top 341 compare *top-addr, 0 342 break-if-<= -343 var data-ah/eax: (addr handle array value) <- get out2, data -344 var _data/eax: (addr array value) <- lookup *data-ah -345 var data/edi: (addr array value) <- copy _data +343 var data-ah/eax: (addr handle array value) <- get out2, data +344 var _data/eax: (addr array value) <- lookup *data-ah +345 var data/edi: (addr array value) <- copy _data 346 var top/eax: int <- copy *top-addr 347 top <- decrement -348 var target-offset/eax: (offset value) <- compute-offset data, top -349 var target-val/ebx: (addr value) <- index data, target-offset +348 var target-offset/eax: (offset value) <- compute-offset data, top +349 var target-val/ebx: (addr value) <- index data, target-offset 350 var type/eax: (addr int) <- get target-val, type 351 compare *type, 4 # screen 352 break-if-!= @@ -419,23 +419,23 @@ if ('onhashchange' in window) { 359 var is-up?/eax: boolean <- stream-data-equal? curr-stream, "up" 360 compare is-up?, 0 361 break-if-= -362 var out2/esi: (addr value-stack) <- copy out +362 var out2/esi: (addr value-stack) <- copy out 363 var top-addr/ebx: (addr int) <- get out2, top 364 compare *top-addr, 0 365 break-if-<= 366 # pop args -367 var _d/eax: int <- pop-int-from-value-stack out2 +367 var _d/eax: int <- pop-int-from-value-stack out2 368 var d/ecx: int <- copy _d 369 # select screen from top of out (but don't pop it) 370 compare *top-addr, 0 371 break-if-<= -372 var data-ah/eax: (addr handle array value) <- get out2, data -373 var _data/eax: (addr array value) <- lookup *data-ah -374 var data/edi: (addr array value) <- copy _data +372 var data-ah/eax: (addr handle array value) <- get out2, data +373 var _data/eax: (addr array value) <- lookup *data-ah +374 var data/edi: (addr array value) <- copy _data 375 var top/eax: int <- copy *top-addr 376 top <- decrement -377 var target-offset/eax: (offset value) <- compute-offset data, top -378 var target-val/ebx: (addr value) <- index data, target-offset +377 var target-offset/eax: (offset value) <- compute-offset data, top +378 var target-val/ebx: (addr value) <- index data, target-offset 379 var type/eax: (addr int) <- get target-val, type 380 compare *type, 4 # screen 381 break-if-!= @@ -462,23 +462,23 @@ if ('onhashchange' in window) { 402 var is-down?/eax: boolean <- stream-data-equal? curr-stream, "down" 403 compare is-down?, 0 404 break-if-= -405 var out2/esi: (addr value-stack) <- copy out +405 var out2/esi: (addr value-stack) <- copy out 406 var top-addr/ebx: (addr int) <- get out2, top 407 compare *top-addr, 0 408 break-if-<= 409 # pop args -410 var _d/eax: int <- pop-int-from-value-stack out2 +410 var _d/eax: int <- pop-int-from-value-stack out2 411 var d/ecx: int <- copy _d 412 # select screen from top of out (but don't pop it) 413 compare *top-addr, 0 414 break-if-<= -415 var data-ah/eax: (addr handle array value) <- get out2, data -416 var _data/eax: (addr array value) <- lookup *data-ah -417 var data/edi: (addr array value) <- copy _data +415 var data-ah/eax: (addr handle array value) <- get out2, data +416 var _data/eax: (addr array value) <- lookup *data-ah +417 var data/edi: (addr array value) <- copy _data 418 var top/eax: int <- copy *top-addr 419 top <- decrement -420 var target-offset/eax: (offset value) <- compute-offset data, top -421 var target-val/ebx: (addr value) <- index data, target-offset +420 var target-offset/eax: (offset value) <- compute-offset data, top +421 var target-val/ebx: (addr value) <- index data, target-offset 422 var type/eax: (addr int) <- get target-val, type 423 compare *type, 4 # screen 424 break-if-!= @@ -507,23 +507,23 @@ if ('onhashchange' in window) { 447 var is-left?/eax: boolean <- stream-data-equal? curr-stream, "left" 448 compare is-left?, 0 449 break-if-= -450 var out2/esi: (addr value-stack) <- copy out +450 var out2/esi: (addr value-stack) <- copy out 451 var top-addr/ebx: (addr int) <- get out2, top 452 compare *top-addr, 0 453 break-if-<= 454 # pop args -455 var _d/eax: int <- pop-int-from-value-stack out2 +455 var _d/eax: int <- pop-int-from-value-stack out2 456 var d/ecx: int <- copy _d 457 # select screen from top of out (but don't pop it) 458 compare *top-addr, 0 459 break-if-<= -460 var data-ah/eax: (addr handle array value) <- get out2, data -461 var _data/eax: (addr array value) <- lookup *data-ah -462 var data/edi: (addr array value) <- copy _data +460 var data-ah/eax: (addr handle array value) <- get out2, data +461 var _data/eax: (addr array value) <- lookup *data-ah +462 var data/edi: (addr array value) <- copy _data 463 var top/eax: int <- copy *top-addr 464 top <- decrement -465 var target-offset/eax: (offset value) <- compute-offset data, top -466 var target-val/ebx: (addr value) <- index data, target-offset +465 var target-offset/eax: (offset value) <- compute-offset data, top +466 var target-val/ebx: (addr value) <- index data, target-offset 467 var type/eax: (addr int) <- get target-val, type 468 compare *type, 4 # screen 469 break-if-!= @@ -551,23 +551,23 @@ if ('onhashchange' in window) { 491 var is-right?/eax: boolean <- stream-data-equal? curr-stream, "right" 492 compare is-right?, 0 493 break-if-= -494 var out2/esi: (addr value-stack) <- copy out +494 var out2/esi: (addr value-stack) <- copy out 495 var top-addr/ebx: (addr int) <- get out2, top 496 compare *top-addr, 0 497 break-if-<= 498 # pop args -499 var _d/eax: int <- pop-int-from-value-stack out2 +499 var _d/eax: int <- pop-int-from-value-stack out2 500 var d/ecx: int <- copy _d 501 # select screen from top of out (but don't pop it) 502 compare *top-addr, 0 503 break-if-<= -504 var data-ah/eax: (addr handle array value) <- get out2, data -505 var _data/eax: (addr array value) <- lookup *data-ah -506 var data/edi: (addr array value) <- copy _data +504 var data-ah/eax: (addr handle array value) <- get out2, data +505 var _data/eax: (addr array value) <- lookup *data-ah +506 var data/edi: (addr array value) <- copy _data 507 var top/eax: int <- copy *top-addr 508 top <- decrement -509 var target-offset/eax: (offset value) <- compute-offset data, top -510 var target-val/ebx: (addr value) <- index data, target-offset +509 var target-offset/eax: (offset value) <- compute-offset data, top +510 var target-val/ebx: (addr value) <- index data, target-offset 511 var type/eax: (addr int) <- get target-val, type 512 compare *type, 4 # screen 513 break-if-!= @@ -598,20 +598,20 @@ if ('onhashchange' in window) { 538 compare is-dup?, 0 539 break-if-= 540 # read src-val from out -541 var out2/esi: (addr value-stack) <- copy out +541 var out2/esi: (addr value-stack) <- copy out 542 var top-addr/ecx: (addr int) <- get out2, top 543 compare *top-addr, 0 544 break-if-<= -545 var data-ah/eax: (addr handle array value) <- get out2, data -546 var data/eax: (addr array value) <- lookup *data-ah +545 var data-ah/eax: (addr handle array value) <- get out2, data +546 var data/eax: (addr array value) <- lookup *data-ah 547 var top/ecx: int <- copy *top-addr 548 top <- decrement -549 var offset/edx: (offset value) <- compute-offset data, top -550 var src-val/edx: (addr value) <- index data, offset +549 var offset/edx: (offset value) <- compute-offset data, top +550 var src-val/edx: (addr value) <- index data, offset 551 # push a copy of it 552 top <- increment -553 var offset/ebx: (offset value) <- compute-offset data, top -554 var target-val/ebx: (addr value) <- index data, offset +553 var offset/ebx: (offset value) <- compute-offset data, top +554 var target-val/ebx: (addr value) <- index data, offset 555 copy-object src-val, target-val 556 # commit 557 var top-addr/ecx: (addr int) <- get out2, top @@ -623,23 +623,23 @@ if ('onhashchange' in window) { 563 compare is-swap?, 0 564 break-if-= 565 # read top-val from out -566 var out2/esi: (addr value-stack) <- copy out +566 var out2/esi: (addr value-stack) <- copy out 567 var top-addr/ecx: (addr int) <- get out2, top 568 compare *top-addr, 0 569 break-if-<= -570 var data-ah/eax: (addr handle array value) <- get out2, data -571 var data/eax: (addr array value) <- lookup *data-ah +570 var data-ah/eax: (addr handle array value) <- get out2, data +571 var data/eax: (addr array value) <- lookup *data-ah 572 var top/ecx: int <- copy *top-addr 573 top <- decrement -574 var offset/edx: (offset value) <- compute-offset data, top -575 var top-val/edx: (addr value) <- index data, offset +574 var offset/edx: (offset value) <- compute-offset data, top +575 var top-val/edx: (addr value) <- index data, offset 576 # read next val from out 577 top <- decrement -578 var offset/ebx: (offset value) <- compute-offset data, top -579 var pen-top-val/ebx: (addr value) <- index data, offset +578 var offset/ebx: (offset value) <- compute-offset data, top +579 var pen-top-val/ebx: (addr value) <- index data, offset 580 # swap -581 var tmp: value -582 var tmp-a/eax: (addr value) <- address tmp +581 var tmp: value +582 var tmp-a/eax: (addr value) <- address tmp 583 copy-object top-val, tmp-a 584 copy-object pen-top-val, top-val 585 copy-object tmp-a, pen-top-val @@ -654,33 +654,33 @@ if ('onhashchange' in window) { 594 compare new-byte, 0x3d # '=' 595 break-if-!= 596 # pop target-val from out -597 var out2/esi: (addr value-stack) <- copy out +597 var out2/esi: (addr value-stack) <- copy out 598 var top-addr/ecx: (addr int) <- get out2, top 599 compare *top-addr, 0 600 break-if-<= -601 var data-ah/eax: (addr handle array value) <- get out2, data -602 var data/eax: (addr array value) <- lookup *data-ah +601 var data-ah/eax: (addr handle array value) <- get out2, data +602 var data/eax: (addr array value) <- lookup *data-ah 603 var top/edx: int <- copy *top-addr 604 top <- decrement -605 var dest-offset/edx: (offset value) <- compute-offset data, top -606 var target-val/edx: (addr value) <- index data, dest-offset +605 var dest-offset/edx: (offset value) <- compute-offset data, top +606 var target-val/edx: (addr value) <- index data, dest-offset 607 # create binding from curr-stream to target-val 608 var key-h: (handle array byte) 609 var key/ecx: (addr handle array byte) <- address key-h 610 stream-to-array curr-stream, key -611 bind-in-table bindings, key, target-val +611 bind-in-table bindings, key, target-val 612 break $evaluate:process-word 613 } 614 rewind-stream curr-stream 615 ### if curr-stream is a known function name, call it appropriately 616 { -617 var callee-h: (handle function) -618 var callee-ah/eax: (addr handle function) <- address callee-h +617 var callee-h: (handle function) +618 var callee-ah/eax: (addr handle function) <- address callee-h 619 find-function functions, curr-stream, callee-ah -620 var callee/eax: (addr function) <- lookup *callee-ah -621 compare callee, 0 +620 var callee/eax: (addr function) <- lookup *callee-ah +621 compare callee, 0 622 break-if-= -623 perform-call callee, out, functions +623 perform-call callee, out, functions 624 break $evaluate:process-word 625 } 626 ### if it's a name, push its value @@ -691,13 +691,13 @@ if ('onhashchange' in window) { 631 var curr-string-ah/edx: (addr handle array byte) <- address tmp 632 stream-to-array curr-stream, curr-string-ah # unfortunate leak 633 var curr-string/eax: (addr array byte) <- lookup *curr-string-ah -634 var val-storage: (handle value) -635 var val-ah/edi: (addr handle value) <- address val-storage -636 lookup-binding bindings, curr-string, val-ah -637 var val/eax: (addr value) <- lookup *val-ah +634 var val-storage: (handle value) +635 var val-ah/edi: (addr handle value) <- address val-storage +636 lookup-binding bindings, curr-string, val-ah +637 var val/eax: (addr value) <- lookup *val-ah 638 compare val, 0 639 break-if-= -640 push-value-stack out, val +640 push-value-stack out, val 641 break $evaluate:process-word 642 } 643 ### if the word starts with a quote and ends with a quote, turn it into a string @@ -711,7 +711,7 @@ if ('onhashchange' in window) { 651 var h: (handle array byte) 652 var s/eax: (addr handle array byte) <- address h 653 unquote-stream-to-array curr-stream, s # leak -654 push-string-to-value-stack out, *s +654 push-string-to-value-stack out, *s 655 break $evaluate:process-word 656 } 657 ### if the word starts with a '[' and ends with a ']', turn it into an array @@ -723,7 +723,7 @@ if ('onhashchange' in window) { 663 compare end, 0x5d # ']' 664 break-if-!= 665 # wastefully create a new input string to strip quotes -666 var h: (handle array value) +666 var h: (handle array value) 667 var input-ah/eax: (addr handle array byte) <- address h 668 unquote-stream-to-array curr-stream, input-ah # leak 669 # wastefully parse input into int-array @@ -736,21 +736,21 @@ if ('onhashchange' in window) { 676 var int-array/esi: (addr array int) <- copy _int-array 677 var len/ebx: int <- length int-array 678 # push value-array of same size as int-array -679 var h3: (handle array value) -680 var value-array-ah/eax: (addr handle array value) <- address h3 +679 var h3: (handle array value) +680 var value-array-ah/eax: (addr handle array value) <- address h3 681 populate value-array-ah, len -682 push-array-to-value-stack out, *value-array-ah +682 push-array-to-value-stack out, *value-array-ah 683 # copy int-array into value-array -684 var _value-array/eax: (addr array value) <- lookup *value-array-ah -685 var value-array/edi: (addr array value) <- copy _value-array +684 var _value-array/eax: (addr array value) <- lookup *value-array-ah +685 var value-array/edi: (addr array value) <- copy _value-array 686 var i/eax: int <- copy 0 687 { 688 compare i, len 689 break-if->= 690 var src-addr/ecx: (addr int) <- index int-array, i 691 var src/ecx: int <- copy *src-addr -692 var dest-offset/edx: (offset value) <- compute-offset value-array, i -693 var dest-val/edx: (addr value) <- index value-array, dest-offset +692 var dest-offset/edx: (offset value) <- compute-offset value-array, i +693 var dest-val/edx: (addr value) <- index value-array, dest-offset 694 var dest/edx: (addr int) <- get dest-val, int-data 695 copy-to *dest, src 696 i <- increment @@ -761,56 +761,56 @@ if ('onhashchange' in window) { 701 ### otherwise assume it's a literal number and push it 702 { 703 var n/eax: int <- parse-decimal-int-from-stream curr-stream -704 push-int-to-value-stack out, n +704 push-int-to-value-stack out, n 705 } 706 } 707 # termination check 708 compare curr, end 709 break-if-= 710 # update -711 var next-word-ah/edx: (addr handle word) <- get curr, next +711 var next-word-ah/edx: (addr handle word) <- get curr, next 712 curr <- lookup *next-word-ah 713 # 714 loop 715 } 716 # process next line if necessary -717 var line/eax: (addr line) <- copy scratch -718 var next-line-ah/eax: (addr handle line) <- get line, next -719 var next-line/eax: (addr line) <- lookup *next-line-ah +717 var line/eax: (addr line) <- copy scratch +718 var next-line-ah/eax: (addr handle line) <- get line, next +719 var next-line/eax: (addr line) <- lookup *next-line-ah 720 compare next-line, 0 721 break-if-= 722 evaluate functions, bindings, next-line, end, out 723 } 724 725 fn test-evaluate { -726 var line-storage: line -727 var line/esi: (addr line) <- address line-storage -728 var first-word-ah/eax: (addr handle word) <- get line-storage, data -729 allocate-word-with first-word-ah, "3" -730 append-word-with *first-word-ah, "=a" -731 var next-line-ah/eax: (addr handle line) <- get line-storage, next +726 var line-storage: line +727 var line/esi: (addr line) <- address line-storage +728 var first-word-ah/eax: (addr handle word) <- get line-storage, data +729 allocate-word-with first-word-ah, "3" +730 append-word-with *first-word-ah, "=a" +731 var next-line-ah/eax: (addr handle line) <- get line-storage, next 732 allocate next-line-ah -733 var next-line/eax: (addr line) <- lookup *next-line-ah -734 var first-word-ah/eax: (addr handle word) <- get next-line, data -735 allocate-word-with first-word-ah, "a" -736 var functions-storage: (handle function) -737 var functions/ecx: (addr handle function) <- address functions-storage -738 var table-storage: table -739 var table/ebx: (addr table) <- address table-storage -740 initialize-table table, 0x10 -741 var stack-storage: value-stack -742 var stack/edi: (addr value-stack) <- address stack-storage -743 initialize-value-stack stack, 0x10 -744 evaluate functions, table, line, 0, stack -745 var x/eax: int <- pop-int-from-value-stack stack +733 var next-line/eax: (addr line) <- lookup *next-line-ah +734 var first-word-ah/eax: (addr handle word) <- get next-line, data +735 allocate-word-with first-word-ah, "a" +736 var functions-storage: (handle function) +737 var functions/ecx: (addr handle function) <- address functions-storage +738 var table-storage: table +739 var table/ebx: (addr table) <- address table-storage +740 initialize-table table, 0x10 +741 var stack-storage: value-stack +742 var stack/edi: (addr value-stack) <- address stack-storage +743 initialize-value-stack stack, 0x10 +744 evaluate functions, table, line, 0, stack +745 var x/eax: int <- pop-int-from-value-stack stack 746 check-ints-equal x, 3, "F - test-evaluate" 747 } 748 -749 fn find-function first: (addr handle function), name: (addr stream byte), out: (addr handle function) { -750 var curr/esi: (addr handle function) <- copy first +749 fn find-function first: (addr handle function), name: (addr stream byte), out: (addr handle function) { +750 var curr/esi: (addr handle function) <- copy first 751 $find-function:loop: { -752 var _f/eax: (addr function) <- lookup *curr -753 var f/ecx: (addr function) <- copy _f +752 var _f/eax: (addr function) <- lookup *curr +753 var f/ecx: (addr function) <- copy _f 754 compare f, 0 755 break-if-= 756 var curr-name-ah/eax: (addr handle array byte) <- get f, name @@ -827,43 +827,43 @@ if ('onhashchange' in window) { 767 } 768 } 769 -770 fn perform-call _callee: (addr function), caller-stack: (addr value-stack), functions: (addr handle function) { -771 var callee/ecx: (addr function) <- copy _callee +770 fn perform-call _callee: (addr function), caller-stack: (addr value-stack), functions: (addr handle function) { +771 var callee/ecx: (addr function) <- copy _callee 772 # create bindings for args -773 var table-storage: table -774 var table/esi: (addr table) <- address table-storage -775 initialize-table table, 0x10 -776 bind-args callee, caller-stack, table +773 var table-storage: table +774 var table/esi: (addr table) <- address table-storage +775 initialize-table table, 0x10 +776 bind-args callee, caller-stack, table 777 # obtain body -778 var body-ah/eax: (addr handle line) <- get callee, body -779 var body/eax: (addr line) <- lookup *body-ah +778 var body-ah/eax: (addr handle line) <- get callee, body +779 var body/eax: (addr line) <- lookup *body-ah 780 # perform call -781 var stack-storage: value-stack -782 var stack/edi: (addr value-stack) <- address stack-storage -783 initialize-value-stack stack, 0x10 +781 var stack-storage: value-stack +782 var stack/edi: (addr value-stack) <- address stack-storage +783 initialize-value-stack stack, 0x10 784 #? print-string-to-real-screen "about to enter recursive eval\n" -785 evaluate functions, table, body, 0, stack +785 evaluate functions, table, body, 0, stack 786 #? print-string-to-real-screen "exited recursive eval\n" 787 # pop target-val from out 788 var top-addr/ecx: (addr int) <- get stack, top 789 compare *top-addr, 0 790 break-if-<= -791 var data-ah/eax: (addr handle array value) <- get stack, data -792 var data/eax: (addr array value) <- lookup *data-ah +791 var data-ah/eax: (addr handle array value) <- get stack, data +792 var data/eax: (addr array value) <- lookup *data-ah 793 var top/edx: int <- copy *top-addr 794 top <- decrement -795 var dest-offset/edx: (offset value) <- compute-offset data, top -796 var target-val/edx: (addr value) <- index data, dest-offset +795 var dest-offset/edx: (offset value) <- compute-offset data, top +796 var target-val/edx: (addr value) <- index data, dest-offset 797 # stitch target-val into caller-stack -798 push-value-stack caller-stack, target-val +798 push-value-stack caller-stack, target-val 799 } 800 801 # pop args from the caller-stack and bind them to successive args 802 # implies: function args are stored in reverse order -803 fn bind-args _callee: (addr function), _caller-stack: (addr value-stack), table: (addr table) { -804 var callee/ecx: (addr function) <- copy _callee -805 var curr-arg-ah/eax: (addr handle word) <- get callee, args -806 var curr-arg/eax: (addr word) <- lookup *curr-arg-ah +803 fn bind-args _callee: (addr function), _caller-stack: (addr value-stack), table: (addr table) { +804 var callee/ecx: (addr function) <- copy _callee +805 var curr-arg-ah/eax: (addr handle word) <- get callee, args +806 var curr-arg/eax: (addr word) <- lookup *curr-arg-ah 807 # 808 var curr-key-storage: (handle array byte) 809 var curr-key/edx: (addr handle array byte) <- address curr-key-storage @@ -871,24 +871,24 @@ if ('onhashchange' in window) { 811 compare curr-arg, 0 812 break-if-= 813 # create binding -814 word-to-string curr-arg, curr-key +814 word-to-string curr-arg, curr-key 815 { 816 # pop target-val from caller-stack -817 var caller-stack/esi: (addr value-stack) <- copy _caller-stack +817 var caller-stack/esi: (addr value-stack) <- copy _caller-stack 818 var top-addr/ecx: (addr int) <- get caller-stack, top 819 compare *top-addr, 0 820 break-if-<= 821 decrement *top-addr -822 var data-ah/eax: (addr handle array value) <- get caller-stack, data -823 var data/eax: (addr array value) <- lookup *data-ah +822 var data-ah/eax: (addr handle array value) <- get caller-stack, data +823 var data/eax: (addr array value) <- lookup *data-ah 824 var top/ebx: int <- copy *top-addr -825 var dest-offset/ebx: (offset value) <- compute-offset data, top -826 var target-val/ebx: (addr value) <- index data, dest-offset +825 var dest-offset/ebx: (offset value) <- compute-offset data, top +826 var target-val/ebx: (addr value) <- index data, dest-offset 827 # create binding from curr-key to target-val -828 bind-in-table table, curr-key, target-val +828 bind-in-table table, curr-key, target-val 829 } 830 # -831 var next-arg-ah/edx: (addr handle word) <- get curr-arg, next +831 var next-arg-ah/edx: (addr handle word) <- get curr-arg, next 832 curr-arg <- lookup *next-arg-ah 833 loop 834 } @@ -896,29 +896,29 @@ if ('onhashchange' in window) { 836 837 # Copy of 'simplify' that just tracks the maximum stack depth needed 838 # Doesn't actually need to simulate the stack, since every word has a predictable effect. -839 fn max-stack-depth first-word: (addr word), final-word: (addr word) -> _/edi: int { -840 var curr-word/eax: (addr word) <- copy first-word +839 fn max-stack-depth first-word: (addr word), final-word: (addr word) -> _/edi: int { +840 var curr-word/eax: (addr word) <- copy first-word 841 var curr-depth/ecx: int <- copy 0 -842 var result/edi: int <- copy 0 +842 var result/edi: int <- copy 0 843 $max-stack-depth:loop: { 844 $max-stack-depth:process-word: { 845 # handle operators 846 { -847 var is-add?/eax: boolean <- word-equal? curr-word, "+" +847 var is-add?/eax: boolean <- word-equal? curr-word, "+" 848 compare is-add?, 0 849 break-if-= 850 curr-depth <- decrement 851 break $max-stack-depth:process-word 852 } 853 { -854 var is-sub?/eax: boolean <- word-equal? curr-word, "-" +854 var is-sub?/eax: boolean <- word-equal? curr-word, "-" 855 compare is-sub?, 0 856 break-if-= 857 curr-depth <- decrement 858 break $max-stack-depth:process-word 859 } 860 { -861 var is-mul?/eax: boolean <- word-equal? curr-word, "*" +861 var is-mul?/eax: boolean <- word-equal? curr-word, "*" 862 compare is-mul?, 0 863 break-if-= 864 curr-depth <- decrement @@ -928,21 +928,21 @@ if ('onhashchange' in window) { 868 curr-depth <- increment 869 # update max depth if necessary 870 { -871 compare curr-depth, result +871 compare curr-depth, result 872 break-if-<= -873 result <- copy curr-depth +873 result <- copy curr-depth 874 } 875 } 876 # if curr-word == final-word break -877 compare curr-word, final-word +877 compare curr-word, final-word 878 break-if-= 879 # curr-word = curr-word->next -880 var next-word-ah/edx: (addr handle word) <- get curr-word, next +880 var next-word-ah/edx: (addr handle word) <- get curr-word, next 881 curr-word <- lookup *next-word-ah 882 # 883 loop 884 } -885 return result +885 return result 886 }https://github.com/akkartik/mu/blob/master/apps/tile/table.mu
- 1 fn initialize-table _self: (addr table), n: int { - 2 var self/esi: (addr table) <- copy _self - 3 var data-ah/eax: (addr handle array bind) <- get self, data + 1 fn initialize-table _self: (addr table), n: int { + 2 var self/esi: (addr table) <- copy _self + 3 var data-ah/eax: (addr handle array bind) <- get self, data 4 populate data-ah, n 5 } 6 - 7 fn deep-copy-table _src: (addr table), _dest: (addr table) { + 7 fn deep-copy-table _src: (addr table), _dest: (addr table) { 8 #? print-string 0, "deep-copy-table\n" - 9 var src/eax: (addr table) <- copy _src - 10 var src-data-ah/eax: (addr handle array bind) <- get src, data - 11 var _src-data/eax: (addr array bind) <- lookup *src-data-ah - 12 var src-data/esi: (addr array bind) <- copy _src-data + 9 var src/eax: (addr table) <- copy _src + 10 var src-data-ah/eax: (addr handle array bind) <- get src, data + 11 var _src-data/eax: (addr array bind) <- lookup *src-data-ah + 12 var src-data/esi: (addr array bind) <- copy _src-data 13 var n/ecx: int <- length src-data - 14 var dest/eax: (addr table) <- copy _dest + 14 var dest/eax: (addr table) <- copy _dest 15 initialize-table dest, n - 16 var dest-data-ah/eax: (addr handle array bind) <- get dest, data - 17 var _dest-data/eax: (addr array bind) <- lookup *dest-data-ah - 18 var dest-data/edi: (addr array bind) <- copy _dest-data + 16 var dest-data-ah/eax: (addr handle array bind) <- get dest, data + 17 var _dest-data/eax: (addr array bind) <- lookup *dest-data-ah + 18 var dest-data/edi: (addr array bind) <- copy _dest-data 19 var i/eax: int <- copy 0 20 { 21 compare i, n 22 break-if->= 23 #? print-string 0, "iter\n" 24 $deep-copy:element: { - 25 var offset/edx: (offset bind) <- compute-offset src-data, i - 26 var src-bind/ecx: (addr bind) <- index src-data, offset - 27 var dest-bind/edx: (addr bind) <- index dest-data, offset + 25 var offset/edx: (offset bind) <- compute-offset src-data, i + 26 var src-bind/ecx: (addr bind) <- index src-data, offset + 27 var dest-bind/edx: (addr bind) <- index dest-data, offset 28 var src-key-ah/ebx: (addr handle array byte) <- get src-bind, key 29 var src-key/eax: (addr array byte) <- lookup *src-key-ah 30 compare src-key, 0 @@ -92,14 +92,14 @@ if ('onhashchange' in window) { 33 var dest-key-ah/eax: (addr handle array byte) <- get dest-bind, key 34 copy-object src-key-ah, dest-key-ah 35 # deep copy value - 36 var src-val-ah/eax: (addr handle value) <- get src-bind, value - 37 var _src-val/eax: (addr value) <- lookup *src-val-ah - 38 var src-val/ecx: (addr value) <- copy _src-val - 39 var dest-val-ah/eax: (addr handle value) <- get dest-bind, value + 36 var src-val-ah/eax: (addr handle value) <- get src-bind, value + 37 var _src-val/eax: (addr value) <- lookup *src-val-ah + 38 var src-val/ecx: (addr value) <- copy _src-val + 39 var dest-val-ah/eax: (addr handle value) <- get dest-bind, value 40 allocate dest-val-ah - 41 var dest-val/eax: (addr value) <- lookup *dest-val-ah + 41 var dest-val/eax: (addr value) <- lookup *dest-val-ah 42 #? print-string 0, "deep copy value {\n" - 43 deep-copy-value src-val, dest-val + 43 deep-copy-value src-val, dest-val 44 #? print-string 0, "}\n" 45 } 46 i <- increment @@ -108,28 +108,28 @@ if ('onhashchange' in window) { 49 #? print-string 0, "end deep-copy-table\n" 50 } 51 - 52 fn bind-in-table _self: (addr table), key: (addr handle array byte), val: (addr value) { - 53 var self/esi: (addr table) <- copy _self - 54 var data-ah/esi: (addr handle array bind) <- get self, data - 55 var _data/eax: (addr array bind) <- lookup *data-ah - 56 var data/esi: (addr array bind) <- copy _data - 57 var next-empty-slot-index/eax: (offset bind) <- next-empty-slot data, key - 58 var dest/eax: (addr bind) <- index data, next-empty-slot-index + 52 fn bind-in-table _self: (addr table), key: (addr handle array byte), val: (addr value) { + 53 var self/esi: (addr table) <- copy _self + 54 var data-ah/esi: (addr handle array bind) <- get self, data + 55 var _data/eax: (addr array bind) <- lookup *data-ah + 56 var data/esi: (addr array bind) <- copy _data + 57 var next-empty-slot-index/eax: (offset bind) <- next-empty-slot data, key + 58 var dest/eax: (addr bind) <- index data, next-empty-slot-index 59 make-binding dest, key, val 60 } 61 62 # manual test: full array of binds - 63 fn next-empty-slot _data: (addr array bind), key: (addr handle array byte) -> _/eax: (offset bind) { - 64 var data/esi: (addr array bind) <- copy _data + 63 fn next-empty-slot _data: (addr array bind), key: (addr handle array byte) -> _/eax: (offset bind) { + 64 var data/esi: (addr array bind) <- copy _data 65 var len/ecx: int <- length data 66 var i/edx: int <- copy 0 - 67 var result/eax: (offset bind) <- copy 0 + 67 var result/eax: (offset bind) <- copy 0 68 $next-empty-slot:loop: { - 69 result <- compute-offset data, i + 69 result <- compute-offset data, i 70 compare i, len 71 break-if->= 72 { - 73 var target/esi: (addr bind) <- index data, result + 73 var target/esi: (addr bind) <- index data, result 74 var target2/esi: (addr handle array byte) <- get target, key 75 var target3/eax: (addr array byte) <- lookup *target2 76 compare target3, 0 @@ -139,44 +139,44 @@ if ('onhashchange' in window) { 80 i <- increment 81 loop 82 } - 83 return result + 83 return result 84 } 85 - 86 fn make-int-binding _self: (addr bind), key: (addr handle array byte), _val: int { - 87 var self/esi: (addr bind) <- copy _self + 86 fn make-int-binding _self: (addr bind), key: (addr handle array byte), _val: int { + 87 var self/esi: (addr bind) <- copy _self 88 var dest/eax: (addr handle array byte) <- get self, key 89 copy-object key, dest - 90 var dest2/eax: (addr handle value) <- get self, value + 90 var dest2/eax: (addr handle value) <- get self, value 91 allocate dest2 - 92 var dest3/eax: (addr value) <- lookup *dest2 + 92 var dest3/eax: (addr value) <- lookup *dest2 93 var dest4/eax: (addr int) <- get dest3, int-data 94 var val/ecx: int <- copy _val 95 copy-to *dest4, val 96 } 97 - 98 fn make-binding _self: (addr bind), key: (addr handle array byte), val: (addr value) { - 99 var self/esi: (addr bind) <- copy _self + 98 fn make-binding _self: (addr bind), key: (addr handle array byte), val: (addr value) { + 99 var self/esi: (addr bind) <- copy _self 100 var dest/eax: (addr handle array byte) <- get self, key 101 copy-object key, dest -102 var dest2/eax: (addr handle value) <- get self, value +102 var dest2/eax: (addr handle value) <- get self, value 103 allocate dest2 -104 var dest3/eax: (addr value) <- lookup *dest2 +104 var dest3/eax: (addr value) <- lookup *dest2 105 copy-object val, dest3 106 } 107 -108 fn lookup-binding _self: (addr table), key: (addr array byte), out: (addr handle value) { -109 var self/esi: (addr table) <- copy _self -110 var data-ah/esi: (addr handle array bind) <- get self, data -111 var _data/eax: (addr array bind) <- lookup *data-ah -112 var data/esi: (addr array bind) <- copy _data +108 fn lookup-binding _self: (addr table), key: (addr array byte), out: (addr handle value) { +109 var self/esi: (addr table) <- copy _self +110 var data-ah/esi: (addr handle array bind) <- get self, data +111 var _data/eax: (addr array bind) <- lookup *data-ah +112 var data/esi: (addr array bind) <- copy _data 113 var len/edx: int <- length data 114 var i/ebx: int <- copy 0 115 $lookup-binding:loop: { 116 compare i, len 117 break-if->= 118 { -119 var offset/edx: (offset bind) <- compute-offset data, i -120 var target-bind/esi: (addr bind) <- index data, offset +119 var offset/edx: (offset bind) <- compute-offset data, i +120 var target-bind/esi: (addr bind) <- index data, offset 121 var target2/edx: (addr handle array byte) <- get target-bind, key 122 var target3/eax: (addr array byte) <- lookup *target2 123 compare target3, 0 @@ -185,7 +185,7 @@ if ('onhashchange' in window) { 126 compare is-match?, 0 # false 127 break-if-= 128 # found -129 var target/eax: (addr handle value) <- get target-bind, value +129 var target/eax: (addr handle value) <- get target-bind, value 130 copy-object target, out 131 break $lookup-binding:loop 132 } @@ -194,26 +194,26 @@ if ('onhashchange' in window) { 135 } 136 } 137 -138 fn dump-table _self: (addr table) { -139 var self/esi: (addr table) <- copy _self -140 var data-ah/esi: (addr handle array bind) <- get self, data -141 var _data/eax: (addr array bind) <- lookup *data-ah -142 var data/esi: (addr array bind) <- copy _data +138 fn dump-table _self: (addr table) { +139 var self/esi: (addr table) <- copy _self +140 var data-ah/esi: (addr handle array bind) <- get self, data +141 var _data/eax: (addr array bind) <- lookup *data-ah +142 var data/esi: (addr array bind) <- copy _data 143 var len/edx: int <- length data 144 var i/ebx: int <- copy 0 145 { 146 compare i, len 147 break-if->= -148 var offset/edx: (offset bind) <- compute-offset data, i -149 var target-bind/esi: (addr bind) <- index data, offset +148 var offset/edx: (offset bind) <- compute-offset data, i +149 var target-bind/esi: (addr bind) <- index data, offset 150 var key-ah/edx: (addr handle array byte) <- get target-bind, key 151 var key/eax: (addr array byte) <- lookup *key-ah 152 compare key, 0 153 break-if-= 154 print-string 0, key 155 print-string 0, ": " -156 var val-ah/eax: (addr handle value) <- get target-bind, value -157 var val/eax: (addr value) <- lookup *val-ah +156 var val-ah/eax: (addr handle value) <- get target-bind, value +157 var val/eax: (addr value) <- lookup *val-ah 158 var type/eax: (addr int) <- get val, type 159 print-int32-hex 0, *type 160 print-string 0, "\n" diff --git a/html/apps/tile/value-stack.mu.html b/html/apps/tile/value-stack.mu.html index 532df190..e8c15026 100644 --- a/html/apps/tile/value-stack.mu.html +++ b/html/apps/tile/value-stack.mu.html @@ -60,13 +60,13 @@ if ('onhashchange' in window) { 1 # support for non-int values is untested 2 3 type value-stack { - 4 data: (handle array value) + 4 data: (handle array value) 5 top: int 6 } 7 8 fn initialize-value-stack _self: (addr value-stack), n: int { 9 var self/esi: (addr value-stack) <- copy _self - 10 var d/edi: (addr handle array value) <- get self, data + 10 var d/edi: (addr handle array value) <- get self, data 11 populate d, n 12 var top/eax: (addr int) <- get self, top 13 copy-to *top, 0 @@ -81,11 +81,11 @@ if ('onhashchange' in window) { 22 fn push-int-to-value-stack _self: (addr value-stack), _val: int { 23 var self/esi: (addr value-stack) <- copy _self 24 var top-addr/ecx: (addr int) <- get self, top - 25 var data-ah/edx: (addr handle array value) <- get self, data - 26 var data/eax: (addr array value) <- lookup *data-ah + 25 var data-ah/edx: (addr handle array value) <- get self, data + 26 var data/eax: (addr array value) <- lookup *data-ah 27 var top/edx: int <- copy *top-addr - 28 var dest-offset/edx: (offset value) <- compute-offset data, top - 29 var dest-addr/edx: (addr value) <- index data, dest-offset + 28 var dest-offset/edx: (offset value) <- compute-offset data, top + 29 var dest-addr/edx: (addr value) <- index data, dest-offset 30 var dest-addr2/eax: (addr int) <- get dest-addr, int-data 31 var val/esi: int <- copy _val 32 #? print-int32-hex-to-real-screen val @@ -98,11 +98,11 @@ if ('onhashchange' in window) { 39 fn push-string-to-value-stack _self: (addr value-stack), val: (handle array byte) { 40 var self/esi: (addr value-stack) <- copy _self 41 var top-addr/ecx: (addr int) <- get self, top - 42 var data-ah/edx: (addr handle array value) <- get self, data - 43 var data/eax: (addr array value) <- lookup *data-ah + 42 var data-ah/edx: (addr handle array value) <- get self, data + 43 var data/eax: (addr array value) <- lookup *data-ah 44 var top/edx: int <- copy *top-addr - 45 var dest-offset/edx: (offset value) <- compute-offset data, top - 46 var dest-addr/edx: (addr value) <- index data, dest-offset + 45 var dest-offset/edx: (offset value) <- compute-offset data, top + 46 var dest-addr/edx: (addr value) <- index data, dest-offset 47 var dest-addr2/eax: (addr handle array byte) <- get dest-addr, text-data 48 copy-handle val, dest-addr2 49 var dest-addr3/eax: (addr int) <- get dest-addr, type @@ -116,15 +116,15 @@ if ('onhashchange' in window) { 57 increment *top-addr 58 } 59 - 60 fn push-array-to-value-stack _self: (addr value-stack), val: (handle array value) { + 60 fn push-array-to-value-stack _self: (addr value-stack), val: (handle array value) { 61 var self/esi: (addr value-stack) <- copy _self 62 var top-addr/ecx: (addr int) <- get self, top - 63 var data-ah/edx: (addr handle array value) <- get self, data - 64 var data/eax: (addr array value) <- lookup *data-ah + 63 var data-ah/edx: (addr handle array value) <- get self, data + 64 var data/eax: (addr array value) <- lookup *data-ah 65 var top/edx: int <- copy *top-addr - 66 var dest-offset/edx: (offset value) <- compute-offset data, top - 67 var dest-addr/edx: (addr value) <- index data, dest-offset - 68 var dest-addr2/eax: (addr handle array value) <- get dest-addr, array-data + 66 var dest-offset/edx: (offset value) <- compute-offset data, top + 67 var dest-addr/edx: (addr value) <- index data, dest-offset + 68 var dest-addr2/eax: (addr handle array value) <- get dest-addr, array-data 69 copy-handle val, dest-addr2 70 # update type 71 var dest-addr3/eax: (addr int) <- get dest-addr, type @@ -132,14 +132,14 @@ if ('onhashchange' in window) { 73 increment *top-addr 74 } 75 - 76 fn push-value-stack _self: (addr value-stack), val: (addr value) { + 76 fn push-value-stack _self: (addr value-stack), val: (addr value) { 77 var self/esi: (addr value-stack) <- copy _self 78 var top-addr/ecx: (addr int) <- get self, top - 79 var data-ah/edx: (addr handle array value) <- get self, data - 80 var data/eax: (addr array value) <- lookup *data-ah + 79 var data-ah/edx: (addr handle array value) <- get self, data + 80 var data/eax: (addr array value) <- lookup *data-ah 81 var top/edx: int <- copy *top-addr - 82 var dest-offset/edx: (offset value) <- compute-offset data, top - 83 var dest-addr/edx: (addr value) <- index data, dest-offset + 82 var dest-offset/edx: (offset value) <- compute-offset data, top + 83 var dest-addr/edx: (addr value) <- index data, dest-offset 84 copy-object val, dest-addr 85 increment *top-addr 86 } @@ -153,11 +153,11 @@ if ('onhashchange' in window) { 94 return -1 95 } 96 decrement *top-addr - 97 var data-ah/edx: (addr handle array value) <- get self, data - 98 var data/eax: (addr array value) <- lookup *data-ah + 97 var data-ah/edx: (addr handle array value) <- get self, data + 98 var data/eax: (addr array value) <- lookup *data-ah 99 var top/edx: int <- copy *top-addr -100 var dest-offset/edx: (offset value) <- compute-offset data, top -101 var result-addr/eax: (addr value) <- index data, dest-offset +100 var dest-offset/edx: (offset value) <- compute-offset data, top +101 var result-addr/eax: (addr value) <- index data, dest-offset 102 var result-addr2/eax: (addr int) <- get result-addr, int-data 103 return *result-addr2 104 } @@ -181,37 +181,37 @@ if ('onhashchange' in window) { 122 123 fn value-stack-max-width _self: (addr value-stack) -> _/eax: int { 124 var self/esi: (addr value-stack) <- copy _self -125 var data-ah/edi: (addr handle array value) <- get self, data -126 var _data/eax: (addr array value) <- lookup *data-ah -127 var data/edi: (addr array value) <- copy _data +125 var data-ah/edi: (addr handle array value) <- get self, data +126 var _data/eax: (addr array value) <- lookup *data-ah +127 var data/edi: (addr array value) <- copy _data 128 var top-addr/ecx: (addr int) <- get self, top 129 var i/ebx: int <- copy 0 -130 var result: int +130 var result: int 131 { 132 compare i, *top-addr 133 break-if->= -134 var o/edx: (offset value) <- compute-offset data, i -135 var v/edx: (addr value) <- index data, o -136 var w/eax: int <- value-width v, 1 # top-level=true +134 var o/edx: (offset value) <- compute-offset data, i +135 var v/edx: (addr value) <- index data, o +136 var w/eax: int <- value-width v, 1 # top-level=true 137 # if (w > result) w = result 138 { -139 compare w, result +139 compare w, result 140 break-if-<= -141 copy-to result, w +141 copy-to result, w 142 } 143 i <- increment 144 loop 145 } -146 return result +146 return result 147 } 148 -149 fn save-lines in-h: (handle array (handle array byte)), _out-ah: (addr handle array value) { +149 fn save-lines in-h: (handle array (handle array byte)), _out-ah: (addr handle array value) { 150 var _in/eax: (addr array (handle array byte)) <- lookup in-h 151 var in/esi: (addr array (handle array byte)) <- copy _in 152 var len/ecx: int <- length in -153 var out-ah/edi: (addr handle array value) <- copy _out-ah +153 var out-ah/edi: (addr handle array value) <- copy _out-ah 154 populate out-ah, len -155 var out/eax: (addr array value) <- lookup *out-ah +155 var out/eax: (addr array value) <- lookup *out-ah 156 # copy in into out 157 var i/ebx: int <- copy 0 158 { @@ -220,8 +220,8 @@ if ('onhashchange' in window) { 161 #? print-int32-hex 0, i 162 #? print-string 0, "\n" 163 var src/ecx: (addr handle array byte) <- index in, i -164 var dest-offset/edx: (offset value) <- compute-offset out, i -165 var dest-val/edx: (addr value) <- index out, dest-offset +164 var dest-offset/edx: (offset value) <- compute-offset out, i +165 var dest-val/edx: (addr value) <- index out, dest-offset 166 var dest/eax: (addr handle array byte) <- get dest-val, text-data 167 copy-object src, dest 168 var type/edx: (addr int) <- get dest-val, type diff --git a/html/apps/tile/value.mu.html b/html/apps/tile/value.mu.html index e982b2bd..6a14baf9 100644 --- a/html/apps/tile/value.mu.html +++ b/html/apps/tile/value.mu.html @@ -57,9 +57,9 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/master/apps/tile/value.mu- 1 fn render-value-at screen: (addr screen), row: int, col: int, _val: (addr value), max-width: int { + 1 fn render-value-at screen: (addr screen), row: int, col: int, _val: (addr value), max-width: int { 2 move-cursor screen, row, col - 3 var val/esi: (addr value) <- copy _val + 3 var val/esi: (addr value) <- copy _val 4 var val-type/ecx: (addr int) <- get val, type 5 # per-type rendering logic goes here 6 compare *val-type, 1 # string @@ -90,8 +90,8 @@ if ('onhashchange' in window) { 31 compare *val-type, 2 # array 32 { 33 break-if-!= - 34 var val-ah/eax: (addr handle array value) <- get val, array-data - 35 var val-array/eax: (addr array value) <- lookup *val-ah + 34 var val-ah/eax: (addr handle array value) <- get val, array-data + 35 var val-array/eax: (addr array value) <- lookup *val-ah 36 render-array-at screen, row, col, val-array 37 return 38 } @@ -154,24 +154,24 @@ if ('onhashchange' in window) { 95 } 96 } 97 - 98 fn render-array-at screen: (addr screen), row: int, col: int, _a: (addr array value) { + 98 fn render-array-at screen: (addr screen), row: int, col: int, _a: (addr array value) { 99 start-color screen, 0xf2, 7 100 # don't surround in spaces 101 print-grapheme screen, 0x5b # '[' 102 increment col -103 var a/esi: (addr array value) <- copy _a -104 var max/ecx: int <- length a +103 var a/esi: (addr array value) <- copy _a +104 var max/ecx: int <- length a 105 var i/eax: int <- copy 0 106 { -107 compare i, max +107 compare i, max 108 break-if->= 109 { 110 compare i, 0 111 break-if-= 112 print-string screen, " " 113 } -114 var off/ecx: (offset value) <- compute-offset a, i -115 var x/ecx: (addr value) <- index a, off +114 var off/ecx: (offset value) <- compute-offset a, i +115 var x/ecx: (addr value) <- index a, off 116 render-value-at screen, row, col, x, 0 117 { 118 var w/eax: int <- value-width x, 0 @@ -216,8 +216,8 @@ if ('onhashchange' in window) { 157 } 158 159 fn hash-color val: int -> _/eax: int { -160 var result/eax: int <- try-modulo val, 7 # assumes that 7 is always the background color -161 return result +160 var result/eax: int <- try-modulo val, 7 # assumes that 7 is always the background color +161 return result 162 } 163 164 fn print-screen-cell-of-fake-screen screen: (addr screen), _target: (addr screen), _row: int, _col: int { @@ -272,15 +272,15 @@ if ('onhashchange' in window) { 213 print-code-point screen, 0x2518 # bottom-right corner 214 } 215 -216 fn value-width _v: (addr value), top-level: boolean -> _/eax: int { -217 var v/esi: (addr value) <- copy _v +216 fn value-width _v: (addr value), top-level: boolean -> _/eax: int { +217 var v/esi: (addr value) <- copy _v 218 var type/eax: (addr int) <- get v, type 219 { 220 compare *type, 0 # int 221 break-if-!= 222 var v-int/edx: (addr int) <- get v, int-data -223 var result/eax: int <- decimal-size *v-int -224 return result +223 var result/eax: int <- decimal-size *v-int +224 return result 225 } 226 { 227 compare *type, 1 # string @@ -289,11 +289,11 @@ if ('onhashchange' in window) { 230 var s/eax: (addr array byte) <- lookup *s-ah 231 compare s, 0 232 break-if-= -233 var result/eax: int <- length s -234 compare result, 0xd # max string size +233 var result/eax: int <- length s +234 compare result, 0xd # max string size 235 { 236 break-if-<= -237 result <- copy 0xd +237 result <- copy 0xd 238 } 239 # if it's a nested string, include space for quotes 240 # we don't do this for the top-level, where the quotes will overflow @@ -301,19 +301,19 @@ if ('onhashchange' in window) { 242 compare top-level, 0 # false 243 { 244 break-if-!= -245 result <- add 2 +245 result <- add 2 246 } -247 return result +247 return result 248 } 249 { 250 compare *type, 2 # array 251 break-if-!= -252 var a-ah/eax: (addr handle array value) <- get v, array-data -253 var a/eax: (addr array value) <- lookup *a-ah +252 var a-ah/eax: (addr handle array value) <- get v, array-data +253 var a/eax: (addr array value) <- lookup *a-ah 254 compare a, 0 255 break-if-= -256 var result/eax: int <- array-width a -257 return result +256 var result/eax: int <- array-width a +257 return result 258 } 259 { 260 compare *type, 3 # file handle @@ -333,43 +333,43 @@ if ('onhashchange' in window) { 274 compare screen, 0 275 break-if-= 276 var ncols/ecx: (addr int) <- get screen, num-cols -277 var result/eax: int <- copy *ncols -278 result <- add 2 # left/right margins +277 var result/eax: int <- copy *ncols +278 result <- add 2 # left/right margins 279 return *ncols 280 } 281 return 0 282 } 283 284 # keep sync'd with render-array-at -285 fn array-width _a: (addr array value) -> _/eax: int { -286 var a/esi: (addr array value) <- copy _a -287 var max/ecx: int <- length a +285 fn array-width _a: (addr array value) -> _/eax: int { +286 var a/esi: (addr array value) <- copy _a +287 var max/ecx: int <- length a 288 var i/eax: int <- copy 0 -289 var result/edi: int <- copy 0 +289 var result/edi: int <- copy 0 290 { -291 compare i, max +291 compare i, max 292 break-if->= 293 { 294 compare i, 0 295 break-if-= -296 result <- increment # for space +296 result <- increment # for space 297 } -298 var off/ecx: (offset value) <- compute-offset a, i -299 var x/ecx: (addr value) <- index a, off +298 var off/ecx: (offset value) <- compute-offset a, i +299 var x/ecx: (addr value) <- index a, off 300 { 301 var w/eax: int <- value-width x, 0 -302 result <- add w +302 result <- add w 303 } 304 i <- increment 305 loop 306 } 307 # we won't add 2 for surrounding brackets since we don't surround arrays in 308 # spaces like other value types -309 return result +309 return result 310 } 311 -312 fn value-height _v: (addr value) -> _/eax: int { -313 var v/esi: (addr value) <- copy _v +312 fn value-height _v: (addr value) -> _/eax: int { +313 var v/esi: (addr value) <- copy _v 314 var type/eax: (addr int) <- get v, type 315 { 316 compare *type, 3 # file handle @@ -385,17 +385,17 @@ if ('onhashchange' in window) { 326 compare screen, 0 327 break-if-= 328 var nrows/ecx: (addr int) <- get screen, num-rows -329 var result/eax: int <- copy *nrows -330 result <- add 2 # top and bottom border -331 return result +329 var result/eax: int <- copy *nrows +330 result <- add 2 # top and bottom border +331 return result 332 } 333 return 1 334 } 335 -336 fn deep-copy-value _src: (addr value), _dest: (addr value) { +336 fn deep-copy-value _src: (addr value), _dest: (addr value) { 337 #? print-string 0, "deep-copy-value\n" -338 var src/esi: (addr value) <- copy _src -339 var dest/edi: (addr value) <- copy _dest +338 var src/esi: (addr value) <- copy _src +339 var dest/edi: (addr value) <- copy _dest 340 var type/ebx: (addr int) <- get src, type 341 var y/ecx: (addr int) <- get dest, type 342 copy-object type, y @@ -422,22 +422,22 @@ if ('onhashchange' in window) { 363 { 364 break-if-!= 365 #? print-string 0, "array value\n" -366 var src-ah/eax: (addr handle array value) <- get src, array-data -367 var _src/eax: (addr array value) <- lookup *src-ah -368 var src/esi: (addr array value) <- copy _src +366 var src-ah/eax: (addr handle array value) <- get src, array-data +367 var _src/eax: (addr array value) <- lookup *src-ah +368 var src/esi: (addr array value) <- copy _src 369 var n/ecx: int <- length src -370 var dest-ah/edx: (addr handle array value) <- get dest, array-data +370 var dest-ah/edx: (addr handle array value) <- get dest, array-data 371 populate dest-ah, n -372 var _dest/eax: (addr array value) <- lookup *dest-ah -373 var dest/edi: (addr array value) <- copy _dest +372 var _dest/eax: (addr array value) <- lookup *dest-ah +373 var dest/edi: (addr array value) <- copy _dest 374 var i/eax: int <- copy 0 375 { 376 compare i, n 377 break-if->= 378 { -379 var offset/edx: (offset value) <- compute-offset src, i -380 var src-element/eax: (addr value) <- index src, offset -381 var dest-element/ecx: (addr value) <- index dest, offset +379 var offset/edx: (offset value) <- compute-offset src, i +380 var src-element/eax: (addr value) <- index src, offset +381 var dest-element/ecx: (addr value) <- index dest, offset 382 deep-copy-value src-element, dest-element 383 } 384 i <- increment diff --git a/html/apps/tile/word.mu.html b/html/apps/tile/word.mu.html index 89adc88b..2a54bb74 100644 --- a/html/apps/tile/word.mu.html +++ b/html/apps/tile/word.mu.html @@ -57,73 +57,73 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/master/apps/tile/word.mu- 1 fn initialize-word _self: (addr word) { - 2 var self/esi: (addr word) <- copy _self - 3 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data + 1 fn initialize-word _self: (addr word) { + 2 var self/esi: (addr word) <- copy _self + 3 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data 4 allocate data-ah - 5 var data/eax: (addr gap-buffer) <- lookup *data-ah - 6 initialize-gap-buffer data + 5 var data/eax: (addr gap-buffer) <- lookup *data-ah + 6 initialize-gap-buffer data 7 # TODO: sometimes initialize box-data rather than scalar-data 8 } 9 10 ## some helpers for creating words. mostly for tests 11 - 12 fn initialize-word-with _self: (addr word), s: (addr array byte) { - 13 var self/esi: (addr word) <- copy _self - 14 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data + 12 fn initialize-word-with _self: (addr word), s: (addr array byte) { + 13 var self/esi: (addr word) <- copy _self + 14 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data 15 allocate data-ah - 16 var data/eax: (addr gap-buffer) <- lookup *data-ah - 17 initialize-gap-buffer-with data, s + 16 var data/eax: (addr gap-buffer) <- lookup *data-ah + 17 initialize-gap-buffer-with data, s 18 } 19 - 20 fn allocate-word-with _out: (addr handle word), s: (addr array byte) { - 21 var out/eax: (addr handle word) <- copy _out + 20 fn allocate-word-with _out: (addr handle word), s: (addr array byte) { + 21 var out/eax: (addr handle word) <- copy _out 22 allocate out - 23 var out-addr/eax: (addr word) <- lookup *out + 23 var out-addr/eax: (addr word) <- lookup *out 24 initialize-word-with out-addr, s 25 } 26 27 # just for tests for now 28 # TODO: handle existing next 29 # one implication of handles: append must take a handle - 30 fn append-word-with self-h: (handle word), s: (addr array byte) { - 31 var self/eax: (addr word) <- lookup self-h - 32 var next-ah/eax: (addr handle word) <- get self, next + 30 fn append-word-with self-h: (handle word), s: (addr array byte) { + 31 var self/eax: (addr word) <- lookup self-h + 32 var next-ah/eax: (addr handle word) <- get self, next 33 allocate-word-with next-ah, s - 34 var next/eax: (addr word) <- lookup *next-ah - 35 var prev-ah/eax: (addr handle word) <- get next, prev + 34 var next/eax: (addr word) <- lookup *next-ah + 35 var prev-ah/eax: (addr handle word) <- get next, prev 36 copy-handle self-h, prev-ah 37 } 38 39 # just for tests for now 40 # TODO: handle existing prev - 41 fn prepend-word-with self-h: (handle word), s: (addr array byte) { - 42 var self/eax: (addr word) <- lookup self-h - 43 var prev-ah/eax: (addr handle word) <- get self, prev + 41 fn prepend-word-with self-h: (handle word), s: (addr array byte) { + 42 var self/eax: (addr word) <- lookup self-h + 43 var prev-ah/eax: (addr handle word) <- get self, prev 44 allocate-word-with prev-ah, s - 45 var prev/eax: (addr word) <- lookup *prev-ah - 46 var next-ah/eax: (addr handle word) <- get prev, next + 45 var prev/eax: (addr word) <- lookup *prev-ah + 46 var next-ah/eax: (addr handle word) <- get prev, next 47 copy-handle self-h, next-ah 48 } 49 50 ## real primitives 51 - 52 fn move-word-contents _src-ah: (addr handle word), _dest-ah: (addr handle word) { - 53 var dest-ah/eax: (addr handle word) <- copy _dest-ah - 54 var _dest/eax: (addr word) <- lookup *dest-ah - 55 var dest/edi: (addr word) <- copy _dest - 56 var src-ah/eax: (addr handle word) <- copy _src-ah - 57 var _src/eax: (addr word) <- lookup *src-ah - 58 var src/esi: (addr word) <- copy _src + 52 fn move-word-contents _src-ah: (addr handle word), _dest-ah: (addr handle word) { + 53 var dest-ah/eax: (addr handle word) <- copy _dest-ah + 54 var _dest/eax: (addr word) <- lookup *dest-ah + 55 var dest/edi: (addr word) <- copy _dest + 56 var src-ah/eax: (addr handle word) <- copy _src-ah + 57 var _src/eax: (addr word) <- lookup *src-ah + 58 var src/esi: (addr word) <- copy _src 59 cursor-to-start src - 60 var src-data-ah/eax: (addr handle gap-buffer) <- get src, scalar-data - 61 var src-data/eax: (addr gap-buffer) <- lookup *src-data-ah - 62 var src-stack/ecx: (addr grapheme-stack) <- get src-data, right + 60 var src-data-ah/eax: (addr handle gap-buffer) <- get src, scalar-data + 61 var src-data/eax: (addr gap-buffer) <- lookup *src-data-ah + 62 var src-stack/ecx: (addr grapheme-stack) <- get src-data, right 63 { - 64 var done?/eax: boolean <- grapheme-stack-empty? src-stack + 64 var done?/eax: boolean <- grapheme-stack-empty? src-stack 65 compare done?, 0 # false 66 break-if-!= - 67 var g/eax: grapheme <- pop-grapheme-stack src-stack + 67 var g/eax: grapheme <- pop-grapheme-stack src-stack 68 #? print-grapheme 0, g 69 #? print-string 0, "\n" 70 add-grapheme-to-word dest, g @@ -131,15 +131,15 @@ if ('onhashchange' in window) { 72 } 73 } 74 - 75 fn copy-word-contents-before-cursor _src-ah: (addr handle word), _dest-ah: (addr handle word) { - 76 var dest-ah/eax: (addr handle word) <- copy _dest-ah - 77 var _dest/eax: (addr word) <- lookup *dest-ah - 78 var dest/edi: (addr word) <- copy _dest - 79 var src-ah/eax: (addr handle word) <- copy _src-ah - 80 var src/eax: (addr word) <- lookup *src-ah - 81 var src-data-ah/eax: (addr handle gap-buffer) <- get src, scalar-data - 82 var src-data/eax: (addr gap-buffer) <- lookup *src-data-ah - 83 var src-stack/ecx: (addr grapheme-stack) <- get src-data, left + 75 fn copy-word-contents-before-cursor _src-ah: (addr handle word), _dest-ah: (addr handle word) { + 76 var dest-ah/eax: (addr handle word) <- copy _dest-ah + 77 var _dest/eax: (addr word) <- lookup *dest-ah + 78 var dest/edi: (addr word) <- copy _dest + 79 var src-ah/eax: (addr handle word) <- copy _src-ah + 80 var src/eax: (addr word) <- lookup *src-ah + 81 var src-data-ah/eax: (addr handle gap-buffer) <- get src, scalar-data + 82 var src-data/eax: (addr gap-buffer) <- lookup *src-data-ah + 83 var src-stack/ecx: (addr grapheme-stack) <- get src-data, left 84 var src-stack-data-ah/eax: (addr handle array grapheme) <- get src-stack, data 85 var _src-stack-data/eax: (addr array grapheme) <- lookup *src-stack-data-ah 86 var src-stack-data/edx: (addr array grapheme) <- copy _src-stack-data @@ -155,29 +155,29 @@ if ('onhashchange' in window) { 96 } 97 } 98 - 99 fn word-equal? _self: (addr word), s: (addr array byte) -> _/eax: boolean { -100 var self/esi: (addr word) <- copy _self -101 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -102 var data/eax: (addr gap-buffer) <- lookup *data-ah -103 var result/eax: boolean <- gap-buffer-equal? data, s -104 return result + 99 fn word-equal? _self: (addr word), s: (addr array byte) -> _/eax: boolean { +100 var self/esi: (addr word) <- copy _self +101 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +102 var data/eax: (addr gap-buffer) <- lookup *data-ah +103 var result/eax: boolean <- gap-buffer-equal? data, s +104 return result 105 } 106 -107 fn word-length _self: (addr word) -> _/eax: int { -108 var self/esi: (addr word) <- copy _self -109 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -110 var data/eax: (addr gap-buffer) <- lookup *data-ah -111 var result/eax: int <- gap-buffer-length data -112 return result +107 fn word-length _self: (addr word) -> _/eax: int { +108 var self/esi: (addr word) <- copy _self +109 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +110 var data/eax: (addr gap-buffer) <- lookup *data-ah +111 var result/eax: int <- gap-buffer-length data +112 return result 113 } 114 -115 fn first-word _in: (addr handle word), out: (addr handle word) { -116 var curr-ah/esi: (addr handle word) <- copy _in -117 var curr/eax: (addr word) <- lookup *curr-ah -118 var prev/edi: (addr handle word) <- copy 0 +115 fn first-word _in: (addr handle word), out: (addr handle word) { +116 var curr-ah/esi: (addr handle word) <- copy _in +117 var curr/eax: (addr word) <- lookup *curr-ah +118 var prev/edi: (addr handle word) <- copy 0 119 { 120 prev <- get curr, prev -121 var curr/eax: (addr word) <- lookup *prev +121 var curr/eax: (addr word) <- lookup *prev 122 compare curr, 0 123 break-if-= 124 copy-object prev, curr-ah @@ -186,12 +186,12 @@ if ('onhashchange' in window) { 127 copy-object curr-ah, out 128 } 129 -130 fn final-word _in: (addr handle word), out: (addr handle word) { -131 var curr-h: (handle word) -132 var curr-ah/esi: (addr handle word) <- address curr-h +130 fn final-word _in: (addr handle word), out: (addr handle word) { +131 var curr-h: (handle word) +132 var curr-ah/esi: (addr handle word) <- address curr-h 133 copy-object _in, curr-ah -134 var curr/eax: (addr word) <- copy 0 -135 var next/edi: (addr handle word) <- copy 0 +134 var curr/eax: (addr word) <- copy 0 +135 var next/edi: (addr handle word) <- copy 0 136 { 137 curr <- lookup *curr-ah 138 next <- get curr, next @@ -204,139 +204,139 @@ if ('onhashchange' in window) { 145 copy-object curr-ah, out 146 } 147 -148 fn first-grapheme _self: (addr word) -> _/eax: grapheme { -149 var self/esi: (addr word) <- copy _self -150 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -151 var data/eax: (addr gap-buffer) <- lookup *data-ah -152 var result/eax: grapheme <- first-grapheme-in-gap-buffer data -153 return result +148 fn first-grapheme _self: (addr word) -> _/eax: grapheme { +149 var self/esi: (addr word) <- copy _self +150 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +151 var data/eax: (addr gap-buffer) <- lookup *data-ah +152 var result/eax: grapheme <- first-grapheme-in-gap-buffer data +153 return result 154 } 155 -156 fn grapheme-before-cursor _self: (addr word) -> _/eax: grapheme { -157 var self/esi: (addr word) <- copy _self -158 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -159 var data/eax: (addr gap-buffer) <- lookup *data-ah -160 var result/eax: grapheme <- grapheme-before-cursor-in-gap-buffer data -161 return result +156 fn grapheme-before-cursor _self: (addr word) -> _/eax: grapheme { +157 var self/esi: (addr word) <- copy _self +158 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +159 var data/eax: (addr gap-buffer) <- lookup *data-ah +160 var result/eax: grapheme <- grapheme-before-cursor-in-gap-buffer data +161 return result 162 } 163 -164 fn add-grapheme-to-word _self: (addr word), c: grapheme { -165 var self/esi: (addr word) <- copy _self -166 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -167 var data/eax: (addr gap-buffer) <- lookup *data-ah -168 add-grapheme-at-gap data, c +164 fn add-grapheme-to-word _self: (addr word), c: grapheme { +165 var self/esi: (addr word) <- copy _self +166 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +167 var data/eax: (addr gap-buffer) <- lookup *data-ah +168 add-grapheme-at-gap data, c 169 } 170 -171 fn cursor-at-start? _self: (addr word) -> _/eax: boolean { -172 var self/esi: (addr word) <- copy _self -173 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -174 var data/eax: (addr gap-buffer) <- lookup *data-ah -175 var result/eax: boolean <- gap-at-start? data -176 return result +171 fn cursor-at-start? _self: (addr word) -> _/eax: boolean { +172 var self/esi: (addr word) <- copy _self +173 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +174 var data/eax: (addr gap-buffer) <- lookup *data-ah +175 var result/eax: boolean <- gap-at-start? data +176 return result 177 } 178 -179 fn cursor-at-end? _self: (addr word) -> _/eax: boolean { -180 var self/esi: (addr word) <- copy _self -181 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -182 var data/eax: (addr gap-buffer) <- lookup *data-ah -183 var result/eax: boolean <- gap-at-end? data -184 return result +179 fn cursor-at-end? _self: (addr word) -> _/eax: boolean { +180 var self/esi: (addr word) <- copy _self +181 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +182 var data/eax: (addr gap-buffer) <- lookup *data-ah +183 var result/eax: boolean <- gap-at-end? data +184 return result 185 } 186 -187 fn cursor-left _self: (addr word) { -188 var self/esi: (addr word) <- copy _self -189 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -190 var data/eax: (addr gap-buffer) <- lookup *data-ah -191 var dummy/eax: grapheme <- gap-left data +187 fn cursor-left _self: (addr word) { +188 var self/esi: (addr word) <- copy _self +189 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +190 var data/eax: (addr gap-buffer) <- lookup *data-ah +191 var dummy/eax: grapheme <- gap-left data 192 } 193 -194 fn cursor-right _self: (addr word) { -195 var self/esi: (addr word) <- copy _self -196 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -197 var data/eax: (addr gap-buffer) <- lookup *data-ah -198 var dummy/eax: grapheme <- gap-right data +194 fn cursor-right _self: (addr word) { +195 var self/esi: (addr word) <- copy _self +196 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +197 var data/eax: (addr gap-buffer) <- lookup *data-ah +198 var dummy/eax: grapheme <- gap-right data 199 } 200 -201 fn cursor-to-start _self: (addr word) { -202 var self/esi: (addr word) <- copy _self -203 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -204 var data/eax: (addr gap-buffer) <- lookup *data-ah -205 gap-to-start data +201 fn cursor-to-start _self: (addr word) { +202 var self/esi: (addr word) <- copy _self +203 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +204 var data/eax: (addr gap-buffer) <- lookup *data-ah +205 gap-to-start data 206 } 207 -208 fn cursor-to-end _self: (addr word) { -209 var self/esi: (addr word) <- copy _self -210 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -211 var data/eax: (addr gap-buffer) <- lookup *data-ah -212 gap-to-end data +208 fn cursor-to-end _self: (addr word) { +209 var self/esi: (addr word) <- copy _self +210 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +211 var data/eax: (addr gap-buffer) <- lookup *data-ah +212 gap-to-end data 213 } 214 -215 fn cursor-index _self: (addr word) -> _/eax: int { -216 var self/esi: (addr word) <- copy _self -217 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -218 var data/eax: (addr gap-buffer) <- lookup *data-ah -219 var result/eax: int <- gap-index data -220 return result +215 fn cursor-index _self: (addr word) -> _/eax: int { +216 var self/esi: (addr word) <- copy _self +217 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +218 var data/eax: (addr gap-buffer) <- lookup *data-ah +219 var result/eax: int <- gap-index data +220 return result 221 } 222 -223 fn delete-before-cursor _self: (addr word) { -224 var self/esi: (addr word) <- copy _self -225 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -226 var data/eax: (addr gap-buffer) <- lookup *data-ah -227 delete-before-gap data +223 fn delete-before-cursor _self: (addr word) { +224 var self/esi: (addr word) <- copy _self +225 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +226 var data/eax: (addr gap-buffer) <- lookup *data-ah +227 delete-before-gap data 228 } 229 -230 fn pop-after-cursor _self: (addr word) -> _/eax: grapheme { -231 var self/esi: (addr word) <- copy _self -232 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -233 var data/eax: (addr gap-buffer) <- lookup *data-ah -234 var result/eax: grapheme <- pop-after-gap data -235 return result +230 fn pop-after-cursor _self: (addr word) -> _/eax: grapheme { +231 var self/esi: (addr word) <- copy _self +232 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +233 var data/eax: (addr gap-buffer) <- lookup *data-ah +234 var result/eax: grapheme <- pop-after-gap data +235 return result 236 } 237 -238 fn delete-next _self: (addr word) { -239 var self/esi: (addr word) <- copy _self -240 var next-ah/edi: (addr handle word) <- get self, next -241 var next/eax: (addr word) <- lookup *next-ah +238 fn delete-next _self: (addr word) { +239 var self/esi: (addr word) <- copy _self +240 var next-ah/edi: (addr handle word) <- get self, next +241 var next/eax: (addr word) <- lookup *next-ah 242 compare next, 0 243 break-if-= -244 var next-next-ah/ecx: (addr handle word) <- get next, next -245 var self-ah/esi: (addr handle word) <- get next, prev +244 var next-next-ah/ecx: (addr handle word) <- get next, next +245 var self-ah/esi: (addr handle word) <- get next, prev 246 copy-object next-next-ah, next-ah -247 var new-next/eax: (addr word) <- lookup *next-next-ah +247 var new-next/eax: (addr word) <- lookup *next-next-ah 248 compare new-next, 0 249 break-if-= -250 var dest/eax: (addr handle word) <- get new-next, prev +250 var dest/eax: (addr handle word) <- get new-next, prev 251 copy-object self-ah, dest 252 } 253 -254 fn print-word screen: (addr screen), _self: (addr word) { -255 var self/esi: (addr word) <- copy _self -256 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -257 var data/eax: (addr gap-buffer) <- lookup *data-ah -258 render-gap-buffer screen, data +254 fn print-word screen: (addr screen), _self: (addr word) { +255 var self/esi: (addr word) <- copy _self +256 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +257 var data/eax: (addr gap-buffer) <- lookup *data-ah +258 render-gap-buffer screen, data 259 } 260 -261 fn print-words screen: (addr screen), _words-ah: (addr handle word) { -262 var words-ah/eax: (addr handle word) <- copy _words-ah -263 var words-a/eax: (addr word) <- lookup *words-ah +261 fn print-words screen: (addr screen), _words-ah: (addr handle word) { +262 var words-ah/eax: (addr handle word) <- copy _words-ah +263 var words-a/eax: (addr word) <- lookup *words-ah 264 compare words-a, 0 265 break-if-= 266 # print 267 print-word screen, words-a 268 print-string screen, " " 269 # recurse -270 var next-ah/eax: (addr handle word) <- get words-a, next +270 var next-ah/eax: (addr handle word) <- get words-a, next 271 print-words screen, next-ah 272 } 273 -274 fn print-words-in-reverse screen: (addr screen), _words-ah: (addr handle word) { -275 var words-ah/eax: (addr handle word) <- copy _words-ah -276 var words-a/eax: (addr word) <- lookup *words-ah +274 fn print-words-in-reverse screen: (addr screen), _words-ah: (addr handle word) { +275 var words-ah/eax: (addr handle word) <- copy _words-ah +276 var words-a/eax: (addr word) <- lookup *words-ah 277 compare words-a, 0 278 break-if-= 279 # recurse -280 var next-ah/ecx: (addr handle word) <- get words-a, next +280 var next-ah/ecx: (addr handle word) <- get words-a, next 281 print-words-in-reverse screen, next-ah 282 # print 283 print-word screen, words-a @@ -346,40 +346,40 @@ if ('onhashchange' in window) { 287 # Gotcha with some word operations: ensure dest-ah isn't in the middle of some 288 # existing chain of words. There are two pointers to patch, and you'll forget 289 # to do the other one. -290 fn copy-words _src-ah: (addr handle word), _dest-ah: (addr handle word) { -291 var src-ah/eax: (addr handle word) <- copy _src-ah -292 var src-a/eax: (addr word) <- lookup *src-ah +290 fn copy-words _src-ah: (addr handle word), _dest-ah: (addr handle word) { +291 var src-ah/eax: (addr handle word) <- copy _src-ah +292 var src-a/eax: (addr word) <- lookup *src-ah 293 compare src-a, 0 294 break-if-= 295 # copy -296 var dest-ah/edi: (addr handle word) <- copy _dest-ah +296 var dest-ah/edi: (addr handle word) <- copy _dest-ah 297 copy-word src-a, dest-ah 298 # recurse -299 var rest: (handle word) -300 var rest-ah/ecx: (addr handle word) <- address rest -301 var next-src-ah/esi: (addr handle word) <- get src-a, next +299 var rest: (handle word) +300 var rest-ah/ecx: (addr handle word) <- address rest +301 var next-src-ah/esi: (addr handle word) <- get src-a, next 302 copy-words next-src-ah, rest-ah 303 chain-words dest-ah, rest-ah 304 } 305 -306 fn copy-words-in-reverse _src-ah: (addr handle word), _dest-ah: (addr handle word) { -307 var src-ah/eax: (addr handle word) <- copy _src-ah -308 var _src-a/eax: (addr word) <- lookup *src-ah -309 var src-a/esi: (addr word) <- copy _src-a +306 fn copy-words-in-reverse _src-ah: (addr handle word), _dest-ah: (addr handle word) { +307 var src-ah/eax: (addr handle word) <- copy _src-ah +308 var _src-a/eax: (addr word) <- lookup *src-ah +309 var src-a/esi: (addr word) <- copy _src-a 310 compare src-a, 0 311 break-if-= 312 # recurse -313 var next-src-ah/ecx: (addr handle word) <- get src-a, next -314 var dest-ah/edi: (addr handle word) <- copy _dest-ah +313 var next-src-ah/ecx: (addr handle word) <- get src-a, next +314 var dest-ah/edi: (addr handle word) <- copy _dest-ah 315 copy-words-in-reverse next-src-ah, dest-ah 316 # 317 copy-word-at-end src-a, dest-ah 318 } 319 -320 fn copy-word-at-end src: (addr word), _dest-ah: (addr handle word) { -321 var dest-ah/edi: (addr handle word) <- copy _dest-ah +320 fn copy-word-at-end src: (addr word), _dest-ah: (addr handle word) { +321 var dest-ah/edi: (addr handle word) <- copy _dest-ah 322 # if dest is null, copy and return -323 var dest-a/eax: (addr word) <- lookup *dest-ah +323 var dest-a/eax: (addr word) <- lookup *dest-ah 324 compare dest-a, 0 325 { 326 break-if-!= @@ -387,15 +387,15 @@ if ('onhashchange' in window) { 328 return 329 } 330 # copy current word -331 var new: (handle word) -332 var new-ah/ecx: (addr handle word) <- address new +331 var new: (handle word) +332 var new-ah/ecx: (addr handle word) <- address new 333 copy-word src, new-ah 334 # append it at the end -335 var curr-ah/edi: (addr handle word) <- copy dest-ah +335 var curr-ah/edi: (addr handle word) <- copy dest-ah 336 { -337 var curr-a/eax: (addr word) <- lookup *curr-ah # curr-a guaranteed not to be null -338 var next-ah/ecx: (addr handle word) <- get curr-a, next -339 var next-a/eax: (addr word) <- lookup *next-ah +337 var curr-a/eax: (addr word) <- lookup *curr-ah # curr-a guaranteed not to be null +338 var next-ah/ecx: (addr handle word) <- get curr-a, next +339 var next-a/eax: (addr word) <- lookup *next-ah 340 compare next-a, 0 341 break-if-= 342 curr-ah <- copy next-ah @@ -404,10 +404,10 @@ if ('onhashchange' in window) { 345 chain-words curr-ah, new-ah 346 } 347 -348 fn append-word-at-end-with _dest-ah: (addr handle word), s: (addr array byte) { -349 var dest-ah/edi: (addr handle word) <- copy _dest-ah +348 fn append-word-at-end-with _dest-ah: (addr handle word), s: (addr array byte) { +349 var dest-ah/edi: (addr handle word) <- copy _dest-ah 350 # if dest is null, copy and return -351 var dest-a/eax: (addr word) <- lookup *dest-ah +351 var dest-a/eax: (addr word) <- lookup *dest-ah 352 compare dest-a, 0 353 { 354 break-if-!= @@ -415,11 +415,11 @@ if ('onhashchange' in window) { 356 return 357 } 358 # otherwise append at end -359 var curr-ah/edi: (addr handle word) <- copy dest-ah +359 var curr-ah/edi: (addr handle word) <- copy dest-ah 360 { -361 var curr-a/eax: (addr word) <- lookup *curr-ah # curr-a guaranteed not to be null -362 var next-ah/ecx: (addr handle word) <- get curr-a, next -363 var next-a/eax: (addr word) <- lookup *next-ah +361 var curr-a/eax: (addr word) <- lookup *curr-ah # curr-a guaranteed not to be null +362 var next-ah/ecx: (addr handle word) <- get curr-a, next +363 var next-a/eax: (addr word) <- lookup *next-ah 364 compare next-a, 0 365 break-if-= 366 curr-ah <- copy next-ah @@ -428,22 +428,22 @@ if ('onhashchange' in window) { 369 append-word-with *curr-ah, s 370 } 371 -372 fn copy-word _src-a: (addr word), _dest-ah: (addr handle word) { -373 var dest-ah/eax: (addr handle word) <- copy _dest-ah +372 fn copy-word _src-a: (addr word), _dest-ah: (addr handle word) { +373 var dest-ah/eax: (addr handle word) <- copy _dest-ah 374 allocate dest-ah -375 var _dest-a/eax: (addr word) <- lookup *dest-ah -376 var dest-a/eax: (addr word) <- copy _dest-a +375 var _dest-a/eax: (addr word) <- lookup *dest-ah +376 var dest-a/eax: (addr word) <- copy _dest-a 377 initialize-word dest-a -378 var dest/edi: (addr handle gap-buffer) <- get dest-a, scalar-data -379 var src-a/eax: (addr word) <- copy _src-a -380 var src/eax: (addr handle gap-buffer) <- get src-a, scalar-data -381 copy-gap-buffer src, dest +378 var dest/edi: (addr handle gap-buffer) <- get dest-a, scalar-data +379 var src-a/eax: (addr word) <- copy _src-a +380 var src/eax: (addr handle gap-buffer) <- get src-a, scalar-data +381 copy-gap-buffer src, dest 382 } 383 384 # one implication of handles: append must take a handle -385 fn append-word _self-ah: (addr handle word) { -386 var saved-self-storage: (handle word) -387 var saved-self/eax: (addr handle word) <- address saved-self-storage +385 fn append-word _self-ah: (addr handle word) { +386 var saved-self-storage: (handle word) +387 var saved-self/eax: (addr handle word) <- address saved-self-storage 388 copy-object _self-ah, saved-self 389 #? { 390 #? print-string 0, "self-ah is " @@ -451,9 +451,9 @@ if ('onhashchange' in window) { 392 #? print-int32-hex 0, foo 393 #? print-string 0, "\n" 394 #? } -395 var self-ah/esi: (addr handle word) <- copy _self-ah -396 var _self/eax: (addr word) <- lookup *self-ah -397 var self/ebx: (addr word) <- copy _self +395 var self-ah/esi: (addr handle word) <- copy _self-ah +396 var _self/eax: (addr word) <- lookup *self-ah +397 var self/ebx: (addr word) <- copy _self 398 #? { 399 #? print-string 0, "0: self is " 400 #? var self-ah/eax: (addr handle word) <- copy _self-ah @@ -463,10 +463,10 @@ if ('onhashchange' in window) { 404 #? print-string 0, "\n" 405 #? } 406 # allocate new handle -407 var new: (handle word) -408 var new-ah/ecx: (addr handle word) <- address new +407 var new: (handle word) +408 var new-ah/ecx: (addr handle word) <- address new 409 allocate new-ah -410 var new-addr/eax: (addr word) <- lookup new +410 var new-addr/eax: (addr word) <- lookup new 411 initialize-word new-addr 412 #? { 413 #? print-string 0, "new is " @@ -475,18 +475,18 @@ if ('onhashchange' in window) { 416 #? print-string 0, "\n" 417 #? } 418 # new->next = self->next -419 var src/esi: (addr handle word) <- get self, next +419 var src/esi: (addr handle word) <- get self, next 420 #? { 421 #? print-string 0, "src is " 422 #? var foo/eax: int <- copy src 423 #? print-int32-hex 0, foo 424 #? print-string 0, "\n" 425 #? } -426 var dest/edi: (addr handle word) <- get new-addr, next +426 var dest/edi: (addr handle word) <- get new-addr, next 427 copy-object src, dest 428 # new->next->prev = new 429 { -430 var next-addr/eax: (addr word) <- lookup *src +430 var next-addr/eax: (addr word) <- lookup *src 431 compare next-addr, 0 432 break-if-= 433 #? { @@ -537,59 +537,59 @@ if ('onhashchange' in window) { 478 #? print-int32-hex 0, foo 479 #? print-string 0, "\n" 480 #? } -481 var saved-self-ah/eax: (addr handle word) <- address saved-self-storage +481 var saved-self-ah/eax: (addr handle word) <- address saved-self-storage 482 copy-object saved-self-ah, dest 483 # self->next = new 484 dest <- get self, next 485 copy-object new-ah, dest 486 } 487 -488 fn chain-words _self-ah: (addr handle word), _next: (addr handle word) { -489 var self-ah/esi: (addr handle word) <- copy _self-ah -490 var _self/eax: (addr word) <- lookup *self-ah -491 var self/ecx: (addr word) <- copy _self -492 var dest/edx: (addr handle word) <- get self, next -493 var next-ah/edi: (addr handle word) <- copy _next +488 fn chain-words _self-ah: (addr handle word), _next: (addr handle word) { +489 var self-ah/esi: (addr handle word) <- copy _self-ah +490 var _self/eax: (addr word) <- lookup *self-ah +491 var self/ecx: (addr word) <- copy _self +492 var dest/edx: (addr handle word) <- get self, next +493 var next-ah/edi: (addr handle word) <- copy _next 494 copy-object next-ah, dest -495 var next/eax: (addr word) <- lookup *next-ah +495 var next/eax: (addr word) <- lookup *next-ah 496 compare next, 0 497 break-if-= 498 dest <- get next, prev 499 copy-object self-ah, dest 500 } 501 -502 fn emit-word _self: (addr word), out: (addr stream byte) { -503 var self/esi: (addr word) <- copy _self -504 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -505 var data/eax: (addr gap-buffer) <- lookup *data-ah -506 emit-gap-buffer data, out +502 fn emit-word _self: (addr word), out: (addr stream byte) { +503 var self/esi: (addr word) <- copy _self +504 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +505 var data/eax: (addr gap-buffer) <- lookup *data-ah +506 emit-gap-buffer data, out 507 } 508 -509 fn word-to-string _self: (addr word), out: (addr handle array byte) { -510 var self/esi: (addr word) <- copy _self -511 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -512 var data/eax: (addr gap-buffer) <- lookup *data-ah -513 gap-buffer-to-string data, out +509 fn word-to-string _self: (addr word), out: (addr handle array byte) { +510 var self/esi: (addr word) <- copy _self +511 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +512 var data/eax: (addr gap-buffer) <- lookup *data-ah +513 gap-buffer-to-string data, out 514 } 515 -516 fn word-is-decimal-integer? _self: (addr word) -> _/eax: boolean { -517 var self/eax: (addr word) <- copy _self -518 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data -519 var data/eax: (addr gap-buffer) <- lookup *data-ah -520 var result/eax: boolean <- gap-buffer-is-decimal-integer? data -521 return result +516 fn word-is-decimal-integer? _self: (addr word) -> _/eax: boolean { +517 var self/eax: (addr word) <- copy _self +518 var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data +519 var data/eax: (addr gap-buffer) <- lookup *data-ah +520 var result/eax: boolean <- gap-buffer-is-decimal-integer? data +521 return result 522 } 523 524 # ABSOLUTELY GHASTLY -525 fn word-exists? _haystack-ah: (addr handle word), _needle: (addr word) -> _/ebx: boolean { +525 fn word-exists? _haystack-ah: (addr handle word), _needle: (addr word) -> _/ebx: boolean { 526 var needle-name-storage: (handle array byte) 527 var needle-name-ah/eax: (addr handle array byte) <- address needle-name-storage 528 word-to-string _needle, needle-name-ah # profligate leak 529 var _needle-name/eax: (addr array byte) <- lookup *needle-name-ah 530 var needle-name/edi: (addr array byte) <- copy _needle-name 531 # base case -532 var haystack-ah/esi: (addr handle word) <- copy _haystack-ah -533 var curr/eax: (addr word) <- lookup *haystack-ah +532 var haystack-ah/esi: (addr handle word) <- copy _haystack-ah +533 var curr/eax: (addr word) <- lookup *haystack-ah 534 compare curr, 0 535 { 536 break-if-!= @@ -607,28 +607,28 @@ if ('onhashchange' in window) { 548 return 1 # true 549 } 550 # recurse -551 var curr/eax: (addr word) <- lookup *haystack-ah -552 var next-haystack-ah/eax: (addr handle word) <- get curr, next -553 var result/ebx: boolean <- word-exists? next-haystack-ah, _needle -554 return result +551 var curr/eax: (addr word) <- lookup *haystack-ah +552 var next-haystack-ah/eax: (addr handle word) <- get curr, next +553 var result/ebx: boolean <- word-exists? next-haystack-ah, _needle +554 return result 555 } 556 -557 fn word-list-length words: (addr handle word) -> _/eax: int { -558 var curr-ah/esi: (addr handle word) <- copy words -559 var result/edi: int <- copy 0 +557 fn word-list-length words: (addr handle word) -> _/eax: int { +558 var curr-ah/esi: (addr handle word) <- copy words +559 var result/edi: int <- copy 0 560 { -561 var curr/eax: (addr word) <- lookup *curr-ah +561 var curr/eax: (addr word) <- lookup *curr-ah 562 compare curr, 0 563 break-if-= 564 { 565 var word-len/eax: int <- word-length curr -566 result <- add word-len -567 result <- add 1 # inter-word-margin +566 result <- add word-len +567 result <- add 1 # inter-word-margin 568 } 569 curr-ah <- get curr, next 570 loop 571 } -572 return result +572 return result 573 }-- cgit 1.4.1-2-gfad0