about summary refs log blame commit diff stats
path: root/html/044space.cc.html
blob: 10e456cb5eb87b4589fa849db4b9dfbe56dcca47 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12



                                                                                          
                               






                                                                                         

                                                                                                 
                        
                                  
                                
                                   
                             

                              
                            
                               
                             










                               
                                                                                                          






                                                                                                                           
                                                                                                                                                                                          
                                                                                                                      
                                                                                                                 


                                                                  
                                                                         

                                                             
                                                                                                                 
                                              
                                                                                                                   
                                                            

                                                                                                                               
                                                                                                                                    


                                                                 

                                                                                          
                                                  
             
                                                                                                                                                                                                       




                                                                              
                                                                                                                                                                   

                                                                                                                   
                                                                                                                                                                                                                                         

                                                                    
                                                                    
                                                           

                                                                               
 

                                                                                  
                                      


                                                                                                                                                                                                                                                                 
                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                            
                                  


                                                                                                                                                                                                                                                                                                                                                                       
                                


                                                  
                                                                                

                                                                          

                                                                                                                  
                                              
                                                                                                                   
                                                            

                                                                                                                               
                                                                                                                                                                                                         



                                                                                               
                                                                                                                                                                                                                                                                                                                                                                       


                                                    
                                                                                  

                                                                      


                                                                                                                  
                                              
                                                                                                                   
                                                            

                                                                                                                                      
                                                                                                                                                                                                           



                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                       
 




                                                                                                             


                                                                                  




                                                                                            
                                                                                                                                                                      

                                                                                                                   
                                                                                                                                                                                                                                            
 
                                                                                                 


                                                                                                                          
                                                                                                                                                                                                           
                                                                                                        

                                                                                               

                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                         


                                                                                                           
                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                                  


                                                                          










                                                                                                                                                                                                  

                                                                                   










                                                                                                        
                                                                                                 
                                                                                                                                                                                                     



                                                                                                        
                                                                                         
                                                                                   




                                                                                                                                                                                                                                                                                                    


                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                            
                                                                                                                                                            

                                                                                                                                                                                                                                                                                                   

                                                                                                                                                                                                                                                                     
                                                                                                                                                         
                                                                                                                                                                                                                        


                                                                                                                                                                                                                                                                              


                                                
                                                                                                                                             

                                                                                                                                    

                                

                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                             
                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   



                                                                                                                      
                                                                                                           
                                                                                                                                                                                                      










                                                                                                                                                                                                                                                                                                                                                                                                                                        




                                                                          
                                                                                                                      
                                                                                                                                         


                                                                 
                                                                                               

                                                                                                                                                                                                      
                                                                                                                                                                               





                                                                                 
<!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 - 044space.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<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-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.traceContains { color: #008000; }
.traceAbsent { color: #c00000; }
.SalientComment { color: #00ffff; }
.cSpecial { color: #008000; }
.Comment { color: #9090ff; }
.Delimiter { color: #a04060; }
.Special { color: #ff6060; }
.Identifier { color: #804000; }
.Constant { color: #00a0a0; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Spaces help isolate recipes from each other. You can create them at will,</span>
<span class="Comment">//: and all addresses in arguments are implicitly based on the 'default-space'</span>
<span class="Comment">//: (unless they have the /raw property)</span>

<span class="Delimiter">:(scenario set_default_space)</span>
<span class="Comment"># if default-space is 10, and if an array of 5 locals lies from location 11 to 15 (inclusive),</span>
<span class="Comment"># then location 0 is really location 11, location 1 is really location 12, and so on.</span>
recipe main [
  <span class="Constant">10</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">5</span>  <span class="Comment"># pretend array; in practice we'll use new</span>
  default-space:address:array:location<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">23</span>
]
<span class="traceContains">+mem: storing 23 in location 12</span>

<span class="Delimiter">:(scenario lookup_sidesteps_default_space)</span>
recipe main [
  <span class="Comment"># pretend pointer from outside</span>
  <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Comment"># pretend array</span>
  <span class="Constant">1000</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">5</span>
  <span class="Comment"># actual start of this recipe</span>
  default-space:address:array:location<span class="Special"> &lt;- </span>copy <span class="Constant">1000</span>/unsafe
  <span class="Constant">1</span>:address:number<span class="Special"> &lt;- </span>copy <span class="Constant">3</span>/unsafe
  <span class="Constant">8</span>:number/<span class="Special">raw &lt;- </span>copy *<span class="Constant">1</span>:address:number
]
<span class="traceContains">+mem: storing 34 in location 8</span>

<span class="SalientComment">//:: first disable name conversion for 'default-space'</span>
<span class="Delimiter">:(scenario convert_names_passes_default_space)</span>
<span class="Special">% Hide_errors = true;</span>
recipe main [
  default-space:number<span class="Delimiter">,</span> x:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+name: assign x 1</span>
<span class="traceAbsent">-name: assign default-space 1</span>

<span class="Delimiter">:(before &quot;End Disqualified Reagents&quot;)</span>
if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;default-space&quot;</span><span class="Delimiter">)</span>
  x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End is_special_name Cases&quot;)</span>
if <span class="Delimiter">(</span>s == <span class="Constant">&quot;default-space&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>

<span class="SalientComment">//:: now implement space support</span>
<span class="Delimiter">:(before &quot;End call Fields&quot;)</span>
long long int default_space<span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End call Constructor&quot;)</span>
default_space = <span class="Constant">0</span><span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;End canonize(x) Special-cases&quot;)</span>
  absolutize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Delimiter">:(code)</span>
void absolutize<span class="Delimiter">(</span>reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">)</span> || is_dummy<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;default-space&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise_error &lt;&lt; current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> &lt;&lt; <span class="Constant">&quot;: reagent not initialized: &quot;</span> &lt;&lt; x<span class="Delimiter">.</span>original_string &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
  x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">,</span> space_base<span class="Delimiter">(</span>x<span class="Delimiter">)));</span>
  x<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;raw&quot;</span><span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span>
  assert<span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">));</span>
<span class="Delimiter">}</span>

<span class="SalientComment">//:: fix 'get'</span>

<span class="Delimiter">:(scenario lookup_sidesteps_default_space_in_get)</span>
recipe main [
  <span class="Comment"># pretend pointer to container from outside</span>
  <span class="Constant">12</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">13</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">35</span>
  <span class="Comment"># pretend array</span>
  <span class="Constant">1000</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">5</span>
  <span class="Comment"># actual start of this recipe</span>
  default-space:address:array:location<span class="Special"> &lt;- </span>copy <span class="Constant">1000</span>/unsafe
  <span class="Constant">1</span>:address:point<span class="Special"> &lt;- </span>copy <span class="Constant">12</span>/unsafe
  <span class="Constant">9</span>:number/<span class="Special">raw &lt;- </span>get *<span class="Constant">1</span>:address:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset
]
<span class="traceContains">+mem: storing 35 in location 9</span>

<span class="Delimiter">:(after &quot;reagent tmp&quot; following &quot;case GET:&quot;)</span>
tmp<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;raw&quot;</span><span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span>

<span class="SalientComment">//:: fix 'index'</span>

<span class="Delimiter">:(scenario lookup_sidesteps_default_space_in_index)</span>
recipe main [
  <span class="Comment"># pretend pointer to array from outside</span>
  <span class="Constant">12</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">2</span>
  <span class="Constant">13</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">14</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">35</span>
  <span class="Comment"># pretend array</span>
  <span class="Constant">1000</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">5</span>
  <span class="Comment"># actual start of this recipe</span>
  default-space:address:array:location<span class="Special"> &lt;- </span>copy <span class="Constant">1000</span>/unsafe
  <span class="Constant">1</span>:address:array:number<span class="Special"> &lt;- </span>copy <span class="Constant">12</span>/unsafe
  <span class="Constant">9</span>:number/<span class="Special">raw &lt;- </span>index *<span class="Constant">1</span>:address:array:number<span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+mem: storing 35 in location 9</span>

<span class="Delimiter">:(after &quot;reagent tmp&quot; following &quot;case INDEX:&quot;)</span>
tmp<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;raw&quot;</span><span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span>

<span class="SalientComment">//:: convenience operation to automatically deduce the amount of space to</span>
<span class="SalientComment">//:: allocate in a default space with names</span>

<span class="Delimiter">:(scenario new_default_space)</span>
recipe main [
  new-default-space
  x:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  y:number<span class="Special"> &lt;- </span>copy <span class="Constant">3</span>
]
<span class="Comment"># allocate space for x and y, as well as the chaining slot at 0</span>
<span class="traceContains">+mem: array size is 3</span>

<span class="Delimiter">:(before &quot;End Disqualified Reagents&quot;)</span>
if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;number-of-locals&quot;</span><span class="Delimiter">)</span>
  x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End is_special_name Cases&quot;)</span>
if <span class="Delimiter">(</span>s == <span class="Constant">&quot;number-of-locals&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 `new-default-space` to</span>
<span class="Comment">//   `default-space:address:array:location &lt;- new location:type, number-of-locals:literal`</span>
<span class="Comment">// where N is Name[recipe][&quot;&quot;]</span>
if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">&quot;new-default-space&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
  rewrite_default_space_instruction<span class="Delimiter">(</span>curr<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(after &quot;vector&lt;double&gt; read_memory(reagent x)&quot;)</span>
  if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;number-of-locals&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    vector&lt;double&gt; result<span class="Delimiter">;</span>
    result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Name[get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> current_recipe_name<span class="Delimiter">())</span>][<span class="Constant">&quot;&quot;</span>]<span class="Delimiter">);</span>
    if <span class="Delimiter">(</span>result<span class="Delimiter">.</span>back<span class="Delimiter">()</span> == <span class="Constant">0</span><span class="Delimiter">)</span>
      raise_error &lt;&lt; <span class="Constant">&quot;no space allocated for default-space in recipe &quot;</span> &lt;&lt; current_recipe_name<span class="Delimiter">()</span> &lt;&lt; <span class="Constant">&quot;; are you using names?</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">return</span> result<span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">:(after &quot;void write_memory(reagent x, vector&lt;double&gt; data)&quot;)</span>
  if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;number-of-locals&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise_error &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;can't write to special name 'number-of-locals'</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="SalientComment">//:: a little hook to automatically reclaim the default-space when returning</span>
<span class="SalientComment">//:: from a recipe</span>

<span class="Delimiter">:(scenario local_scope)</span>
recipe main [
  <span class="Constant">1</span>:address<span class="Special"> &lt;- </span>foo
  <span class="Constant">2</span>:address<span class="Special"> &lt;- </span>foo
  <span class="Constant">3</span>:boolean<span class="Special"> &lt;- </span>equal <span class="Constant">1</span>:address<span class="Delimiter">,</span> <span class="Constant">2</span>:address
]
recipe foo [
  local-scope
  x:number<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  reply default-space:address:array:location
]
<span class="Comment"># both calls to foo should have received the same default-space</span>
<span class="traceContains">+mem: storing 1 in location 3</span>

<span class="Delimiter">:(after &quot;Falling Through End Of Recipe&quot;)</span>
try_reclaim_locals<span class="Delimiter">();</span>
<span class="Delimiter">:(after &quot;Starting Reply&quot;)</span>
try_reclaim_locals<span class="Delimiter">();</span>

<span class="Comment">//: now 'local-scope' is identical to 'new-default-space' except that we'll</span>
<span class="Comment">//: reclaim the default-space when the routine exits</span>
<span class="Delimiter">:(before &quot;End Rewrite Instruction(curr, recipe result)&quot;)</span>
if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">&quot;local-scope&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
  rewrite_default_space_instruction<span class="Delimiter">(</span>curr<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(code)</span>
void try_reclaim_locals<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  <span class="Comment">// only reclaim routines starting with 'local-scope'</span>
  const recipe_ordinal r = get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> current_recipe_name<span class="Delimiter">());</span>
  if <span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  const instruction&amp; inst = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
  if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>old_name != <span class="Constant">&quot;local-scope&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  abandon<span class="Delimiter">(</span>current_call<span class="Delimiter">().</span>default_space<span class="Delimiter">,</span>
          <span class="Comment">/*</span><span class="Comment">array length</span><span class="Comment">*/</span><span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">number-of-locals</span><span class="Comment">*/</span>Name[r][<span class="Constant">&quot;&quot;</span>]<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

void rewrite_default_space_instruction<span class="Delimiter">(</span>instruction&amp; curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  if <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span>
    raise_error &lt;&lt; curr<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> &lt;&lt; <span class="Constant">&quot; can't take any ingredients</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  curr<span class="Delimiter">.</span>name = <span class="Constant">&quot;new&quot;</span><span class="Delimiter">;</span>
  curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">&quot;location:type&quot;</span><span class="Delimiter">));</span>
  curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">&quot;number-of-locals:literal&quot;</span><span class="Delimiter">));</span>
  if <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span>
    raise_error &lt;&lt; <span class="Constant">&quot;new-default-space can't take any results</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<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;default-space:address:array:location&quot;</span><span class="Delimiter">));</span>
<span class="Delimiter">}</span>

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

<span class="Delimiter">:(code)</span>
long long int space_base<span class="Delimiter">(</span>const reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Comment">// temporary stub; will be replaced in a later layer</span>
  <span class="Identifier">return</span> current_call<span class="Delimiter">().</span>default_space<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

long long int address<span class="Delimiter">(</span>long long int offset<span class="Delimiter">,</span> long long int base<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  if <span class="Delimiter">(</span>base == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> offset<span class="Delimiter">;</span>  <span class="Comment">// raw</span>
  if <span class="Delimiter">(</span>offset &gt;= static_cast&lt;long long int&gt;<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base<span class="Delimiter">)))</span> <span class="Delimiter">{</span>
    <span class="Comment">// todo: test</span>
    raise_error &lt;&lt; <span class="Constant">&quot;location &quot;</span> &lt;&lt; offset &lt;&lt; <span class="Constant">&quot; is out of bounds &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base<span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot; at &quot;</span> &lt;&lt; base &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> base+<span class="Constant">1</span> + offset<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(after &quot;void write_memory(reagent x, vector&lt;double&gt; data)&quot;)</span>
  if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;default-space&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>data<span class="Delimiter">)</span>
        || !x<span class="Delimiter">.</span>type
        || x<span class="Delimiter">.</span>type<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>
        || !x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>right
        || x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;array&quot;</span><span class="Delimiter">)</span>
        || !x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>right
        || x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;location&quot;</span><span class="Delimiter">)</span>
        || x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      raise_error &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;'default-space' should be of type address:array:location, but tried to write &quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>data<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Delimiter">}</span>
    current_call<span class="Delimiter">().</span>default_space = data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
    <span class="Identifier">return</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>

<span class="Delimiter">:(scenario get_default_space)</span>
recipe main [
  default-space:address:array:location<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>/unsafe
  <span class="Constant">1</span>:address:array:location/<span class="Special">raw &lt;- </span>copy default-space:address:array:location
]
<span class="traceContains">+mem: storing 10 in location 1</span>

<span class="Delimiter">:(after &quot;vector&lt;double&gt; read_memory(reagent x)&quot;)</span>
  if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">&quot;default-space&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    vector&lt;double&gt; result<span class="Delimiter">;</span>
    result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>current_call<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span>
    <span class="Identifier">return</span> result<span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->