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 | |
parent | c9f920da6e6b3e7049f078fea35e08256cae7c5b (diff) | |
download | mu-6d007fda037331e7761d2a9ed3a2e435131daf7e.tar.gz |
3667
Diffstat (limited to 'html')
42 files changed, 745 insertions, 444 deletions
diff --git a/html/003trace.cc.html b/html/003trace.cc.html index 4cfee97a..881a854f 100644 --- a/html/003trace.cc.html +++ b/html/003trace.cc.html @@ -209,6 +209,9 @@ trace_stream* Trace_stream = <span class="Constant">NULL</span><span class="Deli <span class="Comment">// Errors are a special layer.</span> <span class="PreProc">#define raise (!Trace_stream ? (tb_shutdown()</span><span class="Delimiter">,</span><span class="PreProc">++Trace_errors</span><span class="Delimiter">,</span><span class="PreProc">cerr) </span><span class="Comment">/*</span><span class="Comment">do print</span><span class="Comment">*/</span><span class="PreProc"> : Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">stream(Error_depth</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">"error"</span><span class="PreProc">))</span> +<span class="Comment">// If we aren't yet sure how to deal with some corner case, use assert_for_now</span> +<span class="Comment">// to indicate that it isn't an inviolable invariant.</span> +<span class="PreProc">#define assert_for_now assert</span> <span class="Comment">// Inside tests, fail any tests that displayed (unexpected) errors.</span> <span class="Comment">// Expected errors in tests should always be hidden and silently checked for.</span> diff --git a/html/010vm.cc.html b/html/010vm.cc.html index 22196064..8a104027 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -97,8 +97,8 @@ recipe_ordinal Next_recipe_ordinal = <span class="Constant">1</span><span class= reagent<span class="Delimiter">()</span> :type<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> initialized<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> ~reagent<span class="Delimiter">();</span> <span class="Normal">void</span> clear<span class="Delimiter">();</span> - reagent<span class="Delimiter">(</span><span class="Normal">const</span> reagent& old<span class="Delimiter">);</span> - reagent& <span class="Normal">operator</span>=<span class="Delimiter">(</span><span class="Normal">const</span> reagent& old<span class="Delimiter">);</span> + reagent<span class="Delimiter">(</span><span class="Normal">const</span> reagent& original<span class="Delimiter">);</span> + reagent& <span class="Normal">operator</span>=<span class="Delimiter">(</span><span class="Normal">const</span> reagent& original<span class="Delimiter">);</span> <span class="Normal">void</span> set_value<span class="Delimiter">(</span><span class="Normal">double</span> v<span class="Delimiter">)</span> <span class="Delimiter">{</span> value = v<span class="Delimiter">;</span> initialized = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">};</span> @@ -112,13 +112,13 @@ recipe_ordinal Next_recipe_ordinal = <span class="Constant">1</span><span class= type_tree* left<span class="Delimiter">;</span> <span class="Comment">// only if !atom</span> type_tree* right<span class="Delimiter">;</span> <span class="Comment">// only if !atom</span> ~type_tree<span class="Delimiter">();</span> - type_tree<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& old<span class="Delimiter">);</span> + type_tree<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& original<span class="Delimiter">);</span> <span class="Comment">// atomic type ordinal</span> <span class="Normal">explicit</span> type_tree<span class="Delimiter">(</span>string name<span class="Delimiter">);</span> type_tree<span class="Delimiter">(</span>string name<span class="Delimiter">,</span> type_ordinal v<span class="Delimiter">)</span> :atom<span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">),</span> name<span class="Delimiter">(</span>name<span class="Delimiter">),</span> value<span class="Delimiter">(</span>v<span class="Delimiter">),</span> left<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> right<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Comment">// tree of type ordinals</span> type_tree<span class="Delimiter">(</span>type_tree* l<span class="Delimiter">,</span> type_tree* r<span class="Delimiter">)</span> :atom<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">),</span> value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> left<span class="Delimiter">(</span>l<span class="Delimiter">),</span> right<span class="Delimiter">(</span>r<span class="Delimiter">)</span> <span class="Delimiter">{}</span> - type_tree& <span class="Normal">operator</span>=<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& old<span class="Delimiter">);</span> + type_tree& <span class="Normal">operator</span>=<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& original<span class="Delimiter">);</span> <span class="Normal">bool</span> <span class="Normal">operator</span>==<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& other<span class="Delimiter">)</span> <span class="Normal">const</span><span class="Delimiter">;</span> <span class="Normal">bool</span> <span class="Normal">operator</span>!=<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& other<span class="Delimiter">)</span> <span class="Normal">const</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> !<span class="Normal">operator</span>==<span class="Delimiter">(</span>other<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Normal">bool</span> <span class="Normal">operator</span><<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& other<span class="Delimiter">)</span> <span class="Normal">const</span><span class="Delimiter">;</span> @@ -131,7 +131,7 @@ recipe_ordinal Next_recipe_ordinal = <span class="Constant">1</span><span class= string_tree* left<span class="Delimiter">;</span> <span class="Comment">// only if !atom</span> string_tree* right<span class="Delimiter">;</span> <span class="Comment">// only if !atom</span> ~string_tree<span class="Delimiter">();</span> - string_tree<span class="Delimiter">(</span><span class="Normal">const</span> string_tree& old<span class="Delimiter">);</span> + string_tree<span class="Delimiter">(</span><span class="Normal">const</span> string_tree& original<span class="Delimiter">);</span> <span class="Comment">// atomic string</span> <span class="Normal">explicit</span> string_tree<span class="Delimiter">(</span>string v<span class="Delimiter">)</span> :atom<span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">),</span> value<span class="Delimiter">(</span>v<span class="Delimiter">),</span> left<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> right<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Comment">// tree of strings</span> @@ -337,12 +337,34 @@ reagent::reagent<span class="Delimiter">(</span><span class="Normal">const</span string_tree* parse_property_list<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> skip_whitespace_but_not_newline<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> - string_tree* left = <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>slurp_until<span class="Delimiter">(</span>in<span class="Delimiter">,</span> <span class="Constant">':'</span><span class="Delimiter">));</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">return</span> left<span class="Delimiter">;</span> - string_tree* right = parse_property_list<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Identifier">return</span> <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>left<span class="Delimiter">,</span> right<span class="Delimiter">);</span> + string_tree* first = <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>slurp_until<span class="Delimiter">(</span>in<span class="Delimiter">,</span> <span class="Constant">':'</span><span class="Delimiter">));</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">return</span> first<span class="Delimiter">;</span> + string_tree* rest = parse_property_list<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">)</span> && rest<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> + <span class="Identifier">return</span> <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>first<span class="Delimiter">,</span> <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>rest<span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span> + <span class="Identifier">return</span> <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>first<span class="Delimiter">,</span> rest<span class="Delimiter">);</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Unit Tests")</span> +<span class="Normal">void</span> test_parse_property_list_atom<span class="Delimiter">()</span> <span class="Delimiter">{</span> + istringstream in<span class="Delimiter">(</span><span class="Constant">"a"</span><span class="Delimiter">);</span> + string_tree* x = parse_property_list<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>x<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Normal">delete</span> x<span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Normal">void</span> test_parse_property_list_list<span class="Delimiter">()</span> <span class="Delimiter">{</span> + istringstream in<span class="Delimiter">(</span><span class="Constant">"a:b"</span><span class="Delimiter">);</span> + string_tree* x = parse_property_list<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!x<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>x<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>x<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value<span class="Delimiter">,</span> <span class="Constant">"a"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!x<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>x<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>x<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value<span class="Delimiter">,</span> <span class="Constant">"b"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>x<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right == <span class="Constant">NULL</span><span class="Delimiter">);</span> + <span class="Normal">delete</span> x<span class="Delimiter">;</span> <span class="Delimiter">}</span> +<span class="Delimiter">:(code)</span> type_tree* new_type_tree<span class="Delimiter">(</span><span class="Normal">const</span> string_tree* properties<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!properties<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>properties<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -377,20 +399,22 @@ reagent::reagent<span class="Delimiter">(</span><span class="Normal">const</span <span class="Comment">// End reagent Copy Constructor</span> <span class="Delimiter">}</span> -type_tree::type_tree<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& old<span class="Delimiter">)</span> <span class="Delimiter">{</span> - atom = old<span class="Delimiter">.</span>atom<span class="Delimiter">;</span> - name = old<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - value = old<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - left = old<span class="Delimiter">.</span>left ? <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> - right = old<span class="Delimiter">.</span>right ? <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>right<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> +type_tree::type_tree<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& original<span class="Delimiter">)</span> <span class="Delimiter">{</span> + atom = original<span class="Delimiter">.</span>atom<span class="Delimiter">;</span> + name = original<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + value = original<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + left = original<span class="Delimiter">.</span>left ? <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*original<span class="Delimiter">.</span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> + right = original<span class="Delimiter">.</span>right ? <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*original<span class="Delimiter">.</span>right<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -type_tree& type_tree::<span class="Normal">operator</span>=<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& old<span class="Delimiter">)</span> <span class="Delimiter">{</span> - atom = old<span class="Delimiter">.</span>atom<span class="Delimiter">;</span> - name = old<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - value = old<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - left = old<span class="Delimiter">.</span>left ? <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> - right = old<span class="Delimiter">.</span>right ? <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>right<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> +type_tree& type_tree::<span class="Normal">operator</span>=<span class="Delimiter">(</span><span class="Normal">const</span> type_tree& original<span class="Delimiter">)</span> <span class="Delimiter">{</span> + atom = original<span class="Delimiter">.</span>atom<span class="Delimiter">;</span> + name = original<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + value = original<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>left<span class="Delimiter">)</span> <span class="Normal">delete</span> left<span class="Delimiter">;</span> + left = original<span class="Delimiter">.</span>left ? <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*original<span class="Delimiter">.</span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>right<span class="Delimiter">)</span> <span class="Normal">delete</span> right<span class="Delimiter">;</span> + right = original<span class="Delimiter">.</span>right ? <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*original<span class="Delimiter">.</span>right<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Identifier">return</span> *<span class="Normal">this</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -411,9 +435,10 @@ type_tree& type_tree::<span class="Normal">operator</span>=<span class="Deli <span class="Normal">if</span> <span class="Delimiter">(</span>!left && other<span class="Delimiter">.</span>left<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>right && !other<span class="Delimiter">.</span>right<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>!right && other<span class="Delimiter">.</span>right<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Comment">// now if either pointer is unequal neither side can be null</span> <span class="Comment">// if one side is equal that's easy</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>left == other<span class="Delimiter">.</span>left || *left == *other<span class="Delimiter">.</span>left<span class="Delimiter">)</span> <span class="Identifier">return</span> *right < *other<span class="Delimiter">.</span>right<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>right == other<span class="Delimiter">.</span>right || *right == *other<span class="Delimiter">.</span>right<span class="Delimiter">)</span> <span class="Identifier">return</span> *left < *other<span class="Delimiter">.</span>left<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>left == other<span class="Delimiter">.</span>left || *left == *other<span class="Delimiter">.</span>left<span class="Delimiter">)</span> <span class="Identifier">return</span> right && *right < *other<span class="Delimiter">.</span>right<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>right == other<span class="Delimiter">.</span>right || *right == *other<span class="Delimiter">.</span>right<span class="Delimiter">)</span> <span class="Identifier">return</span> left && *left < *other<span class="Delimiter">.</span>left<span class="Delimiter">;</span> <span class="Comment">// if the two sides criss-cross, pick the side with the smaller lhs</span> <span class="Normal">if</span> <span class="Delimiter">((</span>left == other<span class="Delimiter">.</span>right || *left == *other<span class="Delimiter">.</span>right<span class="Delimiter">)</span> && <span class="Delimiter">(</span>right == other<span class="Delimiter">.</span>left || *right == *other<span class="Delimiter">.</span>left<span class="Delimiter">))</span> @@ -459,25 +484,21 @@ type_tree& type_tree::<span class="Normal">operator</span>=<span class="Deli <span class="Delimiter">}</span> <span class="Normal">void</span> test_compare_list_with_smaller_left_but_larger_right<span class="Delimiter">()</span> <span class="Delimiter">{</span> reagent a<span class="Delimiter">(</span><span class="Constant">"a:address:number"</span><span class="Delimiter">),</span> b<span class="Delimiter">(</span><span class="Constant">"b:character:array"</span><span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>a<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && a<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>b<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && b<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> CHECK<span class="Delimiter">(</span>*a<span class="Delimiter">.</span>type < *b<span class="Delimiter">.</span>type<span class="Delimiter">);</span> CHECK<span class="Delimiter">(</span>!<span class="Delimiter">(</span>*b<span class="Delimiter">.</span>type < *a<span class="Delimiter">.</span>type<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Normal">void</span> test_compare_list_with_smaller_left_but_larger_right_identical_types<span class="Delimiter">()</span> <span class="Delimiter">{</span> reagent a<span class="Delimiter">(</span><span class="Constant">"a:address:boolean"</span><span class="Delimiter">),</span> b<span class="Delimiter">(</span><span class="Constant">"b:boolean:address"</span><span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>a<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && a<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>b<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && b<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> CHECK<span class="Delimiter">(</span>*a<span class="Delimiter">.</span>type < *b<span class="Delimiter">.</span>type<span class="Delimiter">);</span> CHECK<span class="Delimiter">(</span>!<span class="Delimiter">(</span>*b<span class="Delimiter">.</span>type < *a<span class="Delimiter">.</span>type<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -string_tree::string_tree<span class="Delimiter">(</span><span class="Normal">const</span> string_tree& old<span class="Delimiter">)</span> <span class="Delimiter">{</span> - atom = old<span class="Delimiter">.</span>atom<span class="Delimiter">;</span> - value = old<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - left = old<span class="Delimiter">.</span>left ? <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> - right = old<span class="Delimiter">.</span>right ? <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>right<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> +string_tree::string_tree<span class="Delimiter">(</span><span class="Normal">const</span> string_tree& original<span class="Delimiter">)</span> <span class="Delimiter">{</span> + atom = original<span class="Delimiter">.</span>atom<span class="Delimiter">;</span> + value = original<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + left = original<span class="Delimiter">.</span>left ? <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>*original<span class="Delimiter">.</span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> + right = original<span class="Delimiter">.</span>right ? <span class="Normal">new</span> string_tree<span class="Delimiter">(</span>*original<span class="Delimiter">.</span>right<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent& reagent::<span class="Normal">operator</span>=<span class="Delimiter">(</span><span class="Normal">const</span> reagent& other<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -694,8 +715,11 @@ string to_string<span class="Delimiter">(</span><span class="Normal">const</span <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// final right</span> - dump<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Comment">// check for dotted list; should never happen</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << <span class="Constant">". "</span><span class="Delimiter">;</span> + dump<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Delimiter">}</span> out << <span class="Constant">')'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -720,8 +744,11 @@ string to_string<span class="Delimiter">(</span><span class="Normal">const</span <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// final right</span> - dump<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Comment">// check for dotted list; should never happen</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << <span class="Constant">". "</span><span class="Delimiter">;</span> + dump<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Delimiter">}</span> out << <span class="Constant">')'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -753,8 +780,11 @@ string names_to_string<span class="Delimiter">(</span><span class="Normal">const <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// final right</span> - dump_names<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Comment">// check for dotted list; should never happen</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << <span class="Constant">". "</span><span class="Delimiter">;</span> + dump_names<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Delimiter">}</span> out << <span class="Constant">')'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -779,8 +809,11 @@ string names_to_string_without_quotes<span class="Delimiter">(</span><span class <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// final right</span> - dump_names_without_quotes<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Comment">// check for dotted list; should never happen</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << <span class="Constant">". "</span><span class="Delimiter">;</span> + dump_names_without_quotes<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Delimiter">}</span> out << <span class="Constant">')'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/017parse_tree.cc.html b/html/017parse_tree.cc.html index 39f56afb..819f7ee2 100644 --- a/html/017parse_tree.cc.html +++ b/html/017parse_tree.cc.html @@ -40,9 +40,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment">// (address to array of charaters) to (list of numbers)".</span> <span class="Comment">//</span> <span class="Comment">// Type trees aren't as general as s-expressions even if they look like them:</span> -<span class="Comment">// the first element of a type tree is always an atom, and left and right</span> -<span class="Comment">// pointers of non-atoms are never NULL. All type trees are 'dotted' in lisp</span> -<span class="Comment">// parlance.</span> +<span class="Comment">// the first element of a type tree is always an atom, and it can never be</span> +<span class="Comment">// dotted (right->right->right->...->right is always NULL).</span> <span class="Comment">//</span> <span class="Comment">// For now you can't use the simpler 'colon-based' representation inside type</span> <span class="Comment">// trees. Once you start typing parens, keep on typing parens.</span> @@ -115,19 +114,6 @@ string_tree* parse_string_tree<span class="Delimiter">(</span>istream& in<sp <span class="Delimiter">}</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="Comment">// skip ')'</span> assert<span class="Delimiter">(</span>*curr == <span class="Constant">NULL</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>result == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">-></span>right == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> - <span class="Comment">// standardize the final element to always be on the right if it's an atom</span> - <span class="Comment">// (a b c) => (a b . c) in s-expression parlance</span> - string_tree* tmp = result<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>tmp<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> tmp = tmp<span class="Delimiter">-></span>right<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>!tmp<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!tmp<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> - string_tree* tmp2 = tmp<span class="Delimiter">-></span>right<span class="Delimiter">;</span> - tmp<span class="Delimiter">-></span>right = tmp2<span class="Delimiter">-></span>left<span class="Delimiter">;</span> - tmp2<span class="Delimiter">-></span>left = <span class="Constant">NULL</span><span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>tmp2<span class="Delimiter">-></span>right == <span class="Constant">NULL</span><span class="Delimiter">);</span> - <span class="Normal">delete</span> tmp2<span class="Delimiter">;</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/020run.cc.html b/html/020run.cc.html index 59b13726..d036a7fb 100644 --- a/html/020run.cc.html +++ b/html/020run.cc.html @@ -363,18 +363,31 @@ vector<<span class="Normal">double</span>> read_memory<span class="Delimit <span class="Delimiter">:(code)</span> <span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Comment">// End size_of(reagent r) Cases</span> + <span class="Comment">// End size_of(reagent r) Special-cases</span> <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Comment">// End size_of(type) Cases</span> + <span class="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>value == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// error value, but we'll raise it elsewhere</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> + <span class="Comment">// End size_of(type) Atom Special-cases</span> + <span class="Delimiter">}</span> + <span class="Normal">else</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"invalid type "</span> << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> + <span class="Comment">// End size_of(type) Non-atom Special-cases</span> + <span class="Delimiter">}</span> + <span class="Comment">// End size_of(type) Special-cases</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">bool</span> size_mismatch<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">,</span> <span class="Normal">const</span> vector<<span class="Normal">double</span>>& data<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Comment">// End size_mismatch(x) Cases</span> + <span class="Comment">// End size_mismatch(x) Special-cases</span> <span class="CommentedCode">//? if (size_of(x) != SIZE(data)) cerr << size_of(x) << " vs " << SIZE(data) << '\n';</span> <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span> <span class="Delimiter">}</span> diff --git a/html/021check_instruction.cc.html b/html/021check_instruction.cc.html index b4ebf2be..e24fd4a9 100644 --- a/html/021check_instruction.cc.html +++ b/html/021check_instruction.cc.html @@ -137,6 +137,7 @@ $error: <span class="Constant">0</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_address<span class="Delimiter">(</span>from<span class="Delimiter">)</span> && is_mu_number<span class="Delimiter">(</span>to<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>is_mu_boolean<span class="Delimiter">(</span>from<span class="Delimiter">)</span> && is_mu_number<span class="Delimiter">(</span>to<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>is_mu_number<span class="Delimiter">(</span>from<span class="Delimiter">)</span> && is_mu_boolean<span class="Delimiter">(</span>to<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Comment">// End types_coercible Special-cases</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -171,14 +172,12 @@ $error: <span class="Constant">0</span> <span class="Identifier">return</span> types_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> <span class="Delimiter">}</span> -<span class="Comment">// two types match if the second begins like the first</span> -<span class="Comment">// (trees perform the same check recursively on each subtree)</span> <span class="Normal">bool</span> types_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="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>from == to<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>!to<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>!from<span class="Delimiter">)</span> <span class="Identifier">return</span> to<span class="Delimiter">-></span>atom && to<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>to<span class="Delimiter">-></span>atom && !from<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Identifier">return</span> from<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && from<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == to<span class="Delimiter">-></span>name<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> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>from<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!to<span class="Delimiter">-></span>atom<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>from<span class="Delimiter">-></span>value == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">return</span> from<span class="Delimiter">-></span>name == to<span class="Delimiter">-></span>name<span class="Delimiter">;</span> <span class="Identifier">return</span> from<span class="Delimiter">-></span>value == to<span class="Delimiter">-></span>value<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -211,7 +210,10 @@ $error: <span class="Constant">0</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>type<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"invalid type "</span> << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << 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="Identifier">return</span> type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -223,7 +225,10 @@ $error: <span class="Constant">0</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>type<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"invalid type "</span> << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << 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="Identifier">return</span> type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> diff --git a/html/027call_ingredient.cc.html b/html/027call_ingredient.cc.html index 36687fd8..fc4d9f4c 100644 --- a/html/027call_ingredient.cc.html +++ b/html/027call_ingredient.cc.html @@ -217,8 +217,9 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">)</span> && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right - && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom - && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"character"</span><span class="Delimiter">);</span> + && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom + && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"character"</span><span class="Delimiter">)</span> + && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right == <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> </body> diff --git a/html/028call_reply.cc.html b/html/028call_return.cc.html index 4c32013f..0f7c418f 100644 --- a/html/028call_reply.cc.html +++ b/html/028call_return.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 028call_reply.cc</title> +<title>Mu - 028call_return.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v2"> <meta name="syntax" content="cpp"> @@ -14,14 +14,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 12pt; font-size: 1em; } .Constant { color: #00a0a0; } -.cSpecial { color: #008000; } +.traceContains { color: #008000; } .muRecipe { color: #ff8700; } +.cSpecial { color: #008000; } .Comment { color: #9090ff; } .Delimiter { color: #800080; } .Special { color: #c00000; } -.traceContains { color: #008000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Identifier { color: #c0a020; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } --> </style> @@ -42,6 +42,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> f [ <span class="Constant">12</span>:num<span class="Special"> <- </span>next-ingredient <span class="Constant">13</span>:num<span class="Special"> <- </span>add <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">12</span>:num + <span class="Identifier">return</span> <span class="Constant">12</span>:num<span class="Delimiter">,</span> <span class="Constant">13</span>:num +] +<span class="traceContains">+mem: storing 34 in location 1</span> +<span class="traceContains">+mem: storing 35 in location 2</span> + +<span class="Delimiter">:(scenario reply)</span> +<span class="muRecipe">def</span> main [ + <span class="Constant">1</span>:num<span class="Delimiter">,</span> <span class="Constant">2</span>:num<span class="Special"> <- </span>f <span class="Constant">34</span> +] +<span class="muRecipe">def</span> f [ + <span class="Constant">12</span>:num<span class="Special"> <- </span>next-ingredient + <span class="Constant">13</span>:num<span class="Special"> <- </span>add <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">12</span>:num reply <span class="Constant">12</span>:num<span class="Delimiter">,</span> <span class="Constant">13</span>:num ] <span class="traceContains">+mem: storing 34 in location 1</span> @@ -60,7 +72,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Normal">case</span> RETURN: <span class="Delimiter">{</span> <span class="Comment">// Starting Reply</span> <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"trace"</span><span class="Delimiter">)</span> << <span class="Constant">"reply: decrementing callstack depth from "</span> << Trace_stream<span class="Delimiter">-></span>callstack_depth << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"trace"</span><span class="Delimiter">)</span> << current_instruction<span class="Delimiter">().</span>name << <span class="Constant">": decrementing callstack depth from "</span> << Trace_stream<span class="Delimiter">-></span>callstack_depth << end<span class="Delimiter">();</span> --Trace_stream<span class="Delimiter">-></span>callstack_depth<span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>callstack_depth < <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> @@ -72,20 +84,20 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Normal">if</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">goto</span> stop_running_current_routine<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>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result "</span> << i << <span class="Constant">" is "</span> << to_string<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> - <span class="Comment">// make reply products available to caller</span> + <span class="Comment">// make return products available to caller</span> copy<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> ingredients<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>products<span class="Delimiter">,</span> products<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span> <span class="Comment">// End Reply</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// continue to process rest of *caller* instruction</span> <span class="Delimiter">}</span> -<span class="Comment">//: Types in reply instructions are checked ahead of time.</span> +<span class="Comment">//: Types in return instructions are checked ahead of time.</span> <span class="Delimiter">:(before "End Checks")</span> -Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_types_of_reply_instructions<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> +Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_types_of_return_instructions<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> check_types_of_reply_instructions<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> check_types_of_return_instructions<span class="Delimiter">(</span><span class="Normal">const</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> - 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">"--- check types of reply instructions in recipe "</span> << caller<span class="Delimiter">.</span>name << end<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">"--- check types of return instructions in recipe "</span> << caller<span class="Delimiter">.</span>name << end<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>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">const</span> instruction& caller_instruction = caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> @@ -93,43 +105,43 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Normal">if</span> <span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>operation < MAX_PRIMITIVE_RECIPES<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Normal">const</span> recipe& callee = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> caller_instruction<span class="Delimiter">.</span>operation<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>callee<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> instruction& reply_inst = callee<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>operation != RETURN<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Normal">const</span> instruction& return_inst = callee<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>return_inst<span class="Delimiter">.</span>operation != RETURN<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// check types with the caller</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > SIZE<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > SIZE<span class="Delimiter">(</span>return_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"too few values returned from "</span> << callee<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> lhs = reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> lhs = return_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> rhs = caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Comment">// End Check RETURN Copy(lhs, rhs)</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>rhs<span class="Delimiter">,</span> lhs<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << maybe<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << reply_inst<span class="Delimiter">.</span>name << <span class="Constant">" ingredient '"</span> << lhs<span class="Delimiter">.</span>original_string << <span class="Constant">"' can't be saved in '"</span> << rhs<span class="Delimiter">.</span>original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise << maybe<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << return_inst<span class="Delimiter">.</span>name << <span class="Constant">" ingredient '"</span> << lhs<span class="Delimiter">.</span>original_string << <span class="Constant">"' can't be saved in '"</span> << rhs<span class="Delimiter">.</span>original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> raise << <span class="Constant">" ['"</span> << to_string<span class="Delimiter">(</span>lhs<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">"' vs '"</span> << to_string<span class="Delimiter">(</span>rhs<span class="Delimiter">.</span>type<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">goto</span> finish_reply_check<span class="Delimiter">;</span> + <span class="Identifier">goto</span> finish_return_check<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Comment">// check that any reply ingredients with /same-as-ingredient connect up</span> + <span class="Comment">// check that any return ingredients with /same-as-ingredient connect up</span> <span class="Comment">// the corresponding ingredient and product in the caller.</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_instruction<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>has_property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> - string_tree* tmp = property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>return_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> + string_tree* tmp = property<span class="Delimiter">(</span>return_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!tmp || !tmp<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'same-as-ingredient' metadata should take exactly one value in '"</span> << to_original_string<span class="Delimiter">(</span>reply_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="Identifier">goto</span> finish_reply_check<span class="Delimiter">;</span> + raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'same-as-ingredient' metadata should take exactly one value in '"</span> << to_original_string<span class="Delimiter">(</span>return_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="Identifier">goto</span> finish_return_check<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">int</span> ingredient_index = to_integer<span class="Delimiter">(</span>tmp<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>ingredient_index >= SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"too few ingredients in '"</span> << to_original_string<span class="Delimiter">(</span>caller_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">goto</span> finish_reply_check<span class="Delimiter">;</span> + <span class="Identifier">goto</span> finish_return_check<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_dummy<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> && !is_literal<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">))</span> && caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name != caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>name<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << to_original_string<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">)</span> << <span class="Constant">"' should write to '"</span> << caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>original_string << <span class="Constant">"' rather than '"</span> << caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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> - <span class="Normal">finish_reply_check</span>:<span class="Delimiter">;</span> + <span class="Normal">finish_return_check</span>:<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -149,7 +161,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Comment">//: In Mu we'd like to assume that any instruction doesn't modify its</span> <span class="Comment">//: ingredients unless they're also products. The /same-as-ingredient inside</span> -<span class="Comment">//: the recipe's 'reply' indicates that an ingredient is intended to be</span> +<span class="Comment">//: the recipe's 'return' indicates that an ingredient is intended to be</span> <span class="Comment">//: modified in place, and will help catch accidental misuse of such</span> <span class="Comment">//: 'ingredient-products' (sometimes called in-out parameters in other</span> <span class="Comment">//: languages).</span> diff --git a/html/030container.cc.html b/html/030container.cc.html index 81437ba6..6948c628 100644 --- a/html/030container.cc.html +++ b/html/030container.cc.html @@ -13,17 +13,18 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 12pt; font-size: 1em; } -.Constant { color: #00a0a0; } -.traceAbsent { color: #c00000; } -.cSpecial { color: #008000; } -.muRecipe { color: #ff8700; } .SalientComment { color: #00ffff; } -.Comment { color: #9090ff; } -.Delimiter { color: #800080; } -.Special { color: #c00000; } +.CommentedCode { color: #6c6c6c; } +.muRecipe { color: #ff8700; } +.muData { color: #ffff00; } .traceContains { color: #008000; } +.Delimiter { color: #800080; } .Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } -.muData { color: #ffff00; } +.cSpecial { color: #008000; } +.traceAbsent { color: #c00000; } +.Comment { color: #9090ff; } +.Constant { color: #00a0a0; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } --> </style> @@ -182,33 +183,27 @@ atexit<span class="Delimiter">(</span>clear_container_metadata<span class="Delim <span class="Comment">//: do no work in size_of, simply lookup Container_metadata</span> -<span class="Delimiter">:(before "End size_of(reagent r) Cases")</span> +<span class="Delimiter">:(before "End size_of(reagent r) Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>size<span class="Delimiter">)</span> <span class="Identifier">return</span> r<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>size<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End size_of(type) Cases")</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>value == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// error value, but we'll raise it elsewhere</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> -<span class="Normal">const</span> type_tree* root = root_type<span class="Delimiter">(</span>type<span class="Delimiter">);</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"no such type "</span> << root<span class="Delimiter">-></span>value << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span class="Delimiter">:(before "End size_of(type) Special-cases")</span> +<span class="Normal">const</span> type_tree* base_type = type<span class="Delimiter">;</span> +<span class="Comment">// Update base_type in size_of(type)</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"no such type "</span> << base_type<span class="Delimiter">-></span>value << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -type_info t = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root<span class="Delimiter">-></span>value<span class="Delimiter">);</span> +type_info t = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// Compute size_of Container</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> type<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// error raised elsewhere</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> type<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"unknown size for container type '"</span> << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span class="CommentedCode">//? DUMP("");</span> + <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> <span class="Identifier">return</span> get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> type<span class="Delimiter">).</span>size<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(code)</span> -<span class="Normal">const</span> type_tree* root_type<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* t<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> type_tree* result = t<span class="Delimiter">-></span>atom ? t : t<span class="Delimiter">-></span>left<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>result<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> - <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span class="Delimiter">}</span> - <span class="Comment">//: precompute Container_metadata before we need size_of</span> <span class="Comment">//: also store a copy in each reagent in each instruction in each recipe</span> @@ -246,27 +241,21 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Normal">if</span> <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>pending_metadata<span class="Delimiter">,</span> *type<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> pending_metadata<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>*type<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> - assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"address"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - compute_container_sizes<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> pending_metadata<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> type_tree* element_type = type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> - <span class="Comment">// hack: support both array:num:3 and array:address:num</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!element_type<span class="Delimiter">-></span>atom && element_type<span class="Delimiter">-></span>right && element_type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">))</span> - element_type = element_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> - compute_container_sizes<span class="Delimiter">(</span>element_type<span class="Delimiter">,</span> pending_metadata<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"invalid type "</span> << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << location_for_error_messages << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// End compute_container_sizes Non-atom Cases</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"address"</span><span class="Delimiter">)</span> + compute_container_sizes<span class="Delimiter">(</span>payload_type<span class="Delimiter">(</span>type<span class="Delimiter">),</span> pending_metadata<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> + <span class="Comment">// End compute_container_sizes Non-atom Special-cases</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// error raised elsewhere</span> type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">)</span> compute_container_sizes<span class="Delimiter">(</span>info<span class="Delimiter">,</span> type<span class="Delimiter">,</span> pending_metadata<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - <span class="Comment">// End compute_container_sizes Atom Cases</span> + <span class="Comment">// End compute_container_sizes Atom Special-cases</span> <span class="Delimiter">}</span> <span class="Normal">void</span> compute_container_sizes<span class="Delimiter">(</span><span class="Normal">const</span> type_info& container_info<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree* full_type<span class="Delimiter">,</span> set<type_tree>& pending_metadata<span class="Delimiter">,</span> <span class="Normal">const</span> string& location_for_error_messages<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -285,6 +274,14 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa Container_metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<type_tree*<span class="Delimiter">,</span> container_metadata><span class="Delimiter">(</span><span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*full_type<span class="Delimiter">),</span> metadata<span class="Delimiter">));</span> <span class="Delimiter">}</span> +<span class="Normal">const</span> type_tree* payload_type<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!type<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* result = type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!result<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!result<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + container_metadata& get<span class="Delimiter">(</span>vector<pair<type_tree*<span class="Delimiter">,</span> container_metadata> >& all<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree* key<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>all<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>matches<span class="Delimiter">(</span>all<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first<span class="Delimiter">,</span> key<span class="Delimiter">))</span> @@ -384,67 +381,6 @@ container_metadata& get<span class="Delimiter">(</span>vector<pair<typ CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_container_sizes_from_array<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Comment">// a container we don't have the size for</span> - reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> - CHECK<span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> - <span class="Comment">// scanning an array of the container precomputes the size of the container</span> - reagent r<span class="Delimiter">(</span><span class="Constant">"x:array:point"</span><span class="Delimiter">);</span> - compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> - CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> - CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> -<span class="Delimiter">}</span> - -<span class="Normal">void</span> test_container_sizes_from_address_to_array<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Comment">// a container we don't have the size for</span> - reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> - CHECK<span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> - <span class="Comment">// scanning an address to an array of the container precomputes the size of the container</span> - reagent r<span class="Delimiter">(</span><span class="Constant">"x:address:array:point"</span><span class="Delimiter">);</span> - compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> - CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> - CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> -<span class="Delimiter">}</span> - -<span class="Normal">void</span> test_container_sizes_from_static_array<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Comment">// a container we don't have the size for</span> - reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> - <span class="Normal">int</span> old_size = SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">);</span> - <span class="Comment">// scanning an address to an array of the container precomputes the size of the container</span> - reagent r<span class="Delimiter">(</span><span class="Constant">"x:array:point:10"</span><span class="Delimiter">);</span> - compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> - CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> - CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> - <span class="Comment">// no non-container types precomputed</span> - CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">)</span>-old_size<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> -<span class="Delimiter">}</span> - -<span class="Normal">void</span> test_container_sizes_from_address_to_static_array<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Comment">// a container we don't have the size for</span> - reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> - <span class="Normal">int</span> old_size = SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">);</span> - <span class="Comment">// scanning an address to an array of the container precomputes the size of the container</span> - reagent r<span class="Delimiter">(</span><span class="Constant">"x:address:array:point:10"</span><span class="Delimiter">);</span> - compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> - CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> - CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> - <span class="Comment">// no non-container types precomputed</span> - CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">)</span>-old_size<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> -<span class="Delimiter">}</span> - -<span class="Normal">void</span> test_container_sizes_from_repeated_address_and_array_types<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Comment">// a container we don't have the size for</span> - reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> - <span class="Normal">int</span> old_size = SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">);</span> - <span class="Comment">// scanning repeated address and array types modifying the container precomputes the size of the container</span> - reagent r<span class="Delimiter">(</span><span class="Constant">"x:address:array:address:array:point:10"</span><span class="Delimiter">);</span> - compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> - CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> - CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> - <span class="Comment">// no non-container types precomputed</span> - CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">)</span>-old_size<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> -<span class="Delimiter">}</span> - <span class="SalientComment">//:: To access elements of a container, use 'get'</span> <span class="Comment">//: 'get' takes a 'base' container and an 'offset' into it and returns the</span> <span class="Comment">//: appropriate element of the container value.</span> @@ -530,10 +466,11 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(code)</span> <span class="Normal">const</span> reagent element_type<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">,</span> <span class="Normal">int</span> offset_value<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>offset_value >= <span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">const</span> type_tree* root = root_type<span class="Delimiter">(</span>type<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root<span class="Delimiter">-></span>value<span class="Delimiter">));</span> - assert<span class="Delimiter">(</span>!get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> - <span class="Normal">const</span> type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* base_type = type<span class="Delimiter">;</span> + <span class="Comment">// Update base_type in element_type</span> + assert<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">));</span> + assert<span class="Delimiter">(</span>!get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + <span class="Normal">const</span> type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>offset_value >= SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">))</span> <span class="Identifier">return</span> reagent<span class="Delimiter">();</span> <span class="Comment">// error handled elsewhere</span> reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> element = info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset_value<span class="Delimiter">);</span> @@ -821,9 +758,6 @@ Num_calls_to_transform_all_at_first_definition = -<span class="Constant">1</span <span class="Normal">if</span> <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> type<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// sometimes types will contain non-type tags, like numbers for the size of an array</span> - type<span class="Delimiter">-></span>value = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> <span class="Comment">// End insert_container Special-cases</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>name != <span class="Constant">"->"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// used in recipe types</span> put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span> diff --git a/html/031merge.cc.html b/html/031merge.cc.html index 3c86781c..c565c37b 100644 --- a/html/031merge.cc.html +++ b/html/031merge.cc.html @@ -203,7 +203,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Normal">if</span> <span class="Delimiter">(</span>types_coercible<span class="Delimiter">(</span>expected_ingredient<span class="Delimiter">,</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">)))</span> <span class="Delimiter">{</span> ++ingredient_index<span class="Delimiter">;</span> ++state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container<span class="Delimiter">.</span>type<span class="Delimiter">)-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Normal">while</span> <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> get_base_type<span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container<span class="Delimiter">.</span>type<span class="Delimiter">)-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> <span class="Normal">if</span> <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>ingredient_index < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">))</span> @@ -220,7 +220,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// End check_merge_call Cases</span> + <span class="Comment">// End check_merge_call Special-cases</span> <span class="Normal">default</span>: <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>container<span class="Delimiter">,</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"incorrect type of ingredient "</span> << ingredient_index << <span class="Constant">" in '"</span> << 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> @@ -238,7 +238,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> ++state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index<span class="Delimiter">;</span> - <span class="Delimiter">}</span> <span class="Normal">while</span> <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container<span class="Delimiter">.</span>type<span class="Delimiter">)-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">));</span> + <span class="Delimiter">}</span> <span class="Normal">while</span> <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> get_base_type<span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container<span class="Delimiter">.</span>type<span class="Delimiter">)-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -246,6 +246,12 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span class="Comment">// replaced in a later layer</span> +<span class="Comment">// todo: find some clean way to take this call completely out of this layer</span> +<span class="Normal">const</span> type_tree* get_base_type<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* t<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> t<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + <span class="Delimiter">:(scenario merge_check_product)</span> <span class="Special">% Hide_errors = true;</span> <span class="muRecipe">def</span> main [ diff --git a/html/032array.cc.html b/html/032array.cc.html index d8264b08..fce1f02d 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -135,23 +135,38 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span ] <span class="traceContains">+app: foo: 3 14 15 16</span> -<span class="Delimiter">:(before "End size_of(reagent r) Cases")</span> +<span class="Delimiter">:(before "End types_coercible Special-cases")</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>from<span class="Delimiter">)</span> && is_mu_array<span class="Delimiter">(</span>to<span class="Delimiter">))</span> + <span class="Identifier">return</span> types_strictly_match<span class="Delimiter">(</span>array_element<span class="Delimiter">(</span>from<span class="Delimiter">.</span>type<span class="Delimiter">),</span> array_element<span class="Delimiter">(</span>to<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + +<span class="Delimiter">:(before "End size_of(reagent r) Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"'"</span> << r<span class="Delimiter">.</span>original_string << <span class="Constant">"' is an array of what?</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - type_tree* element_type = copy_array_element<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> - <span class="Normal">int</span> result = <span class="Constant">1</span> + array_length<span class="Delimiter">(</span>r<span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">);</span> - <span class="Normal">delete</span> element_type<span class="Delimiter">;</span> - <span class="Identifier">return</span> result<span class="Delimiter">;</span> + <span class="Identifier">return</span> <span class="Comment">/*</span><span class="Comment">space for length</span><span class="Comment">*/</span><span class="Constant">1</span> + array_length<span class="Delimiter">(</span>r<span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>array_element<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">));</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End size_of(type) Non-atom Special-cases")</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> static_array_length<span class="Delimiter">(</span>type<span class="Delimiter">);</span> +<span class="Delimiter">:(code)</span> +<span class="Normal">int</span> static_array_length<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>atom && type<span class="Delimiter">-></span>right && !type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right && !type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && !type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right <span class="Comment">// exactly 3 types</span> + && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// third 'type' is a number</span> + <span class="Comment">// get size from type</span> + <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + cerr << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">//: disable the size mismatch check for arrays since the destination array</span> <span class="Comment">//: need not be initialized</span> -<span class="Delimiter">:(before "End size_mismatch(x) Cases")</span> +<span class="Delimiter">:(before "End size_mismatch(x) Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span class="SalientComment">//:: arrays inside containers</span> <span class="Comment">//: arrays are disallowed inside containers unless their length is fixed in</span> <span class="Comment">//: advance</span> @@ -161,6 +176,11 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span ] $error: <span class="Constant">0</span> +<span class="Delimiter">:(before "End insert_container Special-cases")</span> +<span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// sometimes types will contain non-type tags, like numbers for the size of an array</span> + type<span class="Delimiter">-></span>value = <span class="Constant">0</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + <span class="Delimiter">:(scenario container_disallows_dynamic_array_element)</span> <span class="Special">% Hide_errors = true;</span> <span class="muData">container</span> foo [ @@ -168,25 +188,6 @@ $error: <span class="Constant">0</span> ] <span class="traceContains">+error: container 'foo' cannot determine size of element 'x'</span> -<span class="Comment">//: disable the size mismatch check for 'merge' instructions since containers</span> -<span class="Comment">//: can contain arrays, and since we already do plenty of checking for them</span> -<span class="Delimiter">:(before "End size_mismatch(x) Cases")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>current_call<span class="Delimiter">().</span>running_step_index < SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> current_call<span class="Delimiter">().</span>running_recipe<span class="Delimiter">).</span>steps<span class="Delimiter">)</span> - && current_instruction<span class="Delimiter">().</span>operation == MERGE<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">:(scenario merge_static_array_into_container)</span> -<span class="muData">container</span> foo [ - <span class="Normal">x</span>:num - <span class="Normal">y</span>:array:num:<span class="Constant">3</span> -] -<span class="muRecipe">def</span> main [ - <span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array - <span class="Constant">10</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">1</span>:array:num:<span class="Constant">3</span> -] -<span class="Comment"># no errors</span> - <span class="Delimiter">:(before "End Load Container Element Definition")</span> <span class="Delimiter">{</span> <span class="Normal">const</span> type_tree* type = info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>type<span class="Delimiter">;</span> @@ -199,13 +200,32 @@ $error: <span class="Constant">0</span> raise << <span class="Constant">"container '"</span> << name << <span class="Constant">"' doesn't specify type of array elements for '"</span> << info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<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="Identifier">continue</span><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="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// array has no length</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right || !is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// array has no length</span> raise << <span class="Constant">"container '"</span> << name << <span class="Constant">"' cannot determine size of element '"</span> << info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<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="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> +<span class="Comment">//: disable the size mismatch check for 'merge' instructions since containers</span> +<span class="Comment">//: can contain arrays, and since we already do plenty of checking for them</span> +<span class="Delimiter">:(before "End size_mismatch(x) Special-cases")</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>current_call<span class="Delimiter">().</span>running_step_index < SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> current_call<span class="Delimiter">().</span>running_recipe<span class="Delimiter">).</span>steps<span class="Delimiter">)</span> + && current_instruction<span class="Delimiter">().</span>operation == MERGE<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">:(scenario merge_static_array_into_container)</span> +<span class="muData">container</span> foo [ + <span class="Normal">x</span>:num + <span class="Normal">y</span>:array:num:<span class="Constant">3</span> +] +<span class="muRecipe">def</span> main [ + <span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array + <span class="Constant">10</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">1</span>:array:num:<span class="Constant">3</span> +] +<span class="Comment"># no errors</span> + <span class="Delimiter">:(scenario code_inside_container)</span> <span class="Special">% Hide_errors = true;</span> <span class="muData">container</span> card [ @@ -217,6 +237,75 @@ $error: <span class="Constant">0</span> ] <span class="Comment"># shouldn't die</span> +<span class="SalientComment">//:: containers inside arrays</span> +<span class="Comment">//: make sure we compute container sizes inside arrays</span> + +<span class="Delimiter">:(before "End compute_container_sizes Non-atom Special-cases")</span> +<span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> + compute_container_sizes<span class="Delimiter">(</span>array_element<span class="Delimiter">(</span>type<span class="Delimiter">),</span> pending_metadata<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> + +<span class="Delimiter">:(before "End Unit Tests")</span> +<span class="Normal">void</span> test_container_sizes_from_array<span class="Delimiter">()</span> <span class="Delimiter">{</span> + <span class="Comment">// a container we don't have the size for</span> + reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + <span class="Comment">// scanning an array of the container precomputes the size of the container</span> + reagent r<span class="Delimiter">(</span><span class="Constant">"x:array:point"</span><span class="Delimiter">);</span> + compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Normal">void</span> test_container_sizes_from_address_to_array<span class="Delimiter">()</span> <span class="Delimiter">{</span> + <span class="Comment">// a container we don't have the size for</span> + reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + <span class="Comment">// scanning an address to an array of the container precomputes the size of the container</span> + reagent r<span class="Delimiter">(</span><span class="Constant">"x:address:array:point"</span><span class="Delimiter">);</span> + compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Normal">void</span> test_container_sizes_from_static_array<span class="Delimiter">()</span> <span class="Delimiter">{</span> + <span class="Comment">// a container we don't have the size for</span> + reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> + <span class="Normal">int</span> old_size = SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">);</span> + <span class="Comment">// scanning an address to an array of the container precomputes the size of the container</span> + reagent r<span class="Delimiter">(</span><span class="Constant">"x:array:point:10"</span><span class="Delimiter">);</span> + compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> + <span class="Comment">// no non-container types precomputed</span> + CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">)</span>-old_size<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Normal">void</span> test_container_sizes_from_address_to_static_array<span class="Delimiter">()</span> <span class="Delimiter">{</span> + <span class="Comment">// a container we don't have the size for</span> + reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> + <span class="Normal">int</span> old_size = SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">);</span> + <span class="Comment">// scanning an address to an array of the container precomputes the size of the container</span> + reagent r<span class="Delimiter">(</span><span class="Constant">"x:address:array:point:10"</span><span class="Delimiter">);</span> + compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> + <span class="Comment">// no non-container types precomputed</span> + CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">)</span>-old_size<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Normal">void</span> test_container_sizes_from_repeated_address_and_array_types<span class="Delimiter">()</span> <span class="Delimiter">{</span> + <span class="Comment">// a container we don't have the size for</span> + reagent container<span class="Delimiter">(</span><span class="Constant">"x:point"</span><span class="Delimiter">);</span> + <span class="Normal">int</span> old_size = SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">);</span> + <span class="Comment">// scanning repeated address and array types modifying the container precomputes the size of the container</span> + reagent r<span class="Delimiter">(</span><span class="Constant">"x:address:array:address:array:point:10"</span><span class="Delimiter">);</span> + compute_container_sizes<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + CHECK_EQ<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">).</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> + <span class="Comment">// no non-container types precomputed</span> + CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">)</span>-old_size<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + <span class="SalientComment">//:: To access elements of an array, use 'index'</span> <span class="Delimiter">:(scenario index)</span> @@ -275,7 +364,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> product = inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// Update INDEX product in Check</span> - reagent element<span class="Delimiter">;</span> + reagent<span class="Comment">/*</span><span class="Comment">local</span><span class="Comment">*/</span> element<span class="Delimiter">;</span> element<span class="Delimiter">.</span>type = copy_array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>product<span class="Delimiter">,</span> element<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'index' on '"</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">"' can't be saved in '"</span> << product<span class="Delimiter">.</span>original_string << <span class="Constant">"'; type should be '"</span> << names_to_string_without_quotes<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> @@ -300,13 +389,11 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"invalid index "</span> << no_scientific<span class="Delimiter">(</span>index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> << <span class="Constant">" in '"</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - type_tree* element_type = copy_array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> - <span class="Normal">int</span> src = base_address + <span class="Constant">1</span> + index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src << end<span class="Delimiter">();</span> - trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << to_string<span class="Delimiter">(</span>element_type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - reagent element<span class="Delimiter">;</span> - element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>src<span class="Delimiter">);</span> - element<span class="Delimiter">.</span>type = element_type<span class="Delimiter">;</span> + reagent<span class="Comment">/*</span><span class="Comment">local</span><span class="Comment">*/</span> element<span class="Delimiter">;</span> + element<span class="Delimiter">.</span>type = copy_array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>base_address + <span class="Comment">/*</span><span class="Comment">skip length</span><span class="Comment">*/</span><span class="Constant">1</span> + index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << element<span class="Delimiter">.</span>value << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << to_string<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span class="Comment">// Read element</span> products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>element<span class="Delimiter">));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -314,24 +401,38 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(code)</span> type_tree* copy_array_element<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*array_element<span class="Delimiter">(</span>type<span class="Delimiter">));</span> +<span class="Delimiter">}</span> + +type_tree* array_element<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> - <span class="Comment">// hack: don't require parens for either array:num:3 array:address:num</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">))</span> - <span class="Identifier">return</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">);</span> - <span class="Identifier">return</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Comment">// hack: support array:num:3 without requiring extra parens</span> + <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + <span class="Identifier">return</span> type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">int</span> array_length<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom <span class="Comment">// exactly 3 types</span> - && is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// third 'type' is a number</span> + <span class="Comment">// x should already be canonized.</span> + <span class="Comment">// hack: look for length in type</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right <span class="Comment">// exactly 3 types</span> + && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// third 'type' is a number</span> <span class="Comment">// get size from type</span> - <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// this should never happen at transform time</span> - <span class="Comment">// x should already be canonized.</span> <span class="Identifier">return</span> get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> x<span class="Delimiter">.</span>value<span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Unit Tests")</span> <span class="Normal">void</span> test_array_length_compound<span class="Delimiter">()</span> <span class="Delimiter">{</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">3</span><span class="Delimiter">);</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">14</span><span class="Delimiter">);</span> @@ -342,6 +443,11 @@ type_tree* copy_array_element<span class="Delimiter">(</span><span class="Normal CHECK_EQ<span class="Delimiter">(</span>array_length<span class="Delimiter">(</span>x<span class="Delimiter">),</span> <span class="Constant">3</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span class="Normal">void</span> test_array_length_static<span class="Delimiter">()</span> <span class="Delimiter">{</span> + reagent x<span class="Delimiter">(</span><span class="Constant">"1:array:num:3"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>array_length<span class="Delimiter">(</span>x<span class="Delimiter">),</span> <span class="Constant">3</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + <span class="Delimiter">:(scenario index_truncates)</span> <span class="muRecipe">def</span> main [ <span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array @@ -443,7 +549,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">}</span> reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> value = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span> <span class="Comment">// Update PUT_INDEX value in Check</span> - reagent element<span class="Delimiter">;</span> + reagent<span class="Comment">/*</span><span class="Comment">local</span><span class="Comment">*/</span> element<span class="Delimiter">;</span> element<span class="Delimiter">.</span>type = copy_array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>element<span class="Delimiter">,</span> value<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'put-index "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">", "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>original_string << <span class="Constant">"' should store "</span> << names_to_string_without_quotes<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" but '"</span> << value<span class="Delimiter">.</span>name << <span class="Constant">"' has type "</span> << names_to_string_without_quotes<span class="Delimiter">(</span>value<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> @@ -473,10 +579,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"invalid index "</span> << no_scientific<span class="Delimiter">(</span>index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> << <span class="Constant">" in '"</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - reagent element<span class="Delimiter">;</span> - element<span class="Delimiter">.</span>type = copy_array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> - <span class="Normal">int</span> address = base_address + <span class="Constant">1</span> + index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">);</span> - element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address<span class="Delimiter">);</span> + <span class="Normal">int</span> address = base_address + <span class="Comment">/*</span><span class="Comment">skip length</span><span class="Comment">*/</span><span class="Constant">1</span> + index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">));</span> trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy to is "</span> << address << end<span class="Delimiter">();</span> <span class="Comment">// optimization: directly write the element rather than updating 'product'</span> <span class="Comment">// and writing the entire array</span> diff --git a/html/033exclusive_container.cc.html b/html/033exclusive_container.cc.html index b2dfb99d..82e44b36 100644 --- a/html/033exclusive_container.cc.html +++ b/html/033exclusive_container.cc.html @@ -67,12 +67,12 @@ get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span <span class="traceContains">+mem: storing 34 in location 5</span> <span class="traceContains">+mem: storing 35 in location 6</span> -<span class="Delimiter">:(before "End size_of(type) Cases")</span> +<span class="Delimiter">:(before "End size_of(type) Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == EXCLUSIVE_CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// Compute size_of Exclusive Container</span> <span class="Identifier">return</span> get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> type<span class="Delimiter">).</span>size<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(before "End compute_container_sizes Atom Cases")</span> +<span class="Delimiter">:(before "End compute_container_sizes Atom Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == EXCLUSIVE_CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> compute_exclusive_container_sizes<span class="Delimiter">(</span>info<span class="Delimiter">,</span> type<span class="Delimiter">,</span> pending_metadata<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -351,7 +351,7 @@ $error: <span class="Constant">0</span> <span class="traceContains">+mem: storing 34 in location 6</span> $error: <span class="Constant">0</span> -<span class="Delimiter">:(before "End check_merge_call Cases")</span> +<span class="Delimiter">:(before "End check_merge_call Special-cases")</span> <span class="Normal">case</span> EXCLUSIVE_CONTAINER: <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index == <span class="Constant">0</span><span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking exclusive container "</span> << to_string<span class="Delimiter">(</span>container<span class="Delimiter">)</span> << <span class="Constant">" vs ingredient "</span> << ingredient_index << end<span class="Delimiter">();</span> @@ -472,7 +472,7 @@ $error: <span class="Constant">0</span> <span class="Comment">//: Since the different variants of an exclusive-container might have</span> <span class="Comment">//: different sizes, relax the size mismatch check for 'merge' instructions.</span> -<span class="Delimiter">:(before "End size_mismatch(x) Cases")</span> +<span class="Delimiter">:(before "End size_mismatch(x) Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>current_step_index<span class="Delimiter">()</span> < SIZE<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>steps<span class="Delimiter">())</span> && current_instruction<span class="Delimiter">().</span>operation == MERGE && !current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> diff --git a/html/034address.cc.html b/html/034address.cc.html index 5d2cc554..03c374e6 100644 --- a/html/034address.cc.html +++ b/html/034address.cc.html @@ -41,7 +41,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment">//: units (containers or arrays) that may contain many different primitives at</span> <span class="Comment">//: once. Containers and arrays can grow quite large in complex programs, and</span> <span class="Comment">//: we'd like some way to efficiently share them between recipes without</span> -<span class="Comment">//: constantly having to make copies. Right now 'next-ingredient' and 'reply'</span> +<span class="Comment">//: constantly having to make copies. Right now 'next-ingredient' and 'return'</span> <span class="Comment">//: copy data across recipe boundaries. To avoid copying large quantities of</span> <span class="Comment">//: data around, we'll use *addresses*. An address is a bookmark to some</span> <span class="Comment">//: arbitrary quantity of data (the *payload*). It's a primitive, so it's as</span> @@ -246,10 +246,18 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span raise << <span class="Constant">"can't drop2 "</span> << expected_type << <span class="Constant">" from '"</span> << to_string<span class="Delimiter">(</span>r<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + <span class="Comment">// r.type = r.type->right</span> type_tree* tmp = r<span class="Delimiter">.</span>type<span class="Delimiter">;</span> r<span class="Delimiter">.</span>type = tmp<span class="Delimiter">-></span>right<span class="Delimiter">;</span> tmp<span class="Delimiter">-></span>right = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Normal">delete</span> tmp<span class="Delimiter">;</span> + <span class="Comment">// if (!r.type->right) r.type = r.type->left</span> + assert<span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + tmp = r<span class="Delimiter">.</span>type<span class="Delimiter">;</span> + r<span class="Delimiter">.</span>type = tmp<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + tmp<span class="Delimiter">-></span>left = <span class="Constant">NULL</span><span class="Delimiter">;</span> + <span class="Normal">delete</span> tmp<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario new_returns_incorrect_type)</span> @@ -259,6 +267,13 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span ] <span class="traceContains">+error: main: product of 'new' has incorrect type: '1:bool <- new num:type'</span> +<span class="Delimiter">:(scenario new_discerns_singleton_list_from_atom_container)</span> +<span class="Special">% Hide_errors = true;</span> +<span class="muRecipe">def</span> main [ + <span class="Constant">1</span>:address:num/<span class="Special">raw <- </span><span class="Normal">new</span> <span class="Delimiter">{(</span>num<span class="Delimiter">)</span>: type<span class="Delimiter">}</span> <span class="Comment"># should be '{num: type}'</span> +] +<span class="traceContains">+error: main: product of 'new' has incorrect type: '1:address:num/raw <- new {(num): type}'</span> + <span class="Delimiter">:(scenario new_with_type_abbreviation)</span> <span class="muRecipe">def</span> main [ <span class="Constant">1</span>:address:num/<span class="Special">raw <- </span><span class="Normal">new</span> <span class="Constant">num:type</span> diff --git a/html/036refcount.cc.html b/html/036refcount.cc.html index 54c790d3..fb44f1f0 100644 --- a/html/036refcount.cc.html +++ b/html/036refcount.cc.html @@ -90,7 +90,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_address<span class="Delimiter">(</span>canonized_x<span class="Delimiter">))</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>canonized_x<span class="Delimiter">.</span>value<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>!canonized_x<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>size<span class="Delimiter">);</span> - decrement_refcount<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> canonized_x<span class="Delimiter">.</span>value<span class="Delimiter">),</span> canonized_x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> payload_size<span class="Delimiter">(</span>canonized_x<span class="Delimiter">));</span> + decrement_refcount<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> canonized_x<span class="Delimiter">.</span>value<span class="Delimiter">),</span> payload_type<span class="Delimiter">(</span>canonized_x<span class="Delimiter">.</span>type<span class="Delimiter">),</span> payload_size<span class="Delimiter">(</span>canonized_x<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Comment">// End Decrement Refcounts(canonized_x)</span> <span class="Delimiter">}</span> @@ -196,6 +196,9 @@ update_any_refcounts<span class="Delimiter">(</span>element<span class="Delimite <span class="traceContains">+mem: incrementing refcount of 1000: 1 -> 2</span> <span class="Delimiter">:(after "Write Memory in PUT_INDEX in Run")</span> +reagent<span class="Comment">/*</span><span class="Comment">local</span><span class="Comment">*/</span> element<span class="Delimiter">;</span> +element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address<span class="Delimiter">);</span> +element<span class="Delimiter">.</span>type = copy_array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> update_any_refcounts<span class="Delimiter">(</span>element<span class="Delimiter">,</span> value<span class="Delimiter">);</span> <span class="Delimiter">:(scenario refcounts_maybe_convert)</span> @@ -346,21 +349,20 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Normal">void</span> compute_container_address_offsets<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">,</span> <span class="Normal">const</span> string& location_for_error_messages<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> - assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"address"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - compute_container_address_offsets<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> type_tree* element_type = type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> - <span class="Comment">// hack: support both array:num:3 and array:address:num</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!element_type<span class="Delimiter">-></span>atom && element_type<span class="Delimiter">-></span>right && element_type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">))</span> - element_type = element_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> - compute_container_address_offsets<span class="Delimiter">(</span>element_type<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"invalid type "</span> << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << location_for_error_messages << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// End compute_container_address_offsets Non-atom Cases</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"address"</span><span class="Delimiter">)</span> + compute_container_address_offsets<span class="Delimiter">(</span>payload_type<span class="Delimiter">(</span>type<span class="Delimiter">),</span> location_for_error_messages<span class="Delimiter">);</span> + <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> + compute_container_address_offsets<span class="Delimiter">(</span>array_element<span class="Delimiter">(</span>type<span class="Delimiter">),</span> location_for_error_messages<span class="Delimiter">);</span> + <span class="Comment">// End compute_container_address_offsets Non-atom Special-cases</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">(</span>type<span class="Delimiter">)-></span>value<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// error raised elsewhere</span> - type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">(</span>type<span class="Delimiter">)-></span>value<span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* base_type = type<span class="Delimiter">;</span> + <span class="Comment">// Update base_type in compute_container_address_offsets</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// error raised elsewhere</span> + type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> compute_container_address_offsets<span class="Delimiter">(</span>info<span class="Delimiter">,</span> type<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -388,28 +390,39 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Normal">void</span> append_addresses<span class="Delimiter">(</span><span class="Normal">int</span> base_offset<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree* type<span class="Delimiter">,</span> map<set<tag_condition_info><span class="Delimiter">,</span> set<address_element_info> >& out<span class="Delimiter">,</span> <span class="Normal">const</span> set<tag_condition_info>& key<span class="Delimiter">,</span> <span class="Normal">const</span> string& location_for_error_messages<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_address<span class="Delimiter">(</span>type<span class="Delimiter">))</span> <span class="Delimiter">{</span> - get_or_insert<span class="Delimiter">(</span>out<span class="Delimiter">,</span> key<span class="Delimiter">).</span>insert<span class="Delimiter">(</span>address_element_info<span class="Delimiter">(</span>base_offset<span class="Delimiter">,</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*type<span class="Delimiter">-></span>right<span class="Delimiter">)));</span> + get_or_insert<span class="Delimiter">(</span>out<span class="Delimiter">,</span> key<span class="Delimiter">).</span>insert<span class="Delimiter">(</span>address_element_info<span class="Delimiter">(</span>base_offset<span class="Delimiter">,</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*payload_type<span class="Delimiter">(</span>type<span class="Delimiter">))));</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">const</span> type_tree* root = root_type<span class="Delimiter">(</span>type<span class="Delimiter">);</span> - <span class="Normal">const</span> type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* base_type = type<span class="Delimiter">;</span> + <span class="Comment">// Update base_type in append_container_address_offsets</span> + <span class="Normal">const</span> type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> curr_index = <span class="Constant">0</span><span class="Delimiter">,</span> curr_offset = base_offset<span class="Delimiter">;</span> curr_index < SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++curr_index<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">"checking container "</span> << root<span class="Delimiter">-></span>name << <span class="Constant">", element "</span> << curr_index << end<span class="Delimiter">();</span> - reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> element = element_type<span class="Delimiter">(</span>type<span class="Delimiter">,</span> curr_index<span class="Delimiter">);</span> <span class="Comment">// not root</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">"checking container "</span> << base_type<span class="Delimiter">-></span>name << <span class="Constant">", element "</span> << curr_index << end<span class="Delimiter">();</span> + reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> element = element_type<span class="Delimiter">(</span>type<span class="Delimiter">,</span> curr_index<span class="Delimiter">);</span> <span class="Comment">// not base_type</span> <span class="Comment">// Compute Container Address Offset(element)</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_address<span class="Delimiter">(</span>element<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">"address at offset "</span> << curr_offset << end<span class="Delimiter">();</span> - get_or_insert<span class="Delimiter">(</span>out<span class="Delimiter">,</span> key<span class="Delimiter">).</span>insert<span class="Delimiter">(</span>address_element_info<span class="Delimiter">(</span>curr_offset<span class="Delimiter">,</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)));</span> + get_or_insert<span class="Delimiter">(</span>out<span class="Delimiter">,</span> key<span class="Delimiter">).</span>insert<span class="Delimiter">(</span>address_element_info<span class="Delimiter">(</span>curr_offset<span class="Delimiter">,</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*payload_type<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">))));</span> ++curr_offset<span class="Delimiter">;</span> <span class="Delimiter">}</span> + <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>element<span class="Delimiter">))</span> <span class="Delimiter">{</span> + curr_offset += <span class="Comment">/*</span><span class="Comment">array length</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> + <span class="Normal">const</span> type_tree* array_element_type = array_element<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + <span class="Normal">int</span> array_element_size = size_of<span class="Delimiter">(</span>array_element_type<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 < static_array_length<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + append_addresses<span class="Delimiter">(</span>curr_offset<span class="Delimiter">,</span> array_element_type<span class="Delimiter">,</span> out<span class="Delimiter">,</span> key<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> + curr_offset += array_element_size<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_container<span class="Delimiter">(</span>element<span class="Delimiter">))</span> <span class="Delimiter">{</span> append_addresses<span class="Delimiter">(</span>curr_offset<span class="Delimiter">,</span> element<span class="Delimiter">.</span>type<span class="Delimiter">,</span> out<span class="Delimiter">,</span> key<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> curr_offset += size_of<span class="Delimiter">(</span>element<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_exclusive_container<span class="Delimiter">(</span>element<span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> type_tree* element_root_type = root_type<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">);</span> - <span class="Normal">const</span> type_info& element_info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> element_root_type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* element_base_type = element<span class="Delimiter">.</span>type<span class="Delimiter">;</span> + <span class="Comment">// Update element_base_type For Exclusive Container in append_addresses</span> + <span class="Normal">const</span> type_info& element_info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> element_base_type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> tag = <span class="Constant">0</span><span class="Delimiter">;</span> tag < SIZE<span class="Delimiter">(</span>element_info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++tag<span class="Delimiter">)</span> <span class="Delimiter">{</span> set<tag_condition_info> new_key = key<span class="Delimiter">;</span> new_key<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>tag_condition_info<span class="Delimiter">(</span>curr_offset<span class="Delimiter">,</span> tag<span class="Delimiter">));</span> @@ -434,12 +447,6 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Normal">int</span> payload_size<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name == <span class="Constant">"address"</span><span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name != <span class="Constant">"array"</span><span class="Delimiter">);</span> - <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> + <span class="Comment">/*</span><span class="Comment">refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> - <span class="Comment">//: for the following unit tests we'll do the work of the transform by hand</span> <span class="Delimiter">:(before "End Unit Tests")</span> @@ -739,8 +746,13 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Normal">const</span> container_metadata& metadata = get<span class="Delimiter">(</span>Container_metadata<span class="Delimiter">,</span> canonized_x<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<set<tag_condition_info><span class="Delimiter">,</span> set<address_element_info> >::const_iterator p = metadata<span class="Delimiter">.</span>address<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != metadata<span class="Delimiter">.</span>address<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!all_match<span class="Delimiter">(</span>data<span class="Delimiter">,</span> p<span class="Delimiter">-></span>first<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>set<address_element_info>::const_iterator info = p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> info != p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++info<span class="Delimiter">)</span> - decrement_refcount<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> canonized_x<span class="Delimiter">.</span>value + info<span class="Delimiter">-></span>offset<span class="Delimiter">),</span> info<span class="Delimiter">-></span>payload_type<span class="Delimiter">,</span> size_of<span class="Delimiter">(</span>info<span class="Delimiter">-></span>payload_type<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> + <span class="Normal">for</span> <span class="Delimiter">(</span>set<address_element_info>::const_iterator info = p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> info != p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++info<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">int</span> element_address = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> canonized_x<span class="Delimiter">.</span>value + info<span class="Delimiter">-></span>offset<span class="Delimiter">);</span> + reagent<span class="Comment">/*</span><span class="Comment">local</span><span class="Comment">*/</span> element<span class="Delimiter">;</span> + element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>element_address+<span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> + element<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*info<span class="Delimiter">-></span>payload_type<span class="Delimiter">);</span> + decrement_refcount<span class="Delimiter">(</span>element_address<span class="Delimiter">,</span> info<span class="Delimiter">-></span>payload_type<span class="Delimiter">,</span> size_of<span class="Delimiter">(</span>element<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -948,6 +960,45 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="traceContains">+run: {2: "foo"} <- merge {3: ("address" "array" "number")}</span> <span class="traceContains">+mem: decrementing refcount of 1000: 2 -> 1</span> +<span class="Delimiter">:(scenario refcounts_copy_address_within_static_array_within_container)</span> +<span class="muData">container</span> foo [ + <span class="Normal">a</span>:array:bar:<span class="Constant">3</span> + <span class="Normal">b</span>:address:num +] +<span class="muData">container</span> bar [ + <span class="Normal">y</span>:num + <span class="Normal">z</span>:address:num +] +<span class="muRecipe">def</span> main [ + <span class="Constant">1</span>:address:num<span class="Special"> <- </span><span class="Normal">new</span> <span class="Constant">number:type</span> + <span class="Constant">2</span>:bar<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:num + <span class="Constant">10</span>:array:bar:<span class="Constant">3</span><span class="Special"> <- </span>create-array + put-index <span class="Constant">10</span>:array:bar:<span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">2</span>:bar + <span class="Constant">20</span>:foo<span class="Special"> <- </span>merge <span class="Constant">10</span>:array:bar:<span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:num + <span class="Constant">1</span>:address:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:bar<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:num + put-index <span class="Constant">10</span>:array:bar:<span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">2</span>:bar + <span class="Constant">20</span>:foo<span class="Special"> <- </span>merge <span class="Constant">10</span>:array:bar:<span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:num +] +<span class="traceContains">+run: {1: ("address" "number")} <- new {number: "type"}</span> +<span class="traceContains">+mem: incrementing refcount of 1000: 0 -> 1</span> +<span class="traceContains">+run: {2: "bar"} <- merge {34: "literal"}, {1: ("address" "number")}</span> +<span class="traceContains">+mem: incrementing refcount of 1000: 1 -> 2</span> +<span class="traceContains">+run: put-index {10: ("array" "bar" "3")}, {1: "literal"}, {2: "bar"}</span> +<span class="traceContains">+mem: incrementing refcount of 1000: 2 -> 3</span> +<span class="traceContains">+run: {20: "foo"} <- merge {10: ("array" "bar" "3")}, {1: ("address" "number")}</span> +<span class="traceContains">+mem: incrementing refcount of 1000: 3 -> 4</span> +<span class="traceContains">+mem: incrementing refcount of 1000: 4 -> 5</span> +<span class="traceContains">+run: {1: ("address" "number")} <- copy {0: "literal"}</span> +<span class="traceContains">+mem: decrementing refcount of 1000: 5 -> 4</span> +<span class="traceContains">+run: {2: "bar"} <- merge {34: "literal"}, {1: ("address" "number")}</span> +<span class="traceContains">+mem: decrementing refcount of 1000: 4 -> 3</span> +<span class="traceContains">+run: put-index {10: ("array" "bar" "3")}, {1: "literal"}, {2: "bar"}</span> +<span class="traceContains">+mem: decrementing refcount of 1000: 3 -> 2</span> +<span class="traceContains">+run: {20: "foo"} <- merge {10: ("array" "bar" "3")}, {1: ("address" "number")}</span> +<span class="traceContains">+mem: decrementing refcount of 1000: 2 -> 1</span> +<span class="traceContains">+mem: decrementing refcount of 1000: 1 -> 0</span> + <span class="Delimiter">:(scenario refcounts_handle_exclusive_containers_with_different_tags)</span> <span class="muData">container</span> foo1 [ <span class="Normal">x</span>:address:num diff --git a/html/037abandon.cc.html b/html/037abandon.cc.html index b60bd60b..a11ba8cf 100644 --- a/html/037abandon.cc.html +++ b/html/037abandon.cc.html @@ -69,7 +69,7 @@ map<<span class="Normal">int</span><span class="Delimiter">,</span> <span cla <span class="CommentedCode">//? cerr << "abandon: " << size << '\n';</span> <span class="Comment">// decrement any contained refcounts</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>payload_type<span class="Delimiter">))</span> <span class="Delimiter">{</span> - reagent element<span class="Delimiter">;</span> + reagent<span class="Comment">/*</span><span class="Comment">local</span><span class="Comment">*/</span> element<span class="Delimiter">;</span> element<span class="Delimiter">.</span>type = copy_array_element<span class="Delimiter">(</span>payload_type<span class="Delimiter">);</span> <span class="Normal">int</span> array_length = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> address+<span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name != <span class="Constant">"array"</span><span class="Delimiter">);</span> @@ -260,6 +260,28 @@ map<<span class="Normal">int</span><span class="Delimiter">,</span> <span cla <span class="Comment"># nested abandon</span> <span class="traceContains">+mem: decrementing refcount of 1000: 1 -> 0</span> <span class="traceContains">+abandon: saving 1000 in free-list of size 2</span> + +<span class="Delimiter">:(scenario refcounts_abandon_array_within_container)</span> +<span class="muData">container</span> foo [ + <span class="Normal">x</span>:address:array:num +] +<span class="muRecipe">def</span> main [ + <span class="Constant">1</span>:address:array:num<span class="Special"> <- </span><span class="Normal">new</span> <span class="Constant">number:type</span><span class="Delimiter">,</span> <span class="Constant">3</span> + <span class="Constant">2</span>:foo<span class="Special"> <- </span>merge <span class="Constant">1</span>:address:array:num + <span class="Constant">1</span>:address:array:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:foo<span class="Special"> <- </span>copy <span class="Constant">0</span> +] +<span class="traceContains">+run: {1: ("address" "array" "number")} <- new {number: "type"}, {3: "literal"}</span> +<span class="traceContains">+mem: incrementing refcount of 1000: 0 -> 1</span> +<span class="traceContains">+run: {2: "foo"} <- merge {1: ("address" "array" "number")}</span> +<span class="traceContains">+mem: incrementing refcount of 1000: 1 -> 2</span> +<span class="traceContains">+run: {1: ("address" "array" "number")} <- copy {0: "literal"}</span> +<span class="traceContains">+mem: decrementing refcount of 1000: 2 -> 1</span> +<span class="traceContains">+run: {2: "foo"} <- copy {0: "literal"}</span> +<span class="traceContains">+mem: decrementing refcount of 1000: 1 -> 0</span> +<span class="traceContains">+mem: automatically abandoning 1000</span> +<span class="Comment"># make sure we save it in a free-list of the appropriate size</span> +<span class="traceContains">+abandon: saving 1000 in free-list of size 5</span> </pre> </body> </html> diff --git a/html/040brace.cc.html b/html/040brace.cc.html index 777e91cf..f1bda55e 100644 --- a/html/040brace.cc.html +++ b/html/040brace.cc.html @@ -427,7 +427,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Comment">// ```</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"return-if"</span> || curr<span class="Delimiter">.</span>name == <span class="Constant">"reply-if"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - emit_return_block<span class="Delimiter">(</span>result<span class="Delimiter">,</span> <span class="Constant">"break-unless"</span><span class="Delimiter">,</span> curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> + emit_return_block<span class="Delimiter">(</span>result<span class="Delimiter">,</span> <span class="Constant">"break-unless"</span><span class="Delimiter">,</span> curr<span class="Delimiter">);</span> curr<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Delimiter">{</span> @@ -443,7 +443,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Comment">// ```</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"return-unless"</span> || curr<span class="Delimiter">.</span>name == <span class="Constant">"reply-unless"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - emit_return_block<span class="Delimiter">(</span>result<span class="Delimiter">,</span> <span class="Constant">"break-if"</span><span class="Delimiter">,</span> curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> + emit_return_block<span class="Delimiter">(</span>result<span class="Delimiter">,</span> <span class="Constant">"break-if"</span><span class="Delimiter">,</span> curr<span class="Delimiter">);</span> curr<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Delimiter">{</span> @@ -452,7 +452,8 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> emit_return_block<span class="Delimiter">(</span>recipe& out<span class="Delimiter">,</span> <span class="Normal">const</span> string& break_command<span class="Delimiter">,</span> <span class="Normal">const</span> vector<reagent>& ingredients<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> emit_return_block<span class="Delimiter">(</span>recipe& out<span class="Delimiter">,</span> <span class="Normal">const</span> string& break_command<span class="Delimiter">,</span> <span class="Normal">const</span> instruction& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> vector<reagent>& ingredients = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">;</span> reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> condition = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> vector<reagent> return_ingredients<span class="Delimiter">;</span> copy<span class="Delimiter">(</span>++ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> ingredients<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>return_ingredients<span class="Delimiter">,</span> return_ingredients<span class="Delimiter">.</span>end<span class="Delimiter">()));</span> @@ -473,6 +474,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa return_inst<span class="Delimiter">.</span>operation = get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"return"</span><span class="Delimiter">);</span> return_inst<span class="Delimiter">.</span>name = <span class="Constant">"return"</span><span class="Delimiter">;</span> return_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>swap<span class="Delimiter">(</span>return_ingredients<span class="Delimiter">);</span> + return_inst<span class="Delimiter">.</span>original_string = inst<span class="Delimiter">.</span>original_string<span class="Delimiter">;</span> out<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>return_inst<span class="Delimiter">);</span> <span class="Comment">// }</span> diff --git a/html/042name.cc.html b/html/042name.cc.html index d6133a59..f81abbd6 100644 --- a/html/042name.cc.html +++ b/html/042name.cc.html @@ -141,7 +141,7 @@ Name = Name_snapshot<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<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>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Comment">// End is_disqualified Cases</span> + <span class="Comment">// End is_disqualified Special-cases</span> <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -158,7 +158,13 @@ type_ordinal skip_addresses<span class="Delimiter">(</span>type_tree* type<span <span class="Normal">while</span> <span class="Delimiter">(</span>type && is_compound_type_starting_with<span class="Delimiter">(</span>type<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">))</span> type = type<span class="Delimiter">-></span>right<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">1</span><span class="Delimiter">;</span> <span class="Comment">// error handled elsewhere</span> - <span class="Identifier">return</span> root_type<span class="Delimiter">(</span>type<span class="Delimiter">)-></span>value<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> type<span class="Delimiter">-></span>value<span class="Delimiter">;</span> + <span class="Normal">const</span> type_tree* base_type = type<span class="Delimiter">;</span> + <span class="Comment">// Update base_type in skip_addresses</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>base_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> + <span class="Identifier">return</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>base_type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Identifier">return</span> base_type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">int</span> find_element_name<span class="Delimiter">(</span><span class="Normal">const</span> type_ordinal t<span class="Delimiter">,</span> <span class="Normal">const</span> string& name<span class="Delimiter">,</span> <span class="Normal">const</span> string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -187,7 +193,7 @@ type_ordinal skip_addresses<span class="Delimiter">(</span>type_tree* type<span <span class="Normal">bool</span> is_special_name<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"_"</span><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>s == <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Comment">// End is_special_name Cases</span> + <span class="Comment">// End is_special_name Special-cases</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/043space.cc.html b/html/043space.cc.html index d66b6eeb..5de969b0 100644 --- a/html/043space.cc.html +++ b/html/043space.cc.html @@ -81,10 +81,10 @@ put<span class="Delimiter">(</span>Type_abbreviations<span class="Delimiter">,</ <span class="traceContains">+name: assign x 1</span> <span class="traceAbsent">-name: assign default-space 1</span> -<span class="Delimiter">:(before "End is_disqualified Cases")</span> +<span class="Delimiter">:(before "End is_disqualified Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> -<span class="Delimiter">:(before "End is_special_name Cases")</span> +<span class="Delimiter">:(before "End is_special_name Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="SalientComment">//:: now implement space support</span> @@ -204,10 +204,10 @@ element<span class="Delimiter">.</span>properties<span class="Delimiter">.</span <span class="Comment"># allocate space for x and y, as well as the chaining slot at 0</span> <span class="traceContains">+mem: array length is 3</span> -<span class="Delimiter">:(before "End is_disqualified Cases")</span> +<span class="Delimiter">:(before "End is_disqualified Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"number-of-locals"</span><span class="Delimiter">)</span> x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> -<span class="Delimiter">:(before "End is_special_name Cases")</span> +<span class="Delimiter">:(before "End is_special_name Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"number-of-locals"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Rewrite Instruction(curr, recipe result)")</span> @@ -236,8 +236,8 @@ element<span class="Delimiter">.</span>properties<span class="Delimiter">.</span <span class="Delimiter">:(scenario local_scope)</span> <span class="muRecipe">def</span> main [ - <span class="Constant">1</span>:&<span class="Special"> <- </span>foo - <span class="Constant">2</span>:&<span class="Special"> <- </span>foo + <span class="Constant">1</span>:&:@:location<span class="Special"> <- </span>foo + <span class="Constant">2</span>:&:@:location<span class="Special"> <- </span>foo <span class="Constant">3</span>:<span class="Normal">bool</span><span class="Special"> <- </span>equal <span class="Constant">1</span>:&<span class="Delimiter">,</span> <span class="Constant">2</span>:& ] <span class="muRecipe">def</span> foo [ @@ -260,7 +260,7 @@ element<span class="Delimiter">.</span>properties<span class="Delimiter">.</span rewrite_default_space_instruction<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Comment">//: todo: do this in a transform, rather than magically in the reply instruction</span> +<span class="Comment">//: todo: do this in a transform, rather than magically in the 'return' instruction</span> <span class="Delimiter">:(after "Falling Through End Of Recipe")</span> try_reclaim_locals<span class="Delimiter">();</span> <span class="Delimiter">:(after "Starting Reply")</span> @@ -297,7 +297,7 @@ try_reclaim_locals<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Comment">// is this reagent one of the values returned by the current (reply) instruction?</span> +<span class="Comment">// is this reagent one of the values returned by the current (return) instruction?</span> <span class="Comment">// is the corresponding ingredient saved in the caller?</span> <span class="Normal">bool</span> escaping<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>Current_routine<span class="Delimiter">);</span> <span class="Comment">// run-time only</span> @@ -408,7 +408,7 @@ Update_refcounts_in_write_memory = <span class="Constant">true</span><span class <span class="muRecipe">def</span> f [ local-scope <span class="Normal">x</span>:&:num<span class="Special"> <- </span><span class="Normal">new</span> <span class="Constant">number:type</span> - reply x:&:num + <span class="Identifier">return</span> x:&:num ] <span class="muRecipe">def</span> main [ f <span class="Comment"># doesn't save result</span> diff --git a/html/046global.cc.html b/html/046global.cc.html index 1eb2f4e7..234acdc1 100644 --- a/html/046global.cc.html +++ b/html/046global.cc.html @@ -64,10 +64,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="traceContains">+mem: storing 24 in location 23</span> <span class="Comment">//: to support it, create another special variable called global space</span> -<span class="Delimiter">:(before "End is_disqualified Cases")</span> +<span class="Delimiter">:(before "End is_disqualified Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"global-space"</span><span class="Delimiter">)</span> x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> -<span class="Delimiter">:(before "End is_special_name Cases")</span> +<span class="Delimiter">:(before "End is_special_name Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"global-space"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">//: writes to this variable go to a field in the current routine</span> diff --git a/html/050scenario.cc.html b/html/050scenario.cc.html index 9aafaebf..bda57dbd 100644 --- a/html/050scenario.cc.html +++ b/html/050scenario.cc.html @@ -264,7 +264,7 @@ maybe_make_raw<span class="Delimiter">(</span>product<span class="Delimiter">,</ <span class="Delimiter">}</span> <span class="Comment">//: Test.</span> -<span class="Delimiter">:(before "End is_special_name Cases")</span> +<span class="Delimiter">:(before "End is_special_name Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"__maybe_make_raw_test__"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Special Scenario Variable Names(r)")</span> <span class="Comment">//: ugly: we only need this for this one test, but need to define it for all time</span> @@ -431,7 +431,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Normal">void</span> check_type<span class="Delimiter">(</span><span class="Normal">const</span> string& lhs<span class="Delimiter">,</span> istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> reagent x<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> && is_mu_character<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> && is_mu_character<span class="Delimiter">(</span>array_element<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)))</span> <span class="Delimiter">{</span> x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">));</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> string _assign = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> @@ -455,7 +455,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span check_string<span class="Delimiter">(</span>address<span class="Delimiter">,</span> literal<span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// End Scenario Type Cases</span> + <span class="Comment">// End Scenario Type Special-cases</span> raise << <span class="Constant">"don't know how to check memory for '"</span> << lhs << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> diff --git a/html/053recipe_header.cc.html b/html/053recipe_header.cc.html index a922f9e2..11e83adc 100644 --- a/html/053recipe_header.cc.html +++ b/html/053recipe_header.cc.html @@ -360,13 +360,13 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="traceContains">+error: add2: replied with the wrong type at 'return z'</span> <span class="Delimiter">:(before "End Checks")</span> -Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_reply_instructions_against_header<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> +Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_return_instructions_against_header<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> check_reply_instructions_against_header<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> check_return_instructions_against_header<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">const</span> recipe& caller_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!caller_recipe<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">return</span><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">"--- checking reply instructions against header for "</span> << caller_recipe<span class="Delimiter">.</span>name << end<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">"--- checking return instructions against header for "</span> << caller_recipe<span class="Delimiter">.</span>name << end<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_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">const</span> instruction& inst = caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name != <span class="Constant">"reply"</span> && inst<span class="Delimiter">.</span>name != <span class="Constant">"return"</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> @@ -391,6 +391,16 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa ] <span class="traceContains">+error: add2: replied with the wrong number of products at 'return z'</span> +<span class="Delimiter">:(scenario recipe_headers_are_checked_against_transformed_instructions)</span> +<span class="Special">% Hide_errors = true;</span> +<span class="muRecipe">def</span> foo<span class="muRecipe"> -> </span>x:num [ + local-scope + <span class="Normal">x</span>:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Normal">z</span>:<span class="Normal">bool</span><span class="Special"> <- </span>copy <span class="Constant">0</span>/<span class="Constant">false</span> + <span class="Identifier">return</span>-<span class="Normal">if</span> z<span class="Delimiter">,</span> z +] +<span class="traceContains">+error: foo: replied with the wrong type at 'return-if z, z'</span> + <span class="Delimiter">:(scenario recipe_headers_check_for_duplicate_names)</span> <span class="Special">% Hide_errors = true;</span> <span class="muRecipe">def</span> add2 x:num<span class="Delimiter">,</span> x:num<span class="muRecipe"> -> </span>z:num [ @@ -411,7 +421,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa recipe& caller_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> caller_recipe<span class="Delimiter">.</span>ingredient_index<span class="Delimiter">.</span>clear<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">"--- checking reply instructions against header for "</span> << caller_recipe<span class="Delimiter">.</span>name << end<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">"--- checking return instructions against header for "</span> << caller_recipe<span class="Delimiter">.</span>name << end<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_recipe<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>contains_key<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>ingredient_index<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">))</span> raise << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">"' can't repeat in the ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> @@ -492,24 +502,24 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="traceContains">+mem: storing 8 in location 1</span> <span class="Delimiter">:(after "Transform.push_back(check_header_ingredients)")</span> -Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>fill_in_reply_ingredients<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> +Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>fill_in_return_ingredients<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> fill_in_reply_ingredients<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> fill_in_return_ingredients<span class="Delimiter">(</span><span class="Normal">const</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> <span class="Normal">if</span> <span class="Delimiter">(</span>!caller_recipe<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">return</span><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">"--- fill in reply ingredients from header for recipe "</span> << caller_recipe<span class="Delimiter">.</span>name << end<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">"--- fill in return ingredients from header for recipe "</span> << caller_recipe<span class="Delimiter">.</span>name << end<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_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<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>i<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"reply"</span> || inst<span class="Delimiter">.</span>name == <span class="Constant">"return"</span><span class="Delimiter">)</span> add_header_products<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Comment">// fall through reply</span> + <span class="Comment">// fall through return</span> <span class="Normal">if</span> <span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// error will be raised elsewhere if there's a product in the header; just give up</span> <span class="Normal">const</span> instruction& final_instruction = caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">)</span>-<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>final_instruction<span class="Delimiter">.</span>name != <span class="Constant">"reply"</span> && final_instruction<span class="Delimiter">.</span>name != <span class="Constant">"return"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction inst<span class="Delimiter">;</span> - inst<span class="Delimiter">.</span>name = <span class="Constant">"reply"</span><span class="Delimiter">;</span> + inst<span class="Delimiter">.</span>name = <span class="Constant">"return"</span><span class="Delimiter">;</span> add_header_products<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">);</span> caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>inst<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -531,7 +541,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(scenario explicit_reply_ignores_header)</span> +<span class="Delimiter">:(scenario explicit_return_ignores_header)</span> <span class="muRecipe">def</span> main [ <span class="Constant">1</span>:num/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:num/<span class="Special">raw <- </span>add2 <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">5</span> ] @@ -554,7 +564,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa load-ingredients z<span class="Special"> <- </span>add x<span class="Delimiter">,</span> y ] -<span class="traceContains">+transform: instruction: reply {z: "number"}</span> +<span class="traceContains">+transform: instruction: return {z: "number"}</span> <span class="traceContains">+mem: storing 8 in location 1</span> <span class="Delimiter">:(scenario return_on_fallthrough_already_exists)</span> @@ -568,10 +578,10 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Identifier">return</span> z ] <span class="traceContains">+transform: instruction: return {z: ()}</span> -<span class="traceAbsent">-transform: instruction: reply z:num</span> +<span class="traceAbsent">-transform: instruction: return z:num</span> <span class="traceContains">+mem: storing 8 in location 1</span> -<span class="Delimiter">:(scenario return_after_conditional_reply_based_on_header)</span> +<span class="Delimiter">:(scenario return_after_conditional_return_based_on_header)</span> <span class="muRecipe">def</span> main [ <span class="Constant">1</span>:num/<span class="Special">raw <- </span>add2 <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">5</span> ] diff --git a/html/054static_dispatch.cc.html b/html/054static_dispatch.cc.html index eee71984..476ddbb6 100644 --- a/html/054static_dispatch.cc.html +++ b/html/054static_dispatch.cc.html @@ -131,14 +131,17 @@ Literal_type_names<span class="Delimiter">.</span>insert<span class="Delimiter"> <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> - <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> - <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> + <span class="Normal">if</span> <span class="Delimiter">(</span>a<span class="Delimiter">-></span>atom != b<span class="Delimiter">-></span>atom<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>a<span class="Delimiter">-></span>atom<span class="Delimiter">)</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> && 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> + <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> + <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<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>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> diff --git a/html/055shape_shifting_container.cc.html b/html/055shape_shifting_container.cc.html index 8d8b3545..266fa3d9 100644 --- a/html/055shape_shifting_container.cc.html +++ b/html/055shape_shifting_container.cc.html @@ -13,18 +13,18 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 12pt; font-size: 1em; } -.muData { color: #ffff00; } -.Special { color: #c00000; } +.Constant { color: #00a0a0; } +.cSpecial { color: #008000; } .muRecipe { color: #ff8700; } -.traceContains { color: #008000; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Delimiter { color: #800080; } .SalientComment { color: #00ffff; } .Identifier { color: #c0a020; } .Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.muData { color: #ffff00; } .CommentedCode { color: #6c6c6c; } -.Constant { color: #00a0a0; } -.cSpecial { color: #008000; } +.traceContains { color: #008000; } --> </style> @@ -42,21 +42,46 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment">//: atomic types</span> <span class="Delimiter">:(before "End is_mu_container(type) Special-cases")</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_mu_container<span class="Delimiter">(</span>root_type<span class="Delimiter">(</span>type<span class="Delimiter">));</span> + <span class="Identifier">return</span> is_mu_container<span class="Delimiter">(</span>get_base_type<span class="Delimiter">(</span>type<span class="Delimiter">));</span> <span class="Delimiter">:(before "End is_mu_exclusive_container(type) Special-cases")</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_mu_exclusive_container<span class="Delimiter">(</span>root_type<span class="Delimiter">(</span>type<span class="Delimiter">));</span> -<span class="Comment">// a few calls to root_type() without the assertion (for better error handling)</span> + <span class="Identifier">return</span> is_mu_exclusive_container<span class="Delimiter">(</span>get_base_type<span class="Delimiter">(</span>type<span class="Delimiter">));</span> <span class="Delimiter">:(after "Update GET base_type in Check")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>!base_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> base_type = base_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> <span class="Delimiter">:(after "Update GET base_type in Run")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>!base_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> base_type = base_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> <span class="Delimiter">:(after "Update PUT base_type in Check")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>!base_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> base_type = base_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> <span class="Delimiter">:(after "Update PUT base_type in Run")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>!base_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> base_type = base_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> <span class="Delimiter">:(after "Update MAYBE_CONVERT base_type in Check")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>!base_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> base_type = base_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> +<span class="Delimiter">:(after "Update base_type in size_of(type)")</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> +<span class="Delimiter">:(after "Update base_type in element_type")</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> +<span class="Delimiter">:(after "Update base_type in compute_container_address_offsets")</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> +<span class="Delimiter">:(after "Update base_type in append_container_address_offsets")</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> +<span class="Delimiter">:(after "Update element_base_type For Exclusive Container in append_addresses")</span> +element_base_type = get_base_type<span class="Delimiter">(</span>element_base_type<span class="Delimiter">);</span> +<span class="Delimiter">:(after "Update base_type in skip_addresses")</span> +base_type = get_base_type<span class="Delimiter">(</span>base_type<span class="Delimiter">);</span> +<span class="Delimiter">:(replace{} "const type_tree* get_base_type(const type_tree* t)")</span> +<span class="Normal">const</span> type_tree* get_base_type<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* t<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> type_tree* result = t<span class="Delimiter">-></span>atom ? t : t<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!result<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> + raise << <span class="Constant">"invalid type "</span> << to_string<span class="Delimiter">(</span>t<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario ill_formed_container)</span> +<span class="Special">% Hide_errors = true;</span> +<span class="muRecipe">def</span> main [ + <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">((</span>foo<span class="Delimiter">)</span> num<span class="Delimiter">)}</span><span class="Special"> <- </span>copy <span class="Constant">0</span> +] +<span class="Comment"># no crash</span> <span class="Delimiter">:(scenario size_of_shape_shifting_container)</span> <span class="muData">container</span> foo:_t [ @@ -257,7 +282,7 @@ map<string<span class="Delimiter">,</span> type_ordinal> type_ingredient_n <span class="traceContains">+run: {6: ("foo" "point")} <- merge {1: "literal", "y": ()}, {23: "literal"}</span> <span class="traceContains">+mem: storing 1 in location 6</span> <span class="traceContains">+mem: storing 23 in location 7</span> -<span class="traceContains">+run: reply</span> +<span class="traceContains">+run: return</span> <span class="Comment"># no other stores</span> <span class="Special">% CHECK_EQ(trace_count_prefix("mem", "storing"), 7);</span> @@ -366,12 +391,41 @@ assert<span class="Delimiter">(</span>!contains_type_ingredient<span class="Deli <span class="Normal">if</span> <span class="Delimiter">(</span>!callsite_type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// error but it's already been raised above</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!element_type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!element_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>right == <span class="Constant">NULL</span> && is_type_ingredient<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>left<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Normal">int</span> type_ingredient_index = to_type_ingredient_index<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>left<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>corresponding<span class="Delimiter">(</span>callsite_type<span class="Delimiter">,</span> type_ingredient_index<span class="Delimiter">,</span> is_final_type_ingredient<span class="Delimiter">(</span>type_ingredient_index<span class="Delimiter">,</span> container_info<span class="Delimiter">))-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// replacing type ingredient at end of list, and replacement is a non-degenerate compound type -- (a b) but not (a)</span> + replace_type_ingredient_at<span class="Delimiter">(</span>type_ingredient_index<span class="Delimiter">,</span> element_type<span class="Delimiter">,</span> callsite_type<span class="Delimiter">,</span> container_info<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> replace_type_ingredients<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> callsite_type<span class="Delimiter">,</span> container_info<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> replace_type_ingredients<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> callsite_type<span class="Delimiter">,</span> container_info<span class="Delimiter">,</span> location_for_error_messages<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>element_type<span class="Delimiter">-></span>value < START_TYPE_INGREDIENTS<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Normal">const</span> <span class="Normal">int</span> type_ingredient_index = element_type<span class="Delimiter">-></span>value-START_TYPE_INGREDIENTS<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>is_type_ingredient<span class="Delimiter">(</span>element_type<span class="Delimiter">))</span> + replace_type_ingredient_at<span class="Delimiter">(</span>to_type_ingredient_index<span class="Delimiter">(</span>element_type<span class="Delimiter">),</span> element_type<span class="Delimiter">,</span> callsite_type<span class="Delimiter">,</span> container_info<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Normal">const</span> type_tree* corresponding<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">,</span> <span class="Normal">int</span> index<span class="Delimiter">,</span> <span class="Normal">bool</span> <span class="Normal">final</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">const</span> type_tree* curr = type<span class="Delimiter">;</span> curr<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">,</span> --index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert_for_now<span class="Delimiter">(</span>!curr<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>index == <span class="Constant">0</span><span class="Delimiter">)</span> + <span class="Identifier">return</span> <span class="Normal">final</span> ? curr : curr<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + assert_for_now<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Normal">bool</span> is_type_ingredient<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> type<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>value >= START_TYPE_INGREDIENTS<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Normal">int</span> to_type_ingredient_index<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + <span class="Identifier">return</span> type<span class="Delimiter">-></span>value-START_TYPE_INGREDIENTS<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Normal">void</span> replace_type_ingredient_at<span class="Delimiter">(</span><span class="Normal">const</span> <span class="Normal">int</span> type_ingredient_index<span class="Delimiter">,</span> type_tree* element_type<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree* callsite_type<span class="Delimiter">,</span> <span class="Normal">const</span> type_info& container_info<span class="Delimiter">,</span> <span class="Normal">const</span> string& location_for_error_messages<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_nth_type<span class="Delimiter">(</span>callsite_type<span class="Delimiter">,</span> type_ingredient_index<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << <span class="Constant">"illegal type "</span> << names_to_string<span class="Delimiter">(</span>callsite_type<span class="Delimiter">)</span> << <span class="Constant">" seems to be missing a type ingredient or three"</span> << location_for_error_messages << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> @@ -380,7 +434,7 @@ assert<span class="Delimiter">(</span>!contains_type_ingredient<span class="Deli <span class="Delimiter">}</span> <span class="Normal">const</span> type_tree* nth_type_ingredient<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* callsite_type<span class="Delimiter">,</span> <span class="Normal">int</span> type_ingredient_index<span class="Delimiter">,</span> <span class="Normal">const</span> type_info& container_info<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">bool</span> <span class="Normal">final</span> = final_type_ingredient<span class="Delimiter">(</span>type_ingredient_index<span class="Delimiter">,</span> container_info<span class="Delimiter">);</span> + <span class="Normal">bool</span> <span class="Normal">final</span> = is_final_type_ingredient<span class="Delimiter">(</span>type_ingredient_index<span class="Delimiter">,</span> container_info<span class="Delimiter">);</span> <span class="Normal">const</span> type_tree* curr = callsite_type<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 < type_ingredient_index<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> @@ -395,7 +449,7 @@ assert<span class="Delimiter">(</span>!contains_type_ingredient<span class="Deli <span class="Identifier">return</span> curr<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> final_type_ingredient<span class="Delimiter">(</span><span class="Normal">int</span> type_ingredient_index<span class="Delimiter">,</span> <span class="Normal">const</span> type_info& container_info<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">bool</span> is_final_type_ingredient<span class="Delimiter">(</span><span class="Normal">int</span> type_ingredient_index<span class="Delimiter">,</span> <span class="Normal">const</span> type_info& container_info<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> type_ordinal>::const_iterator p = container_info<span class="Delimiter">.</span>type_ingredient_names<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != container_info<span class="Delimiter">.</span>type_ingredient_names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -463,6 +517,15 @@ assert<span class="Delimiter">(</span>!contains_type_ingredient<span class="Deli CHECK_EQ<span class="Delimiter">(</span>to_string<span class="Delimiter">(</span>element2<span class="Delimiter">),</span> <span class="Constant">"{y: (</span><span class="cSpecial">\"</span><span class="Constant">address</span><span class="cSpecial">\"</span><span class="Constant"> </span><span class="cSpecial">\"</span><span class="Constant">array</span><span class="cSpecial">\"</span><span class="Constant"> </span><span class="cSpecial">\"</span><span class="Constant">character</span><span class="cSpecial">\"</span><span class="Constant">)}"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span class="Normal">void</span> test_replace_last_type_ingredient_inside_compound<span class="Delimiter">()</span> <span class="Delimiter">{</span> + run<span class="Delimiter">(</span><span class="Constant">"container foo:_a:_b [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" {x: (bar _a (address _b))}</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> + reagent callsite<span class="Delimiter">(</span><span class="Constant">"f:foo:number:array:character"</span><span class="Delimiter">);</span> + reagent element = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">.</span>type<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>names_to_string_without_quotes<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">),</span> <span class="Constant">"(bar number (address array character))"</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + <span class="Normal">void</span> test_replace_middle_type_ingredient_with_multiple<span class="Delimiter">()</span> <span class="Delimiter">{</span> run<span class="Delimiter">(</span><span class="Constant">"container foo:_a:_b:_c [</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Constant">" x:_a</span><span class="cSpecial">\n</span><span class="Constant">"</span> @@ -528,8 +591,8 @@ assert<span class="Delimiter">(</span>!contains_type_ingredient<span class="Deli <span class="Comment">//: offsets containing addresses for containers and exclusive containers --</span> <span class="Comment">//: that we need to teach about type ingredients.</span> -<span class="Delimiter">:(before "End compute_container_sizes Non-atom Cases")</span> -<span class="Normal">const</span> type_tree* root = root_type<span class="Delimiter">(</span>type<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End compute_container_sizes Non-atom Special-cases")</span> +<span class="Normal">const</span> type_tree* root = get_base_type<span class="Delimiter">(</span>type<span class="Delimiter">);</span> type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> compute_container_sizes<span class="Delimiter">(</span>info<span class="Delimiter">,</span> type<span class="Delimiter">,</span> pending_metadata<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> @@ -588,8 +651,8 @@ type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimi CHECK_EQ<span class="Delimiter">(</span>r2<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>size<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(before "End compute_container_address_offsets Non-atom Cases")</span> -<span class="Normal">const</span> type_tree* root = root_type<span class="Delimiter">(</span>type<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End compute_container_address_offsets Non-atom Special-cases")</span> +<span class="Normal">const</span> type_tree* root = get_base_type<span class="Delimiter">(</span>type<span class="Delimiter">);</span> type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> compute_container_address_offsets<span class="Delimiter">(</span>info<span class="Delimiter">,</span> type<span class="Delimiter">,</span> location_for_error_messages<span class="Delimiter">);</span> 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 [ diff --git a/html/057immutable.cc.html b/html/057immutable.cc.html index 5f8ad767..c31f5e20 100644 --- a/html/057immutable.cc.html +++ b/html/057immutable.cc.html @@ -14,16 +14,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 12pt; font-size: 1em; } .Constant { color: #00a0a0; } -.cSpecial { color: #008000; } +.traceContains { color: #008000; } .muRecipe { color: #ff8700; } .Todo { color: #000000; background-color: #ffff00; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #800080; } .Special { color: #c00000; } -.traceContains { color: #008000; } +.Identifier { color: #c0a020; } .Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .muData { color: #ffff00; } -.Identifier { color: #c0a020; } +.cSpecial { color: #008000; } --> </style> @@ -93,7 +93,7 @@ $error: <span class="Constant">0</span> load-ingredients <span class="Normal">x</span>:&:d1<span class="Special"> <- </span><span class="Normal">new</span> <span class="Constant">d1:type</span> *x<span class="Special"> <- </span>put *x<span class="Delimiter">,</span> <span class="Constant">p:offset</span><span class="Delimiter">,</span> <span class="Constant">34</span> <span class="Comment"># ignore this 'p'</span> - reply <span class="Constant">36</span> + <span class="Identifier">return</span> <span class="Constant">36</span> ] <span class="muData">container</span> d1 [ <span class="Normal">p</span>:num diff --git a/html/064list.mu.html b/html/064list.mu.html index 9ca8a1d7..95503149 100644 --- a/html/064list.mu.html +++ b/html/064list.mu.html @@ -47,7 +47,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> result:&:list:_elem <span class="Special"><-</span> new <span class="Delimiter">{</span>(list _elem): type<span class="Delimiter">}</span> *result <span class="Special"><-</span> merge x, l - <span class="muControl">reply</span> result + <span class="muControl">return</span> result ] <span class="muRecipe">def</span> first in:&:list:_elem<span class="muRecipe"> -> </span>result:_elem [ @@ -298,7 +298,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> reverse list:&:list:_elem temp:&:list:_elem/contained-in:result<span class="muRecipe"> -> </span>result:&:list:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">reply-unless</span> list, temp + <span class="muControl">return-unless</span> list, temp object:_elem <span class="Special"><-</span> first, list list <span class="Special"><-</span> rest list temp <span class="Special"><-</span> push object, temp diff --git a/html/068random.mu.html b/html/068random.mu.html index 05765f4e..ae1f7596 100644 --- a/html/068random.mu.html +++ b/html/068random.mu.html @@ -38,7 +38,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-if</span> generator <span class="Comment"># generator is 0? use real random-number generator</span> result <span class="Special"><-</span> real-random - <span class="muControl">reply</span> result, <span class="Constant">0/false</span> + <span class="muControl">return</span> result, <span class="Constant">0/false</span> <span class="Delimiter">}</span> result, fail?, generator <span class="Special"><-</span> read generator ] diff --git a/html/069hash.cc.html b/html/069hash.cc.html index 1e65b3f0..b58339af 100644 --- a/html/069hash.cc.html +++ b/html/069hash.cc.html @@ -126,7 +126,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">}</span> <span class="Normal">size_t</span> hash_mu_container<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> <span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)-></span>value<span class="Delimiter">);</span> + type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> get_base_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)-></span>value<span class="Delimiter">);</span> <span class="Normal">int</span> address = r<span class="Delimiter">.</span>value<span class="Delimiter">;</span> <span class="Normal">int</span> offset = <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>info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -141,7 +141,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">}</span> <span class="Normal">size_t</span> hash_mu_exclusive_container<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> <span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> type_tree* type = root_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* type = get_base_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Normal">int</span> tag = get<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">);</span> reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> variant = variant_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> tag<span class="Delimiter">);</span> diff --git a/html/071recipe.cc.html b/html/071recipe.cc.html index b5ac57d7..564275f2 100644 --- a/html/071recipe.cc.html +++ b/html/071recipe.cc.html @@ -241,7 +241,9 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">);</span> <span class="Identifier">return</span> result_header<span class="Delimiter">;</span> <span class="Delimiter">}</span> - assert<span class="Delimiter">(</span>root_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* root_type = r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom ? r<span class="Delimiter">.</span>type : r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>root_type<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>root_type<span class="Delimiter">-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">);</span> <span class="Normal">const</span> type_tree* curr = r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> curr && !curr<span class="Delimiter">-></span>atom<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && curr<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"->"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -296,7 +298,7 @@ reagent next_recipe_reagent<span class="Delimiter">(</span><span class="Normal"> <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> <span class="Identifier">return</span> reagent<span class="Delimiter">(</span><span class="Constant">"recipe:"</span>+curr<span class="Delimiter">-></span>name<span class="Delimiter">);</span> reagent result<span class="Delimiter">;</span> result<span class="Delimiter">.</span>name = <span class="Constant">"recipe"</span><span class="Delimiter">;</span> - result<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*curr<span class="Delimiter">-></span>left<span class="Delimiter">);</span> + result<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*curr<span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/072scheduler.cc.html b/html/072scheduler.cc.html index 33bf23c0..5681858c 100644 --- a/html/072scheduler.cc.html +++ b/html/072scheduler.cc.html @@ -361,7 +361,7 @@ increment_any_refcounts<span class="Delimiter">(</span>ingredient<span class="De <span class="Normal">n</span>:&:num/space:<span class="Constant">1</span><span class="Special"> <- </span>next-ingredient <span class="Comment"># should decrement refcount</span> *n/space:<span class="Constant">1</span><span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Normal">n2</span>:num<span class="Special"> <- </span>add *n/space:<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span> - reply n2 + <span class="Identifier">return</span> n2 ] <span class="muRecipe">def</span> main [ local-scope @@ -702,7 +702,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Constant">20</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span> ] <span class="Comment"># f2 runs an extra instruction for the implicit return added by the</span> -<span class="Comment"># fill_in_reply_ingredients transform</span> +<span class="Comment"># fill_in_return_ingredients transform</span> <span class="traceContains">+mem: storing 3 in location 11</span> <span class="Delimiter">:(scenario number_of_instructions_across_multiple_scheduling_intervals)</span> @@ -722,7 +722,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Constant">20</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span> ] <span class="Comment"># f2 runs an extra instruction for the implicit return added by the</span> -<span class="Comment"># fill_in_reply_ingredients transform</span> +<span class="Comment"># fill_in_return_ingredients transform</span> <span class="traceContains">+mem: storing 5 in location 11</span> <span class="SalientComment">//:: make sure that each routine gets a different alloc to start</span> diff --git a/html/073wait.cc.html b/html/073wait.cc.html index dc24c121..7f11c328 100644 --- a/html/073wait.cc.html +++ b/html/073wait.cc.html @@ -242,9 +242,9 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 in '"</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">const</span> type_tree* base_root_type = root_type<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* base_type = get_base_type<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Normal">int</span> offset = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>offset < <span class="Constant">0</span> || offset >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_root_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// copied from Check above</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>offset < <span class="Constant">0</span> || offset >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// copied from Check above</span> <span class="Normal">int</span> result = base_address<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 < offset<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> result += size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">,</span> i<span class="Delimiter">));</span> @@ -258,7 +258,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Normal">bool</span> is_mu_location<span class="Delimiter">(</span>reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>x<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>!x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<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>!x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"location"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> diff --git a/html/074deep_copy.cc.html b/html/074deep_copy.cc.html index a4bc1c10..7d6570dd 100644 --- a/html/074deep_copy.cc.html +++ b/html/074deep_copy.cc.html @@ -254,7 +254,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>deep_copy<span class="Delimiter">(</span>input<span class="Delimiter">,</span> tmp<span class="Delimiter">));</span> <span class="Comment">// reclaim Mu memory allocated for tmp</span> trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"deep-copy: reclaiming temporary"</span> << end<span class="Delimiter">();</span> - abandon<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>value<span class="Delimiter">,</span> tmp<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> payload_size<span class="Delimiter">(</span>tmp<span class="Delimiter">));</span> + abandon<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>value<span class="Delimiter">,</span> payload_type<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>type<span class="Delimiter">),</span> payload_size<span class="Delimiter">(</span>tmp<span class="Delimiter">));</span> <span class="Comment">// reclaim host memory allocated for tmp.type when tmp goes out of scope</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -319,7 +319,10 @@ vector<<span class="Normal">double</span>> deep_copy<span class="Delimiter <span class="Comment">// construct a fake reagent that reads directly from the appropriate</span> <span class="Comment">// field of the container</span> reagent curr<span class="Delimiter">;</span> - curr<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Constant">"address"</span><span class="Delimiter">),</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*info<span class="Delimiter">-></span>payload_type<span class="Delimiter">));</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">-></span>payload_type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> + curr<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Constant">"address"</span><span class="Delimiter">),</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Normal">new</span> type_tree<span class="Delimiter">(</span>info<span class="Delimiter">-></span>payload_type<span class="Delimiter">-></span>name<span class="Delimiter">),</span> <span class="Constant">NULL</span><span class="Delimiter">));</span> + <span class="Normal">else</span> + curr<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Constant">"address"</span><span class="Delimiter">),</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*info<span class="Delimiter">-></span>payload_type<span class="Delimiter">));</span> curr<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>canonized_in<span class="Delimiter">.</span>value + info<span class="Delimiter">-></span>offset<span class="Delimiter">);</span> curr<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span><span class="Constant">"raw"</span><span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span> trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"deep-copy: copying address "</span> << curr<span class="Delimiter">.</span>value << end<span class="Delimiter">();</span> diff --git a/html/081print.mu.html b/html/081print.mu.html index 5214e80c..be2e0b60 100644 --- a/html/081print.mu.html +++ b/html/081print.mu.html @@ -642,7 +642,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> hide-cursor screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">reply-if</span> screen <span class="Comment"># fake screen; do nothing</span> + <span class="muControl">return-if</span> screen <span class="Comment"># fake screen; do nothing</span> <span class="Comment"># real screen</span> hide-cursor-on-display ] @@ -650,7 +650,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> show-cursor screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">reply-if</span> screen <span class="Comment"># fake screen; do nothing</span> + <span class="muControl">return-if</span> screen <span class="Comment"># fake screen; do nothing</span> <span class="Comment"># real screen</span> show-cursor-on-display ] @@ -658,7 +658,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> hide-screen screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">reply-if</span> screen <span class="Comment"># fake screen; do nothing</span> + <span class="muControl">return-if</span> screen <span class="Comment"># fake screen; do nothing</span> <span class="Comment"># real screen</span> hide-display ] @@ -666,7 +666,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> show-screen screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">reply-if</span> screen <span class="Comment"># fake screen; do nothing</span> + <span class="muControl">return-if</span> screen <span class="Comment"># fake screen; do nothing</span> <span class="Comment"># real screen</span> show-display ] diff --git a/html/082scenario_screen.cc.html b/html/082scenario_screen.cc.html index 222c01a0..f0ab81bc 100644 --- a/html/082scenario_screen.cc.html +++ b/html/082scenario_screen.cc.html @@ -189,7 +189,7 @@ assert<span class="Delimiter">(</span>Next_predefined_global_for_scenarios < <span class="Delimiter">:(before "End Special Scenario Variable Names(r)")</span> Name[r][<span class="Constant">"screen"</span>] = SCREEN<span class="Delimiter">;</span> <span class="Comment">//: make 'screen' always a raw location in scenarios</span> -<span class="Delimiter">:(before "End is_special_name Cases")</span> +<span class="Delimiter">:(before "End is_special_name Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"screen"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Rewrite Instruction(curr, recipe result)")</span> diff --git a/html/085scenario_console.cc.html b/html/085scenario_console.cc.html index 406135c9..d8b50408 100644 --- a/html/085scenario_console.cc.html +++ b/html/085scenario_console.cc.html @@ -73,7 +73,7 @@ recipes_taking_literal_strings<span class="Delimiter">.</span>insert<span class= <span class="Delimiter">:(before "End Special Scenario Variable Names(r)")</span> Name[r][<span class="Constant">"console"</span>] = CONSOLE<span class="Delimiter">;</span> <span class="Comment">//: make 'console' always a raw location in scenarios</span> -<span class="Delimiter">:(before "End is_special_name Cases")</span> +<span class="Delimiter">:(before "End is_special_name Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"console"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> diff --git a/html/088file.mu.html b/html/088file.mu.html index 46d9363a..db45a81e 100644 --- a/html/088file.mu.html +++ b/html/088file.mu.html @@ -119,7 +119,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-unless</span> resources <span class="Comment"># fake file system</span> routine-id <span class="Special"><-</span> start-running transmit-to-fake-file resources, filename, source - <span class="muControl">reply</span> + <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># real file system</span> file:num <span class="Special"><-</span> $open-file-for-writing filename @@ -169,7 +169,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">loop-unless</span> found? put-index *data, i, new-resource reset lock - <span class="muControl">reply</span> + <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># if file didn't already exist, make room for it</span> new-len:num <span class="Special"><-</span> add len,<span class="Constant"> 1</span> diff --git a/html/089scenario_filesystem.cc.html b/html/089scenario_filesystem.cc.html index 608f9c25..d0cc5e17 100644 --- a/html/089scenario_filesystem.cc.html +++ b/html/089scenario_filesystem.cc.html @@ -110,7 +110,7 @@ de f <span class="Delimiter">:(before "End Special Scenario Variable Names(r)")</span> Name[r][<span class="Constant">"resources"</span>] = RESOURCES<span class="Delimiter">;</span> <span class="Comment">//: make 'resources' always a raw location in scenarios</span> -<span class="Delimiter">:(before "End is_special_name Cases")</span> +<span class="Delimiter">:(before "End is_special_name Special-cases")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"resources"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Initialize Type Of Special Name In Scenario(r)")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>name == <span class="Constant">"resources"</span><span class="Delimiter">)</span> r<span class="Delimiter">.</span>type = new_type_tree<span class="Delimiter">(</span><span class="Constant">"address:resources"</span><span class="Delimiter">);</span> diff --git a/html/092socket.mu.html b/html/092socket.mu.html index e3c179eb..f33fb8bd 100644 --- a/html/092socket.mu.html +++ b/html/092socket.mu.html @@ -60,7 +60,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> example-handler query:text<span class="muRecipe"> -> </span>response:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">reply</span> <span class="Constant">[abc]</span> + <span class="muControl">return</span> <span class="Constant">[abc]</span> ] <span class="Comment"># To test client operations, use `assume-resources` with a filename that</span> diff --git a/html/edit/006-sandbox-copy.mu.html b/html/edit/006-sandbox-copy.mu.html index 0ae24c18..3459f1f2 100644 --- a/html/edit/006-sandbox-copy.mu.html +++ b/html/edit/006-sandbox-copy.mu.html @@ -180,7 +180,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Comment"># are we below the sandbox editor?</span> click-sandbox-area?:bool <span class="Special"><-</span> click-on-sandbox-area? click-row, click-column, env - <span class="muControl">reply-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> + <span class="muControl">return-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> <span class="Comment"># narrower, is the click in the columns spanning the 'copy' button?</span> first-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> assert first-sandbox, <span class="Constant">[!!]</span> @@ -188,7 +188,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color sandbox-right-margin:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">right:offset</span> _, _, copy-button-left:num, copy-button-right:num, _ <span class="Special"><-</span> sandbox-menu-columns sandbox-left-margin, sandbox-right-margin copy-button-vertical-area?:bool <span class="Special"><-</span> within-range? click-column, copy-button-left, copy-button-right - <span class="muControl">reply-unless</span> copy-button-vertical-area?, <span class="Constant">0/false</span> + <span class="muControl">return-unless</span> copy-button-vertical-area?, <span class="Constant">0/false</span> <span class="Comment"># finally, is sandbox editor empty?</span> current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> result <span class="Special"><-</span> empty-editor? current-sandbox diff --git a/html/edit/007-sandbox-delete.mu.html b/html/edit/007-sandbox-delete.mu.html index 5fbf7441..48028d51 100644 --- a/html/edit/007-sandbox-delete.mu.html +++ b/html/edit/007-sandbox-delete.mu.html @@ -118,7 +118,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Comment"># are we below the sandbox editor?</span> click-sandbox-area?:bool <span class="Special"><-</span> click-on-sandbox-area? click-row, click-column, env - <span class="muControl">reply-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> + <span class="muControl">return-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> <span class="Comment"># narrower, is the click in the columns spanning the 'copy' button?</span> first-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> assert first-sandbox, <span class="Constant">[!!]</span> diff --git a/html/edit/008-sandbox-edit.mu.html b/html/edit/008-sandbox-edit.mu.html index 43481161..97ca51e3 100644 --- a/html/edit/008-sandbox-edit.mu.html +++ b/html/edit/008-sandbox-edit.mu.html @@ -175,7 +175,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Comment"># are we below the sandbox editor?</span> click-sandbox-area?:bool <span class="Special"><-</span> click-on-sandbox-area? click-row, click-column, env - <span class="muControl">reply-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> + <span class="muControl">return-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> <span class="Comment"># narrower, is the click in the columns spanning the 'edit' button?</span> first-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> assert first-sandbox, <span class="Constant">[!!]</span> @@ -183,7 +183,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color sandbox-right-margin:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">right:offset</span> edit-button-left:num, edit-button-right:num, _ <span class="Special"><-</span> sandbox-menu-columns sandbox-left-margin, sandbox-right-margin edit-button-vertical-area?:bool <span class="Special"><-</span> within-range? click-column, edit-button-left, edit-button-right - <span class="muControl">reply-unless</span> edit-button-vertical-area?, <span class="Constant">0/false</span> + <span class="muControl">return-unless</span> edit-button-vertical-area?, <span class="Constant">0/false</span> <span class="Comment"># finally, is sandbox editor empty?</span> current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> result <span class="Special"><-</span> empty-editor? current-sandbox diff --git a/html/lambda-to-mu.mu.html b/html/lambda-to-mu.mu.html index b4d44558..7e6f9010 100644 --- a/html/lambda-to-mu.mu.html +++ b/html/lambda-to-mu.mu.html @@ -86,14 +86,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> is-atom? x:&:cell<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">reply-unless</span> x, <span class="Constant">0/false</span> + <span class="muControl">return-unless</span> x, <span class="Constant">0/false</span> _, result <span class="Special"><-</span> maybe-convert *x, <span class="Constant">atom:variant</span> ] <span class="muRecipe">def</span> is-pair? x:&:cell<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">reply-unless</span> x, <span class="Constant">0/false</span> + <span class="muControl">return-unless</span> x, <span class="Constant">0/false</span> _, result <span class="Special"><-</span> maybe-convert *x, <span class="Constant">pair:variant</span> ] @@ -127,7 +127,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> s:text, is-atom?:bool <span class="Special"><-</span> maybe-convert *x, <span class="Constant">atom:variant</span> - <span class="muControl">reply-unless</span> is-atom?, <span class="Constant">0/false</span> + <span class="muControl">return-unless</span> is-atom?, <span class="Constant">0/false</span> result <span class="Special"><-</span> equal pat, s ] @@ -144,7 +144,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> pair:pair, pair?:bool <span class="Special"><-</span> maybe-convert *x, <span class="Constant">pair:variant</span> - <span class="muControl">reply-unless</span> pair?, <span class="Constant">0/nil</span> + <span class="muControl">return-unless</span> pair?, <span class="Constant">0/nil</span> result <span class="Special"><-</span> get pair, <span class="Constant">first:offset</span> ] @@ -152,7 +152,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> pair:pair, pair?:bool <span class="Special"><-</span> maybe-convert *x, <span class="Constant">pair:variant</span> - <span class="muControl">reply-unless</span> pair?, <span class="Constant">0/nil</span> + <span class="muControl">return-unless</span> pair?, <span class="Constant">0/nil</span> result <span class="Special"><-</span> get pair, <span class="Constant">rest:offset</span> ] @@ -160,7 +160,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> pair:pair, is-pair?:bool <span class="Special"><-</span> maybe-convert *base, <span class="Constant">pair:variant</span> - <span class="muControl">reply-unless</span> is-pair? + <span class="muControl">return-unless</span> is-pair? pair <span class="Special"><-</span> put pair, <span class="Constant">first:offset</span>, new-first *base <span class="Special"><-</span> merge <span class="Constant">1/pair</span>, pair ] @@ -169,7 +169,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> pair:pair, is-pair?:bool <span class="Special"><-</span> maybe-convert *base, <span class="Constant">pair:variant</span> - <span class="muControl">reply-unless</span> is-pair? + <span class="muControl">return-unless</span> is-pair? pair <span class="Special"><-</span> put pair, <span class="Constant">rest:offset</span>, new-rest *base <span class="Special"><-</span> merge <span class="Constant">1/pair</span>, pair ] @@ -217,7 +217,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># skip whitespace</span> in <span class="Special"><-</span> skip-whitespace in c:char, eof?:bool <span class="Special"><-</span> peek in - <span class="muControl">reply-if</span> eof?, <span class="Constant">0/nil</span> + <span class="muControl">return-if</span> eof?, <span class="Constant">0/nil</span> pair?:bool <span class="Special"><-</span> equal c, <span class="Constant">40/open-paren</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> pair? @@ -306,7 +306,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> done?:bool <span class="Special"><-</span> end-of-stream? in - <span class="muControl">reply-if</span> done?, <span class="Constant">0/null</span> + <span class="muControl">return-if</span> done?, <span class="Constant">0/null</span> c:char <span class="Special"><-</span> peek in space?:bool <span class="Special"><-</span> space? c <span class="muControl">break-unless</span> space? @@ -330,14 +330,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="muControl">break-if</span> x buf <span class="Special"><-</span> append buf, <span class="Constant">[<>]</span> - <span class="muControl">reply</span> + <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># base case: atom</span> <span class="Delimiter">{</span> s:text, atom?:bool <span class="Special"><-</span> maybe-convert *x, <span class="Constant">atom:variant</span> <span class="muControl">break-unless</span> atom? buf <span class="Special"><-</span> append buf, s - <span class="muControl">reply</span> + <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># recursive case: pair</span> buf <span class="Special"><-</span> append buf, <span class="Constant">[< ]</span> diff --git a/html/nqueens.mu.html b/html/nqueens.mu.html index 022bb1bc..efddcc92 100644 --- a/html/nqueens.mu.html +++ b/html/nqueens.mu.html @@ -82,9 +82,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> result1:bool <span class="Special"><-</span> conflicting-file? curr, queens - <span class="muControl">reply-if</span> result1, result1 + <span class="muControl">return-if</span> result1, result1 result2:bool <span class="Special"><-</span> conflicting-diagonal? curr, queens - <span class="muControl">reply</span> result2 + <span class="muControl">return</span> result2 ] <span class="muRecipe">def</span> conflicting-file? curr:square, queens:&:list:square<span class="muRecipe"> -> </span>result:bool [ @@ -96,11 +96,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color q:square <span class="Special"><-</span> first queens qfile:num <span class="Special"><-</span> get q, <span class="Constant">file:offset</span> file-match?:bool <span class="Special"><-</span> equal curr-file, qfile - <span class="muControl">reply-if</span> file-match?, <span class="Constant">1/conflict-found</span> + <span class="muControl">return-if</span> file-match?, <span class="Constant">1/conflict-found</span> queens <span class="Special"><-</span> rest queens <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> <span class="Constant">0/no-conflict-found</span> + <span class="muControl">return</span> <span class="Constant">0/no-conflict-found</span> ] <span class="muRecipe">def</span> conflicting-diagonal? curr:square, queens:&:list:square<span class="muRecipe"> -> </span>result:bool [ @@ -118,11 +118,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color rank-delta <span class="Special"><-</span> abs rank-delta file-delta <span class="Special"><-</span> abs file-delta diagonal-match?:bool <span class="Special"><-</span> equal rank-delta, file-delta - <span class="muControl">reply-if</span> diagonal-match?, <span class="Constant">1/conflict-found</span> + <span class="muControl">return-if</span> diagonal-match?, <span class="Constant">1/conflict-found</span> queens <span class="Special"><-</span> rest queens <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> <span class="Constant">0/no-conflict-found</span> + <span class="muControl">return</span> <span class="Constant">0/no-conflict-found</span> ] <span class="muRecipe">def</span> main [ |