diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-01-26 23:47:23 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-01-26 23:47:23 -0800 |
commit | d009e158803956c76adbf8f58a62884c3e7affb3 (patch) | |
tree | b88198e28d15cd1fc064f5300365a190decc4c50 /html/057static_dispatch.cc.html | |
parent | 2da43c9462c7b7c1bb78d2f2826b3b97b4874973 (diff) | |
download | mu-d009e158803956c76adbf8f58a62884c3e7affb3.tar.gz |
2605
Diffstat (limited to 'html/057static_dispatch.cc.html')
-rw-r--r-- | html/057static_dispatch.cc.html | 98 |
1 files changed, 33 insertions, 65 deletions
diff --git a/html/057static_dispatch.cc.html b/html/057static_dispatch.cc.html index 04d02ab2..319c72e9 100644 --- a/html/057static_dispatch.cc.html +++ b/html/057static_dispatch.cc.html @@ -13,8 +13,8 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.traceContains { color: #008000; } .traceAbsent { color: #c00000; } +.traceContains { color: #008000; } .Identifier { color: #804000; } .cSpecial { color: #008000; } .Comment { color: #9090ff; } @@ -65,16 +65,14 @@ for <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Load Recipe Header(result)")</span> -if <span class="Delimiter">(</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> +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> -<span class="CommentedCode">//? LOG << "checking " << r << " " << result.name << '\n';</span> <span class="CommentedCode">//? cerr << result.name << ": " << contains_key(Recipe, r) << (contains_key(Recipe, r) ? get(Recipe, r).has_header : 0) << matching_variant_name(result) << '\n';</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> 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="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> -<span class="CommentedCode">//? LOG << "adding a variant of " << result.name << ": " << new_name << " is now " << Next_recipe_ordinal << '\n';</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> 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> new_name<span class="Delimiter">));</span> <span class="Delimiter">}</span> @@ -84,7 +82,6 @@ if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>R <span class="Delimiter">}</span> else <span class="Delimiter">{</span> <span class="Comment">// save first variant</span> -<span class="CommentedCode">//? LOG << "saving first variant of " << result.name << ": " << Next_recipe_ordinal << '\n';</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> @@ -93,14 +90,11 @@ else <span class="Delimiter">{</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> -<span class="CommentedCode">//? LOG << "checking variant " << variants.at(i) << " of " << rr.name << '\n';</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> -<span class="CommentedCode">//? LOG << " exists\n";</span> <span class="Identifier">return</span> candidate<span class="Delimiter">.</span>name<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="CommentedCode">//? LOG << " does not exist\n";</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -178,7 +172,7 @@ for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</ <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> -<span class="Delimiter">:(after "End Type Modifying Transforms")</span> +<span class="Delimiter">:(after "Transform.push_back(transform_names)")</span> Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>resolve_ambiguous_calls<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> <span class="Delimiter">:(code)</span> @@ -224,13 +218,8 @@ long long int variant_score<span class="Delimiter">(</span>const instruction& <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> const vector<reagent>& header_ingredients = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>ingredients<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> < SIZE<span class="Delimiter">(</span>header_ingredients<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">"too few ingredients"</span> << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "too few ingredients\n";</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> <span class="CommentedCode">//? cerr << "=== checking ingredients\n";</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>header_ingredients<span class="Delimiter">);</span> ++i<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>header_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>header_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">"mismatch: ingredient "</span> << i << end<span class="Delimiter">();</span> <span class="CommentedCode">//? cerr << "mismatch: ingredient " << i << '\n';</span> @@ -253,13 +242,8 @@ long long int variant_score<span class="Delimiter">(</span>const instruction& <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="CommentedCode">//? cerr << "=== done checking ingredients\n";</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>products<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">"too few products"</span> << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "too few products\n";</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> const vector<reagent>& header_products = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>products<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>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<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>header_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>header_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">"mismatch: product "</span> << i << end<span class="Delimiter">();</span> @@ -283,8 +267,8 @@ long long int variant_score<span class="Delimiter">(</span>const instruction& <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Comment">// the greater the number of unused ingredients/products, the lower the score</span> - <span class="Identifier">return</span> result - <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<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> - - <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>ingredients<span class="Delimiter">));</span> <span class="Comment">// ok to go negative</span> + <span class="Identifier">return</span> result - abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<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> + - abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>ingredients<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario static_dispatch_disabled_on_headerless_definition)</span> @@ -348,13 +332,13 @@ $error: <span class="Constant">0</span> <span class="Delimiter">:(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_first_use)</span> <span class="Special">% Hide_errors = true;</span> recipe main [ - x:address:foo<span class="Special"> <- </span>new foo:type + x:address:shared:foo<span class="Special"> <- </span>new foo:type test x ] container foo [ x:number ] -recipe test a:address:foo <span class="Delimiter">-></span> z:number [ +recipe 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 @@ -364,10 +348,10 @@ $error: <span class="Constant">0</span> <span class="Delimiter">:(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_second_use)</span> <span class="Special">% Hide_errors = true;</span> recipe main [ - x:address:foo<span class="Special"> <- </span>new foo:type + x:address:shared:foo<span class="Special"> <- </span>new foo:type test x ] -recipe test a:address:foo <span class="Delimiter">-></span> z:number [ +recipe 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 @@ -400,7 +384,7 @@ recipe foo x:number <span class="Delimiter">-></span> y:number [ load-ingredients reply <span class="Constant">34</span> ] -<span class="traceContains">+error: foo: wrong type for ingredient x:number</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> @@ -454,43 +438,6 @@ recipe foo x:number <span class="Delimiter">-></span> y:number [ <span class="Comment"># number variant is preferred</span> <span class="traceContains">+mem: storing 35 in location 1</span> -<span class="Comment">//: after we make all attempts to dispatch, any unhandled cases will end up at</span> -<span class="Comment">//: some wrong variant and trigger an error while trying to load-ingredients</span> - -<span class="Delimiter">:(scenario static_dispatch_shows_clear_error_on_missing_variant)</span> -<span class="Special">% Hide_errors = true;</span> -recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>foo <span class="Constant">34</span> -] -recipe foo x:boolean <span class="Delimiter">-></span> y:number [ - local-scope - load-ingredients - reply <span class="Constant">35</span> -] -<span class="traceContains">+error: foo: wrong type for ingredient x:boolean</span> -<span class="traceContains">+error: (we're inside recipe foo x:boolean -> y:number)</span> -<span class="traceContains">+error: (we're trying to call '1:number <- foo 34' inside recipe main)</span> - -<span class="Delimiter">:(before "End next-ingredient Type Mismatch Error")</span> -raise_error << <span class="Constant">" (we're inside "</span> << header_label<span class="Delimiter">(</span>current_call<span class="Delimiter">().</span>running_recipe<span class="Delimiter">)</span> << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -raise_error << <span class="Constant">" (we're trying to call '"</span> << to_instruction<span class="Delimiter">(</span>*++Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>begin<span class="Delimiter">()).</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"' inside "</span> << header_label<span class="Delimiter">((</span>++Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>begin<span class="Delimiter">())-></span>running_recipe<span class="Delimiter">)</span> << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - -<span class="Delimiter">:(scenario static_dispatch_shows_clear_error_on_missing_variant_2)</span> -<span class="Special">% Hide_errors = true;</span> -recipe main [ - <span class="Constant">1</span>:boolean<span class="Special"> <- </span>foo <span class="Constant">34</span> -] -recipe foo x:number <span class="Delimiter">-></span> y:number [ - local-scope - load-ingredients - reply x -] -<span class="traceContains">+error: foo: reply ingredient x can't be saved in 1:boolean</span> -<span class="traceContains">+error: (we just returned from recipe foo x:number -> y:number)</span> - -<span class="Delimiter">:(before "End reply Type Mismatch Error")</span> -raise_error << <span class="Constant">" (we just returned from "</span> << header_label<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>operation<span class="Delimiter">)</span> << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</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> @@ -527,6 +474,27 @@ recipe! foo x:address:number <span class="Delimiter">-></span> y:number [ <span class="traceContains">+mem: storing 34 in location 2</span> $error: <span class="Constant">0</span> $warn: <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 [ + y:number<span class="Special"> <- </span>foo x +] +recipe foo a:number <span class="Delimiter">-></span> b:number [ + local-scope + load-ingredients + reply <span class="Constant">34</span> +] +recipe foo a:boolean <span class="Delimiter">-></span> b:number [ + local-scope + load-ingredients + reply <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> </pre> </body> </html> |