about summary refs log tree commit diff stats
path: root/ranger.py
Commit message (Expand)AuthorAgeFilesLines
* README: polished, removed INSTALLhut2011-10-051-5/+2
* ranger.py: made the argument optional in embedded bash scripthut2011-10-041-15/+16
* Fixed minor issue in ranger.pyhut2011-10-011-3/+3
* another correction of the bash wrapper scriptshut2011-09-281-1/+2
* shortened ranger.pyhut2011-09-281-6/+3
* sanitized bash wrapper scripts, reformulated BUGS section in manualhut2011-09-281-2/+2
* minor optimization in ranger.pyhut2011-09-281-6/+1
* improved bash wrappers in ranger.py and man pagehut2011-09-281-5/+7
* ranger.py: More reliable check for whether ./ranger.py is startedhut2011-05-071-1/+1
* ranger.py: minor change, more general exception handlinghut2011-04-051-1/+1
* improved ranger.pyhut2011-04-051-2/+10
* Polished ranger.pyhut2010-10-161-3/+3
* Small simplification of ranger.pyhut2010-09-291-3/+2
* Don't write any bytecode with --clean optionhut2010-09-291-0/+10
* ranger.py: Return 0 on success in embedded scripthut2010-09-221-1/+1
* simplify ranger.pyhut2010-09-221-25/+11
* ranger.py Fixed embedded shellscript (quotes for bash)hut2010-09-111-2/+2
* ranger.py: fixed escape in embedded shellscripthut2010-09-111-1/+1
* Changed default config dir to $XDG_CONFIG_HOME/rangerhut2010-08-281-1/+5
* main: catch SystemExit and return the exit valuehut2010-06-181-2/+3
* renamed "--fail-if-run" to the more accurate "--fail-unless-cd"hut2010-06-091-1/+1
* Reverted hashbang for ranger.py.hut2010-06-091-1/+1
* Changed hashbang line to "#!/usr/bin/env python"hut2010-06-091-1/+1
* Run python with flag "-O" by defaulthut2010-05-101-1/+1
* Fixed bug #65 by adding flag "--fail-if-run"hut2010-04-261-1/+1
* ranger.py: removed whitespacehut2010-04-121-4/+0
* reverted a part of 45cf5174. Allow "source ranger ranger" againhut2010-04-011-8/+7
* removed the cd-after-exit hackhut2010-03-291-13/+8
* ranger.__init__: don't implicitly import ranger.__main__hut2010-03-261-1/+1
* Changed license to the GNU General Public Licensehut2010-02-281-12/+14
* ranger.py: fixed cd-after-exit with spaces in directoryhut2010-02-241-1/+1
* ranger.py: removed unnecessary codehut2010-02-151-1/+1
* ranger.py: reverted cd-after-exit to the old wayhut2010-02-141-10/+1
* ranger.py: more simple '--debug' flag checkhut2010-02-141-1/+1
* ranger.py: improved handling of bad importhut2010-01-261-1/+2
* ranger.py: more fixeshut2010-01-121-2/+2
* ranger.py: cleanup/fixhut2010-01-111-9/+8
* fixed #31, cd-after-exit works even after pressing ^Chut2010-01-111-1/+12
* added license informationhut2010-01-081-3/+17
* F1 key (inside console) for viewing information about the commandhut2009-12-291-1/+1
* shorten comment in ranger.pyhut2009-12-261-11/+5
* implemented OpenConsolehut2009-12-251-2/+2
* random updateshut2009-12-251-3/+16
* tons of stuffhut2009-12-171-1/+1
* merged main with __init__hut2009-12-121-1/+1
* restructurationshut2009-12-111-2/+4
* changing implementation of optionshut2009-12-061-3/+6
* structural improvementshut2009-12-011-46/+9
* random improvementshut2009-11-291-2/+2
* implemented colorschemes.hut2009-11-291-10/+10
ik K. Agaram <vc@akkartik.com> 2015-05-14 16:04:45 -0700 1376 - update github docs' href='/akkartik/mu/commit/html/020run.cc.html?h=hlt&id=65361948ca7975553757a0e0df4ac7352413044c'>65361948 ^
e8b1d3ff ^
65361948 ^
e8b1d3ff ^
672e3e50 ^


65361948 ^
672e3e50 ^






c5ffb6e1 ^
65361948 ^
c5ffb6e1 ^
65361948 ^

e8b1d3ff ^
672e3e50 ^
e8b1d3ff ^
65361948 ^
672e3e50 ^





c5ffb6e1 ^
672e3e50 ^







65361948 ^
672e3e50 ^


c5ffb6e1 ^
672e3e50 ^


65361948 ^
672e3e50 ^








65361948 ^

672e3e50 ^











65361948 ^


672e3e50 ^









65361948 ^
672e3e50 ^








e8b1d3ff ^
672e3e50 ^


e8b1d3ff ^
672e3e50 ^
e8b1d3ff ^
672e3e50 ^



65361948 ^


672e3e50 ^



c5ffb6e1 ^


65361948 ^
c5ffb6e1 ^
672e3e50 ^




65361948 ^
672e3e50 ^
c5ffb6e1 ^

672e3e50 ^
c5ffb6e1 ^

65361948 ^
672e3e50 ^



c5ffb6e1 ^
672e3e50 ^

c5ffb6e1 ^
672e3e50 ^








c5ffb6e1 ^
672e3e50 ^




65361948 ^

672e3e50 ^
c5ffb6e1 ^


672e3e50 ^




c5ffb6e1 ^
672e3e50 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275



                                                                                          
                             






                                                                                         

                                                                                                 
                     
                                  
                             
                             

                                   


                              
                                  
                               























                                                                                                           
                                                                                                                         
 
                                                                       



                                                                 

                                                                                                                         
 
                                                                     


                                                                 



                                                                                                                                                                                                                                                                         


                                                                 




                                                                    
                                                                  















                                                                                                                                                                                                                                                                                                                              
                                                                                 

                                                                                                                                                                                                           
                                                                                                                               

                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                        




                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                           

                                                                                                                                                                                                                                                                                                           
                                                                                
                                                                                
                                                                                                                                                                                                                                   


                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                  






                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                           
                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                        

                                                                                                                                                                                                                                                                                                                                 
                                                          
                                  
                                                                                 
                                                               





                                                                                                           
                                                                                                              







                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                               


                                                                                                      
                                                                                                                                                                                                  


                                                                            
                                                         








                                                                                                                                                                                                                              

                                                                                    











                                                                                                                                                                                       


                                                                                                                                                                                                   









                                                                                                                                                                        
                                                       








                                                                                                                                  
                                                                                 


                                                                                                                                                                                      
                                                                                 
                                                                                                                
                                                                               



                                                                                


                                                                                                                                          



                                                                                                                                                          


                                                                                                                                                                                                                                                       
                                                                    
                                                                                                                                                                                                                                                                                                                                                                    




                                                                                                                       
                                                                                                                                                                                     
                                                                                                                                                                                      

                                                                                                                                                                                          
                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                       



                                      
                                                                                                                                          

                                                                                                                                                       
                                                                                                                                                                








                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                                            




                                                    

                                                                                                                         
 


                                                                       




                                                                                   
                                                               



                                     
<!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 - 020run.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: 1em; }
.traceContains { color: #008000; }
.cSpecial { color: #008000; }
.Constant { color: #008080; }
.SalientComment { color: #00ffff; }
.traceAbsent { color: #c00000; }
.Comment { color: #8080ff; }
.Delimiter { color: #c000c0; }
.Special { color: #ff6060; }
.CommentedCode { color: #6c6c6c; }
.Identifier { color: #804000; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Phase 3: Start running a loaded and transformed recipe.</span>
<span class="Comment">//:</span>
<span class="Comment">//: So far we've seen recipes as lists of instructions, and instructions point</span>
<span class="Comment">//: at other recipes. To kick things off mu needs to know how to run certain</span>
<span class="Comment">//: 'primitive' recipes. That will then give the ability to run recipes</span>
<span class="Comment">//: containing these primitives.</span>
<span class="Comment">//:</span>
<span class="Comment">//: This layer defines a skeleton with just two primitive recipes: IDLE which</span>
<span class="Comment">//: does nothing, and COPY, which can copy numbers from one memory location to</span>
<span class="Comment">//: another. Later layers will add more primitives.</span>

<span class="Delimiter">:(scenario copy_literal)</span>
recipe main [
  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">23</span>:literal
]
<span class="traceContains">+run: 1:number &lt;- copy 23:literal</span>
<span class="traceContains">+mem: storing 23 in location 1</span>

<span class="Delimiter">:(scenario copy)</span>
recipe main [
  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">23</span>:literal
  <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:number
]
<span class="traceContains">+run: 2:number &lt;- copy 1:number</span>
<span class="traceContains">+mem: location 1 is 23</span>
<span class="traceContains">+mem: storing 23 in location 2</span>

<span class="Delimiter">:(scenario copy_multiple)</span>
recipe main [
  <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">24</span>:literal
]
<span class="traceContains">+mem: storing 23 in location 1</span>
<span class="traceContains">+mem: storing 24 in location 2</span>

<span class="Delimiter">:(before &quot;End Types&quot;)</span>
<span class="Comment">// Book-keeping while running a recipe.</span>
<span class="Comment">//: Later layers will change this.</span>
struct routine <span class="Delimiter">{</span>
  recipe_number running_recipe<span class="Delimiter">;</span>
  long long int running_step_index<span class="Delimiter">;</span>
  routine<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> :running_recipe<span class="Delimiter">(</span>r<span class="Delimiter">),</span> running_step_index<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span>
  bool completed<span class="Delimiter">()</span> const<span class="Delimiter">;</span>
<span class="Delimiter">};</span>

<span class="Delimiter">:(before &quot;End Globals&quot;)</span>
routine* Current_routine = <span class="Constant">NULL</span><span class="Delimiter">;</span>

<span class="Delimiter">:(code)</span>
void run<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  routine rr<span class="Delimiter">(</span>r<span class="Delimiter">);</span>
  Current_routine = &amp;rr<span class="Delimiter">;</span>
  run_current_routine<span class="Delimiter">();</span>
<span class="Delimiter">}</span>

void run_current_routine<span class="Delimiter">()</span>
<span class="Delimiter">{</span>  <span class="Comment">// curly on a separate line, because later layers will modify header</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;AAA 6\n&quot;; //? 2</span>
  while <span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-&gt;</span>completed<span class="Delimiter">())</span>  <span class="Comment">// later layers will modify condition</span>
  <span class="Delimiter">{</span>
<span class="CommentedCode">//?     cerr &lt;&lt; &quot;AAA 7: &quot; &lt;&lt; current_step_index() &lt;&lt; '\n'; //? 1</span>
    <span class="Comment">// Running One Instruction.</span>
    if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>is_label<span class="Delimiter">)</span> <span class="Delimiter">{</span> ++current_step_index<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span>
    trace<span class="Delimiter">(</span>Initial_callstack_depth+Callstack_depth<span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">();</span>
    assert<span class="Delimiter">(</span>Memory[<span class="Constant">0</span>] == <span class="Constant">0</span><span class="Delimiter">);</span>
    <span class="Comment">// Read all ingredients from memory.</span>
    <span class="Comment">// Each ingredient loads a vector of values rather than a single value; mu</span>
    <span class="Comment">// permits operating on reagents spanning multiple locations.</span>
    vector&lt;vector&lt;double&gt; &gt; ingredients<span class="Delimiter">;</span>
    for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</span>
    <span class="Delimiter">}</span>
    <span class="Comment">// Instructions below will write to 'products'.</span>
    vector&lt;vector&lt;double&gt; &gt; products<span class="Delimiter">;</span>
<span class="CommentedCode">//?     cerr &lt;&lt; &quot;AAA 8: &quot; &lt;&lt; current_instruction().operation &lt;&lt; &quot; ^&quot; &lt;&lt; Recipe[current_instruction().operation].name &lt;&lt; &quot;$\n&quot;; //? 1</span>
    switch <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      <span class="Comment">// Primitive Recipe Implementations</span>
      case COPY: <span class="Delimiter">{</span>
        copy<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> ingredients<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>products<span class="Delimiter">,</span> products<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span>
        <span class="Identifier">break</span><span class="Delimiter">;</span>
      <span class="Delimiter">}</span>
      <span class="Comment">// End Primitive Recipe Implementations</span>
      default: <span class="Delimiter">{</span>
        cout &lt;&lt; <span class="Constant">&quot;not a primitive op: &quot;</span> &lt;&lt; current_instruction<span class="Delimiter">().</span>operation &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
      <span class="Delimiter">}</span>
    <span class="Delimiter">}</span>
    if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> &lt; SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">))</span>
      raise &lt;&lt; <span class="Constant">&quot;failed to write to all products! &quot;</span> &lt;&lt; current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">();</span>
    for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
    <span class="Delimiter">}</span>
    ++current_step_index<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;AAA 9\n&quot;; //? 1</span>
  stop_running_current_routine:<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Comment">//: Some helpers.</span>
<span class="Comment">//: We'll need to override these later as we change the definition of routine.</span>
<span class="Comment">//: Important that they return referrences into the routine.</span>

inline long long int&amp; current_step_index<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  <span class="Identifier">return</span> Current_routine<span class="Delimiter">-&gt;</span>running_step_index<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

inline const string&amp; current_recipe_name<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-&gt;</span>running_recipe]<span class="Delimiter">.</span>name<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

inline const instruction&amp; current_instruction<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-&gt;</span>running_recipe]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>running_step_index<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

inline bool routine::completed<span class="Delimiter">()</span> const <span class="Delimiter">{</span>
  <span class="Identifier">return</span> running_step_index &gt;= SIZE<span class="Delimiter">(</span>Recipe[running_recipe]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(before &quot;End Commandline Parsing&quot;)</span>
<span class="Comment">// Loading Commandline Files</span>
if <span class="Delimiter">(</span>argc &gt; <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
  for <span class="Delimiter">(</span>int i = <span class="Constant">1</span><span class="Delimiter">;</span> i &lt; argc<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    load_permanently<span class="Delimiter">(</span>argv[i]<span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(before &quot;End Main&quot;)</span>
if <span class="Delimiter">(</span>!Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  setup<span class="Delimiter">();</span>
<span class="CommentedCode">//?   Trace_file = &quot;interactive&quot;; //? 1</span>
  START_TRACING_UNTIL_END_OF_SCOPE<span class="Delimiter">;</span>
<span class="CommentedCode">//?   Trace_stream-&gt;dump_layer = &quot;all&quot;; //? 2</span>
  transform_all<span class="Delimiter">();</span>
  recipe_number r = Recipe_number[string<span class="Delimiter">(</span><span class="Constant">&quot;main&quot;</span><span class="Delimiter">)</span>]<span class="Delimiter">;</span>
<span class="CommentedCode">//?   Trace_stream-&gt;dump_layer = &quot;all&quot;; //? 1</span>
  if <span class="Delimiter">(</span>r<span class="Delimiter">)</span> run<span class="Delimiter">(</span>r<span class="Delimiter">);</span>
<span class="CommentedCode">//?   dump_memory(); //? 1</span>
  teardown<span class="Delimiter">();</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(code)</span>
void load_permanently<span class="Delimiter">(</span>string filename<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  ifstream fin<span class="Delimiter">(</span>filename<span class="Delimiter">.</span>c_str<span class="Delimiter">());</span>
  fin<span class="Delimiter">.</span>peek<span class="Delimiter">();</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;AAA: &quot; &lt;&lt; filename &lt;&lt; ' ' &lt;&lt; static_cast&lt;bool&gt;(fin) &lt;&lt; ' ' &lt;&lt; fin.fail() &lt;&lt; '\n'; //? 1</span>
<span class="CommentedCode">//?   return; //? 1</span>
  if <span class="Delimiter">(</span>!fin<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise &lt;&lt; <span class="Constant">&quot;no such file &quot;</span> &lt;&lt; filename &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
    <span class="Identifier">return</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  fin &gt;&gt; std::noskipws<span class="Delimiter">;</span>
  load<span class="Delimiter">(</span>fin<span class="Delimiter">);</span>
  transform_all<span class="Delimiter">();</span>
  fin<span class="Delimiter">.</span>close<span class="Delimiter">();</span>
  <span class="Comment">// freeze everything so it doesn't get cleared by tests</span>
  recently_added_recipes<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
  <span class="Comment">// End load_permanently.</span>
<span class="Delimiter">}</span>

<span class="SalientComment">//:: On startup, load everything in core.mu</span>
<span class="Delimiter">:(before &quot;End Load Recipes&quot;)</span>
load_permanently<span class="Delimiter">(</span><span class="Constant">&quot;core.mu&quot;</span><span class="Delimiter">);</span>

<span class="Delimiter">:(code)</span>
<span class="Comment">// helper for tests</span>
void run<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;AAA 2\n&quot;; //? 1</span>
  vector&lt;recipe_number&gt; tmp = load<span class="Delimiter">(</span>form<span class="Delimiter">);</span>
  if <span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  transform_all<span class="Delimiter">();</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;AAA 3\n&quot;; //? 1</span>
  run<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>front<span class="Delimiter">());</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;YYY\n&quot;; //? 1</span>
<span class="Delimiter">}</span>

<span class="SalientComment">//:: Reading from memory, writing to memory.</span>

vector&lt;double&gt; read_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//?   cout &lt;&lt; &quot;read_memory: &quot; &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 2</span>
  vector&lt;double&gt; result<span class="Delimiter">;</span>
  if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span>
    result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">);</span>
    <span class="Identifier">return</span> result<span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  long long int base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span>
  long long int size = size_of<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
  for <span class="Delimiter">(</span>long long int offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset &lt; size<span class="Delimiter">;</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    double val = Memory[base+offset]<span class="Delimiter">;</span>
    trace<span class="Delimiter">(</span>Primitive_recipe_depth<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; base+offset &lt;&lt; <span class="Constant">&quot; is &quot;</span> &lt;&lt; val<span class="Delimiter">;</span>
    result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>val<span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

void write_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> vector&lt;double&gt; data<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  long long int base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span>
  if <span class="Delimiter">(</span>size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>data<span class="Delimiter">))</span>
    raise &lt;&lt; <span class="Constant">&quot;size mismatch in storing to &quot;</span> &lt;&lt; x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
  for <span class="Delimiter">(</span>long long int offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset &lt; SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;storing &quot;</span> &lt;&lt; data<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot; in location &quot;</span> &lt;&lt; base+offset<span class="Delimiter">;</span>
    Memory[base+offset] = data<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset<span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(code)</span>
long long int size_of<span class="Delimiter">(</span>const reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
long long int size_of<span class="Delimiter">(</span>const vector&lt;type_number&gt;&amp; types<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Comment">// End size_of(types) Cases</span>
  <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

bool is_dummy<span class="Delimiter">(</span>const reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Identifier">return</span> x<span class="Delimiter">.</span>name == <span class="Constant">&quot;_&quot;</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

bool isa_literal<span class="Delimiter">(</span>const reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">)</span> == <span class="Constant">1</span> &amp;&amp; r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario run_label)</span>
recipe main [
  +foo
  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">23</span>:literal
  <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:number
]
<span class="traceContains">+run: 1:number &lt;- copy 23:literal</span>
<span class="traceContains">+run: 2:number &lt;- copy 1:number</span>
<span class="traceAbsent">-run: +foo</span>

<span class="Delimiter">:(scenario run_dummy)</span>
recipe main [
  _<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
]
<span class="traceContains">+run: _ &lt;- copy 0:literal</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->