about summary refs log tree commit diff stats
path: root/065write-buffered.subx
blob: 2361ea3df527ded1e3757b13d433b020814a2719 (plain) (blame)
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
> ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                                                 
                             



                                   
                                  
                                                                           
                               





































                                                                                                          
                                                          






                                                                                                           
                                        

                                                                                                                             
                                                                                                  
                                                                                                                                









                                                                                                    
                                        

                                                                                                                             




                                                                                         



                                                                       
                                        

                                                                                                                             

                                                               
                                                                                                            
 








                                                                                                                                








                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         







                                                                                                                                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                  

                                
                                                                                                                                                                                                                                                  







                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             





                                                                                                                                                                                                                                                                                                                                                                         



                                                                                                                                     
                                                                                                                                    







                                                                                                                                                                                                                
                                                                                  
                                                                                                                                    




















                                                                                                                                                                                                                                                             

                                                                                                                                                                                                                                                          














                                                                                                                                                                                                                              


                                                                                                                                                                                                             




                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       









                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                              












                                                                                                                                                                                                                                  
                                        

                                                                                                                               

                                                                                                               
                                                                                                                                                                                                        



                                                                 
                                        

                                                                                                                               


                                                                                                                             
                                                                                                                                                                                                                       



                                                                       
                                        

                                                                                                                               

                                                                                                               
                                                                                                                                                                                                            










                                                                                                                                                                                                                           
                                        

                                                                                                                               

                                                                                                               
                                                                                                                                                                                                                                                                                          









                                                                                                                                                                                                                          

                                                                        
                                        

                                                                                                                               

                                                                                                               
                                                                                                                                                                                                                                                                                   












                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

                                                    

                                                                                                                                                      
 
                                                                                                                       




                                                                                     
                                        
                                                         





                                                                                                                                            





                                                                 
                                                                
                                        


                                                                                                                                                                                                                        






                                                                                                                                                                                                                           

                                                         
                                        
                                                         





                                                                                                                                                                                                       















                                                                                                                                                                                                                           
                                        
                                                         





                                                                                                                                                                                                                                                                                                 



                                                                  
                                        




                                                                                                                             
                                                         

                                                                                                                                                                                                                                                                                                                                                      


                                                                 

                                                                              
                                        
                                                         





                                                                                                                                                                                                                                                                                          
 
                                                                                                                                                            










                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                          
                                        
                                                                                                                                                                                                                                                                                                        
                                                                                                                                                          


                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
















                                                                                                                                                                                                                         
                                        
                                                         





                                                                                                                                        








                                                                                                                                                                                                                         
                                        


                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                                                          




                                                                   
                                        


                                                                                                                                                                                                                               
                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         




                                                                   
                                        


                                                                                                                                                                                                                               
                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                         


















                                                                                                                                                                                                                           
                                        












                                                                                                                                                                                                                                             
                                        









                                                                                                                                
                                                                                                                                                                                                                                                                 













































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
<!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 - 035lookup.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; }
.muRecipe { color: #ff8700; }
.SalientComment { color: #00ffff; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.Special { color: #c00000; }
.traceContains { color: #008000; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.Identifier { color: #c0a020; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Go from an address to the payload it points at (skipping the refcount)</span>
<span class="Comment">//: using /lookup.</span>
<span class="Comment">//:</span>
<span class="Comment">//: Let's say we have this address (read the top of the address layer for</span>
<span class="Comment">//: details on these diagrams):</span>
<span class="Comment">//:</span>
<span class="Comment">//:                     +---+------------+</span>
<span class="Comment">//:          x -------&gt; | 1 |  number    |</span>
<span class="Comment">//:                     +---+------------+</span>
<span class="Comment">//:</span>
<span class="Comment">//: Once you have an address you can read or modify its payload by performing</span>
<span class="Comment">//: a lookup:</span>
<span class="Comment">//:</span>
<span class="Comment">//:     x/lookup &lt;- copy 34</span>
<span class="Comment">//:</span>
<span class="Comment">//: or more concisely:</span>
<span class="Comment">//:</span>
<span class="Comment">//:     *x &lt;- copy 34</span>
<span class="Comment">//:</span>
<span class="Comment">//: This modifies not x, but the payload x points to:</span>
<span class="Comment">//:</span>
<span class="Comment">//:                     +---+------------+</span>
<span class="Comment">//:          x -------&gt; | 1 |         34 |</span>
<span class="Comment">//:                     +---+------------+</span>
<span class="Comment">//:</span>
<span class="Comment">//: You can also read from the payload in instructions like this:</span>
<span class="Comment">//:</span>
<span class="Comment">//:     z:num &lt;- add *x, 1</span>
<span class="Comment">//:</span>
<span class="Comment">//: After this instruction runs the value of z will be 35.</span>
<span class="Comment">//:</span>
<span class="Comment">//: The tests in this layer use unsafe operations so as to stay decoupled from</span>
<span class="Comment">//: 'new'.</span>

<span class="Delimiter">:(scenario copy_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Comment"># This loads location 1 as an address and looks up *that* location.</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:address:num/lookup
]
<span class="Comment"># 1 contains 10. Skip refcount and lookup location 11.</span>
<span class="traceContains">+mem: storing 34 in location 2</span>

<span class="Delimiter">:(before &quot;End Preprocess read_memory(x)&quot;)</span>
canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>

<span class="Comment">//: similarly, write to addresses pointing at other locations using the</span>
<span class="Comment">//: 'lookup' property</span>
<span class="Delimiter">:(scenario store_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">1</span>:address:num/lookup<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
]
<span class="traceContains">+mem: storing 34 in location 11</span>

<span class="Delimiter">:(before &quot;End Preprocess write_memory(x, data)&quot;)</span>
canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>

<span class="Comment">//: writes to address 0 always loudly fail</span>
<span class="Delimiter">:(scenario store_to_0_fails)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">1</span>:address:num/lookup<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
]
<span class="traceAbsent">-mem: storing 34 in location 0</span>
<span class="traceContains">+error: can't write to location 0 in '1:address:num/lookup &lt;- copy 34'</span>

<span class="Comment">//: attempts to /lookup address 0 always loudly fail</span>
<span class="Delimiter">:(scenario lookup_0_fails)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:address:num/lookup
]
<span class="traceContains">+error: tried to /lookup 0 in '2:num &lt;- copy 1:address:num/lookup'</span>

<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> canonize<span class="Delimiter">(</span>reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  <span class="Comment">// End canonize(x) Special-cases</span>
  <span class="Normal">while</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">&quot;lookup&quot;</span><span class="Delimiter">))</span>
    lookup_memory<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> lookup_memory<span class="Delimiter">(</span>reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type || x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>atom || x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;address&quot;</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;tried to /lookup '&quot;</span> &lt;&lt; x<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;' but it isn't an address</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">return</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Comment">// compute value</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;tried to /lookup 0</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">return</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  lookup_memory_core<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">check_for_null</span><span class="Comment">*/</span><span class="Constant">true</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> lookup_memory_core<span class="Delimiter">(</span>reagent&amp; x<span class="Delimiter">,</span> <span class="Normal">bool</span> check_for_null<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;location &quot;</span> &lt;&lt; x<span class="Delimiter">.</span>value &lt;&lt; <span class="Constant">&quot; is &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> x<span class="Delimiter">.</span>value<span class="Delimiter">))</span> &lt;&lt; end<span class="Delimiter">();</span>
  x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> x<span class="Delimiter">.</span>value<span class="Delimiter">));</span>
  drop_from_type<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">&quot;address&quot;</span><span class="Delimiter">);</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;skipping refcount at &quot;</span> &lt;&lt; x<span class="Delimiter">.</span>value &lt;&lt; end<span class="Delimiter">();</span>
    x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value+<span class="Constant">1</span><span class="Delimiter">);</span>  <span class="Comment">// skip refcount</span>
  <span class="Delimiter">}</span>
  <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>check_for_null<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">)</span>
      raise &lt;&lt; <span class="Constant">&quot;tried to /lookup 0 in '&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>current_instruction<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>
    <span class="Normal">else</span>
      raise &lt;&lt; <span class="Constant">&quot;tried to /lookup 0</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
  drop_one_lookup<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_lookup_address_skips_refcount<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  reagent x<span class="Delimiter">(</span><span class="Constant">&quot;*x:address:num&quot;</span><span class="Delimiter">);</span>
  x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span><span class="Constant">34</span><span class="Delimiter">);</span>  <span class="Comment">// unsafe</span>
  put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">1000</span><span class="Delimiter">);</span>
  lookup_memory<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
  CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">&quot;mem: skipping refcount at 1000&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">,</span> <span class="Constant">1001</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_lookup_zero_address_does_not_skip_refcount<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span>
  reagent x<span class="Delimiter">(</span><span class="Constant">&quot;*x:address:num&quot;</span><span class="Delimiter">);</span>
  x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span><span class="Constant">34</span><span class="Delimiter">);</span>  <span class="Comment">// unsafe</span>
  put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
  lookup_memory<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
  CHECK_TRACE_DOESNT_CONTAIN<span class="Delimiter">(</span><span class="Constant">&quot;mem: skipping refcount at 0&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(before &quot;End Preprocess types_strictly_match(reagent to, reagent from)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>to<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>from<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;End Preprocess is_mu_array(reagent r)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;End Preprocess is_mu_address(reagent r)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;End Preprocess is_mu_number(reagent r)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Preprocess is_mu_boolean(reagent r)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Preprocess is_mu_character(reagent r)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>

<span class="Delimiter">:(after &quot;Update product While Type-checking Merge&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;End Compute Call Ingredient&quot;)</span>
canonize_type<span class="Delimiter">(</span>ingredient<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Preprocess NEXT_INGREDIENT product&quot;)</span>
canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Check RETURN Copy(lhs, rhs)</span>
canonize_type<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span>
canonize_type<span class="Delimiter">(</span>rhs<span class="Delimiter">);</span>

<span class="Delimiter">:(before &quot;Compute Container Size(reagent rcopy)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>rcopy<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;Compute Container Size(element, full_type)&quot;)</span>
assert<span class="Delimiter">(</span>!has_property<span class="Delimiter">(</span>element<span class="Delimiter">,</span> <span class="Constant">&quot;lookup&quot;</span><span class="Delimiter">));</span>
<span class="Delimiter">:(before &quot;Compute Exclusive Container Size(element, full_type)&quot;)</span>
assert<span class="Delimiter">(</span>!has_property<span class="Delimiter">(</span>element<span class="Delimiter">,</span> <span class="Constant">&quot;lookup&quot;</span><span class="Delimiter">));</span>

<span class="Delimiter">:(code)</span>
<span class="Normal">bool</span> canonize_type<span class="Delimiter">(</span>reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">while</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">&quot;lookup&quot;</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type || r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>atom || !r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>left || !r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>atom || r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;address&quot;</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
      raise &lt;&lt; <span class="Constant">&quot;can't lookup non-address: '&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>r<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;': '&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<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>
      <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    drop_from_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">&quot;address&quot;</span><span class="Delimiter">);</span>
    drop_one_lookup<span class="Delimiter">(</span>r<span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> drop_one_lookup<span class="Delimiter">(</span>reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span>vector&lt;pair&lt;string<span class="Delimiter">,</span> string_tree*&gt; &gt;::iterator p = r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>begin<span class="Delimiter">();</span>  p != r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>end<span class="Delimiter">();</span>  ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-&gt;</span>first == <span class="Constant">&quot;lookup&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>p<span class="Delimiter">);</span>
      <span class="Identifier">return</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Comment">//: Tedious fixup to support addresses in container/array instructions of previous layers.</span>
<span class="Comment">//: Most instructions don't require fixup if they use the 'ingredients' and</span>
<span class="Comment">//: 'products' variables in run_current_routine().</span>

<span class="Delimiter">:(scenario get_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">35</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>get <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0:offset</span>
]
<span class="traceContains">+mem: storing 34 in location 2</span>

<span class="Delimiter">:(scenario get_indirect2)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">35</span>
  <span class="Constant">2</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">20</span>/unsafe
  <span class="Constant">2</span>:address:num/lookup<span class="Special"> &lt;- </span>get <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0:offset</span>
]
<span class="traceContains">+mem: storing 34 in location 21</span>

<span class="Delimiter">:(scenario include_nonlookup_properties)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">35</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>get <span class="Constant">1</span>:address:point/lookup/foo<span class="Delimiter">,</span> <span class="Constant">0:offset</span>
]
<span class="traceContains">+mem: storing 34 in location 2</span>

<span class="Delimiter">:(after &quot;Update GET base in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after &quot;Update GET product in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after &quot;Update GET base in Run&quot;)</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>

<span class="Delimiter">:(scenario put_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">35</span>
  <span class="Constant">1</span>:address:point/lookup<span class="Special"> &lt;- </span>put <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0:offset</span><span class="Delimiter">,</span> <span class="Constant">36</span>
]
<span class="traceContains">+mem: storing 36 in location 11</span>

<span class="Delimiter">:(after &quot;Update PUT base in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after &quot;Update PUT offset in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>offset<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after &quot;Update PUT base in Run&quot;)</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>

<span class="Delimiter">:(scenario put_product_error_with_lookup)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">35</span>
  <span class="Constant">1</span>:address:point<span class="Special"> &lt;- </span>put <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">x:offset</span><span class="Delimiter">,</span> <span class="Constant">36</span>
]
<span class="traceContains">+error: main: product of 'put' must be first ingredient '1:address:point/lookup', but got '1:address:point'</span>

<span class="Delimiter">:(before &quot;End PUT Product Checks&quot;)</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> p = inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>p<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>  <span class="Comment">// error raised elsewhere</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> i = 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="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>i<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>  <span class="Comment">// error raised elsewhere</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>p<span class="Delimiter">,</span> i<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;product of 'put' must be first ingredient '&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;', but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>products<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="Delimiter">:(scenario new_error)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:num/<span class="Special">raw &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
]
<span class="traceContains">+error: main: product of 'new' has incorrect type: '1:num/raw &lt;- new number:type'</span>

<span class="Delimiter">:(after &quot;Update NEW product in Check&quot;)</span>
canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">);</span>

<span class="Delimiter">:(scenario copy_array_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> &lt;- </span>create-array
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">14</span>
  <span class="Constant">13</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">15</span>
  <span class="Constant">14</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">16</span>
  <span class="Constant">1</span>:address:array:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">2</span>:array:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:address:array:num/lookup
]
<span class="traceContains">+mem: storing 3 in location 2</span>
<span class="traceContains">+mem: storing 14 in location 3</span>
<span class="traceContains">+mem: storing 15 in location 4</span>
<span class="traceContains">+mem: storing 16 in location 5</span>

<span class="Delimiter">:(scenario create_array_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1000</span>:num/<span class="Special">raw &lt;- </span>copy <span class="Constant">1</span>  <span class="Comment"># pretend refcount</span>
  <span class="Constant">1</span>:address:array:num:<span class="Constant">3</span><span class="Special"> &lt;- </span>copy <span class="Constant">1000</span>/unsafe  <span class="Comment"># pretend allocation</span>
  <span class="Constant">1</span>:address:array:num:<span class="Constant">3</span>/lookup<span class="Special"> &lt;- </span>create-array
]
<span class="traceContains">+mem: storing 3 in location 1001</span>

<span class="Delimiter">:(after &quot;Update CREATE_ARRAY product in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after &quot;Update CREATE_ARRAY product in Run&quot;)</span>
canonize<span class="Delimiter">(</span>product<span class="Delimiter">);</span>

<span class="Delimiter">:(scenario index_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> &lt;- </span>create-array
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">14</span>
  <span class="Constant">13</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">15</span>
  <span class="Constant">14</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">16</span>
  <span class="Constant">1</span>:address:array:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>index <span class="Constant">1</span>:address:array:num/lookup<span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+mem: storing 15 in location 2</span>

<span class="Delimiter">:(before &quot;Update INDEX base in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;Update INDEX index in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>index<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;Update INDEX product in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;Update INDEX base in Run&quot;)</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;Update INDEX index in Run&quot;)</span>
canonize<span class="Delimiter">(</span>index<span class="Delimiter">);</span>

<span class="Delimiter">:(scenario put_index_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> &lt;- </span>create-array
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">14</span>
  <span class="Constant">13</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">15</span>
  <span class="Constant">14</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">16</span>
  <span class="Constant">1</span>:address:array:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">1</span>:address:array:num/lookup<span class="Special"> &lt;- </span>put-index <span class="Constant">1</span>:address:array:num/lookup<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="traceContains">+mem: storing 34 in location 13</span>

<span class="Delimiter">:(scenario put_index_indirect_2)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Special"> &lt;- </span>create-array
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">14</span>
  <span class="Constant">3</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">15</span>
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">16</span>
  <span class="Constant">5</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>
  <span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Special"> &lt;- </span>put-index <span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">5</span>:address:num/lookup<span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="traceContains">+mem: storing 34 in location 3</span>

<span class="Delimiter">:(scenario put_index_product_error_with_lookup)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> &lt;- </span>create-array
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">14</span>
  <span class="Constant">13</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">15</span>
  <span class="Constant">14</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">16</span>
  <span class="Constant">1</span>:address:array:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">1</span>:address:array:num<span class="Special"> &lt;- </span>put-index <span class="Constant">1</span>:address:array:num/lookup<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="traceContains">+error: main: product of 'put-index' must be first ingredient '1:address:array:num/lookup', but got '1:address:array:num'</span>

<span class="Delimiter">:(before &quot;End PUT_INDEX Product Checks&quot;)</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> p = inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>p<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>  <span class="Comment">// error raised elsewhere</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> i = 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="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>i<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>  <span class="Comment">// error raised elsewhere</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>p<span class="Delimiter">,</span> i<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;product of 'put-index' must be first ingredient '&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;', but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>products<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="Delimiter">:(scenario dilated_reagent_in_static_array)</span>
<span class="muRecipe">def</span> main [
  <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>array <span class="Delimiter">(</span>address number<span class="Delimiter">)</span> <span class="Constant">3</span><span class="Delimiter">)}</span><span class="Special"> &lt;- </span>create-array
  <span class="Constant">5</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>array <span class="Delimiter">(</span>address number<span class="Delimiter">)</span> <span class="Constant">3</span><span class="Delimiter">)}</span><span class="Special"> &lt;- </span>put-index <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>array <span class="Delimiter">(</span>address number<span class="Delimiter">)</span> <span class="Constant">3</span><span class="Delimiter">)},</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">5</span>:address:num
  *<span class="Constant">5</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">6</span>:num<span class="Special"> &lt;- </span>copy *<span class="Constant">5</span>:address:num
]
<span class="traceContains">+run: creating array of size 4</span>
<span class="traceContains">+mem: storing 34 in location 6</span>

<span class="Delimiter">:(before &quot;Update PUT_INDEX base in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;Update PUT_INDEX index in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>index<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;Update PUT_INDEX value in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>value<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;Update PUT_INDEX base in Run&quot;)</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;Update PUT_INDEX index in Run&quot;)</span>
canonize<span class="Delimiter">(</span>index<span class="Delimiter">);</span>

<span class="Delimiter">:(scenario length_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> &lt;- </span>create-array
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">14</span>
  <span class="Constant">13</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">15</span>
  <span class="Constant">14</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">16</span>
  <span class="Constant">1</span>:address:array:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>length <span class="Constant">1</span>:address:array:num/lookup
]
<span class="traceContains">+mem: storing 3 in location 2</span>

<span class="Delimiter">:(before &quot;Update LENGTH array in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>array<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;Update LENGTH array in Run&quot;)</span>
canonize<span class="Delimiter">(</span>array<span class="Delimiter">);</span>

<span class="Delimiter">:(scenario maybe_convert_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:number-<span class="Normal">or</span>-point<span class="Special"> &lt;- </span>merge <span class="Constant">0</span>/number<span class="Delimiter">,</span> <span class="Constant">34</span>
  <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">3</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>maybe-convert <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point/lookup<span class="Delimiter">,</span> <span class="Constant">i:variant</span>
]
<span class="traceContains">+mem: storing 1 in location 3</span>
<span class="traceContains">+mem: storing 34 in location 2</span>

<span class="Delimiter">:(scenario maybe_convert_indirect_2)</span>
<span class="muRecipe">def</span> main [
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:number-<span class="Normal">or</span>-point<span class="Special"> &lt;- </span>merge <span class="Constant">0</span>/number<span class="Delimiter">,</span> <span class="Constant">34</span>
  <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">2</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">20</span>/unsafe
  <span class="Constant">2</span>:address:num/lookup<span class="Delimiter">,</span> <span class="Constant">3</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>maybe-convert <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point/lookup<span class="Delimiter">,</span> <span class="Constant">i:variant</span>
]
<span class="traceContains">+mem: storing 1 in location 3</span>
<span class="traceContains">+mem: storing 34 in location 21</span>

<span class="Delimiter">:(scenario maybe_convert_indirect_3)</span>
<span class="muRecipe">def</span> main [
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:number-<span class="Normal">or</span>-point<span class="Special"> &lt;- </span>merge <span class="Constant">0</span>/number<span class="Delimiter">,</span> <span class="Constant">34</span>
  <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">2</span>:address:<span class="Normal">bool</span><span class="Special"> &lt;- </span>copy <span class="Constant">20</span>/unsafe
  <span class="Constant">3</span>:num<span class="Delimiter">,</span> <span class="Constant">2</span>:address:<span class="Normal">bool</span>/lookup<span class="Special"> &lt;- </span>maybe-convert <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point/lookup<span class="Delimiter">,</span> <span class="Constant">i:variant</span>
]
<span class="traceContains">+mem: storing 1 in location 21</span>
<span class="traceContains">+mem: storing 34 in location 3</span>

<span class="Delimiter">:(before &quot;Update MAYBE_CONVERT base in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;Update MAYBE_CONVERT product in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;Update MAYBE_CONVERT status in Check&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>status<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;Update MAYBE_CONVERT base in Run&quot;)</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;Update MAYBE_CONVERT product in Run&quot;)</span>
canonize<span class="Delimiter">(</span>product<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;Update MAYBE_CONVERT status in Run&quot;)</span>
canonize<span class="Delimiter">(</span>status<span class="Delimiter">);</span>

<span class="Delimiter">:(scenario merge_exclusive_container_indirect)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point/lookup<span class="Special"> &lt;- </span>merge <span class="Constant">0</span>/number<span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="Comment"># skip 10 for refcount</span>
<span class="traceContains">+mem: storing 0 in location 11</span>
<span class="traceContains">+mem: storing 34 in location 12</span>

<span class="Delimiter">:(before &quot;Update size_mismatch Check for MERGE(x)</span>
canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>

<span class="Comment">//: abbreviation for '/lookup': a prefix '*'</span>

<span class="Delimiter">:(scenario lookup_abbreviation)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:number<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Comment"># 10 reserved for refcount</span>
  <span class="Constant">11</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>copy *<span class="Constant">1</span>:address:number
]
<span class="traceContains">+parse: ingredient: {1: (&quot;address&quot; &quot;number&quot;), &quot;lookup&quot;: ()}</span>
<span class="traceContains">+mem: storing 34 in location 3</span>

<span class="Delimiter">:(before &quot;End Parsing reagent&quot;)</span>
<span class="Delimiter">{</span>
  <span class="Normal">while</span> <span class="Delimiter">(</span>starts_with<span class="Delimiter">(</span>name<span class="Delimiter">,</span> <span class="Constant">&quot;*&quot;</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
    name<span class="Delimiter">.</span>erase<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span>
    properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair&lt;string<span class="Delimiter">,</span> string_tree*&gt;<span class="Delimiter">(</span><span class="Constant">&quot;lookup&quot;</span><span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span>
  <span class="Delimiter">}</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span>
    raise &lt;&lt; <span class="Constant">&quot;illegal name '&quot;</span> &lt;&lt; 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="Delimiter">}</span>

<span class="SalientComment">//:: helpers for debugging</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
_DUMP<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&quot;</span><span class="Delimiter">,</span> _DUMP<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> _DUMP: <span class="Delimiter">{</span>
  reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> after_canonize = 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>
  canonize<span class="Delimiter">(</span>after_canonize<span class="Delimiter">);</span>
  cerr &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; 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 &lt;&lt; <span class="Constant">' '</span> &lt;&lt; no_scientific<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>value<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot; =&gt; &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>after_canonize<span class="Delimiter">.</span>value<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot; =&gt; &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> after_canonize<span class="Delimiter">.</span>value<span class="Delimiter">))</span> &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Comment">//: grab an address, and then dump its value at intervals</span>
<span class="Comment">//: useful for tracking down memory corruption (writing to an out-of-bounds address)</span>
<span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span class="Normal">int</span> Bar = -<span class="Constant">1</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
_BAR<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;$bar&quot;</span><span class="Delimiter">,</span> _BAR<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> _BAR: <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>Bar != -<span class="Constant">1</span><span class="Delimiter">)</span> cerr &lt;&lt; Bar &lt;&lt; <span class="Constant">&quot;: &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> Bar<span class="Delimiter">))</span> &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
    <span class="Normal">else</span> cerr &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">else</span> <span class="Delimiter">{</span>
    reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> tmp = 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>
    canonize<span class="Delimiter">(</span>tmp<span class="Delimiter">);</span>
    Bar = tmp<span class="Delimiter">.</span>value<span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->