diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-09-10 10:43:19 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-09-10 10:43:19 -0700 |
commit | 44c1aeef226542d692f0002b5cca5a3c30935d18 (patch) | |
tree | 46452902ff779d93e4adcb57cda29d923766a5be /html/033exclusive_container.cc.html | |
parent | c7db6a160a9a43d0905d5dea44e742b47acfa42f (diff) | |
download | mu-44c1aeef226542d692f0002b5cca5a3c30935d18.tar.gz |
3315
Diffstat (limited to 'html/033exclusive_container.cc.html')
-rw-r--r-- | html/033exclusive_container.cc.html | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/html/033exclusive_container.cc.html b/html/033exclusive_container.cc.html index 9b31c886..5068a365 100644 --- a/html/033exclusive_container.cc.html +++ b/html/033exclusive_container.cc.html @@ -70,22 +70,27 @@ def main [ <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 Cases")</span> +<span class="Delimiter">:(before "End compute_container_sizes Atom 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> - container_metadata metadata<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> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(code)</span> +<span class="Normal">void</span> compute_exclusive_container_sizes<span class="Delimiter">(</span><span class="Normal">const</span> type_info& exclusive_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="Delimiter">{</span> <span class="Comment">// size of an exclusive container is the size of its largest variant</span> - <span class="Comment">// (So like containers, it can't contain arrays.)</span> - <span class="Normal">int</span> size = <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> - 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>i<span class="Delimiter">);</span> - <span class="Comment">// Compute Exclusive Container Size(element)</span> + <span class="Comment">// (So, like containers, it can only contain arrays if they're static and</span> + <span class="Comment">// include their length in the type.)</span> + container_metadata metadata<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>exclusive_container_info<span class="Delimiter">.</span>elements<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> element = exclusive_container_info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + <span class="Comment">// Compute Exclusive Container Size(element, full_type)</span> compute_container_sizes<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">,</span> pending_metadata<span class="Delimiter">);</span> <span class="Normal">int</span> variant_size = size_of<span class="Delimiter">(</span>element<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>variant_size > size<span class="Delimiter">)</span> size = variant_size<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>variant_size > metadata<span class="Delimiter">.</span>size<span class="Delimiter">)</span> metadata<span class="Delimiter">.</span>size = variant_size<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// ...+1 for its tag.</span> - metadata<span class="Delimiter">.</span>size = size+<span class="Constant">1</span><span class="Delimiter">;</span> - 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>*type<span class="Delimiter">),</span> metadata<span class="Delimiter">));</span> + ++metadata<span class="Delimiter">.</span>size<span class="Delimiter">;</span> + 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="SalientComment">//:: To access variants of an exclusive container, use 'maybe-convert'.</span> @@ -135,7 +140,12 @@ 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> base = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// Update MAYBE_CONVERT base in Check</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!base<span class="Delimiter">.</span>type || !base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value || get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>kind != EXCLUSIVE_CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!base<span class="Delimiter">.</span>type<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">"first ingredient of 'maybe-convert' should be an exclusive-container, but got '"</span> << base<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="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Normal">const</span> type_tree* root_type = base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom ? base<span class="Delimiter">.</span>type : base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!root_type<span class="Delimiter">-></span>atom || root_type<span class="Delimiter">-></span>value == <span class="Constant">0</span> || !contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">-></span>value<span class="Delimiter">)</span> || get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>kind != EXCLUSIVE_CONTAINER<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">"first ingredient of 'maybe-convert' should be an exclusive-container, but got '"</span> << base<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="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -152,7 +162,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Comment">// Update MAYBE_CONVERT product in Check</span> reagent& offset = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> populate_value<span class="Delimiter">(</span>offset<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>offset<span class="Delimiter">.</span>value >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base<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">if</span> <span class="Delimiter">(</span>offset<span class="Delimiter">.</span>value >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>elements<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">"invalid tag "</span> << offset<span class="Delimiter">.</span>value << <span class="Constant">" in '"</span> << inst<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -211,9 +221,10 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Normal">const</span> reagent variant_type<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">,</span> <span class="Normal">int</span> tag<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>tag >= <span class="Constant">0</span><span class="Delimiter">);</span> - assert<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> - assert<span class="Delimiter">(</span>!get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> 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> type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + <span class="Normal">const</span> type_tree* root_type = type<span class="Delimiter">-></span>atom ? type : type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_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> root_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> root_type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == EXCLUSIVE_CONTAINER<span class="Delimiter">);</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>tag<span class="Delimiter">);</span> <span class="Comment">// End variant_type Special-cases</span> @@ -465,7 +476,9 @@ $error: <span class="Constant">0</span> && current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>type<span class="Delimiter">)</span> <span class="Delimiter">{</span> reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> x = current_instruction<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 size_mismatch Check for MERGE(x)</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>kind == EXCLUSIVE_CONTAINER<span class="Delimiter">)</span> + <span class="Normal">const</span> type_tree* root_type = x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom ? x<span class="Delimiter">.</span>type : x<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> + <span class="Normal">if</span> <span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>kind == EXCLUSIVE_CONTAINER<span class="Delimiter">)</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> |