diff options
48 files changed, 3641 insertions, 1849 deletions
diff --git a/html/000organization.cc.html b/html/000organization.cc.html index 5984921c..b50b0238 100644 --- a/html/000organization.cc.html +++ b/html/000organization.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 000organization.cc</title> +<title>~/Desktop/s/mu/000organization.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -101,12 +101,12 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment">//: Here's part of a layer in color: <a href="http://i.imgur.com/0eONnyX.png">http://i.imgur.com/0eONnyX.png</a>. Directives</span> <span class="Comment">//: are shaded dark.</span> <span class="Comment">//:</span> -<span class="Comment">//: Layers do more than just shuffle code around. Their guarantee is that it</span> -<span class="Comment">//: should be possible to stop loading after any file/layer, build and run the</span> -<span class="Comment">//: program, and pass all tests for loaded features. (Relevant is</span> +<span class="Comment">//: Layers do more than just shuffle code around. In a well-organized codebase</span> +<span class="Comment">//: it should be possible to stop loading after any file/layer, build and run</span> +<span class="Comment">//: the program, and pass all tests for loaded features. (Relevant is</span> <span class="Comment">//: <a href="http://youtube.com/watch?v=c8N72t7aScY">http://youtube.com/watch?v=c8N72t7aScY</a>, a scene from "2001: A Space</span> -<span class="Comment">//: Odyssey".) Use the included script called 'test_all_layers' to check the</span> -<span class="Comment">//: guarantee if you make any changes.</span> +<span class="Comment">//: Odyssey".) Get into the habit of running the included script called</span> +<span class="Comment">//: 'test_all_layers' before you commit any changes.</span> <span class="Comment">//:</span> <span class="Comment">//: This 'subsetting guarantee' ensures that this directory contains a</span> <span class="Comment">//: cleaned-up narrative of the evolution of this codebase. Organizing</span> @@ -125,13 +125,14 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment">// Types</span> <span class="Comment">// End Types</span> -<span class="Comment">// prototypes are auto-generated; define your functions in any order</span> +<span class="Comment">// prototypes are auto-generated in the makefile; define your functions in any order</span> <span class="PreProc">#include </span><span class="Constant">"function_list"</span> <span class="Comment">// by convention, files ending with '_list' are auto-generated</span> <span class="Comment">// Globals</span> <span class="Comment">// End Globals</span> int main<span class="Delimiter">(</span>int argc<span class="Delimiter">,</span> char* argv[]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + atexit<span class="Delimiter">(</span>teardown<span class="Delimiter">);</span> <span class="Comment">// End One-time Setup</span> @@ -140,6 +141,13 @@ int main<span class="Delimiter">(</span>int argc<span class="Delimiter">,</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// End Main</span> <span class="Delimiter">}</span> +<span class="Comment">//: our first directive; will move the include above the program</span> +<span class="Delimiter">:(before "End Includes")</span> +<span class="PreProc">#include</span><span class="Constant"><stdlib.h></span> + +<span class="Comment">//: Without directives or with the :(code) directive, lines get added at the</span> +<span class="Comment">//: end.</span> +<span class="Delimiter">:(code)</span> void setup<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Comment">// End Setup</span> <span class="Delimiter">}</span> @@ -147,9 +155,6 @@ void setup<span class="Delimiter">()</span> <span class="Delimiter">{</span> void teardown<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Comment">// End Teardown</span> <span class="Delimiter">}</span> - -<span class="Comment">//: Without directives or with the :(code) directive, lines get added at the</span> -<span class="Comment">//: end.</span> </pre> </body> </html> diff --git a/html/001help.cc.html b/html/001help.cc.html index 8f4c8227..d1a53d63 100644 --- a/html/001help.cc.html +++ b/html/001help.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 001help.cc</title> +<title>~/Desktop/s/mu/001help.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> diff --git a/html/002test.cc.html b/html/002test.cc.html index ef38f047..afbe45ca 100644 --- a/html/002test.cc.html +++ b/html/002test.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 002test.cc</title> +<title>~/Desktop/s/mu/002test.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -55,7 +55,7 @@ long Num_failures = <span class="Constant">0</span><span class="Delimiter">;</sp <span class="PreProc">#define CHECK(X) \</span> <span class="PreProc"> </span>if<span class="PreProc"> (!(X)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> <span class="PreProc"> ++Num_failures</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> <span class="PreProc"> Passed = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> <span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> <span class="PreProc"> </span><span class="Delimiter">}</span> @@ -63,7 +63,7 @@ long Num_failures = <span class="Constant">0</span><span class="Delimiter">;</sp <span class="PreProc">#define CHECK_EQ(X</span><span class="Delimiter">,</span><span class="PreProc"> Y) \</span> <span class="PreProc"> </span>if<span class="PreProc"> ((X) != (Y)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> <span class="PreProc"> ++Num_failures</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="Constant">" == "</span><span class="PreProc"> << #Y << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="Constant">" == "</span><span class="PreProc"> << #Y << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> <span class="PreProc"> cerr << </span><span class="Constant">" got "</span><span class="PreProc"> << (X) << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> BEWARE: multiple eval </span><span class="Comment">*/</span><span class="PreProc"> \</span> <span class="PreProc"> Passed = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> <span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> @@ -90,10 +90,12 @@ if <span class="Delimiter">(</span>Run_tests<span class="Delimiter">)</span> <sp <span class="Delimiter">}</span> <span class="Comment">// End Tests</span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>Num_failures > <span class="Constant">0</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>Num_failures > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> cerr << Num_failures << <span class="Constant">" failure"</span> << <span class="Delimiter">(</span>Num_failures > <span class="Constant">1</span> ? <span class="Constant">"s"</span> : <span class="Constant">""</span><span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</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">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -114,7 +116,7 @@ bool is_number<span class="Delimiter">(</span>const string& s<span class="De <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="Delimiter">;</span> <span class="Delimiter">}</span> -long long int to_int<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int to_number<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> char* end = <span class="Constant">NULL</span><span class="Delimiter">;</span> long long int result = strtoll<span class="Delimiter">(</span>n<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">any base</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>*end == <span class="cSpecial">'\0'</span><span class="Delimiter">);</span> diff --git a/html/003trace.cc.html b/html/003trace.cc.html index cf44c85e..9e98eba5 100644 --- a/html/003trace.cc.html +++ b/html/003trace.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 003trace.cc</title> +<title>~/Desktop/s/mu/003trace.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -151,6 +151,7 @@ struct trace_stream <span class="Delimiter">{</span> past_lines<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> pair<int<span class="Delimiter">,</span> string> ><span class="Delimiter">(</span>curr_layer<span class="Delimiter">,</span> pair<int<span class="Delimiter">,</span> string><span class="Delimiter">(</span>frame[curr_layer]<span class="Delimiter">,</span> curr_contents<span class="Delimiter">)));</span> if <span class="Delimiter">(</span>curr_layer == dump_layer || curr_layer == <span class="Constant">"dump"</span> || dump_layer == <span class="Constant">"all"</span> || <span class="Delimiter">(</span>!Hide_warnings && curr_layer == <span class="Constant">"warn"</span><span class="Delimiter">))</span> +<span class="CommentedCode">//? if (dump_layer == "all" && (Current_routine->id == 3 || curr_layer == "schedule")) //? 1</span> cerr << curr_layer << <span class="Constant">'/'</span> << frame[curr_layer] << <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> @@ -249,12 +250,12 @@ void trace_all<span class="Delimiter">(</span>const string& label<span class bool check_trace_contents<span class="Delimiter">(</span>string FUNCTION<span class="Delimiter">,</span> string FILE<span class="Delimiter">,</span> int LINE<span class="Delimiter">,</span> string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// missing layer == anywhere, frame, hierarchical layers</span> vector<string> expected_lines = split<span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">"^D"</span><span class="Delimiter">);</span> index_t curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> - while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines[curr_expected_line]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> ++curr_expected_line<span class="Delimiter">;</span> if <span class="Delimiter">(</span>curr_expected_line == expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> string layer<span class="Delimiter">,</span> frame<span class="Delimiter">,</span> contents<span class="Delimiter">;</span> - parse_layer_frame_contents<span class="Delimiter">(</span>expected_lines[curr_expected_line]<span class="Delimiter">,</span> &layer<span class="Delimiter">,</span> &frame<span class="Delimiter">,</span> &contents<span class="Delimiter">);</span> + parse_layer_frame_contents<span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">),</span> &layer<span class="Delimiter">,</span> &frame<span class="Delimiter">,</span> &contents<span class="Delimiter">);</span> for <span class="Delimiter">(</span>vector<pair<string<span class="Delimiter">,</span> pair<int<span class="Delimiter">,</span> string> > >::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>!layer<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !prefix_match<span class="Delimiter">(</span>layer<span class="Delimiter">,</span> p<span class="Delimiter">-></span>first<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> @@ -266,14 +267,14 @@ bool check_trace_contents<span class="Delimiter">(</span>string FUNCTION<span cl <span class="Identifier">continue</span><span class="Delimiter">;</span> ++curr_expected_line<span class="Delimiter">;</span> - while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines[curr_expected_line]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> ++curr_expected_line<span class="Delimiter">;</span> if <span class="Delimiter">(</span>curr_expected_line == expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - parse_layer_frame_contents<span class="Delimiter">(</span>expected_lines[curr_expected_line]<span class="Delimiter">,</span> &layer<span class="Delimiter">,</span> &frame<span class="Delimiter">,</span> &contents<span class="Delimiter">);</span> + parse_layer_frame_contents<span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">),</span> &layer<span class="Delimiter">,</span> &frame<span class="Delimiter">,</span> &contents<span class="Delimiter">);</span> <span class="Delimiter">}</span> ++Num_failures<span class="Delimiter">;</span> - cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F "</span> << FUNCTION << <span class="Constant">"("</span> << FILE << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << contents << <span class="Constant">"] in trace:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << FUNCTION << <span class="Constant">"("</span> << FILE << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << contents << <span class="Constant">"] in trace:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> DUMP<span class="Delimiter">(</span>layer<span class="Delimiter">);</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> @@ -315,7 +316,7 @@ void parse_layer_and_frame<span class="Delimiter">(</span>const string& orig bool check_trace_contents<span class="Delimiter">(</span>string FUNCTION<span class="Delimiter">,</span> string FILE<span class="Delimiter">,</span> int LINE<span class="Delimiter">,</span> string layer<span class="Delimiter">,</span> string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// empty layer == everything, multiple layers, hierarchical layers</span> vector<string> expected_lines = split<span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">"^D"</span><span class="Delimiter">);</span> index_t curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> - while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines[curr_expected_line]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> ++curr_expected_line<span class="Delimiter">;</span> if <span class="Delimiter">(</span>curr_expected_line == expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> @@ -323,16 +324,16 @@ bool check_trace_contents<span class="Delimiter">(</span>string FUNCTION<span cl for <span class="Delimiter">(</span>vector<pair<string<span class="Delimiter">,</span> pair<int<span class="Delimiter">,</span> string> > >::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>!layer<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && !any_prefix_match<span class="Delimiter">(</span>layers<span class="Delimiter">,</span> p<span class="Delimiter">-></span>first<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>second != expected_lines[curr_expected_line]<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>second != expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> ++curr_expected_line<span class="Delimiter">;</span> - while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines[curr_expected_line]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> ++curr_expected_line<span class="Delimiter">;</span> if <span class="Delimiter">(</span>curr_expected_line == expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> ++Num_failures<span class="Delimiter">;</span> - cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F "</span> << FUNCTION << <span class="Constant">"("</span> << FILE << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << expected_lines[curr_expected_line] << <span class="Constant">"] in trace:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << FUNCTION << <span class="Constant">"("</span> << FILE << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">)</span> << <span class="Constant">"] in trace:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> DUMP<span class="Delimiter">(</span>layer<span class="Delimiter">);</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> @@ -372,7 +373,7 @@ int trace_count<span class="Delimiter">(</span>string layer<span class="Delimite <span class="PreProc">#define CHECK_TRACE_DOESNT_WARN() \</span> <span class="PreProc"> </span>if<span class="PreProc"> (trace_count(</span><span class="Constant">"warn"</span><span class="PreProc">) > </span><span class="Constant">0</span><span class="PreProc">) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> <span class="PreProc"> ++Num_failures</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): unexpected warnings</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): unexpected warnings</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span><span class="PreProc"> \</span> <span class="PreProc"> DUMP(</span><span class="Constant">"warn"</span><span class="PreProc">)</span><span class="Delimiter">;</span><span class="PreProc"> \</span> <span class="PreProc"> Passed = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> <span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> \</span> @@ -384,7 +385,7 @@ bool trace_doesnt_contain<span class="Delimiter">(</span>string layer<span class bool trace_doesnt_contain<span class="Delimiter">(</span>string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> vector<string> tmp = split<span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">": "</span><span class="Delimiter">);</span> - <span class="Identifier">return</span> trace_doesnt_contain<span class="Delimiter">(</span>tmp[<span class="Constant">0</span>]<span class="Delimiter">,</span> tmp[<span class="Constant">1</span>]<span class="Delimiter">);</span> + <span class="Identifier">return</span> trace_doesnt_contain<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">));</span> <span class="Delimiter">}</span> bool trace_doesnt_contain<span class="Delimiter">(</span>string layer<span class="Delimiter">,</span> int frame<span class="Delimiter">,</span> string line<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -414,7 +415,7 @@ struct lease_trace_frame <span class="Delimiter">{</span> bool check_trace_contents<span class="Delimiter">(</span>string FUNCTION<span class="Delimiter">,</span> string FILE<span class="Delimiter">,</span> int LINE<span class="Delimiter">,</span> string layer<span class="Delimiter">,</span> int frame<span class="Delimiter">,</span> string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// multiple layers, hierarchical layers</span> vector<string> expected_lines = split<span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">"^D"</span><span class="Delimiter">);</span> <span class="Comment">// hack: doesn't handle newlines in embedded in lines</span> index_t curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> - while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines[curr_expected_line]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> ++curr_expected_line<span class="Delimiter">;</span> if <span class="Delimiter">(</span>curr_expected_line == expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> @@ -424,16 +425,16 @@ bool check_trace_contents<span class="Delimiter">(</span>string FUNCTION<span cl <span class="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>first != frame<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>second != expected_lines[curr_expected_line]<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>second != expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> ++curr_expected_line<span class="Delimiter">;</span> - while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines[curr_expected_line]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + while <span class="Delimiter">(</span>curr_expected_line < expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">()</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> ++curr_expected_line<span class="Delimiter">;</span> if <span class="Delimiter">(</span>curr_expected_line == expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> ++Num_failures<span class="Delimiter">;</span> - cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F "</span> << FUNCTION << <span class="Constant">"("</span> << FILE << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << expected_lines[curr_expected_line] << <span class="Constant">"] in trace/"</span> << frame << <span class="Constant">":</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << FUNCTION << <span class="Constant">"("</span> << FILE << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">)</span> << <span class="Constant">"] in trace/"</span> << frame << <span class="Constant">":</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> DUMP<span class="Delimiter">(</span>layer<span class="Delimiter">);</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> @@ -460,7 +461,7 @@ vector<string> split<span class="Delimiter">(</span>string s<span class="D bool any_prefix_match<span class="Delimiter">(</span>const vector<string>& pats<span class="Delimiter">,</span> const string& needle<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>pats<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>*pats[<span class="Constant">0</span>]<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">'/'</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>*pats<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">'/'</span><span class="Delimiter">)</span> <span class="Comment">// prefix match not requested</span> <span class="Identifier">return</span> find<span class="Delimiter">(</span>pats<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> pats<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> needle<span class="Delimiter">)</span> != pats<span class="Delimiter">.</span>end<span class="Delimiter">();</span> <span class="Comment">// first pat ends in a '/'; assume all pats do.</span> diff --git a/html/003trace.test.cc.html b/html/003trace.test.cc.html index ecd40368..7dc51f5d 100644 --- a/html/003trace.test.cc.html +++ b/html/003trace.test.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 003trace.test.cc</title> +<title>~/Desktop/s/mu/003trace.test.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -167,36 +167,36 @@ void test_trace_supports_count2<span class="Delimiter">()</span> <span class="De void test_split_returns_at_least_one_elem<span class="Delimiter">()</span> <span class="Delimiter">{</span> vector<string> result = split<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span> CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">1</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<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> void test_split_returns_entire_input_when_no_delim<span class="Delimiter">()</span> <span class="Delimiter">{</span> vector<string> result = split<span class="Delimiter">(</span><span class="Constant">"abc"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span> CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">1</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> void test_split_works<span class="Delimiter">()</span> <span class="Delimiter">{</span> vector<string> result = split<span class="Delimiter">(</span><span class="Constant">"abc,def"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span> CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">2</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> void test_split_works2<span class="Delimiter">()</span> <span class="Delimiter">{</span> vector<string> result = split<span class="Delimiter">(</span><span class="Constant">"abc,def,ghi"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span> CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">3</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">2</span>]<span class="Delimiter">,</span> <span class="Constant">"ghi"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">),</span> <span class="Constant">"ghi"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> void test_split_handles_multichar_delim<span class="Delimiter">()</span> <span class="Delimiter">{</span> vector<string> result = split<span class="Delimiter">(</span><span class="Constant">"abc,,def,,ghi"</span><span class="Delimiter">,</span> <span class="Constant">",,"</span><span class="Delimiter">);</span> CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">3</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> - CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">2</span>]<span class="Delimiter">,</span> <span class="Constant">"ghi"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">),</span> <span class="Constant">"ghi"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> </pre> </body> diff --git a/html/010vm.cc.html b/html/010vm.cc.html index 08e5ec83..77ed750f 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 010vm.cc</title> +<title>~/Desktop/s/mu/010vm.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -90,14 +90,14 @@ struct property <span class="Delimiter">{</span> <span class="Delimiter">:(before "End Globals")</span> <span class="Comment">// Locations refer to a common 'memory'. Each location can store a number.</span> -map<index_t<span class="Delimiter">,</span> long long int> Memory<span class="Delimiter">;</span> +map<index_t<span class="Delimiter">,</span> double> Memory<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Memory<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">:(after "Types")</span> <span class="Comment">// Mu types encode how the numbers stored in different parts of memory are</span> <span class="Comment">// interpreted. A location tagged as a 'character' type will interpret the</span> -<span class="Comment">// number 97 as the letter 'a', while a different location of type 'integer'</span> +<span class="Comment">// number 97 as the letter 'a', while a different location of type 'number'</span> <span class="Comment">// would not.</span> <span class="Comment">//</span> <span class="Comment">// Unlike most computers today, mu stores types in a single big table, shared</span> @@ -114,9 +114,9 @@ void setup_types<span class="Delimiter">()</span> <span class="Delimiter">{</spa Type_number[<span class="Constant">"literal"</span>] = <span class="Constant">0</span><span class="Delimiter">;</span> Next_type_number = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// Mu Types Initialization</span> - type_number integer = Type_number[<span class="Constant">"integer"</span>] = Next_type_number++<span class="Delimiter">;</span> - Type_number[<span class="Constant">"location"</span>] = Type_number[<span class="Constant">"integer"</span>]<span class="Delimiter">;</span> <span class="Comment">// wildcard type: either a pointer or a scalar</span> - Type[integer]<span class="Delimiter">.</span>name = <span class="Constant">"integer"</span><span class="Delimiter">;</span> + type_number number = Type_number[<span class="Constant">"number"</span>] = Next_type_number++<span class="Delimiter">;</span> + Type_number[<span class="Constant">"location"</span>] = Type_number[<span class="Constant">"number"</span>]<span class="Delimiter">;</span> <span class="Comment">// wildcard type: either a pointer or a scalar</span> + Type[number]<span class="Delimiter">.</span>name = <span class="Constant">"number"</span><span class="Delimiter">;</span> type_number address = Type_number[<span class="Constant">"address"</span>] = Next_type_number++<span class="Delimiter">;</span> Type[address]<span class="Delimiter">.</span>name = <span class="Constant">"address"</span><span class="Delimiter">;</span> type_number boolean = Type_number[<span class="Constant">"boolean"</span>] = Next_type_number++<span class="Delimiter">;</span> @@ -124,7 +124,7 @@ void setup_types<span class="Delimiter">()</span> <span class="Delimiter">{</spa type_number character = Type_number[<span class="Constant">"character"</span>] = Next_type_number++<span class="Delimiter">;</span> Type[character]<span class="Delimiter">.</span>name = <span class="Constant">"character"</span><span class="Delimiter">;</span> <span class="Comment">// Array types are a special modifier to any other type. For example,</span> - <span class="Comment">// array:integer or array:address:boolean.</span> + <span class="Comment">// array:number or array:address:boolean.</span> type_number array = Type_number[<span class="Constant">"array"</span>] = Next_type_number++<span class="Delimiter">;</span> Type[array]<span class="Delimiter">.</span>name = <span class="Constant">"array"</span><span class="Delimiter">;</span> <span class="Comment">// End Mu Types Initialization</span> @@ -214,13 +214,13 @@ reagent::reagent<span class="Delimiter">(</span>string s<span class="Delimiter"> properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> vector<string> ><span class="Delimiter">(</span>name<span class="Delimiter">,</span> values<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Comment">// structures for the first row of properties</span> - name = properties[<span class="Constant">0</span>]<span class="Delimiter">.</span>first<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < properties[<span class="Constant">0</span>]<span class="Delimiter">.</span>second<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[properties[<span class="Constant">0</span>]<span class="Delimiter">.</span>second[i]]<span class="Delimiter">);</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> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span>]<span class="Delimiter">);</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>name == <span class="Constant">"_"</span> && types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - properties[<span class="Constant">0</span>]<span class="Delimiter">.</span>second<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"dummy"</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>push_back<span class="Delimiter">(</span><span class="Constant">"dummy"</span><span class="Delimiter">);</span> <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> <span class="Delimiter">{</span> @@ -233,16 +233,16 @@ string reagent::to_string<span class="Delimiter">()</span> const <span class="De ostringstream out<span class="Delimiter">;</span> out << <span class="Constant">"{name: </span><span class="cSpecial">\"</span><span class="Constant">"</span> << name << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">, value: "</span> << value << <span class="Constant">", type: "</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < types<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - out << types[i]<span class="Delimiter">;</span> + out << types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> if <span class="Delimiter">(</span>i < types<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> out << <span class="Constant">"-"</span><span class="Delimiter">;</span> <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">", properties: ["</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - out << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">"</span> << properties[i]<span class="Delimiter">.</span>first << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">: "</span><span class="Delimiter">;</span> - for <span class="Delimiter">(</span>index_t j = <span class="Constant">0</span><span class="Delimiter">;</span> j < properties[i]<span class="Delimiter">.</span>second<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - out << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">"</span> << properties[i]<span class="Delimiter">.</span>second[j] << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">"</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>j < properties[i]<span class="Delimiter">.</span>second<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</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><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t j = <span class="Constant">0</span><span class="Delimiter">;</span> j < properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++j<span class="Delimiter">)</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>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)</span> << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">"</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>j < properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> out << <span class="Constant">":"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> if <span class="Delimiter">(</span>i < properties<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> else out << <span class="Constant">"]"</span><span class="Delimiter">;</span> @@ -257,13 +257,13 @@ string instruction::to_string<span class="Delimiter">()</span> const <span class ostringstream out<span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < products<span class="Delimiter">.</span>size<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[i]<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> + out << products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>to_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> << operation << <span class="Constant">' '</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<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[i]<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> + out << ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>to_string<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> @@ -282,8 +282,7 @@ string slurp_until<span class="Delimiter">(</span>istream& in<span class="De <span class="Delimiter">}</span> void dump_memory<span class="Delimiter">()</span> <span class="Delimiter">{</span> - map<int<span class="Delimiter">,</span> int> ordered<span class="Delimiter">(</span>Memory<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> Memory<span class="Delimiter">.</span>end<span class="Delimiter">());</span> - for <span class="Delimiter">(</span>map<int<span class="Delimiter">,</span> int>::iterator p = ordered<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != ordered<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>map<index_t<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> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> diff --git a/html/011load.cc.html b/html/011load.cc.html index e73c7198..ccb0db06 100644 --- a/html/011load.cc.html +++ b/html/011load.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 011load.cc</title> +<title>~/Desktop/s/mu/011load.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -37,11 +37,11 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenarios load)</span> <span class="Delimiter">:(scenario first_recipe)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> <span class="Delimiter">:(code)</span> vector<recipe_number> load<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -115,15 +115,15 @@ bool next_instruction<span class="Delimiter">(</span>istream& in<span class= <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>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> -<span class="CommentedCode">//? if (words.size() == 1) cout << words[0] << ' ' << words[0].size() << '\n'; //? 1</span> - if <span class="Delimiter">(</span>words<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span> && words[<span class="Constant">0</span>] == <span class="Constant">"]"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? if (words.size() == 1) cout << words.at(0) << ' ' << words.at(0).size() << '\n'; //? 1</span> + if <span class="Delimiter">(</span>words<span class="Delimiter">.</span>size<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> <span class="CommentedCode">//? cout << "AAA\n"; //? 1</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>words<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span> && !isalnum<span class="Delimiter">(</span>words[<span class="Constant">0</span>][<span class="Constant">0</span>]<span class="Delimiter">)</span> && words[<span class="Constant">0</span>][<span class="Constant">0</span>] != <span class="Constant">'$'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>words<span class="Delimiter">.</span>size<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> - curr<span class="Delimiter">-></span>label = words[<span class="Constant">0</span>]<span class="Delimiter">;</span> + curr<span class="Delimiter">-></span>label = words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"label: "</span> << curr<span class="Delimiter">-></span>label<span class="Delimiter">;</span> <span class="Identifier">return</span> !in<span class="Delimiter">.</span>eof<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -237,9 +237,9 @@ void show_rest_of_stream<span class="Delimiter">(</span>istream& in<span cla vector<recipe_number> recently_added_recipes<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < recently_added_recipes<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "AAA clearing " << Recipe[recently_added_recipes[i]].name << '\n'; //? 2</span> - Recipe_number<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>Recipe[recently_added_recipes[i]]<span class="Delimiter">.</span>name<span class="Delimiter">);</span> - Recipe<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>recently_added_recipes[i]<span class="Delimiter">);</span> +<span class="CommentedCode">//? cout << "AAA clearing " << Recipe[recently_added_recipes.at(i)].name << '\n'; //? 2</span> + Recipe_number<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>Recipe[recently_added_recipes<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span>]<span class="Delimiter">.</span>name<span class="Delimiter">);</span> + Recipe<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>recently_added_recipes<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Comment">// Clear Other State For recently_added_recipes</span> recently_added_recipes<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> @@ -249,51 +249,51 @@ recently_added_recipes<span class="Delimiter">.</span>clear<span class="Delimite recipe f1 [ ] <span class="Comment"># this comment will go through to 'load'</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> <span class="Delimiter">:(scenario parse_comment_amongst_instruction)</span> recipe main [ <span class="Comment"># comment</span> - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> <span class="Delimiter">:(scenario parse_comment_amongst_instruction2)</span> recipe main [ <span class="Comment"># comment</span> - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal <span class="Comment"># comment</span> ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> <span class="Delimiter">:(scenario parse_comment_amongst_instruction3)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal <span class="Comment"># comment</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "number"]}</span> <span class="Delimiter">:(scenario parse_comment_after_instruction)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal <span class="Comment"># comment</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal <span class="Comment"># comment</span> ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> <span class="Delimiter">:(scenario parse_label)</span> recipe main [ @@ -309,46 +309,46 @@ recipe main [ <span class="Delimiter">:(scenario parse_multiple_properties)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal/foo:bar:baz + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal/foo:bar:baz ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal", "foo": "bar":"baz"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> <span class="Delimiter">:(scenario parse_multiple_products)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <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>:literal ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> -<span class="traceContains">+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> +<span class="traceContains">+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "number"]}</span> <span class="Delimiter">:(scenario parse_multiple_ingredients)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:integer + <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>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:number ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: ingredient: {name: "4", value: 0, type: 1, properties: ["4": "integer"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> -<span class="traceContains">+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}</span> +<span class="traceContains">+parse: ingredient: {name: "4", value: 0, type: 1, properties: ["4": "number"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> +<span class="traceContains">+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "number"]}</span> <span class="Delimiter">:(scenario parse_multiple_types)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:address:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:integer + <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>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:number ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}</span> -<span class="traceContains">+parse: ingredient: {name: "4", value: 0, type: 1, properties: ["4": "integer"]}</span> -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}</span> -<span class="traceContains">+parse: product: {name: "2", value: 0, type: 2-1, properties: ["2": "address":"integer"]}</span> +<span class="traceContains">+parse: ingredient: {name: "4", value: 0, type: 1, properties: ["4": "number"]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}</span> +<span class="traceContains">+parse: product: {name: "2", value: 0, type: 2-1, properties: ["2": "address":"number"]}</span> <span class="Delimiter">:(scenario parse_properties)</span> recipe main [ - <span class="Constant">1</span>:integer:address/deref<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number:address/deref<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal ] -<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1-2, properties: ["1": "integer":"address", "deref": ]}</span> +<span class="traceContains">+parse: product: {name: "1", value: 0, type: 1-2, properties: ["1": "number":"address", "deref": ]}</span> </pre> </body> </html> diff --git a/html/012transform.cc.html b/html/012transform.cc.html index b974b8ab..f7d79fe0 100644 --- a/html/012transform.cc.html +++ b/html/012transform.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 012transform.cc</title> +<title>~/Desktop/s/mu/012transform.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -13,7 +13,6 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; } body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } -.cSpecial { color: #008000; } .Identifier { color: #008080; } .Constant { color: #008080; } .Comment { color: #8080ff; } @@ -53,7 +52,7 @@ void transform_all<span class="Delimiter">()</span> <span class="Delimiter">{</s recipe& r = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>transformed_until != t-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Delimiter">(</span>*Transform[t]<span class="Delimiter">)(</span><span class="Comment">/*</span><span class="Comment">recipe_number</span><span class="Comment">*/</span>p<span class="Delimiter">-></span>first<span class="Delimiter">);</span> + <span class="Delimiter">(</span>*Transform<span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span><span class="Comment">/*</span><span class="Comment">recipe_number</span><span class="Comment">*/</span>p<span class="Delimiter">-></span>first<span class="Delimiter">);</span> r<span class="Delimiter">.</span>transformed_until = t<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -66,12 +65,12 @@ void parse_int_reagents<span class="Delimiter">()</span> <span class="Delimiter" recipe& r = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t index = <span class="Constant">0</span><span class="Delimiter">;</span> index < r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - instruction& inst = r<span class="Delimiter">.</span>steps[index]<span class="Delimiter">;</span> + instruction& inst = 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>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - populate_value<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[i]<span class="Delimiter">);</span> + populate_value<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> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - populate_value<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[i]<span class="Delimiter">);</span> + populate_value<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="Delimiter">}</span> <span class="Delimiter">}</span> @@ -79,11 +78,8 @@ void parse_int_reagents<span class="Delimiter">()</span> <span class="Delimiter" void populate_value<span class="Delimiter">(</span>reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - char* end = <span class="Constant">NULL</span><span class="Delimiter">;</span> - int result = strtol<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">any base</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span> - if <span class="Delimiter">(</span>*end != <span class="cSpecial">'\0'</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span class="CommentedCode">//? cout << "setting value\n"; //? 1</span> - r<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>result<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>!is_number<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + r<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>to_number<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">));</span> <span class="Delimiter">}</span> </pre> </body> diff --git a/html/013literal_string.cc.html b/html/013literal_string.cc.html index d2a62afd..f6c692a3 100644 --- a/html/013literal_string.cc.html +++ b/html/013literal_string.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 013literal_string.cc</title> +<title>~/Desktop/s/mu/013literal_string.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -81,9 +81,9 @@ string slurp_quoted<span class="Delimiter">(</span>istream& in<span class="D <span class="Delimiter">}</span> <span class="Delimiter">:(after "reagent::reagent(string s)")</span> -<span class="CommentedCode">//? cout << s[0] << '\n'; //? 1</span> - if <span class="Delimiter">(</span>s[<span class="Constant">0</span>] == <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>s[s<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span>] == <span class="Constant">']'</span><span class="Delimiter">);</span> +<span class="CommentedCode">//? cout << s.at(0) << '\n'; //? 1</span> + if <span class="Delimiter">(</span>s<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>*s<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">']'</span><span class="Delimiter">);</span> <span class="Comment">// delete [] delimiters</span> 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> s<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>s<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>size<span class="Delimiter">());</span> diff --git a/html/020run.cc.html b/html/020run.cc.html index 6b38e2d2..246ca3eb 100644 --- a/html/020run.cc.html +++ b/html/020run.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 020run.cc</title> +<title>~/Desktop/s/mu/020run.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -15,14 +15,14 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } .CommentedCode { color: #6c6c6c; } -.SalientComment { color: #00ffff; } +.traceAbsent { color: #c00000; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .Identifier { color: #008080; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } -.traceAbsent { color: #c00000; } --> </style> @@ -47,7 +47,7 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario copy_literal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 23</span> @@ -55,14 +55,23 @@ recipe main [ <span class="Delimiter">:(scenario copy)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] <span class="traceContains">+run: instruction main/1</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 23</span> <span class="traceContains">+mem: storing 23 in location 2</span> +<span class="Delimiter">:(scenario copy_multiple)</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>:literal<span class="Delimiter">,</span> <span class="Constant">24</span>:literal +] +<span class="traceContains">+run: ingredient 0 is 23</span> +<span class="traceContains">+run: ingredient 1 is 24</span> +<span class="traceContains">+mem: storing 23 in location 1</span> +<span class="traceContains">+mem: storing 24 in location 2</span> + <span class="Delimiter">:(before "End Types")</span> <span class="Comment">// Book-keeping while running a recipe.</span> <span class="Comment">//: Later layers will change this.</span> @@ -91,13 +100,23 @@ void run_current_routine<span class="Delimiter">()</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><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction "</span> << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">'/'</span> << current_step_index<span class="Delimiter">();</span> trace<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> -<span class="CommentedCode">//? cout << "operation " << current_instruction().operation << '\n'; //? 3</span> + assert<span class="Delimiter">(</span>Memory[<span class="Constant">0</span>] == <span class="Constant">0</span><span class="Delimiter">);</span> + <span class="Comment">// Read all ingredients from memory.</span> + <span class="Comment">// Each ingredient loads a vector of values rather than a single value; mu</span> + <span class="Comment">// permits operating on reagents spanning multiple locations.</span> + vector<vector<double> > ingredients<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient "</span> << i << <span class="Constant">" is "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<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="Delimiter">}</span> + <span class="Comment">// Instructions below will write to 'products' or to 'instruction_counter'.</span> + vector<vector<double> > products<span class="Delimiter">;</span> + index_t instruction_counter = current_step_index<span class="Delimiter">();</span> +<span class="CommentedCode">//? cout << "AAA: " << current_instruction().to_string() << '\n'; //? 1</span> switch <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// Primitive Recipe Implementations</span> case COPY: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> data = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> data<span class="Delimiter">);</span> + copy<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> ingredients<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>products<span class="Delimiter">,</span> products<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// End Primitive Recipe Implementations</span> @@ -105,8 +124,19 @@ void run_current_routine<span class="Delimiter">()</span> cout << <span class="Constant">"not a primitive op: "</span> << current_instruction<span class="Delimiter">().</span>operation << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - ++current_step_index<span class="Delimiter">();</span> +<span class="CommentedCode">//? cout << "BBB: " << current_instruction().to_string() << '\n'; //? 1</span> + if <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>size<span class="Delimiter">())</span> + raise << <span class="Constant">"failed to write to all products! "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">();</span> +<span class="CommentedCode">//? cout << "CCC: " << current_instruction().to_string() << '\n'; //? 1</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product "</span> << i << <span class="Constant">" is "</span> << current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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="CommentedCode">//? cout << "DDD: " << current_instruction().to_string() << '\n'; //? 1</span> + current_step_index<span class="Delimiter">()</span> = instruction_counter+<span class="Constant">1</span><span class="Delimiter">;</span> +<span class="CommentedCode">//? cerr << "screen: " << Memory[SCREEN] << '\n'; //? 1</span> <span class="Delimiter">}</span> + stop_running_current_routine:<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: Some helpers.</span> @@ -122,7 +152,7 @@ inline const string& current_recipe_name<span class="Delimiter">()</span> <s <span class="Delimiter">}</span> inline const instruction& current_instruction<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-></span>running_recipe]<span class="Delimiter">.</span>steps[Current_routine<span class="Delimiter">-></span>running_step_index]<span class="Delimiter">;</span> + <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-></span>running_recipe]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>running_step_index<span class="Delimiter">);</span> <span class="Delimiter">}</span> inline bool routine::completed<span class="Delimiter">()</span> const <span class="Delimiter">{</span> @@ -130,6 +160,7 @@ inline bool routine::completed<span class="Delimiter">()</span> const <span clas <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Commandline Parsing")</span> +<span class="Comment">// Loading Commandline Files</span> if <span class="Delimiter">(</span>argc > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>int i = <span class="Constant">1</span><span class="Delimiter">;</span> i < argc<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> load_permanently<span class="Delimiter">(</span>argv[i]<span class="Delimiter">);</span> @@ -139,7 +170,8 @@ if <span class="Delimiter">(</span>argc > <span class="Constant">1</span><spa <span class="Delimiter">:(before "End Main")</span> if <span class="Delimiter">(</span>!Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span> setup<span class="Delimiter">();</span> - Trace_stream = new trace_stream<span class="Delimiter">;</span> +<span class="CommentedCode">//? Trace_file = "interactive"; //? 1</span> + START_TRACING_UNTIL_END_OF_SCOPE<span class="Delimiter">;</span> <span class="CommentedCode">//? Trace_stream->dump_layer = "all"; //? 2</span> transform_all<span class="Delimiter">();</span> recipe_number r = Recipe_number[string<span class="Delimiter">(</span><span class="Constant">"main"</span><span class="Delimiter">)</span>]<span class="Delimiter">;</span> @@ -152,6 +184,9 @@ if <span class="Delimiter">(</span>!Run_tests<span class="Delimiter">)</span> <s <span class="Delimiter">:(code)</span> void load_permanently<span class="Delimiter">(</span>string filename<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> +<span class="CommentedCode">//? cerr << "AAA: " << filename << ' ' << static_cast<bool>(fin) << ' ' << fin.fail() << '\n'; //? 1</span> +<span class="CommentedCode">//? return; //? 1</span> if <span class="Delimiter">(</span>!fin<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"no such file "</span> << filename << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Identifier">return</span><span class="Delimiter">;</span> @@ -162,7 +197,7 @@ void load_permanently<span class="Delimiter">(</span>string filename<span class= fin<span class="Delimiter">.</span>close<span class="Delimiter">();</span> <span class="Comment">// freeze everything so it doesn't get cleared by tests</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="Comment">// End load_permanently.</span> <span class="Delimiter">}</span> <span class="SalientComment">//:: On startup, load everything in core.mu</span> @@ -180,9 +215,9 @@ void run<span class="Delimiter">(</span>string form<span class="Delimiter">)</sp <span class="SalientComment">//:: Reading from memory, writing to memory.</span> -vector<long long int> read_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "read_memory: " << x.to_string() << '\n'; //? 1</span> - vector<long long int> result<span class="Delimiter">;</span> +vector<double> read_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cout << "read_memory: " << x.to_string() << '\n'; //? 2</span> + vector<double> result<span class="Delimiter">;</span> if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> @@ -190,21 +225,21 @@ vector<long long int> read_memory<span class="Delimiter">(</span>reagent x index_t base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> size_t size = size_of<span class="Delimiter">(</span>x<span class="Delimiter">);</span> for <span class="Delimiter">(</span>index_t offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset < size<span class="Delimiter">;</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span> - int val = Memory[base+offset]<span class="Delimiter">;</span> + double val = Memory[base+offset]<span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"location "</span> << base+offset << <span class="Constant">" is "</span> << val<span class="Delimiter">;</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>val<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -void write_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> vector<long long int> data<span class="Delimiter">)</span> <span class="Delimiter">{</span> +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>is_dummy<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> index_t base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> if <span class="Delimiter">(</span>size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> != data<span class="Delimiter">.</span>size<span class="Delimiter">())</span> raise << <span class="Constant">"size mismatch in storing to "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset < data<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << data[offset] << <span class="Constant">" in location "</span> << base+offset<span class="Delimiter">;</span> - Memory[base+offset] = data[offset]<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << data<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << <span class="Constant">" in location "</span> << base+offset<span class="Delimiter">;</span> + Memory[base+offset] = data<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -222,14 +257,14 @@ bool is_dummy<span class="Delimiter">(</span>const reagent& x<span class="De <span class="Delimiter">}</span> bool isa_literal<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span> && r<span class="Delimiter">.</span>types[<span class="Constant">0</span>] == <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span> && r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<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> <span class="Delimiter">:(scenario run_label)</span> recipe main [ +foo - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] <span class="traceContains">+run: instruction main/1</span> <span class="traceContains">+run: instruction main/2</span> diff --git a/html/021arithmetic.cc.html b/html/021arithmetic.cc.html index 98d62402..32705c17 100644 --- a/html/021arithmetic.cc.html +++ b/html/021arithmetic.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 021arithmetic.cc</title> +<title>~/Desktop/s/mu/021arithmetic.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -38,224 +38,237 @@ ADD<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"add"</span>] = ADD<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case ADD: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] + arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + double result = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + result += ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario add_literal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>add <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 23</span> <span class="traceContains">+run: ingredient 1 is 34</span> -<span class="traceContains">+run: product 0 is 57</span> +<span class="traceContains">+run: product 0 is 1</span> <span class="traceContains">+mem: storing 57 in location 1</span> <span class="Delimiter">:(scenario add)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>add <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 23</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 34</span> -<span class="traceContains">+run: product 0 is 57</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 57 in location 3</span> +<span class="Delimiter">:(scenario add_multiple)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">3</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:literal<span class="Delimiter">,</span> <span class="Constant">5</span>:literal +] +<span class="traceContains">+mem: storing 12 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> SUBTRACT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"subtract"</span>] = SUBTRACT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case SUBTRACT: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] - arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + double result = 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> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">1</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + result -= ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario subtract_literal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>subtract <span class="Constant">5</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>subtract <span class="Constant">5</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 5</span> <span class="traceContains">+run: ingredient 1 is 2</span> -<span class="traceContains">+run: product 0 is 3</span> +<span class="traceContains">+run: product 0 is 1</span> <span class="traceContains">+mem: storing 3 in location 1</span> <span class="Delimiter">:(scenario subtract)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>subtract <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>subtract <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 23</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 34</span> -<span class="traceContains">+run: product 0 is -11</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing -11 in location 3</span> +<span class="Delimiter">:(scenario subtract_multiple)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>subtract <span class="Constant">6</span>:literal<span class="Delimiter">,</span> <span class="Constant">3</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> MULTIPLY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"multiply"</span>] = MULTIPLY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MULTIPLY: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << arg1[<span class="Constant">0</span>]<span class="Delimiter">;</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] * arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + double result = <span class="Constant">1</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + result *= ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario multiply_literal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>multiply <span class="Constant">2</span>:literal<span class="Delimiter">,</span> <span class="Constant">3</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>multiply <span class="Constant">2</span>:literal<span class="Delimiter">,</span> <span class="Constant">3</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 2</span> <span class="traceContains">+run: ingredient 1 is 3</span> -<span class="traceContains">+run: product 0 is 6</span> +<span class="traceContains">+run: product 0 is 1</span> <span class="traceContains">+mem: storing 6 in location 1</span> <span class="Delimiter">:(scenario multiply)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">4</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">6</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>multiply <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">4</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">6</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>multiply <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 4</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 6</span> -<span class="traceContains">+run: product 0 is 24</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 24 in location 3</span> +<span class="Delimiter">:(scenario multiply_multiple)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>multiply <span class="Constant">2</span>:literal<span class="Delimiter">,</span> <span class="Constant">3</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:literal +] +<span class="traceContains">+mem: storing 24 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> DIVIDE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"divide"</span>] = DIVIDE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case DIVIDE: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << arg1[<span class="Constant">0</span>]<span class="Delimiter">;</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] / arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + double result = 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> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">1</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + result /= ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario divide_literal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>divide <span class="Constant">8</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>divide <span class="Constant">8</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 8</span> <span class="traceContains">+run: ingredient 1 is 2</span> -<span class="traceContains">+run: product 0 is 4</span> +<span class="traceContains">+run: product 0 is 1</span> <span class="traceContains">+mem: storing 4 in location 1</span> <span class="Delimiter">:(scenario divide)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">27</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>divide <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">27</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>divide <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 27</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 3</span> -<span class="traceContains">+run: product 0 is 9</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 9 in location 3</span> +<span class="Delimiter">:(scenario divide_multiple)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>divide <span class="Constant">12</span>:literal<span class="Delimiter">,</span> <span class="Constant">3</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal +] +<span class="traceContains">+mem: storing 2 in location 1</span> + +<span class="Comment">//: Integer division</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> DIVIDE_WITH_REMAINDER<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"divide-with-remainder"</span>] = DIVIDE_WITH_REMAINDER<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case DIVIDE_WITH_REMAINDER: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result0<span class="Delimiter">;</span> - result0<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] / arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result0[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result0<span class="Delimiter">);</span> - vector<long long int> result1<span class="Delimiter">;</span> - result1<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] % arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 1 is "</span> << result1[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> result1<span class="Delimiter">);</span> + long long int quotient = 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> / 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> + long long int remainder = 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> % 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">2</span><span class="Delimiter">);</span> + <span class="Comment">// very large integers will lose precision</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>quotient<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>remainder<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario divide_with_remainder_literal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer<span class="Special"> <- </span>divide-with-remainder <span class="Constant">9</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>divide-with-remainder <span class="Constant">9</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 9</span> <span class="traceContains">+run: ingredient 1 is 2</span> -<span class="traceContains">+run: product 0 is 4</span> +<span class="traceContains">+run: product 0 is 1</span> <span class="traceContains">+mem: storing 4 in location 1</span> -<span class="traceContains">+run: product 1 is 1</span> +<span class="traceContains">+run: product 1 is 2</span> <span class="traceContains">+mem: storing 1 in location 2</span> <span class="Delimiter">:(scenario divide_with_remainder)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">27</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">11</span>:literal - <span class="Constant">3</span>:integer<span class="Delimiter">,</span> <span class="Constant">4</span>:integer<span class="Special"> <- </span>divide-with-remainder <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">27</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">11</span>:literal + <span class="Constant">3</span>:number<span class="Delimiter">,</span> <span class="Constant">4</span>:number<span class="Special"> <- </span>divide-with-remainder <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 27</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 11</span> -<span class="traceContains">+run: product 0 is 2</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 2 in location 3</span> -<span class="traceContains">+run: product 1 is 5</span> +<span class="traceContains">+run: product 1 is 4</span> <span class="traceContains">+mem: storing 5 in location 4</span> + +<span class="Delimiter">:(scenario divide_with_decimal_point)</span> +recipe main [ + <span class="Comment"># todo: literal floats?</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>divide <span class="Constant">5</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal +] +<span class="traceContains">+mem: storing 2.5 in location 1</span> </pre> </body> </html> diff --git a/html/022boolean.cc.html b/html/022boolean.cc.html index 25955e5a..27947f42 100644 --- a/html/022boolean.cc.html +++ b/html/022boolean.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 022boolean.cc</title> +<title>~/Desktop/s/mu/022boolean.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -38,92 +38,128 @@ AND<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"and"</span>] = AND<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case AND: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] && arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + result = result && ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario and)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>and <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>and <span class="Constant">1</span>:boolean<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 1</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 0</span> -<span class="traceContains">+run: product 0 is 0</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 0 in location 3</span> +<span class="Delimiter">:(scenario and2)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>and <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario and_multiple)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>and <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">0</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> + +<span class="Delimiter">:(scenario and_multiple2)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>and <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> OR<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"or"</span>] = OR<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case OR: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] || arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + bool result = <span class="Constant">false</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + result = result || ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario or)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>or <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>or <span class="Constant">1</span>:boolean<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 1</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 0</span> -<span class="traceContains">+run: product 0 is 1</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 1 in location 3</span> +<span class="Delimiter">:(scenario or2)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>or <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">0</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> + +<span class="Delimiter">:(scenario or_multiple)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>and <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">0</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> + +<span class="Delimiter">:(scenario or_multiple2)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>or <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> NOT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"not"</span>] = NOT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case NOT: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>!arg0[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">());</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>!ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<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="Delimiter">:(scenario not)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>not <span class="Constant">1</span>:integer + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>not <span class="Constant">1</span>:boolean ] <span class="traceContains">+run: instruction main/1</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 1</span> -<span class="traceContains">+run: product 0 is 0</span> +<span class="traceContains">+run: product 0 is 2</span> <span class="traceContains">+mem: storing 0 in location 2</span> + +<span class="Delimiter">:(scenario not_multiple)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean<span class="Delimiter">,</span> <span class="Constant">3</span>:boolean<span class="Special"> <- </span>not <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> +<span class="traceContains">+mem: storing 1 in location 2</span> +<span class="traceContains">+mem: storing 0 in location 3</span> </pre> </body> </html> diff --git a/html/023jump.cc.html b/html/023jump.cc.html index 199eab5b..b572fa90 100644 --- a/html/023jump.cc.html +++ b/html/023jump.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 023jump.cc</title> +<title>~/Desktop/s/mu/023jump.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -13,13 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; } body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } +.traceAbsent { color: #c00000; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .Identifier { color: #008080; } .traceContains { color: #008000; } -.traceAbsent { color: #c00000; } --> </style> @@ -39,16 +39,18 @@ JUMP<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"jump"</span>] = JUMP<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case JUMP: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - current_step_index<span class="Delimiter">()</span> += current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << current_step_index<span class="Delimiter">()</span>+<span class="Constant">1</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>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>initialized<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + instruction_counter += 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> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << instruction_counter+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario jump_can_skip_instructions)</span> recipe main [ jump <span class="Constant">1</span>:offset - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 1</span> @@ -72,23 +74,23 @@ JUMP_IF<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"jump-if"</span>] = JUMP_IF<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case JUMP_IF: <span class="Delimiter">{</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << arg0[<span class="Constant">0</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!arg0[<span class="Constant">0</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>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>initialized<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">2</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</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> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if fell through"</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - current_step_index<span class="Delimiter">()</span> += current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << current_step_index<span class="Delimiter">()</span>+<span class="Constant">1</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + instruction_counter += 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> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << instruction_counter+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario jump_if)</span> recipe main [ - jump-if <span class="Constant">999</span>:literal <span class="Constant">1</span>:offset - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + jump-if <span class="Constant">999</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 1 is 1</span> @@ -98,8 +100,8 @@ recipe main [ <span class="Delimiter">:(scenario jump_if_fallthrough)</span> recipe main [ - jump-if <span class="Constant">0</span>:literal <span class="Constant">1</span>:offset - <span class="Constant">123</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + jump-if <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">123</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: jump-if fell through</span> @@ -112,23 +114,23 @@ JUMP_UNLESS<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"jump-unless"</span>] = JUMP_UNLESS<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case JUMP_UNLESS: <span class="Delimiter">{</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << arg0[<span class="Constant">0</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>arg0[<span class="Constant">0</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>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>initialized<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">2</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</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> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless fell through"</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - current_step_index<span class="Delimiter">()</span> += current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << current_step_index<span class="Delimiter">()</span>+<span class="Constant">1</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + instruction_counter += 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> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << instruction_counter+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario jump_unless)</span> recipe main [ - jump-unless <span class="Constant">0</span>:literal <span class="Constant">1</span>:offset - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + jump-unless <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 1 is 1</span> @@ -138,8 +140,8 @@ recipe main [ <span class="Delimiter">:(scenario jump_unless_fallthrough)</span> recipe main [ - jump-unless <span class="Constant">999</span>:literal <span class="Constant">1</span>:offset - <span class="Constant">123</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + jump-unless <span class="Constant">999</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">123</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 999</span> diff --git a/html/024compare.cc.html b/html/024compare.cc.html index bb633384..56449547 100644 --- a/html/024compare.cc.html +++ b/html/024compare.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 024compare.cc</title> +<title>~/Desktop/s/mu/024compare.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -38,260 +38,326 @@ EQUAL<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"equal"</span>] = EQUAL<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case EQUAL: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>equal<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> arg0<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> arg1<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + vector<double>& exemplar = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">1</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!equal<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>begin<span class="Delimiter">(),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>end<span class="Delimiter">(),</span> exemplar<span class="Delimiter">.</span>begin<span class="Delimiter">()))</span> <span class="Delimiter">{</span> + result = <span class="Constant">false</span><span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario equal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>equal <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 33</span> -<span class="traceContains">+run: product 0 is 0</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 0 in location 3</span> <span class="Delimiter">:(scenario equal2)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>equal <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 34</span> -<span class="traceContains">+run: product 0 is 1</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 1 in location 3</span> +<span class="Delimiter">:(scenario equal_multiple)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>equal <span class="Constant">34</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario equal_multiple2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>equal <span class="Constant">34</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> GREATER_THAN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"greater-than"</span>] = GREATER_THAN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case GREATER_THAN: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] > arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + <span class="Delimiter">}</span> + for <span class="Delimiter">(</span>index_t i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <= ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> + result = <span class="Constant">false</span><span class="Delimiter">;</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario greater_than)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>greater-than <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-than <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 33</span> -<span class="traceContains">+run: product 0 is 1</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario greater_than2)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>greater-than <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-than <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 34</span> -<span class="traceContains">+run: product 0 is 0</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 0 in location 3</span> +<span class="Delimiter">:(scenario greater_than_multiple)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>greater-than <span class="Constant">36</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario greater_than_multiple2)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>greater-than <span class="Constant">36</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> LESSER_THAN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"lesser-than"</span>] = LESSER_THAN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case LESSER_THAN: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] < arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + <span class="Delimiter">}</span> + for <span class="Delimiter">(</span>index_t i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> + result = <span class="Constant">false</span><span class="Delimiter">;</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario lesser_than)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">32</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>lesser-than <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">32</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>lesser-than <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 32</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 33</span> -<span class="traceContains">+run: product 0 is 1</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario lesser_than2)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>lesser-than <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>lesser-than <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 33</span> -<span class="traceContains">+run: product 0 is 0</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 0 in location 3</span> +<span class="Delimiter">:(scenario lesser_than_multiple)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>lesser-than <span class="Constant">34</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal<span class="Delimiter">,</span> <span class="Constant">36</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario lesser_than_multiple2)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>lesser-than <span class="Constant">34</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> GREATER_OR_EQUAL<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"greater-or-equal"</span>] = GREATER_OR_EQUAL<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case GREATER_OR_EQUAL: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] >= arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + <span class="Delimiter">}</span> + for <span class="Delimiter">(</span>index_t i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> + result = <span class="Constant">false</span><span class="Delimiter">;</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario greater_or_equal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>greater-or-equal <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 33</span> -<span class="traceContains">+run: product 0 is 1</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario greater_or_equal2)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>greater-or-equal <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 34</span> -<span class="traceContains">+run: product 0 is 1</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario greater_or_equal3)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>greater-or-equal <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 35</span> -<span class="traceContains">+run: product 0 is 0</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 0 in location 3</span> +<span class="Delimiter">:(scenario greater_or_equal_multiple)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">36</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario greater_or_equal_multiple2)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">36</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal<span class="Delimiter">,</span> <span class="Constant">36</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> LESSER_OR_EQUAL<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"lesser-or-equal"</span>] = LESSER_OR_EQUAL<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case LESSER_OR_EQUAL: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg1 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg1<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] <= arg1[<span class="Constant">0</span>]<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + <span class="Delimiter">}</span> + for <span class="Delimiter">(</span>index_t i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> > ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> + result = <span class="Constant">false</span><span class="Delimiter">;</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>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario lesser_or_equal)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">32</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>lesser-or-equal <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">32</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>lesser-or-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 32</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 33</span> -<span class="traceContains">+run: product 0 is 1</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario lesser_or_equal2)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>lesser-or-equal <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>lesser-or-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 33</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 33</span> -<span class="traceContains">+run: product 0 is 1</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario lesser_or_equal3)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>lesser-or-equal <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>lesser-or-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 34</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 33</span> -<span class="traceContains">+run: product 0 is 0</span> +<span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 0 in location 3</span> + +<span class="Delimiter">:(scenario lesser_or_equal_multiple)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>lesser-or-equal <span class="Constant">34</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal +] +<span class="traceContains">+mem: storing 1 in location 1</span> + +<span class="Delimiter">:(scenario lesser_or_equal_multiple2)</span> +recipe main [ + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>lesser-or-equal <span class="Constant">34</span>:literal<span class="Delimiter">,</span> <span class="Constant">35</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 1</span> </pre> </body> </html> diff --git a/html/025trace.cc.html b/html/025trace.cc.html index 7a4c5cd5..4a802550 100644 --- a/html/025trace.cc.html +++ b/html/025trace.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 025trace.cc</title> +<title>~/Desktop/s/mu/025trace.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -43,13 +43,23 @@ TRACE<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"trace"</span>] = TRACE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case TRACE: <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">));</span> - string label = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> - string message = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + string label = 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>name<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + string message = 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>name<span class="Delimiter">;</span> trace<span class="Delimiter">(</span>label<span class="Delimiter">)</span> << message<span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +HIDE_WARNINGS<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"hide-warnings"</span>] = HIDE_WARNINGS<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case HIDE_WARNINGS: <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> </pre> </body> </html> diff --git a/html/026assert.cc.html b/html/026assert.cc.html index 767382ac..11e9b737 100644 --- a/html/026assert.cc.html +++ b/html/026assert.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 026assert.cc</title> +<title>~/Desktop/s/mu/026assert.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -15,6 +15,7 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } .Constant { color: #008080; } +.Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .Identifier { color: #008080; } @@ -43,11 +44,12 @@ ASSERT<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"assert"</span>] = ASSERT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case ASSERT: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - vector<long long int> arg0 = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>arg0<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - if <span class="Delimiter">(</span>arg0[<span class="Constant">0</span>] == <span class="Constant">0</span><span class="Delimiter">)</span> - raise << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">2</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</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> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + raise << 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>name << <span class="cSpecial">'\n'</span> << die<span class="Delimiter">();</span> + <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> diff --git a/html/027debug.cc.html b/html/027debug.cc.html index b676e8dc..802ddd67 100644 --- a/html/027debug.cc.html +++ b/html/027debug.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 027debug.cc</title> +<title>~/Desktop/s/mu/027debug.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -37,16 +37,18 @@ _PRINT<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"$print"</span>] = _PRINT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case _PRINT: <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"$print: "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - cout << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - vector<long long int> result<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">));</span> - for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < result<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"$print: "</span> << result[i]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> cout << <span class="Constant">" "</span><span class="Delimiter">;</span> - cout << result[i]<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>isa_literal<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="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"$print: "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + cout << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>index_t j = <span class="Constant">0</span><span class="Delimiter">;</span> j < ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>size<span class="Delimiter">();</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"$print: "</span> << ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> cout << <span class="Constant">" "</span><span class="Delimiter">;</span> + cout << ingredients<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="Delimiter">}</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -57,7 +59,10 @@ _START_TRACING<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"$start-tracing"</span>] = _START_TRACING<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case _START_TRACING: <span class="Delimiter">{</span> - Trace_stream<span class="Delimiter">-></span>dump_layer = <span class="Constant">"all"</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + Trace_stream<span class="Delimiter">-></span>dump_layer = <span class="Constant">"all"</span><span class="Delimiter">;</span> + else + Trace_stream<span class="Delimiter">-></span>dump_layer = 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>name<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << Trace_stream << ": " << Trace_stream->dump_layer << '\n'; //? 1</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -81,6 +86,26 @@ case _EXIT: <span class="Delimiter">{</span> exit<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> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +_DUMP_TRACE<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"$dump-trace"</span>] = _DUMP_TRACE<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case _DUMP_TRACE: <span class="Delimiter">{</span> + DUMP<span class="Delimiter">(</span><span class="Constant">""</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 Declarations")</span> +_DUMP_MEMORY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"$dump-memory"</span>] = _DUMP_MEMORY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case _DUMP_MEMORY: <span class="Delimiter">{</span> + dump_memory<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> </pre> </body> </html> diff --git a/html/030container.cc.html b/html/030container.cc.html index 72397676..518e8f99 100644 --- a/html/030container.cc.html +++ b/html/030container.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 030container.cc</title> +<title>~/Desktop/s/mu/030container.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -13,12 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; } body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } -.SalientComment { color: #00ffff; } +.cSpecial { color: #008000; } +.CommentedCode { color: #6c6c6c; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .Identifier { color: #008080; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } --> </style> @@ -34,22 +36,23 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment">//: Containers contain a fixed number of elements of different types.</span> <span class="Delimiter">:(before "End Mu Types Initialization")</span> -<span class="Comment">//: We'll use this container as a running example, with two integer elements.</span> +<span class="Comment">//: We'll use this container as a running example, with two number elements.</span> type_number point = Type_number[<span class="Constant">"point"</span>] = Next_type_number++<span class="Delimiter">;</span> Type[point]<span class="Delimiter">.</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> Type[point]<span class="Delimiter">.</span>kind = container<span class="Delimiter">;</span> Type[point]<span class="Delimiter">.</span>name = <span class="Constant">"point"</span><span class="Delimiter">;</span> vector<type_number> i<span class="Delimiter">;</span> -i<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>integer<span class="Delimiter">);</span> +i<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>number<span class="Delimiter">);</span> Type[point]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>i<span class="Delimiter">);</span> Type[point]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>i<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> + <span class="Delimiter">:(scenario copy_multiple_locations)</span> -<span class="Comment"># Containers can be copied around with a single instruction just like integers,</span> -<span class="Comment"># no matter how large they are.</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal <span class="Constant">3</span>:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:point ] <span class="traceContains">+run: ingredient 0 is 1</span> @@ -61,33 +64,60 @@ recipe main [ <span class="Delimiter">:(before "End Mu Types Initialization")</span> <span class="Comment">// A more complex container, containing another container as one of its</span> <span class="Comment">// elements.</span> -type_number point_integer = Type_number[<span class="Constant">"point-integer"</span>] = Next_type_number++<span class="Delimiter">;</span> -Type[point_integer]<span class="Delimiter">.</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> -Type[point_integer]<span class="Delimiter">.</span>kind = container<span class="Delimiter">;</span> -Type[point_integer]<span class="Delimiter">.</span>name = <span class="Constant">"point-integer"</span><span class="Delimiter">;</span> +type_number point_number = Type_number[<span class="Constant">"point-number"</span>] = Next_type_number++<span class="Delimiter">;</span> +Type[point_number]<span class="Delimiter">.</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> +Type[point_number]<span class="Delimiter">.</span>kind = container<span class="Delimiter">;</span> +Type[point_number]<span class="Delimiter">.</span>name = <span class="Constant">"point-number"</span><span class="Delimiter">;</span> vector<type_number> p2<span class="Delimiter">;</span> p2<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>point<span class="Delimiter">);</span> -Type[point_integer]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>p2<span class="Delimiter">);</span> +Type[point_number]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>p2<span class="Delimiter">);</span> vector<type_number> i2<span class="Delimiter">;</span> -i2<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>integer<span class="Delimiter">);</span> -Type[point_integer]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>i2<span class="Delimiter">);</span> +i2<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>number<span class="Delimiter">);</span> +Type[point_number]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>i2<span class="Delimiter">);</span> <span class="Delimiter">:(scenario copy_handles_nested_container_elements)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal - <span class="Constant">15</span>:point-integer<span class="Special"> <- </span>copy <span class="Constant">12</span>:point-integer + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">15</span>:point-number<span class="Special"> <- </span>copy <span class="Constant">12</span>:point-number ] <span class="traceContains">+mem: storing 36 in location 17</span> +<span class="Comment">//: Containers can be checked for equality with a single instruction just like</span> +<span class="Comment">//: numbers, no matter how large they are.</span> + +<span class="Delimiter">:(scenario compare_multiple_locations)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal <span class="Comment"># first</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal <span class="Comment"># second</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">7</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:point-number<span class="Delimiter">,</span> <span class="Constant">4</span>:point-number +] +<span class="traceContains">+mem: storing 1 in location 7</span> + +<span class="Delimiter">:(scenario compare_multiple_locations2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal <span class="Comment"># first</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal <span class="Comment"># second</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">37</span>:literal <span class="Comment"># different</span> + <span class="Constant">7</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:point-number<span class="Delimiter">,</span> <span class="Constant">4</span>:point-number +] +<span class="traceContains">+mem: storing 0 in location 7</span> + <span class="Delimiter">:(before "End size_of(types) Cases")</span> -type_info t = Type[types[<span class="Constant">0</span>]]<span class="Delimiter">;</span> +type_info t = Type[types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>]<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> size_t result = <span class="Constant">0</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - result += size_of<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements[i]<span class="Delimiter">);</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> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -95,9 +125,9 @@ if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == cont <span class="SalientComment">//:: To access elements of a container, use 'get'</span> <span class="Delimiter">:(scenario get)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">15</span>:integer<span class="Special"> <- </span>get <span class="Constant">12</span>:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">15</span>:number<span class="Special"> <- </span>get <span class="Constant">12</span>:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 12</span> @@ -105,7 +135,7 @@ recipe main [ <span class="traceContains">+run: address to copy is 13</span> <span class="traceContains">+run: its type is 1</span> <span class="traceContains">+mem: location 13 is 35</span> -<span class="traceContains">+run: product 0 is 35</span> +<span class="traceContains">+run: product 0 is 15</span> <span class="traceContains">+mem: storing 35 in location 15</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> @@ -114,29 +144,26 @@ GET<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"get"</span>] = GET<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case GET: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - reagent base = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">;</span> + reagent base = 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> index_t base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - type_number base_type = base<span class="Delimiter">.</span>types[<span class="Constant">0</span>]<span class="Delimiter">;</span> + type_number base_type = base<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind == container<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> - index_t offset = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + index_t offset = 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> index_t src = base_address<span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t 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> - src += size_of<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements[i]<span class="Delimiter">);</span> + src += size_of<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements<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">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind == container<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > offset<span class="Delimiter">);</span> - type_number src_type = Type[base_type]<span class="Delimiter">.</span>elements[offset][<span class="Constant">0</span>]<span class="Delimiter">;</span> + type_number src_type = Type[base_type]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>offset<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << src_type<span class="Delimiter">;</span> reagent tmp<span class="Delimiter">;</span> tmp<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>src<span class="Delimiter">);</span> tmp<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>src_type<span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>tmp<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<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> @@ -147,10 +174,10 @@ Type_number[<span class="Constant">"offset"</span>] = <span class="Con <span class="Delimiter">:(scenario get_handles_nested_container_elements)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal - <span class="Constant">15</span>:integer<span class="Special"> <- </span>get <span class="Constant">12</span>:point-integer<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">15</span>:number<span class="Special"> <- </span>get <span class="Constant">12</span>:point-number<span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 12</span> @@ -158,16 +185,16 @@ recipe main [ <span class="traceContains">+run: address to copy is 14</span> <span class="traceContains">+run: its type is 1</span> <span class="traceContains">+mem: location 14 is 36</span> -<span class="traceContains">+run: product 0 is 36</span> +<span class="traceContains">+run: product 0 is 15</span> <span class="traceContains">+mem: storing 36 in location 15</span> <span class="SalientComment">//:: To write to elements of containers, you need their address.</span> <span class="Delimiter">:(scenario get_address)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">15</span>:address:integer<span class="Special"> <- </span>get-address <span class="Constant">12</span>:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">15</span>:address:number<span class="Special"> <- </span>get-address <span class="Constant">12</span>:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 12</span> @@ -181,25 +208,109 @@ GET_ADDRESS<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"get-address"</span>] = GET_ADDRESS<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case GET_ADDRESS: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - reagent base = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">;</span> + reagent base = 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> index_t base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - type_number base_type = base<span class="Delimiter">.</span>types[<span class="Constant">0</span>]<span class="Delimiter">;</span> + type_number base_type = base<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind == container<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> - index_t offset = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - index_t src = base_address<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + index_t offset = 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> + index_t result = base_address<span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t 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> - src += size_of<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements[i]<span class="Delimiter">);</span> + result += size_of<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements<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">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src<span class="Delimiter">;</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>src<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << result<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="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + +<span class="SalientComment">//:: Allow containers to be defined in mu code.</span> + +<span class="Delimiter">:(scenarios load)</span> +<span class="Delimiter">:(scenario container)</span> +container foo [ + x:number + y:number +] +<span class="traceContains">+parse: reading 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="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> + insert_container<span class="Delimiter">(</span>command<span class="Delimiter">,</span> container<span class="Delimiter">,</span> in<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(code)</span> +void insert_container<span class="Delimiter">(</span>const string& command<span class="Delimiter">,</span> kind_of_type kind<span class="Delimiter">,</span> istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + string name = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"reading "</span> << command << <span class="Constant">' '</span> << name<span class="Delimiter">;</span> +<span class="CommentedCode">//? cout << name << '\n'; //? 2</span> +<span class="CommentedCode">//? if (Type_number.find(name) != Type_number.end()) //? 1</span> +<span class="CommentedCode">//? cerr << Type_number[name] << '\n'; //? 1</span> + if <span class="Delimiter">(</span>Type_number<span class="Delimiter">.</span>find<span class="Delimiter">(</span>name<span class="Delimiter">)</span> == Type_number<span class="Delimiter">.</span>end<span class="Delimiter">()</span> + || Type_number[name] == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + Type_number[name] = Next_type_number++<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + skip_bracket<span class="Delimiter">(</span>in<span class="Delimiter">,</span> <span class="Constant">"'container' must begin with '['"</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>Type<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Type_number[name]<span class="Delimiter">)</span> == Type<span class="Delimiter">.</span>end<span class="Delimiter">());</span> + type_info& t = Type[Type_number[name]]<span class="Delimiter">;</span> + recently_added_types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[name]<span class="Delimiter">);</span> + t<span class="Delimiter">.</span>name = name<span class="Delimiter">;</span> + t<span class="Delimiter">.</span>kind = kind<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> + 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> + istringstream inner<span class="Delimiter">(</span>element<span class="Delimiter">);</span> + t<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">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">" element name: "</span> << t<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>back<span class="Delimiter">();</span> + vector<type_number> types<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>!inner<span class="Delimiter">.</span>eof<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> + if <span class="Delimiter">(</span>Type_number<span class="Delimiter">.</span>find<span class="Delimiter">(</span>type_name<span class="Delimiter">)</span> == Type_number<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + raise << <span class="Constant">"unknown type "</span> << type_name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[type_name]<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">" type: "</span> << types<span class="Delimiter">.</span>back<span class="Delimiter">();</span> + <span class="Delimiter">}</span> + t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>types<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + assert<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == t<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>size<span class="Delimiter">());</span> + t<span class="Delimiter">.</span>size = t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>size<span class="Delimiter">();</span> +<span class="Delimiter">}</span> + +<span class="Comment">//: ensure types created in one scenario don't leak outside it.</span> +<span class="Delimiter">:(before "End Globals")</span> +vector<type_number> recently_added_types<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End load_permanently")</span> <span class="Comment">//: for non-tests</span> +recently_added_types<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> +<span class="Delimiter">:(before "End Setup")</span> <span class="Comment">//: for tests</span> +for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < recently_added_types<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cout << "erasing " << Type[recently_added_types.at(i)].name << '\n'; //? 1</span> + Type_number<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>Type[recently_added_types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span>]<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> +recently_added_types<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> +<span class="Comment">//: lastly, ensure scenarios are consistent by always starting them at the</span> +<span class="Comment">//: same type number.</span> +Next_type_number = <span class="Constant">1000</span><span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Test Run Initialization")</span> +assert<span class="Delimiter">(</span>Next_type_number < <span class="Constant">1000</span><span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Setup")</span> +Next_type_number = <span class="Constant">1000</span><span class="Delimiter">;</span> + +<span class="SalientComment">//:: helpers</span> + +<span class="Delimiter">:(code)</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> + raise << message << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> </pre> </body> </html> diff --git a/html/031address.cc.html b/html/031address.cc.html index e67afc4c..e54f6df1 100644 --- a/html/031address.cc.html +++ b/html/031address.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 031address.cc</title> +<title>~/Desktop/s/mu/031address.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,12 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .CommentedCode { color: #6c6c6c; } -.SalientComment { color: #00ffff; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .Identifier { color: #008080; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } --> </style> @@ -37,31 +37,31 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario copy_indirect)</span> recipe main [ - <span class="Constant">1</span>:address:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal <span class="Comment"># This loads location 1 as an address and looks up *that* location.</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:integer/deref + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:number/deref ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+mem: location 1 is 2</span> <span class="traceContains">+mem: location 2 is 34</span> <span class="traceContains">+mem: storing 34 in location 3</span> -<span class="Delimiter">:(before "index_t base = x.value" following "vector<long long int> read_memory(reagent x)")</span> +<span class="Delimiter">:(before "index_t base = x.value" following "vector<double> read_memory(reagent x)")</span> x = canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span> <span class="Comment">//: similarly, write to addresses pointing at other locations using the</span> <span class="Comment">//: 'deref' property</span> <span class="Delimiter">:(scenario store_indirect)</span> recipe main [ - <span class="Constant">1</span>:address:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">1</span>:address:integer/deref<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal + <span class="Constant">1</span>:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal ] <span class="traceContains">+run: instruction main/1</span> <span class="traceContains">+mem: location 1 is 2</span> <span class="traceContains">+mem: storing 34 in location 2</span> -<span class="Delimiter">:(before "index_t base = x.value" following "void write_memory(reagent x, vector<long long int> data)")</span> +<span class="Delimiter">:(before "index_t base = x.value" following "void write_memory(reagent x, vector<double> data)")</span> x = canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> @@ -79,7 +79,7 @@ reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)< <span class="CommentedCode">//? cout << "deref: " << x.to_string() << "\n"; //? 2</span> static const type_number ADDRESS = Type_number[<span class="Constant">"address"</span>]<span class="Delimiter">;</span> reagent result<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>x<span class="Delimiter">.</span>types[<span class="Constant">0</span>] == ADDRESS<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == ADDRESS<span class="Delimiter">);</span> <span class="Comment">// compute value</span> result<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>Memory[x<span class="Delimiter">.</span>value]<span class="Delimiter">);</span> @@ -92,12 +92,12 @@ reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)< index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> size_t len = x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> for <span class="Delimiter">(</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<span class="Delimiter">.</span>first == <span class="Constant">"deref"</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<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">"deref"</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> ++i<span class="Delimiter">;</span> <span class="Comment">// skip first deref</span> for <span class="Delimiter">(;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<span class="Delimiter">);</span> + result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<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> @@ -105,26 +105,26 @@ reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)< <span class="SalientComment">//:: 'get' can read from container address</span> <span class="Delimiter">:(scenario get_indirect)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">0</span>:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">0</span>:offset ] <span class="traceContains">+run: instruction main/3</span> <span class="traceContains">+run: address to copy is 2</span> -<span class="traceContains">+run: product 0 is 34</span> +<span class="traceContains">+run: product 0 is 4</span> <span class="traceContains">+mem: storing 34 in location 4</span> <span class="Delimiter">:(scenario include_nonderef_properties)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/deref/foo<span class="Delimiter">,</span> <span class="Constant">0</span>:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/deref/foo<span class="Delimiter">,</span> <span class="Constant">0</span>:offset ] <span class="traceContains">+run: instruction main/3</span> <span class="traceContains">+run: address to copy is 2</span> -<span class="traceContains">+run: product 0 is 34</span> +<span class="traceContains">+run: product 0 is 4</span> <span class="traceContains">+mem: storing 34 in location 4</span> <span class="Delimiter">:(after "reagent base = " following "case GET:")</span> @@ -133,14 +133,14 @@ base = canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</s <span class="Delimiter">:(scenario get_address_indirect)</span> <span class="Comment"># 'get' can read from container address</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>get-address <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">0</span>:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>get-address <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">0</span>:offset ] <span class="traceContains">+run: instruction main/3</span> <span class="traceContains">+run: address to copy is 2</span> -<span class="traceContains">+run: product 0 is 2</span> +<span class="traceContains">+run: product 0 is 4</span> <span class="Delimiter">:(after "reagent base = " following "case GET_ADDRESS:")</span> base = canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span> @@ -150,15 +150,15 @@ base = canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</s <span class="Delimiter">:(code)</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>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[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> + 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> vector<string> 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>index_t p = <span class="Constant">0</span><span class="Delimiter">;</span> p != r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties[p]<span class="Delimiter">.</span>first == name<span class="Delimiter">)</span> - <span class="Identifier">return</span> r<span class="Delimiter">.</span>properties[p]<span class="Delimiter">.</span>second<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> vector<string><span class="Delimiter">();</span> <span class="Delimiter">}</span> diff --git a/html/032array.cc.html b/html/032array.cc.html index 2b95ab90..c2fc903c 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 032array.cc</title> +<title>~/Desktop/s/mu/032array.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,12 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .CommentedCode { color: #6c6c6c; } -.SalientComment { color: #00ffff; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .Identifier { color: #008080; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } --> </style> @@ -40,14 +40,14 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment">//: Create containers containing addresses to arrays instead.</span> <span class="Delimiter">:(scenario copy_array)</span> -<span class="Comment"># Arrays can be copied around with a single instruction just like integers,</span> +<span class="Comment"># Arrays can be copied around with a single instruction just like numbers,</span> <span class="Comment"># no matter how large they are.</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:array:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:array:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:array:number ] <span class="traceContains">+run: instruction main/4</span> <span class="traceContains">+run: ingredient 0 is 1</span> @@ -62,12 +62,12 @@ recipe main [ <span class="Delimiter">:(scenario copy_array_indirect)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:address:array:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">6</span>:array:integer<span class="Special"> <- </span>copy <span class="Constant">5</span>:address:array:integer/deref + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">6</span>:array:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:address:array:number/deref ] <span class="traceContains">+run: instruction main/5</span> <span class="traceContains">+run: ingredient 0 is 5</span> @@ -81,11 +81,10 @@ recipe main [ <span class="traceContains">+mem: storing 16 in location 9</span> <span class="Comment">//: disable the size mismatch check since the destination array need not be initialized</span> -<span class="Delimiter">:(replace "if (size_of(x) != data.size())" following "void write_memory(reagent x, vector<long long int> data)")</span> -if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types[<span class="Constant">0</span>] != Type_number[<span class="Constant">"array"</span>] && size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> != data<span class="Delimiter">.</span>size<span class="Delimiter">())</span> +<span class="Delimiter">:(replace "if (size_of(x) != data.size())" following "void write_memory(reagent x, vector<double> data)")</span> +if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_number[<span class="Constant">"array"</span>] && size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> != data<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">:(after "size_t size_of(const reagent& r)")</span> - static const type_number ARRAY = Type_number[<span class="Constant">"array"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>types[<span class="Constant">0</span>] == ARRAY<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == Type_number[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// skip the 'array' type to get at the element type</span> <span class="Identifier">return</span> <span class="Constant">1</span> + Memory[r<span class="Delimiter">.</span>value]*size_of<span class="Delimiter">(</span>array_element<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">));</span> @@ -95,33 +94,33 @@ if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types[<span <span class="Delimiter">:(scenario index)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:integer<span class="Special"> <- </span>index <span class="Constant">1</span>:array:integer<span class="Delimiter">,</span> <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>index <span class="Constant">1</span>:array:number<span class="Delimiter">,</span> <span class="Constant">0</span>:literal ] <span class="traceContains">+run: instruction main/4</span> <span class="traceContains">+run: address to copy is 2</span> <span class="traceContains">+run: its type is 1</span> <span class="traceContains">+mem: location 2 is 14</span> -<span class="traceContains">+run: product 0 is 14</span> +<span class="traceContains">+run: product 0 is 5</span> <span class="traceContains">+mem: storing 14 in location 5</span> <span class="Delimiter">:(scenario index_direct_offset)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">6</span>:integer<span class="Special"> <- </span>index <span class="Constant">1</span>:array:integer<span class="Delimiter">,</span> <span class="Constant">5</span>:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>index <span class="Constant">1</span>:array:number<span class="Delimiter">,</span> <span class="Constant">5</span>:number ] <span class="traceContains">+run: instruction main/5</span> <span class="traceContains">+run: address to copy is 2</span> <span class="traceContains">+run: its type is 1</span> <span class="traceContains">+mem: location 2 is 14</span> -<span class="traceContains">+run: product 0 is 14</span> +<span class="traceContains">+run: product 0 is 6</span> <span class="traceContains">+mem: storing 14 in location 6</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> @@ -130,31 +129,24 @@ INDEX<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"index"</span>] = INDEX<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case INDEX: <span class="Delimiter">{</span> - static const type_number ARRAY = Type_number[<span class="Constant">"array"</span>]<span class="Delimiter">;</span> <span class="CommentedCode">//? if (Trace_stream) Trace_stream->dump_layer = "run"; //? 1</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> - reagent base = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> + reagent base = canonize<span class="Delimiter">(</span>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="CommentedCode">//? trace("run") << "ingredient 0 after canonize: " << base.to_string(); //? 1</span> index_t base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types[<span class="Constant">0</span>] == ARRAY<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> - reagent offset = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == Type_number[<span class="Constant">"array"</span>]<span class="Delimiter">);</span> + reagent offset = canonize<span class="Delimiter">(</span>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> <span class="CommentedCode">//? trace("run") << "ingredient 1 after canonize: " << offset.to_string(); //? 1</span> - vector<long long int> offset_val<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>offset<span class="Delimiter">));</span> + vector<double> offset_val<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>offset<span class="Delimiter">));</span> vector<type_number> element_type = array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">);</span> -<span class="CommentedCode">//? trace("run") << "offset: " << offset_val[0]; //? 1</span> +<span class="CommentedCode">//? trace("run") << "offset: " << offset_val.at(0); //? 1</span> <span class="CommentedCode">//? trace("run") << "size of elements: " << size_of(element_type); //? 1</span> - index_t src = base_address + <span class="Constant">1</span> + offset_val[<span class="Constant">0</span>]*size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">);</span> + index_t src = base_address + <span class="Constant">1</span> + offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << element_type[<span class="Constant">0</span>]<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << element_type<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> reagent tmp<span class="Delimiter">;</span> tmp<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>src<span class="Delimiter">);</span> copy<span class="Delimiter">(</span>element_type<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> element_type<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>types<span class="Delimiter">,</span> tmp<span class="Delimiter">.</span>types<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span> -<span class="CommentedCode">//? trace("run") << "AAA: " << tmp.to_string() << '\n'; //? 3</span> - vector<long long int> result<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>tmp<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> -<span class="CommentedCode">//? if (Trace_stream) Trace_stream->dump_layer = ""; //? 1</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> @@ -165,26 +157,25 @@ vector<type_number> array_element<span class="Delimiter">(</span>const vec <span class="Delimiter">:(scenario index_address)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:integer<span class="Special"> <- </span>index-address <span class="Constant">1</span>:array:integer<span class="Delimiter">,</span> <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>index-address <span class="Constant">1</span>:array:number<span class="Delimiter">,</span> <span class="Constant">0</span>:literal ] <span class="traceContains">+run: instruction main/4</span> -<span class="traceContains">+run: address to copy is 2</span> <span class="traceContains">+mem: storing 2 in location 5</span> <span class="SalientComment">//:: To write to elements of containers, you need their address.</span> <span class="Delimiter">:(scenario index_indirect)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:address:array:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">6</span>:integer<span class="Special"> <- </span>index <span class="Constant">5</span>:address:array:integer/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>index <span class="Constant">5</span>:address:array:number/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] <span class="traceContains">+run: instruction main/5</span> <span class="traceContains">+mem: storing 15 in location 6</span> @@ -195,21 +186,15 @@ INDEX_ADDRESS<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"index-address"</span>] = INDEX_ADDRESS<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case INDEX_ADDRESS: <span class="Delimiter">{</span> - static const type_number ARRAY = Type_number[<span class="Constant">"array"</span>]<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - reagent base = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> + reagent base = canonize<span class="Delimiter">(</span>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> index_t base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types[<span class="Constant">0</span>] == ARRAY<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> - reagent offset = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - vector<long long int> offset_val<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>offset<span class="Delimiter">));</span> + assert<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == Type_number[<span class="Constant">"array"</span>]<span class="Delimiter">);</span> + reagent offset = canonize<span class="Delimiter">(</span>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> + vector<double> offset_val<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>offset<span class="Delimiter">));</span> vector<type_number> element_type = array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">);</span> - index_t src = base_address + <span class="Constant">1</span> + offset_val[<span class="Constant">0</span>]*size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src<span class="Delimiter">;</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>src<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> << result[<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + index_t result = base_address + <span class="Constant">1</span> + offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>element_type<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="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> diff --git a/html/033length.cc.html b/html/033length.cc.html index 17d1f65f..3a2998fd 100644 --- a/html/033length.cc.html +++ b/html/033length.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 033length.cc</title> +<title>~/Desktop/s/mu/033length.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,7 +14,6 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } -.CommentedCode { color: #6c6c6c; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } @@ -36,11 +35,11 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario array_length)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:integer<span class="Special"> <- </span>length <span class="Constant">1</span>:array:integer + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>length <span class="Constant">1</span>:array:number ] <span class="traceContains">+run: instruction main/4</span> <span class="traceContains">+mem: storing 3 in location 5</span> @@ -51,15 +50,13 @@ LENGTH<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"length"</span>] = LENGTH<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case LENGTH: <span class="Delimiter">{</span> - reagent x = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types[<span class="Constant">0</span>] != Type_number[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + reagent x = canonize<span class="Delimiter">(</span>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> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_number[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"tried to calculate length of non-array "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - vector<long long int> result<span class="Delimiter">;</span> -<span class="CommentedCode">//? cout << "length: " << x.value << '\n'; //? 1</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Memory[x<span class="Delimiter">.</span>value]<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<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>Memory[x<span class="Delimiter">.</span>value]<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> diff --git a/html/034exclusive_container.cc.html b/html/034exclusive_container.cc.html index f8387563..32576bd7 100644 --- a/html/034exclusive_container.cc.html +++ b/html/034exclusive_container.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 034exclusive_container.cc</title> +<title>~/Desktop/s/mu/034exclusive_container.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,12 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .Identifier { color: #008080; } -.SalientComment { color: #00ffff; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } --> </style> @@ -39,15 +39,15 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment">//: currently stored in them.</span> <span class="Delimiter">:(before "End Mu Types Initialization")</span> -<span class="Comment">//: We'll use this container as a running example, with two integer elements.</span> +<span class="Comment">//: We'll use this container as a running example, with two number elements.</span> <span class="Delimiter">{</span> -type_number tmp = Type_number[<span class="Constant">"integer-or-point"</span>] = Next_type_number++<span class="Delimiter">;</span> +type_number tmp = Type_number[<span class="Constant">"number-or-point"</span>] = Next_type_number++<span class="Delimiter">;</span> Type[tmp]<span class="Delimiter">.</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> Type[tmp]<span class="Delimiter">.</span>kind = exclusive_container<span class="Delimiter">;</span> -Type[tmp]<span class="Delimiter">.</span>name = <span class="Constant">"integer-or-point"</span><span class="Delimiter">;</span> +Type[tmp]<span class="Delimiter">.</span>name = <span class="Constant">"number-or-point"</span><span class="Delimiter">;</span> <span class="CommentedCode">//? cout << tmp << ": " << Type[tmp].elements.size() << '\n'; //? 1</span> vector<type_number> t1<span class="Delimiter">;</span> -t1<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>integer<span class="Delimiter">);</span> +t1<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>number<span class="Delimiter">);</span> Type[tmp]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>t1<span class="Delimiter">);</span> <span class="CommentedCode">//? cout << Type[tmp].elements.size() << '\n'; //? 1</span> vector<type_number> t2<span class="Delimiter">;</span> @@ -62,10 +62,10 @@ Type[tmp]<span class="Delimiter">.</span>element_names<span class="Delimiter">.< <span class="Delimiter">:(scenario copy_exclusive_container)</span> <span class="Comment"># Copying exclusive containers copies all their contents and an extra location for the tag.</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal <span class="Comment"># 'point' variant</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">4</span>:integer-or-point<span class="Special"> <- </span>copy <span class="Constant">1</span>:integer-or-point + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal <span class="Comment"># 'point' variant</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">4</span>:number-or-point<span class="Special"> <- </span>copy <span class="Constant">1</span>:number-or-point ] <span class="traceContains">+mem: storing 1 in location 4</span> <span class="traceContains">+mem: storing 34 in location 5</span> @@ -75,13 +75,13 @@ recipe main [ if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == exclusive_container<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// size of an exclusive container is the size of its largest variant</span> <span class="Comment">// (So like containers, it can't contain arrays.)</span> -<span class="CommentedCode">//? cout << "--- " << types[0] << ' ' << t.size << '\n'; //? 1</span> +<span class="CommentedCode">//? cout << "--- " << types.at(0) << ' ' << t.size << '\n'; //? 1</span> <span class="CommentedCode">//? cout << "point: " << Type_number["point"] << " " << Type[Type_number["point"]].name << " " << Type[Type_number["point"]].size << '\n'; //? 1</span> <span class="CommentedCode">//? cout << t.name << ' ' << t.size << ' ' << t.elements.size() << '\n'; //? 1</span> size_t result = <span class="Constant">0</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t 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> - size_t tmp = size_of<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements[i]<span class="Delimiter">);</span> -<span class="CommentedCode">//? cout << i << ": " << t.elements[i][0] << ' ' << tmp << ' ' << result << '\n'; //? 1</span> + size_t 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> +<span class="CommentedCode">//? cout << i << ": " << t.elements.at(i).at(0) << ' ' << tmp << ' ' << result << '\n'; //? 1</span> if <span class="Delimiter">(</span>tmp > result<span class="Delimiter">)</span> result = tmp<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// ...+1 for its tag.</span> @@ -100,19 +100,19 @@ Type_number[<span class="Constant">"variant"</span>] = <span class="Co <span class="Delimiter">:(scenario maybe_convert)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal - <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:integer-or-point<span class="Delimiter">,</span> <span class="Constant">1</span>:variant + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point<span class="Delimiter">,</span> <span class="Constant">1</span>:variant ] <span class="traceContains">+mem: storing 13 in location 20</span> <span class="Delimiter">:(scenario maybe_convert_fail)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal - <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:integer-or-point<span class="Delimiter">,</span> <span class="Constant">0</span>:variant + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point<span class="Delimiter">,</span> <span class="Constant">0</span>:variant ] <span class="traceContains">+mem: storing 0 in location 20</span> @@ -122,24 +122,41 @@ MAYBE_CONVERT<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"maybe-convert"</span>] = MAYBE_CONVERT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MAYBE_CONVERT: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - reagent base = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> + reagent base = canonize<span class="Delimiter">(</span>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> index_t base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - type_number base_type = base<span class="Delimiter">.</span>types[<span class="Constant">0</span>]<span class="Delimiter">;</span> + type_number base_type = base<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind == exclusive_container<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> - index_t tag = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - vector<long long int> result<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + index_t 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> + long long int result<span class="Delimiter">;</span> if <span class="Delimiter">(</span>tag == static_cast<index_t><span class="Delimiter">(</span>Memory[base_address]<span class="Delimiter">))</span> <span class="Delimiter">{</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>base_address+<span class="Constant">1</span><span class="Delimiter">);</span> + result = base_address+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + result = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<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="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + +<span class="SalientComment">//:: Allow exclusive containers to be defined in mu code.</span> + +<span class="Delimiter">:(scenario exclusive_container)</span> +exclusive-container foo [ + x:number + y:number +] +<span class="traceContains">+parse: reading 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="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> </pre> </body> </html> diff --git a/html/035call.cc.html b/html/035call.cc.html index 69c23b45..0c3adead 100644 --- a/html/035call.cc.html +++ b/html/035call.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 035call.cc</title> +<title>~/Desktop/s/mu/035call.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,14 +14,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .Identifier { color: #008080; } -.traceContains { color: #008000; } +.SalientComment { color: #00ffff; } .PreProc { color: #c000c0; } +.traceContains { color: #008000; } --> </style> @@ -40,20 +40,20 @@ recipe main [ f ] recipe f [ - <span class="Constant">3</span>:integer<span class="Special"> <- </span>add <span class="Constant">2</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>add <span class="Constant">2</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal ] <span class="traceContains">+mem: storing 4 in location 3</span> <span class="Delimiter">:(scenario return_on_fallthrough)</span> recipe main [ f - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal ] recipe f [ - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">5</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: instruction f/0</span> @@ -72,7 +72,7 @@ struct call <span class="Delimiter">{</span> <span class="Comment">// End call Fields</span> call<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> :running_recipe<span class="Delimiter">(</span>r<span class="Delimiter">),</span> running_step_index<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Delimiter">};</span> -typedef stack<call> call_stack<span class="Delimiter">;</span> +typedef list<call> call_stack<span class="Delimiter">;</span> <span class="Delimiter">:(replace{} "struct routine")</span> struct routine <span class="Delimiter">{</span> @@ -84,7 +84,7 @@ struct routine <span class="Delimiter">{</span> <span class="Delimiter">};</span> <span class="Delimiter">:(code)</span> routine::routine<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - calls<span class="Delimiter">.</span>push<span class="Delimiter">(</span>call<span class="Delimiter">(</span>r<span class="Delimiter">));</span> + calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>r<span class="Delimiter">));</span> <span class="Comment">// End routine Constructor</span> <span class="Delimiter">}</span> @@ -92,25 +92,28 @@ routine::routine<span class="Delimiter">(</span>recipe_number r<span class="Deli <span class="Delimiter">:(replace{} "inline index_t& current_step_index()")</span> inline index_t& current_step_index<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_step_index<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + <span class="Identifier">return</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_step_index<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(replace{} "inline const string& current_recipe_name()")</span> inline const string& current_recipe_name<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(replace{} "inline const instruction& current_instruction()")</span> inline const instruction& current_instruction<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>steps[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_step_index]<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_step_index<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(replace{} "default:" following "End Primitive Recipe Implementations")</span> default: <span class="Delimiter">{</span> <span class="Comment">// not a primitive; try to look up the book of recipes</span> if <span class="Delimiter">(</span>Recipe<span class="Delimiter">.</span>find<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">)</span> == Recipe<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"undefined operation "</span> << current_instruction<span class="Delimiter">().</span>operation << <span class="Constant">": "</span> << current_instruction<span class="Delimiter">().</span>name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + raise << <span class="Constant">"undefined operation "</span> << current_instruction<span class="Delimiter">().</span>operation << <span class="Constant">": "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push<span class="Delimiter">(</span>call<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">));</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">));</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// not done with caller; don't increment current_step_index()</span> <span class="Delimiter">}</span> @@ -122,14 +125,15 @@ inline bool routine::completed<span class="Delimiter">()</span> const <span clas <span class="Delimiter">}</span> inline const vector<instruction>& routine::steps<span class="Delimiter">()</span> const <span class="Delimiter">{</span> - <span class="Identifier">return</span> Recipe[calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>steps<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!calls<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + <span class="Identifier">return</span> Recipe[calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>steps<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "Running One Instruction")</span> <span class="Comment">// when we reach the end of one call, we may reach the end of the one below</span> <span class="Comment">// it, and the one below that, and so on</span> while <span class="Delimiter">(</span>current_step_index<span class="Delimiter">()</span> >= Current_routine<span class="Delimiter">-></span>steps<span class="Delimiter">().</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>pop_front<span class="Delimiter">();</span> if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// todo: no results returned warning</span> ++current_step_index<span class="Delimiter">();</span> diff --git a/html/036call_ingredient.cc.html b/html/036call_ingredient.cc.html index 9e90079f..e1ed83f6 100644 --- a/html/036call_ingredient.cc.html +++ b/html/036call_ingredient.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 036call_ingredient.cc</title> +<title>~/Desktop/s/mu/036call_ingredient.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -38,8 +38,8 @@ recipe main [ f <span class="Constant">2</span>:literal ] recipe f [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>next-ingredient - <span class="Constant">13</span>:integer<span class="Special"> <- </span>add <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">12</span>:integer + <span class="Constant">12</span>:number<span class="Special"> <- </span>next-ingredient + <span class="Constant">13</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">12</span>:number ] <span class="traceContains">+run: instruction f/1</span> <span class="traceContains">+mem: location 12 is 2</span> @@ -50,22 +50,22 @@ recipe main [ f ] recipe f [ - _<span class="Delimiter">,</span> <span class="Constant">12</span>:integer<span class="Special"> <- </span>next-ingredient + _<span class="Delimiter">,</span> <span class="Constant">12</span>:number<span class="Special"> <- </span>next-ingredient ] <span class="traceContains">+mem: storing 0 in location 12</span> <span class="Delimiter">:(before "End call Fields")</span> -vector<vector<long long int> > ingredient_atoms<span class="Delimiter">;</span> +vector<vector<double> > ingredient_atoms<span class="Delimiter">;</span> index_t next_ingredient_to_process<span class="Delimiter">;</span> <span class="Delimiter">:(replace{} "call(recipe_number r)")</span> call<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> :running_recipe<span class="Delimiter">(</span>r<span class="Delimiter">),</span> running_step_index<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> next_ingredient_to_process<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> -<span class="Delimiter">:(replace "Current_routine->calls.push(call(current_instruction().operation))" following "End Primitive Recipe Implementations")</span> +<span class="Delimiter">:(replace "Current_routine->calls.push_front(call(current_instruction().operation))" following "End Primitive Recipe Implementations")</span> call callee<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">);</span> -for <span class="Delimiter">(</span>size_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - callee<span class="Delimiter">.</span>ingredient_atoms<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[i]<span class="Delimiter">));</span> +for <span class="Delimiter">(</span>size_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + callee<span class="Delimiter">.</span>ingredient_atoms<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> -Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push<span class="Delimiter">(</span>callee<span class="Delimiter">);</span> +Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>callee<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> NEXT_INGREDIENT<span class="Delimiter">,</span> @@ -73,24 +73,18 @@ NEXT_INGREDIENT<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"next-ingredient"</span>] = NEXT_INGREDIENT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case NEXT_INGREDIENT: <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process < Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> - << Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process][<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process]<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - vector<long long int> ingredient_exists<span class="Delimiter">;</span> - ingredient_exists<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> ingredient_exists<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - ++Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>next_ingredient_to_process < Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> + products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>next_ingredient_to_process<span class="Delimiter">));</span> + assert<span class="Delimiter">(</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span> <span class="Comment">// push a new vector</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">1</span><span class="Delimiter">);</span> + ++Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>next_ingredient_to_process<span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - vector<long long int> no_ingredient<span class="Delimiter">;</span> - no_ingredient<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> no_ingredient<span class="Delimiter">);</span> - <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> <span class="Comment">// todo: will fail noisily if we try to read a compound value</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> <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -100,10 +94,10 @@ recipe main [ f <span class="Constant">2</span>:literal ] recipe f [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>next-ingredient <span class="Comment"># consume ingredient</span> + <span class="Constant">12</span>:number<span class="Special"> <- </span>next-ingredient <span class="Comment"># consume ingredient</span> _<span class="Delimiter">,</span> <span class="Constant">1</span>:boolean<span class="Special"> <- </span>next-ingredient <span class="Comment"># will not find any ingredients</span> rewind-ingredients - <span class="Constant">13</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean<span class="Special"> <- </span>next-ingredient <span class="Comment"># will find ingredient again</span> + <span class="Constant">13</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean<span class="Special"> <- </span>next-ingredient <span class="Comment"># will find ingredient again</span> ] <span class="traceContains">+mem: storing 2 in location 12</span> <span class="traceContains">+mem: storing 0 in location 1</span> @@ -116,7 +110,7 @@ REWIND_INGREDIENTS<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"rewind-ingredients"</span>] = REWIND_INGREDIENTS<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case REWIND_INGREDIENTS: <span class="Delimiter">{</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process = <span class="Constant">0</span><span class="Delimiter">;</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>next_ingredient_to_process = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -125,8 +119,8 @@ recipe main [ f <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal ] recipe f [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>ingredient <span class="Constant">1</span>:literal <span class="Comment"># consume second ingredient first</span> - <span class="Constant">13</span>:integer<span class="Delimiter">,</span> <span class="Constant">1</span>:boolean<span class="Special"> <- </span>next-ingredient <span class="Comment"># next-ingredient tries to scan past that</span> + <span class="Constant">12</span>:number<span class="Special"> <- </span>ingredient <span class="Constant">1</span>:literal <span class="Comment"># consume second ingredient first</span> + <span class="Constant">13</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>:boolean<span class="Special"> <- </span>next-ingredient <span class="Comment"># next-ingredient tries to scan past that</span> ] <span class="traceContains">+mem: storing 2 in location 12</span> <span class="traceContains">+mem: storing 0 in location 1</span> @@ -137,24 +131,21 @@ INGREDIENT<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"ingredient"</span>] = INGREDIENT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case INGREDIENT: <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>static_cast<index_t><span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>value<span class="Delimiter">)</span> < Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> - << Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process][<span class="Constant">0</span>]<span class="Delimiter">;</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process]<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - vector<long long int> ingredient_exists<span class="Delimiter">;</span> - ingredient_exists<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> ingredient_exists<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - ++Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + if <span class="Delimiter">(</span>static_cast<index_t><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>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>next_ingredient_to_process = 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>push_back<span class="Delimiter">(</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>next_ingredient_to_process<span class="Delimiter">));</span> + assert<span class="Delimiter">(</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span> <span class="Comment">// push a new vector</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">1</span><span class="Delimiter">);</span> + ++Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>next_ingredient_to_process<span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - vector<long long int> no_ingredient<span class="Delimiter">;</span> - no_ingredient<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> no_ingredient<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> <span class="Comment">// todo: will fail noisily if we try to read a compound value</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> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> diff --git a/html/037call_reply.cc.html b/html/037call_reply.cc.html index af7a3359..d175190f 100644 --- a/html/037call_reply.cc.html +++ b/html/037call_reply.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 037call_reply.cc</title> +<title>~/Desktop/s/mu/037call_reply.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -35,18 +35,16 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario reply)</span> recipe main [ - <span class="Constant">3</span>:integer<span class="Delimiter">,</span> <span class="Constant">4</span>:integer<span class="Special"> <- </span>f <span class="Constant">2</span>:literal + <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>f <span class="Constant">34</span>:literal ] recipe f [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>next-ingredient - <span class="Constant">13</span>:integer<span class="Special"> <- </span>add <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">12</span>:integer - reply <span class="Constant">12</span>:integer<span class="Delimiter">,</span> <span class="Constant">13</span>:integer + <span class="Constant">12</span>:number<span class="Special"> <- </span>next-ingredient + <span class="Constant">13</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">12</span>:number + reply <span class="Constant">12</span>:number<span class="Delimiter">,</span> <span class="Constant">13</span>:number ] <span class="traceContains">+run: instruction main/0</span> -<span class="traceContains">+run: result 0 is 2</span> -<span class="traceContains">+mem: storing 2 in location 3</span> -<span class="traceContains">+run: result 1 is 3</span> -<span class="traceContains">+mem: storing 3 in location 4</span> +<span class="traceContains">+mem: storing 34 in location 1</span> +<span class="traceContains">+mem: storing 35 in location 2</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> REPLY<span class="Delimiter">,</span> @@ -54,29 +52,28 @@ REPLY<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"reply"</span>] = REPLY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case REPLY: <span class="Delimiter">{</span> - vector<vector<long long int> > callee_results<span class="Delimiter">;</span> - for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - callee_results<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[i]<span class="Delimiter">));</span> - <span class="Delimiter">}</span> const instruction& reply_inst = current_instruction<span class="Delimiter">();</span> <span class="Comment">// save pointer into recipe before pop</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> - assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>pop_front<span class="Delimiter">();</span> + <span class="Comment">// just in case 'main' returns a value, drop it for now</span> + if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">goto</span> stop_running_current_routine<span class="Delimiter">;</span> const instruction& caller_instruction = current_instruction<span class="Delimiter">();</span> - assert<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> <= callee_results<span class="Delimiter">.</span>size<span class="Delimiter">());</span> + <span class="Comment">// make reply results available to caller</span> + copy<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> ingredients<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>products<span class="Delimiter">,</span> products<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span> + <span class="Comment">// check that any reply ingredients with /same-as-ingredient connect up</span> + <span class="Comment">// the corresponding ingredient and product in the caller.</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result "</span> << i << <span class="Constant">" is "</span> << to_string<span class="Delimiter">(</span>callee_results[i]<span class="Delimiter">);</span> - <span class="Comment">// check that any reply ingredients with /same-as-ingredient connect up</span> - <span class="Comment">// the corresponding ingredient and product in the caller.</span> - if <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients[i]<span class="Delimiter">,</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> - vector<string> tmp = property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients[i]<span class="Delimiter">,</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result "</span> << i << <span class="Constant">" is "</span> << to_string<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + 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> + vector<string> 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> assert<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - long long int ingredient_index = to_int<span class="Delimiter">(</span>tmp[<span class="Constant">0</span>]<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products[i]<span class="Delimiter">.</span>value != caller_instruction<span class="Delimiter">.</span>ingredients[ingredient_index]<span class="Delimiter">.</span>value<span class="Delimiter">)</span> - raise << <span class="Constant">"'same-as-ingredient' result "</span> << caller_instruction<span class="Delimiter">.</span>products[i]<span class="Delimiter">.</span>value << <span class="Constant">" must be location "</span> << caller_instruction<span class="Delimiter">.</span>ingredients[ingredient_index]<span class="Delimiter">.</span>value << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + long long int ingredient_index = to_number<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + if <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>value != caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>value<span class="Delimiter">)</span> + raise << <span class="Constant">"'same-as-ingredient' result "</span> << caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>value << <span class="Constant">" must be location "</span> << caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>value << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - write_memory<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products[i]<span class="Delimiter">,</span> callee_results[i]<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// instruction loop will increment caller's step_index</span> + <span class="Comment">// refresh instruction_counter to caller's step_index</span> + instruction_counter = current_step_index<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: Products can include containers and exclusive containers, addresses and arrays.</span> @@ -85,8 +82,8 @@ recipe main [ <span class="Constant">3</span>:point<span class="Special"> <- </span>f <span class="Constant">2</span>:literal ] recipe f [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>next-ingredient - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">12</span>:number<span class="Special"> <- </span>next-ingredient + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal reply <span class="Constant">12</span>:point ] <span class="traceContains">+run: instruction main/0</span> @@ -98,34 +95,76 @@ recipe f [ <span class="Comment">//: ingredients unless they're also products. The /same-as-ingredient inside</span> <span class="Comment">//: the recipe's 'reply' will help catch accidental misuse of such</span> <span class="Comment">//: 'ingredient-results' (sometimes called in-out parameters in other languages).</span> + <span class="Delimiter">:(scenario reply_same_as_ingredient)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:address:integer<span class="Special"> <- </span>new integer:type - <span class="Constant">2</span>:address:integer<span class="Special"> <- </span>test1 <span class="Constant">1</span>:address:integer <span class="Comment"># call with different ingredient and product</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>test1 <span class="Constant">1</span>:number <span class="Comment"># call with different ingredient and product</span> ] recipe test1 [ - <span class="Constant">10</span>:address:integer<span class="Special"> <- </span>next-ingredient - reply <span class="Constant">10</span>:address:integer/same-as-ingredient:<span class="Constant">0</span> + <span class="Constant">10</span>:address:number<span class="Special"> <- </span>next-ingredient + reply <span class="Constant">10</span>:address:number/same-as-ingredient:<span class="Constant">0</span> ] <span class="traceContains">+warn: 'same-as-ingredient' result 2 must be location 1</span> <span class="Delimiter">:(code)</span> -string to_string<span class="Delimiter">(</span>const vector<long long int>& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string to_string<span class="Delimiter">(</span>const vector<double>& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>empty<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>in<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - out << in[<span class="Constant">0</span>]<span class="Delimiter">;</span> + out << in<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> out << <span class="Constant">"["</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < in<span class="Delimiter">.</span>size<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 << in[i]<span class="Delimiter">;</span> + out << in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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> + +<span class="Comment">//: Conditional reply.</span> + +<span class="Delimiter">:(scenario reply_if)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>test1 +] +recipe test1 [ + reply-if <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal + reply <span class="Constant">35</span>:literal +] +<span class="traceContains">+mem: storing 35 in location 1</span> + +<span class="Delimiter">:(scenario reply_if2)</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>test1 +] +recipe test1 [ + reply-if <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal + reply <span class="Constant">35</span>:literal +] +<span class="traceContains">+mem: storing 34 in location 1</span> + +<span class="Delimiter">:(before "End Rewrite Instruction(curr)")</span> +<span class="Comment">// rewrite `reply-if a, b, c, ...` to</span> +<span class="Comment">// ```</span> +<span class="Comment">// jump-unless a, 1:offset</span> +<span class="Comment">// reply b, c, ...</span> +<span class="Comment">// ```</span> +if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"reply-if"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + curr<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">;</span> + vector<reagent> results<span class="Delimiter">;</span> + copy<span class="Delimiter">(</span>++curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>results<span class="Delimiter">,</span> results<span class="Delimiter">.</span>end<span class="Delimiter">()));</span> + curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</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">"1:offset"</span><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> + curr<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> + curr<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"reply"</span>]<span class="Delimiter">;</span> + curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>swap<span class="Delimiter">(</span>results<span class="Delimiter">);</span> +<span class="Delimiter">}</span> </pre> </body> </html> diff --git a/html/038scheduler.cc.html b/html/038scheduler.cc.html index 2eb59d6d..9d28ed3d 100644 --- a/html/038scheduler.cc.html +++ b/html/038scheduler.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 038scheduler.cc</title> +<title>~/Desktop/s/mu/038scheduler.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -13,15 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; } body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } -.SalientComment { color: #00ffff; } +.traceAbsent { color: #c00000; } +.cSpecial { color: #008000; } .Identifier { color: #008080; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } -.traceAbsent { color: #c00000; } --> </style> @@ -39,10 +40,13 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario scheduler)</span> recipe f1 [ start-running f2:recipe - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal + <span class="Comment"># wait for f2 to run</span> + <span class="Delimiter">{</span> + jump-unless <span class="Constant">1</span>:number<span class="Delimiter">,</span> -<span class="Constant">1</span>:literal + <span class="Delimiter">}</span> ] recipe f2 [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">4</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal ] <span class="traceContains">+schedule: f1</span> <span class="traceContains">+schedule: f2</span> @@ -79,17 +83,23 @@ Scheduling_interval = <span class="Constant">500</span><span class="Delimiter">; <span class="Delimiter">:(replace{} "void run(recipe_number r)")</span> void run<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span> Routines<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new routine<span class="Delimiter">(</span>r<span class="Delimiter">));</span> - Current_routine_index = <span class="Constant">0</span><span class="Delimiter">,</span> Current_routine = Routines[<span class="Constant">0</span>]<span class="Delimiter">;</span> + Current_routine_index = <span class="Constant">0</span><span class="Delimiter">,</span> Current_routine = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> while <span class="Delimiter">(</span>!all_routines_done<span class="Delimiter">())</span> <span class="Delimiter">{</span> skip_to_next_routine<span class="Delimiter">();</span> <span class="CommentedCode">//? cout << "scheduler: " << Current_routine_index << '\n'; //? 1</span> assert<span class="Delimiter">(</span>Current_routine<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>state == RUNNING<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"schedule"</span><span class="Delimiter">)</span> << current_recipe_name<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">"schedule"</span><span class="Delimiter">)</span> << current_routine_label<span class="Delimiter">();</span> +<span class="CommentedCode">//? trace("schedule") << Current_routine_index << ": " << current_recipe_name(); //? 1</span> +<span class="CommentedCode">//? trace("schedule") << Current_routine->id << " " << current_recipe_name(); //? 1</span> run_current_routine<span class="Delimiter">(</span>Scheduling_interval<span class="Delimiter">);</span> + <span class="Comment">// Scheduler State Transitions</span> if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>completed<span class="Delimiter">())</span> Current_routine<span class="Delimiter">-></span>state = COMPLETED<span class="Delimiter">;</span> <span class="Comment">// End Scheduler State Transitions</span> + + <span class="Comment">// Scheduler Cleanup</span> + <span class="Comment">// End Scheduler Cleanup</span> <span class="Delimiter">}</span> <span class="CommentedCode">//? cout << "done with run\n"; //? 1</span> <span class="Delimiter">}</span> @@ -97,8 +107,8 @@ void run<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">) <span class="Delimiter">:(code)</span> bool all_routines_done<span class="Delimiter">()</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "routine " << i << ' ' << Routines[i]->state << '\n'; //? 1</span> - if <span class="Delimiter">(</span>Routines[i]<span class="Delimiter">-></span>state == RUNNING<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cout << "routine " << i << ' ' << Routines.at(i)->state << '\n'; //? 1</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state == RUNNING<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> @@ -110,24 +120,35 @@ void skip_to_next_routine<span class="Delimiter">()</span> <span class="Delimite assert<span class="Delimiter">(</span>!Routines<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> assert<span class="Delimiter">(</span>Current_routine_index < Routines<span class="Delimiter">.</span>size<span class="Delimiter">());</span> for <span class="Delimiter">(</span>index_t i = <span class="Delimiter">(</span>Current_routine_index+<span class="Constant">1</span><span class="Delimiter">)</span>%Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> i != Current_routine_index<span class="Delimiter">;</span> i = <span class="Delimiter">(</span>i+<span class="Constant">1</span><span class="Delimiter">)</span>%Routines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Routines[i]<span class="Delimiter">-></span>state == RUNNING<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state == RUNNING<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "switching to " << i << '\n'; //? 1</span> Current_routine_index = i<span class="Delimiter">;</span> - Current_routine = Routines[i]<span class="Delimiter">;</span> + Current_routine = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="CommentedCode">//? cout << "all done\n"; //? 1</span> <span class="Delimiter">}</span> +string current_routine_label<span class="Delimiter">()</span> <span class="Delimiter">{</span> + ostringstream result<span class="Delimiter">;</span> + call_stack calls = Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>call_stack::iterator p = calls<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != calls<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>p != calls<span class="Delimiter">.</span>begin<span class="Delimiter">())</span> result << <span class="Constant">'/'</span><span class="Delimiter">;</span> + result << Recipe[p<span class="Delimiter">-></span>running_recipe]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> result<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span class="Delimiter">}</span> + <span class="Delimiter">:(before "End Teardown")</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> - delete Routines[i]<span class="Delimiter">;</span> + delete Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> Routines<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="SalientComment">//:: To schedule new routines to run, call 'start-running'.</span> <span class="Comment">//: 'start-running' will return a unique id for the routine that was created.</span> +<span class="Comment">//: routine id is a number, but don't do any arithmetic on it</span> <span class="Delimiter">:(before "End routine Fields")</span> index_t id<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Globals")</span> @@ -138,32 +159,38 @@ Next_routine_id = <span class="Constant">1</span><span class="Delimiter">;</span id = Next_routine_id<span class="Delimiter">;</span> Next_routine_id++<span class="Delimiter">;</span> +<span class="Comment">//: routines save the routine that spawned them</span> +<span class="Delimiter">:(before "End routine Fields")</span> +<span class="Comment">// todo: really should be routine_id, but that's less efficient.</span> +long long int parent_index<span class="Delimiter">;</span> <span class="Comment">// only < 0 if there's no parent_index</span> +<span class="Delimiter">:(before "End routine Constructor")</span> +parent_index = -<span class="Constant">1</span><span class="Delimiter">;</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> START_RUNNING<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_number[<span class="Constant">"start-running"</span>] = START_RUNNING<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case START_RUNNING: <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>!current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>initialized<span class="Delimiter">);</span> - routine* new_routine = new routine<span class="Delimiter">(</span>Recipe_number[current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name]<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + assert<span class="Delimiter">(</span>!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>initialized<span class="Delimiter">);</span> + routine* new_routine = new routine<span class="Delimiter">(</span>Recipe_number[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>name]<span class="Delimiter">);</span> +<span class="CommentedCode">//? cerr << new_routine->id << " -> " << Current_routine->id << '\n'; //? 1</span> + new_routine<span class="Delimiter">-></span>parent_index = Current_routine_index<span class="Delimiter">;</span> <span class="Comment">// populate ingredients</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">1</span><span class="Delimiter">;</span> i < current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> - new_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[i]<span class="Delimiter">));</span> + new_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> Routines<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new_routine<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new_routine<span class="Delimiter">-></span>id<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<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>new_routine<span class="Delimiter">-></span>id<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario scheduler_runs_single_routine)</span> <span class="Special">% Scheduling_interval = 1;</span> recipe f1 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+schedule: f1</span> <span class="traceContains">+run: instruction f1/0</span> @@ -174,12 +201,12 @@ recipe f1 [ <span class="Special">% Scheduling_interval = 1;</span> recipe f1 [ start-running f2:recipe - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] recipe f2 [ - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">4</span>:literal - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">4</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">4</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">4</span>:literal ] <span class="traceContains">+schedule: f1</span> <span class="traceContains">+run: instruction f1/0</span> @@ -195,34 +222,38 @@ recipe f2 [ <span class="Delimiter">:(scenario start_running_takes_args)</span> recipe f1 [ start-running f2:recipe<span class="Delimiter">,</span> <span class="Constant">3</span>:literal + <span class="Comment"># wait for f2 to run</span> + <span class="Delimiter">{</span> + jump-unless <span class="Constant">1</span>:number<span class="Delimiter">,</span> -<span class="Constant">1</span>:literal + <span class="Delimiter">}</span> ] recipe f2 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>next-ingredient - <span class="Constant">2</span>:integer<span class="Special"> <- </span>add <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">1</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>next-ingredient + <span class="Constant">2</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] <span class="traceContains">+mem: storing 4 in location 2</span> <span class="Delimiter">:(scenario start_running_returns_routine_id)</span> recipe f1 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>start-running f2:recipe + <span class="Constant">1</span>:number<span class="Special"> <- </span>start-running f2:recipe ] recipe f2 [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">44</span>:literal + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">44</span>:literal ] <span class="traceContains">+mem: storing 2 in location 1</span> <span class="Delimiter">:(scenario scheduler_skips_completed_routines)</span> <span class="Comment"># this scenario will require some careful setup in escaped C++</span> <span class="Comment"># (straining our tangle capabilities to near-breaking point)</span> -<span class="Special">% recipe_number f1 = load("recipe f1 [\n1:integer <- copy 0:literal\n]").front();</span> -<span class="Special">% recipe_number f2 = load("recipe f2 [\n2:integer <- copy 0:literal\n]").front();</span> +<span class="Special">% recipe_number f1 = load("recipe f1 [\n1:number <- copy 0:literal\n]").front();</span> +<span class="Special">% recipe_number f2 = load("recipe f2 [\n2:number <- copy 0:literal\n]").front();</span> <span class="Special">% Routines.push_back(new routine(f1)); // f1 meant to run</span> <span class="Special">% Routines.push_back(new routine(f2));</span> <span class="Special">% Routines.back()->state = COMPLETED; // f2 not meant to run</span> <span class="CommentedCode">#? % Trace_stream->dump_layer = "all";</span> <span class="Comment"># must have at least one routine without escaping</span> recipe f3 [ - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="Comment"># by interleaving '+' lines with '-' lines, we allow f1 and f3 to run in any order</span> <span class="traceContains">+schedule: f1</span> @@ -236,24 +267,66 @@ recipe f3 [ <span class="Special">% Routines.push_back(new routine(COPY));</span> <span class="Special">% Routines.back()->state = COMPLETED;</span> recipe f1 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+schedule: f1</span> <span class="traceAbsent">-run: idle</span> +<span class="SalientComment">//:: Routines are marked completed when their parent completes.</span> + +<span class="Delimiter">:(scenario scheduler_kills_orphans)</span> +recipe main [ + start-running f1:recipe + <span class="Comment"># f1 never actually runs because its parent completes without waiting for it</span> +] +recipe f1 [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +] +<span class="traceAbsent">-schedule: f1</span> + +<span class="Delimiter">:(before "End Scheduler Cleanup")</span> +<span class="CommentedCode">//? trace("schedule") << "Before cleanup"; //? 1</span> +<span class="CommentedCode">//? for (index_t i = 0; i < Routines.size(); ++i) { //? 1</span> +<span class="CommentedCode">//? trace("schedule") << i << ": " << Routines.at(i)->id << ' ' << Routines.at(i)->state << ' ' << Routines.at(i)->parent_index << ' ' << Routines.at(i)->state; //? 1</span> +<span class="CommentedCode">//? } //? 1</span> +for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state == COMPLETED<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>parent_index < <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// root thread</span> +<span class="CommentedCode">//? trace("schedule") << "AAA " << i; //? 1</span> + if <span class="Delimiter">(</span>has_completed_parent<span class="Delimiter">(</span>i<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? trace("schedule") << "BBB " << i; //? 1</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state = COMPLETED<span class="Delimiter">;</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> +<span class="CommentedCode">//? trace("schedule") << "After cleanup"; //? 1</span> +<span class="CommentedCode">//? for (index_t i = 0; i < Routines.size(); ++i) { //? 1</span> +<span class="CommentedCode">//? trace("schedule") << i << ": " << Routines.at(i)->id << ' ' << Routines.at(i)->state << ' ' << Routines.at(i)->parent_index << ' ' << Routines.at(i)->state; //? 1</span> +<span class="CommentedCode">//? } //? 1</span> + +<span class="Delimiter">:(code)</span> +bool has_completed_parent<span class="Delimiter">(</span>index_t routine_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? trace("schedule") << "CCC " << routine_index << '\n'; //? 2</span> + for <span class="Delimiter">(</span>long long int j = routine_index<span class="Delimiter">;</span> j >= <span class="Constant">0</span><span class="Delimiter">;</span> j = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)-></span>parent_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? trace("schedule") << "DDD " << j << '\n'; //? 2</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)-></span>state == COMPLETED<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> + <span class="SalientComment">//:: 'routine-state' can tell if a given routine id is running</span> <span class="Delimiter">:(scenario routine_state_test)</span> <span class="Special">% Scheduling_interval = 2;</span> recipe f1 [ - <span class="Constant">1</span>:integer/child-id<span class="Special"> <- </span>start-running f2:recipe - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Comment"># race condition since we don't care about location 12</span> + <span class="Constant">1</span>:number/child-id<span class="Special"> <- </span>start-running f2:recipe + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Comment"># race condition since we don't care about location 12</span> <span class="Comment"># thanks to Scheduling_interval, f2's one instruction runs in between here and completes</span> - <span class="Constant">2</span>:integer/state<span class="Special"> <- </span>routine-state <span class="Constant">1</span>:integer/child-id + <span class="Constant">2</span>:number/state<span class="Special"> <- </span>routine-state <span class="Constant">1</span>:number/child-id ] recipe f2 [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Comment"># trying to run a second instruction marks routine as completed</span> ] <span class="Comment"># recipe f2 should be in state COMPLETED</span> @@ -265,15 +338,65 @@ ROUTINE_STATE<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"routine-state"</span>] = ROUTINE_STATE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case ROUTINE_STATE: <span class="Delimiter">{</span> - vector<long long int> result<span class="Delimiter">;</span> - index_t id = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">)</span>[<span class="Constant">0</span>]<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// routine id must be scalar</span> + index_t id = 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 result = -<span class="Constant">1</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Routines[i]<span class="Delimiter">-></span>id == id<span class="Delimiter">)</span> <span class="Delimiter">{</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Routines[i]<span class="Delimiter">-></span>state<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id == id<span class="Delimiter">)</span> <span class="Delimiter">{</span> + result = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state<span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</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>result<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="SalientComment">//:: miscellaneous helpers</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +RESTART<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"restart"</span>] = RESTART<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case RESTART: <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// routine id must be scalar</span> + index_t id = 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> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id == id<span class="Delimiter">)</span> <span class="Delimiter">{</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state = RUNNING<span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</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 Declarations")</span> +STOP<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"stop"</span>] = STOP<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case STOP: <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// routine id must be scalar</span> + index_t id = 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> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id == id<span class="Delimiter">)</span> <span class="Delimiter">{</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state = COMPLETED<span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</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 Declarations")</span> +_DUMP_ROUTINES<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"$dump-routines"</span>] = _DUMP_ROUTINES<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case _DUMP_ROUTINES: <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + cerr << i << <span class="Constant">": "</span> << Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id << <span class="Constant">' '</span> << Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state << <span class="Constant">' '</span> << Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>parent_index << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> diff --git a/html/039wait.cc.html b/html/039wait.cc.html index feb7e536..687cd207 100644 --- a/html/039wait.cc.html +++ b/html/039wait.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 039wait.cc</title> +<title>~/Desktop/s/mu/039wait.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,11 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } +.Identifier { color: #008080; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } -.Identifier { color: #008080; } +.CommentedCode { color: #6c6c6c; } .traceContains { color: #008000; } --> </style> @@ -38,14 +39,14 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario wait_for_location)</span> recipe f1 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal start-running f2:recipe - wait-for-location <span class="Constant">1</span>:integer + wait-for-location <span class="Constant">1</span>:number <span class="Comment"># now wait for f2 to run and modify location 1 before using its value</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:integer + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] recipe f2 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal ] <span class="Comment"># if we got the synchronization wrong we'd be storing 0 in location 2</span> <span class="traceContains">+mem: storing 34 in location 2</span> @@ -57,9 +58,9 @@ WAITING<span class="Delimiter">,</span> <span class="Delimiter">:(before "End routine Fields")</span> <span class="Comment">// only if state == WAITING</span> index_t waiting_on_location<span class="Delimiter">;</span> -int old_value_of_wating_location<span class="Delimiter">;</span> +int old_value_of_waiting_location<span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Constructor")</span> -waiting_on_location = old_value_of_wating_location = <span class="Constant">0</span><span class="Delimiter">;</span> +waiting_on_location = old_value_of_waiting_location = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">//: primitive recipe to put routines in that state</span> @@ -69,11 +70,12 @@ WAIT_FOR_LOCATION<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"wait-for-location"</span>] = WAIT_FOR_LOCATION<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case WAIT_FOR_LOCATION: <span class="Delimiter">{</span> - reagent loc = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> + reagent loc = canonize<span class="Delimiter">(</span>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> Current_routine<span class="Delimiter">-></span>state = WAITING<span class="Delimiter">;</span> Current_routine<span class="Delimiter">-></span>waiting_on_location = loc<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - Current_routine<span class="Delimiter">-></span>old_value_of_wating_location = Memory[loc<span class="Delimiter">.</span>value]<span class="Delimiter">;</span> + Current_routine<span class="Delimiter">-></span>old_value_of_waiting_location = Memory[loc<span class="Delimiter">.</span>value]<span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"waiting for location "</span> << loc<span class="Delimiter">.</span>value << <span class="Constant">" to change from "</span> << Memory[loc<span class="Delimiter">.</span>value]<span class="Delimiter">;</span> +<span class="CommentedCode">//? trace("schedule") << Current_routine->id << ": waiting for location " << loc.value << " to change from " << Memory[loc.value]; //? 2</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -81,28 +83,38 @@ case WAIT_FOR_LOCATION: <span class="Delimiter">{</span> <span class="Delimiter">:(before "End Scheduler State Transitions")</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Routines[i]<span class="Delimiter">-></span>state != WAITING<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>Memory[Routines[i]<span class="Delimiter">-></span>waiting_on_location] && - Memory[Routines[i]<span class="Delimiter">-></span>waiting_on_location] != Routines[i]<span class="Delimiter">-></span>old_value_of_wating_location<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? trace("schedule") << "wake up loop 1: routine " << Routines.at(i)->id << " has state " << Routines.at(i)->state; //? 1</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state != WAITING<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span class="CommentedCode">//? trace("schedule") << "waiting on location: " << Routines.at(i)->waiting_on_location; //? 1</span> +<span class="CommentedCode">//? if (Routines.at(i)->waiting_on_location) //? 2</span> +<span class="CommentedCode">//? trace("schedule") << "checking routine " << Routines.at(i)->id << " waiting on location " //? 2</span> +<span class="CommentedCode">//? << Routines.at(i)->waiting_on_location << ": " << Memory[Routines.at(i)->waiting_on_location] << " vs " << Routines.at(i)->old_value_of_waiting_location; //? 2</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_location && + Memory[Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_location] != Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>old_value_of_waiting_location<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"schedule"</span><span class="Delimiter">)</span> << <span class="Constant">"waking up routine</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - Routines[i]<span class="Delimiter">-></span>state = RUNNING<span class="Delimiter">;</span> - Routines[i]<span class="Delimiter">-></span>waiting_on_location = Routines[i]<span class="Delimiter">-></span>old_value_of_wating_location = <span class="Constant">0</span><span class="Delimiter">;</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state = RUNNING<span class="Delimiter">;</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_location = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>old_value_of_waiting_location = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Comment">//: also allow waiting on a routine</span> +<span class="Comment">//: also allow waiting on a routine to stop running</span> <span class="Delimiter">:(scenario wait_for_routine)</span> recipe f1 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer/routine<span class="Special"> <- </span>start-running f2:recipe - wait-for-routine <span class="Constant">2</span>:integer/routine + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">12</span>:number/routine<span class="Special"> <- </span>start-running f2:recipe + wait-for-routine <span class="Constant">12</span>:number/routine <span class="Comment"># now wait for f2 to run and modify location 1 before using its value</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:integer + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] recipe f2 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal ] +<span class="traceContains">+schedule: f1</span> +<span class="traceContains">+run: waiting for routine 2</span> +<span class="traceContains">+schedule: f2</span> +<span class="traceContains">+schedule: waking up routine 1</span> +<span class="traceContains">+schedule: f1</span> <span class="Comment"># if we got the synchronization wrong we'd be storing 0 in location 3</span> <span class="traceContains">+mem: storing 34 in location 3</span> @@ -118,28 +130,58 @@ WAIT_FOR_ROUTINE<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"wait-for-routine"</span>] = WAIT_FOR_ROUTINE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case WAIT_FOR_ROUTINE: <span class="Delimiter">{</span> - reagent loc = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> Current_routine<span class="Delimiter">-></span>state = WAITING<span class="Delimiter">;</span> - Current_routine<span class="Delimiter">-></span>waiting_on_routine = loc<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"waiting for routine "</span> << loc<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + Current_routine<span class="Delimiter">-></span>waiting_on_routine = 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> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"waiting for routine "</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> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Scheduler State Transitions")</span> +<span class="Comment">// Wake up any routines waiting for other routines to go to sleep.</span> +<span class="Comment">// Important: this must come after the scheduler loop above giving routines</span> +<span class="Comment">// waiting for locations to change a chance to wake up.</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Routines[i]<span class="Delimiter">-></span>state != WAITING<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!Routines[i]<span class="Delimiter">-></span>waiting_on_routine<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - index_t id = Routines[i]<span class="Delimiter">-></span>waiting_on_routine<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>id != i<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state != WAITING<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_routine<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + index_t id = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_routine<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>id != Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id<span class="Delimiter">);</span> for <span class="Delimiter">(</span>index_t j = <span class="Constant">0</span><span class="Delimiter">;</span> j < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Routines[j]<span class="Delimiter">-></span>id == id && Routines[j]<span class="Delimiter">-></span>state != WAITING<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"schedule"</span><span class="Delimiter">)</span> << <span class="Constant">"waking up routine</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - Routines[i]<span class="Delimiter">-></span>state = RUNNING<span class="Delimiter">;</span> - Routines[i]<span class="Delimiter">-></span>waiting_on_routine = <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)-></span>id == id && Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)-></span>state != RUNNING<span class="Delimiter">)</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"schedule"</span><span class="Delimiter">)</span> << <span class="Constant">"waking up routine "</span> << Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id<span class="Delimiter">;</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state = RUNNING<span class="Delimiter">;</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_routine = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +SWITCH<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"switch"</span>] = SWITCH<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case SWITCH: <span class="Delimiter">{</span> + index_t id = some_other_running_routine<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>id<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>id != Current_routine<span class="Delimiter">-></span>id<span class="Delimiter">);</span> +<span class="CommentedCode">//? cerr << "waiting on " << id << " from " << Current_routine->id << '\n'; //? 1</span> + Current_routine<span class="Delimiter">-></span>state = WAITING<span class="Delimiter">;</span> + Current_routine<span class="Delimiter">-></span>waiting_on_routine = id<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> +index_t some_other_running_routine<span class="Delimiter">()</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i == Current_routine_index<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != Current_routine<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id != Current_routine<span class="Delimiter">-></span>id<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state == RUNNING<span class="Delimiter">)</span> + <span class="Identifier">return</span> Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> </pre> </body> </html> diff --git a/html/040brace.cc.html b/html/040brace.cc.html index 33bb5fed..12ed2c80 100644 --- a/html/040brace.cc.html +++ b/html/040brace.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 040brace.cc</title> +<title>~/Desktop/s/mu/040brace.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -57,7 +57,7 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } recipe main [ <span class="Delimiter">{</span> <span class="Identifier">break</span> - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: recipe main</span> @@ -75,7 +75,7 @@ void transform_braces<span class="Delimiter">(</span>const recipe_number r<span const int OPEN = <span class="Constant">0</span><span class="Delimiter">,</span> CLOSE = <span class="Constant">1</span><span class="Delimiter">;</span> list<pair<int<span class="Comment">/*</span><span class="Comment">OPEN/CLOSE</span><span class="Comment">*/</span><span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">step</span><span class="Comment">*/</span>index_t> > braces<span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t index = <span class="Constant">0</span><span class="Delimiter">;</span> index < Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps[index]<span class="Delimiter">;</span> + const instruction& inst = Recipe[r]<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>label == <span class="Constant">"{"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"brace"</span><span class="Delimiter">)</span> << r << <span class="Constant">": push (open, "</span> << index << <span class="Constant">")"</span><span class="Delimiter">;</span> braces<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<int<span class="Delimiter">,</span>index_t><span class="Delimiter">(</span>OPEN<span class="Delimiter">,</span> index<span class="Delimiter">));</span> @@ -88,7 +88,7 @@ void transform_braces<span class="Delimiter">(</span>const recipe_number r<span stack<<span class="Comment">/*</span><span class="Comment">step</span><span class="Comment">*/</span>index_t> open_braces<span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"recipe "</span> << Recipe[r]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t index = <span class="Constant">0</span><span class="Delimiter">;</span> index < Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps[index]<span class="Delimiter">;</span> + instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> <span class="CommentedCode">//? cout << "AAA " << inst.name << ": " << inst.operation << '\n'; //? 1</span> if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"{"</span><span class="Delimiter">)</span> open_braces<span class="Delimiter">.</span>push<span class="Delimiter">(</span>index<span class="Delimiter">);</span> else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"}"</span><span class="Delimiter">)</span> open_braces<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> @@ -96,83 +96,89 @@ void transform_braces<span class="Delimiter">(</span>const recipe_number r<span <span class="Delimiter">;</span> <span class="Comment">// do nothing</span> else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">0</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">0</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> reagent ing<span class="Delimiter">;</span> ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">()</span>-index<span class="Delimiter">);</span> + ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << index << <span class="Constant">": "</span> << ing<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << index << <span class="Constant">": "</span> << Recipe[r]<span class="Delimiter">.</span>steps[index]<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << index << <span class="Constant">": "</span> << Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<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="Delimiter">}</span> <span class="Delimiter">}</span> else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">0</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">0</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> reagent ing<span class="Delimiter">;</span> ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>matching_brace<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">(),</span> braces<span class="Delimiter">)</span> - index - <span class="Constant">1</span><span class="Delimiter">);</span> + ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop-if"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-if"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> reagent ing<span class="Delimiter">;</span> ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">()</span>-index<span class="Delimiter">);</span> + ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name << <span class="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if "</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="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break-if"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-if"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> reagent ing<span class="Delimiter">;</span> ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>matching_brace<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">(),</span> braces<span class="Delimiter">)</span> - index - <span class="Constant">1</span><span class="Delimiter">);</span> + ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name << <span class="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if "</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="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop-unless"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> reagent ing<span class="Delimiter">;</span> ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">()</span>-index<span class="Delimiter">);</span> + ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name << <span class="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless "</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="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break-unless"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "AAA break-unless\n"; //? 1</span> inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span> && isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> reagent ing<span class="Delimiter">;</span> ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>matching_brace<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">(),</span> braces<span class="Delimiter">)</span> - index - <span class="Constant">1</span><span class="Delimiter">);</span> + ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name << <span class="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless "</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="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> @@ -218,10 +224,10 @@ Recipe_number[<span class="Constant">"loop-unless"</span>] = LOOP_UNLE <span class="Delimiter">:(scenario loop)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal loop <span class="Delimiter">}</span> ] @@ -233,7 +239,7 @@ recipe main [ <span class="Delimiter">:(scenario break_empty_block)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> <span class="Identifier">break</span> <span class="Delimiter">}</span> @@ -244,7 +250,7 @@ recipe main [ <span class="Delimiter">:(scenario break_cascading)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> <span class="Identifier">break</span> <span class="Delimiter">}</span> @@ -259,11 +265,11 @@ recipe main [ <span class="Delimiter">:(scenario break_cascading2)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> <span class="Identifier">break</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Identifier">break</span> @@ -278,11 +284,11 @@ recipe main [ <span class="Delimiter">:(scenario break_if)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - <span class="Identifier">break</span>-if <span class="Constant">2</span>:integer - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Identifier">break</span>-if <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Identifier">break</span> @@ -297,36 +303,36 @@ recipe main [ <span class="Delimiter">:(scenario break_nested)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Identifier">break</span> <span class="Delimiter">{</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: jump 4:offset</span> <span class="Delimiter">:(scenario break_nested_degenerate)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Identifier">break</span> <span class="Delimiter">{</span> <span class="Delimiter">}</span> - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: jump 3:offset</span> <span class="Delimiter">:(scenario break_nested_degenerate2)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Identifier">break</span> <span class="Delimiter">{</span> <span class="Delimiter">}</span> @@ -335,8 +341,9 @@ recipe main [ <span class="traceContains">+after-brace: jump 2:offset</span> <span class="Delimiter">:(scenario break_label)</span> +<span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> <span class="Identifier">break</span> +foo:offset <span class="Delimiter">}</span> @@ -345,11 +352,11 @@ recipe main [ <span class="Delimiter">:(scenario break_unless)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - <span class="Identifier">break</span>-unless <span class="Constant">2</span>:integer - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Identifier">break</span>-unless <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: recipe main</span> @@ -360,11 +367,11 @@ recipe main [ <span class="Delimiter">:(scenario loop_unless)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - loop-unless <span class="Constant">2</span>:integer - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + loop-unless <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: recipe main</span> @@ -375,14 +382,14 @@ recipe main [ <span class="Delimiter">:(scenario loop_nested)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">{</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> loop-if <span class="Constant">4</span>:boolean - <span class="Constant">5</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: recipe main</span> @@ -390,9 +397,9 @@ recipe main [ <span class="Delimiter">:(scenario loop_label)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +foo - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+after-brace: recipe main</span> <span class="traceContains">+after-brace: copy ...</span> @@ -401,18 +408,19 @@ recipe main [ <span class="Comment">//: test how things actually run</span> <span class="Delimiter">:(scenarios run)</span> <span class="Delimiter">:(scenario brace_conversion_and_run)</span> +<span class="CommentedCode">#? % Trace_stream->dump_layer = "run";</span> recipe test-factorial [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal <span class="Delimiter">{</span> - <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:integer <span class="Constant">1</span>:literal + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>:literal <span class="Identifier">break</span>-if <span class="Constant">3</span>:boolean -<span class="Comment"># $print 1:integer</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>multiply <span class="Constant">2</span>:integer<span class="Delimiter">,</span> <span class="Constant">1</span>:integer - <span class="Constant">1</span>:integer<span class="Special"> <- </span>subtract <span class="Constant">1</span>:integer<span class="Delimiter">,</span> <span class="Constant">1</span>:literal +<span class="Comment"># $print 1:number</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>multiply <span class="Constant">2</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>:number + <span class="Constant">1</span>:number<span class="Special"> <- </span>subtract <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>:literal loop <span class="Delimiter">}</span> - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:integer <span class="Comment"># trigger a read</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:number <span class="Comment"># trigger a read</span> ] <span class="traceContains">+mem: location 2 is 120</span> </pre> diff --git a/html/041name.cc.html b/html/041name.cc.html index 6734c604..18fbd523 100644 --- a/html/041name.cc.html +++ b/html/041name.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 041name.cc</title> +<title>~/Desktop/s/mu/041name.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,15 +14,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } -.Identifier { color: #008080; } -.SalientComment { color: #00ffff; } +.CommentedCode { color: #6c6c6c; } +.traceAbsent { color: #c00000; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } -.CommentedCode { color: #6c6c6c; } +.Identifier { color: #008080; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } -.traceAbsent { color: #c00000; } --> </style> @@ -40,7 +40,7 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario convert_names)</span> recipe main [ - x:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + x:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+name: assign x 1</span> <span class="traceContains">+run: instruction main/0</span> @@ -49,7 +49,7 @@ recipe main [ <span class="Delimiter">:(scenario convert_names_warns)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - x:integer<span class="Special"> <- </span>copy y:integer + x:number<span class="Special"> <- </span>copy y:number ] <span class="traceContains">+warn: use before set: y in main</span> @@ -60,62 +60,57 @@ recipe main [ map<recipe_number<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> index_t> > Name<span class="Delimiter">;</span> <span class="Delimiter">:(after "Clear Other State For recently_added_recipes")</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < recently_added_recipes<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - Name<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>recently_added_recipes[i]<span class="Delimiter">);</span> + Name<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>recently_added_recipes<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> void transform_names<span class="Delimiter">(</span>const recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + bool names_used = <span class="Constant">false</span><span class="Delimiter">;</span> + bool numeric_locations_used = <span class="Constant">false</span><span class="Delimiter">;</span> map<string<span class="Delimiter">,</span> index_t>& names = Name[r]<span class="Delimiter">;</span> <span class="Comment">// store the indices 'used' so far in the map</span> index_t& curr_idx = names[<span class="Constant">""</span>]<span class="Delimiter">;</span> ++curr_idx<span class="Delimiter">;</span> <span class="Comment">// avoid using index 0, benign skip in some other cases</span> -<span class="CommentedCode">//? cout << "Recipe " << r << ": " << Recipe[r].name << '\n'; //? 3</span> -<span class="CommentedCode">//? cout << Recipe[r].steps.size() << '\n'; //? 2</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "instruction " << i << '\n'; //? 2</span> - instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps[i]<span class="Delimiter">;</span> + instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Comment">// Per-recipe Transforms</span> <span class="Comment">// map names to addresses</span> for <span class="Delimiter">(</span>index_t in = <span class="Constant">0</span><span class="Delimiter">;</span> in < inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++in<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "ingredients\n"; //? 2</span> - if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span class="CommentedCode">//? cout << "ingredient " << inst.ingredients[in].name << '\n'; //? 3</span> -<span class="CommentedCode">//? cout << "ingredient " << inst.ingredients[in].to_string() << '\n'; //? 1</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> - inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> - raise << <span class="Constant">"missing type in "</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>types[<span class="Constant">0</span>] <span class="Comment">// not a literal</span> - && !inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>initialized - && !is_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>!already_transformed<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">,</span> names<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"use before set: "</span> << inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>name << <span class="Constant">" in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>lookup_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[in]<span class="Delimiter">,</span> r<span class="Delimiter">));</span> -<span class="CommentedCode">//? cout << "lookup ingredient " << Recipe[r].name << "/" << i << ": " << inst.ingredients[in].to_string() << '\n'; //? 1</span> + if <span class="Delimiter">(</span>is_numeric_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">)))</span> numeric_locations_used = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_named_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">)))</span> names_used = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!already_transformed<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> names<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"use before set: "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">).</span>name << <span class="Constant">" in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>lookup_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> r<span class="Delimiter">));</span> <span class="Delimiter">}</span> for <span class="Delimiter">(</span>index_t out = <span class="Constant">0</span><span class="Delimiter">;</span> out < inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++out<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "products\n"; //? 1</span> - if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span class="CommentedCode">//? cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 4</span> -<span class="CommentedCode">//? cout << inst.products[out].types[0] << '\n'; //? 1</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> - inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>types[<span class="Constant">0</span>] <span class="Comment">// not a literal</span> - && !inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>initialized - && !is_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>name<span class="Delimiter">)</span> == names<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"assign "</span> << inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>name << <span class="Constant">" "</span> << curr_idx<span class="Delimiter">;</span> - names[inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>name] = curr_idx<span class="Delimiter">;</span> - curr_idx += size_of<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">);</span> - <span class="Delimiter">}</span> - inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>lookup_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[out]<span class="Delimiter">,</span> r<span class="Delimiter">));</span> -<span class="CommentedCode">//? cout << "lookup product " << Recipe[r].name << "/" << i << ": " << inst.products[out].to_string() << '\n'; //? 1</span> + if <span class="Delimiter">(</span>is_numeric_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">)))</span> numeric_locations_used = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_named_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">)))</span> names_used = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name<span class="Delimiter">)</span> == names<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"assign "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name << <span class="Constant">" "</span> << curr_idx<span class="Delimiter">;</span> + names[inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name] = curr_idx<span class="Delimiter">;</span> + curr_idx += size_of<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">));</span> <span class="Delimiter">}</span> + inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>lookup_name<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">),</span> r<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>names_used && numeric_locations_used<span class="Delimiter">)</span> + raise << <span class="Constant">"mixing variable names and numeric addresses in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +bool disqualified<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">mutable</span><span class="Comment">*/</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + raise << <span class="Constant">"missing type in "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>!x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_number<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> + x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> bool already_transformed<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> index_t>& names<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -128,7 +123,7 @@ index_t lookup_name<span class="Delimiter">(</span>const reagent& r<span cla type_number skip_addresses<span class="Delimiter">(</span>const vector<type_number>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < types<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>types[i] != Type_number[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Identifier">return</span> types[i]<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != Type_number[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Identifier">return</span> types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Delimiter">}</span> raise << <span class="Constant">"expected a container"</span> << <span class="cSpecial">'\n'</span> << die<span class="Delimiter">();</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> @@ -138,23 +133,48 @@ int find_element_name<span class="Delimiter">(</span>const type_number t<span cl const type_info& container = Type[t]<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << "looking for element " << name << " in type " << container.name << " with " << container.element_names.size() << " elements\n"; //? 1</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < container<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>container<span class="Delimiter">.</span>element_names[i] == name<span class="Delimiter">)</span> <span class="Identifier">return</span> i<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>container<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == name<span class="Delimiter">)</span> <span class="Identifier">return</span> i<span class="Delimiter">;</span> <span class="Delimiter">}</span> raise << <span class="Constant">"unknown element "</span> << name << <span class="Constant">" in container "</span> << t << <span class="cSpecial">'\n'</span> << die<span class="Delimiter">();</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> +bool is_numeric_location<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// used for chaining lexical scopes</span> + <span class="Identifier">return</span> is_number<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +bool is_named_location<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_special_name<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> !is_number<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + bool is_raw<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>index_t i = <span class="Comment">/*</span><span class="Comment">skip value+type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties[i]<span class="Delimiter">.</span>first == <span class="Constant">"raw"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"raw"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> +bool is_special_name<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>s == <span class="Constant">"_"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Comment">// lexical scopes</span> + if <span class="Delimiter">(</span>s == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>s == <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Comment">// tests will use these in later layers even though tests will mostly use numeric addresses</span> + if <span class="Delimiter">(</span>s == <span class="Constant">"screen"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>s == <span class="Constant">"keyboard"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + <span class="Delimiter">:(scenario convert_names_passes_dummy)</span> <span class="Comment"># _ is just a dummy result that never gets consumed</span> recipe main [ - _<span class="Delimiter">,</span> x:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + _<span class="Delimiter">,</span> x:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] <span class="traceContains">+name: assign x 1</span> <span class="traceAbsent">-name: assign _ 1</span> @@ -162,7 +182,7 @@ recipe main [ <span class="Comment">//: one reserved word that we'll need later</span> <span class="Delimiter">:(scenario convert_names_passes_default_space)</span> recipe main [ - default-space:integer<span class="Delimiter">,</span> x:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + default-space:number<span class="Delimiter">,</span> x:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] <span class="traceContains">+name: assign x 1</span> <span class="traceAbsent">-name: assign default-space 1</span> @@ -170,10 +190,46 @@ recipe main [ <span class="Comment">//: an escape hatch to suppress name conversion that we'll use later</span> <span class="Delimiter">:(scenario convert_names_passes_raw)</span> recipe main [ - x:integer/<span class="Special">raw <- </span>copy <span class="Constant">0</span>:literal + x:number/<span class="Special">raw <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceAbsent">-name: assign x 1</span> +<span class="Delimiter">:(scenario convert_names_warns_when_mixing_names_and_numeric_locations)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number +] +<span class="traceContains">+warn: mixing variable names and numeric addresses in main</span> + +<span class="Delimiter">:(scenario convert_names_warns_when_mixing_names_and_numeric_locations2)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy x:number +] +<span class="traceContains">+warn: mixing variable names and numeric addresses in main</span> + +<span class="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_names_and_raw_locations)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number/<span class="Special">raw</span> +] +<span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</span> + +<span class="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_names_and_literals)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal +] +<span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</span> + +<span class="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_special_names_and_numeric_locations)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + screen:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number +] +<span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</span> + <span class="SalientComment">//:: Support element names for containers in 'get' and 'get-address'.</span> <span class="Comment">//: update our running example container for the next test</span> @@ -182,8 +238,9 @@ Type[point]<span class="Delimiter">.</span>element_names<span class="Delimiter"> Type[point]<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"y"</span><span class="Delimiter">);</span> <span class="Delimiter">:(scenario convert_names_transforms_container_elements)</span> recipe main [ - a:integer<span class="Special"> <- </span>get <span class="Constant">0</span>:point<span class="Delimiter">,</span> y:offset - b:integer<span class="Special"> <- </span>get <span class="Constant">0</span>:point<span class="Delimiter">,</span> x:offset + p:address:point<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Comment"># unsafe</span> + a:number<span class="Special"> <- </span>get p:address:point/deref<span class="Delimiter">,</span> y:offset + b:number<span class="Special"> <- </span>get p:address:point/deref<span class="Delimiter">,</span> x:offset ] <span class="traceContains">+name: element y of type point is at offset 1</span> <span class="traceContains">+name: element x of type point is at offset 0</span> @@ -194,13 +251,13 @@ if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"get-address"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// at least 2 args, and second arg is offset</span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> >= <span class="Constant">2</span><span class="Delimiter">);</span> -<span class="CommentedCode">//? cout << inst.ingredients[1].to_string() << '\n'; //? 1</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span class="CommentedCode">//? cout << inst.ingredients.at(1).to_string() << '\n'; //? 1</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)));</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// since first non-address in base type must be a container, we don't have to canonize</span> - type_number base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>types<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"element "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name << <span class="Constant">" of type "</span> << Type[base_type]<span class="Delimiter">.</span>name << <span class="Constant">" is at offset "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + type_number base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>types<span class="Delimiter">);</span> + inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> + trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"element "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name << <span class="Constant">" of type "</span> << Type[base_type]<span class="Delimiter">.</span>name << <span class="Constant">" is at offset "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>value<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: this test is actually illegal so can't call run</span> @@ -208,7 +265,7 @@ if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation <span class="Delimiter">:(scenario convert_names_handles_containers)</span> recipe main [ a:point<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - b:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + b:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+name: assign a 1</span> <span class="traceContains">+name: assign b 3</span> @@ -218,12 +275,12 @@ recipe main [ <span class="Delimiter">:(scenarios run)</span> <span class="Delimiter">:(scenario maybe_convert_named)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal - <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:integer-or-point<span class="Delimiter">,</span> p:variant + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point<span class="Delimiter">,</span> p:variant ] -<span class="traceContains">+name: variant p of type integer-or-point has tag 1</span> +<span class="traceContains">+name: variant p of type number-or-point has tag 1</span> <span class="traceContains">+mem: storing 13 in location 20</span> <span class="Delimiter">:(after "Per-recipe Transforms")</span> @@ -231,12 +288,12 @@ recipe main [ if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"maybe-convert"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// at least 2 args, and second arg is offset</span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> >= <span class="Constant">2</span><span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)));</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// since first non-address in base type must be an exclusive container, we don't have to canonize</span> - type_number base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>types<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">));</span> - trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"variant "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name << <span class="Constant">" of type "</span> << Type[base_type]<span class="Delimiter">.</span>name << <span class="Constant">" has tag "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + type_number base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>types<span class="Delimiter">);</span> + inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> + trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"variant "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name << <span class="Constant">" of type "</span> << Type[base_type]<span class="Delimiter">.</span>name << <span class="Constant">" has tag "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>value<span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> </body> diff --git a/html/042new.cc.html b/html/042new.cc.html index 0b320546..ad9f4543 100644 --- a/html/042new.cc.html +++ b/html/042new.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 042new.cc</title> +<title>~/Desktop/s/mu/042new.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,12 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .Identifier { color: #008080; } -.SalientComment { color: #00ffff; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } --> </style> @@ -38,9 +38,9 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario new)</span> <span class="Comment"># call new two times with identical arguments; you should get back different results</span> recipe main [ - <span class="Constant">1</span>:address:integer/<span class="Special">raw <- </span>new integer:type - <span class="Constant">2</span>:address:integer/<span class="Special">raw <- </span>new integer:type - <span class="Constant">3</span>:boolean/<span class="Special">raw <- </span>equal <span class="Constant">1</span>:address:integer/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:address:integer/<span class="Special">raw</span> + <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">3</span>:boolean/<span class="Special">raw <- </span>equal <span class="Constant">1</span>:address:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:address:number/<span class="Special">raw</span> ] <span class="traceContains">+mem: storing 0 in location 3</span> @@ -68,12 +68,12 @@ Type_number[<span class="Constant">"type"</span>] = <span class="Const if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"new"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// first arg must be of type 'type'</span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> >= <span class="Constant">1</span><span class="Delimiter">);</span> -<span class="CommentedCode">//? cout << inst.ingredients[0].to_string() << '\n'; //? 1</span> - assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>properties[<span class="Constant">0</span>]<span class="Delimiter">.</span>second[<span class="Constant">0</span>] == <span class="Constant">"type"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>Type_number[inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name]<span class="Delimiter">);</span> +<span class="CommentedCode">//? cout << inst.ingredients.at(0).to_string() << '\n'; //? 1</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)));</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">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>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"type"</span><span class="Delimiter">)</span> <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>Type_number[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> <span class="Delimiter">}</span> - trace<span class="Delimiter">(</span><span class="Constant">"new"</span><span class="Delimiter">)</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name << <span class="Constant">" -> "</span> << inst<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"new"</span><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="Constant">" -> "</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<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="SalientComment">//:: Now implement the primitive recipe.</span> @@ -89,11 +89,11 @@ case NEW: <span class="Delimiter">{</span> size_t array_length = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">{</span> vector<type_number> type<span class="Delimiter">;</span> - type<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>value<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + type<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>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>value<span class="Delimiter">);</span> if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// array</span> - vector<long long int> capacity = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - array_length = capacity[<span class="Constant">0</span>]<span class="Delimiter">;</span> + array_length = 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> trace<span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"array size is "</span> << array_length<span class="Delimiter">;</span> size = array_length*size_of<span class="Delimiter">(</span>type<span class="Delimiter">)</span> + <span class="Comment">/*</span><span class="Comment">space for length</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -104,24 +104,16 @@ case NEW: <span class="Delimiter">{</span> <span class="Delimiter">}</span> <span class="Comment">// compute the resulting location</span> <span class="Comment">// really crappy at the moment</span> - assert<span class="Delimiter">(</span>size <= Initial_memory_per_routine<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>alloc + size >= Current_routine<span class="Delimiter">-></span>alloc_max<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Comment">// waste the remaining space and create a new chunk</span> - Current_routine<span class="Delimiter">-></span>alloc = Memory_allocated_until<span class="Delimiter">;</span> - Memory_allocated_until += Initial_memory_per_routine<span class="Delimiter">;</span> - Current_routine<span class="Delimiter">-></span>alloc_max = Memory_allocated_until<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"new"</span><span class="Delimiter">)</span> << <span class="Constant">"routine allocated memory from "</span> << Current_routine<span class="Delimiter">-></span>alloc << <span class="Constant">" to "</span> << Current_routine<span class="Delimiter">-></span>alloc_max<span class="Delimiter">;</span> - <span class="Delimiter">}</span> + ensure_space<span class="Delimiter">(</span>size<span class="Delimiter">);</span> const index_t result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"new alloc: "</span> << result<span class="Delimiter">;</span> + <span class="Comment">// save result</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 if necessary</span> if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Comment">// initialize array</span> Memory[result] = array_length<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Comment">// write result to memory</span> - vector<long long int> tmp<span class="Delimiter">;</span> - tmp<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> tmp<span class="Delimiter">);</span> <span class="Comment">// bump</span> Current_routine<span class="Delimiter">-></span>alloc += size<span class="Delimiter">;</span> <span class="Comment">// no support for reclaiming memory</span> @@ -129,28 +121,48 @@ case NEW: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> +<span class="Delimiter">:(code)</span> +void ensure_space<span class="Delimiter">(</span>size_t size<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>size <= Initial_memory_per_routine<span class="Delimiter">);</span> +<span class="CommentedCode">//? cout << Current_routine->alloc << " " << Current_routine->alloc_max << " " << size << '\n'; //? 1</span> + if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>alloc + size > Current_routine<span class="Delimiter">-></span>alloc_max<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// waste the remaining space and create a new chunk</span> + Current_routine<span class="Delimiter">-></span>alloc = Memory_allocated_until<span class="Delimiter">;</span> + Memory_allocated_until += Initial_memory_per_routine<span class="Delimiter">;</span> + Current_routine<span class="Delimiter">-></span>alloc_max = Memory_allocated_until<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"new"</span><span class="Delimiter">)</span> << <span class="Constant">"routine allocated memory from "</span> << Current_routine<span class="Delimiter">-></span>alloc << <span class="Constant">" to "</span> << Current_routine<span class="Delimiter">-></span>alloc_max<span class="Delimiter">;</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> + <span class="Delimiter">:(scenario new_array)</span> recipe main [ - <span class="Constant">1</span>:address:array:integer/<span class="Special">raw <- </span>new integer:type<span class="Delimiter">,</span> <span class="Constant">5</span>:literal - <span class="Constant">2</span>:address:integer/<span class="Special">raw <- </span>new integer:type - <span class="Constant">3</span>:integer/<span class="Special">raw <- </span>subtract <span class="Constant">2</span>:address:integer/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:array:integer/<span class="Special">raw</span> + <span class="Constant">1</span>:address:array:number/<span class="Special">raw <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">5</span>:literal + <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">3</span>:number/<span class="Special">raw <- </span>subtract <span class="Constant">2</span>:address:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:array:number/<span class="Special">raw</span> ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+mem: array size is 5</span> <span class="traceContains">+run: instruction main/1</span> <span class="traceContains">+run: instruction main/2</span> +<span class="Comment"># don't forget the extra location for array size</span> <span class="traceContains">+mem: storing 6 in location 3</span> <span class="Comment">//: Make sure that each routine gets a different alloc to start.</span> <span class="Delimiter">:(scenario new_concurrent)</span> recipe f1 [ start-running f2:recipe - <span class="Constant">1</span>:address:integer/<span class="Special">raw <- </span>new integer:type + <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Comment"># wait for f2 to complete</span> + <span class="Delimiter">{</span> + loop-unless <span class="Constant">4</span>:number/<span class="Special">raw</span> + <span class="Delimiter">}</span> ] recipe f2 [ - <span class="Constant">2</span>:address:integer/<span class="Special">raw <- </span>new integer:type + <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span>new number:type <span class="Comment"># hack: assumes scheduler implementation</span> - <span class="Constant">3</span>:boolean/<span class="Special">raw <- </span>equal <span class="Constant">1</span>:address:integer/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:address:integer/<span class="Special">raw</span> + <span class="Constant">3</span>:boolean/<span class="Special">raw <- </span>equal <span class="Constant">1</span>:address:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:address:number/<span class="Special">raw</span> + <span class="Comment"># signal f2 complete</span> + <span class="Constant">4</span>:number/<span class="Special">raw <- </span>copy <span class="Constant">1</span>:literal ] <span class="traceContains">+mem: storing 0 in location 3</span> @@ -158,7 +170,7 @@ recipe f2 [ <span class="Delimiter">:(scenario new_overflow)</span> <span class="Special">% Initial_memory_per_routine = 2;</span> recipe main [ - <span class="Constant">1</span>:address:integer/<span class="Special">raw <- </span>new integer:type + <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span>new number:type <span class="Constant">2</span>:address:point/<span class="Special">raw <- </span>new point:type <span class="Comment"># not enough room in initial page</span> ] <span class="traceContains">+new: routine allocated memory from 1000 to 1002</span> @@ -171,24 +183,37 @@ recipe main [ <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [abc def] <span class="Constant">2</span>:character<span class="Special"> <- </span>index <span class="Constant">1</span>:address:array:character/deref<span class="Delimiter">,</span> <span class="Constant">5</span>:literal ] -<span class="Comment"># integer code for 'e'</span> +<span class="Comment"># number code for 'e'</span> <span class="traceContains">+mem: storing 101 in location 2</span> <span class="Delimiter">:(after "case NEW" following "Primitive Recipe Implementations")</span> -if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>properties[<span class="Constant">0</span>]<span class="Delimiter">.</span>second[<span class="Constant">0</span>] == <span class="Constant">"literal-string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>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> + && 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>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"literal-string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// allocate an array just large enough for it</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> - <span class="Comment">// assume that all characters fit in a single location</span> -<span class="CommentedCode">//? cout << "new string literal: " << current_instruction().ingredients[0].name << '\n'; //? 1</span> - Memory[Current_routine<span class="Delimiter">-></span>alloc++] = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">.</span>size<span class="Delimiter">();</span> - for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - Memory[Current_routine<span class="Delimiter">-></span>alloc++] = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name[i]<span class="Delimiter">;</span> + size_t string_length = 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>name<span class="Delimiter">.</span>size<span class="Delimiter">();</span> +<span class="CommentedCode">//? cout << "string_length is " << string_length << '\n'; //? 1</span> + ensure_space<span class="Delimiter">(</span>string_length+<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// don't forget the extra location for array size</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>Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">);</span> + <span class="Comment">// initialize string</span> +<span class="CommentedCode">//? cout << "new string literal: " << current_instruction().ingredients.at(0).name << '\n'; //? 1</span> + Memory[Current_routine<span class="Delimiter">-></span>alloc++] = string_length<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < string_length<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + Memory[Current_routine<span class="Delimiter">-></span>alloc++] = 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>name<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// mu strings are not null-terminated in memory</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + +<span class="Comment">//: Allocate more to routine when initializing a literal string</span> +<span class="Delimiter">:(scenario new_string_overflow)</span> +<span class="Special">% Initial_memory_per_routine = 2;</span> +recipe main [ + <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span>new number:type + <span class="Constant">2</span>:address:array:character/<span class="Special">raw <- </span>new [a] <span class="Comment"># not enough room in initial page, if you take the array size into account</span> +] +<span class="traceContains">+new: routine allocated memory from 1000 to 1002</span> +<span class="traceContains">+new: routine allocated memory from 1002 to 1004</span> </pre> </body> </html> diff --git a/html/043space.cc.html b/html/043space.cc.html index 3844e879..66e073b3 100644 --- a/html/043space.cc.html +++ b/html/043space.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 043space.cc</title> +<title>~/Desktop/s/mu/043space.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -15,12 +15,12 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } .Identifier { color: #008080; } -.SalientComment { color: #00ffff; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } --> </style> @@ -41,22 +41,22 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment"># if default-space is 10, and if an array of 5 locals lies from location 11 to 15 (inclusive),</span> <span class="Comment"># then location 0 is really location 11, location 1 is really location 12, and so on.</span> recipe main [ - <span class="Constant">10</span>:integer<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># pretend array; in practice we'll use new</span> + <span class="Constant">10</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># pretend array; in practice we'll use new</span> default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>:literal - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal ] <span class="traceContains">+mem: storing 23 in location 12</span> <span class="Delimiter">:(scenario deref_sidesteps_default_space)</span> recipe main [ <span class="Comment"># pretend pointer from outside</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal <span class="Comment"># pretend array</span> - <span class="Constant">1000</span>:integer<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal + <span class="Constant">1000</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># actual start of this function</span> default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span>:literal - <span class="Constant">1</span>:address:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">8</span>:integer/<span class="Special">raw <- </span>copy <span class="Constant">1</span>:address:integer/deref + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal + <span class="Constant">8</span>:number/<span class="Special">raw <- </span>copy <span class="Constant">1</span>:address:number/deref ] <span class="traceContains">+mem: storing 34 in location 8</span> @@ -70,7 +70,7 @@ reagent r = absolutize<span class="Delimiter">(</span>x<span class="Delimiter">) <span class="Delimiter">:(code)</span> reagent absolutize<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? if (Recipe_number.find("increment-counter") != Recipe_number.end()) //? 1</span> -<span class="CommentedCode">//? cout << "AAA " << "increment-counter/2: " << Recipe[Recipe_number["increment-counter"]].steps[2].products[0].to_string() << '\n'; //? 1</span> +<span class="CommentedCode">//? cout << "AAA " << "increment-counter/2: " << Recipe[Recipe_number["increment-counter"]].steps.at(2).products.at(0).to_string() << '\n'; //? 1</span> <span class="CommentedCode">//? cout << "absolutize " << x.to_string() << '\n'; //? 4</span> <span class="CommentedCode">//? cout << is_raw(x) << '\n'; //? 1</span> 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> x<span class="Delimiter">;</span> @@ -91,14 +91,14 @@ result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span> <span class="Delimiter">:(scenario deref_sidesteps_default_space_in_get)</span> recipe main [ <span class="Comment"># pretend pointer to container from outside</span> - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal <span class="Comment"># pretend array</span> - <span class="Constant">1000</span>:integer<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal + <span class="Constant">1000</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># actual start of this function</span> default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span>:literal <span class="Constant">1</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">12</span>:literal - <span class="Constant">9</span>:integer/<span class="Special">raw <- </span>get <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Constant">9</span>:number/<span class="Special">raw <- </span>get <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] <span class="traceContains">+mem: storing 35 in location 9</span> @@ -110,15 +110,15 @@ tmp<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>pus <span class="Delimiter">:(scenario deref_sidesteps_default_space_in_index)</span> recipe main [ <span class="Comment"># pretend pointer to array from outside</span> - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal <span class="Comment"># pretend array</span> - <span class="Constant">1000</span>:integer<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal + <span class="Constant">1000</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># actual start of this function</span> default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span>:literal - <span class="Constant">1</span>:address:array:integer<span class="Special"> <- </span>copy <span class="Constant">12</span>:literal - <span class="Constant">9</span>:integer/<span class="Special">raw <- </span>index <span class="Constant">1</span>:address:array:integer/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:literal + <span class="Constant">1</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">12</span>:literal + <span class="Constant">9</span>:number/<span class="Special">raw <- </span>index <span class="Constant">1</span>:address:array:number/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] <span class="traceContains">+mem: storing 35 in location 9</span> @@ -129,7 +129,7 @@ tmp<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>pus <span class="Delimiter">:(code)</span> index_t space_base<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>default_space<span class="Delimiter">;</span> + <span class="Identifier">return</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>default_space<span class="Delimiter">;</span> <span class="Delimiter">}</span> index_t address<span class="Delimiter">(</span>index_t offset<span class="Delimiter">,</span> index_t base<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -142,25 +142,25 @@ index_t address<span class="Delimiter">(</span>index_t offset<span class="Delimi <span class="Identifier">return</span> base+<span class="Constant">1</span> + offset<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(after "void write_memory(reagent x, vector<long long int> data)")</span> +<span class="Delimiter">:(after "void write_memory(reagent x, vector<double> data)")</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>data<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>default_space = data[<span class="Constant">0</span>]<span class="Delimiter">;</span> -<span class="CommentedCode">//? cout << "AAA " << Current_routine->calls.top().default_space << '\n'; //? 1</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>default_space = data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> +<span class="CommentedCode">//? cout << "AAA " << Current_routine->calls.front().default_space << '\n'; //? 1</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario get_default_space)</span> recipe main [ default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>:literal - <span class="Constant">1</span>:integer/<span class="Special">raw <- </span>copy default-space:address:array:location + <span class="Constant">1</span>:number/<span class="Special">raw <- </span>copy default-space:address:array:location ] <span class="traceContains">+mem: storing 10 in location 1</span> -<span class="Delimiter">:(after "vector<long long int> read_memory(reagent x)")</span> +<span class="Delimiter">:(after "vector<double> read_memory(reagent x)")</span> if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span> + vector<double> result<span class="Delimiter">;</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> diff --git a/html/044space_surround.cc.html b/html/044space_surround.cc.html index fbabca77..fc37c9a1 100644 --- a/html/044space_surround.cc.html +++ b/html/044space_surround.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 044space_surround.cc</title> +<title>~/Desktop/s/mu/044space_surround.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -40,12 +40,12 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario surrounding_space)</span> <span class="Comment"># location 1 in space 1 refers to the space surrounding the default space, here 20.</span> recipe main [ - <span class="Constant">10</span>:integer<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># pretend array</span> - <span class="Constant">20</span>:integer<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># pretend array</span> + <span class="Constant">10</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># pretend array</span> + <span class="Constant">20</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal <span class="Comment"># pretend array</span> default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>:literal <span class="Constant">0</span>:address:array:location/names:dummy<span class="Special"> <- </span>copy <span class="Constant">20</span>:literal <span class="Comment"># later layers will explain the /names: property</span> - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">32</span>:literal - <span class="Constant">1</span>:integer/space:<span class="Constant">1</span><span class="Special"> <- </span>copy <span class="Constant">33</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">32</span>:literal + <span class="Constant">1</span>:number/space:<span class="Constant">1</span><span class="Special"> <- </span>copy <span class="Constant">33</span>:literal ] <span class="traceContains">+run: instruction main/3</span> <span class="traceContains">+mem: storing 20 in location 11</span> @@ -60,7 +60,7 @@ recipe main [ <span class="Delimiter">:(replace{} "index_t space_base(const reagent& x)")</span> index_t space_base<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> space_base<span class="Delimiter">(</span>x<span class="Delimiter">,</span> space_index<span class="Delimiter">(</span>x<span class="Delimiter">),</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span> + <span class="Identifier">return</span> space_base<span class="Delimiter">(</span>x<span class="Delimiter">,</span> space_index<span class="Delimiter">(</span>x<span class="Delimiter">),</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span> <span class="Delimiter">}</span> index_t space_base<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">,</span> index_t space_index<span class="Delimiter">,</span> index_t base<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -76,8 +76,10 @@ index_t space_base<span class="Delimiter">(</span>const reagent& x<span clas index_t space_index<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<span class="Delimiter">.</span>first == <span class="Constant">"space"</span><span class="Delimiter">)</span> - <span class="Identifier">return</span> to_int<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<span class="Delimiter">.</span>second[<span class="Constant">0</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> + assert<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<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> + <span class="Identifier">return</span> to_number<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<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/045closure_name.cc.html b/html/045closure_name.cc.html index 28781bd8..73256e72 100644 --- a/html/045closure_name.cc.html +++ b/html/045closure_name.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 045closure_name.cc</title> +<title>~/Desktop/s/mu/045closure_name.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -43,23 +43,23 @@ recipe main [ <span class="Constant">1</span>:address:array:location/names:init-counter<span class="Special"> <- </span>init-counter <span class="CommentedCode">#? $print [AAAAAAAAAAAAAAAA]</span> <span class="CommentedCode">#? $print 1:address:array:location</span> - <span class="Constant">2</span>:integer/<span class="Special">raw <- </span>increment-counter <span class="Constant">1</span>:address:array:location/names:init-counter - <span class="Constant">3</span>:integer/<span class="Special">raw <- </span>increment-counter <span class="Constant">1</span>:address:array:location/names:init-counter + <span class="Constant">2</span>:number/<span class="Special">raw <- </span>increment-counter <span class="Constant">1</span>:address:array:location/names:init-counter + <span class="Constant">3</span>:number/<span class="Special">raw <- </span>increment-counter <span class="Constant">1</span>:address:array:location/names:init-counter ] recipe init-counter [ default-space:address:array:location<span class="Special"> <- </span>new location:type<span class="Delimiter">,</span> <span class="Constant">30</span>:literal - x:integer<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal - y:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># variable that will be incremented</span> + x:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + y:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># variable that will be incremented</span> reply default-space:address:array:location ] recipe increment-counter [ default-space:address:array:location<span class="Special"> <- </span>new space:literal<span class="Delimiter">,</span> <span class="Constant">30</span>:literal <span class="Constant">0</span>:address:array:location/names:init-counter<span class="Special"> <- </span>next-ingredient <span class="Comment"># outer space must be created by 'init-counter' above</span> - y:integer/space:<span class="Constant">1</span><span class="Special"> <- </span>add y:integer/space:<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span>:literal <span class="Comment"># increment</span> - y:integer<span class="Special"> <- </span>copy <span class="Constant">234</span>:literal <span class="Comment"># dummy</span> - reply y:integer/space:<span class="Constant">1</span> + y:number/space:<span class="Constant">1</span><span class="Special"> <- </span>add y:number/space:<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span>:literal <span class="Comment"># increment</span> + y:number<span class="Special"> <- </span>copy <span class="Constant">234</span>:literal <span class="Comment"># dummy</span> + reply y:number/space:<span class="Constant">1</span> ] <span class="traceContains">+name: recipe increment-counter is surrounded by init-counter</span> @@ -77,23 +77,23 @@ map<recipe_number<span class="Delimiter">,</span> recipe_number> Surroundi <span class="Delimiter">:(code)</span> void collect_surrounding_spaces<span class="Delimiter">(</span>const recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps[i]<span class="Delimiter">;</span> + const instruction& inst = Recipe[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>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t j = <span class="Constant">0</span><span class="Delimiter">;</span> j < inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">.</span>name != <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">.</span>types<span class="Delimiter">.</span>size<span class="Delimiter">()</span> != <span class="Constant">3</span> - || inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">.</span>types[<span class="Constant">0</span>] != Type_number[<span class="Constant">"address"</span>] - || inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">.</span>types[<span class="Constant">1</span>] != Type_number[<span class="Constant">"array"</span>] - || inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">.</span>types[<span class="Constant">2</span>] != Type_number[<span class="Constant">"location"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"slot 0 should always have type address:array:location, but is "</span> << inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>isa_literal<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="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>j<span class="Delimiter">).</span>name != <span class="Constant">"0"</span><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>j<span class="Delimiter">).</span>types<span class="Delimiter">.</span>size<span class="Delimiter">()</span> != <span class="Constant">3</span> + || inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_number[<span class="Constant">"address"</span>] + || inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)</span> != Type_number[<span class="Constant">"array"</span>] + || inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">)</span> != Type_number[<span class="Constant">"location"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"slot 0 should always have type address: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><span class="Delimiter">;</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - vector<string> s = property<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">,</span> <span class="Constant">"names"</span><span class="Delimiter">);</span> + vector<string> 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> if <span class="Delimiter">(</span>s<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << <span class="Constant">"slot 0 requires a /names property in recipe "</span> << Recipe[r]<span class="Delimiter">.</span>name << die<span class="Delimiter">();</span> - if <span class="Delimiter">(</span>s<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> raise << <span class="Constant">"slot 0 should have a single value in /names, got "</span> << inst<span class="Delimiter">.</span>products[j]<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - string surrounding_recipe_name = s[<span class="Constant">0</span>]<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>s<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> raise << <span class="Constant">"slot 0 should have a single value in /names, 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><span class="Delimiter">;</span> + string surrounding_recipe_name = s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> if <span class="Delimiter">(</span>Surrounding_space<span class="Delimiter">.</span>find<span class="Delimiter">(</span>r<span class="Delimiter">)</span> != Surrounding_space<span class="Delimiter">.</span>end<span class="Delimiter">()</span> && Surrounding_space[r] != Recipe_number[surrounding_recipe_name]<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"recipe "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">" can have only one 'surrounding' recipe but has "</span> << Recipe[Surrounding_space[r]]<span class="Delimiter">.</span>name << <span class="Constant">" and "</span> << surrounding_recipe_name << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> @@ -118,7 +118,7 @@ index_t lookup_name<span class="Delimiter">(</span>const reagent& x<span cla <span class="Delimiter">}</span> vector<string> p = property<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">);</span> if <span class="Delimiter">(</span>p<span class="Delimiter">.</span>size<span class="Delimiter">()</span> != <span class="Constant">1</span><span class="Delimiter">)</span> raise << <span class="Constant">"/space property should have exactly one (non-negative integer) value</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - int n = to_int<span class="Delimiter">(</span>p[<span class="Constant">0</span>]<span class="Delimiter">);</span> + int n = to_number<span class="Delimiter">(</span>p<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> assert<span class="Delimiter">(</span>n >= <span class="Constant">0</span><span class="Delimiter">);</span> recipe_number surrounding_recipe = lookup_surrounding_recipe<span class="Delimiter">(</span>default_recipe<span class="Delimiter">,</span> n<span class="Delimiter">);</span> set<recipe_number> done<span class="Delimiter">;</span> @@ -133,9 +133,9 @@ index_t lookup_name<span class="Delimiter">(</span>const reagent& x<span cla if <span class="Delimiter">(</span>done<span class="Delimiter">.</span>find<span class="Delimiter">(</span>r<span class="Delimiter">)</span> != done<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << <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><span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">1</span><span class="Delimiter">;</span> i < path<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << path[i-<span class="Constant">1</span>] << <span class="Constant">" requires computing names of "</span> << path[i] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + raise << 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><span class="Delimiter">;</span> <span class="Delimiter">}</span> - raise << path[path<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span>] << <span class="Constant">" requires computing names of "</span> << r << <span class="Constant">"..ad infinitum</span><span class="cSpecial">\n</span><span class="Constant">"</span> << die<span class="Delimiter">();</span> + raise << path<span class="Delimiter">.</span>at<span class="Delimiter">(</span>path<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> << <span class="Constant">" requires computing names of "</span> << r << <span class="Constant">"..ad infinitum</span><span class="cSpecial">\n</span><span class="Constant">"</span> << die<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> done<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>r<span class="Delimiter">);</span> @@ -161,7 +161,7 @@ bool already_transformed<span class="Delimiter">(</span>const reagent& r<spa if <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> vector<string> p = property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>p<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> - if <span class="Delimiter">(</span>p[<span class="Constant">0</span>] != <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</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="Delimiter">}</span> <span class="Identifier">return</span> names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">)</span> != names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> <span class="Delimiter">}</span> diff --git a/html/046tangle.cc.html b/html/046tangle.cc.html index cd6e296d..cc5a2857 100644 --- a/html/046tangle.cc.html +++ b/html/046tangle.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 046tangle.cc</title> +<title>~/Desktop/s/mu/046tangle.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -37,13 +37,13 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario tangle_before)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +label1 - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] before +label1 [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> @@ -82,7 +82,7 @@ void insert_fragments<span class="Delimiter">(</span>const recipe_number r<span <span class="Comment">// But this way we can't insert into labels created inside before/after.</span> vector<instruction> result<span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - const instruction inst = Recipe[r]<span class="Delimiter">.</span>steps[i]<span class="Delimiter">;</span> + const instruction inst = Recipe[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>is_label<span class="Delimiter">)</span> <span class="Delimiter">{</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>inst<span class="Delimiter">);</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> @@ -96,22 +96,22 @@ void insert_fragments<span class="Delimiter">(</span>const recipe_number r<span <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="CommentedCode">//? for (index_t i = 0; i < result.size(); ++i) { //? 1</span> -<span class="CommentedCode">//? cout << result[i].to_string() << '\n'; //? 1</span> +<span class="CommentedCode">//? cout << result.at(i).to_string() << '\n'; //? 1</span> <span class="CommentedCode">//? } //? 1</span> Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>swap<span class="Delimiter">(</span>result<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario tangle_before_and_after)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +label1 - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] before +label1 [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] after +label1 [ - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> @@ -123,22 +123,22 @@ $mem: <span class="Constant">4</span> <span class="Delimiter">:(scenario tangle_keeps_labels_separate)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +label1 +label2 - <span class="Constant">6</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] before +label1 [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] after +label1 [ - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] before +label2 [ - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] after +label2 [ - <span class="Constant">5</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> @@ -154,21 +154,21 @@ $mem: <span class="Constant">6</span> <span class="Delimiter">:(scenario tangle_stacks_multiple_fragments)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +label1 - <span class="Constant">6</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] before +label1 [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] after +label1 [ - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] before +label1 [ - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] after +label1 [ - <span class="Constant">5</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="Comment"># 'before' fragments stack in order</span> @@ -184,17 +184,17 @@ $mem: <span class="Constant">6</span> <span class="Delimiter">:(scenario tangle_supports_fragments_with_multiple_instructions)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +label1 - <span class="Constant">6</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] before +label1 [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] after +label1 [ - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">5</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> @@ -208,16 +208,16 @@ $mem: <span class="Constant">6</span> <span class="Delimiter">:(scenario tangle_tangles_into_all_labels_with_same_name)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +label1 +label1 - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] before +label1 [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] after +label1 [ - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> diff --git a/html/047jump_label.cc.html b/html/047jump_label.cc.html new file mode 100644 index 00000000..3ff0904a --- /dev/null +++ b/html/047jump_label.cc.html @@ -0,0 +1,146 @@ +<!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>~/Desktop/s/mu/047jump_label.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: #d0d0d0; background-color: #000000; } +body { font-family: monospace; color: #d0d0d0; background-color: #000000; } +* { font-size: 1em; } +.traceAbsent { color: #c00000; } +.Identifier { color: #008080; } +.Constant { color: #008080; } +.Comment { color: #8080ff; } +.Delimiter { color: #c000c0; } +.Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } +.cSpecial { color: #008000; } +.traceContains { color: #008000; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment">//: Support jumps to labels.</span> +<span class="Comment">//: We'll also treat 'break' and 'continue' as jumps. The choice of name is</span> +<span class="Comment">//: just documentation about intent.</span> + +<span class="Delimiter">:(scenario jump_to_label)</span> +recipe main [ + jump +target:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + +target +] +<span class="traceAbsent">-mem: storing 0 in location 1</span> + +<span class="Delimiter">:(after "int main")</span> + Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_labels<span class="Delimiter">);</span> + +<span class="Delimiter">:(code)</span> +void transform_labels<span class="Delimiter">(</span>const recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + map<string<span class="Delimiter">,</span> index_t> offset<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const instruction& inst = Recipe[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> offset[inst<span class="Delimiter">.</span>label] = i<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + instruction& inst = Recipe[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>operation == Recipe_number[<span class="Constant">"jump"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cerr << inst.to_string() << '\n'; //? 1</span> + replace_offset<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> offset<span class="Delimiter">,</span> i<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"jump-if"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + replace_offset<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> offset<span class="Delimiter">,</span> i<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">((</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break"</span>]<span class="Delimiter">)</span> + && inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + replace_offset<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> offset<span class="Delimiter">,</span> i<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">((</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop-if"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop-unless"</span>] + || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break-if"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break-unless"</span>]<span class="Delimiter">)</span> + && inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + replace_offset<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> offset<span class="Delimiter">,</span> i<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(code)</span> +void replace_offset<span class="Delimiter">(</span>reagent& x<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">const</span><span class="Comment">*/</span> map<string<span class="Delimiter">,</span> index_t>& offset<span class="Delimiter">,</span> const index_t current_offset<span class="Delimiter">,</span> const recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cerr << "AAA " << x.to_string() << '\n'; //? 1</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">));</span> +<span class="CommentedCode">//? cerr << "BBB " << x.to_string() << '\n'; //? 1</span> + assert<span class="Delimiter">(</span>!x<span class="Delimiter">.</span>initialized<span class="Delimiter">);</span> +<span class="CommentedCode">//? cerr << "CCC " << x.to_string() << '\n'; //? 1</span> + if <span class="Delimiter">(</span>is_number<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// non-labels will be handled like other number operands</span> +<span class="CommentedCode">//? cerr << "DDD " << x.to_string() << '\n'; //? 1</span> + if <span class="Delimiter">(</span>offset<span class="Delimiter">.</span>find<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">)</span> == offset<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + raise << <span class="Constant">"can't find label "</span> << x<span class="Delimiter">.</span>name << <span class="Constant">" in routine "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</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> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario break_to_label)</span> +recipe main [ +<span class="CommentedCode">#? $print [aaa]</span> + <span class="Delimiter">{</span> + <span class="Delimiter">{</span> + <span class="Identifier">break</span> +target:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + +target +] +<span class="traceAbsent">-mem: storing 0 in location 1</span> + +<span class="Delimiter">:(scenario jump_if_to_label)</span> +recipe main [ + <span class="Delimiter">{</span> + <span class="Delimiter">{</span> + jump-if <span class="Constant">1</span>:literal<span class="Delimiter">,</span> +target:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + +target +] +<span class="traceAbsent">-mem: storing 0 in location 1</span> + +<span class="Delimiter">:(scenario loop_unless_to_label)</span> +recipe main [ + <span class="Delimiter">{</span> + <span class="Delimiter">{</span> + loop-unless <span class="Constant">0</span>:literal<span class="Delimiter">,</span> +target:offset <span class="Comment"># loop/break with a label don't care about braces</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + +target +] +<span class="traceAbsent">-mem: storing 0 in location 1</span> + +<span class="Delimiter">:(scenario jump_runs_code_after_label)</span> +recipe main [ + <span class="Comment"># first a few lines of padding to exercise the offset computation</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + jump +target:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + +target + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal +] +<span class="traceContains">+mem: storing 0 in location 5</span> +<span class="traceAbsent">-mem: storing 0 in location 4</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/050scenario.cc.html b/html/050scenario.cc.html index 9037d68c..b1f294fa 100644 --- a/html/050scenario.cc.html +++ b/html/050scenario.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 050scenario.cc</title> +<title>~/Desktop/s/mu/050scenario.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -15,13 +15,13 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } .CommentedCode { color: #6c6c6c; } +.traceAbsent { color: #c00000; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .Identifier { color: #008080; } .SalientComment { color: #00ffff; } -.traceAbsent { color: #c00000; } .traceContains { color: #008000; } --> </style> @@ -44,7 +44,7 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario scenario_block)</span> scenario foo [ run [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">13</span> @@ -55,13 +55,13 @@ scenario foo [ <span class="Delimiter">:(scenario scenario_multiple_blocks)</span> scenario foo [ run [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">13</span> ] run [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">13</span> @@ -72,7 +72,7 @@ scenario foo [ <span class="Delimiter">:(scenario scenario_check_memory_and_trace)</span> scenario foo [ run [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal trace [a]<span class="Delimiter">,</span> [a b c] ] memory-should-contain [ @@ -124,10 +124,22 @@ time_t mu_time<span class="Delimiter">;</span> time<span class="Delimiter">(</sp 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>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Scenarios<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << Passed << '\n'; //? 1</span> - run_mu_scenario<span class="Delimiter">(</span>Scenarios[i]<span class="Delimiter">);</span> +<span class="CommentedCode">//? cerr << i << ": " << Scenarios.at(i).name << '\n'; //? 3</span> + run_mu_scenario<span class="Delimiter">(</span>Scenarios<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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> +<span class="Comment">//: Convenience: run a single named scenario.</span> +<span class="Delimiter">:(before "Loading Commandline Files")</span> +if <span class="Delimiter">(</span>argc == <span class="Constant">2</span> && Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Scenarios<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Scenarios<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name == argv[<span class="Constant">1</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + run_mu_scenario<span class="Delimiter">(</span>Scenarios<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> + <span class="Delimiter">:(before "End Globals")</span> const scenario* Current_scenario = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> @@ -162,7 +174,7 @@ void run_mu_scenario<span class="Delimiter">(</span>const scenario& s<span c <span class="CommentedCode">#? % Trace_stream->dump_layer = "all";</span> recipe main [ run [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal ] ] <span class="traceContains">+mem: storing 13 in location 1</span> @@ -173,26 +185,26 @@ RUN<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"run"</span>] = RUN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case RUN: <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "recipe " << current_instruction().ingredients[0].name << '\n'; //? 1</span> +<span class="CommentedCode">//? cout << "recipe " << current_instruction().ingredients.at(0).name << '\n'; //? 1</span> ostringstream tmp<span class="Delimiter">;</span> - tmp << <span class="Constant">"recipe run"</span> << Next_recipe_number << <span class="Constant">" [ "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name << <span class="Constant">" ]"</span><span class="Delimiter">;</span> + tmp << <span class="Constant">"recipe run"</span> << Next_recipe_number << <span class="Constant">" [ "</span> << 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>name << <span class="Constant">" ]"</span><span class="Delimiter">;</span> <span class="CommentedCode">//? Show_rest_of_stream = true; //? 1</span> vector<recipe_number> tmp_recipe = load<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>str<span class="Delimiter">());</span> <span class="Comment">// Predefined Scenario Locals In Run.</span> <span class="Comment">// End Predefined Scenario Locals In Run.</span> transform_all<span class="Delimiter">();</span> -<span class="CommentedCode">//? cout << tmp_recipe[0] << ' ' << Recipe_number["main"] << '\n'; //? 1</span> - Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push<span class="Delimiter">(</span>call<span class="Delimiter">(</span>tmp_recipe[<span class="Constant">0</span>]<span class="Delimiter">));</span> +<span class="CommentedCode">//? cout << tmp_recipe.at(0) << ' ' << Recipe_number["main"] << '\n'; //? 1</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>tmp_recipe<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> <span class="Comment">// not done with caller; don't increment current_step_index()</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario run_multiple)</span> recipe main [ run [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal ] run [ - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">13</span>:literal ] ] <span class="traceContains">+mem: storing 13 in location 1</span> @@ -217,8 +229,8 @@ MEMORY_SHOULD_CONTAIN<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"memory-should-contain"</span>] = MEMORY_SHOULD_CONTAIN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MEMORY_SHOULD_CONTAIN: <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << current_instruction().ingredients[0].name << '\n'; //? 1</span> - check_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">);</span> +<span class="CommentedCode">//? cout << current_instruction().ingredients.at(0).name << '\n'; //? 1</span> + check_memory<span class="Delimiter">(</span>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>name<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -235,7 +247,7 @@ void check_memory<span class="Delimiter">(</span>const string& s<span class= check_type<span class="Delimiter">(</span>lhs<span class="Delimiter">,</span> in<span class="Delimiter">);</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - int address = to_int<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> + int address = to_number<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> 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> @@ -257,8 +269,8 @@ 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> - if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[<span class="Constant">0</span>]<span class="Delimiter">.</span>second[<span class="Constant">0</span>] == <span class="Constant">"string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>to_int<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<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>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>to_number<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> assert<span class="Delimiter">(</span>_assign == <span class="Constant">"<-"</span><span class="Delimiter">);</span> @@ -266,8 +278,8 @@ void check_type<span class="Delimiter">(</span>const string& lhs<span class= string literal = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> index_t address = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> <span class="Comment">// exclude quoting brackets</span> - assert<span class="Delimiter">(</span>literal[<span class="Constant">0</span>] == <span class="Constant">'['</span><span class="Delimiter">);</span> literal<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> - assert<span class="Delimiter">(</span>literal[literal<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span>] == <span class="Constant">']'</span><span class="Delimiter">);</span> literal<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>literal<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>*literal<span class="Delimiter">.</span>begin<span class="Delimiter">()</span> == <span class="Constant">'['</span><span class="Delimiter">);</span> literal<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>literal<span class="Delimiter">.</span>begin<span class="Delimiter">());</span> + assert<span class="Delimiter">(</span>*--literal<span class="Delimiter">.</span>end<span class="Delimiter">()</span> == <span class="Constant">']'</span><span class="Delimiter">);</span> literal<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>--literal<span class="Delimiter">.</span>end<span class="Delimiter">());</span> 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> @@ -281,8 +293,8 @@ void check_string<span class="Delimiter">(</span>index_t address<span class="Del ++address<span class="Delimiter">;</span> <span class="Comment">// now skip length</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < literal<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"checking location "</span> << address+i<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>Memory[address+i] != literal[i]<span class="Delimiter">)</span> - raise << <span class="Constant">"expected location "</span> << <span class="Delimiter">(</span>address+i<span class="Delimiter">)</span> << <span class="Constant">" to contain "</span> << literal[i] << <span class="Constant">" but saw "</span> << Memory[address+i] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Memory[address+i] != literal<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> + raise << <span class="Constant">"expected location "</span> << <span class="Delimiter">(</span>address+i<span class="Delimiter">)</span> << <span class="Constant">" to contain "</span> << literal<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> << <span class="Constant">" but saw "</span> << Memory[address+i] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -299,10 +311,10 @@ recipe main [ <span class="Delimiter">:(scenario memory_check_string_length)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">97</span>:literal <span class="Comment"># 'a'</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">98</span>:literal <span class="Comment"># 'b'</span> - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">99</span>:literal <span class="Comment"># 'c'</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">97</span>:literal <span class="Comment"># 'a'</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">98</span>:literal <span class="Comment"># 'b'</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">99</span>:literal <span class="Comment"># 'c'</span> memory-should-contain [ <span class="Constant">1</span>:string<span class="Special"> <- </span>[ab] ] @@ -311,10 +323,10 @@ recipe main [ <span class="Delimiter">:(scenario memory_check_string)</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">97</span>:literal <span class="Comment"># 'a'</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">98</span>:literal <span class="Comment"># 'b'</span> - <span class="Constant">4</span>:integer<span class="Special"> <- </span>copy <span class="Constant">99</span>:literal <span class="Comment"># 'c'</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">97</span>:literal <span class="Comment"># 'a'</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">98</span>:literal <span class="Comment"># 'b'</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">99</span>:literal <span class="Comment"># 'c'</span> memory-should-contain [ <span class="Constant">1</span>:string<span class="Special"> <- </span>[abc] ] @@ -329,6 +341,10 @@ recipe main [ <span class="Comment">// Like runs of contiguous '+' lines, order is important. The trace checks</span> <span class="Comment">// that the lines are present *and* in the specified sequence. (There can be</span> <span class="Comment">// other lines in between.)</span> +<span class="Comment">//</span> +<span class="Comment">// Be careful not to mix setting Hide_warnings and checking the trace in .mu</span> +<span class="Comment">// files. It'll work in C++ scenarios, but the test failure gets silently</span> +<span class="Comment">// hidden in mu scenarios.</span> <span class="Delimiter">:(scenario trace_check_warns_on_failure)</span> <span class="Special">% Hide_warnings = true;</span> @@ -346,7 +362,7 @@ TRACE_SHOULD_CONTAIN<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"trace-should-contain"</span>] = TRACE_SHOULD_CONTAIN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case TRACE_SHOULD_CONTAIN: <span class="Delimiter">{</span> - check_trace<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">);</span> + check_trace<span class="Delimiter">(</span>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>name<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -354,20 +370,25 @@ case TRACE_SHOULD_CONTAIN: <span class="Delimiter">{</span> <span class="Comment">// simplified version of check_trace_contents() that emits warnings rather</span> <span class="Comment">// than just printing to stderr</span> bool check_trace<span class="Delimiter">(</span>const string& expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cerr << "AAA " << expected << '\n'; //? 1</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> vector<pair<string<span class="Delimiter">,</span> string> > expected_lines = parse_trace<span class="Delimiter">(</span>expected<span class="Delimiter">);</span> +<span class="CommentedCode">//? cerr << "BBB " << expected_lines.size() << '\n'; //? 1</span> if <span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> index_t curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> for <span class="Delimiter">(</span>vector<pair<string<span class="Delimiter">,</span> pair<int<span class="Delimiter">,</span> string> > >::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>expected_lines[curr_expected_line]<span class="Delimiter">.</span>first != p<span class="Delimiter">-></span>first<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>expected_lines[curr_expected_line]<span class="Delimiter">.</span>second != p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>second<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>first != p<span class="Delimiter">-></span>first<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>second != p<span class="Delimiter">-></span>second<span class="Delimiter">.</span>second<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// match</span> ++curr_expected_line<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>curr_expected_line == expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr_expected_line == expected_lines<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cerr << "ZZZ\n"; //? 1</span> + <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> - raise << <span class="Constant">"missing ["</span> << expected_lines[curr_expected_line]<span class="Delimiter">.</span>second << <span class="Constant">"] "</span> - << <span class="Constant">"in trace layer "</span> << expected_lines[curr_expected_line]<span class="Delimiter">.</span>first << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + raise << <span class="Constant">"missing ["</span> << expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>second << <span class="Constant">"] "</span> + << <span class="Constant">"in trace layer "</span> << expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>first << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -376,10 +397,10 @@ vector<pair<string<span class="Delimiter">,</span> string> > parse_t vector<string> buf = split<span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> vector<pair<string<span class="Delimiter">,</span> string> > result<span class="Delimiter">;</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < buf<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - buf[i] = trim<span class="Delimiter">(</span>buf[i]<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>buf[i]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - index_t delim = buf[i]<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">": "</span><span class="Delimiter">);</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string><span class="Delimiter">(</span>buf[i]<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> delim<span class="Delimiter">),</span> buf[i]<span class="Delimiter">.</span>substr<span class="Delimiter">(</span>delim+<span class="Constant">2</span><span class="Delimiter">)));</span> + buf<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> = trim<span class="Delimiter">(</span>buf<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + if <span class="Delimiter">(</span>buf<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + index_t delim = buf<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>find<span class="Delimiter">(</span><span class="Constant">": "</span><span class="Delimiter">);</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string><span class="Delimiter">(</span>buf<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> delim<span class="Delimiter">),</span> buf<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>substr<span class="Delimiter">(</span>delim+<span class="Constant">2</span><span class="Delimiter">)));</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -431,7 +452,7 @@ TRACE_SHOULD_NOT_CONTAIN<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"trace-should-not-contain"</span>] = TRACE_SHOULD_NOT_CONTAIN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case TRACE_SHOULD_NOT_CONTAIN: <span class="Delimiter">{</span> - check_trace_missing<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">);</span> + check_trace_missing<span class="Delimiter">(</span>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>name<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -442,8 +463,8 @@ bool check_trace_missing<span class="Delimiter">(</span>const string& in<spa Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> vector<pair<string<span class="Delimiter">,</span> string> > lines = parse_trace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < lines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span>lines[i]<span class="Delimiter">.</span>first<span class="Delimiter">,</span> lines[i]<span class="Delimiter">.</span>second<span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"unexpected ["</span> << lines[i]<span class="Delimiter">.</span>second << <span class="Constant">"] in trace layer "</span> << lines[i]<span class="Delimiter">.</span>first << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span>lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first<span class="Delimiter">,</span> lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"unexpected ["</span> << lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second << <span class="Constant">"] in trace layer "</span> << lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/051scenario_test.mu.html b/html/051scenario_test.mu.html index a0828a86..c71f8c81 100644 --- a/html/051scenario_test.mu.html +++ b/html/051scenario_test.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 051scenario_test.mu</title> +<title>~/Desktop/s/mu/051scenario_test.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -14,7 +14,7 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .Comment { color: #8080ff; } -.Delimiter { color: #c000c0; } +.Constant { color: #008080; } .Special { color: #ff6060; } --> </style> @@ -29,74 +29,74 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <pre id='vimCodeElement'> <span class="Comment"># tests for 'scenario' in previous layer</span> -scenario first_scenario_in_mu <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:integer<span class="Special"> <- </span>add 2:literal, 2:literal - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> +scenario first_scenario_in_mu [ + run [ + 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + ] + memory-should-contain [ 1<span class="Special"> <- </span>4 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario scenario_with_comment_in_mu <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> +scenario scenario_with_comment_in_mu [ + run [ <span class="Comment"># comment</span> - 1:integer<span class="Special"> <- </span>add 2:literal, 2:literal - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + ] + memory-should-contain [ 1<span class="Special"> <- </span>4 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario scenario_with_multiple_comments_in_mu <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> +scenario scenario_with_multiple_comments_in_mu [ + run [ <span class="Comment"># comment1</span> <span class="Comment"># comment2</span> - 1:integer<span class="Special"> <- </span>add 2:literal, 2:literal - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + ] + memory-should-contain [ 1<span class="Special"> <- </span>4 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario check_string_in_memory <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:integer<span class="Special"> <- </span>copy 3:literal - 2:character<span class="Special"> <- </span>copy 97:literal <span class="Comment"># 'a'</span> - 3:character<span class="Special"> <- </span>copy 98:literal <span class="Comment"># 'b'</span> - 4:character<span class="Special"> <- </span>copy 99:literal <span class="Comment"># 'c'</span> - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> - 1:string<span class="Special"> <- </span><span class="Delimiter">[</span>abc<span class="Delimiter">]</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> +scenario check_string_in_memory [ + run [ + 1:number<span class="Special"> <- </span>copy <span class="Constant">3:literal</span> + 2:character<span class="Special"> <- </span>copy <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + 3:character<span class="Special"> <- </span>copy <span class="Constant">98:literal</span> <span class="Comment"># 'b'</span> + 4:character<span class="Special"> <- </span>copy <span class="Constant">99:literal</span> <span class="Comment"># 'c'</span> + ] + memory-should-contain [ + 1:string<span class="Special"> <- </span><span class="Constant">[abc]</span> + ] +] -scenario check_trace <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:integer<span class="Special"> <- </span>add 2:literal, 2:literal - <span class="Delimiter">]</span> - trace-should-contain <span class="Delimiter">[</span> +scenario check_trace [ + run [ + 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + ] + trace-should-contain [ mem: storing 4 in location 1 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario check_trace_negative <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:integer<span class="Special"> <- </span>add 2:literal, 2:literal - <span class="Delimiter">]</span> - trace-should-not-contain <span class="Delimiter">[</span> +scenario check_trace_negative [ + run [ + 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + ] + trace-should-not-contain [ mem: storing 5 in location 1 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario check_trace_instruction <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - trace <span class="Delimiter">[</span>foo<span class="Delimiter">]</span>, <span class="Delimiter">[</span>aaa<span class="Delimiter">]</span> - <span class="Delimiter">]</span> - trace-should-contain <span class="Delimiter">[</span> +scenario check_trace_instruction [ + run [ + trace <span class="Constant">[foo]</span>, <span class="Constant">[aaa]</span> + ] + trace-should-contain [ foo: aaa - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] </pre> </body> </html> diff --git a/html/060string.mu.html b/html/060string.mu.html index 7a494890..193f1463 100644 --- a/html/060string.mu.html +++ b/html/060string.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 060string.mu</title> +<title>~/Desktop/s/mu/060string.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -14,8 +14,9 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .CommentedCode { color: #6c6c6c; } -.Comment { color: #8080ff; } .Delimiter { color: #c000c0; } +.Comment { color: #8080ff; } +.Constant { color: #008080; } .Special { color: #ff6060; } .Identifier { color: #008080; } --> @@ -31,162 +32,160 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <pre id='vimCodeElement'> <span class="Comment"># Some useful helpers for dealing with strings.</span> -recipe string-equal <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe string-equal [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> a:address:array:character<span class="Special"> <- </span>next-ingredient - a-len:integer<span class="Special"> <- </span>length a:address:array:character/deref + a-len:number<span class="Special"> <- </span>length a:address:array:character/deref b:address:array:character<span class="Special"> <- </span>next-ingredient - b-len:integer<span class="Special"> <- </span>length b:address:array:character/deref + b-len:number<span class="Special"> <- </span>length b:address:array:character/deref <span class="Comment"># compare lengths</span> <span class="Delimiter">{</span> - trace <span class="Delimiter">[</span>string-equal<span class="Delimiter">]</span>, <span class="Delimiter">[</span>comparing lengths<span class="Delimiter">]</span> - length-equal?:boolean<span class="Special"> <- </span>equal a-len:integer, b-len:integer + trace <span class="Constant">[string-equal]</span>, <span class="Constant">[comparing lengths]</span> + length-equal?:boolean<span class="Special"> <- </span>equal a-len:number, b-len:number <span class="Identifier">break-if</span> length-equal?:boolean - <span class="Identifier">reply</span> 0:literal + <span class="Identifier">reply</span> <span class="Constant">0:literal</span> <span class="Delimiter">}</span> <span class="Comment"># compare each corresponding character</span> - trace <span class="Delimiter">[</span>string-equal<span class="Delimiter">]</span>, <span class="Delimiter">[</span>comparing characters<span class="Delimiter">]</span> - i:integer<span class="Special"> <- </span>copy 0:literal + trace <span class="Constant">[string-equal]</span>, <span class="Constant">[comparing characters]</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:integer, a-len:integer + done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, a-len:number <span class="Identifier">break-if</span> done?:boolean - a2:character<span class="Special"> <- </span>index a:address:array:character/deref, i:integer - b2:character<span class="Special"> <- </span>index b:address:array:character/deref, i:integer + a2:character<span class="Special"> <- </span>index a:address:array:character/deref, i:number + b2:character<span class="Special"> <- </span>index b:address:array:character/deref, i:number <span class="Delimiter">{</span> chars-match?:boolean<span class="Special"> <- </span>equal a2:character, b2:character <span class="Identifier">break-if</span> chars-match?:boolean - <span class="Identifier">reply</span> 0:literal + <span class="Identifier">reply</span> <span class="Constant">0:literal</span> <span class="Delimiter">}</span> - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> - <span class="Identifier">reply</span> 1:literal -<span class="Delimiter">]</span> + <span class="Identifier">reply</span> <span class="Constant">1:literal</span> +] -scenario string-equal-reflexive <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal - x:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>abc<span class="Delimiter">]</span> +scenario string-equal-reflexive [ + run [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> 3:boolean/<span class="Special">raw <- </span>string-equal x:address:array:character, x:address:array:character - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 3<span class="Special"> <- </span>1 <span class="Comment"># x == x for all x</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario string-equal-identical <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal - x:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>abc<span class="Delimiter">]</span> - y:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>abc<span class="Delimiter">]</span> +scenario string-equal-identical [ + run [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + y:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> 3:boolean/<span class="Special">raw <- </span>string-equal x:address:array:character, y:address:array:character - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 3<span class="Special"> <- </span>1 <span class="Comment"># abc == abc</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario string-equal-distinct-lengths <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal - x:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>abc<span class="Delimiter">]</span> - y:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>abcd<span class="Delimiter">]</span> +scenario string-equal-distinct-lengths [ + run [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + y:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> 3:boolean/<span class="Special">raw <- </span>string-equal x:address:array:character, y:address:array:character - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 3<span class="Special"> <- </span>0 <span class="Comment"># abc != abcd</span> - <span class="Delimiter">]</span> - trace-should-contain <span class="Delimiter">[</span> + ] + trace-should-contain [ string-equal: comparing lengths - <span class="Delimiter">]</span> - trace-should-not-contain <span class="Delimiter">[</span> + ] + trace-should-not-contain [ string-equal: comparing characters - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario string-equal-with-empty <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal - x:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[]</span> - y:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>abcd<span class="Delimiter">]</span> +scenario string-equal-with-empty [ + run [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + y:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> 3:boolean/<span class="Special">raw <- </span>string-equal x:address:array:character, y:address:array:character - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 3<span class="Special"> <- </span>0 <span class="Comment"># "" != abcd</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario string-equal-common-lengths-but-distinct <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal - x:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>abc<span class="Delimiter">]</span> - y:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>abd<span class="Delimiter">]</span> +scenario string-equal-common-lengths-but-distinct [ + run [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + y:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abd]</span> 3:boolean/<span class="Special">raw <- </span>string-equal x:address:array:character, y:address:array:character - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 3<span class="Special"> <- </span>0 <span class="Comment"># abc != abd</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] <span class="Comment"># A new type to help incrementally construct strings.</span> -container buffer <span class="Delimiter">[</span> - length:integer +container buffer [ + length:number data:address:array:character -<span class="Delimiter">]</span> +] -recipe init-buffer <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal -<span class="CommentedCode">#? $print default-space:address:array:location</span> -<span class="CommentedCode">#? $print [</span> +recipe init-buffer [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> +<span class="CommentedCode">#? $print default-space:address:array:location, [</span> <span class="CommentedCode">#? ]</span> result:address:buffer<span class="Special"> <- </span>new buffer:type - len:address:integer<span class="Special"> <- </span>get-address result:address:buffer/deref, length:offset - len:address:integer/deref<span class="Special"> <- </span>copy 0:literal + len:address:number<span class="Special"> <- </span>get-address result:address:buffer/deref, length:offset + len:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> s:address:address:array:character<span class="Special"> <- </span>get-address result:address:buffer/deref, data:offset - capacity:integer<span class="Special"> <- </span>next-ingredient - s:address:address:array:character/deref<span class="Special"> <- </span>new character:type, capacity:integer -<span class="CommentedCode">#? $print s:address:address:array:character/deref</span> -<span class="CommentedCode">#? $print [</span> + capacity:number<span class="Special"> <- </span>next-ingredient + s:address:address:array:character/deref<span class="Special"> <- </span>new character:type, capacity:number +<span class="CommentedCode">#? $print s:address:address:array:character/deref, [</span> <span class="CommentedCode">#? ]</span> <span class="Identifier">reply</span> result:address:buffer -<span class="Delimiter">]</span> +] -recipe grow-buffer <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe grow-buffer [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> in:address:buffer<span class="Special"> <- </span>next-ingredient <span class="Comment"># double buffer size</span> x:address:address:array:character<span class="Special"> <- </span>get-address in:address:buffer/deref, data:offset - oldlen:integer<span class="Special"> <- </span>length x:address:address:array:character/deref/deref - newlen:integer<span class="Special"> <- </span>multiply oldlen:integer, 2:literal + oldlen:number<span class="Special"> <- </span>length x:address:address:array:character/deref/deref + newlen:number<span class="Special"> <- </span>multiply oldlen:number, <span class="Constant">2:literal</span> olddata:address:array:character<span class="Special"> <- </span>copy x:address:address:array:character/deref - x:address:address:array:character/deref<span class="Special"> <- </span>new character:type, newlen:integer + x:address:address:array:character/deref<span class="Special"> <- </span>new character:type, newlen:number <span class="Comment"># copy old contents</span> - i:integer<span class="Special"> <- </span>copy 0:literal + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:integer, oldlen:integer + done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, oldlen:number <span class="Identifier">break-if</span> done?:boolean - src:character<span class="Special"> <- </span>index olddata:address:array:character/deref, i:integer - dest:address:character<span class="Special"> <- </span>index-address x:address:address:array:character/deref/deref, i:integer + src:character<span class="Special"> <- </span>index olddata:address:array:character/deref, i:number + dest:address:character<span class="Special"> <- </span>index-address x:address:address:array:character/deref/deref, i:number dest:address:character/deref<span class="Special"> <- </span>copy src:character - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> in:address:buffer -<span class="Delimiter">]</span> +] -recipe buffer-full? <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe buffer-full? [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> in:address:buffer<span class="Special"> <- </span>next-ingredient - len:integer<span class="Special"> <- </span>get in:address:buffer/deref, length:offset + len:number<span class="Special"> <- </span>get in:address:buffer/deref, length:offset s:address:array:character<span class="Special"> <- </span>get in:address:buffer/deref, data:offset - capacity:integer<span class="Special"> <- </span>length s:address:array:character/deref - result:boolean<span class="Special"> <- </span>greater-or-equal len:integer, capacity:integer + capacity:number<span class="Special"> <- </span>length s:address:array:character/deref + result:boolean<span class="Special"> <- </span>greater-or-equal len:number, capacity:number <span class="Identifier">reply</span> result:boolean -<span class="Delimiter">]</span> +] <span class="Comment"># in:address:buffer <- buffer-append in:address:buffer, c:character</span> -recipe buffer-append <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe buffer-append [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> in:address:buffer<span class="Special"> <- </span>next-ingredient c:character<span class="Special"> <- </span>next-ingredient <span class="Delimiter">{</span> @@ -195,54 +194,47 @@ recipe buffer-append <span class="Delimiter">[</span> <span class="Identifier">break-unless</span> full?:boolean in:address:buffer<span class="Special"> <- </span>grow-buffer in:address:buffer <span class="Delimiter">}</span> - len:address:integer<span class="Special"> <- </span>get-address in:address:buffer/deref, length:offset + len:address:number<span class="Special"> <- </span>get-address in:address:buffer/deref, length:offset s:address:array:character<span class="Special"> <- </span>get in:address:buffer/deref, data:offset - dest:address:character<span class="Special"> <- </span>index-address s:address:array:character/deref, len:address:integer/deref + dest:address:character<span class="Special"> <- </span>index-address s:address:array:character/deref, len:address:number/deref dest:address:character/deref<span class="Special"> <- </span>copy c:character - len:address:integer/deref<span class="Special"> <- </span>add len:address:integer/deref, 1:literal + len:address:number/deref<span class="Special"> <- </span>add len:address:number/deref, <span class="Constant">1:literal</span> <span class="Identifier">reply</span> in:address:buffer/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -scenario buffer-append-works <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal - x:address:buffer<span class="Special"> <- </span>init-buffer 3:literal +scenario buffer-append-works [ + run [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:buffer<span class="Special"> <- </span>init-buffer <span class="Constant">3:literal</span> s1:address:array:character<span class="Special"> <- </span>get x:address:buffer/deref, data:offset - x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, 97:literal <span class="Comment"># 'a'</span> - x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, 98:literal <span class="Comment"># 'b'</span> - x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, 99:literal <span class="Comment"># 'c'</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">98:literal</span> <span class="Comment"># 'b'</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">99:literal</span> <span class="Comment"># 'c'</span> s2:address:array:character<span class="Special"> <- </span>get x:address:buffer/deref, data:offset 1:boolean/<span class="Special">raw <- </span>equal s1:address:array:character, s2:address:array:character -<span class="CommentedCode">#? $print s2:address:array:character</span> -<span class="CommentedCode">#? $print [</span> +<span class="CommentedCode">#? $print s2:address:array:character, [</span> <span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1060:integer/raw</span> -<span class="CommentedCode">#? $print [</span> +<span class="CommentedCode">#? $print 1060:number/raw, [</span> <span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1061:integer/raw</span> -<span class="CommentedCode">#? $print [</span> +<span class="CommentedCode">#? $print 1061:number/raw, [</span> <span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1062:integer/raw</span> -<span class="CommentedCode">#? $print [</span> +<span class="CommentedCode">#? $print 1062:number/raw, [</span> <span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1063:integer/raw</span> -<span class="CommentedCode">#? $print [</span> +<span class="CommentedCode">#? $print 1063:number/raw, [</span> <span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1064:integer/raw</span> -<span class="CommentedCode">#? $print [</span> +<span class="CommentedCode">#? $print 1064:number/raw, [</span> <span class="CommentedCode">#? ]</span> -<span class="CommentedCode">#? $print 1065:integer/raw</span> -<span class="CommentedCode">#? $print [</span> +<span class="CommentedCode">#? $print 1065:number/raw, [</span> <span class="CommentedCode">#? ]</span> 2:array:character/<span class="Special">raw <- </span>copy s2:address:array:character/deref <span class="Identifier"> +buffer-filled</span> - x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, 100:literal <span class="Comment"># 'd'</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">100:literal</span> <span class="Comment"># 'd'</span> s3:address:array:character<span class="Special"> <- </span>get x:address:buffer/deref, data:offset 10:boolean/<span class="Special">raw <- </span>equal s1:address:array:character, s3:address:array:character - 11:integer/<span class="Special">raw <- </span>get x:address:buffer/deref, length:offset + 11:number/<span class="Special">raw <- </span>get x:address:buffer/deref, length:offset 12:array:character/<span class="Special">raw <- </span>copy s3:address:array:character/deref - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ <span class="Comment"># before +buffer-filled</span> 1<span class="Special"> <- </span>1 <span class="Comment"># no change in data pointer</span> 2<span class="Special"> <- </span>3 <span class="Comment"># size of data</span> @@ -259,185 +251,182 @@ scenario buffer-append-works <span class="Delimiter">[</span> 16<span class="Special"> <- </span>100 17<span class="Special"> <- </span>0 18<span class="Special"> <- </span>0 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -<span class="Comment"># result:address:array:character <- integer-to-decimal-string n:integer</span> -recipe integer-to-decimal-string <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal - n:integer<span class="Special"> <- </span>next-ingredient +<span class="Comment"># result:address:array:character <- integer-to-decimal-string n:number</span> +recipe integer-to-decimal-string [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + n:number<span class="Special"> <- </span>next-ingredient <span class="Comment"># is it zero?</span> <span class="Delimiter">{</span> - <span class="Identifier">break-if</span> n:integer - result:address:array:character<span class="Special"> <- </span>new <span class="Delimiter">[</span>0<span class="Delimiter">]</span> + <span class="Identifier">break-if</span> n:number + result:address:array:character<span class="Special"> <- </span>new <span class="Constant">[0]</span> <span class="Identifier">reply</span> result:address:array:character <span class="Delimiter">}</span> <span class="Comment"># save sign</span> - negate-result:boolean<span class="Special"> <- </span>copy 0:literal + negate-result:boolean<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> - negative?:boolean<span class="Special"> <- </span>lesser-than n:integer, 0:literal + negative?:boolean<span class="Special"> <- </span>lesser-than n:number, <span class="Constant">0:literal</span> <span class="Identifier">break-unless</span> negative?:boolean - negate-result:boolean<span class="Special"> <- </span>copy 1:literal - n:integer<span class="Special"> <- </span>multiply n:integer,<span class="Identifier"> -1</span>:literal + negate-result:boolean<span class="Special"> <- </span>copy <span class="Constant">1:literal</span> + n:number<span class="Special"> <- </span>multiply n:number,<span class="Identifier"> -1</span>:literal <span class="Delimiter">}</span> <span class="Comment"># add digits from right to left into intermediate buffer</span> - tmp:address:buffer<span class="Special"> <- </span>init-buffer 30:literal - digit-base:integer<span class="Special"> <- </span>copy 48:literal <span class="Comment"># '0'</span> + tmp:address:buffer<span class="Special"> <- </span>init-buffer <span class="Constant">30:literal</span> + digit-base:number<span class="Special"> <- </span>copy <span class="Constant">48:literal</span> <span class="Comment"># '0'</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>equal n:integer, 0:literal + done?:boolean<span class="Special"> <- </span>equal n:number, <span class="Constant">0:literal</span> <span class="Identifier">break-if</span> done?:boolean - n:integer, digit:integer<span class="Special"> <- </span>divide-with-remainder n:integer, 10:literal - c:character<span class="Special"> <- </span>add digit-base:integer, digit:integer + n:number, digit:number<span class="Special"> <- </span>divide-with-remainder n:number, <span class="Constant">10:literal</span> + c:character<span class="Special"> <- </span>add digit-base:number, digit:number tmp:address:buffer<span class="Special"> <- </span>buffer-append tmp:address:buffer, c:character <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Comment"># add sign</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> negate-result:boolean - tmp:address:buffer<span class="Special"> <- </span>buffer-append tmp:address:buffer, 45:literal <span class="Comment"># '-'</span> + tmp:address:buffer<span class="Special"> <- </span>buffer-append tmp:address:buffer, <span class="Constant">45:literal</span> <span class="Comment"># '-'</span> <span class="Delimiter">}</span> <span class="Comment"># reverse buffer into string result</span> - len:integer<span class="Special"> <- </span>get tmp:address:buffer/deref, length:offset + len:number<span class="Special"> <- </span>get tmp:address:buffer/deref, length:offset buf:address:array:character<span class="Special"> <- </span>get tmp:address:buffer/deref, data:offset - result:address:array:character<span class="Special"> <- </span>new character:type, len:integer - i:integer<span class="Special"> <- </span>subtract len:integer, 1:literal - j:integer<span class="Special"> <- </span>copy 0:literal + result:address:array:character<span class="Special"> <- </span>new character:type, len:number + i:number<span class="Special"> <- </span>subtract len:number, <span class="Constant">1:literal</span> + j:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> <span class="Comment"># while i >= 0</span> - done?:boolean<span class="Special"> <- </span>lesser-than i:integer, 0:literal + done?:boolean<span class="Special"> <- </span>lesser-than i:number, <span class="Constant">0:literal</span> <span class="Identifier">break-if</span> done?:boolean <span class="Comment"># result[j] = tmp[i]</span> - src:character<span class="Special"> <- </span>index buf:address:array:character/deref, i:integer - dest:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, j:integer + src:character<span class="Special"> <- </span>index buf:address:array:character/deref, i:number + dest:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, j:number dest:address:character/deref<span class="Special"> <- </span>copy src:character <span class="Comment"># ++i</span> - i:integer<span class="Special"> <- </span>subtract i:integer, 1:literal + i:number<span class="Special"> <- </span>subtract i:number, <span class="Constant">1:literal</span> <span class="Comment"># --j</span> - j:integer<span class="Special"> <- </span>add j:integer, 1:literal + j:number<span class="Special"> <- </span>add j:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> result:address:array:character -<span class="Delimiter">]</span> +] -scenario integer-to-decimal-digit-zero <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string 0:literal +scenario integer-to-decimal-digit-zero [ + run [ + 1:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string <span class="Constant">0:literal</span> 2:array:character/<span class="Special">raw <- </span>copy 1:address:array:character/deref/<span class="Special">raw</span> - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> - 2:string<span class="Special"> <- </span><span class="Delimiter">[</span>0<span class="Delimiter">]</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] + memory-should-contain [ + 2:string<span class="Special"> <- </span><span class="Constant">[0]</span> + ] +] -scenario integer-to-decimal-digit-positive <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string 234:literal +scenario integer-to-decimal-digit-positive [ + run [ + 1:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string <span class="Constant">234:literal</span> 2:array:character/<span class="Special">raw <- </span>copy 1:address:array:character/deref/<span class="Special">raw</span> - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> - 2:string<span class="Special"> <- </span><span class="Delimiter">[</span>234<span class="Delimiter">]</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] + memory-should-contain [ + 2:string<span class="Special"> <- </span><span class="Constant">[234]</span> + ] +] -scenario integer-to-decimal-digit-negative <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> +scenario integer-to-decimal-digit-negative [ + run [ 1:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string<span class="Identifier"> -1</span>:literal 2:array:character/<span class="Special">raw <- </span>copy 1:address:array:character/deref/<span class="Special">raw</span> - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 2<span class="Special"> <- </span>2 3<span class="Special"> <- </span>45 <span class="Comment"># '-'</span> 4<span class="Special"> <- </span>49 <span class="Comment"># '1'</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -recipe string-append <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe string-append [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> <span class="Comment"># result = new string[a.length + b.length]</span> a:address:array:character<span class="Special"> <- </span>next-ingredient - a-len:integer<span class="Special"> <- </span>length a:address:array:character/deref + a-len:number<span class="Special"> <- </span>length a:address:array:character/deref b:address:array:character<span class="Special"> <- </span>next-ingredient - b-len:integer<span class="Special"> <- </span>length b:address:array:character/deref - result-len:integer<span class="Special"> <- </span>add a-len:integer, b-len:integer - result:address:array:character<span class="Special"> <- </span>new character:type, result-len:integer + b-len:number<span class="Special"> <- </span>length b:address:array:character/deref + result-len:number<span class="Special"> <- </span>add a-len:number, b-len:number + result:address:array:character<span class="Special"> <- </span>new character:type, result-len:number <span class="Comment"># copy a into result</span> - result-idx:integer<span class="Special"> <- </span>copy 0:literal - i:integer<span class="Special"> <- </span>copy 0:literal + result-idx:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> <span class="Comment"># while i < a.length</span> - a-done?:boolean<span class="Special"> <- </span>greater-or-equal i:integer, a-len:integer + a-done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, a-len:number <span class="Identifier">break-if</span> a-done?:boolean <span class="Comment"># result[result-idx] = a[i]</span> - out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:integer - in:character<span class="Special"> <- </span>index a:address:array:character/deref, i:integer + out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:number + in:character<span class="Special"> <- </span>index a:address:array:character/deref, i:number out:address:character/deref<span class="Special"> <- </span>copy in:character <span class="Comment"># ++i</span> - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Comment"># ++result-idx</span> - result-idx:integer<span class="Special"> <- </span>add result-idx:integer, 1:literal + result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Comment"># copy b into result</span> - i:integer<span class="Special"> <- </span>copy 0:literal + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> <span class="Comment"># while i < b.length</span> - b-done?:boolean<span class="Special"> <- </span>greater-or-equal i:integer, b-len:integer + b-done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, b-len:number <span class="Identifier">break-if</span> b-done?:boolean <span class="Comment"># result[result-idx] = a[i]</span> - out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:integer - in:character<span class="Special"> <- </span>index b:address:array:character/deref, i:integer + out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:number + in:character<span class="Special"> <- </span>index b:address:array:character/deref, i:number out:address:character/deref<span class="Special"> <- </span>copy in:character <span class="Comment"># ++i</span> - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Comment"># ++result-idx</span> - result-idx:integer<span class="Special"> <- </span>add result-idx:integer, 1:literal + result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> result:address:array:character -<span class="Delimiter">]</span> +] -scenario string-append-1 <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:array:character/<span class="Special">raw <- </span>new <span class="Delimiter">[</span>hello,<span class="Delimiter">]</span> - 2:address:array:character/<span class="Special">raw <- </span>new <span class="Delimiter">[</span> world!<span class="Delimiter">]</span> +scenario string-append-1 [ + run [ + 1:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[hello,]</span> + 2:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[ world!]</span> 3:address:array:character/<span class="Special">raw <- </span>string-append 1:address:array:character/<span class="Special">raw</span>, 2:address:array:character/<span class="Special">raw</span> 4:array:character/<span class="Special">raw <- </span>copy 3:address:array:character/<span class="Special">raw</span>/deref - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> - 4:string<span class="Special"> <- </span><span class="Delimiter">[</span>hello, world!<span class="Delimiter">]</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] + memory-should-contain [ + 4:string<span class="Special"> <- </span><span class="Constant">[hello, world!]</span> + ] +] <span class="Comment"># replace underscores in first with remaining args</span> <span class="Comment"># result:address:array:character <- interpolate template:address:array:character, ...</span> -recipe interpolate <span class="Delimiter">[</span> - default-space:array:address:location<span class="Special"> <- </span>new location:type, 60:literal +recipe interpolate [ + default-space:array:address:location<span class="Special"> <- </span>new location:type, <span class="Constant">60:literal</span> template:address:array:character<span class="Special"> <- </span>next-ingredient <span class="Comment"># compute result-len, space to allocate for result</span> - tem-len:integer<span class="Special"> <- </span>length template:address:array:character/deref - result-len:integer<span class="Special"> <- </span>copy tem-len:integer + tem-len:number<span class="Special"> <- </span>length template:address:array:character/deref + result-len:number<span class="Special"> <- </span>copy tem-len:number <span class="Delimiter">{</span> <span class="Comment"># while arg received</span> a:address:array:character, arg-received?:boolean<span class="Special"> <- </span>next-ingredient <span class="Identifier">break-unless</span> arg-received?:boolean <span class="Comment"># result-len = result-len + arg.length - 1 for the 'underscore' being replaced</span> - a-len:integer<span class="Special"> <- </span>length a:address:array:character/deref - result-len:integer<span class="Special"> <- </span>add result-len:integer, a-len:integer - result-len:integer<span class="Special"> <- </span>subtract result-len:integer, 1:literal + a-len:number<span class="Special"> <- </span>length a:address:array:character/deref + result-len:number<span class="Special"> <- </span>add result-len:number, a-len:number + result-len:number<span class="Special"> <- </span>subtract result-len:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> -<span class="CommentedCode">#? $print tem-len:integer #? 1</span> -<span class="CommentedCode">#? $print [ ] #? 1</span> -<span class="CommentedCode">#? $print result-len:integer #? 1</span> -<span class="CommentedCode">#? $print [ #? 1</span> +<span class="CommentedCode">#? $print tem-len:number, [ ], $result-len:number, [ </span> <span class="CommentedCode">#? ] #? 1</span> rewind-ingredients _<span class="Special"> <- </span>next-ingredient <span class="Comment"># skip template</span> <span class="Comment"># result = new array:character[result-len]</span> - result:address:array:character<span class="Special"> <- </span>new character:type, result-len:integer + result:address:array:character<span class="Special"> <- </span>new character:type, result-len:number <span class="Comment"># repeatedly copy sections of template and 'holes' into result</span> - result-idx:integer<span class="Special"> <- </span>copy 0:literal - i:integer<span class="Special"> <- </span>copy 0:literal + result-idx:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> <span class="Comment"># while arg received</span> a:address:array:character, arg-received?:boolean<span class="Special"> <- </span>next-ingredient @@ -445,96 +434,96 @@ recipe interpolate <span class="Delimiter">[</span> <span class="Comment"># copy template into result until '_'</span> <span class="Delimiter">{</span> <span class="Comment"># while i < template.length</span> - tem-done?:boolean<span class="Special"> <- </span>greater-or-equal i:integer, tem-len:integer + tem-done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, tem-len:number <span class="Identifier">break-if</span> tem-done?:boolean, 2:blocks <span class="Comment"># while template[i] != '_'</span> - in:character<span class="Special"> <- </span>index template:address:array:character/deref, i:integer - underscore?:boolean<span class="Special"> <- </span>equal in:character, 95:literal <span class="Comment"># '_'</span> + in:character<span class="Special"> <- </span>index template:address:array:character/deref, i:number + underscore?:boolean<span class="Special"> <- </span>equal in:character, <span class="Constant">95:literal</span> <span class="Comment"># '_'</span> <span class="Identifier">break-if</span> underscore?:boolean <span class="Comment"># result[result-idx] = template[i]</span> - out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:integer + out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:number out:address:character/deref<span class="Special"> <- </span>copy in:character <span class="Comment"># ++i</span> - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Comment"># ++result-idx</span> - result-idx:integer<span class="Special"> <- </span>add result-idx:integer, 1:literal + result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Comment"># copy 'a' into result</span> - j:integer<span class="Special"> <- </span>copy 0:literal + j:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> <span class="Comment"># while j < a.length</span> - arg-done?:boolean<span class="Special"> <- </span>greater-or-equal j:integer, a-len:integer + arg-done?:boolean<span class="Special"> <- </span>greater-or-equal j:number, a-len:number <span class="Identifier">break-if</span> arg-done?:boolean <span class="Comment"># result[result-idx] = a[j]</span> - in:character<span class="Special"> <- </span>index a:address:array:character/deref, j:integer - out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:integer + in:character<span class="Special"> <- </span>index a:address:array:character/deref, j:number + out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:number out:address:character/deref<span class="Special"> <- </span>copy in:character <span class="Comment"># ++j</span> - j:integer<span class="Special"> <- </span>add j:integer, 1:literal + j:number<span class="Special"> <- </span>add j:number, <span class="Constant">1:literal</span> <span class="Comment"># ++result-idx</span> - result-idx:integer<span class="Special"> <- </span>add result-idx:integer, 1:literal + result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Comment"># skip '_' in template</span> - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Comment"># interpolate next arg</span> <span class="Delimiter">}</span> <span class="Comment"># done with holes; copy rest of template directly into result</span> <span class="Delimiter">{</span> <span class="Comment"># while i < template.length</span> - tem-done?:boolean<span class="Special"> <- </span>greater-or-equal i:integer, tem-len:integer + tem-done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, tem-len:number <span class="Identifier">break-if</span> tem-done?:boolean <span class="Comment"># result[result-idx] = template[i]</span> - in:character<span class="Special"> <- </span>index template:address:array:character/deref, i:integer - out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:integer + in:character<span class="Special"> <- </span>index template:address:array:character/deref, i:number + out:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, result-idx:number out:address:character/deref<span class="Special"> <- </span>copy in:character <span class="Comment"># ++i</span> - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Comment"># ++result-idx</span> - result-idx:integer<span class="Special"> <- </span>add result-idx:integer, 1:literal + result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> result:address:array:character -<span class="Delimiter">]</span> +] -scenario interpolate-works <span class="Delimiter">[</span> +scenario interpolate-works [ <span class="CommentedCode">#? dump run #? 1</span> - run <span class="Delimiter">[</span> - 1:address:array:character/<span class="Special">raw <- </span>new <span class="Delimiter">[</span>abc _<span class="Delimiter">]</span> - 2:address:array:character/<span class="Special">raw <- </span>new <span class="Delimiter">[</span>def<span class="Delimiter">]</span> + run [ + 1:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[abc _]</span> + 2:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[def]</span> 3:address:array:character/<span class="Special">raw <- </span>interpolate 1:address:array:character/<span class="Special">raw</span>, 2:address:array:character/<span class="Special">raw</span> 4:array:character/<span class="Special">raw <- </span>copy 3:address:array:character/<span class="Special">raw</span>/deref - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> - 4:string<span class="Special"> <- </span><span class="Delimiter">[</span>abc def<span class="Delimiter">]</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] + memory-should-contain [ + 4:string<span class="Special"> <- </span><span class="Constant">[abc def]</span> + ] +] -scenario interpolate-at-start <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:array:character/<span class="Special">raw <- </span>new <span class="Delimiter">[</span>_, hello!<span class="Delimiter">]</span> - 2:address:array:character/<span class="Special">raw <- </span>new <span class="Delimiter">[</span>abc<span class="Delimiter">]</span> +scenario interpolate-at-start [ + run [ + 1:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[_, hello!]</span> + 2:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[abc]</span> 3:address:array:character/<span class="Special">raw <- </span>interpolate 1:address:array:character/<span class="Special">raw</span>, 2:address:array:character/<span class="Special">raw</span> 4:array:character/<span class="Special">raw <- </span>copy 3:address:array:character/<span class="Special">raw</span>/deref - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> - 4:string<span class="Special"> <- </span><span class="Delimiter">[</span>abc, hello!<span class="Delimiter">]</span> + ] + memory-should-contain [ + 4:string<span class="Special"> <- </span><span class="Constant">[abc, hello!]</span> 16<span class="Special"> <- </span>0 <span class="Comment"># out of bounds</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario interpolate-at-end <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:array:character/<span class="Special">raw <- </span>new <span class="Delimiter">[</span>hello, _<span class="Delimiter">]</span> - 2:address:array:character/<span class="Special">raw <- </span>new <span class="Delimiter">[</span>abc<span class="Delimiter">]</span> +scenario interpolate-at-end [ + run [ + 1:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[hello, _]</span> + 2:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[abc]</span> 3:address:array:character/<span class="Special">raw <- </span>interpolate 1:address:array:character/<span class="Special">raw</span>, 2:address:array:character/<span class="Special">raw</span> 4:array:character/<span class="Special">raw <- </span>copy 3:address:array:character/<span class="Special">raw</span>/deref - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> - 4:string<span class="Special"> <- </span><span class="Delimiter">[</span>hello, abc<span class="Delimiter">]</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] + memory-should-contain [ + 4:string<span class="Special"> <- </span><span class="Constant">[hello, abc]</span> + ] +] </pre> </body> </html> diff --git a/html/061channel.mu.html b/html/061channel.mu.html index 286aaf22..51ec7f2b 100644 --- a/html/061channel.mu.html +++ b/html/061channel.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 061channel.mu</title> +<title>~/Desktop/s/mu/061channel.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -13,8 +13,10 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; } body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } -.Comment { color: #8080ff; } +.CommentedCode { color: #6c6c6c; } .Delimiter { color: #c000c0; } +.Comment { color: #8080ff; } +.Constant { color: #008080; } .Special { color: #ff6060; } .Identifier { color: #008080; } .SalientComment { color: #00ffff; } @@ -39,262 +41,388 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment"># from an empty one will put the current routine in 'waiting' state until the</span> <span class="Comment"># operation can be completed.</span> -scenario channel <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:channel<span class="Special"> <- </span>init-channel 3:literal/capacity - 1:address:channel<span class="Special"> <- </span>write 1:address:channel, 34:literal - 2:integer, 1:address:channel<span class="Special"> <- </span>read 1:address:channel - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> +scenario channel [ + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">3:literal/capacity</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">34:literal</span> + 2:number, 1:address:channel<span class="Special"> <- </span>read 1:address:channel + ] + memory-should-contain [ 2<span class="Special"> <- </span>34 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -container channel <span class="Delimiter">[</span> +container channel [ <span class="Comment"># To avoid locking, writer and reader will never write to the same location.</span> <span class="Comment"># So channels will include fields in pairs, one for the writer and one for the</span> <span class="Comment"># reader.</span> - first-full:integer <span class="Comment"># for write</span> - first-free:integer <span class="Comment"># for read</span> + first-full:number <span class="Comment"># for write</span> + first-free:number <span class="Comment"># for read</span> <span class="Comment"># A circular buffer contains values from index first-full up to (but not</span> <span class="Comment"># including) index first-empty. The reader always modifies it at first-full,</span> <span class="Comment"># while the writer always modifies it at first-empty.</span> data:address:array:location -<span class="Delimiter">]</span> +] -<span class="Comment"># result:address:channel <- init-channel capacity:integer</span> -recipe init-channel <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +<span class="Comment"># result:address:channel <- init-channel capacity:number</span> +recipe init-channel [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> <span class="Comment"># result = new channel</span> result:address:channel<span class="Special"> <- </span>new channel:type <span class="Comment"># result.first-full = 0</span> - full:address:integer<span class="Special"> <- </span>get-address result:address:channel/deref, first-full:offset - full:address:integer/deref<span class="Special"> <- </span>copy 0:literal + full:address:number<span class="Special"> <- </span>get-address result:address:channel/deref, first-full:offset + full:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># result.first-free = 0</span> - free:address:integer<span class="Special"> <- </span>get-address result:address:channel/deref, first-free:offset - free:address:integer/deref<span class="Special"> <- </span>copy 0:literal + free:address:number<span class="Special"> <- </span>get-address result:address:channel/deref, first-free:offset + free:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># result.data = new location[ingredient+1]</span> - capacity:integer<span class="Special"> <- </span>next-ingredient - capacity:integer<span class="Special"> <- </span>add capacity:integer, 1:literal <span class="Comment"># unused slot for 'full?' below</span> + capacity:number<span class="Special"> <- </span>next-ingredient + capacity:number<span class="Special"> <- </span>add capacity:number, <span class="Constant">1:literal</span> <span class="Comment"># unused slot for 'full?' below</span> dest:address:address:array:location<span class="Special"> <- </span>get-address result:address:channel/deref, data:offset - dest:address:address:array:location/deref<span class="Special"> <- </span>new location:type, capacity:integer + dest:address:address:array:location/deref<span class="Special"> <- </span>new location:type, capacity:number <span class="Identifier">reply</span> result:address:channel -<span class="Delimiter">]</span> +] <span class="Comment"># chan:address:channel <- write chan:address:channel, val:location</span> -recipe write <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe write [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> chan:address:channel<span class="Special"> <- </span>next-ingredient val:location<span class="Special"> <- </span>next-ingredient <span class="Delimiter">{</span> <span class="Comment"># block if chan is full</span> full:boolean<span class="Special"> <- </span>channel-full? chan:address:channel <span class="Identifier">break-unless</span> full:boolean - full-address:address:integer<span class="Special"> <- </span>get-address chan:address:channel/deref, first-full:offset - wait-for-location full-address:address:integer/deref + full-address:address:number<span class="Special"> <- </span>get-address chan:address:channel/deref, first-full:offset + wait-for-location full-address:address:number/deref <span class="Delimiter">}</span> <span class="Comment"># store val</span> circular-buffer:address:array:location<span class="Special"> <- </span>get chan:address:channel/deref, data:offset - free:address:integer<span class="Special"> <- </span>get-address chan:address:channel/deref, first-free:offset - dest:address:location<span class="Special"> <- </span>index-address circular-buffer:address:array:location/deref, free:address:integer/deref + free:address:number<span class="Special"> <- </span>get-address chan:address:channel/deref, first-free:offset + dest:address:location<span class="Special"> <- </span>index-address circular-buffer:address:array:location/deref, free:address:number/deref dest:address:location/deref<span class="Special"> <- </span>copy val:location <span class="Comment"># increment free</span> - free:address:integer/deref<span class="Special"> <- </span>add free:address:integer/deref, 1:literal + free:address:number/deref<span class="Special"> <- </span>add free:address:number/deref, <span class="Constant">1:literal</span> <span class="Delimiter">{</span> <span class="Comment"># wrap free around to 0 if necessary</span> - len:integer<span class="Special"> <- </span>length circular-buffer:address:array:location/deref - at-end?:boolean<span class="Special"> <- </span>greater-or-equal free:address:integer/deref, len:integer + len:number<span class="Special"> <- </span>length circular-buffer:address:array:location/deref + at-end?:boolean<span class="Special"> <- </span>greater-or-equal free:address:number/deref, len:number <span class="Identifier">break-unless</span> at-end?:boolean - free:address:integer/deref<span class="Special"> <- </span>copy 0:literal + free:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> chan:address:channel/same-as-ingredient:0 -<span class="Delimiter">]</span> +] <span class="Comment"># result:location, chan:address:channel <- read chan:address:channel</span> -recipe read <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe read [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> chan:address:channel<span class="Special"> <- </span>next-ingredient <span class="Delimiter">{</span> <span class="Comment"># block if chan is empty</span> empty:boolean<span class="Special"> <- </span>channel-empty? chan:address:channel <span class="Identifier">break-unless</span> empty:boolean - free-address:address:integer<span class="Special"> <- </span>get-address chan:address:channel/deref, first-free:offset - wait-for-location free-address:address:integer/deref + free-address:address:number<span class="Special"> <- </span>get-address chan:address:channel/deref, first-free:offset + wait-for-location free-address:address:number/deref <span class="Delimiter">}</span> <span class="Comment"># read result</span> - full:address:integer<span class="Special"> <- </span>get-address chan:address:channel/deref, first-full:offset + full:address:number<span class="Special"> <- </span>get-address chan:address:channel/deref, first-full:offset circular-buffer:address:array:location<span class="Special"> <- </span>get chan:address:channel/deref, data:offset - result:location<span class="Special"> <- </span>index circular-buffer:address:array:location/deref, full:address:integer/deref + result:location<span class="Special"> <- </span>index circular-buffer:address:array:location/deref, full:address:number/deref <span class="Comment"># increment full</span> - full:address:integer/deref<span class="Special"> <- </span>add full:address:integer/deref, 1:literal + full:address:number/deref<span class="Special"> <- </span>add full:address:number/deref, <span class="Constant">1:literal</span> <span class="Delimiter">{</span> <span class="Comment"># wrap full around to 0 if necessary</span> - len:integer<span class="Special"> <- </span>length circular-buffer:address:array:location/deref - at-end?:boolean<span class="Special"> <- </span>greater-or-equal full:address:integer/deref, len:integer + len:number<span class="Special"> <- </span>length circular-buffer:address:array:location/deref + at-end?:boolean<span class="Special"> <- </span>greater-or-equal full:address:number/deref, len:number <span class="Identifier">break-unless</span> at-end?:boolean - full:address:integer/deref<span class="Special"> <- </span>copy 0:literal + full:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> result:location, chan:address:channel/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -scenario channel-initialization <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:channel<span class="Special"> <- </span>init-channel 3:literal/capacity - 2:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset - 3:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> +recipe clear-channel [ + default-space:address:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + chan:address:channel<span class="Special"> <- </span>next-ingredient + <span class="Delimiter">{</span> + empty?:boolean<span class="Special"> <- </span>channel-empty? chan:address:channel + <span class="Identifier">break-if</span> empty?:boolean + _, chan:address:channel<span class="Special"> <- </span>read chan:address:channel + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> chan:address:channel/same-as-ingredient:0 +] + +scenario channel-initialization [ + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">3:literal/capacity</span> + 2:number<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset + 3:number<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset + ] + memory-should-contain [ 2<span class="Special"> <- </span>0 <span class="Comment"># first-full</span> 3<span class="Special"> <- </span>0 <span class="Comment"># first-free</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario channel-write-increments-free <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:channel<span class="Special"> <- </span>init-channel 3:literal/capacity - 1:address:channel<span class="Special"> <- </span>write 1:address:channel, 34:literal - 2:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset - 3:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> +scenario channel-write-increments-free [ + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">3:literal/capacity</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">34:literal</span> + 2:number<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset + 3:number<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset + ] + memory-should-contain [ 2<span class="Special"> <- </span>0 <span class="Comment"># first-full</span> 3<span class="Special"> <- </span>1 <span class="Comment"># first-free</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario channel-read-increments-full <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:channel<span class="Special"> <- </span>init-channel 3:literal/capacity - 1:address:channel<span class="Special"> <- </span>write 1:address:channel, 34:literal +scenario channel-read-increments-full [ + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">3:literal/capacity</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">34:literal</span> _, 1:address:channel<span class="Special"> <- </span>read 1:address:channel - 2:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset - 3:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + 2:number<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset + 3:number<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset + ] + memory-should-contain [ 2<span class="Special"> <- </span>1 <span class="Comment"># first-full</span> 3<span class="Special"> <- </span>1 <span class="Comment"># first-free</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario channel-wrap <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> +scenario channel-wrap [ + run [ <span class="Comment"># channel with just 1 slot</span> - 1:address:channel<span class="Special"> <- </span>init-channel 1:literal/capacity + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">1:literal/capacity</span> <span class="Comment"># write and read a value</span> - 1:address:channel<span class="Special"> <- </span>write 1:address:channel, 34:literal + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">34:literal</span> _, 1:address:channel<span class="Special"> <- </span>read 1:address:channel <span class="Comment"># first-free will now be 1</span> - 2:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset - 3:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset + 2:number<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset + 3:number<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset <span class="Comment"># write second value, verify that first-free wraps</span> - 1:address:channel<span class="Special"> <- </span>write 1:address:channel, 34:literal - 4:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">34:literal</span> + 4:number<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset <span class="Comment"># read second value, verify that first-full wraps</span> _, 1:address:channel<span class="Special"> <- </span>read 1:address:channel - 5:integer<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + 5:number<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset + ] + memory-should-contain [ 2<span class="Special"> <- </span>1 <span class="Comment"># first-free after first write</span> 3<span class="Special"> <- </span>1 <span class="Comment"># first-full after first read</span> 4<span class="Special"> <- </span>0 <span class="Comment"># first-free after second write, wrapped</span> 5<span class="Special"> <- </span>0 <span class="Comment"># first-full after second read, wrapped</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] <span class="SalientComment">## helpers</span> <span class="Comment"># An empty channel has first-empty and first-full both at the same value.</span> -recipe channel-empty? <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe channel-empty? [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> chan:address:channel<span class="Special"> <- </span>next-ingredient <span class="Comment"># return chan.first-full == chan.first-free</span> - full:integer<span class="Special"> <- </span>get chan:address:channel/deref, first-full:offset - free:integer<span class="Special"> <- </span>get chan:address:channel/deref, first-free:offset - result:boolean<span class="Special"> <- </span>equal full:integer, free:integer + full:number<span class="Special"> <- </span>get chan:address:channel/deref, first-full:offset + free:number<span class="Special"> <- </span>get chan:address:channel/deref, first-free:offset + result:boolean<span class="Special"> <- </span>equal full:number, free:number <span class="Identifier">reply</span> result:boolean -<span class="Delimiter">]</span> +] <span class="Comment"># A full channel has first-empty just before first-full, wasting one slot.</span> <span class="Comment"># (Other alternatives: <a href="https://en.wikipedia.org/wiki/Circular_buffer#Full_.2F_Empty_Buffer_Distinction)">https://en.wikipedia.org/wiki/Circular_buffer#Full_.2F_Empty_Buffer_Distinction)</a></span> -recipe channel-full? <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe channel-full? [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> chan:address:channel<span class="Special"> <- </span>next-ingredient <span class="Comment"># tmp = chan.first-free + 1</span> - tmp:integer<span class="Special"> <- </span>get chan:address:channel/deref, first-free:offset - tmp:integer<span class="Special"> <- </span>add tmp:integer, 1:literal + tmp:number<span class="Special"> <- </span>get chan:address:channel/deref, first-free:offset + tmp:number<span class="Special"> <- </span>add tmp:number, <span class="Constant">1:literal</span> <span class="Delimiter">{</span> <span class="Comment"># if tmp == chan.capacity, tmp = 0</span> - len:integer<span class="Special"> <- </span>channel-capacity chan:address:channel - at-end?:boolean<span class="Special"> <- </span>greater-or-equal tmp:integer, len:integer + len:number<span class="Special"> <- </span>channel-capacity chan:address:channel + at-end?:boolean<span class="Special"> <- </span>greater-or-equal tmp:number, len:number <span class="Identifier">break-unless</span> at-end?:boolean - tmp:integer<span class="Special"> <- </span>copy 0:literal + tmp:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">}</span> <span class="Comment"># return chan.first-full == tmp</span> - full:integer<span class="Special"> <- </span>get chan:address:channel/deref, first-full:offset - result:boolean<span class="Special"> <- </span>equal full:integer, tmp:integer + full:number<span class="Special"> <- </span>get chan:address:channel/deref, first-full:offset + result:boolean<span class="Special"> <- </span>equal full:number, tmp:number <span class="Identifier">reply</span> result:boolean -<span class="Delimiter">]</span> +] -<span class="Comment"># result:integer <- channel-capacity chan:address:channel</span> -recipe channel-capacity <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +<span class="Comment"># result:number <- channel-capacity chan:address:channel</span> +recipe channel-capacity [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> chan:address:channel<span class="Special"> <- </span>next-ingredient q:address:array:location<span class="Special"> <- </span>get chan:address:channel/deref, data:offset - result:integer<span class="Special"> <- </span>length q:address:array:location/deref - <span class="Identifier">reply</span> result:integer -<span class="Delimiter">]</span> + result:number<span class="Special"> <- </span>length q:address:array:location/deref + <span class="Identifier">reply</span> result:number +] -scenario channel-new-empty-not-full <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:channel<span class="Special"> <- </span>init-channel 3:literal/capacity - 2:integer<span class="Special"> <- </span>channel-empty? 1:address:channel - 3:integer<span class="Special"> <- </span>channel-full? 1:address:channel - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> +scenario channel-new-empty-not-full [ + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">3:literal/capacity</span> + 2:boolean<span class="Special"> <- </span>channel-empty? 1:address:channel + 3:boolean<span class="Special"> <- </span>channel-full? 1:address:channel + ] + memory-should-contain [ 2<span class="Special"> <- </span>1 <span class="Comment"># empty?</span> 3<span class="Special"> <- </span>0 <span class="Comment"># full?</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario channel-write-not-empty <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:channel<span class="Special"> <- </span>init-channel 3:literal/capacity - 1:address:channel<span class="Special"> <- </span>write 1:address:channel, 34:literal - 2:integer<span class="Special"> <- </span>channel-empty? 1:address:channel - 3:integer<span class="Special"> <- </span>channel-full? 1:address:channel - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> +scenario channel-write-not-empty [ + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">3:literal/capacity</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">34:literal</span> + 2:boolean<span class="Special"> <- </span>channel-empty? 1:address:channel + 3:boolean<span class="Special"> <- </span>channel-full? 1:address:channel + ] + memory-should-contain [ 2<span class="Special"> <- </span>0 <span class="Comment"># empty?</span> 3<span class="Special"> <- </span>0 <span class="Comment"># full?</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario channel-write-full <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:channel<span class="Special"> <- </span>init-channel 1:literal/capacity - 1:address:channel<span class="Special"> <- </span>write 1:address:channel, 34:literal - 2:integer<span class="Special"> <- </span>channel-empty? 1:address:channel - 3:integer<span class="Special"> <- </span>channel-full? 1:address:channel - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> +scenario channel-write-full [ + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">1:literal/capacity</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">34:literal</span> + 2:boolean<span class="Special"> <- </span>channel-empty? 1:address:channel + 3:boolean<span class="Special"> <- </span>channel-full? 1:address:channel + ] + memory-should-contain [ 2<span class="Special"> <- </span>0 <span class="Comment"># empty?</span> 3<span class="Special"> <- </span>1 <span class="Comment"># full?</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -scenario channel-read-not-full <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:channel<span class="Special"> <- </span>init-channel 1:literal/capacity - 1:address:channel<span class="Special"> <- </span>write 1:address:channel, 34:literal +scenario channel-read-not-full [ + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">1:literal/capacity</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">34:literal</span> _, 1:address:channel<span class="Special"> <- </span>read 1:address:channel - 2:integer<span class="Special"> <- </span>channel-empty? 1:address:channel - 3:integer<span class="Special"> <- </span>channel-full? 1:address:channel - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + 2:boolean<span class="Special"> <- </span>channel-empty? 1:address:channel + 3:boolean<span class="Special"> <- </span>channel-full? 1:address:channel + ] + memory-should-contain [ 2<span class="Special"> <- </span>1 <span class="Comment"># empty?</span> 3<span class="Special"> <- </span>0 <span class="Comment"># full?</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] + +<span class="Comment"># helper for channels of characters in particular</span> +<span class="Comment"># out:address:channel <- buffer-lines in:address:channel, out:address:channel</span> +recipe buffer-lines [ + default-space:address:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> +<span class="CommentedCode">#? $print [buffer-lines: aaa</span> +<span class="CommentedCode">#? ]</span> + in:address:channel<span class="Special"> <- </span>next-ingredient + out:address:channel<span class="Special"> <- </span>next-ingredient + <span class="Comment"># repeat forever</span> + <span class="Delimiter">{</span> + line:address:buffer<span class="Special"> <- </span>init-buffer, <span class="Constant">30:literal</span> + <span class="Comment"># read characters from 'in' until newline, copy into line</span> + <span class="Delimiter">{</span> + <span class="Identifier"> +next-character</span> + c:character, in:address:channel<span class="Special"> <- </span>read in:address:channel + <span class="Comment"># drop a character on backspace</span> + <span class="Delimiter">{</span> + <span class="Comment"># special-case: if it's a backspace</span> + backspace?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8:literal</span> + <span class="Identifier">break-unless</span> backspace?:boolean + <span class="Comment"># drop previous character</span> +<span class="CommentedCode">#? return-to-console #? 2</span> +<span class="CommentedCode">#? $print [backspace! #? 1</span> +<span class="CommentedCode">#? ] #? 1</span> + <span class="Delimiter">{</span> + buffer-length:address:number<span class="Special"> <- </span>get-address line:address:buffer/deref, length:offset + buffer-empty?:boolean<span class="Special"> <- </span>equal buffer-length:address:number/deref, <span class="Constant">0:literal</span> + <span class="Identifier">break-if</span> buffer-empty?:boolean +<span class="CommentedCode">#? $print [before: ], buffer-length:address:number/deref, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + buffer-length:address:number/deref<span class="Special"> <- </span>subtract buffer-length:address:number/deref, <span class="Constant">1:literal</span> +<span class="CommentedCode">#? $print [after: ], buffer-length:address:number/deref, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + <span class="Delimiter">}</span> +<span class="CommentedCode">#? $exit #? 2</span> + <span class="Comment"># and don't append this one</span> + <span class="Identifier">loop</span><span class="Identifier"> +next-character</span>:label + <span class="Delimiter">}</span> + <span class="Comment"># append anything else</span> +<span class="CommentedCode">#? $print [buffer-lines: appending ], c:character, [ </span> +<span class="CommentedCode">#? ]</span> + line:address:buffer<span class="Special"> <- </span>buffer-append line:address:buffer, c:character + line-done?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal/newline</span> + <span class="Identifier">break-if</span> line-done?:boolean + <span class="Comment"># stop buffering on eof (currently only generated by fake keyboard)</span> + empty-fake-keyboard?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">0:literal/eof</span> + <span class="Identifier">break-if</span> empty-fake-keyboard?:boolean + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> +<span class="CommentedCode">#? return-to-console #? 1</span> + <span class="Comment"># copy line into 'out'</span> +<span class="CommentedCode">#? $print [buffer-lines: emitting</span> +<span class="CommentedCode">#? ]</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + line-contents:address:array:character<span class="Special"> <- </span>get line:address:buffer/deref, data:offset + max:number<span class="Special"> <- </span>get line:address:buffer/deref, length:offset + <span class="Delimiter">{</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, max:number + <span class="Identifier">break-if</span> done?:boolean + c:character<span class="Special"> <- </span>index line-contents:address:array:character/deref, i:number + out:address:channel<span class="Special"> <- </span>write out:address:channel, c:character +<span class="CommentedCode">#? $print [writing ], i:number, [: ], c:character, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> +<span class="CommentedCode">#? $dump-trace #? 1</span> +<span class="CommentedCode">#? $exit #? 1</span> + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> out:address:channel/same-as-ingredient:1 +] + +scenario buffer-lines-blocks-until-newline [ + run [ + 1:address:channel/stdin<span class="Special"> <- </span>init-channel <span class="Constant">10:literal/capacity</span> + 2:address:channel/buffered-stdin<span class="Special"> <- </span>init-channel <span class="Constant">10:literal/capacity</span> + 3:boolean<span class="Special"> <- </span>channel-empty? 2:address:channel/buffered-stdin + assert 3:boolean, [ +F buffer-lines-blocks-until-newline: channel should be empty after init] + <span class="Comment"># buffer stdin into buffered-stdin, try to read from buffered-stdin</span> + 4:number/buffer-routine<span class="Special"> <- </span>start-running buffer-lines:recipe, 1:address:channel/stdin, 2:address:channel/buffered-stdin + wait-for-routine 4:number/buffer-routine + 5:boolean<span class="Special"> <- </span>channel-empty? 2:address:channel/buffered-stdin + assert 5:boolean, [ +F buffer-lines-blocks-until-newline: channel should be empty after buffer-lines bring-up] + <span class="Comment"># write 'a'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">97:literal/a</span> + restart 4:number/buffer-routine + wait-for-routine 4:number/buffer-routine + 6:boolean<span class="Special"> <- </span>channel-empty? 2:address:channel/buffered-stdin + assert 6:boolean, [ +F buffer-lines-blocks-until-newline: channel should be empty after writing<span class="Identifier"> 'a</span>'] + <span class="Comment"># write 'b'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">98:literal/b</span> + restart 4:number/buffer-routine + wait-for-routine 4:number/buffer-routine + 7:boolean<span class="Special"> <- </span>channel-empty? 2:address:channel/buffered-stdin + assert 7:boolean, [ +F buffer-lines-blocks-until-newline: channel should be empty after writing<span class="Identifier"> 'b</span>'] + <span class="Comment"># write newline</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">10:literal/newline</span> + restart 4:number/buffer-routine + wait-for-routine 4:number/buffer-routine + 8:boolean<span class="Special"> <- </span>channel-empty? 2:address:channel/buffered-stdin + 9:boolean/completed?<span class="Special"> <- </span>not 8:boolean + assert 9:boolean/completed?, [ +F buffer-lines-blocks-until-newline: channel should contain data after writing newline] + trace <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> + ] + trace-should-contain [ + test: reached end + ] +] </pre> </body> </html> diff --git a/html/062array.mu.html b/html/062array.mu.html index fe5f9e8d..259e74fa 100644 --- a/html/062array.mu.html +++ b/html/062array.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 062array.mu</title> +<title>~/Desktop/s/mu/062array.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -13,8 +13,9 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; } body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } -.Comment { color: #8080ff; } .Delimiter { color: #c000c0; } +.Comment { color: #8080ff; } +.Constant { color: #008080; } .Special { color: #ff6060; } .Identifier { color: #008080; } --> @@ -28,46 +29,46 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } </head> <body> <pre id='vimCodeElement'> -scenario array-from-args <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> - 1:address:array:location<span class="Special"> <- </span>init-array 0:literal, 1:literal, 2:literal +scenario array-from-args [ + run [ + 1:address:array:location<span class="Special"> <- </span>init-array <span class="Constant">0:literal</span>, <span class="Constant">1:literal</span>, <span class="Constant">2:literal</span> 2:array:location<span class="Special"> <- </span>copy 1:address:array:location/deref - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 2<span class="Special"> <- </span>3 <span class="Comment"># array length</span> 3<span class="Special"> <- </span>0 4<span class="Special"> <- </span>1 5<span class="Special"> <- </span>2 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] <span class="Comment"># create an array out of a list of scalar args</span> -recipe init-array <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal - capacity:integer<span class="Special"> <- </span>copy 0:literal +recipe init-array [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + capacity:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> <span class="Comment"># while read curr-value</span> curr-value:location, exists?:boolean<span class="Special"> <- </span>next-ingredient <span class="Identifier">break-unless</span> exists?:boolean - capacity:integer<span class="Special"> <- </span>add capacity:integer, 1:literal + capacity:number<span class="Special"> <- </span>add capacity:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> - result:address:array:location<span class="Special"> <- </span>new location:type, capacity:integer + result:address:array:location<span class="Special"> <- </span>new location:type, capacity:number rewind-ingredients - i:integer<span class="Special"> <- </span>copy 0:literal + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> <span class="Comment"># while read curr-value</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:integer, capacity:integer + done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, capacity:number <span class="Identifier">break-if</span> done?:boolean curr-value:location, exists?:boolean<span class="Special"> <- </span>next-ingredient - assert exists?:boolean, <span class="Delimiter">[</span>error in rewinding ingredients to init-array<span class="Delimiter">]</span> - tmp:address:location<span class="Special"> <- </span>index-address result:address:array:location/deref, i:integer + assert exists?:boolean, <span class="Constant">[error in rewinding ingredients to init-array]</span> + tmp:address:location<span class="Special"> <- </span>index-address result:address:array:location/deref, i:number tmp:address:location/deref<span class="Special"> <- </span>copy curr-value:location - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> result:address:array:location -<span class="Delimiter">]</span> +] </pre> </body> </html> diff --git a/html/070display.cc.html b/html/070display.cc.html index c0a5deb9..834cace7 100644 --- a/html/070display.cc.html +++ b/html/070display.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 070display.cc</title> +<title>~/Desktop/s/mu/070display.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -61,9 +61,13 @@ Recipe_number[<span class="Constant">"return-to-console"</span>] = RET <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case RETURN_TO_CONSOLE: <span class="Delimiter">{</span> tb_shutdown<span class="Delimiter">();</span> +<span class="CommentedCode">//? Trace_stream->dump_layer = "all"; //? 1</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Teardown")</span> +tb_shutdown<span class="Delimiter">();</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> CLEAR_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> @@ -96,12 +100,13 @@ PRINT_CHARACTER_TO_DISPLAY<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"print-character-to-display"</span>] = PRINT_CHARACTER_TO_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case PRINT_CHARACTER_TO_DISPLAY: <span class="Delimiter">{</span> - vector<long long int> arg = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> int h=tb_height<span class="Delimiter">(),</span> w=tb_width<span class="Delimiter">();</span> size_t height = <span class="Delimiter">(</span>h >= <span class="Constant">0</span><span class="Delimiter">)</span> ? h : <span class="Constant">0</span><span class="Delimiter">;</span> size_t width = <span class="Delimiter">(</span>w >= <span class="Constant">0</span><span class="Delimiter">)</span> ? w : <span class="Constant">0</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>arg[<span class="Constant">0</span>] == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Display_row < height<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + long long int c = 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> + if <span class="Delimiter">(</span>c == <span class="cSpecial">'\n'</span> || c == <span class="cSpecial">'\r'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Display_row < height-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> ++Display_row<span class="Delimiter">;</span> tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> @@ -109,9 +114,18 @@ case PRINT_CHARACTER_TO_DISPLAY: <span class="Delimiter">{</span> <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - tb_change_cell<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">,</span> arg[<span class="Constant">0</span>]<span class="Delimiter">,</span> TB_WHITE<span class="Delimiter">,</span> TB_DEFAULT<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>Display_column < width<span class="Delimiter">)</span> <span class="Delimiter">{</span> - Display_column++<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>c == <span class="cSpecial">'\b'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Display_column > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + tb_change_cell<span class="Delimiter">(</span>Display_column-<span class="Constant">1</span><span class="Delimiter">,</span> Display_row<span class="Delimiter">,</span> <span class="Constant">' '</span><span class="Delimiter">,</span> TB_WHITE<span class="Delimiter">,</span> TB_DEFAULT<span class="Delimiter">);</span> + --Display_column<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + tb_change_cell<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">,</span> c<span class="Delimiter">,</span> TB_WHITE<span class="Delimiter">,</span> TB_DEFAULT<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>Display_column < width-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + ++Display_column<span class="Delimiter">;</span> tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> <span class="Delimiter">}</span> tb_present<span class="Delimiter">();</span> @@ -124,12 +138,9 @@ CURSOR_POSITION_ON_DISPLAY<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"cursor-position-on-display"</span>] = CURSOR_POSITION_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case CURSOR_POSITION_ON_DISPLAY: <span class="Delimiter">{</span> - vector<long long int> row<span class="Delimiter">;</span> - row<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Display_row<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> row<span class="Delimiter">);</span> - vector<long long int> column<span class="Delimiter">;</span> - column<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Display_column<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> column<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>Display_row<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>Display_column<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -139,10 +150,10 @@ MOVE_CURSOR_ON_DISPLAY<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"move-cursor-on-display"</span>] = MOVE_CURSOR_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MOVE_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> - vector<long long int> row = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> - vector<long long int> column = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> - Display_row = row[<span class="Constant">0</span>]<span class="Delimiter">;</span> - Display_column = column[<span class="Constant">0</span>]<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + Display_row = 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> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + Display_column = 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> tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> tb_present<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -154,9 +165,13 @@ MOVE_CURSOR_DOWN_ON_DISPLAY<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"move-cursor-down-on-display"</span>] = MOVE_CURSOR_DOWN_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MOVE_CURSOR_DOWN_ON_DISPLAY: <span class="Delimiter">{</span> - Display_row++<span class="Delimiter">;</span> - tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> - tb_present<span class="Delimiter">();</span> + int h=tb_height<span class="Delimiter">();</span> + size_t height = <span class="Delimiter">(</span>h >= <span class="Constant">0</span><span class="Delimiter">)</span> ? h : <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Display_row < height-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + Display_row++<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -166,9 +181,11 @@ MOVE_CURSOR_UP_ON_DISPLAY<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"move-cursor-up-on-display"</span>] = MOVE_CURSOR_UP_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MOVE_CURSOR_UP_ON_DISPLAY: <span class="Delimiter">{</span> - Display_row--<span class="Delimiter">;</span> - tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> - tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Display_row > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + Display_row--<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -178,9 +195,13 @@ MOVE_CURSOR_RIGHT_ON_DISPLAY<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"move-cursor-right-on-display"</span>] = MOVE_CURSOR_RIGHT_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MOVE_CURSOR_RIGHT_ON_DISPLAY: <span class="Delimiter">{</span> - Display_column++<span class="Delimiter">;</span> - tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> - tb_present<span class="Delimiter">();</span> + int w=tb_width<span class="Delimiter">();</span> + size_t width = <span class="Delimiter">(</span>w >= <span class="Constant">0</span><span class="Delimiter">)</span> ? w : <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Display_column < width-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + Display_column++<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -190,9 +211,11 @@ MOVE_CURSOR_LEFT_ON_DISPLAY<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"move-cursor-left-on-display"</span>] = MOVE_CURSOR_LEFT_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MOVE_CURSOR_LEFT_ON_DISPLAY: <span class="Delimiter">{</span> - Display_column--<span class="Delimiter">;</span> - tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> - tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Display_column > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + Display_column--<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -204,18 +227,12 @@ WAIT_FOR_KEY_FROM_KEYBOARD<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"wait-for-key-from-keyboard"</span>] = WAIT_FOR_KEY_FROM_KEYBOARD<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case WAIT_FOR_KEY_FROM_KEYBOARD: <span class="Delimiter">{</span> -<span class="CommentedCode">//? LOG << "AAA\n"; LOG.flush();</span> struct tb_event event<span class="Delimiter">;</span> do <span class="Delimiter">{</span> tb_poll_event<span class="Delimiter">(</span>&event<span class="Delimiter">);</span> <span class="Delimiter">}</span> while <span class="Delimiter">(</span>event<span class="Delimiter">.</span>type != TB_EVENT_KEY<span class="Delimiter">);</span> -<span class="CommentedCode">//? LOG << "AAA 2\n"; LOG.flush();</span> - vector<long long int> result<span class="Delimiter">;</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>event<span class="Delimiter">.</span>ch<span class="Delimiter">);</span> -<span class="CommentedCode">//? LOG << "AAA 3\n"; LOG.flush();</span> - if <span class="Delimiter">(</span>!current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> -<span class="CommentedCode">//? LOG << "AAA 9\n"; LOG.flush();</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>event<span class="Delimiter">.</span>ch<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -227,18 +244,19 @@ Recipe_number[<span class="Constant">"read-key-from-keyboard"</span>] case READ_KEY_FROM_KEYBOARD: <span class="Delimiter">{</span> struct tb_event event<span class="Delimiter">;</span> int event_type = tb_peek_event<span class="Delimiter">(</span>&event<span class="Delimiter">,</span> <span class="Constant">5</span><span class="Comment">/*</span><span class="Comment">ms</span><span class="Comment">*/</span><span class="Delimiter">);</span> - vector<long long int> result<span class="Delimiter">;</span> - vector<long long int> found<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>event_type != TB_EVENT_KEY<span class="Delimiter">)</span> <span class="Delimiter">{</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - found<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> - <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>event<span class="Delimiter">.</span>ch<span class="Delimiter">);</span> - found<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">);</span> + long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> + long long int found = <span class="Constant">false</span><span class="Delimiter">;</span> +<span class="CommentedCode">//? cerr << event_type << '\n'; //? 1</span> + if <span class="Delimiter">(</span>event_type == TB_EVENT_KEY<span class="Delimiter">)</span> <span class="Delimiter">{</span> + result = event<span class="Delimiter">.</span>key ? event<span class="Delimiter">.</span>key : event<span class="Delimiter">.</span>ch<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>result == TB_KEY_CTRL_C<span class="Delimiter">)</span> tb_shutdown<span class="Delimiter">(),</span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>result == TB_KEY_BACKSPACE2<span class="Delimiter">)</span> result = TB_KEY_BACKSPACE<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>result == TB_KEY_CARRIAGE_RETURN<span class="Delimiter">)</span> result = TB_KEY_NEWLINE<span class="Delimiter">;</span> + found = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> - write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> found<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>result<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>found<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/071print.mu.html b/html/071print.mu.html index 4f69abd9..2e0c0dee 100644 --- a/html/071print.mu.html +++ b/html/071print.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 071print.mu</title> +<title>~/Desktop/s/mu/071print.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -14,8 +14,9 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .CommentedCode { color: #6c6c6c; } -.Comment { color: #8080ff; } .Delimiter { color: #c000c0; } +.Comment { color: #8080ff; } +.Constant { color: #008080; } .Special { color: #ff6060; } .Identifier { color: #008080; } --> @@ -32,182 +33,258 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment"># Wrappers around print primitives that take a 'screen' object and are thus</span> <span class="Comment"># easier to test.</span> -container screen <span class="Delimiter">[</span> - num-rows:integer - num-columns:integer - cursor-row:integer - cursor-column:integer +container screen [ + num-rows:number + num-columns:number + cursor-row:number + cursor-column:number data:address:array:character -<span class="Delimiter">]</span> +] -recipe init-fake-screen <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal/capacity +recipe init-fake-screen [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal/capacity</span> result:address:screen<span class="Special"> <- </span>new screen:type - width:address:integer<span class="Special"> <- </span>get-address result:address:screen/deref, num-columns:offset - width:address:integer/deref<span class="Special"> <- </span>next-ingredient - height:address:integer<span class="Special"> <- </span>get-address result:address:screen/deref, num-rows:offset - height:address:integer/deref<span class="Special"> <- </span>next-ingredient - row:address:integer<span class="Special"> <- </span>get-address result:address:screen/deref, cursor-row:offset - row:address:integer/deref<span class="Special"> <- </span>copy 0:literal - column:address:integer<span class="Special"> <- </span>get-address result:address:screen/deref, cursor-column:offset - column:address:integer/deref<span class="Special"> <- </span>copy 0:literal - bufsize:integer<span class="Special"> <- </span>multiply width:address:integer/deref, height:address:integer/deref + width:address:number<span class="Special"> <- </span>get-address result:address:screen/deref, num-columns:offset + width:address:number/deref<span class="Special"> <- </span>next-ingredient + height:address:number<span class="Special"> <- </span>get-address result:address:screen/deref, num-rows:offset + height:address:number/deref<span class="Special"> <- </span>next-ingredient + row:address:number<span class="Special"> <- </span>get-address result:address:screen/deref, cursor-row:offset + row:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + column:address:number<span class="Special"> <- </span>get-address result:address:screen/deref, cursor-column:offset + column:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + bufsize:number<span class="Special"> <- </span>multiply width:address:number/deref, height:address:number/deref buf:address:address:array:character<span class="Special"> <- </span>get-address result:address:screen/deref, data:offset - buf:address:address:array:character/deref<span class="Special"> <- </span>new character:literal, bufsize:integer + buf:address:address:array:character/deref<span class="Special"> <- </span>new <span class="Constant">character:literal</span>, bufsize:number clear-screen result:address:screen <span class="Identifier">reply</span> result:address:screen -<span class="Delimiter">]</span> +] -recipe clear-screen <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe clear-screen [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient +<span class="CommentedCode">#? $print [clearing screen</span> +<span class="CommentedCode">#? ] #? 1</span> <span class="Comment"># if x exists</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:screen <span class="Comment"># clear fake screen</span> buf:address:array:character<span class="Special"> <- </span>get x:address:screen/deref, data:offset - max:integer<span class="Special"> <- </span>length buf:address:array:character/deref - i:integer<span class="Special"> <- </span>copy 0:literal + max:number<span class="Special"> <- </span>length buf:address:array:character/deref + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:integer, max:integer + done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, max:number <span class="Identifier">break-if</span> done?:boolean - c:address:character<span class="Special"> <- </span>index-address buf:address:array:character/deref, i:integer - c:address:character/deref<span class="Special"> <- </span>copy <span class="Delimiter">[</span> <span class="Delimiter">]</span> - i:integer<span class="Special"> <- </span>add i:integer, 1:literal + c:address:character<span class="Special"> <- </span>index-address buf:address:array:character/deref, i:number + c:address:character/deref<span class="Special"> <- </span>copy <span class="Constant">[ ]</span> + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> + <span class="Comment"># reset cursor</span> + cur:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-row:offset + cur:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + cur:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset + cur:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> clear-display <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -recipe print-character <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe print-character [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient c:character<span class="Special"> <- </span>next-ingredient -<span class="CommentedCode">#? $print x:address:character #? 1</span> -<span class="CommentedCode">#? $print [ print-character #? 1</span> -<span class="CommentedCode">#? ] #? 1</span> <span class="Delimiter">{</span> <span class="Comment"># if x exists</span> + <span class="Comment"># (handle special cases exactly like in the real screen)</span> <span class="Identifier">break-unless</span> x:address:screen -<span class="CommentedCode">#? $print [print-character2 #? 1</span> + row:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-row:offset + column:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset + width:number<span class="Special"> <- </span>get x:address:screen/deref, num-columns:offset + height:number<span class="Special"> <- </span>get x:address:screen/deref, num-rows:offset + max-row:number<span class="Special"> <- </span>subtract height:number, <span class="Constant">1:literal</span> + <span class="Comment"># special-case: newline</span> + <span class="Delimiter">{</span> + newline?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal/newlin</span> +<span class="CommentedCode">#? $print c:character, [ ], newline?:boolean, [ </span> <span class="CommentedCode">#? ] #? 1</span> + <span class="Identifier">break-unless</span> newline?:boolean + <span class="Delimiter">{</span> + <span class="Comment"># unless cursor is already at bottom</span> + at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row:address:number/deref, max-row:number + <span class="Identifier">break-if</span> at-bottom?:boolean + <span class="Comment"># move it to the next row</span> + column:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + row:address:number/deref<span class="Special"> <- </span>add row:address:number/deref, <span class="Constant">1:literal</span> + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 + <span class="Delimiter">}</span> <span class="Comment"># save character in fake screen</span> - row:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-row:offset - column:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset - width:integer<span class="Special"> <- </span>get x:address:screen/deref, num-columns:offset - index:integer<span class="Special"> <- </span>multiply row:address:integer/deref, width:integer - index:integer<span class="Special"> <- </span>add index:integer, column:address:integer/deref + index:number<span class="Special"> <- </span>multiply row:address:number/deref, width:number + index:number<span class="Special"> <- </span>add index:number, column:address:number/deref buf:address:array:character<span class="Special"> <- </span>get x:address:screen/deref, data:offset - cursor:address:character<span class="Special"> <- </span>index-address buf:address:array:character/deref, index:integer -<span class="CommentedCode">#? $print cursor:address:character #? 1</span> -<span class="CommentedCode">#? $print [ #? 1</span> + cursor:address:character<span class="Special"> <- </span>index-address buf:address:array:character/deref, index:number + <span class="Comment"># special-case: backspace</span> + <span class="Delimiter">{</span> + backspace?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8:literal</span> + <span class="Identifier">break-unless</span> backspace?:boolean + <span class="Delimiter">{</span> + <span class="Comment"># unless cursor is already at left margin</span> + at-left?:boolean<span class="Special"> <- </span>lesser-or-equal column:address:number/deref, <span class="Constant">0:literal</span> + <span class="Identifier">break-if</span> at-left?:boolean + <span class="Comment"># clear previous location</span> + column:address:number/deref<span class="Special"> <- </span>subtract column:address:number/deref, <span class="Constant">1:literal</span> + cursor:address:character<span class="Special"> <- </span>subtract cursor:address:character, <span class="Constant">1:literal</span> + cursor:address:character/deref<span class="Special"> <- </span>copy <span class="Constant">32:literal/space</span> + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 + <span class="Delimiter">}</span> +<span class="CommentedCode">#? $print [saving character ], c:character, [ to fake screen ], cursor:address/screen, [ </span> <span class="CommentedCode">#? ] #? 1</span> - cursor:address:character/deref<span class="Special"> <- </span>copy c:character <span class="Comment"># todo: newline, etc.</span> + cursor:address:character/deref<span class="Special"> <- </span>copy c:character <span class="Comment"># increment column unless it's already all the way to the right</span> <span class="Delimiter">{</span> - at-right?:boolean<span class="Special"> <- </span>equal column:address:integer/deref, width:integer + at-right?:boolean<span class="Special"> <- </span>equal column:address:number/deref, width:number <span class="Identifier">break-if</span> at-right?:boolean - column:address:integer/deref<span class="Special"> <- </span>add column:address:integer/deref, 1:literal + column:address:number/deref<span class="Special"> <- </span>add column:address:number/deref, <span class="Constant">1:literal</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> print-character-to-display c:character <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -scenario print-character-at-top-left <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> +scenario print-character-at-top-left [ + run [ <span class="CommentedCode">#? $start-tracing #? 3</span> - 1:address:screen<span class="Special"> <- </span>init-fake-screen 3:literal/width, 2:literal/height - 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, 97:literal <span class="Comment"># 'a'</span> + 1:address:screen<span class="Special"> <- </span>init-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span> + 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> 2:address:array:character<span class="Special"> <- </span>get 1:address:screen/deref, data:offset 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 3<span class="Special"> <- </span>6 <span class="Comment"># width*height</span> 4<span class="Special"> <- </span>97 <span class="Comment"># 'a'</span> 5<span class="Special"> <- </span>0 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -recipe clear-line <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +scenario print-backspace-character [ + run [ +<span class="CommentedCode">#? $start-tracing #? 3</span> + 1:address:screen<span class="Special"> <- </span>init-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span> + 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">8:literal</span> <span class="Comment"># backspace</span> + 2:number<span class="Special"> <- </span>get 1:address:screen/deref, cursor-column:offset + 3:address:array:character<span class="Special"> <- </span>get 1:address:screen/deref, data:offset + 4:array:character<span class="Special"> <- </span>copy 3:address:array:character/deref + ] + memory-should-contain [ + 2<span class="Special"> <- </span>0 <span class="Comment"># cursor column</span> + 4<span class="Special"> <- </span>6 <span class="Comment"># width*height</span> + 5<span class="Special"> <- </span>32 <span class="Comment"># space, not 'a'</span> + 6<span class="Special"> <- </span>0 + ] +] + +scenario print-newline-character [ + run [ +<span class="CommentedCode">#? $start-tracing #? 3</span> + 1:address:screen<span class="Special"> <- </span>init-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span> + 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</span> + 2:number<span class="Special"> <- </span>get 1:address:screen/deref, cursor-row:offset + 3:number<span class="Special"> <- </span>get 1:address:screen/deref, cursor-column:offset + 4:address:array:character<span class="Special"> <- </span>get 1:address:screen/deref, data:offset + 5:array:character<span class="Special"> <- </span>copy 4:address:array:character/deref + ] + memory-should-contain [ + 2<span class="Special"> <- </span>1 <span class="Comment"># cursor row</span> + 3<span class="Special"> <- </span>0 <span class="Comment"># cursor column</span> + 5<span class="Special"> <- </span>6 <span class="Comment"># width*height</span> + 6<span class="Special"> <- </span>97 <span class="Comment"># 'a'</span> + 7<span class="Special"> <- </span>0 + ] +] + +recipe clear-line [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient <span class="Comment"># if x exists, clear line in fake screen</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:screen - n:integer<span class="Special"> <- </span>get x:address:screen/deref, num-columns:offset - column:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset - original-column:integer<span class="Special"> <- </span>copy column:address:integer/deref + n:number<span class="Special"> <- </span>get x:address:screen/deref, num-columns:offset + column:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset + original-column:number<span class="Special"> <- </span>copy column:address:number/deref <span class="Comment"># space over the entire line</span> +<span class="CommentedCode">#? $start-tracing #? 1</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal column:address:integer/deref, n:integer +<span class="CommentedCode">#? $print column:address:number/deref, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal column:address:number/deref, n:number <span class="Identifier">break-if</span> done?:boolean - print-character x:address:screen, <span class="Delimiter">[</span> <span class="Delimiter">]</span> <span class="Comment"># implicitly updates 'column'</span> + print-character x:address:screen, <span class="Constant">[ ]</span> <span class="Comment"># implicitly updates 'column'</span> <span class="Identifier">loop</span> <span class="Delimiter">}</span> <span class="Comment"># now back to where the cursor was</span> - column:address:integer/deref<span class="Special"> <- </span>copy original-column:integer + column:address:number/deref<span class="Special"> <- </span>copy original-column:number <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> clear-line-on-display <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -recipe cursor-position <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe cursor-position [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient <span class="Comment"># if x exists, lookup cursor in fake screen</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:screen - row:integer<span class="Special"> <- </span>get x:address:screen/deref, cursor-row:offset - column:integer<span class="Special"> <- </span>get x:address:screen/deref, cursor-column:offset - <span class="Identifier">reply</span> row:integer, column:integer + row:number<span class="Special"> <- </span>get x:address:screen/deref, cursor-row:offset + column:number<span class="Special"> <- </span>get x:address:screen/deref, cursor-column:offset + <span class="Identifier">reply</span> row:number, column:number, x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> - row:integer, column:integer<span class="Special"> <- </span>cursor-position-on-display - <span class="Identifier">reply</span> row:integer, column:integer -<span class="Delimiter">]</span> + row:number, column:number<span class="Special"> <- </span>cursor-position-on-display + <span class="Identifier">reply</span> row:number, column:number, x:address:screen/same-as-ingredient:0 +] -recipe move-cursor <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe move-cursor [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient - new-row:integer<span class="Special"> <- </span>next-ingredient - new-column:integer<span class="Special"> <- </span>next-ingredient + new-row:number<span class="Special"> <- </span>next-ingredient + new-column:number<span class="Special"> <- </span>next-ingredient <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:screen - row:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref cursor-row:offset - row:address:integer/deref<span class="Special"> <- </span>copy new-row:integer - column:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref cursor-column:offset - column:address:integer/deref<span class="Special"> <- </span>copy new-column:integer + row:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-row:offset + row:address:number/deref<span class="Special"> <- </span>copy new-row:number + column:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset + column:address:number/deref<span class="Special"> <- </span>copy new-column:number <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> - move-cursor-on-display new-row:integer, new-column:integer + move-cursor-on-display new-row:number, new-column:number <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -scenario clear-line-erases-printed-characters <span class="Delimiter">[</span> - run <span class="Delimiter">[</span> -<span class="CommentedCode">#? $start-tracing #? 3</span> - 1:address:screen<span class="Special"> <- </span>init-fake-screen 3:literal/width, 2:literal/height +scenario clear-line-erases-printed-characters [ + run [ +<span class="CommentedCode">#? $start-tracing #? 4</span> + 1:address:screen<span class="Special"> <- </span>init-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span> <span class="Comment"># print a character</span> - 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, 97:literal <span class="Comment"># 'a'</span> + 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> <span class="Comment"># move cursor to start of line</span> - 1:address:screen<span class="Special"> <- </span>move-cursor 1:address:screen, 0:literal/row, 0:literal/column + 1:address:screen<span class="Special"> <- </span>move-cursor 1:address:screen, <span class="Constant">0:literal/row</span>, <span class="Constant">0:literal/column</span> <span class="Comment"># clear line</span> 1:address:screen<span class="Special"> <- </span>clear-line 1:address:screen 2:address:array:character<span class="Special"> <- </span>get 1:address:screen/deref, data:offset 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref - <span class="Delimiter">]</span> + ] <span class="Comment"># screen should be blank</span> - memory-should-contain <span class="Delimiter">[</span> + memory-should-contain [ 3<span class="Special"> <- </span>6 <span class="Comment"># width*height</span> 4<span class="Special"> <- </span>0 5<span class="Special"> <- </span>0 @@ -215,94 +292,143 @@ scenario clear-line-erases-printed-characters <span class="Delimiter">[</span> 7<span class="Special"> <- </span>0 8<span class="Special"> <- </span>0 9<span class="Special"> <- </span>0 - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] +] -recipe cursor-down <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe cursor-down [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:screen <span class="Delimiter">{</span> <span class="Comment"># if row < height</span> - height:integer<span class="Special"> <- </span>get x:address:screen/deref, num-rows:offset - row:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref cursor-row:offset - at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row:address:integer/deref, height:integer + height:number<span class="Special"> <- </span>get x:address:screen/deref, num-rows:offset + row:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-row:offset + at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row:address:number/deref, height:number <span class="Identifier">break-if</span> at-bottom?:boolean <span class="Comment"># row = row+1</span> - row:address:integer/deref<span class="Special"> <- </span>add row:address:integer, 1:literal +<span class="CommentedCode">#? $print [AAA: ], row:address:number, [ -> ], row:address:number/deref, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + row:address:number/deref<span class="Special"> <- </span>add row:address:number/deref, <span class="Constant">1:literal</span> +<span class="CommentedCode">#? $print [BBB: ], row:address:number, [ -> ], row:address:number/deref, [ </span> +<span class="CommentedCode">#? ] #? 1</span> +<span class="CommentedCode">#? $start-tracing #? 1</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-down-on-display <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -recipe cursor-up <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe cursor-up [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:screen <span class="Delimiter">{</span> <span class="Comment"># if row >= 0</span> - row:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref cursor-row:offset - at-top?:boolean<span class="Special"> <- </span>lesser-than row:address:integer/deref, 0:literal + row:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-row:offset + at-top?:boolean<span class="Special"> <- </span>lesser-than row:address:number/deref, <span class="Constant">0:literal</span> <span class="Identifier">break-if</span> at-top?:boolean <span class="Comment"># row = row-1</span> - row:address:integer/deref<span class="Special"> <- </span>subtract row:address:integer, 1:literal + row:address:number/deref<span class="Special"> <- </span>subtract row:address:number/deref, <span class="Constant">1:literal</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-up-on-display <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -recipe cursor-right <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe cursor-right [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:screen <span class="Delimiter">{</span> <span class="Comment"># if column < width</span> - width:integer<span class="Special"> <- </span>get x:address:screen/deref, num-columns:offset - column:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref cursor-column:offset - at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal column:address:integer/deref, width:integer + width:number<span class="Special"> <- </span>get x:address:screen/deref, num-columns:offset + column:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset + at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal column:address:number/deref, width:number <span class="Identifier">break-if</span> at-bottom?:boolean <span class="Comment"># column = column+1</span> - column:address:integer/deref<span class="Special"> <- </span>add column:address:integer, 1:literal + column:address:number/deref<span class="Special"> <- </span>add column:address:number/deref, <span class="Constant">1:literal</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-right-on-display <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -recipe cursor-left <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe cursor-left [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:screen<span class="Special"> <- </span>next-ingredient <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:screen <span class="Delimiter">{</span> <span class="Comment"># if column >= 0</span> - column:address:integer<span class="Special"> <- </span>get-address x:address:screen/deref cursor-column:offset - at-top?:boolean<span class="Special"> <- </span>lesser-than column:address:integer/deref, 0:literal + column:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset + at-top?:boolean<span class="Special"> <- </span>lesser-than column:address:number/deref, <span class="Constant">0:literal</span> <span class="Identifier">break-if</span> at-top?:boolean <span class="Comment"># column = column-1</span> - column:address:integer/deref<span class="Special"> <- </span>subtract column:address:integer, 1:literal + column:address:number/deref<span class="Special"> <- </span>subtract column:address:number/deref, <span class="Constant">1:literal</span> <span class="Delimiter">}</span> <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-left-on-display <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 -<span class="Delimiter">]</span> +] + +recipe cursor-to-start-of-line [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:screen<span class="Special"> <- </span>next-ingredient + row:number, _, x:address:screen<span class="Special"> <- </span>cursor-position x:address:screen + column:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + x:address:screen<span class="Special"> <- </span>move-cursor x:address:screen, row:number, column:number + <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 +] + +recipe cursor-to-next-line [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:screen<span class="Special"> <- </span>next-ingredient + x:address:screen<span class="Special"> <- </span>cursor-down x:address:screen + x:address:screen<span class="Special"> <- </span>cursor-to-start-of-line x:address:screen + <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 +] + +recipe print-string [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:screen<span class="Special"> <- </span>next-ingredient + s:address:array:character<span class="Special"> <- </span>next-ingredient + len:number<span class="Special"> <- </span>length s:address:array:character/deref + i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + <span class="Delimiter">{</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, len:number + <span class="Identifier">break-if</span> done?:boolean + c:character<span class="Special"> <- </span>index s:address:array:character/deref, i:number + print-character x:address:screen c:character + i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 +] + +recipe print-integer [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + x:address:screen<span class="Special"> <- </span>next-ingredient + n:number<span class="Special"> <- </span>next-ingredient + <span class="Comment"># todo: other bases besides decimal</span> + s:address:array:character<span class="Special"> <- </span>integer-to-decimal-string n:number + print-string x:address:screen, s:address:array:character + <span class="Identifier">reply</span> x:address:screen/same-as-ingredient:0 +] </pre> </body> </html> diff --git a/html/072scenario_screen.cc.html b/html/072scenario_screen.cc.html index d5426460..79cc6044 100644 --- a/html/072scenario_screen.cc.html +++ b/html/072scenario_screen.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 072scenario_screen.cc</title> +<title>~/Desktop/s/mu/072scenario_screen.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -83,14 +83,14 @@ assert<span class="Delimiter">(</span>Next_predefined_global_for_scenarios < <span class="Comment">// There's a restriction on the number of variables 'run' can use, so that</span> <span class="Comment">// it can avoid colliding with the dynamic allocator in case it doesn't</span> <span class="Comment">// initialize a default-space.</span> -assert<span class="Delimiter">(</span>Name[tmp_recipe[<span class="Constant">0</span>]][<span class="Constant">""</span>] < Max_variables_in_scenarios<span class="Delimiter">);</span> +assert<span class="Delimiter">(</span>Name[tmp_recipe<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>][<span class="Constant">""</span>] < Max_variables_in_scenarios<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Globals")</span> <span class="Comment">// Scenario Globals.</span> const size_t SCREEN = Next_predefined_global_for_scenarios++<span class="Delimiter">;</span> <span class="Comment">// End Scenario Globals.</span> <span class="Delimiter">:(before "End Predefined Scenario Locals In Run")</span> -Name[tmp_recipe[<span class="Constant">0</span>]][<span class="Constant">"screen"</span>] = SCREEN<span class="Delimiter">;</span> +Name[tmp_recipe<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>][<span class="Constant">"screen"</span>] = SCREEN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Rewrite Instruction(curr)")</span> <span class="Comment">// rewrite `assume-screen width, height` to</span> @@ -100,7 +100,7 @@ if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == < curr<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"init-fake-screen"</span>]<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<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><span class="Constant">"screen:address"</span><span class="Delimiter">));</span> - curr<span class="Delimiter">.</span>products[<span class="Constant">0</span>]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>SCREEN<span class="Delimiter">);</span> + curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>SCREEN<span class="Delimiter">);</span> <span class="CommentedCode">//? cout << "after: " << curr.to_string() << '\n'; //? 1</span> <span class="CommentedCode">//? cout << "AAA " << Recipe_number["init-fake-screen"] << '\n'; //? 1</span> <span class="Delimiter">}</span> @@ -113,13 +113,14 @@ Recipe_number[<span class="Constant">"screen-should-contain"</span>] = <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case SCREEN_SHOULD_CONTAIN: <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "AAA\n"; //? 1</span> - check_screen<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">);</span> + check_screen<span class="Delimiter">(</span>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>name<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> void check_screen<span class="Delimiter">(</span>const string& contents<span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span> <span class="Comment">// not supported</span> +<span class="CommentedCode">//? cerr << "Checking screen\n"; //? 1</span> + assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span> <span class="Comment">// not supported</span> index_t screen_location = Memory[SCREEN]<span class="Delimiter">;</span> int data_offset = find_element_name<span class="Delimiter">(</span>Type_number[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"data"</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>data_offset >= <span class="Constant">0</span><span class="Delimiter">);</span> @@ -151,15 +152,62 @@ void check_screen<span class="Delimiter">(</span>const string& contents<span ++screen_data_start<span class="Delimiter">;</span> <span class="Comment">// now skip length</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < expected_contents<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"checking location "</span> << screen_data_start+i<span class="Delimiter">;</span> - if <span class="Delimiter">((</span>!Memory[screen_data_start+i] && !isspace<span class="Delimiter">(</span>expected_contents[i]<span class="Delimiter">))</span> <span class="Comment">// uninitialized memory => spaces</span> - || <span class="Delimiter">(</span>Memory[screen_data_start+i] && Memory[screen_data_start+i] != expected_contents[i]<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cerr << "comparing " << i/screen_width << ", " << i%screen_width << ": " << Memory[screen_data_start+i] << " vs " << (int)expected_contents.at(i) << '\n'; //? 1</span> + if <span class="Delimiter">((</span>!Memory[screen_data_start+i] && !isspace<span class="Delimiter">(</span>expected_contents<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Comment">// uninitialized memory => spaces</span> + || <span class="Delimiter">(</span>Memory[screen_data_start+i] && Memory[screen_data_start+i] != expected_contents<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "CCC " << Trace_stream << " " << Hide_warnings << '\n'; //? 1</span> - raise << <span class="Constant">"expected screen location ("</span> << i/screen_width << <span class="Constant">", "</span> << i%screen_width << <span class="Constant">") to contain '"</span> << expected_contents[i] << <span class="Constant">"' instead of '"</span> << static_cast<char><span class="Delimiter">(</span>Memory[screen_data_start+i]<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - Passed = <span class="Constant">false</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Current_scenario && !Hide_warnings<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// genuine test in a mu file</span> + raise << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << Current_scenario<span class="Delimiter">-></span>name << <span class="Constant">": expected screen location ("</span> << i/screen_width << <span class="Constant">", "</span> << i%screen_width << <span class="Constant">") to contain '"</span> << expected_contents<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> << <span class="Constant">"' instead of '"</span> << static_cast<char><span class="Delimiter">(</span>Memory[screen_data_start+i]<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + dump_screen<span class="Delimiter">();</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + <span class="Comment">// just testing check_screen</span> + raise << <span class="Constant">"expected screen location ("</span> << i/screen_width << <span class="Constant">", "</span> << i%screen_width << <span class="Constant">") to contain '"</span> << expected_contents<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> << <span class="Constant">"' instead of '"</span> << static_cast<char><span class="Delimiter">(</span>Memory[screen_data_start+i]<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>!Hide_warnings<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> <span class="Delimiter">}</span> <span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +_DUMP_SCREEN<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"$dump-screen"</span>] = _DUMP_SCREEN<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case _DUMP_SCREEN: <span class="Delimiter">{</span> + dump_screen<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(code)</span> +void dump_screen<span class="Delimiter">()</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span> <span class="Comment">// not supported</span> + index_t screen_location = Memory[SCREEN]<span class="Delimiter">;</span> + int width_offset = find_element_name<span class="Delimiter">(</span>Type_number[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-columns"</span><span class="Delimiter">);</span> + size_t screen_width = Memory[screen_location+width_offset]<span class="Delimiter">;</span> + int height_offset = find_element_name<span class="Delimiter">(</span>Type_number[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-rows"</span><span class="Delimiter">);</span> + size_t screen_height = Memory[screen_location+height_offset]<span class="Delimiter">;</span> + int data_offset = find_element_name<span class="Delimiter">(</span>Type_number[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"data"</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>data_offset >= <span class="Constant">0</span><span class="Delimiter">);</span> + index_t screen_data_location = screen_location+data_offset<span class="Delimiter">;</span> <span class="Comment">// type: address:array:character</span> + index_t screen_data_start = Memory[screen_data_location]<span class="Delimiter">;</span> <span class="Comment">// type: array:character</span> +<span class="CommentedCode">//? cerr << "data start: " << screen_data_start << '\n'; //? 1</span> + assert<span class="Delimiter">(</span>Memory[screen_data_start] == screen_width*screen_height<span class="Delimiter">);</span> + index_t curr = screen_data_start+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// skip length</span> + for <span class="Delimiter">(</span>index_t row = <span class="Constant">0</span><span class="Delimiter">;</span> row < screen_height<span class="Delimiter">;</span> ++row<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cerr << curr << ":\n"; //? 1</span> + for <span class="Delimiter">(</span>index_t col = <span class="Constant">0</span><span class="Delimiter">;</span> col < screen_width<span class="Delimiter">;</span> ++col<span class="Delimiter">)</span> <span class="Delimiter">{</span> + cerr << static_cast<char><span class="Delimiter">(</span>Memory[curr]<span class="Delimiter">);</span> + ++curr<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> </pre> </body> </html> diff --git a/html/073scenario_screen_test.mu.html b/html/073scenario_screen_test.mu.html index 0da61050..3213a549 100644 --- a/html/073scenario_screen_test.mu.html +++ b/html/073scenario_screen_test.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 073scenario_screen_test.mu</title> +<title>~/Desktop/s/mu/073scenario_screen_test.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -14,9 +14,8 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .Comment { color: #8080ff; } -.Delimiter { color: #c000c0; } +.Constant { color: #008080; } .Special { color: #ff6060; } -.Identifier { color: #008080; } --> </style> @@ -30,33 +29,33 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <pre id='vimCodeElement'> <span class="Comment"># To check our support for screens in scenarios, rewrite tests from print.mu</span> -scenario print-character-at-top-left2 <span class="Delimiter">[</span> - assume-screen 3:literal/width, 2:literal/height - run <span class="Delimiter">[</span> - screen:address<span class="Special"> <- </span>print-character screen:address, 97:literal <span class="Comment"># 'a'</span> - <span class="Delimiter">]</span> - screen-should-contain <span class="Delimiter">[</span> - <span class="Identifier"> .a</span> . - . . - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> +scenario print-character-at-top-left2 [ + assume-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span> + run [ + screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + ] + screen-should-contain [ + <span class="Constant"> .a .</span> + <span class="Constant"> . .</span> + ] +] -scenario clear-line-erases-printed-characters2 <span class="Delimiter">[</span> - assume-screen 5:literal/width, 3:literal/height - run <span class="Delimiter">[</span> +scenario clear-line-erases-printed-characters2 [ + assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">3:literal/height</span> + run [ <span class="Comment"># print a character</span> - screen:address<span class="Special"> <- </span>print-character screen:address, 97:literal <span class="Comment"># 'a'</span> + screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> <span class="Comment"># move cursor to start of line</span> - screen:address<span class="Special"> <- </span>move-cursor screen:address, 0:literal/row, 0:literal/column + screen:address<span class="Special"> <- </span>move-cursor screen:address, <span class="Constant">0:literal/row</span>, <span class="Constant">0:literal/column</span> <span class="Comment"># clear line</span> screen:address<span class="Special"> <- </span>clear-line screen:address - <span class="Delimiter">]</span> - screen-should-contain <span class="Delimiter">[</span> - . . - . . - . . - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + ] + screen-should-contain [ + <span class="Constant"> . .</span> + <span class="Constant"> . .</span> + <span class="Constant"> . .</span> + ] +] </pre> </body> </html> diff --git a/html/074keyboard.mu.html b/html/074keyboard.mu.html index 13460315..e2b055a3 100644 --- a/html/074keyboard.mu.html +++ b/html/074keyboard.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 074keyboard.mu</title> +<title>~/Desktop/s/mu/074keyboard.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -14,8 +14,9 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .Identifier { color: #008080; } -.Comment { color: #8080ff; } .Delimiter { color: #c000c0; } +.Comment { color: #8080ff; } +.Constant { color: #008080; } .Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } --> @@ -32,46 +33,48 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment"># Wrappers around keyboard primitives that take a 'keyboard' object and are thus</span> <span class="Comment"># easier to test.</span> -container keyboard <span class="Delimiter">[</span> <span class="Comment"># can't think of another word like screen/display, so real and fake keyboards use the same name</span> - index:integer - data:address:array:character -<span class="Delimiter">]</span> +container keyboard <span class="Constant">[ # can't think of another word like screen/display, so real and fake keyboards use the same name</span> +<span class="Constant"> index:number</span> +<span class="Constant"> data:address:array:character</span> +<span class="Constant">]</span> -recipe init-fake-keyboard <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe init-fake-keyboard [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> result:address:keyboard<span class="Special"> <- </span>new keyboard:type - buf:address:address:array:character<span class="Special"> <- </span>get-address result:address:keyboard/deref data:offset + buf:address:address:array:character<span class="Special"> <- </span>get-address result:address:keyboard/deref, data:offset <span class="CommentedCode">#? $start-tracing #? 1</span> buf:address:address:array:character/deref<span class="Special"> <- </span>next-ingredient <span class="CommentedCode">#? $stop-tracing #? 1</span> - idx:address:integer<span class="Special"> <- </span>get-address result:address:keyboard/deref index:offset - idx:address:integer/deref<span class="Special"> <- </span>copy 0:literal + idx:address:number<span class="Special"> <- </span>get-address result:address:keyboard/deref, index:offset + idx:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Identifier">reply</span> result:address:keyboard -<span class="Delimiter">]</span> +] -recipe read-key <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe read-key [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:keyboard<span class="Special"> <- </span>next-ingredient <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:keyboard - idx:address:integer<span class="Special"> <- </span>get-address x:address:keyboard/deref, index:offset + idx:address:number<span class="Special"> <- </span>get-address x:address:keyboard/deref, index:offset buf:address:array:character<span class="Special"> <- </span>get x:address:keyboard/deref, data:offset - max:integer<span class="Special"> <- </span>length buf:address:array:character/deref + max:number<span class="Special"> <- </span>length buf:address:array:character/deref <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal idx:address:integer/deref, max:integer + done?:boolean<span class="Special"> <- </span>greater-or-equal idx:address:number/deref, max:number <span class="Identifier">break-unless</span> done?:boolean - <span class="Identifier">reply</span> 0:literal, 0:literal/done, x:address:keyboard/same-as-ingredient:0 + <span class="Identifier">reply</span> <span class="Constant">0:literal/eof</span>, <span class="Constant">1:literal/found</span>, x:address:keyboard/same-as-ingredient:0 <span class="Delimiter">}</span> - c:character<span class="Special"> <- </span>index buf:address:array:character/deref, idx:address:integer/deref - idx:address:integer/deref<span class="Special"> <- </span>add idx:address:integer/deref, 1:literal - <span class="Identifier">reply</span> c:character, 1:literal/found, x:address:keyboard/same-as-ingredient:0 + c:character<span class="Special"> <- </span>index buf:address:array:character/deref, idx:address:number/deref + idx:address:number/deref<span class="Special"> <- </span>add idx:address:number/deref, <span class="Constant">1:literal</span> + <span class="Identifier">reply</span> c:character, <span class="Constant">1:literal/found</span>, x:address:keyboard/same-as-ingredient:0 <span class="Delimiter">}</span> + <span class="Comment"># real keyboard input is infrequent; avoid polling it too much</span> + switch c:character, found?:boolean<span class="Special"> <- </span>read-key-from-keyboard <span class="Identifier">reply</span> c:character, found?:boolean, x:address:keyboard/same-as-ingredient:0 -<span class="Delimiter">]</span> +] -recipe wait-for-key <span class="Delimiter">[</span> - default-space:address:array:location<span class="Special"> <- </span>new location:type, 30:literal +recipe wait-for-key [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> x:address:keyboard<span class="Special"> <- </span>next-ingredient <span class="Delimiter">{</span> <span class="Identifier">break-unless</span> x:address:keyboard @@ -81,7 +84,23 @@ recipe wait-for-key <span class="Delimiter">[</span> <span class="Delimiter">}</span> c:character<span class="Special"> <- </span>wait-for-key-from-keyboard <span class="Identifier">reply</span> c:character, x:address:keyboard/same-as-ingredient:0 -<span class="Delimiter">]</span> +] + +recipe send-keys-to-channel [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + keyboard:address<span class="Special"> <- </span>next-ingredient + chan:address:channel<span class="Special"> <- </span>next-ingredient + screen:address<span class="Special"> <- </span>next-ingredient + <span class="Delimiter">{</span> + c:character, found?:boolean<span class="Special"> <- </span>read-key keyboard:address + <span class="Identifier">loop-unless</span> found?:boolean +<span class="CommentedCode">#? print-integer screen:address, c:character #? 1</span> + print-character screen:address, c:character + chan:address:channel<span class="Special"> <- </span>write chan:address:channel, c:character + <span class="Comment"># todo: eof</span> + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> +] </pre> </body> </html> diff --git a/html/075scenario_keyboard.cc.html b/html/075scenario_keyboard.cc.html index 3add7460..2a612899 100644 --- a/html/075scenario_keyboard.cc.html +++ b/html/075scenario_keyboard.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 075scenario_keyboard.cc</title> +<title>~/Desktop/s/mu/075scenario_keyboard.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -45,20 +45,20 @@ scenario keyboard-in-scenario [ ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> - <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first read-key call found a character</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">98</span> <span class="Comment"># 'b'</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># second read-key call found a character</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">99</span> <span class="Comment"># 'c'</span> - <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># third read-key call found a character</span> - <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">0</span> - <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># fourth read-key call didn't find a character</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># eof</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">1</span> ] ] <span class="Delimiter">:(before "End Scenario Globals")</span> const size_t KEYBOARD = Next_predefined_global_for_scenarios++<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Predefined Scenario Locals In Run")</span> -Name[tmp_recipe[<span class="Constant">0</span>]][<span class="Constant">"keyboard"</span>] = KEYBOARD<span class="Delimiter">;</span> +Name[tmp_recipe<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>][<span class="Constant">"keyboard"</span>] = KEYBOARD<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Rewrite Instruction(curr)")</span> <span class="Comment">// rewrite `assume-keyboard string` to</span> @@ -71,17 +71,17 @@ if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == < curr<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"new"</span>]<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<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><span class="Constant">"keyboard:address"</span><span class="Delimiter">));</span> - curr<span class="Delimiter">.</span>products[<span class="Constant">0</span>]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>KEYBOARD<span class="Delimiter">);</span> + curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>KEYBOARD<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="Comment">// hacky that "Rewrite Instruction" is converting to multiple instructions</span> <span class="Comment">// leave second instruction in curr</span> curr<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> curr<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"init-fake-keyboard"</span>]<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<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">"keyboard:address"</span><span class="Delimiter">));</span> - curr<span class="Delimiter">.</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>KEYBOARD<span class="Delimiter">);</span> + curr<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>KEYBOARD<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<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><span class="Constant">"keyboard:address"</span><span class="Delimiter">));</span> - curr<span class="Delimiter">.</span>products[<span class="Constant">0</span>]<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>KEYBOARD<span class="Delimiter">);</span> + curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>KEYBOARD<span class="Delimiter">);</span> <span class="Delimiter">}</span> </pre> </body> diff --git a/html/076scenario_keyboard_test.mu.html b/html/076scenario_keyboard_test.mu.html index 233ae5eb..00081624 100644 --- a/html/076scenario_keyboard_test.mu.html +++ b/html/076scenario_keyboard_test.mu.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 076scenario_keyboard_test.mu</title> +<title>~/Desktop/s/mu/076scenario_keyboard_test.mu</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="none"> @@ -14,7 +14,7 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .Comment { color: #8080ff; } -.Delimiter { color: #c000c0; } +.Constant { color: #008080; } .Special { color: #ff6060; } --> </style> @@ -31,25 +31,25 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment"># scenario_keyboard.mu</span> <span class="Comment"># Tests for keyboard interface.</span> -scenario read-key-in-mu <span class="Delimiter">[</span> - assume-keyboard <span class="Delimiter">[</span>abc<span class="Delimiter">]</span> - run <span class="Delimiter">[</span> +scenario read-key-in-mu [ + assume-keyboard <span class="Constant">[abc]</span> + run [ 1:character, 2:boolean, keyboard:address<span class="Special"> <- </span>read-key keyboard:address 3:character, 4:boolean, keyboard:address<span class="Special"> <- </span>read-key keyboard:address 5:character, 6:boolean, keyboard:address<span class="Special"> <- </span>read-key keyboard:address 7:character, 8:boolean, keyboard:address<span class="Special"> <- </span>read-key keyboard:address - <span class="Delimiter">]</span> - memory-should-contain <span class="Delimiter">[</span> + ] + memory-should-contain [ 1<span class="Special"> <- </span>97 <span class="Comment"># 'a'</span> - 2<span class="Special"> <- </span>1 <span class="Comment"># first read-key call found a character</span> + 2<span class="Special"> <- </span>1 3<span class="Special"> <- </span>98 <span class="Comment"># 'b'</span> - 4<span class="Special"> <- </span>1 <span class="Comment"># second read-key call found a character</span> + 4<span class="Special"> <- </span>1 5<span class="Special"> <- </span>99 <span class="Comment"># 'c'</span> - 6<span class="Special"> <- </span>1 <span class="Comment"># third read-key call found a character</span> - 7<span class="Special"> <- </span>0 - 8<span class="Special"> <- </span>0 <span class="Comment"># fourth read-key call didn't find a character</span> - <span class="Delimiter">]</span> -<span class="Delimiter">]</span> + 6<span class="Special"> <- </span>1 + 7<span class="Special"> <- </span>0 <span class="Comment"># eof</span> + 8<span class="Special"> <- </span>1 + ] +] </pre> </body> </html> diff --git a/html/chessboard.mu.html b/html/chessboard.mu.html new file mode 100644 index 00000000..7a0a3c9e --- /dev/null +++ b/html/chessboard.mu.html @@ -0,0 +1,704 @@ +<!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>chessboard.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: #d0d0d0; background-color: #000000; } +body { font-family: monospace; color: #d0d0d0; background-color: #000000; } +* { font-size: 1em; } +.Identifier { color: #008080; } +.Delimiter { color: #c000c0; } +.Comment { color: #8080ff; } +.Constant { color: #008080; } +.Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment"># Chessboard program: you type in moves in algebraic notation, and it'll</span> +<span class="Comment"># display the position after each move.</span> + +<span class="Comment"># recipes are mu's names for functions</span> +recipe main [ + switch-to-display <span class="Comment"># take control of screen and keyboard</span> + + <span class="Comment"># The chessboard recipe takes keyboard and screen objects as 'ingredients'.</span> + <span class="Comment">#</span> + <span class="Comment"># In mu it is good form (though not required) to explicitly show the</span> + <span class="Comment"># hardware you rely on.</span> + <span class="Comment">#</span> + <span class="Comment"># The chessboard also returns the same keyboard and screen objects. In mu it</span> + <span class="Comment"># is good form to not modify ingredients of a recipe unless they are also</span> + <span class="Comment"># results. Here we clearly modify both keyboard and screen, so we return</span> + <span class="Comment"># both.</span> + <span class="Comment">#</span> + <span class="Comment"># Here the keyboard and screen are both 0, which usually indicates real</span> + <span class="Comment"># hardware rather than a fake for testing as you'll see below.</span> + <span class="Constant">0:literal/real-screen</span>, <span class="Constant">0:literal/real-keyboard</span><span class="Special"> <- </span>chessboard <span class="Constant">0:literal/real-screen</span>, <span class="Constant">0:literal/real-keyboard</span> + + return-to-console <span class="Comment"># cleanup screen and keyboard</span> +] + +<span class="Comment"># But enough about mu. Here's what it looks like to run the chessboard</span> +<span class="Comment"># program.</span> + +scenario print-board-and-read-move [ + <span class="Comment"># we'll make the screen really wide because the program currently prints out a long line</span> + assume-screen <span class="Constant">120:literal/width</span>, <span class="Constant">20:literal/height</span> + <span class="Comment"># initialize keyboard to type in a move</span> + assume-keyboard <span class="Constant">[a2-a4</span> +<span class="Constant">]</span> + run [ + screen:address, keyboard:address<span class="Special"> <- </span>chessboard screen:address, keyboard:address +<span class="CommentedCode">#? $dump-screen #? 1</span> + ] + screen-should-contain [ + <span class="Comment"># 1 2 3 4 5 6 7 8 9 10 11</span> + <span class="Comment"># 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789</span> + <span class="Constant"> .Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves. .</span> + <span class="Constant"> . .</span> + <span class="Constant"> .8 | r n b q k b n r .</span> + <span class="Constant"> .7 | p p p p p p p p .</span> + <span class="Constant"> .6 | .</span> + <span class="Constant"> .5 | .</span> + <span class="Constant"> .4 | P .</span> + <span class="Constant"> .3 | .</span> + <span class="Constant"> .2 | P P P P P P P .</span> + <span class="Constant"> .1 | R N B Q K B N R .</span> + <span class="Constant"> . +---------------- .</span> + <span class="Constant"> . a b c d e f g h .</span> + <span class="Constant"> . .</span> + <span class="Constant"> .Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>. .</span> + <span class="Constant"> . .</span> + <span class="Constant"> .Hit 'q' to exit. .</span> + <span class="Constant"> . .</span> + <span class="Constant"> .move: .</span> + <span class="Constant"> . .</span> + <span class="Constant"> . .</span> + ] + <span class="Comment"># todo: doesn't show the cursor position yet (it's right after the 'move: ')</span> +] + +recipe chessboard [ +<span class="CommentedCode">#? $start-tracing [schedule] #? 2</span> +<span class="CommentedCode">#? $start-tracing #? 1</span> + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + screen:address<span class="Special"> <- </span>next-ingredient + keyboard:address<span class="Special"> <- </span>next-ingredient +<span class="CommentedCode">#? $print [screen: ], screen:address, [, keyboard: ], keyboard:address, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + board:address:array:address:array:character<span class="Special"> <- </span>initial-position + <span class="Comment"># hook up stdin</span> + stdin:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">10:literal/capacity</span> + start-running send-keys-to-channel:recipe, keyboard:address, stdin:address:channel, screen:address + <span class="Comment"># buffer lines in stdin</span> + buffered-stdin:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">10:literal/capacity</span> + start-running buffer-lines:recipe, stdin:address:channel, buffered-stdin:address:channel + <span class="Delimiter">{</span> + msg:address:array:character<span class="Special"> <- </span>new <span class="Constant">[Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves.</span> +<span class="Constant">]</span> + print-string screen:address, msg:address:array:character +<span class="CommentedCode">#? $print [aaa</span> +<span class="CommentedCode">#? ] #? 1</span> + cursor-to-next-line screen:address + print-board screen:address, board:address:array:address:array:character + cursor-to-next-line screen:address + msg:address:array:character<span class="Special"> <- </span>new <span class="Constant">[Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>.</span> +<span class="Constant">]</span> + print-string screen:address, msg:address:array:character +<span class="CommentedCode">#? $print [bbb</span> +<span class="CommentedCode">#? ] #? 1</span> + cursor-to-next-line screen:address + msg:address:array:character<span class="Special"> <- </span>new <span class="Constant">[Hit 'q' to exit.</span> +<span class="Constant">]</span> + print-string screen:address, msg:address:array:character +<span class="CommentedCode">#? $print [ccc</span> +<span class="CommentedCode">#? ] #? 1</span> + <span class="Delimiter">{</span> + cursor-to-next-line screen:address + msg:address:array:character<span class="Special"> <- </span>new <span class="Constant">[move: ]</span> + print-string screen:address, msg:address:array:character +<span class="CommentedCode">#? $print [ddd</span> +<span class="CommentedCode">#? ] #? 1</span> + m:address:move, quit:boolean, error:boolean<span class="Special"> <- </span>read-move buffered-stdin:address:channel, screen:address +<span class="CommentedCode">#? $print [eee</span> +<span class="CommentedCode">#? ] #? 1</span> + <span class="Identifier">break-if</span> quit:boolean,<span class="Identifier"> +quit</span>:offset + buffered-stdin:address:channel<span class="Special"> <- </span>clear-channel buffered-stdin:address:channel <span class="Comment"># cleanup after error. todo: test this?</span> + <span class="Identifier">loop-if</span> error:boolean + <span class="Delimiter">}</span> + board:address:array:address:array:character<span class="Special"> <- </span>make-move board:address:array:address:array:character, m:address:move + clear-screen screen:address + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> + <span class="Identifier"> +quit</span> +<span class="CommentedCode">#? $print [aaa] #? 1</span> +] + +<span class="SalientComment">## a board is an array of files, a file is an array of characters (squares)</span> + +recipe init-board [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + initial-position:address:array:number<span class="Special"> <- </span>next-ingredient + <span class="Comment"># assert(length(initial-position) == 64)</span> + len:number<span class="Special"> <- </span>length initial-position:address:array:number/deref + correct-length?:boolean<span class="Special"> <- </span>equal len:number, <span class="Constant">64:literal</span> + assert correct-length?:boolean, <span class="Constant">[chessboard had incorrect size]</span> + <span class="Comment"># board is an array of pointers to files; file is an array of characters</span> + board:address:array:address:array:character<span class="Special"> <- </span>new location:type, <span class="Constant">8:literal</span> + col:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + <span class="Delimiter">{</span> + done?:boolean<span class="Special"> <- </span>equal col:number, <span class="Constant">8:literal</span> + <span class="Identifier">break-if</span> done?:boolean + file:address:address:array:character<span class="Special"> <- </span>index-address board:address:array:address:array:character/deref, col:number + file:address:address:array:character/deref<span class="Special"> <- </span>init-file initial-position:address:array:number, col:number + col:number<span class="Special"> <- </span>add col:number, <span class="Constant">1:literal</span> + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> board:address:array:address:array:character +] + +recipe init-file [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + position:address:array:number<span class="Special"> <- </span>next-ingredient + index:number<span class="Special"> <- </span>next-ingredient + index:number<span class="Special"> <- </span>multiply index:number, <span class="Constant">8:literal</span> + result:address:array:character<span class="Special"> <- </span>new character:type, <span class="Constant">8:literal</span> + row:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + <span class="Delimiter">{</span> + done?:boolean<span class="Special"> <- </span>equal row:number, <span class="Constant">8:literal</span> + <span class="Identifier">break-if</span> done?:boolean + dest:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, row:number + dest:address:character/deref<span class="Special"> <- </span>index position:address:array:number/deref, index:number + row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> + index:number<span class="Special"> <- </span>add index:number, <span class="Constant">1:literal</span> + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> result:address:array:character +] + +recipe print-board [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + screen:address<span class="Special"> <- </span>next-ingredient + board:address:array:address:array:character<span class="Special"> <- </span>next-ingredient + row:number<span class="Special"> <- </span>copy <span class="Constant">7:literal</span> <span class="Comment"># start printing from the top of the board</span> + <span class="Comment"># print each row</span> +<span class="CommentedCode">#? $print [printing board to screen ], screen:address, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + <span class="Delimiter">{</span> + done?:boolean<span class="Special"> <- </span>lesser-than row:number, <span class="Constant">0:literal</span> + <span class="Identifier">break-if</span> done?:boolean +<span class="CommentedCode">#? $print [printing rank ], row:number, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + <span class="Comment"># print rank number as a legend</span> + rank:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> + print-integer screen:address, rank:number + s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ | ]</span> + print-string screen:address, s:address:array:character + <span class="Comment"># print each square in the row</span> + col:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + <span class="Delimiter">{</span> + done?:boolean<span class="Special"> <- </span>equal col:number, <span class="Constant">8:literal</span> + <span class="Identifier">break-if</span> done?:boolean + f:address:array:character<span class="Special"> <- </span>index board:address:array:address:array:character/deref, col:number + s:character<span class="Special"> <- </span>index f:address:array:character/deref, row:number + print-character screen:address, s:character + print-character screen:address, <span class="Constant">32:literal</span> <span class="Comment"># ' '</span> + col:number<span class="Special"> <- </span>add col:number, <span class="Constant">1:literal</span> + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> + row:number<span class="Special"> <- </span>subtract row:number, <span class="Constant">1:literal</span> + cursor-to-next-line screen:address + <span class="Identifier">loop</span> + <span class="Delimiter">}</span> + <span class="Comment"># print file letters as legend</span> +<span class="CommentedCode">#? $print [printing legend</span> +<span class="CommentedCode">#? ] #? 1</span> + s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ +----------------]</span> + print-string screen:address, s:address:array:character + screen:address<span class="Special"> <- </span>cursor-to-next-line screen:address +<span class="CommentedCode">#? screen:address <- print-character screen:address, 97:literal #? 1</span> + s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ a b c d e f g h]</span> + screen:address<span class="Special"> <- </span>print-string screen:address, s:address:array:character + screen:address<span class="Special"> <- </span>cursor-to-next-line screen:address +<span class="CommentedCode">#? $print [done printing board</span> +<span class="CommentedCode">#? ] #? 1</span> +] + +<span class="Comment"># board:address:array:address:array:character <- initial-position</span> +recipe initial-position [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + <span class="Comment"># layout in memory (in raster order):</span> + <span class="Comment"># R P _ _ _ _ p r</span> + <span class="Comment"># N P _ _ _ _ p n</span> + <span class="Comment"># B P _ _ _ _ p b</span> + <span class="Comment"># Q P _ _ _ _ p q</span> + <span class="Comment"># K P _ _ _ _ p k</span> + <span class="Comment"># B P _ _ _ _ p B</span> + <span class="Comment"># N P _ _ _ _ p n</span> + <span class="Comment"># R P _ _ _ _ p r</span> + initial-position:address:array:number<span class="Special"> <- </span>init-array <span class="Constant">82:literal/R</span>, <span class="Constant">80:literal/P</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">112:literal/p</span>, <span class="Constant">114:literal/r</span>, <span class="Constant">78:literal/N</span>, <span class="Constant">80:literal/P</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">112:literal/p</span>, <span class="Constant">110:literal/n</span>, <span class="Constant">66:literal/B</span>, <span class="Constant">80:literal/P</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">112:literal/p</span>, <span class="Constant">98:literal/b</span>, <span class="Constant">81:literal/Q</span>, <span class="Constant">80:literal/P</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">112:literal/p</span>, <span class="Constant">113:literal/q</span>, <span class="Constant">75:literal/K</span>, <span class="Constant">80:literal/P</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">112:literal/p</span>, <span class="Constant">107:literal/k</span>, <span class="Constant">66:literal/B</span>, <span class="Constant">80:literal/P</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">112:literal/p</span>, <span class="Constant">98:literal/b</span>, <span class="Constant">78:literal/N</span>, <span class="Constant">80:literal/P</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">112:literal/p</span>, <span class="Constant">110:literal/n</span>, <span class="Constant">82:literal/R</span>, <span class="Constant">80:literal/P</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">32:literal/blank</span>, <span class="Constant">112:literal/p</span>, <span class="Constant">114:literal/r</span> +<span class="CommentedCode">#? 82:literal/R, 80:literal/P, 32:literal/blank, 32:literal/blank, 32:literal/blank, 32:literal/blank, 112:literal/p, 114:literal/r,</span> +<span class="CommentedCode">#? 78:literal/N, 80:literal/P, 32:literal/blank, 32:literal/blank, 32:literal/blank, 32:literal/blank, 112:literal/p, 110:literal/n,</span> +<span class="CommentedCode">#? 66:literal/B, 80:literal/P, 32:literal/blank, 32:literal/blank, 32:literal/blank, 32:literal/blank, 112:literal/p, 98:literal/b, </span> +<span class="CommentedCode">#? 81:literal/Q, 80:literal/P, 32:literal/blank, 32:literal/blank, 32:literal/blank, 32:literal/blank, 112:literal/p, 113:literal/q,</span> +<span class="CommentedCode">#? 75:literal/K, 80:literal/P, 32:literal/blank, 32:literal/blank, 32:literal/blank, 32:literal/blank, 112:literal/p, 107:literal/k,</span> +<span class="CommentedCode">#? 66:literal/B, 80:literal/P, 32:literal/blank, 32:literal/blank, 32:literal/blank, 32:literal/blank, 112:literal/p, 98:literal/b,</span> +<span class="CommentedCode">#? 78:literal/N, 80:literal/P, 32:literal/blank, 32:literal/blank, 32:literal/blank, 32:literal/blank, 112:literal/p, 110:literal/n,</span> +<span class="CommentedCode">#? 82:literal/R, 80:literal/P, 32:literal/blank, 32:literal/blank, 32:literal/blank, 32:literal/blank, 112:literal/p, 114:literal/r</span> + board:address:array:address:array:character<span class="Special"> <- </span>init-board initial-position:address:array:number + <span class="Identifier">reply</span> board:address:array:address:array:character +] + +scenario printing-the-board [ + assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">12:literal/height</span> + run [ + 1:address:array:address:array:character/board<span class="Special"> <- </span>initial-position + screen:address<span class="Special"> <- </span>print-board screen:address, 1:address:array:address:array:character/board +<span class="CommentedCode">#? $dump-screen #? 1</span> + ] + screen-should-contain [ + <span class="Comment"># 012345678901234567890123456789</span> + <span class="Constant"> .8 | r n b q k b n r .</span> + <span class="Constant"> .7 | p p p p p p p p .</span> + <span class="Constant"> .6 | .</span> + <span class="Constant"> .5 | .</span> + <span class="Constant"> .4 | .</span> + <span class="Constant"> .3 | .</span> + <span class="Constant"> .2 | P P P P P P P P .</span> + <span class="Constant"> .1 | R N B Q K B N R .</span> + <span class="Constant"> . +---------------- .</span> + <span class="Constant"> . a b c d e f g h .</span> + <span class="Constant"> . .</span> + <span class="Constant"> . .</span> + ] +] + +<span class="SalientComment">## data structure: move</span> + +container move [ + <span class="Comment"># valid range: 0-7</span> + from-file:number + from-rank:number + to-file:number + to-rank:number +] + +<span class="Comment"># result:address:move, quit?:boolean, error?:boolean <- read-move stdin:address:channel, screen:address</span> +<span class="Comment"># prints only error messages to screen</span> +recipe read-move [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + stdin:address:channel<span class="Special"> <- </span>next-ingredient + screen:address<span class="Special"> <- </span>next-ingredient +<span class="CommentedCode">#? $print screen:address #? 1</span> + from-file:number, quit?:boolean, error?:boolean<span class="Special"> <- </span>read-file stdin:address:channel, screen:address + <span class="Identifier">reply-if</span> quit?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean + <span class="Identifier">reply-if</span> error?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean +<span class="CommentedCode">#? return-to-console #? 1</span> + <span class="Comment"># construct the move object</span> + result:address:move<span class="Special"> <- </span>new <span class="Constant">move:literal</span> + x:address:number<span class="Special"> <- </span>get-address result:address:move/deref, from-file:offset + x:address:number/deref<span class="Special"> <- </span>copy from-file:number + x:address:number<span class="Special"> <- </span>get-address result:address:move/deref, from-rank:offset + x:address:number/deref, quit?:boolean, error?:boolean<span class="Special"> <- </span>read-rank stdin:address:channel, screen:address + <span class="Identifier">reply-if</span> quit?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean + <span class="Identifier">reply-if</span> error?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean + error?:boolean<span class="Special"> <- </span>expect-from-channel stdin:address:channel, <span class="Constant">45:literal/dash</span>, screen:address + <span class="Identifier">reply-if</span> error?:boolean, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, error?:boolean + x:address:number<span class="Special"> <- </span>get-address result:address:move/deref, to-file:offset + x:address:number/deref, quit?:boolean, error?:boolean<span class="Special"> <- </span>read-file stdin:address:channel, screen:address + <span class="Identifier">reply-if</span> quit?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean + <span class="Identifier">reply-if</span> error?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean + x:address:number<span class="Special"> <- </span>get-address result:address:move/deref, to-rank:offset + x:address:number/deref, quit?:boolean, error?:boolean<span class="Special"> <- </span>read-rank stdin:address:channel, screen:address + <span class="Identifier">reply-if</span> quit?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean + <span class="Identifier">reply-if</span> error?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean +<span class="CommentedCode">#? $exit #? 1</span> + error?:boolean<span class="Special"> <- </span>expect-from-channel stdin:address:channel, <span class="Constant">10:literal/newline</span>, screen:address + <span class="Identifier">reply-if</span> error?:boolean, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, error?:boolean + <span class="Identifier">reply</span> result:address:move, quit?:boolean, error?:boolean +] + +<span class="Comment"># file:number, quit:boolean, error:boolean <- read-file stdin:address:channel, screen:address</span> +<span class="Comment"># valid values for file: 0-7</span> +recipe read-file [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + stdin:address:channel<span class="Special"> <- </span>next-ingredient + screen:address<span class="Special"> <- </span>next-ingredient + c:character, stdin:address:channel<span class="Special"> <- </span>read stdin:address:channel + <span class="Delimiter">{</span> + q-pressed?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">81:literal</span> <span class="Comment"># 'Q'</span> + <span class="Identifier">break-unless</span> q-pressed?:boolean + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + q-pressed?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">113:literal</span> <span class="Comment"># 'q'</span> + <span class="Identifier">break-unless</span> q-pressed?:boolean + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + empty-fake-keyboard?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">0:literal/eof</span> + <span class="Identifier">break-unless</span> empty-fake-keyboard?:boolean + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + newline?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal/newline</span> + <span class="Identifier">break-unless</span> newline?:boolean + error-message:address:array:character<span class="Special"> <- </span>new <span class="Constant">[that's not enough]</span> + print-string screen:address, error-message:address:array:character + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + <span class="Delimiter">}</span> + file:number<span class="Special"> <- </span>subtract c:character, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> +<span class="CommentedCode">#? $print file:number, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + <span class="Comment"># 'a' <= file <= 'h'</span> + <span class="Delimiter">{</span> + above-min:boolean<span class="Special"> <- </span>greater-or-equal file:number, <span class="Constant">0:literal</span> + <span class="Identifier">break-if</span> above-min:boolean + error-message:address:array:character<span class="Special"> <- </span>new <span class="Constant">[file too low: ]</span> + print-string screen:address, error-message:address:array:character + print-character screen:address, c:character + cursor-to-next-line screen:address + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + below-max:boolean<span class="Special"> <- </span>lesser-than file:number, <span class="Constant">8:literal</span> + <span class="Identifier">break-if</span> below-max:boolean + error-message:address:array:character<span class="Special"> <- </span>new <span class="Constant">[file too high: ]</span> + print-string screen:address, error-message:address:array:character + print-character screen:address, c:character + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> file:number, <span class="Constant">0:literal/quit</span>, <span class="Constant">0:literal/error</span> +] + +<span class="Comment"># rank:number <- read-rank stdin:address:channel, screen:address</span> +<span class="Comment"># valid values: 0-7, -1 (quit), -2 (error)</span> +recipe read-rank [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + stdin:address:channel<span class="Special"> <- </span>next-ingredient + screen:address<span class="Special"> <- </span>next-ingredient + c:character, stdin:address:channel<span class="Special"> <- </span>read stdin:address:channel + <span class="Delimiter">{</span> + q-pressed?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">81:literal</span> <span class="Comment"># 'Q'</span> + <span class="Identifier">break-unless</span> q-pressed?:boolean + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + q-pressed?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">113:literal</span> <span class="Comment"># 'q'</span> + <span class="Identifier">break-unless</span> q-pressed?:boolean + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + newline?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal</span> <span class="Comment"># newline</span> + <span class="Identifier">break-unless</span> newline?:boolean + error-message:address:array:character<span class="Special"> <- </span>new <span class="Constant">[that's not enough]</span> + print-string screen:address, error-message:address:array:character + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + <span class="Delimiter">}</span> + rank:number<span class="Special"> <- </span>subtract c:character, <span class="Constant">49:literal</span> <span class="Comment"># '1'</span> +<span class="CommentedCode">#? $print rank:number, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + <span class="Comment"># assert'1' <= rank <= '8'</span> + <span class="Delimiter">{</span> + above-min:boolean<span class="Special"> <- </span>greater-or-equal rank:number, <span class="Constant">0:literal</span> + <span class="Identifier">break-if</span> above-min:boolean + error-message:address:array:character<span class="Special"> <- </span>new <span class="Constant">[rank too low: ]</span> + print-string screen:address, error-message:address:array:character + print-character screen:address, c:character + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + below-max:boolean<span class="Special"> <- </span>lesser-or-equal rank:number, <span class="Constant">7:literal</span> + <span class="Identifier">break-if</span> below-max:boolean + error-message:address:array:character<span class="Special"> <- </span>new <span class="Constant">[rank too high: ]</span> + print-string screen:address, error-message:address:array:character + print-character screen:address, c:character + <span class="Identifier">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + <span class="Delimiter">}</span> + <span class="Identifier">reply</span> rank:number, <span class="Constant">0:literal/quit</span>, <span class="Constant">0:literal/error</span> +] + +<span class="Comment"># read a character from the given channel and check that it's what we expect</span> +<span class="Comment"># return true on error</span> +recipe expect-from-channel [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + stdin:address:channel<span class="Special"> <- </span>next-ingredient + expected:character<span class="Special"> <- </span>next-ingredient + screen:address<span class="Special"> <- </span>next-ingredient + c:character, stdin:address:channel<span class="Special"> <- </span>read stdin:address:channel + match?:boolean<span class="Special"> <- </span>equal c:character, expected:character + <span class="Delimiter">{</span> + <span class="Identifier">break-if</span> match?:boolean + s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[expected character not found]</span> + print-string screen:address, s:address:array:character + <span class="Delimiter">}</span> + result:boolean<span class="Special"> <- </span>not match?:boolean + <span class="Identifier">reply</span> result:boolean +] + +scenario read-move-blocking [ + assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + run [ +<span class="CommentedCode">#? $start-tracing #? 1</span> + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">2:literal</span> +<span class="CommentedCode">#? $print [aaa channel address: ], 1:address:channel, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 2:number/routine<span class="Special"> <- </span>start-running read-move:recipe, 1:address:channel, screen:address + <span class="Comment"># 'read-move' is waiting for input</span> + wait-for-routine 2:number +<span class="CommentedCode">#? $print [bbb channel address: ], 1:address:channel, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 3:number<span class="Special"> <- </span>routine-state 2:number/id +<span class="CommentedCode">#? $print [I: routine ], 2:number, [ state ], 3:number [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?, [ +F read-move-blocking: routine failed to pause after coming up<span class="Identifier"> (before</span> any keys were pressed)] + <span class="Comment"># press 'a'</span> +<span class="CommentedCode">#? $print [ccc channel address: ], 1:address:channel, [ </span> +<span class="CommentedCode">#? ] #? 1</span> +<span class="CommentedCode">#? $exit #? 1</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + restart 2:number/routine + <span class="Comment"># 'read-move' still waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number/id +<span class="CommentedCode">#? $print [II: routine ], 2:number, [ state ], 3:number [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?, [ +F read-move-blocking: routine failed to pause after rank<span class="Identifier"> 'a</span>'] + <span class="Comment"># press '2'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">50:literal</span> <span class="Comment"># '2'</span> + restart 2:number/routine + <span class="Comment"># 'read-move' still waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number/id +<span class="CommentedCode">#? $print [III: routine ], 2:number, [ state ], 3:number [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?, [ +F read-move-blocking: routine failed to pause after file<span class="Identifier"> 'a2</span>'] + <span class="Comment"># press '-'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">45:literal</span> <span class="Comment"># '-'</span> + restart 2:number/routine + <span class="Comment"># 'read-move' still waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number +<span class="CommentedCode">#? $print [IV: routine ], 2:number, [ state ], 3:number [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?/routine-state, [ +F read-move-blocking: routine failed to pause after hyphen<span class="Identifier"> 'a2-</span>'] + <span class="Comment"># press 'a'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + restart 2:number/routine + <span class="Comment"># 'read-move' still waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number +<span class="CommentedCode">#? $print [V: routine ], 2:number, [ state ], 3:number [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?/routine-state, [ +F read-move-blocking: routine failed to pause after rank<span class="Identifier"> 'a2-a</span>'] + <span class="Comment"># press '4'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">52:literal</span> <span class="Comment"># '4'</span> + restart 2:number/routine + <span class="Comment"># 'read-move' still waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number +<span class="CommentedCode">#? $print [VI: routine ], 2:number, [ state ], 3:number [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?, [ +F read-move-blocking: routine failed to pause after file<span class="Identifier"> 'a2-a4</span>'] + <span class="Comment"># press 'newline'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">10:literal</span> <span class="Comment"># newline</span> + restart 2:number/routine + <span class="Comment"># 'read-move' now completes</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number +<span class="CommentedCode">#? $print [VII: routine ], 2:number, [ state ], 3:number [ </span> +<span class="CommentedCode">#? ] #? 1</span> + 4:boolean/completed?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">1:literal/completed</span> + assert 4:boolean/completed?, [ +F read-move-blocking: routine failed to terminate on newline] + trace <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> + ] + trace-should-contain [ + test: reached end + ] +] + +scenario read-move-quit [ + assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">2:literal</span> + 2:number/routine<span class="Special"> <- </span>start-running read-move:recipe, 1:address:channel, screen:address + <span class="Comment"># 'read-move' is waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number/id + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?, [ +F read-move-quit: routine failed to pause after coming up<span class="Identifier"> (before</span> any keys were pressed)] + <span class="Comment"># press 'q'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">113:literal</span> <span class="Comment"># 'q'</span> + restart 2:number/routine + <span class="Comment"># 'read-move' completes</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number/id + 4:boolean/completed?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">1:literal/completed</span> + assert 4:boolean/completed?, [ +F read-move-quit: routine failed to terminate on<span class="Identifier"> 'q</span>'] + trace <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> + ] + trace-should-contain [ + test: reached end + ] +] + +scenario read-move-illegal-file [ + assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">2:literal</span> + 2:number/routine<span class="Special"> <- </span>start-running read-move:recipe, 1:address:channel, screen:address + <span class="Comment"># 'read-move' is waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number/id + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?, [ +F read-move-file: routine failed to pause after coming up<span class="Identifier"> (before</span> any keys were pressed)] + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">50:literal</span> <span class="Comment"># '2'</span> + restart 2:number/routine + wait-for-routine 2:number + ] + screen-should-contain [ + <span class="Constant"> .file too low: 2 .</span> + <span class="Constant"> . .</span> + ] +] + +scenario read-move-illegal-rank [ + assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">2:literal</span> + 2:number/routine<span class="Special"> <- </span>start-running read-move:recipe, 1:address:channel, screen:address + <span class="Comment"># 'read-move' is waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number/id + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?, [ +F read-move-file: routine failed to pause after coming up<span class="Identifier"> (before</span> any keys were pressed)] + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + restart 2:number/routine + wait-for-routine 2:number + ] + screen-should-contain [ + <span class="Constant"> .rank too high: a .</span> + <span class="Constant"> . .</span> + ] +] + +scenario read-move-empty [ + assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + run [ + 1:address:channel<span class="Special"> <- </span>init-channel <span class="Constant">2:literal</span> + 2:number/routine<span class="Special"> <- </span>start-running read-move:recipe, 1:address:channel, screen:address + <span class="Comment"># 'read-move' is waiting for input</span> + wait-for-routine 2:number + 3:number<span class="Special"> <- </span>routine-state 2:number/id + 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> + assert 4:boolean/waiting?, [ +F read-move-file: routine failed to pause after coming up<span class="Identifier"> (before</span> any keys were pressed)] + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">10:literal/newline</span> + 1:address:channel<span class="Special"> <- </span>write 1:address:channel, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + restart 2:number/routine + wait-for-routine 2:number + ] + screen-should-contain [ + <span class="Constant"> .that's not enough .</span> + <span class="Constant"> . .</span> + ] +] + +recipe make-move [ + default-space:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + b:address:array:address:array:character<span class="Special"> <- </span>next-ingredient + m:address:move<span class="Special"> <- </span>next-ingredient + from-file:number<span class="Special"> <- </span>get m:address:move/deref, from-file:offset +<span class="CommentedCode">#? $print from-file:number, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + from-rank:number<span class="Special"> <- </span>get m:address:move/deref, from-rank:offset +<span class="CommentedCode">#? $print from-rank:number, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + to-file:number<span class="Special"> <- </span>get m:address:move/deref, to-file:offset +<span class="CommentedCode">#? $print to-file:number, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + to-rank:number<span class="Special"> <- </span>get m:address:move/deref, to-rank:offset +<span class="CommentedCode">#? $print to-rank:number, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + f:address:array:character<span class="Special"> <- </span>index b:address:array:address:array:character/deref, from-file:number + src:address:character/square<span class="Special"> <- </span>index-address f:address:array:character/deref, from-rank:number + f:address:array:character<span class="Special"> <- </span>index b:address:array:address:array:character/deref, to-file:number + dest:address:character/square<span class="Special"> <- </span>index-address f:address:array:character/deref, to-rank:number +<span class="CommentedCode">#? $print src:address:character/deref, [ </span> +<span class="CommentedCode">#? ] #? 1</span> + dest:address:character/deref/square<span class="Special"> <- </span>copy src:address:character/deref/square + src:address:character/deref/square<span class="Special"> <- </span>copy <span class="Constant">32:literal</span> <span class="Comment"># ' '</span> + <span class="Identifier">reply</span> b:address:array:address:array:character/same-as-ingredient:0 +] + +scenario making-a-move [ + assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">12:literal/height</span> + run [ + 2:address:array:address:array:character/board<span class="Special"> <- </span>initial-position + 3:address:move<span class="Special"> <- </span>new move:type + 4:address:number<span class="Special"> <- </span>get-address 3:address:move/deref, from-file:offset + 4:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">6:literal/g</span> + 5:address:number<span class="Special"> <- </span>get-address 3:address:move/deref, from-rank:offset + 5:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">1:literal/2</span> + 6:address:number<span class="Special"> <- </span>get-address 3:address:move/deref, to-file:offset + 6:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">6:literal/g</span> + 7:address:number<span class="Special"> <- </span>get-address 3:address:move/deref, to-rank:offset + 7:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">3:literal/4</span> + 2:address:array:address:array:character/board<span class="Special"> <- </span>make-move 2:address:array:address:array:character/board, 3:address:move + screen:address<span class="Special"> <- </span>print-board screen:address, 2:address:array:address:array:character/board + ] + screen-should-contain [ + <span class="Comment"># 012345678901234567890123456789</span> + <span class="Constant"> .8 | r n b q k b n r .</span> + <span class="Constant"> .7 | p p p p p p p p .</span> + <span class="Constant"> .6 | .</span> + <span class="Constant"> .5 | .</span> + <span class="Constant"> .4 | P .</span> + <span class="Constant"> .3 | .</span> + <span class="Constant"> .2 | P P P P P P P .</span> + <span class="Constant"> .1 | R N B Q K B N R .</span> + <span class="Constant"> . +---------------- .</span> + <span class="Constant"> . a b c d e f g h .</span> + <span class="Constant"> . .</span> + <span class="Constant"> . .</span> + ] +] +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |