diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-01-26 23:47:23 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-01-26 23:47:23 -0800 |
commit | d009e158803956c76adbf8f58a62884c3e7affb3 (patch) | |
tree | b88198e28d15cd1fc064f5300365a190decc4c50 /html/033exclusive_container.cc.html | |
parent | 2da43c9462c7b7c1bb78d2f2826b3b97b4874973 (diff) | |
download | mu-d009e158803956c76adbf8f58a62884c3e7affb3.tar.gz |
2605
Diffstat (limited to 'html/033exclusive_container.cc.html')
-rw-r--r-- | html/033exclusive_container.cc.html | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/html/033exclusive_container.cc.html b/html/033exclusive_container.cc.html index a4fc191a..f3e258c8 100644 --- a/html/033exclusive_container.cc.html +++ b/html/033exclusive_container.cc.html @@ -60,7 +60,7 @@ recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Comment"># 'point' variant</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> - <span class="Constant">4</span>:number-or-point<span class="Special"> <- </span>copy <span class="Constant">1</span>:number-or-point/<span class="Special">raw</span> <span class="Comment"># unsafe</span> + <span class="Constant">4</span>:number-or-point<span class="Special"> <- </span>copy <span class="Constant">1</span>:number-or-point/unsafe ] <span class="traceContains">+mem: storing 1 in location 4</span> <span class="traceContains">+mem: storing 34 in location 5</span> @@ -94,7 +94,7 @@ recipe main [ <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> - <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:variant <span class="Comment"># unsafe</span> + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/unsafe<span class="Delimiter">,</span> <span class="Constant">1</span>:variant ] <span class="traceContains">+mem: storing 13 in location 20</span> @@ -103,7 +103,7 @@ recipe main [ <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> - <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span>:variant <span class="Comment"># unsafe</span> + <span class="Constant">20</span>:address:number<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/unsafe<span class="Delimiter">,</span> <span class="Constant">0</span>:variant ] <span class="traceContains">+mem: storing 0 in location 20</span> @@ -113,18 +113,36 @@ MAYBE_CONVERT<span class="Delimiter">,</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"maybe-convert"</span><span class="Delimiter">,</span> MAYBE_CONVERT<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case MAYBE_CONVERT: <span class="Delimiter">{</span> + const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << 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">"'maybe-convert' expects exactly 2 ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'maybe-convert' expects exactly 2 ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<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 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> canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">);</span> if <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> - raise_error << 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">"first ingredient of 'maybe-convert' should be an exclusive-container, but got "</span> << base<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << 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="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</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> <span class="Delimiter">{</span> - raise_error << 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">"second ingredient of 'maybe-convert' should have type 'variant', but got "</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="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"second ingredient of 'maybe-convert' should have type 'variant', but got "</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="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <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 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> + if <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + const 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> + long long int tag = <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + tag = to_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + tag = offset<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + reagent variant = variant_type<span class="Delimiter">(</span>base<span class="Delimiter">,</span> tag<span class="Delimiter">);</span> + variant<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">),</span> variant<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>product<span class="Delimiter">,</span> variant<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'maybe-convert "</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 write to "</span> << debug_string<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" but "</span> << product<span class="Delimiter">.</span>name << <span class="Constant">" has type "</span> << debug_string<span class="Delimiter">(</span>product<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <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="Identifier">break</span><span class="Delimiter">;</span> @@ -151,6 +169,30 @@ case MAYBE_CONVERT: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> +<span class="Delimiter">:(code)</span> +const reagent variant_type<span class="Delimiter">(</span>const reagent& canonized_base<span class="Delimiter">,</span> long long int 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> canonized_base<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> canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + const type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> canonized_base<span class="Delimiter">.</span>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 element<span class="Delimiter">;</span> + element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*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> + <span class="Identifier">return</span> element<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario maybe_convert_product_type_mismatch)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> + <span class="Constant">20</span>:address:number<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/unsafe<span class="Delimiter">,</span> <span class="Constant">1</span>:variant +] +<span class="traceContains">+error: main: 'maybe-convert 12:number-or-point/unsafe, 1:variant' should write to <address : <point : <>>> but 20 has type <address : <number : <>>></span> + + <span class="SalientComment">//:: Allow exclusive containers to be defined in mu code.</span> <span class="Delimiter">:(scenario exclusive_container)</span> |