diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-02-25 17:17:20 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-02-25 17:17:20 -0800 |
commit | dcc060c7d4ef56b978beb34ddce8d8ffcec94fa6 (patch) | |
tree | 7cbb9cd1d8544c7c6c65725fa195ca3821b04b07 | |
parent | 0f5a2f4e21046e319ce0fadec32cc5e89d2f4620 (diff) | |
download | mu-dcc060c7d4ef56b978beb34ddce8d8ffcec94fa6.tar.gz |
2706 - update html
60 files changed, 3050 insertions, 1173 deletions
diff --git a/html/001help.cc.html b/html/001help.cc.html index eaa49b8b..83a6c5fd 100644 --- a/html/001help.cc.html +++ b/html/001help.cc.html @@ -167,6 +167,7 @@ using std::iostream<span class="Delimiter">;</span> using std::cin<span class="Delimiter">;</span> using std::cout<span class="Delimiter">;</span> using std::cerr<span class="Delimiter">;</span> +<span class="PreProc">#include</span><span class="Constant"><iomanip></span> <span class="PreProc">#include</span><span class="Constant"><cstring></span> <span class="PreProc">#include</span><span class="Constant"><string></span> diff --git a/html/002test.cc.html b/html/002test.cc.html index e93a5c73..50e2baff 100644 --- a/html/002test.cc.html +++ b/html/002test.cc.html @@ -110,14 +110,15 @@ void run_test<span class="Delimiter">(</span>size_t i<span class="Delimiter">)</ setup<span class="Delimiter">();</span> <span class="Comment">// End Test Setup</span> <span class="Delimiter">(</span>*Tests[i]<span class="Delimiter">)();</span> + <span class="Comment">// End Test Teardown</span> teardown<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">"."</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> bool is_integer<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-"</span><span class="Delimiter">)</span> == string::npos - && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'-'</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">)</span> == string::npos - && s<span class="Delimiter">.</span>find_first_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">;</span> + <span class="Identifier">return</span> s<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="Comment">// no other characters</span> + && s<span class="Delimiter">.</span>find_first_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos <span class="Comment">// at least one digit</span> + && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'-'</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">;</span> <span class="Comment">// '-' only at first position</span> <span class="Delimiter">}</span> long long int to_integer<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> diff --git a/html/003trace.cc.html b/html/003trace.cc.html index c19044fb..a835d7ab 100644 --- a/html/003trace.cc.html +++ b/html/003trace.cc.html @@ -123,15 +123,12 @@ struct trace_line <span class="Delimiter">{</span> <span class="Delimiter">:(before "End Globals")</span> const int Max_depth = <span class="Constant">9999</span><span class="Delimiter">;</span> -const int Error_depth = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// definitely always print the error that caused death</span> -const int Warning_depth = <span class="Constant">1</span><span class="Delimiter">;</span> +const int Error_depth = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// definitely always print errors</span> const int App_depth = <span class="Constant">2</span><span class="Delimiter">;</span> <span class="Comment">// temporarily where all mu code will trace to</span> <span class="Delimiter">:(before "End Tracing")</span> bool Hide_errors = <span class="Constant">false</span><span class="Delimiter">;</span> -bool Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Hide_errors = <span class="Constant">false</span><span class="Delimiter">;</span> -Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Tracing")</span> struct trace_stream <span class="Delimiter">{</span> @@ -166,16 +163,14 @@ struct trace_stream <span class="Delimiter">{</span> past_lines<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>trace_line<span class="Delimiter">(</span>curr_depth<span class="Delimiter">,</span> trim<span class="Delimiter">(</span>curr_label<span class="Delimiter">),</span> curr_contents<span class="Delimiter">));</span> <span class="Comment">// preserve indent in contents</span> if <span class="Delimiter">(</span>!Hide_errors && curr_label == <span class="Constant">"error"</span><span class="Delimiter">)</span> cerr << curr_label << <span class="Constant">": "</span> << curr_contents << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - else if <span class="Delimiter">(</span>!Hide_warnings && curr_label == <span class="Constant">"warn"</span><span class="Delimiter">)</span> - cerr << curr_label << <span class="Constant">": "</span> << curr_contents << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> delete curr_stream<span class="Delimiter">;</span> curr_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> curr_label<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> curr_depth = Max_depth<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// Useful for debugging.</span> - string readable_contents<span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// missing label = everything</span> + <span class="Comment">// useful for debugging</span> + string readable_contents<span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// empty label = show everything</span> ostringstream output<span class="Delimiter">;</span> label = trim<span class="Delimiter">(</span>label<span class="Delimiter">);</span> for <span class="Delimiter">(</span>vector<trace_line>::iterator p = past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> @@ -190,10 +185,18 @@ struct trace_stream <span class="Delimiter">{</span> trace_stream* Trace_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> -<span class="Comment">// Top-level helper. IMPORTANT: can't nest.</span> +<span class="Comment">// Top-level helper. IMPORTANT: can't nest</span> <span class="PreProc">#define trace(</span><span class="Delimiter">...</span><span class="PreProc">) !Trace_stream ? cerr </span><span class="Comment">/*</span><span class="Comment">print nothing</span><span class="Comment">*/</span><span class="PreProc"> : Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">stream(__VA_ARGS__)</span> -<span class="PreProc">#define raise (!Trace_stream ? (tb_shutdown()</span><span class="Delimiter">,</span><span class="PreProc">cerr) </span><span class="Comment">/*</span><span class="Comment">do print</span><span class="Comment">*/</span><span class="PreProc"> : Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">stream(Warning_depth</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">"warn"</span><span class="PreProc">))</span> + +<span class="Comment">// Errors are a special layer.</span> <span class="PreProc">#define raise_error (!Trace_stream ? (tb_shutdown()</span><span class="Delimiter">,</span><span class="PreProc">cerr) </span><span class="Comment">/*</span><span class="Comment">do print</span><span class="Comment">*/</span><span class="PreProc"> : Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">stream(Error_depth</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">"error"</span><span class="PreProc">))</span> +<span class="Comment">// Inside tests, fail any tests that displayed (unexpected) errors.</span> +<span class="Comment">// Expected errors in tests should always be hidden and silently checked for.</span> +<span class="Delimiter">:(before "End Test Teardown")</span> +if <span class="Delimiter">(</span>Passed && !Hide_errors && trace_count<span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">)</span> > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + Passed = <span class="Constant">false</span><span class="Delimiter">;</span> + ++Num_failures<span class="Delimiter">;</span> +<span class="Delimiter">}</span> <span class="Delimiter">:(before "End Types")</span> struct end <span class="Delimiter">{};</span> @@ -284,6 +287,7 @@ int trace_count<span class="Delimiter">(</span>string label<span class="Delimite <span class="Delimiter">}</span> int trace_count<span class="Delimiter">(</span>string label<span class="Delimiter">,</span> string line<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> long result = <span class="Constant">0</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>label == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -375,14 +379,6 @@ using std::map<span class="Delimiter">;</span> using std::set<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant"><algorithm></span> -<span class="PreProc">#include</span><span class="Constant"><iostream></span> -using std::istream<span class="Delimiter">;</span> -using std::ostream<span class="Delimiter">;</span> -using std::cin<span class="Delimiter">;</span> -using std::cout<span class="Delimiter">;</span> -using std::cerr<span class="Delimiter">;</span> -<span class="PreProc">#include</span><span class="Constant"><iomanip></span> - <span class="PreProc">#include</span><span class="Constant"><sstream></span> using std::istringstream<span class="Delimiter">;</span> using std::ostringstream<span class="Delimiter">;</span> @@ -399,8 +395,7 @@ using std::ofstream<span class="Delimiter">;</span> <span class="Comment">//: In future layers we'll use the depth field as follows:</span> <span class="Comment">//:</span> <span class="Comment">//: Errors will be depth 0.</span> -<span class="Comment">//: Warnings will be depth 1.</span> -<span class="Comment">//: Mu 'applications' will be able to use depths 2-100 as they like.</span> +<span class="Comment">//: Mu 'applications' will be able to use depths 1-100 as they like.</span> <span class="Comment">//: Primitive statements will occupy 101-9989</span> const int Initial_callstack_depth = <span class="Constant">101</span><span class="Delimiter">;</span> const int Max_callstack_depth = <span class="Constant">9989</span><span class="Delimiter">;</span> diff --git a/html/010vm.cc.html b/html/010vm.cc.html index 3b090c34..e8b04eb5 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -14,7 +14,6 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } -.CommentedCode { color: #6c6c6c; } .PreProc { color: #c000c0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } @@ -55,7 +54,6 @@ struct recipe <span class="Delimiter">{</span> vector<instruction> steps<span class="Delimiter">;</span> <span class="Comment">// End recipe Fields</span> recipe<span class="Delimiter">();</span> - string to_string<span class="Delimiter">()</span> const<span class="Delimiter">;</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "struct recipe")</span> @@ -76,8 +74,7 @@ struct instruction <span class="Delimiter">{</span> <span class="Comment">// End instruction Fields</span> instruction<span class="Delimiter">();</span> void clear<span class="Delimiter">();</span> - bool is_clear<span class="Delimiter">();</span> - string to_string<span class="Delimiter">()</span> const<span class="Delimiter">;</span> + bool is_empty<span class="Delimiter">();</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "struct instruction")</span> @@ -87,38 +84,34 @@ struct instruction <span class="Delimiter">{</span> <span class="Comment">// properties besides types, but we're getting ahead of ourselves.</span> struct reagent <span class="Delimiter">{</span> string original_string<span class="Delimiter">;</span> - vector<pair<string<span class="Delimiter">,</span> string_tree*> > properties<span class="Delimiter">;</span> string name<span class="Delimiter">;</span> + type_tree* type<span class="Delimiter">;</span> + vector<pair<string<span class="Delimiter">,</span> string_tree*> > properties<span class="Delimiter">;</span> <span class="Comment">// can't be a map because the string_tree sometimes needs to be NULL, which can be confusing</span> double value<span class="Delimiter">;</span> bool initialized<span class="Delimiter">;</span> - type_tree* type<span class="Delimiter">;</span> reagent<span class="Delimiter">(</span>string s<span class="Delimiter">);</span> - reagent<span class="Delimiter">();</span> + reagent<span class="Delimiter">()</span> :type<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> initialized<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> ~reagent<span class="Delimiter">();</span> void clear<span class="Delimiter">();</span> reagent<span class="Delimiter">(</span>const reagent& old<span class="Delimiter">);</span> reagent& operator=<span class="Delimiter">(</span>const reagent& old<span class="Delimiter">);</span> void set_value<span class="Delimiter">(</span>double v<span class="Delimiter">)</span> <span class="Delimiter">{</span> value = v<span class="Delimiter">;</span> initialized = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - string to_string<span class="Delimiter">()</span> const<span class="Delimiter">;</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "struct reagent")</span> -struct property <span class="Delimiter">{</span> - vector<string> values<span class="Delimiter">;</span> -<span class="Delimiter">};</span> - <span class="Comment">// Types can range from a simple type ordinal, to arbitrarily complex trees of</span> <span class="Comment">// type parameters, like (map (address array character) (list number))</span> struct type_tree <span class="Delimiter">{</span> + string name<span class="Delimiter">;</span> type_ordinal value<span class="Delimiter">;</span> type_tree* left<span class="Delimiter">;</span> type_tree* right<span class="Delimiter">;</span> ~type_tree<span class="Delimiter">();</span> type_tree<span class="Delimiter">(</span>const type_tree& old<span class="Delimiter">);</span> <span class="Comment">// simple: type ordinal</span> - explicit type_tree<span class="Delimiter">(</span>type_ordinal v<span class="Delimiter">)</span> :value<span class="Delimiter">(</span>v<span class="Delimiter">),</span> left<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> right<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> + explicit type_tree<span class="Delimiter">(</span>string name<span class="Delimiter">,</span> type_ordinal v<span class="Delimiter">)</span> :name<span class="Delimiter">(</span>name<span class="Delimiter">),</span> value<span class="Delimiter">(</span>v<span class="Delimiter">),</span> left<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> right<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Comment">// intermediate: list of type ordinals</span> - type_tree<span class="Delimiter">(</span>type_ordinal v<span class="Delimiter">,</span> type_tree* r<span class="Delimiter">)</span> :value<span class="Delimiter">(</span>v<span class="Delimiter">),</span> left<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> right<span class="Delimiter">(</span>r<span class="Delimiter">)</span> <span class="Delimiter">{}</span> + type_tree<span class="Delimiter">(</span>string name<span class="Delimiter">,</span> type_ordinal v<span class="Delimiter">,</span> type_tree* r<span class="Delimiter">)</span> :name<span class="Delimiter">(</span>name<span class="Delimiter">),</span> value<span class="Delimiter">(</span>v<span class="Delimiter">),</span> left<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> right<span class="Delimiter">(</span>r<span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Comment">// advanced: tree containing type ordinals</span> type_tree<span class="Delimiter">(</span>type_tree* l<span class="Delimiter">,</span> type_tree* r<span class="Delimiter">)</span> :value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> left<span class="Delimiter">(</span>l<span class="Delimiter">),</span> right<span class="Delimiter">(</span>r<span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Delimiter">};</span> @@ -135,8 +128,6 @@ struct string_tree <span class="Delimiter">{</span> string_tree<span class="Delimiter">(</span>string v<span class="Delimiter">,</span> string_tree* r<span class="Delimiter">)</span> :value<span class="Delimiter">(</span>v<span class="Delimiter">),</span> left<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> right<span class="Delimiter">(</span>r<span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Comment">// advanced: tree containing strings</span> string_tree<span class="Delimiter">(</span>string_tree* l<span class="Delimiter">,</span> string_tree* r<span class="Delimiter">)</span> :left<span class="Delimiter">(</span>l<span class="Delimiter">),</span> right<span class="Delimiter">(</span>r<span class="Delimiter">)</span> <span class="Delimiter">{}</span> - <span class="Comment">// print as s-expression</span> - string to_string<span class="Delimiter">()</span> const<span class="Delimiter">;</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "End Globals")</span> @@ -183,7 +174,7 @@ void setup_types<span class="Delimiter">()</span> <span class="Delimiter">{</spa void teardown_types<span class="Delimiter">()</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>map<type_ordinal<span class="Delimiter">,</span> type_info>::iterator p = Type<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Type<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<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>p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - delete p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> Type_ordinal<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -212,8 +203,7 @@ struct type_info <span class="Delimiter">{</span> string name<span class="Delimiter">;</span> kind_of_type kind<span class="Delimiter">;</span> long long int size<span class="Delimiter">;</span> <span class="Comment">// only if type is not primitive; primitives and addresses have size 1 (except arrays are dynamic)</span> - vector<type_tree*> elements<span class="Delimiter">;</span> - vector<string> element_names<span class="Delimiter">;</span> + vector<reagent> elements<span class="Delimiter">;</span> <span class="Comment">// End type_info Fields</span> type_info<span class="Delimiter">()</span> :kind<span class="Delimiter">(</span>PRIMITIVE<span class="Delimiter">),</span> size<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Delimiter">};</span> @@ -264,14 +254,26 @@ instruction::instruction<span class="Delimiter">()</span> :is_label<span class=" <span class="Comment">// End instruction Constructor</span> <span class="Delimiter">}</span> void instruction::clear<span class="Delimiter">()</span> <span class="Delimiter">{</span> is_label=<span class="Constant">false</span><span class="Delimiter">;</span> label<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> name<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> old_name<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> operation=IDLE<span class="Delimiter">;</span> ingredients<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> products<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> original_string<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> -bool instruction::is_clear<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> !is_label && name<span class="Delimiter">.</span>empty<span class="Delimiter">();</span> <span class="Delimiter">}</span> +bool instruction::is_empty<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> !is_label && name<span class="Delimiter">.</span>empty<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Comment">// Reagents have the form <name>:<type>:<type>:.../<property>/<property>/...</span> -reagent::reagent<span class="Delimiter">(</span>string s<span class="Delimiter">)</span> :original_string<span class="Delimiter">(</span>s<span class="Delimiter">),</span> value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> initialized<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">),</span> type<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +reagent::reagent<span class="Delimiter">(</span>string s<span class="Delimiter">)</span> :original_string<span class="Delimiter">(</span>s<span class="Delimiter">),</span> type<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> initialized<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// Parsing reagent(string s)</span> istringstream in<span class="Delimiter">(</span>s<span class="Delimiter">);</span> in >> std::noskipws<span class="Delimiter">;</span> - <span class="Comment">// properties</span> + <span class="Comment">// name and type</span> + istringstream first_row<span class="Delimiter">(</span>slurp_until<span class="Delimiter">(</span>in<span class="Delimiter">,</span> <span class="Constant">'/'</span><span class="Delimiter">));</span> + first_row >> std::noskipws<span class="Delimiter">;</span> + name = slurp_until<span class="Delimiter">(</span>first_row<span class="Delimiter">,</span> <span class="Constant">':'</span><span class="Delimiter">);</span> + string_tree* type_names = parse_property_list<span class="Delimiter">(</span>first_row<span class="Delimiter">);</span> + type = new_type_tree<span class="Delimiter">(</span>type_names<span class="Delimiter">);</span> + delete type_names<span class="Delimiter">;</span> + <span class="Comment">// special cases</span> + if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>name<span class="Delimiter">)</span> && type == <span class="Constant">NULL</span><span class="Delimiter">)</span> + type = new type_tree<span class="Delimiter">(</span><span class="Constant">"literal"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"literal"</span><span class="Delimiter">));</span> + if <span class="Delimiter">(</span>name == <span class="Constant">"_"</span> && type == <span class="Constant">NULL</span><span class="Delimiter">)</span> + type = new type_tree<span class="Delimiter">(</span><span class="Constant">"literal"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"literal"</span><span class="Delimiter">));</span> + <span class="Comment">// other properties</span> while <span class="Delimiter">(</span>has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> istringstream row<span class="Delimiter">(</span>slurp_until<span class="Delimiter">(</span>in<span class="Delimiter">,</span> <span class="Constant">'/'</span><span class="Delimiter">));</span> row >> std::noskipws<span class="Delimiter">;</span> @@ -279,19 +281,6 @@ reagent::reagent<span class="Delimiter">(</span>string s<span class="Delimiter"> string_tree* value = parse_property_list<span class="Delimiter">(</span>row<span class="Delimiter">);</span> properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span>key<span class="Delimiter">,</span> value<span class="Delimiter">));</span> <span class="Delimiter">}</span> - <span class="Comment">// structures for the first row of properties: name and list of types</span> - name = properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>first<span class="Delimiter">;</span> - type = new_type_tree<span class="Delimiter">(</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>name<span class="Delimiter">)</span> && type == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>!properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = new string_tree<span class="Delimiter">(</span><span class="Constant">"literal"</span><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">"literal"</span><span class="Delimiter">));</span> - <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>name == <span class="Constant">"_"</span> && type == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>!properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = new string_tree<span class="Delimiter">(</span><span class="Constant">"dummy"</span><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">"literal"</span><span class="Delimiter">));</span> - <span class="Delimiter">}</span> <span class="Comment">// End Parsing reagent</span> <span class="Delimiter">}</span> @@ -305,9 +294,9 @@ string_tree* parse_property_list<span class="Delimiter">(</span>istream& in< type_tree* new_type_tree<span class="Delimiter">(</span>const string_tree* properties<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!properties<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> - type_tree* result = new type_tree<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + type_tree* result = new type_tree<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> if <span class="Delimiter">(</span>!properties<span class="Delimiter">-></span>value<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - const string& type_name = properties<span class="Delimiter">-></span>value<span class="Delimiter">;</span> + const string& type_name = result<span class="Delimiter">-></span>name = properties<span class="Delimiter">-></span>value<span class="Delimiter">;</span> if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">))</span> result<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">);</span> else if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>type_name<span class="Delimiter">))</span> <span class="Comment">// sometimes types will contain non-type tags, like numbers for the size of an array</span> @@ -327,7 +316,6 @@ reagent::reagent<span class="Delimiter">(</span>const reagent& old<span clas name = old<span class="Delimiter">.</span>name<span class="Delimiter">;</span> value = old<span class="Delimiter">.</span>value<span class="Delimiter">;</span> initialized = old<span class="Delimiter">.</span>initialized<span class="Delimiter">;</span> - properties<span class="Delimiter">.</span>clear<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>old<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span>old<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first<span class="Delimiter">,</span> old<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second ? new string_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">));</span> @@ -336,6 +324,7 @@ reagent::reagent<span class="Delimiter">(</span>const reagent& old<span clas <span class="Delimiter">}</span> type_tree::type_tree<span class="Delimiter">(</span>const type_tree& old<span class="Delimiter">)</span> <span class="Delimiter">{</span> + name = old<span class="Delimiter">.</span>name<span class="Delimiter">;</span> value = old<span class="Delimiter">.</span>value<span class="Delimiter">;</span> left = old<span class="Delimiter">.</span>left ? new type_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> right = old<span class="Delimiter">.</span>right ? new type_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>right<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> @@ -349,12 +338,15 @@ string_tree::string_tree<span class="Delimiter">(</span>const string_tree& o reagent& reagent::operator=<span class="Delimiter">(</span>const reagent& old<span class="Delimiter">)</span> <span class="Delimiter">{</span> original_string = old<span class="Delimiter">.</span>original_string<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>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">)</span> delete properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">;</span> properties<span class="Delimiter">.</span>clear<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>old<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span>old<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first<span class="Delimiter">,</span> old<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second ? new string_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">));</span> name = old<span class="Delimiter">.</span>name<span class="Delimiter">;</span> value = old<span class="Delimiter">.</span>value<span class="Delimiter">;</span> initialized = old<span class="Delimiter">.</span>initialized<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>type<span class="Delimiter">)</span> delete type<span class="Delimiter">;</span> type = old<span class="Delimiter">.</span>type ? new type_tree<span class="Delimiter">(</span>*old<span class="Delimiter">.</span>type<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Identifier">return</span> *this<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -382,102 +374,66 @@ string_tree::~string_tree<span class="Delimiter">()</span> <span class="Delimite delete right<span class="Delimiter">;</span> <span class="Delimiter">}</span> -reagent::reagent<span class="Delimiter">()</span> :value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> initialized<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">),</span> type<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Comment">// The first property is special, so ensure we always have it.</span> - <span class="Comment">// Other properties can be pushed back, but the first must always be</span> - <span class="Comment">// assigned to.</span> - properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span> -<span class="Delimiter">}</span> - -string reagent::to_string<span class="Delimiter">()</span> const <span class="Delimiter">{</span> +string slurp_until<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> char delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream out<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!properties<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - out << <span class="Constant">"{"</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>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> - out << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">"</span> << properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">: "</span> << debug_string<span class="Delimiter">(</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">);</span> + char c<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>c == delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// drop the delim</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - out << <span class="Constant">"}"</span><span class="Delimiter">;</span> + out << c<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -string debug_string<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - ostringstream out<span class="Delimiter">;</span> - out << x<span class="Delimiter">.</span>name << <span class="Constant">": "</span> << debug_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" -- "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> - <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> -<span class="Delimiter">}</span> - -string debug_string<span class="Delimiter">(</span>const string_tree* property<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!property<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">"<>"</span><span class="Delimiter">;</span> - ostringstream out<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!property<span class="Delimiter">-></span>left && !property<span class="Delimiter">-></span>right<span class="Delimiter">)</span> - <span class="Comment">// abbreviate a single-node tree to just its contents</span> - out << <span class="Constant">'"'</span> << property<span class="Delimiter">-></span>value << <span class="Constant">'"'</span><span class="Delimiter">;</span> - else - dump_property_tree<span class="Delimiter">(</span>property<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +bool has_property<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> string name<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>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == name<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> -void dump_property_tree<span class="Delimiter">(</span>const string_tree* property<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> - out << <span class="Constant">"<"</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>property<span class="Delimiter">-></span>left<span class="Delimiter">)</span> - dump_property_tree<span class="Delimiter">(</span>property<span class="Delimiter">-></span>left<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - else - out << <span class="Constant">'"'</span> << property<span class="Delimiter">-></span>value << <span class="Constant">'"'</span><span class="Delimiter">;</span> - out << <span class="Constant">" : "</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>property<span class="Delimiter">-></span>right<span class="Delimiter">)</span> - dump_property_tree<span class="Delimiter">(</span>property<span class="Delimiter">-></span>right<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - else - out << <span class="Constant">"<>"</span><span class="Delimiter">;</span> - out << <span class="Constant">">"</span><span class="Delimiter">;</span> +string_tree* property<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int p = <span class="Constant">0</span><span class="Delimiter">;</span> p != SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++p<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>p<span class="Delimiter">).</span>first == name<span class="Delimiter">)</span> + <span class="Identifier">return</span> r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>p<span class="Delimiter">).</span>second<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -string debug_string<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Comment">// abbreviate a single-node tree to just its contents</span> - if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">"NULLNULLNULL"</span><span class="Delimiter">;</span> <span class="Comment">// should never happen</span> - ostringstream out<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left && !type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> - dump_type_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>value<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - else - dump_types_tree<span class="Delimiter">(</span>type<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span class="Delimiter">:(before "End Globals")</span> +const string Ignore<span class="Delimiter">(</span><span class="Constant">","</span><span class="Delimiter">);</span> <span class="Comment">// commas are ignored in mu except within [] strings</span> +<span class="Delimiter">:(code)</span> +void skip_whitespace_but_not_newline<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + else if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + else if <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + else if <span class="Delimiter">(</span>Ignore<span class="Delimiter">.</span>find<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> != string::npos<span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + else <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> -void dump_types_tree<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> - out << <span class="Constant">"<"</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">)</span> - dump_types_tree<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - else - dump_type_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>value<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - out << <span class="Constant">" : "</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> - dump_types_tree<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - else - out << <span class="Constant">"<>"</span><span class="Delimiter">;</span> - out << <span class="Constant">">"</span><span class="Delimiter">;</span> +void dump_memory<span class="Delimiter">()</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>map<long long int<span class="Delimiter">,</span> double>::iterator p = Memory<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Memory<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + cout << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << no_scientific<span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> -void dump_type_name<span class="Delimiter">(</span>type_ordinal type<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">))</span> - out << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">).</span>name<span class="Delimiter">;</span> - else - out << <span class="Constant">"?"</span> << type<span class="Delimiter">;</span> -<span class="Delimiter">}</span> +<span class="SalientComment">//:: Helpers for converting various values to string</span> +<span class="Comment">//: Use to_string() in trace(), and try to avoid relying on unstable codes that</span> +<span class="Comment">//: will perturb .traces/ from commit to commit.</span> +<span class="Comment">//: Use debug_string() while debugging, and throw everything into it.</span> +<span class="Comment">//: Use inspect() only for emitting a canonical format that can be parsed back</span> +<span class="Comment">//: into the value.</span> -string instruction::to_string<span class="Delimiter">()</span> const <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>is_label<span class="Delimiter">)</span> <span class="Identifier">return</span> label<span class="Delimiter">;</span> +string to_string<span class="Delimiter">(</span>const recipe& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream out<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>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> - out << products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string<span class="Delimiter">;</span> - <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>!products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> out << <span class="Constant">" <- "</span><span class="Delimiter">;</span> - out << name << <span class="Constant">' '</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>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> - out << ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string<span class="Delimiter">;</span> - <span class="Delimiter">}</span> + out << <span class="Constant">"recipe "</span> << r<span class="Delimiter">.</span>name << <span class="Constant">" [</span><span class="cSpecial">\n</span><span class="Constant">"</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>r<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + out << <span class="Constant">" "</span> << to_string<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="cSpecial">'\n'</span><span class="Delimiter">;</span> + out << <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -487,7 +443,7 @@ string debug_string<span class="Delimiter">(</span>const recipe& x<span clas <span class="Comment">// Begin debug_string(recipe x)</span> for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> const instruction& inst = x<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> - out << <span class="Constant">"inst: "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + out << <span class="Constant">"inst: "</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> out << <span class="Constant">" ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</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>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> out << <span class="Constant">" "</span> << debug_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> @@ -498,52 +454,50 @@ string debug_string<span class="Delimiter">(</span>const recipe& x<span clas <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -string slurp_until<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> char delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string to_string<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">return</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">;</span> ostringstream out<span class="Delimiter">;</span> - char c<span class="Delimiter">;</span> - while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>c == delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Comment">// drop the delim</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - out << c<span class="Delimiter">;</span> - <span class="Delimiter">}</span> - <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> -<span class="Delimiter">}</span> - -bool has_property<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> string name<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 name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == name<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</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>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> + out << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string<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> - -string_tree* property<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int p = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> p != SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++p<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>p<span class="Delimiter">).</span>first == name<span class="Delimiter">)</span> - <span class="Identifier">return</span> r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>p<span class="Delimiter">).</span>second<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> out << <span class="Constant">" <- "</span><span class="Delimiter">;</span> + out << inst<span class="Delimiter">.</span>name << <span class="Constant">' '</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>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> + out << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -void dump_memory<span class="Delimiter">()</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>map<long long int<span class="Delimiter">,</span> double>::iterator p = Memory<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Memory<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - cout << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << no_scientific<span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +string to_string<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + ostringstream out<span class="Delimiter">;</span> + out << r<span class="Delimiter">.</span>name << <span class="Constant">": "</span> << names_to_string<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + out << <span class="Constant">", {"</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>r<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> + out << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">"</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">"</span><span class="cSpecial">\"</span><span class="Constant">: "</span> << to_string<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + out << <span class="Constant">"}"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -string recipe::to_string<span class="Delimiter">()</span> const <span class="Delimiter">{</span> +string debug_string<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream out<span class="Delimiter">;</span> - out << <span class="Constant">"recipe "</span> << name << <span class="Constant">" [</span><span class="cSpecial">\n</span><span class="Constant">"</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>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - out << <span class="Constant">" "</span> << steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - out << <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + out << x<span class="Delimiter">.</span>name << <span class="Constant">": "</span> << x<span class="Delimiter">.</span>value << <span class="Constant">' '</span> << to_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" -- "</span> << to_string<span class="Delimiter">(</span>x<span class="Delimiter">);</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -string string_tree::to_string<span class="Delimiter">()</span> const <span class="Delimiter">{</span> +string to_string<span class="Delimiter">(</span>const string_tree* property<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!property<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">"()"</span><span class="Delimiter">;</span> ostringstream out<span class="Delimiter">;</span> - dump<span class="Delimiter">(</span>this<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!property<span class="Delimiter">-></span>left && !property<span class="Delimiter">-></span>right<span class="Delimiter">)</span> + <span class="Comment">// abbreviate a single-node tree to just its contents</span> + out << <span class="Constant">'"'</span> << property<span class="Delimiter">-></span>value << <span class="Constant">'"'</span><span class="Delimiter">;</span> + else + dump<span class="Delimiter">(</span>property<span class="Delimiter">,</span> out<span class="Delimiter">);</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -558,24 +512,92 @@ void dump<span class="Delimiter">(</span>const string_tree* x<span class="Delimi if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> dump<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">,</span> out<span class="Delimiter">);</span> else - out << curr<span class="Delimiter">-></span>value<span class="Delimiter">;</span> + out << <span class="Constant">'"'</span> << curr<span class="Delimiter">-></span>value << <span class="Constant">'"'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> out << <span class="Constant">')'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(before "End Globals")</span> -const string Ignore<span class="Delimiter">(</span><span class="Constant">","</span><span class="Delimiter">);</span> <span class="Comment">// commas are ignored in mu except within [] strings</span> -<span class="Delimiter">:(code)</span> -void skip_whitespace_but_not_newline<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> - while <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - else if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - else if <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> - else if <span class="Delimiter">(</span>Ignore<span class="Delimiter">.</span>find<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> != string::npos<span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> - else <span class="Identifier">break</span><span class="Delimiter">;</span> +string to_string<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// abbreviate a single-node tree to just its contents</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">"NULLNULLNULL"</span><span class="Delimiter">;</span> <span class="Comment">// should never happen</span> + ostringstream out<span class="Delimiter">;</span> + dump<span class="Delimiter">(</span>type<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span class="Delimiter">}</span> + +void dump<span class="Delimiter">(</span>const type_tree* x<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!x<span class="Delimiter">-></span>left && !x<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + dump<span class="Delimiter">(</span>x<span class="Delimiter">-></span>value<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + out << <span class="Constant">'('</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>const type_tree* curr = x<span class="Delimiter">;</span> curr<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>curr != x<span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> + dump<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + else + dump<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>value<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + out << <span class="Constant">')'</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +void dump<span class="Delimiter">(</span>type_ordinal type<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">))</span> + out << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + else + out << <span class="Constant">"?"</span> << type<span class="Delimiter">;</span> <span class="Delimiter">}</span> +string names_to_string<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// abbreviate a single-node tree to just its contents</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">"()"</span><span class="Delimiter">;</span> <span class="Comment">// should never happen</span> + ostringstream out<span class="Delimiter">;</span> + dump_names<span class="Delimiter">(</span>type<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span class="Delimiter">}</span> + +void dump_names<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left && !type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << <span class="Constant">'"'</span> << type<span class="Delimiter">-></span>name << <span class="Constant">'"'</span><span class="Delimiter">;</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + out << <span class="Constant">'('</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>const type_tree* curr = type<span class="Delimiter">;</span> curr<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>curr != type<span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> + dump_names<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + else + out << <span class="Constant">'"'</span> << curr<span class="Delimiter">-></span>name << <span class="Constant">'"'</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + out << <span class="Constant">')'</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +string names_to_string_without_quotes<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// abbreviate a single-node tree to just its contents</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">"NULLNULLNULL"</span><span class="Delimiter">;</span> <span class="Comment">// should never happen</span> + ostringstream out<span class="Delimiter">;</span> + dump_names_without_quotes<span class="Delimiter">(</span>type<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span class="Delimiter">}</span> + +void dump_names_without_quotes<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left && !type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << type<span class="Delimiter">-></span>name<span class="Delimiter">;</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + out << <span class="Constant">'('</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>const type_tree* curr = type<span class="Delimiter">;</span> curr<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>curr != type<span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> + dump_names_without_quotes<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + else + out << curr<span class="Delimiter">-></span>name<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + out << <span class="Constant">')'</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Comment">//: helper to print numbers without excessive precision</span> + <span class="Delimiter">:(before "End Types")</span> struct no_scientific <span class="Delimiter">{</span> double x<span class="Delimiter">;</span> @@ -603,7 +625,6 @@ string trim_floating_point<span class="Delimiter">(</span>const string& in<s --len<span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>len-<span class="Constant">1</span><span class="Delimiter">)</span> == <span class="Constant">'.'</span><span class="Delimiter">)</span> --len<span class="Delimiter">;</span> -<span class="CommentedCode">//? cerr << in << ": " << in.substr(0, len) << '\n';</span> <span class="Identifier">return</span> in<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> len<span class="Delimiter">);</span> <span class="Delimiter">}</span> diff --git a/html/011load.cc.html b/html/011load.cc.html index 205faacf..180cda8d 100644 --- a/html/011load.cc.html +++ b/html/011load.cc.html @@ -40,8 +40,8 @@ recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: product: 1: "number"</span> <span class="Delimiter">:(code)</span> vector<recipe_ordinal> load<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -62,9 +62,9 @@ vector<recipe_ordinal> load<span class="Delimiter">(</span>istream& in result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>slurp_recipe<span class="Delimiter">(</span>in<span class="Delimiter">));</span> <span class="Delimiter">}</span> else if <span class="Delimiter">(</span>command == <span class="Constant">"recipe!"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - Disable_redefine_warnings = <span class="Constant">true</span><span class="Delimiter">;</span> + Disable_redefine_checks = <span class="Constant">true</span><span class="Delimiter">;</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>slurp_recipe<span class="Delimiter">(</span>in<span class="Delimiter">));</span> - Disable_redefine_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> + Disable_redefine_checks = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// End Command Handlers</span> else <span class="Delimiter">{</span> @@ -77,22 +77,22 @@ vector<recipe_ordinal> load<span class="Delimiter">(</span>istream& in long long int slurp_recipe<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> recipe result<span class="Delimiter">;</span> result<span class="Delimiter">.</span>name = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + <span class="Comment">// End Load Recipe Name</span> skip_whitespace_but_not_newline<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Comment">// End recipe Refinements</span> + <span class="Comment">// End Recipe Refinements</span> if <span class="Delimiter">(</span>result<span class="Delimiter">.</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise_error << <span class="Constant">"empty result.name</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"--- defining "</span> << result<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">))</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">,</span> Next_recipe_ordinal++<span class="Delimiter">);</span> - <span class="Delimiter">}</span> if <span class="Delimiter">(</span>Recipe<span class="Delimiter">.</span>find<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">))</span> != Recipe<span class="Delimiter">.</span>end<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">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"already exists"</span> << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>warn_on_redefine<span class="Delimiter">(</span>result<span class="Delimiter">.</span>name<span class="Delimiter">))</span> - raise << <span class="Constant">"redefining recipe "</span> << result<span class="Delimiter">.</span>name << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>should_check_for_redefine<span class="Delimiter">(</span>result<span class="Delimiter">.</span>name<span class="Delimiter">))</span> + raise_error << <span class="Constant">"redefining recipe "</span> << result<span class="Delimiter">.</span>name << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> Recipe<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">));</span> <span class="Delimiter">}</span> slurp_body<span class="Delimiter">(</span>in<span class="Delimiter">,</span> result<span class="Delimiter">);</span> - <span class="Comment">// End recipe Body(result)</span> + <span class="Comment">// End Recipe Body(result)</span> put<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">),</span> result<span class="Delimiter">);</span> <span class="Comment">// track added recipes because we may need to undo them in tests; see below</span> Recently_added_recipes<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">));</span> @@ -108,9 +108,9 @@ void slurp_body<span class="Delimiter">(</span>istream& in<span class="Delim instruction curr<span class="Delimiter">;</span> while <span class="Delimiter">(</span>next_instruction<span class="Delimiter">(</span>in<span class="Delimiter">,</span> &curr<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// End Rewrite Instruction(curr, recipe result)</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"after rewriting: "</span> << curr<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>is_clear<span class="Delimiter">())</span> <span class="Delimiter">{</span> - curr<span class="Delimiter">.</span>original_string = curr<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"after rewriting: "</span> << to_string<span class="Delimiter">(</span>curr<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>is_empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + curr<span class="Delimiter">.</span>original_string = to_string<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> result<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -136,9 +136,8 @@ bool next_instruction<span class="Delimiter">(</span>istream& in<span class= skip_whitespace_but_not_newline<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> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"]"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"]"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// end of recipe</span> - <span class="Delimiter">}</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && !isalnum<span class="Delimiter">(</span>words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != <span class="Constant">'$'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> curr<span class="Delimiter">-></span>is_label = <span class="Constant">true</span><span class="Delimiter">;</span> @@ -153,9 +152,8 @@ bool next_instruction<span class="Delimiter">(</span>istream& in<span class= vector<string>::iterator p = words<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> if <span class="Delimiter">(</span>find<span class="Delimiter">(</span>words<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> words<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">"<-"</span><span class="Delimiter">)</span> != words<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(;</span> *p != <span class="Constant">"<-"</span><span class="Delimiter">;</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(;</span> *p != <span class="Constant">"<-"</span><span class="Delimiter">;</span> ++p<span class="Delimiter">)</span> curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span>*p<span class="Delimiter">));</span> - <span class="Delimiter">}</span> ++p<span class="Delimiter">;</span> <span class="Comment">// skip <-</span> <span class="Delimiter">}</span> @@ -166,18 +164,15 @@ bool next_instruction<span class="Delimiter">(</span>istream& in<span class= curr<span class="Delimiter">-></span>old_name = curr<span class="Delimiter">-></span>name = *p<span class="Delimiter">;</span> p++<span class="Delimiter">;</span> <span class="Comment">// curr->operation will be set in a later layer</span> - for <span class="Delimiter">(;</span> p != words<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(;</span> p != words<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span>*p<span class="Delimiter">));</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">"instruction: "</span> << curr<span class="Delimiter">-></span>name << end<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">" number of ingredients: "</span> << SIZE<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - for <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</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">" ingredient: "</span> << p<span class="Delimiter">-></span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> - <span class="Delimiter">}</span> - for <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</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">" product: "</span> << p<span class="Delimiter">-></span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> - <span class="Delimiter">}</span> + for <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<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">" ingredient: "</span> << to_string<span class="Delimiter">(</span>*p<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + for <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<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">" product: "</span> << to_string<span class="Delimiter">(</span>*p<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> if <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise_error << <span class="Constant">"9: unbalanced '[' for recipe</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> @@ -245,14 +240,14 @@ void skip_comment<span class="Delimiter">(</span>istream& in<span class="Del <span class="Comment">//: Warn if a recipe gets redefined, because large codebases can accidentally</span> <span class="Comment">//: step on their own toes. But there'll be many occasions later where</span> -<span class="Comment">//: we'll want to disable the warnings.</span> +<span class="Comment">//: we'll want to disable the errors.</span> <span class="Delimiter">:(before "End Globals")</span> -bool Disable_redefine_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> +bool Disable_redefine_checks = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> -Disable_redefine_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> +Disable_redefine_checks = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> -bool warn_on_redefine<span class="Delimiter">(</span>const string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Disable_redefine_warnings<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +bool should_check_for_redefine<span class="Delimiter">(</span>const string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Disable_redefine_checks<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -261,9 +256,8 @@ bool warn_on_redefine<span class="Delimiter">(</span>const string& recipe_na void show_rest_of_stream<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> cerr << <span class="Constant">'^'</span><span class="Delimiter">;</span> char c<span class="Delimiter">;</span> - while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> cerr << c<span class="Delimiter">;</span> - <span class="Delimiter">}</span> cerr << <span class="Constant">"$</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> exit<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -294,8 +288,8 @@ recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: product: 1: "number"</span> <span class="Delimiter">:(scenario parse_comment_amongst_instruction)</span> recipe main [ @@ -303,8 +297,8 @@ recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: product: 1: "number"</span> <span class="Delimiter">:(scenario parse_comment_amongst_instruction_2)</span> recipe main [ @@ -313,8 +307,8 @@ recipe main [ <span class="Comment"># comment</span> ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: product: 1: "number"</span> <span class="Delimiter">:(scenario parse_comment_amongst_instruction_3)</span> recipe main [ @@ -323,19 +317,19 @@ recipe main [ <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: product: 1: "number"</span> <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: product: {"2": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: product: 2: "number"</span> <span class="Delimiter">:(scenario parse_comment_after_instruction)</span> recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> <span class="Comment"># comment</span> ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: product: 1: "number"</span> <span class="Delimiter">:(scenario parse_label)</span> recipe main [ @@ -354,43 +348,43 @@ recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>/foo:bar:baz ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal", "foo": <"bar" : <"baz" : <>>>}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal", {"foo": ("bar" "baz")}</span> +<span class="traceContains">+parse: product: 1: "number"</span> <span class="Delimiter">:(scenario parse_multiple_products)</span> recipe main [ <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> -<span class="traceContains">+parse: product: {"2": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: product: 1: "number"</span> +<span class="traceContains">+parse: product: 2: "number"</span> <span class="Delimiter">:(scenario parse_multiple_ingredients)</span> recipe main [ <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">4</span>:number ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: ingredient: {"4": "number"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> -<span class="traceContains">+parse: product: {"2": "number"}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: ingredient: 4: "number"</span> +<span class="traceContains">+parse: product: 1: "number"</span> +<span class="traceContains">+parse: product: 2: "number"</span> <span class="Delimiter">:(scenario parse_multiple_types)</span> recipe main [ <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">4</span>:number ] <span class="traceContains">+parse: instruction: copy</span> -<span class="traceContains">+parse: ingredient: {"23": "literal"}</span> -<span class="traceContains">+parse: ingredient: {"4": "number"}</span> -<span class="traceContains">+parse: product: {"1": "number"}</span> -<span class="traceContains">+parse: product: {"2": <"address" : <"number" : <>>>}</span> +<span class="traceContains">+parse: ingredient: 23: "literal"</span> +<span class="traceContains">+parse: ingredient: 4: "number"</span> +<span class="traceContains">+parse: product: 1: "number"</span> +<span class="traceContains">+parse: product: 2: ("address" "number")</span> <span class="Delimiter">:(scenario parse_properties)</span> recipe main [ - <span class="Constant">1</span>:number:address/lookup<span class="Special"> <- </span>copy <span class="Constant">23</span> + <span class="Constant">1</span>:address:number/lookup<span class="Special"> <- </span>copy <span class="Constant">23</span> ] -<span class="traceContains">+parse: product: {"1": <"number" : <"address" : <>>>, "lookup": <>}</span> +<span class="traceContains">+parse: product: 1: ("address" "number"), {"lookup": ()}</span> <span class="Comment">//: this test we can't represent with a scenario</span> <span class="Delimiter">:(code)</span> @@ -403,26 +397,26 @@ void test_parse_comment_terminated_by_eof<span class="Delimiter">()</span> <span cerr << <span class="Constant">"."</span><span class="Delimiter">;</span> <span class="Comment">// termination = success</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(scenario warn_on_redefine)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Delimiter">:(scenario forbid_redefining_recipes)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">24</span> ] -<span class="traceContains">+warn: redefining recipe main</span> +<span class="traceContains">+error: redefining recipe main</span> -<span class="Delimiter">:(scenario redefine_without_warning)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Delimiter">:(scenario permit_forcibly_redefining_recipes)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] recipe! main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">24</span> ] -<span class="traceAbsent">-warn: redefining recipe main</span> -$warn: <span class="Constant">0</span> +<span class="traceAbsent">-error: redefining recipe main</span> +$error: <span class="Constant">0</span> </pre> </body> </html> diff --git a/html/013update_operation.cc.html b/html/013update_operation.cc.html index a84aff0d..956fb4eb 100644 --- a/html/013update_operation.cc.html +++ b/html/013update_operation.cc.html @@ -46,14 +46,14 @@ void update_instruction_operations<span class="Delimiter">(</span>recipe_ordinal if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"instruction "</span> << inst<span class="Delimiter">.</span>name << <span class="Constant">" has no recipe</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> inst<span class="Delimiter">.</span>operation = get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span class="Comment">// End Instruction Operation Checks</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Comment">// hook to suppress inserting recipe name into errors and warnings (for later layers)</span> +<span class="Comment">// hook to suppress inserting recipe name into errors (for later layers)</span> string maybe<span class="Delimiter">(</span>string s<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> s + <span class="Constant">": "</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/014literal_string.cc.html b/html/014literal_string.cc.html index 157b2fa4..bc4affd9 100644 --- a/html/014literal_string.cc.html +++ b/html/014literal_string.cc.html @@ -43,13 +43,13 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } recipe main [ <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>copy [abc def] <span class="Comment"># copy can't really take a string</span> ] -<span class="traceContains">+parse: ingredient: {"abc def": "literal-string"}</span> +<span class="traceContains">+parse: ingredient: "abc def": "literal-string"</span> <span class="Delimiter">:(scenario string_literal_with_colons)</span> recipe main [ <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>copy [abc:def/ghi] ] -<span class="traceContains">+parse: ingredient: {"abc:def/ghi": "literal-string"}</span> +<span class="traceContains">+parse: ingredient: "abc:def/ghi": "literal-string"</span> <span class="Delimiter">:(before "End Mu Types Initialization")</span> put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"literal-string"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> @@ -143,28 +143,27 @@ if <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span clas s<span class="Delimiter">.</span>erase<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> strip_last<span class="Delimiter">(</span>s<span class="Delimiter">);</span> name = s<span class="Delimiter">;</span> - type = new type_tree<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span>name<span class="Delimiter">,</span> new string_tree<span class="Delimiter">(</span><span class="Constant">"literal-string"</span><span class="Delimiter">)));</span> + type = new type_tree<span class="Delimiter">(</span><span class="Constant">"literal-string"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: Unlike other reagents, escape newlines in literal strings to make them</span> <span class="Comment">//: more friendly to trace().</span> -<span class="Delimiter">:(after "string reagent::to_string()")</span> - if <span class="Delimiter">(</span>is_literal_string<span class="Delimiter">(</span>*this<span class="Delimiter">))</span> - <span class="Identifier">return</span> emit_literal_string<span class="Delimiter">(</span>name<span class="Delimiter">);</span> +<span class="Delimiter">:(after "string to_string(const reagent& r)")</span> + if <span class="Delimiter">(</span>is_literal_string<span class="Delimiter">(</span>r<span class="Delimiter">))</span> + <span class="Identifier">return</span> emit_literal_string<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> bool is_literal_string<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second && x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"literal-string"</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> x<span class="Delimiter">.</span>type && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"literal-string"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> string emit_literal_string<span class="Delimiter">(</span>string name<span class="Delimiter">)</span> <span class="Delimiter">{</span> size_t pos = <span class="Constant">0</span><span class="Delimiter">;</span> while <span class="Delimiter">(</span>pos != string::npos<span class="Delimiter">)</span> pos = replace<span class="Delimiter">(</span>name<span class="Delimiter">,</span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">,</span> <span class="Constant">"</span><span class="cSpecial">\\</span><span class="Constant">n"</span><span class="Delimiter">,</span> pos<span class="Delimiter">);</span> - <span class="Identifier">return</span> <span class="Constant">"{</span><span class="cSpecial">\"</span><span class="Constant">"</span>+name+<span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">: </span><span class="cSpecial">\"</span><span class="Constant">literal-string</span><span class="cSpecial">\"</span><span class="Constant">}"</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> <span class="Constant">'"'</span>+name+<span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">: </span><span class="cSpecial">\"</span><span class="Constant">literal-string</span><span class="cSpecial">\"</span><span class="Constant">"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> size_t replace<span class="Delimiter">(</span>string& str<span class="Delimiter">,</span> const string& from<span class="Delimiter">,</span> const string& to<span class="Delimiter">,</span> size_t n<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -182,20 +181,20 @@ void strip_last<span class="Delimiter">(</span>string& s<span class="Delimit recipe main [ <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>copy [abc [def]] ] -<span class="traceContains">+parse: ingredient: {"abc [def]": "literal-string"}</span> +<span class="traceContains">+parse: ingredient: "abc [def]": "literal-string"</span> <span class="Delimiter">:(scenario string_literal_escaped)</span> recipe main [ <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>copy [abc \[def] ] -<span class="traceContains">+parse: ingredient: {"abc [def": "literal-string"}</span> +<span class="traceContains">+parse: ingredient: "abc [def": "literal-string"</span> <span class="Delimiter">:(scenario string_literal_escaped_comment_aware)</span> recipe main [ <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>copy [ abc \\\[def] ] -<span class="traceContains">+parse: ingredient: {"\nabc \[def": "literal-string"}</span> +<span class="traceContains">+parse: ingredient: "\nabc \[def": "literal-string"</span> <span class="Delimiter">:(scenario string_literal_and_comment)</span> recipe main [ @@ -204,15 +203,15 @@ recipe main [ <span class="traceContains">+parse: --- defining main</span> <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: number of ingredients: 1</span> -<span class="traceContains">+parse: ingredient: {"abc": "literal-string"}</span> -<span class="traceContains">+parse: product: {"1": <"address" : <"array" : <"character" : <>>>>}</span> +<span class="traceContains">+parse: ingredient: "abc": "literal-string"</span> +<span class="traceContains">+parse: product: 1: ("address" "array" "character")</span> <span class="Delimiter">:(scenario string_literal_escapes_newlines_in_trace)</span> recipe main [ copy [abc def] ] -<span class="traceContains">+parse: ingredient: {"abc\ndef": "literal-string"}</span> +<span class="traceContains">+parse: ingredient: "abc\ndef": "literal-string"</span> <span class="Delimiter">:(scenario string_literal_can_skip_past_comments)</span> recipe main [ @@ -221,13 +220,13 @@ recipe main [ bar ] ] -<span class="traceContains">+parse: ingredient: {"\n # ']' inside comment\n bar\n ": "literal-string"}</span> +<span class="traceContains">+parse: ingredient: "\n # ']' inside comment\n bar\n ": "literal-string"</span> <span class="Delimiter">:(scenario string_literal_empty)</span> recipe main [ copy [] ] -<span class="traceContains">+parse: ingredient: {"": "literal-string"}</span> +<span class="traceContains">+parse: ingredient: "": "literal-string"</span> </pre> </body> </html> diff --git a/html/015literal_noninteger.cc.html b/html/015literal_noninteger.cc.html index 4c0f8852..89a405df 100644 --- a/html/015literal_noninteger.cc.html +++ b/html/015literal_noninteger.cc.html @@ -38,22 +38,22 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3.14159</span> ] -<span class="traceContains">+parse: ingredient: {"3.14159": "literal-number"}</span> +<span class="traceContains">+parse: ingredient: 3.14159: "literal-fractional-number"</span> <span class="Delimiter">:(after "Parsing reagent(string s)")</span> if <span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> name = s<span class="Delimiter">;</span> - type = new type_tree<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span>name<span class="Delimiter">,</span> new string_tree<span class="Delimiter">(</span><span class="Constant">"literal-number"</span><span class="Delimiter">)));</span> + type = new type_tree<span class="Delimiter">(</span><span class="Constant">"literal-fractional-number"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> set_value<span class="Delimiter">(</span>to_double<span class="Delimiter">(</span>s<span class="Delimiter">));</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> bool is_noninteger<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-."</span><span class="Delimiter">)</span> == string::npos - && s<span class="Delimiter">.</span>find_first_of <span class="Delimiter">(</span><span class="Constant">"0123456789-"</span><span class="Delimiter">)</span> != string::npos - && std::count<span class="Delimiter">(</span>s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> s<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">'.'</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> s<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="Comment">// no other characters</span> + && s<span class="Delimiter">.</span>find_first_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos <span class="Comment">// at least one digit</span> + && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'-'</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">)</span> == string::npos <span class="Comment">// '-' only at first position</span> + && std::count<span class="Delimiter">(</span>s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> s<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">'.'</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// exactly one decimal point</span> <span class="Delimiter">}</span> double to_double<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -72,6 +72,11 @@ void test_is_noninteger<span class="Delimiter">()</span> <span class="Delimiter" CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">"."</span><span class="Delimiter">));</span> CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">"2."</span><span class="Delimiter">));</span> CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">".2"</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">"-.2"</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">"-2."</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">"--.2"</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">".-2"</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">"..2"</span><span class="Delimiter">));</span> <span class="Delimiter">}</span> </pre> </body> diff --git a/html/020run.cc.html b/html/020run.cc.html index 9e3e13a3..b3545e30 100644 --- a/html/020run.cc.html +++ b/html/020run.cc.html @@ -97,10 +97,8 @@ void run_current_routine<span class="Delimiter">()</span> while <span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>completed<span class="Delimiter">())</span> <span class="Comment">// later layers will modify condition</span> <span class="Delimiter">{</span> <span class="Comment">// Running One Instruction</span> -<span class="CommentedCode">//? trace(9999, "aaaa") << "location 1 contains " << get_or_insert(Memory, 1) << end();</span> -<span class="CommentedCode">//? Instructions_running[current_recipe_name()]++;</span> if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>is_label<span class="Delimiter">)</span> <span class="Delimiter">{</span> ++current_step_index<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - trace<span class="Delimiter">(</span>Initial_callstack_depth + Trace_stream<span class="Delimiter">-></span>callstack_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span>Initial_callstack_depth + Trace_stream<span class="Delimiter">-></span>callstack_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << end<span class="Delimiter">();</span> if <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise_error << <span class="Constant">"something wrote to location 0; this should never happen</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> @@ -108,11 +106,8 @@ void run_current_routine<span class="Delimiter">()</span> <span class="Comment">// read all ingredients from memory, each potentially spanning multiple locations</span> vector<vector<double> > ingredients<span class="Delimiter">;</span> if <span class="Delimiter">(</span>should_copy_ingredients<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>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<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>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</span> -<span class="CommentedCode">//? Locations_read[current_recipe_name()] += SIZE(ingredients.back());</span> -<span class="CommentedCode">//? Locations_read_by_instruction[current_instruction().name] += SIZE(ingredients.back());</span> - <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Comment">// instructions below will write to 'products'</span> vector<vector<double> > products<span class="Delimiter">;</span> @@ -128,7 +123,7 @@ void run_current_routine<span class="Delimiter">()</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> << <span class="Constant">": failed to write to all products! "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> << <span class="Constant">": failed to write to all products! "</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> else <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>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -175,6 +170,8 @@ inline bool routine::completed<span class="Delimiter">()</span> const <span clas <span class="CommentedCode">//? START_TRACING_UNTIL_END_OF_SCOPE;</span> load_permanently<span class="Delimiter">(</span><span class="Constant">"core.mu"</span><span class="Delimiter">);</span> transform_all<span class="Delimiter">();</span> +<span class="CommentedCode">//? DUMP("");</span> +<span class="CommentedCode">//? exit(0);</span> <span class="Comment">//: Step 2: load any .mu files provided at the commandline</span> <span class="Delimiter">:(before "End Commandline Parsing")</span> @@ -250,12 +247,10 @@ void load_permanently<span class="Delimiter">(</span>string filename<span class= <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> ifstream fin<span class="Delimiter">(</span>filename<span class="Delimiter">.</span>c_str<span class="Delimiter">());</span> - fin<span class="Delimiter">.</span>peek<span class="Delimiter">();</span> if <span class="Delimiter">(</span>!fin<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise_error << <span class="Constant">"no such file "</span> << filename << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - fin >> std::noskipws<span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">9990</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"=== "</span> << filename << end<span class="Delimiter">();</span> load<span class="Delimiter">(</span>fin<span class="Delimiter">);</span> fin<span class="Delimiter">.</span>close<span class="Delimiter">();</span> @@ -275,8 +270,8 @@ void load_all_permanently<span class="Delimiter">(</span>string dir<span class=" int num_files = scandir<span class="Delimiter">(</span>dir<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &files<span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">,</span> alphasort<span class="Delimiter">);</span> for <span class="Delimiter">(</span>int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < num_files<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> string curr_file = files[i]<span class="Delimiter">-></span>d_name<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!isdigit<span class="Delimiter">(</span>curr_file<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - load_permanently<span class="Delimiter">(</span>dir+<span class="Constant">'/'</span>+curr_file<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>isdigit<span class="Delimiter">(</span>curr_file<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> + load_permanently<span class="Delimiter">(</span>dir+<span class="Constant">'/'</span>+curr_file<span class="Delimiter">);</span> free<span class="Delimiter">(</span>files[i]<span class="Delimiter">);</span> files[i] = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -307,7 +302,7 @@ vector<double> read_memory<span class="Delimiter">(</span>reagent x<span c void write_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> vector<double> data<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 << <span class="Constant">"can't write to "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"; no type</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"can't write to "</span> << to_string<span class="Delimiter">(</span>x<span class="Delimiter">)</span> << <span class="Constant">"; no type</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> @@ -315,7 +310,7 @@ void write_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter long long int base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> if <span class="Delimiter">(</span>base == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>size_mismatch<span class="Delimiter">(</span>x<span class="Delimiter">,</span> data<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"size mismatch in storing to "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" ("</span> << size_of<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>data<span class="Delimiter">)</span> << <span class="Constant">") at '"</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>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"size mismatch in storing to "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" ("</span> << size_of<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>data<span class="Delimiter">)</span> << <span class="Constant">") at '"</span> << to_string<span class="Delimiter">(</span>current_instruction<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="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// End write_memory(reagent x, long long int base) Special-cases</span> diff --git a/html/021check_instruction.cc.html b/html/021check_instruction.cc.html index d98db0da..735bf1c1 100644 --- a/html/021check_instruction.cc.html +++ b/html/021check_instruction.cc.html @@ -57,7 +57,7 @@ void check_instruction<span class="Delimiter">(</span>const recipe_ordinal r<spa <span class="Comment">// Primitive Recipe Checks</span> case COPY: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"ingredients and products should match 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 << <span class="Constant">"ingredients and products should match in '"</span> << to_string<span class="Delimiter">(</span>inst<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> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -151,6 +151,15 @@ bool types_match<span class="Delimiter">(</span>const reagent& to<span class <span class="Identifier">return</span> types_strictly_match<span class="Delimiter">(</span>to<span class="Delimiter">,</span> from<span class="Delimiter">);</span> <span class="Delimiter">}</span> +bool types_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>const reagent& to<span class="Delimiter">,</span> const reagent& from<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// to sidestep type-checking, use /unsafe in the source.</span> + <span class="Comment">// this will be highlighted in red inside vim. just for setting up some tests.</span> + if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>from<span class="Delimiter">)</span> + && to<span class="Delimiter">.</span>type && to<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"boolean"</span><span class="Delimiter">))</span> + <span class="Identifier">return</span> boolean_matches_literal<span class="Delimiter">(</span>to<span class="Delimiter">,</span> from<span class="Delimiter">);</span> + <span class="Identifier">return</span> types_strictly_match<span class="Delimiter">(</span>to<span class="Delimiter">,</span> from<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + bool boolean_matches_literal<span class="Delimiter">(</span>const reagent& to<span class="Delimiter">,</span> const reagent& from<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>from<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>!to<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> @@ -205,9 +214,9 @@ bool is_mu_boolean<span class="Delimiter">(</span>reagent r<span class="Delimite bool is_mu_number<span class="Delimiter">(</span>reagent r<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>r<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><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - <span class="Identifier">return</span> r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"literal-number"</span> - || r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"literal-fractional-number"</span> + || r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"character"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// permit arithmetic on unicode code points</span> <span class="Identifier">return</span> r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"number"</span><span class="Delimiter">);</span> @@ -216,7 +225,7 @@ bool is_mu_number<span class="Delimiter">(</span>reagent r<span class="Delimiter bool is_mu_scalar<span class="Delimiter">(</span>reagent r<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>r<span class="Delimiter">))</span> - <span class="Identifier">return</span> !r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second || r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value != <span class="Constant">"literal-string"</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> !r<span class="Delimiter">.</span>type || r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name != <span class="Constant">"literal-string"</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>r<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/022arithmetic.cc.html b/html/022arithmetic.cc.html index f7e89060..3b00bbac 100644 --- a/html/022arithmetic.cc.html +++ b/html/022arithmetic.cc.html @@ -47,7 +47,7 @@ case ADD: <span class="Delimiter">{</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'add' yields exactly one product 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">"'add' yields exactly one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="Delimiter">{</span> @@ -119,7 +119,7 @@ case SUBTRACT: <span class="Delimiter">{</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'subtract' yields exactly one product 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">"'subtract' yields exactly one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="Delimiter">{</span> @@ -175,7 +175,7 @@ case MULTIPLY: <span class="Delimiter">{</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'multiply' yields exactly one product 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">"'multiply' yields exactly one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="Delimiter">{</span> @@ -232,7 +232,7 @@ case DIVIDE: <span class="Delimiter">{</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'divide' yields exactly one product 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">"'divide' yields exactly one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="Delimiter">{</span> @@ -280,15 +280,15 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case DIVIDE_WITH_REMAINDER: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'divide-with-remainder' requires exactly two ingredients, but got '"</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">"'divide-with-remainder' requires exactly two ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> || !is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'divide-with-remainder' requires number ingredients, but got '"</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">"'divide-with-remainder' requires number ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'divide-with-remainder' yields two products 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">"'divide-with-remainder' yields two products in '"</span> << to_string<span class="Delimiter">(</span>inst<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> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -305,7 +305,7 @@ case DIVIDE_WITH_REMAINDER: <span class="Delimiter">{</span> long long int a = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> long long int b = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> if <span class="Delimiter">(</span>b == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"divide by zero 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>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"divide by zero in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> @@ -354,6 +354,369 @@ recipe main [ ] <span class="Comment"># integer division can't return floating-point infinity</span> <span class="traceContains">+error: main: divide by zero in '1:number <- divide-with-remainder 4, 0'</span> + +<span class="Comment">//: Bitwise shifts</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +SHIFT_LEFT<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"shift-left"</span><span class="Delimiter">,</span> SHIFT_LEFT<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case SHIFT_LEFT: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'shift-left' requires exactly two ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> || !is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'shift-left' requires number ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'shift-left' yields one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="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">"'shift-left' should yield a number, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">goto</span> finish_checking_instruction<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case SHIFT_LEFT: <span class="Delimiter">{</span> + <span class="Comment">// ingredients must be integers</span> + long long int a = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + long long int b = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>b < <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"second ingredient can't be negative in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>a<<b<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario shift_left_by_zero)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>shift-left <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">0</span> +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario shift_left_1)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>shift-left <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">4</span> +] +<span class="traceContains">+mem: storing 16 in location 1</span> + +<span class="Delimiter">:(scenario shift_left_2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>shift-left <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">2</span> +] +<span class="traceContains">+mem: storing 12 in location 1</span> + +<span class="Delimiter">:(scenario shift_left_by_negative)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>shift-left <span class="Constant">3</span><span class="Delimiter">,</span> -<span class="Constant">1</span> +] +<span class="traceContains">+error: main: second ingredient can't be negative in '1:number <- shift-left 3, -1'</span> + +<span class="Delimiter">:(scenario shift_left_ignores_fractional_part)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>divide <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">2</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>shift-left <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span> +] +<span class="traceContains">+mem: storing 2 in location 2</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +SHIFT_RIGHT<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"shift-right"</span><span class="Delimiter">,</span> SHIFT_RIGHT<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case SHIFT_RIGHT: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'shift-right' requires exactly two ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> || !is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'shift-right' requires number ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'shift-right' yields one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="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">"'shift-right' should yield a number, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">goto</span> finish_checking_instruction<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case SHIFT_RIGHT: <span class="Delimiter">{</span> + <span class="Comment">// ingredients must be integers</span> + long long int a = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + long long int b = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>b < <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"second ingredient can't be negative in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>a>>b<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario shift_right_by_zero)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>shift-right <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">0</span> +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario shift_right_1)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>shift-right <span class="Constant">1024</span><span class="Delimiter">,</span> <span class="Constant">1</span> +] +<span class="traceContains">+mem: storing 512 in location 1</span> + +<span class="Delimiter">:(scenario shift_right_2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>shift-right <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">1</span> +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario shift_right_by_negative)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>shift-right <span class="Constant">4</span><span class="Delimiter">,</span> -<span class="Constant">1</span> +] +<span class="traceContains">+error: main: second ingredient can't be negative in '1:number <- shift-right 4, -1'</span> + +<span class="Delimiter">:(scenario shift_right_ignores_fractional_part)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>divide <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">2</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>shift-right <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span> +] +<span class="traceContains">+mem: storing 0 in location 2</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +AND_BITS<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"and-bits"</span><span class="Delimiter">,</span> AND_BITS<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case AND_BITS: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'and-bits' requires exactly two ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> || !is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'and-bits' requires number ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'and-bits' yields one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="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">"'and-bits' should yield a number, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">goto</span> finish_checking_instruction<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case AND_BITS: <span class="Delimiter">{</span> + <span class="Comment">// ingredients must be integers</span> + long long int a = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + long long int b = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>a&b<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario and_bits_1)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>and-bits <span class="Constant">8</span><span class="Delimiter">,</span> <span class="Constant">3</span> +] +<span class="traceContains">+mem: storing 0 in location 1</span> + +<span class="Delimiter">:(scenario and_bits_2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>and-bits <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">2</span> +] +<span class="traceContains">+mem: storing 2 in location 1</span> + +<span class="Delimiter">:(scenario and_bits_3)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>and-bits <span class="Constant">14</span><span class="Delimiter">,</span> <span class="Constant">3</span> +] +<span class="traceContains">+mem: storing 2 in location 1</span> + +<span class="Delimiter">:(scenario and_bits_negative)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>and-bits -<span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> +] +<span class="traceContains">+mem: storing 4 in location 1</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +OR_BITS<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"or-bits"</span><span class="Delimiter">,</span> OR_BITS<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case OR_BITS: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'or-bits' requires exactly two ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> || !is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'or-bits' requires number ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'or-bits' yields one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="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">"'or-bits' should yield a number, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">goto</span> finish_checking_instruction<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case OR_BITS: <span class="Delimiter">{</span> + <span class="Comment">// ingredients must be integers</span> + long long int a = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + long long int b = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>a|b<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario or_bits_1)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>or-bits <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">8</span> +] +<span class="traceContains">+mem: storing 11 in location 1</span> + +<span class="Delimiter">:(scenario or_bits_2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>or-bits <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">10</span> +] +<span class="traceContains">+mem: storing 11 in location 1</span> + +<span class="Delimiter">:(scenario or_bits_3)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>or-bits <span class="Constant">4</span><span class="Delimiter">,</span> <span class="Constant">6</span> +] +<span class="traceContains">+mem: storing 6 in location 1</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +XOR_BITS<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"xor-bits"</span><span class="Delimiter">,</span> XOR_BITS<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case XOR_BITS: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'xor-bits' requires exactly two ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> || !is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'xor-bits' requires number ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'xor-bits' yields one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="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">"'xor-bits' should yield a number, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">goto</span> finish_checking_instruction<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case XOR_BITS: <span class="Delimiter">{</span> + <span class="Comment">// ingredients must be integers</span> + long long int a = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + long long int b = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>a^b<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario xor_bits_1)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>xor-bits <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">8</span> +] +<span class="traceContains">+mem: storing 11 in location 1</span> + +<span class="Delimiter">:(scenario xor_bits_2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>xor-bits <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">10</span> +] +<span class="traceContains">+mem: storing 9 in location 1</span> + +<span class="Delimiter">:(scenario xor_bits_3)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>xor-bits <span class="Constant">4</span><span class="Delimiter">,</span> <span class="Constant">6</span> +] +<span class="traceContains">+mem: storing 2 in location 1</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +FLIP_BITS<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"flip-bits"</span><span class="Delimiter">,</span> FLIP_BITS<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case FLIP_BITS: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'flip-bits' requires exactly one ingredient, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> <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">"'flip-bits' requires a number ingredient, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'flip-bits' yields one product in '"</span> << to_string<span class="Delimiter">(</span>inst<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>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && !is_mu_number<span class="Delimiter">(</span>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="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">"'flip-bits' should yield a number, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">goto</span> finish_checking_instruction<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case FLIP_BITS: <span class="Delimiter">{</span> + <span class="Comment">// ingredient must be integer</span> + long long int a = static_cast<long long int><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>~a<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario flip_bits_zero)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>flip-bits <span class="Constant">0</span> +] +<span class="traceContains">+mem: storing -1 in location 1</span> + +<span class="Delimiter">:(scenario flip_bits_negative)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>flip-bits -<span class="Constant">1</span> +] +<span class="traceContains">+mem: storing 0 in location 1</span> + +<span class="Delimiter">:(scenario flip_bits_1)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>flip-bits <span class="Constant">3</span> +] +<span class="traceContains">+mem: storing -4 in location 1</span> + +<span class="Delimiter">:(scenario flip_bits_2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>flip-bits <span class="Constant">12</span> +] +<span class="traceContains">+mem: storing -13 in location 1</span> </pre> </body> </html> diff --git a/html/023boolean.cc.html b/html/023boolean.cc.html index 1daa8686..f744c87c 100644 --- a/html/023boolean.cc.html +++ b/html/023boolean.cc.html @@ -140,7 +140,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case NOT: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<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">"'not' cannot have fewer ingredients than products 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">"'not' cannot have fewer ingredients than products in '"</span> << to_string<span class="Delimiter">(</span>inst<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> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> diff --git a/html/024jump.cc.html b/html/024jump.cc.html index 8f392805..0989240f 100644 --- a/html/024jump.cc.html +++ b/html/024jump.cc.html @@ -50,7 +50,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case JUMP: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'jump' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'jump' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_scalar<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> <span class="Delimiter">{</span> @@ -89,7 +89,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case JUMP_IF: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'jump-if' requires exactly two ingredients, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'jump-if' requires exactly two ingredients, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_scalar<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> <span class="Delimiter">{</span> @@ -141,7 +141,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case JUMP_UNLESS: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'jump-unless' requires exactly two ingredients, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'jump-unless' requires exactly two ingredients, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_scalar<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> <span class="Delimiter">{</span> diff --git a/html/025compare.cc.html b/html/025compare.cc.html index 9d4fc286..19eee8a5 100644 --- a/html/025compare.cc.html +++ b/html/025compare.cc.html @@ -40,7 +40,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case EQUAL: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'equal' needs at least two ingredients to compare 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">"'equal' needs at least two ingredients to compare in '"</span> << to_string<span class="Delimiter">(</span>inst<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> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -99,7 +99,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case GREATER_THAN: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'greater-than' needs at least two ingredients to compare 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">"'greater-than' needs at least two ingredients to compare in '"</span> << to_string<span class="Delimiter">(</span>inst<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> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -158,7 +158,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case LESSER_THAN: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'lesser-than' needs at least two ingredients to compare 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">"'lesser-than' needs at least two ingredients to compare in '"</span> << to_string<span class="Delimiter">(</span>inst<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> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -217,7 +217,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case GREATER_OR_EQUAL: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'greater-or-equal' needs at least two ingredients to compare 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">"'greater-or-equal' needs at least two ingredients to compare in '"</span> << to_string<span class="Delimiter">(</span>inst<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> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -284,7 +284,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case LESSER_OR_EQUAL: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'lesser-or-equal' needs at least two ingredients to compare 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">"'lesser-or-equal' needs at least two ingredients to compare in '"</span> << to_string<span class="Delimiter">(</span>inst<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> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> diff --git a/html/029tools.cc.html b/html/029tools.cc.html index 7944d991..66ecc557 100644 --- a/html/029tools.cc.html +++ b/html/029tools.cc.html @@ -48,7 +48,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case TRACE: <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">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'trace' takes three or more ingredients rather than '"</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">"'trace' takes three or more ingredients rather than '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> <span class="Delimiter">{</span> @@ -134,7 +134,6 @@ case HIDE_ERRORS: <span class="Delimiter">{</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case HIDE_ERRORS: <span class="Delimiter">{</span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> - Hide_warnings = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -149,7 +148,6 @@ case SHOW_ERRORS: <span class="Delimiter">{</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case SHOW_ERRORS: <span class="Delimiter">{</span> Hide_errors = <span class="Constant">false</span><span class="Delimiter">;</span> - Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -236,7 +234,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case ASSERT: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'assert' takes exactly two ingredients rather than '"</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">"'assert' takes exactly two ingredients rather than '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_scalar<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> <span class="Delimiter">{</span> diff --git a/html/030container.cc.html b/html/030container.cc.html index 00935788..6151c829 100644 --- a/html/030container.cc.html +++ b/html/030container.cc.html @@ -16,6 +16,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } .SalientComment { color: #00ffff; } .traceContains { color: #008000; } .cSpecial { color: #008000; } +.PreProc { color: #c000c0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } @@ -40,10 +41,8 @@ type_ordinal point = put<span class="Delimiter">(</span>Type_ordinal<span class= get_or_insert<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point<span class="Delimiter">).</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point<span class="Delimiter">).</span>kind = CONTAINER<span class="Delimiter">;</span> get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point<span class="Delimiter">).</span>name = <span class="Constant">"point"</span><span class="Delimiter">;</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new type_tree<span class="Delimiter">(</span>number<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>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new type_tree<span class="Delimiter">(</span>number<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> +get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"x:number"</span><span class="Delimiter">));</span> +get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"y:number"</span><span class="Delimiter">));</span> <span class="Comment">//: Containers can be copied around with a single instruction just like</span> <span class="Comment">//: numbers, no matter how large they are.</span> @@ -75,10 +74,8 @@ type_ordinal point_number = put<span class="Delimiter">(</span>Type_ordinal<span get_or_insert<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>kind = CONTAINER<span class="Delimiter">;</span> get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>name = <span class="Constant">"point-number"</span><span class="Delimiter">;</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new type_tree<span class="Delimiter">(</span>point<span class="Delimiter">));</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"xy"</span><span class="Delimiter">);</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new type_tree<span class="Delimiter">(</span>number<span class="Delimiter">));</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"z"</span><span class="Delimiter">);</span> +get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"xy:point"</span><span class="Delimiter">));</span> +get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> point_number<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"z:number"</span><span class="Delimiter">));</span> <span class="Delimiter">:(scenario copy_handles_nested_container_elements)</span> recipe main [ @@ -125,18 +122,23 @@ if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value assert<span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left && !type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> +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> + raise_error << <span class="Constant">"no such type "</span> << type<span class="Delimiter">-></span>value << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> type_info t = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// size of a container is the sum of the sizes of its elements</span> long long int result = <span class="Constant">0</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>t<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// todo: strengthen assertion to disallow mutual type recursion</span> - if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>value == type<span class="Delimiter">-></span>value<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">-></span>value == type<span class="Delimiter">-></span>value<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise_error << <span class="Constant">"container "</span> << t<span class="Delimiter">.</span>name << <span class="Constant">" can't include itself as a member</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// End size_of(type) Container Cases</span> - result += size_of<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + reagent tmp<span class="Delimiter">;</span> + tmp<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*type<span class="Delimiter">);</span> + result += size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">(</span>tmp<span class="Delimiter">,</span> i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -166,7 +168,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case GET: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'get' expects exactly 2 ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'get' expects exactly 2 ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent base = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// new copy for every invocation</span> @@ -195,7 +197,7 @@ case GET: <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_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> + 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> << names_to_string_without_quotes<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> << names_to_string_without_quotes<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> @@ -206,7 +208,7 @@ case GET: <span class="Delimiter">{</span> <span class="Comment">// Update GET base in Run</span> long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> if <span class="Delimiter">(</span>base_address == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 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>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<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> type_ordinal base_type = base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">;</span> @@ -215,12 +217,12 @@ case GET: <span class="Delimiter">{</span> long long int src = base_address<span class="Delimiter">;</span> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < offset<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// End GET field Cases</span> - src += size_of<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + src += size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">(</span>base<span class="Delimiter">,</span> i<span class="Delimiter">));</span> <span class="Delimiter">}</span> trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src << end<span class="Delimiter">();</span> reagent tmp = element_type<span class="Delimiter">(</span>base<span class="Delimiter">,</span> offset<span class="Delimiter">);</span> tmp<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>src<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << debug_string<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << names_to_string<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>tmp<span class="Delimiter">));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -232,8 +234,7 @@ const reagent element_type<span class="Delimiter">(</span>const reagent& can assert<span class="Delimiter">(</span>!get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> const type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">);</span> - reagent element<span class="Delimiter">;</span> - element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset_value<span class="Delimiter">));</span> + reagent element = info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset_value<span class="Delimiter">);</span> <span class="Comment">// End element_type Special-cases</span> <span class="Identifier">return</span> element<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -275,7 +276,7 @@ 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 12:point-number/raw, 1:offset' should write to number but 15 has type <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> @@ -304,7 +305,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case GET_ADDRESS: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'get-address' expects exactly 2 ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>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' expects exactly 2 ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent base = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> @@ -335,9 +336,9 @@ case GET_ADDRESS: <span class="Delimiter">{</span> <span class="Comment">// same type as for GET..</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> + element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span><span class="Constant">"address"</span><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_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> + 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> << names_to_string_without_quotes<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> << names_to_string_without_quotes<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> @@ -348,7 +349,7 @@ case GET_ADDRESS: <span class="Delimiter">{</span> <span class="Comment">// Update GET_ADDRESS base in Run</span> long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> if <span class="Delimiter">(</span>base_address == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 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>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<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> type_ordinal base_type = base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">;</span> @@ -357,7 +358,7 @@ case GET_ADDRESS: <span class="Delimiter">{</span> long long int result = base_address<span class="Delimiter">;</span> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < offset<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// End GET_ADDRESS field Cases</span> - result += size_of<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + result += size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">(</span>base<span class="Delimiter">,</span> i<span class="Delimiter">));</span> <span class="Delimiter">}</span> trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << result << end<span class="Delimiter">();</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> @@ -396,7 +397,7 @@ recipe main [ <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 12:boolbool, 1:offset' should write to <address : <boolean : <>>> but 15 has type boolean</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> @@ -407,10 +408,8 @@ container foo [ y:number ] <span class="traceContains">+parse: --- defining container foo</span> -<span class="traceContains">+parse: element name: x</span> -<span class="traceContains">+parse: type: 1</span> -<span class="traceContains">+parse: element name: y</span> -<span class="traceContains">+parse: type: 1</span> +<span class="traceContains">+parse: element: x: "number"</span> +<span class="traceContains">+parse: element: y: "number"</span> <span class="Delimiter">:(scenario container_use_before_definition)</span> container foo [ @@ -424,12 +423,15 @@ container bar [ ] <span class="traceContains">+parse: --- defining container foo</span> <span class="traceContains">+parse: type number: 1000</span> -<span class="traceContains">+parse: element name: x</span> -<span class="traceContains">+parse: type: 1</span> -<span class="traceContains">+parse: element name: y</span> -<span class="traceContains">+parse: type: 1001</span> +<span class="traceContains">+parse: element: x: "number"</span> +<span class="Comment"># todo: brittle</span> +<span class="Comment"># type bar is unknown at this point, but we assign it a number</span> +<span class="traceContains">+parse: element: y: "bar"</span> +<span class="Comment"># later type bar geon</span> <span class="traceContains">+parse: --- defining container bar</span> <span class="traceContains">+parse: type number: 1001</span> +<span class="traceContains">+parse: element: x: "number"</span> +<span class="traceContains">+parse: element: y: "number"</span> <span class="Delimiter">:(before "End Command Handlers")</span> else if <span class="Delimiter">(</span>command == <span class="Constant">"container"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -456,28 +458,33 @@ void insert_container<span class="Delimiter">(</span>const string& command<s 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> - <span class="Comment">// End insert_container Special Definitions(element)</span> - istringstream inner<span class="Delimiter">(</span>element<span class="Delimiter">);</span> - 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> 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> - <span class="Comment">// types can contain integers, like for array sizes</span> - && !is_integer<span class="Delimiter">(</span>type_name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - *curr_type = new type_tree<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<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">" type: "</span> << get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - <span class="Delimiter">}</span> - info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new_type<span class="Delimiter">);</span> + info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span>element<span class="Delimiter">));</span> + replace_unknown_types_with_unique_ordinals<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>type<span class="Delimiter">,</span> info<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: "</span> << to_string<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">())</span> << end<span class="Delimiter">();</span> + <span class="Comment">// End Load Container Element Definition</span> <span class="Delimiter">}</span> - assert<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">)</span> == SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>element_names<span class="Delimiter">));</span> info<span class="Delimiter">.</span>size = SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> <span class="Delimiter">}</span> +void replace_unknown_types_with_unique_ordinals<span class="Delimiter">(</span>type_tree* type<span class="Delimiter">,</span> const type_info& info<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + type<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + else if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// sometimes types will contain non-type tags, like numbers for the size of an array</span> + type<span class="Delimiter">-></span>value = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Comment">// End insert_container Special-cases</span> + else if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>name != <span class="Constant">"->"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// used in recipe types</span> + put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span> + type<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + replace_unknown_types_with_unique_ordinals<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> info<span class="Delimiter">);</span> + replace_unknown_types_with_unique_ordinals<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> info<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + void skip_bracket<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> string message<span class="Delimiter">)</span> <span class="Delimiter">{</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">()</span> != <span class="Constant">'['</span><span class="Delimiter">)</span> @@ -513,9 +520,8 @@ for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</ if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> Type_ordinal<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)).</span>name<span class="Delimiter">);</span> <span class="Comment">// todo: why do I explicitly need to provide this?</span> - for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>Type<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)).</span>elements<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - delete Type<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)).</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> - <span class="Delimiter">}</span> + for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>Type<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)).</span>elements<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> + Type<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)).</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>clear<span class="Delimiter">();</span> Type<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> Recently_added_types<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> @@ -569,35 +575,30 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <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> recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<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">"--- check for invalid types in recipe "</span> << caller<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<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>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - check_or_set_invalid_types<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> - maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"'"</span>+inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span>+<span class="Constant">"'"</span><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>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - check_or_set_invalid_types<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> - maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"'"</span>+inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span>+<span class="Constant">"'"</span><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>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + check_or_set_invalid_types<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"'"</span>+to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span>+<span class="Constant">"'"</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>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + check_or_set_invalid_types<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"'"</span>+to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span>+<span class="Constant">"'"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// End check_or_set_invalid_types</span> <span class="Delimiter">}</span> -void check_or_set_invalid_types<span class="Delimiter">(</span>type_tree* type<span class="Delimiter">,</span> const string_tree* type_name<span class="Delimiter">,</span> const string& block<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Comment">// can't assert that type_name is non-null, even at the top of a recursive call tree</span> +void check_or_set_invalid_types<span class="Delimiter">(</span>type_tree* type<span class="Delimiter">,</span> const string& block<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// will throw a more precise error elsewhere</span> <span class="Comment">// End Container Type Checks</span> if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> 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> + assert<span class="Delimiter">(</span>!type<span class="Delimiter">-></span>name<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> + type<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> else - raise_error << block << <span class="Constant">"missing type in "</span> << name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << block << <span class="Constant">"unknown type "</span> << type<span class="Delimiter">-></span>name << <span class="Constant">" 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> + check_or_set_invalid_types<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<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> block<span class="Delimiter">,</span> name<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario container_unknown_field)</span> @@ -615,10 +616,8 @@ container foo [ y:number ] <span class="traceContains">+parse: --- defining container foo</span> -<span class="traceContains">+parse: element name: x</span> -<span class="traceContains">+parse: type: 1</span> -<span class="traceContains">+parse: element name: y</span> -<span class="traceContains">+parse: type: 1</span> +<span class="traceContains">+parse: element: x: "number"</span> +<span class="traceContains">+parse: element: y: "number"</span> <span class="Delimiter">:(before "End Transform All")</span> check_container_field_types<span class="Delimiter">();</span> @@ -629,27 +628,12 @@ void check_container_field_types<span class="Delimiter">()</span> <span class="D const type_info& info = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> <span class="Comment">// Check Container Field Types(info)</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>info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - check_invalid_types<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> maybe<span class="Delimiter">(</span>info<span class="Delimiter">.</span>name<span class="Delimiter">),</span> info<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - <span class="Delimiter">}</span> -<span class="Delimiter">}</span> - -void check_invalid_types<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < 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> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const 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>index<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>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - check_invalid_types<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> - 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">"'"</span>+inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span>+<span class="Constant">"'"</span><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>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - check_invalid_types<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> - 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">"'"</span>+inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span>+<span class="Constant">"'"</span><span class="Delimiter">);</span> - <span class="Delimiter">}</span> + check_invalid_types<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> maybe<span class="Delimiter">(</span>info<span class="Delimiter">.</span>name<span class="Delimiter">),</span> info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -void check_invalid_types<span class="Delimiter">(</span>type_tree* type<span class="Delimiter">,</span> const string& block<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void check_invalid_types<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">,</span> const string& block<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// will throw a more precise error elsewhere</span> - <span class="Comment">// End Container Type Checks</span> if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>!type<span class="Delimiter">-></span>left && !type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> @@ -660,14 +644,27 @@ void check_invalid_types<span class="Delimiter">(</span>type_tree* type<span cla check_invalid_types<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> block<span class="Delimiter">,</span> name<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="SalientComment">//:: Construct types out of their constituent fields. Doesn't currently do</span> -<span class="SalientComment">//:: type-checking but *does* match sizes.</span> +<span class="SalientComment">//:: Construct types out of their constituent fields.</span> + +<span class="Delimiter">:(scenario merge)</span> +container foo [ + x:number + y:number +] + +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> +] +<span class="traceContains">+mem: storing 3 in location 1</span> +<span class="traceContains">+mem: storing 4 in location 2</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> MERGE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"merge"</span><span class="Delimiter">,</span> MERGE<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case MERGE: <span class="Delimiter">{</span> + <span class="Comment">// type-checking in a separate transform below</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> @@ -679,17 +676,184 @@ case MERGE: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(scenario merge)</span> -container foo [ - x:number - y:number +<span class="Comment">//: type-check 'merge' to avoid interpreting numbers as addresses</span> + +<span class="Delimiter">:(scenario merge_check)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:point<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> ] +$error: <span class="Constant">0</span> +<span class="Delimiter">:(scenario merge_check_missing_element)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ - <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> + <span class="Constant">1</span>:point<span class="Special"> <- </span>merge <span class="Constant">3</span> ] -<span class="traceContains">+mem: storing 3 in location 1</span> -<span class="traceContains">+mem: storing 4 in location 2</span> +<span class="traceContains">+error: main: too few ingredients in '1:point <- merge 3'</span> + +<span class="Delimiter">:(scenario merge_check_extra_element)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:point<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">,</span> <span class="Constant">5</span> +] +<span class="traceContains">+error: main: too many ingredients in '1:point <- merge 3, 4, 5'</span> + +<span class="Comment">//: We want to avoid causing memory corruption, but other than that we want to</span> +<span class="Comment">//: be flexible in how we construct containers of containers. It should be</span> +<span class="Comment">//: equally easy to define a container out of primitives or intermediate</span> +<span class="Comment">//: container fields.</span> + +<span class="Delimiter">:(scenario merge_check_recursive_containers)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:point<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> + <span class="Constant">1</span>:point-number<span class="Special"> <- </span>merge <span class="Constant">1</span>:point<span class="Delimiter">,</span> <span class="Constant">5</span> +] +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_check_recursive_containers_2)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:point<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> + <span class="Constant">2</span>:point-number<span class="Special"> <- </span>merge <span class="Constant">1</span>:point +] +<span class="traceContains">+error: main: too few ingredients in '2:point-number <- merge 1:point'</span> + +<span class="Delimiter">:(scenario merge_check_recursive_containers_3)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:point-number<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">,</span> <span class="Constant">5</span> +] +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_check_recursive_containers_4)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:point-number<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> +] +<span class="traceContains">+error: main: too few ingredients in '1:point-number <- merge 3, 4'</span> + +<span class="Comment">//: Since a container can be merged in several ways, we need to be able to</span> +<span class="Comment">//: backtrack through different possibilities. Later we'll allow creating</span> +<span class="Comment">//: exclusive containers which contain just one of rather than all of their</span> +<span class="Comment">//: elements. That will also require backtracking capabilities. Here's the</span> +<span class="Comment">//: state we need to maintain for backtracking:</span> + +<span class="Delimiter">:(before "End Types")</span> +struct merge_check_point <span class="Delimiter">{</span> + reagent container<span class="Delimiter">;</span> + long long int container_element_index<span class="Delimiter">;</span> + merge_check_point<span class="Delimiter">(</span>const reagent& c<span class="Delimiter">,</span> long long int i<span class="Delimiter">)</span> :container<span class="Delimiter">(</span>c<span class="Delimiter">),</span> container_element_index<span class="Delimiter">(</span>i<span class="Delimiter">)</span> <span class="Delimiter">{}</span> +<span class="Delimiter">};</span> + +struct merge_check_state <span class="Delimiter">{</span> + stack<merge_check_point> data<span class="Delimiter">;</span> +<span class="Delimiter">};</span> + +<span class="Delimiter">:(before "End Checks")</span> +Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_merge_calls<span class="Delimiter">);</span> +<span class="Delimiter">:(code)</span> +void check_merge_calls<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<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">"--- type-check merge instructions in recipe "</span> << caller<span class="Delimiter">.</span>name << end<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>caller<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const instruction& inst = caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name != <span class="Constant">"merge"</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'merge' should yield a single product in '"</span> << to_string<span class="Delimiter">(</span>inst<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">continue</span><span class="Delimiter">;</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 product While Type-checking Merge</span> + type_ordinal product_type = product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>product_type == <span class="Constant">0</span> || !contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> product_type<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'merge' should yield a container in '"</span> << to_string<span class="Delimiter">(</span>inst<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">continue</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + const type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> product_type<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind != CONTAINER && info<span class="Delimiter">.</span>kind != EXCLUSIVE_CONTAINER<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'merge' should yield a container in '"</span> << to_string<span class="Delimiter">(</span>inst<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">continue</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + check_merge_call<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">,</span> product<span class="Delimiter">,</span> caller<span class="Delimiter">,</span> inst<span class="Delimiter">);</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> + +void check_merge_call<span class="Delimiter">(</span>const vector<reagent>& ingredients<span class="Delimiter">,</span> const reagent& product<span class="Delimiter">,</span> const recipe& caller<span class="Delimiter">,</span> const instruction& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int ingredient_index = <span class="Constant">0</span><span class="Delimiter">;</span> + merge_check_state state<span class="Delimiter">;</span> + state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>push<span class="Delimiter">(</span>merge_check_point<span class="Delimiter">(</span>product<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">));</span> + while <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << ingredient_index << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>ingredient_index >= SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"too few ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<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="Delimiter">;</span> + <span class="Delimiter">}</span> + reagent& container = state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container<span class="Delimiter">;</span> + type_info& container_info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> container<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + switch <span class="Delimiter">(</span>container_info<span class="Delimiter">.</span>kind<span class="Delimiter">)</span> <span class="Delimiter">{</span> + case CONTAINER: <span class="Delimiter">{</span> + reagent expected_ingredient = element_type<span class="Delimiter">(</span>container<span class="Delimiter">,</span> state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking container "</span> << to_string<span class="Delimiter">(</span>container<span class="Delimiter">)</span> << <span class="Constant">" || "</span> << to_string<span class="Delimiter">(</span>expected_ingredient<span class="Delimiter">)</span> << <span class="Constant">" vs ingredient "</span> << ingredient_index << end<span class="Delimiter">();</span> + <span class="Comment">// if the current element is the ingredient we expect, move on to the next element/ingredient</span> + if <span class="Delimiter">(</span>types_coercible<span class="Delimiter">(</span>expected_ingredient<span class="Delimiter">,</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + ++ingredient_index<span class="Delimiter">;</span> + ++state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> + state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredient_index < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">))</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"too many ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<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="Delimiter">;</span> + <span class="Delimiter">}</span> + ++state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Comment">// if not, maybe it's a field of the current element</span> + else <span class="Delimiter">{</span> + <span class="Comment">// no change to ingredient_index</span> + state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>push<span class="Delimiter">(</span>merge_check_point<span class="Delimiter">(</span>expected_ingredient<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">));</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Comment">// End valid_merge Cases</span> + default: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>container<span class="Delimiter">,</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"incorrect type of ingredient "</span> << ingredient_index << <span class="Constant">" in '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + cerr << <span class="Constant">" expected "</span> << debug_string<span class="Delimiter">(</span>container<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + cerr << <span class="Constant">" got "</span> << debug_string<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">))</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + ++ingredient_index<span class="Delimiter">;</span> + <span class="Comment">// ++state.data.top().container_element_index; // unnecessary, but wouldn't do any harm</span> + do <span class="Delimiter">{</span> + state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredient_index < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">))</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"too many ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<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="Delimiter">;</span> + <span class="Delimiter">}</span> + ++state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index<span class="Delimiter">;</span> + <span class="Delimiter">}</span> while <span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">));</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Comment">// never gets here</span> + assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario merge_check_product)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>merge <span class="Constant">3</span> +] +<span class="traceContains">+error: main: 'merge' should yield a container in '1:number <- merge 3'</span> + +<span class="Delimiter">:(before "End Includes")</span> +<span class="PreProc">#include </span><span class="Constant"><stack></span> +using std::stack<span class="Delimiter">;</span> </pre> </body> </html> diff --git a/html/031address.cc.html b/html/031address.cc.html index a2da3614..54b8edd3 100644 --- a/html/031address.cc.html +++ b/html/031address.cc.html @@ -60,7 +60,7 @@ recipe main [ <span class="Delimiter">:(before "long long int base = x.value" following "void write_memory(reagent x, vector<double> data)")</span> canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"can't write to location 0 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 << <span class="Constant">"can't write to location 0 in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<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="Delimiter">;</span> <span class="Delimiter">}</span> @@ -119,11 +119,14 @@ recipe foo [ <span class="Delimiter">:(after "bool is_mu_number(reagent r)")</span> if <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span class="Delimiter">:(after "Update product While Type-checking Merge")</span> +if <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Delimiter">:(code)</span> bool canonize_type<span class="Delimiter">(</span>reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> while <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"lookup"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type || r<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="Delimiter">{</span> - raise_error << <span class="Constant">"can't lookup non-address: "</span> << r<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">": "</span> << debug_string<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"can't lookup non-address: "</span> << to_string<span class="Delimiter">(</span>r<span class="Delimiter">)</span> << <span class="Constant">": "</span> << to_string<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> drop_from_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> @@ -135,24 +138,17 @@ bool canonize_type<span class="Delimiter">(</span>reagent& r<span class="Del void drop_from_type<span class="Delimiter">(</span>reagent& r<span class="Delimiter">,</span> string expected_type<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"can't drop "</span> << expected_type << <span class="Constant">" from "</span> << debug_string<span class="Delimiter">(</span>r<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"can't drop "</span> << expected_type << <span class="Constant">" from "</span> << to_string<span class="Delimiter">(</span>r<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><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><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value != expected_type<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"can't drop "</span> << expected_type << <span class="Constant">" from "</span> << debug_string<span class="Delimiter">(</span>r<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name != expected_type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << <span class="Constant">"can't drop2 "</span> << expected_type << <span class="Constant">" from "</span> << to_string<span class="Delimiter">(</span>r<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> type_tree* tmp = r<span class="Delimiter">.</span>type<span class="Delimiter">;</span> r<span class="Delimiter">.</span>type = tmp<span class="Delimiter">-></span>right<span class="Delimiter">;</span> tmp<span class="Delimiter">-></span>right = <span class="Constant">NULL</span><span class="Delimiter">;</span> delete tmp<span class="Delimiter">;</span> - <span class="Comment">// property</span> - if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">)</span> <span class="Delimiter">{</span> - string_tree* tmp2 = r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">;</span> - r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = tmp2<span class="Delimiter">-></span>right<span class="Delimiter">;</span> - tmp2<span class="Delimiter">-></span>right = <span class="Constant">NULL</span><span class="Delimiter">;</span> - delete tmp2<span class="Delimiter">;</span> - <span class="Delimiter">}</span> <span class="Delimiter">}</span> void drop_one_lookup<span class="Delimiter">(</span>reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -226,7 +222,7 @@ recipe main [ <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Constant">3</span>:number<span class="Special"> <- </span>copy *<span class="Constant">1</span>:address:number ] -<span class="traceContains">+parse: ingredient: {"1": <"address" : <"number" : <>>>, "lookup": <>}</span> +<span class="traceContains">+parse: ingredient: 1: ("address" "number"), {"lookup": ()}</span> <span class="traceContains">+mem: storing 34 in location 3</span> <span class="Delimiter">:(before "End Parsing reagent")</span> @@ -237,7 +233,6 @@ recipe main [ <span class="Delimiter">}</span> if <span class="Delimiter">(</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise_error << <span class="Constant">"illegal name "</span> << original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>first = name<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="SalientComment">//:: helpers for debugging</span> diff --git a/html/032array.cc.html b/html/032array.cc.html index 2dde32d7..b60c44c9 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -55,7 +55,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case CREATE_ARRAY: <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="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">"'create-array' needs one product and no ingredients but got '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'create-array' needs one product and no ingredients but got '"</span> << to_string<span class="Delimiter">(</span>inst<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> 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> @@ -65,16 +65,16 @@ case CREATE_ARRAY: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<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">"create array of what? "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"create array of what? "</span> << to_string<span class="Delimiter">(</span>inst<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="Comment">// 'create-array' will need to check properties rather than types</span> - if <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second || !product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>right || !product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<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">"create array of what size? "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<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">"create array of what size? "</span> << to_string<span class="Delimiter">(</span>inst<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> - if <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>value<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">"'create-array' product should specify size of array after its element type, but got "</span> << product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>value << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<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">"'create-array' product should specify size of array after its element type, but got "</span> << product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<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> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -84,7 +84,7 @@ case CREATE_ARRAY: <span class="Delimiter">{</span> reagent product = current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> canonize<span class="Delimiter">(</span>product<span class="Delimiter">);</span> long long int base_address = product<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - long long int array_size = to_integer<span class="Delimiter">(</span>product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + long long int array_size = to_integer<span class="Delimiter">(</span>product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span class="Comment">// initialize array size, so that size_of will work</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base_address<span class="Delimiter">,</span> array_size<span class="Delimiter">);</span> <span class="Comment">// in array elements</span> long long int size = size_of<span class="Delimiter">(</span>product<span class="Delimiter">);</span> <span class="Comment">// in locations</span> @@ -151,6 +151,38 @@ if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type &&a <span class="Identifier">return</span> <span class="Constant">1</span> + get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>array_element<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">));</span> <span class="Delimiter">}</span> +<span class="Comment">//: arrays are disallowed inside containers unless their length is fixed in</span> +<span class="Comment">//: advance</span> + +<span class="Delimiter">:(scenario container_contains_array)</span> +<span class="Special">% Hide_errors = true;</span> +container foo [ + x:array:number:<span class="Constant">3</span> +] +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario container_disallows_dynamic_array_element)</span> +<span class="Special">% Hide_errors = true;</span> +container foo [ + x:array:number +] +<span class="traceContains">+error: container 'foo' cannot determine size of element x</span> + +<span class="Delimiter">:(before "End Load Container Element Definition")</span> +<span class="Delimiter">{</span> + const type_tree* type = info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>type<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << <span class="Constant">"container '"</span> << name << <span class="Constant">"' doesn't specify type of array elements for "</span> << info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// array has no length</span> + raise_error << <span class="Constant">"container '"</span> << name << <span class="Constant">"' cannot determine size of element "</span> << info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> + <span class="SalientComment">//:: To access elements of an array, use 'index'</span> <span class="Delimiter">:(scenario index)</span> @@ -181,7 +213,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case INDEX: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'index' expects exactly 2 ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'index' expects exactly 2 ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent base = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> @@ -196,7 +228,7 @@ case INDEX: <span class="Delimiter">{</span> reagent element<span class="Delimiter">;</span> element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">));</span> if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>product<span class="Delimiter">,</span> 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">"'index' on "</span> << base<span class="Delimiter">.</span>original_string << <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> + 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">"'index' on "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">" can't be saved in "</span> << product<span class="Delimiter">.</span>original_string << <span class="Constant">"; type should be "</span> << names_to_string_without_quotes<span class="Delimiter">(</span>element<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> @@ -208,7 +240,7 @@ case INDEX: <span class="Delimiter">{</span> long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"base address is "</span> << base_address << end<span class="Delimiter">();</span> if <span class="Delimiter">(</span>base_address == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 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>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent offset = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> @@ -321,7 +353,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case INDEX_ADDRESS: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'index-address' expects exactly 2 ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'index-address' expects exactly 2 ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent base = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> @@ -334,10 +366,10 @@ case INDEX_ADDRESS: <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> canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">);</span> reagent element<span class="Delimiter">;</span> - element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">));</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> + element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span><span class="Constant">"address"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">),</span> + new type_tree<span class="Delimiter">(</span>*array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">)));</span> if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>product<span class="Delimiter">,</span> 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">"'index' on "</span> << base<span class="Delimiter">.</span>original_string << <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> + 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">"'index' on "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">" can't be saved in "</span> << product<span class="Delimiter">.</span>original_string << <span class="Constant">"; type should be "</span> << names_to_string_without_quotes<span class="Delimiter">(</span>element<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> @@ -348,7 +380,7 @@ case INDEX_ADDRESS: <span class="Delimiter">{</span> canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span> long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> if <span class="Delimiter">(</span>base_address == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 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>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent offset = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> @@ -408,7 +440,7 @@ recipe main [ <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/unsafe <span class="Constant">9</span>:address:number<span class="Special"> <- </span>index-address *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> <span class="Constant">0</span> ] -<span class="traceContains">+error: main: 'index' on *8:address:array:point can't be saved in 9:address:number; type should be <address : <point : <>>></span> +<span class="traceContains">+error: main: 'index' on *8:address:array:point can't be saved in 9:address:number; type should be (address point)</span> <span class="SalientComment">//:: compute the length of an array</span> @@ -429,7 +461,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case LENGTH: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'length' expects exactly 2 ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'length' expects exactly 2 ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent x = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> @@ -445,7 +477,7 @@ case LENGTH: <span class="Delimiter">{</span> reagent x = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 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>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<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> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> diff --git a/html/033exclusive_container.cc.html b/html/033exclusive_container.cc.html index f3e258c8..c26c885a 100644 --- a/html/033exclusive_container.cc.html +++ b/html/033exclusive_container.cc.html @@ -45,10 +45,8 @@ type_ordinal tmp = put<span class="Delimiter">(</span>Type_ordinal<span class="D get_or_insert<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>kind = EXCLUSIVE_CONTAINER<span class="Delimiter">;</span> get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>name = <span class="Constant">"number-or-point"</span><span class="Delimiter">;</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new type_tree<span class="Delimiter">(</span>number<span class="Delimiter">));</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"i"</span><span class="Delimiter">);</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new type_tree<span class="Delimiter">(</span>point<span class="Delimiter">));</span> -get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"p"</span><span class="Delimiter">);</span> +get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"i:number"</span><span class="Delimiter">));</span> +get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> tmp<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"p:point"</span><span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Comment">//: Tests in this layer often explicitly setup memory before reading it as an</span> @@ -72,8 +70,10 @@ if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == EXCL <span class="Comment">// (So like containers, it can't contain arrays.)</span> long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < t<span class="Delimiter">.</span>size<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - long long int tmp = size_of<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>tmp > result<span class="Delimiter">)</span> result = tmp<span class="Delimiter">;</span> + reagent tmp<span class="Delimiter">;</span> + tmp<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*type<span class="Delimiter">);</span> + long long int size = size_of<span class="Delimiter">(</span>variant_type<span class="Delimiter">(</span>tmp<span class="Delimiter">,</span> i<span class="Delimiter">));</span> + if <span class="Delimiter">(</span>size > result<span class="Delimiter">)</span> result = size<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// ...+1 for its tag.</span> <span class="Identifier">return</span> result+<span class="Constant">1</span><span class="Delimiter">;</span> @@ -115,7 +115,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span case MAYBE_CONVERT: <span class="Delimiter">{</span> const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'maybe-convert' expects exactly 2 ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'maybe-convert' expects exactly 2 ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent base = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> @@ -131,18 +131,16 @@ case MAYBE_CONVERT: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> reagent product = inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> if <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - const reagent& offset = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> - long long int tag = <span class="Constant">0</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - tag = to_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - tag = offset<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + reagent& offset = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + populate_value<span class="Delimiter">(</span>offset<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>offset<span class="Delimiter">.</span>value >= SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"invalid tag "</span> << offset<span class="Delimiter">.</span>value << <span class="Constant">" in '"</span> << to_string<span class="Delimiter">(</span>inst<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> - reagent variant = variant_type<span class="Delimiter">(</span>base<span class="Delimiter">,</span> tag<span class="Delimiter">);</span> - variant<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">),</span> variant<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + reagent variant = variant_type<span class="Delimiter">(</span>base<span class="Delimiter">,</span> offset<span class="Delimiter">.</span>value<span class="Delimiter">);</span> + variant<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span><span class="Constant">"address"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">),</span> variant<span class="Delimiter">.</span>type<span class="Delimiter">);</span> if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>product<span class="Delimiter">,</span> variant<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'maybe-convert "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">", "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>original_string << <span class="Constant">"' should write to "</span> << debug_string<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" but "</span> << product<span class="Delimiter">.</span>name << <span class="Constant">" has type "</span> << debug_string<span class="Delimiter">(</span>product<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'maybe-convert "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">", "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>original_string << <span class="Constant">"' should write to "</span> << to_string<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" but "</span> << product<span class="Delimiter">.</span>name << <span class="Constant">" has type "</span> << to_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> @@ -153,7 +151,7 @@ case MAYBE_CONVERT: <span class="Delimiter">{</span> canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span> long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> if <span class="Delimiter">(</span>base_address == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 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>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to access location 0 in '"</span> << to_string<span class="Delimiter">(</span>current_instruction<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> long long int tag = current_instruction<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> @@ -176,8 +174,7 @@ const reagent variant_type<span class="Delimiter">(</span>const reagent& can assert<span class="Delimiter">(</span>!get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> const type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>info<span class="Delimiter">.</span>kind == EXCLUSIVE_CONTAINER<span class="Delimiter">);</span> - reagent element<span class="Delimiter">;</span> - element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>tag<span class="Delimiter">));</span> + reagent element = info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>tag<span class="Delimiter">);</span> <span class="Comment">// End variant_type Special-cases</span> <span class="Identifier">return</span> element<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -190,8 +187,7 @@ recipe main [ <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> <span class="Constant">20</span>:address:number<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/unsafe<span class="Delimiter">,</span> <span class="Constant">1</span>:variant ] -<span class="traceContains">+error: main: 'maybe-convert 12:number-or-point/unsafe, 1:variant' should write to <address : <point : <>>> but 20 has type <address : <number : <>>></span> - +<span class="traceContains">+error: main: 'maybe-convert 12:number-or-point/unsafe, 1:variant' should write to (address point) but 20 has type (address number)</span> <span class="SalientComment">//:: Allow exclusive containers to be defined in mu code.</span> @@ -201,16 +197,31 @@ exclusive-container foo [ y:number ] <span class="traceContains">+parse: --- defining exclusive-container foo</span> -<span class="traceContains">+parse: element name: x</span> -<span class="traceContains">+parse: type: 1</span> -<span class="traceContains">+parse: element name: y</span> -<span class="traceContains">+parse: type: 1</span> +<span class="traceContains">+parse: element: x: "number"</span> +<span class="traceContains">+parse: element: y: "number"</span> <span class="Delimiter">:(before "End Command Handlers")</span> else if <span class="Delimiter">(</span>command == <span class="Constant">"exclusive-container"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> insert_container<span class="Delimiter">(</span>command<span class="Delimiter">,</span> EXCLUSIVE_CONTAINER<span class="Delimiter">,</span> in<span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span class="Comment">//: arrays are disallowed inside exclusive containers unless their length is</span> +<span class="Comment">//: fixed in advance</span> + +<span class="Delimiter">:(scenario exclusive_container_contains_array)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo [ + x:array:number:<span class="Constant">3</span> +] +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario exclusive_container_disallows_dynamic_array_element)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo [ + x:array:number +] +<span class="traceContains">+error: container 'foo' cannot determine size of element x</span> + <span class="SalientComment">//:: To construct exclusive containers out of variant types, use 'merge'.</span> <span class="Delimiter">:(scenario lift_to_exclusive_container)</span> exclusive-container foo [ @@ -220,14 +231,152 @@ exclusive-container foo [ recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> - <span class="Constant">2</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">1</span>:number - <span class="Constant">4</span>:foo<span class="Special"> <- </span>merge <span class="Constant">1</span>/x<span class="Delimiter">,</span> <span class="Constant">1</span>:number + <span class="Constant">2</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">1</span>:number <span class="Comment"># tag must be a literal when merging exclusive containers</span> + <span class="Constant">4</span>:foo<span class="Special"> <- </span>merge <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">1</span>:number ] <span class="traceContains">+mem: storing 0 in location 2</span> <span class="traceContains">+mem: storing 34 in location 3</span> <span class="traceContains">+mem: storing 1 in location 4</span> <span class="traceContains">+mem: storing 34 in location 5</span> +<span class="Comment">//: type-checking for 'merge' on exclusive containers</span> + +<span class="Delimiter">:(scenario merge_handles_exclusive_container)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo [ + x:number + y:bar +] +container bar [ + z:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">34</span> +] +<span class="traceContains">+mem: storing 0 in location 1</span> +<span class="traceContains">+mem: storing 34 in location 2</span> +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_requires_literal_tag_for_exclusive_container)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo [ + x:number + y:bar +] +container bar [ + z:number +] +recipe main [ + local-scope + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:foo<span class="Special"> <- </span>merge <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">34</span> +] +<span class="traceContains">+error: main: ingredient 0 of 'merge' should be a literal, for the tag of exclusive-container foo</span> + +<span class="Delimiter">:(before "End valid_merge Cases")</span> +case EXCLUSIVE_CONTAINER: <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>top<span class="Delimiter">().</span>container_element_index == <span class="Constant">0</span><span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking exclusive container "</span> << to_string<span class="Delimiter">(</span>container<span class="Delimiter">)</span> << <span class="Constant">" vs ingredient "</span> << ingredient_index << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"ingredient "</span> << ingredient_index << <span class="Constant">" of 'merge' should be a literal, for the tag of exclusive-container "</span> << container_info<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + reagent ingredient = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">);</span> <span class="Comment">// unnecessary copy just to keep this function from modifying caller</span> + populate_value<span class="Delimiter">(</span>ingredient<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>ingredient<span class="Delimiter">.</span>value >= SIZE<span class="Delimiter">(</span>container_info<span class="Delimiter">.</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"invalid tag at "</span> << ingredient_index << <span class="Constant">" for "</span> << container_info<span class="Delimiter">.</span>name << <span class="Constant">" in '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + reagent variant = variant_type<span class="Delimiter">(</span>container<span class="Delimiter">,</span> ingredient<span class="Delimiter">.</span>value<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"tag: "</span> << ingredient<span class="Delimiter">.</span>value << end<span class="Delimiter">();</span> + <span class="Comment">// replace union with its variant</span> + state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> + state<span class="Delimiter">.</span>data<span class="Delimiter">.</span>push<span class="Delimiter">(</span>merge_check_point<span class="Delimiter">(</span>variant<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">));</span> + ++ingredient_index<span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario merge_check_container_containing_exclusive_container)</span> +<span class="Special">% Hide_errors = true;</span> +container foo [ + x:number + y:bar +] +exclusive-container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">34</span> +] +<span class="traceContains">+mem: storing 23 in location 1</span> +<span class="traceContains">+mem: storing 1 in location 2</span> +<span class="traceContains">+mem: storing 34 in location 3</span> +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_check_container_containing_exclusive_container_2)</span> +<span class="Special">% Hide_errors = true;</span> +container foo [ + x:number + y:bar +] +exclusive-container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span> +] +<span class="traceContains">+error: main: too many ingredients in '1:foo <- merge 23, 1/y, 34, 35'</span> + +<span class="Delimiter">:(scenario merge_check_exclusive_container_containing_container)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo [ + x:number + y:bar +] +container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">34</span> +] +<span class="traceContains">+mem: storing 1 in location 1</span> +<span class="traceContains">+mem: storing 23 in location 2</span> +<span class="traceContains">+mem: storing 34 in location 3</span> +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_check_exclusive_container_containing_container_2)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo [ + x:number + y:bar +] +container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">23</span> +] +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_check_exclusive_container_containing_container_3)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo [ + x:number + y:bar +] +container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">23</span> +] +<span class="traceContains">+error: main: too few ingredients in '1:foo <- merge 1/y, 23'</span> + <span class="Comment">//: Since the different variants of an exclusive-container might have</span> <span class="Comment">//: different sizes, relax the size mismatch check for 'merge' instructions.</span> <span class="Delimiter">:(before "End size_mismatch(x) Cases")</span> diff --git a/html/034call.cc.html b/html/034call.cc.html index d2664036..036ea99d 100644 --- a/html/034call.cc.html +++ b/html/034call.cc.html @@ -16,7 +16,6 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } .traceContains { color: #008000; } .SalientComment { color: #00ffff; } .cSpecial { color: #008000; } -.PreProc { color: #c000c0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } @@ -132,7 +131,7 @@ inline const instruction& to_instruction<span class="Delimiter">(</span>cons <span class="Delimiter">:(after "Defined Recipe Checks")</span> <span class="Comment">// not a primitive; check that it's present in the book of recipes</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>operation<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">"undefined operation 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">"undefined operation in '"</span> << to_string<span class="Delimiter">(</span>inst<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> <span class="Delimiter">:(replace{} "default:" following "End Primitive Recipe Implementations")</span> @@ -200,10 +199,6 @@ while <span class="Delimiter">(</span>current_step_index<span class="Delimiter"> <span class="Comment">// todo: fail if no products returned</span> ++current_step_index<span class="Delimiter">();</span> <span class="Delimiter">}</span> - -<span class="Delimiter">:(before "End Includes")</span> -<span class="PreProc">#include </span><span class="Constant"><stack></span> -using std::stack<span class="Delimiter">;</span> </pre> </body> </html> diff --git a/html/035call_ingredient.cc.html b/html/035call_ingredient.cc.html index 640dc430..94021c56 100644 --- a/html/035call_ingredient.cc.html +++ b/html/035call_ingredient.cc.html @@ -75,7 +75,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case NEXT_INGREDIENT: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<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">"'next-ingredient' didn't expect any ingredients in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'next-ingredient' didn't expect any ingredients in '"</span> << to_string<span class="Delimiter">(</span>inst<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> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -174,7 +174,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case INGREDIENT: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'ingredient' expects exactly one ingredient, but got '"</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">"'ingredient' expects exactly one ingredient, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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">0</span><span class="Delimiter">))</span> && !is_mu_number<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> <span class="Delimiter">{</span> diff --git a/html/036call_reply.cc.html b/html/036call_reply.cc.html index 89005838..2334a5c4 100644 --- a/html/036call_reply.cc.html +++ b/html/036call_reply.cc.html @@ -98,6 +98,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">:(code)</span> void check_types_of_reply_instructions<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<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">"--- check types of reply instructions in recipe "</span> << caller<span class="Delimiter">.</span>name << end<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>caller<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> const instruction& caller_instruction = caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> if <span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> @@ -113,14 +114,13 @@ void check_types_of_reply_instructions<span class="Delimiter">(</span>recipe_ord <span class="Identifier">break</span><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>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"reply ingredient "</span> << reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string << <span class="Constant">" can't be saved in "</span> << caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - reagent lhs = reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - canonize_type<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> - reagent rhs = caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - canonize_type<span class="Delimiter">(</span>rhs<span class="Delimiter">);</span> - raise_error << debug_string<span class="Delimiter">(</span>lhs<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << debug_string<span class="Delimiter">(</span>rhs<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Comment">// End reply Type Mismatch Error</span> + reagent lhs = reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + canonize_type<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> + reagent rhs = caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + canonize_type<span class="Delimiter">(</span>rhs<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>rhs<span class="Delimiter">,</span> lhs<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"reply ingredient "</span> << lhs<span class="Delimiter">.</span>original_string << <span class="Constant">" can't be saved in "</span> << rhs<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << to_string<span class="Delimiter">(</span>lhs<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << to_string<span class="Delimiter">(</span>rhs<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">goto</span> finish_reply_check<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -130,16 +130,17 @@ void check_types_of_reply_instructions<span class="Delimiter">(</span>recipe_ord if <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> string_tree* tmp = property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">);</span> if <span class="Delimiter">(</span>!tmp || tmp<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'same-as-ingredient' metadata should take exactly one value in "</span> << reply_inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'same-as-ingredient' metadata should take exactly one value in "</span> << to_string<span class="Delimiter">(</span>reply_inst<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">goto</span> finish_reply_check<span class="Delimiter">;</span> <span class="Delimiter">}</span> long long int ingredient_index = to_integer<span class="Delimiter">(</span>tmp<span class="Delimiter">-></span>value<span class="Delimiter">);</span> if <span class="Delimiter">(</span>ingredient_index >= SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"too few ingredients in '"</span> << caller_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>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"too few ingredients in '"</span> << to_string<span class="Delimiter">(</span>caller_instruction<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">goto</span> finish_reply_check<span class="Delimiter">;</span> <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>!is_dummy<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> && caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name != caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>name<span class="Delimiter">)</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << caller_instruction<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"' should write to "</span> << caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>original_string << <span class="Constant">" rather than "</span> << caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!is_dummy<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> && !is_literal<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">))</span> && caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name != caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">)</span> << <span class="Constant">"' should write to "</span> << caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>original_string << <span class="Constant">" rather than "</span> << caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> finish_reply_check:<span class="Delimiter">;</span> diff --git a/html/038new.cc.html b/html/037new.cc.html index 07a6d9ec..b3a4ed1e 100644 --- a/html/038new.cc.html +++ b/html/037new.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 038new.cc</title> +<title>Mu - 037new.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -69,13 +69,13 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } type_ordinal shared = put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span> get_or_insert<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> shared<span class="Delimiter">).</span>name = <span class="Constant">"shared"</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Drop Address In lookup_memory(x)")</span> -if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"shared"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"shared"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"skipping refcount at "</span> << x<span class="Delimiter">.</span>value << end<span class="Delimiter">();</span> x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value+<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// skip refcount</span> drop_from_type<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Drop Address In canonize_type(r)")</span> -if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"shared"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"shared"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> drop_from_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -116,7 +116,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span case NEW: <span class="Delimiter">{</span> const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'new' requires one or two ingredients, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'new' requires one or two ingredients, but got "</span> << to_string<span class="Delimiter">(</span>inst<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="Comment">// End NEW Check Special-cases</span> @@ -130,7 +130,7 @@ case NEW: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>!product_of_new_is_valid<span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"product of 'new' has incorrect type: "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"product of 'new' has incorrect type: "</span> << to_string<span class="Delimiter">(</span>inst<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> @@ -160,7 +160,6 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">:(code)</span> void transform_new_to_allocate<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">"--- convert 'new' to 'allocate' 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 << "--- convert 'new' to 'allocate' for recipe " << get(Recipe, r).name << '\n';</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">// Convert 'new' To 'allocate'</span> @@ -170,7 +169,7 @@ void transform_new_to_allocate<span class="Delimiter">(</span>const recipe_ordin <span class="Comment">// End Post-processing(type_name) When Converting 'new'</span> type_tree* type = new_type_tree<span class="Delimiter">(</span>type_name<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>set_value<span class="Delimiter">(</span>size_of<span class="Delimiter">(</span>type<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"new"</span><span class="Delimiter">)</span> << <span class="Constant">"size of "</span> << debug_string<span class="Delimiter">(</span>type_name<span class="Delimiter">)</span> << <span class="Constant">" is "</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>value << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"new"</span><span class="Delimiter">)</span> << <span class="Constant">"size of "</span> << to_string<span class="Delimiter">(</span>type_name<span class="Delimiter">)</span> << <span class="Constant">" is "</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>value << end<span class="Delimiter">();</span> delete type<span class="Delimiter">;</span> delete type_name<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -223,14 +222,14 @@ case ALLOCATE: <span class="Delimiter">{</span> <span class="SalientComment">//:: ensure we never call 'allocate' directly; its types are not checked</span> <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case ALLOCATE: <span class="Delimiter">{</span> - raise << <span class="Constant">"never call 'allocate' directly'; always use 'new'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"never call 'allocate' directly'; always use 'new'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="SalientComment">//:: ensure we never call 'new' without translating it (unless we add special-cases later)</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case NEW: <span class="Delimiter">{</span> - raise << <span class="Constant">"no implementation for 'new'; why wasn't it translated to 'allocate'?</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"no implementation for 'new'; why wasn't it translated to 'allocate'? Please save a copy of your program and send it to Kartik.</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> @@ -336,7 +335,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case ABANDON: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'abandon' requires one ingredient, but got '"</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">"'abandon' requires one ingredient, but got '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> reagent types = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> @@ -364,7 +363,7 @@ case ABANDON: <span class="Delimiter">{</span> abandon<span class="Delimiter">(</span>address<span class="Delimiter">,</span> size_of<span class="Delimiter">(</span>types<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// clear the address</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"resetting location "</span> << address_location << end<span class="Delimiter">();</span> - Memory[address_location] = <span class="Constant">0</span><span class="Delimiter">;</span> + put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> address_location<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -378,15 +377,15 @@ void abandon<span class="Delimiter">(</span>long long int address<span class="De for <span class="Delimiter">(</span>long long int curr = address<span class="Delimiter">;</span> curr < address+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// append existing free list to address</span> - put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> address<span class="Delimiter">,</span> Free_list[size]<span class="Delimiter">);</span> - Free_list[size] = address<span class="Delimiter">;</span> + put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> address<span class="Delimiter">,</span> get_or_insert<span class="Delimiter">(</span>Free_list<span class="Delimiter">,</span> size<span class="Delimiter">));</span> + put<span class="Delimiter">(</span>Free_list<span class="Delimiter">,</span> size<span class="Delimiter">,</span> address<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "ensure_space(size)" following "case ALLOCATE")</span> -if <span class="Delimiter">(</span>Free_list[size]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Free_list<span class="Delimiter">,</span> size<span class="Delimiter">))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"abandon"</span><span class="Delimiter">)</span> << <span class="Constant">"picking up space from free-list of size "</span> << size << end<span class="Delimiter">();</span> - long long int result = Free_list[size]<span class="Delimiter">;</span> - Free_list[size] = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + long long int result = get_or_insert<span class="Delimiter">(</span>Free_list<span class="Delimiter">,</span> size<span class="Delimiter">);</span> + put<span class="Delimiter">(</span>Free_list<span class="Delimiter">,</span> size<span class="Delimiter">,</span> get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> result<span class="Delimiter">));</span> for <span class="Delimiter">(</span>long long int curr = result+<span class="Constant">1</span><span class="Delimiter">;</span> curr < result+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr<span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"memory in free list was not zeroed out: "</span> << curr << <span class="Constant">'/'</span> << result << <span class="Constant">"; somebody wrote to us after free!!!</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> @@ -464,27 +463,21 @@ if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span cl <span class="Comment">// decrement refcount of old address</span> if <span class="Delimiter">(</span>old_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> long long int old_refcount = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> old_address<span class="Delimiter">);</span> -<span class="CommentedCode">//? cerr << old_refcount << '\n';</span> -<span class="CommentedCode">//? assert(old_refcount > 0);</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"decrementing refcount of "</span> << old_address << <span class="Constant">": "</span> << old_refcount << <span class="Constant">" -> "</span> << <span class="Delimiter">(</span>old_refcount-<span class="Constant">1</span><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> old_address<span class="Delimiter">,</span> old_refcount-<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// perform the write</span> -<span class="CommentedCode">//? trace(9999, "mem") << "038new.cc:424: location " << x.value << " contains " << old_address << " with refcount " << get_or_insert(Memory, old_address) << end();</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << no_scientific<span class="Delimiter">(</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> << <span class="Constant">" in location "</span> << base << end<span class="Delimiter">();</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base<span class="Delimiter">,</span> new_address<span class="Delimiter">);</span> <span class="Comment">// increment refcount of new address</span> if <span class="Delimiter">(</span>new_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> long long int new_refcount = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> new_address<span class="Delimiter">);</span> -<span class="CommentedCode">//? assert(new_refcount >= 0); // == 0 only when new_address == old_address</span> + assert<span class="Delimiter">(</span>new_refcount >= <span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// == 0 only when new_address == old_address</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"incrementing refcount of "</span> << new_address << <span class="Constant">": "</span> << new_refcount << <span class="Constant">" -> "</span> << <span class="Delimiter">(</span>new_refcount+<span class="Constant">1</span><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> new_address<span class="Delimiter">,</span> new_refcount+<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// abandon old address if necessary</span> <span class="Comment">// do this after all refcount updates are done just in case old and new are identical</span> -<span class="CommentedCode">//? if (get_or_insert(Memory, old_address) < 0) {</span> -<span class="CommentedCode">//? DUMP("");</span> -<span class="CommentedCode">//? }</span> assert<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> old_address<span class="Delimiter">)</span> >= <span class="Constant">0</span><span class="Delimiter">);</span> if <span class="Delimiter">(</span>old_address && get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> old_address<span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// lookup_memory without drop_one_lookup {</span> @@ -494,7 +487,6 @@ if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span cl drop_from_type<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> drop_from_type<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> <span class="Comment">// }</span> -<span class="CommentedCode">//? cerr << "ABANDON\n";</span> abandon<span class="Delimiter">(</span>old_address<span class="Delimiter">,</span> size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Identifier">return</span><span class="Delimiter">;</span> @@ -688,9 +680,7 @@ string read_mu_string<span class="Delimiter">(</span>long long int address<span <span class="Delimiter">}</span> bool is_mu_type_literal<span class="Delimiter">(</span>reagent r<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? if (!r.properties.empty())</span> -<span class="CommentedCode">//? dump_property(r.properties.at(0).second, cerr);</span> - <span class="Identifier">return</span> is_literal<span class="Delimiter">(</span>r<span class="Delimiter">)</span> && !r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second && r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"type"</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> is_literal<span class="Delimiter">(</span>r<span class="Delimiter">)</span> && r<span class="Delimiter">.</span>type && r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"type"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> </body> diff --git a/html/038location_array.cc.html b/html/038location_array.cc.html new file mode 100644 index 00000000..4823670e --- /dev/null +++ b/html/038location_array.cc.html @@ -0,0 +1,77 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - 038location_array.cc</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +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; } +.Comment { color: #9090ff; } +.Delimiter { color: #a04060; } +.Identifier { color: #804000; } +.Constant { color: #00a0a0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +TO_LOCATION_ARRAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"to-location-array"</span><span class="Delimiter">,</span> TO_LOCATION_ARRAY<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case TO_LOCATION_ARRAY: <span class="Delimiter">{</span> + const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!is_shared_address_of_array_of_numbers<span class="Delimiter">(</span>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="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"product of 'to-location-array' has incorrect type: "</span> << to_string<span class="Delimiter">(</span>inst<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> +<span class="Delimiter">}</span> +<span class="Delimiter">:(code)</span> +bool is_shared_address_of_array_of_numbers<span class="Delimiter">(</span>reagent product<span class="Delimiter">)</span> <span class="Delimiter">{</span> + canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type || product<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> <span class="Constant">false</span><span class="Delimiter">;</span> + drop_from_type<span class="Delimiter">(</span>product<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type || product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + drop_from_type<span class="Delimiter">(</span>product<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type || product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + drop_from_type<span class="Delimiter">(</span>product<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type || product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"number"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</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="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case TO_LOCATION_ARRAY: <span class="Delimiter">{</span> + long long int array_size = SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + long long int allocation_size = array_size + <span class="Comment">/*</span><span class="Comment">refcount</span><span class="Comment">*/</span><span class="Constant">1</span> + <span class="Comment">/*</span><span class="Comment">length</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> + ensure_space<span class="Delimiter">(</span>allocation_size<span class="Delimiter">);</span> + const long long int result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span> + <span class="Comment">// initialize array refcount</span> + put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> result<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + <span class="Comment">// initialize array length</span> + put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> result+<span class="Constant">1</span><span class="Delimiter">,</span> array_size<span class="Delimiter">);</span> + <span class="Comment">// now copy over data</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < array_size<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> + put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> result+<span class="Constant">2</span>+i<span class="Delimiter">,</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/040brace.cc.html b/html/040brace.cc.html index a65f6e0f..3dbfd8d3 100644 --- a/html/040brace.cc.html +++ b/html/040brace.cc.html @@ -95,7 +95,7 @@ void transform_braces<span class="Delimiter">(</span>const recipe_ordinal r<span <span class="Delimiter">}</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"}"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"missing '{' in "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + raise_error << <span class="Constant">"missing '{' in "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> open_braces<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> @@ -148,8 +148,7 @@ void transform_braces<span class="Delimiter">(</span>const recipe_ordinal r<span <span class="Delimiter">}</span> <span class="Comment">// if implicit, compute target</span> reagent target<span class="Delimiter">;</span> - target<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">"offset"</span><span class="Delimiter">));</span> - target<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = new string_tree<span class="Delimiter">(</span><span class="Constant">"offset"</span><span class="Delimiter">);</span> + target<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span><span class="Constant">"offset"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"offset"</span><span class="Delimiter">));</span> target<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> if <span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise_error << inst<span class="Delimiter">.</span>old_name << <span class="Constant">" needs a '{' before</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> diff --git a/html/041jump_target.cc.html b/html/041jump_target.cc.html index 341cf3c2..b9354279 100644 --- a/html/041jump_target.cc.html +++ b/html/041jump_target.cc.html @@ -62,12 +62,12 @@ void transform_labels<span class="Delimiter">(</span>const recipe_ordinal r<span const 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> if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>label<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && inst<span class="Delimiter">.</span>label<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'+'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>offset<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">))</span> <span class="Delimiter">{</span> - offset[inst<span class="Delimiter">.</span>label] = i<span class="Delimiter">;</span> + put<span class="Delimiter">(</span>offset<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">,</span> i<span class="Delimiter">);</span> <span class="Delimiter">}</span> else <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">"duplicate label '"</span> << inst<span class="Delimiter">.</span>label << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> <span class="Comment">// have all jumps skip some random but noticeable and deterministic amount of code</span> - offset[inst<span class="Delimiter">.</span>label] = <span class="Constant">9999</span><span class="Delimiter">;</span> + put<span class="Delimiter">(</span>offset<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">,</span> <span class="Constant">9999</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -110,7 +110,7 @@ void replace_offset<span class="Delimiter">(</span>reagent& x<span class="De x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// no jump by default</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>offset[x<span class="Delimiter">.</span>name]-current_offset<span class="Delimiter">);</span> + x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>get<span class="Delimiter">(</span>offset<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">)</span> - current_offset<span class="Delimiter">);</span> <span class="Delimiter">}</span> bool is_jump_target<span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> diff --git a/html/042name.cc.html b/html/042name.cc.html index b39670fb..e3b73f35 100644 --- a/html/042name.cc.html +++ b/html/042name.cc.html @@ -109,7 +109,7 @@ void transform_names<span class="Delimiter">(</span>const recipe_ordinal r<span bool is_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> <span class="Comment">// End Null-type is_disqualified Exceptions</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> + 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> << to_string<span class="Delimiter">(</span>inst<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> @@ -140,9 +140,8 @@ type_ordinal skip_addresses<span class="Delimiter">(</span>type_tree* type<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> + 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>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>container<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name == name<span class="Delimiter">)</span> <span class="Identifier">return</span> i<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> @@ -220,10 +219,6 @@ $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> -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> @@ -237,7 +232,7 @@ recipe main [ <span class="Comment">// replace element names of containers with offsets</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_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> + 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> << to_string<span class="Delimiter">(</span>inst<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> @@ -279,7 +274,7 @@ recipe main [ <span class="Comment">// convert variant names of exclusive containers</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_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> + 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> << to_string<span class="Delimiter">(</span>inst<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> diff --git a/html/043space.cc.html b/html/043space.cc.html index 36e41bc1..777562dd 100644 --- a/html/043space.cc.html +++ b/html/043space.cc.html @@ -92,7 +92,7 @@ void absolutize<span class="Delimiter">(</span>reagent& x<span class="Delimi if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">)</span> || is_dummy<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</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> <span class="Identifier">return</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">": reagent not initialized: "</span> << x<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">": reagent not initialized: "</span> << x<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">,</span> space_base<span class="Delimiter">(</span>x<span class="Delimiter">)));</span> x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span><span class="Constant">"raw"</span><span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span> @@ -271,7 +271,7 @@ void try_reclaim_locals<span class="Delimiter">()</span> <span class="Delimiter" void rewrite_default_space_instruction<span class="Delimiter">(</span>instruction& curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> - raise_error << curr<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">" can't take any ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << to_string<span class="Delimiter">(</span>curr<span class="Delimiter">)</span> << <span class="Constant">" can't take any ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> curr<span class="Delimiter">.</span>name = <span class="Constant">"new"</span><span class="Delimiter">;</span> curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"location:type"</span><span class="Delimiter">));</span> curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"number-of-locals:literal"</span><span class="Delimiter">));</span> @@ -283,12 +283,12 @@ void rewrite_default_space_instruction<span class="Delimiter">(</span>instructio <span class="SalientComment">//:: all recipes must set default-space one way or another</span> <span class="Delimiter">:(before "End Globals")</span> -bool Warn_on_missing_default_space = <span class="Constant">false</span><span class="Delimiter">;</span> +bool Hide_missing_default_space_errors = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Checks")</span> Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_default_space<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> <span class="Delimiter">:(code)</span> void check_default_space<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!Warn_on_missing_default_space<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// skip previous core tests; this is only for mu code</span> + if <span class="Delimiter">(</span>Hide_missing_default_space_errors<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// skip previous core tests; this is only for mu code</span> const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> <span class="Comment">// skip scenarios (later layer)</span> <span class="Comment">// user code should never create recipes with underscores in their names</span> @@ -300,24 +300,24 @@ void check_default_space<span class="Delimiter">(</span>const recipe_ordinal r<s if <span class="Delimiter">(</span>caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name != <span class="Constant">"default-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">" does not seem to start with default-space or local-scope</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">" does not seem to start with default-space or local-scope</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="CommentedCode">//? cerr << maybe(caller.name) << " does not seem to start with default-space or local-scope\n" << '\n';</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">:(after "Load .mu Core")</span> -Warn_on_missing_default_space = <span class="Constant">true</span><span class="Delimiter">;</span> +Hide_missing_default_space_errors = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(after "Test Runs")</span> -Warn_on_missing_default_space = <span class="Constant">false</span><span class="Delimiter">;</span> +Hide_missing_default_space_errors = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(after "Running Main")</span> -Warn_on_missing_default_space = <span class="Constant">true</span><span class="Delimiter">;</span> +Hide_missing_default_space_errors = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> bool contains_non_special_name<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> long long int>::iterator p = Name[r]<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Name[r]<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>first<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>first<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"stash_"</span><span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// generated by rewrite_stashes_to_text</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>first<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"stash_"</span><span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// generated by rewrite_stashes_to_text (cross-layer)</span> if <span class="Delimiter">(</span>!is_special_name<span class="Delimiter">(</span>p<span class="Delimiter">-></span>first<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cerr << " " << Recipe[r].name << ": " << p->first << '\n';</span> +<span class="CommentedCode">//? cerr << " " << get(Recipe, r).name << ": " << p->first << '\n';</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> diff --git a/html/044space_surround.cc.html b/html/044space_surround.cc.html index 47e01b94..e58029c4 100644 --- a/html/044space_surround.cc.html +++ b/html/044space_surround.cc.html @@ -83,7 +83,7 @@ long long int space_base<span class="Delimiter">(</span>const reagent& x<spa <span class="Delimiter">}</span> long long int space_index<span class="Delimiter">(</span>const reagent& x<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 name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<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>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second || x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">-></span>right<span class="Delimiter">)</span> raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"/space metadata should take exactly one value in "</span> << x<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> diff --git a/html/045closure_name.cc.html b/html/045closure_name.cc.html index ae93ad02..5f1b3232 100644 --- a/html/045closure_name.cc.html +++ b/html/045closure_name.cc.html @@ -92,7 +92,7 @@ void collect_surrounding_spaces<span class="Delimiter">(</span>const recipe_ordi || !type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right || type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"location"</span><span class="Delimiter">)</span> || type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"slot 0 should always have type address:shared:array:location, but is "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"slot 0 should always have type address:shared:array:location, but is "</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">))</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> string_tree* s = property<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">),</span> <span class="Constant">"names"</span><span class="Delimiter">);</span> @@ -100,20 +100,24 @@ void collect_surrounding_spaces<span class="Delimiter">(</span>const recipe_ordi raise_error << <span class="Constant">"slot 0 requires a /names property in 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="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>s<span class="Delimiter">-></span>right<span class="Delimiter">)</span> raise_error << <span class="Constant">"slot 0 should have a single value in /names, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>s<span class="Delimiter">-></span>right<span class="Delimiter">)</span> raise_error << <span class="Constant">"slot 0 should have a single value in /names, but got "</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">))</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> const string& surrounding_recipe_name = s<span class="Delimiter">-></span>value<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>surrounding_recipe_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + raise_error << <span class="Constant">"slot 0 doesn't initialize its /names property in 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="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Surrounding_space<span class="Delimiter">,</span> r<span class="Delimiter">)</span> - && Surrounding_space[r] != get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> surrounding_recipe_name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"recipe "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="Constant">" can have only one 'surrounding' recipe but has "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> Surrounding_space[r]<span class="Delimiter">).</span>name << <span class="Constant">" and "</span> << surrounding_recipe_name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + && get<span class="Delimiter">(</span>Surrounding_space<span class="Delimiter">,</span> r<span class="Delimiter">)</span> != get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> surrounding_recipe_name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << <span class="Constant">"recipe "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="Constant">" can have only one 'surrounding' recipe but has "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Surrounding_space<span class="Delimiter">,</span> r<span class="Delimiter">)).</span>name << <span class="Constant">" and "</span> << surrounding_recipe_name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <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">"lexically surrounding space for recipe "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="Constant">" comes from "</span> << surrounding_recipe_name << end<span class="Delimiter">();</span> <span class="CommentedCode">//? cerr << "lexically surrounding space for recipe " << get(Recipe, r).name << " comes from " << surrounding_recipe_name << '\n';</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> surrounding_recipe_name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"can't find recipe providing surrounding space for "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="Constant">": "</span> << surrounding_recipe_name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"can't find recipe providing surrounding space for "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="Constant">": "</span> << surrounding_recipe_name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - Surrounding_space[r] = get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> surrounding_recipe_name<span class="Delimiter">);</span> + put<span class="Delimiter">(</span>Surrounding_space<span class="Delimiter">,</span> r<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> surrounding_recipe_name<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -142,7 +146,7 @@ long long int lookup_name<span class="Delimiter">(</span>const reagent& x<sp long long int lookup_name<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">,</span> const recipe_ordinal r<span class="Delimiter">,</span> set<recipe_ordinal>& done<span class="Delimiter">,</span> vector<recipe_ordinal>& path<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!Name[r]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> Name[r][x<span class="Delimiter">.</span>name]<span class="Delimiter">;</span> if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>done<span class="Delimiter">,</span> r<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"can't compute address of "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">" because "</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"can't compute address of "</span> << to_string<span class="Delimiter">(</span>x<span class="Delimiter">)</span> << <span class="Constant">" because "</span> << end<span class="Delimiter">();</span> for <span class="Delimiter">(</span>long long int i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>path<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise_error << path<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Constant">1</span><span class="Delimiter">)</span> << <span class="Constant">" requires computing names of "</span> << path<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -162,8 +166,8 @@ recipe_ordinal lookup_surrounding_recipe<span class="Delimiter">(</span>const re raise_error << <span class="Constant">"don't know surrounding recipe of "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - assert<span class="Delimiter">(</span>Surrounding_space[r]<span class="Delimiter">);</span> - <span class="Identifier">return</span> lookup_surrounding_recipe<span class="Delimiter">(</span>Surrounding_space[r]<span class="Delimiter">,</span> n-<span class="Constant">1</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Surrounding_space<span class="Delimiter">,</span> r<span class="Delimiter">));</span> + <span class="Identifier">return</span> lookup_surrounding_recipe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Surrounding_space<span class="Delimiter">,</span> r<span class="Delimiter">),</span> n-<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">//: weaken use-before-set detection just a tad</span> diff --git a/html/046global.cc.html b/html/046global.cc.html index bb3869e7..b9b8feea 100644 --- a/html/046global.cc.html +++ b/html/046global.cc.html @@ -115,7 +115,7 @@ $error: <span class="Constant">0</span> <span class="Delimiter">:(code)</span> bool is_global<span class="Delimiter">(</span>const reagent& x<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 name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<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>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"space"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second && x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"global"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/047check_type_by_name.cc.html b/html/047check_type_by_name.cc.html index 62456bf1..191d7255 100644 --- a/html/047check_type_by_name.cc.html +++ b/html/047check_type_by_name.cc.html @@ -14,13 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .traceContains { color: #008000; } -.Identifier { color: #804000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } -.CommentedCode { color: #6c6c6c; } +.Identifier { color: #804000; } --> </style> @@ -54,43 +53,49 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">:(code)</span> void check_or_set_types_by_name<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">"--- deduce types 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 << "--- deduce types for recipe " << get(Recipe, r).name << '\n';</span> map<string<span class="Delimiter">,</span> type_tree*> type<span class="Delimiter">;</span> - map<string<span class="Delimiter">,</span> string_tree*> type_name<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>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> 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> - deduce_missing_type<span class="Delimiter">(</span>type<span class="Delimiter">,</span> type_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> - check_type<span class="Delimiter">(</span>type<span class="Delimiter">,</span> type_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> + deduce_missing_type<span class="Delimiter">(</span>type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">));</span> + check_type<span class="Delimiter">(</span>type<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> - deduce_missing_type<span class="Delimiter">(</span>type<span class="Delimiter">,</span> type_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> - check_type<span class="Delimiter">(</span>type<span class="Delimiter">,</span> type_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> + deduce_missing_type<span class="Delimiter">(</span>type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">));</span> + check_type<span class="Delimiter">(</span>type<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> <span class="Delimiter">}</span> -void deduce_missing_type<span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> type_tree*>& type<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> string_tree*>& type_name<span class="Delimiter">,</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void deduce_missing_type<span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> type_tree*>& type<span class="Delimiter">,</span> reagent& x<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="Identifier">return</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - x<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*type[x<span class="Delimiter">.</span>name]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" <= "</span> << debug_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - assert<span class="Delimiter">(</span>!x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = new string_tree<span class="Delimiter">(</span>*type_name[x<span class="Delimiter">.</span>name]<span class="Delimiter">);</span> + x<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*get<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">));</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" <= "</span> << names_to_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> -void check_type<span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> type_tree*>& type<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> string_tree*>& type_name<span class="Delimiter">,</span> const reagent& x<span class="Delimiter">,</span> const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void check_type<span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> type_tree*>& type<span class="Delimiter">,</span> const reagent& x<span class="Delimiter">,</span> const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// if you use raw locations you're probably doing something unsafe</span> if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// might get filled in by other logic later</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" => "</span> << debug_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" => "</span> << names_to_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> put<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>type_name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> - put<span class="Delimiter">(</span>type_name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>type[x<span class="Delimiter">.</span>name]<span class="Delimiter">,</span> x<span class="Delimiter">.</span>type<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>get<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<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>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" used with multiple types</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>get<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">)-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!get<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">)-></span>right<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> << x<span class="Delimiter">.</span>name << <span class="Constant">" can't be just an array. What is it an array of?</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>!get<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">)-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="Constant">" can't determine the size of array variable "</span> << x<span class="Delimiter">.</span>name << <span class="Constant">". Either allocate it separately and make the type of "</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" address:shared:..., or specify the length of the array in the type of "</span> << x<span class="Delimiter">.</span>name << <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="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario transform_fills_in_missing_types)</span> @@ -127,6 +132,13 @@ recipe main [ *y<span class="Special"> <- </span>copy <span class="Constant">67</span> ] <span class="traceContains">+error: main: unknown type charcter in 'y:address:shared:charcter <- new character:type'</span> + +<span class="Delimiter">:(scenario array_type_without_size_fails)</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + x:array:number<span class="Special"> <- </span>merge <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">12</span><span class="Delimiter">,</span> <span class="Constant">13</span> +] +<span class="traceContains">+error: main can't determine the size of array variable x. Either allocate it separately and make the type of x address:shared:..., or specify the length of the array in the type of x.</span> </pre> </body> </html> diff --git a/html/050scenario.cc.html b/html/050scenario.cc.html index f43664f9..420826b2 100644 --- a/html/050scenario.cc.html +++ b/html/050scenario.cc.html @@ -147,7 +147,7 @@ long long int Num_core_mu_tests = <span class="Constant">0</span><span class="De <span class="Delimiter">:(after "Check For .mu Files")</span> Num_core_mu_tests = SIZE<span class="Delimiter">(</span>Scenarios<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Tests")</span> -Warn_on_missing_default_space = <span class="Constant">true</span><span class="Delimiter">;</span> +Hide_missing_default_space_errors = <span class="Constant">false</span><span class="Delimiter">;</span> time_t mu_time<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&mu_time<span class="Delimiter">);</span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">Mu tests: "</span> << ctime<span class="Delimiter">(</span>&mu_time<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>Scenarios<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -186,6 +186,10 @@ void run_mu_scenario<span class="Delimiter">(</span>const scenario& s<span c bind_special_scenario_names<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> transform_all<span class="Delimiter">();</span> run<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>front<span class="Delimiter">());</span> + if <span class="Delimiter">(</span>Passed && !Hide_errors && trace_count<span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">)</span> > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + Passed = <span class="Constant">false</span><span class="Delimiter">;</span> + ++Num_failures<span class="Delimiter">;</span> + <span class="Delimiter">}</span> if <span class="Delimiter">(</span>not_already_inside_test && Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> teardown<span class="Delimiter">();</span> ofstream fout<span class="Delimiter">((</span>Trace_dir+Trace_file<span class="Delimiter">).</span>c_str<span class="Delimiter">());</span> @@ -201,9 +205,9 @@ void run_mu_scenario<span class="Delimiter">(</span>const scenario& s<span c <span class="Comment">//: Watch out for redefinitions of scenario routines. We should never ever be</span> <span class="Comment">//: doing that, regardless of anything else.</span> <span class="Delimiter">:(scenarios run)</span> -<span class="Delimiter">:(scenario warn_on_redefine_scenario)</span> -<span class="Special">% Hide_warnings = true;</span> -<span class="Special">% Disable_redefine_warnings = true;</span> +<span class="Delimiter">:(scenario forbid_redefining_scenario_even_if_forced)</span> +<span class="Special">% Hide_errors = true;</span> +<span class="Special">% Disable_redefine_checks = true;</span> recipe scenario-foo [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> ] @@ -211,9 +215,9 @@ recipe scenario-foo [ recipe scenario-foo [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> ] -<span class="traceContains">+warn: redefining recipe scenario-foo</span> +<span class="traceContains">+error: redefining recipe scenario-foo</span> -<span class="Delimiter">:(after "bool warn_on_redefine(const string& recipe_name)")</span> +<span class="Delimiter">:(after "bool should_check_for_redefine(const string& recipe_name)")</span> if <span class="Delimiter">(</span>recipe_name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"scenario-"</span><span class="Delimiter">)</span> == <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="SalientComment">//:: The special instructions we want to support inside scenarios.</span> @@ -330,7 +334,21 @@ void check_memory<span class="Delimiter">(</span>const string& s<span class= skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> string _assign<span class="Delimiter">;</span> in >> _assign<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>_assign == <span class="Constant">"<-"</span><span class="Delimiter">);</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - double value = <span class="Constant">0</span><span class="Delimiter">;</span> in >> value<span class="Delimiter">;</span> + string rhs = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>rhs<span class="Delimiter">)</span> && !is_noninteger<span class="Delimiter">(</span>rhs<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> + <span class="Comment">// genuine test in a mu file</span> + raise_error << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << Current_scenario<span class="Delimiter">-></span>name << <span class="Constant">": location "</span> << address << <span class="Constant">" can't contain non-number "</span> << rhs << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + else + <span class="Comment">// just testing scenario support</span> + raise_error << <span class="Constant">"location "</span> << address << <span class="Constant">" can't contain non-number "</span> << rhs << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + Passed = <span class="Constant">false</span><span class="Delimiter">;</span> + ++Num_failures<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + double value = to_double<span class="Delimiter">(</span>rhs<span class="Delimiter">);</span> if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>locations_checked<span class="Delimiter">,</span> address<span class="Delimiter">))</span> raise_error << <span class="Constant">"duplicate expectation for location "</span> << address << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"checking location "</span> << address << end<span class="Delimiter">();</span> @@ -355,10 +373,9 @@ void check_memory<span class="Delimiter">(</span>const string& s<span class= void check_type<span class="Delimiter">(</span>const string& lhs<span class="Delimiter">,</span> istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> reagent x<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> - const string_tree* type_name = x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>type_name<span class="Delimiter">-></span>value == <span class="Constant">"array"</span> - && type_name<span class="Delimiter">-></span>right && type_name<span class="Delimiter">-></span>right<span class="Delimiter">-></span>value == <span class="Constant">"character"</span> - && !type_name<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"array"</span> + && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name == <span class="Constant">"character"</span> + && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">));</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> string _assign = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> @@ -372,6 +389,7 @@ void check_type<span class="Delimiter">(</span>const string& lhs<span class= check_string<span class="Delimiter">(</span>address<span class="Delimiter">,</span> literal<span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + <span class="Comment">// End Scenario Type Cases</span> raise_error << <span class="Constant">"don't know how to check memory for "</span> << lhs << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -449,6 +467,26 @@ recipe main [ <span class="traceContains">+run: checking location 3</span> <span class="traceContains">+run: checking location 4</span> +<span class="Delimiter">:(scenario memory_invalid_string_check)</span> +<span class="Special">% Scenario_testing_scenario = true;</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + memory-should-contain [ + <span class="Constant">1</span><span class="Special"> <- </span>[abc] + ] +] +<span class="traceContains">+error: location 1 can't contain non-number [abc]</span> + +<span class="Delimiter">:(scenario memory_check_with_comment)</span> +<span class="Special">% Scenario_testing_scenario = true;</span> +<span class="Special">% Hide_errors = true;</span> +recipe main [ + memory-should-contain [ + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">34</span> <span class="Comment"># comment</span> + ] +] +<span class="traceAbsent">-error: location 1 can't contain non-number 34 # comment</span> + <span class="Delimiter">:(code)</span> <span class="Comment">//: 'trace-should-contain' is like the '+' lines in our scenarios so far</span> <span class="Comment">// Like runs of contiguous '+' lines, order is important. The trace checks</span> @@ -630,7 +668,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case CHECK_TRACE_COUNT_FOR_LABEL: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'check-trace-for-label' requires exactly two ingredients, but got '"</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">"'check-trace-for-label' requires exactly two ingredients, but got '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_number<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> <span class="Delimiter">{</span> @@ -652,9 +690,8 @@ case CHECK_TRACE_COUNT_FOR_LABEL: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>count != expected_count<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// genuine test in a mu file</span> - raise_error << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << Current_scenario<span class="Delimiter">-></span>name << <span class="Constant">": "</span> << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"expected "</span> << expected_count << <span class="Constant">" lines in trace with label "</span> << label << <span class="Constant">" in trace: "</span><span class="Delimiter">;</span> + raise_error << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << Current_scenario<span class="Delimiter">-></span>name << <span class="Constant">": "</span> << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"expected "</span> << expected_count << <span class="Constant">" lines in trace with label "</span> << label << <span class="Constant">" in trace: "</span> << end<span class="Delimiter">();</span> DUMP<span class="Delimiter">(</span>label<span class="Delimiter">);</span> - raise_error<span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> <span class="Comment">// just testing scenario support</span> diff --git a/html/052tangle.cc.html b/html/052tangle.cc.html index 00bbfb45..dc26e9ea 100644 --- a/html/052tangle.cc.html +++ b/html/052tangle.cc.html @@ -118,13 +118,13 @@ void insert_fragments<span class="Delimiter">(</span>const recipe_ordinal r<span Fragments_used<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">);</span> ostringstream prefix<span class="Delimiter">;</span> prefix << <span class="Constant">'+'</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << <span class="Constant">'_'</span> << pass << <span class="Constant">'_'</span> << i<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Before_fragments<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Comment">// ok to use contains_key even though Before_fragments uses [],</span> + <span class="Comment">// because appending an empty recipe is a noop</span> + if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Before_fragments<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">))</span> append_fragment<span class="Delimiter">(</span>result<span class="Delimiter">,</span> Before_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">,</span> prefix<span class="Delimiter">.</span>str<span class="Delimiter">());</span> - <span class="Delimiter">}</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>inst<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>After_fragments<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>After_fragments<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">))</span> append_fragment<span class="Delimiter">(</span>result<span class="Delimiter">,</span> After_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">,</span> prefix<span class="Delimiter">.</span>str<span class="Delimiter">());</span> - <span class="Delimiter">}</span> <span class="Delimiter">}</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>steps<span class="Delimiter">.</span>swap<span class="Delimiter">(</span>result<span class="Delimiter">);</span> ++pass<span class="Delimiter">;</span> @@ -155,7 +155,7 @@ void append_fragment<span class="Delimiter">(</span>vector<instruction>&am for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> reagent& x = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> if <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"label"</span> && contains_key<span class="Delimiter">(</span>jump_targets<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"label"</span> && contains_key<span class="Delimiter">(</span>jump_targets<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> x<span class="Delimiter">.</span>name = prefix+x<span class="Delimiter">.</span>name<span class="Delimiter">;</span> <span class="Delimiter">}</span> base<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>inst<span class="Delimiter">);</span> diff --git a/html/053rewrite_stash.cc.html b/html/053rewrite_stash.cc.html index 6bef7eed..a076a54f 100644 --- a/html/053rewrite_stash.cc.html +++ b/html/053rewrite_stash.cc.html @@ -37,9 +37,10 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">:(code)</span> void rewrite_stashes_to_text<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<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">"--- rewrite 'stash' instructions in recipe "</span> << caller<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> if <span class="Delimiter">(</span>contains_named_locations<span class="Delimiter">(</span>caller<span class="Delimiter">))</span> rewrite_stashes_to_text_named<span class="Delimiter">(</span>caller<span class="Delimiter">);</span> - <span class="Comment">// in recipes without named locations, 'stash' is still not configurable</span> + <span class="Comment">// in recipes without named locations, 'stash' is still not extensible</span> <span class="Delimiter">}</span> bool contains_named_locations<span class="Delimiter">(</span>const recipe& caller<span class="Delimiter">)</span> <span class="Delimiter">{</span> diff --git a/html/054dilated_reagent.cc.html b/html/054dilated_reagent.cc.html index 55526228..900a3f8c 100644 --- a/html/054dilated_reagent.cc.html +++ b/html/054dilated_reagent.cc.html @@ -42,7 +42,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } recipe main [ <span class="Delimiter">{</span><span class="Constant">1</span>: number<span class="Delimiter">,</span> foo: bar<span class="Delimiter">}</span><span class="Special"> <- </span>copy <span class="Constant">34</span> ] -<span class="traceContains">+parse: product: {"1": "number", "foo": "bar"}</span> +<span class="traceContains">+parse: product: 1: "number", {"foo": "bar"}</span> <span class="Delimiter">:(scenario load_trailing_space_after_curly_bracket)</span> recipe main [ @@ -57,7 +57,7 @@ recipe main [ recipe main [ <span class="Delimiter">{</span><span class="Constant">1</span>: number<span class="Delimiter">,</span> foo: bar<span class="Delimiter">}</span><span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># test comment</span> ] -<span class="traceContains">+parse: product: {"1": "number", "foo": "bar"}</span> +<span class="traceContains">+parse: product: 1: "number", {"foo": "bar"}</span> $error: <span class="Constant">0</span> <span class="Delimiter">:(scenario dilated_reagent_with_comment_immediately_following)</span> @@ -132,6 +132,21 @@ if <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span clas istringstream in<span class="Delimiter">(</span>s<span class="Delimiter">);</span> in >> std::noskipws<span class="Delimiter">;</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="Comment">// skip '{'</span> + name = slurp_key<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + raise_error << <span class="Constant">"invalid reagent "</span> << s << <span class="Constant">" without a name</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>name == <span class="Constant">"}"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << <span class="Constant">"invalid empty reagent "</span> << s << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + string_tree* value = new string_tree<span class="Delimiter">(</span>next_word<span class="Delimiter">(</span>in<span class="Delimiter">));</span> + <span class="Comment">// End Parsing Reagent Type Property(value)</span> + type = new_type_tree<span class="Delimiter">(</span>value<span class="Delimiter">);</span> + delete value<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> string key = slurp_key<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>key<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> @@ -140,14 +155,6 @@ if <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span clas <span class="Comment">// End Parsing Reagent Property(value)</span> properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span>key<span class="Delimiter">,</span> value<span class="Delimiter">));</span> <span class="Delimiter">}</span> - <span class="Comment">// structures for the first row of properties</span> - name = properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>first<span class="Delimiter">;</span> - string type_name = properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Comment">// this type can't be an integer literal</span> - put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - type = new_type_tree<span class="Delimiter">(</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/055parse_tree.cc.html b/html/055parse_tree.cc.html index ec8d3f77..46a199a3 100644 --- a/html/055parse_tree.cc.html +++ b/html/055parse_tree.cc.html @@ -39,10 +39,12 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } recipe main [ <span class="Delimiter">{</span><span class="Constant">1</span>: number<span class="Delimiter">,</span> foo: <span class="Delimiter">(</span>bar <span class="Delimiter">(</span>baz quux<span class="Delimiter">))}</span><span class="Special"> <- </span>copy <span class="Constant">34</span> ] -<span class="traceContains">+parse: product: {"1": "number", "foo": <"bar" : <<"baz" : <"quux" : <>>> : <>>>}</span> +<span class="traceContains">+parse: product: 1: "number", {"foo": ("bar" ("baz" "quux"))}</span> <span class="Delimiter">:(before "End Parsing Reagent Property(value)")</span> value = parse_string_tree<span class="Delimiter">(</span>value<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Parsing Reagent Type Property(value)")</span> +value = parse_string_tree<span class="Delimiter">(</span>value<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> string_tree* parse_string_tree<span class="Delimiter">(</span>string_tree* s<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -97,7 +99,7 @@ container foo [ ] container bar [ ] -<span class="traceContains">+parse: product: {"1": <"foo" : <<"address" : <"array" : <"character" : <>>>> : <<"bar" : <"number" : <>>> : <>>>>}</span> +<span class="traceContains">+parse: product: 1: ("foo" ("address" "array" "character") ("bar" "number"))</span> <span class="Comment">//: an exception is 'new', which takes a type tree as its ingredient *value*</span> @@ -105,12 +107,15 @@ container bar [ recipe main [ x:address:shared:address:number<span class="Special"> <- </span>new <span class="Delimiter">{(</span>address number<span class="Delimiter">)</span>: type<span class="Delimiter">}</span> ] -<span class="traceContains">+new: size of <"address" : <"number" : <>>> is 1</span> +<span class="traceContains">+new: size of ("address" "number") is 1</span> <span class="Delimiter">:(before "End Post-processing(expected_product) When Checking 'new'")</span> -expected_product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = parse_string_tree<span class="Delimiter">(</span>expected_product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> -delete expected_product<span class="Delimiter">.</span>type<span class="Delimiter">;</span> -expected_product<span class="Delimiter">.</span>type = new_type_tree<span class="Delimiter">(</span>expected_product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> +<span class="Delimiter">{</span> + string_tree* tmp_type_names = parse_string_tree<span class="Delimiter">(</span>expected_product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + delete expected_product<span class="Delimiter">.</span>type<span class="Delimiter">;</span> + expected_product<span class="Delimiter">.</span>type = new_type_tree<span class="Delimiter">(</span>tmp_type_names<span class="Delimiter">);</span> + delete tmp_type_names<span class="Delimiter">;</span> +<span class="Delimiter">}</span> <span class="Delimiter">:(before "End Post-processing(type_name) When Converting 'new'")</span> type_name = parse_string_tree<span class="Delimiter">(</span>type_name<span class="Delimiter">);</span> </pre> diff --git a/html/056recipe_header.cc.html b/html/056recipe_header.cc.html index c4847398..5648dd5e 100644 --- a/html/056recipe_header.cc.html +++ b/html/056recipe_header.cc.html @@ -13,17 +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; } -.SalientComment { color: #00ffff; } -.CommentedCode { color: #6c6c6c; } -.Error { color: #ffffff; background-color: #ff6060; padding-bottom: 1px; } -.Delimiter { color: #a04060; } -.traceContains { color: #008000; } .traceAbsent { color: #c00000; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } +.Error { color: #ffffff; background-color: #ff6060; padding-bottom: 1px; } .Comment { color: #9090ff; } -.Constant { color: #00a0a0; } +.Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } +.Constant { color: #00a0a0; } +.SalientComment { color: #00ffff; } --> </style> @@ -59,7 +58,7 @@ vector<reagent> products<span class="Delimiter">;</span> <span class="Delimiter">:(before "End recipe Constructor")</span> has_header = <span class="Constant">false</span><span class="Delimiter">;</span> -<span class="Delimiter">:(before "End recipe Refinements")</span> +<span class="Delimiter">:(before "End Recipe Refinements")</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"recipe has a header; parsing"</span> << end<span class="Delimiter">();</span> load_recipe_header<span class="Delimiter">(</span>in<span class="Delimiter">,</span> result<span class="Delimiter">);</span> @@ -152,7 +151,7 @@ recipe test [ ] <span class="traceContains">+parse: recipe test has a header</span> -<span class="Delimiter">:(before "End recipe Body(result)")</span> +<span class="Delimiter">:(before "End Recipe Body(result)")</span> if <span class="Delimiter">(</span>!result<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Delimiter">{</span> result<span class="Delimiter">.</span>has_header = <span class="Constant">true</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>result<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -255,17 +254,17 @@ void check_calls_against_header<span class="Delimiter">(</span>const recipe_ordi for <span class="Delimiter">(</span>long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// ingredients coerced from call to callee</span> if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"ingredient "</span> << i << <span class="Constant">" has the wrong type at '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"ingredient "</span> << i << <span class="Constant">" has the wrong type at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> if <span class="Delimiter">(</span>is_unique_address<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"try to avoid passing non-shared addresses into calls, like ingredient "</span> << i << <span class="Constant">" at '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"avoid passing non-shared addresses into calls, like ingredient "</span> << i << <span class="Constant">" at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> for <span class="Delimiter">(</span>long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// products coerced from callee to call</span> if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> callee<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"product "</span> << i << <span class="Constant">" has the wrong type at '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"product "</span> << i << <span class="Constant">" has the wrong type at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> if <span class="Delimiter">(</span>is_unique_address<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"try to avoid getting non-shared addresses out of calls, like product "</span> << i << <span class="Constant">" at '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"avoid getting non-shared addresses out of calls, like product "</span> << i << <span class="Constant">" at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -278,22 +277,22 @@ bool is_unique_address<span class="Delimiter">(</span>reagent x<span class="Deli <span class="Identifier">return</span> x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Comment">//: additionally, warn on calls receiving non-shared addresses</span> +<span class="Comment">//: additionally, flag an error on calls receiving non-shared addresses</span> -<span class="Delimiter">:(scenario warn_on_calls_with_addresses)</span> -<span class="Special">% Hide_warnings= true;</span> +<span class="Delimiter">:(scenario forbid_calls_with_nonshared_addresses)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">3</span>/unsafe + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">0</span> foo <span class="Constant">1</span>:address:number ] recipe foo x:address:number [ local-scope load-ingredients ] -<span class="traceContains">+warn: main: try to avoid passing non-shared addresses into calls, like ingredient 0 at 'foo 1:address:number'</span> +<span class="traceContains">+error: main: avoid passing non-shared addresses into calls, like ingredient 0 at 'foo 1:address:number'</span> -<span class="Delimiter">:(scenario warn_on_calls_with_addresses_2)</span> -<span class="Special">% Hide_warnings= true;</span> +<span class="Delimiter">:(scenario forbid_calls_with_nonshared_addresses_2)</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ <span class="Constant">1</span>:address:number<span class="Special"> <- </span>foo ] @@ -302,7 +301,7 @@ recipe foo <span class="Delimiter">-></span> x:address:number [ load-ingredients x<span class="Special"> <- </span>copy <span class="Constant">0</span> ] -<span class="traceContains">+warn: main: try to avoid getting non-shared addresses out of calls, like product 0 at '1:address:number <- foo '</span> +<span class="traceContains">+error: main: avoid getting non-shared addresses out of calls, like product 0 at '1:address:number <- foo '</span> <span class="SalientComment">//:: Check types going in and out of all recipes with headers.</span> @@ -323,19 +322,32 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">:(code)</span> void check_reply_instructions_against_header<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> const recipe& caller_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!caller_recipe<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">return</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">"--- checking reply instructions against header for "</span> << caller_recipe<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "--- checking reply instructions against header for " << caller_recipe.name << '\n';</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>caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> const instruction& inst = caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name != <span class="Constant">"reply"</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"replied with the wrong number of products at '"</span> << to_string<span class="Delimiter">(</span>inst<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">continue</span><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>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> - raise_error << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"replied with the wrong type at '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"replied with the wrong type at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> +<span class="Delimiter">:(scenario recipe_headers_are_checked_2)</span> +<span class="Special">% Hide_errors = true;</span> +recipe add2 x:number<span class="Delimiter">,</span> y:number [ + local-scope + load-ingredients + z:address:number<span class="Special"> <- </span>copy <span class="Constant">0</span>/unsafe + reply z +] +<span class="traceContains">+error: add2: replied with the wrong number of products at 'reply z'</span> + <span class="Delimiter">:(scenario recipe_headers_check_for_duplicate_names)</span> <span class="Special">% Hide_errors = true;</span> recipe add2 x:number<span class="Delimiter">,</span> x:number <span class="Delimiter">-></span> z:number [ @@ -387,42 +399,34 @@ void deduce_types_from_header<span class="Delimiter">(</span>const recipe_ordina recipe& caller_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> if <span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</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">"--- deduce types from header for "</span> << caller_recipe<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "--- deduce types from header for " << caller_recipe.name << '\n';</span> map<string<span class="Delimiter">,</span> const type_tree*> header_type<span class="Delimiter">;</span> - map<string<span class="Delimiter">,</span> const string_tree*> header_type_name<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>caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> put<span class="Delimiter">(</span>header_type<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">);</span> - put<span class="Delimiter">(</span>header_type_name<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">" is "</span> << debug_string<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">" is "</span> << names_to_string<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> << end<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>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> put<span class="Delimiter">(</span>header_type<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">);</span> - put<span class="Delimiter">(</span>header_type_name<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">" is "</span> << debug_string<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">" is "</span> << names_to_string<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> << end<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>caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction: "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction: "</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << end<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>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</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>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>header_type<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">)</span> == header_type<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">continue</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>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type = new type_tree<span class="Delimiter">(</span>*get<span class="Delimiter">(</span>header_type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">)</span> - inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = new string_tree<span class="Delimiter">(</span>*get<span class="Delimiter">(</span>header_type_name<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">" is "</span> << debug_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">" is "</span> << names_to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> << end<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>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" product: "</span> << debug_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" product: "</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>header_type<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">)</span> == header_type<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type = new type_tree<span class="Delimiter">(</span>*get<span class="Delimiter">(</span>header_type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">)</span> - inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = new string_tree<span class="Delimiter">(</span>*get<span class="Delimiter">(</span>header_type_name<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">" is "</span> << debug_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name << <span class="Constant">" is "</span> << names_to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -452,7 +456,7 @@ void fill_in_reply_ingredients<span class="Delimiter">(</span>recipe_ordinal r<s 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">"--- fill in reply ingredients from header for recipe "</span> << caller_recipe<span class="Delimiter">.</span>name << end<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>caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"reply"</span> && inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"reply"</span><span class="Delimiter">)</span> add_header_products<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// fall through reply</span> diff --git a/html/057static_dispatch.cc.html b/html/057static_dispatch.cc.html index adcf7995..ac2db406 100644 --- a/html/057static_dispatch.cc.html +++ b/html/057static_dispatch.cc.html @@ -50,7 +50,7 @@ recipe test a:number<span class="Delimiter">,</span> b:number <span class="Delim <span class="traceContains">+mem: storing 1 in location 7</span> <span class="Comment">//: When loading recipes, accumulate variants if headers don't collide, and</span> -<span class="Comment">//: raise a warning if headers collide.</span> +<span class="Comment">//: flag an error if headers collide.</span> <span class="Delimiter">:(before "End Globals")</span> map<string<span class="Delimiter">,</span> vector<recipe_ordinal> > Recipe_variants<span class="Delimiter">;</span> @@ -65,6 +65,7 @@ for <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Load Recipe Header(result)")</span> +<span class="Comment">// there can only ever be one variant for main</span> if <span class="Delimiter">(</span>result<span class="Delimiter">.</span>name != <span class="Constant">"main"</span> && contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> const recipe_ordinal r = get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span class="CommentedCode">//? cerr << result.name << ": " << contains_key(Recipe, r) << (contains_key(Recipe, r) ? get(Recipe, r).has_header : 0) << matching_variant_name(result) << '\n';</span> @@ -76,6 +77,7 @@ if <span class="Delimiter">(</span>result<span class="Delimiter">.</span>name != put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> new_name<span class="Delimiter">,</span> Next_recipe_ordinal++<span class="Delimiter">);</span> get_or_insert<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> result<span class="Delimiter">.</span>name<span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> new_name<span class="Delimiter">));</span> <span class="Delimiter">}</span> + trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"switching "</span> << result<span class="Delimiter">.</span>name << <span class="Constant">" to "</span> << new_name << end<span class="Delimiter">();</span> result<span class="Delimiter">.</span>name = new_name<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "=> " << new_name << '\n';</span> <span class="Delimiter">}</span> @@ -102,14 +104,12 @@ bool all_reagents_match<span class="Delimiter">(</span>const recipe& r1<span if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>r2<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>products<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>r2<span class="Delimiter">.</span>products<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</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>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!deeply_equal_types<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> - r2<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> r2<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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> <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>r1<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!deeply_equal_types<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> - r2<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>r1<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> r2<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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> <span class="Delimiter">}</span> @@ -122,18 +122,21 @@ set<string> Literal_type_names<span class="Delimiter">;</span> Literal_type_names<span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"number"</span><span class="Delimiter">);</span> Literal_type_names<span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"character"</span><span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -bool deeply_equal_types<span class="Delimiter">(</span>const string_tree* a<span class="Delimiter">,</span> const string_tree* b<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool deeply_equal_type_names<span class="Delimiter">(</span>const reagent& a<span class="Delimiter">,</span> const reagent& b<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> deeply_equal_type_names<span class="Delimiter">(</span>a<span class="Delimiter">.</span>type<span class="Delimiter">,</span> b<span class="Delimiter">.</span>type<span class="Delimiter">);</span> +<span class="Delimiter">}</span> +bool deeply_equal_type_names<span class="Delimiter">(</span>const type_tree* a<span class="Delimiter">,</span> const type_tree* b<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!a<span class="Delimiter">)</span> <span class="Identifier">return</span> !b<span class="Delimiter">;</span> if <span class="Delimiter">(</span>!b<span class="Delimiter">)</span> <span class="Identifier">return</span> !a<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>a<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span> && b<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>a<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span> && b<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>a<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span><span class="Delimiter">)</span> - <span class="Identifier">return</span> Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>b<span class="Delimiter">-></span>value<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>b<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span><span class="Delimiter">)</span> - <span class="Identifier">return</span> Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>a<span class="Delimiter">-></span>value<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> - <span class="Identifier">return</span> a<span class="Delimiter">-></span>value == b<span class="Delimiter">-></span>value - && deeply_equal_types<span class="Delimiter">(</span>a<span class="Delimiter">-></span>left<span class="Delimiter">,</span> b<span class="Delimiter">-></span>left<span class="Delimiter">)</span> - && deeply_equal_types<span class="Delimiter">(</span>a<span class="Delimiter">-></span>right<span class="Delimiter">,</span> b<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>a<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> + <span class="Identifier">return</span> Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>b<span class="Delimiter">-></span>name<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>b<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> + <span class="Identifier">return</span> Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>a<span class="Delimiter">-></span>name<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> + <span class="Identifier">return</span> a<span class="Delimiter">-></span>name == b<span class="Delimiter">-></span>name + && deeply_equal_type_names<span class="Delimiter">(</span>a<span class="Delimiter">-></span>left<span class="Delimiter">,</span> b<span class="Delimiter">-></span>left<span class="Delimiter">)</span> + && deeply_equal_type_names<span class="Delimiter">(</span>a<span class="Delimiter">-></span>right<span class="Delimiter">,</span> b<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> string next_unused_recipe_name<span class="Delimiter">(</span>const string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -162,14 +165,10 @@ recipe test a:number<span class="Delimiter">,</span> b:number <span class="Delim <span class="Comment">//: support recipe headers in a previous transform to fill in missing types</span> <span class="Delimiter">:(before "End check_or_set_invalid_types")</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>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - check_or_set_invalid_types<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> - maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"recipe header ingredient"</span><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>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - check_or_set_invalid_types<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> - maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"recipe header product"</span><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>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + check_or_set_invalid_types<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"recipe header ingredient"</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>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + check_or_set_invalid_types<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">,</span> maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">),</span> <span class="Constant">"recipe header product"</span><span class="Delimiter">);</span> <span class="Comment">//: after filling in all missing types (because we'll be introducing 'blank' types in this transform in a later layer, for shape-shifting recipes)</span> <span class="Delimiter">:(after "Transform.push_back(transform_names)")</span> @@ -188,46 +187,51 @@ list<call> resolve_stack<span class="Delimiter">;</span> void resolve_ambiguous_calls<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> recipe& caller_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<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">"--- resolve ambiguous calls for recipe "</span> << caller_recipe<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "--- resolve ambiguous calls for recipe " << caller_recipe.name << '\n';</span> for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = caller_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>non_ghost_size<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">))</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction "</span> << inst<span class="Delimiter">.</span>original_string << end<span class="Delimiter">();</span> resolve_stack<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>r<span class="Delimiter">));</span> resolve_stack<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_step_index = index<span class="Delimiter">;</span> - replace_best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">);</span> + string new_name = best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!new_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + inst<span class="Delimiter">.</span>name = new_name<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>resolve_stack<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_recipe == r<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>resolve_stack<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_step_index == index<span class="Delimiter">);</span> resolve_stack<span class="Delimiter">.</span>pop_front<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -void replace_best_variant<span class="Delimiter">(</span>instruction& inst<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction "</span> << inst<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> +string best_variant<span class="Delimiter">(</span>instruction& inst<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> vector<recipe_ordinal>& variants = get<span class="Delimiter">(</span>Recipe_variants<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">);</span> -<span class="CommentedCode">//? trace(9992, "transform") << "checking base: " << get(Recipe_ordinal, inst.name) << end();</span> - long long int best_score = variant_score<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"score for base: "</span> << best_score << end<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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span class="CommentedCode">//? trace(9992, "transform") << "checking variant " << i << ": " << variants.at(i) << end();</span> - long long int current_score = variant_score<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"score for variant "</span> << i << <span class="Constant">": "</span> << current_score << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>current_score > best_score<span class="Delimiter">)</span> <span class="Delimiter">{</span> - inst<span class="Delimiter">.</span>name = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)).</span>name<span class="Delimiter">;</span> - best_score = current_score<span class="Delimiter">;</span> - <span class="Delimiter">}</span> - <span class="Delimiter">}</span> - <span class="Comment">// End Instruction Dispatch(inst, best_score)</span> - if <span class="Delimiter">(</span>best_score == -<span class="Constant">1</span> && get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">)</span> >= MAX_PRIMITIVE_RECIPES<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"failed to find a matching call for '"</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> + vector<recipe_ordinal> candidates<span class="Delimiter">;</span> + + <span class="Comment">// Static Dispatch Phase 1</span> + candidates = strictly_matching_variants<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + + <span class="Comment">// Static Dispatch Phase 2 (shape-shifting recipes in a later layer)</span> + <span class="Comment">// End Static Dispatch Phase 2</span> + + <span class="Comment">// Static Dispatch Phase 3</span> + candidates = strictly_matching_variants_except_literal_against_boolean<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + + <span class="Comment">// Static Dispatch Phase 4</span> + candidates = matching_variants<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> best_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + + <span class="Comment">// error messages</span> + if <span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">)</span> >= MAX_PRIMITIVE_RECIPES<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// we currently don't check types for primitive variants</span> + raise_error << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"failed to find a matching call for '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> for <span class="Delimiter">(</span>list<call>::iterator p = <span class="Comment">/*</span><span class="Comment">skip</span><span class="Comment">*/</span>++resolve_stack<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != resolve_stack<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> const recipe& specializer_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> p<span class="Delimiter">-></span>running_recipe<span class="Delimiter">);</span> const instruction& specializer_inst = specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>p<span class="Delimiter">-></span>running_step_index<span class="Delimiter">);</span> if <span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>name != <span class="Constant">"interactive"</span><span class="Delimiter">)</span> - raise_error << <span class="Constant">" (from '"</span> << specializer_inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"' in "</span> << specializer_recipe<span class="Delimiter">.</span>name << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">" (from '"</span> << to_string<span class="Delimiter">(</span>specializer_inst<span class="Delimiter">)</span> << <span class="Constant">"' in "</span> << specializer_recipe<span class="Delimiter">.</span>name << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> else - raise_error << <span class="Constant">" (from '"</span> << specializer_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 << <span class="Constant">" (from '"</span> << to_string<span class="Delimiter">(</span>specializer_inst<span class="Delimiter">)</span> << <span class="Constant">"')</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Comment">// One special-case to help with the rewrite_stash transform. (cross-layer)</span> if <span class="Delimiter">(</span>specializer_inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"stash_"</span><span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction stash_inst<span class="Delimiter">;</span> @@ -240,102 +244,163 @@ void replace_best_variant<span class="Delimiter">(</span>instruction& inst<s <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> + <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -bool next_stash<span class="Delimiter">(</span>const call& c<span class="Delimiter">,</span> instruction* stash_inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const recipe& specializer_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> c<span class="Delimiter">.</span>running_recipe<span class="Delimiter">);</span> - long long int index = c<span class="Delimiter">.</span>running_step_index<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>++index<span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const instruction& inst = specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"stash"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - *stash_inst = inst<span class="Delimiter">;</span> - <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> +<span class="Comment">// phase 1</span> +vector<recipe_ordinal> strictly_matching_variants<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<recipe_ordinal> result<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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking variant (strict) "</span> << i << <span class="Constant">": "</span> << header_label<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>all_header_reagents_strictly_match<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> - <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -long long int variant_score<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> recipe_ordinal variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> - long long int result = <span class="Constant">1000</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>variant == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// ghost from a previous test</span> -<span class="CommentedCode">//? cerr << "variant score: " << inst.to_string() << '\n';</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">))</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>variant < MAX_PRIMITIVE_RECIPES<span class="Delimiter">);</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> +bool all_header_reagents_strictly_match<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> const recipe& variant<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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: ingredient "</span> << i << end<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">}</span> - const vector<reagent>& header_ingredients = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>ingredients<span class="Delimiter">;</span> -<span class="CommentedCode">//? cerr << "=== checking ingredients\n";</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>header_ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>header_ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"mismatch: ingredient "</span> << i << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "mismatch: ingredient " << i << '\n';</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: product "</span> << i << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>types_strictly_match<span class="Delimiter">(</span>header_ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match: ingredient "</span> << i << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "strict match: ingredient " << i << '\n';</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="Comment">// phase 3</span> +vector<recipe_ordinal> strictly_matching_variants_except_literal_against_boolean<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<recipe_ordinal> result<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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking variant (strict except literals-against-booleans) "</span> << i << <span class="Constant">": "</span> << header_label<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>all_header_reagents_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +bool all_header_reagents_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> const recipe& variant<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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!types_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: ingredient "</span> << i << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - else if <span class="Delimiter">(</span>boolean_matches_literal<span class="Delimiter">(</span>header_ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - <span class="Comment">// slight penalty for coercing literal to boolean (prefer direct conversion to number if possible)</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"boolean matches literal: ingredient "</span> << i << end<span class="Delimiter">();</span> - result--<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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!types_strictly_match_except_literal_against_boolean<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: product "</span> << i << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - <span class="Comment">// slightly larger penalty for modifying type in other ways</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"non-strict match: ingredient "</span> << i << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "non-strict match: ingredient " << i << '\n';</span> - result-=<span class="Constant">10</span><span class="Delimiter">;</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="Comment">// phase 4</span> +vector<recipe_ordinal> matching_variants<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<recipe_ordinal> result<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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking variant "</span> << i << <span class="Constant">": "</span> << header_label<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>all_header_reagents_match<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +bool all_header_reagents_match<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> const recipe& variant<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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: ingredient "</span> << i << end<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">}</span> -<span class="CommentedCode">//? cerr << "=== done checking ingredients\n";</span> - const vector<reagent>& header_products = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>products<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>header_products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<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 < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>header_products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"mismatch: product "</span> << i << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "mismatch: product " << i << '\n';</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>types_strictly_match<span class="Delimiter">(</span>header_products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match: product "</span> << i << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "strict match: product " << i << '\n';</span> + if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: product "</span> << i << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - else if <span class="Delimiter">(</span>boolean_matches_literal<span class="Delimiter">(</span>header_products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - <span class="Comment">// slight penalty for coercing literal to boolean (prefer direct conversion to number if possible)</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"boolean matches literal: product "</span> << i << end<span class="Delimiter">();</span> - result--<span class="Delimiter">;</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="Comment">// tie-breaker for each phase</span> +const recipe& best_variant<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& candidates<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + long long int min_score = <span class="Constant">999</span><span class="Delimiter">;</span> + long long int min_index = <span class="Constant">0</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>candidates<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const recipe& candidate = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + long long int score = abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>candidate<span class="Delimiter">.</span>products<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">))</span> + + abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>candidate<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> + assert<span class="Delimiter">(</span>score < <span class="Constant">999</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>score < min_score<span class="Delimiter">)</span> <span class="Delimiter">{</span> + min_score = score<span class="Delimiter">;</span> + min_index = i<span class="Delimiter">;</span> <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - <span class="Comment">// slightly larger penalty for modifying type in other ways</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"non-strict match: product "</span> << i << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "non-strict match: product " << i << '\n';</span> - result-=<span class="Constant">10</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>min_index<span class="Delimiter">));</span> +<span class="Delimiter">}</span> + +long long int non_ghost_size<span class="Delimiter">(</span>vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int result = <span class="Constant">0</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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != -<span class="Constant">1</span><span class="Delimiter">)</span> ++result<span class="Delimiter">;</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +bool next_stash<span class="Delimiter">(</span>const call& c<span class="Delimiter">,</span> instruction* stash_inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const recipe& specializer_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> c<span class="Delimiter">.</span>running_recipe<span class="Delimiter">);</span> + long long int index = c<span class="Delimiter">.</span>running_step_index<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>++index<span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const instruction& inst = specializer_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"stash"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + *stash_inst = inst<span class="Delimiter">;</span> + <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Comment">// the greater the number of unused ingredients/products, the lower the score</span> - <span class="Identifier">return</span> result - abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>products<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">))</span> - - abs<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>ingredients<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 static_dispatch_disabled_in_recipe_without_variants)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>test <span class="Constant">3</span> +] +recipe test [ + <span class="Constant">2</span>:number<span class="Special"> <- </span>next-ingredient <span class="Comment"># ensure no header</span> + reply <span class="Constant">34</span> +] +<span class="traceContains">+mem: storing 34 in location 1</span> + <span class="Delimiter">:(scenario static_dispatch_disabled_on_headerless_definition)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe test a:number <span class="Delimiter">-></span> z:number [ z<span class="Special"> <- </span>copy <span class="Constant">1</span> ] recipe test [ reply <span class="Constant">34</span> ] -<span class="traceContains">+warn: redefining recipe test</span> +<span class="traceContains">+error: redefining recipe test</span> <span class="Delimiter">:(scenario static_dispatch_disabled_on_headerless_definition_2)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe test [ reply <span class="Constant">34</span> ] recipe test a:number <span class="Delimiter">-></span> z:number [ z<span class="Special"> <- </span>copy <span class="Constant">1</span> ] -<span class="traceContains">+warn: redefining recipe test</span> +<span class="traceContains">+error: redefining recipe test</span> <span class="Delimiter">:(scenario static_dispatch_on_primitive_names)</span> recipe main [ @@ -490,10 +555,10 @@ string header_label<span class="Delimiter">(</span>recipe_ordinal r<span class=" ostringstream out<span class="Delimiter">;</span> out << <span class="Constant">"recipe "</span> << caller<span class="Delimiter">.</span>name<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>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - out << <span class="Constant">' '</span> << caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string<span class="Delimiter">;</span> + out << <span class="Constant">' '</span> << to_string<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> if <span class="Delimiter">(</span>!caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> out << <span class="Constant">" ->"</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>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - out << <span class="Constant">' '</span> << caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string<span class="Delimiter">;</span> + out << <span class="Constant">' '</span> << to_string<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -519,7 +584,6 @@ recipe! foo x:address:number <span class="Delimiter">-></span> y:number [ ] <span class="traceContains">+mem: storing 34 in location 2</span> $error: <span class="Constant">0</span> -$warn: <span class="Constant">0</span> <span class="Delimiter">:(scenario dispatch_errors_come_after_unknown_name_errors)</span> <span class="Special">% Hide_errors = true;</span> diff --git a/html/058shape_shifting_container.cc.html b/html/058shape_shifting_container.cc.html index 6229c527..ef2ac641 100644 --- a/html/058shape_shifting_container.cc.html +++ b/html/058shape_shifting_container.cc.html @@ -32,12 +32,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } </head> <body> <pre id='vimCodeElement'> -<span class="SalientComment">//:: Container definitions can contain type parameters.</span> -<span class="Comment">//:</span> -<span class="Comment">//: Extremely hacky initial implementation. We still don't support the full</span> -<span class="Comment">//: complexity of type trees inside container definitions. So for example you</span> -<span class="Comment">//: can't have a container element with this type:</span> -<span class="Comment">//: (map (array address character) (list number))</span> +<span class="SalientComment">//:: Container definitions can contain 'type ingredients'</span> <span class="Delimiter">:(scenario size_of_shape_shifting_container)</span> container foo:_t [ @@ -54,6 +49,47 @@ recipe main [ <span class="traceContains">+mem: storing 15 in location 4</span> <span class="traceContains">+mem: storing 16 in location 5</span> +<span class="Delimiter">:(scenario size_of_shape_shifting_container_2)</span> +<span class="Special">% Hide_errors = true;</span> +<span class="Comment"># multiple type ingredients</span> +container foo:_a:_b [ + x:_a + y:_b +] +recipe main [ + <span class="Constant">1</span>:foo:number:boolean<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">1</span>/<span class="Constant">true</span> +] +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario size_of_shape_shifting_container_3)</span> +<span class="Special">% Hide_errors = true;</span> +container foo:_a:_b [ + x:_a + y:_b +] +recipe main [ + <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new [abc] + <span class="Comment"># compound types for type ingredients</span> + <span class="Delimiter">{</span><span class="Constant">2</span>: <span class="Delimiter">(</span>foo number <span class="Delimiter">(</span>address shared array character<span class="Delimiter">))}</span><span class="Special"> <- </span>merge <span class="Constant">34</span>/x<span class="Delimiter">,</span> <span class="Constant">1</span>:address:shared:array:character/y +] +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario size_of_shape_shifting_container_4)</span> +<span class="Special">% Hide_errors = true;</span> +container foo:_a:_b [ + x:_a + y:_b +] +container bar:_a:_b [ + <span class="Comment"># dilated element</span> + <span class="Delimiter">{</span>data: <span class="Delimiter">(</span>foo _a <span class="Delimiter">(</span>address shared _b<span class="Delimiter">))}</span> +] +recipe main [ + <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new [abc] + <span class="Constant">2</span>:bar:number:array:character<span class="Special"> <- </span>merge <span class="Constant">34</span>/x<span class="Delimiter">,</span> <span class="Constant">1</span>:address:shared:array:character/y +] +$error: <span class="Constant">0</span> + <span class="Delimiter">:(before "End Globals")</span> <span class="Comment">// We'll use large type ordinals to mean "the following type of the variable".</span> const int START_TYPE_INGREDIENTS = <span class="Constant">2000</span><span class="Delimiter">;</span> @@ -93,12 +129,14 @@ void read_type_ingredients<span class="Delimiter">(</span>string& name<span <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(before "End insert_container Special Uses(type_name)")</span> +<span class="Delimiter">:(before "End insert_container Special-cases")</span> <span class="Comment">// check for use of type ingredients</span> -if <span class="Delimiter">(</span>type_name<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'_'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - *curr_type = new type_tree<span class="Delimiter">(</span>get<span class="Delimiter">(</span>info<span class="Delimiter">.</span>type_ingredient_names<span class="Delimiter">,</span> type_name<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">" type: "</span> << get<span class="Delimiter">(</span>info<span class="Delimiter">.</span>type_ingredient_names<span class="Delimiter">,</span> type_name<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - <span class="Identifier">continue</span><span class="Delimiter">;</span> +else if <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + type<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>info<span class="Delimiter">.</span>type_ingredient_names<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(code)</span> +bool is_type_ingredient_name<span class="Delimiter">(</span>const string& type<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> !type<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && type<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'_'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Container Type Checks")</span> @@ -106,35 +144,49 @@ if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value && <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value - START_TYPE_INGREDIENTS<span class="Delimiter">)</span> < SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>type_ingredient_names<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span class="Delimiter">:(before "End size_of(type) Container Cases")</span> -if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>value >= START_TYPE_INGREDIENTS<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"type"</span><span class="Delimiter">)</span> << <span class="Constant">"checking size of type ingredient</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - long long int size = size_of_type_ingredient<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!size<span class="Delimiter">)</span> - raise_error << <span class="Constant">"illegal type '"</span> << debug_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="Constant">"' seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - result += size<span class="Delimiter">;</span> - <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> +<span class="Delimiter">:(scenario size_of_shape_shifting_exclusive_container)</span> +exclusive-container foo:_t [ + x:_t + y:number +] +recipe main [ + <span class="Constant">1</span>:foo:number<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">34</span> + <span class="Constant">3</span>:foo:point<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">15</span><span class="Delimiter">,</span> <span class="Constant">16</span> + <span class="Constant">6</span>:foo:point<span class="Special"> <- </span>merge <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">23</span> +] +<span class="traceContains">+mem: storing 0 in location 1</span> +<span class="traceContains">+mem: storing 34 in location 2</span> +<span class="traceContains">+mem: storing 0 in location 3</span> +<span class="traceContains">+mem: storing 15 in location 4</span> +<span class="traceContains">+mem: storing 16 in location 5</span> +<span class="traceContains">+mem: storing 1 in location 6</span> +<span class="traceContains">+mem: storing 23 in location 7</span> +$mem: <span class="Constant">7</span> <span class="Delimiter">:(code)</span> <span class="Comment">// shape-shifting version of size_of</span> long long int size_of_type_ingredient<span class="Delimiter">(</span>const type_tree* element_template<span class="Delimiter">,</span> const type_tree* rest_of_use<span class="Delimiter">)</span> <span class="Delimiter">{</span> + type_tree* element_type = type_ingredient<span class="Delimiter">(</span>element_template<span class="Delimiter">,</span> rest_of_use<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!element_type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + long long int result = size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">);</span> + delete element_type<span class="Delimiter">;</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +type_tree* type_ingredient<span class="Delimiter">(</span>const type_tree* element_template<span class="Delimiter">,</span> const type_tree* rest_of_use<span class="Delimiter">)</span> <span class="Delimiter">{</span> long long int type_ingredient_index = element_template<span class="Delimiter">-></span>value - START_TYPE_INGREDIENTS<span class="Delimiter">;</span> const type_tree* curr = rest_of_use<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!curr<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!curr<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> while <span class="Delimiter">(</span>type_ingredient_index > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> --type_ingredient_index<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!curr<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!curr<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>!curr<span class="Delimiter">-></span>left<span class="Delimiter">);</span> <span class="Comment">// unimplemented</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> curr<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> curr = curr<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>value > <span class="Constant">0</span><span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"type"</span><span class="Delimiter">)</span> << <span class="Constant">"type deduced to be "</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> curr<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name << <span class="Constant">"$"</span> << end<span class="Delimiter">();</span> - type_tree tmp<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>value<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> - tmp<span class="Delimiter">.</span>right = new type_tree<span class="Delimiter">(</span>*curr<span class="Delimiter">-></span>right<span class="Delimiter">);</span> - <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>&tmp<span class="Delimiter">);</span> + <span class="Identifier">return</span> new type_tree<span class="Delimiter">(</span>*curr<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario get_on_shape_shifting_container)</span> @@ -149,11 +201,11 @@ recipe main [ <span class="traceContains">+mem: storing 16 in location 2</span> <span class="Delimiter">:(before "End GET field Cases")</span> -const type_tree* type = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +const type_tree* type = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">;</span> if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value >= START_TYPE_INGREDIENTS<span class="Delimiter">)</span> <span class="Delimiter">{</span> long long int size = size_of_type_ingredient<span class="Delimiter">(</span>type<span class="Delimiter">,</span> base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> if <span class="Delimiter">(</span>!size<span class="Delimiter">)</span> - raise_error << <span class="Constant">"illegal field type '"</span> << debug_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="Constant">"' seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"illegal field type '"</span> << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="Constant">"' seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> src += size<span class="Delimiter">;</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -176,16 +228,44 @@ container foo:_t [ y:number ] recipe main [ - <span class="Constant">1</span>:foo:address:point<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">48</span> <span class="Comment"># unsafe</span> + <span class="Constant">1</span>:foo:address:point<span class="Special"> <- </span>merge <span class="Constant">34</span>/unsafe<span class="Delimiter">,</span> <span class="Constant">48</span> <span class="Constant">2</span>:address:point<span class="Special"> <- </span>get <span class="Constant">1</span>:foo:address:point<span class="Delimiter">,</span> x:offset ] <span class="traceContains">+mem: storing 34 in location 2</span> +<span class="Delimiter">:(scenario get_on_shape_shifting_container_inside_container)</span> +container foo:_t [ + x:_t + y:number +] +container bar [ + x:foo:point + y:number +] +recipe main [ + <span class="Constant">1</span>:bar<span class="Special"> <- </span>merge <span class="Constant">14</span><span class="Delimiter">,</span> <span class="Constant">15</span><span class="Delimiter">,</span> <span class="Constant">16</span><span class="Delimiter">,</span> <span class="Constant">17</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:bar<span class="Delimiter">,</span> <span class="Constant">1</span>:offset +] +<span class="traceContains">+mem: storing 17 in location 2</span> + +<span class="Delimiter">:(scenario get_on_complex_shape_shifting_container)</span> +container foo:_a:_b [ + x:_a + y:_b +] +recipe main [ + <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new [abc] + <span class="Delimiter">{</span><span class="Constant">2</span>: <span class="Delimiter">(</span>foo number <span class="Delimiter">(</span>address shared array character<span class="Delimiter">))}</span><span class="Special"> <- </span>merge <span class="Constant">34</span>/x<span class="Delimiter">,</span> <span class="Constant">1</span>:address:shared:array:character/y + <span class="Constant">3</span>:address:shared:array:character<span class="Special"> <- </span>get <span class="Delimiter">{</span><span class="Constant">2</span>: <span class="Delimiter">(</span>foo number <span class="Delimiter">(</span>address shared array character<span class="Delimiter">))},</span> y:offset + <span class="Constant">4</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:shared:array:character<span class="Delimiter">,</span> <span class="Constant">3</span>:address:shared:array:character +] +<span class="traceContains">+mem: storing 1 in location 4</span> + <span class="Delimiter">:(before "End element_type Special-cases")</span> if <span class="Delimiter">(</span>contains_type_ingredient<span class="Delimiter">(</span>element<span class="Delimiter">))</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> - raise_error << <span class="Constant">"illegal type '"</span> << debug_string<span class="Delimiter">(</span>canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">"' seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - replace_type_ingredient<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">,</span> canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + raise_error << <span class="Constant">"illegal type "</span> << names_to_string<span class="Delimiter">(</span>canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">" seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + replace_type_ingredients<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">,</span> canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> info<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> @@ -199,26 +279,187 @@ bool contains_type_ingredient<span class="Delimiter">(</span>const type_tree* ty <span class="Identifier">return</span> contains_type_ingredient<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">)</span> || contains_type_ingredient<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> -void replace_type_ingredient<span class="Delimiter">(</span>type_tree* element_type<span class="Delimiter">,</span> const type_tree* callsite_type<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Comment">// todo: too complicated and likely incomplete; maybe avoid replacing in place? Maybe process element_type and element_type_name in separate functions?</span> +void replace_type_ingredients<span class="Delimiter">(</span>type_tree* element_type<span class="Delimiter">,</span> const type_tree* callsite_type<span class="Delimiter">,</span> const type_info& container_info<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!callsite_type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// error but it's already been raised above</span> if <span class="Delimiter">(</span>!element_type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>value >= START_TYPE_INGREDIENTS<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!has_nth_type<span class="Delimiter">(</span>callsite_type<span class="Delimiter">,</span> element_type<span class="Delimiter">-></span>value-START_TYPE_INGREDIENTS<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"illegal type '"</span> << debug_string<span class="Delimiter">(</span>callsite_type<span class="Delimiter">)</span> << <span class="Constant">"' seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - <span class="Identifier">return</span><span class="Delimiter">;</span> + + <span class="Comment">// A. recurse first to avoid nested replaces (which I can't reason about yet)</span> + replace_type_ingredients<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> callsite_type<span class="Delimiter">,</span> container_info<span class="Delimiter">);</span> + replace_type_ingredients<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> callsite_type<span class="Delimiter">,</span> container_info<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>value < START_TYPE_INGREDIENTS<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + + const long long int type_ingredient_index = element_type<span class="Delimiter">-></span>value-START_TYPE_INGREDIENTS<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!has_nth_type<span class="Delimiter">(</span>callsite_type<span class="Delimiter">,</span> type_ingredient_index<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << <span class="Constant">"illegal type "</span> << names_to_string<span class="Delimiter">(</span>callsite_type<span class="Delimiter">)</span> << <span class="Constant">" seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + + <span class="Comment">// B. replace the current location</span> + const type_tree* replacement = <span class="Constant">NULL</span><span class="Delimiter">;</span> + bool splice_right = <span class="Constant">true</span> <span class="Delimiter">;</span> + <span class="Delimiter">{</span> + const type_tree* curr = callsite_type<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < type_ingredient_index<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> + curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr && curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> <span class="Delimiter">{</span> + replacement = curr<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + <span class="Comment">// We want foo:_t to be used like foo:number, which expands to {foo: number}</span> + <span class="Comment">// rather than {foo: (number)}</span> + <span class="Comment">// We'd also like to use it with multiple types: foo:address:number.</span> + replacement = curr<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!final_type_ingredient<span class="Delimiter">(</span>type_ingredient_index<span class="Delimiter">,</span> container_info<span class="Delimiter">))</span> <span class="Delimiter">{</span> + splice_right = <span class="Constant">false</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> - const type_tree* replacement = nth_type<span class="Delimiter">(</span>callsite_type<span class="Delimiter">,</span> element_type<span class="Delimiter">-></span>value-START_TYPE_INGREDIENTS<span class="Delimiter">);</span> - element_type<span class="Delimiter">-></span>value = replacement<span class="Delimiter">-></span>value<span class="Delimiter">;</span> - element_type<span class="Delimiter">-></span>left = replacement<span class="Delimiter">-></span>left ? new type_tree<span class="Delimiter">(</span>*replacement<span class="Delimiter">-></span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + element_type<span class="Delimiter">-></span>name = replacement<span class="Delimiter">-></span>name<span class="Delimiter">;</span> + element_type<span class="Delimiter">-></span>value = replacement<span class="Delimiter">-></span>value<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!element_type<span class="Delimiter">-></span>left<span class="Delimiter">);</span> <span class="Comment">// since value is set</span> + element_type<span class="Delimiter">-></span>left = replacement<span class="Delimiter">-></span>left ? new type_tree<span class="Delimiter">(</span>*replacement<span class="Delimiter">-></span>left<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>splice_right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + type_tree* old_right = element_type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> element_type<span class="Delimiter">-></span>right = replacement<span class="Delimiter">-></span>right ? new type_tree<span class="Delimiter">(</span>*replacement<span class="Delimiter">-></span>right<span class="Delimiter">)</span> : <span class="Constant">NULL</span><span class="Delimiter">;</span> + append<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> old_right<span class="Delimiter">);</span> <span class="Delimiter">}</span> - replace_type_ingredient<span class="Delimiter">(</span>element_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> callsite_type<span class="Delimiter">);</span> <span class="Delimiter">}</span> -const type_tree* nth_type<span class="Delimiter">(</span>const type_tree* base<span class="Delimiter">,</span> long long int n<span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>n >= <span class="Constant">0</span><span class="Delimiter">);</span> - if <span class="Delimiter">(</span>n == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> base<span class="Delimiter">;</span> - <span class="Identifier">return</span> nth_type<span class="Delimiter">(</span>base<span class="Delimiter">-></span>right<span class="Delimiter">,</span> n-<span class="Constant">1</span><span class="Delimiter">);</span> +bool final_type_ingredient<span class="Delimiter">(</span>long long int type_ingredient_index<span class="Delimiter">,</span> const type_info& container_info<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> type_ordinal>::const_iterator p = container_info<span class="Delimiter">.</span>type_ingredient_names<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> + p != container_info<span class="Delimiter">.</span>type_ingredient_names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> + ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>second > START_TYPE_INGREDIENTS+type_ingredient_index<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +void append<span class="Delimiter">(</span>type_tree*& base<span class="Delimiter">,</span> type_tree* extra<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!base<span class="Delimiter">)</span> <span class="Delimiter">{</span> + base = extra<span class="Delimiter">;</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + type_tree* curr = base<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> + curr<span class="Delimiter">-></span>right = extra<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +void append<span class="Delimiter">(</span>string_tree*& base<span class="Delimiter">,</span> string_tree* extra<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!base<span class="Delimiter">)</span> <span class="Delimiter">{</span> + base = extra<span class="Delimiter">;</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + string_tree* curr = base<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> + curr<span class="Delimiter">-></span>right = extra<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +void test_replace_type_ingredients_entire<span class="Delimiter">()</span> <span class="Delimiter">{</span> + run<span class="Delimiter">(</span><span class="Constant">"container foo:_elem [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:_elem</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" y:number</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> + reagent callsite<span class="Delimiter">(</span><span class="Constant">"x:foo:point"</span><span class="Delimiter">);</span> + reagent element = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"x"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"point"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +void test_replace_type_ingredients_tail<span class="Delimiter">()</span> <span class="Delimiter">{</span> + run<span class="Delimiter">(</span><span class="Constant">"container foo:_elem [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:_elem</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"container bar:_elem [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:foo:_elem</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> + reagent callsite<span class="Delimiter">(</span><span class="Constant">"x:bar:point"</span><span class="Delimiter">);</span> + reagent element = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"x"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"point"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +void test_replace_type_ingredients_head_tail_multiple<span class="Delimiter">()</span> <span class="Delimiter">{</span> + run<span class="Delimiter">(</span><span class="Constant">"container foo:_elem [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:_elem</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"container bar:_elem [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:foo:_elem</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> + reagent callsite<span class="Delimiter">(</span><span class="Constant">"x:bar:address:shared:array:character"</span><span class="Delimiter">);</span> + reagent element = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"x"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"character"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +void test_replace_type_ingredients_head_middle<span class="Delimiter">()</span> <span class="Delimiter">{</span> + run<span class="Delimiter">(</span><span class="Constant">"container foo:_elem [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:_elem</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"container bar:_elem [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:foo:_elem:number</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> + reagent callsite<span class="Delimiter">(</span><span class="Constant">"x:bar:address"</span><span class="Delimiter">);</span> + reagent element = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"x"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">)</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> + CHECK_EQ<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"number"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +void test_replace_last_type_ingredient_with_multiple<span class="Delimiter">()</span> <span class="Delimiter">{</span> + run<span class="Delimiter">(</span><span class="Constant">"container foo:_a:_b [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:_a</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" y:_b</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> + reagent callsite<span class="Delimiter">(</span><span class="Constant">"{f: (foo number (address shared array character))}"</span><span class="Delimiter">);</span> + reagent element1 = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element1<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"x"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element1<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"number"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element1<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + reagent element2 = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"y"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"character"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +void test_replace_middle_type_ingredient_with_multiple<span class="Delimiter">()</span> <span class="Delimiter">{</span> + run<span class="Delimiter">(</span><span class="Constant">"container foo:_a:_b:_c [</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" x:_a</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" y:_b</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">" z:_c</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> + reagent callsite<span class="Delimiter">(</span><span class="Constant">"{f: (foo number (address shared array character) boolean)}"</span><span class="Delimiter">);</span> + reagent element1 = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element1<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"x"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element1<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"number"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element1<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + reagent element2 = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"y"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"character"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element2<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + reagent element3 = element_type<span class="Delimiter">(</span>callsite<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element3<span class="Delimiter">.</span>name<span class="Delimiter">,</span> <span class="Constant">"z"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>element3<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> <span class="Constant">"boolean"</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>!element3<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> bool has_nth_type<span class="Delimiter">(</span>const type_tree* base<span class="Delimiter">,</span> long long int n<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -238,7 +479,7 @@ recipe main [ <span class="Constant">10</span>:foo:point<span class="Special"> <- </span>merge <span class="Constant">14</span><span class="Delimiter">,</span> <span class="Constant">15</span><span class="Delimiter">,</span> <span class="Constant">16</span> <span class="Constant">1</span>:number<span class="Special"> <- </span>get <span class="Constant">10</span>:foo<span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] -<span class="traceContains">+error: illegal type 'foo' seems to be missing a type ingredient or three</span> +<span class="traceContains">+error: illegal type "foo" seems to be missing a type ingredient or three</span> <span class="Comment">//: get-address similarly</span> @@ -254,29 +495,104 @@ recipe main [ <span class="traceContains">+mem: storing 12 in location 1</span> <span class="Delimiter">:(before "End GET_ADDRESS field Cases")</span> -const type_tree* type = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +const type_tree* type = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">;</span> if <span class="Delimiter">(</span>type<span class="Delimiter">-></span>value >= START_TYPE_INGREDIENTS<span class="Delimiter">)</span> <span class="Delimiter">{</span> long long int size = size_of_type_ingredient<span class="Delimiter">(</span>type<span class="Delimiter">,</span> base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> if <span class="Delimiter">(</span>!size<span class="Delimiter">)</span> - raise_error << <span class="Constant">"illegal type '"</span> << debug_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="Constant">"' seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"illegal type '"</span> << to_string<span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="Constant">"' seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> result += size<span class="Delimiter">;</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(scenario get_on_shape_shifting_container_inside_shape_shifting_container)</span> -container foo:_t [ - x:_t +<span class="Comment">//: 'merge' on shape-shifting containers</span> + +<span class="Delimiter">:(scenario merge_check_shape_shifting_container_containing_exclusive_container)</span> +<span class="Special">% Hide_errors = true;</span> +container foo:_elem [ + x:number + y:_elem +] +exclusive-container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo:bar<span class="Special"> <- </span>merge <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">34</span> +] +<span class="traceContains">+mem: storing 23 in location 1</span> +<span class="traceContains">+mem: storing 1 in location 2</span> +<span class="traceContains">+mem: storing 34 in location 3</span> +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_check_shape_shifting_container_containing_exclusive_container_2)</span> +<span class="Special">% Hide_errors = true;</span> +container foo:_elem [ + x:number + y:_elem +] +exclusive-container bar [ + x:number y:number ] +recipe main [ + <span class="Constant">1</span>:foo:bar<span class="Special"> <- </span>merge <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span> +] +<span class="traceContains">+error: main: too many ingredients in '1:foo:bar <- merge 23, 1/y, 34, 35'</span> + +<span class="Delimiter">:(scenario merge_check_shape_shifting_exclusive_container_containing_container)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo:_elem [ + x:number + y:_elem +] container bar [ - x:foo:point + x:number y:number ] recipe main [ - <span class="Constant">1</span>:bar<span class="Special"> <- </span>merge <span class="Constant">14</span><span class="Delimiter">,</span> <span class="Constant">15</span><span class="Delimiter">,</span> <span class="Constant">16</span><span class="Delimiter">,</span> <span class="Constant">17</span> - <span class="Constant">2</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:bar<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">1</span>:foo:bar<span class="Special"> <- </span>merge <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">34</span> ] -<span class="traceContains">+mem: storing 17 in location 2</span> +<span class="traceContains">+mem: storing 1 in location 1</span> +<span class="traceContains">+mem: storing 23 in location 2</span> +<span class="traceContains">+mem: storing 34 in location 3</span> +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_check_shape_shifting_exclusive_container_containing_container_2)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo:_elem [ + x:number + y:_elem +] +container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo:bar<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">23</span> +] +$error: <span class="Constant">0</span> + +<span class="Delimiter">:(scenario merge_check_shape_shifting_exclusive_container_containing_container_3)</span> +<span class="Special">% Hide_errors = true;</span> +exclusive-container foo:_elem [ + x:number + y:_elem +] +container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo:bar<span class="Special"> <- </span>merge <span class="Constant">1</span>/y<span class="Delimiter">,</span> <span class="Constant">23</span> +] +<span class="traceContains">+error: main: too few ingredients in '1:foo:bar <- merge 1/y, 23'</span> + +<span class="Delimiter">:(before "End variant_type Special-cases")</span> +if <span class="Delimiter">(</span>contains_type_ingredient<span class="Delimiter">(</span>element<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> + raise_error << <span class="Constant">"illegal type '"</span> << to_string<span class="Delimiter">(</span>canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">"' seems to be missing a type ingredient or three</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + replace_type_ingredients<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">,</span> canonized_base<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> info<span class="Delimiter">);</span> +<span class="Delimiter">}</span> </pre> </body> </html> diff --git a/html/059shape_shifting_recipe.cc.html b/html/059shape_shifting_recipe.cc.html index 857bfca0..294f5e7e 100644 --- a/html/059shape_shifting_recipe.cc.html +++ b/html/059shape_shifting_recipe.cc.html @@ -22,6 +22,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } .SalientComment { color: #00ffff; } .Identifier { color: #804000; } .Constant { color: #00a0a0; } +.Todo { color: #000000; background-color: #ffff00; padding-bottom: 1px; } --> </style> @@ -84,48 +85,42 @@ if <span class="Delimiter">(</span>contains_type_ingredient_name<span class="Del <span class="Delimiter">:(before "End Globals")</span> vector<recipe_ordinal> Recently_added_shape_shifting_recipes<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> -<span class="CommentedCode">//? cerr << "setup: clearing recently-added shape-shifting recipes\n";</span> Recently_added_shape_shifting_recipes<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Comment">//: make sure we don't clear any of these recipes when we start running tests</span> <span class="Delimiter">:(before "End Loading .mu Files")</span> Recently_added_recipes<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Recently_added_types<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "clearing recently-added shape-shifting recipes\n";</span> Recently_added_shape_shifting_recipes<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Comment">//: save original name of specialized recipes</span> <span class="Delimiter">:(before "End recipe Fields")</span> string original_name<span class="Delimiter">;</span> <span class="Comment">//: original name is only set during load</span> -<span class="Delimiter">:(before "End recipe Refinements")</span> +<span class="Delimiter">:(before "End Load Recipe Name")</span> result<span class="Delimiter">.</span>original_name = result<span class="Delimiter">.</span>name<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Instruction Dispatch(inst, best_score)")</span> -if <span class="Delimiter">(</span>best_score == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"no variant found; searching for variant with suitable type ingredients"</span> << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "no variant found for " << inst.name << "; searching for variant with suitable type ingredients" << '\n';</span> - recipe_ordinal exemplar = pick_matching_shape_shifting_variant<span class="Delimiter">(</span>variants<span class="Delimiter">,</span> inst<span class="Delimiter">,</span> best_score<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>exemplar<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cerr << "specializing " << inst.name << '\n';</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"found variant to specialize: "</span> << exemplar << <span class="Constant">' '</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> exemplar<span class="Delimiter">).</span>name << end<span class="Delimiter">();</span> - recipe_ordinal new_recipe_ordinal = new_variant<span class="Delimiter">(</span>exemplar<span class="Delimiter">,</span> inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>new_recipe_ordinal == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">goto</span> done_constructing_variant<span class="Delimiter">;</span> - variants<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new_recipe_ordinal<span class="Delimiter">);</span> - recipe& variant = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> new_recipe_ordinal<span class="Delimiter">);</span> - <span class="Comment">// perform all transforms on the new specialization</span> - if <span class="Delimiter">(</span>!variant<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"transforming new specialization: "</span> << variant<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> - for <span class="Delimiter">(</span>long long int t = <span class="Constant">0</span><span class="Delimiter">;</span> t < SIZE<span class="Delimiter">(</span>Transform<span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Delimiter">(</span>*Transform<span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span>new_recipe_ordinal<span class="Delimiter">);</span> - <span class="Delimiter">}</span> +<span class="Delimiter">:(after "Static Dispatch Phase 2")</span> +candidates = strictly_matching_shape_shifting_variants<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">);</span> +if <span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + recipe_ordinal exemplar = best_shape_shifting_variant<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> candidates<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"found variant to specialize: "</span> << exemplar << <span class="Constant">' '</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> exemplar<span class="Delimiter">).</span>name << end<span class="Delimiter">();</span> + recipe_ordinal new_recipe_ordinal = new_variant<span class="Delimiter">(</span>exemplar<span class="Delimiter">,</span> inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>new_recipe_ordinal == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">goto</span> skip_shape_shifting_variants<span class="Delimiter">;</span> + variants<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new_recipe_ordinal<span class="Delimiter">);</span> <span class="Comment">// side-effect</span> + recipe& variant = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> new_recipe_ordinal<span class="Delimiter">);</span> + <span class="Comment">// perform all transforms on the new specialization</span> + if <span class="Delimiter">(</span>!variant<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"transforming new specialization: "</span> << variant<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> + for <span class="Delimiter">(</span>long long int t = <span class="Constant">0</span><span class="Delimiter">;</span> t < SIZE<span class="Delimiter">(</span>Transform<span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Delimiter">(</span>*Transform<span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span>new_recipe_ordinal<span class="Delimiter">);</span> <span class="Delimiter">}</span> - variant<span class="Delimiter">.</span>transformed_until = SIZE<span class="Delimiter">(</span>Transform<span class="Delimiter">)</span>-<span class="Constant">1</span><span class="Delimiter">;</span> - inst<span class="Delimiter">.</span>name = variant<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"new specialization: "</span> << inst<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - done_constructing_variant:<span class="Delimiter">;</span> + variant<span class="Delimiter">.</span>transformed_until = SIZE<span class="Delimiter">(</span>Transform<span class="Delimiter">)</span>-<span class="Constant">1</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"new specialization: "</span> << variant<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> variant<span class="Delimiter">.</span>name<span class="Delimiter">;</span> <span class="Delimiter">}</span> +skip_shape_shifting_variants:<span class="Delimiter">;</span> <span class="Comment">//: make sure we have no unspecialized shape-shifting recipes being called</span> <span class="Comment">//: before running mu programs</span> @@ -138,82 +133,70 @@ if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>R <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -string header<span class="Delimiter">(</span>const recipe& caller<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!caller<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">return</span> maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">);</span> - ostringstream out<span class="Delimiter">;</span> - out << caller<span class="Delimiter">.</span>name<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>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">','</span><span class="Delimiter">;</span> - out << <span class="Constant">' '</span> << debug_string<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>!caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - out << <span class="Constant">" ->"</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>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">','</span><span class="Delimiter">;</span> - out << <span class="Constant">' '</span> << debug_string<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - <span class="Delimiter">}</span> - <span class="Delimiter">}</span> - out << <span class="Constant">": "</span><span class="Delimiter">;</span> - <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> -<span class="Delimiter">}</span> - -recipe_ordinal pick_matching_shape_shifting_variant<span class="Delimiter">(</span>vector<recipe_ordinal>& variants<span class="Delimiter">,</span> const instruction& inst<span class="Delimiter">,</span> long long int& best_score<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cerr << "---- " << inst.name << ": " << non_ghost_size(variants) << '\n';</span> - recipe_ordinal result = <span class="Constant">0</span><span class="Delimiter">;</span> +<span class="Comment">// phase 2 of static dispatch</span> +vector<recipe_ordinal> strictly_matching_shape_shifting_variants<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<recipe_ordinal> result<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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// ghost from a previous test</span> -<span class="CommentedCode">//? cerr << "-- variant " << i << "\n" << debug_string(get(Recipe, variants.at(i)));</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"checking shape-shifting variant "</span> << i << end<span class="Delimiter">();</span> - long long int current_score = shape_shifting_variant_score<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"final score: "</span> << current_score << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << get(Recipe, variants.at(i)).name << ": " << current_score << '\n';</span> - if <span class="Delimiter">(</span>current_score > best_score<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9992</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"matches"</span> << end<span class="Delimiter">();</span> - result = variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - best_score = current_score<span class="Delimiter">;</span> - <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!any_type_ingredient_in_header<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>all_concrete_header_reagents_strictly_match<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))))</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -long long int shape_shifting_variant_score<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> recipe_ordinal variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cerr << "======== " << inst.to_string() << '\n';</span> - if <span class="Delimiter">(</span>!any_type_ingredient_in_header<span class="Delimiter">(</span>variant<span class="Delimiter">))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"no type ingredients"</span> << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "no type ingredients\n";</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - const vector<reagent>& header_ingredients = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>ingredients<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> < SIZE<span class="Delimiter">(</span>header_ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> +bool all_concrete_header_reagents_strictly_match<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> const recipe& variant<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> < SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"too few ingredients"</span> << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "too few ingredients\n";</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><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>header_ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!deeply_equal_concrete_types<span class="Delimiter">(</span>header_ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"mismatch: ingredient "</span> << i << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "mismatch: ingredient " << i << ": " << debug_string(header_ingredients.at(i)) << " vs " << debug_string(inst.ingredients.at(i)) << '\n';</span> - <span class="Identifier">return</span> -<span class="Constant">1</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> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>products<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">)</span> < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">))</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"too few products"</span> << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "too few products\n";</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> <span class="Constant">false</span><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>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!concrete_type_names_strictly_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"concrete-type match failed: ingredient "</span> << i << end<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">}</span> - const vector<reagent>& header_products = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>products<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>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!deeply_equal_concrete_types<span class="Delimiter">(</span>header_products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"mismatch: product "</span> << i << end<span class="Delimiter">();</span> -<span class="CommentedCode">//? cerr << "mismatch: product " << i << '\n';</span> - <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!concrete_type_names_strictly_match<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"strict match failed: product "</span> << i << end<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">}</span> + <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Comment">// tie-breaker for phase 2</span> +recipe_ordinal best_shape_shifting_variant<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> vector<recipe_ordinal>& candidates<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!candidates<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + <span class="Comment">// primary score</span> + long long int max_score = -<span class="Constant">1</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>candidates<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int score = number_of_concrete_type_names<span class="Delimiter">(</span>candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + assert<span class="Delimiter">(</span>score > -<span class="Constant">1</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>score > max_score<span class="Delimiter">)</span> max_score = score<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Comment">// break any ties at max_score by a secondary score</span> + long long int min_score2 = <span class="Constant">999</span><span class="Delimiter">;</span> + long long int best_index = <span class="Constant">0</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>candidates<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int score1 = number_of_concrete_type_names<span class="Delimiter">(</span>candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + assert<span class="Delimiter">(</span>score1 <= max_score<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>score1 != max_score<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + const recipe& candidate = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + long long int score2 = <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>candidate<span class="Delimiter">.</span>products<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">))</span> + + <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>candidate<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> + assert<span class="Delimiter">(</span>score2 < <span class="Constant">999</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>score2 < min_score2<span class="Delimiter">)</span> <span class="Delimiter">{</span> + min_score2 = score2<span class="Delimiter">;</span> + best_index = i<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Comment">// the greater the number of unused ingredients, the lower the score</span> - <span class="Identifier">return</span> <span class="Constant">100</span> - <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>products<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">))</span> - - <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>-SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> variant<span class="Delimiter">).</span>ingredients<span class="Delimiter">))</span> <span class="Comment">// ok to go negative</span> - + number_of_concrete_types<span class="Delimiter">(</span>variant<span class="Delimiter">);</span> + <span class="Identifier">return</span> candidates<span class="Delimiter">.</span>at<span class="Delimiter">(</span>best_index<span class="Delimiter">);</span> <span class="Delimiter">}</span> bool any_type_ingredient_in_header<span class="Delimiter">(</span>recipe_ordinal variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -229,73 +212,67 @@ bool any_type_ingredient_in_header<span class="Delimiter">(</span>recipe_ordinal <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -bool deeply_equal_concrete_types<span class="Delimiter">(</span>reagent to<span class="Delimiter">,</span> reagent from<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool concrete_type_names_strictly_match<span class="Delimiter">(</span>reagent to<span class="Delimiter">,</span> reagent from<span class="Delimiter">)</span> <span class="Delimiter">{</span> canonize_type<span class="Delimiter">(</span>to<span class="Delimiter">);</span> canonize_type<span class="Delimiter">(</span>from<span class="Delimiter">);</span> - <span class="Identifier">return</span> deeply_equal_concrete_types<span class="Delimiter">(</span>to<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> from<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> from<span class="Delimiter">);</span> + <span class="Identifier">return</span> concrete_type_names_strictly_match<span class="Delimiter">(</span>to<span class="Delimiter">.</span>type<span class="Delimiter">,</span> from<span class="Delimiter">.</span>type<span class="Delimiter">,</span> from<span class="Delimiter">);</span> <span class="Delimiter">}</span> -long long int number_of_concrete_types<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int number_of_concrete_type_names<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> long long int result = <span class="Constant">0</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>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - result += number_of_concrete_types<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + result += number_of_concrete_type_names<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - result += number_of_concrete_types<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + result += number_of_concrete_type_names<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -long long int number_of_concrete_types<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> number_of_concrete_types<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> +long long int number_of_concrete_type_names<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> number_of_concrete_type_names<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Delimiter">}</span> -long long int number_of_concrete_types<span class="Delimiter">(</span>const string_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int number_of_concrete_type_names<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>value<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>value<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>name<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> result++<span class="Delimiter">;</span> - result += number_of_concrete_types<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">);</span> - result += number_of_concrete_types<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + result += number_of_concrete_type_names<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">);</span> + result += number_of_concrete_type_names<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -bool deeply_equal_concrete_types<span class="Delimiter">(</span>const string_tree* to<span class="Delimiter">,</span> const string_tree* from<span class="Delimiter">,</span> const reagent& rhs_reagent<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool concrete_type_names_strictly_match<span class="Delimiter">(</span>const type_tree* to<span class="Delimiter">,</span> const type_tree* from<span class="Delimiter">,</span> const reagent& rhs_reagent<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!to<span class="Delimiter">)</span> <span class="Identifier">return</span> !from<span class="Delimiter">;</span> if <span class="Delimiter">(</span>!from<span class="Delimiter">)</span> <span class="Identifier">return</span> !to<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>to<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// type ingredient matches anything</span> - if <span class="Delimiter">(</span>to<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span> && from<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>to<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// type ingredient matches anything</span> + if <span class="Delimiter">(</span>to<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span> && from<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>to<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span> - && Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>from<span class="Delimiter">-></span>value<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>to<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span> + && Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>from<span class="Delimiter">-></span>name<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>from<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span> - && Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>to<span class="Delimiter">-></span>value<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>from<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span> + && Literal_type_names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>to<span class="Delimiter">-></span>name<span class="Delimiter">)</span> != Literal_type_names<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>from<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span> && to<span class="Delimiter">-></span>value == <span class="Constant">"address"</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>from<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span> && to<span class="Delimiter">-></span>name == <span class="Constant">"address"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> rhs_reagent<span class="Delimiter">.</span>name == <span class="Constant">"0"</span><span class="Delimiter">;</span> -<span class="CommentedCode">//? cerr << to->value << " vs " << from->value << '\n';</span> - <span class="Identifier">return</span> to<span class="Delimiter">-></span>value == from<span class="Delimiter">-></span>value - && deeply_equal_concrete_types<span class="Delimiter">(</span>to<span class="Delimiter">-></span>left<span class="Delimiter">,</span> from<span class="Delimiter">-></span>left<span class="Delimiter">,</span> rhs_reagent<span class="Delimiter">)</span> - && deeply_equal_concrete_types<span class="Delimiter">(</span>to<span class="Delimiter">-></span>right<span class="Delimiter">,</span> from<span class="Delimiter">-></span>right<span class="Delimiter">,</span> rhs_reagent<span class="Delimiter">);</span> + <span class="Identifier">return</span> to<span class="Delimiter">-></span>name == from<span class="Delimiter">-></span>name + && concrete_type_names_strictly_match<span class="Delimiter">(</span>to<span class="Delimiter">-></span>left<span class="Delimiter">,</span> from<span class="Delimiter">-></span>left<span class="Delimiter">,</span> rhs_reagent<span class="Delimiter">)</span> + && concrete_type_names_strictly_match<span class="Delimiter">(</span>to<span class="Delimiter">-></span>right<span class="Delimiter">,</span> from<span class="Delimiter">-></span>right<span class="Delimiter">,</span> rhs_reagent<span class="Delimiter">);</span> <span class="Delimiter">}</span> bool contains_type_ingredient_name<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> contains_type_ingredient_name<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> + <span class="Identifier">return</span> contains_type_ingredient_name<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Delimiter">}</span> -bool contains_type_ingredient_name<span class="Delimiter">(</span>const string_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool contains_type_ingredient_name<span class="Delimiter">(</span>const type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Identifier">return</span> contains_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">)</span> || contains_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> -bool is_type_ingredient_name<span class="Delimiter">(</span>const string& type<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> !type<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && type<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'_'</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> - recipe_ordinal new_variant<span class="Delimiter">(</span>recipe_ordinal exemplar<span class="Delimiter">,</span> const instruction& inst<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> string new_name = next_unused_recipe_name<span class="Delimiter">(</span>inst<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">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"switching "</span> << inst<span class="Delimiter">.</span>name << <span class="Constant">" to "</span> << new_name << end<span class="Delimiter">();</span> assert<span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> new_name<span class="Delimiter">));</span> recipe_ordinal new_recipe_ordinal = put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> new_name<span class="Delimiter">,</span> Next_recipe_ordinal++<span class="Delimiter">);</span> <span class="Comment">// make a copy</span> @@ -306,16 +283,17 @@ recipe_ordinal new_variant<span class="Delimiter">(</span>recipe_ordinal exempla put<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> new_recipe_ordinal<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> exemplar<span class="Delimiter">));</span> recipe& new_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> new_recipe_ordinal<span class="Delimiter">);</span> new_recipe<span class="Delimiter">.</span>name = new_name<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"switching "</span> << inst<span class="Delimiter">.</span>name << <span class="Constant">" to specialized "</span> << header_label<span class="Delimiter">(</span>new_recipe_ordinal<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span class="Comment">// Since the exemplar never ran any transforms, we have to redo some of the</span> <span class="Comment">// work of the check_types_by_name transform while supporting type-ingredients.</span> compute_type_names<span class="Delimiter">(</span>new_recipe<span class="Delimiter">);</span> <span class="Comment">// that gives enough information to replace type-ingredients with concrete types</span> <span class="Delimiter">{</span> - map<string<span class="Delimiter">,</span> const string_tree*> mappings<span class="Delimiter">;</span> + map<string<span class="Delimiter">,</span> const type_tree*> mappings<span class="Delimiter">;</span> bool error = <span class="Constant">false</span><span class="Delimiter">;</span> compute_type_ingredient_mappings<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> exemplar<span class="Delimiter">),</span> inst<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> &error<span class="Delimiter">);</span> if <span class="Delimiter">(</span>!error<span class="Delimiter">)</span> replace_type_ingredients<span class="Delimiter">(</span>new_recipe<span class="Delimiter">,</span> mappings<span class="Delimiter">);</span> - for <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> const string_tree*>::iterator p = mappings<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != mappings<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> const type_tree*>::iterator p = mappings<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != mappings<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> delete p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> if <span class="Delimiter">(</span>error<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// todo: delete new_recipe_ordinal from Recipes and other global state</span> <span class="Delimiter">}</span> @@ -325,14 +303,14 @@ recipe_ordinal new_variant<span class="Delimiter">(</span>recipe_ordinal exempla void compute_type_names<span class="Delimiter">(</span>recipe& variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"compute type names: "</span> << variant<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> - map<string<span class="Delimiter">,</span> string_tree*> type_names<span class="Delimiter">;</span> + map<string<span class="Delimiter">,</span> type_tree*> type_names<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>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> save_or_deduce_type_name<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> type_names<span class="Delimiter">,</span> variant<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>variant<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> save_or_deduce_type_name<span class="Delimiter">(</span>variant<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> type_names<span class="Delimiter">,</span> variant<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>variant<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = variant<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" instruction: "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" instruction: "</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << end<span class="Delimiter">();</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> save_or_deduce_type_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> type_names<span class="Delimiter">,</span> variant<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> @@ -340,29 +318,28 @@ void compute_type_names<span class="Delimiter">(</span>recipe& variant<span <span class="Delimiter">}</span> <span class="Delimiter">}</span> -void save_or_deduce_type_name<span class="Delimiter">(</span>reagent& x<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> string_tree*>& type_name<span class="Delimiter">,</span> const recipe& variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9994</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" checking "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">": "</span> << debug_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second && contains_key<span class="Delimiter">(</span>type_name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = new string_tree<span class="Delimiter">(</span>*get<span class="Delimiter">(</span>type_name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">9994</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" deducing type to "</span> << debug_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +void save_or_deduce_type_name<span class="Delimiter">(</span>reagent& x<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> type_tree*>& type<span class="Delimiter">,</span> const recipe& variant<span class="Delimiter">)</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9994</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" checking "</span> << to_string<span class="Delimiter">(</span>x<span class="Delimiter">)</span> << <span class="Constant">": "</span> << names_to_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type && contains_key<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + x<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*get<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">));</span> <span class="Comment">//</span><span class="Todo">TODO</span> + trace<span class="Delimiter">(</span><span class="Constant">9994</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" deducing type to "</span> << names_to_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<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>variant<span class="Delimiter">.</span>original_name<span class="Delimiter">)</span> << <span class="Constant">"unknown type for "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" (check the name for typos)</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>type_name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"offset"</span> || x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"variant"</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// special-case for container-access instructions</span> - put<span class="Delimiter">(</span>type_name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" is "</span> << debug_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"offset"</span> || x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"variant"</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// special-case for container-access instructions</span> + put<span class="Delimiter">(</span>type<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">,</span> x<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"type of "</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" is "</span> << names_to_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> -void compute_type_ingredient_mappings<span class="Delimiter">(</span>const recipe& exemplar<span class="Delimiter">,</span> const instruction& inst<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> const string_tree*>& mappings<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">,</span> bool* error<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void compute_type_ingredient_mappings<span class="Delimiter">(</span>const recipe& exemplar<span class="Delimiter">,</span> const instruction& inst<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> const type_tree*>& mappings<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">,</span> bool* error<span class="Delimiter">)</span> <span class="Delimiter">{</span> long long int limit = min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>exemplar<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < limit<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> const reagent& exemplar_reagent = exemplar<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> reagent ingredient = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>ingredient<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> canonize_type<span class="Delimiter">(</span>ingredient<span class="Delimiter">);</span> if <span class="Delimiter">(</span>is_mu_address<span class="Delimiter">(</span>exemplar_reagent<span class="Delimiter">)</span> && ingredient<span class="Delimiter">.</span>name == <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// assume it matches</span> accumulate_type_ingredients<span class="Delimiter">(</span>exemplar_reagent<span class="Delimiter">,</span> ingredient<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> exemplar<span class="Delimiter">,</span> inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> error<span class="Delimiter">);</span> @@ -371,7 +348,6 @@ void compute_type_ingredient_mappings<span class="Delimiter">(</span>const recip for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < limit<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> const reagent& exemplar_reagent = exemplar<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> reagent product = inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>product<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">);</span> accumulate_type_ingredients<span class="Delimiter">(</span>exemplar_reagent<span class="Delimiter">,</span> product<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> exemplar<span class="Delimiter">,</span> inst<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> error<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -381,39 +357,33 @@ inline long long int min<span class="Delimiter">(</span>long long int a<span cla <span class="Identifier">return</span> <span class="Delimiter">(</span>a < b<span class="Delimiter">)</span> ? a : b<span class="Delimiter">;</span> <span class="Delimiter">}</span> -void accumulate_type_ingredients<span class="Delimiter">(</span>const reagent& exemplar_reagent<span class="Delimiter">,</span> reagent& refinement<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> const string_tree*>& mappings<span class="Delimiter">,</span> const recipe& exemplar<span class="Delimiter">,</span> const instruction& call_instruction<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">,</span> bool* error<span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>refinement<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - accumulate_type_ingredients<span class="Delimiter">(</span>exemplar_reagent<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> refinement<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> exemplar<span class="Delimiter">,</span> exemplar_reagent<span class="Delimiter">,</span> call_instruction<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> error<span class="Delimiter">);</span> +void accumulate_type_ingredients<span class="Delimiter">(</span>const reagent& exemplar_reagent<span class="Delimiter">,</span> reagent& refinement<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> const type_tree*>& mappings<span class="Delimiter">,</span> const recipe& exemplar<span class="Delimiter">,</span> const instruction& call_instruction<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">,</span> bool* error<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>refinement<span class="Delimiter">.</span>type<span class="Delimiter">);</span> + accumulate_type_ingredients<span class="Delimiter">(</span>exemplar_reagent<span class="Delimiter">.</span>type<span class="Delimiter">,</span> refinement<span class="Delimiter">.</span>type<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> exemplar<span class="Delimiter">,</span> exemplar_reagent<span class="Delimiter">,</span> call_instruction<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> error<span class="Delimiter">);</span> <span class="Delimiter">}</span> -void accumulate_type_ingredients<span class="Delimiter">(</span>const string_tree* exemplar_type<span class="Delimiter">,</span> const string_tree* refinement_type<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> const string_tree*>& mappings<span class="Delimiter">,</span> const recipe& exemplar<span class="Delimiter">,</span> const reagent& exemplar_reagent<span class="Delimiter">,</span> const instruction& call_instruction<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">,</span> bool* error<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void accumulate_type_ingredients<span class="Delimiter">(</span>const type_tree* exemplar_type<span class="Delimiter">,</span> const type_tree* refinement_type<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> const type_tree*>& mappings<span class="Delimiter">,</span> const recipe& exemplar<span class="Delimiter">,</span> const reagent& exemplar_reagent<span class="Delimiter">,</span> const instruction& call_instruction<span class="Delimiter">,</span> const recipe& caller_recipe<span class="Delimiter">,</span> bool* error<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!exemplar_type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>!refinement_type<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Comment">// todo: make this smarter; only warn if exemplar_type contains some *new* type ingredient</span> + <span class="Comment">// todo: make this smarter; only flag an error if exemplar_type contains some *new* type ingredient</span> raise_error << maybe<span class="Delimiter">(</span>exemplar<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"missing type ingredient in "</span> << exemplar_reagent<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>!exemplar_type<span class="Delimiter">-></span>value<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && exemplar_type<span class="Delimiter">-></span>value<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'_'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>!refinement_type<span class="Delimiter">-></span>value<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> - if <span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"type_ingredients in non-last position not currently supported</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"adding mapping from "</span> << exemplar_type<span class="Delimiter">-></span>value << <span class="Constant">" to "</span> << debug_string<span class="Delimiter">(</span>refinement_type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - put<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>value<span class="Delimiter">,</span> new string_tree<span class="Delimiter">(</span>*refinement_type<span class="Delimiter">));</span> + if <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!refinement_type<span class="Delimiter">-></span>name<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"adding mapping from "</span> << exemplar_type<span class="Delimiter">-></span>name << <span class="Constant">" to "</span> << to_string<span class="Delimiter">(</span>refinement_type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + put<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> new type_tree<span class="Delimiter">(</span>*refinement_type<span class="Delimiter">));</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!deeply_equal_types<span class="Delimiter">(</span>get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>value<span class="Delimiter">),</span> refinement_type<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"no call found for '"</span> << call_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> -<span class="CommentedCode">//? cerr << exemplar_type->value << ": " << debug_string(get(mappings, exemplar_type->value)) << " vs " << debug_string(refinement_type) << '\n';</span> + if <span class="Delimiter">(</span>!deeply_equal_type_names<span class="Delimiter">(</span>get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">),</span> refinement_type<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>caller_recipe<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"no call found for '"</span> << to_string<span class="Delimiter">(</span>call_instruction<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> *error = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="CommentedCode">//? cerr << exemplar_type->value << ": " << debug_string(get(mappings, exemplar_type->value)) << " <= " << debug_string(refinement_type) << '\n';</span> - if <span class="Delimiter">(</span>get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>value<span class="Delimiter">)-></span>value == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - delete get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> - put<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>value<span class="Delimiter">,</span> new string_tree<span class="Delimiter">(</span>*refinement_type<span class="Delimiter">));</span> + if <span class="Delimiter">(</span>get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">)-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + delete get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + put<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> exemplar_type<span class="Delimiter">-></span>name<span class="Delimiter">,</span> new type_tree<span class="Delimiter">(</span>*refinement_type<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -423,7 +393,7 @@ void accumulate_type_ingredients<span class="Delimiter">(</span>const string_tre accumulate_type_ingredients<span class="Delimiter">(</span>exemplar_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> refinement_type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> mappings<span class="Delimiter">,</span> exemplar<span class="Delimiter">,</span> exemplar_reagent<span class="Delimiter">,</span> call_instruction<span class="Delimiter">,</span> caller_recipe<span class="Delimiter">,</span> error<span class="Delimiter">);</span> <span class="Delimiter">}</span> -void replace_type_ingredients<span class="Delimiter">(</span>recipe& new_recipe<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> const string_tree*>& mappings<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void replace_type_ingredients<span class="Delimiter">(</span>recipe& new_recipe<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> const type_tree*>& mappings<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// update its header</span> if <span class="Delimiter">(</span>mappings<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"replacing in recipe header ingredients"</span> << end<span class="Delimiter">();</span> @@ -435,52 +405,118 @@ void replace_type_ingredients<span class="Delimiter">(</span>recipe& new_rec <span class="Comment">// update its body</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>new_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = new_recipe<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"replacing in instruction '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"replacing in instruction '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> replace_type_ingredients<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">),</span> mappings<span class="Delimiter">,</span> new_recipe<span class="Delimiter">);</span> for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> replace_type_ingredients<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">),</span> mappings<span class="Delimiter">,</span> new_recipe<span class="Delimiter">);</span> <span class="Comment">// special-case for new: replace type ingredient in first ingredient *value*</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"new"</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>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value != <span class="Constant">"literal-string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - string_tree* type_name = parse_string_tree<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>name<span class="Delimiter">);</span> - replace_type_ingredients<span class="Delimiter">(</span>type_name<span class="Delimiter">,</span> mappings<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>name = type_name<span class="Delimiter">-></span>to_string<span class="Delimiter">();</span> - delete type_name<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"new"</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>name != <span class="Constant">"literal-string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + type_tree* type = parse_type_tree<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>name<span class="Delimiter">);</span> + replace_type_ingredients<span class="Delimiter">(</span>type<span class="Delimiter">,</span> mappings<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>name = inspect<span class="Delimiter">(</span>type<span class="Delimiter">);</span> + delete type<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -void replace_type_ingredients<span class="Delimiter">(</span>reagent& x<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> const string_tree*>& mappings<span class="Delimiter">,</span> const recipe& caller<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void replace_type_ingredients<span class="Delimiter">(</span>reagent& x<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> const type_tree*>& mappings<span class="Delimiter">,</span> const recipe& caller<span class="Delimiter">)</span> <span class="Delimiter">{</span> + string before = to_string<span class="Delimiter">(</span>x<span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"replacing in ingredient "</span> << x<span class="Delimiter">.</span>original_string << end<span class="Delimiter">();</span> - <span class="Comment">// replace properties</span> - if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<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 << <span class="Constant">"specializing "</span> << caller<span class="Delimiter">.</span>original_name << <span class="Constant">": missing type for "</span> << x<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - replace_type_ingredients<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">,</span> mappings<span class="Delimiter">);</span> - <span class="Comment">// refresh types from properties</span> - delete x<span class="Delimiter">.</span>type<span class="Delimiter">;</span> - x<span class="Delimiter">.</span>type = new_type_tree<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">" after: "</span> << debug_string<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + replace_type_ingredients<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">,</span> mappings<span class="Delimiter">);</span> <span class="Delimiter">}</span> -void replace_type_ingredients<span class="Delimiter">(</span>string_tree* type<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> const string_tree*>& mappings<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void replace_type_ingredients<span class="Delimiter">(</span>type_tree* type<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> const type_tree*>& mappings<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>value<span class="Delimiter">)</span> && contains_key<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> type<span class="Delimiter">-></span>value<span class="Delimiter">))</span> <span class="Delimiter">{</span> - const string_tree* replacement = get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << type<span class="Delimiter">-></span>value << <span class="Constant">" => "</span> << debug_string<span class="Delimiter">(</span>replacement<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>replacement<span class="Delimiter">-></span>value == <span class="Constant">"literal"</span><span class="Delimiter">)</span> - type<span class="Delimiter">-></span>value = <span class="Constant">"number"</span><span class="Delimiter">;</span> - else + if <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Comment">// todo: ugly side effect</span> + type<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>is_type_ingredient_name<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">)</span> && contains_key<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + const type_tree* replacement = get<span class="Delimiter">(</span>mappings<span class="Delimiter">,</span> type<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">"transform"</span><span class="Delimiter">)</span> << type<span class="Delimiter">-></span>name << <span class="Constant">" => "</span> << names_to_string<span class="Delimiter">(</span>replacement<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>replacement<span class="Delimiter">-></span>name == <span class="Constant">"literal"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + type<span class="Delimiter">-></span>name = <span class="Constant">"number"</span><span class="Delimiter">;</span> + type<span class="Delimiter">-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"number"</span><span class="Delimiter">);</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + type<span class="Delimiter">-></span>name = replacement<span class="Delimiter">-></span>name<span class="Delimiter">;</span> type<span class="Delimiter">-></span>value = replacement<span class="Delimiter">-></span>value<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>replacement<span class="Delimiter">-></span>left<span class="Delimiter">)</span> type<span class="Delimiter">-></span>left = new string_tree<span class="Delimiter">(</span>*replacement<span class="Delimiter">-></span>left<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>replacement<span class="Delimiter">-></span>right<span class="Delimiter">)</span> type<span class="Delimiter">-></span>right = new string_tree<span class="Delimiter">(</span>*replacement<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>replacement<span class="Delimiter">-></span>left<span class="Delimiter">)</span> type<span class="Delimiter">-></span>left = new type_tree<span class="Delimiter">(</span>*replacement<span class="Delimiter">-></span>left<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>replacement<span class="Delimiter">-></span>right<span class="Delimiter">)</span> type<span class="Delimiter">-></span>right = new type_tree<span class="Delimiter">(</span>*replacement<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> replace_type_ingredients<span class="Delimiter">(</span>type<span class="Delimiter">-></span>left<span class="Delimiter">,</span> mappings<span class="Delimiter">);</span> replace_type_ingredients<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">,</span> mappings<span class="Delimiter">);</span> <span class="Delimiter">}</span> +type_tree* parse_type_tree<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> + istringstream in<span class="Delimiter">(</span>s<span class="Delimiter">);</span> + in >> std::noskipws<span class="Delimiter">;</span> + <span class="Identifier">return</span> parse_type_tree<span class="Delimiter">(</span>in<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +type_tree* parse_type_tree<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + skip_whitespace_but_not_newline<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">')'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="Constant">'('</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + string type_name = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">))</span> + put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span> + type_tree* result = new type_tree<span class="Delimiter">(</span>type_name<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">));</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="Comment">// skip '('</span> + type_tree* result = <span class="Constant">NULL</span><span class="Delimiter">;</span> + type_tree** curr = &result<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="Constant">')'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>has_data<span class="Delimiter">(</span>in<span class="Delimiter">));</span> + *curr = new type_tree<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + skip_whitespace_but_not_newline<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'('</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>left = parse_type_tree<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + else <span class="Delimiter">{</span> + <span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>name = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!is_type_ingredient_name<span class="Delimiter">((</span>*curr<span class="Delimiter">)-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>name<span class="Delimiter">))</span> + put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>name<span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span> + <span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>name<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + curr = &<span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>right<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="Comment">// skip ')'</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +string inspect<span class="Delimiter">(</span>const type_tree* x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + ostringstream out<span class="Delimiter">;</span> + dump_inspect<span class="Delimiter">(</span>x<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span class="Delimiter">}</span> + +void dump_inspect<span class="Delimiter">(</span>const type_tree* x<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!x<span class="Delimiter">-></span>left && !x<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << x<span class="Delimiter">-></span>name<span class="Delimiter">;</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + out << <span class="Constant">'('</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>const type_tree* curr = x<span class="Delimiter">;</span> curr<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>curr != x<span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> + dump_inspect<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">,</span> out<span class="Delimiter">);</span> + else + out << curr<span class="Delimiter">-></span>name<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + out << <span class="Constant">')'</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + void ensure_all_concrete_types<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">const</span><span class="Comment">*/</span> recipe& new_recipe<span class="Delimiter">,</span> const recipe& exemplar<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>new_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> ensure_all_concrete_types<span class="Delimiter">(</span>new_recipe<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> exemplar<span class="Delimiter">);</span> @@ -496,9 +532,9 @@ void ensure_all_concrete_types<span class="Delimiter">(</span><span class="Comme <span class="Delimiter">}</span> void ensure_all_concrete_types<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">const</span><span class="Comment">*/</span> reagent& x<span class="Delimiter">,</span> const recipe& exemplar<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> + if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type || contains_type_ingredient_name<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>exemplar<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"failed to map a type to "</span> << x<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - x<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// just to prevent crashes later</span> + if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> x<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// just to prevent crashes later</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -507,13 +543,6 @@ void ensure_all_concrete_types<span class="Delimiter">(</span><span class="Comme <span class="Delimiter">}</span> <span class="Delimiter">}</span> -long long int non_ghost_size<span class="Delimiter">(</span>vector<recipe_ordinal>& variants<span class="Delimiter">)</span> <span class="Delimiter">{</span> - long long int result = <span class="Constant">0</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>variants<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - if <span class="Delimiter">(</span>variants<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != -<span class="Constant">1</span><span class="Delimiter">)</span> ++result<span class="Delimiter">;</span> - <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span class="Delimiter">}</span> - <span class="Delimiter">:(scenario shape_shifting_recipe_2)</span> recipe main [ <span class="Constant">10</span>:point<span class="Special"> <- </span>merge <span class="Constant">14</span><span class="Delimiter">,</span> <span class="Constant">15</span> @@ -859,6 +888,78 @@ recipe foo x:address:shared:_elem <span class="Delimiter">-></span> y:number reply <span class="Constant">35</span> ] <span class="traceContains">+mem: storing 35 in location 2</span> + +<span class="Delimiter">:(scenario specialize_most_similar_variant_2)</span> +<span class="Comment"># version with headers padded with lots of unrelated concrete types</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> + <span class="Constant">2</span>:address:shared:array:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>foo <span class="Constant">2</span>:address:shared:array:number<span class="Delimiter">,</span> <span class="Constant">1</span>:number +] +<span class="Comment"># variant with concrete type</span> +recipe foo dummy:address:shared:array:number<span class="Delimiter">,</span> x:number <span class="Delimiter">-></span> y:number<span class="Delimiter">,</span> dummy:address:shared:array:number [ + local-scope + load-ingredients + reply <span class="Constant">34</span> +] +<span class="Comment"># shape-shifting variant</span> +recipe foo dummy:address:shared:array:number<span class="Delimiter">,</span> x:_elem <span class="Delimiter">-></span> y:number<span class="Delimiter">,</span> dummy:address:shared:array:number [ + local-scope + load-ingredients + reply <span class="Constant">35</span> +] +<span class="Comment"># prefer the concrete variant</span> +<span class="traceContains">+mem: storing 34 in location 3</span> + +<span class="Delimiter">:(scenario specialize_most_similar_variant_3)</span> +recipe main [ + <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new [abc] + foo <span class="Constant">1</span>:address:shared:array:character +] +recipe foo x:address:shared:array:character [ + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> +] +recipe foo x:address:_elem [ + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> +] +<span class="Comment"># make sure the more precise version was used</span> +<span class="traceContains">+mem: storing 34 in location 2</span> + +<span class="Delimiter">:(scenario specialize_literal_as_number)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>foo <span class="Constant">23</span> +] +recipe foo x:_elem <span class="Delimiter">-></span> y:number [ + local-scope + load-ingredients + reply <span class="Constant">34</span> +] +recipe foo x:character <span class="Delimiter">-></span> y:number [ + local-scope + load-ingredients + reply <span class="Constant">35</span> +] +<span class="traceContains">+mem: storing 34 in location 1</span> + +<span class="Delimiter">:(scenario specialize_literal_as_number_2)</span> +<span class="Comment"># version calling with literal</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>foo <span class="Constant">0</span> +] +<span class="Comment"># variant with concrete type</span> +recipe foo x:number <span class="Delimiter">-></span> y:number [ + local-scope + load-ingredients + reply <span class="Constant">34</span> +] +<span class="Comment"># shape-shifting variant</span> +recipe foo x:address:shared:_elem <span class="Delimiter">-></span> y:number [ + local-scope + load-ingredients + reply <span class="Constant">35</span> +] +<span class="Comment"># prefer the concrete variant, ignore concrete types in scoring the shape-shifting variant</span> +<span class="traceContains">+mem: storing 34 in location 1</span> </pre> </body> </html> diff --git a/html/060immutable.cc.html b/html/060immutable.cc.html index 777149a7..0b8e2845 100644 --- a/html/060immutable.cc.html +++ b/html/060immutable.cc.html @@ -14,13 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .traceContains { color: #008000; } -.Identifier { color: #804000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } -.CommentedCode { color: #6c6c6c; } +.Identifier { color: #804000; } --> </style> @@ -36,7 +35,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">//: also products. This layer will start enforcing this check.</span> <span class="Delimiter">:(scenario can_modify_value_ingredients)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ local-scope p:address:shared:point<span class="Special"> <- </span>new point:type @@ -48,10 +47,10 @@ recipe foo p:point [ x:address:number<span class="Special"> <- </span>get-address p<span class="Delimiter">,</span> x:offset *x<span class="Special"> <- </span>copy <span class="Constant">34</span> ] -$warn: <span class="Constant">0</span> +$error: <span class="Constant">0</span> <span class="Delimiter">:(scenario can_modify_ingredients_that_are_also_products)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ local-scope p:address:shared:point<span class="Special"> <- </span>new point:type @@ -63,10 +62,10 @@ recipe foo p:address:shared:point <span class="Delimiter">-></span> p:address x:address:number<span class="Special"> <- </span>get-address *p<span class="Delimiter">,</span> x:offset *x<span class="Special"> <- </span>copy <span class="Constant">34</span> ] -$warn: <span class="Constant">0</span> +$error: <span class="Constant">0</span> <span class="Delimiter">:(scenario ignore_literal_ingredients_for_immutability_checks)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ local-scope p:address:shared:d1<span class="Special"> <- </span>new d1:type @@ -83,10 +82,10 @@ container d1 [ p:number q:number ] -$warn: <span class="Constant">0</span> +$error: <span class="Constant">0</span> <span class="Delimiter">:(scenario cannot_take_address_inside_immutable_ingredients)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ local-scope p:address:shared:point<span class="Special"> <- </span>new point:type @@ -98,10 +97,10 @@ recipe foo p:address:shared:point [ x:address:number<span class="Special"> <- </span>get-address *p<span class="Delimiter">,</span> x:offset *x<span class="Special"> <- </span>copy <span class="Constant">34</span> ] -<span class="traceContains">+warn: foo: cannot modify ingredient p after instruction 'x:address:number <- get-address *p, x:offset' because it's not also a product of foo</span> +<span class="traceContains">+error: foo: cannot modify ingredient p after instruction 'x:address:number <- get-address *p, x:offset' because it's not also a product of foo</span> <span class="Delimiter">:(scenario cannot_call_mutating_recipes_on_immutable_ingredients)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ local-scope p:address:shared:point<span class="Special"> <- </span>new point:type @@ -118,10 +117,10 @@ recipe bar p:address:shared:point <span class="Delimiter">-></span> p:address x:address:number<span class="Special"> <- </span>get-address *p<span class="Delimiter">,</span> x:offset *x<span class="Special"> <- </span>copy <span class="Constant">34</span> ] -<span class="traceContains">+warn: foo: cannot modify ingredient p at instruction 'bar p' because it's not also a product of foo</span> +<span class="traceContains">+error: foo: cannot modify ingredient p at instruction 'bar p' because it's not also a product of foo</span> <span class="Delimiter">:(scenario cannot_modify_copies_of_immutable_ingredients)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ local-scope p:address:shared:point<span class="Special"> <- </span>new point:type @@ -133,10 +132,10 @@ recipe foo p:address:shared:point [ q:address:shared:point<span class="Special"> <- </span>copy p x:address:number<span class="Special"> <- </span>get-address *q<span class="Delimiter">,</span> x:offset ] -<span class="traceContains">+warn: foo: cannot modify q after instruction 'x:address:number <- get-address *q, x:offset' because that would modify ingredient p which is not also a product of foo</span> +<span class="traceContains">+error: foo: cannot modify q after instruction 'x:address:number <- get-address *q, x:offset' because that would modify ingredient p which is not also a product of foo</span> <span class="Delimiter">:(scenario can_traverse_immutable_ingredients)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> container test-list [ next:address:shared:test-list ] @@ -155,10 +154,10 @@ recipe bar x:address:shared:test-list <span class="Delimiter">-></span> y:add load-ingredients y<span class="Special"> <- </span>get *x<span class="Delimiter">,</span> next:offset ] -$warn: <span class="Constant">0</span> +$error: <span class="Constant">0</span> <span class="Delimiter">:(scenario handle_optional_ingredients_in_immutability_checks)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> recipe main [ k:address:shared:number<span class="Special"> <- </span>new number:type test k @@ -175,7 +174,7 @@ recipe foo <span class="Delimiter">-></span> [ load-ingredients k:address:shared:number<span class="Delimiter">,</span> found?:boolean<span class="Special"> <- </span>next-ingredient ] -$warn: <span class="Constant">0</span> +$error: <span class="Constant">0</span> <span class="Delimiter">:(before "End Transforms")</span> Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_immutable_ingredients<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> @@ -186,11 +185,10 @@ void check_immutable_ingredients<span class="Delimiter">(</span>recipe_ordinal r <span class="Comment">// call get-address or index-address with it, and that any non-primitive</span> <span class="Comment">// recipe calls in the body aren't returning it as a product.</span> const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> -<span class="CommentedCode">//? cerr << caller.name << '\n';</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">"--- check mutability of ingredients in recipe "</span> << caller<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> if <span class="Delimiter">(</span>!caller<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// skip check for old-style recipes calling next-ingredient directly</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>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> const reagent& current_ingredient = caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span class="CommentedCode">//? cerr << " " << current_ingredient.original_string << '\n';</span> if <span class="Delimiter">(</span>!is_mu_address<span class="Delimiter">(</span>current_ingredient<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// will be copied</span> if <span class="Delimiter">(</span>is_present_in_products<span class="Delimiter">(</span>caller<span class="Delimiter">,</span> current_ingredient<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// not expected to be immutable</span> <span class="Comment">// End Immutable Ingredients Special-cases</span> @@ -198,7 +196,6 @@ void check_immutable_ingredients<span class="Delimiter">(</span>recipe_ordinal r immutable_vars<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>current_ingredient<span class="Delimiter">.</span>name<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>caller<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> const instruction& inst = caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span class="CommentedCode">//? cerr << " " << inst.to_string() << '\n';</span> check_immutable_ingredient_in_instruction<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> immutable_vars<span class="Delimiter">,</span> current_ingredient<span class="Delimiter">.</span>name<span class="Delimiter">,</span> caller<span class="Delimiter">);</span> update_aliases<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> immutable_vars<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -244,7 +241,7 @@ set<long long int> scan_contained_in_product_indices<span class="Delimiter <span class="Delimiter">:(scenarios transform)</span> <span class="Delimiter">:(scenario immutability_infects_contained_in_variables)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> container test-list [ next:address:shared:test-list ] @@ -264,7 +261,7 @@ recipe test-next x:address:shared:test-list <span class="Delimiter">-></span> load-ingredients y<span class="Special"> <- </span>get *x<span class="Delimiter">,</span> next:offset ] -<span class="traceContains">+warn: foo: cannot modify p2 after instruction 'p3:address:address:shared:test-list <- get-address *p2, next:offset' because that would modify ingredient p which is not also a product of foo</span> +<span class="traceContains">+error: foo: cannot modify p2 after instruction 'p3:address:address:shared:test-list <- get-address *p2, next:offset' because that would modify ingredient p which is not also a product of foo</span> <span class="Delimiter">:(code)</span> void check_immutable_ingredient_in_instruction<span class="Delimiter">(</span>const instruction& inst<span class="Delimiter">,</span> const set<string>& current_ingredient_and_aliases<span class="Delimiter">,</span> const string& original_ingredient_name<span class="Delimiter">,</span> const recipe& caller<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -272,7 +269,6 @@ void check_immutable_ingredient_in_instruction<span class="Delimiter">(</span>co if <span class="Delimiter">(</span>current_ingredient_indices<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// ingredient not found in call</span> for <span class="Delimiter">(</span>set<long long int>::iterator p = current_ingredient_indices<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != current_ingredient_indices<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> const long long int current_ingredient_index = *p<span class="Delimiter">;</span> -<span class="CommentedCode">//? cerr << " ingredient index: " << *p << '\n';</span> reagent current_ingredient = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>current_ingredient_index<span class="Delimiter">);</span> canonize_type<span class="Delimiter">(</span>current_ingredient<span class="Delimiter">);</span> const string& current_ingredient_name = current_ingredient<span class="Delimiter">.</span>name<span class="Delimiter">;</span> @@ -280,9 +276,9 @@ void check_immutable_ingredient_in_instruction<span class="Delimiter">(</span>co <span class="Comment">// primitive recipe</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == GET_ADDRESS || inst<span class="Delimiter">.</span>operation == INDEX_ADDRESS<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>current_ingredient_name == original_ingredient_name<span class="Delimiter">)</span> - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"cannot modify ingredient "</span> << current_ingredient_name << <span class="Constant">" after instruction '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"' because it's not also a product of "</span> << caller<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"cannot modify ingredient "</span> << current_ingredient_name << <span class="Constant">" after instruction '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"' because it's not also a product of "</span> << caller<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> else - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"cannot modify "</span> << current_ingredient_name << <span class="Constant">" after instruction '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"' because that would modify ingredient "</span> << original_ingredient_name << <span class="Constant">" which is not also a product of "</span> << caller<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"cannot modify "</span> << current_ingredient_name << <span class="Constant">" after instruction '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"' because that would modify ingredient "</span> << original_ingredient_name << <span class="Constant">" which is not also a product of "</span> << caller<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> @@ -290,9 +286,9 @@ void check_immutable_ingredient_in_instruction<span class="Delimiter">(</span>co if <span class="Delimiter">(</span>!is_mu_address<span class="Delimiter">(</span>current_ingredient<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// making a copy is ok</span> if <span class="Delimiter">(</span>is_modified_in_recipe<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation<span class="Delimiter">,</span> current_ingredient_index<span class="Delimiter">,</span> caller<span class="Delimiter">))</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>current_ingredient_name == original_ingredient_name<span class="Delimiter">)</span> - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"cannot modify ingredient "</span> << current_ingredient_name << <span class="Constant">" at instruction '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"' because it's not also a product of "</span> << caller<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"cannot modify ingredient "</span> << current_ingredient_name << <span class="Constant">" at instruction '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"' because it's not also a product of "</span> << caller<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> else - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"cannot modify "</span> << current_ingredient_name << <span class="Constant">" after instruction '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"' because that would modify ingredient "</span> << original_ingredient_name << <span class="Constant">" which is not also a product of "</span> << caller<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"cannot modify "</span> << current_ingredient_name << <span class="Constant">" after instruction '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"' because that would modify ingredient "</span> << original_ingredient_name << <span class="Constant">" which is not also a product of "</span> << caller<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -301,7 +297,7 @@ void check_immutable_ingredient_in_instruction<span class="Delimiter">(</span>co bool is_modified_in_recipe<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">,</span> long long int ingredient_index<span class="Delimiter">,</span> const recipe& caller<span class="Delimiter">)</span> <span class="Delimiter">{</span> const recipe& callee = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> if <span class="Delimiter">(</span>!callee<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"can't check mutability of ingredients in "</span> << callee<span class="Delimiter">.</span>name << <span class="Constant">" because it uses 'next-ingredient' directly, rather than a recipe header.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"can't check mutability of ingredients in "</span> << callee<span class="Delimiter">.</span>name << <span class="Constant">" because it uses 'next-ingredient' directly, rather than a recipe header.</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>ingredient_index >= SIZE<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// optional immutable ingredient</span> @@ -347,7 +343,7 @@ set<long long int> ingredient_indices<span class="Delimiter">(</span>const <span class="Delimiter">:(scenarios transform)</span> <span class="Delimiter">:(scenario can_modify_contained_in_addresses)</span> -<span class="Special">% Hide_warnings = true;</span> +<span class="Special">% Hide_errors = true;</span> container test-list [ next:address:shared:test-list ] @@ -372,7 +368,7 @@ recipe test-remove x:address:shared:test-list/contained-in:from<span class="Deli load-ingredients x2:address:address:shared:test-list<span class="Special"> <- </span>get-address *x<span class="Delimiter">,</span> next:offset <span class="Comment"># pretend modification</span> ] -$warn: <span class="Constant">0</span> +$error: <span class="Constant">0</span> <span class="Delimiter">:(before "End Immutable Ingredients Special-cases")</span> if <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>current_ingredient<span class="Delimiter">,</span> <span class="Constant">"contained-in"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> @@ -380,7 +376,7 @@ if <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>c if <span class="Delimiter">(</span>tmp<span class="Delimiter">-></span>left || tmp<span class="Delimiter">-></span>right || !is_present_in_ingredients<span class="Delimiter">(</span>caller<span class="Delimiter">,</span> tmp<span class="Delimiter">-></span>value<span class="Delimiter">)</span> || !is_present_in_products<span class="Delimiter">(</span>caller<span class="Delimiter">,</span> tmp<span class="Delimiter">-></span>value<span class="Delimiter">))</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"contained-in can only point to another ingredient+product, but got "</span> << debug_string<span class="Delimiter">(</span>property<span class="Delimiter">(</span>current_ingredient<span class="Delimiter">,</span> <span class="Constant">"contained-in"</span><span class="Delimiter">))</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"contained-in can only point to another ingredient+product, but got "</span> << to_string<span class="Delimiter">(</span>property<span class="Delimiter">(</span>current_ingredient<span class="Delimiter">,</span> <span class="Constant">"contained-in"</span><span class="Delimiter">))</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> diff --git a/html/061recipe.cc.html b/html/061recipe.cc.html index 1bfc9758..c1bbe2ed 100644 --- a/html/061recipe.cc.html +++ b/html/061recipe.cc.html @@ -35,6 +35,8 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">//: So far we've been calling a fixed recipe in each instruction, but we'd</span> <span class="Comment">//: also like to make the recipe a variable, pass recipes to "higher-order"</span> <span class="Comment">//: recipes, return recipes from recipes and so on.</span> +<span class="Comment">//:</span> +<span class="Comment">//: todo: support storing shape-shifting recipes into recipe variables and calling them</span> <span class="Delimiter">:(scenario call_literal_recipe)</span> recipe main [ @@ -66,9 +68,8 @@ type_ordinal recipe = put<span class="Delimiter">(</span>Type_ordinal<span class get_or_insert<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> recipe<span class="Delimiter">).</span>name = <span class="Constant">"recipe"</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Null-type is_disqualified Exceptions")</span> -if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second && contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second = new string_tree<span class="Delimiter">(</span><span class="Constant">"recipe-literal"</span><span class="Delimiter">);</span> - x<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">"recipe-literal"</span><span class="Delimiter">));</span> +if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type && contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + x<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span><span class="Constant">"recipe-literal"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"recipe-literal"</span><span class="Delimiter">));</span> x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<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> <span class="Delimiter">}</span> @@ -149,38 +150,37 @@ void check_indirect_calls_against_header<span class="Delimiter">(</span>const re if <span class="Delimiter">(</span>!callee_header<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>long int i = <span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"ingredient "</span> << i-<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span> << <span class="Constant">" has the wrong type at '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"ingredient "</span> << i-<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span> << <span class="Constant">" has the wrong type at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> for <span class="Delimiter">(</span>long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> - raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"product "</span> << i << <span class="Constant">" has the wrong type at '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"product "</span> << i << <span class="Constant">" has the wrong type at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> recipe from_reagent<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"recipe"</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">);</span> recipe result_header<span class="Delimiter">;</span> <span class="Comment">// will contain only ingredients and products, nothing else</span> result_header<span class="Delimiter">.</span>has_header = <span class="Constant">true</span><span class="Delimiter">;</span> - const string_tree* curr = r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>right<span class="Delimiter">;</span> + const type_tree* curr = r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> for <span class="Delimiter">(;</span> curr<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>value == <span class="Constant">"->"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>name == <span class="Constant">"->"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Comment">// skip delimiter</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"recipe:"</span>+curr<span class="Delimiter">-></span>value<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - for <span class="Delimiter">(;</span> curr<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> - result_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"recipe:"</span>+curr<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"recipe:"</span>+curr<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> + for <span class="Delimiter">(;</span> curr<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> + result_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"recipe:"</span>+curr<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span class="Identifier">return</span> result_header<span class="Delimiter">;</span> <span class="Delimiter">}</span> bool is_mu_recipe<span class="Delimiter">(</span>reagent r<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</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><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"recipe"</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><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-></span>value == <span class="Constant">"recipe-literal"</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>type<span class="Delimiter">-></span>name == <span class="Constant">"recipe"</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>type<span class="Delimiter">-></span>name == <span class="Constant">"recipe-literal"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// End is_mu_recipe Cases</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -214,7 +214,7 @@ recipe f x:boolean <span class="Delimiter">-></span> y:boolean [ <span class="Delimiter">:(before "End Matching Types For Literal(to)")</span> if <span class="Delimiter">(</span>is_mu_recipe<span class="Delimiter">(</span>to<span class="Delimiter">))</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> from<span class="Delimiter">.</span>value<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise_error << <span class="Constant">"trying to store recipe "</span> << from<span class="Delimiter">.</span>name << <span class="Constant">" into "</span> << debug_string<span class="Delimiter">(</span>to<span class="Delimiter">)</span> << <span class="Constant">" but there's no such recipe</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + raise_error << <span class="Constant">"trying to store recipe "</span> << from<span class="Delimiter">.</span>name << <span class="Constant">" into "</span> << to_string<span class="Delimiter">(</span>to<span class="Delimiter">)</span> << <span class="Constant">" but there's no such recipe</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> const recipe& rrhs = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> from<span class="Delimiter">.</span>value<span class="Delimiter">);</span> diff --git a/html/062scheduler.cc.html b/html/062scheduler.cc.html index d772144e..2c6edf84 100644 --- a/html/062scheduler.cc.html +++ b/html/062scheduler.cc.html @@ -192,7 +192,7 @@ case START_RUNNING: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>!is_mu_recipe<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> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"first ingredient of 'start-running' should be a recipe, but got "</span> << debug_string<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> << <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">"first ingredient of 'start-running' should be a recipe, but got "</span> << to_string<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> << <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> @@ -378,7 +378,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case ROUTINE_STATE: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'routine-state' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'routine-state' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_number<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> <span class="Delimiter">{</span> @@ -411,7 +411,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case RESTART: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'restart' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'restart' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_number<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> <span class="Delimiter">{</span> @@ -439,7 +439,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case STOP: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'stop' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'stop' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_number<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> <span class="Delimiter">{</span> @@ -521,7 +521,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case LIMIT_TIME: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'limit-time' requires exactly two ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'limit-time' requires exactly two ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_number<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> <span class="Delimiter">{</span> diff --git a/html/063wait.cc.html b/html/063wait.cc.html index 08d4b049..9115e7d6 100644 --- a/html/063wait.cc.html +++ b/html/063wait.cc.html @@ -129,7 +129,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case WAIT_FOR_ROUTINE: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'wait-for-routine' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'wait-for-routine' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_number<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> <span class="Delimiter">{</span> @@ -141,7 +141,7 @@ case WAIT_FOR_ROUTINE: <span class="Delimiter">{</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case WAIT_FOR_ROUTINE: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == Current_routine<span class="Delimiter">-></span>id<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"routine can't wait for itself! "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"routine can't wait for itself! "</span> << to_string<span class="Delimiter">(</span>current_instruction<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> Current_routine<span class="Delimiter">-></span>state = WAITING<span class="Delimiter">;</span> diff --git a/html/070text.mu.html b/html/070text.mu.html index a517c13f..4c802574 100644 --- a/html/070text.mu.html +++ b/html/070text.mu.html @@ -244,14 +244,18 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Constant">local-scope</span> x:address:shared:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">3</span> s1:address:shared:array:character<span class="Special"> <- </span>get *x, <span class="Constant">data:offset</span> - x<span class="Special"> <- </span>append x, <span class="Constant">97</span> <span class="Comment"># 'a'</span> - x<span class="Special"> <- </span>append x, <span class="Constant">98</span> <span class="Comment"># 'b'</span> - x<span class="Special"> <- </span>append x, <span class="Constant">99</span> <span class="Comment"># 'c'</span> + c:character<span class="Special"> <- </span>copy <span class="Constant">97/a</span> + x<span class="Special"> <- </span>append x, c + c:character<span class="Special"> <- </span>copy <span class="Constant">98/b</span> + x<span class="Special"> <- </span>append x, c + c:character<span class="Special"> <- </span>copy <span class="Constant">99/c</span> + x<span class="Special"> <- </span>append x, c s2:address:shared:array:character<span class="Special"> <- </span>get *x, <span class="Constant">data:offset</span> <span class="Constant">1</span>:boolean/<span class="Special">raw <- </span>equal s1, s2 <span class="Constant">2</span>:array:character/<span class="Special">raw <- </span>copy *s2 <span class="Constant"> +buffer-filled</span> - x<span class="Special"> <- </span>append x, <span class="Constant">100</span> <span class="Comment"># 'd'</span> + c:character<span class="Special"> <- </span>copy <span class="Constant">100/d</span> + x<span class="Special"> <- </span>append x, c s3:address:shared:array:character<span class="Special"> <- </span>get *x, <span class="Constant">data:offset</span> <span class="Constant">10</span>:boolean/<span class="Special">raw <- </span>equal s1, s3 <span class="Constant">11</span>:number/<span class="Special">raw <- </span>get *x, <span class="Constant">length:offset</span> @@ -281,9 +285,12 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } run [ <span class="Constant">local-scope</span> x:address:shared:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">3</span> - x<span class="Special"> <- </span>append x, <span class="Constant">97</span> <span class="Comment"># 'a'</span> - x<span class="Special"> <- </span>append x, <span class="Constant">98</span> <span class="Comment"># 'b'</span> - x<span class="Special"> <- </span>append x, <span class="Constant">8/backspace</span> + c:character<span class="Special"> <- </span>copy <span class="Constant">97/a</span> + x<span class="Special"> <- </span>append x, c + c:character<span class="Special"> <- </span>copy <span class="Constant">98/b</span> + x<span class="Special"> <- </span>append x, c + c:character<span class="Special"> <- </span>copy <span class="Constant">8/backspace</span> + x<span class="Special"> <- </span>append x, c s:address:shared:array:character<span class="Special"> <- </span>buffer-to-array x <span class="Constant">1</span>:array:character/<span class="Special">raw <- </span>copy *s ] @@ -325,7 +332,8 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment"># add sign</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> negate-result:boolean - tmp<span class="Special"> <- </span>append tmp, <span class="Constant">45</span> <span class="Comment"># '-'</span> + minus:character<span class="Special"> <- </span>copy <span class="Constant">45/-</span> + tmp<span class="Special"> <- </span>append tmp, minus <span class="Delimiter">}</span> <span class="Comment"># reverse buffer into text result</span> len:number<span class="Special"> <- </span>get *tmp, <span class="Constant">length:offset</span> @@ -354,6 +362,12 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } result<span class="Special"> <- </span>to-text n ] +<span class="muRecipe">recipe</span> to-text x:address:_elem<span class="muRecipe"> -> </span>result:address:shared:array:character [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + n:number<span class="Special"> <- </span>copy x + result<span class="Special"> <- </span>to-text n +] <span class="muRecipe">recipe</span> buffer-to-array in:address:shared:buffer<span class="muRecipe"> -> </span>result:address:shared:array:character [ <span class="Constant">local-scope</span> diff --git a/html/074random.cc.html b/html/074random.cc.html index 86a40ca5..dd525d58 100644 --- a/html/074random.cc.html +++ b/html/074random.cc.html @@ -70,7 +70,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case ROUND: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'round' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'round' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_number<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> <span class="Delimiter">{</span> diff --git a/html/077hash.cc.html b/html/077hash.cc.html new file mode 100644 index 00000000..d223be71 --- /dev/null +++ b/html/077hash.cc.html @@ -0,0 +1,431 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - 077hash.cc</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +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; } +.traceContains { color: #008000; } +.cSpecial { color: #008000; } +.CommentedCode { color: #6c6c6c; } +.Comment { color: #9090ff; } +.Delimiter { color: #a04060; } +.Special { color: #ff6060; } +.Identifier { color: #804000; } +.Constant { color: #00a0a0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment">// A universal hash function that can handle objects of any type.</span> +<span class="Comment">//</span> +<span class="Comment">// The way it's currently implemented, two objects will have the same hash if</span> +<span class="Comment">// all their non-address fields (all the way down) expand to the same sequence</span> +<span class="Comment">// of scalar values. In particular, a container with all zero addresses hashes</span> +<span class="Comment">// to 0. Hopefully this won't be an issue because we are usually hashing</span> +<span class="Comment">// objects of a single type in any given hash table.</span> +<span class="Comment">//</span> +<span class="Comment">// Based on <a href="http://burtleburtle.net/bob/hash/hashfaq.html">http://burtleburtle.net/bob/hash/hashfaq.html</a></span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +HASH<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"hash"</span><span class="Delimiter">,</span> HASH<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case HASH: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'hash' takes exactly one ingredient rather than '"</span> << to_string<span class="Delimiter">(</span>inst<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> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case HASH: <span class="Delimiter">{</span> + reagent input = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// copy</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>hash<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> input<span class="Delimiter">));</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Comment">//: in all the code below, the intermediate results of hashing are threaded through 'h'</span> + +<span class="Delimiter">:(code)</span> +size_t hash<span class="Delimiter">(</span>size_t h<span class="Delimiter">,</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cerr << debug_string(r) << '\n';</span> + canonize<span class="Delimiter">(</span>r<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>is_mu_string<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Comment">// optimization</span> + <span class="Identifier">return</span> hash_mu_string<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + else if <span class="Delimiter">(</span>is_mu_address<span class="Delimiter">(</span>r<span class="Delimiter">))</span> + <span class="Identifier">return</span> hash_mu_address<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + else if <span class="Delimiter">(</span>is_mu_scalar<span class="Delimiter">(</span>r<span class="Delimiter">))</span> + <span class="Identifier">return</span> hash_mu_scalar<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + else if <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>r<span class="Delimiter">))</span> + <span class="Identifier">return</span> hash_mu_array<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + else if <span class="Delimiter">(</span>is_mu_container<span class="Delimiter">(</span>r<span class="Delimiter">))</span> + <span class="Identifier">return</span> hash_mu_container<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + else if <span class="Delimiter">(</span>is_mu_exclusive_container<span class="Delimiter">(</span>r<span class="Delimiter">))</span> + <span class="Identifier">return</span> hash_mu_exclusive_container<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +size_t hash_mu_scalar<span class="Delimiter">(</span>size_t h<span class="Delimiter">,</span> const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + double input = is_literal<span class="Delimiter">(</span>r<span class="Delimiter">)</span> ? r<span class="Delimiter">.</span>value : get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">);</span> + <span class="Identifier">return</span> hash_iter<span class="Delimiter">(</span>h<span class="Delimiter">,</span> static_cast<size_t><span class="Delimiter">(</span>input<span class="Delimiter">));</span> +<span class="Delimiter">}</span> + +size_t hash_mu_address<span class="Delimiter">(</span>size_t h<span class="Delimiter">,</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + r<span class="Delimiter">.</span>value = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">);</span> + drop_from_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"shared"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + ++r<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + drop_from_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"shared"</span><span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> hash<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +size_t hash_mu_string<span class="Delimiter">(</span>size_t h<span class="Delimiter">,</span> const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + string input = read_mu_string<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<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>input<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + h = hash_iter<span class="Delimiter">(</span>h<span class="Delimiter">,</span> static_cast<size_t><span class="Delimiter">(</span>input<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</span> +<span class="CommentedCode">//? cerr << i << ": " << h << '\n';</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> h<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +size_t hash_mu_array<span class="Delimiter">(</span>size_t h<span class="Delimiter">,</span> const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int size = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">);</span> + reagent elem = r<span class="Delimiter">;</span> + delete elem<span class="Delimiter">.</span>type<span class="Delimiter">;</span> + elem<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*array_element<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">));</span> + for <span class="Delimiter">(</span>long long int i=<span class="Constant">0</span><span class="Delimiter">,</span> address = r<span class="Delimiter">.</span>value+<span class="Constant">1</span><span class="Delimiter">;</span> i < size<span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> address += size_of<span class="Delimiter">(</span>elem<span class="Delimiter">))</span> <span class="Delimiter">{</span> + reagent tmp = elem<span class="Delimiter">;</span> + tmp<span class="Delimiter">.</span>value = address<span class="Delimiter">;</span> + h = hash<span class="Delimiter">(</span>h<span class="Delimiter">,</span> tmp<span class="Delimiter">);</span> +<span class="CommentedCode">//? cerr << i << " (" << address << "): " << h << '\n';</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> h<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +bool is_mu_container<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + <span class="Identifier">return</span> info<span class="Delimiter">.</span>kind == CONTAINER<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +size_t hash_mu_container<span class="Delimiter">(</span>size_t h<span class="Delimiter">,</span> const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + long long int address = r<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + long long int offset = <span class="Constant">0</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>info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + reagent element = element_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> i<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>element<span class="Delimiter">,</span> <span class="Constant">"ignore-for-hash"</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address+offset<span class="Delimiter">);</span> + h = hash<span class="Delimiter">(</span>h<span class="Delimiter">,</span> element<span class="Delimiter">);</span> +<span class="CommentedCode">//? cerr << i << ": " << h << '\n';</span> + offset += size_of<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> h<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +bool is_mu_exclusive_container<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + type_info& info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + <span class="Identifier">return</span> info<span class="Delimiter">.</span>kind == EXCLUSIVE_CONTAINER<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +size_t hash_mu_exclusive_container<span class="Delimiter">(</span>size_t h<span class="Delimiter">,</span> const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + long long int tag = get<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">);</span> + reagent variant = variant_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> tag<span class="Delimiter">);</span> + <span class="Comment">// todo: move this error to container definition time</span> + if <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>variant<span class="Delimiter">,</span> <span class="Constant">"ignore-for-hash"</span><span class="Delimiter">))</span> + raise_error << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name << <span class="Constant">": /ignore-for-hash won't work in exclusive containers</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + variant<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>r<span class="Delimiter">.</span>value + <span class="Comment">/*</span><span class="Comment">skip tag</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> + h = hash<span class="Delimiter">(</span>h<span class="Delimiter">,</span> variant<span class="Delimiter">);</span> + <span class="Identifier">return</span> h<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +size_t hash_iter<span class="Delimiter">(</span>size_t h<span class="Delimiter">,</span> size_t input<span class="Delimiter">)</span> <span class="Delimiter">{</span> + h += input<span class="Delimiter">;</span> + h += <span class="Delimiter">(</span>h<<<span class="Constant">10</span><span class="Delimiter">);</span> + h ^= <span class="Delimiter">(</span>h>><span class="Constant">6</span><span class="Delimiter">);</span> + + h += <span class="Delimiter">(</span>h<<<span class="Constant">3</span><span class="Delimiter">);</span> + h ^= <span class="Delimiter">(</span>h>><span class="Constant">11</span><span class="Delimiter">);</span> + h += <span class="Delimiter">(</span>h<<<span class="Constant">15</span><span class="Delimiter">);</span> + <span class="Identifier">return</span> h<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario hash_container_checks_all_elements)</span> +container foo [ + x:number + y:character +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a + <span class="Constant">3</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:foo + reply-unless <span class="Constant">3</span>:number + <span class="Constant">4</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">98</span>/a + <span class="Constant">6</span>:number<span class="Special"> <- </span>hash <span class="Constant">4</span>:foo + reply-unless <span class="Constant">6</span>:number + <span class="Constant">7</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">3</span>:number<span class="Delimiter">,</span> <span class="Constant">6</span>:number +] +<span class="Comment"># hash on containers includes all elements</span> +<span class="traceContains">+mem: storing 0 in location 7</span> + +<span class="Delimiter">:(scenario hash_exclusive_container_checks_all_elements)</span> +exclusive-container foo [ + x:bar + y:number +] +container bar [ + a:number + b:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:foo + reply-unless <span class="Constant">4</span>:number + <span class="Constant">5</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">36</span> + <span class="Constant">8</span>:number<span class="Special"> <- </span>hash <span class="Constant">5</span>:foo + reply-unless <span class="Constant">8</span>:number + <span class="Constant">9</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">4</span>:number<span class="Delimiter">,</span> <span class="Constant">8</span>:number +] +<span class="Comment"># hash on containers includes all elements</span> +<span class="traceContains">+mem: storing 0 in location 9</span> + +<span class="Delimiter">:(scenario hash_can_ignore_container_elements)</span> +container foo [ + x:number + y:character/ignore-for-hash +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a + <span class="Constant">3</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:foo + reply-unless <span class="Constant">3</span>:number + <span class="Constant">4</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">98</span>/a + <span class="Constant">6</span>:number<span class="Special"> <- </span>hash <span class="Constant">4</span>:foo + reply-unless <span class="Constant">6</span>:number + <span class="Constant">7</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">3</span>:number<span class="Delimiter">,</span> <span class="Constant">6</span>:number +] +<span class="Comment"># hashes match even though y is different</span> +<span class="traceContains">+mem: storing 1 in location 7</span> + +<span class="Comment">//: These properties aren't necessary for hash, they just test that the</span> +<span class="Comment">//: current implementation works like we think it does.</span> + +<span class="Delimiter">:(scenario hash_of_zero_address)</span> +recipe main [ + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:address:number +] +<span class="traceContains">+mem: storing 0 in location 2</span> + +<span class="Comment">//: This is probably too aggressive, but we need some way to avoid depending</span> +<span class="Comment">//: on the precise bit pattern of a floating-point number.</span> +<span class="Delimiter">:(scenario hash_of_numbers_ignores_fractional_part)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>hash <span class="Constant">1.5</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number +] +<span class="traceContains">+mem: storing 1 in location 3</span> + +<span class="Delimiter">:(scenario hash_of_array_same_as_string)</span> +recipe main [ + <span class="Constant">10</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> + <span class="Constant">11</span>:number<span class="Special"> <- </span>copy <span class="Constant">97</span> + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">98</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">99</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>hash <span class="Constant">10</span>:array:number/unsafe + reply-unless <span class="Constant">2</span>:number + <span class="Constant">3</span>:address:shared:array:character<span class="Special"> <- </span>new [abc] + <span class="Constant">4</span>:number<span class="Special"> <- </span>hash <span class="Constant">3</span>:address:shared:array:character + reply-unless <span class="Constant">4</span>:number + <span class="Constant">5</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">2</span>:number<span class="Delimiter">,</span> <span class="Constant">4</span>:number +] +<span class="traceContains">+mem: storing 1 in location 5</span> + +<span class="Delimiter">:(scenario hash_ignores_address_value)</span> +recipe main [ + <span class="Constant">1</span>:address:shared:number<span class="Special"> <- </span>new number:type + *<span class="Constant">1</span>:address:shared:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:address:shared:number + <span class="Constant">3</span>:address:shared:number<span class="Special"> <- </span>new number:type + *<span class="Constant">3</span>:address:shared:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>hash <span class="Constant">3</span>:address:shared:number + <span class="Constant">5</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">2</span>:number<span class="Delimiter">,</span> <span class="Constant">4</span>:number +] +<span class="Comment"># different addresses hash to the same result as long as the values the point to do so</span> +<span class="traceContains">+mem: storing 1 in location 5</span> + +<span class="Delimiter">:(scenario hash_ignores_address_refcount)</span> +recipe main [ + <span class="Constant">1</span>:address:shared:number<span class="Special"> <- </span>new number:type + *<span class="Constant">1</span>:address:shared:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:address:shared:number + reply-unless <span class="Constant">2</span>:number + <span class="Comment"># increment refcount</span> + <span class="Constant">3</span>:address:shared:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:shared:number + <span class="Constant">4</span>:number<span class="Special"> <- </span>hash <span class="Constant">3</span>:address:shared:number + reply-unless <span class="Constant">4</span>:number + <span class="Constant">5</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">2</span>:number<span class="Delimiter">,</span> <span class="Constant">4</span>:number +] +<span class="Comment"># hash doesn't change when refcount changes</span> +<span class="traceContains">+mem: storing 1 in location 5</span> + +<span class="Delimiter">:(scenario hash_container_depends_only_on_elements)</span> +container foo [ + x:number + y:character +] +container bar [ + x:number + y:character +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a + <span class="Constant">3</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:foo + reply-unless <span class="Constant">3</span>:number + <span class="Constant">4</span>:bar<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a + <span class="Constant">6</span>:number<span class="Special"> <- </span>hash <span class="Constant">4</span>:bar + reply-unless <span class="Constant">6</span>:number + <span class="Constant">7</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">3</span>:number<span class="Delimiter">,</span> <span class="Constant">6</span>:number +] +<span class="Comment"># containers with identical elements return identical hashes</span> +<span class="traceContains">+mem: storing 1 in location 7</span> + +<span class="Delimiter">:(scenario hash_container_depends_only_on_elements_2)</span> +container foo [ + x:number + y:character + z:address:shared:number +] +recipe main [ + <span class="Constant">1</span>:address:shared:number<span class="Special"> <- </span>new number:type + *<span class="Constant">1</span>:address:shared:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">1</span>:address:shared:number + <span class="Constant">5</span>:number<span class="Special"> <- </span>hash <span class="Constant">2</span>:foo + reply-unless <span class="Constant">5</span>:number + <span class="Constant">6</span>:address:shared:number<span class="Special"> <- </span>new number:type + *<span class="Constant">6</span>:address:shared:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">7</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">6</span>:address:shared:number + <span class="Constant">10</span>:number<span class="Special"> <- </span>hash <span class="Constant">7</span>:foo + reply-unless <span class="Constant">10</span>:number + <span class="Constant">11</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">5</span>:number<span class="Delimiter">,</span> <span class="Constant">10</span>:number +] +<span class="Comment"># containers with identical 'leaf' elements return identical hashes</span> +<span class="traceContains">+mem: storing 1 in location 11</span> + +<span class="Delimiter">:(scenario hash_container_depends_only_on_elements_3)</span> +container foo [ + x:number + y:character + z:bar +] +container bar [ + x:number + y:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">47</span><span class="Delimiter">,</span> <span class="Constant">48</span> + <span class="Constant">6</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:foo + reply-unless <span class="Constant">6</span>:number + <span class="Constant">7</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">47</span><span class="Delimiter">,</span> <span class="Constant">48</span> + <span class="Constant">12</span>:number<span class="Special"> <- </span>hash <span class="Constant">7</span>:foo + reply-unless <span class="Constant">12</span>:number + <span class="Constant">13</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">6</span>:number<span class="Delimiter">,</span> <span class="Constant">12</span>:number +] +<span class="Comment"># containers with identical 'leaf' elements return identical hashes</span> +<span class="traceContains">+mem: storing 1 in location 13</span> + +<span class="Delimiter">:(scenario hash_exclusive_container_ignores_tag)</span> +exclusive-container foo [ + x:bar + y:number +] +container bar [ + a:number + b:number +] +recipe main [ + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:foo + reply-unless <span class="Constant">4</span>:number + <span class="Constant">5</span>:bar<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span> + <span class="Constant">7</span>:number<span class="Special"> <- </span>hash <span class="Constant">5</span>:bar + reply-unless <span class="Constant">7</span>:number + <span class="Constant">8</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">4</span>:number<span class="Delimiter">,</span> <span class="Constant">7</span>:number +] +<span class="Comment"># hash on containers includes all elements</span> +<span class="traceContains">+mem: storing 1 in location 8</span> + +<span class="Comment">//: An older version that supported only strings.</span> +<span class="Comment">//: Hash functions are subtle and easy to get wrong, so we keep the old</span> +<span class="Comment">//: version around and check that the new one is consistent with it.</span> + +<span class="Delimiter">:(scenario hash_matches_old_version)</span> +recipe main [ + <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new [abc] + <span class="Constant">2</span>:number<span class="Special"> <- </span>hash <span class="Constant">1</span>:address:shared:array:character + <span class="Constant">3</span>:number<span class="Special"> <- </span>hash_old <span class="Constant">1</span>:address:shared:array:character + <span class="Constant">4</span>:number<span class="Special"> <- </span>equal <span class="Constant">2</span>:number<span class="Delimiter">,</span> <span class="Constant">3</span>:number +] +<span class="traceContains">+mem: storing 1 in location 4</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +HASH_OLD<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"hash_old"</span><span class="Delimiter">,</span> HASH_OLD<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</span> +case HASH_OLD: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'hash_old' takes exactly one ingredient rather than '"</span> << to_string<span class="Delimiter">(</span>inst<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_mu_string<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> <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">"'hash_old' currently only supports strings (address:shared:array:character), but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case HASH_OLD: <span class="Delimiter">{</span> + string input = read_mu_string<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + size_t h = <span class="Constant">0</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>input<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + h += static_cast<size_t><span class="Delimiter">(</span>input<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + h += <span class="Delimiter">(</span>h<<<span class="Constant">10</span><span class="Delimiter">);</span> + h ^= <span class="Delimiter">(</span>h>><span class="Constant">6</span><span class="Delimiter">);</span> + + h += <span class="Delimiter">(</span>h<<<span class="Constant">3</span><span class="Delimiter">);</span> + h ^= <span class="Delimiter">(</span>h>><span class="Constant">11</span><span class="Delimiter">);</span> + h += <span class="Delimiter">(</span>h<<<span class="Constant">15</span><span class="Delimiter">);</span> + <span class="Delimiter">}</span> + + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>h<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/078table.mu.html b/html/078table.mu.html new file mode 100644 index 00000000..6efef6d2 --- /dev/null +++ b/html/078table.mu.html @@ -0,0 +1,99 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - 078table.mu</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v1"> +<meta name="syntax" content="none"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +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; } +.muRecipe { color: #ff8700; } +.muScenario { color: #00af00; } +.muData { color: #ffff00; } +.Comment { color: #9090ff; } +.Constant { color: #00a0a0; } +.Special { color: #ff6060; } +.Delimiter { color: #a04060; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment"># A table is like an array, except that its keys are not integers but</span> +<span class="Comment"># arbitrary types.</span> + +<span class="muScenario">scenario</span> table-read-write [ + run [ + <span class="Constant">1</span>:address:shared:table:number:number<span class="Special"> <- </span>new-table <span class="Constant">30</span> + put <span class="Constant">1</span>:address:shared:table:number:number, <span class="Constant">12</span>, <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>index <span class="Constant">1</span>:address:shared:table:number:number, <span class="Constant">12</span> + ] + memory-should-contain [ + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">34</span> + ] +] + +<span class="muData">container</span> table:_key:_value [ + length:number + capacity:number + data:address:shared:array:table_row:_key:_value +] + +<span class="muData">container</span> table_row:_key:_value [ + occupied?:boolean + key:_key + value:_value +] + +<span class="muRecipe">recipe</span> new-table capacity:number<span class="muRecipe"> -> </span>result:address:shared:table:_key:_value [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + result<span class="Special"> <- </span>new <span class="Delimiter">{</span>(table _key _value): type<span class="Delimiter">}</span> + tmp:address:number<span class="Special"> <- </span>get-address *result, <span class="Constant">capacity:offset</span> + *tmp<span class="Special"> <- </span>copy capacity + data:address:address:shared:array:table_row:_key:_value<span class="Special"> <- </span>get-address *result, <span class="Constant">data:offset</span> + *data<span class="Special"> <- </span>new <span class="Delimiter">{</span>(table_row _key _value): type<span class="Delimiter">}</span>, capacity +] + +<span class="muRecipe">recipe</span> put table:address:shared:table:_key:_value, key:_key, value:_value<span class="muRecipe"> -> </span>table:address:shared:table:_key:_value [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + hash:number<span class="Special"> <- </span>hash key + capacity:number<span class="Special"> <- </span>get *table, <span class="Constant">capacity:offset</span> + _, hash<span class="Special"> <- </span>divide-with-remainder hash, capacity + table-data:address:shared:array:table_row:_key:_value<span class="Special"> <- </span>get *table, <span class="Constant">data:offset</span> + x:address:table_row:_key:_value<span class="Special"> <- </span>index-address *table-data, hash + occupied?:boolean<span class="Special"> <- </span>get *x, <span class="Constant">occupied?:offset</span> + not-occupied?:boolean<span class="Special"> <- </span>not occupied?:boolean + assert not-occupied?, <span class="Constant">[can't handle collisions yet]</span> + *x<span class="Special"> <- </span>merge <span class="Constant">1/true</span>, key, value +] + +<span class="muRecipe">recipe</span> index table:address:shared:table:_key:_value, key:_key<span class="muRecipe"> -> </span>result:_value [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + hash:number<span class="Special"> <- </span>hash key + capacity:number<span class="Special"> <- </span>get *table, <span class="Constant">capacity:offset</span> + _, hash<span class="Special"> <- </span>divide-with-remainder hash, capacity + table-data:address:shared:array:table_row:_key:_value<span class="Special"> <- </span>get *table, <span class="Constant">data:offset</span> + x:address:table_row:_key:_value<span class="Special"> <- </span>index-address *table-data, hash + occupied?:boolean<span class="Special"> <- </span>get *x, <span class="Constant">occupied?:offset</span> + assert occupied?, <span class="Constant">[can't handle missing elements yet]</span> + result<span class="Special"> <- </span>get *x, <span class="Constant">value:offset</span> +] +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/080display.cc.html b/html/080display.cc.html index 6e605255..b5668ab4 100644 --- a/html/080display.cc.html +++ b/html/080display.cc.html @@ -132,7 +132,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case PRINT_CHARACTER_TO_DISPLAY: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<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">"'print-character-to-display' requires at least one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'print-character-to-display' requires at least one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_number<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> <span class="Delimiter">{</span> @@ -218,7 +218,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case MOVE_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'move-cursor-on-display' requires two ingredients, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'move-cursor-on-display' requires two ingredients, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_number<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> <span class="Delimiter">{</span> diff --git a/html/085scenario_console.cc.html b/html/085scenario_console.cc.html index 24311448..53ba320b 100644 --- a/html/085scenario_console.cc.html +++ b/html/085scenario_console.cc.html @@ -309,7 +309,7 @@ long long int size_of_event<span class="Delimiter">()</span> <span class="Delimi <span class="Comment">// memoize result if already computed</span> static long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>result<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> - type_tree* type = new type_tree<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"event"</span><span class="Delimiter">));</span> + type_tree* type = new type_tree<span class="Delimiter">(</span><span class="Constant">"event"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"event"</span><span class="Delimiter">));</span> result = size_of<span class="Delimiter">(</span>type<span class="Delimiter">);</span> delete type<span class="Delimiter">;</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> @@ -320,7 +320,7 @@ long long int size_of_console<span class="Delimiter">()</span> <span class="Deli static long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>result<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"console"</span><span class="Delimiter">));</span> - type_tree* type = new type_tree<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"console"</span><span class="Delimiter">));</span> + type_tree* type = new type_tree<span class="Delimiter">(</span><span class="Constant">"console"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"console"</span><span class="Delimiter">));</span> result = size_of<span class="Delimiter">(</span>type<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> delete type<span class="Delimiter">;</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> diff --git a/html/086scenario_console_test.mu.html b/html/086scenario_console_test.mu.html index f36290b3..181c8973 100644 --- a/html/086scenario_console_test.mu.html +++ b/html/086scenario_console_test.mu.html @@ -17,6 +17,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -53,6 +54,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">1</span> ] ] + +<span class="CommentedCode">#? recipe foo-editor [</span> +<span class="CommentedCode">#? local-scope</span> +<span class="CommentedCode">#? init:address:shared:list:character <- push 97/a, 0</span> +<span class="CommentedCode">#? ]</span> </pre> </body> </html> diff --git a/html/090trace_browser.cc.html b/html/090trace_browser.cc.html index 7cc79bce..26c71eba 100644 --- a/html/090trace_browser.cc.html +++ b/html/090trace_browser.cc.html @@ -110,7 +110,7 @@ void start_trace_browser<span class="Delimiter">()</span> <span class="Delimiter if <span class="Delimiter">(</span>key == <span class="Constant">'J'</span> || key == TB_KEY_PGDN<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// page-down</span> if <span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> != Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> - Top_of_screen = Trace_index[tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span>]+<span class="Constant">1</span><span class="Delimiter">;</span> + Top_of_screen = get<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> + <span class="Constant">1</span><span class="Delimiter">;</span> refresh_screen_rows<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -142,7 +142,7 @@ void start_trace_browser<span class="Delimiter">()</span> <span class="Delimiter if <span class="Delimiter">(</span>key == TB_KEY_CARRIAGE_RETURN<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// expand lines under current by one level</span> assert<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> Display_row<span class="Delimiter">));</span> - long long int start_index = Trace_index[Display_row]<span class="Delimiter">;</span> + long long int start_index = get<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// simultaneously compute end_index and min_depth</span> int min_depth = <span class="Constant">9999</span><span class="Delimiter">;</span> @@ -165,7 +165,7 @@ void start_trace_browser<span class="Delimiter">()</span> <span class="Delimiter if <span class="Delimiter">(</span>key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// collapse all lines under current</span> assert<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> Display_row<span class="Delimiter">));</span> - long long int start_index = Trace_index[Display_row]<span class="Delimiter">;</span> + long long int start_index = get<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// end_index is the next line at a depth same as or lower than start_index</span> int initial_depth = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>start_index<span class="Delimiter">).</span>depth<span class="Delimiter">;</span> @@ -196,7 +196,7 @@ void refresh_screen_rows<span class="Delimiter">()</span> <span class="Delimiter if <span class="Delimiter">(</span>index >= SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">))</span> <span class="Identifier">goto</span> done<span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>index < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">));</span> - Trace_index[screen_row] = index<span class="Delimiter">;</span> + put<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> screen_row<span class="Delimiter">,</span> index<span class="Delimiter">);</span> <span class="Delimiter">}</span> done:<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -205,7 +205,7 @@ void render<span class="Delimiter">()</span> <span class="Delimiter">{</span> long long int screen_row = <span class="Constant">0</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>screen_row = <span class="Constant">0</span><span class="Delimiter">;</span> screen_row < tb_height<span class="Delimiter">();</span> ++screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> screen_row<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - trace_line& curr_line = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Trace_index[screen_row]<span class="Delimiter">);</span> + trace_line& curr_line = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> screen_row<span class="Delimiter">));</span> ostringstream out<span class="Delimiter">;</span> out << std::setw<span class="Delimiter">(</span><span class="Constant">4</span><span class="Delimiter">)</span> << curr_line<span class="Delimiter">.</span>depth << <span class="Constant">' '</span> << curr_line<span class="Delimiter">.</span>label << <span class="Constant">": "</span> << curr_line<span class="Delimiter">.</span>contents<span class="Delimiter">;</span> if <span class="Delimiter">(</span>screen_row < tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -230,9 +230,9 @@ void render<span class="Delimiter">()</span> <span class="Delimiter">{</span> long long int lines_hidden<span class="Delimiter">(</span>long long int screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> screen_row<span class="Delimiter">));</span> if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> screen_row+<span class="Constant">1</span><span class="Delimiter">))</span> - <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">)</span>-Trace_index[screen_row]<span class="Delimiter">;</span> + <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">)</span> - get<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> screen_row<span class="Delimiter">);</span> else - <span class="Identifier">return</span> Trace_index[screen_row+<span class="Constant">1</span>] - Trace_index[screen_row]<span class="Delimiter">;</span> + <span class="Identifier">return</span> get<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> screen_row+<span class="Constant">1</span><span class="Delimiter">)</span> - get<span class="Delimiter">(</span>Trace_index<span class="Delimiter">,</span> screen_row<span class="Delimiter">);</span> <span class="Delimiter">}</span> void render_line<span class="Delimiter">(</span>int screen_row<span class="Delimiter">,</span> const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> diff --git a/html/091run_interactive.cc.html b/html/091run_interactive.cc.html index 661ff83c..423e1f89 100644 --- a/html/091run_interactive.cc.html +++ b/html/091run_interactive.cc.html @@ -52,9 +52,9 @@ recipe main [ <span class="Comment"># result is null</span> <span class="traceContains">+mem: storing 0 in location 2</span> -<span class="Comment">//: run code in 'interactive mode', i.e. with errors+warnings off and return:</span> +<span class="Comment">//: run code in 'interactive mode', i.e. with errors off and return:</span> <span class="Comment">//: stringified output in case we want to print it to screen</span> -<span class="Comment">//: any errors+warnings encountered</span> +<span class="Comment">//: any errors encountered</span> <span class="Comment">//: simulated screen any prints went to</span> <span class="Comment">//: any 'app' layer traces generated</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> @@ -64,11 +64,11 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case RUN_INTERACTIVE: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'run-interactive' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'run-interactive' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_string<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> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"first ingredient of 'run-interactive' should be a string, but got "</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>to_string<span class="Delimiter">()</span> << <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">"first ingredient of 'run-interactive' should be a string, but got "</span> << to_string<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> << <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> @@ -79,7 +79,7 @@ case RUN_INTERACTIVE: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!new_code_pushed_to_stack<span class="Delimiter">)</span> <span class="Delimiter">{</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">5</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>trace_error_warning_contents<span class="Delimiter">());</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>trace_error_contents<span class="Delimiter">());</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>trace_app_contents<span class="Delimiter">());</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">4</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// completed</span> @@ -102,7 +102,7 @@ vector<recipe_ordinal> Save_recently_added_shape_shifting_recipes<span cla Track_most_recent_products = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> <span class="Comment">// reads a string, tries to call it as code (treating it as a test), saving</span> -<span class="Comment">// all warnings.</span> +<span class="Comment">// all errors.</span> <span class="Comment">// returns true if successfully called (no errors found during load and transform)</span> bool run_interactive<span class="Delimiter">(</span>long long int address<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"interactive"</span><span class="Delimiter">)</span> && get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"interactive"</span><span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">);</span> @@ -145,9 +145,8 @@ bool run_interactive<span class="Delimiter">(</span>long long int address<span c void run_code_begin<span class="Delimiter">(</span>bool snapshot_recently_added_recipes<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "loading new trace\n";</span> <span class="Comment">// stuff to undo later, in run_code_end()</span> - Hide_warnings = <span class="Constant">true</span><span class="Delimiter">;</span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> - Disable_redefine_warnings = <span class="Constant">true</span><span class="Delimiter">;</span> + Disable_redefine_checks = <span class="Constant">true</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>snapshot_recently_added_recipes<span class="Delimiter">)</span> <span class="Delimiter">{</span> Save_recently_added_recipes = Recently_added_recipes<span class="Delimiter">;</span> Recently_added_recipes<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> @@ -163,9 +162,8 @@ void run_code_begin<span class="Delimiter">(</span>bool snapshot_recently_added_ void run_code_end<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "back to old trace\n";</span> - Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> Hide_errors = <span class="Constant">false</span><span class="Delimiter">;</span> - Disable_redefine_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> + Disable_redefine_checks = <span class="Constant">false</span><span class="Delimiter">;</span> delete Trace_stream<span class="Delimiter">;</span> Trace_stream = Save_trace_stream<span class="Delimiter">;</span> Save_trace_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> @@ -194,15 +192,15 @@ load<span class="Delimiter">(</span>string<span class="Delimiter">(</span> <span class="Constant">"sandbox-state:number <- routine-state r/routine_id</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"completed?:boolean <- equal sandbox-state, 1/completed</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"output:address:shared:array:character <- $most-recent-products</span><span class="cSpecial">\n</span><span class="Constant">"</span> + - <span class="Constant">"warnings:address:shared:array:character <- save-errors-warnings</span><span class="cSpecial">\n</span><span class="Constant">"</span> + + <span class="Constant">"errors:address:shared:array:character <- save-errors</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"stashes:address:shared:array:character <- save-app-trace</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"$cleanup-run-interactive</span><span class="cSpecial">\n</span><span class="Constant">"</span> + - <span class="Constant">"reply output, warnings, screen, stashes, completed?</span><span class="cSpecial">\n</span><span class="Constant">"</span> + + <span class="Constant">"reply output, errors, screen, stashes, completed?</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> transform_all<span class="Delimiter">();</span> Recently_added_recipes<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> -<span class="Comment">//: adjust errors/warnings in the sandbox</span> +<span class="Comment">//: adjust errors in the sandbox</span> <span class="Delimiter">:(after "string maybe(string s)")</span> if <span class="Delimiter">(</span>s == <span class="Constant">"interactive"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> @@ -259,17 +257,17 @@ case _MOST_RECENT_PRODUCTS: <span class="Delimiter">{</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -SAVE_ERRORS_WARNINGS<span class="Delimiter">,</span> +SAVE_ERRORS<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"save-errors-warnings"</span><span class="Delimiter">,</span> SAVE_ERRORS_WARNINGS<span class="Delimiter">);</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"save-errors"</span><span class="Delimiter">,</span> SAVE_ERRORS<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> -case SAVE_ERRORS_WARNINGS: <span class="Delimiter">{</span> +case SAVE_ERRORS: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -case SAVE_ERRORS_WARNINGS: <span class="Delimiter">{</span> +case SAVE_ERRORS: <span class="Delimiter">{</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> - products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>trace_error_warning_contents<span class="Delimiter">());</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>trace_error_contents<span class="Delimiter">());</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -395,7 +393,7 @@ void track_most_recent_products<span class="Delimiter">(</span>const instruction if <span class="Delimiter">(</span>is_mu_string<span class="Delimiter">(</span>instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> tb_shutdown<span class="Delimiter">();</span> - cerr << read_mu_string<span class="Delimiter">(</span>trace_error_warning_contents<span class="Delimiter">())</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + cerr << read_mu_string<span class="Delimiter">(</span>trace_error_contents<span class="Delimiter">())</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> cerr << SIZE<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> << <span class="Constant">": "</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> cerr << no_scientific<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">))</span> << <span class="Constant">' '</span><span class="Delimiter">;</span> @@ -436,11 +434,11 @@ long long int stringified_value_of_location<span class="Delimiter">(</span>long <span class="Identifier">return</span> new_mu_string<span class="Delimiter">(</span>out<span class="Delimiter">.</span>str<span class="Delimiter">());</span> <span class="Delimiter">}</span> -long long int trace_error_warning_contents<span class="Delimiter">()</span> <span class="Delimiter">{</span> +long long int trace_error_contents<span class="Delimiter">()</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> ostringstream out<span class="Delimiter">;</span> for <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>depth > Warning_depth<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>label != <span class="Constant">"error"</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> out << p<span class="Delimiter">-></span>contents<span class="Delimiter">;</span> if <span class="Delimiter">(</span>*--p<span class="Delimiter">-></span>contents<span class="Delimiter">.</span>end<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> out << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -474,7 +472,7 @@ void truncate<span class="Delimiter">(</span>string& x<span class="Delimiter <span class="Delimiter">}</span> <span class="Comment">//: simpler version of run-interactive: doesn't do any running, just loads</span> -<span class="Comment">//: recipes and reports errors+warnings.</span> +<span class="Comment">//: recipes and reports errors.</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> RELOAD<span class="Delimiter">,</span> @@ -483,7 +481,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case RELOAD: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'reload' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'reload' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>!is_mu_string<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> <span class="Delimiter">{</span> @@ -497,6 +495,7 @@ case RELOAD: <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "== reload\n";</span> <span class="Comment">// clear any containers in advance</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>Recently_added_types<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> Type_ordinal<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)).</span>name<span class="Delimiter">);</span> Type<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>Recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> @@ -529,7 +528,7 @@ case RELOAD: <span class="Delimiter">{</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> <span class="Comment">// flush trace</span> Current_routine = save_current_routine<span class="Delimiter">;</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> - products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>trace_error_warning_contents<span class="Delimiter">());</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>trace_error_contents<span class="Delimiter">());</span> run_code_end<span class="Delimiter">();</span> <span class="Comment">// wait until we're done with the trace contents</span> <span class="CommentedCode">//? cerr << "reload done\n";</span> <span class="Identifier">break</span><span class="Delimiter">;</span> diff --git a/html/092persist.cc.html b/html/092persist.cc.html index c2056b8c..9aadfceb 100644 --- a/html/092persist.cc.html +++ b/html/092persist.cc.html @@ -40,7 +40,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case RESTORE: <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">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'restore' requires exactly one ingredient, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'restore' requires exactly one ingredient, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> string filename<span class="Delimiter">;</span> @@ -51,7 +51,7 @@ case RESTORE: <span class="Delimiter">{</span> <span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"first ingredient of 'restore' should be a string, but got "</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>to_string<span class="Delimiter">()</span> << <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">"first ingredient of 'restore' should be a string, but got "</span> << to_string<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> << <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> @@ -104,7 +104,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(before "End Primitive Recipe Checks")</span> case SAVE: <span class="Delimiter">{</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'save' requires exactly two ingredients, but got "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <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">"'save' requires exactly two ingredients, but got "</span> << to_string<span class="Delimiter">(</span>inst<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> if <span class="Delimiter">(</span>is_literal_string<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> <span class="Delimiter">{</span> @@ -114,11 +114,11 @@ case SAVE: <span class="Delimiter">{</span> <span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"first ingredient of 'save' should be a string, but got "</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>to_string<span class="Delimiter">()</span> << <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">"first ingredient of 'save' should be a string, but got "</span> << to_string<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> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>!is_mu_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> - raise_error << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"second ingredient of 'save' should be an address:array:character, but got "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>to_string<span class="Delimiter">()</span> << <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">"second ingredient of 'save' should be an address:array:character, but got "</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">))</span> << <span class="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> diff --git a/html/console.mu.html b/html/console.mu.html index 1a14d4ed..c96b585d 100644 --- a/html/console.mu.html +++ b/html/console.mu.html @@ -16,9 +16,9 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } .muControl { color: #c0a020; } .muRecipe { color: #ff8700; } .Comment { color: #9090ff; } -.Delimiter { color: #a04060; } -.Special { color: #ff6060; } .Constant { color: #00a0a0; } +.Special { color: #ff6060; } +.Delimiter { color: #a04060; } --> </style> @@ -35,6 +35,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment"># Keeps printing 'a' until you press a key or click on the mouse.</span> <span class="muRecipe">recipe</span> main [ + <span class="Constant">local-scope</span> open-console <span class="Delimiter">{</span> e:event, found?:boolean<span class="Special"> <- </span>check-for-interaction diff --git a/html/edit/003-shortcuts.mu.html b/html/edit/003-shortcuts.mu.html index d47c0614..d3a4f5e8 100644 --- a/html/edit/003-shortcuts.mu.html +++ b/html/edit/003-shortcuts.mu.html @@ -2344,9 +2344,10 @@ def] <span class="Comment"># takes a pointer into the doubly-linked list, scans back to before start of</span> <span class="Comment"># previous *wrapped* line</span> <span class="Comment"># beware: never return null pointer</span> -<span class="muRecipe">recipe</span> before-previous-line curr:address:shared:duplex-list:character, editor:address:shared:editor-data<span class="muRecipe"> -> </span>curr:address:shared:duplex-list:character [ +<span class="muRecipe">recipe</span> before-previous-line in:address:shared:duplex-list:character, editor:address:shared:editor-data<span class="muRecipe"> -> </span>out:address:shared:duplex-list:character [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> + curr:address:shared:duplex-list:character<span class="Special"> <- </span>copy in c:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> <span class="Comment"># compute max, number of characters to skip</span> <span class="Comment"># 1 + len%(width-1)</span> diff --git a/html/edit/010-warnings.mu.html b/html/edit/010-errors.mu.html index eca63962..b72ce428 100644 --- a/html/edit/010-warnings.mu.html +++ b/html/edit/010-errors.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - edit/010-warnings.mu</title> +<title>Mu - edit/010-errors.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -37,10 +37,10 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="SalientComment">## handling malformed programs</span> <span class="muData">container</span> programming-environment-data [ - recipe-warnings:address:shared:array:character + recipe-errors:address:shared:array:character ] -<span class="Comment"># copy code from recipe editor, persist, load into mu, save any warnings</span> +<span class="Comment"># copy code from recipe editor, persist, load into mu, save any errors</span> <span class="muRecipe">recipe!</span> update-recipes env:address:shared:programming-environment-data, screen:address:shared:screen<span class="muRecipe"> -> </span>errors-found?:boolean, env:address:shared:programming-environment-data, screen:address:shared:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> @@ -48,11 +48,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } recipes:address:shared:editor-data<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> in:address:shared:array:character<span class="Special"> <- </span>editor-contents recipes save <span class="Constant">[recipes.mu]</span>, in - recipe-warnings:address:address:shared:array:character<span class="Special"> <- </span>get-address *env, <span class="Constant">recipe-warnings:offset</span> - *recipe-warnings<span class="Special"> <- </span>reload in + recipe-errors:address:address:shared:array:character<span class="Special"> <- </span>get-address *env, <span class="Constant">recipe-errors:offset</span> + *recipe-errors<span class="Special"> <- </span>reload in <span class="Comment"># if recipe editor has errors, stop</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> *recipe-warnings + <span class="muControl">break-unless</span> *recipe-errors status:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[errors found ]</span> update-status screen, status, <span class="Constant">1/red</span> errors-found?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> @@ -63,9 +63,9 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">before</span> <span class="Constant"><render-components-end></span> [ trace <span class="Constant">11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render status]</span> - recipe-warnings:address:shared:array:character<span class="Special"> <- </span>get *env, <span class="Constant">recipe-warnings:offset</span> + recipe-errors:address:shared:array:character<span class="Special"> <- </span>get *env, <span class="Constant">recipe-errors:offset</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> recipe-warnings + <span class="muControl">break-unless</span> recipe-errors status:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[errors found ]</span> update-status screen, status, <span class="Constant">1/red</span> <span class="Delimiter">}</span> @@ -73,29 +73,29 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">before</span> <span class="Constant"><render-recipe-components-end></span> [ <span class="Delimiter">{</span> - recipe-warnings:address:shared:array:character<span class="Special"> <- </span>get *env, <span class="Constant">recipe-warnings:offset</span> - <span class="muControl">break-unless</span> recipe-warnings - row, screen<span class="Special"> <- </span>render screen, recipe-warnings, left, right, <span class="Constant">1/red</span>, row + recipe-errors:address:shared:array:character<span class="Special"> <- </span>get *env, <span class="Constant">recipe-errors:offset</span> + <span class="muControl">break-unless</span> recipe-errors + row, screen<span class="Special"> <- </span>render screen, recipe-errors, left, right, <span class="Constant">1/red</span>, row <span class="Delimiter">}</span> ] <span class="muData">container</span> programming-environment-data [ - warning-index:number <span class="Comment"># index of first sandbox with an error (or -1 if none)</span> + error-index:number <span class="Comment"># index of first sandbox with an error (or -1 if none)</span> ] <span class="muRecipe">after</span> <span class="Constant"><programming-environment-initialization></span> [ - warning-index:address:number<span class="Special"> <- </span>get-address *result, <span class="Constant">warning-index:offset</span> - *warning-index<span class="Special"> <- </span>copy <span class="Constant">-1</span> + error-index:address:number<span class="Special"> <- </span>get-address *result, <span class="Constant">error-index:offset</span> + *error-index<span class="Special"> <- </span>copy <span class="Constant">-1</span> ] <span class="muRecipe">after</span> <span class="Constant"><run-sandboxes-begin></span> [ - warning-index:address:number<span class="Special"> <- </span>get-address *env, <span class="Constant">warning-index:offset</span> - *warning-index<span class="Special"> <- </span>copy <span class="Constant">-1</span> + error-index:address:number<span class="Special"> <- </span>get-address *env, <span class="Constant">error-index:offset</span> + *error-index<span class="Special"> <- </span>copy <span class="Constant">-1</span> ] <span class="muRecipe">before</span> <span class="Constant"><run-sandboxes-end></span> [ <span class="Delimiter">{</span> - sandboxes-completed-successfully?:boolean<span class="Special"> <- </span>equal *warning-index, <span class="Constant">-1</span> + sandboxes-completed-successfully?:boolean<span class="Special"> <- </span>equal *error-index, <span class="Constant">-1</span> <span class="muControl">break-if</span> sandboxes-completed-successfully? errors-found?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> <span class="Delimiter">}</span> @@ -103,21 +103,21 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">before</span> <span class="Constant"><render-components-end></span> [ <span class="Delimiter">{</span> - <span class="muControl">break-if</span> recipe-warnings - warning-index:number<span class="Special"> <- </span>get *env, <span class="Constant">warning-index:offset</span> - sandboxes-completed-successfully?:boolean<span class="Special"> <- </span>equal warning-index, <span class="Constant">-1</span> + <span class="muControl">break-if</span> recipe-errors + error-index:number<span class="Special"> <- </span>get *env, <span class="Constant">error-index:offset</span> + sandboxes-completed-successfully?:boolean<span class="Special"> <- </span>equal error-index, <span class="Constant">-1</span> <span class="muControl">break-if</span> sandboxes-completed-successfully? status-template:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[errors found (_) ]</span> - warning-index-text:address:shared:array:character<span class="Special"> <- </span>to-text warning-index - status:address:shared:array:character<span class="Special"> <- </span>interpolate status-template, warning-index-text -<span class="CommentedCode">#? $print [update-status: sandbox warning], 10/newline</span> + error-index-text:address:shared:array:character<span class="Special"> <- </span>to-text error-index + status:address:shared:array:character<span class="Special"> <- </span>interpolate status-template, error-index-text +<span class="CommentedCode">#? $print [update-status: sandbox error], 10/newline</span> update-status screen, status, <span class="Constant">1/red</span> <span class="CommentedCode">#? $print [run sandboxes end], 10/newline</span> <span class="Delimiter">}</span> ] <span class="muData">container</span> sandbox-data [ - warnings:address:shared:array:character + errors:address:shared:array:character ] <span class="muRecipe">recipe!</span> update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number<span class="muRecipe"> -> </span>sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [ @@ -126,24 +126,24 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="CommentedCode">#? $log [update sandbox]</span> data:address:shared:array:character<span class="Special"> <- </span>get *sandbox, <span class="Constant">data:offset</span> response:address:address:shared:array:character<span class="Special"> <- </span>get-address *sandbox, <span class="Constant">response:offset</span> - warnings:address:address:shared:array:character<span class="Special"> <- </span>get-address *sandbox, <span class="Constant">warnings:offset</span> + errors:address:address:shared:array:character<span class="Special"> <- </span>get-address *sandbox, <span class="Constant">errors:offset</span> trace:address:address:shared:array:character<span class="Special"> <- </span>get-address *sandbox, <span class="Constant">trace:offset</span> fake-screen:address:address:shared:screen<span class="Special"> <- </span>get-address *sandbox, <span class="Constant">screen:offset</span> <span class="CommentedCode">#? $print [run-interactive], 10/newline</span> - *response, *warnings, *fake-screen, *trace, completed?:boolean<span class="Special"> <- </span>run-interactive data + *response, *errors, *fake-screen, *trace, completed?:boolean<span class="Special"> <- </span>run-interactive data <span class="Delimiter">{</span> - <span class="muControl">break-if</span> *warnings + <span class="muControl">break-if</span> *errors <span class="muControl">break-if</span> completed?:boolean - *warnings<span class="Special"> <- </span>new <span class="Constant">[took too long!</span> + *errors<span class="Special"> <- </span>new <span class="Constant">[took too long!</span> <span class="Constant">]</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> *warnings -<span class="CommentedCode">#? $print [setting warning-index to ], idx, 10/newline</span> - warning-index:address:number<span class="Special"> <- </span>get-address *env, <span class="Constant">warning-index:offset</span> - warning-not-set?:boolean<span class="Special"> <- </span>equal *warning-index, <span class="Constant">-1</span> - <span class="muControl">break-unless</span> warning-not-set? - *warning-index<span class="Special"> <- </span>copy idx + <span class="muControl">break-unless</span> *errors +<span class="CommentedCode">#? $print [setting error-index to ], idx, 10/newline</span> + error-index:address:number<span class="Special"> <- </span>get-address *env, <span class="Constant">error-index:offset</span> + error-not-set?:boolean<span class="Special"> <- </span>equal *error-index, <span class="Constant">-1</span> + <span class="muControl">break-unless</span> error-not-set? + *error-index<span class="Special"> <- </span>copy idx <span class="Delimiter">}</span> <span class="CommentedCode">#? $print [done with run-interactive], 10/newline</span> ] @@ -151,17 +151,17 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment"># make sure we render any trace</span> <span class="muRecipe">after</span> <span class="Constant"><render-sandbox-trace-done></span> [ <span class="Delimiter">{</span> - sandbox-warnings:address:shared:array:character<span class="Special"> <- </span>get *sandbox, <span class="Constant">warnings:offset</span> - <span class="muControl">break-unless</span> sandbox-warnings + sandbox-errors:address:shared:array:character<span class="Special"> <- </span>get *sandbox, <span class="Constant">errors:offset</span> + <span class="muControl">break-unless</span> sandbox-errors response-starting-row:address:number<span class="Special"> <- </span>get-address *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span> *response-starting-row<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># no response</span> - row, screen<span class="Special"> <- </span>render screen, sandbox-warnings, left, right, <span class="Constant">1/red</span>, row + row, screen<span class="Special"> <- </span>render screen, sandbox-errors, left, right, <span class="Constant">1/red</span>, row <span class="Comment"># don't try to print anything more for this sandbox</span> <span class="muControl">jump</span> <span class="Constant">+render-sandbox-end:label</span> <span class="Delimiter">}</span> ] -<span class="muScenario">scenario</span> run-shows-warnings-in-get [ +<span class="muScenario">scenario</span> run-shows-errors-in-get [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> @@ -252,7 +252,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-hides-warnings-from-past-sandboxes [ +<span class="muScenario">scenario</span> run-hides-errors-from-past-sandboxes [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> @@ -286,7 +286,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-updates-warnings-for-shape-shifting-recipes [ +<span class="muScenario">scenario</span> run-updates-errors-for-shape-shifting-recipes [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Comment"># define a shape-shifting recipe with an error</span> @@ -333,7 +333,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-avoids-spurious-warnings-on-reloading-shape-shifting-recipes [ +<span class="muScenario">scenario</span> run-avoids-spurious-errors-on-reloading-shape-shifting-recipes [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Comment"># overload a well-known shape-shifting recipe</span> @@ -393,7 +393,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-shows-missing-type-warnings [ +<span class="muScenario">scenario</span> run-shows-missing-type-errors [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> @@ -418,7 +418,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-shows-unbalanced-bracket-warnings [ +<span class="muScenario">scenario</span> run-shows-unbalanced-bracket-errors [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Comment"># recipe is incomplete (unbalanced '[')</span> @@ -447,7 +447,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-shows-get-on-non-container-warnings [ +<span class="muScenario">scenario</span> run-shows-get-on-non-container-errors [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> @@ -479,7 +479,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-shows-non-literal-get-argument-warnings [ +<span class="muScenario">scenario</span> run-shows-non-literal-get-argument-errors [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> @@ -515,7 +515,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-shows-warnings-everytime [ +<span class="muScenario">scenario</span> run-shows-errors-everytime [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> <span class="Comment"># try to run a file with an error</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> @@ -561,7 +561,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-instruction-and-print-warnings [ +<span class="muScenario">scenario</span> run-instruction-and-print-errors [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># left editor is empty</span> @@ -624,7 +624,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> run-instruction-and-print-warnings-only-once [ +<span class="muScenario">scenario</span> run-instruction-and-print-errors-only-once [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># left editor is empty</span> @@ -686,10 +686,10 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] ] -<span class="muScenario">scenario</span> sandbox-with-warnings-shows-trace [ +<span class="muScenario">scenario</span> sandbox-with-errors-shows-trace [ trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> - <span class="Comment"># generate a stash and a warning</span> + <span class="Comment"># generate a stash and a error</span> <span class="Constant">1</span>:address:shared:array:character<span class="Special"> <- </span>new <span class="Constant">[recipe foo [</span> <span class="Constant">local-scope</span> <span class="Constant">a:number <- next-ingredient</span> diff --git a/html/example1.mu.html b/html/example1.mu.html index 13333c91..972f37d2 100644 --- a/html/example1.mu.html +++ b/html/example1.mu.html @@ -28,6 +28,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <body> <pre id='vimCodeElement'> <span class="muRecipe">recipe</span> example1 [ + <span class="Constant">local-scope</span> a:number<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> a<span class="Special"> <- </span>multiply a, <span class="Constant">3</span> ] diff --git a/index.html b/index.html index e88da515..90f46772 100644 --- a/index.html +++ b/index.html @@ -243,8 +243,8 @@ click on code in a sandbox to open up a drawer containing its trace. The trace can be added to using the <span style='font-family:courier,fixed'>stash</span> command, which renders arbitrary data structures using <span style='font-family:courier,fixed'>to-text</span> with the appropriate recipe header. -<br/><a href='html/edit/010-warnings.mu.html'>edit/010-warnings.mu</a>: -support for rendering warnings on both the left and in each sandbox. +<br/><a href='html/edit/010-errors.mu.html'>edit/010-errors.mu</a>: +support for rendering errors on both the left and in each sandbox. <br/><a href='html/edit/011-editor-undo.mu.html'>edit/011-editor-undo.mu</a>: support for undo in the editor widget. |