about summary refs log tree commit diff stats
path: root/html/022arithmetic.cc.html
Commit message (Expand)AuthorAgeFilesLines
* 3544Kartik K. Agaram2016-10-221-1/+1
* 3543Kartik K. Agaram2016-10-221-1/+1
* 3524Kartik K. Agaram2016-10-201-10/+10
* 3431Kartik K. Agaram2016-09-301-44/+45
* 3395Kartik K. Agaram2016-09-171-61/+61
* 3219Kartik K. Agaram2016-08-171-0/+68
* 3158Kartik K. Agaram2016-07-271-25/+25
* 2996Kartik K. Agaram2016-05-211-17/+17
* 2812Kartik K. Agaram2016-03-271-63/+72
* 2745Kartik K. Agaram2016-03-091-1/+1
* 2744Kartik K. Agaram2016-03-091-3/+3
* 2743Kartik K. Agaram2016-03-091-212/+204
* 2706 - update htmlKartik K. Agaram2016-02-251-8/+371
* 2605Kartik K. Agaram2016-01-261-0/+7
* 2423 - describe shape-shifting in html docsKartik K. Agaram2015-11-101-0/+353
16-03-27 17:43:41 -0700 2812' href='/akkartik/mu/commit/html/082scenario_screen.cc.html?h=hlt&id=a654e4ecace2d506d1b10f1dde2c287ebe84ef37'>a654e4ec ^
4690ce81 ^
3e1349d2 ^
4690ce81 ^
a654e4ec ^

70f4e9b6 ^
a654e4ec ^
3e1349d2 ^
672e3e50 ^

a654e4ec ^





672e3e50 ^

a654e4ec ^
672e3e50 ^

513ba330 ^


672e3e50 ^
d990e8f0 ^




672e3e50 ^

3e1349d2 ^
6c69569a ^
9570363a ^
672e3e50 ^
6c69569a ^

672e3e50 ^






672e3e50 ^
e81da299 ^
672e3e50 ^
c5ffb6e1 ^
d059fe74 ^

6c69569a ^
9570363a ^
4bbd3ded ^
6c69569a ^
d059fe74 ^
6c69569a ^

4bbd3ded ^






4bbd3ded ^
e81da299 ^
4bbd3ded ^

3e1349d2 ^
6c69569a ^
9570363a ^
c5ffb6e1 ^
6c69569a ^



c5ffb6e1 ^
4bbd3ded ^
c5ffb6e1 ^

4bbd3ded ^





9570363a ^
4bbd3ded ^





9570363a ^
4bbd3ded ^
c5ffb6e1 ^



c5ffb6e1 ^
e81da299 ^
c5ffb6e1 ^
672e3e50 ^
d5d908dd ^
76755b28 ^
3e1349d2 ^
6c69569a ^
9570363a ^
672e3e50 ^
6c69569a ^

672e3e50 ^







76755b28 ^
c5ffb6e1 ^
4bbd3ded ^
d5d908dd ^
76755b28 ^
4bbd3ded ^
d059fe74 ^
6c69569a ^
9570363a ^
4bbd3ded ^
6c69569a ^

4bbd3ded ^
9570363a ^
4bbd3ded ^





76755b28 ^
4bbd3ded ^
62a52ffb ^
76755b28 ^
d5d908dd ^
3e1349d2 ^
f344b250 ^
62a52ffb ^
76755b28 ^

62a52ffb ^

cd9bb850 ^





672e3e50 ^
44c1aeef ^
a654e4ec ^
672e3e50 ^

672e3e50 ^


44c1aeef ^
672e3e50 ^
8e7b4429 ^

62a52ffb ^

8e7b4429 ^


672e3e50 ^
76755b28 ^
672e3e50 ^
f344b250 ^
4690ce81 ^
dbe12410 ^
cd9bb850 ^







f344b250 ^
cd9bb850 ^

672e3e50 ^

c842d90b ^

d059fe74 ^
c842d90b ^

d059fe74 ^
c842d90b ^
672e3e50 ^



76755b28 ^

4690ce81 ^
cd9bb850 ^



f344b250 ^
cd9bb850 ^


76755b28 ^

672e3e50 ^
4690ce81 ^

67db19a0 ^
4bbd3ded ^






76755b28 ^

4690ce81 ^
cd9bb850 ^







f344b250 ^
cd9bb850 ^


76755b28 ^

4bbd3ded ^
4690ce81 ^

4bbd3ded ^
67db19a0 ^
4bbd3ded ^
672e3e50 ^


c5ffb6e1 ^

4690ce81 ^
a654e4ec ^

4690ce81 ^
c5ffb6e1 ^
4690ce81 ^




c5ffb6e1 ^

672e3e50 ^
4690ce81 ^
a654e4ec ^
4690ce81 ^
672e3e50 ^
32b8fac2 ^
a654e4ec ^
4690ce81 ^
a654e4ec ^
4690ce81 ^
a654e4ec ^
c5ffb6e1 ^

a654e4ec ^
d059fe74 ^
c5ffb6e1 ^
4690ce81 ^
cd9bb850 ^

beea7ce2 ^
cd9bb850 ^

a654e4ec ^
4690ce81 ^



4bbd3ded ^


4690ce81 ^

4bbd3ded ^
4690ce81 ^
9a81d746 ^
4690ce81 ^
2f02189d ^
4bbd3ded ^
4690ce81 ^
4bbd3ded ^
4690ce81 ^
4bbd3ded ^
c842d90b ^
4bbd3ded ^



76755b28 ^
4690ce81 ^

c5ffb6e1 ^
4690ce81 ^
c5ffb6e1 ^
4690ce81 ^

c5ffb6e1 ^
4690ce81 ^
c5ffb6e1 ^

76755b28 ^
4690ce81 ^

9a81d746 ^
4690ce81 ^
65361948 ^

4690ce81 ^
65361948 ^
4690ce81 ^
65361948 ^
c842d90b ^
672e3e50 ^

cd9bb850 ^

beea7ce2 ^
cd9bb850 ^

c5ffb6e1 ^

cd9bb850 ^



c5ffb6e1 ^

4690ce81 ^
c5ffb6e1 ^
4690ce81 ^



c5ffb6e1 ^




4690ce81 ^
c5ffb6e1 ^
4690ce81 ^

c5ffb6e1 ^




4690ce81 ^
c5ffb6e1 ^
4690ce81 ^

c5ffb6e1 ^



4690ce81 ^



c5ffb6e1 ^

4690ce81 ^
c5ffb6e1 ^
4690ce81 ^
672e3e50 ^

65361948 ^



76755b28 ^

4690ce81 ^
76755b28 ^

65361948 ^
4690ce81 ^
65361948 ^




4690ce81 ^
a654e4ec ^
4690ce81 ^
a654e4ec ^
4690ce81 ^
a654e4ec ^
4690ce81 ^
65361948 ^
32b8fac2 ^
a654e4ec ^
76755b28 ^
a654e4ec ^
d059fe74 ^
62a52ffb ^
d059fe74 ^
4690ce81 ^


dbe12410 ^
4bbd3ded ^
65361948 ^
62a52ffb ^
65361948 ^

672e3e50 ^


a654e4ec ^
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



                                                                                          
                                         

                                                
                                  

                                                                                         

                       
                                                                                                 
                                                                                            

                                      
                                
                             
                                  
                               
                            

                              
                               
                                                                           
                             

        





                               

       
                         

                                                                                                           


                                                                                                           
 




                                                                                                                                                                                                             

                                                             
                                                             
             
                                                                                                                            
       

                                                                                                                                                  






                                                                         
 
                                                         
 
                                                                     

                                                                                                    
             
                                                                                                                            
       
                                                                                                                                                                    
                                                                                                                                                       

                                                                                                                                                  






                                                                          
 
                                                         

                                                                   
                                                                   
             
                                                                                                                            
       



                                                                                                                                                                                                                           
   
                                                                       

                                       





                                                                                                       
                                                                                                        





                                                                         
                                                                                                      
                                       



                                                                          
 
                                                         
 
                                                                   
                                                                
                                                  
                                                                   
             
                                                                                                                            
       

                                                                                                                                                  







                                                                         
                                                                                                                  
 
                                                                         
                                                                
                                                  
                                                                                                    
                                                                         
             
                                                                                                                            
       

                                                                                                                                                                                                                      
   
                                                                                                        





                                                                         
                                                                                                        
 
                                               
                                                                                                                      
                                                                
                                        
                                                                                                                    
 

                                                                                            

                                                           





                                                                                                          
                                                                
                                                                                                                                                                                                                      
                                                                                                                                 

                                                                                                                                   


                                                                
                                                                                                                                                                                    
                                                     

                                                                            

                                                                                                  


                                                                                                                                                                                                                                                              
 
                                                                                                 
                                                                        
                                                                                         
                                                                                                                                                                                                                                   
                                                                                                                                      







                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                   

                                                                                                                                                                                                                                                                  

                                

                                                                           
                                                                           

                                                                                     
                                                                                                                                          
 



                                                                                      

                                                                                                                                                                                                                                        
                                                                                        



                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                    


                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

                                                                       
                                                                                         

                                                                                                                                                                              
                                                                                                                                                                                                                             






                                                                                                                                                                                                                                                                                                                                                      

                                                                                                                                                                                                                                                          
                                                                                                 







                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                                    


                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

                                                                       
                                                                                         

                                                                                                                                                                              
                                                                                                                                                                                                                             
                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     


                                                                       

                                                                                                     
                                                                                     

                                                                                                       
                                                                                                         
 




                                                                                                                                            

                                 
                                      
                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                          
                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                    

                                                                                                            
                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                       
                                                                                                        
                                                                                                                                                                                                                       

                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                            

                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      



                                                                                                                                                                                                                                                                                                                                                                                                 


                                                                                

                                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                       
                                                                                                                                                                                              
                                                                    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                                       
                                        
                                                                         
                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                        
                                                                                                                                                                                                              



                                                                              
                                                                                                                                         

                                                                                                                                                                                                                                          
                                                                     
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                      

                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                     
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

                                      
                                                                

                                                                                                                                                                                                                                                                        
                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

                                                     
                                                                       
                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                      
                                                                                                                                                                                                            

                                                                            

                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                            

                                                                            

                                                                                                      



                                                                                                                                                                                                                                                                               

                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
 



                                                                                                                                                                                                                                                                                                                                                                                                                                               




                                                                                                             
                                                                                                                             
                                                                                                                                                                      

                                                                                                                                                                                              




                                                                                         
                                                                                                                              
                                                                                                                                                                      

                                                                                                                                                                                              



                                                                                         



                                                                                                                                                                                                                                               

                                                  
                                                                                                                                                                                                                                                                                       
                                    
                                                                                                          

                                  



                                                                                      

                                                                                                                                                                                                                      
                                                                               

                                                                       
                                                                                         
                                                                               




                                                                       
                                                                                                              
                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                          
                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                            
                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                       
                                                                                   
                                                                                                                                                                                                                                                                                                        


                                                                                                                                                                                                                                                                                                              
                                                                                       
                                                                                                                                                                                           
                                    
                                                                                                                                                           

                                  


       
                                     
<!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 - 082scenario_screen.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<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-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.Constant { color: #00a0a0; }
.traceAbsent { color: #c00000; }
.cSpecial { color: #008000; }
.traceContains { color: #008000; }
.muScenario { color: #00af00; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.Special { color: #c00000; }
.Identifier { color: #c0a020; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.muRecipe { color: #ff8700; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Clean syntax to manipulate and check the screen in scenarios.</span>
<span class="Comment">//: Instructions 'assume-screen' and 'screen-should-contain' implicitly create</span>
<span class="Comment">//: a variable called 'screen' that is accessible to later instructions in the</span>
<span class="Comment">//: scenario. 'screen-should-contain' can check unicode characters in the fake</span>
<span class="Comment">//: screen</span>

<span class="Comment">//: first make sure we don't mangle these functions in other transforms</span>
<span class="Delimiter">:(before &quot;End initialize_transform_rewrite_literal_string_to_text()&quot;)</span>
recipes_taking_literal_strings<span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">&quot;screen-should-contain&quot;</span><span class="Delimiter">);</span>
recipes_taking_literal_strings<span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">&quot;screen-should-contain-in-color&quot;</span><span class="Delimiter">);</span>

<span class="Delimiter">:(scenarios run_mu_scenario)</span>
<span class="Delimiter">:(scenario screen_in_scenario)</span>
<span class="muScenario">scenario</span> screen-in-scenario [
  local-scope
  assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height
  run [
    <span class="Normal">a</span>:<span class="Normal">char</span><span class="Special"> &lt;- </span>copy <span class="Constant">97</span>/a
    <span class="Normal">screen</span>:&amp;:screen<span class="Special"> &lt;- </span>print screen:&amp;:screen<span class="Delimiter">,</span> a
  ]
  screen-should-contain [
  <span class="Comment">#  01234</span>
    <span class="Delimiter">.</span>a    <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
  ]
]
<span class="Comment"># checks are inside scenario</span>

<span class="Delimiter">:(scenario screen_in_scenario_unicode)</span>
<span class="Comment"># screen-should-contain can check unicode characters in the fake screen</span>
<span class="muScenario">scenario</span> screen-in-scenario-unicode [
  local-scope
  assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height
  run [
    <span class="Normal">lambda</span>:<span class="Normal">char</span><span class="Special"> &lt;- </span>copy <span class="Constant">955</span>/greek-small-lambda
    <span class="Normal">screen</span>:&amp;:screen<span class="Special"> &lt;- </span>print screen:&amp;:screen<span class="Delimiter">,</span> lambda
    <span class="Normal">a</span>:<span class="Normal">char</span><span class="Special"> &lt;- </span>copy <span class="Constant">97</span>/a
    <span class="Normal">screen</span>:&amp;:screen<span class="Special"> &lt;- </span>print screen:&amp;:screen<span class="Delimiter">,</span> a
  ]
  screen-should-contain [
  <span class="Comment">#  01234</span>
    <span class="Delimiter">.</span>λa   <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
  ]
]
<span class="Comment"># checks are inside scenario</span>

<span class="Delimiter">:(scenario screen_in_scenario_color)</span>
<span class="muScenario">scenario</span> screen-in-scenario-color [
  local-scope
  assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height
  run [
    <span class="Normal">lambda</span>:<span class="Normal">char</span><span class="Special"> &lt;- </span>copy <span class="Constant">955</span>/greek-small-lambda
    <span class="Normal">screen</span>:&amp;:screen<span class="Special"> &lt;- </span>print screen:&amp;:screen<span class="Delimiter">,</span> lambda<span class="Delimiter">,</span> <span class="Constant">1</span>/red
    <span class="Normal">a</span>:<span class="Normal">char</span><span class="Special"> &lt;- </span>copy <span class="Constant">97</span>/a
    <span class="Normal">screen</span>:&amp;:screen<span class="Special"> &lt;- </span>print screen:&amp;:screen<span class="Delimiter">,</span> a<span class="Delimiter">,</span> <span class="Constant">7</span>/white
  ]
  <span class="Comment"># screen-should-contain shows everything</span>
  screen-should-contain [
  <span class="Comment">#  01234</span>
    <span class="Delimiter">.</span>λa   <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
  ]
  <span class="Comment"># screen-should-contain-in-color filters out everything except the given</span>
  <span class="Comment"># color, all you see is the 'a' in white.</span>
  screen-should-contain-in-color <span class="Constant">7</span>/white<span class="Delimiter">,</span> [
  <span class="Comment">#  01234</span>
    <span class="Delimiter">.</span> a   <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
  ]
  <span class="Comment"># ..and the λ in red.</span>
  screen-should-contain-in-color <span class="Constant">1</span>/red<span class="Delimiter">,</span> [
  <span class="Comment">#  01234</span>
    <span class="Delimiter">.</span>λ    <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
  ]
]
<span class="Comment"># checks are inside scenario</span>

<span class="Delimiter">:(scenario screen_in_scenario_error)</span>
<span class="Special">% Scenario_testing_scenario = true;</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muScenario">scenario</span> screen-in-scenario-error [
  local-scope
  assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height
  run [
    <span class="Normal">a</span>:<span class="Normal">char</span><span class="Special"> &lt;- </span>copy <span class="Constant">97</span>/a
    <span class="Normal">screen</span>:&amp;:screen<span class="Special"> &lt;- </span>print screen:&amp;:screen<span class="Delimiter">,</span> a
  ]
  screen-should-contain [
  <span class="Comment">#  01234</span>
    <span class="Delimiter">.</span>b    <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
  ]
]
<span class="traceContains">+error: expected screen location (0, 0) to contain 98 ('b') instead of 97 ('a')</span>

<span class="Delimiter">:(scenario screen_in_scenario_color_error)</span>
<span class="Special">% Scenario_testing_scenario = true;</span>
<span class="Special">% Hide_errors = true;</span>
<span class="Comment"># screen-should-contain can check unicode characters in the fake screen</span>
<span class="muScenario">scenario</span> screen-in-scenario-color-error [
  local-scope
  assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height
  run [
    <span class="Normal">a</span>:<span class="Normal">char</span><span class="Special"> &lt;- </span>copy <span class="Constant">97</span>/a
    <span class="Normal">screen</span>:&amp;:screen<span class="Special"> &lt;- </span>print screen:&amp;:screen<span class="Delimiter">,</span> a<span class="Delimiter">,</span> <span class="Constant">1</span>/red
  ]
  screen-should-contain-in-color <span class="Constant">2</span>/green<span class="Delimiter">,</span> [
  <span class="Comment">#  01234</span>
    <span class="Delimiter">.</span>a    <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
    <span class="Delimiter">.</span>     <span class="Delimiter">.</span>
  ]
]
<span class="traceContains">+error: expected screen location (0, 0) to be in color 2 instead of 1</span>

<span class="Delimiter">:(scenarios run)</span>
<span class="Delimiter">:(scenario convert_names_does_not_fail_when_mixing_special_names_and_numeric_locations)</span>
<span class="Special">% Scenario_testing_scenario = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Normal">screen</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:num
]
<span class="traceAbsent">-error: mixing variable names and numeric addresses in main</span>
$error: <span class="Constant">0</span>
<span class="Delimiter">:(scenarios run_mu_scenario)</span>

<span class="Comment">//: It's easier to implement assume-screen and other similar scenario-only</span>
<span class="Comment">//: primitives if they always write to a fixed location. So we'll assign a</span>
<span class="Comment">//: single fixed location for the per-scenario screen, keyboard, file system,</span>
<span class="Comment">//: etc. Carve space for these fixed locations out of the reserved-for-test</span>
<span class="Comment">//: locations.</span>

<span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span class="Normal">extern</span> <span class="Normal">const</span> <span class="Normal">int</span> Max_variables_in_scenarios = Reserved_for_tests-<span class="Constant">100</span><span class="Delimiter">;</span>
<span class="Normal">int</span> Next_predefined_global_for_scenarios = Max_variables_in_scenarios<span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Setup&quot;)</span>
assert<span class="Delimiter">(</span>Next_predefined_global_for_scenarios &lt; Reserved_for_tests<span class="Delimiter">);</span>

<span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span class="Comment">// Scenario Globals.</span>
<span class="Normal">extern</span> <span class="Normal">const</span> <span class="Normal">int</span> SCREEN = Next_predefined_global_for_scenarios++<span class="Delimiter">;</span>
<span class="Comment">// End Scenario Globals.</span>

<span class="Comment">//: give 'screen' a fixed location in scenarios</span>
<span class="Delimiter">:(before &quot;End Special Scenario Variable Names(r)&quot;)</span>
Name[r][<span class="Constant">&quot;screen&quot;</span>] = SCREEN<span class="Delimiter">;</span>
<span class="Comment">//: make 'screen' always a raw location in scenarios</span>
<span class="Delimiter">:(before &quot;End is_special_name Cases&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">&quot;screen&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;End Rewrite Instruction(curr, recipe result)&quot;)</span>
<span class="Comment">// rewrite `assume-screen width, height` to</span>
<span class="Comment">// `screen:&amp;:screen &lt;- new-fake-screen width, height`</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">&quot;assume-screen&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
  curr<span class="Delimiter">.</span>name = <span class="Constant">&quot;new-fake-screen&quot;</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span>
    raise &lt;&lt; result<span class="Delimiter">.</span>name &lt;&lt; <span class="Constant">&quot;: 'assume-screen' has no products</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
  <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!starts_with<span class="Delimiter">(</span>result<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">&quot;scenario_&quot;</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; result<span class="Delimiter">.</span>name &lt;&lt; <span class="Constant">&quot;: 'assume-screen' can't be called here, only in scenarios</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
  <span class="Normal">else</span> <span class="Delimiter">{</span>
    assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
    curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">&quot;screen:&amp;:screen/raw&quot;</span><span class="Delimiter">));</span>
    curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>SCREEN<span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario assume_screen_shows_up_in_errors)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muScenario">scenario</span> assume-screen-shows-up-in-errors [
  assume-screen width<span class="Delimiter">,</span> <span class="Constant">5</span>
]
<span class="traceContains">+error: scenario_assume-screen-shows-up-in-errors: missing type for 'width' in 'assume-screen width, 5'</span>

<span class="Comment">//: screen-should-contain is a regular instruction</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
SCREEN_SHOULD_CONTAIN<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;screen-should-contain&quot;</span><span class="Delimiter">,</span> SCREEN_SHOULD_CONTAIN<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
<span class="Normal">case</span> SCREEN_SHOULD_CONTAIN: <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'screen-should-contain' requires exactly one ingredient, but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_literal_text<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;first ingredient of 'screen-should-contain' should be a literal string, but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> SCREEN_SHOULD_CONTAIN: <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
  assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)));</span>
  check_screen<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">,</span> -<span class="Constant">1</span><span class="Delimiter">);</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
SCREEN_SHOULD_CONTAIN_IN_COLOR<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;screen-should-contain-in-color&quot;</span><span class="Delimiter">,</span> SCREEN_SHOULD_CONTAIN_IN_COLOR<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
<span class="Normal">case</span> SCREEN_SHOULD_CONTAIN_IN_COLOR: <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'screen-should-contain-in-color' requires exactly two ingredients, but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;first ingredient of 'screen-should-contain-in-color' should be a number (color code), but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_literal_text<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;second ingredient of 'screen-should-contain-in-color' should be a literal string, but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> SCREEN_SHOULD_CONTAIN_IN_COLOR: <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
  assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)));</span>
  assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)));</span>
  check_screen<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">,</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(before &quot;End Types&quot;)</span>
<span class="Comment">// scan an array of characters in a unicode-aware, bounds-checked manner</span>
<span class="Normal">struct</span> raw_string_stream <span class="Delimiter">{</span>
  <span class="Normal">int</span> index<span class="Delimiter">;</span>
  <span class="Normal">const</span> <span class="Normal">int</span> max<span class="Delimiter">;</span>
  <span class="Normal">const</span> <span class="Normal">char</span>* buf<span class="Delimiter">;</span>

  raw_string_stream<span class="Delimiter">(</span><span class="Normal">const</span> string&amp;<span class="Delimiter">);</span>
  <span class="Normal">uint32_t</span> get<span class="Delimiter">();</span>  <span class="Comment">// unicode codepoint</span>
  <span class="Normal">uint32_t</span> peek<span class="Delimiter">();</span>  <span class="Comment">// unicode codepoint</span>
  <span class="Normal">bool</span> at_end<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span>
  <span class="Normal">void</span> skip_whitespace_and_comments<span class="Delimiter">();</span>
<span class="Delimiter">};</span>

<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> check_screen<span class="Delimiter">(</span><span class="Normal">const</span> string&amp; expected_contents<span class="Delimiter">,</span> <span class="Normal">const</span> <span class="Normal">int</span> color<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">int</span> screen_location = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> SCREEN<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span>
  <span class="Normal">int</span> data_offset = find_element_name<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;screen&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;data&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  assert<span class="Delimiter">(</span>data_offset &gt;= <span class="Constant">0</span><span class="Delimiter">);</span>
  <span class="Normal">int</span> screen_data_location = screen_location+data_offset<span class="Delimiter">;</span>  <span class="Comment">// type: address:array:character</span>
  <span class="Normal">int</span> screen_data_start = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> screen_data_location<span class="Delimiter">)</span> + <span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span>  <span class="Comment">// type: array:character</span>
  <span class="Normal">int</span> width_offset = find_element_name<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;screen&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;num-columns&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  <span class="Normal">int</span> screen_width = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> screen_location+width_offset<span class="Delimiter">);</span>
  <span class="Normal">int</span> height_offset = find_element_name<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;screen&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;num-rows&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  <span class="Normal">int</span> screen_height = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> screen_location+height_offset<span class="Delimiter">);</span>
  raw_string_stream cursor<span class="Delimiter">(</span>expected_contents<span class="Delimiter">);</span>
  <span class="Comment">// todo: too-long expected_contents should fail</span>
  <span class="Normal">int</span> addr = screen_data_start+<span class="Comment">/*</span><span class="Comment">skip length</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> row = <span class="Constant">0</span><span class="Delimiter">;</span>  row &lt; screen_height<span class="Delimiter">;</span>  ++row<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    cursor<span class="Delimiter">.</span>skip_whitespace_and_comments<span class="Delimiter">();</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>cursor<span class="Delimiter">.</span>at_end<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>cursor<span class="Delimiter">.</span>get<span class="Delimiter">()</span> != <span class="Constant">'.'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      raise &lt;&lt; Current_scenario<span class="Delimiter">-&gt;</span>name &lt;&lt; <span class="Constant">&quot;: each row of the expected screen should start with a '.'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span>
      <span class="Identifier">return</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> column = <span class="Constant">0</span><span class="Delimiter">;</span>  column &lt; screen_width<span class="Delimiter">;</span>  ++column<span class="Delimiter">,</span> addr+= <span class="Comment">/*</span><span class="Comment">size of screen-cell</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      <span class="Normal">const</span> <span class="Normal">int</span> cell_color_offset = <span class="Constant">1</span><span class="Delimiter">;</span>
      <span class="Normal">uint32_t</span> curr = cursor<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">)</span> == <span class="Constant">0</span> &amp;&amp; isspace<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>curr == <span class="Constant">' '</span> &amp;&amp; color != -<span class="Constant">1</span> &amp;&amp; color != get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr+cell_color_offset<span class="Delimiter">))</span> <span class="Delimiter">{</span>
        <span class="Comment">// filter out other colors</span>
        <span class="Identifier">continue</span><span class="Delimiter">;</span>
      <span class="Delimiter">}</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">)</span> != <span class="Constant">0</span> &amp;&amp; get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">)</span> == curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
        <span class="Normal">if</span> <span class="Delimiter">(</span>color == -<span class="Constant">1</span> || color == get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr+cell_color_offset<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
        <span class="Comment">// contents match but color is off</span>
        <span class="Normal">if</span> <span class="Delimiter">(</span>Current_scenario &amp;&amp; !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span>
          <span class="Comment">// genuine test in a .mu file</span>
          raise &lt;&lt; <span class="Constant">&quot;</span><span class="cSpecial">\n</span><span class="Constant">F - &quot;</span> &lt;&lt; Current_scenario<span class="Delimiter">-&gt;</span>name &lt;&lt; <span class="Constant">&quot;: expected screen location (&quot;</span> &lt;&lt; row &lt;&lt; <span class="Constant">&quot;, &quot;</span> &lt;&lt; column &lt;&lt; <span class="Constant">&quot;, address &quot;</span> &lt;&lt; addr &lt;&lt; <span class="Constant">&quot;, value &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot;) to be in color &quot;</span> &lt;&lt; color &lt;&lt; <span class="Constant">&quot; instead of &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr+cell_color_offset<span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot;</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
          dump_screen<span class="Delimiter">();</span>
        <span class="Delimiter">}</span>
        <span class="Normal">else</span> <span class="Delimiter">{</span>
          <span class="Comment">// just testing check_screen</span>
          raise &lt;&lt; <span class="Constant">&quot;expected screen location (&quot;</span> &lt;&lt; row &lt;&lt; <span class="Constant">&quot;, &quot;</span> &lt;&lt; column &lt;&lt; <span class="Constant">&quot;) to be in color &quot;</span> &lt;&lt; color &lt;&lt; <span class="Constant">&quot; instead of &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr+cell_color_offset<span class="Delimiter">))</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
        <span class="Delimiter">}</span>
        <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span>
        <span class="Identifier">return</span><span class="Delimiter">;</span>
      <span class="Delimiter">}</span>

      <span class="Comment">// really a mismatch</span>
      <span class="Comment">// can't print multi-byte unicode characters in errors just yet. not very useful for debugging anyway.</span>
      <span class="Normal">char</span> expected_pretty[<span class="Constant">10</span>] = <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">};</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>curr &lt; <span class="Constant">256</span> &amp;&amp; !iscntrl<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Delimiter">{</span>
        <span class="Comment">// &quot; ('&lt;curr&gt;')&quot;</span>
        expected_pretty[<span class="Constant">0</span>] = <span class="Constant">' '</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">1</span>] = <span class="Constant">'('</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">2</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">3</span>] = <span class="Normal">static_cast</span>&lt;<span class="Normal">unsigned</span> <span class="Normal">char</span>&gt;<span class="Delimiter">(</span>curr<span class="Delimiter">),</span> expected_pretty[<span class="Constant">4</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">5</span>] = <span class="Constant">')'</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">6</span>] = <span class="cSpecial">'\0'</span><span class="Delimiter">;</span>
      <span class="Delimiter">}</span>
      <span class="Normal">char</span> actual_pretty[<span class="Constant">10</span>] = <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">};</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">)</span> &lt; <span class="Constant">256</span> &amp;&amp; !iscntrl<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">)))</span> <span class="Delimiter">{</span>
        <span class="Comment">// &quot; ('&lt;curr&gt;')&quot;</span>
        actual_pretty[<span class="Constant">0</span>] = <span class="Constant">' '</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">1</span>] = <span class="Constant">'('</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">2</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">3</span>] = <span class="Normal">static_cast</span>&lt;<span class="Normal">unsigned</span> <span class="Normal">char</span>&gt;<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">)),</span> actual_pretty[<span class="Constant">4</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">5</span>] = <span class="Constant">')'</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">6</span>] = <span class="cSpecial">'\0'</span><span class="Delimiter">;</span>
      <span class="Delimiter">}</span>

      ostringstream color_phrase<span class="Delimiter">;</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>color != -<span class="Constant">1</span><span class="Delimiter">)</span> color_phrase &lt;&lt; <span class="Constant">&quot; in color &quot;</span> &lt;&lt; color<span class="Delimiter">;</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>Current_scenario &amp;&amp; !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span>
        <span class="Comment">// genuine test in a .mu file</span>
        raise &lt;&lt; <span class="Constant">&quot;</span><span class="cSpecial">\n</span><span class="Constant">F - &quot;</span> &lt;&lt; Current_scenario<span class="Delimiter">-&gt;</span>name &lt;&lt; <span class="Constant">&quot;: expected screen location (&quot;</span> &lt;&lt; row &lt;&lt; <span class="Constant">&quot;, &quot;</span> &lt;&lt; column &lt;&lt; <span class="Constant">&quot;) to contain &quot;</span> &lt;&lt; curr &lt;&lt; expected_pretty &lt;&lt; color_phrase<span class="Delimiter">.</span>str<span class="Delimiter">()</span> &lt;&lt; <span class="Constant">&quot; instead of &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">))</span> &lt;&lt; actual_pretty &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
        dump_screen<span class="Delimiter">();</span>
      <span class="Delimiter">}</span>
      <span class="Normal">else</span> <span class="Delimiter">{</span>
        <span class="Comment">// just testing check_screen</span>
        raise &lt;&lt; <span class="Constant">&quot;expected screen location (&quot;</span> &lt;&lt; row &lt;&lt; <span class="Constant">&quot;, &quot;</span> &lt;&lt; column &lt;&lt; <span class="Constant">&quot;) to contain &quot;</span> &lt;&lt; curr &lt;&lt; expected_pretty &lt;&lt; color_phrase<span class="Delimiter">.</span>str<span class="Delimiter">()</span> &lt;&lt; <span class="Constant">&quot; instead of &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> addr<span class="Delimiter">))</span> &lt;&lt; actual_pretty &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
      <span class="Delimiter">}</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span>
      <span class="Identifier">return</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>cursor<span class="Delimiter">.</span>get<span class="Delimiter">()</span> != <span class="Constant">'.'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      raise &lt;&lt; Current_scenario<span class="Delimiter">-&gt;</span>name &lt;&lt; <span class="Constant">&quot;: row &quot;</span> &lt;&lt; row &lt;&lt; <span class="Constant">&quot; of the expected screen is too long</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span>
      <span class="Identifier">return</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  cursor<span class="Delimiter">.</span>skip_whitespace_and_comments<span class="Delimiter">();</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!cursor<span class="Delimiter">.</span>at_end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
    raise &lt;&lt; Current_scenario<span class="Delimiter">-&gt;</span>name &lt;&lt; <span class="Constant">&quot;: expected screen has too many rows</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    Passed = <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

raw_string_stream::raw_string_stream<span class="Delimiter">(</span><span class="Normal">const</span> string&amp; backing<span class="Delimiter">)</span> :index<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> max<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>backing<span class="Delimiter">)),</span> buf<span class="Delimiter">(</span>backing<span class="Delimiter">.</span>c_str<span class="Delimiter">())</span> <span class="Delimiter">{}</span>

<span class="Normal">bool</span> raw_string_stream::at_end<span class="Delimiter">()</span> <span class="Normal">const</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>index &gt;= max<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>tb_utf8_char_length<span class="Delimiter">(</span>buf[index]<span class="Delimiter">)</span> &gt; max-index<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise &lt;&lt; <span class="Constant">&quot;unicode string seems corrupted at index &quot;</span>&lt;&lt; index &lt;&lt; <span class="Constant">&quot; character &quot;</span> &lt;&lt; <span class="Normal">static_cast</span>&lt;<span class="Normal">int</span>&gt;<span class="Delimiter">(</span>buf[index]<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">uint32_t</span> raw_string_stream::get<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  assert<span class="Delimiter">(</span>index &lt; max<span class="Delimiter">);</span>  <span class="Comment">// caller must check bounds before calling 'get'</span>
  <span class="Normal">uint32_t</span> result = <span class="Constant">0</span><span class="Delimiter">;</span>
  <span class="Normal">int</span> length = tb_utf8_char_to_unicode<span class="Delimiter">(</span>&amp;result<span class="Delimiter">,</span> &amp;buf[index]<span class="Delimiter">);</span>
  assert<span class="Delimiter">(</span>length != TB_EOF<span class="Delimiter">);</span>
  index += length<span class="Delimiter">;</span>
  <span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">uint32_t</span> raw_string_stream::peek<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  assert<span class="Delimiter">(</span>index &lt; max<span class="Delimiter">);</span>  <span class="Comment">// caller must check bounds before calling 'get'</span>
  <span class="Normal">uint32_t</span> result = <span class="Constant">0</span><span class="Delimiter">;</span>
  <span class="Normal">int</span> length = tb_utf8_char_to_unicode<span class="Delimiter">(</span>&amp;result<span class="Delimiter">,</span> &amp;buf[index]<span class="Delimiter">);</span>
  assert<span class="Delimiter">(</span>length != TB_EOF<span class="Delimiter">);</span>
  <span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> raw_string_stream::skip_whitespace_and_comments<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  <span class="Normal">while</span> <span class="Delimiter">(</span>!at_end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>peek<span class="Delimiter">()))</span> get<span class="Delimiter">();</span>
    <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      <span class="Comment">// skip comment</span>
      get<span class="Delimiter">();</span>
      <span class="Normal">while</span> <span class="Delimiter">(</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> get<span class="Delimiter">();</span>  <span class="Comment">// implicitly also handles CRLF</span>
    <span class="Delimiter">}</span>
    <span class="Normal">else</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
_DUMP_SCREEN<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;$dump-screen&quot;</span><span class="Delimiter">,</span> _DUMP_SCREEN<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
<span class="Normal">case</span> _DUMP_SCREEN: <span class="Delimiter">{</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> _DUMP_SCREEN: <span class="Delimiter">{</span>
  dump_screen<span class="Delimiter">();</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> dump_screen<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  <span class="Normal">int</span> screen_location = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> SCREEN<span class="Delimiter">)</span> + <span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span>
  <span class="Normal">int</span> width_offset = find_element_name<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;screen&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;num-columns&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  <span class="Normal">int</span> screen_width = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> screen_location+width_offset<span class="Delimiter">);</span>
  <span class="Normal">int</span> height_offset = find_element_name<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;screen&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;num-rows&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  <span class="Normal">int</span> screen_height = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> screen_location+height_offset<span class="Delimiter">);</span>
  <span class="Normal">int</span> data_offset = find_element_name<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;screen&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;data&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  assert<span class="Delimiter">(</span>data_offset &gt;= <span class="Constant">0</span><span class="Delimiter">);</span>
  <span class="Normal">int</span> screen_data_location = screen_location+data_offset<span class="Delimiter">;</span>  <span class="Comment">// type: address:array:character</span>
  <span class="Normal">int</span> screen_data_start = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> screen_data_location<span class="Delimiter">)</span> + <span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span>  <span class="Comment">// type: array:character</span>
  assert<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> screen_data_start<span class="Delimiter">)</span> == screen_width*screen_height<span class="Delimiter">);</span>
  <span class="Normal">int</span> curr = screen_data_start+<span class="Constant">1</span><span class="Delimiter">;</span>  <span class="Comment">// skip length</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> row = <span class="Constant">0</span><span class="Delimiter">;</span>  row &lt; screen_height<span class="Delimiter">;</span>  ++row<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    cerr &lt;&lt; <span class="Constant">'.'</span><span class="Delimiter">;</span>
    <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> col = <span class="Constant">0</span><span class="Delimiter">;</span>  col &lt; screen_width<span class="Delimiter">;</span>  ++col<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr<span class="Delimiter">))</span>
        cerr &lt;&lt; to_unicode<span class="Delimiter">(</span><span class="Normal">static_cast</span>&lt;<span class="Normal">uint32_t</span>&gt;<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr<span class="Delimiter">)));</span>
      <span class="Normal">else</span>
        cerr &lt;&lt; <span class="Constant">' '</span><span class="Delimiter">;</span>
      curr += <span class="Comment">/*</span><span class="Comment">size of screen-cell</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    cerr &lt;&lt; <span class="Constant">&quot;.</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->