diff options
Diffstat (limited to 'html/057static_dispatch.cc.html')
-rw-r--r-- | html/057static_dispatch.cc.html | 368 |
1 files changed, 180 insertions, 188 deletions
diff --git a/html/057static_dispatch.cc.html b/html/057static_dispatch.cc.html index 5287542c..9f7fa7b6 100644 --- a/html/057static_dispatch.cc.html +++ b/html/057static_dispatch.cc.html @@ -3,47 +3,40 @@ <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Mu - 057static_dispatch.cc</title> -<meta name="Generator" content="Vim/7.4"> -<meta name="plugin-version" content="vim7.4_v1"> +<meta name="Generator" content="Vim/7.3"> +<meta name="plugin-version" content="vim7.3_v6"> <meta name="syntax" content="cpp"> -<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> -<meta name="colorscheme" content="minimal"> +<meta name="settings" content="use_css"> <style type="text/css"> <!-- -pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } +pre { font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } -* { font-size: 1.05em; } .traceAbsent { color: #c00000; } -.traceContains { color: #008000; } .cSpecial { color: #008000; } -.Comment { color: #9090ff; } -.Delimiter { color: #a04060; } -.Special { color: #ff6060; } .Identifier { color: #804000; } +.Normal { color: #eeeeee; background-color: #080808; } +.traceContains { color: #008000; } +.Special { color: #ff6060; } .Constant { color: #00a0a0; } +.Delimiter { color: #a04060; } +.Comment { color: #9090ff; } --> </style> - -<script type='text/javascript'> -<!-- - ---> -</script> </head> <body> -<pre id='vimCodeElement'> +<pre> <span class="Comment">//: Transform to maintain multiple variants of a recipe depending on the</span> <span class="Comment">//: number and types of the ingredients and products. Allows us to use nice</span> <span class="Comment">//: names like 'print' or 'length' in many mutually extensible ways.</span> <span class="Delimiter">:(scenario static_dispatch)</span> -recipe main [ +def main [ <span class="Constant">7</span>:number/<span class="Special">raw <- </span>test <span class="Constant">3</span> ] -recipe test a:number <span class="Delimiter">-></span> z:number [ +def test a:number <span class="Delimiter">-></span> z:number [ z<span class="Special"> <- </span>copy <span class="Constant">1</span> ] -recipe test a:number<span class="Delimiter">,</span> b:number <span class="Delimiter">-></span> z:number [ +def test a:number<span class="Delimiter">,</span> b:number <span class="Delimiter">-></span> z:number [ z<span class="Special"> <- </span>copy <span class="Constant">2</span> ] <span class="traceContains">+mem: storing 1 in location 7</span> @@ -56,20 +49,20 @@ map<string<span class="Delimiter">,</span> vector<recipe_ordinal> > <span class="Delimiter">:(before "End One-time Setup")</span> put<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> <span class="Constant">"main"</span><span class="Delimiter">,</span> vector<recipe_ordinal><span class="Delimiter">());</span> <span class="Comment">// since we manually added main to Recipe_ordinal</span> <span class="Delimiter">:(before "Clear Other State For Recently_added_recipes")</span> -for <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> vector<recipe_ordinal> >::iterator p = Recipe_variants<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Recipe_variants<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>find<span class="Delimiter">(</span>Recently_added_recipes<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> Recently_added_recipes<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> != Recently_added_recipes<span class="Delimiter">.</span>end<span class="Delimiter">())</span> +<span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> vector<recipe_ordinal> >::iterator p = Recipe_variants<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Recipe_variants<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><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>p<span class="Delimiter">-></span>second<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>find<span class="Delimiter">(</span>Recently_added_recipes<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> Recently_added_recipes<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> != Recently_added_recipes<span class="Delimiter">.</span>end<span class="Delimiter">())</span> p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> = -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// just leave a ghost</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Load Recipe Header(result)")</span> <span class="Comment">// there can only ever be one variant for main</span> -if <span class="Delimiter">(</span>result<span class="Delimiter">.</span>name != <span class="Constant">"main"</span> && contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - const recipe_ordinal r = get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">)</span> || get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>has_header<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">.</span>name != <span class="Constant">"main"</span> && contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> recipe_ordinal r = get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">)</span> || get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>has_header<span class="Delimiter">)</span> <span class="Delimiter">{</span> string new_name = matching_variant_name<span class="Delimiter">(</span>result<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>new_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>new_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span class="Comment">// variant doesn't already exist</span> new_name = next_unused_recipe_name<span class="Delimiter">(</span>result<span class="Delimiter">.</span>name<span class="Delimiter">);</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> new_name<span class="Delimiter">,</span> Next_recipe_ordinal++<span class="Delimiter">);</span> @@ -79,34 +72,34 @@ if <span class="Delimiter">(</span>result<span class="Delimiter">.</span>name != result<span class="Delimiter">.</span>name = new_name<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -else <span class="Delimiter">{</span> +<span class="Normal">else</span> <span class="Delimiter">{</span> <span class="Comment">// save first variant</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">,</span> Next_recipe_ordinal++<span class="Delimiter">);</span> get_or_insert<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -string matching_variant_name<span class="Delimiter">(</span>const recipe& rr<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const vector<recipe_ordinal>& variants = get_or_insert<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> rr<span class="Delimiter">.</span>name<span class="Delimiter">);</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - const recipe& candidate = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>!all_reagents_match<span class="Delimiter">(</span>rr<span class="Delimiter">,</span> candidate<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +string matching_variant_name<span class="Delimiter">(</span><span class="Normal">const</span> recipe& rr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> vector<recipe_ordinal>& variants = get_or_insert<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> rr<span class="Delimiter">.</span>name<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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Normal">const</span> recipe& candidate = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!all_reagents_match<span class="Delimiter">(</span>rr<span class="Delimiter">,</span> candidate<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Identifier">return</span> candidate<span class="Delimiter">.</span>name<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -bool all_reagents_match<span class="Delimiter">(</span>const recipe& r1<span class="Delimiter">,</span> const recipe& r2<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>r2<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>products<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>r2<span class="Delimiter">.</span>products<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> r2<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="Normal">bool</span> all_reagents_match<span class="Delimiter">(</span><span class="Normal">const</span> recipe& r1<span class="Delimiter">,</span> <span class="Normal">const</span> recipe& r2<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>r2<span class="Delimiter">.</span>ingredients<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>SIZE<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>products<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>r2<span class="Delimiter">.</span>products<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</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>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> r2<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="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> r2<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="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>r1<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> r2<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="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -119,28 +112,28 @@ set<string> Literal_type_names<span class="Delimiter">;</span> Literal_type_names<span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"number"</span><span class="Delimiter">);</span> Literal_type_names<span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"character"</span><span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -bool deeply_equal_type_names<span class="Delimiter">(</span>const reagent& a<span class="Delimiter">,</span> const reagent& b<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">bool</span> deeply_equal_type_names<span class="Delimiter">(</span><span class="Normal">const</span> reagent& a<span class="Delimiter">,</span> <span class="Normal">const</span> reagent& b<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> deeply_equal_type_names<span class="Delimiter">(</span>a<span class="Delimiter">.</span>type<span class="Delimiter">,</span> b<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Delimiter">}</span> -bool deeply_equal_type_names<span class="Delimiter">(</span>const type_tree* a<span class="Delimiter">,</span> const type_tree* b<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!a<span class="Delimiter">)</span> <span class="Identifier">return</span> !b<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!b<span class="Delimiter">)</span> <span class="Identifier">return</span> !a<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>a<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span> && b<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> +<span class="Normal">bool</span> deeply_equal_type_names<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* a<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree* b<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!a<span class="Delimiter">)</span> <span class="Identifier">return</span> !b<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!b<span class="Delimiter">)</span> <span class="Identifier">return</span> !a<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>a<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span> && b<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>a<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>a<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>b<span class="Delimiter">-></span>name<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>b<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>b<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>a<span class="Delimiter">-></span>name<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> <span class="Identifier">return</span> a<span class="Delimiter">-></span>name == b<span class="Delimiter">-></span>name && deeply_equal_type_names<span class="Delimiter">(</span>a<span class="Delimiter">-></span>left<span class="Delimiter">,</span> b<span class="Delimiter">-></span>left<span class="Delimiter">)</span> && deeply_equal_type_names<span class="Delimiter">(</span>a<span class="Delimiter">-></span>right<span class="Delimiter">,</span> b<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> -string next_unused_recipe_name<span class="Delimiter">(</span>const string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">2</span><span class="Delimiter">;</span> <span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string next_unused_recipe_name<span class="Delimiter">(</span><span class="Normal">const</span> string& recipe_name<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">2</span><span class="Delimiter">;</span> <span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream out<span class="Delimiter">;</span> out << recipe_name << <span class="Constant">'_'</span> << i<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> out<span class="Delimiter">.</span>str<span class="Delimiter">()))</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> out<span class="Delimiter">.</span>str<span class="Delimiter">()))</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -149,22 +142,22 @@ string next_unused_recipe_name<span class="Delimiter">(</span>const string& <span class="Comment">//: call with the most suitable variant.</span> <span class="Delimiter">:(scenario static_dispatch_picks_most_similar_variant)</span> -recipe main [ +def main [ <span class="Constant">7</span>:number/<span class="Special">raw <- </span>test <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">,</span> <span class="Constant">5</span> ] -recipe test a:number <span class="Delimiter">-></span> z:number [ +def test a:number <span class="Delimiter">-></span> z:number [ z<span class="Special"> <- </span>copy <span class="Constant">1</span> ] -recipe test a:number<span class="Delimiter">,</span> b:number <span class="Delimiter">-></span> z:number [ +def test a:number<span class="Delimiter">,</span> b:number <span class="Delimiter">-></span> z:number [ z<span class="Special"> <- </span>copy <span class="Constant">2</span> ] <span class="traceContains">+mem: storing 2 in location 7</span> <span class="Comment">//: support recipe headers in a previous transform to fill in missing types</span> <span class="Delimiter">:(before "End check_or_set_invalid_types")</span> -for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller<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">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>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> check_or_set_invalid_types<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"recipe header ingredient"</span><span class="Delimiter">);</span> -for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<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>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> check_or_set_invalid_types<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"recipe header product"</span><span class="Delimiter">);</span> <span class="Comment">//: after filling in all missing types (because we'll be introducing 'blank' types in this transform in a later layer, for shape-shifting recipes)</span> @@ -181,18 +174,18 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa list<call> resolve_stack<span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> -void resolve_ambiguous_calls<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> resolve_ambiguous_calls<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> recipe& caller_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"--- resolve ambiguous calls for recipe "</span> << caller_recipe<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> - for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<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> index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>non_ghost_size<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">))</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>non_ghost_size<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">))</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction "</span> << inst<span class="Delimiter">.</span>original_string << end<span class="Delimiter">();</span> resolve_stack<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>r<span class="Delimiter">));</span> resolve_stack<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_step_index = index<span class="Delimiter">;</span> string new_name = best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!new_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!new_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> inst<span class="Delimiter">.</span>name = new_name<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>resolve_stack<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_recipe == r<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>resolve_stack<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_step_index == index<span class="Delimiter">);</span> @@ -200,43 +193,43 @@ void resolve_ambiguous_calls<span class="Delimiter">(</span>recipe_ordinal r<spa <span class="Delimiter">}</span> <span class="Delimiter">}</span> -string best_variant<span class="Delimiter">(</span>instruction& inst<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string best_variant<span class="Delimiter">(</span>instruction& inst<span class="Delimiter">,</span> <span class="Normal">const</span> recipe& caller_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> vector<recipe_ordinal>& variants = get<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">);</span> vector<recipe_ordinal> candidates<span class="Delimiter">;</span> <span class="Comment">// Static Dispatch Phase 1</span> candidates = strictly_matching_variants<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> <span class="Comment">// Static Dispatch Phase 2 (shape-shifting recipes in a later layer)</span> <span class="Comment">// End Static Dispatch Phase 2</span> <span class="Comment">// Static Dispatch Phase 3</span> candidates = strictly_matching_variants_except_literal_against_boolean<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> <span class="Comment">// Static Dispatch Phase 4</span> candidates = matching_variants<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> <span class="Comment">// error messages</span> - if <span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">)</span> >= MAX_PRIMITIVE_RECIPES<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// we currently don't check types for primitive variants</span> - raise_error << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"failed to find a matching call for '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - for <span class="Delimiter">(</span>list<call>::iterator p = <span class="Comment">/*</span><span class="Comment">skip</span><span class="Comment">*/</span>++resolve_stack<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != resolve_stack<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const recipe& specializer_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> p<span class="Delimiter">-></span>running_recipe<span class="Delimiter">);</span> - const instruction& specializer_inst = specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>p<span class="Delimiter">-></span>running_step_index<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>name != <span class="Constant">"interactive"</span><span class="Delimiter">)</span> - raise_error << <span class="Constant">" (from '"</span> << to_string<span class="Delimiter">(</span>specializer_inst<span class="Delimiter">)</span> << <span class="Constant">"' in "</span> << specializer_recipe<span class="Delimiter">.</span>name << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - else - raise_error << <span class="Constant">" (from '"</span> << to_string<span class="Delimiter">(</span>specializer_inst<span class="Delimiter">)</span> << <span class="Constant">"')</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">)</span> >= MAX_PRIMITIVE_RECIPES<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// we currently don't check types for primitive variants</span> + raise << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"failed to find a matching call for '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Normal">for</span> <span class="Delimiter">(</span>list<call>::iterator p = <span class="Comment">/*</span><span class="Comment">skip</span><span class="Comment">*/</span>++resolve_stack<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != resolve_stack<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> recipe& specializer_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> p<span class="Delimiter">-></span>running_recipe<span class="Delimiter">);</span> + <span class="Normal">const</span> instruction& specializer_inst = specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>p<span class="Delimiter">-></span>running_step_index<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>name != <span class="Constant">"interactive"</span><span class="Delimiter">)</span> + raise << <span class="Constant">" (from '"</span> << to_string<span class="Delimiter">(</span>specializer_inst<span class="Delimiter">)</span> << <span class="Constant">"' in "</span> << specializer_recipe<span class="Delimiter">.</span>name << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Normal">else</span> + raise << <span class="Constant">" (from '"</span> << to_string<span class="Delimiter">(</span>specializer_inst<span class="Delimiter">)</span> << <span class="Constant">"')</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Comment">// One special-case to help with the rewrite_stash transform. (cross-layer)</span> - if <span class="Delimiter">(</span>specializer_inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"stash_"</span><span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>specializer_inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"stash_"</span><span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction stash_inst<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>next_stash<span class="Delimiter">(</span>*p<span class="Delimiter">,</span> &stash_inst<span class="Delimiter">))</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>name != <span class="Constant">"interactive"</span><span class="Delimiter">)</span> - raise_error << <span class="Constant">" (part of '"</span> << stash_inst<span class="Delimiter">.</span>original_string << <span class="Constant">"' in "</span> << specializer_recipe<span class="Delimiter">.</span>name << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - else - raise_error << <span class="Constant">" (part of '"</span> << stash_inst<span class="Delimiter">.</span>original_string << <span class="Constant">"')</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>next_stash<span class="Delimiter">(</span>*p<span class="Delimiter">,</span> &stash_inst<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>name != <span class="Constant">"interactive"</span><span class="Delimiter">)</span> + raise << <span class="Constant">" (part of '"</span> << stash_inst<span class="Delimiter">.</span>original_string << <span class="Constant">"' in "</span> << specializer_recipe<span class="Delimiter">.</span>name << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Normal">else</span> + raise << <span class="Constant">" (part of '"</span> << stash_inst<span class="Delimiter">.</span>original_string << <span class="Constant">"')</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -245,27 +238,27 @@ string best_variant<span class="Delimiter">(</span>instruction& inst<span cl <span class="Delimiter">}</span> <span class="Comment">// phase 1</span> -vector<recipe_ordinal> strictly_matching_variants<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> +vector<recipe_ordinal> strictly_matching_variants<span class="Delimiter">(</span><span class="Normal">const</span> instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> vector<recipe_ordinal> result<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking variant (strict) "</span> << i << <span class="Constant">": "</span> << header_label<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>all_header_reagents_strictly_match<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>all_header_reagents_strictly_match<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -bool all_header_reagents_strictly_match<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> const recipe& variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<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="Normal">bool</span> all_header_reagents_strictly_match<span class="Delimiter">(</span><span class="Normal">const</span> instruction& inst<span class="Delimiter">,</span> <span class="Normal">const</span> recipe& variant<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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: ingredient "</span> << i << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<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="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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: product "</span> << i << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -274,27 +267,27 @@ bool all_header_reagents_strictly_match<span class="Delimiter">(</span>const ins <span class="Delimiter">}</span> <span class="Comment">// phase 3</span> -vector<recipe_ordinal> strictly_matching_variants_except_literal_against_boolean<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> +vector<recipe_ordinal> strictly_matching_variants_except_literal_against_boolean<span class="Delimiter">(</span><span class="Normal">const</span> instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> vector<recipe_ordinal> result<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking variant (strict except literals-against-booleans) "</span> << i << <span class="Constant">": "</span> << header_label<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>all_header_reagents_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>all_header_reagents_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -bool all_header_reagents_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> const recipe& variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!types_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<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="Normal">bool</span> all_header_reagents_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span><span class="Normal">const</span> instruction& inst<span class="Delimiter">,</span> <span class="Normal">const</span> recipe& variant<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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: ingredient "</span> << i << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!types_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<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="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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: product "</span> << i << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -303,27 +296,27 @@ bool all_header_reagents_strictly_match_except_literal_against_boolean<span clas <span class="Delimiter">}</span> <span class="Comment">// phase 4</span> -vector<recipe_ordinal> matching_variants<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> +vector<recipe_ordinal> matching_variants<span class="Delimiter">(</span><span class="Normal">const</span> instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> vector<recipe_ordinal> result<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking variant "</span> << i << <span class="Constant">": "</span> << header_label<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>all_header_reagents_match<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>all_header_reagents_match<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -bool all_header_reagents_match<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> const recipe& variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<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="Normal">bool</span> all_header_reagents_match<span class="Delimiter">(</span><span class="Normal">const</span> instruction& inst<span class="Delimiter">,</span> <span class="Normal">const</span> recipe& variant<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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: ingredient "</span> << i << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<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="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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: product "</span> << i << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -332,16 +325,16 @@ bool all_header_reagents_match<span class="Delimiter">(</span>const instruction& <span class="Delimiter">}</span> <span class="Comment">// tie-breaker for each phase</span> -const recipe& best_variant<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& candidates<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">const</span> recipe& best_variant<span class="Delimiter">(</span><span class="Normal">const</span> instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& candidates<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> - long long int min_score = <span class="Constant">999</span><span class="Delimiter">;</span> - long long int min_index = <span class="Constant">0</span><span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>candidates<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const recipe& candidate = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - long long int score = abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>candidate<span class="Delimiter">.</span>products<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">))</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> min_score = <span class="Constant">999</span><span class="Delimiter">;</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> min_index = <span class="Constant">0</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>candidates<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> recipe& candidate = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> score = abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>candidate<span class="Delimiter">.</span>products<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">))</span> + abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>candidate<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> assert<span class="Delimiter">(</span>score < <span class="Constant">999</span><span class="Delimiter">);</span> - if <span class="Delimiter">(</span>score < min_score<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>score < min_score<span class="Delimiter">)</span> <span class="Delimiter">{</span> min_score = score<span class="Delimiter">;</span> min_index = i<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -349,19 +342,19 @@ const recipe& best_variant<span class="Delimiter">(</span>const instruction& <span class="Identifier">return</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>min_index<span class="Delimiter">));</span> <span class="Delimiter">}</span> -long long int non_ghost_size<span class="Delimiter">(</span>vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> - long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != -<span class="Constant">1</span><span class="Delimiter">)</span> ++result<span class="Delimiter">;</span> +<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> non_ghost_size<span class="Delimiter">(</span>vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = <span class="Constant">0</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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != -<span class="Constant">1</span><span class="Delimiter">)</span> ++result<span class="Delimiter">;</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -bool next_stash<span class="Delimiter">(</span>const call& c<span class="Delimiter">,</span> instruction* stash_inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const recipe& specializer_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> c<span class="Delimiter">.</span>running_recipe<span class="Delimiter">);</span> - long long int index = c<span class="Delimiter">.</span>running_step_index<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>++index<span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const instruction& inst = specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"stash"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">bool</span> next_stash<span class="Delimiter">(</span><span class="Normal">const</span> call& c<span class="Delimiter">,</span> instruction* stash_inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> recipe& specializer_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> c<span class="Delimiter">.</span>running_recipe<span class="Delimiter">);</span> + <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index = c<span class="Delimiter">.</span>running_step_index<span class="Delimiter">;</span> + <span class="Normal">for</span> <span class="Delimiter">(</span>++index<span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> instruction& inst = specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"stash"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> *stash_inst = inst<span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -370,37 +363,37 @@ bool next_stash<span class="Delimiter">(</span>const call& c<span class="Del <span class="Delimiter">}</span> <span class="Delimiter">:(scenario static_dispatch_disabled_in_recipe_without_variants)</span> -recipe main [ +def main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>test <span class="Constant">3</span> ] -recipe test [ +def test [ <span class="Constant">2</span>:number<span class="Special"> <- </span>next-ingredient <span class="Comment"># ensure no header</span> - reply <span class="Constant">34</span> + <span class="Identifier">return</span> <span class="Constant">34</span> ] <span class="traceContains">+mem: storing 34 in location 1</span> <span class="Delimiter">:(scenario static_dispatch_disabled_on_headerless_definition)</span> <span class="Special">% Hide_errors = true;</span> -recipe test a:number <span class="Delimiter">-></span> z:number [ +def test a:number <span class="Delimiter">-></span> z:number [ z<span class="Special"> <- </span>copy <span class="Constant">1</span> ] -recipe test [ - reply <span class="Constant">34</span> +def test [ + <span class="Identifier">return</span> <span class="Constant">34</span> ] <span class="traceContains">+error: redefining recipe test</span> <span class="Delimiter">:(scenario static_dispatch_disabled_on_headerless_definition_2)</span> <span class="Special">% Hide_errors = true;</span> -recipe test [ - reply <span class="Constant">34</span> +def test [ + <span class="Identifier">return</span> <span class="Constant">34</span> ] -recipe test a:number <span class="Delimiter">-></span> z:number [ +def test a:number <span class="Delimiter">-></span> z:number [ z<span class="Special"> <- </span>copy <span class="Constant">1</span> ] <span class="traceContains">+error: redefining recipe test</span> <span class="Delimiter">:(scenario static_dispatch_on_primitive_names)</span> -recipe main [ +def main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number @@ -410,7 +403,7 @@ recipe main [ ] <span class="Comment"># temporarily hardcode number equality to always fail</span> -recipe equal x:number<span class="Delimiter">,</span> y:number <span class="Delimiter">-></span> z:boolean [ +def equal x:number<span class="Delimiter">,</span> y:number <span class="Delimiter">-></span> z:boolean [ local-scope load-ingredients z<span class="Special"> <- </span>copy <span class="Constant">0</span>/<span class="Constant">false</span> @@ -421,15 +414,15 @@ recipe equal x:number<span class="Delimiter">,</span> y:number <span class="Deli <span class="traceContains">+mem: storing 1 in location 6</span> <span class="Delimiter">:(scenario static_dispatch_works_with_dummy_results_for_containers)</span> -recipe main [ +def main [ _<span class="Special"> <- </span>test <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> ] -recipe test a:number <span class="Delimiter">-></span> z:point [ +def test a:number <span class="Delimiter">-></span> z:point [ local-scope load-ingredients z<span class="Special"> <- </span>merge a<span class="Delimiter">,</span> <span class="Constant">0</span> ] -recipe test a:number<span class="Delimiter">,</span> b:number <span class="Delimiter">-></span> z:point [ +def test a:number<span class="Delimiter">,</span> b:number <span class="Delimiter">-></span> z:point [ local-scope load-ingredients z<span class="Special"> <- </span>merge a<span class="Delimiter">,</span> b @@ -437,14 +430,14 @@ recipe test a:number<span class="Delimiter">,</span> b:number <span class="Delim $error: <span class="Constant">0</span> <span class="Delimiter">:(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_first_use)</span> -recipe main [ - x:address:shared:foo<span class="Special"> <- </span>new foo:type +def main [ + x:address:shared:foo<span class="Special"> <- </span><span class="Normal">new</span> foo:type test x ] container foo [ x:number ] -recipe test a:address:shared:foo <span class="Delimiter">-></span> z:number [ +def test a:address:shared:foo <span class="Delimiter">-></span> z:number [ local-scope load-ingredients z:number<span class="Special"> <- </span>get *a<span class="Delimiter">,</span> x:offset @@ -452,11 +445,11 @@ recipe test a:address:shared:foo <span class="Delimiter">-></span> z:number [ $error: <span class="Constant">0</span> <span class="Delimiter">:(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_second_use)</span> -recipe main [ - x:address:shared:foo<span class="Special"> <- </span>new foo:type +def main [ + x:address:shared:foo<span class="Special"> <- </span><span class="Normal">new</span> foo:type test x ] -recipe test a:address:shared:foo <span class="Delimiter">-></span> z:number [ +def test a:address:shared:foo <span class="Delimiter">-></span> z:number [ local-scope load-ingredients z:number<span class="Special"> <- </span>get *a<span class="Delimiter">,</span> x:offset @@ -467,139 +460,138 @@ container foo [ $error: <span class="Constant">0</span> <span class="Delimiter">:(scenario static_dispatch_prefers_literals_to_be_numbers_rather_than_addresses)</span> -recipe main [ +def main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>foo <span class="Constant">0</span> ] -recipe foo x:address:number <span class="Delimiter">-></span> y:number [ - reply <span class="Constant">34</span> +def foo x:address:number <span class="Delimiter">-></span> y:number [ + <span class="Identifier">return</span> <span class="Constant">34</span> ] -recipe foo x:number <span class="Delimiter">-></span> y:number [ - reply <span class="Constant">35</span> +def foo x:number <span class="Delimiter">-></span> y:number [ + <span class="Identifier">return</span> <span class="Constant">35</span> ] <span class="traceContains">+mem: storing 35 in location 1</span> <span class="Delimiter">:(scenario static_dispatch_on_non_literal_character_ignores_variant_with_numbers)</span> <span class="Special">% Hide_errors = true;</span> -recipe main [ +def main [ local-scope x:character<span class="Special"> <- </span>copy <span class="Constant">10</span>/newline <span class="Constant">1</span>:number/<span class="Special">raw <- </span>foo x ] -recipe foo x:number <span class="Delimiter">-></span> y:number [ +def foo x:number <span class="Delimiter">-></span> y:number [ load-ingredients - reply <span class="Constant">34</span> + <span class="Identifier">return</span> <span class="Constant">34</span> ] <span class="traceContains">+error: main: ingredient 0 has the wrong type at '1:number/raw <- foo x'</span> <span class="traceAbsent">-mem: storing 34 in location 1</span> <span class="Delimiter">:(scenario static_dispatch_dispatches_literal_to_boolean_before_character)</span> -recipe main [ +def main [ <span class="Constant">1</span>:number/<span class="Special">raw <- </span>foo <span class="Constant">0</span> <span class="Comment"># valid literal for boolean</span> ] -recipe foo x:character <span class="Delimiter">-></span> y:number [ +def foo x:character <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">34</span> + <span class="Identifier">return</span> <span class="Constant">34</span> ] -recipe foo x:boolean <span class="Delimiter">-></span> y:number [ +def foo x:boolean <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">35</span> + <span class="Identifier">return</span> <span class="Constant">35</span> ] <span class="Comment"># boolean variant is preferred</span> <span class="traceContains">+mem: storing 35 in location 1</span> <span class="Delimiter">:(scenario static_dispatch_dispatches_literal_to_character_when_out_of_boolean_range)</span> -recipe main [ +def main [ <span class="Constant">1</span>:number/<span class="Special">raw <- </span>foo <span class="Constant">97</span> <span class="Comment"># not a valid literal for boolean</span> ] -recipe foo x:character <span class="Delimiter">-></span> y:number [ +def foo x:character <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">34</span> + <span class="Identifier">return</span> <span class="Constant">34</span> ] -recipe foo x:boolean <span class="Delimiter">-></span> y:number [ +def foo x:boolean <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">35</span> + <span class="Identifier">return</span> <span class="Constant">35</span> ] <span class="Comment"># character variant is preferred</span> <span class="traceContains">+mem: storing 34 in location 1</span> <span class="Delimiter">:(scenario static_dispatch_dispatches_literal_to_number_if_at_all_possible)</span> -recipe main [ +def main [ <span class="Constant">1</span>:number/<span class="Special">raw <- </span>foo <span class="Constant">97</span> ] -recipe foo x:character <span class="Delimiter">-></span> y:number [ +def foo x:character <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">34</span> + <span class="Identifier">return</span> <span class="Constant">34</span> ] -recipe foo x:number <span class="Delimiter">-></span> y:number [ +def foo x:number <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">35</span> + <span class="Identifier">return</span> <span class="Constant">35</span> ] <span class="Comment"># number variant is preferred</span> <span class="traceContains">+mem: storing 35 in location 1</span> <span class="Delimiter">:(code)</span> string header_label<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + <span class="Normal">const</span> recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> ostringstream out<span class="Delimiter">;</span> out << <span class="Constant">"recipe "</span> << caller<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller<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">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>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> out << <span class="Constant">' '</span> << to_string<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>!caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> out << <span class="Constant">" ->"</span><span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> out << <span class="Constant">" ->"</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>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> out << <span class="Constant">' '</span> << to_string<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario reload_variant_retains_other_variants)</span> -recipe main [ +def main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>foo <span class="Constant">1</span>:number ] -recipe foo x:number <span class="Delimiter">-></span> y:number [ +def foo x:number <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">34</span> + <span class="Identifier">return</span> <span class="Constant">34</span> ] -recipe foo x:address:number <span class="Delimiter">-></span> y:number [ +def foo x:address:number <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">35</span> + <span class="Identifier">return</span> <span class="Constant">35</span> ] -recipe! foo x:address:number <span class="Delimiter">-></span> y:number [ +def! foo x:address:number <span class="Delimiter">-></span> y:number [ local-scope load-ingredients - reply <span class="Constant">36</span> + <span class="Identifier">return</span> <span class="Constant">36</span> ] <span class="traceContains">+mem: storing 34 in location 2</span> $error: <span class="Constant">0</span> <span class="Delimiter">:(scenario dispatch_errors_come_after_unknown_name_errors)</span> <span class="Special">% Hide_errors = true;</span> -recipe main [ +def main [ y:number<span class="Special"> <- </span>foo x ] -recipe foo a:number <span class="Delimiter">-></span> b:number [ +def foo a:number <span class="Delimiter">-></span> b:number [ local-scope load-ingredients - reply <span class="Constant">34</span> + <span class="Identifier">return</span> <span class="Constant">34</span> ] -recipe foo a:boolean <span class="Delimiter">-></span> b:number [ +def foo a:boolean <span class="Delimiter">-></span> b:number [ local-scope load-ingredients - reply <span class="Constant">35</span> + <span class="Identifier">return</span> <span class="Constant">35</span> ] <span class="traceContains">+error: main: missing type for x in 'y:number <- foo x'</span> <span class="traceContains">+error: main: failed to find a matching call for 'y:number <- foo x'</span> <span class="Delimiter">:(before "End Includes")</span> -using std::abs<span class="Delimiter">;</span> +<span class="Normal">using</span> std::abs<span class="Delimiter">;</span> </pre> </body> </html> -<!-- vim: set foldmethod=manual : --> |