diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-14 16:04:45 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-14 16:04:45 -0700 |
commit | 65361948ca7975553757a0e0df4ac7352413044c (patch) | |
tree | 22063c089f67cb0d82623f2edc2c16b7e4389d41 /html/041name.cc.html | |
parent | 64586540eccbc0880341782d329b419ab9d002de (diff) | |
download | mu-65361948ca7975553757a0e0df4ac7352413044c.tar.gz |
1376 - update github docs
Diffstat (limited to 'html/041name.cc.html')
-rw-r--r-- | html/041name.cc.html | 197 |
1 files changed, 127 insertions, 70 deletions
diff --git a/html/041name.cc.html b/html/041name.cc.html index 6734c604..18fbd523 100644 --- a/html/041name.cc.html +++ b/html/041name.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 041name.cc</title> +<title>~/Desktop/s/mu/041name.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,15 +14,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } -.Identifier { color: #008080; } -.SalientComment { color: #00ffff; } +.CommentedCode { color: #6c6c6c; } +.traceAbsent { color: #c00000; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } -.CommentedCode { color: #6c6c6c; } +.Identifier { color: #008080; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } -.traceAbsent { color: #c00000; } --> </style> @@ -40,7 +40,7 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario convert_names)</span> recipe main [ - x:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + x:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+name: assign x 1</span> <span class="traceContains">+run: instruction main/0</span> @@ -49,7 +49,7 @@ recipe main [ <span class="Delimiter">:(scenario convert_names_warns)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - x:integer<span class="Special"> <- </span>copy y:integer + x:number<span class="Special"> <- </span>copy y:number ] <span class="traceContains">+warn: use before set: y in main</span> @@ -60,62 +60,57 @@ recipe main [ map<recipe_number<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> index_t> > Name<span class="Delimiter">;</span> <span class="Delimiter">:(after "Clear Other State For recently_added_recipes")</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < recently_added_recipes<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - Name<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>recently_added_recipes[i]<span class="Delimiter">);</span> + Name<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>recently_added_recipes<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> void transform_names<span class="Delimiter">(</span>const recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</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> index_t>& names = Name[r]<span class="Delimiter">;</span> <span class="Comment">// store the indices 'used' so far in the map</span> index_t& 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> -<span class="CommentedCode">//? cout << "Recipe " << r << ": " << Recipe[r].name << '\n'; //? 3</span> -<span class="CommentedCode">//? cout << Recipe[r].steps.size() << '\n'; //? 2</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "instruction " << i << '\n'; //? 2</span> - instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps[i]<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> <span class="Comment">// map names to addresses</span> for <span class="Delimiter">(</span>index_t in = <span class="Constant">0</span><span class="Delimiter">;</span> in < inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++in<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "ingredients\n"; //? 2</span> - if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span class="CommentedCode">//? cout << "ingredient " << inst.ingredients[in].name << '\n'; //? 3</span> -<span class="CommentedCode">//? cout << "ingredient " << inst.ingredients[in].to_string() << '\n'; //? 1</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> - inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<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="cSpecial">'\n'</span><span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>types[<span class="Constant">0</span>] <span class="Comment">// not a literal</span> - && !inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>initialized - && !is_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!already_transformed<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[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[in]<span class="Delimiter">.</span>name << <span class="Constant">" in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>lookup_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">,</span> r<span class="Delimiter">));</span> -<span class="CommentedCode">//? cout << "lookup ingredient " << Recipe[r].name << "/" << i << ": " << inst.ingredients[in].to_string() << '\n'; //? 1</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> <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><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>index_t out = <span class="Constant">0</span><span class="Delimiter">;</span> out < inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++out<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "products\n"; //? 1</span> - if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span class="CommentedCode">//? cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 4</span> -<span class="CommentedCode">//? cout << inst.products[out].types[0] << '\n'; //? 1</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> - inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>types[<span class="Constant">0</span>] <span class="Comment">// not a literal</span> - && !inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>initialized - && !is_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>name<span class="Delimiter">))</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[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[out]<span class="Delimiter">.</span>name << <span class="Constant">" "</span> << curr_idx<span class="Delimiter">;</span> - names[inst<span class="Delimiter">.</span>products[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[out]<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>lookup_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">,</span> r<span class="Delimiter">));</span> -<span class="CommentedCode">//? cout << "lookup product " << Recipe[r].name << "/" << i << ": " << inst.products[out].to_string() << '\n'; //? 1</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> <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<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> + inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>lookup_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">),</span> r<span class="Delimiter">));</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><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> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + raise << <span class="Constant">"missing type in "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<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> + if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_number<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <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> + if <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> bool already_transformed<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> index_t>& names<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -128,7 +123,7 @@ index_t lookup_name<span class="Delimiter">(</span>const reagent& r<span cla type_number skip_addresses<span class="Delimiter">(</span>const vector<type_number>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < types<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>types[i] != Type_number[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Identifier">return</span> types[i]<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_number[<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> <span class="Delimiter">}</span> raise << <span class="Constant">"expected a container"</span> << <span class="cSpecial">'\n'</span> << die<span class="Delimiter">();</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> @@ -138,23 +133,48 @@ int find_element_name<span class="Delimiter">(</span>const type_number t<span cl const type_info& container = Type[t]<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << "looking for element " << name << " in type " << container.name << " with " << container.element_names.size() << " elements\n"; //? 1</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < container<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>size<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[i] == name<span class="Delimiter">)</span> <span class="Identifier">return</span> i<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> << t << <span class="cSpecial">'\n'</span> << die<span class="Delimiter">();</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> +bool is_numeric_location<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</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">false</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// used for chaining lexical scopes</span> + <span class="Identifier">return</span> is_number<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +bool is_named_location<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</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">false</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_special_name<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> !is_number<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>index_t 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 < r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties[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> + 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> + <span class="Comment">// lexical scopes</span> + if <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> + 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> + <span class="Comment">// tests will use these in later layers even though tests will mostly use numeric addresses</span> + if <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> + if <span class="Delimiter">(</span>s == <span class="Constant">"keyboard"</span><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> + <span class="Delimiter">:(scenario convert_names_passes_dummy)</span> <span class="Comment"># _ is just a dummy result that never gets consumed</span> recipe main [ - _<span class="Delimiter">,</span> x:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + _<span class="Delimiter">,</span> x:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] <span class="traceContains">+name: assign x 1</span> <span class="traceAbsent">-name: assign _ 1</span> @@ -162,7 +182,7 @@ recipe main [ <span class="Comment">//: one reserved word that we'll need later</span> <span class="Delimiter">:(scenario convert_names_passes_default_space)</span> recipe main [ - default-space:integer<span class="Delimiter">,</span> x:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + default-space:number<span class="Delimiter">,</span> x:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] <span class="traceContains">+name: assign x 1</span> <span class="traceAbsent">-name: assign default-space 1</span> @@ -170,10 +190,46 @@ recipe main [ <span class="Comment">//: an escape hatch to suppress name conversion that we'll use later</span> <span class="Delimiter">:(scenario convert_names_passes_raw)</span> recipe main [ - x:integer/<span class="Special">raw <- </span>copy <span class="Constant">0</span>:literal + x:number/<span class="Special">raw <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceAbsent">-name: assign x 1</span> +<span class="Delimiter">:(scenario convert_names_warns_when_mixing_names_and_numeric_locations)</span> +<span class="Special">% Hide_warnings = 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="Delimiter">:(scenario convert_names_warns_when_mixing_names_and_numeric_locations2)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <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="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_names_and_raw_locations)</span> +<span class="Special">% Hide_warnings = 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> + +<span class="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_names_and_literals)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal +] +<span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</span> + +<span class="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_special_names_and_numeric_locations)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + screen:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number +] +<span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</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> @@ -182,8 +238,9 @@ Type[point]<span class="Delimiter">.</span>element_names<span class="Delimiter"> 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> <span class="Delimiter">:(scenario convert_names_transforms_container_elements)</span> recipe main [ - a:integer<span class="Special"> <- </span>get <span class="Constant">0</span>:point<span class="Delimiter">,</span> y:offset - b:integer<span class="Special"> <- </span>get <span class="Constant">0</span>:point<span class="Delimiter">,</span> x:offset + p:address:point<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Comment"># unsafe</span> + a:number<span class="Special"> <- </span>get p:address:point/deref<span class="Delimiter">,</span> y:offset + b:number<span class="Special"> <- </span>get p:address:point/deref<span class="Delimiter">,</span> x:offset ] <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> @@ -194,13 +251,13 @@ if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"get-address"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// at least 2 args, and second arg is offset</span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> >= <span class="Constant">2</span><span class="Delimiter">);</span> -<span class="CommentedCode">//? cout << inst.ingredients[1].to_string() << '\n'; //? 1</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<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="Identifier">continue</span><span class="Delimiter">;</span> +<span class="CommentedCode">//? cout << inst.ingredients.at(1).to_string() << '\n'; //? 1</span> + assert<span class="Delimiter">(</span>isa_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="Identifier">continue</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_number base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>types<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients[<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="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="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="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + type_number 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<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: this test is actually illegal so can't call run</span> @@ -208,7 +265,7 @@ if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation <span class="Delimiter">:(scenario convert_names_handles_containers)</span> recipe main [ a:point<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - b:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + b:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+name: assign a 1</span> <span class="traceContains">+name: assign b 3</span> @@ -218,12 +275,12 @@ recipe main [ <span class="Delimiter">:(scenarios run)</span> <span class="Delimiter">:(scenario maybe_convert_named)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal - <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:integer-or-point<span class="Delimiter">,</span> p:variant + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point<span class="Delimiter">,</span> p:variant ] -<span class="traceContains">+name: variant p of type integer-or-point has tag 1</span> +<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> @@ -231,12 +288,12 @@ recipe main [ if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"maybe-convert"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// at least 2 args, and second arg is offset</span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> >= <span class="Constant">2</span><span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<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="Identifier">continue</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_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="Identifier">continue</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_number base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>types<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients[<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="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="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="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + type_number 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<span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> </body> |