diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-29 14:18:52 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-29 14:18:52 -0800 |
commit | db1f56c8449d2ea3d158753fe37bac5a750a2566 (patch) | |
tree | 508a24c522c040498dbe7d60036035f3c4ae440a /html/030container.cc.html | |
parent | 3670fb87f6d38c9ba4fcbb1eaa6439b4007a194e (diff) | |
download | mu-db1f56c8449d2ea3d158753fe37bac5a750a2566.tar.gz |
2611
Diffstat (limited to 'html/030container.cc.html')
-rw-r--r-- | html/030container.cc.html | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/html/030container.cc.html b/html/030container.cc.html index 403c6a60..8ef0dda6 100644 --- a/html/030container.cc.html +++ b/html/030container.cc.html @@ -16,7 +16,6 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } .traceContains { color: #008000; } .SalientComment { color: #00ffff; } .cSpecial { color: #008000; } -.traceAbsent { color: #c00000; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } @@ -191,11 +190,12 @@ case GET: <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">"invalid offset "</span> << offset_value << <span class="Constant">" for "</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<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> + 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> <span class="Comment">// Update GET product in Check</span> const reagent element = element_type<span class="Delimiter">(</span>base<span class="Delimiter">,</span> offset_value<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>product<span class="Delimiter">,</span> element<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">"'get' "</span> << offset<span class="Delimiter">.</span>original_string << <span class="Constant">" ("</span> << offset_value << <span class="Constant">") on "</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>name << <span class="Constant">" can't be saved in "</span> << product<span class="Delimiter">.</span>original_string << <span class="Constant">"; type should be "</span> << debug_string<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" but is "</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> + if <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_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">"'get "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">", "</span> << offset<span class="Delimiter">.</span>original_string << <span class="Constant">"' should write to "</span> << debug_string<span class="Delimiter">(</span>element<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> @@ -275,7 +275,17 @@ recipe main [ <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> <span class="Constant">15</span>:address:number<span class="Special"> <- </span>get <span class="Constant">12</span>:point-number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] -<span class="traceContains">+error: main: 'get' 1:offset (1) on point-number can't be saved in 15:address:number; type should be number but is <address : <number : <>>></span> +<span class="traceContains">+error: main: 'get 12:point-number/raw, 1:offset' should write to number but 15 has type <address : <number : <>>></span> + +<span class="Comment">//: we might want to call 'get' without saving the results, say in a sandbox</span> + +<span class="Delimiter">:(scenario get_without_product)</span> +recipe main [ + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + get <span class="Constant">12</span>:point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:offset <span class="Comment"># unsafe</span> +] +<span class="Comment"># just don't die</span> <span class="SalientComment">//:: To write to elements of containers, you need their address.</span> @@ -326,8 +336,8 @@ case GET_ADDRESS: <span class="Delimiter">{</span> reagent element = element_type<span class="Delimiter">(</span>base<span class="Delimiter">,</span> offset_value<span class="Delimiter">);</span> <span class="Comment">// ..except for an address at the start</span> element<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> element<span class="Delimiter">.</span>type<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>product<span class="Delimiter">,</span> element<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">"'get-address' "</span> << offset<span class="Delimiter">.</span>original_string << <span class="Constant">" ("</span> << offset_value << <span class="Constant">") on "</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>name << <span class="Constant">" can't be saved in "</span> << product<span class="Delimiter">.</span>original_string << <span class="Constant">"; type should be "</span> << debug_string<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <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_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">"'get-address "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">", "</span> << offset<span class="Delimiter">.</span>original_string << <span class="Constant">"' should write to "</span> << debug_string<span class="Delimiter">(</span>element<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> @@ -377,13 +387,16 @@ recipe main [ <span class="Delimiter">:(scenario get_address_product_type_mismatch)</span> <span class="Special">% Hide_errors = true;</span> +container boolbool [ + x:boolean + y:boolean +] recipe main [ - <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</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">15</span>:number<span class="Special"> <- </span>get-address <span class="Constant">12</span>:point-number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">12</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">13</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">15</span>:boolean<span class="Special"> <- </span>get-address <span class="Constant">12</span>:boolbool<span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] -<span class="traceContains">+error: main: 'get-address' 1:offset (1) on point-number can't be saved in 15:number; type should be <address : <number : <>>></span> +<span class="traceContains">+error: main: 'get-address 12:boolbool, 1:offset' should write to <address : <boolean : <>>> but 15 has type boolean</span> <span class="SalientComment">//:: Allow containers to be defined in mu code.</span> @@ -439,7 +452,7 @@ void insert_container<span class="Delimiter">(</span>const string& command<s recently_added_types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> name<span class="Delimiter">));</span> info<span class="Delimiter">.</span>name = name<span class="Delimiter">;</span> info<span class="Delimiter">.</span>kind = kind<span class="Delimiter">;</span> - while <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> string element = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>element == <span class="Constant">"]"</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -448,7 +461,7 @@ void insert_container<span class="Delimiter">(</span>const string& command<s info<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>slurp_until<span class="Delimiter">(</span>inner<span class="Delimiter">,</span> <span class="Constant">':'</span><span class="Delimiter">));</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">" element name: "</span> << info<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>back<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> type_tree* new_type = <span class="Constant">NULL</span><span class="Delimiter">;</span> - for <span class="Delimiter">(</span>type_tree** curr_type = &new_type<span class="Delimiter">;</span> !inner<span class="Delimiter">.</span>eof<span class="Delimiter">();</span> curr_type = &<span class="Delimiter">(</span>*curr_type<span class="Delimiter">)-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>type_tree** curr_type = &new_type<span class="Delimiter">;</span> has_data<span class="Delimiter">(</span>inner<span class="Delimiter">);</span> curr_type = &<span class="Delimiter">(</span>*curr_type<span class="Delimiter">)-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> string type_name = slurp_until<span class="Delimiter">(</span>inner<span class="Delimiter">,</span> <span class="Constant">':'</span><span class="Delimiter">);</span> <span class="Comment">// End insert_container Special Uses(type_name)</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">)</span> @@ -535,22 +548,23 @@ recipe main [ <span class="Comment"># integer is not a type</span> <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span> ] -<span class="traceContains">+error: main: unknown type in '1:integer <- copy 0'</span> +<span class="traceContains">+error: main: unknown type integer in '1:integer <- copy 0'</span> <span class="Delimiter">:(scenario run_allows_type_definition_after_use)</span> <span class="Special">% Hide_errors = true;</span> recipe main [ - <span class="Constant">1</span>:bar<span class="Special"> <- </span>copy <span class="Constant">0</span>/<span class="Special">raw</span> + <span class="Constant">1</span>:bar<span class="Special"> <- </span>copy <span class="Constant">0</span>/unsafe ] container bar [ x:number ] -<span class="traceAbsent">-error: unknown type: bar</span> $error: <span class="Constant">0</span> -<span class="Delimiter">:(after "Begin Transforms")</span> +<span class="Delimiter">:(after "Begin Instruction Modifying Transforms")</span> +<span class="Comment">// Begin Type Modifying Transforms</span> Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_or_set_invalid_types<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> +<span class="Comment">// End Type Modifying Transforms</span> <span class="Delimiter">:(code)</span> void check_or_set_invalid_types<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -578,8 +592,10 @@ void check_or_set_invalid_types<span class="Delimiter">(</span>type_tree* type<s if <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="Delimiter">{</span> if <span class="Delimiter">(</span>type_name && contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">-></span>value<span class="Delimiter">))</span> type<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + else if <span class="Delimiter">(</span>type_name<span class="Delimiter">)</span> + raise_error << block << <span class="Constant">"unknown type "</span> << type_name<span class="Delimiter">-></span>value << <span class="Constant">" in "</span> << name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> else - raise_error << block << <span class="Constant">"unknown type in "</span> << name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << block << <span class="Constant">"missing type in "</span> << name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> check_or_set_invalid_types<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> type_name ? type_name<span class="Delimiter">-></span>left : <span class="Constant">NULL</span><span class="Delimiter">,</span> block<span class="Delimiter">,</span> name<span class="Delimiter">);</span> check_or_set_invalid_types<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> type_name ? type_name<span class="Delimiter">-></span>right : <span class="Constant">NULL</span><span class="Delimiter">,</span> block<span class="Delimiter">,</span> name<span class="Delimiter">);</span> |