diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-10 21:35:42 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-10 21:43:45 -0800 |
commit | 76755b2836b0dadd88f82635f661f9d9df77604d (patch) | |
tree | f4f4429510c739fd1f9e51edd10e03c27107acba /html/042name.cc.html | |
parent | 080e9cb73fa55cdc862f1dd7593df56e0a6302b8 (diff) | |
download | mu-76755b2836b0dadd88f82635f661f9d9df77604d.tar.gz |
2423 - describe shape-shifting in html docs
Diffstat (limited to 'html/042name.cc.html')
-rw-r--r-- | html/042name.cc.html | 135 |
1 files changed, 66 insertions, 69 deletions
diff --git a/html/042name.cc.html b/html/042name.cc.html index 16cf8117..da006079 100644 --- a/html/042name.cc.html +++ b/html/042name.cc.html @@ -13,15 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } +.traceContains { color: #008000; } .traceAbsent { color: #c00000; } +.Identifier { color: #804000; } +.cSpecial { color: #008000; } .Constant { color: #00a0a0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } -.Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } --> </style> @@ -45,15 +46,16 @@ recipe main [ <span class="traceContains">+mem: storing 0 in location 1</span> <span class="Delimiter">:(scenarios transform)</span> -<span class="Delimiter">:(scenario transform_names_warns)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Delimiter">:(scenario transform_names_fails_on_use_before_define)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ x:number<span class="Special"> <- </span>copy y:number ] -<span class="traceContains">+warn: use before set: y in main</span> +<span class="traceContains">+error: main: use before set: y</span> +<span class="Comment"># todo: detect conditional defines</span> -<span class="Delimiter">:(after "int main")</span> - Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_names<span class="Delimiter">);</span> +<span class="Delimiter">:(after "Transform.push_back(check_or_set_invalid_types")</span> <span class="Comment">// there'll be other transforms relating to types; they all need to happen first</span> +Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_names<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> <span class="Delimiter">:(before "End Globals")</span> map<recipe_ordinal<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> long long int> > Name<span class="Delimiter">;</span> @@ -64,31 +66,33 @@ for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</ <span class="Delimiter">:(code)</span> void transform_names<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</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">"--- transform names for recipe "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << end<span class="Delimiter">();</span> +<span class="CommentedCode">//? cerr << "--- transform names for recipe " << get(Recipe, r).name << '\n';</span> bool names_used = <span class="Constant">false</span><span class="Delimiter">;</span> bool numeric_locations_used = <span class="Constant">false</span><span class="Delimiter">;</span> map<string<span class="Delimiter">,</span> long long int>& names = Name[r]<span class="Delimiter">;</span> <span class="Comment">// store the indices 'used' so far in the map</span> long long int& curr_idx = names[<span class="Constant">""</span>]<span class="Delimiter">;</span> ++curr_idx<span class="Delimiter">;</span> <span class="Comment">// avoid using index 0, benign skip in some other cases</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - <span class="Comment">// Per-recipe Transforms</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + instruction& inst = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + <span class="Comment">// End transform_names(inst) Special-cases</span> <span class="Comment">// map names to addresses</span> for <span class="Delimiter">(</span>long long int in = <span class="Constant">0</span><span class="Delimiter">;</span> in < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++in<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>is_numeric_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">)))</span> numeric_locations_used = <span class="Constant">true</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>is_named_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">)))</span> names_used = <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> inst<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> inst<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="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>!already_transformed<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> names<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"use before set: "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">).</span>name << <span class="Constant">" in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<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">"use before set: "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">).</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>lookup_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> r<span class="Delimiter">));</span> <span class="Delimiter">}</span> for <span class="Delimiter">(</span>long long int out = <span class="Constant">0</span><span class="Delimiter">;</span> out < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++out<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>is_numeric_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">)))</span> numeric_locations_used = <span class="Constant">true</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>is_named_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">)))</span> names_used = <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">),</span> inst<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">),</span> inst<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="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name<span class="Delimiter">)</span> == names<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"assign "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name << <span class="Constant">" "</span> << curr_idx << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"assign "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name << <span class="Constant">" "</span> << curr_idx << end<span class="Delimiter">();</span> names[inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name] = curr_idx<span class="Delimiter">;</span> curr_idx += size_of<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">));</span> <span class="Delimiter">}</span> @@ -96,12 +100,12 @@ void transform_names<span class="Delimiter">(</span>const recipe_ordinal r<span <span class="Delimiter">}</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>names_used && numeric_locations_used<span class="Delimiter">)</span> - raise << <span class="Constant">"mixing variable names and numeric addresses in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<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">"mixing variable names and numeric addresses</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> -bool disqualified<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">mutable</span><span class="Comment">*/</span> reagent& x<span class="Delimiter">,</span> const instruction& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"missing type 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> +bool disqualified<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">mutable</span><span class="Comment">*/</span> reagent& x<span class="Delimiter">,</span> const instruction& inst<span class="Delimiter">,</span> const string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>recipe_name<span class="Delimiter">)</span> << <span class="Constant">"missing type for "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" 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">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <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> @@ -113,27 +117,28 @@ bool disqualified<span class="Delimiter">(</span><span class="Comment">/*</span> <span class="Delimiter">}</span> bool already_transformed<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> long long int>& names<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">)</span> != names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> + <span class="Identifier">return</span> contains_key<span class="Delimiter">(</span>names<span class="Delimiter">,</span> r<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> long long int lookup_name<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const recipe_ordinal default_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> Name[default_recipe][r<span class="Delimiter">.</span>name]<span class="Delimiter">;</span> <span class="Delimiter">}</span> -type_ordinal skip_addresses<span class="Delimiter">(</span>const vector<type_ordinal>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>types<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Identifier">return</span> types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +type_ordinal skip_addresses<span class="Delimiter">(</span>type_tree* type<span class="Delimiter">,</span> const string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(;</span> type<span class="Delimiter">;</span> type = type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>type<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> type<span class="Delimiter">-></span>value<span class="Delimiter">;</span> <span class="Delimiter">}</span> - raise << <span class="Constant">"expected a container"</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>recipe_name<span class="Delimiter">)</span> << <span class="Constant">"expected a container"</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -int find_element_name<span class="Delimiter">(</span>const type_ordinal t<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const type_info& container = Type[t]<span class="Delimiter">;</span> +int find_element_name<span class="Delimiter">(</span>const type_ordinal t<span class="Delimiter">,</span> const string& name<span class="Delimiter">,</span> const string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const type_info& container = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> t<span class="Delimiter">);</span> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>container<span class="Delimiter">.</span>element_names<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>container<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == name<span class="Delimiter">)</span> <span class="Identifier">return</span> i<span class="Delimiter">;</span> <span class="Delimiter">}</span> - raise << <span class="Constant">"unknown element "</span> << name << <span class="Constant">" in container "</span> << Type[t]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>recipe_name<span class="Delimiter">)</span> << <span class="Constant">"unknown element "</span> << name << <span class="Constant">" in container "</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> t<span class="Delimiter">).</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -151,13 +156,6 @@ bool is_named_location<span class="Delimiter">(</span>const reagent& x<span <span class="Identifier">return</span> !is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> -bool is_raw<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int i = <span class="Comment">/*</span><span class="Comment">skip value+type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"raw"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><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> - bool is_special_name<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <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> if <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> @@ -176,51 +174,51 @@ recipe main [ <span class="Comment">//: an escape hatch to suppress name conversion that we'll use later</span> <span class="Delimiter">:(scenarios run)</span> <span class="Delimiter">:(scenario transform_names_passes_raw)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ x:number/<span class="Special">raw <- </span>copy <span class="Constant">0</span> ] <span class="traceAbsent">-name: assign x 1</span> -<span class="traceContains">+warn: can't write to location 0 in 'x:number/raw <- copy 0'</span> +<span class="traceContains">+error: can't write to location 0 in 'x:number/raw <- copy 0'</span> <span class="Delimiter">:(scenarios transform)</span> -<span class="Delimiter">:(scenario transform_names_warns_when_mixing_names_and_numeric_locations)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Delimiter">:(scenario transform_names_fails_when_mixing_names_and_numeric_locations)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] -<span class="traceContains">+warn: mixing variable names and numeric addresses in main</span> +<span class="traceContains">+error: main: mixing variable names and numeric addresses</span> -<span class="Delimiter">:(scenario transform_names_warns_when_mixing_names_and_numeric_locations_2)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Delimiter">:(scenario transform_names_fails_when_mixing_names_and_numeric_locations_2)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ x:number<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Constant">1</span>:number<span class="Special"> <- </span>copy x:number ] -<span class="traceContains">+warn: mixing variable names and numeric addresses in main</span> +<span class="traceContains">+error: main: mixing variable names and numeric addresses</span> -<span class="Delimiter">:(scenario transform_names_does_not_warn_when_mixing_names_and_raw_locations)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Delimiter">:(scenario transform_names_does_not_fail_when_mixing_names_and_raw_locations)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number/<span class="Special">raw</span> ] -<span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</span> -$warn: <span class="Constant">0</span> +<span class="traceAbsent">-error: main: mixing variable names and numeric addresses</span> +$error: <span class="Constant">0</span> -<span class="Delimiter">:(scenario transform_names_does_not_warn_when_mixing_names_and_literals)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Delimiter">:(scenario transform_names_does_not_fail_when_mixing_names_and_literals)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ x:number<span class="Special"> <- </span>copy <span class="Constant">1</span> ] -<span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</span> -$warn: <span class="Constant">0</span> +<span class="traceAbsent">-error: main: mixing variable names and numeric addresses</span> +$error: <span class="Constant">0</span> <span class="SalientComment">//:: Support element names for containers in 'get' and 'get-address'.</span> <span class="Comment">//: update our running example container for the next test</span> <span class="Delimiter">:(before "End Mu Types Initialization")</span> -Type[point]<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"x"</span><span class="Delimiter">);</span> -Type[point]<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"y"</span><span class="Delimiter">);</span> +get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point<span class="Delimiter">).</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"x"</span><span class="Delimiter">);</span> +get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point<span class="Delimiter">).</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"y"</span><span class="Delimiter">);</span> <span class="Delimiter">:(scenario transform_names_transforms_container_elements)</span> recipe main [ p:address:point<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># unsafe</span> @@ -230,21 +228,20 @@ recipe main [ <span class="traceContains">+name: element y of type point is at offset 1</span> <span class="traceContains">+name: element x of type point is at offset 0</span> -<span class="Delimiter">:(after "Per-recipe Transforms")</span> +<span class="Delimiter">:(before "End transform_names(inst) Special-cases")</span> <span class="Comment">// replace element names of containers with offsets</span> -if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"get"</span>] - || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"get-address"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"get"</span> || inst<span class="Delimiter">.</span>name == <span class="Constant">"get-address"</span><span class="Delimiter">)</span> <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 << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": exactly 2 ingredients expected 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>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"exactly 2 ingredients expected 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> 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> - raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": expected ingredient 1 of "</span> << <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"get"</span>] ? <span class="Constant">"'get'"</span> : <span class="Constant">"'get-address'"</span><span class="Delimiter">)</span> << <span class="Constant">" to have type 'offset'; 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>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"expected ingredient 1 of "</span> << <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"get"</span> ? <span class="Constant">"'get'"</span> : <span class="Constant">"'get-address'"</span><span class="Delimiter">)</span> << <span class="Constant">" to have type 'offset'; 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> if <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>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// since first non-address in base type must be a container, we don't have to canonize</span> - type_ordinal base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>types<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>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<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>name<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"element "</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>name << <span class="Constant">" of type "</span> << Type[base_type]<span class="Delimiter">.</span>name << <span class="Constant">" is at offset "</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>value << end<span class="Delimiter">();</span> + type_ordinal base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>type<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<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>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<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>name<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">));</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"element "</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>name << <span class="Constant">" of type "</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>name << <span class="Constant">" is at offset "</span> << no_scientific<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>value<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -252,8 +249,8 @@ if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation <span class="Delimiter">:(scenarios transform)</span> <span class="Delimiter">:(scenario transform_names_handles_containers)</span> recipe main [ - a:point<span class="Special"> <- </span>copy <span class="Constant">0</span> - b:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + a:point<span class="Special"> <- </span>copy <span class="Constant">0</span>/<span class="Special">raw</span> + b:number<span class="Special"> <- </span>copy <span class="Constant">0</span>/<span class="Special">raw</span> ] <span class="traceContains">+name: assign a 1</span> <span class="traceContains">+name: assign b 3</span> @@ -271,19 +268,19 @@ recipe main [ <span class="traceContains">+name: variant p of type number-or-point has tag 1</span> <span class="traceContains">+mem: storing 13 in location 20</span> -<span class="Delimiter">:(after "Per-recipe Transforms")</span> +<span class="Delimiter">:(before "End transform_names(inst) Special-cases")</span> <span class="Comment">// convert variant names of exclusive containers</span> -if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"maybe-convert"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"maybe-convert"</span><span class="Delimiter">)</span> <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 << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": exactly 2 ingredients expected in '"</span> << current_instruction<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>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"exactly 2 ingredients expected 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> assert<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> if <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>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// since first non-address in base type must be an exclusive container, we don't have to canonize</span> - type_ordinal base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>types<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>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<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>name<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"variant "</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>name << <span class="Constant">" of type "</span> << Type[base_type]<span class="Delimiter">.</span>name << <span class="Constant">" has tag "</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>value << end<span class="Delimiter">();</span> + type_ordinal base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>type<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<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>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<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>name<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">));</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"variant "</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>name << <span class="Constant">" of type "</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>name << <span class="Constant">" has tag "</span> << no_scientific<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>value<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> </pre> |