summary refs log tree commit diff stats
path: root/compiler/jsgen.nim
Commit message (Collapse)AuthorAgeFilesLines
* fixes #21317; 1.6.4 regression; etyBaseIndex should return fat pointers ↵ringabout2023-02-011-3/+4
| | | | | [backport 1.6] (#21320) fixes #21317; regression; etyBaseIndex should return fat pointers
* JS backend properly extends string with `setLen` (#21087)Jake Leahy2022-12-131-1/+3
| | | | | * Add test case * Extend string with '0' when setting length to be longer
* Refactor JS sourcemap generator (#21053)Jake Leahy2022-12-131-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Parse the new line format * Fix pattern Didn't have space after the path * Remove duplicate sources Sources would sometimes double up with a new line at the end * Remove unused variable * Refactor sourcemap.nim Removes the multiple translations needed, now goes from single high level type to the final SourceMap Adds documentation for procs * Line numbers line up properly now Files aren't linking correctly though * Files now link up correctly Lines are sometimes off but overall seems pretty good Just need to implement parser * Add column info to output Add sourceMappingURL to rope directly to prevent copy * Properly handle columns * Remove debug lines * Add testcase * Finish testcase * Use the outdir folder instead of the folder the test is in to find the sourcemap Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* Fix #18079 Illegal storage access compiling call with nested ref/deref (#20738)Bung2022-11-041-0/+7
| | | | | | * add test case * refactoring transformAddrDeref and fix #18079 * fix jsgen
* fixes #20572 (#20585)Andreas Rumpf2022-10-171-1/+1
| | | | | * fixes #20572 * added a test case
* fix #8821 JS codegen can produce extreme switch statements with case … ↵Bung2022-10-141-6/+1
| | | | | | | (#20548) * fix #8821 JS codegen can produce extreme switch statements with case a of range * remove totalRange
* refactorings (#20536)Andreas Rumpf2022-10-101-1/+1
| | | | | | | * refactoring * refactoring: removed unused macroUsagesSection * enum instead of bool for better readability
* DAA and 'out' parameters (#20506)Andreas Rumpf2022-10-061-2/+2
| | | | | | | | | | | * DAA and 'out' parameters * progress * documented strictDefs and out parameters * docs, tests and a bugfix * fixes silly regression
* add default field support for object in ARC/ORC (#20480)ringabout2022-10-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fresh start * add cpp target * add result support * add nimPreviewRangeDefault * reduce * use orc * refactor common parts * add tuple support * add testcase for tuple * cleanup; fixes nimsuggest tests * there is something wrong with cpp * remove * add support for seqs * fixes style * addd initial distinct support * remove links * typo * fixes tuple defaults * add rangedefault * add cpp support * fixes one more bugs * add more hasDefaults * fixes ordinal types * add testcase for #16744 * add testcase for #3608 * fixes docgen * small fix * recursive * fixes * cleanup and remove tuple support * fixes nimsuggest * fixes generics procs * refactor * increases timeout * refactor hasDefault * zero default; disable i386 * add tuples back * fixes bugs * fixes tuple * add more tests * fix one more bug regarding tuples * more tests and cleanup * remove messy distinct types which must be initialized by original types * add tests * fixes zero default * fixes grammar * fixes tests * fixes tests * fixes tests * fixes comments * fixes and add testcase * undo default values for results Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
* store full definition AST for consts, fix noRewrite (#20115)metagn2022-09-281-3/+3
| | | | | | | | | | | | | | | | | | | | | | | * continue #9582 for consts, close #9331, fix #20114 also move extractPragma to ast to pave the way for things like {.strdefine: "abc".} etc * changelog correctly * fix jsgen * update tgetimpl * fix sighashes * fix #19766, add comment about postfix * fix noRewrite LOL refs #16620 * fix changelog * fix destructors
* allow more simple expressions in js (#20270)Amjad Ben Hedhili2022-09-271-1/+3
| | | | | | | | * make it match ccgexprs.nim `isSimpleExpr` * x in {1, 2} * r[].x and r.x when r is ref type * float(x) Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
* Compute small nim string lit at CT (#20439)Amjad Ben Hedhili2022-09-271-3/+18
| | | | | * Reduces runtime overhead for small strings. * Avoids including `makeNimstrLit` in the output when all strings are small enough.
* no ropes WIP (#20433)Andreas Rumpf2022-09-271-71/+68
| | | | | | | | | | | | | * refactorings in preparation for ropes elimination of the C code generator; mostly the usual ': Rope' -> 'result: var Rope' rewrite * rewrote ccgcalls.nim * refactored ccgexprs.nim * ccgliterals: refactoring * refactoring: code dealing with name mangling * refactoring: getRecordFieldsAux * ropes are strings (insert obscene joke here) * optimize JS code gen * optimizations and code improvements * more optimizations * final cleanups
* Represent more types as JS `TypedArray`s (#20411)Amjad Ben Hedhili2022-09-261-2/+8
| | | | | | | * Represent `array[N, char]` as JS `UInt8Array(N)` * Add support distinct and range types * Add support for bools and enums
* Shorten JS block code (#20370)Amjad Ben Hedhili2022-09-191-4/+4
|
* fix #20233 Float ranges in case statement in JS crash compiler (#20349)Bung2022-09-141-18/+55
|
* Replace `if` by `case` in JS `isSimpleExpr` (#20267)Amjad Ben Hedhili2022-09-061-5/+7
| | | use case stmt
* support cstring in `case` (#20130)metagn2022-09-011-3/+5
| | | | | | | | | | | | | | | * implement case for cstring for now just converts to string on C backend * custom implementation for cstring * remove leftover * revert even more * add nil + fix packages weird variant literal bug * update docs
* fixes #20227; skip distinct types for genObjConstr [JS backend] (#20229)ringabout2022-08-241-1/+2
| | | fixes #20227; skip distinct types for genObjConstr
* fixes #20219; ignore comment/empty node in stmtListExpr (#20249)ringabout2022-08-241-0/+4
|
* top-down type inference, implements rfc 149 (#20091)metagn2022-08-241-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * micro implementation of rfc 149 refs https://github.com/nim-lang/RFCs/issues/149 * number/array/seq literals, more statements * try fix number literal alias issue * renew expectedType with if/case/try branch types * fix (nerf) index type handling and float typed int * use typeAllowed * tweaks + const test (tested locally) [skip ci] * fill out more of the checklist * more literals, change @ order, type conversions Not copying the full call tree before the typedesc call check in `semIndirectOp` is also a small performance improvement. * disable self-conversion warning * revert type conversions (maybe separate op later) * deal with CI for now (seems unrelated), try enums * workaround CI different way * proper fix * again * see sizes * lol * overload selection, simplify int literal -> float * range, new @ solution, try use fitNode for nil * use new magic * try fix ranges, new magic, deal with #20193 * add documentation, support templates Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* bootstrap the compiler with nimPreviewSlimSystem (#20176)ringabout2022-08-091-0/+4
| | | | | * bootstrap the compiler with nimPreviewSlimSystem * threads
* Fix global destructor injection for JS backend (#19797)quantimnot2022-05-231-5/+25
| | | | | | | | | | | | | | * Fix global destructor injection for JS backend * Moved global destructors injection before the final call to transform and generate JS code. It had previously been after and thus not no JS was generated for them. * Added some internal documentation of `jsgen`. * Enable a current destructor test to cover the JS backend as well. * Fixes the JS aspect of #17237. * Fixed global destructor injection order for JS backend Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* remove tmpFramePtr when optStackTrace is absent (#19649)flywind2022-03-261-4/+0
|
* remove unnecessary framePtr code (#19645)flywind2022-03-251-3/+6
|
* Fix #18662 (#19534)Evan Typanski2022-02-281-1/+3
|
* Optimize lent in JS [backport:1.6] (#19393)hlaaftana2022-01-171-15/+36
| | | | | | | * Optimize lent in JS [backport:1.6] * addr on lent doesn't work anymore, don't use it * use unsafeAddr in test again for older versions
* Fixed generic distinct conversions for 'var' (#18837)Jason Beetham2021-10-261-62/+76
| | | | | | | | | | | | | | | * SameTypeAux now properly traverses generic distincts * Smarter traversal of distincts * Removed redundant check * Fixed nkConv for jsgen * Added test for non distinct nkConv * using skiptypes for distinct now * Fixed genaddr for nkconv
* correct effect tracking for .borrowed procs [backport] (#18882)Andreas Rumpf2021-09-231-1/+1
| | | | | | | | | | | * correct effect tracking for .borrowed procs [backport] * progress * fix error message in a test * correctly fix it Co-authored-by: narimiran <narimiran@disroot.org>
* fix for js strict mode (#18799)Sven Keller2021-09-041-1/+1
| | | | | | | | * Assignments, which would accidentally create global variables, instead throw an error in strict mode * Assignment to a getter-only property Co-authored-by: Sven Keller <s.keller@cortona.de>
* allow building 1.4.0 from devel (#18708)Timothee Cour2021-08-181-0/+1
| | | | | * allow building 1.4.0 from devel * changelog
* properly fix #10053 ; `FieldDefect` msg now shows discriminant value + ↵Timothee Cour2021-08-131-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | lineinfo, in all backends (c,vm,js) (#11955) * fix #10053 FieldError for vm * fixup * FieldError now also shows runtime value of discriminant * fix field error reporting in vm * also report culprit line info in err msg * fix errors for newruntime 2 * fix for js * fixup * PRTEMP4 * works * works * works perfect * refactor * std/private/repr_impl * suppport --gc:arc * cleanup * refactor * simplify * simplify * simplify * fixup * move out compiler.vmgen.genCustom * fixup * fixup * add tests * revert compiler/debugutils.nim * simplify reprDiscriminant * fixup * lib/std/private/repr_impl.nim -> lib/system/repr_impl.nim * try to fix D20210812T165220 * honor --declaredlocs * control toFileLineCol via --declaredlocs
* Remove unused imports, and deprecated function usage (#18663)Kyle Brown2021-08-111-1/+1
| | | | | | | * clean up imports and slice to remove delete * revert buggy code * Replace "delete" with setlen to remove depreciation warning
* fixes #18469 (#18544)Andreas Rumpf2021-07-201-10/+0
| | | | | * fixes #18469 * Update compiler/injectdestructors.nim
* make -d:nimFpRoundtrips work consistently in vm vs rt, fix #18400, etc (#18531)Timothee Cour2021-07-201-6/+1
| | | | | | * compiler/vmhooks: add getVar to allow vmops with var params * addFloat vmops with var param * cgen now renders float32 literals in c backend using roundtrip float to string
* ORC: support for custom =trace procs (#18459)Andreas Rumpf2021-07-091-1/+1
| | | | | | | | | | | * ORC: support custom =trace procs (WIP) * Update tests/arc/tcustomtrace.nim Co-authored-by: Clyybber <darkmine956@gmail.com> * =trace is now documented and seems to work * make test green Co-authored-by: Clyybber <darkmine956@gmail.com>
* fixes #18319 (#18375)Andreas Rumpf2021-06-281-2/+12
|
* followup #18362: make `UnusedImport` work robustly (#18366)Timothee Cour2021-06-271-2/+0
| | | | * warnDuplicateModuleImport => hintDuplicateModuleImport * improve DuplicateModuleImport msg, add test
* jsgen improve spacing (#18048)Juan Carlos2021-05-201-30/+30
| | | | * Fix inconsistent spacings in generated JS of jsgen
* js generates spurious >>> on shr (#17767)Sivchari2021-04-211-2/+1
| | | | | * js generates spurious >>> on shr * Add shr arithmetic test * fix variables from const to let during testing
* CIs: attempt to use csources_v1 (#16282)Andreas Rumpf2021-04-211-1/+1
| | | | | | | | * CIs: attempt to use csources_v1 * also updated the BSDs * also updated azure pipelines * std modules should not itself use the 'std/' import dir... * compiler has to be careful with std/ for v1 booting
* cString => cSourceString; tyCString => tyCstring so that error msgs show ↵Timothee Cour2021-04-171-10/+10
| | | | cstring, not cString (#17744)
* iterable[T] (#17196)Timothee Cour2021-04-111-1/+1
| | | | | | | | * fix failing test toSeq in manual which now works * changelog * reject proc fn(a: iterable) * add iterable to spec * remove MCS/UFCS limitation that now works
* fixes #11225; generic sandwich problems; [backport:1.2] (#17255)Andreas Rumpf2021-03-091-1/+2
| | | | | * fixes #11225; generic sandwich problems; [backport:1.2] * progress * delegating these symbols must be done via 'bind'
* fix #17264 [backport:1.4] (#17266)flywind2021-03-051-2/+2
| | | | | * fix #17264 * fix vm * fix js and add tests
* new-style concepts implementation, WIP (#15251)Andreas Rumpf2021-02-241-1/+1
| | | | | | | | | | | | | * fixes #15210 [backport:1.2] * make tests green * make ordinal work * makes Swapable test compile * make Indexable example work * concepts: 'self' is now 'Self' * concepts: make Dictionary example compile * document the new concept implementation * concepts: make typeDesc work properly * concepts: allow documentation comments (d'oh)
* fix #17076 (#17081)flywind2021-02-181-1/+5
|
* JS: fix div uint64 no truncation (#16899)flywind2021-02-151-1/+4
|
* array literals uses typed arrays; fix a jsgen bug (#16850)flywind2021-02-151-16/+39
| | | | | | | * array litterals uses typed arrays * Update compiler/jsgen.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* [backport:1.4] JS cstring null fixes (#16979)hlaaftana2021-02-111-3/+19
| | | | | * [backport:1.4] JS cstring null fixes * fix JS move string * make it look cleaner
mu.html?h=hlt&id=65361948ca7975553757a0e0df4ac7352413044c'>65361948 ^
672e3e50 ^
f5465e12 ^
65361948 ^
f5465e12 ^





dbe12410 ^

f5465e12 ^




dbe12410 ^


f5465e12 ^
dbe12410 ^
f5465e12 ^






65361948 ^

f5465e12 ^




65361948 ^


f5465e12 ^
dbe12410 ^
f5465e12 ^






dbe12410 ^

f5465e12 ^






dbe12410 ^


f5465e12 ^
65361948 ^
f5465e12 ^






65361948 ^

f5465e12 ^





65361948 ^


f5465e12 ^
dbe12410 ^
f5465e12 ^





dbe12410 ^

f5465e12 ^

dbe12410 ^


f5465e12 ^
dbe12410 ^
f5465e12 ^










dbe12410 ^

f5465e12 ^











dbe12410 ^


f5465e12 ^


672e3e50 ^
f5465e12 ^




672e3e50 ^
f5465e12 ^

9570363a ^
f5465e12 ^



672e3e50 ^
f5465e12 ^


672e3e50 ^

f5465e12 ^
65361948 ^
672e3e50 ^
f5465e12 ^


672e3e50 ^
f5465e12 ^





9570363a ^
f5465e12 ^
65361948 ^
672e3e50 ^
f5465e12 ^




672e3e50 ^
f5465e12 ^







672e3e50 ^
f5465e12 ^

65361948 ^
672e3e50 ^
f5465e12 ^
65361948 ^
f5465e12 ^
672e3e50 ^
f5465e12 ^
672e3e50 ^
f5465e12 ^
672e3e50 ^
f5465e12 ^


65361948 ^
672e3e50 ^
65361948 ^
f5465e12 ^












65361948 ^

672e3e50 ^
f5465e12 ^


672e3e50 ^
f5465e12 ^


eaeb9552 ^
f5465e12 ^








672e3e50 ^

f5465e12 ^
65361948 ^
672e3e50 ^
f5465e12 ^


672e3e50 ^
f5465e12 ^


eaeb9552 ^
f5465e12 ^






672e3e50 ^

f5465e12 ^
65361948 ^
672e3e50 ^
f5465e12 ^


672e3e50 ^
f5465e12 ^


eaeb9552 ^
f5465e12 ^








672e3e50 ^

f5465e12 ^
65361948 ^
672e3e50 ^
f5465e12 ^


672e3e50 ^
f5465e12 ^


eaeb9552 ^
f5465e12 ^






672e3e50 ^

f5465e12 ^
65361948 ^

f5465e12 ^


9570363a ^
f5465e12 ^
9570363a ^
f5465e12 ^
65361948 ^

f5465e12 ^

76755b28 ^
9570363a ^

f5465e12 ^
65361948 ^

f5465e12 ^


e8b1d3ff ^
f5465e12 ^




e8b1d3ff ^

f5465e12 ^
e8b1d3ff ^

f5465e12 ^


e8b1d3ff ^
f5465e12 ^




e8b1d3ff ^

f5465e12 ^
e8b1d3ff ^

f5465e12 ^

76755b28 ^
62a52ffb ^
f5465e12 ^



62a52ffb ^

f5465e12 ^
62a52ffb ^

f5465e12 ^

76755b28 ^
62a52ffb ^
f5465e12 ^



62a52ffb ^

f5465e12 ^
62a52ffb ^

f5465e12 ^

76755b28 ^
62a52ffb ^
90560d71 ^
f5465e12 ^



62a52ffb ^

f5465e12 ^
62a52ffb ^

f5465e12 ^

76755b28 ^
62a52ffb ^
90560d71 ^
f5465e12 ^



62a52ffb ^

f5465e12 ^
62a52ffb ^

f5465e12 ^

76755b28 ^
f5465e12 ^


e8b1d3ff ^
f5465e12 ^




d5d908dd ^
f5465e12 ^





9570363a ^
f5465e12 ^
9570363a ^
f5465e12 ^




65361948 ^

f5465e12 ^
dbe12410 ^
f5465e12 ^




dbe12410 ^

f5465e12 ^







dbe12410 ^


f5465e12 ^

76755b28 ^
f5465e12 ^


e8b1d3ff ^
f5465e12 ^




d5d908dd ^
f5465e12 ^


65361948 ^
f5465e12 ^


65361948 ^
672e3e50 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722



                                                                                          
                               






                                                                                         

                                                                                                 
                        
                              
                             
                               
                           
                            


                              













                                                                                                        
                                              



                      
                                

 
                                                   

                    
 
 










                                                                                                                                  
                                                                            

                                                                                                                                         
                     
                                             
 
 


                                                                                                    
                                            

                                                  
                                                    





                                                                                                                       
                                                                                       
                                                                                                                                        

                                                                                                                                



                                                                                               
                                               





                                                                                                                        

                                                       
                                                                                            

 




                                                                                                    
                
                                  


                                                            







                                                                                                                     
                                                                            
                                                 
                                                                     


                                                                                                                      
                                        


                                                                              

 





                                                                                                                     
                                                         




                                                                                                                           
                                                            




                                                                                            
                                              
                                                                                         


                                                                                                             
                                                                            


                                                                                                                          
                                                                      



                                                                                                                                
                                                                        
                                                          
                                                        



                                                                                                           
                                                                         
                                                                                                         
                                                                                           
                                                          
                                                              




                                                                                                
                                                                

                                                                        

                                                                                                                       
                                                          



                                                                                                    
                                                                              

                                                                                                                    
                                                              

                                                                                                    
                                                                                               






                                                                                                                                               
                                                                                           



                                                                                                                                           
                                                                                                

                                                                                                     
                                                                                          




                                                                                              
                                                       

                                                                                            
 
 
                                                                      
       



                                                                                                                                                                                                                          

                         



                                                                                                                                                   


   
                                                                
       



                                                                                                                                                                                                                             

                         



                                                                                                                                                   

   
 
                                                                    
       





                                                                                                                                                                                                                               

                         




                                                                                                                                                      


   
                                                                          
       






                                                                                                                                                                                                                               

                         




                                                                                                                                                      


   
                                                                
       






                                                                                                                                                                                                                          

                         






                                                                                                                                                    


   
                                                                  
       






                                                                                                                                                                                                                          

                         





                                                                                                                                                    


   
                                                                       
       





                                                                                                                                                                                              

                         

                                                                                                                                                    


   
                                                                
       










                                                                                                                                                                                                                           

                         











                                                                                                                                                                          


   


                                                                                                    
                                                                       




                                                                                                                                
                                                             

                                                                                                     
                                                                                      



                                                                                                                       
                                                                   


                                                                                              

                                                       
                                                                                            
 
 


                                                                                                    
                                                                          





                                                                                                                
                                                                           
                                                                                                         
 
 




                                                                                                    
                                                                        







                                                                                                                                
                                                       

                                                                                            
 
 
                                                                               
       
                                                                                                                                                                                   
                                                    
                                                                                                                                                                                                                          
                                                               
                                                                                                                                                                                                                             
                                             


                                                                                                                                                                                               
   
                                                       
                         












                                                                                                                                                   

   
 


                                                                                                    
                                                                        


                                                  
                                                                                       








                                                                                                                            

                                                       
                                                                                            
 
 


                                                                                                    
                                                                        


                                                  
                                                                                     






                                                                                                                            

                                                       
                                                                                            
 
 


                                                                                                    
                                                                        


                                                  
                                                                                                  








                                                                                                                                  

                                                       
                                                                                            
 
 


                                                                                                    
                                                                        


                                                  
                                                                                                 






                                                                                                                                  

                                                       
                                                                                            

 


                                                                                                    
                                                                         
                                                                                       
                                                                   
                                                                                            

 

                                                          
                                                                                                        

                                                                          
                                                                                                

 


                                                                                                    
                                                                        




                                                                                                             

                                                               
                                            

 


                                                                                                    
                                                                        




                                                                                                           

                                                                 
                                             

 

                                                  
                                                                                                        
                                                                           



                                                      

                                                       
                                             

 

                                                  
                                                                                                        
                                                                           



                                                      

                                                       
                                             

 

                                                  
                                                                                                        
                                                                           
                                                     



                                                      

                                                       
                                             

 

                                                  
                                                                                                        
                                                                           
                                                     



                                                      

                                                       
                                             

 

                                                   
                                                                                                        


                                                                                                                     
                                                         




                                                                                                                           
                                                            





                                                                                          
                                                                            
                                                 
                                                              




                                                                                                

 
                                                                             
       




                                                                                                                                                                                                          

                         







                                                                                                                                                           


   

                                                    
                                                                                                        


                                                                                                                     
                                                         




                                                                                                                           
                                                            


                                                                                          
                                                                  


                                                                                                
 



                                     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 081print.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.muControl { color: #c0a020; }
.muRecipe { color: #ff8700; }
.muScenario { color: #00af00; }
.muData { color: #ffff00; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.Special { color: #ff6060; }
.Delimiter { color: #a04060; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment"># Wrappers around print primitives that take a 'screen' object and are thus</span>
<span class="Comment"># easier to test.</span>

<span class="muData">container</span> screen [
  num-rows:number
  num-columns:number
  cursor-row:number
  cursor-column:number
  data:address:array:screen-cell
]

<span class="muData">container</span> screen-cell [
  contents:character
  color:number
]

<span class="muRecipe">recipe</span> new-fake-screen [
  <span class="Constant">local-scope</span>
  result:address:screen<span class="Special"> &lt;- </span>new <span class="Constant">screen:type</span>
  width:address:number<span class="Special"> &lt;- </span>get-address *result, <span class="Constant">num-columns:offset</span>
  *width<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  height:address:number<span class="Special"> &lt;- </span>get-address *result, <span class="Constant">num-rows:offset</span>
  *height<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  row:address:number<span class="Special"> &lt;- </span>get-address *result, <span class="Constant">cursor-row:offset</span>
  *row<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  column:address:number<span class="Special"> &lt;- </span>get-address *result, <span class="Constant">cursor-column:offset</span>
  *column<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  bufsize:number<span class="Special"> &lt;- </span>multiply *width, *height
  buf:address:address:array:screen-cell<span class="Special"> &lt;- </span>get-address *result, <span class="Constant">data:offset</span>
  *buf<span class="Special"> &lt;- </span>new <span class="Constant">screen-cell:type</span>, bufsize
  clear-screen result
  <span class="muControl">reply</span> result
]

<span class="muRecipe">recipe</span> clear-screen [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    <span class="Comment"># clear fake screen</span>
    buf:address:array:screen-cell<span class="Special"> &lt;- </span>get *sc, <span class="Constant">data:offset</span>
    max:number<span class="Special"> &lt;- </span>length *buf
    i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
    <span class="Delimiter">{</span>
      done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, max
      <span class="muControl">break-if</span> done?
      curr:address:screen-cell<span class="Special"> &lt;- </span>index-address *buf, i
      curr-content:address:character<span class="Special"> &lt;- </span>get-address *curr, <span class="Constant">contents:offset</span>
      *curr-content<span class="Special"> &lt;- </span>copy <span class="Constant">0/empty</span>
      curr-color:address:number<span class="Special"> &lt;- </span>get-address *curr, <span class="Constant">color:offset</span>
      *curr-color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span>
      i<span class="Special"> &lt;- </span>add i, <span class="Constant">1</span>
      <span class="muControl">loop</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># reset cursor</span>
    x:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-row:offset</span>
    *x<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
    x<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-column:offset</span>
    *x<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
    <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  clear-display
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> sync-screen [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-if</span> sc
    sync-display
  <span class="Delimiter">}</span>
  <span class="Comment"># do nothing for fake screens</span>
]

<span class="muRecipe">recipe</span> fake-screen-is-empty? [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="muControl">reply-unless</span> sc, <span class="Constant">1/true</span>
  buf:address:array:screen-cell<span class="Special"> &lt;- </span>get *sc, <span class="Constant">data:offset</span>
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  len:number<span class="Special"> &lt;- </span>length *buf
  <span class="Delimiter">{</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, len
    <span class="muControl">break-if</span> done?
    curr:screen-cell<span class="Special"> &lt;- </span>index *buf, i
    curr-contents:character<span class="Special"> &lt;- </span>get curr, <span class="Constant">contents:offset</span>
    i<span class="Special"> &lt;- </span>add i, <span class="Constant">1</span>
    <span class="muControl">loop-unless</span> curr-contents
    <span class="Comment"># not 0</span>
    <span class="muControl">reply</span> <span class="Constant">0/false</span>
  <span class="Delimiter">}</span>
  <span class="muControl">reply</span> <span class="Constant">1/true</span>
]

<span class="muRecipe">recipe</span> print-character [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  c:character<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?
    color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span>
  <span class="Delimiter">}</span>
  bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default bg-color to black</span>
    <span class="muControl">break-if</span> bg-color-found?
    bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span>
  <span class="Delimiter">}</span>
  trace <span class="Constant">90</span>, <span class="Constant">[print-character]</span>, c
  <span class="Delimiter">{</span>
    <span class="Comment"># if x exists</span>
    <span class="Comment"># (handle special cases exactly like in the real screen)</span>
    <span class="muControl">break-unless</span> sc
    width:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">num-columns:offset</span>
    height:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">num-rows:offset</span>
    <span class="Comment"># if cursor is out of bounds, silently exit</span>
    row:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-row:offset</span>
    legal?:boolean<span class="Special"> &lt;- </span>greater-or-equal *row, <span class="Constant">0</span>
    <span class="muControl">reply-unless</span> legal?, sc
    legal?<span class="Special"> &lt;- </span>lesser-than *row, height
    <span class="muControl">reply-unless</span> legal?, sc
    column:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-column:offset</span>
    legal?<span class="Special"> &lt;- </span>greater-or-equal *column, <span class="Constant">0</span>
    <span class="muControl">reply-unless</span> legal?, sc
    legal?<span class="Special"> &lt;- </span>lesser-than *column, width
    <span class="muControl">reply-unless</span> legal?, sc
    <span class="Comment"># special-case: newline</span>
    <span class="Delimiter">{</span>
      newline?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">10/newline</span>
      <span class="muControl">break-unless</span> newline?
      <span class="Delimiter">{</span>
        <span class="Comment"># unless cursor is already at bottom</span>
        bottom:number<span class="Special"> &lt;- </span>subtract height, <span class="Constant">1</span>
        at-bottom?:boolean<span class="Special"> &lt;- </span>greater-or-equal *row, bottom
        <span class="muControl">break-if</span> at-bottom?
        <span class="Comment"># move it to the next row</span>
        *column<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
        *row<span class="Special"> &lt;- </span>add *row, <span class="Constant">1</span>
      <span class="Delimiter">}</span>
      <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># save character in fake screen</span>
    index:number<span class="Special"> &lt;- </span>multiply *row, width
    index<span class="Special"> &lt;- </span>add index, *column
    buf:address:array:screen-cell<span class="Special"> &lt;- </span>get *sc, <span class="Constant">data:offset</span>
    len:number<span class="Special"> &lt;- </span>length *buf
    <span class="Comment"># special-case: backspace</span>
    <span class="Delimiter">{</span>
      backspace?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">8</span>
      <span class="muControl">break-unless</span> backspace?
      <span class="Delimiter">{</span>
        <span class="Comment"># unless cursor is already at left margin</span>
        at-left?:boolean<span class="Special"> &lt;- </span>lesser-or-equal *column, <span class="Constant">0</span>
        <span class="muControl">break-if</span> at-left?
        <span class="Comment"># clear previous location</span>
        *column<span class="Special"> &lt;- </span>subtract *column, <span class="Constant">1</span>
        index<span class="Special"> &lt;- </span>subtract index, <span class="Constant">1</span>
        cursor:address:screen-cell<span class="Special"> &lt;- </span>index-address *buf, index
        cursor-contents:address:character<span class="Special"> &lt;- </span>get-address *cursor, <span class="Constant">contents:offset</span>
        *cursor-contents<span class="Special"> &lt;- </span>copy <span class="Constant">32/space</span>
        cursor-color:address:number<span class="Special"> &lt;- </span>get-address *cursor, <span class="Constant">color:offset</span>
        *cursor-color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span>
      <span class="Delimiter">}</span>
      <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
    <span class="Delimiter">}</span>
    cursor:address:screen-cell<span class="Special"> &lt;- </span>index-address *buf, index
    cursor-contents:address:character<span class="Special"> &lt;- </span>get-address *cursor, <span class="Constant">contents:offset</span>
    *cursor-contents<span class="Special"> &lt;- </span>copy c
    cursor-color:address:number<span class="Special"> &lt;- </span>get-address *cursor, <span class="Constant">color:offset</span>
    *cursor-color<span class="Special"> &lt;- </span>copy color
    <span class="Comment"># increment column unless it's already all the way to the right</span>
    <span class="Delimiter">{</span>
      right:number<span class="Special"> &lt;- </span>subtract width, <span class="Constant">1</span>
      at-right?:boolean<span class="Special"> &lt;- </span>greater-or-equal *column, right
      <span class="muControl">break-if</span> at-right?
      *column<span class="Special"> &lt;- </span>add *column, <span class="Constant">1</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  print-character-to-display c, color, bg-color
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muScenario">scenario</span> print-character-at-top-left [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">2</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">3</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">2</span>:address:array:screen-cell
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">6</span>  <span class="Comment"># width*height</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
  ]
]

<span class="muScenario">scenario</span> print-character-color [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97/a</span>, <span class="Constant">1/red</span>
    <span class="Constant">2</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">3</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">2</span>:address:array:screen-cell
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">6</span>  <span class="Comment"># width*height</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># red</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
  ]
]

<span class="muScenario">scenario</span> print-backspace-character [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">8</span>  <span class="Comment"># backspace</span>
    <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-column:offset</span>
    <span class="Constant">3</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">4</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">3</span>:address:array:screen-cell
  ]
  memory-should-contain [
    <span class="Constant">2</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># cursor column</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">6</span>  <span class="Comment"># width*height</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">32</span>  <span class="Comment"># space, not 'a'</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">7</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
  ]
]

<span class="muScenario">scenario</span> print-extra-backspace-character [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">8</span>  <span class="Comment"># backspace</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">8</span>  <span class="Comment"># backspace</span>
    <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-column:offset</span>
    <span class="Constant">3</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">4</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">3</span>:address:array:screen-cell
  ]
  memory-should-contain [
    <span class="Constant">2</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># cursor column</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">6</span>  <span class="Comment"># width*height</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">32</span>  <span class="Comment"># space, not 'a'</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">7</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
  ]
]

<span class="muScenario">scenario</span> print-at-right-margin [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">98</span>  <span class="Comment"># 'b'</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">99</span>  <span class="Comment"># 'c'</span>
    <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-column:offset</span>
    <span class="Constant">3</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">4</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">3</span>:address:array:screen-cell
  ]
  memory-should-contain [
    <span class="Constant">2</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor column</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">4</span>  <span class="Comment"># width*height</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">7</span><span class="Special"> &lt;- </span><span class="Constant">99</span>  <span class="Comment"># 'c' over 'b'</span>
    <span class="Constant">8</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">9</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
  ]
]

<span class="muScenario">scenario</span> print-newline-character [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span>
    <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-column:offset</span>
    <span class="Constant">4</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">5</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">4</span>:address:array:screen-cell
  ]
  memory-should-contain [
    <span class="Constant">2</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># cursor column</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">6</span>  <span class="Comment"># width*height</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">7</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">8</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
  ]
]

<span class="muScenario">scenario</span> print-newline-at-bottom-line [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span>
    <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-column:offset</span>
  ]
  memory-should-contain [
    <span class="Constant">2</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># cursor column</span>
  ]
]

<span class="muScenario">scenario</span> print-at-bottom-right [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">98</span>  <span class="Comment"># 'b'</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">99</span>  <span class="Comment"># 'c'</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">100</span>  <span class="Comment"># 'd'</span>
    <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">cursor-column:offset</span>
    <span class="Constant">4</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">5</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">4</span>:address:array:screen-cell
  ]
  memory-should-contain [
    <span class="Constant">2</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor column</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">4</span>  <span class="Comment"># width*height</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># unused</span>
    <span class="Constant">7</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">8</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># unused</span>
    <span class="Constant">9</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span>
    <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">12</span><span class="Special"> &lt;- </span><span class="Constant">100</span>  <span class="Comment"># 'd' over 'b' and 'c' and newline</span>
    <span class="Constant">13</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">14</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
  ]
]

<span class="muRecipe">recipe</span> clear-line [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, clear line in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    width:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">num-columns:offset</span>
    column:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-column:offset</span>
    original-column:number<span class="Special"> &lt;- </span>copy *column
    <span class="Comment"># space over the entire line</span>
    <span class="Delimiter">{</span>
      right:number<span class="Special"> &lt;- </span>subtract width, <span class="Constant">1</span>
      done?:boolean<span class="Special"> &lt;- </span>greater-or-equal *column, right
      <span class="muControl">break-if</span> done?
      print-character sc, <span class="Constant">[ ]</span>  <span class="Comment"># implicitly updates 'column'</span>
      <span class="muControl">loop</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># now back to where the cursor was</span>
    *column<span class="Special"> &lt;- </span>copy original-column
    <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  clear-line-on-display
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> cursor-position [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, lookup cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    row:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">cursor-row:offset</span>
    column:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">cursor-column:offset</span>
    <span class="muControl">reply</span> row, column, sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  row, column<span class="Special"> &lt;- </span>cursor-position-on-display
  <span class="muControl">reply</span> row, column, sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> move-cursor [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  new-row:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  new-column:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    row:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-row:offset</span>
    *row<span class="Special"> &lt;- </span>copy new-row
    column:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-column:offset</span>
    *column<span class="Special"> &lt;- </span>copy new-column
    <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-on-display new-row, new-column
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muScenario">scenario</span> clear-line-erases-printed-characters [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
    <span class="Comment"># print a character</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Comment"># move cursor to start of line</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>move-cursor <span class="Constant">1</span>:address:screen, <span class="Constant">0/row</span>, <span class="Constant">0/column</span>
    <span class="Comment"># clear line</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>clear-line <span class="Constant">1</span>:address:screen
    <span class="Constant">2</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">3</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">2</span>:address:array:screen-cell
  ]
  <span class="Comment"># screen should be blank</span>
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">6</span>  <span class="Comment"># width*height</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">7</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
    <span class="Constant">7</span><span class="Special"> &lt;- </span><span class="Constant">7</span>
    <span class="Constant">8</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
    <span class="Constant">9</span><span class="Special"> &lt;- </span><span class="Constant">7</span>
    <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
    <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">7</span>
    <span class="Constant">12</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
    <span class="Constant">13</span><span class="Special"> &lt;- </span><span class="Constant">7</span>
    <span class="Constant">14</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
    <span class="Constant">15</span><span class="Special"> &lt;- </span><span class="Constant">7</span>
  ]
]

<span class="muRecipe">recipe</span> cursor-down [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    <span class="Delimiter">{</span>
      <span class="Comment"># increment row unless it's already all the way down</span>
      height:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">num-rows:offset</span>
      row:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-row:offset</span>
      max:number<span class="Special"> &lt;- </span>subtract height, <span class="Constant">1</span>
      at-bottom?:boolean<span class="Special"> &lt;- </span>greater-or-equal *row, max
      <span class="muControl">break-if</span> at-bottom?
      *row<span class="Special"> &lt;- </span>add *row, <span class="Constant">1</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-down-on-display
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> cursor-up [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    <span class="Delimiter">{</span>
      <span class="Comment"># decrement row unless it's already all the way up</span>
      row:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-row:offset</span>
      at-top?:boolean<span class="Special"> &lt;- </span>lesser-or-equal *row, <span class="Constant">0</span>
      <span class="muControl">break-if</span> at-top?
      *row<span class="Special"> &lt;- </span>subtract *row, <span class="Constant">1</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-up-on-display
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> cursor-right [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    <span class="Delimiter">{</span>
      <span class="Comment"># increment column unless it's already all the way to the right</span>
      width:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">num-columns:offset</span>
      column:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-column:offset</span>
      max:number<span class="Special"> &lt;- </span>subtract width, <span class="Constant">1</span>
      at-bottom?:boolean<span class="Special"> &lt;- </span>greater-or-equal *column, max
      <span class="muControl">break-if</span> at-bottom?
      *column<span class="Special"> &lt;- </span>add *column, <span class="Constant">1</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-right-on-display
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> cursor-left [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    <span class="Delimiter">{</span>
      <span class="Comment"># decrement column unless it's already all the way to the left</span>
      column:address:number<span class="Special"> &lt;- </span>get-address *sc, <span class="Constant">cursor-column:offset</span>
      at-top?:boolean<span class="Special"> &lt;- </span>lesser-or-equal *column, <span class="Constant">0</span>
      <span class="muControl">break-if</span> at-top?
      *column<span class="Special"> &lt;- </span>subtract *column, <span class="Constant">1</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-left-on-display
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> cursor-to-start-of-line [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  row:number, _, sc<span class="Special"> &lt;- </span>cursor-position sc
  column:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  sc<span class="Special"> &lt;- </span>move-cursor sc, row, column
  <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> cursor-to-next-line [
  <span class="Constant">local-scope</span>
  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen<span class="Special"> &lt;- </span>cursor-down screen
  screen<span class="Special"> &lt;- </span>cursor-to-start-of-line screen
  <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muRecipe">recipe</span> screen-width [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    width:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">num-columns:offset</span>
    <span class="muControl">reply</span> width
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  width:number<span class="Special"> &lt;- </span>display-width
  <span class="muControl">reply</span> width
]

<span class="muRecipe">recipe</span> screen-height [
  <span class="Constant">local-scope</span>
  sc:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> sc
    height:number<span class="Special"> &lt;- </span>get *sc, <span class="Constant">num-rows:offset</span>
    <span class="muControl">reply</span> height
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  height:number<span class="Special"> &lt;- </span>display-height
  <span class="muControl">reply</span> height
]

<span class="muRecipe">recipe</span> hide-cursor [
  <span class="Constant">local-scope</span>
  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists (not real display), do nothing</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> screen
    <span class="muControl">reply</span> screen
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  hide-cursor-on-display
  <span class="muControl">reply</span> screen
]

<span class="muRecipe">recipe</span> show-cursor [
  <span class="Constant">local-scope</span>
  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists (not real display), do nothing</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> screen
    <span class="muControl">reply</span> screen
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  show-cursor-on-display
  <span class="muControl">reply</span> screen
]

<span class="muRecipe">recipe</span> hide-screen [
  <span class="Constant">local-scope</span>
  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists (not real display), do nothing</span>
  <span class="Comment"># todo: help test this</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> screen
    <span class="muControl">reply</span> screen
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  hide-display
  <span class="muControl">reply</span> screen
]

<span class="muRecipe">recipe</span> show-screen [
  <span class="Constant">local-scope</span>
  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists (not real display), do nothing</span>
  <span class="Comment"># todo: help test this</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> screen
    <span class="muControl">reply</span> screen
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  show-display
  <span class="muControl">reply</span> screen
]

<span class="muRecipe">recipe</span> print-string [
  <span class="Constant">local-scope</span>
  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  s:address:array:character<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?
    color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span>
  <span class="Delimiter">}</span>
  bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default bg-color to black</span>
    <span class="muControl">break-if</span> bg-color-found?
    bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span>
  <span class="Delimiter">}</span>
  len:number<span class="Special"> &lt;- </span>length *s
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Delimiter">{</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, len
    <span class="muControl">break-if</span> done?
    c:character<span class="Special"> &lt;- </span>index *s, i
    print-character screen, c, color, bg-color
    i<span class="Special"> &lt;- </span>add i, <span class="Constant">1</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>
]

<span class="muScenario">scenario</span> print-string-stops-at-right-margin [
  run [
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
    <span class="Constant">2</span>:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcd]</span>
    <span class="Constant">1</span>:address:screen<span class="Special"> &lt;- </span>print-string <span class="Constant">1</span>:address:screen, <span class="Constant">2</span>:address:array:character
    <span class="Constant">3</span>:address:array:screen-cell<span class="Special"> &lt;- </span>get *<span class="Constant">1</span>:address:screen, <span class="Constant">data:offset</span>
    <span class="Constant">4</span>:array:screen-cell<span class="Special"> &lt;- </span>copy *<span class="Constant">3</span>:address:array:screen-cell
  ]
  memory-should-contain [
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">6</span>  <span class="Comment"># width*height</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">7</span><span class="Special"> &lt;- </span><span class="Constant">98</span>  <span class="Comment"># 'b'</span>
    <span class="Constant">8</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">9</span><span class="Special"> &lt;- </span><span class="Constant">100</span>  <span class="Comment"># 'd' overwrites 'c'</span>
    <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">7</span>  <span class="Comment"># white</span>
    <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># unused</span>
  ]
]

<span class="muRecipe">recipe</span> print-integer [
  <span class="Constant">local-scope</span>
  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  n:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?
    color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span>
  <span class="Delimiter">}</span>
  bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default bg-color to black</span>
    <span class="muControl">break-if</span> bg-color-found?
    bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># todo: other bases besides decimal</span>
  s:address:array:character<span class="Special"> &lt;- </span>integer-to-decimal-string n
  print-string screen, s, color, bg-color
  <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->