diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-11-11 15:54:19 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-11-11 15:54:19 -0800 |
commit | 6d007fda037331e7761d2a9ed3a2e435131daf7e (patch) | |
tree | 656aa7fe284b2b11c01f0389fe81f1b31025ce4e /html/056shape_shifting_recipe.cc.html | |
parent | c9f920da6e6b3e7049f078fea35e08256cae7c5b (diff) | |
download | mu-6d007fda037331e7761d2a9ed3a2e435131daf7e.tar.gz |
3667
Diffstat (limited to 'html/056shape_shifting_recipe.cc.html')
-rw-r--r-- | html/056shape_shifting_recipe.cc.html | 118 |
1 files changed, 73 insertions, 45 deletions
diff --git a/html/056shape_shifting_recipe.cc.html b/html/056shape_shifting_recipe.cc.html index 32aef874..6bb9c81e 100644 --- a/html/056shape_shifting_recipe.cc.html +++ b/html/056shape_shifting_recipe.cc.html @@ -157,7 +157,7 @@ vector<recipe_ordinal> strictly_matching_shape_shifting_variants<span clas <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < 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>ingredients<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>!concrete_type_names_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> + 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">"concrete-type 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> <span class="Delimiter">}</span> @@ -212,32 +212,11 @@ recipe_ordinal best_shape_shifting_variant<span class="Delimiter">(</span><span <span class="Identifier">return</span> concrete_type_names_strictly_match<span class="Delimiter">(</span>to<span class="Delimiter">.</span>type<span class="Delimiter">,</span> from<span class="Delimiter">.</span>type<span class="Delimiter">,</span> from<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">int</span> number_of_concrete_type_names<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <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> - <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">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> - result += number_of_concrete_type_names<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - result += number_of_concrete_type_names<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> result<span class="Delimiter">;</span> -<span class="Delimiter">}</span> - -<span class="Normal">int</span> number_of_concrete_type_names<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> number_of_concrete_type_names<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> -<span class="Delimiter">}</span> - -<span class="Normal">int</span> number_of_concrete_type_names<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> - <span class="Identifier">return</span> is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">)</span> ? <span class="Constant">0</span> : <span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Identifier">return</span> number_of_concrete_type_names<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">)</span> - + number_of_concrete_type_names<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> -<span class="Delimiter">}</span> - <span class="Normal">bool</span> concrete_type_names_strictly_match<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* to<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree* from<span class="Delimiter">,</span> <span class="Normal">const</span> reagent& rhs_reagent<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!to<span class="Delimiter">)</span> <span class="Identifier">return</span> !from<span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!from<span class="Delimiter">)</span> <span class="Identifier">return</span> !to<span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>to<span class="Delimiter">-></span>atom && is_type_ingredient_name<span class="Delimiter">(</span>to<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// type ingredient matches anything</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!to<span class="Delimiter">-></span>atom && to<span class="Delimiter">-></span>right == <span class="Constant">NULL</span> && to<span class="Delimiter">-></span>left != <span class="Constant">NULL</span> && to<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && is_type_ingredient_name<span class="Delimiter">(</span>to<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>from<span class="Delimiter">-></span>atom && is_mu_address<span class="Delimiter">(</span>to<span class="Delimiter">))</span> <span class="Identifier">return</span> from<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span> && rhs_reagent<span class="Delimiter">.</span>name == <span class="Constant">"0"</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!from<span class="Delimiter">-></span>atom && !to<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> @@ -262,6 +241,28 @@ recipe_ordinal best_shape_shifting_variant<span class="Delimiter">(</span><span <span class="Identifier">return</span> contains_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">)</span> || contains_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span class="Normal">int</span> number_of_concrete_type_names<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <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> + <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">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> + result += number_of_concrete_type_names<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + result += number_of_concrete_type_names<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> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Normal">int</span> number_of_concrete_type_names<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> number_of_concrete_type_names<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Normal">int</span> number_of_concrete_type_names<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> + <span class="Identifier">return</span> is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">)</span> ? <span class="Constant">0</span> : <span class="Constant">1</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> number_of_concrete_type_names<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">)</span> + + number_of_concrete_type_names<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + recipe_ordinal new_variant<span class="Delimiter">(</span>recipe_ordinal exemplar<span class="Delimiter">,</span> <span class="Normal">const</span> instruction& inst<span class="Delimiter">,</span> <span class="Normal">const</span> recipe& caller_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> string new_name = next_unused_recipe_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> new_name<span class="Delimiter">));</span> @@ -367,36 +368,42 @@ recipe_ordinal new_variant<span class="Delimiter">(</span>recipe_ordinal exempla raise << <span class="Constant">" (called from '"</span> << to_original_string<span class="Delimiter">(</span>call_instruction<span class="Delimiter">)</span> << <span class="Constant">"')</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> type_tree* curr_refinement_type = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Comment">// temporary heap allocation; must always be deleted before it goes out of scope</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> - curr_refinement_type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*refinement_type<span class="Delimiter">);</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>!refinement_type<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> - curr_refinement_type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*refinement_type<span class="Delimiter">-></span>left<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<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">"adding mapping from "</span> << exemplar_type<span class="Delimiter">-></span>name << <span class="Constant">" to "</span> << to_string<span class="Delimiter">(</span>curr_refinement_type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - put<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*curr_refinement_type<span class="Delimiter">));</span> - <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">),</span> curr_refinement_type<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"no call found for '"</span> << to_original_string<span class="Delimiter">(</span>call_instruction<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - *error = <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">delete</span> curr_refinement_type<span class="Delimiter">;</span> - <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!exemplar_type<span class="Delimiter">-></span>atom && exemplar_type<span class="Delimiter">-></span>right == <span class="Constant">NULL</span> && !refinement_type<span class="Delimiter">-></span>atom && refinement_type<span class="Delimiter">-></span>right != <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + exemplar_type = exemplar_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + assert_for_now<span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> type_tree* curr_refinement_type = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Comment">// temporary heap allocation; must always be deleted before it goes out of scope</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> + curr_refinement_type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*refinement_type<span class="Delimiter">);</span> + <span class="Normal">else</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!refinement_type<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + curr_refinement_type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*refinement_type<span class="Delimiter">-></span>left<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">)-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">delete</span> get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<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">"adding mapping from "</span> << exemplar_type<span class="Delimiter">-></span>name << <span class="Constant">" to "</span> << to_string<span class="Delimiter">(</span>curr_refinement_type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> put<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*curr_refinement_type<span class="Delimiter">));</span> <span class="Delimiter">}</span> + <span class="Normal">else</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">),</span> curr_refinement_type<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"no call found for '"</span> << to_original_string<span class="Delimiter">(</span>call_instruction<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + *error = <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Normal">delete</span> curr_refinement_type<span class="Delimiter">;</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">)-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">delete</span> get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + put<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*curr_refinement_type<span class="Delimiter">));</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Normal">delete</span> curr_refinement_type<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">delete</span> curr_refinement_type<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Delimiter">{</span> accumulate_type_ingredients<span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> refinement_type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> exemplar<span class="Delimiter">,</span> exemplar_reagent<span class="Delimiter">,</span> call_instruction<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> error<span class="Delimiter">);</span> + accumulate_type_ingredients<span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> refinement_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> exemplar<span class="Delimiter">,</span> exemplar_reagent<span class="Delimiter">,</span> call_instruction<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> error<span class="Delimiter">);</span> <span class="Delimiter">}</span> - accumulate_type_ingredients<span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> refinement_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> exemplar<span class="Delimiter">,</span> exemplar_reagent<span class="Delimiter">,</span> call_instruction<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> error<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Normal">void</span> replace_type_ingredients<span class="Delimiter">(</span>recipe& new_recipe<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree*>& mappings<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -439,6 +446,10 @@ recipe_ordinal new_variant<span class="Delimiter">(</span>recipe_ordinal exempla <span class="Normal">void</span> replace_type_ingredients<span class="Delimiter">(</span>type_tree* type<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree*>& mappings<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right == <span class="Constant">NULL</span> && type<span class="Delimiter">-></span>left != <span class="Constant">NULL</span> && type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && contains_key<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">)</span> && !get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">)-></span>atom && get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">)-></span>right != <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + *type = *get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> replace_type_ingredients<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> mappings<span class="Delimiter">);</span> replace_type_ingredients<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> mappings<span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> @@ -693,6 +704,7 @@ $error: <span class="Constant">0</span> CHECK<span class="Delimiter">(</span>!element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span class="Comment">//: specializing a type ingredient with a compound type</span> <span class="Delimiter">:(scenario shape_shifting_recipe_supports_compound_types)</span> <span class="muRecipe">def</span> main [ <span class="Constant">1</span>:&:point<span class="Special"> <- </span><span class="Normal">new</span> <span class="Constant">point:type</span> @@ -707,6 +719,22 @@ $error: <span class="Constant">0</span> ] <span class="traceContains">+mem: storing 34 in location 5</span> +<span class="Comment">//: specializing a type ingredient with a compound type -- while *inside* another compound type</span> +<span class="Delimiter">:(scenario shape_shifting_recipe_supports_compound_types_2)</span> +<span class="muData">container</span> foo:_t [ + <span class="Normal">value</span>:_t +] +<span class="muRecipe">def</span> bar x:&:foo:_t<span class="muRecipe"> -> </span>result:_t [ + local-scope + load-ingredients + result<span class="Special"> <- </span>get *x<span class="Delimiter">,</span> <span class="Constant">value:offset</span> +] +<span class="muRecipe">def</span> main [ + <span class="Constant">1</span>:&:foo:&:point<span class="Special"> <- </span><span class="Normal">new</span> <span class="Delimiter">{(</span>foo address point<span class="Delimiter">)</span>: type<span class="Delimiter">}</span> + <span class="Constant">2</span>:&:point<span class="Special"> <- </span>bar <span class="Constant">1</span>:&:foo:&:point +] +<span class="Comment"># no errors; call to 'bar' successfully specialized</span> + <span class="Delimiter">:(scenario shape_shifting_recipe_error)</span> <span class="Special">% Hide_errors = true;</span> <span class="muRecipe">def</span> main [ |