diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-03-26 23:59:59 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-03-27 17:43:41 -0700 |
commit | a654e4ecace2d506d1b10f1dde2c287ebe84ef37 (patch) | |
tree | 1e34a3ad99a56e32bdf9ee03ecfe7d339e7942ae /html/020run.cc.html | |
parent | 859f35fbe2f6a78157b875e12eb7dc8cd95c1152 (diff) | |
download | mu-a654e4ecace2d506d1b10f1dde2c287ebe84ef37.tar.gz |
2812
Diffstat (limited to 'html/020run.cc.html')
-rw-r--r-- | html/020run.cc.html | 137 |
1 files changed, 75 insertions, 62 deletions
diff --git a/html/020run.cc.html b/html/020run.cc.html index 6f24364a..a31b6dcd 100644 --- a/html/020run.cc.html +++ b/html/020run.cc.html @@ -3,31 +3,39 @@ <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Mu - 020run.cc</title> -<meta name="Generator" content="Vim/7.3"> -<meta name="plugin-version" content="vim7.3_v6"> +<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"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> <style type="text/css"> <!-- -pre { font-family: monospace; color: #eeeeee; background-color: #080808; } +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; } -.PreProc { color: #800080; } -.CommentedCode { color: #6c6c6c; } -.SalientComment { color: #00ffff; } .cSpecial { color: #008000; } -.Identifier { color: #fcb165; } -.Normal { color: #eeeeee; background-color: #080808; } .traceContains { color: #008000; } -.Special { color: #c00000; } -.Constant { color: #00a0a0; } -.Delimiter { color: #800080; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } +.Identifier { color: #fcb165; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.PreProc { color: #800080; } +.CommentedCode { color: #6c6c6c; } --> </style> + +<script type='text/javascript'> +<!-- + +--> +</script> </head> <body> -<pre> +<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> @@ -43,7 +51,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] -<span class="traceContains">+run: 1:number <- copy 23</span> +<span class="traceContains">+run: {1: "number"} <- copy {23: "literal"}</span> <span class="traceContains">+mem: storing 23 in location 1</span> <span class="Delimiter">:(scenario copy)</span> @@ -51,7 +59,7 @@ def main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] -<span class="traceContains">+run: 2:number <- copy 1:number</span> +<span class="traceContains">+run: {2: "number"} <- copy {1: "number"}</span> <span class="traceContains">+mem: location 1 is 23</span> <span class="traceContains">+mem: storing 23 in location 2</span> @@ -67,16 +75,17 @@ def main [ <span class="Comment">//: Later layers will change this.</span> <span class="Normal">struct</span> routine <span class="Delimiter">{</span> recipe_ordinal running_recipe<span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> running_step_index<span class="Delimiter">;</span> + <span class="Normal">int</span> running_step_index<span class="Delimiter">;</span> routine<span class="Delimiter">(</span>recipe_ordinal 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> <span class="Normal">bool</span> completed<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span> + <span class="Normal">const</span> vector<instruction>& steps<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "End Globals")</span> routine* Current_routine = <span class="Constant">NULL</span><span class="Delimiter">;</span> -map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> Instructions_running<span class="Delimiter">;</span> -map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> Locations_read<span class="Delimiter">;</span> -map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> Locations_read_by_instruction<span class="Delimiter">;</span> +map<string<span class="Delimiter">,</span> <span class="Normal">int</span>> Instructions_running<span class="Delimiter">;</span> +map<string<span class="Delimiter">,</span> <span class="Normal">int</span>> Locations_read<span class="Delimiter">;</span> +map<string<span class="Delimiter">,</span> <span class="Normal">int</span>> Locations_read_by_instruction<span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> <span class="Normal">void</span> run<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -99,7 +108,7 @@ map<string<span class="Delimiter">,</span> <span class="Normal">long</span> < <span class="Comment">// read all ingredients from memory, each potentially spanning multiple locations</span> vector<vector<<span class="Normal">double</span>> > ingredients<span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>should_copy_ingredients<span class="Delimiter">())</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<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> @@ -116,10 +125,10 @@ map<string<span class="Delimiter">,</span> <span class="Normal">long</span> < <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> << <span class="Constant">": failed to write to all products! "</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise << SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> << <span class="Constant">": failed to write to all products! "</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < 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> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < 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> <span class="Delimiter">}</span> @@ -138,7 +147,7 @@ map<string<span class="Delimiter">,</span> <span class="Normal">long</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> -<span class="Normal">inline</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>& current_step_index<span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span class="Normal">inline</span> <span class="Normal">int</span>& current_step_index<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> Current_routine<span class="Delimiter">-></span>running_step_index<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -154,6 +163,10 @@ map<string<span class="Delimiter">,</span> <span class="Normal">long</span> < <span class="Identifier">return</span> running_step_index >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> running_recipe<span class="Delimiter">).</span>steps<span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span class="Normal">inline</span> <span class="Normal">const</span> vector<instruction>& routine::steps<span class="Delimiter">()</span> <span class="Normal">const</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> running_recipe<span class="Delimiter">).</span>steps<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + <span class="SalientComment">//:: Startup flow</span> <span class="Comment">//: Step 1: load all .mu files with numeric prefixes (in order)</span> @@ -161,14 +174,14 @@ map<string<span class="Delimiter">,</span> <span class="Normal">long</span> < <span class="Comment">// Load .mu Core</span> <span class="CommentedCode">//? Trace_file = "interactive";</span> <span class="CommentedCode">//? START_TRACING_UNTIL_END_OF_SCOPE;</span> -load_permanently<span class="Delimiter">(</span><span class="Constant">"core.mu"</span><span class="Delimiter">);</span> -transform_all<span class="Delimiter">();</span> +load_file_or_directory<span class="Delimiter">(</span><span class="Constant">"core.mu"</span><span class="Delimiter">);</span> <span class="CommentedCode">//? DUMP("");</span> <span class="CommentedCode">//? exit(0);</span> <span class="Comment">//: Step 2: load any .mu files provided at the commandline</span> <span class="Delimiter">:(before "End Commandline Parsing")</span> <span class="Comment">// Check For .mu Files</span> +<span class="CommentedCode">//? START_TRACING_UNTIL_END_OF_SCOPE</span> <span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// skip argv[0]</span> argv++<span class="Delimiter">;</span> @@ -176,14 +189,15 @@ transform_all<span class="Delimiter">();</span> <span class="Comment">// ignore argv past '--'; that's commandline args for 'main'</span> <span class="Normal">while</span> <span class="Delimiter">(</span>argc > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>string<span class="Delimiter">(</span>*argv<span class="Delimiter">)</span> == <span class="Constant">"--"</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - load_permanently<span class="Delimiter">(</span>*argv<span class="Delimiter">);</span> + load_file_or_directory<span class="Delimiter">(</span>*argv<span class="Delimiter">);</span> argv++<span class="Delimiter">;</span> argc--<span class="Delimiter">;</span> <span class="Delimiter">}</span> - transform_all<span class="Delimiter">();</span> <span class="Normal">if</span> <span class="Delimiter">(</span>Run_tests<span class="Delimiter">)</span> Recipe<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"main"</span><span class="Delimiter">));</span> <span class="Comment">// End Loading .mu Files</span> <span class="Delimiter">}</span> +transform_all<span class="Delimiter">();</span> +save_snapshots<span class="Delimiter">();</span> <span class="Comment">//: Step 3: if we aren't running tests, locate a recipe called 'main' and</span> <span class="Comment">//: start running it.</span> @@ -206,15 +220,15 @@ transform_all<span class="Delimiter">();</span> <span class="Delimiter">:(code)</span> <span class="Normal">void</span> dump_profile<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>::iterator p = Instructions_running<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Instructions_running<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">int</span>>::iterator p = Instructions_running<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Instructions_running<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> cerr << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> cerr << <span class="Constant">"== locations read</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>::iterator p = Locations_read<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Locations_read<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">int</span>>::iterator p = Locations_read<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Locations_read<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> cerr << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> cerr << <span class="Constant">"== locations read by instruction</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>::iterator p = Locations_read_by_instruction<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Locations_read_by_instruction<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">int</span>>::iterator p = Locations_read_by_instruction<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Locations_read_by_instruction<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> cerr << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -233,9 +247,9 @@ transform_all<span class="Delimiter">();</span> atexit<span class="Delimiter">(</span>cleanup_main<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> load_permanently<span class="Delimiter">(</span>string filename<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> load_file_or_directory<span class="Delimiter">(</span>string filename<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_directory<span class="Delimiter">(</span>filename<span class="Delimiter">))</span> <span class="Delimiter">{</span> - load_all_permanently<span class="Delimiter">(</span>filename<span class="Delimiter">);</span> + load_all<span class="Delimiter">(</span>filename<span class="Delimiter">);</span> <span class="Identifier">return</span><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> @@ -246,9 +260,6 @@ atexit<span class="Delimiter">(</span>cleanup_main<span class="Delimiter">);</sp trace<span class="Delimiter">(</span><span class="Constant">9990</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"=== "</span> << filename << end<span class="Delimiter">();</span> load<span class="Delimiter">(</span>fin<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="Normal">bool</span> is_directory<span class="Delimiter">(</span>string path<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -257,13 +268,13 @@ atexit<span class="Delimiter">(</span>cleanup_main<span class="Delimiter">);</sp <span class="Identifier">return</span> info<span class="Delimiter">.</span>st_mode & S_IFDIR<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> load_all_permanently<span class="Delimiter">(</span>string dir<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> load_all<span class="Delimiter">(</span>string dir<span class="Delimiter">)</span> <span class="Delimiter">{</span> dirent** files<span class="Delimiter">;</span> <span class="Normal">int</span> num_files = scandir<span class="Delimiter">(</span>dir<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &files<span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">,</span> alphasort<span class="Delimiter">);</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < num_files<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> string curr_file = files[i]<span class="Delimiter">-></span>d_name<span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>isdigit<span class="Delimiter">(</span>curr_file<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> - load_permanently<span class="Delimiter">(</span>dir+<span class="Constant">'/'</span>+curr_file<span class="Delimiter">);</span> + load_file_or_directory<span class="Delimiter">(</span>dir+<span class="Constant">'/'</span>+curr_file<span class="Delimiter">);</span> free<span class="Delimiter">(</span>files[i]<span class="Delimiter">);</span> files[i] = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -282,44 +293,44 @@ vector<<span class="Normal">double</span>> read_memory<span class="Delimit 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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size = size_of<span class="Delimiter">(</span>x<span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset < size<span class="Delimiter">;</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">double</span> val = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base+offset<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"location "</span> << base+offset << <span class="Constant">" is "</span> << no_scientific<span class="Delimiter">(</span>val<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + <span class="Comment">// End Preprocess read_memory(x)</span> + <span class="Normal">int</span> size = size_of<span class="Delimiter">(</span>x<span class="Delimiter">);</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset < size<span class="Delimiter">;</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">double</span> val = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> x<span class="Delimiter">.</span>value+offset<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"location "</span> << x<span class="Delimiter">.</span>value+offset << <span class="Constant">" is "</span> << no_scientific<span class="Delimiter">(</span>val<span class="Delimiter">)</span> << end<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> -<span class="Normal">void</span> write_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> vector<<span class="Normal">double</span>> data<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> write_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> <span class="Normal">const</span> vector<<span class="Normal">double</span>>& data<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"can't write to "</span> << to_string<span class="Delimiter">(</span>x<span class="Delimiter">)</span> << <span class="Constant">"; no type</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</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="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>base == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Comment">// End Preprocess write_memory(x)</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> <span class="Normal">if</span> <span class="Delimiter">(</span>size_mismatch<span class="Delimiter">(</span>x<span class="Delimiter">,</span> data<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"size mismatch in storing to "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" ("</span> << size_of<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>data<span class="Delimiter">)</span> << <span class="Constant">") at '"</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"size mismatch in storing to "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" ("</span> << size_of<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>data<span class="Delimiter">)</span> << <span class="Constant">") at '"</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// End write_memory(reagent x, long long int base) Special-cases</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset < SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>base+offset > <span class="Constant">0</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << no_scientific<span class="Delimiter">(</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset<span class="Delimiter">))</span> << <span class="Constant">" in location "</span> << base+offset << end<span class="Delimiter">();</span> - put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base+offset<span class="Delimiter">,</span> data<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset<span class="Delimiter">));</span> + <span class="Comment">// End write_memory(reagent x) Special-cases</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset < SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value+offset > <span class="Constant">0</span><span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << no_scientific<span class="Delimiter">(</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset<span class="Delimiter">))</span> << <span class="Constant">" in location "</span> << x<span class="Delimiter">.</span>value+offset << end<span class="Delimiter">();</span> + put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> x<span class="Delimiter">.</span>value+offset<span class="Delimiter">,</span> 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> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// End size_of(reagent) Cases</span> <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// End size_of(type) Cases</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> @@ -332,10 +343,6 @@ vector<<span class="Normal">double</span>> read_memory<span class="Delimit <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">inline</span> <span class="Normal">bool</span> is_dummy<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> x<span class="Delimiter">.</span>name == <span class="Constant">"_"</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> - <span class="Normal">inline</span> <span class="Normal">bool</span> is_literal<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<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>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">)</span> @@ -343,7 +350,7 @@ vector<<span class="Normal">double</span>> read_memory<span class="Delimit <span class="Identifier">return</span> r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">inline</span> <span class="Normal">bool</span> scalar<span class="Delimiter">(</span><span class="Normal">const</span> vector<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">inline</span> <span class="Normal">bool</span> scalar<span class="Delimiter">(</span><span class="Normal">const</span> vector<<span class="Normal">int</span>>& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>x<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">inline</span> <span class="Normal">bool</span> scalar<span class="Delimiter">(</span><span class="Normal">const</span> vector<<span class="Normal">double</span>>& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -356,7 +363,12 @@ vector<<span class="Normal">double</span>> read_memory<span class="Delimit transform_all<span class="Delimiter">();</span> <span class="Normal">if</span> <span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">)</span> > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - run<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>front<span class="Delimiter">());</span> + <span class="Comment">// if a test defines main, it probably wants to start there regardless of</span> + <span class="Comment">// definition order</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"main"</span><span class="Delimiter">)))</span> + run<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"main"</span><span class="Delimiter">));</span> + <span class="Normal">else</span> + run<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>front<span class="Delimiter">());</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario run_label)</span> @@ -365,15 +377,15 @@ def main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] -<span class="traceContains">+run: 1:number <- copy 23</span> -<span class="traceContains">+run: 2:number <- copy 1:number</span> +<span class="traceContains">+run: {1: "number"} <- copy {23: "literal"}</span> +<span class="traceContains">+run: {2: "number"} <- copy {1: "number"}</span> <span class="traceAbsent">-run: +foo</span> <span class="Delimiter">:(scenario run_dummy)</span> def main [ _<span class="Special"> <- </span>copy <span class="Constant">0</span> ] -<span class="traceContains">+run: _ <- copy 0</span> +<span class="traceContains">+run: _ <- copy {0: "literal"}</span> <span class="Delimiter">:(scenario write_to_0_disallowed)</span> <span class="Special">% Hide_errors = true;</span> @@ -411,3 +423,4 @@ def main [ </pre> </body> </html> +<!-- vim: set foldmethod=manual : --> |