diff options
Diffstat (limited to 'html')
74 files changed, 5785 insertions, 5705 deletions
diff --git a/html/000organization.cc.html b/html/000organization.cc.html index b882e19c..641dae8c 100644 --- a/html/000organization.cc.html +++ b/html/000organization.cc.html @@ -13,12 +13,11 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.Delimiter { color: #a04060; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.Identifier { color: #804000; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .PreProc { color: #c000c0; } -.Identifier { color: #804000; } +.Delimiter { color: #a04060; } --> </style> @@ -132,7 +131,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">// Globals</span> <span class="Comment">// End Globals</span> -<span class="Normal">int</span> main<span class="Delimiter">(</span><span class="Normal">int</span> argc<span class="Delimiter">,</span> <span class="Normal">char</span>* argv[]<span class="Delimiter">)</span> <span class="Delimiter">{</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> @@ -149,11 +148,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <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> -<span class="Normal">void</span> setup<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void setup<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Comment">// End Setup</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> teardown<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> </pre> diff --git a/html/001help.cc.html b/html/001help.cc.html index 2a89daac..b7f03457 100644 --- a/html/001help.cc.html +++ b/html/001help.cc.html @@ -14,13 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.PreProc { color: #c000c0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } +.SalientComment { color: #00ffff; } .Identifier { color: #804000; } +.PreProc { color: #c000c0; } --> </style> @@ -36,7 +35,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">//: This should give you a sense for what to look forward to in later layers.</span> <span class="Delimiter">:(before "End Commandline Parsing")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>argc <= <span class="Constant">1</span> || is_equal<span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"--help"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>argc <= <span class="Constant">1</span> || is_equal<span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"--help"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// this is the functionality later layers will provide</span> <span class="Comment">// currently no automated tests for commandline arg parsing</span> cerr << <span class="Constant">"To load files and run 'main':</span><span class="cSpecial">\n</span><span class="Constant">"</span> @@ -59,7 +58,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">//: way, our makefile contains a little command to automatically generate</span> <span class="Comment">//: declarations for them.</span> <span class="Delimiter">:(code)</span> -<span class="Normal">bool</span> is_equal<span class="Delimiter">(</span><span class="Normal">char</span>* s<span class="Delimiter">,</span> <span class="Normal">const</span> <span class="Normal">char</span>* lit<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool is_equal<span class="Delimiter">(</span>char* s<span class="Delimiter">,</span> const char* lit<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> strncmp<span class="Delimiter">(</span>s<span class="Delimiter">,</span> lit<span class="Delimiter">,</span> strlen<span class="Delimiter">(</span>lit<span class="Delimiter">))</span> == <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -112,7 +111,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">// yadda-yadda. Instead use this macro below to perform an unsafe cast to</span> <span class="Comment">// signed. We'll just give up immediately if a container's every too large.</span> <span class="Delimiter">:(before "End Includes")</span> -<span class="PreProc">#define SIZE(X) (assert(X</span><span class="Delimiter">.</span><span class="PreProc">size() < (</span><span class="Constant">1LL</span><span class="PreProc"><<(</span><span class="Normal">sizeof</span><span class="PreProc">(</span><span class="Normal">long</span><span class="PreProc"> </span><span class="Normal">long</span><span class="PreProc"> </span><span class="Normal">int</span><span class="PreProc">)*</span><span class="Constant">8</span><span class="PreProc">-</span><span class="Constant">2</span><span class="PreProc">)))</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Normal">static_cast</span><span class="PreProc"><</span><span class="Normal">long</span><span class="PreProc"> </span><span class="Normal">long</span><span class="PreProc"> </span><span class="Normal">int</span><span class="PreProc">>(X</span><span class="Delimiter">.</span><span class="PreProc">size()))</span> +<span class="PreProc">#define SIZE(X) (assert(X</span><span class="Delimiter">.</span><span class="PreProc">size() < (</span><span class="Constant">1LL</span><span class="PreProc"><<(</span>sizeof<span class="PreProc">(</span>long<span class="PreProc"> </span>long<span class="PreProc"> </span>int<span class="PreProc">)*</span><span class="Constant">8</span><span class="PreProc">-</span><span class="Constant">2</span><span class="PreProc">)))</span><span class="Delimiter">,</span><span class="PreProc"> </span>static_cast<span class="PreProc"><</span>long<span class="PreProc"> </span>long<span class="PreProc"> </span>int<span class="PreProc">>(X</span><span class="Delimiter">.</span><span class="PreProc">size()))</span> <span class="Comment">//</span> <span class="Comment">// 5. Integer overflow is still impossible to guard against. Maybe after</span> <span class="Comment">// reading <a href="http://www.cs.utah.edu/~regehr/papers/overflow12.pdf">http://www.cs.utah.edu/~regehr/papers/overflow12.pdf</a></span> @@ -121,16 +120,16 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="PreProc">#include</span><span class="Constant"><assert.h></span> <span class="PreProc">#include</span><span class="Constant"><iostream></span> -<span class="Normal">using</span> std::istream<span class="Delimiter">;</span> -<span class="Normal">using</span> std::ostream<span class="Delimiter">;</span> -<span class="Normal">using</span> std::iostream<span class="Delimiter">;</span> -<span class="Normal">using</span> std::cin<span class="Delimiter">;</span> -<span class="Normal">using</span> std::cout<span class="Delimiter">;</span> -<span class="Normal">using</span> std::cerr<span class="Delimiter">;</span> +using std::istream<span class="Delimiter">;</span> +using std::ostream<span class="Delimiter">;</span> +using std::iostream<span class="Delimiter">;</span> +using std::cin<span class="Delimiter">;</span> +using std::cout<span class="Delimiter">;</span> +using std::cerr<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant"><cstring></span> <span class="PreProc">#include</span><span class="Constant"><string></span> -<span class="Normal">using</span> std::string<span class="Delimiter">;</span> +using std::string<span class="Delimiter">;</span> </pre> </body> </html> diff --git a/html/002test.cc.html b/html/002test.cc.html index 6d7eb925..4c280e92 100644 --- a/html/002test.cc.html +++ b/html/002test.cc.html @@ -15,11 +15,10 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } .PreProc { color: #c000c0; } +.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } --> </style> @@ -43,19 +42,19 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">//: subsets of the program.</span> <span class="Delimiter">:(before "End Types")</span> -<span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*test_fn<span class="Delimiter">)(</span><span class="Normal">void</span><span class="Delimiter">);</span> +typedef void <span class="Delimiter">(</span>*test_fn<span class="Delimiter">)(</span>void<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">const</span> test_fn Tests[] = <span class="Delimiter">{</span> +const test_fn Tests[] = <span class="Delimiter">{</span> <span class="PreProc"> #include </span><span class="Constant">"test_list"</span> <span class="Comment">// auto-generated; see makefile</span> <span class="Delimiter">};</span> -<span class="Normal">bool</span> Run_tests = <span class="Constant">false</span><span class="Delimiter">;</span> -<span class="Normal">bool</span> Passed = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> -<span class="Normal">long</span> Num_failures = <span class="Constant">0</span><span class="Delimiter">;</span> +bool Run_tests = <span class="Constant">false</span><span class="Delimiter">;</span> +bool Passed = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> +long Num_failures = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="PreProc">#define CHECK(X) \</span> -<span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (!(X)) </span><span class="Delimiter">{</span><span class="PreProc"> \</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"> Passed = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> @@ -63,7 +62,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="PreProc"> </span><span class="Delimiter">}</span> <span class="PreProc">#define CHECK_EQ(X</span><span class="Delimiter">,</span><span class="PreProc"> Y) \</span> -<span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> ((X) != (Y)) </span><span class="Delimiter">{</span><span class="PreProc"> \</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">" 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> @@ -75,25 +74,25 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } Passed = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Commandline Parsing")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && is_equal<span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"test"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && is_equal<span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"test"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> Run_tests = <span class="Constant">true</span><span class="Delimiter">;</span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> <span class="Comment">// shift 'test' out of commandline args</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Main")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// Test Runs</span> <span class="Comment">// we run some tests and then exit; assume no state need be maintained afterward</span> <span class="Comment">// End Test Run Initialization</span> - <span class="Normal">time_t</span> t<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> + time_t t<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> cerr << <span class="Constant">"C tests: "</span> << ctime<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests<span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>size_t i=<span class="Constant">0</span><span class="Delimiter">;</span> i < sizeof<span class="Delimiter">(</span>Tests<span class="Delimiter">)</span>/sizeof<span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << i << '\n'; //? 2</span> run_test<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// End Tests</span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Num_failures > <span class="Constant">0</span><span class="Delimiter">)</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> @@ -103,8 +102,8 @@ Passed = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> run_test<span class="Delimiter">(</span><span class="Normal">size_t</span> i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>i >= <span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests<span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> +void run_test<span class="Delimiter">(</span>size_t i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i >= sizeof<span class="Delimiter">(</span>Tests<span class="Delimiter">)</span>/sizeof<span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> cerr << <span class="Constant">"no test "</span> << i << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -112,18 +111,18 @@ Passed = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// End Test Setup</span> <span class="Delimiter">(</span>*Tests[i]<span class="Delimiter">)();</span> teardown<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">"."</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">"."</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> is_integer<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool is_integer<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-"</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> to_integer<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">char</span>* end = <span class="Constant">NULL</span><span class="Delimiter">;</span> +long long int to_integer<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> <span class="Comment">// safe because string.c_str() is guaranteed to be null-terminated</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>*end != <span class="cSpecial">'\0'</span><span class="Delimiter">)</span> cerr << <span class="Constant">"tried to convert "</span> << n << <span class="Constant">" to number</span><span class="cSpecial">\n</span><span class="Constant">"</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> + if <span class="Delimiter">(</span>*end != <span class="cSpecial">'\0'</span><span class="Delimiter">)</span> cerr << <span class="Constant">"tried to convert "</span> << n << <span class="Constant">" to number</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> assert<span class="Delimiter">(</span>*end == <span class="cSpecial">'\0'</span><span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/003trace.cc.html b/html/003trace.cc.html index 2eabf9ff..ea09cda6 100644 --- a/html/003trace.cc.html +++ b/html/003trace.cc.html @@ -16,7 +16,6 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } .PreProc { color: #c000c0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .CommentedCode { color: #6c6c6c; } @@ -115,56 +114,56 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">// End Tracing // hack to ensure most code in this layer comes before anything else</span> <span class="Delimiter">:(before "End Tracing")</span> -<span class="Normal">bool</span> Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> +bool Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> <span class="CommentedCode">//? cerr << "AAA setup\n"; //? 2</span> Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Types")</span> -<span class="Normal">struct</span> trace_line <span class="Delimiter">{</span> - <span class="Normal">int</span> depth<span class="Delimiter">;</span> <span class="Comment">// optional field just to help browse traces later</span> +struct trace_line <span class="Delimiter">{</span> + int depth<span class="Delimiter">;</span> <span class="Comment">// optional field just to help browse traces later</span> string label<span class="Delimiter">;</span> string contents<span class="Delimiter">;</span> trace_line<span class="Delimiter">(</span>string l<span class="Delimiter">,</span> string c<span class="Delimiter">)</span> :depth<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> label<span class="Delimiter">(</span>l<span class="Delimiter">),</span> contents<span class="Delimiter">(</span>c<span class="Delimiter">)</span> <span class="Delimiter">{}</span> - trace_line<span class="Delimiter">(</span><span class="Normal">int</span> d<span class="Delimiter">,</span> string l<span class="Delimiter">,</span> string c<span class="Delimiter">)</span> :depth<span class="Delimiter">(</span>d<span class="Delimiter">),</span> label<span class="Delimiter">(</span>l<span class="Delimiter">),</span> contents<span class="Delimiter">(</span>c<span class="Delimiter">)</span> <span class="Delimiter">{}</span> + trace_line<span class="Delimiter">(</span>int d<span class="Delimiter">,</span> string l<span class="Delimiter">,</span> string c<span class="Delimiter">)</span> :depth<span class="Delimiter">(</span>d<span class="Delimiter">),</span> label<span class="Delimiter">(</span>l<span class="Delimiter">),</span> contents<span class="Delimiter">(</span>c<span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "End Tracing")</span> -<span class="Normal">struct</span> trace_stream <span class="Delimiter">{</span> +struct trace_stream <span class="Delimiter">{</span> vector<trace_line> past_lines<span class="Delimiter">;</span> <span class="Comment">// accumulator for current line</span> ostringstream* curr_stream<span class="Delimiter">;</span> string curr_layer<span class="Delimiter">;</span> - <span class="Normal">int</span> curr_depth<span class="Delimiter">;</span> + int curr_depth<span class="Delimiter">;</span> string dump_layer<span class="Delimiter">;</span> string collect_layer<span class="Delimiter">;</span> <span class="Comment">// if set, ignore all other layers</span> ofstream null_stream<span class="Delimiter">;</span> <span class="Comment">// never opens a file, so writes silently fail</span> trace_stream<span class="Delimiter">()</span> :curr_stream<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> curr_depth<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> - ~trace_stream<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr_stream<span class="Delimiter">)</span> <span class="Normal">delete</span> curr_stream<span class="Delimiter">;</span> <span class="Delimiter">}</span> + ~trace_stream<span class="Delimiter">()</span> <span class="Delimiter">{</span> if <span class="Delimiter">(</span>curr_stream<span class="Delimiter">)</span> delete curr_stream<span class="Delimiter">;</span> <span class="Delimiter">}</span> ostream& stream<span class="Delimiter">(</span>string layer<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> stream<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> layer<span class="Delimiter">);</span> <span class="Delimiter">}</span> - ostream& stream<span class="Delimiter">(</span><span class="Normal">int</span> depth<span class="Delimiter">,</span> string layer<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!collect_layer<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && layer != collect_layer<span class="Delimiter">)</span> <span class="Identifier">return</span> null_stream<span class="Delimiter">;</span> - curr_stream = <span class="Normal">new</span> ostringstream<span class="Delimiter">;</span> + ostream& stream<span class="Delimiter">(</span>int depth<span class="Delimiter">,</span> string layer<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!collect_layer<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && layer != collect_layer<span class="Delimiter">)</span> <span class="Identifier">return</span> null_stream<span class="Delimiter">;</span> + curr_stream = new ostringstream<span class="Delimiter">;</span> curr_layer = layer<span class="Delimiter">;</span> curr_depth = depth<span class="Delimiter">;</span> <span class="Identifier">return</span> *curr_stream<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// be sure to call this before messing with curr_stream or curr_layer</span> - <span class="Normal">void</span> newline<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!curr_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + void newline<span class="Delimiter">()</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!curr_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> string curr_contents = curr_stream<span class="Delimiter">-></span>str<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_contents<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr_contents<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> past_lines<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>trace_line<span class="Delimiter">(</span>curr_depth<span class="Delimiter">,</span> trim<span class="Delimiter">(</span>curr_layer<span class="Delimiter">),</span> curr_contents<span class="Delimiter">));</span> <span class="Comment">// preserve indent in contents</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_layer == dump_layer || curr_layer == <span class="Constant">"dump"</span> || dump_layer == <span class="Constant">"all"</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> << curr_contents << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - <span class="Normal">delete</span> curr_stream<span class="Delimiter">;</span> + delete curr_stream<span class="Delimiter">;</span> curr_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> curr_layer<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> curr_depth = <span class="Constant">0</span><span class="Delimiter">;</span> @@ -174,9 +173,9 @@ Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</sp string readable_contents<span class="Delimiter">(</span>string layer<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// missing layer = everything</span> ostringstream output<span class="Delimiter">;</span> layer = trim<span class="Delimiter">(</span>layer<span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>layer<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || layer == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-></span>depth<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>vector<trace_line>::iterator p = past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>layer<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || layer == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>depth<span class="Delimiter">)</span> output << std::setw<span class="Delimiter">(</span><span class="Constant">4</span><span class="Delimiter">)</span> << p<span class="Delimiter">-></span>depth << <span class="Constant">' '</span><span class="Delimiter">;</span> output << p<span class="Delimiter">-></span>label << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>contents << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -195,34 +194,34 @@ trace_stream* Trace_stream = <span class="Constant">NULL</span><span class="Deli <span class="PreProc">#define raise ((!Trace_stream || !Hide_warnings) ? (tb_shutdown()</span><span class="Delimiter">,</span><span class="PreProc">cerr) </span><span class="Comment">/*</span><span class="Comment">do print</span><span class="Comment">*/</span><span class="PreProc"> : Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">stream(</span><span class="Constant">"warn"</span><span class="PreProc">))</span> <span class="Delimiter">:(before "End Types")</span> -<span class="Normal">struct</span> end <span class="Delimiter">{};</span> +struct end <span class="Delimiter">{};</span> <span class="Delimiter">:(before "End Tracing")</span> -ostream& <span class="Normal">operator</span><<<span class="Delimiter">(</span>ostream& os<span class="Delimiter">,</span> unused end<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">)</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> +ostream& operator<<<span class="Delimiter">(</span>ostream& os<span class="Delimiter">,</span> unused end<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">)</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> <span class="Identifier">return</span> os<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="PreProc">#define CLEAR_TRACE </span><span class="Normal">delete</span><span class="PreProc"> Trace_stream</span><span class="Delimiter">,</span><span class="PreProc"> Trace_stream = </span><span class="Normal">new</span><span class="PreProc"> trace_stream</span><span class="Delimiter">;</span> +<span class="PreProc">#define CLEAR_TRACE </span>delete<span class="PreProc"> Trace_stream</span><span class="Delimiter">,</span><span class="PreProc"> Trace_stream = </span>new<span class="PreProc"> trace_stream</span><span class="Delimiter">;</span> -<span class="PreProc">#define DUMP(layer) </span><span class="Normal">if</span><span class="PreProc"> (Trace_stream) cerr << Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">readable_contents(layer)</span><span class="Delimiter">;</span> +<span class="PreProc">#define DUMP(layer) </span>if<span class="PreProc"> (Trace_stream) cerr << Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">readable_contents(layer)</span><span class="Delimiter">;</span> <span class="Comment">// All scenarios save their traces in the repo, just like code. This gives</span> <span class="Comment">// future readers more meat when they try to make sense of a new project.</span> -<span class="Normal">static</span> string Trace_dir = <span class="Constant">".traces/"</span><span class="Delimiter">;</span> +static string Trace_dir = <span class="Constant">".traces/"</span><span class="Delimiter">;</span> string Trace_file<span class="Delimiter">;</span> <span class="Comment">// Trace_stream is a resource, lease_tracer uses RAII to manage it.</span> -<span class="Normal">struct</span> lease_tracer <span class="Delimiter">{</span> - lease_tracer<span class="Delimiter">()</span> <span class="Delimiter">{</span> Trace_stream = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> <span class="Delimiter">}</span> +struct lease_tracer <span class="Delimiter">{</span> + lease_tracer<span class="Delimiter">()</span> <span class="Delimiter">{</span> Trace_stream = new trace_stream<span class="Delimiter">;</span> <span class="Delimiter">}</span> ~lease_tracer<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "write to file? " << Trace_file << "$\n"; //? 2</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_file<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Trace_file<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "writing\n"; //? 2</span> ofstream fout<span class="Delimiter">((</span>Trace_dir+Trace_file<span class="Delimiter">).</span>c_str<span class="Delimiter">());</span> fout << Trace_stream<span class="Delimiter">-></span>readable_contents<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> fout<span class="Delimiter">.</span>close<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">delete</span> Trace_stream<span class="Delimiter">,</span> Trace_stream = <span class="Constant">NULL</span><span class="Delimiter">,</span> Trace_file = <span class="Constant">""</span><span class="Delimiter">;</span> + delete Trace_stream<span class="Delimiter">,</span> Trace_stream = <span class="Constant">NULL</span><span class="Delimiter">,</span> Trace_file = <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">};</span> @@ -234,47 +233,47 @@ START_TRACING_UNTIL_END_OF_SCOPE <span class="PreProc">#define CHECK_TRACE_CONTENTS(</span><span class="Delimiter">...</span><span class="PreProc">) check_trace_contents(__FUNCTION__</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">__FILE__</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">__LINE__</span><span class="Delimiter">,</span><span class="PreProc"> __VA_ARGS__)</span> <span class="Delimiter">:(before "End Tracing")</span> -<span class="Normal">bool</span> check_trace_contents<span class="Delimiter">(</span>string FUNCTION<span class="Delimiter">,</span> string <span class="Normal">FILE</span><span class="Delimiter">,</span> <span class="Normal">int</span> LINE<span class="Delimiter">,</span> string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// missing layer == anywhere</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 expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// missing layer == anywhere</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="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>curr_expected_line < SIZE<span class="Delimiter">(</span>expected_lines<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> + long long int curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> + while <span class="Delimiter">(</span>curr_expected_line < SIZE<span class="Delimiter">(</span>expected_lines<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> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_expected_line == SIZE<span class="Delimiter">(</span>expected_lines<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 == SIZE<span class="Delimiter">(</span>expected_lines<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> string layer<span class="Delimiter">,</span> contents<span class="Delimiter">;</span> split_layer_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> &contents<span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "AAA " << layer << ' ' << p->label << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>layer != p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>layer != p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "BBB ^" << contents << "$ ^" << p->contents << "$\n"; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>contents != trim<span class="Delimiter">(</span>p<span class="Delimiter">-></span>contents<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>contents != trim<span class="Delimiter">(</span>p<span class="Delimiter">-></span>contents<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "CCC\n"; //? 1</span> ++curr_expected_line<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>curr_expected_line < SIZE<span class="Delimiter">(</span>expected_lines<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> + while <span class="Delimiter">(</span>curr_expected_line < SIZE<span class="Delimiter">(</span>expected_lines<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> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_expected_line == SIZE<span class="Delimiter">(</span>expected_lines<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 == SIZE<span class="Delimiter">(</span>expected_lines<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> split_layer_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> &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> << <span class="Normal">FILE</span> << <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> <span class="CommentedCode">//? exit(0); //? 1</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> -<span class="Normal">void</span> split_layer_contents<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">,</span> string* layer<span class="Delimiter">,</span> string* contents<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">static</span> <span class="Normal">const</span> string delim<span class="Delimiter">(</span><span class="Constant">": "</span><span class="Delimiter">);</span> - <span class="Normal">size_t</span> pos = s<span class="Delimiter">.</span>find<span class="Delimiter">(</span>delim<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>pos == string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void split_layer_contents<span class="Delimiter">(</span>const string& s<span class="Delimiter">,</span> string* layer<span class="Delimiter">,</span> string* contents<span class="Delimiter">)</span> <span class="Delimiter">{</span> + static const string delim<span class="Delimiter">(</span><span class="Constant">": "</span><span class="Delimiter">);</span> + size_t pos = s<span class="Delimiter">.</span>find<span class="Delimiter">(</span>delim<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>pos == string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> *layer = <span class="Constant">""</span><span class="Delimiter">;</span> *contents = trim<span class="Delimiter">(</span>s<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> *layer = trim<span class="Delimiter">(</span>s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> pos<span class="Delimiter">));</span> *contents = trim<span class="Delimiter">(</span>s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span>pos+SIZE<span class="Delimiter">(</span>delim<span class="Delimiter">)));</span> <span class="Delimiter">}</span> @@ -282,17 +281,17 @@ START_TRACING_UNTIL_END_OF_SCOPE ^L -<span class="Normal">int</span> trace_count<span class="Delimiter">(</span>string layer<span class="Delimiter">)</span> <span class="Delimiter">{</span> +int trace_count<span class="Delimiter">(</span>string layer<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> trace_count<span class="Delimiter">(</span>layer<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">int</span> trace_count<span class="Delimiter">(</span>string layer<span class="Delimiter">,</span> string line<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">long</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>layer == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> +int trace_count<span class="Delimiter">(</span>string layer<span class="Delimiter">,</span> string line<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long result = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>layer == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "a: " << line << "$\n"; //? 1</span> <span class="CommentedCode">//? cerr << "b: " << trim(p->contents) << "$\n"; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>line == <span class="Constant">""</span> || line == trim<span class="Delimiter">(</span>p<span class="Delimiter">-></span>contents<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>line == <span class="Constant">""</span> || line == trim<span class="Delimiter">(</span>p<span class="Delimiter">-></span>contents<span class="Delimiter">))</span> ++result<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -301,7 +300,7 @@ START_TRACING_UNTIL_END_OF_SCOPE <span class="PreProc">#define CHECK_TRACE_WARNS() CHECK(trace_count(</span><span class="Constant">"warn"</span><span class="PreProc">) > </span><span class="Constant">0</span><span class="PreProc">)</span> <span class="PreProc">#define CHECK_TRACE_DOESNT_WARN() \</span> -<span class="PreProc"> </span><span class="Normal">if</span><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"> </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"> DUMP(</span><span class="Constant">"warn"</span><span class="PreProc">)</span><span class="Delimiter">;</span><span class="PreProc"> \</span> @@ -309,11 +308,11 @@ START_TRACING_UNTIL_END_OF_SCOPE <span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> \</span> <span class="PreProc"> </span><span class="Delimiter">}</span> -<span class="Normal">bool</span> trace_doesnt_contain<span class="Delimiter">(</span>string layer<span class="Delimiter">,</span> string line<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool trace_doesnt_contain<span class="Delimiter">(</span>string layer<span class="Delimiter">,</span> string line<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> trace_count<span class="Delimiter">(</span>layer<span class="Delimiter">,</span> line<span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> trace_doesnt_contain<span class="Delimiter">(</span>string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> +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="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> @@ -324,9 +323,9 @@ START_TRACING_UNTIL_END_OF_SCOPE vector<string> split<span class="Delimiter">(</span>string s<span class="Delimiter">,</span> string delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> vector<string> result<span class="Delimiter">;</span> - <span class="Normal">size_t</span> begin=<span class="Constant">0</span><span class="Delimiter">,</span> end=s<span class="Delimiter">.</span>find<span class="Delimiter">(</span>delim<span class="Delimiter">);</span> - <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>end == string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> + size_t begin=<span class="Constant">0</span><span class="Delimiter">,</span> end=s<span class="Delimiter">.</span>find<span class="Delimiter">(</span>delim<span class="Delimiter">);</span> + while <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>end == string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>string<span class="Delimiter">(</span>s<span class="Delimiter">,</span> begin<span class="Delimiter">,</span> string::npos<span class="Delimiter">));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -337,14 +336,14 @@ vector<string> split<span class="Delimiter">(</span>string s<span class="D <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -string trim<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string trim<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> string::const_iterator first = s<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>first != s<span class="Delimiter">.</span>end<span class="Delimiter">()</span> && isspace<span class="Delimiter">(</span>*first<span class="Delimiter">))</span> + while <span class="Delimiter">(</span>first != s<span class="Delimiter">.</span>end<span class="Delimiter">()</span> && isspace<span class="Delimiter">(</span>*first<span class="Delimiter">))</span> ++first<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>first == s<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>first == s<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> string::const_iterator last = --s<span class="Delimiter">.</span>end<span class="Delimiter">();</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>last != s<span class="Delimiter">.</span>begin<span class="Delimiter">()</span> && isspace<span class="Delimiter">(</span>*last<span class="Delimiter">))</span> + while <span class="Delimiter">(</span>last != s<span class="Delimiter">.</span>begin<span class="Delimiter">()</span> && isspace<span class="Delimiter">(</span>*last<span class="Delimiter">))</span> --last<span class="Delimiter">;</span> ++last<span class="Delimiter">;</span> <span class="Identifier">return</span> string<span class="Delimiter">(</span>first<span class="Delimiter">,</span> last<span class="Delimiter">);</span> @@ -352,30 +351,30 @@ string trim<span class="Delimiter">(</span><span class="Normal">const</span> str <span class="Delimiter">:(before "End Includes")</span> <span class="PreProc">#include</span><span class="Constant"><vector></span> -<span class="Normal">using</span> std::vector<span class="Delimiter">;</span> +using std::vector<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant"><list></span> -<span class="Normal">using</span> std::list<span class="Delimiter">;</span> +using std::list<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant"><map></span> -<span class="Normal">using</span> std::map<span class="Delimiter">;</span> +using std::map<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant"><set></span> -<span class="Normal">using</span> std::set<span class="Delimiter">;</span> +using std::set<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant"><algorithm></span> <span class="PreProc">#include</span><span class="Constant"><iostream></span> -<span class="Normal">using</span> std::istream<span class="Delimiter">;</span> -<span class="Normal">using</span> std::ostream<span class="Delimiter">;</span> -<span class="Normal">using</span> std::cin<span class="Delimiter">;</span> -<span class="Normal">using</span> std::cout<span class="Delimiter">;</span> -<span class="Normal">using</span> std::cerr<span class="Delimiter">;</span> +using std::istream<span class="Delimiter">;</span> +using std::ostream<span class="Delimiter">;</span> +using std::cin<span class="Delimiter">;</span> +using std::cout<span class="Delimiter">;</span> +using std::cerr<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant"><iomanip></span> <span class="PreProc">#include</span><span class="Constant"><sstream></span> -<span class="Normal">using</span> std::istringstream<span class="Delimiter">;</span> -<span class="Normal">using</span> std::ostringstream<span class="Delimiter">;</span> +using std::istringstream<span class="Delimiter">;</span> +using std::ostringstream<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant"><fstream></span> -<span class="Normal">using</span> std::ifstream<span class="Delimiter">;</span> -<span class="Normal">using</span> std::ofstream<span class="Delimiter">;</span> +using std::ifstream<span class="Delimiter">;</span> +using std::ofstream<span class="Delimiter">;</span> <span class="PreProc">#include</span><span class="Constant">"termbox/termbox.h"</span> @@ -386,18 +385,18 @@ string trim<span class="Delimiter">(</span><span class="Normal">const</span> str <span class="Comment">//:</span> <span class="Comment">//: Mu 'applications' will be able to use depths 1-99 as they like.</span> <span class="Comment">//: Depth 100 will be for scheduling (more on that later).</span> -<span class="Normal">const</span> <span class="Normal">int</span> Scheduling_depth = <span class="Constant">100</span><span class="Delimiter">;</span> +const int Scheduling_depth = <span class="Constant">100</span><span class="Delimiter">;</span> <span class="Comment">//: Primitive statements will occupy 101-9998</span> -<span class="Normal">const</span> <span class="Normal">int</span> Initial_callstack_depth = <span class="Constant">101</span><span class="Delimiter">;</span> -<span class="Normal">const</span> <span class="Normal">int</span> Max_callstack_depth = <span class="Constant">9998</span><span class="Delimiter">;</span> +const int Initial_callstack_depth = <span class="Constant">101</span><span class="Delimiter">;</span> +const int Max_callstack_depth = <span class="Constant">9998</span><span class="Delimiter">;</span> <span class="Comment">//: (ignore this until the call layer)</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">int</span> Callstack_depth = <span class="Constant">0</span><span class="Delimiter">;</span> +int Callstack_depth = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Callstack_depth = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">//: Finally, details of primitive mu statements will occupy depth 9999 (more on that later as well)</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">const</span> <span class="Normal">int</span> Primitive_recipe_depth = <span class="Constant">9999</span><span class="Delimiter">;</span> +const int Primitive_recipe_depth = <span class="Constant">9999</span><span class="Delimiter">;</span> <span class="Comment">//:</span> <span class="Comment">//: This framework should help us hide some details at each level, mixing</span> <span class="Comment">//: static ideas like layers with the dynamic notion of call-stack depth.</span> diff --git a/html/003trace.test.cc.html b/html/003trace.test.cc.html index 4a720eca..e800a8cc 100644 --- a/html/003trace.test.cc.html +++ b/html/003trace.test.cc.html @@ -14,10 +14,9 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } +.Delimiter { color: #a04060; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } -.Delimiter { color: #a04060; } --> </style> @@ -29,60 +28,60 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } </head> <body> <pre id='vimCodeElement'> -<span class="Normal">void</span> test_trace_check_compares<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_check_compares<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer: foo"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_check_ignores_other_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_check_ignores_other_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> CHECK_TRACE_DOESNT_CONTAIN<span class="Delimiter">(</span><span class="Constant">"test layer 2: foo"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_check_ignores_other_lines<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_check_ignores_other_lines<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_check_ignores_other_lines2<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_check_ignores_other_lines2<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1: bar"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_ignores_trailing_whitespace<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_ignores_trailing_whitespace<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_ignores_trailing_whitespace2<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_ignores_trailing_whitespace2<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo "</span> << end<span class="Delimiter">();</span> CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_orders_across_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_orders_across_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"qux"</span> << end<span class="Delimiter">();</span> CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1: foo^Dtest layer 2: bar^Dtest layer 1: qux^D"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_supports_count<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_supports_count<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> CHECK_EQ<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_supports_count2<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_supports_count2<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> CHECK_EQ<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> test_trace_count_ignores_trailing_whitespace<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trace_count_ignores_trailing_whitespace<span class="Delimiter">()</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> CHECK<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -100,26 +99,26 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">// can't check trace because trace methods call 'split'</span> -<span class="Normal">void</span> test_split_returns_at_least_one_elem<span class="Delimiter">()</span> <span class="Delimiter">{</span> +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="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="Normal">void</span> test_split_returns_entire_input_when_no_delim<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="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> -<span class="Normal">void</span> test_split_works<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="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> -<span class="Normal">void</span> test_split_works2<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="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> @@ -127,7 +126,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } 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> -<span class="Normal">void</span> test_split_handles_multichar_delim<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="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> @@ -135,7 +134,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } 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> -<span class="Normal">void</span> test_trim<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void test_trim<span class="Delimiter">()</span> <span class="Delimiter">{</span> CHECK_EQ<span class="Delimiter">(</span>trim<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>trim<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>trim<span class="Delimiter">(</span><span class="Constant">" "</span><span class="Delimiter">),</span> <span class="Constant">""</span><span class="Delimiter">);</span> diff --git a/html/010vm.cc.html b/html/010vm.cc.html index f028e2f1..4d1ed5fc 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -14,13 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.PreProc { color: #c000c0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } +.SalientComment { color: #00ffff; } .CommentedCode { color: #6c6c6c; } +.PreProc { color: #c000c0; } .Identifier { color: #804000; } --> </style> @@ -46,12 +45,12 @@ recipe_ordinal Next_recipe_ordinal = <span class="Constant">1</span><span class= <span class="Comment">//: adding two phone numbers is meaningless. Here each recipe does something</span> <span class="Comment">//: incommensurable with any other recipe.</span> <span class="Delimiter">:(after "Types")</span> -<span class="Normal">typedef</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> recipe_ordinal<span class="Delimiter">;</span> +typedef long long int recipe_ordinal<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Types")</span> <span class="Comment">// Recipes are lists of instructions. To perform or 'run' a recipe, the</span> <span class="Comment">// computer runs its instructions.</span> -<span class="Normal">struct</span> recipe <span class="Delimiter">{</span> +struct recipe <span class="Delimiter">{</span> string name<span class="Delimiter">;</span> vector<instruction> steps<span class="Delimiter">;</span> <span class="Comment">// End recipe Fields</span> @@ -63,16 +62,16 @@ recipe_ordinal Next_recipe_ordinal = <span class="Constant">1</span><span class= <span class="Comment">// or just a single 'label' starting with a non-alphanumeric character</span> <span class="Comment">// +label</span> <span class="Comment">// Labels don't do anything, they're just waypoints.</span> -<span class="Normal">struct</span> instruction <span class="Delimiter">{</span> - <span class="Normal">bool</span> is_label<span class="Delimiter">;</span> +struct instruction <span class="Delimiter">{</span> + bool is_label<span class="Delimiter">;</span> string label<span class="Delimiter">;</span> <span class="Comment">// only if is_label</span> string name<span class="Delimiter">;</span> <span class="Comment">// only if !is_label</span> recipe_ordinal operation<span class="Delimiter">;</span> <span class="Comment">// Recipe_ordinal[name]</span> vector<reagent> ingredients<span class="Delimiter">;</span> <span class="Comment">// only if !is_label</span> vector<reagent> products<span class="Delimiter">;</span> <span class="Comment">// only if !is_label</span> instruction<span class="Delimiter">();</span> - <span class="Normal">void</span> clear<span class="Delimiter">();</span> - string to_string<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span> + void clear<span class="Delimiter">();</span> + string to_string<span class="Delimiter">()</span> const<span class="Delimiter">;</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "struct instruction")</span> @@ -80,27 +79,27 @@ recipe_ordinal Next_recipe_ordinal = <span class="Constant">1</span><span class= <span class="Comment">// either to numbers or to locations in memory along with 'type' tags telling</span> <span class="Comment">// us how to interpret them. They also can contain arbitrary other lists of</span> <span class="Comment">// properties besides types, but we're getting ahead of ourselves.</span> -<span class="Normal">struct</span> reagent <span class="Delimiter">{</span> +struct reagent <span class="Delimiter">{</span> string original_string<span class="Delimiter">;</span> vector<pair<string<span class="Delimiter">,</span> vector<string> > > properties<span class="Delimiter">;</span> string name<span class="Delimiter">;</span> - <span class="Normal">double</span> value<span class="Delimiter">;</span> - <span class="Normal">bool</span> initialized<span class="Delimiter">;</span> + double value<span class="Delimiter">;</span> + bool initialized<span class="Delimiter">;</span> vector<type_ordinal> types<span class="Delimiter">;</span> reagent<span class="Delimiter">(</span>string s<span class="Delimiter">);</span> reagent<span class="Delimiter">();</span> - <span class="Normal">void</span> set_value<span class="Delimiter">(</span><span class="Normal">double</span> v<span class="Delimiter">)</span> <span class="Delimiter">{</span> value = v<span class="Delimiter">;</span> initialized = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - string to_string<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span> + void set_value<span class="Delimiter">(</span>double v<span class="Delimiter">)</span> <span class="Delimiter">{</span> value = v<span class="Delimiter">;</span> initialized = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + string to_string<span class="Delimiter">()</span> const<span class="Delimiter">;</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "struct reagent")</span> -<span class="Normal">struct</span> property <span class="Delimiter">{</span> +struct property <span class="Delimiter">{</span> vector<string> values<span class="Delimiter">;</span> <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<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span><span class="Delimiter">,</span> <span class="Normal">double</span>> Memory<span class="Delimiter">;</span> +map<long long int<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> @@ -113,13 +112,13 @@ Memory<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Comment">// Unlike most computers today, mu stores types in a single big table, shared</span> <span class="Comment">// by all the mu programs on the computer. This is useful in providing a</span> <span class="Comment">// seamless experience to help understand arbitrary mu programs.</span> -<span class="Normal">typedef</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> type_ordinal<span class="Delimiter">;</span> +typedef long long int type_ordinal<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Globals")</span> map<string<span class="Delimiter">,</span> type_ordinal> Type_ordinal<span class="Delimiter">;</span> map<type_ordinal<span class="Delimiter">,</span> type_info> Type<span class="Delimiter">;</span> type_ordinal Next_type_ordinal = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> setup_types<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void setup_types<span class="Delimiter">()</span> <span class="Delimiter">{</span> Type<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Type_ordinal<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Type_ordinal[<span class="Constant">"literal"</span>] = <span class="Constant">0</span><span class="Delimiter">;</span> Next_type_ordinal = <span class="Constant">1</span><span class="Delimiter">;</span> @@ -153,23 +152,23 @@ setup_types<span class="Delimiter">();</span> <span class="Comment">// container, but if bank accounts may be either for individuals or groups,</span> <span class="Comment">// with different properties for each, that may require an exclusive container</span> <span class="Comment">// whose variants are individual-account and joint-account containers.</span> -<span class="Normal">enum</span> kind_of_type <span class="Delimiter">{</span> +enum kind_of_type <span class="Delimiter">{</span> primitive<span class="Delimiter">,</span> container<span class="Delimiter">,</span> exclusive_container <span class="Delimiter">};</span> -<span class="Normal">struct</span> type_info <span class="Delimiter">{</span> +struct type_info <span class="Delimiter">{</span> string name<span class="Delimiter">;</span> kind_of_type kind<span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size<span class="Delimiter">;</span> <span class="Comment">// only if type is not primitive; primitives and addresses have size 1 (except arrays are dynamic)</span> + long long int size<span class="Delimiter">;</span> <span class="Comment">// only if type is not primitive; primitives and addresses have size 1 (except arrays are dynamic)</span> vector<vector<type_ordinal> > elements<span class="Delimiter">;</span> vector<string> element_names<span class="Delimiter">;</span> <span class="Comment">// End type_info Fields</span> type_info<span class="Delimiter">()</span> :kind<span class="Delimiter">(</span>primitive<span class="Delimiter">),</span> size<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Delimiter">};</span> -<span class="Normal">enum</span> primitive_recipes <span class="Delimiter">{</span> +enum primitive_recipes <span class="Delimiter">{</span> IDLE = <span class="Constant">0</span><span class="Delimiter">,</span> COPY<span class="Delimiter">,</span> <span class="Comment">// End Primitive Recipe Declarations</span> @@ -180,7 +179,7 @@ setup_types<span class="Delimiter">();</span> <span class="Comment">//: to know how to do *something* out of the box. For the following</span> <span class="Comment">//: recipes there are only codes, no entries in the book, because mu just knows</span> <span class="Comment">//: what to do for them.</span> -<span class="Normal">void</span> setup_recipes<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void setup_recipes<span class="Delimiter">()</span> <span class="Delimiter">{</span> Recipe<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Recipe_ordinal<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Recipe_ordinal[<span class="Constant">"idle"</span>] = IDLE<span class="Delimiter">;</span> <span class="Comment">// Primitive Recipe Numbers</span> @@ -207,40 +206,42 @@ Next_recipe_ordinal = <span class="Constant">1000</span><span class="Delimiter"> <span class="Delimiter">:(code)</span> instruction::instruction<span class="Delimiter">()</span> :is_label<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">),</span> operation<span class="Delimiter">(</span>IDLE<span class="Delimiter">)</span> <span class="Delimiter">{}</span> -<span class="Normal">void</span> instruction::clear<span class="Delimiter">()</span> <span class="Delimiter">{</span> is_label=<span class="Constant">false</span><span class="Delimiter">;</span> label<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> operation=IDLE<span class="Delimiter">;</span> ingredients<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> products<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> +void instruction::clear<span class="Delimiter">()</span> <span class="Delimiter">{</span> is_label=<span class="Constant">false</span><span class="Delimiter">;</span> label<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> operation=IDLE<span class="Delimiter">;</span> ingredients<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> products<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Comment">// Reagents have the form <name>:<type>:<type>:.../<property>/<property>/...</span> reagent::reagent<span class="Delimiter">(</span>string s<span class="Delimiter">)</span> :original_string<span class="Delimiter">(</span>s<span class="Delimiter">),</span> value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> initialized<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// Parsing reagent(string s)</span> istringstream in<span class="Delimiter">(</span>s<span class="Delimiter">);</span> in >> std::noskipws<span class="Delimiter">;</span> <span class="Comment">// properties</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> istringstream row<span class="Delimiter">(</span>slurp_until<span class="Delimiter">(</span>in<span class="Delimiter">,</span> <span class="Constant">'/'</span><span class="Delimiter">));</span> row >> std::noskipws<span class="Delimiter">;</span> string name = slurp_until<span class="Delimiter">(</span>row<span class="Delimiter">,</span> <span class="Constant">':'</span><span class="Delimiter">);</span> vector<string> values<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!row<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> + while <span class="Delimiter">(</span>!row<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> values<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>slurp_until<span class="Delimiter">(</span>row<span class="Delimiter">,</span> <span class="Constant">':'</span><span class="Delimiter">));</span> 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="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>first<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<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> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> string type = 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="Normal">if</span> <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>type<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>type<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << type << " is " << Next_type_ordinal << '\n'; //? 1</span> Type_ordinal[type] = Next_type_ordinal++<span class="Delimiter">;</span> <span class="Delimiter">}</span> types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_ordinal[type]<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>name<span class="Delimiter">)</span> && types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>name<span class="Delimiter">)</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="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">"literal"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>name == <span class="Constant">"_"</span> && types<span class="Delimiter">.</span>empty<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="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="Comment">// End Parsing reagent</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> @@ -250,19 +251,19 @@ reagent::reagent<span class="Delimiter">()</span> :value<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><span class="Constant">""</span><span class="Delimiter">,</span> vector<string><span class="Delimiter">()));</span> <span class="Delimiter">}</span> -string reagent::to_string<span class="Delimiter">()</span> <span class="Normal">const</span> <span class="Delimiter">{</span> +string reagent::to_string<span class="Delimiter">()</span> const <span class="Delimiter">{</span> 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">"</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!properties<span class="Delimiter">.</span>empty<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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> 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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">':'</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">':'</span><span class="Delimiter">;</span> out << <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">"</span> << properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>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> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>i < SIZE<span class="Delimiter">(</span>properties<span class="Delimiter">)</span>-<span class="Constant">1</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> - <span class="Normal">else</span> out << <span class="Constant">"]"</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>i < SIZE<span class="Delimiter">(</span>properties<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> <span class="Delimiter">}</span> <span class="Delimiter">}</span> out << <span class="Constant">"}"</span><span class="Delimiter">;</span> @@ -270,27 +271,27 @@ string reagent::to_string<span class="Delimiter">()</span> <span class="Normal"> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -string instruction::to_string<span class="Delimiter">()</span> <span class="Normal">const</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_label<span class="Delimiter">)</span> <span class="Identifier">return</span> label<span class="Delimiter">;</span> +string instruction::to_string<span class="Delimiter">()</span> const <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_label<span class="Delimiter">)</span> <span class="Identifier">return</span> label<span class="Delimiter">;</span> ostringstream out<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> out << products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> out << <span class="Constant">" <- "</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> out << <span class="Constant">" <- "</span><span class="Delimiter">;</span> out << name << <span class="Constant">' '</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> out << ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -string slurp_until<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> <span class="Normal">char</span> delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string slurp_until<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> char delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream out<span class="Delimiter">;</span> - <span class="Normal">char</span> c<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> + char c<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>c == delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// drop the delim</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -299,29 +300,29 @@ string slurp_until<span class="Delimiter">(</span>istream& in<span class="De <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> has_property<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> string name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> +bool has_property<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> string name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == name<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <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><span class="Normal">const</span> reagent& r<span class="Delimiter">,</span> <span class="Normal">const</span> string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> p = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> p != SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> +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>long long int p = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> p != SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>p<span class="Delimiter">).</span>first == name<span class="Delimiter">)</span> <span class="Identifier">return</span> r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>p<span class="Delimiter">).</span>second<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> vector<string><span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> dump_memory<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>map<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span><span class="Delimiter">,</span> <span class="Normal">double</span>>::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> +void dump_memory<span class="Delimiter">()</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>map<long long int<span class="Delimiter">,</span> double>::iterator p = Memory<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Memory<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> cout << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Includes")</span> <span class="PreProc">#include</span><span class="Constant"><utility></span> -<span class="Normal">using</span> std::pair<span class="Delimiter">;</span> +using std::pair<span class="Delimiter">;</span> </pre> </body> </html> diff --git a/html/011load.cc.html b/html/011load.cc.html index bda6b17b..73e924c9 100644 --- a/html/011load.cc.html +++ b/html/011load.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -38,7 +37,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenarios load)</span> <span class="Comment">// use 'load' instead of 'run' in all scenarios in this layer</span> <span class="Delimiter">:(scenario first_recipe)</span> recipe main [ - <span class="Constant">1</span>:number<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> ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span> @@ -54,21 +53,21 @@ vector<recipe_ordinal> load<span class="Delimiter">(</span>string form<spa vector<recipe_ordinal> load<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> in >> std::noskipws<span class="Delimiter">;</span> vector<recipe_ordinal> result<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "===\n"; //? 1</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> string command = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Comment">// Command Handlers</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>command == <span class="Constant">"recipe"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>command == <span class="Constant">"recipe"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> string recipe_name = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="CommentedCode">//? cerr << "recipe: " << recipe_name << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>recipe_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>recipe_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << <span class="Constant">"empty recipe name</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>recipe_name<span class="Delimiter">)</span> == Recipe_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>recipe_name<span class="Delimiter">)</span> == Recipe_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> Recipe_ordinal[recipe_name] = Next_recipe_ordinal++<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>warn_on_redefine<span class="Delimiter">(</span>recipe_name<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>warn_on_redefine<span class="Delimiter">(</span>recipe_name<span class="Delimiter">)</span> && Recipe<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Recipe_ordinal[recipe_name]<span class="Delimiter">)</span> != Recipe<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << <span class="Constant">"redefining recipe "</span> << Recipe[Recipe_ordinal[recipe_name]]<span class="Delimiter">.</span>name << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -81,7 +80,7 @@ vector<recipe_ordinal> load<span class="Delimiter">(</span>istream& in result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Recipe_ordinal[recipe_name]<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// End Command Handlers</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> raise << <span class="Constant">"unknown top-level command: "</span> << command << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -92,11 +91,11 @@ vector<recipe_ordinal> load<span class="Delimiter">(</span>istream& in recipe slurp_recipe<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> recipe result<span class="Delimiter">;</span> skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">()</span> != <span class="Constant">'['</span><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 << <span class="Constant">"recipe body must begin with '['</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> instruction curr<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>next_instruction<span class="Delimiter">(</span>in<span class="Delimiter">,</span> &curr<span class="Delimiter">))</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>next_instruction<span class="Delimiter">(</span>in<span class="Delimiter">,</span> &curr<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// End Rewrite Instruction(curr)</span> <span class="CommentedCode">//? cerr << "instruction: " << curr.to_string() << '\n'; //? 2</span> result<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> @@ -104,34 +103,34 @@ recipe slurp_recipe<span class="Delimiter">(</span>istream& in<span class="D <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> next_instruction<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> instruction* curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool next_instruction<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> instruction* curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> in >> std::noskipws<span class="Delimiter">;</span> curr<span class="Delimiter">-></span>clear<span class="Delimiter">();</span> - <span class="Normal">if</span> <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> + 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">//? show_rest_of_stream(in); //? 1</span> - skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Normal">if</span> <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> + skip_whitespace<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">//? show_rest_of_stream(in); //? 1</span> - skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Normal">if</span> <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> + 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> vector<string> words<span class="Delimiter">;</span> <span class="CommentedCode">//? show_rest_of_stream(in); //? 1</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Normal">if</span> <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> + while <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + skip_whitespace<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">//? show_rest_of_stream(in); //? 1</span> - string word = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Normal">if</span> <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> + string word = next_word<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">//? cerr << "AAA: " << word << '\n'; //? 1</span> words<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>word<span class="Delimiter">);</span> - skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Normal">if</span> <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> + skip_whitespace<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="Delimiter">}</span> - skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Normal">if</span> <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> + 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 (SIZE(words) == 1) cout << words.at(0) << ' ' << SIZE(words.at(0)) << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"]"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"]"</span><span class="Delimiter">)</span> <span class="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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && !isalnum<span class="Delimiter">(</span>words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != <span class="Constant">'$'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && !isalnum<span class="Delimiter">(</span>words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != <span class="Constant">'$'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> curr<span class="Delimiter">-></span>is_label = <span class="Constant">true</span><span class="Delimiter">;</span> 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 << end<span class="Delimiter">();</span> @@ -139,41 +138,41 @@ recipe slurp_recipe<span class="Delimiter">(</span>istream& in<span class="D <span class="Delimiter">}</span> vector<string>::iterator p = words<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>find<span class="Delimiter">(</span>words<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> words<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">"<-"</span><span class="Delimiter">)</span> != words<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(;</span> *p != <span class="Constant">"<-"</span><span class="Delimiter">;</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>*p == <span class="Constant">","</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>find<span class="Delimiter">(</span>words<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> words<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">"<-"</span><span class="Delimiter">)</span> != words<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(;</span> *p != <span class="Constant">"<-"</span><span class="Delimiter">;</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>*p == <span class="Constant">","</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span>*p<span class="Delimiter">));</span> <span class="CommentedCode">//? cerr << "product: " << curr->products.back().to_string() << '\n'; //? 1</span> <span class="Delimiter">}</span> ++p<span class="Delimiter">;</span> <span class="Comment">// skip <-</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>p == words<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>p == words<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << <span class="Constant">"instruction prematurely ended with '<-'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> curr<span class="Delimiter">-></span>name = *p<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>*p<span class="Delimiter">)</span> == Recipe_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>*p<span class="Delimiter">)</span> == Recipe_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> Recipe_ordinal[*p] = Next_recipe_ordinal++<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << "AAA: " << *p << " is now " << Recipe_ordinal[*p] << '\n'; //? 1</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Recipe_ordinal[*p] == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Recipe_ordinal[*p] == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"Recipe "</span> << *p << <span class="Constant">" has number 0, which is reserved for IDLE.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> curr<span class="Delimiter">-></span>operation = Recipe_ordinal[*p]<span class="Delimiter">;</span> ++p<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(;</span> p != words<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>*p == <span class="Constant">","</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + for <span class="Delimiter">(;</span> p != words<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>*p == <span class="Constant">","</span><span class="Delimiter">)</span> <span class="Identifier">continue</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>*p<span class="Delimiter">));</span> <span class="CommentedCode">//? cerr << "ingredient: " << curr->ingredients.back().to_string() << '\n'; //? 1</span> <span class="Delimiter">}</span> trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction: "</span> << curr<span class="Delimiter">-></span>name << end<span class="Delimiter">();</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">" ingredient: "</span> << p<span class="Delimiter">-></span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">" product: "</span> << p<span class="Delimiter">-></span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> !in<span class="Delimiter">.</span>eof<span class="Delimiter">();</span> @@ -190,17 +189,17 @@ string next_word<span class="Delimiter">(</span>istream& in<span class="Deli <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> slurp_word<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void slurp_word<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "AAA slurp_word\n"; //? 1</span> - <span class="Normal">char</span> c<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">','</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + char c<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">','</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> in >> c<span class="Delimiter">;</span> out << c<span class="Delimiter">;</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << c << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>c<span class="Delimiter">)</span> || c == <span class="Constant">','</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>c<span class="Delimiter">)</span> || c == <span class="Constant">','</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> in<span class="Delimiter">.</span>putback<span class="Delimiter">(</span>c<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -208,30 +207,30 @@ string next_word<span class="Delimiter">(</span>istream& in<span class="Deli <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> skip_whitespace<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +void skip_whitespace<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> skip_whitespace_and_comments<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> skip_comment<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">else</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +void skip_whitespace_and_comments<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + else if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> skip_comment<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + else <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> skip_comment<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +void skip_comment<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + while <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> skip_comma<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void skip_comma<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> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">','</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">','</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -239,24 +238,24 @@ string next_word<span class="Delimiter">(</span>istream& in<span class="Deli <span class="Comment">//: step on their own toes. But there'll be many occasions later where</span> <span class="Comment">//: we'll want to disable the warnings.</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">bool</span> Disable_redefine_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> +bool Disable_redefine_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Disable_redefine_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> -<span class="Normal">bool</span> warn_on_redefine<span class="Delimiter">(</span><span class="Normal">const</span> string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Disable_redefine_warnings<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +bool warn_on_redefine<span class="Delimiter">(</span>const string& recipe_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Disable_redefine_warnings<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// for debugging</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">bool</span> Show_rest_of_stream = <span class="Constant">false</span><span class="Delimiter">;</span> +bool Show_rest_of_stream = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> show_rest_of_stream<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Show_rest_of_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +void show_rest_of_stream<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Show_rest_of_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> cerr << <span class="Constant">'^'</span><span class="Delimiter">;</span> - <span class="Normal">char</span> c<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> + char c<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> cerr << c<span class="Delimiter">;</span> <span class="Delimiter">}</span> cerr << <span class="Constant">"$</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> @@ -267,7 +266,7 @@ Disable_redefine_warnings = <span class="Constant">false</span><span class="Deli <span class="Delimiter">:(before "End Globals")</span> vector<recipe_ordinal> recently_added_recipes<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>recently_added_recipes<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>recently_added_recipes<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "AAA clearing " << Recipe[recently_added_recipes.at(i)].name << '\n'; //? 2</span> Recipe_ordinal<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> @@ -280,7 +279,7 @@ 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>:number<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> ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span> @@ -289,7 +288,7 @@ recipe main [ <span class="Delimiter">:(scenario parse_comment_amongst_instruction)</span> recipe main [ <span class="Comment"># comment</span> - <span class="Constant">1</span>:number<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> ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span> @@ -298,7 +297,7 @@ recipe main [ <span class="Delimiter">:(scenario parse_comment_amongst_instruction2)</span> recipe main [ <span class="Comment"># comment</span> - <span class="Constant">1</span>:number<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> <span class="Comment"># comment</span> ] <span class="traceContains">+parse: instruction: copy</span> @@ -307,9 +306,9 @@ recipe main [ <span class="Delimiter">:(scenario parse_comment_amongst_instruction3)</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Comment"># comment</span> - <span class="Constant">2</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">23</span> ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span> @@ -320,7 +319,7 @@ recipe main [ <span class="Delimiter">:(scenario parse_comment_after_instruction)</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal <span class="Comment"># comment</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> <span class="Comment"># comment</span> ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span> @@ -340,7 +339,7 @@ recipe main [ <span class="Delimiter">:(scenario parse_multiple_properties)</span> recipe main [ - <span class="Constant">1</span>:number<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>/foo:bar:baz ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal", "foo": "bar":"baz"]}</span> @@ -348,7 +347,7 @@ recipe main [ <span class="Delimiter">:(scenario parse_multiple_products)</span> recipe main [ - <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>: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> ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span> @@ -357,7 +356,7 @@ recipe main [ <span class="Delimiter">:(scenario parse_multiple_ingredients)</span> recipe main [ - <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:number + <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">4</span>:number ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span> @@ -367,7 +366,7 @@ recipe main [ <span class="Delimiter">:(scenario parse_multiple_types)</span> recipe main [ - <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:number + <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">4</span>:number ] <span class="traceContains">+parse: instruction: copy</span> <span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span> @@ -377,9 +376,9 @@ recipe main [ <span class="Delimiter">:(scenario parse_properties)</span> recipe main [ - <span class="Constant">1</span>:number:address/deref<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">1</span>:number:address/lookup<span class="Special"> <- </span>copy <span class="Constant">23</span> ] -<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number":"address", "deref": ]}</span> +<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number":"address", "lookup": ]}</span> </pre> </body> </html> diff --git a/html/012transform.cc.html b/html/012transform.cc.html index 21163e04..407e5be7 100644 --- a/html/012transform.cc.html +++ b/html/012transform.cc.html @@ -14,7 +14,6 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .CommentedCode { color: #6c6c6c; } @@ -36,23 +35,23 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">//: deconstructed alternative to conventional compilers.</span> <span class="Delimiter">:(before "End recipe Fields")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> transformed_until<span class="Delimiter">;</span> +long long int transformed_until<span class="Delimiter">;</span> recipe<span class="Delimiter">()</span> :transformed_until<span class="Delimiter">(</span>-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span class="Delimiter">:(before "End Types")</span> -<span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*transform_fn<span class="Delimiter">)(</span>recipe_ordinal<span class="Delimiter">);</span> +typedef void <span class="Delimiter">(</span>*transform_fn<span class="Delimiter">)(</span>recipe_ordinal<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Globals")</span> vector<transform_fn> Transform<span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> transform_all<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void transform_all<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "AAA transform_all\n"; //? 2</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> t = <span class="Constant">0</span><span class="Delimiter">;</span> t < SIZE<span class="Delimiter">(</span>Transform<span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>map<recipe_ordinal<span class="Delimiter">,</span> recipe>::iterator p = Recipe<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Recipe<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int t = <span class="Constant">0</span><span class="Delimiter">;</span> t < SIZE<span class="Delimiter">(</span>Transform<span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>map<recipe_ordinal<span class="Delimiter">,</span> recipe>::iterator p = Recipe<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Recipe<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> recipe& r = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <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> + 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<span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span><span class="Comment">/*</span><span class="Comment">recipe_ordinal</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> @@ -60,27 +59,27 @@ vector<transform_fn> Transform<span class="Delimiter">;</span> parse_int_reagents<span class="Delimiter">();</span> <span class="Comment">// do this after all other transforms have run</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> parse_int_reagents<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void parse_int_reagents<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "parse_int_reagents\n"; //? 1</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>map<recipe_ordinal<span class="Delimiter">,</span> recipe>::iterator p = Recipe<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Recipe<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>map<recipe_ordinal<span class="Delimiter">,</span> recipe>::iterator p = Recipe<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Recipe<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> recipe& r = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> - <span class="Normal">if</span> <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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <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>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> 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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> 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> <span class="Delimiter">}</span> -<span class="Normal">void</span> populate_value<span class="Delimiter">(</span>reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +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> <span class="Comment">// End Reagent-parsing Exceptions</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!is_integer<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_integer<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">));</span> <span class="Delimiter">}</span> </pre> diff --git a/html/013literal_string.cc.html b/html/013literal_string.cc.html index 03e3b5d3..b6c539cf 100644 --- a/html/013literal_string.cc.html +++ b/html/013literal_string.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -57,7 +56,7 @@ recipe main [ Type_ordinal[<span class="Constant">"literal-string"</span>] = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(after "string next_word(istream& in)")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> string result = slurp_quoted<span class="Delimiter">(</span>in<span class="Delimiter">);</span> skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> skip_comment<span class="Delimiter">(</span>in<span class="Delimiter">);</span> @@ -68,26 +67,26 @@ Type_ordinal[<span class="Constant">"literal-string"</span>] = <span c <span class="Delimiter">:(code)</span> string slurp_quoted<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream out<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">());</span> assert<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'['</span><span class="Delimiter">);</span> out << <span class="Normal">static_cast</span><<span class="Normal">char</span>><span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span> <span class="Comment">// slurp the '['</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>code_string<span class="Delimiter">(</span>in<span class="Delimiter">,</span> out<span class="Delimiter">))</span> + assert<span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">());</span> assert<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'['</span><span class="Delimiter">);</span> out << static_cast<char><span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span> <span class="Comment">// slurp the '['</span> + if <span class="Delimiter">(</span>code_string<span class="Delimiter">(</span>in<span class="Delimiter">,</span> out<span class="Delimiter">))</span> slurp_quoted_comment_aware<span class="Delimiter">(</span>in<span class="Delimiter">,</span> out<span class="Delimiter">);</span> - <span class="Normal">else</span> + else slurp_quoted_comment_oblivious<span class="Delimiter">(</span>in<span class="Delimiter">,</span> out<span class="Delimiter">);</span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Comment">// A string is a code string if it contains a newline before any non-whitespace</span> <span class="Comment">// todo: support comments before the newline. But that gets messy.</span> -<span class="Normal">bool</span> code_string<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostringstream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> - <span class="Normal">char</span> c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!isspace<span class="Delimiter">(</span>c<span class="Delimiter">))</span> <span class="Delimiter">{</span> +bool code_string<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostringstream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> + char c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!isspace<span class="Delimiter">(</span>c<span class="Delimiter">))</span> <span class="Delimiter">{</span> in<span class="Delimiter">.</span>putback<span class="Delimiter">(</span>c<span class="Delimiter">);</span> <span class="CommentedCode">//? cerr << "code_string: " << out.str() << '\n'; //? 1</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> out << c<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>c == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "code_string: " << out.str() << '\n'; //? 1</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -97,70 +96,69 @@ string slurp_quoted<span class="Delimiter">(</span>istream& in<span class="D <span class="Comment">// Read a regular string. Regular strings can only contain other regular</span> <span class="Comment">// strings.</span> -<span class="Normal">void</span> slurp_quoted_comment_oblivious<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostringstream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void slurp_quoted_comment_oblivious<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostringstream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "comment oblivious\n"; //? 1</span> - <span class="Normal">int</span> brace_depth = <span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> - <span class="Normal">char</span> c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + int brace_depth = <span class="Constant">1</span><span class="Delimiter">;</span> + while <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> + char c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="CommentedCode">//? cerr << '%' << (int)c << ' ' << brace_depth << ": " << out.str() << "%$\n"; //? 1</span> <span class="CommentedCode">//? cout << (int)c << ": " << brace_depth << '\n'; //? 2</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="cSpecial">'\\'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - out << <span class="Normal">static_cast</span><<span class="Normal">char</span>><span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span> + if <span class="Delimiter">(</span>c == <span class="cSpecial">'\\'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << static_cast<char><span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> out << c<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << out.str() << "$\n"; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'['</span><span class="Delimiter">)</span> ++brace_depth<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">']'</span><span class="Delimiter">)</span> --brace_depth<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>brace_depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>c == <span class="Constant">'['</span><span class="Delimiter">)</span> ++brace_depth<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>c == <span class="Constant">']'</span><span class="Delimiter">)</span> --brace_depth<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>brace_depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">()</span> && brace_depth > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">()</span> && brace_depth > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"unbalanced '['</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> out<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Comment">// Read a code string. Code strings can contain either code or regular strings.</span> -<span class="Normal">void</span> slurp_quoted_comment_aware<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostringstream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void slurp_quoted_comment_aware<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostringstream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "comment aware\n"; //? 1</span> - <span class="Normal">char</span> c<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> + char c<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << '^' << (int)c << ": " << out.str() << "$\n"; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="cSpecial">'\\'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - out << <span class="Normal">static_cast</span><<span class="Normal">char</span>><span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span> + if <span class="Delimiter">(</span>c == <span class="cSpecial">'\\'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << static_cast<char><span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>c == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> out << c<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">()</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> out << <span class="Normal">static_cast</span><<span class="Normal">char</span>><span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span> + while <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">()</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> out << static_cast<char><span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>c == <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> in<span class="Delimiter">.</span>putback<span class="Delimiter">(</span>c<span class="Delimiter">);</span> <span class="Comment">// recurse</span> out << slurp_quoted<span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> out << c<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">']'</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>c == <span class="Constant">']'</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> raise << <span class="Constant">"unbalanced '['</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> out<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(after "reagent::reagent(string s)")</span> -<span class="CommentedCode">//? cout << s.at(0) << '\n'; //? 1</span> - <span class="Normal">if</span> <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>SIZE<span class="Delimiter">(</span>s<span class="Delimiter">)</span>-<span class="Constant">1</span><span class="Delimiter">);</span> - name = s<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="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> vector<string><span class="Delimiter">()));</span> - properties<span class="Delimiter">.</span>back<span class="Delimiter">().</span>second<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"literal-string"</span><span class="Delimiter">);</span> - <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> +<span class="Delimiter">:(after "Parsing reagent(string s)")</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>SIZE<span class="Delimiter">(</span>s<span class="Delimiter">)</span>-<span class="Constant">1</span><span class="Delimiter">);</span> + name = s<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="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> vector<string><span class="Delimiter">()));</span> + properties<span class="Delimiter">.</span>back<span class="Delimiter">().</span>second<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"literal-string"</span><span class="Delimiter">);</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> <span class="Comment">//: Two tweaks to printing literal strings compared to other reagents:</span> <span class="Comment">//: a) Don't print the string twice in the representation, just put '_' in</span> @@ -168,21 +166,21 @@ string slurp_quoted<span class="Delimiter">(</span>istream& in<span class="D <span class="Comment">//: b) Escape newlines in the string to make it more friendly to trace().</span> <span class="Delimiter">:(after "string reagent::to_string()")</span> - <span class="Normal">if</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>empty<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> + if <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>empty<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="Identifier">return</span> emit_literal_string<span class="Delimiter">(</span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> string emit_literal_string<span class="Delimiter">(</span>string name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">size_t</span> pos = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>pos != string::npos<span class="Delimiter">)</span> + size_t pos = <span class="Constant">0</span><span class="Delimiter">;</span> + while <span class="Delimiter">(</span>pos != string::npos<span class="Delimiter">)</span> pos = replace<span class="Delimiter">(</span>name<span class="Delimiter">,</span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">,</span> <span class="Constant">"</span><span class="cSpecial">\\</span><span class="Constant">n"</span><span class="Delimiter">,</span> pos<span class="Delimiter">);</span> <span class="Identifier">return</span> <span class="Constant">"{name: </span><span class="cSpecial">\"</span><span class="Constant">"</span>+name+<span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">, properties: [_: </span><span class="cSpecial">\"</span><span class="Constant">literal-string</span><span class="cSpecial">\"</span><span class="Constant">]}"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">size_t</span> replace<span class="Delimiter">(</span>string& str<span class="Delimiter">,</span> <span class="Normal">const</span> string& from<span class="Delimiter">,</span> <span class="Normal">const</span> string& to<span class="Delimiter">,</span> <span class="Normal">size_t</span> n<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">size_t</span> result = str<span class="Delimiter">.</span>find<span class="Delimiter">(</span>from<span class="Delimiter">,</span> n<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>result != string::npos<span class="Delimiter">)</span> +size_t replace<span class="Delimiter">(</span>string& str<span class="Delimiter">,</span> const string& from<span class="Delimiter">,</span> const string& to<span class="Delimiter">,</span> size_t n<span class="Delimiter">)</span> <span class="Delimiter">{</span> + size_t result = str<span class="Delimiter">.</span>find<span class="Delimiter">(</span>from<span class="Delimiter">,</span> n<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>result != string::npos<span class="Delimiter">)</span> str<span class="Delimiter">.</span>replace<span class="Delimiter">(</span>result<span class="Delimiter">,</span> from<span class="Delimiter">.</span>length<span class="Delimiter">(),</span> to<span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/014literal_noninteger.cc.html b/html/014literal_noninteger.cc.html index b2578e88..7235bf47 100644 --- a/html/014literal_noninteger.cc.html +++ b/html/014literal_noninteger.cc.html @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -33,7 +32,6 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <body> <pre id='vimCodeElement'> <span class="Comment">//: Support literal non-integers.</span> -<span class="Comment">//: '3.14159:literal' is ugly, so we'll just say '3.14159' for non-integers.</span> <span class="Delimiter">:(scenarios load)</span> <span class="Delimiter">:(scenario noninteger_literal)</span> @@ -42,26 +40,26 @@ recipe main [ ] <span class="traceContains">+parse: ingredient: {name: "3.14159", properties: ["3.14159": "literal-number"]}</span> -<span class="Delimiter">:(after "reagent::reagent(string s)")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> - name = s<span class="Delimiter">;</span> - types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> vector<string> ><span class="Delimiter">(</span>name<span class="Delimiter">,</span> vector<string><span class="Delimiter">()));</span> - properties<span class="Delimiter">.</span>back<span class="Delimiter">().</span>second<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"literal-number"</span><span class="Delimiter">);</span> - set_value<span class="Delimiter">(</span>to_double<span class="Delimiter">(</span>s<span class="Delimiter">));</span> - <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> +<span class="Delimiter">:(after "Parsing reagent(string s)")</span> +if <span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> + name = s<span class="Delimiter">;</span> + types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> vector<string> ><span class="Delimiter">(</span>name<span class="Delimiter">,</span> vector<string><span class="Delimiter">()));</span> + properties<span class="Delimiter">.</span>back<span class="Delimiter">().</span>second<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"literal-number"</span><span class="Delimiter">);</span> + set_value<span class="Delimiter">(</span>to_double<span class="Delimiter">(</span>s<span class="Delimiter">));</span> + <span class="Identifier">return</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">bool</span> is_noninteger<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool is_noninteger<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-."</span><span class="Delimiter">)</span> == string::npos && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'.'</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">double</span> to_double<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">char</span>* end = <span class="Constant">NULL</span><span class="Delimiter">;</span> +double to_double<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> <span class="Comment">// safe because string.c_str() is guaranteed to be null-terminated</span> - <span class="Normal">double</span> result = strtod<span class="Delimiter">(</span>n<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">);</span> + double result = strtod<span class="Delimiter">(</span>n<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>*end == <span class="cSpecial">'\0'</span><span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/020run.cc.html b/html/020run.cc.html index ffe4de8f..bf21779f 100644 --- a/html/020run.cc.html +++ b/html/020run.cc.html @@ -13,17 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceAbsent { color: #c00000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -48,14 +47,14 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario copy_literal)</span> recipe main [ - <span class="Constant">1</span>:number<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> ] -<span class="traceContains">+run: 1:number <- copy 23:literal</span> +<span class="traceContains">+run: 1:number <- copy 23</span> <span class="traceContains">+mem: storing 23 in location 1</span> <span class="Delimiter">:(scenario copy)</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] <span class="traceContains">+run: 2:number <- copy 1:number</span> @@ -64,7 +63,7 @@ recipe main [ <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="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">24</span> ] <span class="traceContains">+mem: storing 23 in location 1</span> <span class="traceContains">+mem: storing 24 in location 2</span> @@ -72,120 +71,130 @@ recipe main [ <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> -<span class="Normal">struct</span> routine <span class="Delimiter">{</span> +struct routine <span class="Delimiter">{</span> recipe_ordinal running_recipe<span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> running_step_index<span class="Delimiter">;</span> + long long int running_step_index<span class="Delimiter">;</span> routine<span class="Delimiter">(</span>recipe_ordinal 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="Normal">bool</span> completed<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span> + bool completed<span class="Delimiter">()</span> const<span class="Delimiter">;</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "End Globals")</span> routine* Current_routine = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> run<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void run<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> routine rr<span class="Delimiter">(</span>r<span class="Delimiter">);</span> Current_routine = &rr<span class="Delimiter">;</span> run_current_routine<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> run_current_routine<span class="Delimiter">()</span> +void run_current_routine<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Comment">// curly on a separate line, because later layers will modify header</span> <span class="CommentedCode">//? cerr << "AAA 6\n"; //? 3</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>completed<span class="Delimiter">())</span> <span class="Comment">// later layers will modify condition</span> + while <span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>completed<span class="Delimiter">())</span> <span class="Comment">// later layers will modify condition</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "AAA 7: " << current_step_index() << '\n'; //? 1</span> <span class="Comment">// Running One Instruction</span> - <span class="Normal">if</span> <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> + if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>is_label<span class="Delimiter">)</span> <span class="Delimiter">{</span> ++current_step_index<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> trace<span class="Delimiter">(</span>Initial_callstack_depth+Callstack_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[<span class="Constant">0</span>] != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Memory[<span class="Constant">0</span>] != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"something wrote to location 0; this should never happen</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</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<<span class="Normal">double</span>> > ingredients<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<vector<double> > ingredients<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> 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'.</span> - vector<vector<<span class="Normal">double</span>> > products<span class="Delimiter">;</span> + vector<vector<double> > products<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "AAA 8: " << current_instruction().operation << " ^" << Recipe[current_instruction().operation].name << "$\n"; //? 1</span> <span class="CommentedCode">//? cerr << "% " << current_recipe_name() << "/" << current_step_index() << ": " << Memory[1013] << ' ' << Memory[1014] << '\n'; //? 1</span> - <span class="Normal">switch</span> <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">)</span> <span class="Delimiter">{</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> - <span class="Normal">case</span> COPY: <span class="Delimiter">{</span> + case COPY: <span class="Delimiter">{</span> <span class="CommentedCode">//? if (!ingredients.empty()) cerr << current_instruction().ingredients.at(0).to_string() << ' ' << ingredients.at(0).at(0) << '\n'; //? 1</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> - <span class="Normal">default</span>: <span class="Delimiter">{</span> + default: <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">))</span> raise << SIZE<span class="Delimiter">(</span>products<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> << <span class="Constant">": failed to write to all products! "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> 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="Comment">// End of Instruction</span> ++current_step_index<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="CommentedCode">//? cerr << "AAA 9\n"; //? 2</span> - <span class="Normal">stop_running_current_routine</span>:<span class="Delimiter">;</span> + stop_running_current_routine:<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: Some helpers.</span> <span class="Comment">//: We'll need to override these later as we change the definition of routine.</span> <span class="Comment">//: Important that they return referrences into the routine.</span> -<span class="Normal">inline</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>& current_step_index<span class="Delimiter">()</span> <span class="Delimiter">{</span> +inline long long int& current_step_index<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> Current_routine<span class="Delimiter">-></span>running_step_index<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">inline</span> <span class="Normal">const</span> string& current_recipe_name<span class="Delimiter">()</span> <span class="Delimiter">{</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>running_recipe]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">inline</span> <span class="Normal">const</span> instruction& current_instruction<span class="Delimiter">()</span> <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<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> -<span class="Normal">inline</span> <span class="Normal">bool</span> routine::completed<span class="Delimiter">()</span> <span class="Normal">const</span> <span class="Delimiter">{</span> +inline bool routine::completed<span class="Delimiter">()</span> const <span class="Delimiter">{</span> <span class="Identifier">return</span> running_step_index >= SIZE<span class="Delimiter">(</span>Recipe[running_recipe]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Commandline Parsing")</span> <span class="Comment">// Loading Commandline Files</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> 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> +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> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Main")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>!Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>!Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span> setup<span class="Delimiter">();</span> -<span class="CommentedCode">//? Trace_file = "interactive"; //? 1</span> -<span class="CommentedCode">//? START_TRACING_UNTIL_END_OF_SCOPE;</span> -<span class="CommentedCode">//? Trace_stream->dump_layer = "all"; //? 2</span> +<span class="CommentedCode">//? Trace_file = "interactive"; //? 2</span> +<span class="CommentedCode">//? START_TRACING_UNTIL_END_OF_SCOPE; //? 2</span> +<span class="CommentedCode">//? Trace_stream->collect_layer = "app"; //? 1</span> transform_all<span class="Delimiter">();</span> recipe_ordinal r = Recipe_ordinal[string<span class="Delimiter">(</span><span class="Constant">"main"</span><span class="Delimiter">)</span>]<span class="Delimiter">;</span> -<span class="CommentedCode">//? Trace_stream->dump_layer = "all"; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">)</span> run<span class="Delimiter">(</span>r<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">)</span> run<span class="Delimiter">(</span>r<span class="Delimiter">);</span> <span class="CommentedCode">//? dump_memory(); //? 1</span> teardown<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> load_permanently<span class="Delimiter">(</span>string filename<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void cleanup_main<span class="Delimiter">()</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Trace_file<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + ofstream fout<span class="Delimiter">(</span>Trace_file<span class="Delimiter">.</span>c_str<span class="Delimiter">());</span> + fout << Trace_stream<span class="Delimiter">-></span>readable_contents<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> + fout<span class="Delimiter">.</span>close<span class="Delimiter">();</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(before "End One-time Setup")</span> +atexit<span class="Delimiter">(</span>cleanup_main<span class="Delimiter">);</span> + +<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> - <span class="Normal">if</span> <span class="Delimiter">(</span>!fin<span class="Delimiter">)</span> <span class="Delimiter">{</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> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -204,11 +213,11 @@ load_permanently<span class="Delimiter">(</span><span class="Constant">"cor <span class="Delimiter">:(code)</span> <span class="Comment">// helper for tests</span> -<span class="Normal">void</span> run<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void run<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "AAA 2\n"; //? 2</span> <span class="CommentedCode">//? cerr << form << '\n'; //? 1</span> vector<recipe_ordinal> tmp = load<span class="Delimiter">(</span>form<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> transform_all<span class="Delimiter">();</span> <span class="CommentedCode">//? cerr << "AAA 3\n"; //? 2</span> run<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>front<span class="Delimiter">());</span> @@ -217,83 +226,85 @@ load_permanently<span class="Delimiter">(</span><span class="Constant">"cor <span class="SalientComment">//:: Reading from memory, writing to memory.</span> -vector<<span class="Normal">double</span>> read_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <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<<span class="Normal">double</span>> result<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span> + vector<double> result<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_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> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size = size_of<span class="Delimiter">(</span>x<span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">double</span> val = Memory[base+offset]<span class="Delimiter">;</span> + long long int base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + long long int size = size_of<span class="Delimiter">(</span>x<span class="Delimiter">);</span> + for <span class="Delimiter">(</span>long long int 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> + double val = Memory[base+offset]<span class="Delimiter">;</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<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 << end<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> -<span class="Normal">void</span> write_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> vector<<span class="Normal">double</span>> data<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>size_mismatch<span class="Delimiter">(</span>x<span class="Delimiter">,</span> data<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": size mismatch in storing to "</span> << x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">" at "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<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> + if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + long long int base = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>size_mismatch<span class="Delimiter">(</span>x<span class="Delimiter">,</span> data<span class="Delimiter">))</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": size mismatch in storing to "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" at '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset < SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int offset = <span class="Constant">0</span><span class="Delimiter">;</span> offset < SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span> ++offset<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<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 << end<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> <span class="Delimiter">:(code)</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +long long int size_of<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// End size_of(reagent) Cases</span> <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> vector<type_ordinal>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +long long int size_of<span class="Delimiter">(</span>const vector<type_ordinal>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// End size_of(types) Cases</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> size_mismatch<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">,</span> <span class="Normal">const</span> vector<<span class="Normal">double</span>>& data<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool size_mismatch<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">,</span> const vector<double>& data<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Comment">// End size_mismatch(x) Cases</span> <span class="CommentedCode">//? if (size_of(x) != SIZE(data)) cerr << size_of(x) << " vs " << SIZE(data) << '\n'; //? 2</span> <span class="Identifier">return</span> size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> != SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> is_dummy<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool is_dummy<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> x<span class="Delimiter">.</span>name == <span class="Constant">"_"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> is_literal<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool is_literal<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<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>:number<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> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] -<span class="traceContains">+run: 1:number <- copy 23:literal</span> +<span class="traceContains">+run: 1:number <- copy 23</span> <span class="traceContains">+run: 2:number <- copy 1:number</span> <span class="traceAbsent">-run: +foo</span> <span class="Delimiter">:(scenario run_dummy)</span> recipe main [ - _<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + _<span class="Special"> <- </span>copy <span class="Constant">0</span> ] -<span class="traceContains">+run: _ <- copy 0:literal</span> +<span class="traceContains">+run: _ <- copy 0</span> -<span class="Delimiter">:(scenario run_literal)</span> +<span class="Delimiter">:(scenario write_to_0_disallowed)</span> recipe main [ - <span class="Constant">0</span>:literal/screen<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">0</span><span class="Special"> <- </span>copy <span class="Constant">34</span> ] -<span class="traceAbsent">-mem: storing 0 in location 0</span> +<span class="traceAbsent">-mem: storing 34 in location 0</span> </pre> </body> </html> diff --git a/html/021arithmetic.cc.html b/html/021arithmetic.cc.html index 11c9267a..b43cb286 100644 --- a/html/021arithmetic.cc.html +++ b/html/021arithmetic.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Special { color: #ff6060; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } +.Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -40,10 +39,10 @@ ADD<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"add"</span>] = ADD<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> ADD: <span class="Delimiter">{</span> - <span class="Normal">double</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> +case ADD: <span class="Delimiter">{</span> + double result = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="CommentedCode">//? if (!tb_is_active()) cerr << ingredients.at(1).at(0) << '\n'; //? 1</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</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> @@ -54,21 +53,21 @@ Recipe_ordinal[<span class="Constant">"add"</span>] = ADD<span class=" <span class="Delimiter">:(scenario add_literal)</span> recipe main [ - <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="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">23</span><span class="Delimiter">,</span> <span class="Constant">34</span> ] <span class="traceContains">+mem: storing 57 in location 1</span> <span class="Delimiter">:(scenario add)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Constant">3</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <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="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">,</span> <span class="Constant">5</span> ] <span class="traceContains">+mem: storing 12 in location 1</span> @@ -77,14 +76,14 @@ SUBTRACT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"subtract"</span>] = SUBTRACT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> SUBTRACT: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +case SUBTRACT: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'subtract' has no ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>scalar<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="Normal">double</span> 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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + 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>long long int i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</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> @@ -95,21 +94,21 @@ Recipe_ordinal[<span class="Constant">"subtract"</span>] = SUBTRACT<sp <span class="Delimiter">:(scenario subtract_literal)</span> recipe main [ - <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="Constant">1</span>:number<span class="Special"> <- </span>subtract <span class="Constant">5</span><span class="Delimiter">,</span> <span class="Constant">2</span> ] <span class="traceContains">+mem: storing 3 in location 1</span> <span class="Delimiter">:(scenario subtract)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Constant">3</span>:number<span class="Special"> <- </span>subtract <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <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="Constant">1</span>:number<span class="Special"> <- </span>subtract <span class="Constant">6</span><span class="Delimiter">,</span> <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">2</span> ] <span class="traceContains">+mem: storing 1 in location 1</span> @@ -118,9 +117,9 @@ MULTIPLY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"multiply"</span>] = MULTIPLY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> MULTIPLY: <span class="Delimiter">{</span> - <span class="Normal">double</span> result = <span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +case MULTIPLY: <span class="Delimiter">{</span> + double result = <span class="Constant">1</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</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> @@ -131,21 +130,21 @@ Recipe_ordinal[<span class="Constant">"multiply"</span>] = MULTIPLY<sp <span class="Delimiter">:(scenario multiply_literal)</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="Constant">1</span>:number<span class="Special"> <- </span>multiply <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">3</span> ] <span class="traceContains">+mem: storing 6 in location 1</span> <span class="Delimiter">:(scenario multiply)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">4</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">6</span> <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">+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="Constant">1</span>:number<span class="Special"> <- </span>multiply <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> ] <span class="traceContains">+mem: storing 24 in location 1</span> @@ -154,14 +153,14 @@ DIVIDE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"divide"</span>] = DIVIDE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> DIVIDE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +case DIVIDE: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'divide' has no ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>scalar<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="Normal">double</span> 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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + 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>long long int i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</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> @@ -172,21 +171,21 @@ Recipe_ordinal[<span class="Constant">"divide"</span>] = DIVIDE<span c <span class="Delimiter">:(scenario divide_literal)</span> recipe main [ - <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="Constant">1</span>:number<span class="Special"> <- </span>divide <span class="Constant">8</span><span class="Delimiter">,</span> <span class="Constant">2</span> ] <span class="traceContains">+mem: storing 4 in location 1</span> <span class="Delimiter">:(scenario divide)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">27</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <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">+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="Constant">1</span>:number<span class="Special"> <- </span>divide <span class="Constant">12</span><span class="Delimiter">,</span> <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">2</span> ] <span class="traceContains">+mem: storing 2 in location 1</span> @@ -197,13 +196,13 @@ DIVIDE_WITH_REMAINDER<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"divide-with-remainder"</span>] = DIVIDE_WITH_REMAINDER<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> DIVIDE_WITH_REMAINDER: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case DIVIDE_WITH_REMAINDER: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'divide-with-remainder' requires exactly two ingredients, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> remainder = <span class="Normal">static_cast</span><<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>><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="Normal">static_cast</span><<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</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 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> @@ -213,15 +212,15 @@ Recipe_ordinal[<span class="Constant">"divide-with-remainder"</span>] <span class="Delimiter">:(scenario divide_with_remainder_literal)</span> recipe main [ - <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="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><span class="Delimiter">,</span> <span class="Constant">2</span> ] <span class="traceContains">+mem: storing 4 in location 1</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>: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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">27</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">11</span> <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">+mem: storing 2 in location 3</span> @@ -230,15 +229,15 @@ recipe main [ <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="Constant">1</span>:number<span class="Special"> <- </span>divide <span class="Constant">5</span><span class="Delimiter">,</span> <span class="Constant">2</span> ] <span class="traceContains">+mem: storing 2.5 in location 1</span> <span class="Delimiter">:(code)</span> -<span class="Normal">inline</span> <span class="Normal">bool</span> scalar<span class="Delimiter">(</span><span class="Normal">const</span> vector<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +inline bool scalar<span class="Delimiter">(</span>const vector<long long int>& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>x<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">inline</span> <span class="Normal">bool</span> scalar<span class="Delimiter">(</span><span class="Normal">const</span> vector<<span class="Normal">double</span>>& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +inline bool scalar<span class="Delimiter">(</span>const vector<double>& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>x<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> </pre> diff --git a/html/022boolean.cc.html b/html/022boolean.cc.html index a3a6d1c1..484cae1a 100644 --- a/html/022boolean.cc.html +++ b/html/022boolean.cc.html @@ -13,13 +13,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -38,9 +37,9 @@ AND<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"and"</span>] = AND<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> AND: <span class="Delimiter">{</span> - <span class="Normal">bool</span> result = <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +case AND: <span class="Delimiter">{</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</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> @@ -51,27 +50,27 @@ Recipe_ordinal[<span class="Constant">"and"</span>] = AND<span class=" <span class="Delimiter">:(scenario and)</span> recipe main [ - <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><span class="Normal">and</span> <span class="Constant">1</span>:boolean<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">0</span> + <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">+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><span class="Normal">and</span> <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">1</span>:literal + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>and <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span> ] <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><span class="Normal">and</span> <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="Constant">1</span>:boolean<span class="Special"> <- </span>and <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">0</span> ] <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><span class="Normal">and</span> <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="Constant">1</span>:boolean<span class="Special"> <- </span>and <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 1 in location 1</span> @@ -80,9 +79,9 @@ OR<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"or"</span>] = OR<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> OR: <span class="Delimiter">{</span> - <span class="Normal">bool</span> result = <span class="Constant">false</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +case OR: <span class="Delimiter">{</span> + bool result = <span class="Constant">false</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</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> @@ -93,27 +92,27 @@ Recipe_ordinal[<span class="Constant">"or"</span>] = OR<span class="De <span class="Delimiter">:(scenario or)</span> recipe main [ - <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><span class="Normal">or</span> <span class="Constant">1</span>:boolean<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">0</span> + <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">+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><span class="Normal">or</span> <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">0</span>:literal + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>or <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span> ] <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><span class="Normal">and</span> <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="Constant">1</span>:boolean<span class="Special"> <- </span>and <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span> ] <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><span class="Normal">or</span> <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="Constant">1</span>:boolean<span class="Special"> <- </span>or <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 1 in location 1</span> @@ -122,9 +121,9 @@ NOT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"not"</span>] = NOT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> NOT: <span class="Delimiter">{</span> +case NOT: <span class="Delimiter">{</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">));</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<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>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> @@ -133,14 +132,14 @@ Recipe_ordinal[<span class="Constant">"not"</span>] = NOT<span class=" <span class="Delimiter">:(scenario not)</span> recipe main [ - <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><span class="Normal">not</span> <span class="Constant">1</span>:boolean + <span class="Constant">1</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>not <span class="Constant">1</span>:boolean ] <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><span class="Normal">not</span> <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="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><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 1 in location 2</span> diff --git a/html/023jump.cc.html b/html/023jump.cc.html index 16a89563..472a964b 100644 --- a/html/023jump.cc.html +++ b/html/023jump.cc.html @@ -13,16 +13,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.traceAbsent { color: #c00000; } -.Constant { color: #00a0a0; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } -.Special { color: #ff6060; } +.Constant { color: #00a0a0; } +.traceAbsent { color: #c00000; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } +.Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -40,10 +39,10 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="CommentedCode">#? % Trace_stream->dump_layer = "all"; #? 1</span> recipe main [ jump <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="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> ] <span class="traceContains">+run: jump 1:offset</span> -<span class="traceAbsent">-run: 1:number <- copy 1:literal</span> +<span class="traceAbsent">-run: 1:number <- copy 1</span> <span class="traceAbsent">-mem: storing 1 in location 1</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> @@ -51,12 +50,12 @@ JUMP<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"jump"</span>] = JUMP<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> JUMP: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case JUMP: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'jump' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'jump' should be a label or offset, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -86,21 +85,21 @@ JUMP_IF<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"jump-if"</span>] = JUMP_IF<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> JUMP_IF: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case JUMP_IF: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'jump-if' requires exactly two ingredients, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'jump-if' requires a boolean for its first ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'jump-if' requires a label or offset for its second ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> 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> - <span class="Normal">if</span> <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> + 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>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if fell through"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -111,22 +110,22 @@ Recipe_ordinal[<span class="Constant">"jump-if"</span>] = JUMP_IF<span <span class="Delimiter">:(scenario jump_if)</span> recipe main [ - jump-<span class="Normal">if</span> <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 + jump-if <span class="Constant">999</span><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> ] -<span class="traceContains">+run: jump-if 999:literal, 1:offset</span> +<span class="traceContains">+run: jump-if 999, 1:offset</span> <span class="traceContains">+run: jumping to instruction 2</span> -<span class="traceAbsent">-run: 1:number <- copy 1:literal</span> +<span class="traceAbsent">-run: 1:number <- copy 1</span> <span class="traceAbsent">-mem: storing 1 in location 123</span> <span class="Delimiter">:(scenario jump_if_fallthrough)</span> recipe main [ - jump-<span class="Normal">if</span> <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 + jump-if <span class="Constant">0</span><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> ] -<span class="traceContains">+run: jump-if 0:literal, 1:offset</span> +<span class="traceContains">+run: jump-if 0, 1:offset</span> <span class="traceContains">+run: jump-if fell through</span> -<span class="traceContains">+run: 123:number <- copy 1:literal</span> +<span class="traceContains">+run: 123:number <- copy 1</span> <span class="traceContains">+mem: storing 1 in location 123</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> @@ -134,21 +133,21 @@ JUMP_UNLESS<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"jump-unless"</span>] = JUMP_UNLESS<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> JUMP_UNLESS: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case JUMP_UNLESS: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'jump-unless' requires exactly two ingredients, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'jump-unless' requires a boolean for its first ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'jump-unless' requires a label or offset for its second ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> 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> - <span class="Normal">if</span> <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> + 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>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless fell through"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -159,22 +158,22 @@ Recipe_ordinal[<span class="Constant">"jump-unless"</span>] = JUMP_UNL <span class="Delimiter">:(scenario jump_unless)</span> recipe main [ - jump-unless <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 + jump-unless <span class="Constant">0</span><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> ] -<span class="traceContains">+run: jump-unless 0:literal, 1:offset</span> +<span class="traceContains">+run: jump-unless 0, 1:offset</span> <span class="traceContains">+run: jumping to instruction 2</span> -<span class="traceAbsent">-run: 123:number <- copy 1:literal</span> +<span class="traceAbsent">-run: 123:number <- copy 1</span> <span class="traceAbsent">-mem: storing 1 in location 123</span> <span class="Delimiter">:(scenario jump_unless_fallthrough)</span> recipe main [ - 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 + jump-unless <span class="Constant">999</span><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> ] -<span class="traceContains">+run: jump-unless 999:literal, 1:offset</span> +<span class="traceContains">+run: jump-unless 999, 1:offset</span> <span class="traceContains">+run: jump-unless fell through</span> -<span class="traceContains">+run: 123:number <- copy 1:literal</span> +<span class="traceContains">+run: 123:number <- copy 1</span> <span class="traceContains">+mem: storing 1 in location 123</span> </pre> </body> diff --git a/html/024compare.cc.html b/html/024compare.cc.html index 38879a66..7944d4ff 100644 --- a/html/024compare.cc.html +++ b/html/024compare.cc.html @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -39,15 +38,15 @@ EQUAL<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"equal"</span>] = EQUAL<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> EQUAL: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case EQUAL: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'equal' needs at least two ingredients to compare in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - vector<<span class="Normal">double</span>>& exemplar = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">bool</span> result = <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + 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>long long int i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!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> @@ -59,8 +58,8 @@ Recipe_ordinal[<span class="Constant">"equal"</span>] = EQUAL<span cla <span class="Delimiter">:(scenario equal)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> <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">+mem: location 1 is 34</span> @@ -69,8 +68,8 @@ recipe main [ <span class="Delimiter">:(scenario equal2)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Constant">3</span>:number<span class="Special"> <- </span>equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+mem: location 1 is 34</span> @@ -79,13 +78,13 @@ recipe main [ <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="Constant">1</span>:number<span class="Special"> <- </span>equal <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">34</span> ] <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="Constant">1</span>:number<span class="Special"> <- </span>equal <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span> ] <span class="traceContains">+mem: storing 0 in location 1</span> @@ -94,24 +93,24 @@ GREATER_THAN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"greater-than"</span>] = GREATER_THAN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> GREATER_THAN: <span class="Delimiter">{</span> - <span class="Normal">bool</span> result = <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case GREATER_THAN: <span class="Delimiter">{</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'greater-than' needs at least two ingredients to compare in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'greater-than' can only compare numbers; got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">goto</span> finish_greater_than<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>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> - <span class="Normal">finish_greater_than</span>: + finish_greater_than: 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> @@ -119,29 +118,29 @@ Recipe_ordinal[<span class="Constant">"greater-than"</span>] = GREATER <span class="Delimiter">:(scenario greater_than)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> <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">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario greater_than2)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <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">+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="Constant">1</span>:boolean<span class="Special"> <- </span>greater-than <span class="Constant">36</span><span class="Delimiter">,</span> <span class="Constant">35</span><span class="Delimiter">,</span> <span class="Constant">34</span> ] <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="Constant">1</span>:boolean<span class="Special"> <- </span>greater-than <span class="Constant">36</span><span class="Delimiter">,</span> <span class="Constant">35</span><span class="Delimiter">,</span> <span class="Constant">35</span> ] <span class="traceContains">+mem: storing 0 in location 1</span> @@ -150,24 +149,24 @@ LESSER_THAN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"lesser-than"</span>] = LESSER_THAN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> LESSER_THAN: <span class="Delimiter">{</span> - <span class="Normal">bool</span> result = <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case LESSER_THAN: <span class="Delimiter">{</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'lesser-than' needs at least two ingredients to compare in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'lesser-than' can only compare numbers; got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">goto</span> finish_lesser_than<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>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> - <span class="Normal">finish_lesser_than</span>: + finish_lesser_than: 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> @@ -175,29 +174,29 @@ Recipe_ordinal[<span class="Constant">"lesser-than"</span>] = LESSER_T <span class="Delimiter">:(scenario lesser_than)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">32</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> <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">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario lesser_than2)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> <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">+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="Constant">1</span>:boolean<span class="Special"> <- </span>lesser-than <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span><span class="Delimiter">,</span> <span class="Constant">36</span> ] <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="Constant">1</span>:boolean<span class="Special"> <- </span>lesser-than <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span><span class="Delimiter">,</span> <span class="Constant">35</span> ] <span class="traceContains">+mem: storing 0 in location 1</span> @@ -206,24 +205,24 @@ GREATER_OR_EQUAL<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"greater-or-equal"</span>] = GREATER_OR_EQUAL<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> GREATER_OR_EQUAL: <span class="Delimiter">{</span> - <span class="Normal">bool</span> result = <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case GREATER_OR_EQUAL: <span class="Delimiter">{</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'greater-or-equal' needs at least two ingredients to compare in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'greater-or-equal' can only compare numbers; got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">goto</span> finish_greater_or_equal<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>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> - <span class="Normal">finish_greater_or_equal</span>: + finish_greater_or_equal: 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> @@ -231,37 +230,37 @@ Recipe_ordinal[<span class="Constant">"greater-or-equal"</span>] = GRE <span class="Delimiter">:(scenario greater_or_equal)</span> recipe main [ - <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-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> + <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">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario greater_or_equal2)</span> recipe main [ - <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-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <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">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario greater_or_equal3)</span> recipe main [ - <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-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <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">+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-<span class="Normal">or</span>-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="Constant">1</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">36</span><span class="Delimiter">,</span> <span class="Constant">35</span><span class="Delimiter">,</span> <span class="Constant">35</span> ] <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-<span class="Normal">or</span>-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="Constant">1</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">36</span><span class="Delimiter">,</span> <span class="Constant">35</span><span class="Delimiter">,</span> <span class="Constant">36</span> ] <span class="traceContains">+mem: storing 0 in location 1</span> @@ -270,24 +269,24 @@ LESSER_OR_EQUAL<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"lesser-or-equal"</span>] = LESSER_OR_EQUAL<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> LESSER_OR_EQUAL: <span class="Delimiter">{</span> - <span class="Normal">bool</span> result = <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case LESSER_OR_EQUAL: <span class="Delimiter">{</span> + bool result = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> <= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'lesser-or-equal' needs at least two ingredients to compare in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'lesser-or-equal' can only compare numbers; got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">goto</span> finish_lesser_or_equal<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/**/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>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> - <span class="Normal">finish_lesser_or_equal</span>: + finish_lesser_or_equal: 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> @@ -295,37 +294,37 @@ Recipe_ordinal[<span class="Constant">"lesser-or-equal"</span>] = LESS <span class="Delimiter">:(scenario lesser_or_equal)</span> recipe main [ - <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-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">32</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> + <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">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario lesser_or_equal2)</span> recipe main [ - <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-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> + <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">+mem: storing 1 in location 3</span> <span class="Delimiter">:(scenario lesser_or_equal3)</span> recipe main [ - <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-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">33</span> + <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">+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-<span class="Normal">or</span>-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="Constant">1</span>:boolean<span class="Special"> <- </span>lesser-or-equal <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span><span class="Delimiter">,</span> <span class="Constant">35</span> ] <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-<span class="Normal">or</span>-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="Constant">1</span>:boolean<span class="Special"> <- </span>lesser-or-equal <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span><span class="Delimiter">,</span> <span class="Constant">34</span> ] <span class="traceContains">+mem: storing 0 in location 1</span> </pre> diff --git a/html/027trace.cc.html b/html/027trace.cc.html deleted file mode 100644 index 1be9cffe..00000000 --- a/html/027trace.cc.html +++ /dev/null @@ -1,122 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> -<meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 027trace.cc</title> -<meta name="Generator" content="Vim/7.4"> -<meta name="plugin-version" content="vim7.4_v1"> -<meta name="syntax" content="cpp"> -<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> -<meta name="colorscheme" content="minimal"> -<style type="text/css"> -<!-- -pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } -body { font-family: monospace; color: #eeeeee; background-color: #080808; } -* { font-size: 1.05em; } -.cSpecial { color: #008000; } -.Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } -.Comment { color: #9090ff; } -.Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } -.Identifier { color: #804000; } -.traceContains { color: #008000; } ---> -</style> - -<script type='text/javascript'> -<!-- - ---> -</script> -</head> -<body> -<pre id='vimCodeElement'> -<span class="Comment">//: Allow mu programs to log facts just like we've been doing in C++ so far.</span> - -<span class="Delimiter">:(scenario trace)</span> -recipe main [ - trace [foo]<span class="Delimiter">,</span> [<span class="Normal">this</span> is a trace in mu] -] -<span class="traceContains">+foo: this is a trace in mu</span> - -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -TRACE<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"trace"</span>] = TRACE<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> TRACE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'trace' takes exactly two ingredients rather than '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - assert<span class="Delimiter">(</span>is_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>is_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><span class="Constant">1</span><span class="Delimiter">,</span> label<span class="Delimiter">)</span> << message << end<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_ordinal[<span class="Constant">"hide-warnings"</span>] = HIDE_WARNINGS<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> 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> - -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -SHOW_WARNINGS<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"show-warnings"</span>] = SHOW_WARNINGS<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> SHOW_WARNINGS: <span class="Delimiter">{</span> - Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> - -<span class="Comment">//: helpers for debugging</span> - -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -_START_TRACING<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$start-tracing"</span>] = _START_TRACING<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _START_TRACING: <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> - <span class="Normal">else</span> - 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> - -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -_STOP_TRACING<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$stop-tracing"</span>] = _STOP_TRACING<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _STOP_TRACING: <span class="Delimiter">{</span> - Trace_stream<span class="Delimiter">-></span>dump_layer = <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> -_CLOSE_TRACE<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$close-trace"</span>] = _CLOSE_TRACE<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _CLOSE_TRACE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">delete</span> Trace_stream<span class="Delimiter">;</span> - Trace_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> -</pre> -</body> -</html> -<!-- vim: set foldmethod=manual : --> diff --git a/html/028assert.cc.html b/html/028assert.cc.html deleted file mode 100644 index 3adae63f..00000000 --- a/html/028assert.cc.html +++ /dev/null @@ -1,67 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> -<meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 028assert.cc</title> -<meta name="Generator" content="Vim/7.4"> -<meta name="plugin-version" content="vim7.4_v1"> -<meta name="syntax" content="cpp"> -<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> -<meta name="colorscheme" content="minimal"> -<style type="text/css"> -<!-- -pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } -body { font-family: monospace; color: #eeeeee; background-color: #080808; } -* { font-size: 1.05em; } -.cSpecial { color: #008000; } -.Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } -.Delimiter { color: #a04060; } -.Special { color: #ff6060; } -.Identifier { color: #804000; } -.traceContains { color: #008000; } ---> -</style> - -<script type='text/javascript'> -<!-- - ---> -</script> -</head> -<body> -<pre id='vimCodeElement'> -<span class="Delimiter">:(scenario assert)</span> -<span class="Special">% Hide_warnings = true; // '%' lines insert arbitrary C code into tests before calling 'run' with the lines below. Must be immediately after :(scenario) line.</span> -recipe main [ - assert <span class="Constant">0</span>:literal<span class="Delimiter">,</span> [<span class="Normal">this</span> is an assert in mu] -] -<span class="traceContains">+warn: this is an assert in mu</span> - -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -ASSERT<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"assert"</span>] = ASSERT<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> ASSERT: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'assert' takes exactly two ingredients rather than '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'assert' requires a boolean for its first ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'assert' requires a literal string for its second ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - <span class="Normal">if</span> <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> - 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> << end<span class="Delimiter">();</span> - <span class="Delimiter">}</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> -</pre> -</body> -</html> -<!-- vim: set foldmethod=manual : --> diff --git a/html/029debug.cc.html b/html/029debug.cc.html deleted file mode 100644 index 80f33d7d..00000000 --- a/html/029debug.cc.html +++ /dev/null @@ -1,69 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> -<meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 029debug.cc</title> -<meta name="Generator" content="Vim/7.4"> -<meta name="plugin-version" content="vim7.4_v1"> -<meta name="syntax" content="cpp"> -<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> -<meta name="colorscheme" content="minimal"> -<style type="text/css"> -<!-- -pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } -body { font-family: monospace; color: #eeeeee; background-color: #080808; } -* { font-size: 1.05em; } -.cSpecial { color: #008000; } -.Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } -.Delimiter { color: #a04060; } -.Identifier { color: #804000; } ---> -</style> - -<script type='text/javascript'> -<!-- - ---> -</script> -</head> -<body> -<pre id='vimCodeElement'> -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -_PRINT<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$print"</span>] = _PRINT<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _PRINT: <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_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>Primitive_recipe_depth<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 << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>has_property<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="Constant">"newline"</span><span class="Delimiter">))</span> - cout << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - <span class="Normal">else</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> - <span class="Normal">else</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span>Primitive_recipe_depth<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> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <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> - -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -_EXIT<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$exit"</span>] = _EXIT<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _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> -</pre> -</body> -</html> -<!-- vim: set foldmethod=manual : --> diff --git a/html/029tools.cc.html b/html/029tools.cc.html new file mode 100644 index 00000000..58b813e1 --- /dev/null +++ b/html/029tools.cc.html @@ -0,0 +1,244 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - 029tools.cc</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } +body { font-family: monospace; color: #eeeeee; background-color: #080808; } +* { font-size: 1.05em; } +.traceContains { color: #008000; } +.cSpecial { color: #008000; } +.Constant { color: #00a0a0; } +.SalientComment { color: #00ffff; } +.Comment { color: #9090ff; } +.Delimiter { color: #a04060; } +.Special { color: #ff6060; } +.Identifier { color: #804000; } +.CommentedCode { color: #6c6c6c; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment">//: Allow mu programs to log facts just like we've been doing in C++ so far.</span> + +<span class="Delimiter">:(scenario trace)</span> +recipe main [ + trace [foo]<span class="Delimiter">,</span> [this is a trace in mu] +] +<span class="traceContains">+foo: this is a trace in mu</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +TRACE<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<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> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'trace' takes exactly two ingredients rather than '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + assert<span class="Delimiter">(</span>is_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>is_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><span class="Constant">1</span><span class="Delimiter">,</span> label<span class="Delimiter">)</span> << message << end<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_ordinal[<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> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +SHOW_WARNINGS<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<span class="Constant">"show-warnings"</span>] = SHOW_WARNINGS<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case SHOW_WARNINGS: <span class="Delimiter">{</span> + Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +_START_TRACING<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<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> + 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> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +_STOP_TRACING<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<span class="Constant">"$stop-tracing"</span>] = _STOP_TRACING<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case _STOP_TRACING: <span class="Delimiter">{</span> + Trace_stream<span class="Delimiter">-></span>dump_layer = <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> +_CLOSE_TRACE<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<span class="Constant">"$close-trace"</span>] = _CLOSE_TRACE<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case _CLOSE_TRACE: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> + delete Trace_stream<span class="Delimiter">;</span> + Trace_stream = <span class="Constant">NULL</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_TRACE<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<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> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + DUMP<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + DUMP<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="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +_CLEAR_TRACE<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<span class="Constant">"$clear-trace"</span>] = _CLEAR_TRACE<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case _CLEAR_TRACE: <span class="Delimiter">{</span> + CLEAR_TRACE<span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Comment">//: assert: perform sanity checks at runtime</span> + +<span class="Delimiter">:(scenario assert)</span> +<span class="Special">% Hide_warnings = true; // '%' lines insert arbitrary C code into tests before calling 'run' with the lines below. Must be immediately after :(scenario) line.</span> +recipe main [ + assert <span class="Constant">0</span><span class="Delimiter">,</span> [this is an assert in mu] +] +<span class="traceContains">+warn: this is an assert in mu</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +ASSERT<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<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> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'assert' takes exactly two ingredients rather than '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'assert' requires a boolean for its first ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'assert' requires a literal string for its second ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + 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> + 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> << end<span class="Delimiter">();</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="SalientComment">//:: 'cheating' by using the host system</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +_PRINT<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<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> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_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>Primitive_recipe_depth<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 << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>has_property<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="Constant">"newline"</span><span class="Delimiter">))</span> + cout << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + else + 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>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span>Primitive_recipe_depth<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> << end<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> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +_EXIT<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<span class="Constant">"$exit"</span>] = _EXIT<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +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> +_SYSTEM<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_ordinal[<span class="Constant">"$system"</span>] = _SYSTEM<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case _SYSTEM: <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> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": '$system' requires exactly one ingredient, but got none</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + int status = system<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>c_str<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>status<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="SalientComment">//:: helpers for debugging</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_ordinal[<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> +<!-- vim: set foldmethod=manual : --> diff --git a/html/030container.cc.html b/html/030container.cc.html index 74eab00b..5d939c14 100644 --- a/html/030container.cc.html +++ b/html/030container.cc.html @@ -13,17 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceAbsent { color: #c00000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -56,8 +55,8 @@ Type[point]<span class="Delimiter">.</span>elements<span class="Delimiter">.</sp <span class="Comment">//: avoid warnings.</span> <span class="Delimiter">:(scenario copy_multiple_locations)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Constant">3</span>:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:point/<span class="Special">raw</span> <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 34 in location 3</span> @@ -79,9 +78,9 @@ Type[point_number]<span class="Delimiter">.</span>elements<span class="Delimiter <span class="Delimiter">:(scenario copy_handles_nested_container_elements)</span> recipe main [ - <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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> <span class="Constant">15</span>:point-number<span class="Special"> <- </span>copy <span class="Constant">12</span>:point-number/<span class="Special">raw</span> <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 36 in location 17</span> @@ -91,36 +90,36 @@ recipe main [ <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># first</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># second</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> <span class="Constant">7</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:point-number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">4</span>:point-number/<span class="Special">raw</span> <span class="Comment"># unsafe</span> ] <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># first</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># second</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">37</span> <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="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">4</span>:point-number/<span class="Special">raw</span> <span class="Comment"># unsafe</span> ] <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="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>]<span class="Delimiter">;</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == container<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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// todo: strengthen assertion to disallow mutual type recursion</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == t<span class="Delimiter">.</span>elements<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> + if <span class="Delimiter">(</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == t<span class="Delimiter">.</span>elements<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> raise << <span class="Constant">"container "</span> << t<span class="Delimiter">.</span>name << <span class="Constant">" can't include itself as a member</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -132,8 +131,8 @@ type_info t = Type[types<span class="Delimiter">.</span>at<span class="Delimiter <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>: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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Constant">15</span>:number<span class="Special"> <- </span>get <span class="Constant">12</span>:point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:offset <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 35 in location 15</span> @@ -143,30 +142,30 @@ GET<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"get"</span>] = GET<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> GET: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case GET: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'get' expects exactly 2 ingredients in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> type_ordinal 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind != container<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind != container<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name <span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'get' should be a container, but got "</span> << base<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_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> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!is_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> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": second ingredient of 'get' should have type 'offset', but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>scalar<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="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> src = base_address<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> + long long int 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> + long long int src = base_address<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < offset<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> 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>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>offset < <span class="Constant">0</span> || offset >= SIZE<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>offset < <span class="Constant">0</span> || offset >= SIZE<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": invalid offset "</span> << offset << <span class="Constant">" for "</span> << Type[base_type]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -182,9 +181,9 @@ Recipe_ordinal[<span class="Constant">"get"</span>] = GET<span class=" <span class="Delimiter">:(scenario get_handles_nested_container_elements)</span> recipe main [ - <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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> <span class="Constant">15</span>:number<span class="Special"> <- </span>get <span class="Constant">12</span>:point-number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:offset <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 36 in location 15</span> @@ -193,8 +192,8 @@ recipe main [ <span class="Delimiter">:(scenario get_address)</span> recipe main [ - <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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Constant">15</span>:address:number<span class="Special"> <- </span>get-address <span class="Constant">12</span>:point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:offset <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 13 in location 15</span> @@ -202,9 +201,9 @@ recipe main [ <span class="Delimiter">:(scenario get_out_of_bounds)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> get <span class="Constant">12</span>:point-number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:offset <span class="Comment"># point-number occupies 3 locations but has only 2 fields; out of bounds</span> ] <span class="traceContains">+warn: main: invalid offset 2 for point-number</span> @@ -212,9 +211,9 @@ recipe main [ <span class="Delimiter">:(scenario get_out_of_bounds2)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> get <span class="Constant">12</span>:point-number/<span class="Special">raw</span><span class="Delimiter">,</span> -<span class="Constant">1</span>:offset ] <span class="traceContains">+warn: main: invalid offset -1 for point-number</span> @@ -224,27 +223,27 @@ GET_ADDRESS<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"get-address"</span>] = GET_ADDRESS<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> GET_ADDRESS: <span class="Delimiter">{</span> +case GET_ADDRESS: <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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> type_ordinal 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind != container<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind != container<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name <span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'get-address' should be a container, but got "</span> << base<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_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> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!is_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> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": second ingredient of 'get-address' should have type 'offset', but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>scalar<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="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>offset < <span class="Constant">0</span> || offset >= SIZE<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> + long long int 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> + if <span class="Delimiter">(</span>offset < <span class="Constant">0</span> || offset >= SIZE<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << <span class="Constant">"invalid offset "</span> << offset << <span class="Constant">" for "</span> << Type[base_type]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = base_address<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> + long long int result = base_address<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < offset<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> 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>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << result << end<span class="Delimiter">();</span> @@ -256,9 +255,9 @@ Recipe_ordinal[<span class="Constant">"get-address"</span>] = GET_ADDR <span class="Delimiter">:(scenario get_address_out_of_bounds)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> get-address <span class="Constant">12</span>:point-number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">2</span>:offset <span class="Comment"># point-number occupies 3 locations but has only 2 fields; out of bounds</span> ] <span class="traceContains">+warn: invalid offset 2 for point-number</span> @@ -266,9 +265,9 @@ recipe main [ <span class="Delimiter">:(scenario get_address_out_of_bounds2)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> get-address <span class="Constant">12</span>:point-number/<span class="Special">raw</span><span class="Delimiter">,</span> -<span class="Constant">1</span>:offset ] <span class="traceContains">+warn: invalid offset -1 for point-number</span> @@ -278,8 +277,8 @@ recipe main [ <span class="Delimiter">:(scenarios load)</span> <span class="Delimiter">:(scenario container)</span> container foo [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:number + x:number + y:number ] <span class="traceContains">+parse: reading container foo</span> <span class="traceContains">+parse: element name: x</span> @@ -289,13 +288,13 @@ container foo [ <span class="Delimiter">:(scenario container_use_before_definition)</span> container foo [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:bar + x:number + y:bar ] container bar [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:number + x:number + y:number ] <span class="traceContains">+parse: reading container foo</span> <span class="traceContains">+parse: type number: 1000</span> @@ -307,19 +306,19 @@ container bar [ <span class="traceContains">+parse: type number: 1001</span> <span class="Delimiter">:(before "End Command Handlers")</span> -<span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>command == <span class="Constant">"container"</span><span class="Delimiter">)</span> <span class="Delimiter">{</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> -<span class="Normal">void</span> insert_container<span class="Delimiter">(</span><span class="Normal">const</span> string& command<span class="Delimiter">,</span> kind_of_type kind<span class="Delimiter">,</span> istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</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 << end<span class="Delimiter">();</span> <span class="CommentedCode">//? cout << name << '\n'; //? 2</span> <span class="CommentedCode">//? if (Type_ordinal.find(name) != Type_ordinal.end()) //? 1</span> <span class="CommentedCode">//? cerr << Type_ordinal[name] << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>name<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">()</span> + if <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>name<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">()</span> || Type_ordinal[name] == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> Type_ordinal[name] = Next_type_ordinal++<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -329,17 +328,17 @@ container bar [ recently_added_types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_ordinal[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> - <span class="Normal">while</span> <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>element == <span class="Constant">"]"</span><span class="Delimiter">)</span> <span class="Identifier">break</span><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> << end<span class="Delimiter">();</span> vector<type_ordinal> types<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!inner<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>type_name<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>type_name<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << type_name << " is " << Next_type_ordinal << '\n'; //? 1</span> Type_ordinal[type_name] = Next_type_ordinal++<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -358,7 +357,7 @@ vector<type_ordinal> 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> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>recently_added_types<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>recently_added_types<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "erasing " << Type[recently_added_types.at(i)].name << '\n'; //? 1</span> Type_ordinal<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> @@ -367,14 +366,14 @@ recently_added_types<span class="Delimiter">.</span>clear<span class="Delimiter" <span class="Comment">// delete recent type references</span> <span class="Comment">// can't rely on recently_added_types to cleanup Type_ordinal, because of deliberately misbehaving tests with references to undefined types</span> map<string<span class="Delimiter">,</span> type_ordinal>::iterator p = Type_ordinal<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> -<span class="Normal">while</span><span class="Delimiter">(</span>p != Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> +while<span class="Delimiter">(</span>p != Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span class="Comment">// save current item</span> string name = p<span class="Delimiter">-></span>first<span class="Delimiter">;</span> type_ordinal t = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> <span class="Comment">// increment iterator</span> ++p<span class="Delimiter">;</span> <span class="Comment">// now delete current item if necessary</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>t >= <span class="Constant">1000</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>t >= <span class="Constant">1000</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "AAA " << name << " " << t << '\n'; //? 1</span> Type_ordinal<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -396,18 +395,18 @@ Next_type_ordinal = <span class="Constant">1000</span><span class="Delimiter">;< <span class="CommentedCode">#? % Trace_stream->dump_layer = "run";</span> recipe main [ <span class="Comment"># integer is not a type</span> - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+warn: unknown type: integer</span> <span class="Delimiter">:(scenario run_allows_type_definition_after_use)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:bar<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:bar<span class="Special"> <- </span>copy <span class="Constant">0</span> ] container bar [ - <span class="Normal">x</span>:number + x:number ] <span class="traceAbsent">-warn: unknown type: bar</span> $warn: <span class="Constant">0</span> @@ -416,22 +415,22 @@ $warn: <span class="Constant">0</span> Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_invalid_types<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> check_invalid_types<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</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="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void check_invalid_types<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<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>index<span class="Delimiter">);</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> check_invalid_types<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> check_invalid_types<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> check_invalid_types<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Type<span class="Delimiter">.</span>find<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> == Type<span class="Delimiter">.</span>end<span class="Delimiter">())</span> +void check_invalid_types<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">);</span> ++i<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>i<span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Type<span class="Delimiter">.</span>find<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> == Type<span class="Delimiter">.</span>end<span class="Delimiter">())</span> raise << <span class="Constant">"unknown type: "</span> << r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -439,16 +438,16 @@ $warn: <span class="Constant">0</span> <span class="Delimiter">:(scenario container_unknown_field)</span> <span class="Special">% Hide_warnings = true;</span> container foo [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:bar + x:number + y:bar ] <span class="traceContains">+warn: unknown type for field y in foo</span> <span class="Delimiter">:(scenario read_container_with_bracket_in_comment)</span> container foo [ - <span class="Normal">x</span>:number + x:number <span class="Comment"># ']' in comment</span> - <span class="Normal">y</span>:number + y:number ] <span class="traceContains">+parse: reading container foo</span> <span class="traceContains">+parse: element name: x</span> @@ -460,14 +459,14 @@ container foo [ check_container_field_types<span class="Delimiter">();</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> check_container_field_types<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>map<type_ordinal<span class="Delimiter">,</span> type_info>::iterator p = Type<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Type<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> type_info& info = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> +void check_container_field_types<span class="Delimiter">()</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>map<type_ordinal<span class="Delimiter">,</span> type_info>::iterator p = Type<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Type<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const type_info& info = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "checking " << p->first << '\n'; //? 1</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Type<span class="Delimiter">.</span>find<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">))</span> == Type<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Type<span class="Delimiter">.</span>find<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">))</span> == Type<span class="Delimiter">.</span>end<span class="Delimiter">())</span> raise << <span class="Constant">"unknown type for field "</span> << info<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> << <span class="Constant">" in "</span> << info<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -481,22 +480,22 @@ MERGE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"merge"</span>] = MERGE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> MERGE: <span class="Delimiter">{</span> +case MERGE: <span class="Delimiter">{</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<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>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="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario merge)</span> container foo [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:number + x:number + y:number ] recipe main [ - <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">3</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:literal + <span class="Constant">1</span>:foo<span class="Special"> <- </span>merge <span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">4</span> ] <span class="traceContains">+mem: storing 3 in location 1</span> <span class="traceContains">+mem: storing 4 in location 2</span> @@ -504,9 +503,9 @@ recipe main [ <span class="SalientComment">//:: helpers</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> skip_bracket<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> string message<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void skip_bracket<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> string message<span class="Delimiter">)</span> <span class="Delimiter">{</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">()</span> != <span class="Constant">'['</span><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> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> </pre> diff --git a/html/031address.cc.html b/html/031address.cc.html index 2f88d3e2..1709e1a1 100644 --- a/html/031address.cc.html +++ b/html/031address.cc.html @@ -13,16 +13,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -35,14 +34,14 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <body> <pre id='vimCodeElement'> <span class="Comment">//: Instructions can read from addresses pointing at other locations using the</span> -<span class="Comment">//: 'deref' property.</span> +<span class="Comment">//: 'lookup' property.</span> <span class="Delimiter">:(scenario copy_indirect)</span> recipe main [ - <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="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># This loads location 1 as an address and looks up *that* location.</span> - <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:number/deref + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:number/lookup ] <span class="traceContains">+mem: storing 34 in location 3</span> @@ -50,11 +49,11 @@ recipe main [ 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="Comment">//: 'lookup' property</span> <span class="Delimiter">:(scenario store_indirect)</span> recipe main [ - <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="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">1</span>:address:number/lookup<span class="Special"> <- </span>copy <span class="Constant">34</span> ] <span class="traceContains">+mem: storing 34 in location 2</span> @@ -63,26 +62,26 @@ x = canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> reagent canonize<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> x<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> x<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << "canonize\n"; //? 1</span> reagent r = x<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << x.to_string() << " => " << r.to_string() << '\n'; //? 1</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"deref"</span><span class="Delimiter">))</span> - r = deref<span class="Delimiter">(</span>r<span class="Delimiter">);</span> + while <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"lookup"</span><span class="Delimiter">))</span> + r = lookup_memory<span class="Delimiter">(</span>r<span class="Delimiter">);</span> <span class="Identifier">return</span> r<span class="Delimiter">;</span> <span class="Delimiter">}</span> -reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "deref: " << x.to_string() << "\n"; //? 2</span> - <span class="Normal">static</span> <span class="Normal">const</span> type_ordinal ADDRESS = Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">;</span> +reagent lookup_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cout << "lookup_memory: " << x.to_string() << "\n"; //? 2</span> + static const type_ordinal ADDRESS = Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">;</span> reagent result<span class="Delimiter">;</span> - <span class="Normal">if</span> <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="Delimiter">{</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": tried to /deref "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" but it isn't an address</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<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> != ADDRESS<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": tried to /lookup "</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">" but it isn't an address</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// compute value</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": tried to /deref 0</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": tried to /lookup 0</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> result<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>Memory[x<span class="Delimiter">.</span>value]<span class="Delimiter">);</span> @@ -91,15 +90,15 @@ reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)< <span class="Comment">// populate types</span> copy<span class="Delimiter">(</span>++x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>result<span class="Delimiter">.</span>types<span class="Delimiter">,</span> result<span class="Delimiter">.</span>types<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span> - <span class="Comment">// drop-one 'deref'</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> len = SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> - <span class="Normal">for</span> <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> - <span class="Normal">if</span> <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> + <span class="Comment">// drop-one 'lookup'</span> + long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> + long long int len = SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<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<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"lookup"</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> - <span class="Normal">for</span> <span class="Delimiter">(;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + ++i<span class="Delimiter">;</span> <span class="Comment">// skip first lookup</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<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> @@ -108,19 +107,19 @@ 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>: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="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0</span>:offset ] <span class="traceContains">+mem: storing 34 in location 4</span> -<span class="Delimiter">:(scenario include_nonderef_properties)</span> +<span class="Delimiter">:(scenario include_nonlookup_properties)</span> recipe main [ - <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="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/lookup/foo<span class="Delimiter">,</span> <span class="Constant">0</span>:offset ] <span class="traceContains">+mem: storing 34 in location 4</span> @@ -130,78 +129,64 @@ 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>: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="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>get-address <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0</span>:offset ] <span class="traceContains">+mem: storing 2 in location 4</span> <span class="Delimiter">:(after "reagent base = " following "case GET_ADDRESS:")</span> base = canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span> -<span class="SalientComment">//:: Helpers for debugging</span> +<span class="SalientComment">//:: abbreviation for '/lookup': a prefix '*'</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_ordinal[<span class="Constant">"$dump-trace"</span>] = _DUMP_TRACE<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _DUMP_TRACE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - DUMP<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> - <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> - DUMP<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="Delimiter">}</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> +<span class="Delimiter">:(scenario lookup_abbreviation)</span> +recipe main [ + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy *<span class="Constant">1</span>:address:number +] +<span class="traceContains">+mem: storing 34 in location 3</span> -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -_CLEAR_TRACE<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$clear-trace"</span>] = _CLEAR_TRACE<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _CLEAR_TRACE: <span class="Delimiter">{</span> - CLEAR_TRACE<span class="Delimiter">;</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Parsing reagent")</span> +<span class="Delimiter">{</span> + while <span class="Delimiter">(</span>!name<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && name<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'*'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + name<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> + properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> vector<string> ><span class="Delimiter">(</span><span class="Constant">"lookup"</span><span class="Delimiter">,</span> vector<string><span class="Delimiter">()));</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + raise << <span class="Constant">"illegal name "</span> << original_string << <span class="cSpecial">'\n'</span> << end<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_ordinal[<span class="Constant">"$dump-memory"</span>] = _DUMP_MEMORY<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _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> +<span class="SalientComment">//:: helpers for debugging</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> _DUMP<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"$dump"</span>] = _DUMP<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _DUMP: <span class="Delimiter">{</span> +case _DUMP: <span class="Delimiter">{</span> reagent after_canonize = 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> cerr << current_recipe_name<span class="Delimiter">()</span> << <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> << 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="Constant">" => "</span> << after_canonize<span class="Delimiter">.</span>value << <span class="Constant">" => "</span> << Memory[after_canonize<span class="Delimiter">.</span>value] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: grab an address, and then dump its value at intervals</span> +<span class="Comment">//: useful for tracking down memory corruption (writing to an out-of-bounds address)</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> foo = -<span class="Constant">1</span><span class="Delimiter">;</span> +long long int foo = -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> _FOO<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"$foo"</span>] = _FOO<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _FOO: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>foo != -<span class="Constant">1</span><span class="Delimiter">)</span> cerr << foo << <span class="Constant">": "</span> << Memory[foo] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - <span class="Normal">else</span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +case _FOO: <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> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>foo != -<span class="Constant">1</span><span class="Delimiter">)</span> cerr << foo << <span class="Constant">": "</span> << Memory[foo] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + else cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> foo = 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>value<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> diff --git a/html/032array.cc.html b/html/032array.cc.html index b210893c..6086d339 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -47,10 +46,10 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <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>: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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> <span class="Constant">5</span>:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:array:number/<span class="Special">raw</span> <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 3 in location 5</span> @@ -60,12 +59,12 @@ recipe main [ <span class="Delimiter">:(scenario copy_array_indirect)</span> recipe main [ - <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="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">6</span>:array:number<span class="Special"> <- </span>copy *<span class="Constant">5</span>:address:array:number ] <span class="traceContains">+mem: storing 3 in location 6</span> <span class="traceContains">+mem: storing 14 in location 7</span> @@ -73,11 +72,11 @@ 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">:(after "bool size_mismatch(const reagent& x, const vector<double>& data)")</span> -<span class="Normal">if</span> <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_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span class="Delimiter">:(before "End size_mismatch(x) Cases")</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_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End size_of(reagent) Cases")</span> - <span class="Normal">if</span> <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_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">)</span> == <span class="Constant">1</span><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_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>types<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": '"</span> << r<span class="Delimiter">.</span>original_string << <span class="Constant">"' is an array of what?</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -89,21 +88,21 @@ recipe main [ <span class="Delimiter">:(scenario index)</span> recipe main [ - <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="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span>:literal <span class="Comment"># unsafe</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>index <span class="Constant">1</span>:array:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span> <span class="Comment"># unsafe</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>: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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Constant">6</span>:number<span class="Special"> <- </span>index <span class="Constant">1</span>:array:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">5</span>:number <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 14 in location 6</span> @@ -113,26 +112,26 @@ INDEX<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"index"</span>] = INDEX<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> INDEX: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case INDEX: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'index' expects exactly 2 ingredients in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</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="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - <span class="Normal">if</span> <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_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name <span class="Delimiter">()</span> << <span class="Constant">": 'index' on a non-array "</span> << base<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> 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<<span class="Normal">double</span>> 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_ordinal> element_type = array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < <span class="Constant">0</span> || offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= Memory[base_address]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < <span class="Constant">0</span> || offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= Memory[base_address]<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": invalid index "</span> << offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> + long long int 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>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << Type[element_type<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>]<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> reagent tmp<span class="Delimiter">;</span> @@ -143,48 +142,48 @@ Recipe_ordinal[<span class="Constant">"index"</span>] = INDEX<span cla <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -vector<type_ordinal> array_element<span class="Delimiter">(</span><span class="Normal">const</span> vector<type_ordinal>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> +vector<type_ordinal> array_element<span class="Delimiter">(</span>const vector<type_ordinal>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> vector<type_ordinal><span class="Delimiter">(</span>++types<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> types<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario index_indirect)</span> recipe main [ - <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="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">6</span>:number<span class="Special"> <- </span>index *<span class="Constant">5</span>:address:array:number<span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 15 in location 6</span> <span class="Delimiter">:(scenario index_out_of_bounds)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># 3 points</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">14</span>:literal - <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - index <span class="Constant">8</span>:address:array:point/deref<span class="Delimiter">,</span> <span class="Constant">4</span>:literal <span class="Comment"># less than size of array in locations, but larger than its length in elements</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># 3 points</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span> + index *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> <span class="Constant">4</span> <span class="Comment"># less than size of array in locations, but larger than its length in elements</span> ] <span class="traceContains">+warn: main: invalid index 4</span> <span class="Delimiter">:(scenario index_out_of_bounds2)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># 3 points</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">14</span>:literal - <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - index <span class="Constant">8</span>:address:array:point/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> <span class="Comment"># 3 points</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span> + index *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> -<span class="Constant">1</span> ] <span class="traceContains">+warn: main: invalid index -1</span> @@ -192,11 +191,11 @@ recipe main [ <span class="Delimiter">:(scenario index_address)</span> recipe main [ - <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="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span>:literal <span class="Comment"># unsafe</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>index-address <span class="Constant">1</span>:array:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span> <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 2 in location 5</span> @@ -205,26 +204,26 @@ INDEX_ADDRESS<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"index-address"</span>] = INDEX_ADDRESS<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> INDEX_ADDRESS: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case INDEX_ADDRESS: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'index-address' expects exactly 2 ingredients in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</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="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - <span class="Normal">if</span> <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_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name <span class="Delimiter">()</span> << <span class="Constant">": 'index-address' on a non-array "</span> << base<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> 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<<span class="Normal">double</span>> 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_ordinal> element_type = array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < <span class="Constant">0</span> || offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= Memory[base_address]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < <span class="Constant">0</span> || offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= Memory[base_address]<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": invalid index "</span> << offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> + long long int 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> @@ -233,30 +232,30 @@ Recipe_ordinal[<span class="Constant">"index-address"</span>] = INDEX_ <span class="Delimiter">:(scenario index_address_out_of_bounds)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># 3 points</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">14</span>:literal - <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - index-address <span class="Constant">8</span>:address:array:point/deref<span class="Delimiter">,</span> <span class="Constant">4</span>:literal <span class="Comment"># less than size of array in locations, but larger than its length in elements</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># 3 points</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span> + index-address *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> <span class="Constant">4</span> <span class="Comment"># less than size of array in locations, but larger than its length in elements</span> ] <span class="traceContains">+warn: main: invalid index 4</span> <span class="Delimiter">:(scenario index_address_out_of_bounds2)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># 3 points</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">14</span>:literal - <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal - <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - index-address <span class="Constant">8</span>:address:array:point/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> <span class="Comment"># 3 points</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span> + index-address *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> -<span class="Constant">1</span> ] <span class="traceContains">+warn: main: invalid index -1</span> @@ -264,10 +263,10 @@ recipe main [ <span class="Delimiter">:(scenario array_length)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># length</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> <span class="Constant">5</span>:number<span class="Special"> <- </span>length <span class="Constant">1</span>:array:number/<span class="Special">raw</span> <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 3 in location 5</span> @@ -277,13 +276,13 @@ LENGTH<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"length"</span>] = LENGTH<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> LENGTH: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case LENGTH: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'length' expects exactly 2 ingredients in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</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> - <span class="Normal">if</span> <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_ordinal[<span class="Constant">"array"</span>]<span class="Delimiter">)</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_ordinal[<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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/033exclusive_container.cc.html b/html/033exclusive_container.cc.html index 3ab9bc99..2aaf30fb 100644 --- a/html/033exclusive_container.cc.html +++ b/html/033exclusive_container.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -62,23 +61,23 @@ 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>: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-<span class="Normal">or</span>-point<span class="Special"> <- </span>copy <span class="Constant">1</span>:number-<span class="Normal">or</span>-point/<span class="Special">raw</span> <span class="Comment"># unsafe</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Comment"># 'point' variant</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">4</span>:number-or-point<span class="Special"> <- </span>copy <span class="Constant">1</span>:number-or-point/<span class="Special">raw</span> <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 1 in location 4</span> <span class="traceContains">+mem: storing 34 in location 5</span> <span class="traceContains">+mem: storing 35 in location 6</span> <span class="Delimiter">:(before "End size_of(types) Cases")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == exclusive_container<span class="Delimiter">)</span> <span class="Delimiter">{</span> +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="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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="Normal">if</span> <span class="Delimiter">(</span>tmp > result<span class="Delimiter">)</span> result = tmp<span class="Delimiter">;</span> + long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < t<span class="Delimiter">.</span>size<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int tmp = size_of<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> + if <span class="Delimiter">(</span>tmp > result<span class="Delimiter">)</span> result = tmp<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// ...+1 for its tag.</span> <span class="Identifier">return</span> result+<span class="Constant">1</span><span class="Delimiter">;</span> @@ -96,19 +95,19 @@ Type_ordinal[<span class="Constant">"variant"</span>] = <span class="C <span class="Delimiter">:(scenario maybe_convert)</span> recipe main [ - <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-<span class="Normal">or</span>-point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:variant <span class="Comment"># unsafe</span> + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">1</span>:variant <span class="Comment"># unsafe</span> ] <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>: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-<span class="Normal">or</span>-point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span>:variant <span class="Comment"># unsafe</span> + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span>:variant <span class="Comment"># unsafe</span> ] <span class="traceContains">+mem: storing 0 in location 20</span> @@ -117,28 +116,28 @@ MAYBE_CONVERT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"maybe-convert"</span>] = MAYBE_CONVERT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> MAYBE_CONVERT: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case MAYBE_CONVERT: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'maybe-convert' expects exactly 2 ingredients in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</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="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + long long int base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> type_ordinal 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind != exclusive_container<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind != exclusive_container<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name <span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'maybe-convert' should be an exclusive-container, but got "</span> << base<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_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> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!is_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> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": second ingredient of 'maybe-convert' should have type 'variant', but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>tag == <span class="Normal">static_cast</span><<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>><span class="Delimiter">(</span>Memory[base_address]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + long long int tag = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>value<span class="Delimiter">;</span> + long long int result<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>tag == static_cast<long long int><span class="Delimiter">(</span>Memory[base_address]<span class="Delimiter">))</span> <span class="Delimiter">{</span> result = base_address+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> result = <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> @@ -150,8 +149,8 @@ Recipe_ordinal[<span class="Constant">"maybe-convert"</span>] = MAYBE_ <span class="Delimiter">:(scenario exclusive_container)</span> exclusive-container foo [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:number + x:number + y:number ] <span class="traceContains">+parse: reading exclusive-container foo</span> <span class="traceContains">+parse: element name: x</span> @@ -160,21 +159,21 @@ exclusive-container foo [ <span class="traceContains">+parse: type: 1</span> <span class="Delimiter">:(before "End Command Handlers")</span> -<span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>command == <span class="Constant">"exclusive-container"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +else if <span class="Delimiter">(</span>command == <span class="Constant">"exclusive-container"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> insert_container<span class="Delimiter">(</span>command<span class="Delimiter">,</span> exclusive_container<span class="Delimiter">,</span> in<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="SalientComment">//:: To construct exclusive containers out of variant types, use 'merge'.</span> <span class="Delimiter">:(scenario lift_to_exclusive_container)</span> exclusive-container foo [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:number + x:number + y:number ] recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">2</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>:literal/x<span class="Delimiter">,</span> <span class="Constant">1</span>:number - <span class="Constant">4</span>:foo<span class="Special"> <- </span>merge <span class="Constant">1</span>:literal/x<span class="Delimiter">,</span> <span class="Constant">1</span>:number + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:foo<span class="Special"> <- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">1</span>:number + <span class="Constant">4</span>:foo<span class="Special"> <- </span>merge <span class="Constant">1</span>/x<span class="Delimiter">,</span> <span class="Constant">1</span>:number ] <span class="traceContains">+mem: storing 0 in location 2</span> <span class="traceContains">+mem: storing 34 in location 3</span> diff --git a/html/034call.cc.html b/html/034call.cc.html index 9b978a5d..5e9d93b0 100644 --- a/html/034call.cc.html +++ b/html/034call.cc.html @@ -13,17 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.PreProc { color: #c000c0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.PreProc { color: #c000c0; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -42,37 +41,37 @@ recipe main [ f ] recipe f [ - <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="Constant">3</span>:number<span class="Special"> <- </span>add <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">2</span> ] <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>: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 + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] recipe f [ - <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="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+run: f</span> <span class="Comment"># running f</span> -<span class="traceContains">+run: 4:number <- copy 0:literal</span> -<span class="traceContains">+run: 5:number <- copy 0:literal</span> +<span class="traceContains">+run: 4:number <- copy 0</span> +<span class="traceContains">+run: 5:number <- copy 0</span> <span class="Comment"># back out to main</span> -<span class="traceContains">+run: 1:number <- copy 0:literal</span> -<span class="traceContains">+run: 2:number <- copy 0:literal</span> -<span class="traceContains">+run: 3:number <- copy 0:literal</span> +<span class="traceContains">+run: 1:number <- copy 0</span> +<span class="traceContains">+run: 2:number <- copy 0</span> +<span class="traceContains">+run: 3:number <- copy 0</span> <span class="Delimiter">:(before "struct routine {")</span> <span class="Comment">// Everytime a recipe runs another, we interrupt it and start running the new</span> <span class="Comment">// recipe. When that finishes, we continue this one where we left off.</span> <span class="Comment">// This requires maintaining a 'stack' of interrupted recipes or 'calls'.</span> -<span class="Normal">struct</span> call <span class="Delimiter">{</span> +struct call <span class="Delimiter">{</span> recipe_ordinal running_recipe<span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> running_step_index<span class="Delimiter">;</span> + long long int running_step_index<span class="Delimiter">;</span> <span class="Comment">// End call Fields</span> call<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> running_recipe = r<span class="Delimiter">;</span> @@ -80,15 +79,15 @@ recipe f [ <span class="Comment">// End call Constructor</span> <span class="Delimiter">}</span> <span class="Delimiter">};</span> -<span class="Normal">typedef</span> list<call> call_stack<span class="Delimiter">;</span> +typedef list<call> call_stack<span class="Delimiter">;</span> <span class="Delimiter">:(replace{} "struct routine")</span> -<span class="Normal">struct</span> routine <span class="Delimiter">{</span> +struct routine <span class="Delimiter">{</span> call_stack calls<span class="Delimiter">;</span> <span class="Comment">// End routine Fields</span> routine<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">);</span> - <span class="Normal">bool</span> completed<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span> - <span class="Normal">const</span> vector<instruction>& steps<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span> + bool completed<span class="Delimiter">()</span> const<span class="Delimiter">;</span> + const vector<instruction>& steps<span class="Delimiter">()</span> const<span class="Delimiter">;</span> <span class="Delimiter">};</span> <span class="Delimiter">:(code)</span> routine::routine<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -99,30 +98,30 @@ routine::routine<span class="Delimiter">(</span>recipe_ordinal r<span class="Del <span class="SalientComment">//:: now update routine's helpers</span> <span class="Delimiter">:(replace{} "inline long long int& current_step_index()")</span> -<span class="Normal">inline</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>& current_step_index<span class="Delimiter">()</span> <span class="Delimiter">{</span> +inline long long int& current_step_index<span class="Delimiter">()</span> <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> -<span class="Normal">inline</span> <span class="Normal">const</span> string& current_recipe_name<span class="Delimiter">()</span> <span class="Delimiter">{</span> +inline const string& current_recipe_name<span class="Delimiter">()</span> <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> -<span class="Normal">inline</span> <span class="Normal">const</span> instruction& current_instruction<span class="Delimiter">()</span> <span class="Delimiter">{</span> +inline const instruction& current_instruction<span class="Delimiter">()</span> <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> -<span class="Normal">default</span>: <span class="Delimiter">{</span> +default: <span class="Delimiter">{</span> <span class="Comment">// not a primitive; try to look up the book of recipes</span> - <span class="Normal">if</span> <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> + 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>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> Current_routine<span class="Delimiter">-></span>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="Normal">call_housekeeping</span>: + call_housekeeping: ++Callstack_depth<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>Callstack_depth < <span class="Constant">9000</span><span class="Delimiter">);</span> <span class="Comment">// 9998-101 plus cushion</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// not done with caller; don't increment current_step_index()</span> @@ -131,11 +130,11 @@ routine::routine<span class="Delimiter">(</span>recipe_ordinal r<span class="Del <span class="SalientComment">//:: finally, we need to fix the termination conditions for the run loop</span> <span class="Delimiter">:(replace{} "inline bool routine::completed() const")</span> -<span class="Normal">inline</span> <span class="Normal">bool</span> routine::completed<span class="Delimiter">()</span> <span class="Normal">const</span> <span class="Delimiter">{</span> +inline bool routine::completed<span class="Delimiter">()</span> const <span class="Delimiter">{</span> <span class="Identifier">return</span> calls<span class="Delimiter">.</span>empty<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">inline</span> <span class="Normal">const</span> vector<instruction>& routine::steps<span class="Delimiter">()</span> <span class="Normal">const</span> <span class="Delimiter">{</span> +inline const vector<instruction>& routine::steps<span class="Delimiter">()</span> const <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> @@ -143,12 +142,12 @@ routine::routine<span class="Delimiter">(</span>recipe_ordinal r<span class="Del <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> -<span class="Normal">while</span> <span class="Delimiter">(</span>current_step_index<span class="Delimiter">()</span> >= SIZE<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>steps<span class="Delimiter">()))</span> <span class="Delimiter">{</span> +while <span class="Delimiter">(</span>current_step_index<span class="Delimiter">()</span> >= SIZE<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>steps<span class="Delimiter">()))</span> <span class="Delimiter">{</span> <span class="Comment">// Falling Through End Of Recipe</span> --Callstack_depth<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "reply " << SIZE(Current_routine->calls) << '\n'; //? 2</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>pop_front<span class="Delimiter">();</span> - <span class="Normal">if</span> <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> + 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">// Complete Call Fallthrough</span> <span class="Comment">// todo: no products returned warning</span> ++current_step_index<span class="Delimiter">();</span> @@ -156,7 +155,7 @@ routine::routine<span class="Delimiter">(</span>recipe_ordinal r<span class="Del <span class="Delimiter">:(before "End Includes")</span> <span class="PreProc">#include </span><span class="Constant"><stack></span> -<span class="Normal">using</span> std::stack<span class="Delimiter">;</span> +using std::stack<span class="Delimiter">;</span> </pre> </body> </html> diff --git a/html/035call_ingredient.cc.html b/html/035call_ingredient.cc.html index 357f1178..14c718a6 100644 --- a/html/035call_ingredient.cc.html +++ b/html/035call_ingredient.cc.html @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -37,11 +36,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario next_ingredient)</span> recipe main [ - f <span class="Constant">2</span>:literal + f <span class="Constant">2</span> ] recipe f [ <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="Constant">13</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">12</span>:number ] <span class="traceContains">+mem: storing 3 in location 13</span> @@ -55,13 +54,13 @@ recipe f [ <span class="traceContains">+mem: storing 0 in location 12</span> <span class="Delimiter">:(before "End call Fields")</span> -vector<vector<<span class="Normal">double</span>> > ingredient_atoms<span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> next_ingredient_to_process<span class="Delimiter">;</span> +vector<vector<double> > ingredient_atoms<span class="Delimiter">;</span> +long long int next_ingredient_to_process<span class="Delimiter">;</span> <span class="Delimiter">:(before "End call Constructor")</span> next_ingredient_to_process = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(after "call_housekeeping:")</span> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> Current_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> <span class="Delimiter">}</span> @@ -70,20 +69,20 @@ NEXT_INGREDIENT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"next-ingredient"</span>] = NEXT_INGREDIENT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> NEXT_INGREDIENT: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +case NEXT_INGREDIENT: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'next-ingredient' didn't expect any ingredients in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <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="Normal">if</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 < SIZE<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> <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 < SIZE<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> <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>SIZE<span class="Delimiter">(</span>products<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> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <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> @@ -93,7 +92,7 @@ Recipe_ordinal[<span class="Constant">"next-ingredient"</span>] = NEXT <span class="Delimiter">:(scenario rewind_ingredients)</span> recipe main [ - f <span class="Constant">2</span>:literal + f <span class="Constant">2</span> ] recipe f [ <span class="Constant">12</span>:number<span class="Special"> <- </span>next-ingredient <span class="Comment"># consume ingredient</span> @@ -111,17 +110,17 @@ REWIND_INGREDIENTS<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"rewind-ingredients"</span>] = REWIND_INGREDIENTS<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> REWIND_INGREDIENTS: <span class="Delimiter">{</span> +case REWIND_INGREDIENTS: <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> <span class="Delimiter">:(scenario ingredient)</span> recipe main [ - f <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + f <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">2</span> ] recipe f [ - <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">12</span>:number<span class="Special"> <- </span>ingredient <span class="Constant">1</span> <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> @@ -132,17 +131,17 @@ INGREDIENT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"ingredient"</span>] = INGREDIENT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> INGREDIENT: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case INGREDIENT: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'ingredient' expects exactly one ingredient, but got '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_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> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!is_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> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'ingredient' expects a literal ingredient, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>scalar<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="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">static_cast</span><<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> < SIZE<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> <span class="Delimiter">{</span> + if <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">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> < SIZE<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> <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> @@ -150,8 +149,8 @@ Recipe_ordinal[<span class="Constant">"ingredient"</span>] = INGREDIEN 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> - <span class="Normal">else</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> > <span class="Constant">1</span><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> diff --git a/html/036call_reply.cc.html b/html/036call_reply.cc.html index e5d028cc..b293886c 100644 --- a/html/036call_reply.cc.html +++ b/html/036call_reply.cc.html @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -36,11 +35,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario reply)</span> recipe main [ - <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 + <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> ] recipe f [ <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="Constant">13</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span><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">+mem: storing 34 in location 1</span> @@ -51,49 +50,49 @@ REPLY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"reply"</span>] = REPLY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> REPLY: <span class="Delimiter">{</span> +case REPLY: <span class="Delimiter">{</span> <span class="Comment">// Starting Reply</span> - <span class="Normal">const</span> instruction& reply_inst = current_instruction<span class="Delimiter">();</span> <span class="Comment">// save pointer into recipe before pop</span> - <span class="Normal">const</span> string& callee = current_recipe_name<span class="Delimiter">();</span> + const instruction& reply_inst = current_instruction<span class="Delimiter">();</span> <span class="Comment">// save pointer into recipe before pop</span> + const string& callee = current_recipe_name<span class="Delimiter">();</span> --Callstack_depth<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> - <span class="Normal">if</span> <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> - <span class="Normal">const</span> instruction& caller_instruction = current_instruction<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">goto</span> stop_running_current_routine<span class="Delimiter">;</span> + const instruction& caller_instruction = current_instruction<span class="Delimiter">();</span> <span class="Comment">// make reply products 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">)</span> > SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">))</span> raise << <span class="Constant">"too few values replied from "</span> << callee << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<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> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <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> + 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>tmp<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>tmp<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'same-as-ingredient' metadata should take exactly one value in "</span> << reply_inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">goto</span> finish_reply<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> ingredient_index = to_integer<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredient_index >= SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> + long long int ingredient_index = to_integer<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>ingredient_index >= SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'same-as-ingredient' metadata overflows ingredients in: "</span> << caller_instruction<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_dummy<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> && caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>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> + if <span class="Delimiter">(</span>!is_dummy<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> && caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>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 << current_recipe_name<span class="Delimiter">()</span> << <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">" from call to "</span> << callee << <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> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Comment">// End Reply</span> - <span class="Normal">finish_reply</span>: + finish_reply: <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// continue to process rest of *caller* instruction</span> <span class="Delimiter">}</span> <span class="Comment">//: Products can include containers and exclusive containers, addresses and arrays.</span> <span class="Delimiter">:(scenario reply_container)</span> recipe main [ - <span class="Constant">3</span>:point<span class="Special"> <- </span>f <span class="Constant">2</span>:literal + <span class="Constant">3</span>:point<span class="Special"> <- </span>f <span class="Constant">2</span> ] recipe f [ <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 + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> reply <span class="Constant">12</span>:point/<span class="Special">raw</span> <span class="Comment"># unsafe</span> ] <span class="traceContains">+run: result 0 is [2, 35]</span> @@ -108,7 +107,7 @@ recipe f [ <span class="Delimiter">:(scenario reply_same_as_ingredient)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:number<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> <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 [ @@ -120,7 +119,7 @@ recipe test1 [ <span class="Delimiter">:(scenario reply_same_as_ingredient_dummy)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:number<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> _<span class="Special"> <- </span>test1 <span class="Constant">1</span>:number <span class="Comment"># call with different ingredient and product</span> ] recipe test1 [ @@ -130,16 +129,16 @@ recipe test1 [ $warn: <span class="Constant">0</span> <span class="Delimiter">:(code)</span> -string to_string<span class="Delimiter">(</span><span class="Normal">const</span> vector<<span class="Normal">double</span>>& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> +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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>in<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>in<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>in<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>in<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<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> @@ -153,8 +152,8 @@ recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>test1 ] recipe test1 [ - reply-<span class="Normal">if</span> <span class="Constant">0</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal - reply <span class="Constant">35</span>:literal + reply-if <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">34</span> + reply <span class="Constant">35</span> ] <span class="traceContains">+mem: storing 35 in location 1</span> @@ -163,8 +162,8 @@ recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>test1 ] recipe test1 [ - reply-<span class="Normal">if</span> <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal - reply <span class="Constant">35</span>:literal + reply-if <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">34</span> + reply <span class="Constant">35</span> ] <span class="traceContains">+mem: storing 34 in location 1</span> @@ -174,8 +173,8 @@ recipe test1 [ <span class="Comment">// jump-unless a, 1:offset</span> <span class="Comment">// reply b, c, ...</span> <span class="Comment">// ```</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"reply-if"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</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> + if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> curr<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">;</span> curr<span class="Delimiter">.</span>name = <span class="Constant">"jump-unless"</span><span class="Delimiter">;</span> vector<reagent> results<span class="Delimiter">;</span> @@ -188,7 +187,7 @@ recipe test1 [ curr<span class="Delimiter">.</span>name = <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> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> raise << <span class="Constant">"'reply-if' never yields any products</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -197,8 +196,8 @@ recipe test1 [ <span class="Comment">// jump-if a, 1:offset</span> <span class="Comment">// reply b, c, ...</span> <span class="Comment">// ```</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"reply-unless"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"reply-unless"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> curr<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"jump-if"</span>]<span class="Delimiter">;</span> curr<span class="Delimiter">.</span>name = <span class="Constant">"jump-if"</span><span class="Delimiter">;</span> vector<reagent> results<span class="Delimiter">;</span> @@ -211,7 +210,7 @@ recipe test1 [ curr<span class="Delimiter">.</span>name = <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> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> raise << <span class="Constant">"'reply-unless' never yields any products</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> diff --git a/html/037recipe.cc.html b/html/037recipe.cc.html index ce2f2798..e0d7a2c4 100644 --- a/html/037recipe.cc.html +++ b/html/037recipe.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } -.CommentedCode { color: #6c6c6c; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -39,7 +38,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario call_literal_recipe)</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>call f:recipe<span class="Delimiter">,</span> <span class="Constant">34</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>call f:recipe<span class="Delimiter">,</span> <span class="Constant">34</span> ] recipe f [ <span class="Constant">2</span>:number<span class="Special"> <- </span>next-ingredient @@ -50,7 +49,7 @@ recipe f [ <span class="Delimiter">:(scenario call_variable)</span> recipe main [ <span class="Constant">1</span>:recipe-ordinal<span class="Special"> <- </span>copy f:recipe - <span class="Constant">2</span>:number<span class="Special"> <- </span>call <span class="Constant">1</span>:recipe-ordinal<span class="Delimiter">,</span> <span class="Constant">34</span>:literal + <span class="Constant">2</span>:number<span class="Special"> <- </span>call <span class="Constant">1</span>:recipe-ordinal<span class="Delimiter">,</span> <span class="Constant">34</span> ] recipe f [ <span class="Constant">3</span>:number<span class="Special"> <- </span>next-ingredient @@ -67,7 +66,7 @@ type_ordinal recipe_ordinal = Type_ordinal[<span class="Constant">"recipe-o Type[recipe_ordinal]<span class="Delimiter">.</span>name = <span class="Constant">"recipe-ordinal"</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Reagent-parsing Exceptions")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"recipe"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"recipe"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> r<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>Recipe_ordinal[r<span class="Delimiter">.</span>name]<span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -77,13 +76,13 @@ CALL<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"call"</span>] = CALL<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> CALL: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +case CALL: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'call' requires at least one ingredient (the recipe to call)</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// Begin Call</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'call' should be a recipe, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/038scheduler.cc.html b/html/038scheduler.cc.html index 56f3c3c4..667ad6e4 100644 --- a/html/038scheduler.cc.html +++ b/html/038scheduler.cc.html @@ -13,17 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.traceAbsent { color: #c00000; } -.SalientComment { color: #00ffff; } -.Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.Constant { color: #00a0a0; } +.SalientComment { color: #00ffff; } +.traceAbsent { color: #c00000; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -43,11 +42,11 @@ recipe f1 [ start-running f2:recipe <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 + jump-unless <span class="Constant">1</span>:number<span class="Delimiter">,</span> -<span class="Constant">1</span> <span class="Delimiter">}</span> ] recipe f2 [ - <span class="Constant">1</span>:number<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> ] <span class="traceContains">+schedule: f1</span> <span class="traceContains">+schedule: f2</span> @@ -55,45 +54,45 @@ recipe f2 [ <span class="Comment">//: first, add a deadline to run(routine)</span> <span class="Comment">//: these changes are ugly and brittle; just close your nose and get through the next few lines</span> <span class="Delimiter">:(replace "void run_current_routine()")</span> -<span class="Normal">void</span> run_current_routine<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> time_slice<span class="Delimiter">)</span> +void run_current_routine<span class="Delimiter">(</span>long long int time_slice<span class="Delimiter">)</span> <span class="Delimiter">:(replace "while (!Current_routine->completed())" following "void run_current_routine(long long int time_slice)")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> ninstrs = <span class="Constant">0</span><span class="Delimiter">;</span> -<span class="Normal">while</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>state == RUNNING && ninstrs < time_slice<span class="Delimiter">)</span> +long long int ninstrs = <span class="Constant">0</span><span class="Delimiter">;</span> +while <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>state == RUNNING && ninstrs < time_slice<span class="Delimiter">)</span> <span class="Delimiter">:(after "Running One Instruction")</span> ninstrs++<span class="Delimiter">;</span> <span class="Comment">//: now the rest of the scheduler is clean</span> <span class="Delimiter">:(before "struct routine")</span> -<span class="Normal">enum</span> routine_state <span class="Delimiter">{</span> +enum routine_state <span class="Delimiter">{</span> RUNNING<span class="Delimiter">,</span> COMPLETED<span class="Delimiter">,</span> <span class="Comment">// End routine States</span> <span class="Delimiter">};</span> <span class="Delimiter">:(before "End routine Fields")</span> -<span class="Normal">enum</span> routine_state state<span class="Delimiter">;</span> +enum routine_state state<span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Constructor")</span> state = RUNNING<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Globals")</span> vector<routine*> Routines<span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Current_routine_index = <span class="Constant">0</span><span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Scheduling_interval = <span class="Constant">500</span><span class="Delimiter">;</span> +long long int Current_routine_index = <span class="Constant">0</span><span class="Delimiter">;</span> +long long int Scheduling_interval = <span class="Constant">500</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Scheduling_interval = <span class="Constant">500</span><span class="Delimiter">;</span> Routines<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">:(replace{} "void run(recipe_ordinal r)")</span> -<span class="Normal">void</span> run<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - Routines<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Normal">new</span> routine<span class="Delimiter">(</span>r<span class="Delimiter">));</span> +void run<span class="Delimiter">(</span>recipe_ordinal 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="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!all_routines_done<span class="Delimiter">())</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> 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_routine_label<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> run_current_routine<span class="Delimiter">(</span>Scheduling_interval<span class="Delimiter">);</span> <span class="Comment">// Scheduler State Transitions</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>completed<span class="Delimiter">())</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> @@ -103,9 +102,9 @@ Routines<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">bool</span> all_routines_done<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</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="Delimiter">{</span> +bool all_routines_done<span class="Delimiter">()</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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 == 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> @@ -113,11 +112,11 @@ Routines<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Comment">// skip Current_routine_index past non-RUNNING routines</span> -<span class="Normal">void</span> skip_to_next_routine<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void skip_to_next_routine<span class="Delimiter">()</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>!Routines<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> assert<span class="Delimiter">(</span>Current_routine_index < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">));</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Delimiter">(</span>Current_routine_index+<span class="Constant">1</span><span class="Delimiter">)</span>%SIZE<span class="Delimiter">(</span>Routines<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>%SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Normal">if</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="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Delimiter">(</span>Current_routine_index+<span class="Constant">1</span><span class="Delimiter">)</span>%SIZE<span class="Delimiter">(</span>Routines<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>%SIZE<span class="Delimiter">(</span>Routines<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> Current_routine_index = 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> @@ -128,16 +127,16 @@ Routines<span class="Delimiter">.</span>clear<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> - <span class="Normal">for</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>p != calls<span class="Delimiter">.</span>begin<span class="Delimiter">())</span> result << <span class="Constant">'/'</span><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> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> - <span class="Normal">delete</span> Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++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> @@ -145,9 +144,9 @@ Routines<span class="Delimiter">.</span>clear<span class="Delimiter">();</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> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> id<span class="Delimiter">;</span> +long long int id<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Next_routine_id = <span class="Constant">1</span><span class="Delimiter">;</span> +long long int Next_routine_id = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Next_routine_id = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Constructor")</span> @@ -157,7 +156,7 @@ 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> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> parent_index<span class="Delimiter">;</span> <span class="Comment">// only < 0 if there's no parent_index</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> @@ -166,11 +165,11 @@ START_RUNNING<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"start-running"</span>] = START_RUNNING<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> START_RUNNING: <span class="Delimiter">{</span> - routine* new_routine = <span class="Normal">new</span> routine<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> +case START_RUNNING: <span class="Delimiter">{</span> + routine* new_routine = new routine<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> new_routine<span class="Delimiter">-></span>parent_index = Current_routine_index<span class="Delimiter">;</span> <span class="Comment">// populate ingredients</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> 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> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> @@ -181,47 +180,47 @@ Recipe_ordinal[<span class="Constant">"start-running"</span>] = START_ <span class="Delimiter">:(scenario scheduler_runs_single_routine)</span> <span class="Special">% Scheduling_interval = 1;</span> recipe f1 [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+schedule: f1</span> -<span class="traceContains">+run: 1:number <- copy 0:literal</span> +<span class="traceContains">+run: 1:number <- copy 0</span> <span class="traceContains">+schedule: f1</span> -<span class="traceContains">+run: 2:number <- copy 0:literal</span> +<span class="traceContains">+run: 2:number <- copy 0</span> <span class="Delimiter">:(scenario scheduler_interleaves_routines)</span> <span class="Special">% Scheduling_interval = 1;</span> recipe f1 [ start-running f2:recipe - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] recipe f2 [ - <span class="Constant">3</span>:number<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">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+schedule: f1</span> <span class="traceContains">+run: start-running f2:recipe</span> <span class="traceContains">+schedule: f2</span> -<span class="traceContains">+run: 3:number <- copy 0:literal</span> +<span class="traceContains">+run: 3:number <- copy 0</span> <span class="traceContains">+schedule: f1</span> -<span class="traceContains">+run: 1:number <- copy 0:literal</span> +<span class="traceContains">+run: 1:number <- copy 0</span> <span class="traceContains">+schedule: f2</span> -<span class="traceContains">+run: 4:number <- copy 0:literal</span> +<span class="traceContains">+run: 4:number <- copy 0</span> <span class="traceContains">+schedule: f1</span> -<span class="traceContains">+run: 2:number <- copy 0:literal</span> +<span class="traceContains">+run: 2:number <- copy 0</span> <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 + start-running f2:recipe<span class="Delimiter">,</span> <span class="Constant">3</span> <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 + jump-unless <span class="Constant">1</span>:number<span class="Delimiter">,</span> -<span class="Constant">1</span> <span class="Delimiter">}</span> ] recipe f2 [ <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="Constant">2</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 4 in location 2</span> @@ -230,22 +229,22 @@ recipe f1 [ <span class="Constant">1</span>:number<span class="Special"> <- </span>start-running f2:recipe ] recipe f2 [ - <span class="Constant">12</span>:number<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> ] <span class="traceContains">+mem: storing 2 in location 1</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="Delimiter">:(scenario scheduler_skips_completed_routines)</span> -<span class="Special">% recipe_ordinal f1 = load("recipe f1 [\n1:number <- copy 0:literal\n]").front();</span> -<span class="Special">% recipe_ordinal f2 = load("recipe f2 [\n2:number <- copy 0:literal\n]").front();</span> +<span class="Special">% recipe_ordinal f1 = load("recipe f1 [\n1:number <- copy 0\n]").front();</span> +<span class="Special">% recipe_ordinal f2 = load("recipe f2 [\n2:number <- copy 0\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>: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> ] <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> @@ -259,8 +258,8 @@ 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>: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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+schedule: f1</span> <span class="traceAbsent">-run: idle</span> @@ -273,23 +272,23 @@ recipe main [ <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="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceAbsent">-schedule: f1</span> <span class="Delimiter">:(before "End Scheduler Cleanup")</span> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</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">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <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="Normal">if</span> <span class="Delimiter">(</span>has_completed_parent<span class="Delimiter">(</span>i<span class="Delimiter">))</span> <span class="Delimiter">{</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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> + if <span class="Delimiter">(</span>has_completed_parent<span class="Delimiter">(</span>i<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="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">bool</span> has_completed_parent<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> routine_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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="Normal">if</span> <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> +bool has_completed_parent<span class="Delimiter">(</span>long long int routine_index<span class="Delimiter">)</span> <span class="Delimiter">{</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> + 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> @@ -301,12 +300,12 @@ recipe f1 [ <span class="Special">% Scheduling_interval = 2;</span> recipe f1 [ <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="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <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>:number/state<span class="Special"> <- </span>routine-state <span class="Constant">1</span>:number/child-id ] recipe f2 [ - <span class="Constant">12</span>:number<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> <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> @@ -317,19 +316,19 @@ ROUTINE_STATE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"routine-state"</span>] = ROUTINE_STATE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> ROUTINE_STATE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case ROUTINE_STATE: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'routine-state' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'routine-state' should be a routine id generated by 'start-running', but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = -<span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + long long int 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>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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> 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> @@ -346,18 +345,18 @@ RESTART<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"restart"</span>] = RESTART<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> RESTART: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case RESTART: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'restart' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'restart' should be a routine id generated by 'start-running', but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + long long int 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>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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> @@ -370,18 +369,18 @@ STOP<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"stop"</span>] = STOP<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> STOP: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case STOP: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'stop' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'stop' should be a routine id generated by 'start-running', but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + long long int 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>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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> @@ -394,8 +393,8 @@ _DUMP_ROUTINES<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"$dump-routines"</span>] = _DUMP_ROUTINES<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _DUMP_ROUTINES: <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +case _DUMP_ROUTINES: <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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> diff --git a/html/039wait.cc.html b/html/039wait.cc.html index 1e56cf9d..311f37ca 100644 --- a/html/039wait.cc.html +++ b/html/039wait.cc.html @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -39,14 +38,14 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario wait_for_location)</span> recipe f1 [ - <span class="Constant">1</span>:number<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> start-running f2:recipe - wait-<span class="Normal">for</span>-location <span class="Constant">1</span>:number + 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>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] recipe f2 [ - <span class="Constant">1</span>:number<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> ] <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,8 +56,8 @@ recipe f2 [ WAITING<span class="Delimiter">,</span> <span class="Delimiter">:(before "End routine Fields")</span> <span class="Comment">// only if state == WAITING</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> waiting_on_location<span class="Delimiter">;</span> -<span class="Normal">int</span> old_value_of_waiting_location<span class="Delimiter">;</span> +long long int waiting_on_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_waiting_location = <span class="Constant">0</span><span class="Delimiter">;</span> @@ -69,7 +68,7 @@ WAIT_FOR_LOCATION<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"wait-for-location"</span>] = WAIT_FOR_LOCATION<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> WAIT_FOR_LOCATION: <span class="Delimiter">{</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="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> @@ -81,9 +80,9 @@ Recipe_ordinal[<span class="Constant">"wait-for-location"</span>] = WA <span class="Comment">//: scheduler tweak to get routines out of that state</span> <span class="Delimiter">:(before "End Scheduler State Transitions")</span> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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="Normal">if</span> <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_location && +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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 != 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_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> << end<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> @@ -95,14 +94,14 @@ Recipe_ordinal[<span class="Constant">"wait-for-location"</span>] = WA <span class="Delimiter">:(scenario wait_for_routine)</span> recipe f1 [ - <span class="Constant">1</span>:number<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> <span class="Constant">12</span>:number/routine<span class="Special"> <- </span>start-running f2:recipe - wait-<span class="Normal">for</span>-routine <span class="Constant">12</span>:number/routine + 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>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] recipe f2 [ - <span class="Constant">1</span>:number<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> ] <span class="traceContains">+schedule: f1</span> <span class="traceContains">+run: waiting for routine 2</span> @@ -114,7 +113,7 @@ recipe f2 [ <span class="Delimiter">:(before "End routine Fields")</span> <span class="Comment">// only if state == WAITING</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> waiting_on_routine<span class="Delimiter">;</span> +long long int waiting_on_routine<span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Constructor")</span> waiting_on_routine = <span class="Constant">0</span><span class="Delimiter">;</span> @@ -123,16 +122,16 @@ WAIT_FOR_ROUTINE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"wait-for-routine"</span>] = WAIT_FOR_ROUTINE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> WAIT_FOR_ROUTINE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case WAIT_FOR_ROUTINE: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'wait-for-routine' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'wait-for-routine' should be a routine id generated by 'start-running', but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == Current_routine<span class="Delimiter">-></span>id<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == Current_routine<span class="Delimiter">-></span>id<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": routine can't wait for itself! "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -146,13 +145,13 @@ Recipe_ordinal[<span class="Constant">"wait-for-routine"</span>] = WAI <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> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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="Normal">if</span> <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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> id = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_routine<span class="Delimiter">;</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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 != 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> + long long int 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> <span class="Comment">// routine can't wait on itself</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++j<span class="Delimiter">)</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 << end<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> @@ -165,9 +164,9 @@ SWITCH<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"switch"</span>] = SWITCH<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> SWITCH: <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> id = some_other_running_routine<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>id<span class="Delimiter">)</span> <span class="Delimiter">{</span> +case SWITCH: <span class="Delimiter">{</span> + long long int 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> 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> @@ -176,12 +175,12 @@ Recipe_ordinal[<span class="Constant">"switch"</span>] = SWITCH<span c <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> some_other_running_routine<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>i == Current_routine_index<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +long long int some_other_running_routine<span class="Delimiter">()</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Routines<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> - <span class="Normal">if</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> + 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> diff --git a/html/040brace.cc.html b/html/040brace.cc.html index a4313315..7d468a9d 100644 --- a/html/040brace.cc.html +++ b/html/040brace.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -59,7 +58,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } recipe main [ <span class="Delimiter">{</span> <span class="Identifier">break</span> - <span class="Constant">1</span>:number<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> <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: recipe main</span> @@ -71,37 +70,37 @@ recipe main [ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_braces<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> transform_braces<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void transform_braces<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "AAA transform_braces\n"; //? 1</span> <span class="CommentedCode">//? exit(0); //? 1</span> - <span class="Normal">const</span> <span class="Normal">int</span> OPEN = <span class="Constant">0</span><span class="Delimiter">,</span> CLOSE = <span class="Constant">1</span><span class="Delimiter">;</span> + const int OPEN = <span class="Constant">0</span><span class="Delimiter">,</span> CLOSE = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// use signed integer for step index because we'll be doing arithmetic on it</span> - list<pair<<span class="Normal">int</span><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><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> > braces<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</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="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"{"</span><span class="Delimiter">)</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>long long int> > braces<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<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>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> << end<span class="Delimiter">();</span> - braces<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<<span class="Normal">int</span><span class="Delimiter">,</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>><span class="Delimiter">(</span>OPEN<span class="Delimiter">,</span> index<span class="Delimiter">));</span> + braces<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<int<span class="Delimiter">,</span>long long int><span class="Delimiter">(</span>OPEN<span class="Delimiter">,</span> index<span class="Delimiter">));</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"}"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>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> << <span class="Constant">"push (close, "</span> << index << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> - braces<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<<span class="Normal">int</span><span class="Delimiter">,</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>><span class="Delimiter">(</span>CLOSE<span class="Delimiter">,</span> index<span class="Delimiter">));</span> + braces<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<int<span class="Delimiter">,</span>long long int><span class="Delimiter">(</span>CLOSE<span class="Delimiter">,</span> index<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - stack<<span class="Comment">/*</span><span class="Comment">step</span><span class="Comment">*/</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> open_braces<span class="Delimiter">;</span> + stack<<span class="Comment">/*</span><span class="Comment">step</span><span class="Comment">*/</span>long long int> 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 << end<span class="Delimiter">();</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<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>index<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"{"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"{"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> open_braces<span class="Delimiter">.</span>push<span class="Delimiter">(</span>index<span class="Delimiter">);</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"}"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"}"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> open_braces<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"loop"</span>] + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"loop"</span>] && inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"loop-if"</span>] && inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"loop-unless"</span>] && inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"break"</span>] @@ -111,23 +110,23 @@ recipe main [ <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// update instruction operation</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> inst<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"jump-if"</span>]<span class="Delimiter">;</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> inst<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">;</span> - <span class="Normal">else</span> + else inst<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"jump"</span>]<span class="Delimiter">;</span> <span class="Comment">// check for explicitly provided targets</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos || inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos || inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// conditional branches check arg 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span> && is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span> && is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <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> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> <span class="Comment">// unconditional branches check arg 0</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <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> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -136,38 +135,38 @@ recipe main [ reagent target<span class="Delimiter">;</span> target<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> target<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << inst<span class="Delimiter">.</span>name << <span class="Constant">" needs a '{' before</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"loop"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"loop"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> target<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> - <span class="Normal">else</span> <span class="Comment">// break instruction</span> + else <span class="Comment">// break instruction</span> target<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> r<span class="Delimiter">)</span> - index - <span class="Constant">1</span><span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>target<span class="Delimiter">);</span> <span class="Comment">// log computed target</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos<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> << target<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span> << end<span class="Delimiter">();</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<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> << target<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span> << end<span class="Delimiter">();</span> - <span class="Normal">else</span> + else trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << target<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Comment">// returns a signed integer not just so that we can return -1 but also to</span> <span class="Comment">// enable future signed arithmetic</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> matching_brace<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index<span class="Delimiter">,</span> <span class="Normal">const</span> list<pair<<span class="Normal">int</span><span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> >& braces<span class="Delimiter">,</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">int</span> stacksize = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>list<pair<<span class="Normal">int</span><span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> >::const_iterator p = braces<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != braces<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-></span>second < index<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +long long int matching_brace<span class="Delimiter">(</span>long long int index<span class="Delimiter">,</span> const list<pair<int<span class="Delimiter">,</span> long long int> >& braces<span class="Delimiter">,</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + int stacksize = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>list<pair<int<span class="Delimiter">,</span> long long int> >::const_iterator p = braces<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != braces<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>second < index<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> stacksize += <span class="Delimiter">(</span>p<span class="Delimiter">-></span>first ? <span class="Constant">1</span> : -<span class="Constant">1</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>stacksize == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>stacksize == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> p<span class="Delimiter">-></span>second<span class="Delimiter">;</span> <span class="Delimiter">}</span> raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": unbalanced '{'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> <span class="Comment">// exit current routine</span> <span class="Delimiter">}</span> <span class="Comment">// temporarily suppress run</span> -<span class="Normal">void</span> transform<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void transform<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span> load<span class="Delimiter">(</span>form<span class="Delimiter">);</span> transform_all<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -192,10 +191,10 @@ Recipe_ordinal[<span class="Constant">"loop-unless"</span>] = LOOP_UNL <span class="Delimiter">:(scenario loop)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - <span class="Constant">3</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> loop <span class="Delimiter">}</span> ] @@ -207,7 +206,7 @@ recipe main [ <span class="Delimiter">:(scenario break_empty_block)</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Delimiter">{</span> <span class="Identifier">break</span> <span class="Delimiter">}</span> @@ -218,7 +217,7 @@ recipe main [ <span class="Delimiter">:(scenario break_cascading)</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Delimiter">{</span> <span class="Identifier">break</span> <span class="Delimiter">}</span> @@ -233,11 +232,11 @@ recipe main [ <span class="Delimiter">:(scenario break_cascading2)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Identifier">break</span> - <span class="Constant">3</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> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Identifier">break</span> @@ -252,11 +251,11 @@ recipe main [ <span class="Delimiter">:(scenario break_if)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - <span class="Identifier">break</span>-<span class="Normal">if</span> <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="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> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Identifier">break</span> @@ -271,36 +270,36 @@ recipe main [ <span class="Delimiter">:(scenario break_nested)</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Delimiter">{</span> - <span class="Constant">2</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> <span class="Identifier">break</span> <span class="Delimiter">{</span> - <span class="Constant">3</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> <span class="Delimiter">}</span> - <span class="Constant">4</span>:number<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> <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>:number<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> <span class="Delimiter">{</span> - <span class="Constant">2</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> <span class="Identifier">break</span> <span class="Delimiter">{</span> <span class="Delimiter">}</span> - <span class="Constant">4</span>:number<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> <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>:number<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> <span class="Delimiter">{</span> - <span class="Constant">2</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> <span class="Identifier">break</span> <span class="Delimiter">{</span> <span class="Delimiter">}</span> @@ -311,7 +310,7 @@ recipe main [ <span class="Delimiter">:(scenario break_label)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Delimiter">{</span> <span class="Identifier">break</span> +foo:offset <span class="Delimiter">}</span> @@ -320,11 +319,11 @@ recipe main [ <span class="Delimiter">:(scenario break_unless)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <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="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: recipe main</span> @@ -335,11 +334,11 @@ recipe main [ <span class="Delimiter">:(scenario loop_unless)</span> recipe main [ - <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">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> 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="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: recipe main</span> @@ -350,14 +349,14 @@ recipe main [ <span class="Delimiter">:(scenario loop_nested)</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Delimiter">{</span> - <span class="Constant">2</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> <span class="Delimiter">{</span> - <span class="Constant">3</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> <span class="Delimiter">}</span> - loop-<span class="Normal">if</span> <span class="Constant">4</span>:boolean - <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + loop-if <span class="Constant">4</span>:boolean + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">}</span> ] <span class="traceContains">+after-brace: recipe main</span> @@ -365,9 +364,9 @@ recipe main [ <span class="Delimiter">:(scenario loop_label)</span> recipe main [ - <span class="Constant">1</span>:number<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> +foo - <span class="Constant">2</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> ] <span class="traceContains">+after-brace: recipe main</span> <span class="traceContains">+after-brace: copy ...</span> @@ -378,14 +377,14 @@ recipe main [ <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>: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="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Delimiter">{</span> - <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>:literal - <span class="Identifier">break</span>-<span class="Normal">if</span> <span class="Constant">3</span>:boolean + <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> + <span class="Identifier">break</span>-if <span class="Constant">3</span>:boolean <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 + <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> loop <span class="Delimiter">}</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> diff --git a/html/041jump_label.cc.html b/html/041jump_label.cc.html index 8cf9292a..05493404 100644 --- a/html/041jump_label.cc.html +++ b/html/041jump_label.cc.html @@ -14,15 +14,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .traceAbsent { color: #c00000; } -.Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } .cSpecial { color: #008000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.Constant { color: #00a0a0; } +.traceContains { color: #008000; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -35,13 +34,15 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <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="Comment">//: We'll also treat 'break' and 'loop' as jumps. The choice of name is</span> +<span class="Comment">//: just documentation about intent; use 'break' to indicate you're exiting</span> +<span class="Comment">//: one or more loop nests, and 'loop' to indicate you're skipping to the next</span> +<span class="Comment">//: iteration of some containing loop nest.</span> <span class="Delimiter">:(scenario jump_to_label)</span> recipe main [ jump +target:label - <span class="Constant">1</span>:number<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> +target ] <span class="traceAbsent">-mem: storing 0 in location 1</span> @@ -53,25 +54,25 @@ Type_ordinal[<span class="Constant">"label"</span>] = <span class="Con Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_labels<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> transform_labels<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> offset<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</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="Normal">if</span> <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> +void transform_labels<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + map<string<span class="Delimiter">,</span> long long int> offset<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"jump"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"jump"</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> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"jump-if"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"jump-if"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<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> - <span class="Normal">if</span> <span class="Delimiter">((</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"loop"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"break"</span>]<span class="Delimiter">)</span> + if <span class="Delimiter">((</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"loop"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"break"</span>]<span class="Delimiter">)</span> && SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> 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> - <span class="Normal">if</span> <span class="Delimiter">((</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"loop-if"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"loop-unless"</span>] + if <span class="Delimiter">((</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"loop-if"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"loop-unless"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"break-if"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"break-unless"</span>]<span class="Delimiter">)</span> && SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> == <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> 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> @@ -80,14 +81,14 @@ Type_ordinal[<span class="Constant">"label"</span>] = <span class="Con <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> 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> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>& offset<span class="Delimiter">,</span> <span class="Normal">const</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> current_offset<span class="Delimiter">,</span> <span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</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> long long int>& offset<span class="Delimiter">,</span> const long long int current_offset<span class="Delimiter">,</span> const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": jump target must be offset or label but is "</span> << x<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>!x<span class="Delimiter">.</span>initialized<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// non-labels will be handled like other number operands</span> - <span class="Normal">if</span> <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> + if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// non-labels will be handled like other number operands</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 << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": can't find label "</span> << x<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<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> @@ -98,7 +99,7 @@ recipe main [ <span class="Delimiter">{</span> <span class="Delimiter">{</span> <span class="Identifier">break</span> +target:label - <span class="Constant">1</span>:number<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> <span class="Delimiter">}</span> <span class="Delimiter">}</span> +target @@ -109,8 +110,8 @@ recipe main [ recipe main [ <span class="Delimiter">{</span> <span class="Delimiter">{</span> - jump-<span class="Normal">if</span> <span class="Constant">1</span>:literal<span class="Delimiter">,</span> +target:label - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + jump-if <span class="Constant">1</span><span class="Delimiter">,</span> +target:label + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> +target @@ -121,8 +122,8 @@ recipe main [ recipe main [ <span class="Delimiter">{</span> <span class="Delimiter">{</span> - loop-unless <span class="Constant">0</span>:literal<span class="Delimiter">,</span> +target:label <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 + loop-unless <span class="Constant">0</span><span class="Delimiter">,</span> +target:label <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> <span class="Delimiter">}</span> <span class="Delimiter">}</span> +target @@ -132,13 +133,13 @@ recipe main [ <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 + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> jump +target:label - <span class="Constant">4</span>:number<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> +target - <span class="Constant">5</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> ] <span class="traceContains">+mem: storing 0 in location 5</span> <span class="traceAbsent">-mem: storing 0 in location 4</span> diff --git a/html/042name.cc.html b/html/042name.cc.html index 9eddb2c5..1a0cc746 100644 --- a/html/042name.cc.html +++ b/html/042name.cc.html @@ -13,17 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceAbsent { color: #c00000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -39,17 +38,17 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">//: locations. In mu, a transform called 'transform_names' provides this</span> <span class="Comment">//: convenience.</span> -<span class="Delimiter">:(scenario convert_names)</span> +<span class="Delimiter">:(scenario transform_names)</span> recipe main [ - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + x:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+name: assign x 1</span> <span class="traceContains">+mem: storing 0 in location 1</span> -<span class="Delimiter">:(scenario convert_names_warns)</span> +<span class="Delimiter">:(scenario transform_names_warns)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy y:number + x:number<span class="Special"> <- </span>copy y:number ] <span class="traceContains">+warn: use before set: y in main</span> @@ -57,41 +56,38 @@ recipe main [ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_names<span class="Delimiter">);</span> <span class="Delimiter">:(before "End Globals")</span> -map<recipe_ordinal<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> > Name<span class="Delimiter">;</span> +map<recipe_ordinal<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> long long int> > Name<span class="Delimiter">;</span> <span class="Delimiter">:(after "Clear Other State For recently_added_recipes")</span> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>recently_added_recipes<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>recently_added_recipes<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<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> transform_names<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">bool</span> names_used = <span class="Constant">false</span><span class="Delimiter">;</span> - <span class="Normal">bool</span> numeric_locations_used = <span class="Constant">false</span><span class="Delimiter">;</span> - map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>& names = Name[r]<span class="Delimiter">;</span> - map<string<span class="Delimiter">,</span> vector<type_ordinal> > metadata<span class="Delimiter">;</span> +void transform_names<span class="Delimiter">(</span>const recipe_ordinal 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> long long int>& names = Name[r]<span class="Delimiter">;</span> <span class="Comment">// store the indices 'used' so far in the map</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>& curr_idx = names[<span class="Constant">""</span>]<span class="Delimiter">;</span> + long long int& curr_idx = names[<span class="Constant">""</span>]<span class="Delimiter">;</span> ++curr_idx<span class="Delimiter">;</span> <span class="Comment">// avoid using index 0, benign skip in some other cases</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Comment">// Per-recipe Transforms</span> <span class="Comment">// map names to addresses</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> in = <span class="Constant">0</span><span class="Delimiter">;</span> in < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++in<span class="Delimiter">)</span> <span class="Delimiter">{</span> - check_metadata<span class="Delimiter">(</span>metadata<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="Normal">if</span> <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> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> inst<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <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> + for <span class="Delimiter">(</span>long long int in = <span class="Constant">0</span><span class="Delimiter">;</span> in < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_numeric_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">)))</span> numeric_locations_used = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_named_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">)))</span> names_used = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> inst<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!already_transformed<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> names<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << <span class="Constant">"use before set: "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">).</span>name << <span class="Constant">" in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> out = <span class="Constant">0</span><span class="Delimiter">;</span> out < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++out<span class="Delimiter">)</span> <span class="Delimiter">{</span> - check_metadata<span class="Delimiter">(</span>metadata<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="Normal">if</span> <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> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">),</span> inst<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <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> + for <span class="Delimiter">(</span>long long int out = <span class="Constant">0</span><span class="Delimiter">;</span> out < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++out<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_numeric_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">)))</span> numeric_locations_used = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_named_location<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">)))</span> names_used = <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>disqualified<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">),</span> inst<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name<span class="Delimiter">)</span> == names<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"assign "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">).</span>name << <span class="Constant">" "</span> << curr_idx << end<span class="Delimiter">();</span> 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> @@ -99,170 +95,150 @@ map<recipe_ordinal<span class="Delimiter">,</span> map<string<span class=" 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>names_used && numeric_locations_used && r != Recipe_ordinal[<span class="Constant">"interactive"</span>]<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>names_used && numeric_locations_used && r != Recipe_ordinal[<span class="Constant">"interactive"</span>]<span class="Delimiter">)</span> raise << <span class="Constant">"mixing variable names and numeric addresses in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> check_metadata<span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> vector<type_ordinal> >& metadata<span class="Delimiter">,</span> <span class="Normal">const</span> reagent& x<span class="Delimiter">,</span> <span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Comment">// if you use raw locations you're probably doing something unsafe</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// will throw a more precise warning elsewhere</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>metadata<span class="Delimiter">.</span>find<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">)</span> == metadata<span class="Delimiter">.</span>end<span class="Delimiter">())</span> - metadata[x<span class="Delimiter">.</span>name] = x<span class="Delimiter">.</span>types<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>metadata[x<span class="Delimiter">.</span>name] != x<span class="Delimiter">.</span>types<span class="Delimiter">)</span> - raise << x<span class="Delimiter">.</span>name << <span class="Constant">" used with multiple types in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span class="Delimiter">}</span> - -<span class="Normal">bool</span> 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="Normal">const</span> instruction& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool disqualified<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">mutable</span><span class="Comment">*/</span> reagent& x<span class="Delimiter">,</span> const instruction& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << x.to_string() << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << <span class="Constant">"missing type in '"</span> << inst<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_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_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// End Disqualified Reagents</span> - <span class="Normal">if</span> <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> + 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> -<span class="Normal">bool</span> already_transformed<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>& names<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> long long int>& names<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">)</span> != names<span class="Delimiter">.</span>end<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> lookup_name<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">,</span> <span class="Normal">const</span> recipe_ordinal default_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int lookup_name<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const recipe_ordinal default_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> Name[default_recipe][r<span class="Delimiter">.</span>name]<span class="Delimiter">;</span> <span class="Delimiter">}</span> -type_ordinal skip_addresses<span class="Delimiter">(</span><span class="Normal">const</span> vector<type_ordinal>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>types<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Identifier">return</span> types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +type_ordinal skip_addresses<span class="Delimiter">(</span>const vector<type_ordinal>& types<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>types<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Identifier">return</span> types<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Delimiter">}</span> raise << <span class="Constant">"expected a container"</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">int</span> find_element_name<span class="Delimiter">(</span><span class="Normal">const</span> type_ordinal t<span class="Delimiter">,</span> <span class="Normal">const</span> string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> type_info& container = Type[t]<span class="Delimiter">;</span> +int find_element_name<span class="Delimiter">(</span>const type_ordinal t<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const type_info& container = Type[t]<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << "looking for element " << name << " in type " << container.name << " with " << SIZE(container.element_names) << " elements\n"; //? 1</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>container<span class="Delimiter">.</span>element_names<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>container<span class="Delimiter">.</span>element_names<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>container<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == name<span class="Delimiter">)</span> <span class="Identifier">return</span> i<span class="Delimiter">;</span> <span class="Delimiter">}</span> raise << <span class="Constant">"unknown element "</span> << name << <span class="Constant">" in container "</span> << Type[t]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> is_numeric_location<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <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> +bool is_numeric_location<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="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_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> is_named_location<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <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> +bool is_named_location<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="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_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> is_raw<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip value+type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> +bool is_raw<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/*</span><span class="Comment">skip value+type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"raw"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> is_special_name<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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="Normal">if</span> <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> +bool is_special_name<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>s == <span class="Constant">"_"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>s == <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// End is_special_name Cases</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="Delimiter">:(scenario transform_names_passes_dummy)</span> <span class="Comment"># _ is just a dummy result that never gets consumed</span> recipe main [ - _<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="Delimiter">,</span> x:number<span class="Special"> <- </span>copy <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+name: assign x 1</span> <span class="traceAbsent">-name: assign _ 1</span> <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> +<span class="Delimiter">:(scenario transform_names_passes_raw)</span> recipe main [ - <span class="Normal">x</span>:number/<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> ] <span class="traceAbsent">-name: assign x 1</span> -<span class="Delimiter">:(scenario convert_names_warns_when_mixing_names_and_numeric_locations)</span> +<span class="Delimiter">:(scenario transform_names_warns_when_mixing_names_and_numeric_locations)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number + 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="Delimiter">:(scenario transform_names_warns_when_mixing_names_and_numeric_locations2)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Constant">1</span>:number<span class="Special"> <- </span>copy x:number ] <span class="traceContains">+warn: mixing variable names and numeric addresses in main</span> -<span class="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_names_and_raw_locations)</span> +<span class="Delimiter">:(scenario transform_names_does_not_warn_when_mixing_names_and_raw_locations)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number/<span class="Special">raw</span> + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number/<span class="Special">raw</span> ] <span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</span> $warn: <span class="Constant">0</span> -<span class="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_names_and_literals)</span> +<span class="Delimiter">:(scenario transform_names_does_not_warn_when_mixing_names_and_literals)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span> ] <span class="traceAbsent">-warn: mixing variable names and numeric addresses in main</span> $warn: <span class="Constant">0</span> -<span class="Delimiter">:(scenario convert_names_warns_on_reusing_name_with_different_type)</span> -<span class="Special">% Hide_warnings = true;</span> -recipe main [ - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Normal">x</span>:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal -] -<span class="traceContains">+warn: x used with multiple types 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> <span class="Delimiter">:(before "End Mu Types Initialization")</span> Type[point]<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"x"</span><span class="Delimiter">);</span> Type[point]<span class="Delimiter">.</span>element_names<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"y"</span><span class="Delimiter">);</span> -<span class="Delimiter">:(scenario convert_names_transforms_container_elements)</span> +<span class="Delimiter">:(scenario transform_names_transforms_container_elements)</span> recipe main [ - <span class="Normal">p</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal <span class="Comment"># unsafe</span> - <span class="Normal">a</span>:number<span class="Special"> <- </span>get p:address:point/deref<span class="Delimiter">,</span> y:offset - <span class="Normal">b</span>:number<span class="Special"> <- </span>get p:address:point/deref<span class="Delimiter">,</span> x:offset + p:address:point<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># unsafe</span> + a:number<span class="Special"> <- </span>get *p:address:point<span class="Delimiter">,</span> y:offset + b:number<span class="Special"> <- </span>get *p:address:point<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> <span class="Delimiter">:(after "Per-recipe Transforms")</span> <span class="Comment">// replace element names of containers with offsets</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"get"</span>] +if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"get"</span>] || inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"get-address"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": exactly 2 ingredients expected in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> + if <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": expected ingredient 1 of "</span> << <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"get"</span>] ? <span class="Constant">"'get'"</span> : <span class="Constant">"'get-address'"</span><span class="Delimiter">)</span> << <span class="Constant">" to have type 'offset'; got "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// since first non-address in base type must be a container, we don't have to canonize</span> type_ordinal base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>types<span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> @@ -272,10 +248,10 @@ recipe main [ <span class="Comment">//: this test is actually illegal so can't call run</span> <span class="Delimiter">:(scenarios transform)</span> -<span class="Delimiter">:(scenario convert_names_handles_containers)</span> +<span class="Delimiter">:(scenario transform_names_handles_containers)</span> recipe main [ - <span class="Normal">a</span>:point<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Normal">b</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + a:point<span class="Special"> <- </span>copy <span class="Constant">0</span> + b:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+name: assign a 1</span> <span class="traceContains">+name: assign b 3</span> @@ -283,25 +259,25 @@ recipe main [ <span class="SalientComment">//:: Support variant names for exclusive containers in 'maybe-convert'.</span> <span class="Delimiter">:(scenarios run)</span> -<span class="Delimiter">:(scenario maybe_convert_named)</span> +<span class="Delimiter">:(scenario transform_names_handles_exclusive_containers)</span> recipe main [ - <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-<span class="Normal">or</span>-point/<span class="Special">raw</span><span class="Delimiter">,</span> p:variant <span class="Comment"># unsafe</span> + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span> + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point/<span class="Special">raw</span><span class="Delimiter">,</span> p:variant <span class="Comment"># unsafe</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> <span class="Comment">// convert variant names of exclusive containers</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"maybe-convert"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"maybe-convert"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": exactly 2 ingredients expected in '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)));</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// since first non-address in base type must be an exclusive container, we don't have to canonize</span> type_ordinal base_type = skip_addresses<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>types<span class="Delimiter">);</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>find_element_name<span class="Delimiter">(</span>base_type<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> diff --git a/html/043new.cc.html b/html/043new.cc.html index 83bbbef2..6175f3dc 100644 --- a/html/043new.cc.html +++ b/html/043new.cc.html @@ -13,16 +13,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -40,21 +39,21 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <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:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type - <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type + <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> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Reserved_for_tests = <span class="Constant">1000</span><span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Memory_allocated_until = Reserved_for_tests<span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Initial_memory_per_routine = <span class="Constant">100000</span><span class="Delimiter">;</span> +long long int Reserved_for_tests = <span class="Constant">1000</span><span class="Delimiter">;</span> +long long int Memory_allocated_until = Reserved_for_tests<span class="Delimiter">;</span> +long long int Initial_memory_per_routine = <span class="Constant">100000</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Memory_allocated_until = Reserved_for_tests<span class="Delimiter">;</span> Initial_memory_per_routine = <span class="Constant">100000</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Fields")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> alloc<span class="Delimiter">,</span> alloc_max<span class="Delimiter">;</span> +long long int alloc<span class="Delimiter">,</span> alloc_max<span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Constructor")</span> alloc = Memory_allocated_until<span class="Delimiter">;</span> Memory_allocated_until += Initial_memory_per_routine<span class="Delimiter">;</span> @@ -67,20 +66,20 @@ trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimite Type_ordinal[<span class="Constant">"type"</span>] = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(after "Per-recipe Transforms")</span> <span class="Comment">// replace type names with type_ordinals</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"new"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_ordinal[<span class="Constant">"new"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// End NEW Transform Special-cases</span> <span class="Comment">// first arg must be of type 'type'</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": 'new' expects one or two ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - <span class="Normal">if</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>properties<span class="Delimiter">.</span>empty<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>empty<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>empty<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> raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": first ingredient of 'new' should be a type, but got "</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">)</span> == Type_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> raise << Recipe[r]<span class="Delimiter">.</span>name << <span class="Constant">": unknown type "</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="cSpecial">'\n'</span> << end<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_ordinal[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> trace<span class="Delimiter">(</span>Primitive_recipe_depth<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>name << end<span class="Delimiter">();</span> - <span class="Normal">end_new_transform</span>:<span class="Delimiter">;</span> + end_new_transform:<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="SalientComment">//:: Now implement the primitive recipe.</span> @@ -91,27 +90,27 @@ NEW<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"new"</span>] = NEW<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> NEW: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case NEW: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'new' requires one or two ingredients, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'new' should be a type, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Comment">// compute the space we need</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> array_length = <span class="Constant">0</span><span class="Delimiter">;</span> + long long int size = <span class="Constant">0</span><span class="Delimiter">;</span> + long long int array_length = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">{</span> vector<type_ordinal> 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="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>value<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// array</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>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"array size is "</span> << array_length << end<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> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> <span class="Comment">// scalar</span> size = size_of<span class="Delimiter">(</span>type<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -121,16 +120,16 @@ Recipe_ordinal[<span class="Constant">"new"</span>] = NEW<span class=" <span class="Comment">// compute the region of memory to return</span> <span class="Comment">// really crappy at the moment</span> ensure_space<span class="Delimiter">(</span>size<span class="Delimiter">);</span> - <span class="Normal">const</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> + const long long int result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"new alloc: "</span> << result << end<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 allocated space</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address = result<span class="Delimiter">;</span> address < result+size<span class="Delimiter">;</span> ++address<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int address = result<span class="Delimiter">;</span> address < result+size<span class="Delimiter">;</span> ++address<span class="Delimiter">)</span> <span class="Delimiter">{</span> Memory[address] = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> Memory[result] = array_length<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// bump</span> @@ -153,9 +152,9 @@ Recipe_ordinal[<span class="Constant">"new"</span>] = NEW<span class=" <span class="CommentedCode">//? cerr << SIZE(Memory) << '\n'; //? 1</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> ensure_space<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void ensure_space<span class="Delimiter">(</span>long long int 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="Normal">if</span> <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> + 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> @@ -168,29 +167,29 @@ Recipe_ordinal[<span class="Constant">"new"</span>] = NEW<span class=" <span class="Special">% Memory_allocated_until = 10;</span> <span class="Special">% Memory[Memory_allocated_until] = 1;</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type - <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:number/deref + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>new number:type + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy *<span class="Constant">1</span>:address:number ] <span class="traceContains">+mem: storing 0 in location 2</span> <span class="Delimiter">:(scenario new_array)</span> recipe main [ - <span class="Constant">1</span>:address:array:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">5</span>:literal - <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type + <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> + <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: 1:address:array:number/raw <- new number:type, 5:literal</span> +<span class="traceContains">+run: 1:address:array:number/raw <- new number:type, 5</span> <span class="traceContains">+mem: array size is 5</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="Delimiter">:(scenario new_empty_array)</span> recipe main [ - <span class="Constant">1</span>:address:array:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">0</span>:literal - <span class="Constant">2</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type + <span class="Constant">1</span>:address:array:number/<span class="Special">raw <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">0</span> + <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: 1:address:array:number/raw <- new number:type, 0:literal</span> +<span class="traceContains">+run: 1:address:array:number/raw <- new number:type, 0</span> <span class="traceContains">+mem: array size is 0</span> <span class="traceContains">+mem: storing 1 in location 3</span> @@ -198,18 +197,18 @@ recipe main [ <span class="Delimiter">:(scenario new_concurrent)</span> recipe f1 [ start-running f2:recipe - <span class="Constant">1</span>:address:number/<span class="Special">raw <- </span><span class="Normal">new</span> number: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:number/<span class="Special">raw <- </span><span class="Normal">new</span> number: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: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="Constant">4</span>:number/<span class="Special">raw <- </span>copy <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 0 in location 3</span> @@ -217,8 +216,8 @@ 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:number/<span class="Special">raw <- </span><span class="Normal">new</span> number:type - <span class="Constant">2</span>:address:point/<span class="Special">raw <- </span><span class="Normal">new</span> point:type <span class="Comment"># not enough room in initial page</span> + <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> <span class="traceContains">+new: routine allocated memory from 1002 to 1004</span> @@ -228,16 +227,16 @@ recipe main [ <span class="Delimiter">:(scenario new_reclaim)</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>new number:type abandon <span class="Constant">1</span>:address:number - <span class="Constant">2</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type <span class="Comment"># must be same size as abandoned memory to reuse</span> + <span class="Constant">2</span>:address:number<span class="Special"> <- </span>new number:type <span class="Comment"># must be same size as abandoned memory to reuse</span> <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:number ] <span class="Comment"># both allocations should have returned the same address</span> <span class="traceContains">+mem: storing 1 in location 3</span> <span class="Delimiter">:(before "End Globals")</span> -map<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span><span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> Free_list<span class="Delimiter">;</span> +map<long long int<span class="Delimiter">,</span> long long int> Free_list<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Free_list<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> @@ -246,33 +245,33 @@ ABANDON<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"abandon"</span>] = ABANDON<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> ABANDON: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case ABANDON: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'abandon' requires one ingredient, but got '"</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'abandon' should be an address, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address = 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 address = 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> reagent types = 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="Normal">if</span> <span class="Delimiter">(</span>types<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>types<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'abandon' should be an address, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - reagent target_type = deref<span class="Delimiter">(</span>types<span class="Delimiter">);</span> + reagent target_type = lookup_memory<span class="Delimiter">(</span>types<span class="Delimiter">);</span> abandon<span class="Delimiter">(</span>address<span class="Delimiter">,</span> size_of<span class="Delimiter">(</span>target_type<span class="Delimiter">));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> abandon<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void abandon<span class="Delimiter">(</span>long long int address<span class="Delimiter">,</span> long long int size<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? Total_free += size; //? 1</span> <span class="CommentedCode">//? Num_free++; //? 1</span> <span class="CommentedCode">//? cerr << "abandon: " << size << '\n'; //? 2</span> <span class="Comment">// clear memory</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = address<span class="Delimiter">;</span> curr < address+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>long long int curr = address<span class="Delimiter">;</span> curr < address+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> Memory[curr] = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// append existing free list to address</span> Memory[address] = Free_list[size]<span class="Delimiter">;</span> @@ -280,18 +279,18 @@ Recipe_ordinal[<span class="Constant">"abandon"</span>] = ABANDON<span <span class="Delimiter">}</span> <span class="Delimiter">:(before "ensure_space(size)" following "case NEW")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>Free_list[size]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = Free_list[size]<span class="Delimiter">;</span> +if <span class="Delimiter">(</span>Free_list[size]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int result = Free_list[size]<span class="Delimiter">;</span> Free_list[size] = Memory[result]<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = result+<span class="Constant">1</span><span class="Delimiter">;</span> curr < result+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[curr] != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int curr = result+<span class="Constant">1</span><span class="Delimiter">;</span> curr < result+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Memory[curr] != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": memory in free list was not zeroed out: "</span> << curr << <span class="Constant">'/'</span> << result << <span class="Constant">"; somebody wrote to us after free!!!</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// always fatal</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> Memory[result] = array_length<span class="Delimiter">;</span> - <span class="Normal">else</span> + else Memory[result] = <span class="Constant">0</span><span class="Delimiter">;</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span> @@ -300,9 +299,9 @@ Recipe_ordinal[<span class="Constant">"abandon"</span>] = ABANDON<span <span class="Delimiter">:(scenario new_differing_size_no_reclaim)</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>new number:type abandon <span class="Constant">1</span>:address:number - <span class="Constant">2</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal <span class="Comment"># different size</span> + <span class="Constant">2</span>:address:number<span class="Special"> <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">2</span> <span class="Comment"># different size</span> <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:number ] <span class="Comment"># no reuse</span> @@ -310,9 +309,9 @@ recipe main [ <span class="Delimiter">:(scenario new_reclaim_array)</span> recipe main [ - <span class="Constant">1</span>:address:array:number<span class="Special"> <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + <span class="Constant">1</span>:address:array:number<span class="Special"> <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">2</span> abandon <span class="Constant">1</span>:address:array:number - <span class="Constant">2</span>:address:array:number<span class="Special"> <- </span><span class="Normal">new</span> number:type<span class="Delimiter">,</span> <span class="Constant">2</span>:literal + <span class="Constant">2</span>:address:array:number<span class="Special"> <- </span>new number:type<span class="Delimiter">,</span> <span class="Constant">2</span> <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:array:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:array:number ] <span class="Comment"># reuse</span> @@ -322,24 +321,24 @@ recipe main [ <span class="Delimiter">:(scenario new_string)</span> recipe main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [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="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<span class="Delimiter">,</span> <span class="Constant">5</span> ] <span class="Comment"># number code for 'e'</span> <span class="traceContains">+mem: storing 101 in location 2</span> <span class="Delimiter">:(scenario new_string_handles_unicode)</span> recipe main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [a«c] - <span class="Constant">2</span>:number<span class="Special"> <- </span>length <span class="Constant">1</span>:address:array:character/deref - <span class="Constant">3</span>:character<span class="Special"> <- </span>index <span class="Constant">1</span>:address:array:character/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:literal + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [a«c] + <span class="Constant">2</span>:number<span class="Special"> <- </span>length *<span class="Constant">1</span>:address:array:character + <span class="Constant">3</span>:character<span class="Special"> <- </span>index *<span class="Constant">1</span>:address:array:character<span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 3 in location 2</span> <span class="Comment"># unicode for '«'</span> <span class="traceContains">+mem: storing 171 in location 3</span> <span class="Delimiter">:(before "End NEW Transform Special-cases")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> + if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<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>empty<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>empty<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">"literal-string"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -349,7 +348,7 @@ recipe main [ <span class="Delimiter">}</span> <span class="Delimiter">:(after "case NEW" following "Primitive Recipe Implementations")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>is_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> +if <span class="Delimiter">(</span>is_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> 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_mu_string<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> @@ -357,20 +356,20 @@ recipe main [ <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> new_mu_string<span class="Delimiter">(</span><span class="Normal">const</span> string& contents<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int new_mu_string<span class="Delimiter">(</span>const string& contents<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// allocate an array just large enough for it</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> string_length = unicode_length<span class="Delimiter">(</span>contents<span class="Delimiter">);</span> + long long int string_length = unicode_length<span class="Delimiter">(</span>contents<span class="Delimiter">);</span> <span class="CommentedCode">//? cout << "string_length is " << string_length << '\n'; //? 1</span> <span class="CommentedCode">//? Total_alloc += string_length+1; //? 1</span> <span class="CommentedCode">//? Num_alloc++; //? 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> <span class="Comment">// initialize string</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> + long long int result = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> Memory[Current_routine<span class="Delimiter">-></span>alloc++] = string_length<span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">const</span> <span class="Normal">char</span>* raw_contents = contents<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">uint32_t</span> curr_character<span class="Delimiter">;</span> + long long int curr = <span class="Constant">0</span><span class="Delimiter">;</span> + const char* raw_contents = contents<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> + for <span class="Delimiter">(</span>long long int 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> + uint32_t curr_character<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>curr < SIZE<span class="Delimiter">(</span>contents<span class="Delimiter">));</span> tb_utf8_char_to_unicode<span class="Delimiter">(</span>&curr_character<span class="Delimiter">,</span> &raw_contents[curr]<span class="Delimiter">);</span> Memory[Current_routine<span class="Delimiter">-></span>alloc] = curr_character<span class="Delimiter">;</span> @@ -385,19 +384,19 @@ recipe main [ <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><span class="Normal">new</span> number:type - <span class="Constant">2</span>:address:array:character/<span class="Special">raw <- </span><span class="Normal">new</span> [a] <span class="Comment"># not enough room in initial page, if you take the array size into account</span> + <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> <span class="Comment">//: helpers</span> <span class="Delimiter">:(code)</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> unicode_length<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> <span class="Normal">char</span>* in = s<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>curr < SIZE<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// carefully bounds-check on the string</span> +long long int unicode_length<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const char* in = s<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> + long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> + long long int curr = <span class="Constant">0</span><span class="Delimiter">;</span> + while <span class="Delimiter">(</span>curr < SIZE<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// carefully bounds-check on the string</span> <span class="Comment">// before accessing its raw pointer</span> ++result<span class="Delimiter">;</span> curr += tb_utf8_char_length<span class="Delimiter">(</span>in[curr]<span class="Delimiter">);</span> diff --git a/html/044space.cc.html b/html/044space.cc.html index 14ef9f7a..7f4e742e 100644 --- a/html/044space.cc.html +++ b/html/044space.cc.html @@ -13,17 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.traceAbsent { color: #c00000; } -.SalientComment { color: #00ffff; } -.Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.Constant { color: #00a0a0; } +.SalientComment { color: #00ffff; } +.traceAbsent { color: #c00000; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -43,42 +42,42 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <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>:number<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="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>:literal - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal + <span class="Constant">10</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <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> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> ] <span class="traceContains">+mem: storing 23 in location 12</span> -<span class="Delimiter">:(scenario deref_sidesteps_default_space)</span> +<span class="Delimiter">:(scenario lookup_sidesteps_default_space)</span> recipe main [ <span class="Comment"># pretend pointer from outside</span> - <span class="Constant">3</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> <span class="Comment"># pretend array</span> - <span class="Constant">1000</span>:number<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> <span class="Comment"># actual start of this recipe</span> - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span>:literal - <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 + default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span> + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">3</span> + <span class="Constant">8</span>:number/<span class="Special">raw <- </span>copy *<span class="Constant">1</span>:address:number ] <span class="traceContains">+mem: storing 34 in location 8</span> <span class="SalientComment">//:: first disable name conversion for 'default-space'</span> <span class="Delimiter">:(scenario convert_names_passes_default_space)</span> recipe main [ - <span class="Normal">default</span>-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 + default-space:number<span class="Delimiter">,</span> x:number<span class="Special"> <- </span>copy <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+name: assign x 1</span> <span class="traceAbsent">-name: assign default-space 1</span> <span class="Delimiter">:(before "End Disqualified Reagents")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</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> <span class="Delimiter">:(before "End is_special_name Cases")</span> -<span class="Normal">if</span> <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">"default-space"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="SalientComment">//:: now implement space support</span> <span class="Delimiter">:(before "End call Fields")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> default_space<span class="Delimiter">;</span> +long long int default_space<span class="Delimiter">;</span> <span class="Delimiter">:(before "End call Constructor")</span> default_space = <span class="Constant">0</span><span class="Delimiter">;</span> @@ -87,8 +86,8 @@ 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">//? cout << "absolutize " << x.to_string() << '\n'; //? 4</span> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Delimiter">{</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> + if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="Constant">": reagent not initialized: "</span> << x<span class="Delimiter">.</span>original_string << end<span class="Delimiter">();</span> <span class="Identifier">return</span> x<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -98,22 +97,22 @@ reagent absolutize<span class="Delimiter">(</span>reagent x<span class="Delimite assert<span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>r<span class="Delimiter">));</span> <span class="Identifier">return</span> r<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(before "return result" following "reagent deref(reagent x)")</span> +<span class="Delimiter">:(before "return result" following "reagent lookup_memory(reagent x)")</span> result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> vector<string> ><span class="Delimiter">(</span><span class="Constant">"raw"</span><span class="Delimiter">,</span> vector<string><span class="Delimiter">()));</span> <span class="SalientComment">//:: fix 'get'</span> -<span class="Delimiter">:(scenario deref_sidesteps_default_space_in_get)</span> +<span class="Delimiter">:(scenario lookup_sidesteps_default_space_in_get)</span> recipe main [ <span class="Comment"># pretend pointer to container from outside</span> - <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">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Comment"># pretend array</span> - <span class="Constant">1000</span>:number<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> <span class="Comment"># actual start of this recipe</span> - <span class="Normal">default</span>-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>: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 + default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span> + <span class="Constant">1</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">12</span> + <span class="Constant">9</span>:number/<span class="Special">raw <- </span>get *<span class="Constant">1</span>:address:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] <span class="traceContains">+mem: storing 35 in location 9</span> @@ -122,18 +121,18 @@ tmp<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>pus <span class="SalientComment">//:: fix 'index'</span> -<span class="Delimiter">:(scenario deref_sidesteps_default_space_in_index)</span> +<span class="Delimiter">:(scenario lookup_sidesteps_default_space_in_index)</span> recipe main [ <span class="Comment"># pretend pointer to array from outside</span> - <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="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Comment"># pretend array</span> - <span class="Constant">1000</span>:number<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> <span class="Comment"># actual start of this recipe</span> - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</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 + default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span> + <span class="Constant">1</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">12</span> + <span class="Constant">9</span>:number/<span class="Special">raw <- </span>index *<span class="Constant">1</span>:address:array:number<span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 35 in location 9</span> @@ -145,36 +144,36 @@ tmp<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>pus <span class="Delimiter">:(scenario new_default_space)</span> recipe main [ - <span class="Normal">new</span>-<span class="Normal">default</span>-space - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Normal">y</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal + new-default-space + x:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + y:number<span class="Special"> <- </span>copy <span class="Constant">3</span> ] <span class="Comment"># allocate space for x and y, as well as the chaining slot at 0</span> <span class="traceContains">+mem: array size is 3</span> <span class="Delimiter">:(before "End Disqualified Reagents")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"number-of-locals"</span><span class="Delimiter">)</span> +if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"number-of-locals"</span><span class="Delimiter">)</span> x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End is_special_name Cases")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"number-of-locals"</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">"number-of-locals"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Rewrite Instruction(curr)")</span> <span class="Comment">// rewrite `new-default-space` to</span> <span class="Comment">// `default-space:address:array:location <- new location:type, number-of-locals:literal`</span> <span class="Comment">// where N is Name[recipe][""]</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"new-default-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"new-default-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> rewrite_default_space_instruction<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(after "vector<double> read_memory(reagent x)")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"number-of-locals"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - vector<<span class="Normal">double</span>> result<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"number-of-locals"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<double> result<span class="Delimiter">;</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Name[Recipe_ordinal[current_recipe_name<span class="Delimiter">()</span>]][<span class="Constant">""</span>]<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">.</span>back<span class="Delimiter">()</span> == <span class="Constant">0</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>result<span class="Delimiter">.</span>back<span class="Delimiter">()</span> == <span class="Constant">0</span><span class="Delimiter">)</span> raise << <span class="Constant">"no space allocated for default-space in recipe "</span> << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">"; are you using names</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(after "void write_memory(reagent x, vector<double> data)")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"number-of-locals"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"number-of-locals"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": can't write to special name 'number-of-locals'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -190,8 +189,8 @@ recipe main [ ] recipe foo [ local-scope - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - reply <span class="Normal">default</span>-space:address:array:location + x:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + reply default-space:address:array:location ] <span class="Comment"># both calls to foo should have received the same default-space</span> <span class="traceContains">+mem: storing 1 in location 3</span> @@ -204,28 +203,28 @@ try_reclaim_locals<span class="Delimiter">();</span> <span class="Comment">//: now 'local-scope' is identical to 'new-default-space' except that we'll</span> <span class="Comment">//: reclaim the default-space when the routine exits</span> <span class="Delimiter">:(before "End Rewrite Instruction(curr)")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"local-scope"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"local-scope"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> rewrite_default_space_instruction<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> try_reclaim_locals<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void try_reclaim_locals<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Comment">// only reclaim routines starting with 'local-scope'</span> - <span class="Normal">const</span> recipe_ordinal r = Recipe_ordinal[current_recipe_name<span class="Delimiter">()</span>]<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> - <span class="Normal">const</span> instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name != <span class="Constant">"local-scope"</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + const recipe_ordinal r = Recipe_ordinal[current_recipe_name<span class="Delimiter">()</span>]<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + const instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<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>name != <span class="Constant">"local-scope"</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> abandon<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">/*</span><span class="Comment">array length</span><span class="Comment">*/</span><span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">number-of-locals</span><span class="Comment">*/</span>Name[r][<span class="Constant">""</span>]<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> rewrite_default_space_instruction<span class="Delimiter">(</span>instruction& curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void rewrite_default_space_instruction<span class="Delimiter">(</span>instruction& curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> curr<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"new"</span>]<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << <span class="Constant">"new-default-space can't take any ingredients</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"location:type"</span><span class="Delimiter">));</span> curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"number-of-locals:literal"</span><span class="Delimiter">));</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << <span class="Constant">"new-default-space can't take any results</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<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">"default-space:address:array:location"</span><span class="Delimiter">));</span> <span class="Delimiter">}</span> @@ -233,14 +232,14 @@ try_reclaim_locals<span class="Delimiter">();</span> <span class="SalientComment">//:: helpers</span> <span class="Delimiter">:(code)</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> space_base<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int 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>front<span class="Delimiter">().</span>default_space<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> offset<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>base == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> offset<span class="Delimiter">;</span> <span class="Comment">// raw</span> +long long int address<span class="Delimiter">(</span>long long int offset<span class="Delimiter">,</span> long long int base<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>base == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> offset<span class="Delimiter">;</span> <span class="Comment">// raw</span> <span class="CommentedCode">//? cout << base << '\n'; //? 2</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>offset >= <span class="Normal">static_cast</span><<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>><span class="Delimiter">(</span>Memory[base]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>offset >= static_cast<long long int><span class="Delimiter">(</span>Memory[base]<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// todo: test</span> raise << <span class="Constant">"location "</span> << offset << <span class="Constant">" is out of bounds "</span> << Memory[base] << <span class="Constant">" at "</span> << base << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -248,8 +247,8 @@ try_reclaim_locals<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">:(after "void write_memory(reagent x, vector<double> data)")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>data<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>data<span class="Delimiter">))</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'default-space' should be of type address:array:location, but tried to write "</span> << to_string<span class="Delimiter">(</span>data<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</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="Identifier">return</span><span class="Delimiter">;</span> @@ -257,14 +256,14 @@ try_reclaim_locals<span class="Delimiter">();</span> <span class="Delimiter">:(scenario get_default_space)</span> recipe main [ - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>:literal - <span class="Constant">1</span>:number/<span class="Special">raw <- </span>copy <span class="Normal">default</span>-space:address:array:location + default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span> + <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<double> read_memory(reagent x)")</span> - <span class="Normal">if</span> <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<<span class="Normal">double</span>> result<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"default-space"</span><span class="Delimiter">)</span> <span class="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> diff --git a/html/045space_surround.cc.html b/html/045space_surround.cc.html index 2bf9c648..1b356165 100644 --- a/html/045space_surround.cc.html +++ b/html/045space_surround.cc.html @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -41,12 +40,12 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <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>: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> - <span class="Normal">default</span>-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>: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="Constant">10</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># pretend array</span> + <span class="Constant">20</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># pretend array</span> + default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span> + <span class="Constant">0</span>:address:array:location/names:dummy<span class="Special"> <- </span>copy <span class="Constant">20</span> <span class="Comment"># later layers will explain the /names: property</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">32</span> + <span class="Constant">1</span>:number/space:<span class="Constant">1</span><span class="Special"> <- </span>copy <span class="Constant">33</span> ] <span class="Comment"># chain space</span> <span class="traceContains">+mem: storing 20 in location 11</span> @@ -60,22 +59,22 @@ recipe main [ <span class="Comment">//: one.</span> <span class="Delimiter">:(replace{} "long long int space_base(const reagent& x)")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> space_base<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int 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>front<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> space_base<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> space_index<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> base<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>space_index == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int space_base<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">,</span> long long int space_index<span class="Delimiter">,</span> long long int base<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>space_index == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> base<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = space_base<span class="Delimiter">(</span>x<span class="Delimiter">,</span> space_index-<span class="Constant">1</span><span class="Delimiter">,</span> Memory[base+<span class="Constant">1</span>]<span class="Delimiter">);</span> + long long int result = space_base<span class="Delimiter">(</span>x<span class="Delimiter">,</span> space_index-<span class="Constant">1</span><span class="Delimiter">,</span> Memory[base+<span class="Constant">1</span>]<span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> space_index<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<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> != <span class="Constant">1</span><span class="Delimiter">)</span> +long long int space_index<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<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> != <span class="Constant">1</span><span class="Delimiter">)</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": /space metadata should take exactly one value in "</span> << x<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> to_integer<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> @@ -85,7 +84,7 @@ recipe main [ <span class="Delimiter">:(scenario permit_space_as_variable_name)</span> recipe main [ - <span class="Normal">space</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + space:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] </pre> </body> diff --git a/html/046closure_name.cc.html b/html/046closure_name.cc.html index 83650402..b406f481 100644 --- a/html/046closure_name.cc.html +++ b/html/046closure_name.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -40,24 +39,24 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario closure)</span> recipe main [ - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span><span class="Normal">new</span> location:type<span class="Delimiter">,</span> <span class="Constant">30</span>:literal - <span class="Constant">1</span>:address:array:location/names:<span class="Normal">new</span>-counter<span class="Special"> <- </span><span class="Normal">new</span>-counter - <span class="Constant">2</span>:number/<span class="Special">raw <- </span>increment-counter <span class="Constant">1</span>:address:array:location/names:<span class="Normal">new</span>-counter - <span class="Constant">3</span>:number/<span class="Special">raw <- </span>increment-counter <span class="Constant">1</span>:address:array:location/names:<span class="Normal">new</span>-counter + default-space:address:array:location<span class="Special"> <- </span>new location:type<span class="Delimiter">,</span> <span class="Constant">30</span> + <span class="Constant">1</span>:address:array:location/names:new-counter<span class="Special"> <- </span>new-counter + <span class="Constant">2</span>:number/<span class="Special">raw <- </span>increment-counter <span class="Constant">1</span>:address:array:location/names:new-counter + <span class="Constant">3</span>:number/<span class="Special">raw <- </span>increment-counter <span class="Constant">1</span>:address:array:location/names:new-counter ] -recipe <span class="Normal">new</span>-counter [ - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span><span class="Normal">new</span> location:type<span class="Delimiter">,</span> <span class="Constant">30</span>:literal - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal - <span class="Normal">y</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># variable that will be incremented</span> - reply <span class="Normal">default</span>-space:address:array:location +recipe new-counter [ + default-space:address:array:location<span class="Special"> <- </span>new location:type<span class="Delimiter">,</span> <span class="Constant">30</span> + x:number<span class="Special"> <- </span>copy <span class="Constant">23</span> + y:number<span class="Special"> <- </span>copy <span class="Constant">3</span> <span class="Comment"># variable that will be incremented</span> + reply default-space:address:array:location ] recipe increment-counter [ - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span><span class="Normal">new</span> location:type<span class="Delimiter">,</span> <span class="Constant">30</span>:literal - <span class="Constant">0</span>:address:array:location/names:<span class="Normal">new</span>-counter<span class="Special"> <- </span>next-ingredient <span class="Comment"># outer space must be created by 'new-counter' above</span> - <span class="Normal">y</span>: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> - <span class="Normal">y</span>:number<span class="Special"> <- </span>copy <span class="Constant">234</span>:literal <span class="Comment"># dummy</span> + default-space:address:array:location<span class="Special"> <- </span>new location:type<span class="Delimiter">,</span> <span class="Constant">30</span> + <span class="Constant">0</span>:address:array:location/names:new-counter<span class="Special"> <- </span>next-ingredient <span class="Comment"># outer space must be created by 'new-counter' above</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> <span class="Comment"># increment</span> + y:number<span class="Special"> <- </span>copy <span class="Constant">234</span> <span class="Comment"># dummy</span> reply y:number/space:<span class="Constant">1</span> ] @@ -74,14 +73,14 @@ map<recipe_ordinal<span class="Delimiter">,</span> recipe_ordinal> Surroun Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>collect_surrounding_spaces<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> collect_surrounding_spaces<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</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="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_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> - <span class="Normal">if</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<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> != <span class="Constant">3</span> +void collect_surrounding_spaces<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<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>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_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>SIZE<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> != <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_ordinal[<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_ordinal[<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_ordinal[<span class="Constant">"location"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -89,13 +88,13 @@ map<recipe_ordinal<span class="Delimiter">,</span> recipe_ordinal> Surroun <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<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">),</span> <span class="Constant">"names"</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>s<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << <span class="Constant">"slot 0 requires a /names property in recipe "</span> << Recipe[r]<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>s<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, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>s<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, but got "</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> string surrounding_recipe_name = s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <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> + 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_ordinal[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> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> @@ -110,16 +109,16 @@ map<recipe_ordinal<span class="Delimiter">,</span> recipe_ordinal> Surroun <span class="Comment">//: /space properties.</span> <span class="Delimiter">:(replace{} "long long int lookup_name(const reagent& r, const recipe_ordinal default_recipe)")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> lookup_name<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">,</span> <span class="Normal">const</span> recipe_ordinal default_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int lookup_name<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">,</span> const recipe_ordinal default_recipe<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "AAA " << default_recipe << " " << Recipe[default_recipe].name << '\n'; //? 2</span> <span class="CommentedCode">//? cout << "AAA " << x.to_string() << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!has_property<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Name[default_recipe]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << <span class="Constant">"name not found: "</span> << x<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!has_property<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Name[default_recipe]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << <span class="Constant">"name not found: "</span> << x<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> Name[default_recipe][x<span class="Delimiter">.</span>name]<span class="Delimiter">;</span> <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>p<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> << end<span class="Delimiter">();</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> n = to_integer<span class="Delimiter">(</span>p<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>p<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> << end<span class="Delimiter">();</span> + long long int n = to_integer<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_ordinal surrounding_recipe = lookup_surrounding_recipe<span class="Delimiter">(</span>default_recipe<span class="Delimiter">,</span> n<span class="Delimiter">);</span> set<recipe_ordinal> done<span class="Delimiter">;</span> @@ -129,11 +128,11 @@ map<recipe_ordinal<span class="Delimiter">,</span> recipe_ordinal> Surroun <span class="Comment">// If the recipe we need to lookup this name in doesn't have names done yet,</span> <span class="Comment">// recursively call transform_names on it.</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> lookup_name<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">,</span> <span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">,</span> set<recipe_ordinal>& done<span class="Delimiter">,</span> vector<recipe_ordinal>& path<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Name[r]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> Name[r][x<span class="Delimiter">.</span>name]<span class="Delimiter">;</span> - <span class="Normal">if</span> <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> +long long int lookup_name<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">,</span> const recipe_ordinal r<span class="Delimiter">,</span> set<recipe_ordinal>& done<span class="Delimiter">,</span> vector<recipe_ordinal>& path<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Name[r]<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> Name[r][x<span class="Delimiter">.</span>name]<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>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> << end<span class="Delimiter">();</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>path<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>path<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << path<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Constant">1</span><span class="Delimiter">)</span> << <span class="Constant">" requires computing names of "</span> << path<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> raise << path<span class="Delimiter">.</span>at<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>path<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> << end<span class="Delimiter">();</span> @@ -146,9 +145,9 @@ map<recipe_ordinal<span class="Delimiter">,</span> recipe_ordinal> Surroun <span class="Identifier">return</span> Name[r][x<span class="Delimiter">.</span>name]<span class="Delimiter">;</span> <span class="Delimiter">}</span> -recipe_ordinal lookup_surrounding_recipe<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> n<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>n == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> r<span class="Delimiter">;</span> - <span class="Normal">if</span> <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> <span class="Delimiter">{</span> +recipe_ordinal lookup_surrounding_recipe<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">,</span> long long int n<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>n == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> r<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> <span class="Delimiter">{</span> raise << <span class="Constant">"don't know surrounding recipe of "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -158,14 +157,14 @@ recipe_ordinal lookup_surrounding_recipe<span class="Delimiter">(</span><span cl <span class="Comment">//: weaken use-before-set warnings just a tad</span> <span class="Delimiter">:(replace{} "bool already_transformed(const reagent& r, const map<string, long long int>& names)")</span> -<span class="Normal">bool</span> already_transformed<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>>& names<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> +bool already_transformed<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const map<string<span class="Delimiter">,</span> long long int>& names<span class="Delimiter">)</span> <span class="Delimiter">{</span> + 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>p<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>p<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"/space property should have exactly one (non-negative integer) value in "</span> << r<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <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> + 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/047global.cc.html b/html/047global.cc.html index 3fcf82fc..941f8c90 100644 --- a/html/047global.cc.html +++ b/html/047global.cc.html @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -40,34 +39,34 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario global_space)</span> recipe main [ <span class="Comment"># pretend arrays; 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="Constant">20</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal + <span class="Constant">10</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> + <span class="Constant">20</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># actual start of this recipe</span> - global-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">20</span>:literal - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>:literal - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal - <span class="Constant">1</span>:number/space:global<span class="Special"> <- </span>copy <span class="Constant">24</span>:literal + global-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">20</span> + default-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> + <span class="Constant">1</span>:number/space:global<span class="Special"> <- </span>copy <span class="Constant">24</span> ] <span class="traceContains">+mem: storing 23 in location 12</span> <span class="traceContains">+mem: storing 24 in location 22</span> <span class="Comment">//: to support it, create another special variable called global space</span> <span class="Delimiter">:(before "End Disqualified Reagents")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"global-space"</span><span class="Delimiter">)</span> +if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"global-space"</span><span class="Delimiter">)</span> x<span class="Delimiter">.</span>initialized = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End is_special_name Cases")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"global-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">"global-space"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">//: writes to this variable go to a field in the current routine</span> <span class="Delimiter">:(before "End routine Fields")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> global_space<span class="Delimiter">;</span> +long long int global_space<span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Constructor")</span> global_space = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(after "void write_memory(reagent x, vector<double> data)")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"global-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>data<span class="Delimiter">))</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"global-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>data<span class="Delimiter">))</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'global-space' should be of type address:array:location, but tried to write "</span> << to_string<span class="Delimiter">(</span>data<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>global_space<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>global_space<span class="Delimiter">)</span> raise << <span class="Constant">"routine already has a global-space; you can't over-write your globals"</span> << end<span class="Delimiter">();</span> Current_routine<span class="Delimiter">-></span>global_space = data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Identifier">return</span><span class="Delimiter">;</span> @@ -75,8 +74,8 @@ global_space = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">//: now marking variables as /space:global looks them up inside this field</span> <span class="Delimiter">:(after "long long int space_base(const reagent& x)")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_global<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>global_space<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>is_global<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>global_space<span class="Delimiter">)</span> raise << <span class="Constant">"routine has no global space</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> Current_routine<span class="Delimiter">-></span>global_space<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -87,22 +86,22 @@ global_space = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(scenario global_space_with_names)</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - global-space:address:array:location<span class="Special"> <- </span><span class="Normal">new</span> location:type<span class="Delimiter">,</span> <span class="Constant">10</span>:literal - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal - <span class="Constant">1</span>:number/space:global<span class="Special"> <- </span>copy <span class="Constant">24</span>:literal + global-space:address:array:location<span class="Special"> <- </span>new location:type<span class="Delimiter">,</span> <span class="Constant">10</span> + x:number<span class="Special"> <- </span>copy <span class="Constant">23</span> + <span class="Constant">1</span>:number/space:global<span class="Special"> <- </span>copy <span class="Constant">24</span> ] <span class="Comment"># don't warn that we're mixing numeric addresses and names</span> $warn: <span class="Constant">0</span> <span class="Delimiter">:(after "bool is_numeric_location(const reagent& x)")</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_global<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_global<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">//: helpers</span> <span class="Delimiter">:(code)</span> -<span class="Normal">bool</span> is_global<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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> +bool is_global<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"space"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> !x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">.</span>empty<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="Constant">"global"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> diff --git a/html/048typecheck.cc.html b/html/048typecheck.cc.html new file mode 100644 index 00000000..aafbd8f5 --- /dev/null +++ b/html/048typecheck.cc.html @@ -0,0 +1,121 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - 048typecheck.cc</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } +body { font-family: monospace; color: #eeeeee; background-color: #080808; } +* { font-size: 1.05em; } +.traceContains { color: #008000; } +.cSpecial { color: #008000; } +.Constant { color: #00a0a0; } +.Comment { color: #9090ff; } +.Delimiter { color: #a04060; } +.Special { color: #ff6060; } +.Identifier { color: #804000; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment">//: Some simple sanity checks for types, and also attempts to guess them where</span> +<span class="Comment">//: they aren't provided.</span> +<span class="Comment">//:</span> +<span class="Comment">//: You still have to provide the full type the first time you mention a</span> +<span class="Comment">//: variable in a recipe. You have to explicitly name :offset and :variant</span> +<span class="Comment">//: every single time. You can't use the same name with multiple types in a</span> +<span class="Comment">//: single recipe.</span> + +<span class="Delimiter">:(scenario transform_types_warns_on_reusing_name_with_different_type)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + x:boolean<span class="Special"> <- </span>copy <span class="Constant">1</span> +] +<span class="traceContains">+warn: x used with multiple types in main</span> + +<span class="Delimiter">:(after "int main")</span> + Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_types<span class="Delimiter">);</span> + +<span class="Delimiter">:(code)</span> +void transform_types<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + map<string<span class="Delimiter">,</span> vector<type_ordinal> > metadata<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + for <span class="Delimiter">(</span>long long int in = <span class="Constant">0</span><span class="Delimiter">;</span> in < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + deduce_missing_type<span class="Delimiter">(</span>metadata<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">));</span> + check_metadata<span class="Delimiter">(</span>metadata<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>in<span class="Delimiter">),</span> r<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + for <span class="Delimiter">(</span>long long int out = <span class="Constant">0</span><span class="Delimiter">;</span> out < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++out<span class="Delimiter">)</span> <span class="Delimiter">{</span> + deduce_missing_type<span class="Delimiter">(</span>metadata<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">));</span> + check_metadata<span class="Delimiter">(</span>metadata<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>out<span class="Delimiter">),</span> r<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> + +void check_metadata<span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> vector<type_ordinal> >& metadata<span class="Delimiter">,</span> const reagent& x<span class="Delimiter">,</span> const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_raw<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Comment">// if you use raw locations you're probably doing something unsafe</span> + if <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// will throw a more precise warning elsewhere</span> + if <span class="Delimiter">(</span>metadata<span class="Delimiter">.</span>find<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">)</span> == metadata<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + metadata[x<span class="Delimiter">.</span>name] = x<span class="Delimiter">.</span>types<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>metadata[x<span class="Delimiter">.</span>name] != x<span class="Delimiter">.</span>types<span class="Delimiter">)</span> + raise << x<span class="Delimiter">.</span>name << <span class="Constant">" used with multiple types in "</span> << Recipe[r]<span class="Delimiter">.</span>name << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario transform_types_fills_in_missing_types)</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + y:number<span class="Special"> <- </span>add x<span class="Delimiter">,</span> <span class="Constant">1</span> +] + +<span class="Delimiter">:(code)</span> +void deduce_missing_type<span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> vector<type_ordinal> >& metadata<span class="Delimiter">,</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> <span class="Identifier">return</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>metadata<span class="Delimiter">.</span>find<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">)</span> == metadata<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + copy<span class="Delimiter">(</span>metadata[x<span class="Delimiter">.</span>name]<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> metadata[x<span class="Delimiter">.</span>name]<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">,</span> x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span> + assert<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>empty<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>push_back<span class="Delimiter">(</span><span class="Constant">"as-before"</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario transform_types_fills_in_missing_types_in_product)</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + x<span class="Special"> <- </span>copy <span class="Constant">2</span> +] + +<span class="Delimiter">:(scenario transform_types_fills_in_missing_types_in_product_and_ingredient)</span> +recipe main [ + x:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + x<span class="Special"> <- </span>add x<span class="Delimiter">,</span> <span class="Constant">1</span> +] +<span class="traceContains">+mem: storing 2 in location 1</span> + +<span class="Delimiter">:(scenario transform_warns_on_missing_types_in_first_mention)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + x<span class="Special"> <- </span>copy <span class="Constant">1</span> + x:number<span class="Special"> <- </span>copy <span class="Constant">2</span> +] +<span class="traceContains">+warn: missing type in 'x <- copy 1'</span> +<span class="traceContains">+warn: x <- copy 1: reagent not initialized: x</span> +<span class="traceContains">+warn: main: size mismatch in storing to x at 'x <- copy 1'</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/050scenario.cc.html b/html/050scenario.cc.html index c6b6b2fd..dff6c56f 100644 --- a/html/050scenario.cc.html +++ b/html/050scenario.cc.html @@ -13,17 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceAbsent { color: #c00000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -45,7 +44,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario scenario_block)</span> scenario foo [ run [ - <span class="Constant">1</span>:number<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> ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">13</span> @@ -56,13 +55,13 @@ scenario foo [ <span class="Delimiter">:(scenario scenario_multiple_blocks)</span> scenario foo [ run [ - <span class="Constant">1</span>:number<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> ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">13</span> ] run [ - <span class="Constant">2</span>:number<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> ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">13</span> @@ -73,24 +72,24 @@ scenario foo [ <span class="Delimiter">:(scenario scenario_check_memory_and_trace)</span> scenario foo [ run [ - <span class="Constant">1</span>:number<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> trace [a]<span class="Delimiter">,</span> [a b c] ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">13</span> ] trace-should-contain [ - <span class="Normal">a</span>: a b c + a: a b c ] - trace-should-<span class="Normal">not</span>-contain [ - <span class="Normal">a</span>: x y z + trace-should-not-contain [ + a: x y z ] ] <span class="SalientComment">//:: Core data structure</span> <span class="Delimiter">:(before "End Types")</span> -<span class="Normal">struct</span> scenario <span class="Delimiter">{</span> +struct scenario <span class="Delimiter">{</span> string name<span class="Delimiter">;</span> string to_run<span class="Delimiter">;</span> <span class="Delimiter">};</span> @@ -102,7 +101,7 @@ vector<scenario> Scenarios<span class="Delimiter">;</span> <span class="Comment">//: Simply store the text of the scenario.</span> <span class="Delimiter">:(before "End Command Handlers")</span> -<span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>command == <span class="Constant">"scenario"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +else if <span class="Delimiter">(</span>command == <span class="Constant">"scenario"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> Scenarios<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>parse_scenario<span class="Delimiter">(</span>in<span class="Delimiter">));</span> <span class="Delimiter">}</span> @@ -129,13 +128,13 @@ scenario parse_scenario<span class="Delimiter">(</span>istream& in<span clas <span class="Delimiter">:(scenario read_scenario_with_bracket_in_comment)</span> scenario foo [ <span class="Comment"># ']' in comment</span> - <span class="Constant">1</span>:number<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> ] -<span class="traceContains">+run: 1:number <- copy 0:literal</span> +<span class="traceContains">+run: 1:number <- copy 0</span> <span class="Delimiter">:(scenario read_scenario_with_bracket_in_comment_in_nested_string)</span> scenario foo [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [<span class="Comment"># not a comment]</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [<span class="Comment"># not a comment]</span> ] <span class="traceContains">+run: 1:address:array:character <- new [# not a comment]</span> @@ -143,35 +142,35 @@ scenario foo [ <span class="Comment">//: Treat the text of the scenario as a regular series of instructions.</span> <span class="Delimiter">:(before "End Tests")</span> -<span class="Normal">time_t</span> mu_time<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&mu_time<span class="Delimiter">);</span> +time_t mu_time<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&mu_time<span class="Delimiter">);</span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">Mu tests: "</span> << ctime<span class="Delimiter">(</span>&mu_time<span class="Delimiter">);</span> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Scenarios<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Scenarios<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << Passed << '\n'; //? 1</span> <span class="CommentedCode">//? cerr << i << ": " << Scenarios.at(i).name << '\n'; //? 6</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="Normal">if</span> <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">"."</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">"."</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">//: Convenience: run a single named scenario.</span> <span class="Delimiter">:(after "Test Runs")</span> -<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Scenarios<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Scenarios<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name == argv[argc-<span class="Constant">1</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Scenarios<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[argc-<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="Normal">if</span> <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">".</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">".</span><span class="cSpecial">\n</span><span class="Constant">"</span><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">:(before "End Globals")</span> -<span class="Normal">const</span> scenario* Current_scenario = <span class="Constant">NULL</span><span class="Delimiter">;</span> +const scenario* Current_scenario = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> run_mu_scenario<span class="Delimiter">(</span><span class="Normal">const</span> scenario& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void run_mu_scenario<span class="Delimiter">(</span>const scenario& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> Current_scenario = &s<span class="Delimiter">;</span> - <span class="Normal">bool</span> not_already_inside_test = !Trace_stream<span class="Delimiter">;</span> + bool not_already_inside_test = !Trace_stream<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << s.name << '\n'; //? 12</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>not_already_inside_test<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>not_already_inside_test<span class="Delimiter">)</span> <span class="Delimiter">{</span> Trace_file = s<span class="Delimiter">.</span>name<span class="Delimiter">;</span> - Trace_stream = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> + Trace_stream = new trace_stream<span class="Delimiter">;</span> setup<span class="Delimiter">();</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> @@ -179,12 +178,12 @@ cerr << <span class="Constant">"</span><span class="cSpecial">\n</spa bind_special_scenario_names<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> transform_all<span class="Delimiter">();</span> run<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>front<span class="Delimiter">());</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>not_already_inside_test && Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>not_already_inside_test && Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> teardown<span class="Delimiter">();</span> ofstream fout<span class="Delimiter">((</span>Trace_dir+Trace_file<span class="Delimiter">).</span>c_str<span class="Delimiter">());</span> fout << Trace_stream<span class="Delimiter">-></span>readable_contents<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> fout<span class="Delimiter">.</span>close<span class="Delimiter">();</span> - <span class="Normal">delete</span> Trace_stream<span class="Delimiter">;</span> + delete Trace_stream<span class="Delimiter">;</span> Trace_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> Trace_file = <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -198,16 +197,16 @@ cerr << <span class="Constant">"</span><span class="cSpecial">\n</spa <span class="Special">% Hide_warnings = true;</span> <span class="Special">% Disable_redefine_warnings = true;</span> recipe scenario-foo [ - <span class="Constant">1</span>:number<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> ] recipe scenario-foo [ - <span class="Constant">1</span>:number<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">35</span> ] <span class="traceContains">+warn: redefining recipe scenario-foo</span> <span class="Delimiter">:(after "bool warn_on_redefine(const string& recipe_name)")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>recipe_name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"scenario-"</span><span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +if <span class="Delimiter">(</span>recipe_name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"scenario-"</span><span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="SalientComment">//:: The special instructions we want to support inside scenarios.</span> <span class="Comment">//: In a compiler for the mu VM these will require more work.</span> @@ -218,7 +217,7 @@ recipe scenario-foo [ <span class="CommentedCode">#? % Trace_stream->dump_layer = "all";</span> recipe main [ run [ - <span class="Constant">1</span>:number<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> ] ] <span class="traceContains">+mem: storing 13 in location 1</span> @@ -228,7 +227,7 @@ RUN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"run"</span>] = RUN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> RUN: <span class="Delimiter">{</span> +case RUN: <span class="Delimiter">{</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_ordinal << <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> @@ -244,7 +243,7 @@ Recipe_ordinal[<span class="Constant">"run"</span>] = RUN<span class=" <span class="Comment">// Some variables for fake resources always get special addresses in</span> <span class="Comment">// scenarios.</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> bind_special_scenario_names<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void bind_special_scenario_names<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// Special Scenario Variable Names(r)</span> <span class="Comment">// End Special Scenario Variable Names(r)</span> <span class="Delimiter">}</span> @@ -252,10 +251,10 @@ Recipe_ordinal[<span class="Constant">"run"</span>] = RUN<span class=" <span class="Delimiter">:(scenario run_multiple)</span> recipe main [ run [ - <span class="Constant">1</span>:number<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> ] run [ - <span class="Constant">2</span>:number<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> ] ] <span class="traceContains">+mem: storing 13 in location 1</span> @@ -265,7 +264,7 @@ recipe main [ <span class="Comment">//: Also includes some special support for checking strings.</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">bool</span> Scenario_testing_scenario = <span class="Constant">false</span><span class="Delimiter">;</span> +bool Scenario_testing_scenario = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Scenario_testing_scenario = <span class="Constant">false</span><span class="Delimiter">;</span> @@ -285,44 +284,44 @@ MEMORY_SHOULD_CONTAIN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"memory-should-contain"</span>] = MEMORY_SHOULD_CONTAIN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> MEMORY_SHOULD_CONTAIN: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +case MEMORY_SHOULD_CONTAIN: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><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> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> check_memory<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void check_memory<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> istringstream in<span class="Delimiter">(</span>s<span class="Delimiter">);</span> in >> std::noskipws<span class="Delimiter">;</span> - set<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> locations_checked<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + set<long long int> locations_checked<span class="Delimiter">;</span> + while <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> string lhs = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>lhs<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>lhs<span class="Delimiter">))</span> <span class="Delimiter">{</span> 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> - <span class="Normal">int</span> address = to_integer<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> + int address = to_integer<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> - <span class="Normal">int</span> value = <span class="Constant">0</span><span class="Delimiter">;</span> in >> value<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>locations_checked<span class="Delimiter">.</span>find<span class="Delimiter">(</span>address<span class="Delimiter">)</span> != locations_checked<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + int value = <span class="Constant">0</span><span class="Delimiter">;</span> in >> value<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>locations_checked<span class="Delimiter">.</span>find<span class="Delimiter">(</span>address<span class="Delimiter">)</span> != locations_checked<span class="Delimiter">.</span>end<span class="Delimiter">())</span> raise << <span class="Constant">"duplicate expectation for location "</span> << address << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"checking location "</span> << address << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[address] != value<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Memory[address] != value<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// genuine test in a mu file</span> raise << <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 location "</span> << address << <span class="Constant">" to contain "</span> << value << <span class="Constant">" but saw "</span> << Memory[address] << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> <span class="Comment">// just testing scenario support</span> raise << <span class="Constant">"expected location "</span> << address << <span class="Constant">" to contain "</span> << value << <span class="Constant">" but saw "</span> << Memory[address] << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> ++Num_failures<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -332,16 +331,16 @@ Recipe_ordinal[<span class="Constant">"memory-should-contain"</span>] <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> check_type<span class="Delimiter">(</span><span class="Normal">const</span> string& lhs<span class="Delimiter">,</span> istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +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> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<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> + 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_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">));</span> skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> string _assign = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> 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> string literal = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address = x<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + long long int 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="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> @@ -351,32 +350,32 @@ Recipe_ordinal[<span class="Constant">"memory-should-contain"</span>] raise << <span class="Constant">"don't know how to check memory for "</span> << lhs << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> check_string<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address<span class="Delimiter">,</span> <span class="Normal">const</span> string& literal<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void check_string<span class="Delimiter">(</span>long long int address<span class="Delimiter">,</span> const string& literal<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"checking string length at "</span> << address << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[address] != SIZE<span class="Delimiter">(</span>literal<span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>Memory[address] != SIZE<span class="Delimiter">(</span>literal<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</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 location "</span> << address << <span class="Constant">" to contain length "</span> << SIZE<span class="Delimiter">(</span>literal<span class="Delimiter">)</span> << <span class="Constant">" of string ["</span> << literal << <span class="Constant">"] but saw "</span> << Memory[address] << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Normal">else</span> + else raise << <span class="Constant">"expected location "</span> << address << <span class="Constant">" to contain length "</span> << SIZE<span class="Delimiter">(</span>literal<span class="Delimiter">)</span> << <span class="Constant">" of string ["</span> << literal << <span class="Constant">"] but saw "</span> << Memory[address] << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> ++Num_failures<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> ++address<span class="Delimiter">;</span> <span class="Comment">// now skip length</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>literal<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>literal<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"checking location "</span> << address+i << end<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[address+i] != literal<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</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> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// genuine test in a mu file</span> raise << <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 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> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> <span class="Comment">// just testing scenario support</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> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> ++Num_failures<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -400,10 +399,10 @@ recipe main [ <span class="Special">% Scenario_testing_scenario = true;</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <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> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">98</span> <span class="Comment"># 'b'</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">99</span> <span class="Comment"># 'c'</span> memory-should-contain [ <span class="Constant">1</span>:string<span class="Special"> <- </span>[ab] ] @@ -412,10 +411,10 @@ recipe main [ <span class="Delimiter">:(scenario memory_check_string)</span> recipe main [ - <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> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">98</span> <span class="Comment"># 'b'</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">99</span> <span class="Comment"># 'c'</span> memory-should-contain [ <span class="Constant">1</span>:string<span class="Special"> <- </span>[abc] ] @@ -436,8 +435,8 @@ recipe main [ <span class="Special">% Hide_warnings = true;</span> recipe main [ trace-should-contain [ - <span class="Normal">a</span>: b - <span class="Normal">a</span>: d + a: b + a: d ] ] <span class="traceContains">+warn: missing [b] in trace layer a</span> @@ -447,8 +446,8 @@ TRACE_SHOULD_CONTAIN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"trace-should-contain"</span>] = TRACE_SHOULD_CONTAIN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> TRACE_SHOULD_CONTAIN: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +case TRACE_SHOULD_CONTAIN: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><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> @@ -456,19 +455,19 @@ Recipe_ordinal[<span class="Constant">"trace-should-contain"</span>] = <span class="Delimiter">:(code)</span> <span class="Comment">// simplified version of check_trace_contents() that emits warnings rather</span> <span class="Comment">// than just printing to stderr</span> -<span class="Normal">bool</span> check_trace<span class="Delimiter">(</span><span class="Normal">const</span> string& expected<span class="Delimiter">)</span> <span class="Delimiter">{</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<trace_line> expected_lines = parse_trace<span class="Delimiter">(</span>expected<span class="Delimiter">);</span> <span class="CommentedCode">//? cerr << "BBB " << SIZE(expected_lines) << '\n'; //? 1</span> - <span class="Normal">if</span> <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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>label != p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>contents != trim<span class="Delimiter">(</span>p<span class="Delimiter">-></span>contents<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</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> + long long int curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>label != p<span class="Delimiter">-></span>label<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>contents != trim<span class="Delimiter">(</span>p<span class="Delimiter">-></span>contents<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> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_expected_line == SIZE<span class="Delimiter">(</span>expected_lines<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>curr_expected_line == SIZE<span class="Delimiter">(</span>expected_lines<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> @@ -480,13 +479,13 @@ Recipe_ordinal[<span class="Constant">"trace-should-contain"</span>] = <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> -vector<trace_line> parse_trace<span class="Delimiter">(</span><span class="Normal">const</span> string& expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> +vector<trace_line> parse_trace<span class="Delimiter">(</span>const string& expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> 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<trace_line> result<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>buf<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>buf<span class="Delimiter">);</span> ++i<span class="Delimiter">)</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> - <span class="Normal">if</span> <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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> + 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> + long long int 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>trace_line<span class="Delimiter">(</span>trim<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> trim<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> @@ -500,8 +499,8 @@ recipe main [ trace [a]<span class="Delimiter">,</span> [b] ] trace-should-contain [ - <span class="Normal">a</span>: b - <span class="Normal">a</span>: d + a: b + a: d ] ] <span class="traceContains">+warn: missing [d] in trace layer a</span> @@ -514,7 +513,7 @@ recipe main [ trace [a]<span class="Delimiter">,</span> [b] ] trace-should-contain [ - <span class="Normal">a</span>: b + a: b ] ] <span class="traceAbsent">-warn: missing [b] in trace layer a</span> @@ -531,8 +530,8 @@ recipe main [ run [ trace [a]<span class="Delimiter">,</span> [b] ] - trace-should-<span class="Normal">not</span>-contain [ - <span class="Normal">a</span>: b + trace-should-not-contain [ + a: b ] ] <span class="traceContains">+warn: unexpected [b] in trace layer a</span> @@ -542,8 +541,8 @@ TRACE_SHOULD_NOT_CONTAIN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<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> -<span class="Normal">case</span> TRACE_SHOULD_NOT_CONTAIN: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +case TRACE_SHOULD_NOT_CONTAIN: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><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> @@ -551,11 +550,11 @@ Recipe_ordinal[<span class="Constant">"trace-should-not-contain"</span <span class="Delimiter">:(code)</span> <span class="Comment">// simplified version of check_trace_contents() that emits warnings rather</span> <span class="Comment">// than just printing to stderr</span> -<span class="Normal">bool</span> check_trace_missing<span class="Delimiter">(</span><span class="Normal">const</span> string& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool check_trace_missing<span class="Delimiter">(</span>const string& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> vector<trace_line> lines = parse_trace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>lines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <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>label<span class="Delimiter">,</span> lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>contents<span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>lines<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<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>label<span class="Delimiter">,</span> lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>contents<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>contents << <span class="Constant">"] in trace layer "</span> << lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>label << <span class="cSpecial">'\n'</span> << end<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> @@ -568,8 +567,8 @@ Recipe_ordinal[<span class="Constant">"trace-should-not-contain"</span <span class="Special">% Scenario_testing_scenario = true;</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - trace-should-<span class="Normal">not</span>-contain [ - <span class="Normal">a</span>: b + trace-should-not-contain [ + a: b ] ] <span class="traceAbsent">-warn: unexpected [b] in trace layer a</span> @@ -582,18 +581,23 @@ recipe main [ run [ trace [a]<span class="Delimiter">,</span> [d] ] - trace-should-<span class="Normal">not</span>-contain [ - <span class="Normal">a</span>: b - <span class="Normal">a</span>: d + trace-should-not-contain [ + a: b + a: d ] ] <span class="traceContains">+warn: unexpected [d] in trace layer a</span> +<span class="Comment">//: Minor detail: ignore 'system' calls in scenarios, since anything we do</span> +<span class="Comment">//: with them is by definition impossible to test through mu.</span> +<span class="Delimiter">:(after "case _SYSTEM:")</span> + if <span class="Delimiter">(</span>Current_scenario<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="SalientComment">//:: Helpers</span> <span class="Delimiter">:(code)</span> <span class="Comment">// just for the scenarios running scenarios in C++ layers</span> -<span class="Normal">void</span> run_mu_scenario<span class="Delimiter">(</span><span class="Normal">const</span> string& form<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void run_mu_scenario<span class="Delimiter">(</span>const string& form<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << form << '\n'; //? 1</span> istringstream in<span class="Delimiter">(</span>form<span class="Delimiter">);</span> in >> std::noskipws<span class="Delimiter">;</span> diff --git a/html/051scenario_test.mu.html b/html/051scenario_test.mu.html index 4a996b81..d02cc41a 100644 --- a/html/051scenario_test.mu.html +++ b/html/051scenario_test.mu.html @@ -32,20 +32,20 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muScenario">scenario</span> first_scenario_in_mu [ run [ - 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> ] memory-should-contain [ - 1<span class="Special"> <- </span>4 + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">4</span> ] ] <span class="muScenario">scenario</span> scenario_with_comment_in_mu [ run [ <span class="Comment"># comment</span> - 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> ] memory-should-contain [ - 1<span class="Special"> <- </span>4 + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">4</span> ] ] @@ -53,40 +53,40 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } run [ <span class="Comment"># comment1</span> <span class="Comment"># comment2</span> - 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> ] memory-should-contain [ - 1<span class="Special"> <- </span>4 + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">4</span> ] ] <span class="muScenario">scenario</span> 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> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> + <span class="Constant">2</span>:character<span class="Special"> <- </span>copy <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">3</span>:character<span class="Special"> <- </span>copy <span class="Constant">98</span> <span class="Comment"># 'b'</span> + <span class="Constant">4</span>:character<span class="Special"> <- </span>copy <span class="Constant">99</span> <span class="Comment"># 'c'</span> ] memory-should-contain [ - 1:string<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant">1</span>:string<span class="Special"> <- </span><span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> check_trace [ run [ - 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> ] trace-should-contain [ - mem: storing 4 in location 1 + mem: storing <span class="Constant">4</span> in location <span class="Constant">1</span> ] ] <span class="muScenario">scenario</span> check_trace_negative [ run [ - 1:number<span class="Special"> <- </span>add <span class="Constant">2:literal</span>, <span class="Constant">2:literal</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> ] trace-should-not-contain [ - mem: storing 5 in location 1 + mem: storing <span class="Constant">5</span> in location <span class="Constant">1</span> ] ] diff --git a/html/048tangle.cc.html b/html/052tangle.cc.html index ac7d52e9..627640eb 100644 --- a/html/048tangle.cc.html +++ b/html/052tangle.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 048tangle.cc</title> +<title>Mu - 052tangle.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -38,13 +37,13 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario tangle_before)</span> recipe main [ - <span class="Constant">1</span>:number<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> +label1 - <span class="Constant">3</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> ] before +label1 [ - <span class="Constant">2</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> ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> @@ -61,12 +60,12 @@ Before_fragments<span class="Delimiter">.</span>clear<span class="Delimiter">(); After_fragments<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">:(before "End Command Handlers")</span> -<span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>command == <span class="Constant">"before"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +else if <span class="Delimiter">(</span>command == <span class="Constant">"before"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> string label = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> recipe tmp = slurp_recipe<span class="Delimiter">(</span>in<span class="Delimiter">);</span> Before_fragments[label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>Before_fragments[label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> tmp<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> tmp<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span class="Delimiter">}</span> -<span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>command == <span class="Constant">"after"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +else if <span class="Delimiter">(</span>command == <span class="Constant">"after"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> string label = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> recipe tmp = slurp_recipe<span class="Delimiter">(</span>in<span class="Delimiter">);</span> After_fragments[label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>After_fragments[label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> tmp<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> tmp<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">());</span> @@ -78,21 +77,21 @@ After_fragments<span class="Delimiter">.</span>clear<span class="Delimiter">();< Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>insert_fragments<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> insert_fragments<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void insert_fragments<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// Copy into a new vector because insertions invalidate iterators.</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> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</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="Normal">if</span> <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<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>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> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Before_fragments<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">)</span> != Before_fragments<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Before_fragments<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">)</span> != Before_fragments<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> result<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>result<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> Before_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> Before_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<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="Normal">if</span> <span class="Delimiter">(</span>After_fragments<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">)</span> != After_fragments<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>After_fragments<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">)</span> != After_fragments<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> result<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>result<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> After_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> After_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -104,15 +103,15 @@ After_fragments<span class="Delimiter">.</span>clear<span class="Delimiter">();< <span class="Delimiter">:(scenario tangle_before_and_after)</span> recipe main [ - <span class="Constant">1</span>:number<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> +label1 - <span class="Constant">4</span>:number<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> ] before +label1 [ - <span class="Constant">2</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> ] after +label1 [ - <span class="Constant">3</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> ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> @@ -124,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>:number<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> +label1 +label2 - <span class="Constant">6</span>:number<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> ] before +label1 [ - <span class="Constant">2</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> ] after +label1 [ - <span class="Constant">3</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> ] before +label2 [ - <span class="Constant">4</span>:number<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> ] after +label2 [ - <span class="Constant">5</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> ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> @@ -155,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>:number<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> +label1 - <span class="Constant">6</span>:number<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> ] before +label1 [ - <span class="Constant">2</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> ] after +label1 [ - <span class="Constant">3</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> ] before +label1 [ - <span class="Constant">4</span>:number<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> ] after +label1 [ - <span class="Constant">5</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> ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="Comment"># 'before' fragments stack in order</span> @@ -185,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>:number<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> +label1 - <span class="Constant">6</span>:number<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> ] before +label1 [ - <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 + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] after +label1 [ - <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="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> @@ -209,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>:number<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> +label1 +label1 - <span class="Constant">4</span>:number<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> ] before +label1 [ - <span class="Constant">2</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> ] after +label1 [ - <span class="Constant">3</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> ] <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> diff --git a/html/049continuation.cc.html b/html/053continuation.cc.html index 12ac59a9..1118064c 100644 --- a/html/049continuation.cc.html +++ b/html/053continuation.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 049continuation.cc</title> +<title>Mu - 053continuation.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -13,17 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceAbsent { color: #c00000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -44,8 +43,8 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment">//: todo: implement continuations in mu's memory</span> <span class="Delimiter">:(before "End Globals")</span> -map<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span><span class="Delimiter">,</span> call_stack> Continuation<span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Next_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span> +map<long long int<span class="Delimiter">,</span> call_stack> Continuation<span class="Delimiter">;</span> +long long int Next_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Continuation<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Next_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span> @@ -59,7 +58,7 @@ CURRENT_CONTINUATION<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"current-continuation"</span>] = CURRENT_CONTINUATION<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> CURRENT_CONTINUATION: <span class="Delimiter">{</span> +case CURRENT_CONTINUATION: <span class="Delimiter">{</span> <span class="Comment">// copy the current call stack</span> Continuation[Next_continuation_id] = Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">;</span> <span class="Comment">// deep copy because calls have no pointers</span> <span class="Comment">// make sure calling the copy doesn't spawn the same continuation again</span> @@ -76,12 +75,12 @@ CONTINUE_FROM<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"continue-from"</span>] = CONTINUE_FROM<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> CONTINUE_FROM: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> +case CONTINUE_FROM: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'continue-from' should be a continuation id generated by 'current-continuation', but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> + 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> Current_routine<span class="Delimiter">-></span>calls = Continuation[c]<span class="Delimiter">;</span> <span class="Comment">// deep copy; calls have no pointers</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// skip rest of this instruction</span> <span class="Delimiter">}</span> @@ -89,13 +88,13 @@ Recipe_ordinal[<span class="Constant">"continue-from"</span>] = CONTIN <span class="Delimiter">:(scenario continuation)</span> <span class="Comment"># simulate a loop using continuations</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Constant">2</span>:continuation<span class="Special"> <- </span>current-continuation <span class="Delimiter">{</span> <span class="CommentedCode">#? $print 1:number</span> - <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">3</span>:literal - <span class="Identifier">break</span>-<span class="Normal">if</span> <span class="Constant">3</span>:boolean - <span class="Constant">1</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="Constant">3</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">3</span> + <span class="Identifier">break</span>-if <span class="Constant">3</span>:boolean + <span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span> <span class="Identifier">continue</span>-from <span class="Constant">2</span>:continuation <span class="Comment"># loop</span> <span class="Delimiter">}</span> ] @@ -109,18 +108,18 @@ $current-continuation: <span class="Constant">1</span> <span class="Delimiter">:(scenario continuation_inside_caller)</span> <span class="CommentedCode">#? % Trace_stream->dump_layer = "all"; #? 1</span> recipe main [ - <span class="Constant">1</span>:number<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> <span class="Constant">2</span>:continuation<span class="Special"> <- </span>loop-body <span class="Delimiter">{</span> - <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">3</span>:literal - <span class="Identifier">break</span>-<span class="Normal">if</span> <span class="Constant">3</span>:boolean + <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">3</span> + <span class="Identifier">break</span>-if <span class="Constant">3</span>:boolean <span class="Identifier">continue</span>-from <span class="Constant">2</span>:continuation <span class="Comment"># loop</span> <span class="Delimiter">}</span> ] recipe loop-body [ <span class="Constant">4</span>:continuation<span class="Special"> <- </span>current-continuation - <span class="Constant">1</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="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 1 in location 1</span> <span class="traceContains">+mem: storing 2 in location 1</span> @@ -143,12 +142,12 @@ recipe loop-body [ <span class="Delimiter">:(scenario delimited_continuation)</span> recipe main [ - <span class="Constant">1</span>:continuation<span class="Special"> <- </span>create-delimited-continuation f:recipe <span class="Constant">12</span>:literal <span class="Comment"># 12 is an argument to f</span> - <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>:literal + <span class="Constant">1</span>:continuation<span class="Special"> <- </span>create-delimited-continuation f:recipe <span class="Constant">12</span> <span class="Comment"># 12 is an argument to f</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Delimiter">{</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>call <span class="Constant">1</span>:continuation<span class="Delimiter">,</span> <span class="Constant">2</span>:number <span class="Comment"># 2 is an argument to g, the 'top' of the continuation</span> - <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-<span class="Normal">or</span>-equal <span class="Constant">2</span>:number<span class="Delimiter">,</span> <span class="Constant">8</span>:literal - <span class="Identifier">break</span>-<span class="Normal">if</span> <span class="Constant">3</span>:boolean + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-or-equal <span class="Constant">2</span>:number<span class="Delimiter">,</span> <span class="Constant">8</span> + <span class="Identifier">break</span>-if <span class="Constant">3</span>:boolean loop <span class="Delimiter">}</span> ] @@ -165,13 +164,13 @@ recipe g [ reply-delimited-continuation <span class="Comment"># calls of the continuation start from here</span> <span class="Constant">22</span>:number<span class="Special"> <- </span>next-ingredient - <span class="Constant">23</span>:number<span class="Special"> <- </span>add <span class="Constant">22</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>:literal + <span class="Constant">23</span>:number<span class="Special"> <- </span>add <span class="Constant">22</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span> reply <span class="Constant">23</span>:number ] <span class="CommentedCode">#? ?</span> <span class="Comment"># first call of 'g' executes the part before reply-delimited-continuation</span> <span class="traceContains">+mem: storing 12 in location 21</span> -<span class="traceContains">+run: 2:number <- copy 5:literal</span> +<span class="traceContains">+run: 2:number <- copy 5</span> <span class="traceContains">+mem: storing 5 in location 2</span> <span class="Comment"># calls of the continuation execute the part after reply-delimited-continuation</span> <span class="traceContains">+run: 2:number <- call 1:continuation, 2:number</span> @@ -196,7 +195,7 @@ recipe g [ <span class="Comment">//: the call stack</span> <span class="Delimiter">:(before "End call Fields")</span> -<span class="Normal">bool</span> is_reset<span class="Delimiter">;</span> +bool is_reset<span class="Delimiter">;</span> <span class="Delimiter">:(before "End call Constructor")</span> is_reset = <span class="Constant">false</span><span class="Delimiter">;</span> @@ -207,7 +206,7 @@ CREATE_DELIMITED_CONTINUATION<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"create-delimited-continuation"</span>] = CREATE_DELIMITED_CONTINUATION<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> CREATE_DELIMITED_CONTINUATION: <span class="Delimiter">{</span> +case CREATE_DELIMITED_CONTINUATION: <span class="Delimiter">{</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>is_reset = <span class="Constant">true</span><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>Recipe_ordinal[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> ingredients<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">());</span> <span class="Comment">// drop the callee</span> @@ -218,8 +217,8 @@ Recipe_ordinal[<span class="Constant">"create-delimited-continuation"< <span class="Comment">//: call, and return it as the result.</span> <span class="Comment">//: todo: implement delimited continuations in mu's memory</span> <span class="Delimiter">:(before "End Globals")</span> -map<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span><span class="Delimiter">,</span> call_stack> Delimited_continuation<span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Next_delimited_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span> +map<long long int<span class="Delimiter">,</span> call_stack> Delimited_continuation<span class="Delimiter">;</span> +long long int Next_delimited_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Delimited_continuation<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Next_delimited_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span> @@ -229,7 +228,7 @@ REPLY_DELIMITED_CONTINUATION<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"reply-delimited-continuation"</span>] = REPLY_DELIMITED_CONTINUATION<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> REPLY_DELIMITED_CONTINUATION: <span class="Delimiter">{</span> +case REPLY_DELIMITED_CONTINUATION: <span class="Delimiter">{</span> <span class="Comment">// first clear any existing ingredients, to isolate the creation of the</span> <span class="Comment">// continuation from its calls</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> @@ -237,12 +236,12 @@ Recipe_ordinal[<span class="Constant">"reply-delimited-continuation"</ <span class="Comment">// copy the current call stack until the most recent 'reset' call</span> call_stack::iterator find_reset<span class="Delimiter">(</span>call_stack& c<span class="Delimiter">);</span> <span class="Comment">// manual prototype containing '::'</span> call_stack::iterator reset = find_reset<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>reset == Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>reset == Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": couldn't find a 'reset' call to jump out to</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> Delimited_continuation[Next_delimited_continuation_id] = call_stack<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> reset<span class="Delimiter">);</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>begin<span class="Delimiter">()</span> != reset<span class="Delimiter">)</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>begin<span class="Delimiter">()</span> != reset<span class="Delimiter">)</span> <span class="Delimiter">{</span> --Callstack_depth<span class="Delimiter">;</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>pop_front<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -255,23 +254,23 @@ Recipe_ordinal[<span class="Constant">"reply-delimited-continuation"</ <span class="Delimiter">:(code)</span> call_stack::iterator find_reset<span class="Delimiter">(</span>call_stack& c<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>call_stack::iterator p = c<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != c<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-></span>is_reset<span class="Delimiter">)</span> <span class="Identifier">return</span> p<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>call_stack::iterator p = c<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != c<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>is_reset<span class="Delimiter">)</span> <span class="Identifier">return</span> p<span class="Delimiter">;</span> <span class="Identifier">return</span> c<span class="Delimiter">.</span>end<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Comment">//: overload 'call' for continuations</span> <span class="Delimiter">:(after "Begin Call")</span> - <span class="Normal">if</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>empty<span class="Delimiter">()</span> + if <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>empty<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>empty<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">"continuation"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// copy multiple calls on to current call stack</span> assert<span class="Delimiter">(</span>scalar<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="Normal">if</span> <span class="Delimiter">(</span>Delimited_continuation<span class="Delimiter">.</span>find<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> == Delimited_continuation<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Delimited_continuation<span class="Delimiter">.</span>find<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> == Delimited_continuation<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": no such delimited continuation "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">const</span> call_stack& new_calls = Delimited_continuation[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> - <span class="Normal">for</span> <span class="Delimiter">(</span>call_stack::const_reverse_iterator p = new_calls<span class="Delimiter">.</span>rbegin<span class="Delimiter">();</span> p != new_calls<span class="Delimiter">.</span>rend<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> + const call_stack& new_calls = Delimited_continuation[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> + for <span class="Delimiter">(</span>call_stack::const_reverse_iterator p = new_calls<span class="Delimiter">.</span>rbegin<span class="Delimiter">();</span> p != new_calls<span class="Delimiter">.</span>rend<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>*p<span class="Delimiter">);</span> ++current_step_index<span class="Delimiter">();</span> <span class="Comment">// skip past the reply-delimited-continuation</span> ingredients<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">());</span> <span class="Comment">// drop the callee</span> diff --git a/html/060string.mu.html b/html/060string.mu.html index 595a96b0..9b30c7fa 100644 --- a/html/060string.mu.html +++ b/html/060string.mu.html @@ -13,14 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.muScenario { color: #00af00; } +.muRecipe { color: #ff8700; } .Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } +.muScenario { color: #00af00; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -37,67 +37,67 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">recipe</span> string-equal [ <span class="Constant">local-scope</span> a:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - a-len:number<span class="Special"> <- </span>length a:address:array:character/deref + a-len:number<span class="Special"> <- </span>length *a b:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - b-len:number<span class="Special"> <- </span>length b:address:array:character/deref + b-len:number<span class="Special"> <- </span>length *b <span class="Comment"># compare lengths</span> <span class="Delimiter">{</span> 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="muControl">break-if</span> length-equal?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal</span> + length-equal?:boolean<span class="Special"> <- </span>equal a-len, b-len + <span class="muControl">break-if</span> length-equal? + <span class="muControl">reply</span> <span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># compare each corresponding character</span> 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> + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, a-len:number - <span class="muControl">break-if</span> done?:boolean - 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 + done?:boolean<span class="Special"> <- </span>greater-or-equal i, a-len + <span class="muControl">break-if</span> done? + a2:character<span class="Special"> <- </span>index *a, i + b2:character<span class="Special"> <- </span>index *b, i <span class="Delimiter">{</span> - chars-match?:boolean<span class="Special"> <- </span>equal a2:character, b2:character - <span class="muControl">break-if</span> chars-match?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal</span> + chars-match?:boolean<span class="Special"> <- </span>equal a2, b2 + <span class="muControl">break-if</span> chars-match? + <span class="muControl">reply</span> <span class="Constant">0</span> <span class="Delimiter">}</span> - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> <span class="Constant">1:literal</span> + <span class="muControl">reply</span> <span class="Constant">1</span> ] <span class="muScenario">scenario</span> string-equal-reflexive [ run [ - <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30</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="Constant">3</span>:boolean/<span class="Special">raw <- </span>string-equal x, x ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># x == x for all x</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># x == x for all x</span> ] ] <span class="muScenario">scenario</span> string-equal-identical [ run [ - <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30</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="Constant">3</span>:boolean/<span class="Special">raw <- </span>string-equal x, y ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># abc == abc</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># abc == abc</span> ] ] <span class="muScenario">scenario</span> string-equal-distinct-lengths [ run [ - <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30</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="Constant">3</span>:boolean/<span class="Special">raw <- </span>string-equal x, y ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># abc != abcd</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># abc != abcd</span> ] trace-should-contain [ string-equal: comparing lengths @@ -109,25 +109,25 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muScenario">scenario</span> string-equal-with-empty [ run [ - <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30</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="Constant">3</span>:boolean/<span class="Special">raw <- </span>string-equal x, y ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># "" != abcd</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># "" != abcd</span> ] ] <span class="muScenario">scenario</span> string-equal-common-lengths-but-distinct [ run [ - <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30</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="Constant">3</span>:boolean/<span class="Special">raw <- </span>string-equal x, y ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># abc != abd</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># abc != abd</span> ] ] @@ -139,49 +139,49 @@ container buffer [ <span class="muRecipe">recipe</span> new-buffer [ <span class="Constant">local-scope</span> -<span class="CommentedCode">#? $print default-space:address:array:location, 10:literal/newline</span> +<span class="CommentedCode">#? $print default-space:address:array:location, 10/newline</span> result:address:buffer<span class="Special"> <- </span>new buffer:type - 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 + len:address:number<span class="Special"> <- </span>get-address *result, length:offset + *len:address:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + s:address:address:array:character<span class="Special"> <- </span>get-address *result, data:offset capacity:number, found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - assert found?:boolean, <span class="Constant">[new-buffer must get a capacity argument]</span> - 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, 10:literal/newline</span> - <span class="muControl">reply</span> result:address:buffer + assert found?, <span class="Constant">[new-buffer must get a capacity argument]</span> + *s<span class="Special"> <- </span>new character:type, capacity +<span class="CommentedCode">#? $print *s, 10/newline</span> + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> grow-buffer [ <span class="Constant">local-scope</span> in:address:buffer<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <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: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:number + x:address:address:array:character<span class="Special"> <- </span>get-address *in, data:offset + oldlen:number<span class="Special"> <- </span>length **x + newlen:number<span class="Special"> <- </span>multiply oldlen, <span class="Constant">2</span> + olddata:address:array:character<span class="Special"> <- </span>copy *x + *x<span class="Special"> <- </span>new character:type, newlen <span class="Comment"># copy old contents</span> - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, oldlen:number - <span class="muControl">break-if</span> done?:boolean - 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:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal i, oldlen + <span class="muControl">break-if</span> done? + src:character<span class="Special"> <- </span>index *olddata, i + dest:address:character<span class="Special"> <- </span>index-address **x, i + *dest<span class="Special"> <- </span>copy src + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> in:address:buffer + <span class="muControl">reply</span> in ] <span class="muRecipe">recipe</span> buffer-full? [ <span class="Constant">local-scope</span> in:address:buffer<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - 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: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="muControl">reply</span> result:boolean + len:number<span class="Special"> <- </span>get *in, length:offset + s:address:array:character<span class="Special"> <- </span>get *in, data:offset + capacity:number<span class="Special"> <- </span>length *s + result:boolean<span class="Special"> <- </span>greater-or-equal len, capacity + <span class="muControl">reply</span> result ] <span class="Comment"># in:address:buffer <- buffer-append in:address:buffer, c:character</span> @@ -189,84 +189,84 @@ container buffer [ <span class="Constant">local-scope</span> in:address:buffer<span class="Special"> <- </span><span class="Constant">next-ingredient</span> c:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - len:address:number<span class="Special"> <- </span>get-address in:address:buffer/deref, length:offset + len:address:number<span class="Special"> <- </span>get-address *in, length:offset <span class="Delimiter">{</span> <span class="Comment"># backspace? just drop last character if it exists and return</span> - backspace?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8:literal/backspace</span> - <span class="muControl">break-unless</span> backspace?:boolean - empty?:boolean<span class="Special"> <- </span>lesser-or-equal len:address:number/deref, <span class="Constant">0:literal</span> - <span class="muControl">reply-if</span> empty?:boolean, in:address:buffer/same-as-ingredient:0 - len:address:number/deref<span class="Special"> <- </span>subtract len:address:number/deref, <span class="Constant">1:literal</span> - <span class="muControl">reply</span> in:address:buffer/same-as-ingredient:0 + backspace?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">8/backspace</span> + <span class="muControl">break-unless</span> backspace? + empty?:boolean<span class="Special"> <- </span>lesser-or-equal *len, <span class="Constant">0</span> + <span class="muControl">reply-if</span> empty?, in/same-as-ingredient:<span class="Constant">0</span> + *len<span class="Special"> <- </span>subtract *len, <span class="Constant">1</span> + <span class="muControl">reply</span> in/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># grow buffer if necessary</span> - full?:boolean<span class="Special"> <- </span>buffer-full? in:address:buffer - <span class="muControl">break-unless</span> full?:boolean - in:address:buffer<span class="Special"> <- </span>grow-buffer in:address:buffer + full?:boolean<span class="Special"> <- </span>buffer-full? in + <span class="muControl">break-unless</span> full? + in<span class="Special"> <- </span>grow-buffer in <span class="Delimiter">}</span> - s:address:array:character<span class="Special"> <- </span>get in:address:buffer/deref, data:offset -<span class="CommentedCode">#? $print [array underlying buf: ], s:address:array:character, 10:literal/newline</span> -<span class="CommentedCode">#? $print [index: ], len:address:number/deref, 10:literal/newline</span> - dest:address:character<span class="Special"> <- </span>index-address s:address:array:character/deref, len:address:number/deref -<span class="CommentedCode">#? $print [storing ], c:character, [ in ], dest:address:character, 10:literal/newline</span> - dest:address:character/deref<span class="Special"> <- </span>copy c:character - len:address:number/deref<span class="Special"> <- </span>add len:address:number/deref, <span class="Constant">1:literal</span> - <span class="muControl">reply</span> in:address:buffer/same-as-ingredient:0 + s:address:array:character<span class="Special"> <- </span>get *in, data:offset +<span class="CommentedCode">#? $print [array underlying buf: ], s, 10/newline</span> +<span class="CommentedCode">#? $print [index: ], *len, 10/newline</span> + dest:address:character<span class="Special"> <- </span>index-address *s, *len +<span class="CommentedCode">#? $print [storing ], c, [ in ], dest, 10/newline</span> + *dest<span class="Special"> <- </span>copy c + *len<span class="Special"> <- </span>add *len, <span class="Constant">1</span> + <span class="muControl">reply</span> in/same-as-ingredient:<span class="Constant">0</span> ] <span class="muScenario">scenario</span> buffer-append-works [ run [ <span class="Constant">local-scope</span> - x:address:buffer<span class="Special"> <- </span>new-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, <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 - 2:array:character/<span class="Special">raw <- </span>copy s2:address:array:character/deref + x:address:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">3</span> + s1:address:array:character<span class="Special"> <- </span>get *x:address:buffer, data:offset + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">97</span> <span class="Comment"># 'a'</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">98</span> <span class="Comment"># 'b'</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">99</span> <span class="Comment"># 'c'</span> + s2:address:array:character<span class="Special"> <- </span>get *x:address:buffer, data:offset + <span class="Constant">1</span>:boolean/<span class="Special">raw <- </span>equal s1:address:array:character, s2:address:array:character + <span class="Constant">2</span>:array:character/<span class="Special">raw <- </span>copy *s2:address:array:character <span class="Constant"> +buffer-filled</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: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 + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">100</span> <span class="Comment"># 'd'</span> + s3:address:array:character<span class="Special"> <- </span>get *x:address:buffer, data:offset + <span class="Constant">10</span>:boolean/<span class="Special">raw <- </span>equal s1:address:array:character, s3:address:array:character + <span class="Constant">11</span>:number/<span class="Special">raw <- </span>get *x:address:buffer, length:offset + <span class="Constant">12</span>:array:character/<span class="Special">raw <- </span>copy *s3:address:array:character ] 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> - 3<span class="Special"> <- </span>97 <span class="Comment"># data</span> - 4<span class="Special"> <- </span>98 - 5<span class="Special"> <- </span>99 + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># no change in data pointer</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># size of data</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># data</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">98</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">99</span> <span class="Comment"># in the end</span> - 10<span class="Special"> <- </span>0 <span class="Comment"># data pointer has grown</span> - 11<span class="Special"> <- </span>4 <span class="Comment"># final length</span> - 12<span class="Special"> <- </span>6 <span class="Comment"># but data's capacity has doubled</span> - 13<span class="Special"> <- </span>97 <span class="Comment"># data</span> - 14<span class="Special"> <- </span>98 - 15<span class="Special"> <- </span>99 - 16<span class="Special"> <- </span>100 - 17<span class="Special"> <- </span>0 - 18<span class="Special"> <- </span>0 + <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># data pointer has grown</span> + <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># final length</span> + <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># but data's capacity has doubled</span> + <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># data</span> + <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">98</span> + <span class="Constant">15</span><span class="Special"> <- </span><span class="Constant">99</span> + <span class="Constant">16</span><span class="Special"> <- </span><span class="Constant">100</span> + <span class="Constant">17</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant">18</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> buffer-append-handles-backspace [ run [ <span class="Constant">local-scope</span> - x:address:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">3:literal</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">8:literal/backspace</span> + x:address:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">3</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">97</span> <span class="Comment"># 'a'</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">98</span> <span class="Comment"># 'b'</span> + x:address:buffer<span class="Special"> <- </span>buffer-append x:address:buffer, <span class="Constant">8/backspace</span> s:address:array:character<span class="Special"> <- </span>buffer-to-array x:address:buffer - 1:array:character/<span class="Special">raw <- </span>copy s:address:array:character/deref + <span class="Constant">1</span>:array:character/<span class="Special">raw <- </span>copy *s:address:array:character ] memory-should-contain [ - 1<span class="Special"> <- </span>1 <span class="Comment"># length</span> - 2<span class="Special"> <- </span>97 <span class="Comment"># contents</span> - 3<span class="Special"> <- </span>0 + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># length</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># contents</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] @@ -276,55 +276,53 @@ container buffer [ n:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># is it zero?</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> n:number + <span class="muControl">break-if</span> n result:address:array:character<span class="Special"> <- </span>new <span class="Constant">[0]</span> - <span class="muControl">reply</span> result:address:array:character + <span class="muControl">reply</span> result <span class="Delimiter">}</span> <span class="Comment"># save sign</span> - negate-result:boolean<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + negate-result:boolean<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - negative?:boolean<span class="Special"> <- </span>lesser-than n:number, <span class="Constant">0:literal</span> - <span class="muControl">break-unless</span> negative?:boolean - 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="Constant">-1:literal</span> + negative?:boolean<span class="Special"> <- </span>lesser-than n, <span class="Constant">0</span> + <span class="muControl">break-unless</span> negative? + negate-result<span class="Special"> <- </span>copy <span class="Constant">1</span> + n<span class="Special"> <- </span>multiply n, -1 <span class="Delimiter">}</span> <span class="Comment"># add digits from right to left into intermediate buffer</span> - tmp:address:buffer<span class="Special"> <- </span>new-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> + tmp:address:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> + digit-base:number<span class="Special"> <- </span>copy <span class="Constant">48</span> <span class="Comment"># '0'</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>equal n:number, <span class="Constant">0:literal</span> - <span class="muControl">break-if</span> done?:boolean - 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 + done?:boolean<span class="Special"> <- </span>equal n, <span class="Constant">0</span> + <span class="muControl">break-if</span> done? + n, digit:number<span class="Special"> <- </span>divide-with-remainder n, <span class="Constant">10</span> + c:character<span class="Special"> <- </span>add digit-base, digit + tmp:address:buffer<span class="Special"> <- </span>buffer-append tmp, c <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># add sign</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> negate-result:boolean - tmp:address:buffer<span class="Special"> <- </span>buffer-append tmp:address:buffer, <span class="Constant">45:literal</span> <span class="Comment"># '-'</span> + tmp<span class="Special"> <- </span>buffer-append tmp, <span class="Constant">45</span> <span class="Comment"># '-'</span> <span class="Delimiter">}</span> <span class="Comment"># reverse buffer into string result</span> - 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: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> + len:number<span class="Special"> <- </span>get *tmp, length:offset + buf:address:array:character<span class="Special"> <- </span>get *tmp, data:offset + result:address:array:character<span class="Special"> <- </span>new character:type, len + i:number<span class="Special"> <- </span>subtract len, <span class="Constant">1</span> <span class="Comment"># source index, decreasing</span> + j:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># destination index, increasing</span> <span class="Delimiter">{</span> <span class="Comment"># while i >= 0</span> - done?:boolean<span class="Special"> <- </span>lesser-than i:number, <span class="Constant">0:literal</span> - <span class="muControl">break-if</span> done?:boolean + done?:boolean<span class="Special"> <- </span>lesser-than i, <span class="Constant">0</span> + <span class="muControl">break-if</span> done? <span class="Comment"># result[j] = tmp[i]</span> - 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:number<span class="Special"> <- </span>subtract i:number, <span class="Constant">1:literal</span> - <span class="Comment"># --j</span> - j:number<span class="Special"> <- </span>add j:number, <span class="Constant">1:literal</span> + src:character<span class="Special"> <- </span>index *buf, i + dest:address:character<span class="Special"> <- </span>index-address *result, j + *dest<span class="Special"> <- </span>copy src + i<span class="Special"> <- </span>subtract i, <span class="Constant">1</span> + j<span class="Special"> <- </span>add j, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:character + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> buffer-to-array [ @@ -332,57 +330,57 @@ container buffer [ in:address:buffer<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># propagate null buffer</span> - <span class="muControl">break-if</span> in:address:buffer - <span class="muControl">reply</span> <span class="Constant">0:literal</span> + <span class="muControl">break-if</span> in + <span class="muControl">reply</span> <span class="Constant">0</span> <span class="Delimiter">}</span> - len:number<span class="Special"> <- </span>get in:address:buffer/deref, length:offset -<span class="CommentedCode">#? $print [size ], len:number, 10:literal/newline</span> - s:address:array:character<span class="Special"> <- </span>get in:address:buffer/deref, data:offset + len:number<span class="Special"> <- </span>get *in, length:offset +<span class="CommentedCode">#? $print [size ], len, 10/newline</span> + s:address:array:character<span class="Special"> <- </span>get *in, data:offset <span class="Comment"># we can't just return s because it is usually the wrong length</span> - result:address:array:character<span class="Special"> <- </span>new character:type, len:number - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + result:address:array:character<span class="Special"> <- </span>new character:type, len + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> -<span class="CommentedCode">#? $print i:number #? 1</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, len:number - <span class="muControl">break-if</span> done?:boolean - src:character<span class="Special"> <- </span>index s:address:array:character/deref, i:number - dest:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, i:number - dest:address:character/deref<span class="Special"> <- </span>copy src:character - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> +<span class="CommentedCode">#? $print i #? 1</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal i, len + <span class="muControl">break-if</span> done? + src:character<span class="Special"> <- </span>index *s, i + dest:address:character<span class="Special"> <- </span>index-address *result, i + *dest<span class="Special"> <- </span>copy src + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:character + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> 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="Constant">1</span>:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string <span class="Constant">0</span> + <span class="Constant">2</span>:array:character/<span class="Special">raw <- </span>copy *<span class="Constant">1</span>:address:array:character/<span class="Special">raw</span> ] memory-should-contain [ - 2:string<span class="Special"> <- </span><span class="Constant">[0]</span> + <span class="Constant">2</span>:string<span class="Special"> <- </span><span class="Constant">[0]</span> ] ] <span class="muScenario">scenario</span> 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="Constant">1</span>:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string <span class="Constant">234</span> + <span class="Constant">2</span>:array:character/<span class="Special">raw <- </span>copy *<span class="Constant">1</span>:address:array:character/<span class="Special">raw</span> ] memory-should-contain [ - 2:string<span class="Special"> <- </span><span class="Constant">[234]</span> + <span class="Constant">2</span>:string<span class="Special"> <- </span><span class="Constant">[234]</span> ] ] <span class="muScenario">scenario</span> integer-to-decimal-digit-negative [ run [ - 1:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string <span class="Constant">-1:literal</span> - 2:array:character/<span class="Special">raw <- </span>copy 1:address:array:character/deref/<span class="Special">raw</span> + <span class="Constant">1</span>:address:array:character/<span class="Special">raw <- </span>integer-to-decimal-string -1 + <span class="Constant">2</span>:array:character/<span class="Special">raw <- </span>copy *<span class="Constant">1</span>:address:array:character/<span class="Special">raw</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="Constant">2</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">45</span> <span class="Comment"># '-'</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">49</span> <span class="Comment"># '1'</span> ] ] @@ -391,56 +389,52 @@ container buffer [ <span class="Constant">local-scope</span> <span class="Comment"># result = new character[a.length + b.length]</span> a:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - a-len:number<span class="Special"> <- </span>length a:address:array:character/deref + a-len:number<span class="Special"> <- </span>length *a b:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - 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 + b-len:number<span class="Special"> <- </span>length *b + result-len:number<span class="Special"> <- </span>add a-len, b-len + result:address:array:character<span class="Special"> <- </span>new character:type, result-len <span class="Comment"># copy a into result</span> - 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> + result-idx:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># while i < a.length</span> - a-done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, a-len:number - <span class="muControl">break-if</span> a-done?:boolean + a-done?:boolean<span class="Special"> <- </span>greater-or-equal i, a-len + <span class="muControl">break-if</span> a-done? <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: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:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> - <span class="Comment"># ++result-idx</span> - result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> + out:address:character<span class="Special"> <- </span>index-address *result, result-idx + in:character<span class="Special"> <- </span>index *a, i + *out<span class="Special"> <- </span>copy in + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + result-idx<span class="Special"> <- </span>add result-idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># copy b into result</span> - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + i<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># while i < b.length</span> - b-done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, b-len:number - <span class="muControl">break-if</span> b-done?:boolean + b-done?:boolean<span class="Special"> <- </span>greater-or-equal i, b-len + <span class="muControl">break-if</span> b-done? <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: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:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> - <span class="Comment"># ++result-idx</span> - result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> + out:address:character<span class="Special"> <- </span>index-address *result, result-idx + in:character<span class="Special"> <- </span>index *b, i + *out<span class="Special"> <- </span>copy in + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + result-idx<span class="Special"> <- </span>add result-idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:character + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> 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="Constant">1</span>:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[hello,]</span> + <span class="Constant">2</span>:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[ world!]</span> + <span class="Constant">3</span>:address:array:character/<span class="Special">raw <- </span>string-append <span class="Constant">1</span>:address:array:character/<span class="Special">raw</span>, <span class="Constant">2</span>:address:array:character/<span class="Special">raw</span> + <span class="Constant">4</span>:array:character/<span class="Special">raw <- </span>copy *<span class="Constant">3</span>:address:array:character/<span class="Special">raw</span> ] memory-should-contain [ - 4:string<span class="Special"> <- </span><span class="Constant">[hello, world!]</span> + <span class="Constant">4</span>:string<span class="Special"> <- </span><span class="Constant">[hello, world!]</span> ] ] @@ -450,122 +444,115 @@ container buffer [ <span class="Constant">local-scope</span> template:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># compute result-len, space to allocate for result</span> - tem-len:number<span class="Special"> <- </span>length template:address:array:character/deref - result-len:number<span class="Special"> <- </span>copy tem-len:number + tem-len:number<span class="Special"> <- </span>length *template + result-len:number<span class="Special"> <- </span>copy tem-len <span class="Delimiter">{</span> <span class="Comment"># while arg received</span> a:address:array:character, arg-received?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">break-unless</span> arg-received?:boolean - <span class="Comment"># result-len = result-len + arg.length - 1 for the 'underscore' being replaced</span> - 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="muControl">break-unless</span> arg-received? + <span class="Comment"># result-len = result-len + arg.length - 1 (for the 'underscore' being replaced)</span> + a-len:number<span class="Special"> <- </span>length *a + result-len<span class="Special"> <- </span>add result-len, a-len + result-len<span class="Special"> <- </span>subtract result-len, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> -<span class="CommentedCode">#? $print tem-len:number, [ ], $result-len:number, 10:literal/newline</span> +<span class="CommentedCode">#? $print tem-len, [ ], $result-len, 10/newline</span> rewind-ingredients _<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <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:number + result:address:array:character<span class="Special"> <- </span>new character:type, result-len <span class="Comment"># repeatedly copy sections of template and 'holes' into result</span> - 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> + result-idx:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># while arg received</span> a:address:array:character, arg-received?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">break-unless</span> arg-received?:boolean + <span class="muControl">break-unless</span> arg-received? <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:number, tem-len:number - <span class="muControl">break-if</span> tem-done?:boolean, <span class="Constant">+done:label</span> + tem-done?:boolean<span class="Special"> <- </span>greater-or-equal i, tem-len + <span class="muControl">break-if</span> tem-done?, <span class="Constant">+done:label</span> <span class="Comment"># while template[i] != '_'</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="muControl">break-if</span> underscore?:boolean + in:character<span class="Special"> <- </span>index *template, i + underscore?:boolean<span class="Special"> <- </span>equal in, <span class="Constant">95/_</span> + <span class="muControl">break-if</span> underscore? <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:number - out:address:character/deref<span class="Special"> <- </span>copy in:character - <span class="Comment"># ++i</span> - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> - <span class="Comment"># ++result-idx</span> - result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> + out:address:character<span class="Special"> <- </span>index-address *result, result-idx + *out<span class="Special"> <- </span>copy in + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + result-idx<span class="Special"> <- </span>add result-idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># copy 'a' into result</span> - j:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + j:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># while j < a.length</span> - arg-done?:boolean<span class="Special"> <- </span>greater-or-equal j:number, a-len:number - <span class="muControl">break-if</span> arg-done?:boolean + arg-done?:boolean<span class="Special"> <- </span>greater-or-equal j, a-len + <span class="muControl">break-if</span> arg-done? <span class="Comment"># result[result-idx] = a[j]</span> - 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:number<span class="Special"> <- </span>add j:number, <span class="Constant">1:literal</span> - <span class="Comment"># ++result-idx</span> - result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> + in:character<span class="Special"> <- </span>index *a, j + out:address:character<span class="Special"> <- </span>index-address *result, result-idx + *out<span class="Special"> <- </span>copy in + j<span class="Special"> <- </span>add j, <span class="Constant">1</span> + result-idx<span class="Special"> <- </span>add result-idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># skip '_' in template</span> - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Comment"># interpolate next arg</span> <span class="Delimiter">}</span> <span class="Constant"> +done</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:number, tem-len:number - <span class="muControl">break-if</span> tem-done?:boolean + tem-done?:boolean<span class="Special"> <- </span>greater-or-equal i, tem-len + <span class="muControl">break-if</span> tem-done? <span class="Comment"># result[result-idx] = template[i]</span> - 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:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> - <span class="Comment"># ++result-idx</span> - result-idx:number<span class="Special"> <- </span>add result-idx:number, <span class="Constant">1:literal</span> + in:character<span class="Special"> <- </span>index *template, i + out:address:character<span class="Special"> <- </span>index-address *result, result-idx:number + *out<span class="Special"> <- </span>copy in + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + result-idx<span class="Special"> <- </span>add result-idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:character + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> interpolate-works [ <span class="CommentedCode">#? dump run #? 1</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="Constant">1</span>:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[abc _]</span> + <span class="Constant">2</span>:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[def]</span> + <span class="Constant">3</span>:address:array:character/<span class="Special">raw <- </span>interpolate <span class="Constant">1</span>:address:array:character/<span class="Special">raw</span>, <span class="Constant">2</span>:address:array:character/<span class="Special">raw</span> + <span class="Constant">4</span>:array:character/<span class="Special">raw <- </span>copy *<span class="Constant">3</span>:address:array:character/<span class="Special">raw</span> ] memory-should-contain [ - 4:string<span class="Special"> <- </span><span class="Constant">[abc def]</span> + <span class="Constant">4</span>:string<span class="Special"> <- </span><span class="Constant">[abc def]</span> ] ] <span class="muScenario">scenario</span> 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="Constant">1</span>:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[_, hello!]</span> + <span class="Constant">2</span>:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">3</span>:address:array:character/<span class="Special">raw <- </span>interpolate <span class="Constant">1</span>:address:array:character/<span class="Special">raw</span>, <span class="Constant">2</span>:address:array:character/<span class="Special">raw</span> + <span class="Constant">4</span>:array:character/<span class="Special">raw <- </span>copy *<span class="Constant">3</span>:address:array:character/<span class="Special">raw</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="Constant">4</span>:string<span class="Special"> <- </span><span class="Constant">[abc, hello!]</span> + <span class="Constant">16</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># out of bounds</span> ] ] <span class="muScenario">scenario</span> 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="Constant">1</span>:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[hello, _]</span> + <span class="Constant">2</span>:address:array:character/<span class="Special">raw <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">3</span>:address:array:character/<span class="Special">raw <- </span>interpolate <span class="Constant">1</span>:address:array:character/<span class="Special">raw</span>, <span class="Constant">2</span>:address:array:character/<span class="Special">raw</span> + <span class="Constant">4</span>:array:character/<span class="Special">raw <- </span>copy *<span class="Constant">3</span>:address:array:character/<span class="Special">raw</span> ] memory-should-contain [ - 4:string<span class="Special"> <- </span><span class="Constant">[hello, abc]</span> + <span class="Constant">4</span>:string<span class="Special"> <- </span><span class="Constant">[hello, abc]</span> ] ] @@ -574,274 +561,274 @@ container buffer [ <span class="Constant">local-scope</span> c:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># most common case first</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">32:literal/space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">9:literal/tab</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">13:literal/carriage-return</span> + result:boolean<span class="Special"> <- </span>equal c, <span class="Constant">32/space</span> + <span class="muControl">jump-if</span> result <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">9/tab</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">13/carriage-return</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> <span class="Comment"># remaining uncommon cases in sorted order</span> <span class="Comment"># <a href="http://unicode.org">http://unicode.org</a> code-points in unicode-set Z and Pattern_White_Space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">11:literal/ctrl-k</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">12:literal/ctrl-l</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">133:literal/ctrl-0085</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">160:literal/no-break-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">5760:literal/ogham-space-mark</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8192:literal/en-quad</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8193:literal/em-quad</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8194:literal/en-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8195:literal/em-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8196:literal/three-per-em-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8197:literal/four-per-em-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8198:literal/six-per-em-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8199:literal/figure-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8200:literal/punctuation-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8201:literal/thin-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8202:literal/hair-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8206:literal/left-to-right</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8207:literal/right-to-left</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8232:literal/line-separator</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8233:literal/paragraph-separator</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8239:literal/narrow-no-break-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">8287:literal/medium-mathematical-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> - result:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">12288:literal/ideographic-space</span> - <span class="muControl">jump-if</span> result:boolean, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">11/ctrl-k</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">12/ctrl-l</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">133/ctrl-0085</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">160/no-break-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">5760/ogham-space-mark</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8192/en-quad</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8193/em-quad</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8194/en-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8195/em-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8196/three-per-em-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8197/four-per-em-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8198/six-per-em-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8199/figure-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8200/punctuation-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8201/thin-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8202/hair-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8206/left-to-right</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8207/right-to-left</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8232/line-separator</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8233/paragraph-separator</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8239/narrow-no-break-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">8287/medium-mathematical-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> + result<span class="Special"> <- </span>equal c, <span class="Constant">12288/ideographic-space</span> + <span class="muControl">jump-if</span> result, <span class="Constant">+reply:label</span> <span class="Constant"> +reply</span> - <span class="muControl">reply</span> result:boolean + <span class="muControl">reply</span> result ] <span class="Comment"># result:address:array:character <- trim s:address:array:character</span> <span class="muRecipe">recipe</span> trim [ <span class="Constant">local-scope</span> s:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - len:number<span class="Special"> <- </span>length s:address:array:character/deref + len:number<span class="Special"> <- </span>length *s <span class="Comment"># left trim: compute start</span> - start:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + start:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Delimiter">{</span> - at-end?:boolean<span class="Special"> <- </span>greater-or-equal start:number, len:number - <span class="muControl">break-unless</span> at-end?:boolean - result:address:array:character<span class="Special"> <- </span>new character:type, <span class="Constant">0:literal</span> - <span class="muControl">reply</span> result:address:array:character + at-end?:boolean<span class="Special"> <- </span>greater-or-equal start, len + <span class="muControl">break-unless</span> at-end? + result:address:array:character<span class="Special"> <- </span>new character:type, <span class="Constant">0</span> + <span class="muControl">reply</span> result <span class="Delimiter">}</span> - curr:character<span class="Special"> <- </span>index s:address:array:character/deref, start:number - whitespace?:boolean<span class="Special"> <- </span>space? curr:character - <span class="muControl">break-unless</span> whitespace?:boolean - start:number<span class="Special"> <- </span>add start:number, <span class="Constant">1:literal</span> + curr:character<span class="Special"> <- </span>index *s, start + whitespace?:boolean<span class="Special"> <- </span>space? curr + <span class="muControl">break-unless</span> whitespace? + start<span class="Special"> <- </span>add start, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># right trim: compute end</span> - end:number<span class="Special"> <- </span>subtract len:number, <span class="Constant">1:literal</span> + end:number<span class="Special"> <- </span>subtract len, <span class="Constant">1</span> <span class="Delimiter">{</span> - not-at-start?:boolean<span class="Special"> <- </span>greater-than end:number, start:number - assert not-at-start?:boolean <span class="Constant">[end ran up against start]</span> - curr:character<span class="Special"> <- </span>index s:address:array:character/deref, end:number - whitespace?:boolean<span class="Special"> <- </span>space? curr:character - <span class="muControl">break-unless</span> whitespace?:boolean - end:number<span class="Special"> <- </span>subtract end:number, <span class="Constant">1:literal</span> + not-at-start?:boolean<span class="Special"> <- </span>greater-than end, start + assert not-at-start?, <span class="Constant">[end ran up against start]</span> + curr:character<span class="Special"> <- </span>index *s, end + whitespace?:boolean<span class="Special"> <- </span>space? curr + <span class="muControl">break-unless</span> whitespace? + end<span class="Special"> <- </span>subtract end, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># result = new character[end+1 - start]</span> - new-len:number<span class="Special"> <- </span>subtract end:number, start:number, <span class="Constant">-1:literal</span> - result:address:array:character<span class="Special"> <- </span>new character:type, new-len:number + new-len:number<span class="Special"> <- </span>subtract end, start, -1 + result:address:array:character<span class="Special"> <- </span>new character:type, new-len <span class="Comment"># i = start, j = 0</span> - i:number<span class="Special"> <- </span>copy start:number - j:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + i:number<span class="Special"> <- </span>copy start + j:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># while i <= end</span> - done?:boolean<span class="Special"> <- </span>greater-than i:number, end:number - <span class="muControl">break-if</span> done?:boolean + done?:boolean<span class="Special"> <- </span>greater-than i, end + <span class="muControl">break-if</span> done? <span class="Comment"># result[j] = s[i]</span> - src:character<span class="Special"> <- </span>index s: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, ++j</span> - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> - j:number<span class="Special"> <- </span>add j:number, <span class="Constant">1:literal</span> + src:character<span class="Special"> <- </span>index *s, i + dest:address:character<span class="Special"> <- </span>index-address *result, j + *dest<span class="Special"> <- </span>copy src + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + j<span class="Special"> <- </span>add j, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:character + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> trim-unmodified [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>trim 1:address:array:character - 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>trim <span class="Constant">1</span>:address:array:character + <span class="Constant">3</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character ] memory-should-contain [ - 3:string<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant">3</span>:string<span class="Special"> <- </span><span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> trim-left [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ abc]</span> - 2:address:array:character<span class="Special"> <- </span>trim 1:address:array:character - 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>trim <span class="Constant">1</span>:address:array:character + <span class="Constant">3</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character ] memory-should-contain [ - 3:string<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant">3</span>:string<span class="Special"> <- </span><span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> trim-right [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc ]</span> - 2:address:array:character<span class="Special"> <- </span>trim 1:address:array:character - 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc ]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>trim <span class="Constant">1</span>:address:array:character + <span class="Constant">3</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character ] memory-should-contain [ - 3:string<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant">3</span>:string<span class="Special"> <- </span><span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> trim-left-right [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ abc ]</span> - 2:address:array:character<span class="Special"> <- </span>trim 1:address:array:character - 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ abc ]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>trim <span class="Constant">1</span>:address:array:character + <span class="Constant">3</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character ] memory-should-contain [ - 3:string<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant">3</span>:string<span class="Special"> <- </span><span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> trim-newline-tab [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ abc</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ abc</span> <span class="Constant">]</span> - 2:address:array:character<span class="Special"> <- </span>trim 1:address:array:character - 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>trim <span class="Constant">1</span>:address:array:character + <span class="Constant">3</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character ] memory-should-contain [ - 3:string<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant">3</span>:string<span class="Special"> <- </span><span class="Constant">[abc]</span> ] ] -<span class="Comment"># next-index:number <- find-next text:address:array:character, pattern:character</span> +<span class="Comment"># next-index:number <- find-next text:address:array:character, pattern:character, idx:number</span> <span class="muRecipe">recipe</span> find-next [ <span class="Constant">local-scope</span> text:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> pattern:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> idx:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - len:number<span class="Special"> <- </span>length text:address:array:character/deref + len:number<span class="Special"> <- </span>length *text <span class="Delimiter">{</span> - eof?:boolean<span class="Special"> <- </span>greater-or-equal idx:number, len:number - <span class="muControl">break-if</span> eof?:boolean - curr:character<span class="Special"> <- </span>index text:address:array:character/deref, idx:number - found?:boolean<span class="Special"> <- </span>equal curr:character, pattern:character - <span class="muControl">break-if</span> found?:boolean - idx:number<span class="Special"> <- </span>add idx:number, <span class="Constant">1:literal</span> + eof?:boolean<span class="Special"> <- </span>greater-or-equal idx, len + <span class="muControl">break-if</span> eof? + curr:character<span class="Special"> <- </span>index *text, idx + found?:boolean<span class="Special"> <- </span>equal curr, pattern + <span class="muControl">break-if</span> found? + idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> idx:number + <span class="muControl">reply</span> idx ] <span class="muScenario">scenario</span> string-find-next [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> - 2:number<span class="Special"> <- </span>find-next 1:address:array:character, <span class="Constant">47:literal/slash</span>, <span class="Constant">0:literal/start-index</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>find-next <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - 2<span class="Special"> <- </span>1 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> ] ] <span class="muScenario">scenario</span> string-find-next-empty [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 2:number<span class="Special"> <- </span>find-next 1:address:array:character, <span class="Constant">47:literal/slash</span>, <span class="Constant">0:literal/start-index</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>find-next <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - 2<span class="Special"> <- </span>0 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> string-find-next-initial [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[/abc]</span> - 2:number<span class="Special"> <- </span>find-next 1:address:array:character, <span class="Constant">47:literal/slash</span>, <span class="Constant">0:literal/start-index</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[/abc]</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>find-next <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - 2<span class="Special"> <- </span>0 <span class="Comment"># prefix match</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># prefix match</span> ] ] <span class="muScenario">scenario</span> string-find-next-final [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc/]</span> - 2:number<span class="Special"> <- </span>find-next 1:address:array:character, <span class="Constant">47:literal/slash</span>, <span class="Constant">0:literal/start-index</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc/]</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>find-next <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - 2<span class="Special"> <- </span>3 <span class="Comment"># suffix match</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># suffix match</span> ] ] <span class="muScenario">scenario</span> string-find-next-missing [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:number<span class="Special"> <- </span>find-next 1:address:array:character, <span class="Constant">47:literal/slash</span>, <span class="Constant">0:literal/start-index</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>find-next <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - 2<span class="Special"> <- </span>3 <span class="Comment"># no match</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># no match</span> ] ] <span class="muScenario">scenario</span> string-find-next-invalid-index [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:number<span class="Special"> <- </span>find-next 1:address:array:character, <span class="Constant">47:literal/slash</span>, <span class="Constant">4:literal/start-index</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>find-next <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span>, <span class="Constant">4/start-index</span> ] memory-should-contain [ - 2<span class="Special"> <- </span>4 <span class="Comment"># no change</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># no change</span> ] ] <span class="muScenario">scenario</span> string-find-next-first [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab/c/]</span> - 2:number<span class="Special"> <- </span>find-next 1:address:array:character, <span class="Constant">47:literal/slash</span>, <span class="Constant">0:literal/start-index</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab/c/]</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>find-next <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - 2<span class="Special"> <- </span>2 <span class="Comment"># first '/' of multiple</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># first '/' of multiple</span> ] ] <span class="muScenario">scenario</span> string-find-next-second [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab/c/]</span> - 2:number<span class="Special"> <- </span>find-next 1:address:array:character, <span class="Constant">47:literal/slash</span>, <span class="Constant">3:literal/start-index</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab/c/]</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>find-next <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span>, <span class="Constant">3/start-index</span> ] memory-should-contain [ - 2<span class="Special"> <- </span>4 <span class="Comment"># second '/' of multiple</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># second '/' of multiple</span> ] ] +<span class="Comment"># idx:number <- find-substring text:address:array:character, pattern:address:array:character, idx:number</span> <span class="Comment"># like find-next, but searches for multiple characters</span> <span class="Comment"># fairly dumb algorithm</span> <span class="muRecipe">recipe</span> find-substring [ @@ -849,75 +836,75 @@ container buffer [ text:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> pattern:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> idx:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - first:character<span class="Special"> <- </span>index pattern:address:array:character/deref, <span class="Constant">0:literal</span> + first:character<span class="Special"> <- </span>index *pattern, <span class="Constant">0</span> <span class="Comment"># repeatedly check for match at current idx</span> - len:number<span class="Special"> <- </span>length text:address:array:character/deref + len:number<span class="Special"> <- </span>length *text <span class="Delimiter">{</span> <span class="Comment"># does some unnecessary work checking for substrings even when there isn't enough of text left</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal idx:number, len:number - <span class="muControl">break-if</span> done?:boolean - found?:boolean<span class="Special"> <- </span>match-at text:address:array:character pattern:address:array:character, idx:number - <span class="muControl">break-if</span> found?:boolean - idx:number<span class="Special"> <- </span>add idx:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal idx, len + <span class="muControl">break-if</span> done? + found?:boolean<span class="Special"> <- </span>match-at text, pattern, idx + <span class="muControl">break-if</span> found? + idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> <span class="Comment"># optimization: skip past indices that definitely won't match</span> - idx:number<span class="Special"> <- </span>find-next text:address:array:character, first:character, idx:number + idx<span class="Special"> <- </span>find-next text, first, idx <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> idx:number + <span class="muControl">reply</span> idx ] <span class="muScenario">scenario</span> find-substring-1 [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bc]</span> - 3:number<span class="Special"> <- </span>find-substring 1:address:array:character, 2:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bc]</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>find-substring <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> ] ] <span class="muScenario">scenario</span> find-substring-2 [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bc]</span> - 3:number<span class="Special"> <- </span>find-substring 1:address:array:character, 2:address:array:character, <span class="Constant">1:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bc]</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>find-substring <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">1</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> ] ] <span class="muScenario">scenario</span> find-substring-no-match [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bd]</span> - 3:number<span class="Special"> <- </span>find-substring 1:address:array:character, 2:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bd]</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>find-substring <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>3 <span class="Comment"># not found</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># not found</span> ] ] <span class="muScenario">scenario</span> find-substring-suffix-match [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[cd]</span> - 3:number<span class="Special"> <- </span>find-substring 1:address:array:character, 2:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[cd]</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>find-substring <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>2 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> ] ] <span class="muScenario">scenario</span> find-substring-suffix-match-2 [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[cde]</span> - 3:number<span class="Special"> <- </span>find-substring 1:address:array:character, 2:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[cde]</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>find-substring <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>4 <span class="Comment"># not found</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># not found</span> ] ] @@ -928,128 +915,128 @@ container buffer [ text:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> pattern:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> idx:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - pattern-len:number<span class="Special"> <- </span>length pattern:address:array:character/deref + pattern-len:number<span class="Special"> <- </span>length *pattern <span class="Comment"># check that there's space left for the pattern</span> <span class="Delimiter">{</span> - x:number<span class="Special"> <- </span>length text:address:array:character/deref - x:number<span class="Special"> <- </span>subtract x:number, pattern-len:number - enough-room?:boolean<span class="Special"> <- </span>lesser-or-equal idx:number, x:number - <span class="muControl">break-if</span> enough-room?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal/not-found</span> + x:number<span class="Special"> <- </span>length *text + x<span class="Special"> <- </span>subtract x, pattern-len + enough-room?:boolean<span class="Special"> <- </span>lesser-or-equal idx, x + <span class="muControl">break-if</span> enough-room? + <span class="muControl">reply</span> <span class="Constant">0/not-found</span> <span class="Delimiter">}</span> <span class="Comment"># check each character of pattern</span> - pattern-idx:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + pattern-idx:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal pattern-idx:number, pattern-len:number - <span class="muControl">break-if</span> done?:boolean - c:character<span class="Special"> <- </span>index text:address:array:character/deref, idx:number - exp:character<span class="Special"> <- </span>index pattern:address:array:character/deref, pattern-idx:number + done?:boolean<span class="Special"> <- </span>greater-or-equal pattern-idx, pattern-len + <span class="muControl">break-if</span> done? + c:character<span class="Special"> <- </span>index *text, idx + exp:character<span class="Special"> <- </span>index *pattern, pattern-idx <span class="Delimiter">{</span> - match?:boolean<span class="Special"> <- </span>equal c:character, exp:character - <span class="muControl">break-if</span> match?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal/not-found</span> + match?:boolean<span class="Special"> <- </span>equal c, exp + <span class="muControl">break-if</span> match? + <span class="muControl">reply</span> <span class="Constant">0/not-found</span> <span class="Delimiter">}</span> - idx:number<span class="Special"> <- </span>add idx:number, <span class="Constant">1:literal</span> - pattern-idx:number<span class="Special"> <- </span>add pattern-idx:number, <span class="Constant">1:literal</span> + idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> + pattern-idx<span class="Special"> <- </span>add pattern-idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> <span class="Constant">1:literal/found</span> + <span class="muControl">reply</span> <span class="Constant">1/found</span> ] <span class="muScenario">scenario</span> match-at-checks-substring-at-index [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 2:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># match found</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># match found</span> ] ] <span class="muScenario">scenario</span> match-at-reflexive [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 1:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">1</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># match found</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># match found</span> ] ] <span class="muScenario">scenario</span> match-at-outside-bounds [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 2:address:array:character, <span class="Constant">4:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">4</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># never matches</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># never matches</span> ] ] <span class="muScenario">scenario</span> match-at-empty-pattern [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 2:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># always matches empty pattern given a valid index</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># always matches empty pattern given a valid index</span> ] ] <span class="muScenario">scenario</span> match-at-empty-pattern-outside-bound [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 2:address:array:character, <span class="Constant">4:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">4</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># no match</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no match</span> ] ] <span class="muScenario">scenario</span> match-at-empty-text [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 2:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># no match</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no match</span> ] ] <span class="muScenario">scenario</span> match-at-empty-against-empty [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 1:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">1</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># matches because pattern is also empty</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># matches because pattern is also empty</span> ] ] <span class="muScenario">scenario</span> match-at-inside-bounds [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bc]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 2:address:array:character, <span class="Constant">1:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bc]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">1</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># matches inner substring</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># matches inner substring</span> ] ] <span class="muScenario">scenario</span> match-at-inside-bounds-2 [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bc]</span> - 3:boolean<span class="Special"> <- </span>match-at 1:address:array:character, 2:address:array:character, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[bc]</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>match-at <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character, <span class="Constant">0</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># no match</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no match</span> ] ] @@ -1059,127 +1046,127 @@ container buffer [ s:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> delim:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># empty string? return empty array</span> - len:number<span class="Special"> <- </span>length s:address:array:character/deref + len:number<span class="Special"> <- </span>length *s <span class="Delimiter">{</span> - empty?:boolean<span class="Special"> <- </span>equal len:number, <span class="Constant">0:literal</span> - <span class="muControl">break-unless</span> empty?:boolean - result:address:array:address:array:character<span class="Special"> <- </span>new location:type, <span class="Constant">0:literal</span> - <span class="muControl">reply</span> result:address:array:address:array:character + empty?:boolean<span class="Special"> <- </span>equal len, <span class="Constant">0</span> + <span class="muControl">break-unless</span> empty? + result:address:array:address:array:character<span class="Special"> <- </span>new location:type, <span class="Constant">0</span> + <span class="muControl">reply</span> result <span class="Delimiter">}</span> <span class="Comment"># count #pieces we need room for</span> - count:number<span class="Special"> <- </span>copy <span class="Constant">1:literal</span> <span class="Comment"># n delimiters = n+1 pieces</span> - idx:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + count:number<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Comment"># n delimiters = n+1 pieces</span> + idx:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - idx:number<span class="Special"> <- </span>find-next s:address:array:character, delim:character, idx:number - done?:boolean<span class="Special"> <- </span>greater-or-equal idx:number, len:number - <span class="muControl">break-if</span> done?:boolean - idx:number<span class="Special"> <- </span>add idx:number, <span class="Constant">1:literal</span> - count:number<span class="Special"> <- </span>add count:number, <span class="Constant">1:literal</span> + idx<span class="Special"> <- </span>find-next s, delim, idx + done?:boolean<span class="Special"> <- </span>greater-or-equal idx, len + <span class="muControl">break-if</span> done? + idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> + count<span class="Special"> <- </span>add count, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># allocate space</span> - result:address:array:address:array:character<span class="Special"> <- </span>new location:type, count:number + result:address:array:address:array:character<span class="Special"> <- </span>new location:type, count <span class="Comment"># repeatedly copy slices start..end until delimiter into result[curr-result]</span> - curr-result:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - start:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + curr-result:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + start:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># while next delim exists</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal start:number, len:number - <span class="muControl">break-if</span> done?:boolean - end:number<span class="Special"> <- </span>find-next s:address:array:character, delim:character, start:number + done?:boolean<span class="Special"> <- </span>greater-or-equal start, len + <span class="muControl">break-if</span> done? + end:number<span class="Special"> <- </span>find-next s, delim, start <span class="Comment"># copy start..end into result[curr-result]</span> - dest:address:address:array:character<span class="Special"> <- </span>index-address result:address:array:address:array:character/deref, curr-result:number - dest:address:address:array:character/deref<span class="Special"> <- </span>string-copy s:address:array:character, start:number, end:number + dest:address:address:array:character<span class="Special"> <- </span>index-address *result, curr-result + *dest<span class="Special"> <- </span>string-copy s, start, end <span class="Comment"># slide over to next slice</span> - start:number<span class="Special"> <- </span>add end:number, <span class="Constant">1:literal</span> - curr-result:number<span class="Special"> <- </span>add curr-result:number, <span class="Constant">1:literal</span> + start<span class="Special"> <- </span>add end, <span class="Constant">1</span> + curr-result<span class="Special"> <- </span>add curr-result, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:address:array:character + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> string-split-1 [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> - 2:address:array:address:array:character<span class="Special"> <- </span>split 1:address:array:character, <span class="Constant">47:literal/slash</span> - 3:number<span class="Special"> <- </span>length 2:address:array:address:array:character/deref - 4:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">0:literal</span> - 5:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">1:literal</span> - 10:array:character<span class="Special"> <- </span>copy 4:address:array:character/deref - 20:array:character<span class="Special"> <- </span>copy 5:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> + <span class="Constant">2</span>:address:array:address:array:character<span class="Special"> <- </span>split <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>length *<span class="Constant">2</span>:address:array:address:array:character + <span class="Constant">4</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">0</span> + <span class="Constant">5</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">1</span> + <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">4</span>:address:array:character + <span class="Constant">20</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">5</span>:address:array:character ] memory-should-contain [ - 3<span class="Special"> <- </span>2 <span class="Comment"># length of result</span> - 10:string<span class="Special"> <- </span><span class="Constant">[a]</span> - 20:string<span class="Special"> <- </span><span class="Constant">[b]</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># length of result</span> + <span class="Constant">10</span>:string<span class="Special"> <- </span><span class="Constant">[a]</span> + <span class="Constant">20</span>:string<span class="Special"> <- </span><span class="Constant">[b]</span> ] ] <span class="muScenario">scenario</span> string-split-2 [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b/c]</span> - 2:address:array:address:array:character<span class="Special"> <- </span>split 1:address:array:character, <span class="Constant">47:literal/slash</span> - 3:number<span class="Special"> <- </span>length 2:address:array:address:array:character/deref - 4:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">0:literal</span> - 5:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">1:literal</span> - 6:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">2:literal</span> - 10:array:character<span class="Special"> <- </span>copy 4:address:array:character/deref - 20:array:character<span class="Special"> <- </span>copy 5:address:array:character/deref - 30:array:character<span class="Special"> <- </span>copy 6:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b/c]</span> + <span class="Constant">2</span>:address:array:address:array:character<span class="Special"> <- </span>split <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>length *<span class="Constant">2</span>:address:array:address:array:character + <span class="Constant">4</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">0</span> + <span class="Constant">5</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">1</span> + <span class="Constant">6</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">2</span> + <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">4</span>:address:array:character + <span class="Constant">20</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">5</span>:address:array:character + <span class="Constant">30</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">6</span>:address:array:character ] memory-should-contain [ - 3<span class="Special"> <- </span>3 <span class="Comment"># length of result</span> - 10:string<span class="Special"> <- </span><span class="Constant">[a]</span> - 20:string<span class="Special"> <- </span><span class="Constant">[b]</span> - 30:string<span class="Special"> <- </span><span class="Constant">[c]</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># length of result</span> + <span class="Constant">10</span>:string<span class="Special"> <- </span><span class="Constant">[a]</span> + <span class="Constant">20</span>:string<span class="Special"> <- </span><span class="Constant">[b]</span> + <span class="Constant">30</span>:string<span class="Special"> <- </span><span class="Constant">[c]</span> ] ] <span class="muScenario">scenario</span> string-split-missing [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:address:array:character<span class="Special"> <- </span>split 1:address:array:character, <span class="Constant">47:literal/slash</span> - 3:number<span class="Special"> <- </span>length 2:address:array:address:array:character/deref - 4:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">0:literal</span> - 10:array:character<span class="Special"> <- </span>copy 4:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:address:array:character<span class="Special"> <- </span>split <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>length *<span class="Constant">2</span>:address:array:address:array:character + <span class="Constant">4</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">0</span> + <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">4</span>:address:array:character ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># length of result</span> - 10:string<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># length of result</span> + <span class="Constant">10</span>:string<span class="Special"> <- </span><span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> string-split-empty [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 2:address:array:address:array:character<span class="Special"> <- </span>split 1:address:array:character, <span class="Constant">47:literal/slash</span> - 3:number<span class="Special"> <- </span>length 2:address:array:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">2</span>:address:array:address:array:character<span class="Special"> <- </span>split <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>length *<span class="Constant">2</span>:address:array:address:array:character ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># empty result</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty result</span> ] ] <span class="muScenario">scenario</span> string-split-empty-piece [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b//c]</span> - 2:address:array:address:array:character<span class="Special"> <- </span>split 1:address:array:character, <span class="Constant">47:literal/slash</span> - 3:number<span class="Special"> <- </span>length 2:address:array:address:array:character/deref - 4:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">0:literal</span> - 5:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">1:literal</span> - 6:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">2:literal</span> - 7:address:array:character<span class="Special"> <- </span>index 2:address:array:address:array:character/deref, <span class="Constant">3:literal</span> - 10:array:character<span class="Special"> <- </span>copy 4:address:array:character/deref - 20:array:character<span class="Special"> <- </span>copy 5:address:array:character/deref - 30:array:character<span class="Special"> <- </span>copy 6:address:array:character/deref - 40:array:character<span class="Special"> <- </span>copy 7:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b//c]</span> + <span class="Constant">2</span>:address:array:address:array:character<span class="Special"> <- </span>split <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>length *<span class="Constant">2</span>:address:array:address:array:character + <span class="Constant">4</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">0</span> + <span class="Constant">5</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">1</span> + <span class="Constant">6</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">2</span> + <span class="Constant">7</span>:address:array:character<span class="Special"> <- </span>index *<span class="Constant">2</span>:address:array:address:array:character, <span class="Constant">3</span> + <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">4</span>:address:array:character + <span class="Constant">20</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">5</span>:address:array:character + <span class="Constant">30</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">6</span>:address:array:character + <span class="Constant">40</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">7</span>:address:array:character ] memory-should-contain [ - 3<span class="Special"> <- </span>4 <span class="Comment"># length of result</span> - 10:string<span class="Special"> <- </span><span class="Constant">[a]</span> - 20:string<span class="Special"> <- </span><span class="Constant">[b]</span> - 30:string<span class="Special"> <- </span><span class="Constant">[]</span> - 40:string<span class="Special"> <- </span><span class="Constant">[c]</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># length of result</span> + <span class="Constant">10</span>:string<span class="Special"> <- </span><span class="Constant">[a]</span> + <span class="Constant">20</span>:string<span class="Special"> <- </span><span class="Constant">[b]</span> + <span class="Constant">30</span>:string<span class="Special"> <- </span><span class="Constant">[]</span> + <span class="Constant">40</span>:string<span class="Special"> <- </span><span class="Constant">[c]</span> ] ] @@ -1189,31 +1176,31 @@ container buffer [ text:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> delim:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># empty string? return empty strings</span> - len:number<span class="Special"> <- </span>length text:address:array:character/deref + len:number<span class="Special"> <- </span>length *text <span class="Delimiter">{</span> - empty?:boolean<span class="Special"> <- </span>equal len:number, <span class="Constant">0:literal</span> - <span class="muControl">break-unless</span> empty?:boolean + empty?:boolean<span class="Special"> <- </span>equal len, <span class="Constant">0</span> + <span class="muControl">break-unless</span> empty? 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">[]</span> - <span class="muControl">reply</span> x:address:array:character, y:address:array:character + <span class="muControl">reply</span> x, y <span class="Delimiter">}</span> - idx:number<span class="Special"> <- </span>find-next text:address:array:character, delim:character, <span class="Constant">0:literal</span> - x:address:array:character<span class="Special"> <- </span>string-copy text:address:array:character, <span class="Constant">0:literal</span>, idx:number - idx:number<span class="Special"> <- </span>add idx:number, <span class="Constant">1:literal</span> - y:address:array:character<span class="Special"> <- </span>string-copy text:address:array:character, idx:number, len:number - <span class="muControl">reply</span> x:address:array:character, y:address:array:character + idx:number<span class="Special"> <- </span>find-next text, delim, <span class="Constant">0</span> + x:address:array:character<span class="Special"> <- </span>string-copy text, <span class="Constant">0</span>, idx + idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> + y:address:array:character<span class="Special"> <- </span>string-copy text, idx, len + <span class="muControl">reply</span> x, y ] <span class="muScenario">scenario</span> string-split-first [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> - 2:address:array:character, 3:address:array:character<span class="Special"> <- </span>split-first 1:address:array:character, <span class="Constant">47:literal/slash</span> - 10:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref - 20:array:character<span class="Special"> <- </span>copy 3:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> + <span class="Constant">2</span>:address:array:character, <span class="Constant">3</span>:address:array:character<span class="Special"> <- </span>split-first <span class="Constant">1</span>:address:array:character, <span class="Constant">47/slash</span> + <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character + <span class="Constant">20</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">3</span>:address:array:character ] memory-should-contain [ - 10:string<span class="Special"> <- </span><span class="Constant">[a]</span> - 20:string<span class="Special"> <- </span><span class="Constant">[b]</span> + <span class="Constant">10</span>:string<span class="Special"> <- </span><span class="Constant">[a]</span> + <span class="Constant">20</span>:string<span class="Special"> <- </span><span class="Constant">[b]</span> ] ] @@ -1225,57 +1212,57 @@ container buffer [ start:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> end:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if end is out of bounds, trim it</span> - len:number<span class="Special"> <- </span>length buf:address:array:character/deref - end:number<span class="Special"> <- </span>min len:number, end:number + len:number<span class="Special"> <- </span>length *buf + end:number<span class="Special"> <- </span>min len, end <span class="Comment"># allocate space for result</span> - len:number<span class="Special"> <- </span>subtract end:number, start:number - result:address:array:character<span class="Special"> <- </span>new character:type, len:number + len<span class="Special"> <- </span>subtract end, start + result:address:array:character<span class="Special"> <- </span>new character:type, len <span class="Comment"># copy start..end into result[curr-result]</span> - src-idx:number<span class="Special"> <- </span>copy start:number - dest-idx:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + src-idx:number<span class="Special"> <- </span>copy start + dest-idx:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal src-idx:number, end:number - <span class="muControl">break-if</span> done?:boolean - src:character<span class="Special"> <- </span>index buf:address:array:character/deref, src-idx:number - dest:address:character<span class="Special"> <- </span>index-address result:address:array:character/deref, dest-idx:number - dest:address:character/deref<span class="Special"> <- </span>copy src:character - src-idx:number<span class="Special"> <- </span>add src-idx:number, <span class="Constant">1:literal</span> - dest-idx:number<span class="Special"> <- </span>add dest-idx:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal src-idx, end + <span class="muControl">break-if</span> done? + src:character<span class="Special"> <- </span>index *buf, src-idx + dest:address:character<span class="Special"> <- </span>index-address *result, dest-idx + *dest<span class="Special"> <- </span>copy src + src-idx<span class="Special"> <- </span>add src-idx, <span class="Constant">1</span> + dest-idx<span class="Special"> <- </span>add dest-idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:character + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> string-copy-copies-substring [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>string-copy 1:address:array:character, <span class="Constant">1:literal</span>, <span class="Constant">3:literal</span> - 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>string-copy <span class="Constant">1</span>:address:array:character, <span class="Constant">1</span>, <span class="Constant">3</span> + <span class="Constant">3</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character ] memory-should-contain [ - 3:string<span class="Special"> <- </span><span class="Constant">[bc]</span> + <span class="Constant">3</span>:string<span class="Special"> <- </span><span class="Constant">[bc]</span> ] ] <span class="muScenario">scenario</span> string-copy-out-of-bounds [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>string-copy 1:address:array:character, <span class="Constant">2:literal</span>, <span class="Constant">4:literal</span> - 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>string-copy <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>, <span class="Constant">4</span> + <span class="Constant">3</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character ] memory-should-contain [ - 3:string<span class="Special"> <- </span><span class="Constant">[c]</span> + <span class="Constant">3</span>:string<span class="Special"> <- </span><span class="Constant">[c]</span> ] ] <span class="muScenario">scenario</span> string-copy-out-of-bounds-2 [ run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>string-copy 1:address:array:character, <span class="Constant">3:literal</span>, <span class="Constant">3:literal</span> - 3:array:character<span class="Special"> <- </span>copy 2:address:array:character/deref + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>string-copy <span class="Constant">1</span>:address:array:character, <span class="Constant">3</span>, <span class="Constant">3</span> + <span class="Constant">3</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:character ] memory-should-contain [ - 3:string<span class="Special"> <- </span><span class="Constant">[]</span> + <span class="Constant">3</span>:string<span class="Special"> <- </span><span class="Constant">[]</span> ] ] @@ -1284,11 +1271,11 @@ container buffer [ x:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> y:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - return-x?:boolean<span class="Special"> <- </span>lesser-than x:number, y:number - <span class="muControl">break-if</span> return-x?:boolean - <span class="muControl">reply</span> y:number + return-x?:boolean<span class="Special"> <- </span>lesser-than x, y + <span class="muControl">break-if</span> return-x? + <span class="muControl">reply</span> y <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:number + <span class="muControl">reply</span> x ] <span class="muRecipe">recipe</span> max [ @@ -1296,11 +1283,11 @@ container buffer [ x:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> y:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - return-x?:boolean<span class="Special"> <- </span>greater-than x:number, y:number - <span class="muControl">break-if</span> return-x?:boolean - <span class="muControl">reply</span> y:number + return-x?:boolean<span class="Special"> <- </span>greater-than x, y + <span class="muControl">break-if</span> return-x? + <span class="muControl">reply</span> y <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:number + <span class="muControl">reply</span> x ] </pre> </body> diff --git a/html/061channel.mu.html b/html/061channel.mu.html index 913265de..89df9b83 100644 --- a/html/061channel.mu.html +++ b/html/061channel.mu.html @@ -14,14 +14,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .muScenario { color: #00af00; } -.SalientComment { color: #00ffff; } .Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } +.muRecipe { color: #ff8700; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -45,12 +44,12 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muScenario">scenario</span> channel [ run [ - 1:address:channel<span class="Special"> <- </span>new-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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">34</span> + <span class="Constant">2</span>:number, <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>read <span class="Constant">1</span>:address:channel ] memory-should-contain [ - 2<span class="Special"> <- </span>34 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">34</span> ] ] @@ -72,17 +71,17 @@ container channel [ <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: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> + full:address:number<span class="Special"> <- </span>get-address *result, first-full:offset + *full<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># result.first-free = 0</span> - 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> + free:address:number<span class="Special"> <- </span>get-address *result, first-free:offset + *free<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># result.data = new location[ingredient+1]</span> capacity:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - 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:number - <span class="muControl">reply</span> result:address:channel + capacity<span class="Special"> <- </span>add capacity, <span class="Constant">1</span> <span class="Comment"># unused slot for 'full?' below</span> + dest:address:address:array:location<span class="Special"> <- </span>get-address *result, data:offset + *dest<span class="Special"> <- </span>new location:type, capacity + <span class="muControl">reply</span> result ] <span class="Comment"># chan:address:channel <- write chan:address:channel, val:location</span> @@ -92,26 +91,26 @@ container channel [ val:location<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <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="muControl">break-unless</span> full:boolean - 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 + full:boolean<span class="Special"> <- </span>channel-full? chan + <span class="muControl">break-unless</span> full + full-address:address:number<span class="Special"> <- </span>get-address *chan, first-full:offset + wait-for-location *full-address <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: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:number/deref<span class="Special"> <- </span>add free:address:number/deref, <span class="Constant">1:literal</span> + circular-buffer:address:array:location<span class="Special"> <- </span>get *chan, data:offset + free:address:number<span class="Special"> <- </span>get-address *chan, first-free:offset + dest:address:location<span class="Special"> <- </span>index-address *circular-buffer, *free + *dest<span class="Special"> <- </span>copy val + <span class="Comment"># mark its slot as filled</span> + *free<span class="Special"> <- </span>add *free, <span class="Constant">1</span> <span class="Delimiter">{</span> <span class="Comment"># wrap free around to 0 if necessary</span> - 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="muControl">break-unless</span> at-end?:boolean - free:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + len:number<span class="Special"> <- </span>length *circular-buffer + at-end?:boolean<span class="Special"> <- </span>greater-or-equal *free, len + <span class="muControl">break-unless</span> at-end? + *free<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> chan:address:channel/same-as-ingredient:0 + <span class="muControl">reply</span> chan/same-as-ingredient:<span class="Constant">0</span> ] <span class="Comment"># result:location, chan:address:channel <- read chan:address:channel</span> @@ -120,99 +119,99 @@ container channel [ chan:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <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="muControl">break-unless</span> empty:boolean - 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 + empty?:boolean<span class="Special"> <- </span>channel-empty? chan + <span class="muControl">break-unless</span> empty? + free-address:address:number<span class="Special"> <- </span>get-address *chan, first-free:offset + wait-for-location *free-address <span class="Delimiter">}</span> <span class="Comment"># read result</span> - 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:number/deref + full:address:number<span class="Special"> <- </span>get-address *chan, first-full:offset + circular-buffer:address:array:location<span class="Special"> <- </span>get *chan, data:offset + result:location<span class="Special"> <- </span>index *circular-buffer, *full <span class="Comment"># increment full</span> - full:address:number/deref<span class="Special"> <- </span>add full:address:number/deref, <span class="Constant">1:literal</span> + *full<span class="Special"> <- </span>add *full, <span class="Constant">1</span> <span class="Delimiter">{</span> <span class="Comment"># wrap full around to 0 if necessary</span> - 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="muControl">break-unless</span> at-end?:boolean - full:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + len:number<span class="Special"> <- </span>length *circular-buffer + at-end?:boolean<span class="Special"> <- </span>greater-or-equal *full, len + <span class="muControl">break-unless</span> at-end? + *full<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:location, chan:address:channel/same-as-ingredient:0 + <span class="muControl">reply</span> result, chan/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> clear-channel [ <span class="Constant">local-scope</span> chan:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - empty?:boolean<span class="Special"> <- </span>channel-empty? chan:address:channel - <span class="muControl">break-if</span> empty?:boolean - _, chan:address:channel<span class="Special"> <- </span>read chan:address:channel + empty?:boolean<span class="Special"> <- </span>channel-empty? chan + <span class="muControl">break-if</span> empty? + _, chan<span class="Special"> <- </span>read chan <span class="Delimiter">}</span> - <span class="muControl">reply</span> chan:address:channel/same-as-ingredient:0 + <span class="muControl">reply</span> chan/same-as-ingredient:<span class="Constant">0</span> ] <span class="muScenario">scenario</span> channel-initialization [ run [ - 1:address:channel<span class="Special"> <- </span>new-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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, first-full:offset + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, 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="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-full</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-free</span> ] ] <span class="muScenario">scenario</span> channel-write-increments-free [ run [ - 1:address:channel<span class="Special"> <- </span>new-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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, first-full:offset + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, 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="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-full</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-free</span> ] ] <span class="muScenario">scenario</span> channel-read-increments-full [ run [ - 1:address:channel<span class="Special"> <- </span>new-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: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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">34</span> + _, <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>read <span class="Constant">1</span>:address:channel + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, first-full:offset + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, 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="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-full</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-free</span> ] ] <span class="muScenario">scenario</span> channel-wrap [ run [ <span class="Comment"># channel with just 1 slot</span> - 1:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">1:literal/capacity</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">1/capacity</span> <span class="Comment"># write and read a value</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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">34</span> + _, <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>read <span class="Constant">1</span>:address:channel <span class="Comment"># first-free will now be 1</span> - 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="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, first-free:offset + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, 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, <span class="Constant">34:literal</span> - 4:number<span class="Special"> <- </span>get 1:address:channel/deref, first-free:offset + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">34</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, 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:number<span class="Special"> <- </span>get 1:address:channel/deref, first-full:offset + _, <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>read <span class="Constant">1</span>:address:channel + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:channel, 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="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-free after first write</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-full after first read</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-free after second write, wrapped</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-full after second read, wrapped</span> ] ] @@ -223,10 +222,10 @@ container channel [ <span class="Constant">local-scope</span> chan:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># return chan.first-full == chan.first-free</span> - 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="muControl">reply</span> result:boolean + full:number<span class="Special"> <- </span>get *chan, first-full:offset + free:number<span class="Special"> <- </span>get *chan, first-free:offset + result:boolean<span class="Special"> <- </span>equal full, free + <span class="muControl">reply</span> result ] <span class="Comment"># A full channel has first-empty just before first-full, wasting one slot.</span> @@ -235,79 +234,79 @@ container channel [ <span class="Constant">local-scope</span> chan:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># tmp = chan.first-free + 1</span> - 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> + tmp:number<span class="Special"> <- </span>get *chan, first-free:offset + tmp<span class="Special"> <- </span>add tmp, <span class="Constant">1</span> <span class="Delimiter">{</span> <span class="Comment"># if tmp == chan.capacity, tmp = 0</span> - 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="muControl">break-unless</span> at-end?:boolean - tmp:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + len:number<span class="Special"> <- </span>channel-capacity chan + at-end?:boolean<span class="Special"> <- </span>greater-or-equal tmp, len + <span class="muControl">break-unless</span> at-end? + tmp<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># return chan.first-full == tmp</span> - 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="muControl">reply</span> result:boolean + full:number<span class="Special"> <- </span>get *chan, first-full:offset + result:boolean<span class="Special"> <- </span>equal full, tmp + <span class="muControl">reply</span> result ] <span class="Comment"># result:number <- channel-capacity chan:address:channel</span> <span class="muRecipe">recipe</span> channel-capacity [ <span class="Constant">local-scope</span> chan:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - q:address:array:location<span class="Special"> <- </span>get chan:address:channel/deref, data:offset - result:number<span class="Special"> <- </span>length q:address:array:location/deref - <span class="muControl">reply</span> result:number + q:address:array:location<span class="Special"> <- </span>get *chan, data:offset + result:number<span class="Special"> <- </span>length *q + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> channel-new-empty-not-full [ run [ - 1:address:channel<span class="Special"> <- </span>new-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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">1</span>:address:channel + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>channel-full? <span class="Constant">1</span>: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="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># empty?</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># full?</span> ] ] <span class="muScenario">scenario</span> channel-write-not-empty [ run [ - 1:address:channel<span class="Special"> <- </span>new-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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">34</span> + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">1</span>:address:channel + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>channel-full? <span class="Constant">1</span>: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="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty?</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># full?</span> ] ] <span class="muScenario">scenario</span> channel-write-full [ run [ - 1:address:channel<span class="Special"> <- </span>new-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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">1/capacity</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">34</span> + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">1</span>:address:channel + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>channel-full? <span class="Constant">1</span>: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="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty?</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># full?</span> ] ] <span class="muScenario">scenario</span> channel-read-not-full [ run [ - 1:address:channel<span class="Special"> <- </span>new-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:boolean<span class="Special"> <- </span>channel-empty? 1:address:channel - 3:boolean<span class="Special"> <- </span>channel-full? 1:address:channel + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">1/capacity</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">34</span> + _, <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>read <span class="Constant">1</span>:address:channel + <span class="Constant">2</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">1</span>:address:channel + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>channel-full? <span class="Constant">1</span>: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="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># empty?</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># full?</span> ] ] @@ -315,105 +314,90 @@ container channel [ <span class="Comment"># out:address:channel <- buffer-lines in:address:channel, out:address:channel</span> <span class="muRecipe">recipe</span> buffer-lines [ <span class="Constant">local-scope</span> -<span class="CommentedCode">#? $print [buffer-lines: aaa</span> -<span class="CommentedCode">#? ]</span> in:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> out:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># repeat forever</span> <span class="Delimiter">{</span> - line:address:buffer<span class="Special"> <- </span>new-buffer, <span class="Constant">30:literal</span> + line:address:buffer<span class="Special"> <- </span>new-buffer, <span class="Constant">30</span> <span class="Comment"># read characters from 'in' until newline, copy into line</span> <span class="Delimiter">{</span> <span class="Constant"> +next-character</span> - c:character, in:address:channel<span class="Special"> <- </span>read in:address:channel + c:character, in<span class="Special"> <- </span>read in <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="muControl">break-unless</span> backspace?:boolean + backspace?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">8</span> + <span class="muControl">break-unless</span> backspace? <span class="Comment"># drop previous character</span> -<span class="CommentedCode">#? close-console #? 2</span> -<span class="CommentedCode">#? $print [backspace!</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="muControl">break-if</span> buffer-empty?:boolean -<span class="CommentedCode">#? $print [before: ], buffer-length:address:number/deref, 10:literal/newline</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, 10:literal/newline</span> + buffer-length:address:number<span class="Special"> <- </span>get-address *line, length:offset + buffer-empty?:boolean<span class="Special"> <- </span>equal *buffer-length, <span class="Constant">0</span> + <span class="muControl">break-if</span> buffer-empty? + *buffer-length<span class="Special"> <- </span>subtract *buffer-length, <span class="Constant">1</span> <span class="Delimiter">}</span> -<span class="CommentedCode">#? $exit #? 2</span> <span class="Comment"># and don't append this one</span> <span class="muControl">loop</span> <span class="Constant">+next-character:label</span> <span class="Delimiter">}</span> <span class="Comment"># append anything else</span> -<span class="CommentedCode">#? $print [buffer-lines: appending ], c:character, 10:literal/newline</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="muControl">break-if</span> line-done?:boolean + line<span class="Special"> <- </span>buffer-append line, c + line-done?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">break-if</span> line-done? <span class="Comment"># stop buffering on eof (currently only generated by fake console)</span> - eof?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">0:literal/eof</span> - <span class="muControl">break-if</span> eof?:boolean + eof?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">0/eof</span> + <span class="muControl">break-if</span> eof? <span class="muControl">loop</span> <span class="Delimiter">}</span> -<span class="CommentedCode">#? close-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 + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + line-contents:address:array:character<span class="Special"> <- </span>get *line, data:offset + max:number<span class="Special"> <- </span>get *line, length:offset <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, max:number - <span class="muControl">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, 10:literal/newline</span> - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal i, max + <span class="muControl">break-if</span> done? + c:character<span class="Special"> <- </span>index *line-contents, i + out<span class="Special"> <- </span>write out, c + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> -<span class="CommentedCode">#? $dump-trace #? 1</span> -<span class="CommentedCode">#? $exit #? 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> out:address:channel/same-as-ingredient:1 + <span class="muControl">reply</span> out/same-as-ingredient:<span class="Constant">1</span> ] <span class="muScenario">scenario</span> buffer-lines-blocks-until-newline [ run [ - 1:address:channel/stdin<span class="Special"> <- </span>new-channel <span class="Constant">10:literal/capacity</span> - 2:address:channel/buffered-stdin<span class="Special"> <- </span>new-channel <span class="Constant">10:literal/capacity</span> - 3:boolean<span class="Special"> <- </span>channel-empty? 2:address:channel/buffered-stdin - assert 3:boolean, [ + <span class="Constant">1</span>:address:channel/stdin<span class="Special"> <- </span>new-channel <span class="Constant">10/capacity</span> + <span class="Constant">2</span>:address:channel/buffered-stdin<span class="Special"> <- </span>new-channel <span class="Constant">10/capacity</span> + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">2</span>:address:channel/buffered-stdin + assert <span class="Constant">3</span>:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty <span class="muRecipe">after</span> 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:<span class="muRecipe">recipe</span>, 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, [ + <span class="Constant">4</span>:number/buffer-routine<span class="Special"> <- </span>start-running buffer-lines:<span class="muRecipe">recipe</span>, <span class="Constant">1</span>:address:channel/stdin, <span class="Constant">2</span>:address:channel/buffered-stdin + wait-for-routine <span class="Constant">4</span>:number/buffer-routine + <span class="Constant">5</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">2</span>:address:channel/buffered-stdin + assert <span class="Constant">5</span>:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty <span class="muRecipe">after</span> 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, [ + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">97/a</span> + restart <span class="Constant">4</span>:number/buffer-routine + wait-for-routine <span class="Constant">4</span>:number/buffer-routine + <span class="Constant">6</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">2</span>:address:channel/buffered-stdin + assert <span class="Constant">6</span>:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty <span class="muRecipe">after</span> writing 'a'] <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, [ + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">98/b</span> + restart <span class="Constant">4</span>:number/buffer-routine + wait-for-routine <span class="Constant">4</span>:number/buffer-routine + <span class="Constant">7</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">2</span>:address:channel/buffered-stdin + assert <span class="Constant">7</span>:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty <span class="muRecipe">after</span> writing 'b'] <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?, [ + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">10/newline</span> + restart <span class="Constant">4</span>:number/buffer-routine + wait-for-routine <span class="Constant">4</span>:number/buffer-routine + <span class="Constant">8</span>:boolean<span class="Special"> <- </span>channel-empty? <span class="Constant">2</span>:address:channel/buffered-stdin + <span class="Constant">9</span>:boolean/completed?<span class="Special"> <- </span>not <span class="Constant">8</span>:boolean + assert <span class="Constant">9</span>:boolean/completed?, [ F buffer-lines-blocks-until-newline: channel should contain data <span class="muRecipe">after</span> writing newline] trace <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> ] diff --git a/html/062array.mu.html b/html/062array.mu.html index 50b72162..55169dfe 100644 --- a/html/062array.mu.html +++ b/html/062array.mu.html @@ -15,11 +15,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .muScenario { color: #00af00; } .Delimiter { color: #a04060; } +.muRecipe { color: #ff8700; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -33,43 +33,43 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <pre id='vimCodeElement'> <span class="muScenario">scenario</span> array-from-args [ run [ - 1:address:array:location<span class="Special"> <- </span>new-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="Constant">1</span>:address:array:location<span class="Special"> <- </span>new-array <span class="Constant">0</span>, <span class="Constant">1</span>, <span class="Constant">2</span> + <span class="Constant">2</span>:array:location<span class="Special"> <- </span>copy *<span class="Constant">1</span>:address:array:location ] 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="Constant">2</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># array length</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</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">2</span> ] ] <span class="Comment"># create an array out of a list of scalar args</span> <span class="muRecipe">recipe</span> new-array [ <span class="Constant">local-scope</span> - capacity:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + capacity:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># while read curr-value</span> curr-value:location, exists?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">break-unless</span> exists?:boolean - capacity:number<span class="Special"> <- </span>add capacity:number, <span class="Constant">1:literal</span> + <span class="muControl">break-unless</span> exists? + capacity<span class="Special"> <- </span>add capacity, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - result:address:array:location<span class="Special"> <- </span>new location:type, capacity:number + result:address:array:location<span class="Special"> <- </span>new location:type, capacity rewind-ingredients - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># while read curr-value</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, capacity:number - <span class="muControl">break-if</span> done?:boolean + done?:boolean<span class="Special"> <- </span>greater-or-equal i, capacity + <span class="muControl">break-if</span> done? curr-value:location, exists?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - assert exists?:boolean, <span class="Constant">[error in rewinding ingredients to new-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:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + assert exists?, <span class="Constant">[error in rewinding ingredients to new-array]</span> + tmp:address:location<span class="Special"> <- </span>index-address *result, i + *tmp<span class="Special"> <- </span>copy curr-value + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:location + <span class="muControl">reply</span> result ] </pre> </body> diff --git a/html/063list.mu.html b/html/063list.mu.html index 9763729b..50060a5f 100644 --- a/html/063list.mu.html +++ b/html/063list.mu.html @@ -13,13 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .muScenario { color: #00af00; } -.CommentedCode { color: #6c6c6c; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -47,48 +47,48 @@ container list [ x:location<span class="Special"> <- </span><span class="Constant">next-ingredient</span> in:address:list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> result:address:list<span class="Special"> <- </span>new list:type - val:address:location<span class="Special"> <- </span>get-address result:address:list/deref, value:offset - val:address:location/deref<span class="Special"> <- </span>copy x:location - next:address:address:list<span class="Special"> <- </span>get-address result:address:list/deref, next:offset - next:address:address:list/deref<span class="Special"> <- </span>copy in:address:list - <span class="muControl">reply</span> result:address:list + val:address:location<span class="Special"> <- </span>get-address *result, value:offset + *val<span class="Special"> <- </span>copy x + next:address:address:list<span class="Special"> <- </span>get-address *result, next:offset + *next<span class="Special"> <- </span>copy in + <span class="muControl">reply</span> result ] <span class="Comment"># result:location <- first in:address:list</span> <span class="muRecipe">recipe</span> first [ <span class="Constant">local-scope</span> in:address:list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - result:location<span class="Special"> <- </span>get in:address:list/deref, value:offset - <span class="muControl">reply</span> result:location + result:location<span class="Special"> <- </span>get *in, value:offset + <span class="muControl">reply</span> result ] <span class="Comment"># result:address:list <- rest in:address:list</span> <span class="muRecipe">recipe</span> rest [ <span class="Constant">local-scope</span> in:address:list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - result:address:list<span class="Special"> <- </span>get in:address:list/deref, next:offset - <span class="muControl">reply</span> result:address:list + result:address:list<span class="Special"> <- </span>get *in, next:offset + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> list-handling [ run [ <span class="CommentedCode">#? $start-tracing #? 1</span> - 1:address:list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - 1:address:list<span class="Special"> <- </span>push <span class="Constant">3:literal</span>, 1:address:list - 1:address:list<span class="Special"> <- </span>push <span class="Constant">4:literal</span>, 1:address:list - 1:address:list<span class="Special"> <- </span>push <span class="Constant">5:literal</span>, 1:address:list - 2:number<span class="Special"> <- </span>first 1:address:list - 1:address:list<span class="Special"> <- </span>rest 1:address:list - 3:number<span class="Special"> <- </span>first 1:address:list - 1:address:list<span class="Special"> <- </span>rest 1:address:list - 4:number<span class="Special"> <- </span>first 1:address:list - 1:address:list<span class="Special"> <- </span>rest 1:address:list + <span class="Constant">1</span>:address:list<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">1</span>:address:list<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">1</span>:address:list + <span class="Constant">1</span>:address:list<span class="Special"> <- </span>push <span class="Constant">4</span>, <span class="Constant">1</span>:address:list + <span class="Constant">1</span>:address:list<span class="Special"> <- </span>push <span class="Constant">5</span>, <span class="Constant">1</span>:address:list + <span class="Constant">2</span>:number<span class="Special"> <- </span>first <span class="Constant">1</span>:address:list + <span class="Constant">1</span>:address:list<span class="Special"> <- </span>rest <span class="Constant">1</span>:address:list + <span class="Constant">3</span>:number<span class="Special"> <- </span>first <span class="Constant">1</span>:address:list + <span class="Constant">1</span>:address:list<span class="Special"> <- </span>rest <span class="Constant">1</span>:address:list + <span class="Constant">4</span>:number<span class="Special"> <- </span>first <span class="Constant">1</span>:address:list + <span class="Constant">1</span>:address:list<span class="Special"> <- </span>rest <span class="Constant">1</span>:address:list ] memory-should-contain [ - 1<span class="Special"> <- </span>0 <span class="Comment"># empty to empty, dust to dust..</span> - 2<span class="Special"> <- </span>5 - 3<span class="Special"> <- </span>4 - 4<span class="Special"> <- </span>3 + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty to empty, dust to dust..</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">5</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> ] ] </pre> diff --git a/html/064random.cc.html b/html/064random.cc.html index c2cf118f..8735a580 100644 --- a/html/064random.cc.html +++ b/html/064random.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } .PreProc { color: #c000c0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -38,7 +37,7 @@ RANDOM<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"random"</span>] = RANDOM<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> RANDOM: <span class="Delimiter">{</span> +case RANDOM: <span class="Delimiter">{</span> <span class="Comment">// todo: limited range of numbers, might be imperfectly random</span> <span class="Comment">// todo: thread state in extra ingredients and products</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> @@ -51,7 +50,7 @@ MAKE_RANDOM_NONDETERMINISTIC<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"make-random-nondeterministic"</span>] = MAKE_RANDOM_NONDETERMINISTIC<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> MAKE_RANDOM_NONDETERMINISTIC: <span class="Delimiter">{</span> +case MAKE_RANDOM_NONDETERMINISTIC: <span class="Delimiter">{</span> srand<span class="Delimiter">(</span>time<span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -61,12 +60,12 @@ ROUND<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"round"</span>] = ROUND<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> ROUND: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case ROUND: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'round' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'round' should be a number, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/065duplex_list.mu.html b/html/065duplex_list.mu.html index 2a517067..cbae7303 100644 --- a/html/065duplex_list.mu.html +++ b/html/065duplex_list.mu.html @@ -13,14 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.muScenario { color: #00af00; } +.muRecipe { color: #ff8700; } .Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } +.muScenario { color: #00af00; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -46,83 +46,83 @@ container duplex-list [ x:location<span class="Special"> <- </span><span class="Constant">next-ingredient</span> in:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> result:address:duplex-list<span class="Special"> <- </span>new duplex-list:type - val:address:location<span class="Special"> <- </span>get-address result:address:duplex-list/deref, value:offset - val:address:location/deref<span class="Special"> <- </span>copy x:location - next:address:address:duplex-list<span class="Special"> <- </span>get-address result:address:duplex-list/deref, next:offset - next:address:address:duplex-list/deref<span class="Special"> <- </span>copy in:address:duplex-list - <span class="muControl">reply-unless</span> in:address:duplex-list, result:address:duplex-list - prev:address:address:duplex-list<span class="Special"> <- </span>get-address in:address:duplex-list/deref, prev:offset - prev:address:address:duplex-list/deref<span class="Special"> <- </span>copy result:address:duplex-list - <span class="muControl">reply</span> result:address:duplex-list + val:address:location<span class="Special"> <- </span>get-address *result, value:offset + *val<span class="Special"> <- </span>copy x + next:address:address:duplex-list<span class="Special"> <- </span>get-address *result, next:offset + *next<span class="Special"> <- </span>copy in + <span class="muControl">reply-unless</span> in, result + prev:address:address:duplex-list<span class="Special"> <- </span>get-address *in, prev:offset + *prev<span class="Special"> <- </span>copy result + <span class="muControl">reply</span> result ] <span class="Comment"># result:location <- first-duplex in:address:duplex-list</span> <span class="muRecipe">recipe</span> first-duplex [ <span class="Constant">local-scope</span> in:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply-unless</span> in:address:duplex-list, <span class="Constant">0:literal</span> - result:location<span class="Special"> <- </span>get in:address:duplex-list/deref, value:offset - <span class="muControl">reply</span> result:location + <span class="muControl">reply-unless</span> in, <span class="Constant">0</span> + result:location<span class="Special"> <- </span>get *in, value:offset + <span class="muControl">reply</span> result ] <span class="Comment"># result:address:duplex-list <- next-duplex in:address:duplex-list</span> <span class="muRecipe">recipe</span> next-duplex [ <span class="Constant">local-scope</span> in:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply-unless</span> in:address:duplex-list, <span class="Constant">0:literal</span> - result:address:duplex-list<span class="Special"> <- </span>get in:address:duplex-list/deref, next:offset - <span class="muControl">reply</span> result:address:duplex-list + <span class="muControl">reply-unless</span> in, <span class="Constant">0</span> + result:address:duplex-list<span class="Special"> <- </span>get *in, next:offset + <span class="muControl">reply</span> result ] <span class="Comment"># result:address:duplex-list <- prev-duplex in:address:duplex-list</span> <span class="muRecipe">recipe</span> prev-duplex [ <span class="Constant">local-scope</span> in:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply-unless</span> in:address:duplex-list, <span class="Constant">0:literal</span> - result:address:duplex-list<span class="Special"> <- </span>get in:address:duplex-list/deref, prev:offset - <span class="muControl">reply</span> result:address:duplex-list + <span class="muControl">reply-unless</span> in, <span class="Constant">0</span> + result:address:duplex-list<span class="Special"> <- </span>get *in, prev:offset + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> duplex-list-handling [ run [ <span class="Comment"># reserve locations 0, 1 and 2 to check for missing null check</span> - 1:number<span class="Special"> <- </span>copy <span class="Constant">34:literal</span> - 2:number<span class="Special"> <- </span>copy <span class="Constant">35:literal</span> - 3:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - 3:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3:literal</span>, 3:address:duplex-list - 3:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4:literal</span>, 3:address:duplex-list - 3:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5:literal</span>, 3:address:duplex-list - 4:address:duplex-list<span class="Special"> <- </span>copy 3:address:duplex-list - 5:number<span class="Special"> <- </span>first 4:address:duplex-list - 4:address:duplex-list<span class="Special"> <- </span>next-duplex 4:address:duplex-list - 6:number<span class="Special"> <- </span>first 4:address:duplex-list - 4:address:duplex-list<span class="Special"> <- </span>next-duplex 4:address:duplex-list - 7:number<span class="Special"> <- </span>first 4:address:duplex-list - 8:address:duplex-list<span class="Special"> <- </span>next-duplex 4:address:duplex-list - 9:number<span class="Special"> <- </span>first 8:address:duplex-list - 10:address:duplex-list<span class="Special"> <- </span>next-duplex 8:address:duplex-list - 11:address:duplex-list<span class="Special"> <- </span>prev-duplex 8:address:duplex-list - 4:address:duplex-list<span class="Special"> <- </span>prev-duplex 4:address:duplex-list - 12:number<span class="Special"> <- </span>first 4:address:duplex-list - 4:address:duplex-list<span class="Special"> <- </span>prev-duplex 4:address:duplex-list - 13:number<span class="Special"> <- </span>first 4:address:duplex-list - 14:boolean<span class="Special"> <- </span>equal 3:address:duplex-list, 4:address:duplex-list + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">3</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">3</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3</span>, <span class="Constant">3</span>:address:duplex-list + <span class="Constant">3</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4</span>, <span class="Constant">3</span>:address:duplex-list + <span class="Constant">3</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5</span>, <span class="Constant">3</span>:address:duplex-list + <span class="Constant">4</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">3</span>:address:duplex-list + <span class="Constant">5</span>:number<span class="Special"> <- </span>first <span class="Constant">4</span>:address:duplex-list + <span class="Constant">4</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">4</span>:address:duplex-list + <span class="Constant">6</span>:number<span class="Special"> <- </span>first <span class="Constant">4</span>:address:duplex-list + <span class="Constant">4</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">4</span>:address:duplex-list + <span class="Constant">7</span>:number<span class="Special"> <- </span>first <span class="Constant">4</span>:address:duplex-list + <span class="Constant">8</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">4</span>:address:duplex-list + <span class="Constant">9</span>:number<span class="Special"> <- </span>first <span class="Constant">8</span>:address:duplex-list + <span class="Constant">10</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">8</span>:address:duplex-list + <span class="Constant">11</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">8</span>:address:duplex-list + <span class="Constant">4</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">4</span>:address:duplex-list + <span class="Constant">12</span>:number<span class="Special"> <- </span>first <span class="Constant">4</span>:address:duplex-list + <span class="Constant">4</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">4</span>:address:duplex-list + <span class="Constant">13</span>:number<span class="Special"> <- </span>first <span class="Constant">4</span>:address:duplex-list + <span class="Constant">14</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">3</span>:address:duplex-list, <span class="Constant">4</span>:address:duplex-list <span class="CommentedCode">#? $dump-trace #? 1</span> ] memory-should-contain [ - 0<span class="Special"> <- </span>0 <span class="Comment"># no modifications to null pointers</span> - 1<span class="Special"> <- </span>34 - 2<span class="Special"> <- </span>35 - 5<span class="Special"> <- </span>5 <span class="Comment"># scanning next</span> - 6<span class="Special"> <- </span>4 - 7<span class="Special"> <- </span>3 - 8<span class="Special"> <- </span>0 <span class="Comment"># null</span> - 9<span class="Special"> <- </span>0 <span class="Comment"># first of null</span> - 10<span class="Special"> <- </span>0 <span class="Comment"># next of null</span> - 11<span class="Special"> <- </span>0 <span class="Comment"># prev of null</span> - 12<span class="Special"> <- </span>4 <span class="Comment"># then start scanning prev</span> - 13<span class="Special"> <- </span>5 - 14<span class="Special"> <- </span>1 <span class="Comment"># list back at start</span> + <span class="Constant">0</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no modifications to null pointers</span> + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">34</span> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">35</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># null</span> + <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first of null</span> + <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># next of null</span> + <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># prev of null</span> + <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># then start scanning prev</span> + <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">5</span> + <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> ] ] @@ -133,134 +133,134 @@ container duplex-list [ x:location<span class="Special"> <- </span><span class="Constant">next-ingredient</span> in:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> new-node:address:duplex-list<span class="Special"> <- </span>new duplex-list:type - val:address:location<span class="Special"> <- </span>get-address new-node:address:duplex-list/deref, value:offset - val:address:location/deref<span class="Special"> <- </span>copy x:location - next-node:address:duplex-list<span class="Special"> <- </span>get in:address:duplex-list/deref, next:offset + val:address:location<span class="Special"> <- </span>get-address *new-node, value:offset + *val<span class="Special"> <- </span>copy x + next-node:address:duplex-list<span class="Special"> <- </span>get *in, next:offset <span class="Comment"># in.next = new-node</span> - y:address:address:duplex-list<span class="Special"> <- </span>get-address in:address:duplex-list/deref, next:offset - y:address:address:duplex-list/deref<span class="Special"> <- </span>copy new-node:address:duplex-list + y:address:address:duplex-list<span class="Special"> <- </span>get-address *in, next:offset + *y<span class="Special"> <- </span>copy new-node <span class="Comment"># new-node.prev = in</span> - y:address:address:duplex-list<span class="Special"> <- </span>get-address new-node:address:duplex-list/deref, prev:offset - y:address:address:duplex-list/deref<span class="Special"> <- </span>copy in:address:duplex-list + y<span class="Special"> <- </span>get-address *new-node, prev:offset + *y<span class="Special"> <- </span>copy in <span class="Comment"># new-node.next = next-node</span> - y:address:address:duplex-list<span class="Special"> <- </span>get-address new-node:address:duplex-list/deref, next:offset - y:address:address:duplex-list/deref<span class="Special"> <- </span>copy next-node:address:duplex-list + y<span class="Special"> <- </span>get-address *new-node, next:offset + *y<span class="Special"> <- </span>copy next-node <span class="Comment"># if next-node is not null</span> - <span class="muControl">reply-unless</span> next-node:address:duplex-list, new-node:address:duplex-list + <span class="muControl">reply-unless</span> next-node, new-node <span class="Comment"># next-node.prev = new-node</span> - y:address:address:duplex-list<span class="Special"> <- </span>get-address next-node:address:duplex-list/deref, prev:offset - y:address:address:duplex-list/deref<span class="Special"> <- </span>copy new-node:address:duplex-list - <span class="muControl">reply</span> new-node:address:duplex-list <span class="Comment"># just signalling something changed; don't rely on the result</span> + y<span class="Special"> <- </span>get-address *next-node, prev:offset + *y<span class="Special"> <- </span>copy new-node + <span class="muControl">reply</span> new-node <span class="Comment"># just signalling something changed; don't rely on the result</span> ] <span class="muScenario">scenario</span> inserting-into-duplex-list [ run [ - 1:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># 1 points to head of list</span> - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 1:address:duplex-list <span class="Comment"># 2 points inside list</span> - 2:address:duplex-list<span class="Special"> <- </span>insert-duplex <span class="Constant">6:literal</span>, 2:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># 1 points to head of list</span> + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">1</span>:address:duplex-list <span class="Comment"># 2 points inside list</span> + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>insert-duplex <span class="Constant">6</span>, <span class="Constant">2</span>:address:duplex-list <span class="Comment"># check structure like before</span> - 2:address:duplex-list<span class="Special"> <- </span>copy 1:address:duplex-list - 3:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 4:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 5:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 6:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 7:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 8:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 9:number<span class="Special"> <- </span>first 2:address:duplex-list - 10:boolean<span class="Special"> <- </span>equal 1:address:duplex-list, 2:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:duplex-list + <span class="Constant">3</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">4</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">5</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">6</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">7</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">8</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">9</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">10</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:duplex-list, <span class="Constant">2</span>:address:duplex-list ] memory-should-contain [ - 3<span class="Special"> <- </span>5 <span class="Comment"># scanning next</span> - 4<span class="Special"> <- </span>4 - 5<span class="Special"> <- </span>6 <span class="Comment"># inserted element</span> - 6<span class="Special"> <- </span>3 - 7<span class="Special"> <- </span>6 <span class="Comment"># then prev</span> - 8<span class="Special"> <- </span>4 - 9<span class="Special"> <- </span>5 - 10<span class="Special"> <- </span>1 <span class="Comment"># list back at start</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># then prev</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">5</span> + <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> ] ] <span class="muScenario">scenario</span> inserting-at-end-of-duplex-list [ run [ - 1:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># 1 points to head of list</span> - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 1:address:duplex-list <span class="Comment"># 2 points inside list</span> - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list <span class="Comment"># now at end of list</span> - 2:address:duplex-list<span class="Special"> <- </span>insert-duplex <span class="Constant">6:literal</span>, 2:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># 1 points to head of list</span> + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">1</span>:address:duplex-list <span class="Comment"># 2 points inside list</span> + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list <span class="Comment"># now at end of list</span> + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>insert-duplex <span class="Constant">6</span>, <span class="Constant">2</span>:address:duplex-list <span class="Comment"># check structure like before</span> - 2:address:duplex-list<span class="Special"> <- </span>copy 1:address:duplex-list - 3:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 4:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 5:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 6:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 7:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 8:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 9:number<span class="Special"> <- </span>first 2:address:duplex-list - 10:boolean<span class="Special"> <- </span>equal 1:address:duplex-list, 2:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:duplex-list + <span class="Constant">3</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">4</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">5</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">6</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">7</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">8</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">9</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">10</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:duplex-list, <span class="Constant">2</span>:address:duplex-list ] memory-should-contain [ - 3<span class="Special"> <- </span>5 <span class="Comment"># scanning next</span> - 4<span class="Special"> <- </span>4 - 5<span class="Special"> <- </span>3 - 6<span class="Special"> <- </span>6 <span class="Comment"># inserted element</span> - 7<span class="Special"> <- </span>3 <span class="Comment"># then prev</span> - 8<span class="Special"> <- </span>4 - 9<span class="Special"> <- </span>5 - 10<span class="Special"> <- </span>1 <span class="Comment"># list back at start</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># then prev</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">5</span> + <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> ] ] <span class="muScenario">scenario</span> inserting-after-start-of-duplex-list [ run [ - 1:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># 1 points to head of list</span> - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>insert-duplex <span class="Constant">6:literal</span>, 1:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># 1 points to head of list</span> + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>insert-duplex <span class="Constant">6</span>, <span class="Constant">1</span>:address:duplex-list <span class="Comment"># check structure like before</span> - 2:address:duplex-list<span class="Special"> <- </span>copy 1:address:duplex-list - 3:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 4:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 5:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 6:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 7:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 8:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 9:number<span class="Special"> <- </span>first 2:address:duplex-list - 10:boolean<span class="Special"> <- </span>equal 1:address:duplex-list, 2:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:duplex-list + <span class="Constant">3</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">4</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">5</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">6</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">7</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">8</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">9</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">10</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:duplex-list, <span class="Constant">2</span>:address:duplex-list ] memory-should-contain [ - 3<span class="Special"> <- </span>5 <span class="Comment"># scanning next</span> - 4<span class="Special"> <- </span>6 <span class="Comment"># inserted element</span> - 5<span class="Special"> <- </span>4 - 6<span class="Special"> <- </span>3 - 7<span class="Special"> <- </span>4 <span class="Comment"># then prev</span> - 8<span class="Special"> <- </span>6 - 9<span class="Special"> <- </span>5 - 10<span class="Special"> <- </span>1 <span class="Comment"># list back at start</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># then prev</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">6</span> + <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">5</span> + <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> ] ] @@ -274,131 +274,131 @@ container duplex-list [ <span class="Constant">local-scope</span> in:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if 'in' is null, return</span> - <span class="muControl">reply-unless</span> in:address:duplex-list, in:address:duplex-list - next-node:address:duplex-list<span class="Special"> <- </span>get in:address:duplex-list/deref, next:offset - prev-node:address:duplex-list<span class="Special"> <- </span>get in:address:duplex-list/deref, prev:offset + <span class="muControl">reply-unless</span> in, in + next-node:address:duplex-list<span class="Special"> <- </span>get *in, next:offset + prev-node:address:duplex-list<span class="Special"> <- </span>get *in, prev:offset <span class="Comment"># null in's pointers</span> - x:address:address:duplex-list<span class="Special"> <- </span>get-address in:address:duplex-list/deref, next:offset - x:address:address:duplex-list/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - x:address:address:duplex-list<span class="Special"> <- </span>get-address in:address:duplex-list/deref, prev:offset - x:address:address:duplex-list/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + x:address:address:duplex-list<span class="Special"> <- </span>get-address *in, next:offset + *x<span class="Special"> <- </span>copy <span class="Constant">0</span> + x<span class="Special"> <- </span>get-address *in, prev:offset + *x<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> <span class="Comment"># if next-node is not null</span> - <span class="muControl">break-unless</span> next-node:address:duplex-list + <span class="muControl">break-unless</span> next-node <span class="Comment"># next-node.prev = prev-node</span> - x:address:address:duplex-list<span class="Special"> <- </span>get-address next-node:address:duplex-list/deref, prev:offset - x:address:address:duplex-list/deref<span class="Special"> <- </span>copy prev-node:address:duplex-list + x<span class="Special"> <- </span>get-address *next-node, prev:offset + *x<span class="Special"> <- </span>copy prev-node <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># if prev-node is not null</span> - <span class="muControl">break-unless</span> prev-node:address:duplex-list + <span class="muControl">break-unless</span> prev-node <span class="Comment"># prev-node.next = next-node</span> - x:address:address:duplex-list<span class="Special"> <- </span>get-address prev-node:address:duplex-list/deref, next:offset - x:address:address:duplex-list/deref<span class="Special"> <- </span>copy next-node:address:duplex-list - <span class="muControl">reply</span> prev-node:address:duplex-list + x<span class="Special"> <- </span>get-address *prev-node, next:offset + *x<span class="Special"> <- </span>copy next-node + <span class="muControl">reply</span> prev-node <span class="Delimiter">}</span> - <span class="muControl">reply</span> next-node:address:duplex-list + <span class="muControl">reply</span> next-node ] <span class="muScenario">scenario</span> removing-from-duplex-list [ run [ - 1:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># 1 points to head of list</span> - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 1:address:duplex-list <span class="Comment"># 2 points at second element</span> - 2:address:duplex-list<span class="Special"> <- </span>remove-duplex 2:address:duplex-list - 3:boolean<span class="Special"> <- </span>equal 2:address:duplex-list, <span class="Constant">0:literal</span> + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># 1 points to head of list</span> + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">1</span>:address:duplex-list <span class="Comment"># 2 points at second element</span> + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>remove-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">2</span>:address:duplex-list, <span class="Constant">0</span> <span class="Comment"># check structure like before</span> - 2:address:duplex-list<span class="Special"> <- </span>copy 1:address:duplex-list - 4:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 5:number<span class="Special"> <- </span>first 2:address:duplex-list - 6:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 7:number<span class="Special"> <- </span>first 2:address:duplex-list - 8:boolean<span class="Special"> <- </span>equal 1:address:duplex-list, 2:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:duplex-list + <span class="Constant">4</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">5</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">6</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">7</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">8</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:duplex-list, <span class="Constant">2</span>:address:duplex-list ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># remove returned non-null</span> - 4<span class="Special"> <- </span>5 <span class="Comment"># scanning next, skipping deleted element</span> - 5<span class="Special"> <- </span>3 - 6<span class="Special"> <- </span>0 <span class="Comment"># no more elements</span> - 7<span class="Special"> <- </span>5 <span class="Comment"># prev of final element</span> - 8<span class="Special"> <- </span>1 <span class="Comment"># list back at start</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># remove returned non-null</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># prev of final element</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> ] ] <span class="muScenario">scenario</span> removing-from-start-of-duplex-list [ run [ - 1:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># 1 points to head of list</span> - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># 1 points to head of list</span> + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5</span>, <span class="Constant">1</span>:address:duplex-list <span class="Comment"># removing from head? return value matters.</span> - 1:address:duplex-list<span class="Special"> <- </span>remove-duplex 1:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>remove-duplex <span class="Constant">1</span>:address:duplex-list <span class="Comment"># check structure like before</span> - 2:address:duplex-list<span class="Special"> <- </span>copy 1:address:duplex-list - 3:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 4:number<span class="Special"> <- </span>first 2:address:duplex-list - 5:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 6:number<span class="Special"> <- </span>first 2:address:duplex-list - 7:boolean<span class="Special"> <- </span>equal 1:address:duplex-list, 2:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:duplex-list + <span class="Constant">3</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">4</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">5</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">6</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">7</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:duplex-list, <span class="Constant">2</span>:address:duplex-list ] memory-should-contain [ - 3<span class="Special"> <- </span>4 <span class="Comment"># scanning next, skipping deleted element</span> - 4<span class="Special"> <- </span>3 - 5<span class="Special"> <- </span>0 <span class="Comment"># no more elements</span> - 6<span class="Special"> <- </span>4 <span class="Comment"># prev of final element</span> - 7<span class="Special"> <- </span>1 <span class="Comment"># list back at start</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># prev of final element</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> ] ] <span class="muScenario">scenario</span> removing-from-end-of-duplex-list [ run [ - 1:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># 1 points to head of list</span> - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># 1 points to head of list</span> + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">4</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">5</span>, <span class="Constant">1</span>:address:duplex-list <span class="Comment"># delete last element</span> - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 1:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>remove-duplex 2:address:duplex-list - 3:boolean<span class="Special"> <- </span>equal 2:address:duplex-list, <span class="Constant">0:literal</span> + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">1</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>remove-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">2</span>:address:duplex-list, <span class="Constant">0</span> <span class="Comment"># check structure like before</span> - 2:address:duplex-list<span class="Special"> <- </span>copy 1:address:duplex-list - 4:number<span class="Special"> <- </span>first 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 5:number<span class="Special"> <- </span>first 2:address:duplex-list - 6:address:duplex-list<span class="Special"> <- </span>next-duplex 2:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>prev-duplex 2:address:duplex-list - 7:number<span class="Special"> <- </span>first 2:address:duplex-list - 8:boolean<span class="Special"> <- </span>equal 1:address:duplex-list, 2:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:duplex-list + <span class="Constant">4</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">5</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">6</span>:address:duplex-list<span class="Special"> <- </span>next-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>prev-duplex <span class="Constant">2</span>:address:duplex-list + <span class="Constant">7</span>:number<span class="Special"> <- </span>first <span class="Constant">2</span>:address:duplex-list + <span class="Constant">8</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address:duplex-list, <span class="Constant">2</span>:address:duplex-list ] memory-should-contain [ - 3<span class="Special"> <- </span>0 <span class="Comment"># remove returned non-null</span> - 4<span class="Special"> <- </span>5 <span class="Comment"># scanning next, skipping deleted element</span> - 5<span class="Special"> <- </span>4 - 6<span class="Special"> <- </span>0 <span class="Comment"># no more elements</span> - 7<span class="Special"> <- </span>5 <span class="Comment"># prev of final element</span> - 8<span class="Special"> <- </span>1 <span class="Comment"># list back at start</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># remove returned non-null</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># prev of final element</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> ] ] <span class="muScenario">scenario</span> removing-from-singleton-list [ run [ - 1:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> <span class="Comment"># 1 points to singleton list</span> - 1:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list - 2:address:duplex-list<span class="Special"> <- </span>remove-duplex 1:address:duplex-list - 3:address:duplex-list<span class="Special"> <- </span>get 1:address:duplex-list/deref, next:offset - 4:address:duplex-list<span class="Special"> <- </span>get 1:address:duplex-list/deref, prev:offset + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># 1 points to singleton list</span> + <span class="Constant">1</span>:address:duplex-list<span class="Special"> <- </span>push-duplex <span class="Constant">3</span>, <span class="Constant">1</span>:address:duplex-list + <span class="Constant">2</span>:address:duplex-list<span class="Special"> <- </span>remove-duplex <span class="Constant">1</span>:address:duplex-list + <span class="Constant">3</span>:address:duplex-list<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:duplex-list, next:offset + <span class="Constant">4</span>:address:duplex-list<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:duplex-list, prev:offset ] memory-should-contain [ - 2<span class="Special"> <- </span>0 <span class="Comment"># remove returned null</span> - 3<span class="Special"> <- </span>0 <span class="Comment"># removed node is also detached</span> - 4<span class="Special"> <- </span>0 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># remove returned null</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># removed node is also detached</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] </pre> diff --git a/html/066stream.mu.html b/html/066stream.mu.html index cd1ef1de..ad7aebdf 100644 --- a/html/066stream.mu.html +++ b/html/066stream.mu.html @@ -13,11 +13,11 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -38,40 +38,40 @@ container stream [ <span class="muRecipe">recipe</span> new-stream [ <span class="Constant">local-scope</span> result:address:stream<span class="Special"> <- </span>new stream:type - i:address:number<span class="Special"> <- </span>get-address result:address:stream/deref, index:offset - i:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - d:address:address:array:character<span class="Special"> <- </span>get-address result:address:stream/deref, data:offset - d:address:address:array:character/deref<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply</span> result:address:stream + i:address:number<span class="Special"> <- </span>get-address *result, index:offset + *i<span class="Special"> <- </span>copy <span class="Constant">0</span> + d:address:address:array:character<span class="Special"> <- </span>get-address *result, data:offset + *d<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> rewind-stream [ <span class="Constant">local-scope</span> in:address:stream<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - x:address:number<span class="Special"> <- </span>get-address in:address:stream/deref, index:offset - x:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - <span class="muControl">reply</span> in:address:stream/same-as-arg:0 + x:address:number<span class="Special"> <- </span>get-address *in, index:offset + *x<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="muControl">reply</span> in/same-as-arg:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> read-line [ <span class="Constant">local-scope</span> in:address:stream<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - idx:address:number<span class="Special"> <- </span>get-address in:address:stream/deref, index:offset - s:address:array:character<span class="Special"> <- </span>get in:address:stream/deref, data:offset - next-idx:number<span class="Special"> <- </span>find-next s:address:array:character, <span class="Constant">10:literal/newline</span>, idx:address:number/deref - result:address:array:character<span class="Special"> <- </span>string-copy s:address:array:character, idx:address:number/deref, next-idx:number - idx:address:number/deref<span class="Special"> <- </span>add next-idx:number, <span class="Constant">1:literal</span> <span class="Comment"># skip newline</span> - <span class="muControl">reply</span> result:address:array:character + idx:address:number<span class="Special"> <- </span>get-address *in, index:offset + s:address:array:character<span class="Special"> <- </span>get *in, data:offset + next-idx:number<span class="Special"> <- </span>find-next s, <span class="Constant">10/newline</span>, *idx + result:address:array:character<span class="Special"> <- </span>string-copy s, *idx, next-idx + *idx<span class="Special"> <- </span>add next-idx, <span class="Constant">1</span> <span class="Comment"># skip newline</span> + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> end-of-stream? [ <span class="Constant">local-scope</span> in:address:stream<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - idx:number<span class="Special"> <- </span>get in:address:stream/deref, index:offset - s:address:array:character<span class="Special"> <- </span>get in:address:stream/deref, data:offset - len:number<span class="Special"> <- </span>length s:address:array:character/deref - result:boolean<span class="Special"> <- </span>greater-or-equal idx:number, len:number - <span class="muControl">reply</span> result:boolean + idx:address:number<span class="Special"> <- </span>get *in, index:offset + s:address:array:character<span class="Special"> <- </span>get *in, data:offset + len:number<span class="Special"> <- </span>length *s + result:boolean<span class="Special"> <- </span>greater-or-equal idx, len + <span class="muControl">reply</span> result ] </pre> </body> diff --git a/html/070display.cc.html b/html/070display.cc.html index e09146cb..986d56be 100644 --- a/html/070display.cc.html +++ b/html/070display.cc.html @@ -14,11 +14,10 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } +.SalientComment { color: #00ffff; } .CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } --> @@ -41,15 +40,15 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="SalientComment">//:: Display management</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Display_row = <span class="Constant">0</span><span class="Delimiter">,</span> Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> -<span class="Normal">bool</span> Autodisplay = <span class="Constant">true</span><span class="Delimiter">;</span> +long long int Display_row = <span class="Constant">0</span><span class="Delimiter">,</span> Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> +bool Autodisplay = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> OPEN_CONSOLE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"open-console"</span>] = OPEN_CONSOLE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> OPEN_CONSOLE: <span class="Delimiter">{</span> +case OPEN_CONSOLE: <span class="Delimiter">{</span> tb_init<span class="Delimiter">();</span> Display_row = Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -60,7 +59,7 @@ CLOSE_CONSOLE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"close-console"</span>] = CLOSE_CONSOLE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> CLOSE_CONSOLE: <span class="Delimiter">{</span> +case CLOSE_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> @@ -74,7 +73,7 @@ CLEAR_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"clear-display"</span>] = CLEAR_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> CLEAR_DISPLAY: <span class="Delimiter">{</span> +case CLEAR_DISPLAY: <span class="Delimiter">{</span> tb_clear<span class="Delimiter">();</span> Display_row = Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -85,13 +84,13 @@ CLEAR_LINE_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"clear-line-on-display"</span>] = CLEAR_LINE_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> CLEAR_LINE_ON_DISPLAY: <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> width = tb_width<span class="Delimiter">();</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> x = Display_column<span class="Delimiter">;</span> x < width<span class="Delimiter">;</span> ++x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +case CLEAR_LINE_ON_DISPLAY: <span class="Delimiter">{</span> + long long int width = tb_width<span class="Delimiter">();</span> + for <span class="Delimiter">(</span>long long int x = Display_column<span class="Delimiter">;</span> x < width<span class="Delimiter">;</span> ++x<span class="Delimiter">)</span> <span class="Delimiter">{</span> tb_change_cell<span class="Delimiter">(</span>x<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_BLACK<span class="Delimiter">);</span> <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="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -100,60 +99,60 @@ PRINT_CHARACTER_TO_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<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> -<span class="Normal">case</span> PRINT_CHARACTER_TO_DISPLAY: <span class="Delimiter">{</span> - <span class="Normal">int</span> h=tb_height<span class="Delimiter">(),</span> w=tb_width<span class="Delimiter">();</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +case PRINT_CHARACTER_TO_DISPLAY: <span class="Delimiter">{</span> + int h=tb_height<span class="Delimiter">(),</span> w=tb_width<span class="Delimiter">();</span> + long long int 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> + long long int 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>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'print-character-to-display' requires at least one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'print-character-to-display' should be a character, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">int</span> color = TB_BLACK<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + 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> + int color = TB_BLACK<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": second ingredient of 'print-character-to-display' should be a foreground color number, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> color = 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> <span class="Delimiter">}</span> - <span class="Normal">int</span> bg_color = TB_BLACK<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> + int bg_color = TB_BLACK<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": third ingredient of 'print-character-to-display' should be a background color number, but got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> bg_color = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>bg_color == <span class="Constant">0</span><span class="Delimiter">)</span> bg_color = TB_BLACK<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>bg_color == <span class="Constant">0</span><span class="Delimiter">)</span> bg_color = TB_BLACK<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> color<span class="Delimiter">,</span> bg_color<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="cSpecial">'\n'</span> || c == <span class="cSpecial">'\r'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_row < height-<span class="Constant">1</span><span class="Delimiter">)</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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<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> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="cSpecial">'\b'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_column > <span class="Constant">0</span><span class="Delimiter">)</span> <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> color<span class="Delimiter">,</span> bg_color<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="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_column < width-<span class="Constant">1</span><span class="Delimiter">)</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> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -162,7 +161,7 @@ CURSOR_POSITION_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<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> -<span class="Normal">case</span> CURSOR_POSITION_ON_DISPLAY: <span class="Delimiter">{</span> +case CURSOR_POSITION_ON_DISPLAY: <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> @@ -174,23 +173,23 @@ MOVE_CURSOR_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<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> -<span class="Normal">case</span> MOVE_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case MOVE_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'move-cursor-on-display' requires two ingredients, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'move-cursor-on-display' should be a row number, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": second ingredient of 'move-cursor-on-display' should be a column number, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -199,13 +198,13 @@ MOVE_CURSOR_DOWN_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<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> -<span class="Normal">case</span> MOVE_CURSOR_DOWN_ON_DISPLAY: <span class="Delimiter">{</span> - <span class="Normal">int</span> h=tb_height<span class="Delimiter">();</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_row < height-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case MOVE_CURSOR_DOWN_ON_DISPLAY: <span class="Delimiter">{</span> + int h=tb_height<span class="Delimiter">();</span> + long long int 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<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> @@ -215,11 +214,11 @@ MOVE_CURSOR_UP_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<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> -<span class="Normal">case</span> MOVE_CURSOR_UP_ON_DISPLAY: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_row > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case MOVE_CURSOR_UP_ON_DISPLAY: <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<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> @@ -229,13 +228,13 @@ MOVE_CURSOR_RIGHT_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<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> -<span class="Normal">case</span> MOVE_CURSOR_RIGHT_ON_DISPLAY: <span class="Delimiter">{</span> - <span class="Normal">int</span> w=tb_width<span class="Delimiter">();</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_column < width-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case MOVE_CURSOR_RIGHT_ON_DISPLAY: <span class="Delimiter">{</span> + int w=tb_width<span class="Delimiter">();</span> + long long int 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<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> @@ -245,11 +244,11 @@ MOVE_CURSOR_LEFT_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<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> -<span class="Normal">case</span> MOVE_CURSOR_LEFT_ON_DISPLAY: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_column > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case MOVE_CURSOR_LEFT_ON_DISPLAY: <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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Autodisplay<span class="Delimiter">)</span> tb_present<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Autodisplay<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> @@ -259,7 +258,7 @@ DISPLAY_WIDTH<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"display-width"</span>] = DISPLAY_WIDTH<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> DISPLAY_WIDTH: <span class="Delimiter">{</span> +case DISPLAY_WIDTH: <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>tb_width<span class="Delimiter">());</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -270,7 +269,7 @@ DISPLAY_HEIGHT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"display-height"</span>] = DISPLAY_HEIGHT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> DISPLAY_HEIGHT: <span class="Delimiter">{</span> +case DISPLAY_HEIGHT: <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>tb_height<span class="Delimiter">());</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -281,7 +280,7 @@ HIDE_CURSOR_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"hide-cursor-on-display"</span>] = HIDE_CURSOR_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> HIDE_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> +case HIDE_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> tb_set_cursor<span class="Delimiter">(</span>TB_HIDE_CURSOR<span class="Delimiter">,</span> TB_HIDE_CURSOR<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -291,7 +290,7 @@ SHOW_CURSOR_ON_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"show-cursor-on-display"</span>] = SHOW_CURSOR_ON_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> SHOW_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> +case SHOW_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> tb_set_cursor<span class="Delimiter">(</span>Display_row<span class="Delimiter">,</span> Display_column<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -301,7 +300,7 @@ HIDE_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"hide-display"</span>] = HIDE_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> HIDE_DISPLAY: <span class="Delimiter">{</span> +case HIDE_DISPLAY: <span class="Delimiter">{</span> Autodisplay = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -311,7 +310,7 @@ SHOW_DISPLAY<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"show-display"</span>] = SHOW_DISPLAY<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> SHOW_DISPLAY: <span class="Delimiter">{</span> +case SHOW_DISPLAY: <span class="Delimiter">{</span> Autodisplay = <span class="Constant">true</span><span class="Delimiter">;</span> tb_present<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -324,7 +323,7 @@ WAIT_FOR_SOME_INTERACTION<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"wait-for-some-interaction"</span>] = WAIT_FOR_SOME_INTERACTION<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> WAIT_FOR_SOME_INTERACTION: <span class="Delimiter">{</span> +case WAIT_FOR_SOME_INTERACTION: <span class="Delimiter">{</span> tb_event event<span class="Delimiter">;</span> tb_poll_event<span class="Delimiter">(</span>&event<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -335,11 +334,11 @@ CHECK_FOR_INTERACTION<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"check-for-interaction"</span>] = CHECK_FOR_INTERACTION<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> CHECK_FOR_INTERACTION: <span class="Delimiter">{</span> +case CHECK_FOR_INTERACTION: <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">// result and status</span> tb_event event<span class="Delimiter">;</span> - <span class="Normal">int</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>event_type == TB_EVENT_KEY && event<span class="Delimiter">.</span>ch<span class="Delimiter">)</span> <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> + if <span class="Delimiter">(</span>event_type == TB_EVENT_KEY && event<span class="Delimiter">.</span>ch<span class="Delimiter">)</span> <span class="Delimiter">{</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">text event</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>event<span class="Delimiter">.</span>ch<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> @@ -348,11 +347,11 @@ Recipe_ordinal[<span class="Constant">"check-for-interaction"</span>] <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// treat keys within ascii as unicode characters</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>event_type == TB_EVENT_KEY && event<span class="Delimiter">.</span>key < <span class="Constant">0xff</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>event_type == TB_EVENT_KEY && event<span class="Delimiter">.</span>key < <span class="Constant">0xff</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">text event</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>event<span class="Delimiter">.</span>key == 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>event<span class="Delimiter">.</span>key == TB_KEY_BACKSPACE2<span class="Delimiter">)</span> event<span class="Delimiter">.</span>key = TB_KEY_BACKSPACE<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>event<span class="Delimiter">.</span>key == TB_KEY_CARRIAGE_RETURN<span class="Delimiter">)</span> event<span class="Delimiter">.</span>key = TB_KEY_NEWLINE<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>event<span class="Delimiter">.</span>key == 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>event<span class="Delimiter">.</span>key == TB_KEY_BACKSPACE2<span class="Delimiter">)</span> event<span class="Delimiter">.</span>key = TB_KEY_BACKSPACE<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>event<span class="Delimiter">.</span>key == TB_KEY_CARRIAGE_RETURN<span class="Delimiter">)</span> event<span class="Delimiter">.</span>key = TB_KEY_NEWLINE<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>key<span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> @@ -360,7 +359,7 @@ Recipe_ordinal[<span class="Constant">"check-for-interaction"</span>] <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// keys outside ascii aren't unicode characters but arbitrary termbox inventions</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>event_type == TB_EVENT_KEY<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>event_type == TB_EVENT_KEY<span class="Delimiter">)</span> <span class="Delimiter">{</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">keycode event</span><span class="Comment">*/</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>key<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> @@ -368,7 +367,7 @@ Recipe_ordinal[<span class="Constant">"check-for-interaction"</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="Comment">/*</span><span class="Comment">found</span><span class="Comment">*/</span><span class="Constant">true</span><span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>event_type == TB_EVENT_MOUSE<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>event_type == TB_EVENT_MOUSE<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? tb_shutdown(); //? 1</span> <span class="CommentedCode">//? cerr << "AAA\n"; //? 1</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="Comment">/*</span><span class="Comment">touch event</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">);</span> @@ -392,7 +391,7 @@ INTERACTIONS_LEFT<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"interactions-left?"</span>] = INTERACTIONS_LEFT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> INTERACTIONS_LEFT: <span class="Delimiter">{</span> +case INTERACTIONS_LEFT: <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>tb_event_ready<span class="Delimiter">());</span> <span class="Identifier">break</span><span class="Delimiter">;</span> diff --git a/html/071print.mu.html b/html/071print.mu.html index e622b83f..fb8d0ae7 100644 --- a/html/071print.mu.html +++ b/html/071print.mu.html @@ -13,14 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.muScenario { color: #00af00; } +.muRecipe { color: #ff8700; } .Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } +.muScenario { color: #00af00; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -51,676 +51,670 @@ container screen-cell [ <span class="muRecipe">recipe</span> new-fake-screen [ <span class="Constant">local-scope</span> result:address:screen<span class="Special"> <- </span>new screen:type - width:address:number<span class="Special"> <- </span>get-address result:address:screen/deref, num-columns:offset - width:address:number/deref<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - height:address:number<span class="Special"> <- </span>get-address result:address:screen/deref, num-rows:offset - height:address:number/deref<span class="Special"> <- </span><span class="Constant">next-ingredient</span> -<span class="CommentedCode">#? $print height:address:number/deref, 10:literal/newline</span> - 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:screen-cell<span class="Special"> <- </span>get-address result:address:screen/deref, data:offset - buf:address:address:array:screen-cell/deref<span class="Special"> <- </span>new screen-cell:type, bufsize:number - clear-screen result:address:screen - <span class="muControl">reply</span> result:address:screen + width:address:number<span class="Special"> <- </span>get-address *result, num-columns:offset + *width<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + height:address:number<span class="Special"> <- </span>get-address *result, num-rows:offset + *height<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + row:address:number<span class="Special"> <- </span>get-address *result, cursor-row:offset + *row<span class="Special"> <- </span>copy <span class="Constant">0</span> + column:address:number<span class="Special"> <- </span>get-address *result, cursor-column:offset + *column<span class="Special"> <- </span>copy <span class="Constant">0</span> + bufsize:number<span class="Special"> <- </span>multiply *width, *height + buf:address:address:array:screen-cell<span class="Special"> <- </span>get-address *result, data:offset + *buf<span class="Special"> <- </span>new screen-cell:type, bufsize + clear-screen result + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> clear-screen [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> -<span class="CommentedCode">#? $print [clearing screen</span> -<span class="CommentedCode">#? ] #? 1</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen + <span class="muControl">break-unless</span> sc <span class="Comment"># clear fake screen</span> - buf:address:array:screen-cell<span class="Special"> <- </span>get x:address:screen/deref, data:offset - max:number<span class="Special"> <- </span>length buf:address:array:screen-cell/deref - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + buf:address:array:screen-cell<span class="Special"> <- </span>get *sc, data:offset + max:number<span class="Special"> <- </span>length *buf + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, max:number - <span class="muControl">break-if</span> done?:boolean - curr:address:screen-cell<span class="Special"> <- </span>index-address buf:address:array:screen-cell/deref, i:number - curr-content:address:character<span class="Special"> <- </span>get-address curr:address:screen-cell/deref, contents:offset - curr-content:address:character/deref<span class="Special"> <- </span>copy <span class="Constant">[ ]</span> - curr-color:address:character<span class="Special"> <- </span>get-address curr:address:screen-cell/deref, color:offset - curr-color:address:character/deref<span class="Special"> <- </span>copy <span class="Constant">7:literal/white</span> - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal i, max + <span class="muControl">break-if</span> done? + curr:address:screen-cell<span class="Special"> <- </span>index-address *buf, i + curr-content:address:character<span class="Special"> <- </span>get-address *curr, contents:offset + *curr-content<span class="Special"> <- </span>copy <span class="Constant">[ ]</span> + curr-color:address:character<span class="Special"> <- </span>get-address *curr, color:offset + *curr-color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">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="muControl">reply</span> x:address:screen/same-as-ingredient:0 + x:address:number<span class="Special"> <- </span>get-address *sc, cursor-row:offset + *x<span class="Special"> <- </span>copy <span class="Constant">0</span> + x<span class="Special"> <- </span>get-address *sc, cursor-column:offset + *x<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> clear-display - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] -<span class="muRecipe">recipe</span> fake-screen-is-clear? [ +<span class="muRecipe">recipe</span> fake-screen-is-empty? [ <span class="Constant">local-scope</span> - screen:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply-unless</span> screen:address:screen, <span class="Constant">1:literal/true</span> - buf:address:array:screen-cell<span class="Special"> <- </span>get screen:address:screen/deref, data:offset - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - len:number<span class="Special"> <- </span>length buf:address:array:screen-cell/deref + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + <span class="muControl">reply-unless</span> sc, <span class="Constant">1/true</span> + buf:address:array:screen-cell<span class="Special"> <- </span>get *sc, data:offset + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + len:number<span class="Special"> <- </span>length *buf <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, len:number - <span class="muControl">break-if</span> done?:boolean - curr:screen-cell<span class="Special"> <- </span>index buf:address:array:screen-cell/deref, i:number - curr-contents:character<span class="Special"> <- </span>get curr:screen-cell, contents:offset - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> - <span class="muControl">loop-unless</span> curr-contents:character + done?:boolean<span class="Special"> <- </span>greater-or-equal i, len + <span class="muControl">break-if</span> done? + curr:screen-cell<span class="Special"> <- </span>index *buf, i + curr-contents:character<span class="Special"> <- </span>get curr, contents:offset + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + <span class="muControl">loop-unless</span> curr-contents <span class="Comment"># not 0</span> - <span class="muControl">reply</span> <span class="Constant">0:literal/false</span> + <span class="muControl">reply</span> <span class="Constant">0/false</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> <span class="Constant">1:literal/true</span> + <span class="muControl">reply</span> <span class="Constant">1/true</span> ] <span class="muRecipe">recipe</span> print-character [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> c:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">7:literal/white</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default bg-color to black</span> - <span class="muControl">break-if</span> bg-color-found?:boolean - bg-color:number<span class="Special"> <- </span>copy <span class="Constant">0:literal/black</span> + <span class="muControl">break-if</span> bg-color-found? + bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> <span class="CommentedCode">#? trace [app], [print character] #? 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="muControl">break-unless</span> x:address:screen - 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 + <span class="muControl">break-unless</span> sc + width:number<span class="Special"> <- </span>get *sc, num-columns:offset + height:number<span class="Special"> <- </span>get *sc, num-rows:offset <span class="Comment"># if cursor is out of bounds, silently exit</span> - row:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-row:offset - legal?:boolean<span class="Special"> <- </span>greater-or-equal row:address:number/deref, <span class="Constant">0:literal</span> - <span class="muControl">reply-unless</span> legal?:boolean, x:address:screen - legal?:boolean<span class="Special"> <- </span>lesser-than row:address:number/deref, height:number - <span class="muControl">reply-unless</span> legal?:boolean, x:address:screen - column:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset - legal?:boolean<span class="Special"> <- </span>greater-or-equal column:address:number/deref, <span class="Constant">0:literal</span> - <span class="muControl">reply-unless</span> legal?:boolean, x:address:screen - legal?:boolean<span class="Special"> <- </span>lesser-than column:address:number/deref, width:number - <span class="muControl">reply-unless</span> legal?:boolean, x:address:screen + row:address:number<span class="Special"> <- </span>get-address *sc, cursor-row:offset + legal?:boolean<span class="Special"> <- </span>greater-or-equal *row, <span class="Constant">0</span> + <span class="muControl">reply-unless</span> legal?, sc + legal?<span class="Special"> <- </span>lesser-than *row, height + <span class="muControl">reply-unless</span> legal?, sc + column:address:number<span class="Special"> <- </span>get-address *sc, cursor-column:offset + legal?<span class="Special"> <- </span>greater-or-equal *column, <span class="Constant">0</span> + <span class="muControl">reply-unless</span> legal?, sc + legal?<span class="Special"> <- </span>lesser-than *column, width + <span class="muControl">reply-unless</span> legal?, sc <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/newline</span> -<span class="CommentedCode">#? $print c:character, [ ], newline?:boolean, 10:literal/newline</span> - <span class="muControl">break-unless</span> newline?:boolean + newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> +<span class="CommentedCode">#? $print c, [ ], newline?, 10/newline</span> + <span class="muControl">break-unless</span> newline? <span class="Delimiter">{</span> <span class="Comment"># unless cursor is already at bottom</span> - bottom:number<span class="Special"> <- </span>subtract height:number, <span class="Constant">1:literal</span> - at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row:address:number/deref, bottom:number - <span class="muControl">break-if</span> at-bottom?:boolean + bottom:number<span class="Special"> <- </span>subtract height, <span class="Constant">1</span> + at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal *row, bottom + <span class="muControl">break-if</span> at-bottom? <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> + *column<span class="Special"> <- </span>copy <span class="Constant">0</span> + *row<span class="Special"> <- </span>add *row, <span class="Constant">1</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># save character in fake screen</span> - 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:screen-cell<span class="Special"> <- </span>get x:address:screen/deref, data:offset - len:number<span class="Special"> <- </span>length buf:address:array:screen-cell/deref + index:number<span class="Special"> <- </span>multiply *row, width + index<span class="Special"> <- </span>add index, *column + buf:address:array:screen-cell<span class="Special"> <- </span>get *sc, data:offset + len:number<span class="Special"> <- </span>length *buf <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="muControl">break-unless</span> backspace?:boolean + backspace?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">8</span> + <span class="muControl">break-unless</span> backspace? <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="muControl">break-if</span> at-left?:boolean + at-left?:boolean<span class="Special"> <- </span>lesser-or-equal *column, <span class="Constant">0</span> + <span class="muControl">break-if</span> at-left? <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> - index:number<span class="Special"> <- </span>subtract index:number, <span class="Constant">1:literal</span> - cursor:address:screen-cell<span class="Special"> <- </span>index-address buf:address:array:screen-cell/deref, index:number - cursor-contents:address:character<span class="Special"> <- </span>get-address cursor:address:screen-cell/deref, contents:offset - cursor-color:address:number<span class="Special"> <- </span>get-address cursor:address:screen-cell/deref, color:offset - cursor-contents:address:character/deref<span class="Special"> <- </span>copy <span class="Constant">32:literal/space</span> - cursor-color:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">7:literal/white</span> + *column<span class="Special"> <- </span>subtract *column, <span class="Constant">1</span> + index<span class="Special"> <- </span>subtract index, <span class="Constant">1</span> + cursor:address:screen-cell<span class="Special"> <- </span>index-address *buf, index + cursor-contents:address:character<span class="Special"> <- </span>get-address *cursor, contents:offset + *cursor-contents<span class="Special"> <- </span>copy <span class="Constant">32/space</span> + cursor-color:address:number<span class="Special"> <- </span>get-address *cursor, color:offset + *cursor-color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> -<span class="CommentedCode">#? $print [saving character ], c:character, [ to fake screen ], cursor:address/screen, 10:literal/newline</span> - cursor:address:screen-cell<span class="Special"> <- </span>index-address buf:address:array:screen-cell/deref, index:number - cursor-contents:address:character<span class="Special"> <- </span>get-address cursor:address:screen-cell/deref, contents:offset - cursor-color:address:number<span class="Special"> <- </span>get-address cursor:address:screen-cell/deref, color:offset - cursor-contents:address:character/deref<span class="Special"> <- </span>copy c:character - cursor-color:address:number/deref<span class="Special"> <- </span>copy color:number +<span class="CommentedCode">#? $print [saving character ], c, [ to fake screen ], cursor, 10/newline</span> + cursor:address:screen-cell<span class="Special"> <- </span>index-address *buf, index + cursor-contents:address:character<span class="Special"> <- </span>get-address *cursor, contents:offset + *cursor-contents<span class="Special"> <- </span>copy c + cursor-color:address:number<span class="Special"> <- </span>get-address *cursor, color:offset + *cursor-color<span class="Special"> <- </span>copy color <span class="Comment"># increment column unless it's already all the way to the right</span> <span class="Delimiter">{</span> - right:number<span class="Special"> <- </span>subtract width:number, <span class="Constant">1:literal</span> - at-right?:boolean<span class="Special"> <- </span>greater-or-equal column:address:number/deref, right:number - <span class="muControl">break-if</span> at-right?:boolean - column:address:number/deref<span class="Special"> <- </span>add column:address:number/deref, <span class="Constant">1:literal</span> + right:number<span class="Special"> <- </span>subtract width, <span class="Constant">1</span> + at-right?:boolean<span class="Special"> <- </span>greater-or-equal *column, right + <span class="muControl">break-if</span> at-right? + *column<span class="Special"> <- </span>add *column, <span class="Constant">1</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> - print-character-to-display c:character, color:number, bg-color:number - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + print-character-to-display c, color, bg-color + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muScenario">scenario</span> print-character-at-top-left [ run [ <span class="CommentedCode">#? $start-tracing #? 3</span> - 1:address:screen<span class="Special"> <- </span>new-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:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 3:array:screen-cell<span class="Special"> <- </span>copy 2:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">2</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">3</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:screen-cell ] 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>7 <span class="Comment"># white</span> - 6<span class="Special"> <- </span>0 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-character-color [ run [ - 1:address:screen<span class="Special"> <- </span>new-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/a</span>, <span class="Constant">1:literal/red</span> - 2:address:array:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 3:array:screen-cell<span class="Special"> <- </span>copy 2:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97/a</span>, <span class="Constant">1/red</span> + <span class="Constant">2</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">3</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:screen-cell ] 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>1 <span class="Comment"># red</span> - 6<span class="Special"> <- </span>0 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># red</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-backspace-character [ run [ <span class="CommentedCode">#? $start-tracing #? 3</span> - 1:address:screen<span class="Special"> <- </span>new-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:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 4:array:screen-cell<span class="Special"> <- </span>copy 3:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">8</span> <span class="Comment"># backspace</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-column:offset + <span class="Constant">3</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">4</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">3</span>:address:array:screen-cell ] 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>7 <span class="Comment"># white</span> - 7<span class="Special"> <- </span>0 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">32</span> <span class="Comment"># space, not 'a'</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-extra-backspace-character [ run [ - 1:address:screen<span class="Special"> <- </span>new-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> - 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:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 4:array:screen-cell<span class="Special"> <- </span>copy 3:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">8</span> <span class="Comment"># backspace</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">8</span> <span class="Comment"># backspace</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-column:offset + <span class="Constant">3</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">4</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">3</span>:address:array:screen-cell ] 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>7 <span class="Comment"># white</span> - 7<span class="Special"> <- </span>0 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">32</span> <span class="Comment"># space, not 'a'</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-at-right-margin [ run [ - 1:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">2: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">98:literal</span> <span class="Comment"># 'b'</span> - 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">99:literal</span> <span class="Comment"># 'c'</span> - 2:number<span class="Special"> <- </span>get 1:address:screen/deref, cursor-column:offset - 3:address:array:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 4:array:screen-cell<span class="Special"> <- </span>copy 3:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">98</span> <span class="Comment"># 'b'</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">99</span> <span class="Comment"># 'c'</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-column:offset + <span class="Constant">3</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">4</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">3</span>:address:array:screen-cell ] memory-should-contain [ - 2<span class="Special"> <- </span>1 <span class="Comment"># cursor column</span> - 4<span class="Special"> <- </span>4 <span class="Comment"># width*height</span> - 5<span class="Special"> <- </span>97 <span class="Comment"># 'a'</span> - 6<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 7<span class="Special"> <- </span>99 <span class="Comment"># 'c' over 'b'</span> - 8<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 9<span class="Special"> <- </span>0 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor column</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># width*height</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">99</span> <span class="Comment"># 'c' over 'b'</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-newline-character [ run [ <span class="CommentedCode">#? $start-tracing #? 3</span> - 1:address:screen<span class="Special"> <- </span>new-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:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 5:array:screen-cell<span class="Special"> <- </span>copy 4:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-row:offset + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-column:offset + <span class="Constant">4</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">5</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">4</span>:address:array:screen-cell ] 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>7 <span class="Comment"># white</span> - 8<span class="Special"> <- </span>0 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-newline-at-bottom-line [ run [ - 1:address:screen<span class="Special"> <- </span>new-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">10:literal/newline</span> - 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</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 + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-row:offset + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-column:offset ] 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> + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> print-at-bottom-right [ run [ - 1:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">2: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">10:literal/newline</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">98:literal</span> <span class="Comment"># 'b'</span> - 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">99:literal</span> <span class="Comment"># 'c'</span> - 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</span> - 1:address:screen<span class="Special"> <- </span>print-character 1:address:screen, <span class="Constant">100:literal</span> <span class="Comment"># 'd'</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:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 5:array:screen-cell<span class="Special"> <- </span>copy 4:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">98</span> <span class="Comment"># 'b'</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">99</span> <span class="Comment"># 'c'</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">10/newline</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">100</span> <span class="Comment"># 'd'</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-row:offset + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, cursor-column:offset + <span class="Constant">4</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">5</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">4</span>:address:array:screen-cell ] memory-should-contain [ - 2<span class="Special"> <- </span>1 <span class="Comment"># cursor row</span> - 3<span class="Special"> <- </span>1 <span class="Comment"># cursor column</span> - 5<span class="Special"> <- </span>4 <span class="Comment"># width*height</span> - 6<span class="Special"> <- </span>0 <span class="Comment"># unused</span> - 7<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 8<span class="Special"> <- </span>0 <span class="Comment"># unused</span> - 9<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 10<span class="Special"> <- </span>97 <span class="Comment"># 'a'</span> - 11<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 12<span class="Special"> <- </span>100 <span class="Comment"># 'd' over 'b' and 'c' and newline</span> - 13<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 14<span class="Special"> <- </span>0 + <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor column</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># width*height</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># unused</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># unused</span> + <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">100</span> <span class="Comment"># 'd' over 'b' and 'c' and newline</span> + <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muRecipe">recipe</span> clear-line [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, clear line in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - 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 - original-column:number<span class="Special"> <- </span>copy column:address:number/deref + <span class="muControl">break-unless</span> sc + width:number<span class="Special"> <- </span>get *sc, num-columns:offset + column:address:number<span class="Special"> <- </span>get-address *sc, cursor-column:offset + original-column:number<span class="Special"> <- </span>copy *column <span class="Comment"># space over the entire line</span> <span class="CommentedCode">#? $start-tracing #? 1</span> <span class="Delimiter">{</span> -<span class="CommentedCode">#? $print column:address:number/deref, 10:literal/newline</span> - right:number<span class="Special"> <- </span>subtract width:number, <span class="Constant">1:literal</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal column:address:number/deref, right:number - <span class="muControl">break-if</span> done?:boolean - print-character x:address:screen, <span class="Constant">[ ]</span> <span class="Comment"># implicitly updates 'column'</span> +<span class="CommentedCode">#? $print *column, 10/newline</span> + right:number<span class="Special"> <- </span>subtract width, <span class="Constant">1</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal *column, right + <span class="muControl">break-if</span> done? + print-character sc, <span class="Constant">[ ]</span> <span class="Comment"># implicitly updates 'column'</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># now back to where the cursor was</span> - column:address:number/deref<span class="Special"> <- </span>copy original-column:number - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + *column<span class="Special"> <- </span>copy original-column + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> clear-line-on-display - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> cursor-position [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, lookup cursor in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - 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="muControl">reply</span> row:number, column:number, x:address:screen/same-as-ingredient:0 + <span class="muControl">break-unless</span> sc + row:number<span class="Special"> <- </span>get *sc, cursor-row:offset + column:number<span class="Special"> <- </span>get *sc, cursor-column:offset + <span class="muControl">reply</span> row, column, sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> - row:number, column:number<span class="Special"> <- </span>cursor-position-on-display - <span class="muControl">reply</span> row:number, column:number, x:address:screen/same-as-ingredient:0 + row, column<span class="Special"> <- </span>cursor-position-on-display + <span class="muControl">reply</span> row, column, sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> move-cursor [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> new-row:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> new-column:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - 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="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">break-unless</span> sc + row:address:number<span class="Special"> <- </span>get-address *sc, cursor-row:offset + *row<span class="Special"> <- </span>copy new-row + column:address:number<span class="Special"> <- </span>get-address *sc, cursor-column:offset + *column<span class="Special"> <- </span>copy new-column + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> - move-cursor-on-display new-row:number, new-column:number - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + move-cursor-on-display new-row, new-column + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muScenario">scenario</span> clear-line-erases-printed-characters [ run [ <span class="CommentedCode">#? $start-tracing #? 4</span> - 1:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> <span class="Comment"># print a character</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="Constant">1</span>:address:screen<span class="Special"> <- </span>print-character <span class="Constant">1</span>:address:screen, <span class="Constant">97</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, <span class="Constant">0:literal/row</span>, <span class="Constant">0:literal/column</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>move-cursor <span class="Constant">1</span>:address:screen, <span class="Constant">0/row</span>, <span class="Constant">0/column</span> <span class="Comment"># clear line</span> - 1:address:screen<span class="Special"> <- </span>clear-line 1:address:screen - 2:address:array:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 3:array:screen-cell<span class="Special"> <- </span>copy 2:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>clear-line <span class="Constant">1</span>:address:screen + <span class="Constant">2</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">3</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">2</span>:address:array:screen-cell ] <span class="Comment"># screen should be blank</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>7 - 6<span class="Special"> <- </span>0 - 7<span class="Special"> <- </span>7 - 8<span class="Special"> <- </span>0 - 9<span class="Special"> <- </span>7 - 10<span class="Special"> <- </span>0 - 11<span class="Special"> <- </span>7 - 12<span class="Special"> <- </span>0 - 13<span class="Special"> <- </span>7 - 14<span class="Special"> <- </span>0 - 15<span class="Special"> <- </span>7 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">7</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">7</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">7</span> + <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">7</span> + <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">7</span> + <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant">15</span><span class="Special"> <- </span><span class="Constant">7</span> ] ] <span class="muRecipe">recipe</span> cursor-down [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen + <span class="muControl">break-unless</span> sc <span class="Delimiter">{</span> <span class="Comment"># if row < height-1</span> - 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 - max:number<span class="Special"> <- </span>subtract height:number, <span class="Constant">1:literal</span> - at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row:address:number/deref, max:number - <span class="muControl">break-if</span> at-bottom?:boolean + height:number<span class="Special"> <- </span>get *sc, num-rows:offset + row:address:number<span class="Special"> <- </span>get-address *sc, cursor-row:offset + max:number<span class="Special"> <- </span>subtract height, <span class="Constant">1</span> + at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal *row, max + <span class="muControl">break-if</span> at-bottom? <span class="Comment"># row = row+1</span> -<span class="CommentedCode">#? $print [AAA: ], row:address:number, [ -> ], row:address:number/deref, 10:literal/newline</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, 10:literal/newline</span> -<span class="CommentedCode">#? $start-tracing #? 1</span> + *row<span class="Special"> <- </span>add *row, <span class="Constant">1</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-down-on-display - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> cursor-up [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen + <span class="muControl">break-unless</span> sc <span class="Delimiter">{</span> <span class="Comment"># if row > 0</span> - row:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-row:offset - at-top?:boolean<span class="Special"> <- </span>lesser-or-equal row:address:number/deref, <span class="Constant">0:literal</span> - <span class="muControl">break-if</span> at-top?:boolean + row:address:number<span class="Special"> <- </span>get-address *sc, cursor-row:offset + at-top?:boolean<span class="Special"> <- </span>lesser-or-equal *row, <span class="Constant">0</span> + <span class="muControl">break-if</span> at-top? <span class="Comment"># row = row-1</span> - row:address:number/deref<span class="Special"> <- </span>subtract row:address:number/deref, <span class="Constant">1:literal</span> + *row<span class="Special"> <- </span>subtract *row, <span class="Constant">1</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-up-on-display - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> cursor-right [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen + <span class="muControl">break-unless</span> sc <span class="Delimiter">{</span> <span class="Comment"># if column < width-1</span> - 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 - max:number<span class="Special"> <- </span>subtract width:number, <span class="Constant">1:literal</span> - at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal column:address:number/deref, max:number - <span class="muControl">break-if</span> at-bottom?:boolean + width:number<span class="Special"> <- </span>get *sc, num-columns:offset + column:address:number<span class="Special"> <- </span>get-address *sc, cursor-column:offset + max:number<span class="Special"> <- </span>subtract width, <span class="Constant">1</span> + at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal *column, max + <span class="muControl">break-if</span> at-bottom? <span class="Comment"># column = column+1</span> - column:address:number/deref<span class="Special"> <- </span>add column:address:number/deref, <span class="Constant">1:literal</span> + *column<span class="Special"> <- </span>add *column, <span class="Constant">1</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-right-on-display - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> cursor-left [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen + <span class="muControl">break-unless</span> sc <span class="Delimiter">{</span> <span class="Comment"># if column > 0</span> - column:address:number<span class="Special"> <- </span>get-address x:address:screen/deref, cursor-column:offset - at-top?:boolean<span class="Special"> <- </span>lesser-or-equal column:address:number/deref, <span class="Constant">0:literal</span> - <span class="muControl">break-if</span> at-top?:boolean + column:address:number<span class="Special"> <- </span>get-address *sc, cursor-column:offset + at-top?:boolean<span class="Special"> <- </span>lesser-or-equal *column, <span class="Constant">0</span> + <span class="muControl">break-if</span> at-top? <span class="Comment"># column = column-1</span> - column:address:number/deref<span class="Special"> <- </span>subtract column:address:number/deref, <span class="Constant">1:literal</span> + *column<span class="Special"> <- </span>subtract *column, <span class="Constant">1</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-left-on-display - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> cursor-to-start-of-line [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - 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="muControl">reply</span> x:address:screen/same-as-ingredient:0 + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + row:number, _, sc<span class="Special"> <- </span>cursor-position sc + column:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + sc<span class="Special"> <- </span>move-cursor sc, row, column + <span class="muControl">reply</span> sc/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> cursor-to-next-line [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - 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="muControl">reply</span> x:address:screen/same-as-ingredient:0 + screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + screen<span class="Special"> <- </span>cursor-down screen + screen<span class="Special"> <- </span>cursor-to-start-of-line screen + <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> screen-width [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - width:number<span class="Special"> <- </span>get x:address:screen/deref, num-columns:offset - <span class="muControl">reply</span> width:number + <span class="muControl">break-unless</span> sc + width:number<span class="Special"> <- </span>get *sc, num-columns:offset + <span class="muControl">reply</span> width <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> width:number<span class="Special"> <- </span>display-width - <span class="muControl">reply</span> width:number + <span class="muControl">reply</span> width ] <span class="muRecipe">recipe</span> screen-height [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + sc:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - height:number<span class="Special"> <- </span>get x:address:screen/deref, num-rows:offset - <span class="muControl">reply</span> height:number + <span class="muControl">break-unless</span> sc + height:number<span class="Special"> <- </span>get *sc, num-rows:offset + <span class="muControl">reply</span> height <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> height:number<span class="Special"> <- </span>display-height - <span class="muControl">reply</span> height:number + <span class="muControl">reply</span> height ] <span class="muRecipe">recipe</span> hide-cursor [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists (not real display), do nothing</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - <span class="muControl">reply</span> x:address:screen + <span class="muControl">break-unless</span> screen + <span class="muControl">reply</span> screen <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> hide-cursor-on-display - <span class="muControl">reply</span> x:address:screen + <span class="muControl">reply</span> screen ] <span class="muRecipe">recipe</span> show-cursor [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists (not real display), do nothing</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - <span class="muControl">reply</span> x:address:screen + <span class="muControl">break-unless</span> screen + <span class="muControl">reply</span> screen <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> show-cursor-on-display - <span class="muControl">reply</span> x:address:screen + <span class="muControl">reply</span> screen ] <span class="muRecipe">recipe</span> hide-screen [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists (not real display), do nothing</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - <span class="muControl">reply</span> x:address:screen + <span class="muControl">break-unless</span> screen + <span class="muControl">reply</span> screen <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> hide-display - <span class="muControl">reply</span> x:address:screen + <span class="muControl">reply</span> screen ] <span class="muRecipe">recipe</span> show-screen [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># if x exists (not real display), do nothing</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:screen - <span class="muControl">reply</span> x:address:screen + <span class="muControl">break-unless</span> screen + <span class="muControl">reply</span> screen <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> show-display - <span class="muControl">reply</span> x:address:screen + <span class="muControl">reply</span> screen ] <span class="muRecipe">recipe</span> print-string [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> s:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">7:literal/white</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default bg-color to black</span> - <span class="muControl">break-if</span> bg-color-found?:boolean - bg-color:number<span class="Special"> <- </span>copy <span class="Constant">0:literal/black</span> + <span class="muControl">break-if</span> bg-color-found? + bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> - 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> + len:number<span class="Special"> <- </span>length *s + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, len:number - <span class="muControl">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, color:number, bg-color:number - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal i, len + <span class="muControl">break-if</span> done? + c:character<span class="Special"> <- </span>index *s, i + print-character screen, c, color, bg-color + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="muScenario">scenario</span> print-string-stops-at-right-margin [ run [ - 1:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> - 1:address:screen<span class="Special"> <- </span>print-string 1:address:screen, 2:address:array:character - 3:address:array:screen-cell<span class="Special"> <- </span>get 1:address:screen/deref, data:offset - 4:array:screen-cell<span class="Special"> <- </span>copy 3:address:array:screen-cell/deref + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> + <span class="Constant">1</span>:address:screen<span class="Special"> <- </span>print-string <span class="Constant">1</span>:address:screen, <span class="Constant">2</span>:address:array:character + <span class="Constant">3</span>:address:array:screen-cell<span class="Special"> <- </span>get *<span class="Constant">1</span>:address:screen, data:offset + <span class="Constant">4</span>:array:screen-cell<span class="Special"> <- </span>copy *<span class="Constant">3</span>:address:array:screen-cell ] memory-should-contain [ - 4<span class="Special"> <- </span>6 <span class="Comment"># width*height</span> - 5<span class="Special"> <- </span>97 <span class="Comment"># 'a'</span> - 6<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 7<span class="Special"> <- </span>98 <span class="Comment"># 'b'</span> - 8<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 9<span class="Special"> <- </span>100 <span class="Comment"># 'd' overwrites 'c'</span> - 10<span class="Special"> <- </span>7 <span class="Comment"># white</span> - 11<span class="Special"> <- </span>0 <span class="Comment"># unused</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">98</span> <span class="Comment"># 'b'</span> + <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">100</span> <span class="Comment"># 'd' overwrites 'c'</span> + <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># unused</span> ] ] <span class="muRecipe">recipe</span> print-integer [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> n:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">7:literal/white</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default bg-color to black</span> - <span class="muControl">break-if</span> bg-color-found?:boolean - bg-color:number<span class="Special"> <- </span>copy <span class="Constant">0:literal/black</span> + <span class="muControl">break-if</span> bg-color-found? + bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> <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, color:number, bg-color:number - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + s:address:array:character<span class="Special"> <- </span>integer-to-decimal-string n + print-string screen, s, color, bg-color + <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span> ] </pre> </body> diff --git a/html/072scenario_screen.cc.html b/html/072scenario_screen.cc.html index 5f24dd8c..44757729 100644 --- a/html/072scenario_screen.cc.html +++ b/html/072scenario_screen.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.traceAbsent { color: #c00000; } -.Constant { color: #00a0a0; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.Constant { color: #00a0a0; } +.traceAbsent { color: #c00000; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -42,9 +41,9 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenarios run_mu_scenario)</span> <span class="Delimiter">:(scenario screen_in_scenario)</span> scenario screen-in-scenario [ - assume-screen <span class="Constant">5</span>:literal/width<span class="Delimiter">,</span> <span class="Constant">3</span>:literal/height + assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height run [ - <span class="Normal">screen</span>:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span>:literal <span class="Comment"># 'a'</span> + screen:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span> <span class="Comment"># 'a'</span> ] screen-should-contain [ <span class="Comment"># 01234</span> @@ -56,10 +55,10 @@ scenario screen-in-scenario [ <span class="Delimiter">:(scenario screen_in_scenario_unicode)</span> scenario screen-in-scenario-unicode-color [ - assume-screen <span class="Constant">5</span>:literal/width<span class="Delimiter">,</span> <span class="Constant">3</span>:literal/height + assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height run [ - <span class="Normal">screen</span>:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">955</span>:literal/greek-small-lambda<span class="Delimiter">,</span> <span class="Constant">1</span>:literal/red - <span class="Normal">screen</span>:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span>:literal/a + screen:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">955</span>/greek-small-lambda<span class="Delimiter">,</span> <span class="Constant">1</span>/red + screen:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span>/a ] screen-should-contain [ <span class="Comment"># 01234</span> @@ -72,10 +71,10 @@ scenario screen-in-scenario-unicode-color [ <span class="Delimiter">:(scenario screen_in_scenario_color)</span> <span class="Comment"># screen-should-contain can check unicode characters in the fake screen</span> scenario screen-in-scenario-color [ - assume-screen <span class="Constant">5</span>:literal/width<span class="Delimiter">,</span> <span class="Constant">3</span>:literal/height + assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height run [ - <span class="Normal">screen</span>:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">955</span>:literal/greek-small-lambda<span class="Delimiter">,</span> <span class="Constant">1</span>:literal/red - <span class="Normal">screen</span>:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span>:literal/a<span class="Delimiter">,</span> <span class="Constant">7</span>:literal/white + screen:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">955</span>/greek-small-lambda<span class="Delimiter">,</span> <span class="Constant">1</span>/red + screen:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">7</span>/white ] <span class="Comment"># screen-should-contain shows everything</span> screen-should-contain [ @@ -86,14 +85,14 @@ scenario screen-in-scenario-color [ ] <span class="Comment"># screen-should-contain-in-color filters out everything except the given</span> <span class="Comment"># color, all you see is the 'a' in white.</span> - screen-should-contain-in-color <span class="Constant">7</span>:literal/white<span class="Delimiter">,</span> [ + screen-should-contain-in-color <span class="Constant">7</span>/white<span class="Delimiter">,</span> [ <span class="Comment"># 01234</span> <span class="Delimiter">.</span> a <span class="Delimiter">.</span> <span class="Delimiter">.</span> <span class="Delimiter">.</span> <span class="Delimiter">.</span> <span class="Delimiter">.</span> ] <span class="Comment"># ..and the λ in red.</span> - screen-should-contain-in-color <span class="Constant">1</span>:literal/red<span class="Delimiter">,</span> [ + screen-should-contain-in-color <span class="Constant">1</span>/red<span class="Delimiter">,</span> [ <span class="Comment"># 01234</span> <span class="Delimiter">.</span>λ <span class="Delimiter">.</span> <span class="Delimiter">.</span> <span class="Delimiter">.</span> @@ -105,9 +104,9 @@ scenario screen-in-scenario-color [ <span class="Special">% Scenario_testing_scenario = true;</span> <span class="Special">% Hide_warnings = true;</span> scenario screen-in-scenario-error [ - assume-screen <span class="Constant">5</span>:literal/width<span class="Delimiter">,</span> <span class="Constant">3</span>:literal/height + assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height run [ - <span class="Normal">screen</span>:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span>:literal <span class="Comment"># 'a'</span> + screen:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span> <span class="Comment"># 'a'</span> ] screen-should-contain [ <span class="Comment"># 01234</span> @@ -123,11 +122,11 @@ scenario screen-in-scenario-error [ <span class="Special">% Hide_warnings = true;</span> <span class="Comment"># screen-should-contain can check unicode characters in the fake screen</span> scenario screen-in-scenario-color [ - assume-screen <span class="Constant">5</span>:literal/width<span class="Delimiter">,</span> <span class="Constant">3</span>:literal/height + assume-screen <span class="Constant">5</span>/width<span class="Delimiter">,</span> <span class="Constant">3</span>/height run [ - <span class="Normal">screen</span>:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span>:literal/a<span class="Delimiter">,</span> <span class="Constant">1</span>:literal/red + screen:address<span class="Special"> <- </span>print-character screen:address<span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">1</span>/red ] - screen-should-contain-in-color <span class="Constant">2</span>:literal/green<span class="Delimiter">,</span> [ + screen-should-contain-in-color <span class="Constant">2</span>/green<span class="Delimiter">,</span> [ <span class="Comment"># 01234</span> <span class="Delimiter">.</span>a <span class="Delimiter">.</span> <span class="Delimiter">.</span> <span class="Delimiter">.</span> @@ -138,14 +137,14 @@ scenario screen-in-scenario-color [ <span class="Comment">//: allow naming just for 'screen'</span> <span class="Delimiter">:(before "End is_special_name Cases")</span> -<span class="Normal">if</span> <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">"screen"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Delimiter">:(scenarios run)</span> <span class="Delimiter">:(scenario convert_names_does_not_warn_when_mixing_special_names_and_numeric_locations)</span> <span class="Special">% Scenario_testing_scenario = true;</span> <span class="Special">% Hide_warnings = true;</span> recipe main [ - <span class="Normal">screen</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number + 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> $warn: <span class="Constant">0</span> @@ -155,8 +154,8 @@ $warn: <span class="Constant">0</span> <span class="Comment">// Scenarios may not define default-space, so they should fit within the</span> <span class="Comment">// initial area of memory reserved for tests. We'll put the predefined</span> <span class="Comment">// variables available to them at the end of that region.</span> -<span class="Normal">const</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Max_variables_in_scenarios = Reserved_for_tests-<span class="Constant">100</span><span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Next_predefined_global_for_scenarios = Max_variables_in_scenarios<span class="Delimiter">;</span> +const long long int Max_variables_in_scenarios = Reserved_for_tests-<span class="Constant">100</span><span class="Delimiter">;</span> +long long int Next_predefined_global_for_scenarios = Max_variables_in_scenarios<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> assert<span class="Delimiter">(</span>Next_predefined_global_for_scenarios < Reserved_for_tests<span class="Delimiter">);</span> <span class="Delimiter">:(after "transform_all()" following "case RUN:")</span> @@ -167,7 +166,7 @@ assert<span class="Delimiter">(</span>Name[tmp_recipe<span class="Delimiter">.</ <span class="Delimiter">:(before "End Globals")</span> <span class="Comment">// Scenario Globals.</span> -<span class="Normal">const</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> SCREEN = Next_predefined_global_for_scenarios++<span class="Delimiter">;</span> +const long long int SCREEN = Next_predefined_global_for_scenarios++<span class="Delimiter">;</span> <span class="Comment">// End Scenario Globals.</span> <span class="Delimiter">:(before "End Special Scenario Variable Names(r)")</span> Name[r][<span class="Constant">"screen"</span>] = SCREEN<span class="Delimiter">;</span> @@ -175,7 +174,7 @@ Name[r][<span class="Constant">"screen"</span>] = SCREEN<span class="D <span class="Delimiter">:(before "End Rewrite Instruction(curr)")</span> <span class="Comment">// rewrite `assume-screen width, height` to</span> <span class="Comment">// `screen:address <- new-fake-screen width, height`</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"assume-screen"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"assume-screen"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> curr<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"new-fake-screen"</span>]<span class="Delimiter">;</span> curr<span class="Delimiter">.</span>name = <span class="Constant">"new-fake-screen"</span><span class="Delimiter">;</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>operation<span class="Delimiter">);</span> @@ -190,8 +189,8 @@ SCREEN_SHOULD_CONTAIN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"screen-should-contain"</span>] = SCREEN_SHOULD_CONTAIN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> SCREEN_SHOULD_CONTAIN: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +case SCREEN_SHOULD_CONTAIN: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><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="Constant">1</span><span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -201,8 +200,8 @@ SCREEN_SHOULD_CONTAIN_IN_COLOR<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"screen-should-contain-in-color"</span>] = SCREEN_SHOULD_CONTAIN_IN_COLOR<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> SCREEN_SHOULD_CONTAIN_IN_COLOR: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +case SCREEN_SHOULD_CONTAIN_IN_COLOR: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><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">1</span><span class="Delimiter">).</span>name<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="Identifier">break</span><span class="Delimiter">;</span> @@ -210,57 +209,57 @@ Recipe_ordinal[<span class="Constant">"screen-should-contain-in-color" <span class="Delimiter">:(before "End Types")</span> <span class="Comment">// scan an array of characters in a unicode-aware, bounds-checked manner</span> -<span class="Normal">struct</span> raw_string_stream <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index<span class="Delimiter">;</span> - <span class="Normal">const</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> max<span class="Delimiter">;</span> - <span class="Normal">const</span> <span class="Normal">char</span>* buf<span class="Delimiter">;</span> +struct raw_string_stream <span class="Delimiter">{</span> + long long int index<span class="Delimiter">;</span> + const long long int max<span class="Delimiter">;</span> + const char* buf<span class="Delimiter">;</span> - raw_string_stream<span class="Delimiter">(</span><span class="Normal">const</span> string&<span class="Delimiter">);</span> - <span class="Normal">uint32_t</span> get<span class="Delimiter">();</span> <span class="Comment">// unicode codepoint</span> - <span class="Normal">uint32_t</span> peek<span class="Delimiter">();</span> <span class="Comment">// unicode codepoint</span> - <span class="Normal">bool</span> at_end<span class="Delimiter">()</span> <span class="Normal">const</span><span class="Delimiter">;</span> - <span class="Normal">void</span> skip_whitespace_and_comments<span class="Delimiter">();</span> + raw_string_stream<span class="Delimiter">(</span>const string&<span class="Delimiter">);</span> + uint32_t get<span class="Delimiter">();</span> <span class="Comment">// unicode codepoint</span> + uint32_t peek<span class="Delimiter">();</span> <span class="Comment">// unicode codepoint</span> + bool at_end<span class="Delimiter">()</span> const<span class="Delimiter">;</span> + void skip_whitespace_and_comments<span class="Delimiter">();</span> <span class="Delimiter">};</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> check_screen<span class="Delimiter">(</span><span class="Normal">const</span> string& expected_contents<span class="Delimiter">,</span> <span class="Normal">const</span> <span class="Normal">int</span> color<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void check_screen<span class="Delimiter">(</span>const string& expected_contents<span class="Delimiter">,</span> const int color<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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_location = Memory[SCREEN]<span class="Delimiter">;</span> - <span class="Normal">int</span> data_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"data"</span><span class="Delimiter">);</span> + long long int screen_location = Memory[SCREEN]<span class="Delimiter">;</span> + int data_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_data_location = screen_location+data_offset<span class="Delimiter">;</span> <span class="Comment">// type: address:array:character</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_data_start = Memory[screen_data_location]<span class="Delimiter">;</span> <span class="Comment">// type: array:character</span> - <span class="Normal">int</span> width_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-columns"</span><span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_width = Memory[screen_location+width_offset]<span class="Delimiter">;</span> - <span class="Normal">int</span> height_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-rows"</span><span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_height = Memory[screen_location+height_offset]<span class="Delimiter">;</span> + long long int screen_data_location = screen_location+data_offset<span class="Delimiter">;</span> <span class="Comment">// type: address:array:character</span> + long long int screen_data_start = Memory[screen_data_location]<span class="Delimiter">;</span> <span class="Comment">// type: array:character</span> + int width_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-columns"</span><span class="Delimiter">);</span> + long long int screen_width = Memory[screen_location+width_offset]<span class="Delimiter">;</span> + int height_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-rows"</span><span class="Delimiter">);</span> + long long int screen_height = Memory[screen_location+height_offset]<span class="Delimiter">;</span> raw_string_stream cursor<span class="Delimiter">(</span>expected_contents<span class="Delimiter">);</span> <span class="Comment">// todo: too-long expected_contents should fail</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> addr = screen_data_start+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// skip length</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> + long long int addr = screen_data_start+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// skip length</span> + for <span class="Delimiter">(</span>long long int 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> cursor<span class="Delimiter">.</span>skip_whitespace_and_comments<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>cursor<span class="Delimiter">.</span>at_end<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>cursor<span class="Delimiter">.</span>at_end<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> assert<span class="Delimiter">(</span>cursor<span class="Delimiter">.</span>get<span class="Delimiter">()</span> == <span class="Constant">'.'</span><span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> column = <span class="Constant">0</span><span class="Delimiter">;</span> column < screen_width<span class="Delimiter">;</span> ++column<span class="Delimiter">,</span> addr+= <span class="Comment">/*</span><span class="Comment">size of screen-cell</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> <span class="Normal">int</span> cell_color_offset = <span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Normal">uint32_t</span> curr = cursor<span class="Delimiter">.</span>get<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[addr] == <span class="Constant">0</span> && isspace<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr == <span class="Constant">' '</span> && color != -<span class="Constant">1</span> && color != Memory[addr+cell_color_offset]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int column = <span class="Constant">0</span><span class="Delimiter">;</span> column < screen_width<span class="Delimiter">;</span> ++column<span class="Delimiter">,</span> addr+= <span class="Comment">/*</span><span class="Comment">size of screen-cell</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + const int cell_color_offset = <span class="Constant">1</span><span class="Delimiter">;</span> + uint32_t curr = cursor<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Memory[addr] == <span class="Constant">0</span> && isspace<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr == <span class="Constant">' '</span> && color != -<span class="Constant">1</span> && color != Memory[addr+cell_color_offset]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// filter out other colors</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[addr] != <span class="Constant">0</span> && Memory[addr] == curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>color == -<span class="Constant">1</span> || color == Memory[addr+cell_color_offset]<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Memory[addr] != <span class="Constant">0</span> && Memory[addr] == curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>color == -<span class="Constant">1</span> || color == Memory[addr+cell_color_offset]<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// contents match but color is off</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// genuine test in a mu file</span> raise << <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> << row << <span class="Constant">", "</span> << column << <span class="Constant">", address "</span> << addr << <span class="Constant">", value "</span> << Memory[addr] << <span class="Constant">") to be in color "</span> << color << <span class="Constant">" instead of "</span> << Memory[addr+cell_color_offset] << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">else</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> << row << <span class="Constant">", "</span> << column << <span class="Constant">") to be in color "</span> << color << <span class="Constant">" instead of "</span> << Memory[addr+cell_color_offset] << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> ++Num_failures<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -269,27 +268,27 @@ Recipe_ordinal[<span class="Constant">"screen-should-contain-in-color" <span class="Comment">// really a mismatch</span> <span class="Comment">// can't print multi-byte unicode characters in warnings just yet. not very useful for debugging anyway.</span> - <span class="Normal">char</span> expected_pretty[<span class="Constant">10</span>] = <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">};</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr < <span class="Constant">256</span> && !iscntrl<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Delimiter">{</span> + char expected_pretty[<span class="Constant">10</span>] = <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">};</span> + if <span class="Delimiter">(</span>curr < <span class="Constant">256</span> && !iscntrl<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// " ('<curr>')"</span> - expected_pretty[<span class="Constant">0</span>] = <span class="Constant">' '</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">1</span>] = <span class="Constant">'('</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">2</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">3</span>] = <span class="Normal">static_cast</span><<span class="Normal">unsigned</span> <span class="Normal">char</span>><span class="Delimiter">(</span>curr<span class="Delimiter">),</span> expected_pretty[<span class="Constant">4</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">5</span>] = <span class="Constant">')'</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">6</span>] = <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> + expected_pretty[<span class="Constant">0</span>] = <span class="Constant">' '</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">1</span>] = <span class="Constant">'('</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">2</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">3</span>] = static_cast<unsigned char><span class="Delimiter">(</span>curr<span class="Delimiter">),</span> expected_pretty[<span class="Constant">4</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">5</span>] = <span class="Constant">')'</span><span class="Delimiter">,</span> expected_pretty[<span class="Constant">6</span>] = <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">char</span> actual_pretty[<span class="Constant">10</span>] = <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">};</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[addr] < <span class="Constant">256</span> && !iscntrl<span class="Delimiter">(</span>Memory[addr]<span class="Delimiter">))</span> <span class="Delimiter">{</span> + char actual_pretty[<span class="Constant">10</span>] = <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">};</span> + if <span class="Delimiter">(</span>Memory[addr] < <span class="Constant">256</span> && !iscntrl<span class="Delimiter">(</span>Memory[addr]<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// " ('<curr>')"</span> - actual_pretty[<span class="Constant">0</span>] = <span class="Constant">' '</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">1</span>] = <span class="Constant">'('</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">2</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">3</span>] = <span class="Normal">static_cast</span><<span class="Normal">unsigned</span> <span class="Normal">char</span>><span class="Delimiter">(</span>Memory[addr]<span class="Delimiter">),</span> actual_pretty[<span class="Constant">4</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">5</span>] = <span class="Constant">')'</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">6</span>] = <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> + actual_pretty[<span class="Constant">0</span>] = <span class="Constant">' '</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">1</span>] = <span class="Constant">'('</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">2</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">3</span>] = static_cast<unsigned char><span class="Delimiter">(</span>Memory[addr]<span class="Delimiter">),</span> actual_pretty[<span class="Constant">4</span>] = <span class="cSpecial">'\''</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">5</span>] = <span class="Constant">')'</span><span class="Delimiter">,</span> actual_pretty[<span class="Constant">6</span>] = <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Current_scenario && !Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// genuine test in a mu file</span> raise << <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> << row << <span class="Constant">", "</span> << column << <span class="Constant">") to contain "</span> << curr << expected_pretty << <span class="Constant">" instead of "</span> << Memory[addr] << actual_pretty << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> dump_screen<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">else</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> << row << <span class="Constant">", "</span> << column << <span class="Constant">") to contain "</span> << curr << expected_pretty << <span class="Constant">" instead of "</span> << Memory[addr] << actual_pretty << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Scenario_testing_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> Passed = <span class="Constant">false</span><span class="Delimiter">;</span> ++Num_failures<span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -301,43 +300,43 @@ Recipe_ordinal[<span class="Constant">"screen-should-contain-in-color" assert<span class="Delimiter">(</span>cursor<span class="Delimiter">.</span>at_end<span class="Delimiter">());</span> <span class="Delimiter">}</span> -raw_string_stream::raw_string_stream<span class="Delimiter">(</span><span class="Normal">const</span> string& backing<span class="Delimiter">)</span> :index<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> max<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>backing<span class="Delimiter">)),</span> buf<span class="Delimiter">(</span>backing<span class="Delimiter">.</span>c_str<span class="Delimiter">())</span> <span class="Delimiter">{}</span> +raw_string_stream::raw_string_stream<span class="Delimiter">(</span>const string& backing<span class="Delimiter">)</span> :index<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> max<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>backing<span class="Delimiter">)),</span> buf<span class="Delimiter">(</span>backing<span class="Delimiter">.</span>c_str<span class="Delimiter">())</span> <span class="Delimiter">{}</span> -<span class="Normal">bool</span> raw_string_stream::at_end<span class="Delimiter">()</span> <span class="Normal">const</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>index >= max<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>tb_utf8_char_length<span class="Delimiter">(</span>buf[index]<span class="Delimiter">)</span> > max-index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << <span class="Constant">"unicode string seems corrupted at index "</span><< index << <span class="Constant">" character "</span> << <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span>buf[index]<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +bool raw_string_stream::at_end<span class="Delimiter">()</span> const <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>index >= max<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>tb_utf8_char_length<span class="Delimiter">(</span>buf[index]<span class="Delimiter">)</span> > max-index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"unicode string seems corrupted at index "</span><< index << <span class="Constant">" character "</span> << static_cast<int><span class="Delimiter">(</span>buf[index]<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<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="Normal">uint32_t</span> raw_string_stream::get<span class="Delimiter">()</span> <span class="Delimiter">{</span> +uint32_t raw_string_stream::get<span class="Delimiter">()</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>index < max<span class="Delimiter">);</span> <span class="Comment">// caller must check bounds before calling 'get'</span> - <span class="Normal">uint32_t</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">int</span> length = tb_utf8_char_to_unicode<span class="Delimiter">(</span>&result<span class="Delimiter">,</span> &buf[index]<span class="Delimiter">);</span> + uint32_t result = <span class="Constant">0</span><span class="Delimiter">;</span> + int length = tb_utf8_char_to_unicode<span class="Delimiter">(</span>&result<span class="Delimiter">,</span> &buf[index]<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>length != TB_EOF<span class="Delimiter">);</span> index += length<span class="Delimiter">;</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">uint32_t</span> raw_string_stream::peek<span class="Delimiter">()</span> <span class="Delimiter">{</span> +uint32_t raw_string_stream::peek<span class="Delimiter">()</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>index < max<span class="Delimiter">);</span> <span class="Comment">// caller must check bounds before calling 'get'</span> - <span class="Normal">uint32_t</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">int</span> length = tb_utf8_char_to_unicode<span class="Delimiter">(</span>&result<span class="Delimiter">,</span> &buf[index]<span class="Delimiter">);</span> + uint32_t result = <span class="Constant">0</span><span class="Delimiter">;</span> + int length = tb_utf8_char_to_unicode<span class="Delimiter">(</span>&result<span class="Delimiter">,</span> &buf[index]<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>length != TB_EOF<span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> raw_string_stream::skip_whitespace_and_comments<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!at_end<span class="Delimiter">())</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>peek<span class="Delimiter">()))</span> get<span class="Delimiter">();</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +void raw_string_stream::skip_whitespace_and_comments<span class="Delimiter">()</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>!at_end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>peek<span class="Delimiter">()))</span> get<span class="Delimiter">();</span> + else if <span class="Delimiter">(</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// skip comment</span> get<span class="Delimiter">();</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> get<span class="Delimiter">();</span> <span class="Comment">// implicitly also handles CRLF</span> + while <span class="Delimiter">(</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> get<span class="Delimiter">();</span> <span class="Comment">// implicitly also handles CRLF</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + else <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -346,31 +345,31 @@ _DUMP_SCREEN<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"$dump-screen"</span>] = _DUMP_SCREEN<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _DUMP_SCREEN: <span class="Delimiter">{</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> -<span class="Normal">void</span> dump_screen<span class="Delimiter">()</span> <span class="Delimiter">{</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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_location = Memory[SCREEN]<span class="Delimiter">;</span> - <span class="Normal">int</span> width_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-columns"</span><span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_width = Memory[screen_location+width_offset]<span class="Delimiter">;</span> - <span class="Normal">int</span> height_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-rows"</span><span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_height = Memory[screen_location+height_offset]<span class="Delimiter">;</span> - <span class="Normal">int</span> data_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"data"</span><span class="Delimiter">);</span> + long long int screen_location = Memory[SCREEN]<span class="Delimiter">;</span> + int width_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-columns"</span><span class="Delimiter">);</span> + long long int screen_width = Memory[screen_location+width_offset]<span class="Delimiter">;</span> + int height_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"screen"</span>]<span class="Delimiter">,</span> <span class="Constant">"num-rows"</span><span class="Delimiter">);</span> + long long int screen_height = Memory[screen_location+height_offset]<span class="Delimiter">;</span> + int data_offset = find_element_name<span class="Delimiter">(</span>Type_ordinal[<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> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_data_location = screen_location+data_offset<span class="Delimiter">;</span> <span class="Comment">// type: address:array:character</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_data_start = Memory[screen_data_location]<span class="Delimiter">;</span> <span class="Comment">// type: array:character</span> + long long int screen_data_location = screen_location+data_offset<span class="Delimiter">;</span> <span class="Comment">// type: address:array:character</span> + long long int screen_data_start = Memory[screen_data_location]<span class="Delimiter">;</span> <span class="Comment">// type: array:character</span> assert<span class="Delimiter">(</span>Memory[screen_data_start] == screen_width*screen_height<span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = screen_data_start+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// skip length</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> + long long int curr = screen_data_start+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// skip length</span> + for <span class="Delimiter">(</span>long long int 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> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> 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> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[curr]<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>long long int 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> + if <span class="Delimiter">(</span>Memory[curr]<span class="Delimiter">)</span> cerr << to_unicode<span class="Delimiter">(</span>Memory[curr]<span class="Delimiter">);</span> - <span class="Normal">else</span> + else cerr << <span class="Constant">' '</span><span class="Delimiter">;</span> curr += <span class="Comment">/*</span><span class="Comment">size of screen-cell</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> diff --git a/html/073scenario_screen_test.mu.html b/html/073scenario_screen_test.mu.html index 229a2e90..71c878ca 100644 --- a/html/073scenario_screen_test.mu.html +++ b/html/073scenario_screen_test.mu.html @@ -31,9 +31,9 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment"># To check our support for screens in scenarios, rewrite tests from print.mu</span> <span class="muScenario">scenario</span> print-character-at-top-left2 [ - assume-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span> + assume-screen <span class="Constant">3/width</span>, <span class="Constant">2/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:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">97/a</span> ] screen-should-contain [ <span class="Constant"> .a .</span> @@ -42,12 +42,12 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] <span class="muScenario">scenario</span> clear-line-erases-printed-characters2 [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">3:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">3/height</span> run [ <span class="Comment"># print a character</span> - screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">97:literal</span> <span class="Comment"># 'a'</span> + screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">97/a</span> <span class="Comment"># move cursor to start of line</span> - screen:address<span class="Special"> <- </span>move-cursor screen:address, <span class="Constant">0:literal/row</span>, <span class="Constant">0:literal/column</span> + screen:address<span class="Special"> <- </span>move-cursor screen:address, <span class="Constant">0/row</span>, <span class="Constant">0/column</span> <span class="Comment"># clear line</span> screen:address<span class="Special"> <- </span>clear-line screen:address ] diff --git a/html/074console.mu.html b/html/074console.mu.html index 104ac569..53c01cfe 100644 --- a/html/074console.mu.html +++ b/html/074console.mu.html @@ -13,13 +13,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -55,37 +54,35 @@ container console [ <span class="muRecipe">recipe</span> new-fake-console [ <span class="Constant">local-scope</span> result:address:console<span class="Special"> <- </span>new console:type - buf:address:address:array:character<span class="Special"> <- </span>get-address result:address:console/deref, data:offset -<span class="CommentedCode">#? $start-tracing #? 1</span> - buf:address:address:array:character/deref<span class="Special"> <- </span><span class="Constant">next-ingredient</span> -<span class="CommentedCode">#? $stop-tracing #? 1</span> - idx:address:number<span class="Special"> <- </span>get-address result:address:console/deref, index:offset - idx:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - <span class="muControl">reply</span> result:address:console + buf:address:address:array:character<span class="Special"> <- </span>get-address *result, data:offset + *buf<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + idx:address:number<span class="Special"> <- </span>get-address *result, index:offset + *idx<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> read-event [ <span class="Constant">local-scope</span> x:address:console<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> x:address:console - idx:address:number<span class="Special"> <- </span>get-address x:address:console/deref, index:offset - buf:address:array:event<span class="Special"> <- </span>get x:address:console/deref, data:offset + <span class="muControl">break-unless</span> x + idx:address:number<span class="Special"> <- </span>get-address *x, index:offset + buf:address:array:event<span class="Special"> <- </span>get *x, data:offset <span class="Delimiter">{</span> - max:number<span class="Special"> <- </span>length buf:address:array:event/deref - done?:boolean<span class="Special"> <- </span>greater-or-equal idx:address:number/deref, max:number - <span class="muControl">break-unless</span> done?:boolean + max:number<span class="Special"> <- </span>length *buf + done?:boolean<span class="Special"> <- </span>greater-or-equal *idx, max + <span class="muControl">break-unless</span> done? dummy:address:event<span class="Special"> <- </span>new event:type - <span class="muControl">reply</span> dummy:address:event/deref, x:address:console/same-as-ingredient:0, <span class="Constant">1:literal/found</span>, <span class="Constant">1:literal/quit</span> + <span class="muControl">reply</span> *dummy, x/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/found</span>, <span class="Constant">1/quit</span> <span class="Delimiter">}</span> - result:event<span class="Special"> <- </span>index buf:address:array:event/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="muControl">reply</span> result:event, x:address:console/same-as-ingredient:0, <span class="Constant">1:literal/found</span>, <span class="Constant">0:literal/quit</span> + result:event<span class="Special"> <- </span>index *buf, *idx + *idx<span class="Special"> <- </span>add *idx, <span class="Constant">1</span> + <span class="muControl">reply</span> result, x/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/found</span>, <span class="Constant">0/quit</span> <span class="Delimiter">}</span> <span class="Comment"># real event source is infrequent; avoid polling it too much</span> switch result:event, found?:boolean<span class="Special"> <- </span>check-for-interaction - <span class="muControl">reply</span> result:event, x:address:console/same-as-ingredient:0, found?:boolean, <span class="Constant">0:literal/quit</span> + <span class="muControl">reply</span> result, x/same-as-ingredient:<span class="Constant">0</span>, found?, <span class="Constant">0/quit</span> ] <span class="Comment"># variant of read-event for just keyboard events. Discards everything that</span> @@ -93,20 +90,13 @@ container console [ <span class="Comment"># newlines, tabs, ctrl-d..</span> <span class="muRecipe">recipe</span> read-key [ <span class="Constant">local-scope</span> -<span class="CommentedCode">#? $print default-space:address:array:location #? 1</span> -<span class="CommentedCode">#? $exit #? 1</span> -<span class="CommentedCode">#? $start-tracing #? 1</span> console:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - x:event, console:address, found?:boolean, quit?:boolean<span class="Special"> <- </span>read-event console:address -<span class="CommentedCode">#? $print [aaa 1] #? 1</span> - <span class="muControl">reply-if</span> quit?:boolean, <span class="Constant">0:literal</span>, console:address/same-as-ingredient:0, found?:boolean, quit?:boolean -<span class="CommentedCode">#? $print [aaa 2] #? 1</span> - <span class="muControl">reply-unless</span> found?:boolean, <span class="Constant">0:literal</span>, console:address/same-as-ingredient:0, found?:boolean, quit?:boolean -<span class="CommentedCode">#? $print [aaa 3] #? 1</span> - c:address:character<span class="Special"> <- </span>maybe-convert x:event, text:variant - <span class="muControl">reply-unless</span> c:address:character, <span class="Constant">0:literal</span>, console:address/same-as-ingredient:0, <span class="Constant">0:literal/found</span>, <span class="Constant">0:literal/quit</span> -<span class="CommentedCode">#? $print [aaa 4] #? 1</span> - <span class="muControl">reply</span> c:address:character/deref, console:address/same-as-ingredient:0, <span class="Constant">1:literal/found</span>, <span class="Constant">0:literal/quit</span> + x:event, console, found?:boolean, quit?:boolean<span class="Special"> <- </span>read-event console + <span class="muControl">reply-if</span> quit?, <span class="Constant">0</span>, console/same-as-ingredient:<span class="Constant">0</span>, found?, quit? + <span class="muControl">reply-unless</span> found?, <span class="Constant">0</span>, console/same-as-ingredient:<span class="Constant">0</span>, found?, quit? + c:address:character<span class="Special"> <- </span>maybe-convert x, text:variant + <span class="muControl">reply-unless</span> c, <span class="Constant">0</span>, console/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/found</span>, <span class="Constant">0/quit</span> + <span class="muControl">reply</span> *c, console/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/found</span>, <span class="Constant">0/quit</span> ] <span class="muRecipe">recipe</span> send-keys-to-channel [ @@ -115,23 +105,25 @@ container console [ chan:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - c:character, console:address, found?:boolean, quit?:boolean<span class="Special"> <- </span>read-key console:address - <span class="muControl">loop-unless</span> found?:boolean - <span class="muControl">break-if</span> quit?:boolean - assert c:character, <span class="Constant">[invalid event, expected text]</span> - print-character screen:address, c:character - chan:address:channel<span class="Special"> <- </span>write chan:address:channel, c:character + c:character, console, found?:boolean, quit?:boolean<span class="Special"> <- </span>read-key console + <span class="muControl">loop-unless</span> found? + <span class="muControl">break-if</span> quit? + assert c, <span class="Constant">[invalid event, expected text]</span> + screen<span class="Special"> <- </span>print-character screen, c + chan<span class="Special"> <- </span>write chan, c <span class="muControl">loop</span> <span class="Delimiter">}</span> + <span class="muControl">reply</span> console/same-as-ingredient:<span class="Constant">0</span>, chan/same-as-ingredient:<span class="Constant">1</span>, screen/same-as-ingredient:<span class="Constant">2</span> ] <span class="muRecipe">recipe</span> wait-for-event [ <span class="Constant">local-scope</span> console:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - _, console:address, found?:boolean<span class="Special"> <- </span>read-event console:address - <span class="muControl">loop-unless</span> found?:boolean + _, console, found?:boolean<span class="Special"> <- </span>read-event console + <span class="muControl">loop-unless</span> found? <span class="Delimiter">}</span> + <span class="muControl">reply</span> console/same-as-ingredient:<span class="Constant">0</span> ] <span class="Comment"># use this helper to skip rendering if there's lots of other events queued up</span> @@ -139,12 +131,12 @@ container console [ <span class="Constant">local-scope</span> console:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> console:address + <span class="muControl">break-unless</span> console <span class="Comment"># fake consoles should be plenty fast; never skip</span> - <span class="muControl">reply</span> <span class="Constant">0:literal/false</span> + <span class="muControl">reply</span> <span class="Constant">0/false</span> <span class="Delimiter">}</span> result:boolean<span class="Special"> <- </span>interactions-left? - <span class="muControl">reply</span> result:boolean + <span class="muControl">reply</span> result ] </pre> </body> diff --git a/html/075scenario_console.cc.html b/html/075scenario_console.cc.html index c64534a7..3b965fdb 100644 --- a/html/075scenario_console.cc.html +++ b/html/075scenario_console.cc.html @@ -15,12 +15,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -64,13 +63,13 @@ scenario keyboard-in-scenario [ ] <span class="Delimiter">:(before "End Scenario Globals")</span> -<span class="Normal">const</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> CONSOLE = Next_predefined_global_for_scenarios++<span class="Delimiter">;</span> +const long long int CONSOLE = Next_predefined_global_for_scenarios++<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Special Scenario Variable Names(r)")</span> Name[r][<span class="Constant">"console"</span>] = CONSOLE<span class="Delimiter">;</span> <span class="Comment">//: allow naming just for 'console'</span> <span class="Delimiter">:(before "End is_special_name Cases")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">"console"</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">"console"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">//: Unlike assume-keyboard, assume-console is easiest to implement as just a</span> <span class="Comment">//: primitive recipe.</span> @@ -79,22 +78,22 @@ ASSUME_CONSOLE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"assume-console"</span>] = ASSUME_CONSOLE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> ASSUME_CONSOLE: <span class="Delimiter">{</span> +case ASSUME_CONSOLE: <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "aaa: " << current_instruction().ingredients.at(0).name << '\n'; //? 2</span> <span class="Comment">// create a temporary recipe just for parsing; it won't contain valid instructions</span> istringstream in<span class="Delimiter">(</span><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> recipe r = slurp_recipe<span class="Delimiter">(</span>in<span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> num_events = count_events<span class="Delimiter">(</span>r<span class="Delimiter">);</span> + long long int num_events = count_events<span class="Delimiter">(</span>r<span class="Delimiter">);</span> <span class="CommentedCode">//? cerr << "fff: " << num_events << '\n'; //? 3</span> <span class="Comment">// initialize the events</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size = num_events*size_of_event<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> + long long int size = num_events*size_of_event<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> ensure_space<span class="Delimiter">(</span>size<span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> event_data_address = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> + long long int event_data_address = Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> Memory[event_data_address] = num_events<span class="Delimiter">;</span> ++Current_routine<span class="Delimiter">-></span>alloc<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> instruction& curr = r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"left-click"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const instruction& curr = 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>curr<span class="Delimiter">.</span>name == <span class="Constant">"left-click"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> Memory[Current_routine<span class="Delimiter">-></span>alloc] = <span class="Comment">/*</span><span class="Comment">tag for 'touch-event' variant of 'event' exclusive-container</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">;</span> Memory[Current_routine<span class="Delimiter">-></span>alloc+<span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">offset of 'type' in 'mouse-event'</span><span class="Comment">*/</span><span class="Constant">0</span>] = TB_KEY_MOUSE_LEFT<span class="Delimiter">;</span> Memory[Current_routine<span class="Delimiter">-></span>alloc+<span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">offset of 'row' in 'mouse-event'</span><span class="Comment">*/</span><span class="Constant">1</span>] = to_integer<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>name<span class="Delimiter">);</span> @@ -102,24 +101,24 @@ Recipe_ordinal[<span class="Constant">"assume-console"</span>] = ASSUM <span class="CommentedCode">//? cerr << "AA left click: " << Memory[Current_routine->alloc+2] << ' ' << Memory[Current_routine->alloc+3] << '\n'; //? 1</span> Current_routine<span class="Delimiter">-></span>alloc += size_of_event<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"press"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + else if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"press"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> Memory[Current_routine<span class="Delimiter">-></span>alloc] = <span class="Comment">/*</span><span class="Comment">tag for 'keycode' variant of 'event' exclusive-container</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> Memory[Current_routine<span class="Delimiter">-></span>alloc+<span class="Constant">1</span>] = to_integer<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>name<span class="Delimiter">);</span> <span class="CommentedCode">//? cerr << "AA press: " << Memory[Current_routine->alloc+1] << '\n'; //? 3</span> Current_routine<span class="Delimiter">-></span>alloc += size_of_event<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Comment">// End Event Handlers</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> <span class="Comment">// keyboard input</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"type"</span><span class="Delimiter">);</span> - <span class="Normal">const</span> string& contents = curr<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="Normal">const</span> <span class="Normal">char</span>* raw_contents = contents<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> num_keyboard_events = unicode_length<span class="Delimiter">(</span>contents<span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = <span class="Constant">0</span><span class="Delimiter">;</span> + const string& contents = curr<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> + const char* raw_contents = contents<span class="Delimiter">.</span>c_str<span class="Delimiter">();</span> + long long int num_keyboard_events = unicode_length<span class="Delimiter">(</span>contents<span class="Delimiter">);</span> + long long int curr = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "AAA: " << num_keyboard_events << '\n'; //? 1</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < num_keyboard_events<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < num_keyboard_events<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> Memory[Current_routine<span class="Delimiter">-></span>alloc] = <span class="Comment">/*</span><span class="Comment">tag for 'text' variant of 'event' exclusive-container</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">uint32_t</span> curr_character<span class="Delimiter">;</span> + uint32_t curr_character<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>curr < SIZE<span class="Delimiter">(</span>contents<span class="Delimiter">));</span> tb_utf8_char_to_unicode<span class="Delimiter">(</span>&curr_character<span class="Delimiter">,</span> &raw_contents[curr]<span class="Delimiter">);</span> <span class="CommentedCode">//? cerr << "AA keyboard: " << curr_character << '\n'; //? 3</span> @@ -198,57 +197,57 @@ REPLACE_IN_CONSOLE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"replace-in-console"</span>] = REPLACE_IN_CONSOLE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> REPLACE_IN_CONSOLE: <span class="Delimiter">{</span> +case REPLACE_IN_CONSOLE: <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<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">//? cerr << "console: " << Memory[CONSOLE] << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Memory[CONSOLE]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Memory[CONSOLE]<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"console not initialized</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> console_data = Memory[Memory[CONSOLE]+<span class="Constant">1</span>]<span class="Delimiter">;</span> + long long int console_data = Memory[Memory[CONSOLE]+<span class="Constant">1</span>]<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "console data starts at " << console_data << '\n'; //? 1</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size = Memory[console_data]<span class="Delimiter">;</span> <span class="Comment">// array size</span> + long long int size = Memory[console_data]<span class="Delimiter">;</span> <span class="Comment">// array size</span> <span class="CommentedCode">//? cerr << "size of console data is " << size << '\n'; //? 1</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">,</span> curr = console_data+<span class="Constant">1</span><span class="Delimiter">;</span> i < size<span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> curr+=size_of_event<span class="Delimiter">())</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">,</span> curr = console_data+<span class="Constant">1</span><span class="Delimiter">;</span> i < size<span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> curr+=size_of_event<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << curr << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[curr] != <span class="Comment">/*</span><span class="Comment">text</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Memory[curr+<span class="Constant">1</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">continue</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> n = <span class="Constant">0</span><span class="Delimiter">;</span> n < size_of_event<span class="Delimiter">();</span> ++n<span class="Delimiter">)</span> + if <span class="Delimiter">(</span>Memory[curr] != <span class="Comment">/*</span><span class="Comment">text</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Memory[curr+<span class="Constant">1</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">continue</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int n = <span class="Constant">0</span><span class="Delimiter">;</span> n < size_of_event<span class="Delimiter">();</span> ++n<span class="Delimiter">)</span> Memory[curr+n] = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span>n<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> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> count_events<span class="Delimiter">(</span><span class="Normal">const</span> recipe& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">const</span> instruction& curr = r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +long long int count_events<span class="Delimiter">(</span>const recipe& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + const instruction& curr = r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="CommentedCode">//? cerr << "aa: " << curr.name << '\n'; //? 3</span> <span class="CommentedCode">//? cerr << "bb: " << curr.ingredients.at(0).name << '\n'; //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"type"</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"type"</span><span class="Delimiter">)</span> result += unicode_length<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>name<span class="Delimiter">);</span> - <span class="Normal">else</span> + else result++<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "cc: " << result << '\n'; //? 1</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size_of_event<span class="Delimiter">()</span> <span class="Delimiter">{</span> +long long int size_of_event<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Comment">// memoize result if already computed</span> - <span class="Normal">static</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> + static long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>result<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> vector<type_ordinal> type<span class="Delimiter">;</span> type<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"event"</span>]<span class="Delimiter">);</span> result = size_of<span class="Delimiter">(</span>type<span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size_of_events<span class="Delimiter">()</span> <span class="Delimiter">{</span> +long long int size_of_events<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Comment">// memoize result if already computed</span> - <span class="Normal">static</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> + static long long int result = <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>result<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> vector<type_ordinal> type<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"console"</span>]<span class="Delimiter">);</span> type<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"console"</span>]<span class="Delimiter">);</span> diff --git a/html/076scenario_console_test.mu.html b/html/076scenario_console_test.mu.html index a3fa6101..b33cb4cd 100644 --- a/html/076scenario_console_test.mu.html +++ b/html/076scenario_console_test.mu.html @@ -37,20 +37,20 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } type <span class="Constant">[abc]</span> ] run [ - 1:character, console:address, 2:boolean<span class="Special"> <- </span>read-key console:address - 3:character, console:address, 4:boolean<span class="Special"> <- </span>read-key console:address - 5:character, console:address, 6:boolean<span class="Special"> <- </span>read-key console:address - 7:character, console:address, 8:boolean<span class="Special"> <- </span>read-key console:address + <span class="Constant">1</span>:character, console:address, <span class="Constant">2</span>:boolean<span class="Special"> <- </span>read-key console:address + <span class="Constant">3</span>:character, console:address, <span class="Constant">4</span>:boolean<span class="Special"> <- </span>read-key console:address + <span class="Constant">5</span>:character, console:address, <span class="Constant">6</span>:boolean<span class="Special"> <- </span>read-key console:address + <span class="Constant">7</span>:character, console:address, <span class="Constant">8</span>:boolean<span class="Special"> <- </span>read-key console:address ] memory-should-contain [ - 1<span class="Special"> <- </span>97 <span class="Comment"># 'a'</span> - 2<span class="Special"> <- </span>1 - 3<span class="Special"> <- </span>98 <span class="Comment"># 'b'</span> - 4<span class="Special"> <- </span>1 - 5<span class="Special"> <- </span>99 <span class="Comment"># 'c'</span> - 6<span class="Special"> <- </span>1 - 7<span class="Special"> <- </span>0 <span class="Comment"># eof</span> - 8<span class="Special"> <- </span>1 + <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="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="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="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> ] ] </pre> diff --git a/html/080trace_browser.cc.html b/html/080trace_browser.cc.html index 07635388..f2139f3f 100644 --- a/html/080trace_browser.cc.html +++ b/html/080trace_browser.cc.html @@ -15,11 +15,10 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -36,31 +35,31 @@ _BROWSE_TRACE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"$browse-trace"</span>] = _BROWSE_TRACE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _BROWSE_TRACE: <span class="Delimiter">{</span> +case _BROWSE_TRACE: <span class="Delimiter">{</span> start_trace_browser<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Globals")</span> -set<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> Visible<span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Top_of_screen = <span class="Constant">0</span><span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Last_printed_row = <span class="Constant">0</span><span class="Delimiter">;</span> -map<<span class="Normal">int</span><span class="Delimiter">,</span> <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>> Trace_index<span class="Delimiter">;</span> <span class="Comment">// screen row -> trace index</span> +set<long long int> Visible<span class="Delimiter">;</span> +long long int Top_of_screen = <span class="Constant">0</span><span class="Delimiter">;</span> +long long int Last_printed_row = <span class="Constant">0</span><span class="Delimiter">;</span> +map<int<span class="Delimiter">,</span> long long int> Trace_index<span class="Delimiter">;</span> <span class="Comment">// screen row -> trace index</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> start_trace_browser<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +void start_trace_browser<span class="Delimiter">()</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> cerr << <span class="Constant">"computing depth to display</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> min_depth = <span class="Constant">9999</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int min_depth = <span class="Constant">9999</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace_line& curr_line = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth < min_depth<span class="Delimiter">)</span> min_depth = curr_line<span class="Delimiter">.</span>depth<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth < min_depth<span class="Delimiter">)</span> min_depth = curr_line<span class="Delimiter">.</span>depth<span class="Delimiter">;</span> <span class="Delimiter">}</span> cerr << <span class="Constant">"depth is "</span> << min_depth << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> cerr << <span class="Constant">"computing lines to display</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>depth == min_depth<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>depth == min_depth<span class="Delimiter">)</span> Visible<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Delimiter">}</span> tb_init<span class="Delimiter">();</span> @@ -68,62 +67,62 @@ map<<span class="Normal">int</span><span class="Delimiter">,</span> <span cla tb_event event<span class="Delimiter">;</span> Top_of_screen = <span class="Constant">0</span><span class="Delimiter">;</span> refresh_screen_rows<span class="Delimiter">();</span> - <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> render<span class="Delimiter">();</span> - <span class="Normal">do</span> <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> <span class="Normal">while</span> <span class="Delimiter">(</span>event<span class="Delimiter">.</span>type != TB_EVENT_KEY<span class="Delimiter">);</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> key = event<span class="Delimiter">.</span>key ? event<span class="Delimiter">.</span>key : event<span class="Delimiter">.</span>ch<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'q'</span> || key == <span class="Constant">'Q'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'j'</span> || key == TB_KEY_ARROW_DOWN<span class="Delimiter">)</span> <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> + long long int key = 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>key == <span class="Constant">'q'</span> || key == <span class="Constant">'Q'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>key == <span class="Constant">'j'</span> || key == TB_KEY_ARROW_DOWN<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// move cursor one line down</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_row < Last_printed_row<span class="Delimiter">)</span> ++Display_row<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Display_row < Last_printed_row<span class="Delimiter">)</span> ++Display_row<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'k'</span> || key == TB_KEY_ARROW_UP<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == <span class="Constant">'k'</span> || key == TB_KEY_ARROW_UP<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// move cursor one line up</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Display_row > <span class="Constant">0</span><span class="Delimiter">)</span> --Display_row<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Display_row > <span class="Constant">0</span><span class="Delimiter">)</span> --Display_row<span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'H'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == <span class="Constant">'H'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// move cursor to top of screen</span> Display_row = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'M'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == <span class="Constant">'M'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// move cursor to center of screen</span> Display_row = tb_height<span class="Delimiter">()</span>/<span class="Constant">2</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'L'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == <span class="Constant">'L'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// move cursor to bottom of screen</span> Display_row = tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'J'</span> || key == TB_KEY_PGDN<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == <span class="Constant">'J'</span> || key == TB_KEY_PGDN<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// page-down</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> != Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> != Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> Top_of_screen = Trace_index[tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span>]+<span class="Constant">1</span><span class="Delimiter">;</span> refresh_screen_rows<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'K'</span> || key == TB_KEY_PGUP<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == <span class="Constant">'K'</span> || key == TB_KEY_PGUP<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// page-up is more convoluted</span> <span class="CommentedCode">//? tb_shutdown(); //? 1</span> <span class="CommentedCode">//? cerr << "page-up: Top_of_screen is currently " << Top_of_screen << '\n'; //? 1</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> screen_row = tb_height<span class="Delimiter">();</span> screen_row > <span class="Constant">0</span> && Top_of_screen > <span class="Constant">0</span><span class="Delimiter">;</span> --screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>int screen_row = tb_height<span class="Delimiter">();</span> screen_row > <span class="Constant">0</span> && Top_of_screen > <span class="Constant">0</span><span class="Delimiter">;</span> --screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> --Top_of_screen<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Top_of_screen <= <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>Top_of_screen > <span class="Constant">0</span> && Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Top_of_screen<span class="Delimiter">)</span> == Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>Top_of_screen <= <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + while <span class="Delimiter">(</span>Top_of_screen > <span class="Constant">0</span> && Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Top_of_screen<span class="Delimiter">)</span> == Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> --Top_of_screen<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "now " << Top_of_screen << '\n'; //? 1</span> <span class="Delimiter">}</span> <span class="CommentedCode">//? exit(0); //? 1</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Top_of_screen > <span class="Constant">0</span><span class="Delimiter">)</span> + if <span class="Delimiter">(</span>Top_of_screen > <span class="Constant">0</span><span class="Delimiter">)</span> refresh_screen_rows<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">'G'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == <span class="Constant">'G'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// go to bottom of screen; largely like page-up, interestingly</span> Top_of_screen = SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">)</span>-<span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> screen_row = tb_height<span class="Delimiter">();</span> screen_row > <span class="Constant">0</span> && Top_of_screen > <span class="Constant">0</span><span class="Delimiter">;</span> --screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>int screen_row = tb_height<span class="Delimiter">();</span> screen_row > <span class="Constant">0</span> && Top_of_screen > <span class="Constant">0</span><span class="Delimiter">;</span> --screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> --Top_of_screen<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Top_of_screen <= <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>Top_of_screen > <span class="Constant">0</span> && Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Top_of_screen<span class="Delimiter">)</span> == Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>Top_of_screen <= <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + while <span class="Delimiter">(</span>Top_of_screen > <span class="Constant">0</span> && Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Top_of_screen<span class="Delimiter">)</span> == Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> --Top_of_screen<span class="Delimiter">;</span> <span class="Delimiter">}</span> refresh_screen_rows<span class="Delimiter">();</span> @@ -131,29 +130,29 @@ map<<span class="Normal">int</span><span class="Delimiter">,</span> <span cla Display_row = Last_printed_row<span class="Delimiter">;</span> refresh_screen_rows<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == TB_KEY_CARRIAGE_RETURN<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == TB_KEY_CARRIAGE_RETURN<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// expand lines under current by one level</span> <span class="CommentedCode">//? tb_shutdown();</span> assert<span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Display_row<span class="Delimiter">)</span> != Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">());</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> start_index = Trace_index[Display_row]<span class="Delimiter">;</span> + long long int start_index = Trace_index[Display_row]<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "start_index is " << start_index << '\n';</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> + long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// simultaneously compute end_index and min_depth</span> - <span class="Normal">int</span> min_depth = <span class="Constant">9999</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>index = start_index+<span class="Constant">1</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>index<span class="Delimiter">)</span> != Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + int min_depth = <span class="Constant">9999</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index = start_index+<span class="Constant">1</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>index<span class="Delimiter">)</span> != Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> trace_line& curr_line = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> assert<span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth > Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>start_index<span class="Delimiter">).</span>depth<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth < min_depth<span class="Delimiter">)</span> min_depth = curr_line<span class="Delimiter">.</span>depth<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth < min_depth<span class="Delimiter">)</span> min_depth = curr_line<span class="Delimiter">.</span>depth<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="CommentedCode">//? cerr << "min_depth is " << min_depth << '\n';</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> end_index = index<span class="Delimiter">;</span> + long long int end_index = index<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "end_index is " << end_index << '\n';</span> <span class="Comment">// mark as visible all intervening indices at min_depth</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>index = start_index<span class="Delimiter">;</span> index < end_index<span class="Delimiter">;</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>index = start_index<span class="Delimiter">;</span> index < end_index<span class="Delimiter">;</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace_line& curr_line = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth == min_depth<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth == min_depth<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << "adding " << index << '\n';</span> Visible<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>index<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -161,22 +160,22 @@ map<<span class="Normal">int</span><span class="Delimiter">,</span> <span cla <span class="CommentedCode">//? exit(0);</span> refresh_screen_rows<span class="Delimiter">();</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// collapse all lines under current</span> assert<span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Display_row<span class="Delimiter">)</span> != Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">());</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> start_index = Trace_index[Display_row]<span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> + long long int start_index = Trace_index[Display_row]<span class="Delimiter">;</span> + long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// end_index is the next line at a depth same as or lower than start_index</span> - <span class="Normal">int</span> initial_depth = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>start_index<span class="Delimiter">).</span>depth<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>index = start_index+<span class="Constant">1</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>index<span class="Delimiter">)</span> == Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + int initial_depth = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>start_index<span class="Delimiter">).</span>depth<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index = start_index+<span class="Constant">1</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>index<span class="Delimiter">)</span> == Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> trace_line& curr_line = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth <= initial_depth<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>curr_line<span class="Delimiter">.</span>depth <= initial_depth<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> end_index = index<span class="Delimiter">;</span> + long long int end_index = index<span class="Delimiter">;</span> <span class="Comment">// mark as visible all intervening indices at min_depth</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>index = start_index+<span class="Constant">1</span><span class="Delimiter">;</span> index < end_index<span class="Delimiter">;</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>index = start_index+<span class="Constant">1</span><span class="Delimiter">;</span> index < end_index<span class="Delimiter">;</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> Visible<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>index<span class="Delimiter">);</span> <span class="Delimiter">}</span> refresh_screen_rows<span class="Delimiter">();</span> @@ -186,40 +185,40 @@ map<<span class="Normal">int</span><span class="Delimiter">,</span> <span cla <span class="Delimiter">}</span> <span class="Comment">// update Trace_indices for each screen_row on the basis of Top_of_screen and Visible</span> -<span class="Normal">void</span> refresh_screen_rows<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_row = <span class="Constant">0</span><span class="Delimiter">,</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> +void refresh_screen_rows<span class="Delimiter">()</span> <span class="Delimiter">{</span> + long long int screen_row = <span class="Constant">0</span><span class="Delimiter">,</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> Trace_index<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>screen_row = <span class="Constant">0</span><span class="Delimiter">,</span> index = Top_of_screen<span class="Delimiter">;</span> screen_row < tb_height<span class="Delimiter">()</span> && index < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++screen_row<span class="Delimiter">,</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>screen_row = <span class="Constant">0</span><span class="Delimiter">,</span> index = Top_of_screen<span class="Delimiter">;</span> screen_row < tb_height<span class="Delimiter">()</span> && index < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">);</span> ++screen_row<span class="Delimiter">,</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// skip lines without depth for now</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>index<span class="Delimiter">)</span> == Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>Visible<span class="Delimiter">.</span>find<span class="Delimiter">(</span>index<span class="Delimiter">)</span> == Visible<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> ++index<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>index >= SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">))</span> <span class="Identifier">goto</span> done<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>index >= SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">))</span> <span class="Identifier">goto</span> done<span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>index < SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">));</span> Trace_index[screen_row] = index<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">done</span>:<span class="Delimiter">;</span> +done:<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> render<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_row = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>screen_row = <span class="Constant">0</span><span class="Delimiter">;</span> screen_row < tb_height<span class="Delimiter">();</span> ++screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>screen_row<span class="Delimiter">)</span> == Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +void render<span class="Delimiter">()</span> <span class="Delimiter">{</span> + long long int screen_row = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>screen_row = <span class="Constant">0</span><span class="Delimiter">;</span> screen_row < tb_height<span class="Delimiter">();</span> ++screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>screen_row<span class="Delimiter">)</span> == Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span> trace_line& curr_line = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Trace_index[screen_row]<span class="Delimiter">);</span> ostringstream out<span class="Delimiter">;</span> out << std::setw<span class="Delimiter">(</span><span class="Constant">4</span><span class="Delimiter">)</span> << curr_line<span class="Delimiter">.</span>depth << <span class="Constant">' '</span> << curr_line<span class="Delimiter">.</span>label << <span class="Constant">": "</span> << curr_line<span class="Delimiter">.</span>contents<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>screen_row < tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> delta = lines_hidden<span class="Delimiter">(</span>screen_row<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>screen_row < tb_height<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int delta = lines_hidden<span class="Delimiter">(</span>screen_row<span class="Delimiter">);</span> <span class="Comment">// home-brew escape sequence for red</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>delta > <span class="Constant">999</span><span class="Delimiter">)</span> out << <span class="Constant">"{"</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>delta > <span class="Constant">999</span><span class="Delimiter">)</span> out << <span class="Constant">"{"</span><span class="Delimiter">;</span> out << <span class="Constant">" ("</span> << lines_hidden<span class="Delimiter">(</span>screen_row<span class="Delimiter">)</span> << <span class="Constant">")"</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>delta > <span class="Constant">999</span><span class="Delimiter">)</span> out << <span class="Constant">"}"</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>delta > <span class="Constant">999</span><span class="Delimiter">)</span> out << <span class="Constant">"}"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> render_line<span class="Delimiter">(</span>screen_row<span class="Delimiter">,</span> out<span class="Delimiter">.</span>str<span class="Delimiter">());</span> <span class="Delimiter">}</span> <span class="Comment">// clear rest of screen</span> Last_printed_row = screen_row-<span class="Constant">1</span><span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(;</span> screen_row < tb_height<span class="Delimiter">();</span> ++screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(;</span> screen_row < tb_height<span class="Delimiter">();</span> ++screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> render_line<span class="Delimiter">(</span>screen_row<span class="Delimiter">,</span> <span class="Constant">"~"</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Comment">// move cursor back to display row at the end</span> @@ -227,26 +226,26 @@ map<<span class="Normal">int</span><span class="Delimiter">,</span> <span cla tb_present<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> lines_hidden<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int lines_hidden<span class="Delimiter">(</span>long long int screen_row<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>screen_row<span class="Delimiter">)</span> != Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">());</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>screen_row+<span class="Constant">1</span><span class="Delimiter">)</span> == Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>Trace_index<span class="Delimiter">.</span>find<span class="Delimiter">(</span>screen_row+<span class="Constant">1</span><span class="Delimiter">)</span> == Trace_index<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">)</span>-Trace_index[screen_row]<span class="Delimiter">;</span> - <span class="Normal">else</span> + else <span class="Identifier">return</span> Trace_index[screen_row+<span class="Constant">1</span>] - Trace_index[screen_row]<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">void</span> render_line<span class="Delimiter">(</span><span class="Normal">int</span> screen_row<span class="Delimiter">,</span> <span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> col = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">int</span> color = TB_WHITE<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>col = <span class="Constant">0</span><span class="Delimiter">;</span> col < tb_width<span class="Delimiter">()</span> && col < SIZE<span class="Delimiter">(</span>s<span class="Delimiter">);</span> ++col<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">char</span> c = s<span class="Delimiter">.</span>at<span class="Delimiter">(</span>col<span class="Delimiter">);</span> <span class="Comment">// todo: unicode</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> c = <span class="Constant">';'</span><span class="Delimiter">;</span> <span class="Comment">// replace newlines with semi-colons</span> +void render_line<span class="Delimiter">(</span>int screen_row<span class="Delimiter">,</span> const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int col = <span class="Constant">0</span><span class="Delimiter">;</span> + int color = TB_WHITE<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>col = <span class="Constant">0</span><span class="Delimiter">;</span> col < tb_width<span class="Delimiter">()</span> && col < SIZE<span class="Delimiter">(</span>s<span class="Delimiter">);</span> ++col<span class="Delimiter">)</span> <span class="Delimiter">{</span> + char c = s<span class="Delimiter">.</span>at<span class="Delimiter">(</span>col<span class="Delimiter">);</span> <span class="Comment">// todo: unicode</span> + if <span class="Delimiter">(</span>c == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> c = <span class="Constant">';'</span><span class="Delimiter">;</span> <span class="Comment">// replace newlines with semi-colons</span> <span class="Comment">// escapes. hack: can't start a line with them.</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'{'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> color = <span class="Comment">/*</span><span class="Comment">red</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> c = <span class="Constant">' '</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'}'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> color = TB_WHITE<span class="Delimiter">;</span> c = <span class="Constant">' '</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>c == <span class="Constant">'{'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> color = <span class="Comment">/*</span><span class="Comment">red</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> c = <span class="Constant">' '</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>c == <span class="Constant">'}'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> color = TB_WHITE<span class="Delimiter">;</span> c = <span class="Constant">' '</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> tb_change_cell<span class="Delimiter">(</span>col<span class="Delimiter">,</span> screen_row<span class="Delimiter">,</span> c<span class="Delimiter">,</span> color<span class="Delimiter">,</span> TB_BLACK<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(;</span> col < tb_width<span class="Delimiter">();</span> ++col<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(;</span> col < tb_width<span class="Delimiter">();</span> ++col<span class="Delimiter">)</span> <span class="Delimiter">{</span> tb_change_cell<span class="Delimiter">(</span>col<span class="Delimiter">,</span> screen_row<span class="Delimiter">,</span> <span class="Constant">' '</span><span class="Delimiter">,</span> TB_WHITE<span class="Delimiter">,</span> TB_BLACK<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> diff --git a/html/081run_interactive.cc.html b/html/081run_interactive.cc.html index ab064b17..03c1f523 100644 --- a/html/081run_interactive.cc.html +++ b/html/081run_interactive.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> </style> @@ -38,14 +37,14 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Delimiter">:(scenario run_interactive_code)</span> recipe main [ - <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal] + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new [<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>] run-interactive <span class="Constant">2</span>:address:array:character ] <span class="traceContains">+mem: storing 34 in location 1</span> <span class="Delimiter">:(scenario run_interactive_empty)</span> recipe main [ - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>run-interactive <span class="Constant">0</span>:literal + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>run-interactive <span class="Constant">0</span> ] <span class="Comment"># result is null</span> <span class="traceContains">+mem: storing 0 in location 1</span> @@ -60,32 +59,32 @@ RUN_INTERACTIVE<span class="Delimiter">,</span> Recipe_ordinal[<span class="Constant">"run-interactive"</span>] = RUN_INTERACTIVE<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "run-interactive: " << RUN_INTERACTIVE << '\n'; //? 1</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> RUN_INTERACTIVE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case RUN_INTERACTIVE: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'run-interactive' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'run-interactive' should be a literal string, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">);</span> - <span class="Normal">bool</span> new_code_pushed_to_stack = run_interactive<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="Normal">if</span> <span class="Delimiter">(</span>!new_code_pushed_to_stack<span class="Delimiter">)</span> <span class="Delimiter">{</span> + bool new_code_pushed_to_stack = run_interactive<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> + if <span class="Delimiter">(</span>!new_code_pushed_to_stack<span class="Delimiter">)</span> <span class="Delimiter">{</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>warnings_from_trace<span class="Delimiter">());</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> clean_up_interactive<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// done with this instruction</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <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">}</span> <span class="Delimiter">:(before "End Globals")</span> -<span class="Normal">bool</span> Running_interactive = <span class="Constant">false</span><span class="Delimiter">;</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Old_screen = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// we can support one iteration of screen inside screen</span> +bool Running_interactive = <span class="Constant">false</span><span class="Delimiter">;</span> +long long int Old_screen = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// we can support one iteration of screen inside screen</span> <span class="Delimiter">:(before "End Setup")</span> Running_interactive = <span class="Constant">false</span><span class="Delimiter">;</span> Old_screen = <span class="Constant">0</span><span class="Delimiter">;</span> @@ -93,16 +92,16 @@ Old_screen = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// reads a string, tries to call it as code (treating it as a test), saving</span> <span class="Comment">// all warnings.</span> <span class="Comment">// returns true if successfully called (no errors found during load and transform)</span> -<span class="Normal">bool</span> run_interactive<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"interactive"</span><span class="Delimiter">)</span> == Recipe_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> +bool run_interactive<span class="Delimiter">(</span>long long int address<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"interactive"</span><span class="Delimiter">)</span> == Recipe_ordinal<span class="Delimiter">.</span>end<span class="Delimiter">())</span> Recipe_ordinal[<span class="Constant">"interactive"</span>] = Next_recipe_ordinal++<span class="Delimiter">;</span> Old_screen = Memory[SCREEN]<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "save screen: " << Old_screen << '\n'; //? 2</span> <span class="Comment">// try to sandbox the run as best you can</span> <span class="Comment">// todo: test this</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Current_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Current_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// not already sandboxed</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">1</span><span class="Delimiter">;</span> i < Reserved_for_tests<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">1</span><span class="Delimiter">;</span> i < Reserved_for_tests<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> Memory<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>i<span class="Delimiter">);</span> Name[Recipe_ordinal[<span class="Constant">"interactive"</span>]]<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> @@ -110,12 +109,12 @@ Old_screen = <span class="Constant">0</span><span class="Delimiter">;</span> Name[Recipe_ordinal[<span class="Constant">"interactive"</span>]][<span class="Constant">"screen"</span>] = SCREEN<span class="Delimiter">;</span> <span class="CommentedCode">//? cerr << "screen now at " << Name[Recipe_ordinal["interactive"]]["screen"] << '\n'; //? 1</span> string command = trim<span class="Delimiter">(</span>strip_comments<span class="Delimiter">(</span>read_mu_string<span class="Delimiter">(</span>address<span class="Delimiter">)));</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>command<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>command<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> Recipe<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>Recipe_ordinal[<span class="Constant">"interactive"</span>]<span class="Delimiter">);</span> Hide_warnings = <span class="Constant">true</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> Trace_file = <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Comment">// if there wasn't already a stream we don't want to save it</span> - Trace_stream = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> + Trace_stream = new trace_stream<span class="Delimiter">;</span> Trace_stream<span class="Delimiter">-></span>collect_layer = <span class="Constant">"warn"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// call run(string) but without the scheduling</span> @@ -126,7 +125,7 @@ Old_screen = <span class="Constant">0</span><span class="Delimiter">;</span> command + <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> + <span class="Constant">"]</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> transform_all<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"warn"</span><span class="Delimiter">)</span> > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"warn"</span><span class="Delimiter">)</span> > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> Running_interactive = <span class="Constant">true</span><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>Recipe_ordinal[<span class="Constant">"interactive"</span>]<span class="Delimiter">));</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> @@ -135,9 +134,9 @@ Old_screen = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">:(scenario "run_interactive_returns_stringified_result")</span> recipe main [ <span class="Comment"># try to interactively add 2 and 2</span> - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [add <span class="Constant">2</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal] + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [add <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">2</span>] <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>run-interactive <span class="Constant">1</span>:address:array:character - <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy <span class="Constant">2</span>:address:array:character/deref + <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy <span class="Constant">2</span>:address:array:character/lookup ] <span class="Comment"># first letter in the output should be '4' in unicode</span> <span class="traceContains">+mem: storing 52 in location 11</span> @@ -145,13 +144,13 @@ recipe main [ <span class="Delimiter">:(scenario "run_interactive_returns_string")</span> recipe main [ <span class="Comment"># try to interactively add 2 and 2</span> - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [ - <span class="Constant">100</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [a] - <span class="Constant">101</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [b] + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [ + <span class="Constant">100</span>:address:array:character<span class="Special"> <- </span>new [a] + <span class="Constant">101</span>:address:array:character<span class="Special"> <- </span>new [b] <span class="Constant">102</span>:address:array:character<span class="Special"> <- </span>string-append <span class="Constant">100</span>:address:array:character<span class="Delimiter">,</span> <span class="Constant">101</span>:address:array:character ] <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>run-interactive <span class="Constant">1</span>:address:array:character - <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy <span class="Constant">2</span>:address:array:character/deref + <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy <span class="Constant">2</span>:address:array:character/lookup ] <span class="Comment"># output contains "ab"</span> <span class="traceContains">+mem: storing 97 in location 11</span> @@ -160,9 +159,9 @@ recipe main [ <span class="Delimiter">:(scenario "run_interactive_returns_warnings")</span> recipe main [ <span class="Comment"># run a command that generates a warning</span> - <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [get <span class="Constant">1234</span>:number<span class="Delimiter">,</span> foo:offset] + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [get <span class="Constant">1234</span>:number<span class="Delimiter">,</span> foo:offset] <span class="Constant">2</span>:address:array:character<span class="Delimiter">,</span> <span class="Constant">3</span>:address:array:character<span class="Special"> <- </span>run-interactive <span class="Constant">1</span>:address:array:character - <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy <span class="Constant">3</span>:address:array:character/deref + <span class="Constant">10</span>:array:character<span class="Special"> <- </span>copy <span class="Constant">3</span>:address:array:character/lookup ] <span class="Comment"># warning should be "unknown element foo in container number"</span> <span class="traceContains">+mem: storing 117 in location 11</span> @@ -175,43 +174,43 @@ string Most_recent_results<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Setup")</span> Most_recent_results = <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End of Instruction")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>Running_interactive<span class="Delimiter">)</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>Running_interactive<span class="Delimiter">)</span> <span class="Delimiter">{</span> record_products<span class="Delimiter">(</span>current_instruction<span class="Delimiter">(),</span> products<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> record_products<span class="Delimiter">(</span><span class="Normal">const</span> instruction& instruction<span class="Delimiter">,</span> <span class="Normal">const</span> vector<vector<<span class="Normal">double</span>> >& products<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void record_products<span class="Delimiter">(</span>const instruction& instruction<span class="Delimiter">,</span> const vector<vector<double> >& products<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream out<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// string</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>i < SIZE<span class="Delimiter">(</span>instruction<span class="Delimiter">.</span>products<span class="Delimiter">))</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>is_string<span class="Delimiter">(</span>instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i < SIZE<span class="Delimiter">(</span>instruction<span class="Delimiter">.</span>products<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>is_string<span class="Delimiter">(</span>instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</span> out << read_mu_string<span class="Delimiter">(</span>products<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="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// End Record Product Special-cases</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> + for <span class="Delimiter">(</span>long long int j = <span class="Constant">0</span><span class="Delimiter">;</span> j < SIZE<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> out << products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)</span> << <span class="Constant">' '</span><span class="Delimiter">;</span> out << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> Most_recent_results = out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "Complete Call Fallthrough")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation == RUN_INTERACTIVE && !current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation == RUN_INTERACTIVE && !current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> <= <span class="Constant">3</span><span class="Delimiter">);</span> <span class="Comment">// Send the results of the most recently executed instruction, regardless of</span> <span class="Comment">// call depth, to be converted to string and potentially printed to string.</span> - vector<<span class="Normal">double</span>> result<span class="Delimiter">;</span> + vector<double> result<span class="Delimiter">;</span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>new_mu_string<span class="Delimiter">(</span>Most_recent_results<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><span class="Constant">0</span><span class="Delimiter">),</span> result<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> >= <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - vector<<span class="Normal">double</span>> warnings<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> >= <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<double> warnings<span class="Delimiter">;</span> warnings<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>warnings_from_trace<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><span class="Constant">1</span><span class="Delimiter">),</span> warnings<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> >= <span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - vector<<span class="Normal">double</span>> screen<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">)</span> >= <span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<double> screen<span class="Delimiter">;</span> screen<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Memory[SCREEN]<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><span class="Constant">2</span><span class="Delimiter">),</span> screen<span class="Delimiter">);</span> <span class="Delimiter">}</span> @@ -220,21 +219,21 @@ Most_recent_results = <span class="Constant">""</span><span class="Del <span class="Comment">//: clean up reply after we've popped it off the call-stack</span> <span class="Comment">//: however, we need what was on the stack to decide whether to clean up</span> <span class="Delimiter">:(after "Starting Reply")</span> -<span class="Normal">bool</span> must_clean_up_interactive = <span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">()</span> == <span class="Constant">"interactive"</span><span class="Delimiter">);</span> +bool must_clean_up_interactive = <span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">()</span> == <span class="Constant">"interactive"</span><span class="Delimiter">);</span> <span class="Delimiter">:(after "Falling Through End Of Recipe")</span> -<span class="Normal">bool</span> must_clean_up_interactive = <span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">()</span> == <span class="Constant">"interactive"</span><span class="Delimiter">);</span> +bool must_clean_up_interactive = <span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">()</span> == <span class="Constant">"interactive"</span><span class="Delimiter">);</span> <span class="Delimiter">:(before "End Reply")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>must_clean_up_interactive<span class="Delimiter">)</span> clean_up_interactive<span class="Delimiter">();</span> +if <span class="Delimiter">(</span>must_clean_up_interactive<span class="Delimiter">)</span> clean_up_interactive<span class="Delimiter">();</span> <span class="Delimiter">:(before "Complete Call Fallthrough")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>must_clean_up_interactive<span class="Delimiter">)</span> clean_up_interactive<span class="Delimiter">();</span> +if <span class="Delimiter">(</span>must_clean_up_interactive<span class="Delimiter">)</span> clean_up_interactive<span class="Delimiter">();</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> clean_up_interactive<span class="Delimiter">()</span> <span class="Delimiter">{</span> +void clean_up_interactive<span class="Delimiter">()</span> <span class="Delimiter">{</span> Trace_stream<span class="Delimiter">-></span>newline<span class="Delimiter">();</span> <span class="Comment">// flush trace</span> Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> Running_interactive = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// hack: assume collect_layer isn't set anywhere else</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>collect_layer == <span class="Constant">"warn"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">delete</span> Trace_stream<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>collect_layer == <span class="Constant">"warn"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + delete Trace_stream<span class="Delimiter">;</span> Trace_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="CommentedCode">//? cerr << "restore screen: " << Memory[SCREEN] << " to " << Old_screen << '\n'; //? 1</span> @@ -245,52 +244,52 @@ Most_recent_results = <span class="Constant">""</span><span class="Del <span class="Delimiter">:(code)</span> string strip_comments<span class="Delimiter">(</span>string in<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream result<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>in<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>in<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> result << in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>i < SIZE<span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> + else <span class="Delimiter">{</span> + while <span class="Delimiter">(</span>i < SIZE<span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> ++i<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>i < SIZE<span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> ++i<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>i < SIZE<span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> ++i<span class="Delimiter">;</span> <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> -string read_mu_string<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> size = Memory[address]<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>size == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +string read_mu_string<span class="Delimiter">(</span>long long int address<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int size = Memory[address]<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>size == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> ostringstream tmp<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> curr = address+<span class="Constant">1</span><span class="Delimiter">;</span> curr <= address+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int curr = address+<span class="Constant">1</span><span class="Delimiter">;</span> curr <= address+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// todo: unicode</span> - tmp << <span class="Delimiter">(</span><span class="Normal">char</span><span class="Delimiter">)(</span><span class="Normal">int</span><span class="Delimiter">)</span>Memory[curr]<span class="Delimiter">;</span> + tmp << <span class="Delimiter">(</span>char<span class="Delimiter">)(</span>int<span class="Delimiter">)</span>Memory[curr]<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> tmp<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> stringified_value_of_location<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +long long int stringified_value_of_location<span class="Delimiter">(</span>long long int address<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// convert to string</span> ostringstream out<span class="Delimiter">;</span> out << Memory[address]<span class="Delimiter">;</span> <span class="Identifier">return</span> new_mu_string<span class="Delimiter">(</span>out<span class="Delimiter">.</span>str<span class="Delimiter">());</span> <span class="Delimiter">}</span> -<span class="Normal">bool</span> is_string<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +bool is_string<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">)</span> == <span class="Constant">3</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_ordinal[<span class="Constant">"address"</span>] && x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)</span> == Type_ordinal[<span class="Constant">"array"</span>] && x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">)</span> == Type_ordinal[<span class="Constant">"character"</span>]<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> warnings_from_trace<span class="Delimiter">()</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"warn"</span><span class="Delimiter">)</span> <= <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +long long int warnings_from_trace<span class="Delimiter">()</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"warn"</span><span class="Delimiter">)</span> <= <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> ostringstream out<span class="Delimiter">;</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-></span>label != <span class="Constant">"warn"</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>vector<trace_line>::iterator p = Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-></span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>p<span class="Delimiter">-></span>label != <span class="Constant">"warn"</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> out << p<span class="Delimiter">-></span>contents<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>*--p<span class="Delimiter">-></span>contents<span class="Delimiter">.</span>end<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> out << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>*--p<span class="Delimiter">-></span>contents<span class="Delimiter">.</span>end<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> out << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>!out<span class="Delimiter">.</span>str<span class="Delimiter">().</span>empty<span class="Delimiter">());</span> <span class="Identifier">return</span> new_mu_string<span class="Delimiter">(</span>out<span class="Delimiter">.</span>str<span class="Delimiter">());</span> @@ -303,18 +302,18 @@ RELOAD<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"reload"</span>] = RELOAD<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> RELOAD: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case RELOAD: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'reload' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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> + if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'reload' should be a literal string, but got "</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>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span> Trace_file = <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Comment">// if there wasn't already a stream we don't want to save it</span> - Trace_stream = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> + Trace_stream = new trace_stream<span class="Delimiter">;</span> Trace_stream<span class="Delimiter">-></span>collect_layer = <span class="Constant">"warn"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> Hide_warnings = <span class="Constant">true</span><span class="Delimiter">;</span> @@ -326,8 +325,8 @@ Recipe_ordinal[<span class="Constant">"reload"</span>] = RELOAD<span c Hide_warnings = <span class="Constant">false</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>warnings_from_trace<span class="Delimiter">());</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>collect_layer == <span class="Constant">"warn"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">delete</span> Trace_stream<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>collect_layer == <span class="Constant">"warn"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + delete Trace_stream<span class="Delimiter">;</span> Trace_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> diff --git a/html/082persist.cc.html b/html/082persist.cc.html index a450633a..bb5582ee 100644 --- a/html/082persist.cc.html +++ b/html/082persist.cc.html @@ -15,12 +15,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.PreProc { color: #c000c0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } +.PreProc { color: #c000c0; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -41,35 +40,36 @@ RESTORE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"restore"</span>] = RESTORE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> RESTORE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case RESTORE: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'restore' requires exactly one ingredient, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'restore' should be a literal string, but got "</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>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>Current_scenario<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// do nothing in tests</span> string filename = 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="Normal">if</span> <span class="Delimiter">(</span>!is_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> + if <span class="Delimiter">(</span>!is_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> filename = to_string<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> string contents = slurp<span class="Delimiter">(</span><span class="Constant">"lesson/"</span>+filename<span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>contents<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + if <span class="Delimiter">(</span>contents<span class="Delimiter">.</span>empty<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="Normal">else</span> + else 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_mu_string<span class="Delimiter">(</span>contents<span class="Delimiter">));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -string slurp<span class="Delimiter">(</span><span class="Normal">const</span> string& filename<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string slurp<span class="Delimiter">(</span>const string& filename<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cerr << filename << '\n'; //? 1</span> ostringstream result<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="Normal">if</span> <span class="Delimiter">(</span>!fin<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Comment">// don't bother checking errno</span> - <span class="Normal">const</span> <span class="Normal">int</span> N = <span class="Constant">1024</span><span class="Delimiter">;</span> - <span class="Normal">char</span> buf[N]<span class="Delimiter">;</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>!fin<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!fin<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Comment">// don't bother checking errno</span> + const int N = <span class="Constant">1024</span><span class="Delimiter">;</span> + char buf[N]<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>!fin<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> bzero<span class="Delimiter">(</span>buf<span class="Delimiter">,</span> N<span class="Delimiter">);</span> fin<span class="Delimiter">.</span>read<span class="Delimiter">(</span>buf<span class="Delimiter">,</span> N-<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// leave at least one null</span> result << buf<span class="Delimiter">;</span> @@ -84,37 +84,38 @@ SAVE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"save"</span>] = SAVE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> SAVE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +case SAVE: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": 'save' requires exactly two ingredients, but got "</span> << current_instruction<span class="Delimiter">().</span>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'save' should be a literal string, but got "</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>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>!scalar<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_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": second ingredient of 'save' should be an address:array:character, but got "</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>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>Current_scenario<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// do nothing in tests</span> string filename = 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="Normal">if</span> <span class="Delimiter">(</span>!is_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> + if <span class="Delimiter">(</span>!is_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> filename = to_string<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> ofstream fout<span class="Delimiter">((</span><span class="Constant">"lesson/"</span>+filename<span class="Delimiter">).</span>c_str<span class="Delimiter">());</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<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_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": second ingredient of 'save' should be an address:array:character, but got "</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>to_string<span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> string contents = read_mu_string<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> fout << contents<span class="Delimiter">;</span> fout<span class="Delimiter">.</span>close<span class="Delimiter">();</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!exists<span class="Delimiter">(</span><span class="Constant">"lesson/.git"</span><span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!exists<span class="Delimiter">(</span><span class="Constant">"lesson/.git"</span><span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// bug in git: git diff -q messes up --exit-code</span> - <span class="Normal">int</span> status = system<span class="Delimiter">(</span><span class="Constant">"cd lesson; git add .; git diff HEAD --exit-code >/dev/null || git commit -a -m . >/dev/null"</span><span class="Delimiter">);</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>status != <span class="Constant">0</span><span class="Delimiter">)</span> + int status = system<span class="Delimiter">(</span><span class="Constant">"cd lesson; git add .; git diff HEAD --exit-code >/dev/null || git commit -a -m . >/dev/null"</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>status != <span class="Constant">0</span><span class="Delimiter">)</span> raise << <span class="Constant">"error in commit: contents "</span> << contents << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -<span class="Normal">bool</span> exists<span class="Delimiter">(</span><span class="Normal">const</span> string& filename<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">struct</span> stat dummy<span class="Delimiter">;</span> +bool exists<span class="Delimiter">(</span>const string& filename<span class="Delimiter">)</span> <span class="Delimiter">{</span> + struct stat dummy<span class="Delimiter">;</span> <span class="Identifier">return</span> <span class="Constant">0</span> == stat<span class="Delimiter">(</span>filename<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &dummy<span class="Delimiter">);</span> <span class="Delimiter">}</span> -string to_string<span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +string to_string<span class="Delimiter">(</span>long long int x<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream tmp<span class="Delimiter">;</span> tmp << x<span class="Delimiter">;</span> <span class="Identifier">return</span> tmp<span class="Delimiter">.</span>str<span class="Delimiter">();</span> diff --git a/html/999spaces.cc.html b/html/999spaces.cc.html index 9f5b995c..a9512b34 100644 --- a/html/999spaces.cc.html +++ b/html/999spaces.cc.html @@ -13,9 +13,9 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.Delimiter { color: #a04060; } .Constant { color: #00a0a0; } .Comment { color: #9090ff; } +.Delimiter { color: #a04060; } .SalientComment { color: #00ffff; } --> </style> diff --git a/html/callcc.mu.html b/html/callcc.mu.html index e16e87c4..20ebd83c 100644 --- a/html/callcc.mu.html +++ b/html/callcc.mu.html @@ -13,11 +13,11 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -33,18 +33,18 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">recipe</span> main [ c:continuation<span class="Special"> <- </span>f - <span class="muControl">continue-from</span> c:continuation <span class="Comment"># <-- ..when you hit this</span> + <span class="muControl">continue-from</span> c <span class="Comment"># <-- ..when you hit this</span> ] <span class="muRecipe">recipe</span> f [ c:continuation<span class="Special"> <- </span>g - <span class="muControl">reply</span> c:continuation + <span class="muControl">reply</span> c ] <span class="muRecipe">recipe</span> g [ c:continuation<span class="Special"> <- </span><span class="muControl">current-continuation</span> <span class="Comment"># <-- loop back to here</span> - $print <span class="Constant">1:literal</span> - <span class="muControl">reply</span> c:continuation <span class="Comment"># threaded through unmodified after first iteration</span> + $print <span class="Constant">1</span> + <span class="muControl">reply</span> c <span class="Comment"># threaded through unmodified after first iteration</span> ] </pre> </body> diff --git a/html/channel.mu.html b/html/channel.mu.html index 40a058af..45450112 100644 --- a/html/channel.mu.html +++ b/html/channel.mu.html @@ -13,12 +13,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Delimiter { color: #a04060; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -37,15 +37,15 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Constant">local-scope</span> chan:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># n = 0</span> - n:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + n:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>lesser-than n:number, <span class="Constant">5:literal</span> - <span class="muControl">break-unless</span> done?:boolean + done?:boolean<span class="Special"> <- </span>lesser-than n, <span class="Constant">5</span> + <span class="muControl">break-unless</span> done? <span class="Comment"># other threads might get between these prints</span> - $print <span class="Constant">[produce: ]</span>, n:number, <span class="Constant">[ </span> + $print <span class="Constant">[produce: ]</span>, n, <span class="Constant">[ </span> <span class="Constant">]</span> - chan:address:channel<span class="Special"> <- </span>write chan:address:channel, n:number - n:number<span class="Special"> <- </span>add n:number, <span class="Constant">1:literal</span> + chan:address:channel<span class="Special"> <- </span>write chan, n + n<span class="Special"> <- </span>add n, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -56,7 +56,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } chan:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># read an integer from the channel</span> - n:number, chan:address:channel<span class="Special"> <- </span>read chan:address:channel + n:number, chan:address:channel<span class="Special"> <- </span>read chan <span class="Comment"># other threads might get between these prints</span> $print <span class="Constant">[consume: ]</span>, n:number, <span class="Constant">[ </span> <span class="Constant">]</span> @@ -66,12 +66,12 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">recipe</span> main [ <span class="Constant">local-scope</span> - chan:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">3:literal</span> + chan:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">3</span> <span class="Comment"># create two background 'routines' that communicate by a channel</span> - routine1:number<span class="Special"> <- </span>start-running producer:<span class="muRecipe">recipe</span>, chan:address:channel - routine2:number<span class="Special"> <- </span>start-running consumer:<span class="muRecipe">recipe</span>, chan:address:channel - wait-for-routine routine1:number - wait-for-routine routine2:number + routine1:number<span class="Special"> <- </span>start-running producer:<span class="muRecipe">recipe</span>, chan + routine2:number<span class="Special"> <- </span>start-running consumer:<span class="muRecipe">recipe</span>, chan + wait-for-routine routine1 + wait-for-routine routine2 ] </pre> </body> diff --git a/html/chessboard.mu.html b/html/chessboard.mu.html index d66e9ab1..d04f4df0 100644 --- a/html/chessboard.mu.html +++ b/html/chessboard.mu.html @@ -13,15 +13,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } +.Delimiter { color: #a04060; } .muScenario { color: #00af00; } .SalientComment { color: #00ffff; } -.Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -52,7 +52,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Constant"> #</span> <span class="Comment"># Here the console 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/screen</span>, <span class="Constant">0:literal/console</span><span class="Special"> <- </span>chessboard <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal/console</span> + <span class="Constant">0/screen</span>, <span class="Constant">0/console</span><span class="Special"> <- </span>chessboard <span class="Constant">0/screen</span>, <span class="Constant">0/console</span> close-console <span class="Comment"># cleanup screen, keyboard and mouse</span> ] @@ -62,7 +62,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muScenario">scenario</span> print-board-and-read-move [ $close-trace <span class="Comment"># administrivia: most scenarios save and check traces, but this one gets too large/slow</span> <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> + assume-screen <span class="Constant">120/width</span>, <span class="Constant">20/height</span> <span class="Comment"># initialize keyboard to type in a move</span> assume-console [ type <span class="Constant">[a2-a4</span> @@ -70,10 +70,8 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } ] run [ screen:address, console:address<span class="Special"> <- </span>chessboard screen:address, console:address -<span class="CommentedCode">#? $browse-trace #? 1</span> -<span class="CommentedCode">#? $close-trace #? 1</span> <span class="Comment"># icon for the cursor</span> - screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">9251:literal</span> <span class="Comment"># '␣'</span> + screen<span class="Special"> <- </span>print-character screen, <span class="Constant">9251/␣</span> ] screen-should-contain [ <span class="Comment"># 1 2 3 4 5 6 7 8 9 10 11</span> @@ -104,44 +102,41 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="SalientComment">## Here's how 'chessboard' is implemented.</span> <span class="muRecipe">recipe</span> chessboard [ -<span class="CommentedCode">#? $start-tracing [schedule] #? 2</span> -<span class="CommentedCode">#? $start-tracing #? 1</span> <span class="Constant">local-scope</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> console:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> -<span class="CommentedCode">#? $print [screen: ], screen:address, [, console: ], console:address, 10:literal/newline</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>new-channel <span class="Constant">10:literal/capacity</span> - start-running send-keys-to-channel:<span class="muRecipe">recipe</span>, console:address, stdin:address:channel, screen:address + stdin:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">10/capacity</span> + start-running send-keys-to-channel:<span class="muRecipe">recipe</span>, console, stdin, screen <span class="Comment"># buffer lines in stdin</span> - buffered-stdin:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">10:literal/capacity</span> - start-running buffer-lines:<span class="muRecipe">recipe</span>, stdin:address:channel, buffered-stdin:address:channel + buffered-stdin:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">10/capacity</span> + start-running buffer-lines:<span class="muRecipe">recipe</span>, stdin, buffered-stdin <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 - 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> + print-string screen, msg + cursor-to-next-line screen + print-board screen, board + cursor-to-next-line screen + msg<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 - cursor-to-next-line screen:address - msg:address:array:character<span class="Special"> <- </span>new <span class="Constant">[Hit 'q' to exit.</span> + print-string screen, msg + cursor-to-next-line screen + msg<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 + print-string screen, msg <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 - m:address:move, quit:boolean, error:boolean<span class="Special"> <- </span>read-move buffered-stdin:address:channel, screen:address - <span class="muControl">break-if</span> quit:boolean, +quit: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="muControl">loop-if</span> error:boolean + cursor-to-next-line screen + msg<span class="Special"> <- </span>new <span class="Constant">[move: ]</span> + print-string screen, msg + m:address:move, quit:boolean, error:boolean<span class="Special"> <- </span>read-move buffered-stdin, screen + <span class="muControl">break-if</span> quit, <span class="Constant">+quit:label</span> + buffered-stdin<span class="Special"> <- </span>clear-channel buffered-stdin <span class="Comment"># cleanup after error. todo: test this?</span> + <span class="muControl">loop-if</span> error <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 + board<span class="Special"> <- </span>make-move board, m + clear-screen screen <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Constant"> +quit</span> @@ -153,84 +148,84 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Constant">local-scope</span> initial-position:address:array:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <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> + len:number<span class="Special"> <- </span>length *initial-position + correct-length?:boolean<span class="Special"> <- </span>equal len, <span class="Constant">64</span> + assert correct-length?, <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> + board:address:array:address:array:character<span class="Special"> <- </span>new location:type, <span class="Constant">8</span> + col:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>equal col:number, <span class="Constant">8:literal</span> - <span class="muControl">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>new-file initial-position:address:array:number, col:number - col:number<span class="Special"> <- </span>add col:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>equal col, <span class="Constant">8</span> + <span class="muControl">break-if</span> done? + file:address:address:array:character<span class="Special"> <- </span>index-address *board, col + *file<span class="Special"> <- </span>new-file initial-position, col + col<span class="Special"> <- </span>add col, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> board:address:array:address:array:character + <span class="muControl">reply</span> board ] <span class="muRecipe">recipe</span> new-file [ <span class="Constant">local-scope</span> position:address:array:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> index:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - 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> + index<span class="Special"> <- </span>multiply index, <span class="Constant">8</span> + result:address:array:character<span class="Special"> <- </span>new character:type, <span class="Constant">8</span> + row:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>equal row:number, <span class="Constant">8:literal</span> - <span class="muControl">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> + done?:boolean<span class="Special"> <- </span>equal row, <span class="Constant">8</span> + <span class="muControl">break-if</span> done? + dest:address:character<span class="Special"> <- </span>index-address *result, row + *dest<span class="Special"> <- </span>index *position, index + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + index<span class="Special"> <- </span>add index, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:address:array:character + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> print-board [ <span class="Constant">local-scope</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> board:address:array:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - 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> + row:number<span class="Special"> <- </span>copy <span class="Constant">7</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, 10:literal/newline</span> +<span class="CommentedCode">#? $print [printing board to screen ], screen, 10/newline</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>lesser-than row:number, <span class="Constant">0:literal</span> - <span class="muControl">break-if</span> done?:boolean -<span class="CommentedCode">#? $print [printing rank ], row:number, 10:literal/newline</span> + done?:boolean<span class="Special"> <- </span>lesser-than row, <span class="Constant">0</span> + <span class="muControl">break-if</span> done? +<span class="CommentedCode">#? $print [printing rank ], row, 10/newline</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 + rank:number<span class="Special"> <- </span>add row, <span class="Constant">1</span> + print-integer screen, rank s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ | ]</span> - print-string screen:address, s:address:array:character + print-string screen, s <span class="Comment"># print each square in the row</span> - col:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + col:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>equal col:number, <span class="Constant">8:literal</span> + done?:boolean<span class="Special"> <- </span>equal col:number, <span class="Constant">8</span> <span class="muControl">break-if</span> done?:boolean - f:address:array:character<span class="Special"> <- </span>index board:address:array:address:array:character/deref, col:number - c:character<span class="Special"> <- </span>index f:address:array:character/deref, row:number - print-character screen:address, c: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> + f:address:array:character<span class="Special"> <- </span>index *board, col + c:character<span class="Special"> <- </span>index *f, row + print-character screen, c + print-character screen, <span class="Constant">32/space</span> + col<span class="Special"> <- </span>add col, <span class="Constant">1</span> <span class="muControl">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 + row<span class="Special"> <- </span>subtract row, <span class="Constant">1</span> + cursor-to-next-line screen <span class="muControl">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 + s<span class="Special"> <- </span>new <span class="Constant">[ +----------------]</span> + print-string screen, s + screen<span class="Special"> <- </span>cursor-to-next-line screen +<span class="CommentedCode">#? screen <- print-character screen, 97 #? 1</span> + s<span class="Special"> <- </span>new <span class="Constant">[ a b c d e f g h]</span> + screen<span class="Special"> <- </span>print-string screen, s + screen<span class="Special"> <- </span>cursor-to-next-line screen <span class="CommentedCode">#? $print [done printing board</span> <span class="CommentedCode">#? ] #? 1</span> ] @@ -247,24 +242,24 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <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>new-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>new-board initial-position:address:array:number - <span class="muControl">reply</span> board:address:array:address:array:character + initial-position:address:array:number<span class="Special"> <- </span>new-array <span class="Constant">82/R</span>, <span class="Constant">80/P</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">112/p</span>, <span class="Constant">114/r</span>, <span class="Constant">78/N</span>, <span class="Constant">80/P</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">112/p</span>, <span class="Constant">110/n</span>, <span class="Constant">66/B</span>, <span class="Constant">80/P</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">112/p</span>, <span class="Constant">98/b</span>, <span class="Constant">81/Q</span>, <span class="Constant">80/P</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">112/p</span>, <span class="Constant">113/q</span>, <span class="Constant">75/K</span>, <span class="Constant">80/P</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">112/p</span>, <span class="Constant">107/k</span>, <span class="Constant">66/B</span>, <span class="Constant">80/P</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">112/p</span>, <span class="Constant">98/b</span>, <span class="Constant">78/N</span>, <span class="Constant">80/P</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">112/p</span>, <span class="Constant">110/n</span>, <span class="Constant">82/R</span>, <span class="Constant">80/P</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">32/blank</span>, <span class="Constant">112/p</span>, <span class="Constant">114/r</span> +<span class="CommentedCode">#? 82/R, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 114/r,</span> +<span class="CommentedCode">#? 78/N, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 110/n,</span> +<span class="CommentedCode">#? 66/B, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 98/b, </span> +<span class="CommentedCode">#? 81/Q, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 113/q,</span> +<span class="CommentedCode">#? 75/K, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 107/k,</span> +<span class="CommentedCode">#? 66/B, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 98/b,</span> +<span class="CommentedCode">#? 78/N, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 110/n,</span> +<span class="CommentedCode">#? 82/R, 80/P, 32/blank, 32/blank, 32/blank, 32/blank, 112/p, 114/r</span> + board:address:array:address:array:character<span class="Special"> <- </span>new-board initial-position + <span class="muControl">reply</span> board ] <span class="muScenario">scenario</span> printing-the-board [ - assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">12:literal/height</span> + assume-screen <span class="Constant">30/width</span>, <span class="Constant">12/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="Constant">1</span>:address:array:address:array:character/board<span class="Special"> <- </span>initial-position + screen:address<span class="Special"> <- </span>print-board screen:address, <span class="Constant">1</span>:address:array:address:array:character/board <span class="CommentedCode">#? $dump-screen #? 1</span> ] screen-should-contain [ @@ -300,33 +295,30 @@ container move [ <span class="Constant">local-scope</span> stdin:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> -<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="muControl">reply-if</span> quit?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean - <span class="muControl">reply-if</span> error?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean -<span class="CommentedCode">#? close-console #? 1</span> + from-file:number, quit?:boolean, error?:boolean<span class="Special"> <- </span>read-file stdin, screen + <span class="muControl">reply-if</span> quit?, <span class="Constant">0/dummy</span>, quit?, error? + <span class="muControl">reply-if</span> error?, <span class="Constant">0/dummy</span>, quit?, error? <span class="Comment"># construct the move object</span> result:address:move<span class="Special"> <- </span>new move:type - 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="muControl">reply-if</span> quit?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean - <span class="muControl">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="muControl">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="muControl">reply-if</span> quit?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean - <span class="muControl">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="muControl">reply-if</span> quit?:boolean, <span class="Constant">0:literal/dummy</span>, quit?:boolean, error?:boolean - <span class="muControl">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="muControl">reply-if</span> error?:boolean, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, error?:boolean - <span class="muControl">reply</span> result:address:move, quit?:boolean, error?:boolean + x:address:number<span class="Special"> <- </span>get-address *result, from-file:offset + *x<span class="Special"> <- </span>copy from-file + x<span class="Special"> <- </span>get-address *result, from-rank:offset + *x, quit?, error?<span class="Special"> <- </span>read-rank stdin, screen + <span class="muControl">reply-if</span> quit?, <span class="Constant">0/dummy</span>, quit?, error? + <span class="muControl">reply-if</span> error?, <span class="Constant">0/dummy</span>, quit?, error? + error?<span class="Special"> <- </span>expect-from-channel stdin, <span class="Constant">45/dash</span>, screen + <span class="muControl">reply-if</span> error?, <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, error? + x<span class="Special"> <- </span>get-address *result, to-file:offset + *x, quit?, error?<span class="Special"> <- </span>read-file stdin, screen + <span class="muControl">reply-if</span> quit?:boolean, <span class="Constant">0/dummy</span>, quit?:boolean, error?:boolean + <span class="muControl">reply-if</span> error?:boolean, <span class="Constant">0/dummy</span>, quit?:boolean, error?:boolean + x:address:number<span class="Special"> <- </span>get-address *result, to-rank:offset + *x, quit?, error?<span class="Special"> <- </span>read-rank stdin, screen + <span class="muControl">reply-if</span> quit?, <span class="Constant">0/dummy</span>, quit?, error? + <span class="muControl">reply-if</span> error?, <span class="Constant">0/dummy</span>, quit?, error? + error?<span class="Special"> <- </span>expect-from-channel stdin, <span class="Constant">10/newline</span>, screen + <span class="muControl">reply-if</span> error?, <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, error? + <span class="muControl">reply</span> result, quit?, error? ] <span class="Comment"># file:number, quit:boolean, error:boolean <- read-file stdin:address:channel, screen:address</span> @@ -335,50 +327,49 @@ container move [ <span class="Constant">local-scope</span> stdin:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - c:character, stdin:address:channel<span class="Special"> <- </span>read stdin:address:channel + c:character, stdin<span class="Special"> <- </span>read stdin <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="muControl">break-unless</span> q-pressed?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + q-pressed?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">81/Q</span> + <span class="muControl">break-unless</span> q-pressed? + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">1/quit</span>, <span class="Constant">0/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="muControl">break-unless</span> q-pressed?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + q-pressed?<span class="Special"> <- </span>equal c, <span class="Constant">113/q</span> + <span class="muControl">break-unless</span> q-pressed? + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">1/quit</span>, <span class="Constant">0/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="muControl">break-unless</span> empty-fake-keyboard?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + empty-fake-keyboard?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">0/eof</span> + <span class="muControl">break-unless</span> empty-fake-keyboard? + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">1/quit</span>, <span class="Constant">0/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="muControl">break-unless</span> newline?:boolean + newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">break-unless</span> newline? 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="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + print-string screen, error-message + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, <span class="Constant">1/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, 10:literal/newline</span> + file:number<span class="Special"> <- </span>subtract c, <span class="Constant">97/a</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="muControl">break-if</span> above-min:boolean + above-min:boolean<span class="Special"> <- </span>greater-or-equal file, <span class="Constant">0</span> + <span class="muControl">break-if</span> above-min 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="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + print-string screen, error-message + print-character screen, c + cursor-to-next-line screen + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, <span class="Constant">1/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="muControl">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="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + below-max:boolean<span class="Special"> <- </span>lesser-than file, <span class="Constant">8</span> + <span class="muControl">break-if</span> below-max + error-message<span class="Special"> <- </span>new <span class="Constant">[file too high: ]</span> + print-string screen, error-message + print-character screen, c + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, <span class="Constant">1/error</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> file:number, <span class="Constant">0:literal/quit</span>, <span class="Constant">0:literal/error</span> + <span class="muControl">reply</span> file, <span class="Constant">0/quit</span>, <span class="Constant">0/error</span> ] <span class="Comment"># rank:number <- read-rank stdin:address:channel, screen:address</span> @@ -387,44 +378,43 @@ container move [ <span class="Constant">local-scope</span> stdin:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - c:character, stdin:address:channel<span class="Special"> <- </span>read stdin:address:channel + c:character, stdin<span class="Special"> <- </span>read stdin <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="muControl">break-unless</span> q-pressed?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + q-pressed?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">8/Q</span> + <span class="muControl">break-unless</span> q-pressed? + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">1/quit</span>, <span class="Constant">0/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="muControl">break-unless</span> q-pressed?:boolean - <span class="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">1:literal/quit</span>, <span class="Constant">0:literal/error</span> + q-pressed?<span class="Special"> <- </span>equal c, <span class="Constant">113/q</span> + <span class="muControl">break-unless</span> q-pressed? + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">1/quit</span>, <span class="Constant">0/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="muControl">break-unless</span> newline?:boolean + newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10</span> <span class="Comment"># newline</span> + <span class="muControl">break-unless</span> newline? 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="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + print-string screen, error-message + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, <span class="Constant">1/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, 10:literal/newline</span> + rank:number<span class="Special"> <- </span>subtract c, <span class="Constant">49/'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="muControl">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="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + above-min:boolean<span class="Special"> <- </span>greater-or-equal rank, <span class="Constant">0</span> + <span class="muControl">break-if</span> above-min + error-message<span class="Special"> <- </span>new <span class="Constant">[rank too low: ]</span> + print-string screen, error-message + print-character screen, c + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, <span class="Constant">1/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="muControl">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="muControl">reply</span> <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/quit</span>, <span class="Constant">1:literal/error</span> + below-max:boolean<span class="Special"> <- </span>lesser-or-equal rank, <span class="Constant">7</span> + <span class="muControl">break-if</span> below-max + error-message<span class="Special"> <- </span>new <span class="Constant">[rank too high: ]</span> + print-string screen, error-message + print-character screen, c + <span class="muControl">reply</span> <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, <span class="Constant">1/error</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> rank:number, <span class="Constant">0:literal/quit</span>, <span class="Constant">0:literal/error</span> + <span class="muControl">reply</span> rank, <span class="Constant">0/quit</span>, <span class="Constant">0/error</span> ] <span class="Comment"># read a character from the given channel and check that it's what we expect</span> @@ -434,93 +424,81 @@ container move [ stdin:address:channel<span class="Special"> <- </span><span class="Constant">next-ingredient</span> expected:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - c:character, stdin:address:channel<span class="Special"> <- </span>read stdin:address:channel - match?:boolean<span class="Special"> <- </span>equal c:character, expected:character + c:character, stdin<span class="Special"> <- </span>read stdin <span class="Delimiter">{</span> - <span class="muControl">break-if</span> match?:boolean + match?:boolean<span class="Special"> <- </span>equal c, expected + <span class="muControl">break-if</span> match? 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 + print-string screen, s <span class="Delimiter">}</span> - result:boolean<span class="Special"> <- </span>not match?:boolean - <span class="muControl">reply</span> result:boolean + result:boolean<span class="Special"> <- </span>not match? + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> read-move-blocking [ - assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> run [ -<span class="CommentedCode">#? $start-tracing #? 1</span> - 1:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2:literal</span> -<span class="CommentedCode">#? $print [aaa channel address: ], 1:address:channel, 10:literal/newline</span> - 2:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, 1:address:channel, screen:address + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2</span> + <span class="Constant">2</span>:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, <span class="Constant">1</span>: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, 10:literal/newline</span> - 3:number<span class="Special"> <- </span>routine-state 2:number/id -<span class="CommentedCode">#? $print [I: routine ], 2:number, [ state ], 3:number 10:literal/newline</span> - 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> - assert 4:boolean/waiting?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number/id + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?, [ F read-move-blocking: routine failed to pause <span class="muRecipe">after</span> coming up (<span class="muRecipe">before</span> any keys were pressed)] <span class="Comment"># press 'a'</span> -<span class="CommentedCode">#? $print [ccc channel address: ], 1:address:channel, 10:literal/newline</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="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">97/a</span> + restart <span class="Constant">2</span>: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 10:literal/newline</span> - 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> - assert 4:boolean/waiting?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number/id + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?, [ F read-move-blocking: routine failed to pause <span class="muRecipe">after</span> rank 'a'] <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="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">50/'2'</span> + restart <span class="Constant">2</span>: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 10:literal/newline</span> - 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> - assert 4:boolean/waiting?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number/id + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?, [ F read-move-blocking: routine failed to pause <span class="muRecipe">after</span> file 'a2'] <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="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">45/'-'</span> + restart <span class="Constant">2</span>: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 10:literal/newline</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, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?/routine-state, [ F read-move-blocking: routine failed to pause <span class="muRecipe">after</span> hyphen 'a2-'] <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="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">97/a</span> + restart <span class="Constant">2</span>: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 10:literal/newline</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, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?/routine-state, [ F read-move-blocking: routine failed to pause <span class="muRecipe">after</span> rank 'a2-a'] <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="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">52/'4'</span> + restart <span class="Constant">2</span>: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 10:literal/newline</span> - 4:boolean/waiting?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">2:literal/waiting</span> - assert 4:boolean/waiting?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?, [ F read-move-blocking: routine failed to pause <span class="muRecipe">after</span> file 'a2-a4'] <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="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">10</span> <span class="Comment"># newline</span> + restart <span class="Constant">2</span>: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 10:literal/newline</span> - 4:boolean/completed?<span class="Special"> <- </span>equal 3:number/routine-state, <span class="Constant">1:literal/completed</span> - assert 4:boolean/completed?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number + <span class="Constant">4</span>:boolean/completed?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">1/completed</span> + assert <span class="Constant">4</span>:boolean/completed?, [ F read-move-blocking: routine failed to terminate on newline] trace <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> ] @@ -530,24 +508,24 @@ F read-move-blocking: routine failed to terminate on newline] ] <span class="muScenario">scenario</span> read-move-quit [ - assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> run [ - 1:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2:literal</span> - 2:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, 1:address:channel, screen:address + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2</span> + <span class="Constant">2</span>:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, <span class="Constant">1</span>: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?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number/id + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?, [ F read-move-quit: routine failed to pause <span class="muRecipe">after</span> coming up (<span class="muRecipe">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="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">113/q</span> + restart <span class="Constant">2</span>: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?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number/id + <span class="Constant">4</span>:boolean/completed?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">1/completed</span> + assert <span class="Constant">4</span>:boolean/completed?, [ F read-move-quit: routine failed to terminate on 'q'] trace <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> ] @@ -557,19 +535,19 @@ F read-move-quit: routine failed to terminate on 'q'] ] <span class="muScenario">scenario</span> read-move-illegal-file [ - assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> run [ - 1:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2:literal</span> - 2:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, 1:address:channel, screen:address + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2</span> + <span class="Constant">2</span>:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, <span class="Constant">1</span>: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?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number/id + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?, [ F read-move-file: routine failed to pause <span class="muRecipe">after</span> coming up (<span class="muRecipe">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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">50/'2'</span> + restart <span class="Constant">2</span>:number/routine + wait-for-routine <span class="Constant">2</span>:number ] screen-should-contain [ <span class="Constant"> .file too low: 2 .</span> @@ -578,20 +556,20 @@ F read-move-file: routine failed to pause <span class="muRecipe">after</span> co ] <span class="muScenario">scenario</span> read-move-illegal-rank [ - assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> run [ - 1:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2:literal</span> - 2:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, 1:address:channel, screen:address + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2</span> + <span class="Constant">2</span>:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, <span class="Constant">1</span>: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?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number/id + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?, [ F read-move-file: routine failed to pause <span class="muRecipe">after</span> coming up (<span class="muRecipe">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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">97/a</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">97/a</span> + restart <span class="Constant">2</span>:number/routine + wait-for-routine <span class="Constant">2</span>:number ] screen-should-contain [ <span class="Constant"> .rank too high: a .</span> @@ -600,20 +578,20 @@ F read-move-file: routine failed to pause <span class="muRecipe">after</span> co ] <span class="muScenario">scenario</span> read-move-empty [ - assume-screen <span class="Constant">20:literal/width</span>, <span class="Constant">2:literal/height</span> + assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> run [ - 1:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2:literal</span> - 2:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, 1:address:channel, screen:address + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>new-channel <span class="Constant">2</span> + <span class="Constant">2</span>:number/routine<span class="Special"> <- </span>start-running read-move:<span class="muRecipe">recipe</span>, <span class="Constant">1</span>: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?, [ + wait-for-routine <span class="Constant">2</span>:number + <span class="Constant">3</span>:number<span class="Special"> <- </span>routine-state <span class="Constant">2</span>:number/id + <span class="Constant">4</span>:boolean/waiting?<span class="Special"> <- </span>equal <span class="Constant">3</span>:number/routine-state, <span class="Constant">2/waiting</span> + assert <span class="Constant">4</span>:boolean/waiting?, [ F read-move-file: routine failed to pause <span class="muRecipe">after</span> coming up (<span class="muRecipe">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 + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">10/newline</span> + <span class="Constant">1</span>:address:channel<span class="Special"> <- </span>write <span class="Constant">1</span>:address:channel, <span class="Constant">97/a</span> + restart <span class="Constant">2</span>:number/routine + wait-for-routine <span class="Constant">2</span>:number ] screen-should-contain [ <span class="Constant"> .that's not enough .</span> @@ -625,39 +603,34 @@ F read-move-file: routine failed to pause <span class="muRecipe">after</span> co <span class="Constant">local-scope</span> b:address:array:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> m:address:move<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - from-file:number<span class="Special"> <- </span>get m:address:move/deref, from-file:offset -<span class="CommentedCode">#? $print from-file:number, 10:literal/newline</span> - from-rank:number<span class="Special"> <- </span>get m:address:move/deref, from-rank:offset -<span class="CommentedCode">#? $print from-rank:number, 10:literal/newline</span> - to-file:number<span class="Special"> <- </span>get m:address:move/deref, to-file:offset -<span class="CommentedCode">#? $print to-file:number, 10:literal/newline</span> - to-rank:number<span class="Special"> <- </span>get m:address:move/deref, to-rank:offset -<span class="CommentedCode">#? $print to-rank:number, 10:literal/newline</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, 10:literal/newline</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="muControl">reply</span> b:address:array:address:array:character/same-as-ingredient:0 + from-file:number<span class="Special"> <- </span>get *m, from-file:offset + from-rank:number<span class="Special"> <- </span>get *m, from-rank:offset + to-file:number<span class="Special"> <- </span>get *m, to-file:offset + to-rank:number<span class="Special"> <- </span>get *m, to-rank:offset + f:address:array:character<span class="Special"> <- </span>index *b, from-file + src:address:character/square<span class="Special"> <- </span>index-address *f, from-rank + f<span class="Special"> <- </span>index *b, to-file + dest:address:character/square<span class="Special"> <- </span>index-address *f, to-rank + *dest<span class="Special"> <- </span>copy *src + *src<span class="Special"> <- </span>copy <span class="Constant">32/space</span> + <span class="muControl">reply</span> b/same-as-ingredient:<span class="Constant">0</span> ] <span class="muScenario">scenario</span> making-a-move [ - assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">12:literal/height</span> + assume-screen <span class="Constant">30/width</span>, <span class="Constant">12/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 + <span class="Constant">2</span>:address:array:address:array:character/board<span class="Special"> <- </span>initial-position + <span class="Constant">3</span>:address:move<span class="Special"> <- </span>new move:type + <span class="Constant">4</span>:address:number<span class="Special"> <- </span>get-address *<span class="Constant">3</span>:address:move, from-file:offset + *<span class="Constant">4</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">6/g</span> + <span class="Constant">5</span>:address:number<span class="Special"> <- </span>get-address *<span class="Constant">3</span>:address:move, from-rank:offset + *<span class="Constant">5</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">1/'2'</span> + <span class="Constant">6</span>:address:number<span class="Special"> <- </span>get-address *<span class="Constant">3</span>:address:move, to-file:offset + *<span class="Constant">6</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">6/g</span> + <span class="Constant">7</span>:address:number<span class="Special"> <- </span>get-address *<span class="Constant">3</span>:address:move, to-rank:offset + *<span class="Constant">7</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">3/'4'</span> + <span class="Constant">2</span>:address:array:address:array:character/board<span class="Special"> <- </span>make-move <span class="Constant">2</span>:address:array:address:array:character/board, <span class="Constant">3</span>:address:move + screen:address<span class="Special"> <- </span>print-board screen:address, <span class="Constant">2</span>:address:array:address:array:character/board ] screen-should-contain [ <span class="Comment"># 012345678901234567890123456789</span> diff --git a/html/console.mu.html b/html/console.mu.html index 098c7e43..8e0f4284 100644 --- a/html/console.mu.html +++ b/html/console.mu.html @@ -13,12 +13,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Constant { color: #00a0a0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -38,8 +38,8 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } open-console <span class="Delimiter">{</span> _, found?:boolean<span class="Special"> <- </span>check-for-interaction - <span class="muControl">break-if</span> found?:boolean - print-character-to-display <span class="Constant">97:literal</span>, <span class="Constant">7:literal/white</span> + <span class="muControl">break-if</span> found? + print-character-to-display <span class="Constant">97</span>, <span class="Constant">7/white</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> close-console diff --git a/html/counters.mu.html b/html/counters.mu.html index df75d6bd..926eca68 100644 --- a/html/counters.mu.html +++ b/html/counters.mu.html @@ -13,11 +13,11 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -33,34 +33,34 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment"># (spaces)</span> <span class="muRecipe">recipe</span> new-counter [ - <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30:literal</span> + <span class="Constant">default-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">30</span> n:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply</span> <span class="Constant">default-space</span>:address:array:location + <span class="muControl">reply</span> <span class="Constant">default-space</span> ] <span class="muRecipe">recipe</span> increment-counter [ <span class="Constant">local-scope</span> - 0:address:array:location/names:new-counter<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># setup outer space; it *must* come from 'new-counter'</span> + <span class="Constant">0</span>:address:array:location/names:new-counter<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># setup outer space; it *must* come from 'new-counter'</span> x:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - n:number/space:1<span class="Special"> <- </span>add n:number/space:1, x:number - <span class="muControl">reply</span> n:number/space:1 + n:number/space:<span class="Constant">1</span><span class="Special"> <- </span>add n:number/space:<span class="Constant">1</span>, x + <span class="muControl">reply</span> n:number/space:<span class="Constant">1</span> ] <span class="muRecipe">recipe</span> main [ <span class="Constant">local-scope</span> <span class="Comment"># counter A</span> - a:address:array:location<span class="Special"> <- </span>new-counter <span class="Constant">34:literal</span> + a:address:array:location<span class="Special"> <- </span>new-counter <span class="Constant">34</span> <span class="Comment"># counter B</span> - b:address:array:location<span class="Special"> <- </span>new-counter <span class="Constant">23:literal</span> + b:address:array:location<span class="Special"> <- </span>new-counter <span class="Constant">23</span> <span class="Comment"># increment both by 2 but in different ways</span> - increment-counter a:address:array:location, <span class="Constant">1:literal</span> - b-value:number<span class="Special"> <- </span>increment-counter b:address:array:location, <span class="Constant">2:literal</span> - a-value:number<span class="Special"> <- </span>increment-counter a:address:array:location, <span class="Constant">1:literal</span> + increment-counter a, <span class="Constant">1</span> + b-value:number<span class="Special"> <- </span>increment-counter b, <span class="Constant">2</span> + a-value:number<span class="Special"> <- </span>increment-counter a, <span class="Constant">1</span> <span class="Comment"># check results</span> $print <span class="Constant">[Contents of counters</span> <span class="Constant">]</span> <span class="Comment"># trailing space in next line is to help with syntax highlighting</span> - $print <span class="Constant">[a: ]</span>, a-value:number, <span class="Constant">[ b: ]</span>, b-value:number, <span class="Constant">[ </span> + $print <span class="Constant">[a: ]</span>, a-value, <span class="Constant">[ b: ]</span>, b-value, <span class="Constant">[ </span> <span class="Constant">]</span> ] </pre> diff --git a/html/display.mu.html b/html/display.mu.html index 04daf6de..baf12e83 100644 --- a/html/display.mu.html +++ b/html/display.mu.html @@ -13,11 +13,11 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.CommentedCode { color: #6c6c6c; } +.muRecipe { color: #ff8700; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } -.muRecipe { color: #ff8700; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -33,14 +33,14 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">recipe</span> main [ open-console - print-character-to-display <span class="Constant">97:literal</span>, <span class="Constant">1:literal/red</span>, <span class="Constant">2:literal/green</span> - 1:number/<span class="Special">raw</span>, 2:number/<span class="Special">raw <- </span>cursor-position-on-display + print-character-to-display <span class="Constant">97</span>, <span class="Constant">1/red</span>, <span class="Constant">2/green</span> + <span class="Constant">1</span>:number/<span class="Special">raw</span>, <span class="Constant">2</span>:number/<span class="Special">raw <- </span>cursor-position-on-display wait-for-some-interaction clear-display - move-cursor-on-display <span class="Constant">0:literal</span>, <span class="Constant">4:literal</span> - print-character-to-display <span class="Constant">98:literal</span> + move-cursor-on-display <span class="Constant">0</span>, <span class="Constant">4</span> + print-character-to-display <span class="Constant">98</span> wait-for-some-interaction - move-cursor-on-display <span class="Constant">0:literal</span>, <span class="Constant">0:literal</span> + move-cursor-on-display <span class="Constant">0</span>, <span class="Constant">0</span> clear-line-on-display wait-for-some-interaction move-cursor-down-on-display diff --git a/html/edit.mu.html b/html/edit.mu.html index f86b4c35..fa1b442f 100644 --- a/html/edit.mu.html +++ b/html/edit.mu.html @@ -13,15 +13,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } +.Delimiter { color: #a04060; } .muScenario { color: #00af00; } .SalientComment { color: #00ffff; } -.Delimiter { color: #a04060; } -.CommentedCode { color: #6c6c6c; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -40,11 +40,11 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } open-console initial-recipe:address:array:character<span class="Special"> <- </span>restore <span class="Constant">[recipes.mu]</span> initial-sandbox:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - env:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment <span class="Constant">0:literal/screen</span>, initial-recipe:address:array:character, initial-sandbox:address:array:character - env:address:programming-environment-data<span class="Special"> <- </span>restore-sandboxes env:address:programming-environment-data - render-all <span class="Constant">0:literal/screen</span>, env:address:programming-environment-data - show-screen <span class="Constant">0:literal/screen</span> - event-loop <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal/console</span>, env:address:programming-environment-data + env:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment <span class="Constant">0/screen</span>, initial-recipe, initial-sandbox + env<span class="Special"> <- </span>restore-sandboxes env + render-all <span class="Constant">0/screen</span>, env + show-screen <span class="Constant">0/screen</span> + event-loop <span class="Constant">0/screen</span>, <span class="Constant">0/console</span>, env <span class="Comment"># never gets here</span> ] @@ -61,37 +61,37 @@ container programming-environment-data [ screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> initial-recipe-contents:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> initial-sandbox-contents:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - width:number<span class="Special"> <- </span>screen-width screen:address - height:number<span class="Special"> <- </span>screen-height screen:address + width:number<span class="Special"> <- </span>screen-width screen + height:number<span class="Special"> <- </span>screen-height screen <span class="Comment"># top menu</span> result:address:programming-environment-data<span class="Special"> <- </span>new programming-environment-data:type - draw-horizontal screen:address, <span class="Constant">0:literal</span>, <span class="Constant">0:literal/left</span>, width:number, <span class="Constant">32:literal/space</span>, <span class="Constant">0:literal/black</span>, <span class="Constant">238:literal/grey</span> - button-start:number<span class="Special"> <- </span>subtract width:number, <span class="Constant">20:literal</span> - button-on-screen?:boolean<span class="Special"> <- </span>greater-or-equal button-start:number, <span class="Constant">0:literal</span> - assert button-on-screen?:boolean, <span class="Constant">[screen too narrow for menu]</span> - move-cursor screen:address, <span class="Constant">0:literal/row</span>, button-start:number/column - run-button:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ run (F10) ]</span> - print-string screen:address, run-button:address:array:character, <span class="Constant">255:literal/white</span>, <span class="Constant">161:literal/reddish</span> + draw-horizontal screen, <span class="Constant">0</span>, <span class="Constant">0/left</span>, width, <span class="Constant">32/space</span>, <span class="Constant">0/black</span>, <span class="Constant">238/grey</span> + button-start:number<span class="Special"> <- </span>subtract width, <span class="Constant">20</span> + button-on-screen?:boolean<span class="Special"> <- </span>greater-or-equal button-start, <span class="Constant">0</span> + assert button-on-screen?, <span class="Constant">[screen too narrow for menu]</span> + move-cursor screen, <span class="Constant">0/row</span>, button-start + run-button:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ run (F4) ]</span> + print-string screen, run-button, <span class="Constant">255/white</span>, <span class="Constant">161/reddish</span> <span class="Comment"># dotted line down the middle</span> - divider:number, _<span class="Special"> <- </span>divide-with-remainder width:number, <span class="Constant">2:literal</span> - draw-vertical screen:address, divider:number, <span class="Constant">1:literal/top</span>, height:number, <span class="Constant">9482:literal/vertical-dotted</span> + divider:number, _<span class="Special"> <- </span>divide-with-remainder width, <span class="Constant">2</span> + draw-vertical screen, divider, <span class="Constant">1/top</span>, height, <span class="Constant">9482/vertical-dotted</span> <span class="Comment"># recipe editor on the left</span> - recipes:address:address:editor-data<span class="Special"> <- </span>get-address result:address:programming-environment-data/deref, recipes:offset - recipes:address:address:editor-data/deref<span class="Special"> <- </span>new-editor initial-recipe-contents:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, divider:number/right + recipes:address:address:editor-data<span class="Special"> <- </span>get-address *result, recipes:offset + *recipes<span class="Special"> <- </span>new-editor initial-recipe-contents, screen, <span class="Constant">0/left</span>, divider/right <span class="Comment"># sandbox editor on the right</span> - new-left:number<span class="Special"> <- </span>add divider:number, <span class="Constant">1:literal</span> - new-right:number<span class="Special"> <- </span>add new-left:number, <span class="Constant">5:literal</span> - current-sandbox:address:address:editor-data<span class="Special"> <- </span>get-address result:address:programming-environment-data/deref, current-sandbox:offset - current-sandbox:address:address:editor-data/deref<span class="Special"> <- </span>new-editor initial-sandbox-contents:address:array:character, screen:address, new-left:number, width:number - screen:address<span class="Special"> <- </span>render-all screen:address, result:address:programming-environment-data - <span class="muControl">reply</span> result:address:programming-environment-data + new-left:number<span class="Special"> <- </span>add divider, <span class="Constant">1</span> + new-right:number<span class="Special"> <- </span>add new-left, <span class="Constant">5</span> + current-sandbox:address:address:editor-data<span class="Special"> <- </span>get-address *result, current-sandbox:offset + *current-sandbox<span class="Special"> <- </span>new-editor initial-sandbox-contents, screen, new-left, width/right + screen<span class="Special"> <- </span>render-all screen, result + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> editor-initially-prints-string-to-screen [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -129,60 +129,60 @@ container editor-data [ <span class="Comment"># no clipping of bounds</span> left:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> right:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - right:number<span class="Special"> <- </span>subtract right:number, <span class="Constant">1:literal</span> + right<span class="Special"> <- </span>subtract right, <span class="Constant">1</span> result:address:editor-data<span class="Special"> <- </span>new editor-data:type <span class="Comment"># initialize screen-related fields</span> - x:address:number<span class="Special"> <- </span>get-address result:address:editor-data/deref, left:offset - x:address:number/deref<span class="Special"> <- </span>copy left:number - x:address:number<span class="Special"> <- </span>get-address result:address:editor-data/deref, right:offset - x:address:number/deref<span class="Special"> <- </span>copy right:number + x:address:number<span class="Special"> <- </span>get-address *result, left:offset + *x<span class="Special"> <- </span>copy left + x<span class="Special"> <- </span>get-address *result, right:offset + *x<span class="Special"> <- </span>copy right <span class="Comment"># initialize cursor</span> - x:address:number<span class="Special"> <- </span>get-address result:address:editor-data/deref, cursor-row:offset - x:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">1:literal/top</span> - x:address:number<span class="Special"> <- </span>get-address result:address:editor-data/deref, cursor-column:offset - x:address:number/deref<span class="Special"> <- </span>copy left:number - init:address:address:duplex-list<span class="Special"> <- </span>get-address result:address:editor-data/deref, data:offset - init:address:address:duplex-list/deref<span class="Special"> <- </span>push-duplex <span class="Constant">167:literal/§</span>, <span class="Constant">0:literal/tail</span> - y:address:address:duplex-list<span class="Special"> <- </span>get-address result:address:editor-data/deref, before-cursor:offset - y:address:address:duplex-list/deref<span class="Special"> <- </span>copy init:address:address:duplex-list/deref + x<span class="Special"> <- </span>get-address *result, cursor-row:offset + *x<span class="Special"> <- </span>copy <span class="Constant">1/top</span> + x<span class="Special"> <- </span>get-address *result, cursor-column:offset + *x<span class="Special"> <- </span>copy left + init:address:address:duplex-list<span class="Special"> <- </span>get-address *result, data:offset + *init<span class="Special"> <- </span>push-duplex <span class="Constant">167/§</span>, <span class="Constant">0/tail</span> + y:address:address:duplex-list<span class="Special"> <- </span>get-address *result, before-cursor:offset + *y<span class="Special"> <- </span>copy *init <span class="Comment"># early exit if s is empty</span> - <span class="muControl">reply-unless</span> s:address:array:character, result:address:editor-data - len:number<span class="Special"> <- </span>length s:address:array:character/deref - <span class="muControl">reply-unless</span> len:number, result:address:editor-data - idx:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + <span class="muControl">reply-unless</span> s, result + len:number<span class="Special"> <- </span>length *s + <span class="muControl">reply-unless</span> len, result + idx:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># now we can start appending the rest, character by character</span> - curr:address:duplex-list<span class="Special"> <- </span>copy init:address:address:duplex-list/deref + curr:address:duplex-list<span class="Special"> <- </span>copy *init <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal idx:number, len:number - <span class="muControl">break-if</span> done?:boolean - c:character<span class="Special"> <- </span>index s:address:array:character/deref, idx:number - insert-duplex c:character, curr:address:duplex-list + done?:boolean<span class="Special"> <- </span>greater-or-equal idx, len + <span class="muControl">break-if</span> done? + c:character<span class="Special"> <- </span>index *s, idx + insert-duplex c, curr <span class="Comment"># next iter</span> - curr:address:duplex-list<span class="Special"> <- </span>next-duplex curr:address:duplex-list - idx:number<span class="Special"> <- </span>add idx:number, <span class="Constant">1:literal</span> + curr<span class="Special"> <- </span>next-duplex curr + idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># initialize cursor to top of screen</span> - y:address:address:duplex-list<span class="Special"> <- </span>get-address result:address:editor-data/deref, before-cursor:offset - y:address:address:duplex-list/deref<span class="Special"> <- </span>copy init:address:address:duplex-list/deref + y<span class="Special"> <- </span>get-address *result, before-cursor:offset + *y<span class="Special"> <- </span>copy *init <span class="Comment"># initial render to screen, just for some old tests</span> - _, screen:address<span class="Special"> <- </span>render screen:address, result:address:editor-data - <span class="muControl">reply</span> result:address:editor-data + _, screen<span class="Special"> <- </span>render screen, result + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> editor-initializes-without-data [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">3:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">3/height</span> run [ - 1:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">0:literal/data</span>, screen:address, <span class="Constant">2:literal/left</span>, <span class="Constant">5:literal/right</span> - 2:editor-data<span class="Special"> <- </span>copy 1:address:editor-data/deref + <span class="Constant">1</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">0/data</span>, screen:address, <span class="Constant">2/left</span>, <span class="Constant">5/right</span> + <span class="Constant">2</span>:editor-data<span class="Special"> <- </span>copy *<span class="Constant">1</span>:address:editor-data ] memory-should-contain [ <span class="Comment"># 2 (data) <- just the § sentinel</span> <span class="Comment"># 3 (before cursor) <- the § sentinel</span> - 4<span class="Special"> <- </span>2 <span class="Comment"># left</span> - 5<span class="Special"> <- </span>4 <span class="Comment"># right (inclusive)</span> - 6<span class="Special"> <- </span>1 <span class="Comment"># cursor row</span> - 7<span class="Special"> <- </span>2 <span class="Comment"># cursor column</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># left</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># right (inclusive)</span> + <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># cursor column</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -196,108 +196,108 @@ container editor-data [ <span class="Constant">local-scope</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply-unless</span> editor:address:editor-data, <span class="Constant">1:literal/top</span>, screen:address/same-as-ingredient:0 - left:number<span class="Special"> <- </span>get editor:address:editor-data/deref, left:offset - screen-height:number<span class="Special"> <- </span>screen-height screen:address - right:number<span class="Special"> <- </span>get editor:address:editor-data/deref, right:offset - hide-screen screen:address + <span class="muControl">reply-unless</span> editor, <span class="Constant">1/top</span>, screen/same-as-ingredient:<span class="Constant">0</span> + left:number<span class="Special"> <- </span>get *editor, left:offset + screen-height:number<span class="Special"> <- </span>screen-height screen + right:number<span class="Special"> <- </span>get *editor, right:offset + hide-screen screen <span class="Comment"># highlight mu code with color</span> - color:number<span class="Special"> <- </span>copy <span class="Constant">7:literal/white</span> - highlighting-state:number<span class="Special"> <- </span>copy <span class="Constant">0:literal/normal</span> + color:number<span class="Special"> <- </span>copy <span class="Constant">7/white</span> + highlighting-state:number<span class="Special"> <- </span>copy <span class="Constant">0/normal</span> <span class="Comment"># traversing editor</span> - curr:address:duplex-list<span class="Special"> <- </span>get editor:address:editor-data/deref, data:offset - prev:address:duplex-list<span class="Special"> <- </span>copy curr:address:duplex-list - curr:address:duplex-list<span class="Special"> <- </span>next-duplex curr:address:duplex-list + curr:address:duplex-list<span class="Special"> <- </span>get *editor, data:offset + prev:address:duplex-list<span class="Special"> <- </span>copy curr + curr<span class="Special"> <- </span>next-duplex curr <span class="Comment"># traversing screen</span> - row:number<span class="Special"> <- </span>copy <span class="Constant">1:literal/top</span> - column:number<span class="Special"> <- </span>copy left:number - cursor-row:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-row:offset - cursor-column:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-column:offset - before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address editor:address:editor-data/deref, before-cursor:offset - move-cursor screen:address, row:number, column:number + row:number<span class="Special"> <- </span>copy <span class="Constant">1/top</span> + column:number<span class="Special"> <- </span>copy left + cursor-row:address:number<span class="Special"> <- </span>get-address *editor, cursor-row:offset + cursor-column:address:number<span class="Special"> <- </span>get-address *editor, cursor-column:offset + before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, before-cursor:offset + move-cursor screen, row, column <span class="Delimiter">{</span> <span class="Constant"> +next-character</span> - <span class="muControl">break-unless</span> curr:address:duplex-list - off-screen?:boolean<span class="Special"> <- </span>greater-or-equal row:number, screen-height:number - <span class="muControl">break-if</span> off-screen?:boolean + <span class="muControl">break-unless</span> curr + off-screen?:boolean<span class="Special"> <- </span>greater-or-equal row, screen-height + <span class="muControl">break-if</span> off-screen? <span class="Comment"># update editor-data.before-cursor</span> <span class="Comment"># Doing so at the start of each iteration ensures it stays one step behind</span> <span class="Comment"># the current character.</span> <span class="Delimiter">{</span> - at-cursor-row?:boolean<span class="Special"> <- </span>equal row:number, cursor-row:address:number/deref - <span class="muControl">break-unless</span> at-cursor-row?:boolean - at-cursor?:boolean<span class="Special"> <- </span>equal column:number, cursor-column:address:number/deref - <span class="muControl">break-unless</span> at-cursor?:boolean - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>prev-duplex curr:address:duplex-list + at-cursor-row?:boolean<span class="Special"> <- </span>equal row, *cursor-row + <span class="muControl">break-unless</span> at-cursor-row? + at-cursor?:boolean<span class="Special"> <- </span>equal column, *cursor-column + <span class="muControl">break-unless</span> at-cursor? + *before-cursor<span class="Special"> <- </span>prev-duplex curr <span class="Delimiter">}</span> - c:character<span class="Special"> <- </span>get curr:address:duplex-list/deref, value:offset - color:number, highlighting-state:number<span class="Special"> <- </span>get-color color:number, highlighting-state:number, c:character + c:character<span class="Special"> <- </span>get *curr, value:offset + color, highlighting-state<span class="Special"> <- </span>get-color color, highlighting-state, c <span class="Delimiter">{</span> <span class="Comment"># newline? move to left rather than 0</span> - newline?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-unless</span> newline?:boolean + newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">break-unless</span> newline? <span class="Comment"># adjust cursor if necessary</span> <span class="Delimiter">{</span> - at-cursor-row?:boolean<span class="Special"> <- </span>equal row:number, cursor-row:address:number/deref - <span class="muControl">break-unless</span> at-cursor-row?:boolean - left-of-cursor?:boolean<span class="Special"> <- </span>lesser-than column:number, cursor-column:address:number/deref - <span class="muControl">break-unless</span> left-of-cursor?:boolean - cursor-column:address:number/deref<span class="Special"> <- </span>copy column:number - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>prev-duplex curr:address:duplex-list + at-cursor-row?:boolean<span class="Special"> <- </span>equal row, *cursor-row + <span class="muControl">break-unless</span> at-cursor-row? + left-of-cursor?:boolean<span class="Special"> <- </span>lesser-than column, *cursor-column + <span class="muControl">break-unless</span> left-of-cursor? + *cursor-column<span class="Special"> <- </span>copy column + *before-cursor<span class="Special"> <- </span>prev-duplex curr <span class="Delimiter">}</span> <span class="Comment"># clear rest of line in this window</span> - clear-line-delimited screen:address, column:number, right:number + clear-line-delimited screen, column, right <span class="Comment"># skip to next line</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - column:number<span class="Special"> <- </span>copy left:number - move-cursor screen:address, row:number, column:number - curr:address:duplex-list<span class="Special"> <- </span>next-duplex curr:address:duplex-list - prev:address:duplex-list<span class="Special"> <- </span>next-duplex prev:address:duplex-list + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + column<span class="Special"> <- </span>copy left + move-cursor screen, row, column + curr<span class="Special"> <- </span>next-duplex curr + prev<span class="Special"> <- </span>next-duplex prev <span class="muControl">loop</span> <span class="Constant">+next-character:label</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># at right? wrap. even if there's only one more letter left; we need</span> <span class="Comment"># room for clicking on the cursor after it.</span> - at-right?:boolean<span class="Special"> <- </span>equal column:number, right:number - <span class="muControl">break-unless</span> at-right?:boolean + at-right?:boolean<span class="Special"> <- </span>equal column, right + <span class="muControl">break-unless</span> at-right? <span class="Comment"># print wrap icon</span> - print-character screen:address, <span class="Constant">8617:literal/loop-back-to-left</span>, <span class="Constant">245:literal/grey</span> - column:number<span class="Special"> <- </span>copy left:number - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - move-cursor screen:address, row:number, column:number + print-character screen, <span class="Constant">8617/loop-back-to-left</span>, <span class="Constant">245/grey</span> + column<span class="Special"> <- </span>copy left + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + move-cursor screen, row, column <span class="Comment"># don't increment curr</span> <span class="muControl">loop</span> <span class="Constant">+next-character:label</span> <span class="Delimiter">}</span> - print-character screen:address, c:character, color:number - curr:address:duplex-list<span class="Special"> <- </span>next-duplex curr:address:duplex-list - prev:address:duplex-list<span class="Special"> <- </span>next-duplex prev:address:duplex-list - column:number<span class="Special"> <- </span>add column:number, <span class="Constant">1:literal</span> + print-character screen, c, color + curr<span class="Special"> <- </span>next-duplex curr + prev<span class="Special"> <- </span>next-duplex prev + column<span class="Special"> <- </span>add column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># is cursor to the right of the last line? move to end</span> <span class="Delimiter">{</span> - at-cursor-row?:boolean<span class="Special"> <- </span>equal row:number, cursor-row:address:number/deref - cursor-outside-line?:boolean<span class="Special"> <- </span>lesser-or-equal column:number, cursor-column:address:number/deref - before-cursor-on-same-line?:boolean<span class="Special"> <- </span>and at-cursor-row?:boolean, cursor-outside-line?:boolean - above-cursor-row?:boolean<span class="Special"> <- </span>lesser-than row:number, cursor-row:address:number/deref - before-cursor?:boolean<span class="Special"> <- </span>or before-cursor-on-same-line?:boolean, above-cursor-row?:boolean - <span class="muControl">break-unless</span> before-cursor?:boolean - cursor-row:address:number/deref<span class="Special"> <- </span>copy row:number - cursor-column:address:number/deref<span class="Special"> <- </span>copy column:number + at-cursor-row?:boolean<span class="Special"> <- </span>equal row, *cursor-row + cursor-outside-line?:boolean<span class="Special"> <- </span>lesser-or-equal column, *cursor-column + before-cursor-on-same-line?:boolean<span class="Special"> <- </span>and at-cursor-row?, cursor-outside-line? + above-cursor-row?:boolean<span class="Special"> <- </span>lesser-than row, *cursor-row + before-cursor?:boolean<span class="Special"> <- </span>or before-cursor-on-same-line?, above-cursor-row? + <span class="muControl">break-unless</span> before-cursor? + *cursor-row<span class="Special"> <- </span>copy row + *cursor-column<span class="Special"> <- </span>copy column <span class="Comment"># line not wrapped but cursor outside bounds? wrap cursor</span> <span class="Delimiter">{</span> - too-far-right?:boolean<span class="Special"> <- </span>greater-than cursor-column:address:number/deref, right:number - <span class="muControl">break-unless</span> too-far-right?:boolean - cursor-column:address:number/deref<span class="Special"> <- </span>copy left:number - cursor-row:address:number/deref<span class="Special"> <- </span>add cursor-row:address:number/deref, <span class="Constant">1:literal</span> - above-screen-bottom?:boolean<span class="Special"> <- </span>lesser-than cursor-row:address:number/deref, screen-height:number - assert above-screen-bottom?:boolean, <span class="Constant">[unimplemented: wrapping cursor past bottom of screen]</span> + too-far-right?:boolean<span class="Special"> <- </span>greater-than *cursor-column, right + <span class="muControl">break-unless</span> too-far-right? + *cursor-column<span class="Special"> <- </span>copy left + *cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span> + above-screen-bottom?:boolean<span class="Special"> <- </span>lesser-than *cursor-row, screen-height + assert above-screen-bottom?, <span class="Constant">[unimplemented: wrapping cursor past bottom of screen]</span> <span class="Delimiter">}</span> - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>copy prev:address:duplex-list + *before-cursor<span class="Special"> <- </span>copy prev <span class="Delimiter">}</span> <span class="Comment"># clear rest of current line</span> - clear-line-delimited screen:address, column:number, right:number - <span class="muControl">reply</span> row:number, screen:address/same-as-ingredient:0 + clear-line-delimited screen, column, right + <span class="muControl">reply</span> row, screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="Comment"># row:number, screen:address <- render-string screen:address, s:address:array:character, left:number, right:number, color:number, row:number</span> @@ -312,62 +312,62 @@ container editor-data [ right:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> color:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> row:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - <span class="muControl">reply-unless</span> s:address:array:character, row:number/same-as-ingredient:5, screen:address/same-as-ingredient:0 - column:number<span class="Special"> <- </span>copy left:number - move-cursor screen:address, row:number, column:number - screen-height:number<span class="Special"> <- </span>screen-height screen:address - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - len:number<span class="Special"> <- </span>length s:address:array:character/deref + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + <span class="muControl">reply-unless</span> s, row/same-as-ingredient:<span class="Constant">5</span>, screen/same-as-ingredient:<span class="Constant">0</span> + column:number<span class="Special"> <- </span>copy left + move-cursor screen, row, column + screen-height:number<span class="Special"> <- </span>screen-height screen + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + len:number<span class="Special"> <- </span>length *s <span class="Delimiter">{</span> <span class="Constant"> +next-character</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, len:number - <span class="muControl">break-if</span> done?:boolean - done?:boolean<span class="Special"> <- </span>greater-or-equal row:number, screen-height:number - <span class="muControl">break-if</span> done?:boolean - c:character<span class="Special"> <- </span>index s:address:array:character/deref, i:number + done?:boolean<span class="Special"> <- </span>greater-or-equal i, len + <span class="muControl">break-if</span> done? + done?<span class="Special"> <- </span>greater-or-equal row, screen-height + <span class="muControl">break-if</span> done? + c:character<span class="Special"> <- </span>index *s, i <span class="Delimiter">{</span> <span class="Comment"># at right? wrap.</span> - at-right?:boolean<span class="Special"> <- </span>equal column:number, right:number - <span class="muControl">break-unless</span> at-right?:boolean + at-right?:boolean<span class="Special"> <- </span>equal column, right + <span class="muControl">break-unless</span> at-right? <span class="Comment"># print wrap icon</span> - print-character screen:address, <span class="Constant">8617:literal/loop-back-to-left</span>, <span class="Constant">245:literal/grey</span> - column:number<span class="Special"> <- </span>copy left:number - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - move-cursor screen:address, row:number, column:number + print-character screen, <span class="Constant">8617/loop-back-to-left</span>, <span class="Constant">245/grey</span> + column<span class="Special"> <- </span>copy left + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + move-cursor screen, row, column <span class="muControl">loop</span> <span class="Constant">+next-character:label</span> <span class="Comment"># retry i</span> <span class="Delimiter">}</span> - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="Delimiter">{</span> <span class="Comment"># newline? move to left rather than 0</span> - newline?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-unless</span> newline?:boolean + newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">break-unless</span> newline? <span class="Comment"># clear rest of line in this window</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-than column:number, right:number - <span class="muControl">break-if</span> done?:boolean - print-character screen:address, <span class="Constant">32:literal/space</span> - column:number<span class="Special"> <- </span>add column:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>greater-than column, right + <span class="muControl">break-if</span> done? + print-character screen, <span class="Constant">32/space</span> + column<span class="Special"> <- </span>add column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - column:number<span class="Special"> <- </span>copy left:number - move-cursor screen:address, row:number, column:number + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + column<span class="Special"> <- </span>copy left + move-cursor screen, row, column <span class="muControl">loop</span> <span class="Constant">+next-character:label</span> <span class="Delimiter">}</span> - print-character screen:address, c:character, color:number - column:number<span class="Special"> <- </span>add column:number, <span class="Constant">1:literal</span> + print-character screen, c, color + column<span class="Special"> <- </span>add column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># clear rest of current line</span> - line-done?:boolean<span class="Special"> <- </span>greater-than column:number, right:number - <span class="muControl">break-if</span> line-done?:boolean - print-character screen:address, <span class="Constant">32:literal/space</span> - column:number<span class="Special"> <- </span>add column:number, <span class="Constant">1:literal</span> + line-done?:boolean<span class="Special"> <- </span>greater-than column, right + <span class="muControl">break-if</span> line-done? + print-character screen, <span class="Constant">32/space</span> + column<span class="Special"> <- </span>add column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> row:number/same-as-ingredient:5, screen:address/same-as-ingredient:0 + <span class="muControl">reply</span> row/same-as-ingredient:<span class="Constant">5</span>, screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="Comment"># row:number, screen:address <- render-screen screen:address, sandbox-screen:address, left:number, right:number, row:number</span> @@ -380,63 +380,63 @@ container editor-data [ left:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> right:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> row:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - <span class="muControl">reply-unless</span> s:address:screen, row:number/same-as-ingredient:4, screen:address/same-as-ingredient:0 + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + <span class="muControl">reply-unless</span> s, row/same-as-ingredient:<span class="Constant">4</span>, screen/same-as-ingredient:<span class="Constant">0</span> <span class="Comment"># print 'screen:'</span> header:address:array:character<span class="Special"> <- </span>new <span class="Constant">[screen:]</span> - row:number<span class="Special"> <- </span>subtract row:number, <span class="Constant">1:literal</span> <span class="Comment"># compensate for render-string below</span> - row:number<span class="Special"> <- </span>render-string screen:address, header:address:array:character, left:number, right:number, <span class="Constant">245:literal/grey</span>, row:number + row<span class="Special"> <- </span>subtract row, <span class="Constant">1</span> <span class="Comment"># compensate for render-string below</span> + row<span class="Special"> <- </span>render-string screen, header, left, right, <span class="Constant">245/grey</span>, row <span class="Comment"># newline</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - move-cursor screen:address, row:number, left:number + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + move-cursor screen, row, left <span class="Comment"># start printing s</span> - column:number<span class="Special"> <- </span>copy left:number - s-width:number<span class="Special"> <- </span>screen-width s:address:screen - s-height:number<span class="Special"> <- </span>screen-height s:address:screen - buf:address:array:screen-cell<span class="Special"> <- </span>get s:address:screen/deref, data:offset - stop-printing:number<span class="Special"> <- </span>add left:number, s-width:number, <span class="Constant">3:literal</span> - max-column:number<span class="Special"> <- </span>min stop-printing:number, right:number - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - len:number<span class="Special"> <- </span>length buf:address:array:screen-cell/deref - screen-height:number<span class="Special"> <- </span>screen-height screen:address + column:number<span class="Special"> <- </span>copy left + s-width:number<span class="Special"> <- </span>screen-width s + s-height:number<span class="Special"> <- </span>screen-height s + buf:address:array:screen-cell<span class="Special"> <- </span>get *s, data:offset + stop-printing:number<span class="Special"> <- </span>add left, s-width, <span class="Constant">3</span> + max-column:number<span class="Special"> <- </span>min stop-printing, right + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + len:number<span class="Special"> <- </span>length *buf + screen-height:number<span class="Special"> <- </span>screen-height screen <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, len:number - <span class="muControl">break-if</span> done?:boolean - done?:boolean<span class="Special"> <- </span>greater-or-equal row:number, screen-height:number - <span class="muControl">break-if</span> done?:boolean - column:number<span class="Special"> <- </span>copy left:number - move-cursor screen:address, row:number, column:number + done?:boolean<span class="Special"> <- </span>greater-or-equal i, len + <span class="muControl">break-if</span> done? + done?<span class="Special"> <- </span>greater-or-equal row, screen-height + <span class="muControl">break-if</span> done? + column<span class="Special"> <- </span>copy left + move-cursor screen, row, column <span class="Comment"># initial leader for each row: two spaces and a '.'</span> - print-character screen:address, <span class="Constant">32:literal/space</span>, <span class="Constant">245:literal/grey</span> - print-character screen:address, <span class="Constant">32:literal/space</span>, <span class="Constant">245:literal/grey</span> - print-character screen:address, <span class="Constant">46:literal/full-stop</span>, <span class="Constant">245:literal/grey</span> - column:number<span class="Special"> <- </span>add left:number, <span class="Constant">3:literal</span> + print-character screen, <span class="Constant">32/space</span>, <span class="Constant">245/grey</span> + print-character screen, <span class="Constant">32/space</span>, <span class="Constant">245/grey</span> + print-character screen, <span class="Constant">46/full-stop</span>, <span class="Constant">245/grey</span> + column<span class="Special"> <- </span>add left, <span class="Constant">3</span> <span class="Delimiter">{</span> <span class="Comment"># print row</span> - row-done?:boolean<span class="Special"> <- </span>greater-or-equal column:number, max-column:number - <span class="muControl">break-if</span> row-done?:boolean - curr:screen-cell<span class="Special"> <- </span>index buf:address:array:screen-cell/deref, i:number - c:character<span class="Special"> <- </span>get curr:screen-cell, contents:offset - print-character screen:address, c:character, <span class="Constant">245:literal/grey</span> - column:number<span class="Special"> <- </span>add column:number, <span class="Constant">1:literal</span> - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> + row-done?:boolean<span class="Special"> <- </span>greater-or-equal column, max-column + <span class="muControl">break-if</span> row-done? + curr:screen-cell<span class="Special"> <- </span>index *buf, i + c:character<span class="Special"> <- </span>get curr, contents:offset + print-character screen, c, <span class="Constant">245/grey</span> + column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># print final '.'</span> - print-character screen:address, <span class="Constant">46:literal/full-stop</span>, <span class="Constant">245:literal/grey</span> - column:number<span class="Special"> <- </span>add column:number, <span class="Constant">1:literal</span> + print-character screen, <span class="Constant">46/full-stop</span>, <span class="Constant">245/grey</span> + column<span class="Special"> <- </span>add column, <span class="Constant">1</span> <span class="Delimiter">{</span> <span class="Comment"># clear rest of current line</span> - line-done?:boolean<span class="Special"> <- </span>greater-than column:number, right:number - <span class="muControl">break-if</span> line-done?:boolean - print-character screen:address, <span class="Constant">32:literal/space</span> - column:number<span class="Special"> <- </span>add column:number, <span class="Constant">1:literal</span> + line-done?:boolean<span class="Special"> <- </span>greater-than column, right + <span class="muControl">break-if</span> line-done? + print-character screen, <span class="Constant">32/space</span> + column<span class="Special"> <- </span>add column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> row:number/same-as-ingredient:4, screen:address/same-as-ingredient:0 + <span class="muControl">reply</span> row/same-as-ingredient:<span class="Constant">4</span>, screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> clear-line-delimited [ @@ -444,22 +444,22 @@ container editor-data [ screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> left:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> right:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - column:number<span class="Special"> <- </span>copy left:number + column:number<span class="Special"> <- </span>copy left <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-than column:number, right:number - <span class="muControl">break-if</span> done?:boolean - print-character screen:address, <span class="Constant">32:literal/space</span> - column:number<span class="Special"> <- </span>add column:number, <span class="Constant">1:literal</span> + done?:boolean<span class="Special"> <- </span>greater-than column, right + <span class="muControl">break-if</span> done? + print-character screen, <span class="Constant">32/space</span> + column<span class="Special"> <- </span>add column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muScenario">scenario</span> editor-initially-prints-multiple-lines [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">def]</span> - new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + new-editor s:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -470,10 +470,10 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-initially-handles-offsets [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - new-editor s:address:array:character, screen:address, <span class="Constant">1:literal/left</span>, <span class="Constant">5:literal/right</span> + new-editor s:address:array:character, screen:address, <span class="Constant">1/left</span>, <span class="Constant">5/right</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -483,11 +483,11 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-initially-prints-multiple-lines-at-offset [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">def]</span> - new-editor s:address:array:character, screen:address, <span class="Constant">1:literal/left</span>, <span class="Constant">5:literal/right</span> + new-editor s:address:array:character, screen:address, <span class="Constant">1/left</span>, <span class="Constant">5/right</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -498,10 +498,10 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-initially-wraps-long-lines [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc def]</span> - new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + new-editor s:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -509,7 +509,7 @@ container editor-data [ <span class="Constant"> .def .</span> <span class="Constant"> . .</span> ] - screen-should-contain-in-color <span class="Constant">245:literal/grey</span> [ + screen-should-contain-in-color <span class="Constant">245/grey</span> [ <span class="Constant"> . .</span> <span class="Constant"> . ↩.</span> <span class="Constant"> . .</span> @@ -518,10 +518,10 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-initially-wraps-barely-long-lines [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> - new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + new-editor s:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> ] <span class="Comment"># still wrap, even though the line would fit. We need room to click on the</span> <span class="Comment"># end of the line</span> @@ -531,7 +531,7 @@ container editor-data [ <span class="Constant"> .e .</span> <span class="Constant"> . .</span> ] - screen-should-contain-in-color <span class="Constant">245:literal/grey</span> [ + screen-should-contain-in-color <span class="Constant">245/grey</span> [ <span class="Constant"> . .</span> <span class="Constant"> . ↩.</span> <span class="Constant"> . .</span> @@ -540,12 +540,12 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-initializes-empty-text [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ <span class="Constant"> . .</span> @@ -553,20 +553,20 @@ container editor-data [ <span class="Constant"> . .</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># cursor row</span> - 4<span class="Special"> <- </span>0 <span class="Comment"># cursor column</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> ] ] <span class="SalientComment">## highlighting mu code</span> <span class="muScenario">scenario</span> render-colors-comments [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant"># de</span> <span class="Constant">f]</span> - new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + new-editor s:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -575,14 +575,14 @@ container editor-data [ <span class="Constant"> .f .</span> <span class="Constant"> . .</span> ] - screen-should-contain-in-color <span class="Constant">12:literal/lightblue</span>, [ + screen-should-contain-in-color <span class="Constant">12/lightblue</span>, [ <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> .# de .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> ] - screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [ + screen-should-contain-in-color <span class="Constant">7/white</span>, [ <span class="Constant"> . .</span> <span class="Constant"> .abc .</span> <span class="Constant"> . .</span> @@ -597,56 +597,56 @@ container editor-data [ color:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> highlighting-state:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> c:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - color-is-white?:boolean<span class="Special"> <- </span>equal color:number, <span class="Constant">7:literal/white</span> -<span class="CommentedCode">#? $print [character: ], c:character, 10:literal/newline #? 1</span> + color-is-white?:boolean<span class="Special"> <- </span>equal color, <span class="Constant">7/white</span> +<span class="CommentedCode">#? $print [character: ], c, 10/newline #? 1</span> <span class="Comment"># if color is white and next character is '#', switch color to blue</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> color-is-white?:boolean - starting-comment?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">35:literal/#</span> - <span class="muControl">break-unless</span> starting-comment?:boolean -<span class="CommentedCode">#? $print [switch color back to blue], 10:literal/newline #? 1</span> - color:number<span class="Special"> <- </span>copy <span class="Constant">12:literal/lightblue</span> + <span class="muControl">break-unless</span> color-is-white? + starting-comment?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">35/#</span> + <span class="muControl">break-unless</span> starting-comment? +<span class="CommentedCode">#? $print [switch color back to blue], 10/newline #? 1</span> + color<span class="Special"> <- </span>copy <span class="Constant">12/lightblue</span> <span class="muControl">jump</span> <span class="Constant">+exit:label</span> <span class="Delimiter">}</span> <span class="Comment"># if color is blue and next character is newline, switch color to white</span> <span class="Delimiter">{</span> - color-is-blue?:boolean<span class="Special"> <- </span>equal color:number, <span class="Constant">12:literal/lightblue</span> - <span class="muControl">break-unless</span> color-is-blue?:boolean - ending-comment?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-unless</span> ending-comment?:boolean -<span class="CommentedCode">#? $print [switch color back to white], 10:literal/newline #? 1</span> - color:number<span class="Special"> <- </span>copy <span class="Constant">7:literal/white</span> + color-is-blue?:boolean<span class="Special"> <- </span>equal color, <span class="Constant">12/lightblue</span> + <span class="muControl">break-unless</span> color-is-blue? + ending-comment?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">break-unless</span> ending-comment? +<span class="CommentedCode">#? $print [switch color back to white], 10/newline #? 1</span> + color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> <span class="muControl">jump</span> <span class="Constant">+exit:label</span> <span class="Delimiter">}</span> <span class="Comment"># if color is white (no comments) and next character is '<', switch color to red</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> color-is-white?:boolean - starting-assignment?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">60:literal/<</span> - <span class="muControl">break-unless</span> starting-assignment?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">1:literal/red</span> + <span class="muControl">break-unless</span> color-is-white? + starting-assignment?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">60/<</span> + <span class="muControl">break-unless</span> starting-assignment? + color<span class="Special"> <- </span>copy <span class="Constant">1/red</span> <span class="muControl">jump</span> <span class="Constant">+exit:label</span> <span class="Delimiter">}</span> <span class="Comment"># if color is red and next character is space, switch color to white</span> <span class="Delimiter">{</span> - color-is-red?:boolean<span class="Special"> <- </span>equal color:number, <span class="Constant">1:literal/red</span> - <span class="muControl">break-unless</span> color-is-red?:boolean - ending-assignment?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">32:literal/space</span> - <span class="muControl">break-unless</span> ending-assignment?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">7:literal/white</span> + color-is-red?:boolean<span class="Special"> <- </span>equal color, <span class="Constant">1/red</span> + <span class="muControl">break-unless</span> color-is-red? + ending-assignment?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">32/space</span> + <span class="muControl">break-unless</span> ending-assignment? + color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> <span class="muControl">jump</span> <span class="Constant">+exit:label</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise no change</span> <span class="Constant"> +exit</span> - <span class="muControl">reply</span> color:number, highlighting-state:number + <span class="muControl">reply</span> color, highlighting-state ] <span class="muScenario">scenario</span> render-colors-assignment [ - assume-screen <span class="Constant">8:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">8/width</span>, <span class="Constant">5/height</span> run [ s:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">d <- e</span> <span class="Constant">f]</span> - new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">8:literal/right</span> + new-editor s:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">8/right</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -655,7 +655,7 @@ container editor-data [ <span class="Constant"> .f .</span> <span class="Constant"> . .</span> ] - screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [ + screen-should-contain-in-color <span class="Constant">1/red</span>, [ <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> . <- .</span> @@ -671,58 +671,78 @@ container editor-data [ screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> console:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> env:address:programming-environment-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - recipes:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, recipes:offset - current-sandbox:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, current-sandbox:offset - sandbox-in-focus?:address:boolean<span class="Special"> <- </span>get-address env:address:programming-environment-data/deref, sandbox-in-focus?:offset + recipes:address:editor-data<span class="Special"> <- </span>get *env, recipes:offset + current-sandbox:address:editor-data<span class="Special"> <- </span>get *env, current-sandbox:offset + sandbox-in-focus?:address:boolean<span class="Special"> <- </span>get-address *env, sandbox-in-focus?:offset <span class="Delimiter">{</span> <span class="Comment"># looping over each (keyboard or touch) event as it occurs</span> <span class="Constant"> +next-event</span> - e:event, console:address, found?:boolean, quit?:boolean<span class="Special"> <- </span>read-event console:address - <span class="muControl">loop-unless</span> found?:boolean - <span class="muControl">break-if</span> quit?:boolean <span class="Comment"># only in tests</span> + e:event, console, found?:boolean, quit?:boolean<span class="Special"> <- </span>read-event console + <span class="muControl">loop-unless</span> found? + <span class="muControl">break-if</span> quit? <span class="Comment"># only in tests</span> trace <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span> <span class="Comment"># check for global events that will trigger regardless of which editor has focus</span> <span class="Delimiter">{</span> k:address:number<span class="Special"> <- </span>maybe-convert e:event, keycode:variant - <span class="muControl">break-unless</span> k:address:number - <span class="Comment"># F10? load all code and run all sandboxes.</span> + <span class="muControl">break-unless</span> k + <span class="Comment"># F4? load all code and run all sandboxes.</span> + <span class="Delimiter">{</span> + do-run?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65532/F4</span> + <span class="muControl">break-unless</span> do-run? + run-sandboxes env + <span class="Comment"># F4 might update warnings and results on both sides</span> + screen<span class="Special"> <- </span>render-all screen, env + update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? + show-screen screen + <span class="muControl">loop</span> <span class="Constant">+next-event:label</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Delimiter">{</span> + c:address:character<span class="Special"> <- </span>maybe-convert e:event, text:variant + <span class="muControl">break-unless</span> c + <span class="Comment"># ctrl-n? - switch focus</span> <span class="Delimiter">{</span> - do-run?:boolean<span class="Special"> <- </span>equal k:address:number/deref, <span class="Constant">65526:literal/F10</span> - <span class="muControl">break-unless</span> do-run?:boolean - run-sandboxes env:address:programming-environment-data - <span class="Comment"># F10 might update warnings and results on both sides</span> - screen:address<span class="Special"> <- </span>render-all screen:address, env:address:programming-environment-data - update-cursor screen:address, recipes:address:editor-data, current-sandbox:address:editor-data, sandbox-in-focus?:address:boolean/deref - show-screen screen:address + ctrl-n?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">14/ctrl-n</span> + <span class="muControl">break-unless</span> ctrl-n? + *sandbox-in-focus?<span class="Special"> <- </span>not *sandbox-in-focus? + update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? + show-screen screen <span class="muControl">loop</span> <span class="Constant">+next-event:label</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Comment"># 'touch' event</span> <span class="Delimiter">{</span> t:address:touch-event<span class="Special"> <- </span>maybe-convert e:event, touch:variant - <span class="muControl">break-unless</span> t:address:touch-event + <span class="muControl">break-unless</span> t + <span class="Comment"># ignore all but 'left-click' events for now</span> + <span class="Comment"># todo: test this</span> + touch-type:number<span class="Special"> <- </span>get *t, type:offset + is-left-click?:boolean<span class="Special"> <- </span>equal touch-type, <span class="Constant">65513/mouse-left</span> + <span class="muControl">loop-unless</span> is-left-click?, <span class="Constant">+next-event:label</span> <span class="Comment"># on a sandbox delete icon? process delete</span> <span class="Delimiter">{</span> - was-delete?:boolean<span class="Special"> <- </span>delete-sandbox t:address:touch-event/deref, env:address:programming-environment-data - <span class="muControl">break-unless</span> was-delete?:boolean - screen:address<span class="Special"> <- </span>render-sandbox-side screen:address, env:address:programming-environment-data, <span class="Constant">1:literal/clear</span> - update-cursor screen:address, recipes:address:editor-data, current-sandbox:address:editor-data, sandbox-in-focus?:address:boolean/deref + was-delete?:boolean<span class="Special"> <- </span>delete-sandbox *t, env + <span class="muControl">break-unless</span> was-delete? +<span class="CommentedCode">#? trace [app], [delete clicked] #? 1</span> + screen<span class="Special"> <- </span>render-sandbox-side screen, env, <span class="Constant">1/clear</span> + update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? + show-screen screen <span class="muControl">loop</span> <span class="Constant">+next-event:label</span> <span class="Delimiter">}</span> <span class="Comment"># if not, send to both editors</span> - _<span class="Special"> <- </span>move-cursor-in-editor screen:address, recipes:address:editor-data, t:address:touch-event/deref - sandbox-in-focus?:address:boolean/deref<span class="Special"> <- </span>move-cursor-in-editor screen:address, current-sandbox:address:editor-data, t:address:touch-event/deref + _<span class="Special"> <- </span>move-cursor-in-editor screen, recipes, *t + *sandbox-in-focus?<span class="Special"> <- </span>move-cursor-in-editor screen, current-sandbox, *t <span class="muControl">jump</span> <span class="Constant">+continue:label</span> <span class="Delimiter">}</span> <span class="Comment"># if it's not global, send to appropriate editor</span> <span class="Delimiter">{</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> sandbox-in-focus?:address:boolean/deref - handle-event screen:address, console:address, recipes:address:editor-data, e:event + <span class="muControl">break-if</span> *sandbox-in-focus? + handle-event screen, console, recipes, e:event <span class="Delimiter">}</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> sandbox-in-focus?:address:boolean/deref - handle-event screen:address, console:address, current-sandbox:address:editor-data, e:event + <span class="muControl">break-unless</span> *sandbox-in-focus? + handle-event screen, console, current-sandbox, e:event <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Constant"> +continue</span> @@ -731,9 +751,9 @@ container editor-data [ <span class="Comment"># they won't usually come fast enough to trigger this.</span> <span class="Comment"># todo: test this</span> <span class="Delimiter">{</span> - more-events?:boolean<span class="Special"> <- </span>has-more-events? console:address - <span class="muControl">break-if</span> more-events?:boolean - render-minimal screen:address, env:address:programming-environment-data + more-events?:boolean<span class="Special"> <- </span>has-more-events? console + <span class="muControl">break-if</span> more-events? + render-minimal screen, env <span class="Delimiter">}</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> @@ -748,27 +768,27 @@ container editor-data [ <span class="Delimiter">{</span> <span class="Comment"># looping over each (keyboard or touch) event as it occurs</span> <span class="Constant"> +next-event</span> - e:event, console:address, found?:boolean, quit?:boolean<span class="Special"> <- </span>read-event console:address - <span class="muControl">loop-unless</span> found?:boolean - <span class="muControl">break-if</span> quit?:boolean <span class="Comment"># only in tests</span> + e:event, console:address, found?:boolean, quit?:boolean<span class="Special"> <- </span>read-event console + <span class="muControl">loop-unless</span> found? + <span class="muControl">break-if</span> quit? <span class="Comment"># only in tests</span> trace <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span> <span class="Comment"># 'touch' event - send to both editors</span> <span class="Delimiter">{</span> t:address:touch-event<span class="Special"> <- </span>maybe-convert e:event, touch:variant - <span class="muControl">break-unless</span> t:address:touch-event - move-cursor-in-editor screen:address, editor:address:editor-data, t:address:touch-event/deref + <span class="muControl">break-unless</span> t + move-cursor-in-editor screen, editor, *t <span class="muControl">jump</span> <span class="Constant">+continue:label</span> <span class="Delimiter">}</span> <span class="Comment"># other events - send to appropriate editor</span> - handle-event screen:address, console:address, editor:address:editor-data, e:event + handle-event screen, console, editor, e:event <span class="Constant"> +continue</span> - row:number, screen:address<span class="Special"> <- </span>render screen:address, editor:address:editor-data + row:number, screen<span class="Special"> <- </span>render screen, editor <span class="Comment"># clear next line, in case we just processed a backspace</span> - left:number<span class="Special"> <- </span>get editor:address:editor-data/deref, left:offset - right:number<span class="Special"> <- </span>get editor:address:editor-data/deref, right:offset - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - move-cursor screen:address, row:number, left:number - clear-line-delimited screen:address, left:number, right:number + left:number<span class="Special"> <- </span>get *editor, left:offset + right:number<span class="Special"> <- </span>get *editor, right:offset + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + move-cursor screen, row, left + clear-line-delimited screen, left, right <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -779,177 +799,185 @@ container editor-data [ console:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> e:event<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply-unless</span> editor:address:editor-data + <span class="muControl">reply-unless</span> editor <span class="Comment"># character</span> <span class="Delimiter">{</span> c:address:character<span class="Special"> <- </span>maybe-convert e:event, text:variant - <span class="muControl">break-unless</span> c:address:character - <span class="Comment"># check for special characters</span> - <span class="Comment"># unless it's a backspace</span> + <span class="muControl">break-unless</span> c + <span class="SalientComment">## check for special characters</span> + <span class="Comment"># backspace - delete character before cursor</span> + <span class="Delimiter">{</span> + backspace?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">8/backspace</span> + <span class="muControl">break-unless</span> backspace? + delete-before-cursor editor + <span class="muControl">reply</span> + <span class="Delimiter">}</span> + <span class="Comment"># ctrl-a - move cursor to start of line</span> <span class="Delimiter">{</span> - backspace?:boolean<span class="Special"> <- </span>equal c:address:character/deref, <span class="Constant">8:literal/backspace</span> - <span class="muControl">break-unless</span> backspace?:boolean - delete-before-cursor editor:address:editor-data + ctrl-a?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">1/ctrl-a</span> + <span class="muControl">break-unless</span> ctrl-a? + move-to-start-of-line editor <span class="muControl">reply</span> <span class="Delimiter">}</span> - <span class="Comment"># ctrl-a</span> + <span class="Comment"># ctrl-e - move cursor to end of line</span> <span class="Delimiter">{</span> - ctrl-a?:boolean<span class="Special"> <- </span>equal c:address:character/deref, <span class="Constant">1:literal/ctrl-a</span> - <span class="muControl">break-unless</span> ctrl-a?:boolean - move-to-start-of-line editor:address:editor-data + ctrl-e?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">5/ctrl-e</span> + <span class="muControl">break-unless</span> ctrl-e? + move-to-end-of-line editor <span class="muControl">reply</span> <span class="Delimiter">}</span> - <span class="Comment"># ctrl-e</span> + <span class="Comment"># ctrl-u - delete until start of line (excluding cursor)</span> <span class="Delimiter">{</span> - ctrl-e?:boolean<span class="Special"> <- </span>equal c:address:character/deref, <span class="Constant">5:literal/ctrl-e</span> - <span class="muControl">break-unless</span> ctrl-e?:boolean - move-to-end-of-line editor:address:editor-data + ctrl-u?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">21/ctrl-u</span> + <span class="muControl">break-unless</span> ctrl-u? + delete-to-start-of-line editor <span class="muControl">reply</span> <span class="Delimiter">}</span> - <span class="Comment"># ctrl-u</span> + <span class="Comment"># ctrl-k - delete until end of line (including cursor)</span> <span class="Delimiter">{</span> - ctrl-u?:boolean<span class="Special"> <- </span>equal c:address:character/deref, <span class="Constant">21:literal/ctrl-u</span> - <span class="muControl">break-unless</span> ctrl-u?:boolean - delete-to-start-of-line editor:address:editor-data + ctrl-k?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">11/ctrl-k</span> + <span class="muControl">break-unless</span> ctrl-k? + delete-to-end-of-line editor <span class="muControl">reply</span> <span class="Delimiter">}</span> - <span class="Comment"># ctrl-k</span> + <span class="Comment"># tab - insert two spaces</span> <span class="Delimiter">{</span> - ctrl-k?:boolean<span class="Special"> <- </span>equal c:address:character/deref, <span class="Constant">11:literal/ctrl-k</span> - <span class="muControl">break-unless</span> ctrl-k?:boolean - delete-to-end-of-line editor:address:editor-data + tab?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">9/tab</span> + <span class="muControl">break-unless</span> tab?:boolean + insert-at-cursor editor, <span class="Constant">32/space</span>, screen + insert-at-cursor editor, <span class="Constant">32/space</span>, screen <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise type it in</span> - insert-at-cursor editor:address:editor-data, c:address:character/deref, screen:address + insert-at-cursor editor, *c, screen <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise it's a special key</span> k:address:number<span class="Special"> <- </span>maybe-convert e:event, keycode:variant - assert k:address:number, <span class="Constant">[event was of unknown type; neither keyboard nor mouse]</span> - d:address:duplex-list<span class="Special"> <- </span>get editor:address:editor-data/deref, data:offset - before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address editor:address:editor-data/deref, before-cursor:offset - cursor-row:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-row:offset - cursor-column:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-column:offset - screen-height:number<span class="Special"> <- </span>screen-height screen:address - left:number<span class="Special"> <- </span>get editor:address:editor-data/deref, left:offset - right:number<span class="Special"> <- </span>get editor:address:editor-data/deref, right:offset + assert k, <span class="Constant">[event was of unknown type; neither keyboard nor mouse]</span> + d:address:duplex-list<span class="Special"> <- </span>get *editor, data:offset + before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, before-cursor:offset + cursor-row:address:number<span class="Special"> <- </span>get-address *editor, cursor-row:offset + cursor-column:address:number<span class="Special"> <- </span>get-address *editor, cursor-column:offset + screen-height:number<span class="Special"> <- </span>screen-height screen + left:number<span class="Special"> <- </span>get *editor, left:offset + right:number<span class="Special"> <- </span>get *editor, right:offset <span class="Comment"># arrows; update cursor-row and cursor-column, leave before-cursor to 'render'.</span> <span class="Comment"># right arrow</span> <span class="Delimiter">{</span> - move-to-next-character?:boolean<span class="Special"> <- </span>equal k:address:number/deref, <span class="Constant">65514:literal/right-arrow</span> - <span class="muControl">break-unless</span> move-to-next-character?:boolean + move-to-next-character?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65514/right-arrow</span> + <span class="muControl">break-unless</span> move-to-next-character? <span class="Comment"># if not at end of text</span> - old-cursor:address:duplex-list<span class="Special"> <- </span>next-duplex before-cursor:address:address:duplex-list/deref - <span class="muControl">break-unless</span> old-cursor:address:duplex-list + old-cursor:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor + <span class="muControl">break-unless</span> old-cursor <span class="Comment"># scan to next character</span> - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>copy old-cursor:address:duplex-list + *before-cursor<span class="Special"> <- </span>copy old-cursor <span class="Comment"># if crossed a newline, move cursor to start of next row</span> <span class="Delimiter">{</span> - old-cursor-character:character<span class="Special"> <- </span>get before-cursor:address:address:duplex-list/deref/deref, value:offset - was-at-newline?:boolean<span class="Special"> <- </span>equal old-cursor-character:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-unless</span> was-at-newline?:boolean - cursor-row:address:number/deref<span class="Special"> <- </span>add cursor-row:address:number/deref, <span class="Constant">1:literal</span> - cursor-column:address:number/deref<span class="Special"> <- </span>copy left:number + old-cursor-character:character<span class="Special"> <- </span>get **before-cursor, value:offset + was-at-newline?:boolean<span class="Special"> <- </span>equal old-cursor-character, <span class="Constant">10/newline</span> + <span class="muControl">break-unless</span> was-at-newline? + *cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span> + *cursor-column<span class="Special"> <- </span>copy left <span class="Comment"># todo: what happens when cursor is too far down?</span> - screen-height:number<span class="Special"> <- </span>screen-height screen:address - above-screen-bottom?:boolean<span class="Special"> <- </span>lesser-than cursor-row:address:number/deref, screen-height:number - assert above-screen-bottom?:boolean, <span class="Constant">[unimplemented: moving past bottom of screen]</span> + screen-height<span class="Special"> <- </span>screen-height screen + above-screen-bottom?:boolean<span class="Special"> <- </span>lesser-than *cursor-row, screen-height + assert above-screen-bottom?, <span class="Constant">[unimplemented: moving past bottom of screen]</span> <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># if the line wraps, move cursor to start of next row</span> <span class="Delimiter">{</span> <span class="Comment"># if we're at the column just before the wrap indicator</span> - wrap-column:number<span class="Special"> <- </span>subtract right:number, <span class="Constant">1:literal</span> - at-wrap?:boolean<span class="Special"> <- </span>equal cursor-column:address:number/deref, wrap-column:number - <span class="muControl">break-unless</span> at-wrap?:boolean + wrap-column:number<span class="Special"> <- </span>subtract right, <span class="Constant">1</span> + at-wrap?:boolean<span class="Special"> <- </span>equal *cursor-column, wrap-column + <span class="muControl">break-unless</span> at-wrap? <span class="Comment"># and if next character isn't newline</span> - new-cursor:address:duplex-list<span class="Special"> <- </span>next-duplex old-cursor:address:duplex-list - <span class="muControl">break-unless</span> new-cursor:address:duplex-list - next-character:character<span class="Special"> <- </span>get new-cursor:address:duplex-list/deref, value:offset - newline?:boolean<span class="Special"> <- </span>equal next-character:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-if</span> newline?:boolean - cursor-row:address:number/deref<span class="Special"> <- </span>add cursor-row:address:number/deref, <span class="Constant">1:literal</span> - cursor-column:address:number/deref<span class="Special"> <- </span>copy left:number + new-cursor:address:duplex-list<span class="Special"> <- </span>next-duplex old-cursor + <span class="muControl">break-unless</span> new-cursor + next-character:character<span class="Special"> <- </span>get *new-cursor, value:offset + newline?:boolean<span class="Special"> <- </span>equal next-character, <span class="Constant">10/newline</span> + <span class="muControl">break-if</span> newline? + *cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span> + *cursor-column<span class="Special"> <- </span>copy left <span class="Comment"># todo: what happens when cursor is too far down?</span> - above-screen-bottom?:boolean<span class="Special"> <- </span>lesser-than cursor-row:address:number/deref, screen-height:number - assert above-screen-bottom?:boolean, <span class="Constant">[unimplemented: moving past bottom of screen]</span> + above-screen-bottom?:boolean<span class="Special"> <- </span>lesser-than *cursor-row, screen-height + assert above-screen-bottom?, <span class="Constant">[unimplemented: moving past bottom of screen]</span> <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise move cursor one character right</span> - cursor-column:address:number/deref<span class="Special"> <- </span>add cursor-column:address:number/deref, <span class="Constant">1:literal</span> + *cursor-column<span class="Special"> <- </span>add *cursor-column, <span class="Constant">1</span> <span class="Delimiter">}</span> <span class="Comment"># left arrow</span> <span class="Delimiter">{</span> - move-to-previous-character?:boolean<span class="Special"> <- </span>equal k:address:number/deref, <span class="Constant">65515:literal/left-arrow</span> - <span class="muControl">break-unless</span> move-to-previous-character?:boolean + move-to-previous-character?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65515/left-arrow</span> + <span class="muControl">break-unless</span> move-to-previous-character? <span class="CommentedCode">#? trace [app], [left arrow] #? 1</span> <span class="Comment"># if not at start of text (before-cursor at § sentinel)</span> - prev:address:duplex-list<span class="Special"> <- </span>prev-duplex before-cursor:address:address:duplex-list/deref - <span class="muControl">break-unless</span> prev:address:duplex-list + prev:address:duplex-list<span class="Special"> <- </span>prev-duplex *before-cursor + <span class="muControl">break-unless</span> prev <span class="Comment"># if cursor not at left margin, move one character left</span> <span class="Delimiter">{</span> - at-left-margin?:boolean<span class="Special"> <- </span>equal cursor-column:address:number/deref, <span class="Constant">0:literal</span> - <span class="muControl">break-if</span> at-left-margin?:boolean + at-left-margin?:boolean<span class="Special"> <- </span>equal *cursor-column, <span class="Constant">0</span> + <span class="muControl">break-if</span> at-left-margin? <span class="CommentedCode">#? trace [app], [decrementing] #? 1</span> - cursor-column:address:number/deref<span class="Special"> <- </span>subtract cursor-column:address:number/deref, <span class="Constant">1:literal</span> + *cursor-column<span class="Special"> <- </span>subtract *cursor-column, <span class="Constant">1</span> <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># if at left margin, there's guaranteed to be a previous line, since we're</span> <span class="Comment"># not at start of text</span> <span class="Delimiter">{</span> <span class="Comment"># if before-cursor is at newline, figure out how long the previous line is</span> - prevc:character<span class="Special"> <- </span>get before-cursor:address:address:duplex-list/deref/deref, value:offset - previous-character-is-newline?:boolean<span class="Special"> <- </span>equal prevc:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-unless</span> previous-character-is-newline?:boolean + prevc:character<span class="Special"> <- </span>get **before-cursor, value:offset + previous-character-is-newline?:boolean<span class="Special"> <- </span>equal prevc, <span class="Constant">10/newline</span> + <span class="muControl">break-unless</span> previous-character-is-newline? <span class="CommentedCode">#? trace [app], [previous line] #? 1</span> <span class="Comment"># compute length of previous line</span> - end-of-line:number<span class="Special"> <- </span>previous-line-length before-cursor:address:address:duplex-list/deref, d:address:duplex-list - cursor-row:address:number/deref<span class="Special"> <- </span>subtract cursor-row:address:number/deref, <span class="Constant">1:literal</span> - cursor-column:address:number/deref<span class="Special"> <- </span>copy end-of-line:number + end-of-line:number<span class="Special"> <- </span>previous-line-length *before-cursor, d + *cursor-row<span class="Special"> <- </span>subtract *cursor-row, <span class="Constant">1</span> + *cursor-column<span class="Special"> <- </span>copy end-of-line <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># if before-cursor is not at newline, we're just at a wrapped line</span> - assert cursor-row:address:number/deref, <span class="Constant">[unimplemented: moving cursor above top of screen]</span> - cursor-row:address:number/deref<span class="Special"> <- </span>subtract cursor-row:address:number/deref, <span class="Constant">1:literal</span> - cursor-column:address:number/deref<span class="Special"> <- </span>subtract right:number, <span class="Constant">1:literal</span> <span class="Comment"># leave room for wrap icon</span> + assert *cursor-row, <span class="Constant">[unimplemented: moving cursor above top of screen]</span> + *cursor-row<span class="Special"> <- </span>subtract *cursor-row, <span class="Constant">1</span> + *cursor-column<span class="Special"> <- </span>subtract right, <span class="Constant">1</span> <span class="Comment"># leave room for wrap icon</span> <span class="Delimiter">}</span> <span class="Comment"># down arrow</span> <span class="Delimiter">{</span> - move-to-next-line?:boolean<span class="Special"> <- </span>equal k:address:number/deref, <span class="Constant">65516:literal/down-arrow</span> - <span class="muControl">break-unless</span> move-to-next-line?:boolean + move-to-next-line?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65516/down-arrow</span> + <span class="muControl">break-unless</span> move-to-next-line? <span class="Comment"># todo: support scrolling</span> - already-at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal cursor-row:address:number/deref, screen-height:number - <span class="muControl">break-if</span> already-at-bottom?:boolean + already-at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal *cursor-row, screen-height + <span class="muControl">break-if</span> already-at-bottom? <span class="CommentedCode">#? $print [moving down</span> <span class="CommentedCode">#? ] #? 1</span> - cursor-row:address:number/deref<span class="Special"> <- </span>add cursor-row:address:number/deref, <span class="Constant">1:literal</span> + *cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span> <span class="Comment"># that's it; render will adjust cursor-column as necessary</span> <span class="Delimiter">}</span> <span class="Comment"># up arrow</span> <span class="Delimiter">{</span> - move-to-previous-line?:boolean<span class="Special"> <- </span>equal k:address:number/deref, <span class="Constant">65517:literal/up-arrow</span> - <span class="muControl">break-unless</span> move-to-previous-line?:boolean + move-to-previous-line?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65517/up-arrow</span> + <span class="muControl">break-unless</span> move-to-previous-line? <span class="Comment"># todo: support scrolling</span> - already-at-top?:boolean<span class="Special"> <- </span>lesser-or-equal cursor-row:address:number/deref, <span class="Constant">1:literal/top</span> - <span class="muControl">break-if</span> already-at-top?:boolean + already-at-top?:boolean<span class="Special"> <- </span>lesser-or-equal *cursor-row, <span class="Constant">1/top</span> + <span class="muControl">break-if</span> already-at-top? <span class="CommentedCode">#? $print [moving up</span> <span class="CommentedCode">#? ] #? 1</span> - cursor-row:address:number/deref<span class="Special"> <- </span>subtract cursor-row:address:number/deref, <span class="Constant">1:literal</span> + *cursor-row<span class="Special"> <- </span>subtract *cursor-row, <span class="Constant">1</span> <span class="Comment"># that's it; render will adjust cursor-column as necessary</span> <span class="Delimiter">}</span> <span class="Comment"># home</span> <span class="Delimiter">{</span> - home?:boolean<span class="Special"> <- </span>equal k:address:number/deref, <span class="Constant">65521:literal/home</span> - <span class="muControl">break-unless</span> home?:boolean - move-to-start-of-line editor:address:editor-data + home?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65521/home</span> + <span class="muControl">break-unless</span> home? + move-to-start-of-line editor <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># end</span> <span class="Delimiter">{</span> - end?:boolean<span class="Special"> <- </span>equal k:address:number/deref, <span class="Constant">65520:literal/end</span> - <span class="muControl">break-unless</span> end?:boolean - move-to-end-of-line editor:address:editor-data + end?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65520/end</span> + <span class="muControl">break-unless</span> end? + move-to-end-of-line editor <span class="muControl">reply</span> <span class="Delimiter">}</span> ] @@ -961,21 +989,21 @@ container editor-data [ screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> t:touch-event<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply-unless</span> editor:address:editor-data, <span class="Constant">0:literal/false</span> - click-column:number<span class="Special"> <- </span>get t:touch-event, column:offset - left:number<span class="Special"> <- </span>get editor:address:editor-data/deref, left:offset - too-far-left?:boolean<span class="Special"> <- </span>lesser-than click-column:number, left:number - <span class="muControl">reply-if</span> too-far-left?:boolean, <span class="Constant">0:literal/false</span> - right:number<span class="Special"> <- </span>get editor:address:editor-data/deref, right:offset - too-far-right?:boolean<span class="Special"> <- </span>greater-than click-column:number, right:number - <span class="muControl">reply-if</span> too-far-right?:boolean, <span class="Constant">0:literal/false</span> + <span class="muControl">reply-unless</span> editor, <span class="Constant">0/false</span> + click-column:number<span class="Special"> <- </span>get t, column:offset + left:number<span class="Special"> <- </span>get *editor, left:offset + too-far-left?:boolean<span class="Special"> <- </span>lesser-than click-column, left + <span class="muControl">reply-if</span> too-far-left?, <span class="Constant">0/false</span> + right:number<span class="Special"> <- </span>get *editor, right:offset + too-far-right?:boolean<span class="Special"> <- </span>greater-than click-column, right + <span class="muControl">reply-if</span> too-far-right?, <span class="Constant">0/false</span> <span class="Comment"># update cursor</span> - cursor-row:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-row:offset - cursor-row:address:number/deref<span class="Special"> <- </span>get t:touch-event, row:offset - cursor-column:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-column:offset - cursor-column:address:number/deref<span class="Special"> <- </span>get t:touch-event, column:offset + cursor-row:address:number<span class="Special"> <- </span>get-address *editor, cursor-row:offset + *cursor-row<span class="Special"> <- </span>get t, row:offset + cursor-column:address:number<span class="Special"> <- </span>get-address *editor, cursor-column:offset + *cursor-column<span class="Special"> <- </span>get t, column:offset <span class="Comment"># gain focus</span> - <span class="muControl">reply</span> <span class="Constant">1:literal/true</span> + <span class="muControl">reply</span> <span class="Constant">1/true</span> ] <span class="muRecipe">recipe</span> insert-at-cursor [ @@ -983,63 +1011,76 @@ container editor-data [ editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> c:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> -<span class="CommentedCode">#? $print [insert ], c:character, 10:literal/newline</span> - before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address editor:address:editor-data/deref, before-cursor:offset - d:address:duplex-list<span class="Special"> <- </span>get editor:address:editor-data/deref, data:offset - insert-duplex c:character, before-cursor:address:address:duplex-list/deref - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>next-duplex before-cursor:address:address:duplex-list/deref - cursor-row:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-row:offset - cursor-column:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-column:offset - left:number<span class="Special"> <- </span>get editor:address:editor-data/deref, left:offset - right:number<span class="Special"> <- </span>get editor:address:editor-data/deref, right:offset +<span class="CommentedCode">#? $print [insert ], c, 10/newline #? 1</span> + before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, before-cursor:offset + insert-duplex c, *before-cursor + *before-cursor<span class="Special"> <- </span>next-duplex *before-cursor + cursor-row:address:number<span class="Special"> <- </span>get-address *editor, cursor-row:offset + cursor-column:address:number<span class="Special"> <- </span>get-address *editor, cursor-column:offset + left:number<span class="Special"> <- </span>get *editor, left:offset + right:number<span class="Special"> <- </span>get *editor, right:offset <span class="Comment"># update cursor: if newline, move cursor to start of next line</span> <span class="Comment"># todo: bottom of screen</span> <span class="Delimiter">{</span> - newline?:boolean<span class="Special"> <- </span>equal c:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-unless</span> newline?:boolean - cursor-row:address:number/deref<span class="Special"> <- </span>add cursor-row:address:number/deref, <span class="Constant">1:literal</span> - cursor-column:address:number/deref<span class="Special"> <- </span>copy left:number + newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">break-unless</span> newline? + *cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span> + *cursor-column<span class="Special"> <- </span>copy left + <span class="Comment"># indent if necessary</span> +<span class="CommentedCode">#? $print [computing indent], 10/newline #? 1</span> + d:address:duplex-list<span class="Special"> <- </span>get *editor, data:offset + end-of-previous-line:address:duplex-list<span class="Special"> <- </span>prev-duplex *before-cursor + indent:number<span class="Special"> <- </span>line-indent end-of-previous-line, d +<span class="CommentedCode">#? $print indent, 10/newline #? 1</span> + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Delimiter">{</span> + indent-done?:boolean<span class="Special"> <- </span>greater-or-equal i, indent + <span class="muControl">break-if</span> indent-done? + insert-at-cursor editor, <span class="Constant">32/space</span>, screen + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + <span class="muControl">loop</span> + <span class="Delimiter">}</span> <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># if the line wraps at the cursor, move cursor to start of next row</span> <span class="Delimiter">{</span> <span class="Comment"># if we're at the column just before the wrap indicator</span> - wrap-column:number<span class="Special"> <- </span>subtract right:number, <span class="Constant">1:literal</span> -<span class="CommentedCode">#? $print [wrap? ], cursor-column:address:number/deref, [ vs ], wrap-column:number, 10:literal/newline</span> - at-wrap?:boolean<span class="Special"> <- </span>greater-or-equal cursor-column:address:number/deref, wrap-column:number - <span class="muControl">break-unless</span> at-wrap?:boolean + wrap-column:number<span class="Special"> <- </span>subtract right, <span class="Constant">1</span> +<span class="CommentedCode">#? $print [wrap? ], *cursor-column, [ vs ], wrap-column, 10/newline</span> + at-wrap?:boolean<span class="Special"> <- </span>greater-or-equal *cursor-column, wrap-column + <span class="muControl">break-unless</span> at-wrap? <span class="CommentedCode">#? $print [wrap!</span> <span class="CommentedCode">#? ] #? 1</span> - cursor-column:address:number/deref<span class="Special"> <- </span>subtract cursor-column:address:number/deref, wrap-column:number - cursor-row:address:number/deref<span class="Special"> <- </span>add cursor-row:address:number/deref, <span class="Constant">1:literal</span> + *cursor-column<span class="Special"> <- </span>subtract *cursor-column, wrap-column + *cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span> <span class="Comment"># todo: what happens when cursor is too far down?</span> - screen-height:number<span class="Special"> <- </span>screen-height screen:address - above-screen-bottom?:boolean<span class="Special"> <- </span>lesser-than cursor-row:address:number/deref, screen-height:number - assert above-screen-bottom?:boolean, <span class="Constant">[unimplemented: typing past bottom of screen]</span> + screen-height:number<span class="Special"> <- </span>screen-height screen + above-screen-bottom?:boolean<span class="Special"> <- </span>lesser-than *cursor-row, screen-height + assert above-screen-bottom?, <span class="Constant">[unimplemented: typing past bottom of screen]</span> <span class="CommentedCode">#? $print [return</span> <span class="CommentedCode">#? ] #? 1</span> <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise move cursor right</span> - cursor-column:address:number/deref<span class="Special"> <- </span>add cursor-column:address:number/deref, <span class="Constant">1:literal</span> + *cursor-column<span class="Special"> <- </span>add *cursor-column, <span class="Constant">1</span> ] <span class="muRecipe">recipe</span> delete-before-cursor [ <span class="Constant">local-scope</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address editor:address:editor-data/deref, before-cursor:offset - d:address:duplex-list<span class="Special"> <- </span>get editor:address:editor-data/deref, data:offset + before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor:address:editor-data, before-cursor:offset + d:address:duplex-list<span class="Special"> <- </span>get *editor:address:editor-data, data:offset <span class="Comment"># unless already at start</span> - at-start?:boolean<span class="Special"> <- </span>equal before-cursor:address:address:duplex-list/deref, d:address:duplex-list + at-start?:boolean<span class="Special"> <- </span>equal *before-cursor:address:address:duplex-list, d:address:duplex-list <span class="muControl">reply-if</span> at-start?:boolean <span class="Comment"># delete character</span> - prev:address:duplex-list<span class="Special"> <- </span>prev-duplex before-cursor:address:address:duplex-list/deref - remove-duplex before-cursor:address:address:duplex-list/deref + prev:address:duplex-list<span class="Special"> <- </span>prev-duplex *before-cursor:address:address:duplex-list + remove-duplex *before-cursor:address:address:duplex-list <span class="Comment"># update cursor</span> - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>copy prev:address:duplex-list - cursor-column:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-column:offset - cursor-column:address:number/deref<span class="Special"> <- </span>subtract cursor-column:address:number/deref, <span class="Constant">1:literal</span> -<span class="CommentedCode">#? $print [delete-before-cursor: ], cursor-column:address:number/deref, 10:literal/newline</span> + *before-cursor:address:address:duplex-list<span class="Special"> <- </span>copy prev:address:duplex-list + cursor-column:address:number<span class="Special"> <- </span>get-address *editor:address:editor-data, cursor-column:offset + *cursor-column:address:number<span class="Special"> <- </span>subtract *cursor-column:address:number, <span class="Constant">1</span> +<span class="CommentedCode">#? $print [delete-before-cursor: ], *cursor-column:address:number, 10/newline</span> ] <span class="Comment"># takes a pointer 'curr' into the doubly-linked list and its sentinel, counts</span> @@ -1048,43 +1089,77 @@ container editor-data [ <span class="Constant">local-scope</span> curr:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> start:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - result:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - <span class="muControl">reply-unless</span> curr:address:duplex-list, result:number - at-start?:boolean<span class="Special"> <- </span>equal curr:address:duplex-list, start:address:duplex-list - <span class="muControl">reply-if</span> at-start?:boolean, result:number + result:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="muControl">reply-unless</span> curr, result + at-start?:boolean<span class="Special"> <- </span>equal curr, start + <span class="muControl">reply-if</span> at-start?, result <span class="Delimiter">{</span> - curr:address:duplex-list<span class="Special"> <- </span>prev-duplex curr:address:duplex-list - <span class="muControl">break-unless</span> curr:address:duplex-list - at-start?:boolean<span class="Special"> <- </span>equal curr:address:duplex-list, start:address:duplex-list - <span class="muControl">break-if</span> at-start?:boolean - c:character<span class="Special"> <- </span>get curr:address:duplex-list/deref, value:offset - at-newline?:boolean<span class="Special"> <- </span>equal c:character <span class="Constant">10:literal/newline</span> - <span class="muControl">break-if</span> at-newline?:boolean - result:number<span class="Special"> <- </span>add result:number, <span class="Constant">1:literal</span> + curr<span class="Special"> <- </span>prev-duplex curr + <span class="muControl">break-unless</span> curr + at-start?:boolean<span class="Special"> <- </span>equal curr, start + <span class="muControl">break-if</span> at-start? + c:character<span class="Special"> <- </span>get *curr, value:offset + at-newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">break-if</span> at-newline? + result<span class="Special"> <- </span>add result, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> result:number + <span class="muControl">reply</span> result +] + +<span class="Comment"># takes a pointer 'curr' into the doubly-linked list and its sentinel, counts</span> +<span class="Comment"># the number of spaces at the start of the line containing 'curr'.</span> +<span class="muRecipe">recipe</span> line-indent [ + <span class="Constant">local-scope</span> + curr:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + start:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + result:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="muControl">reply-unless</span> curr, result + at-start?:boolean<span class="Special"> <- </span>equal curr, start + <span class="muControl">reply-if</span> at-start?, result + <span class="Delimiter">{</span> + curr<span class="Special"> <- </span>prev-duplex curr + <span class="muControl">break-unless</span> curr + at-start?:boolean<span class="Special"> <- </span>equal curr, start + <span class="muControl">break-if</span> at-start? + c:character<span class="Special"> <- </span>get *curr, value:offset + at-newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + <span class="muControl">break-if</span> at-newline? + <span class="Comment"># if c is a space, increment result</span> + is-space?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">32/space</span> + <span class="Delimiter">{</span> + <span class="muControl">break-unless</span> is-space? + result<span class="Special"> <- </span>add result, <span class="Constant">1</span> + <span class="Delimiter">}</span> + <span class="Comment"># if c is not a space, reset result</span> + <span class="Delimiter">{</span> + <span class="muControl">break-if</span> is-space? + result<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Delimiter">}</span> + <span class="muControl">loop</span> + <span class="Delimiter">}</span> + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> move-to-start-of-line [ <span class="Constant">local-scope</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># update cursor column</span> - left:number<span class="Special"> <- </span>get editor:address:editor-data/deref, left:offset - cursor-column:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-column:offset - cursor-column:address:number/deref<span class="Special"> <- </span>copy left:number + left:number<span class="Special"> <- </span>get *editor, left:offset + cursor-column:address:number<span class="Special"> <- </span>get-address *editor, cursor-column:offset + *cursor-column<span class="Special"> <- </span>copy left <span class="Comment"># update before-cursor</span> - before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address editor:address:editor-data/deref, before-cursor:offset - init:address:duplex-list<span class="Special"> <- </span>get editor:address:editor-data/deref, data:offset + before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, before-cursor:offset + init:address:duplex-list<span class="Special"> <- </span>get *editor, data:offset <span class="Comment"># while not at start of line, move </span> <span class="Delimiter">{</span> - at-start-of-text?:boolean<span class="Special"> <- </span>equal before-cursor:address:address:duplex-list/deref, init:address:duplex-list - <span class="muControl">break-if</span> at-start-of-text?:boolean - prev:character<span class="Special"> <- </span>get before-cursor:address:address:duplex-list/deref/deref, value:offset - at-start-of-line?:boolean<span class="Special"> <- </span>equal prev:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-if</span> at-start-of-line?:boolean - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>prev-duplex before-cursor:address:address:duplex-list/deref - assert before-cursor:address:address:duplex-list/deref, <span class="Constant">[move-to-start-of-line tried to move before start of text]</span> + at-start-of-text?:boolean<span class="Special"> <- </span>equal *before-cursor, init + <span class="muControl">break-if</span> at-start-of-text? + prev:character<span class="Special"> <- </span>get **before-cursor, value:offset + at-start-of-line?:boolean<span class="Special"> <- </span>equal prev, <span class="Constant">10/newline</span> + <span class="muControl">break-if</span> at-start-of-line? + *before-cursor<span class="Special"> <- </span>prev-duplex *before-cursor + assert *before-cursor, <span class="Constant">[move-to-start-of-line tried to move before start of text]</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -1092,75 +1167,75 @@ container editor-data [ <span class="muRecipe">recipe</span> move-to-end-of-line [ <span class="Constant">local-scope</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address editor:address:editor-data/deref, before-cursor:offset - cursor-column:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-column:offset + before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, before-cursor:offset + cursor-column:address:number<span class="Special"> <- </span>get-address *editor, cursor-column:offset <span class="Comment"># while not at start of line, move </span> <span class="Delimiter">{</span> - next:address:duplex-list<span class="Special"> <- </span>next-duplex before-cursor:address:address:duplex-list/deref - <span class="muControl">break-unless</span> next:address:duplex-list <span class="Comment"># end of text</span> - nextc:character<span class="Special"> <- </span>get next:address:duplex-list/deref, value:offset - at-end-of-line?:boolean<span class="Special"> <- </span>equal nextc:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-if</span> at-end-of-line?:boolean - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>copy next:address:duplex-list - cursor-column:address:number/deref<span class="Special"> <- </span>add cursor-column:address:number/deref, <span class="Constant">1:literal</span> + next:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor + <span class="muControl">break-unless</span> next <span class="Comment"># end of text</span> + nextc:character<span class="Special"> <- </span>get *next, value:offset + at-end-of-line?:boolean<span class="Special"> <- </span>equal nextc, <span class="Constant">10/newline</span> + <span class="muControl">break-if</span> at-end-of-line? + *before-cursor<span class="Special"> <- </span>copy next + *cursor-column<span class="Special"> <- </span>add *cursor-column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="Comment"># move one past end of line</span> - cursor-column:address:number/deref<span class="Special"> <- </span>add cursor-column:address:number/deref, <span class="Constant">1:literal</span> + <span class="Comment"># move one past final character</span> + *cursor-column<span class="Special"> <- </span>add *cursor-column, <span class="Constant">1</span> ] <span class="muRecipe">recipe</span> delete-to-start-of-line [ <span class="Constant">local-scope</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># compute range to delete</span> - init:address:duplex-list<span class="Special"> <- </span>get editor:address:editor-data/deref, data:offset - before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address editor:address:editor-data/deref, before-cursor:offset - start:address:duplex-list<span class="Special"> <- </span>copy before-cursor:address:address:duplex-list/deref - end:address:duplex-list<span class="Special"> <- </span>next-duplex before-cursor:address:address:duplex-list/deref + init:address:duplex-list<span class="Special"> <- </span>get *editor, data:offset + before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, before-cursor:offset + start:address:duplex-list<span class="Special"> <- </span>copy *before-cursor + end:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor <span class="Delimiter">{</span> - at-start-of-text?:boolean<span class="Special"> <- </span>equal start:address:duplex-list, init:address:duplex-list - <span class="muControl">break-if</span> at-start-of-text?:boolean - curr:character<span class="Special"> <- </span>get start:address:duplex-list/deref, value:offset - at-start-of-line?:boolean<span class="Special"> <- </span>equal curr:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-if</span> at-start-of-line?:boolean - start:address:duplex-list<span class="Special"> <- </span>prev-duplex start:address:duplex-list - assert start:address:duplex-list, <span class="Constant">[delete-to-start-of-line tried to move before start of text]</span> + at-start-of-text?:boolean<span class="Special"> <- </span>equal start, init + <span class="muControl">break-if</span> at-start-of-text? + curr:character<span class="Special"> <- </span>get *start, value:offset + at-start-of-line?:boolean<span class="Special"> <- </span>equal curr, <span class="Constant">10/newline</span> + <span class="muControl">break-if</span> at-start-of-line? + start<span class="Special"> <- </span>prev-duplex start + assert start, <span class="Constant">[delete-to-start-of-line tried to move before start of text]</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># snip it out</span> - start-next:address:address:duplex-list<span class="Special"> <- </span>get-address start:address:duplex-list/deref, next:offset - start-next:address:address:duplex-list/deref<span class="Special"> <- </span>copy end:address:duplex-list - end-prev:address:address:duplex-list<span class="Special"> <- </span>get-address end:address:duplex-list/deref, prev:offset - end-prev:address:address:duplex-list/deref<span class="Special"> <- </span>copy start:address:duplex-list + start-next:address:address:duplex-list<span class="Special"> <- </span>get-address *start, next:offset + *start-next<span class="Special"> <- </span>copy end + end-prev:address:address:duplex-list<span class="Special"> <- </span>get-address *end, prev:offset + *end-prev<span class="Special"> <- </span>copy start <span class="Comment"># adjust cursor</span> - before-cursor:address:address:duplex-list/deref<span class="Special"> <- </span>prev-duplex end:address:duplex-list - left:number<span class="Special"> <- </span>get editor:address:editor-data/deref, left:offset - cursor-column:address:number<span class="Special"> <- </span>get-address editor:address:editor-data/deref, cursor-column:offset - cursor-column:address:number/deref<span class="Special"> <- </span>copy left:number + *before-cursor<span class="Special"> <- </span>prev-duplex end + left:number<span class="Special"> <- </span>get *editor, left:offset + cursor-column:address:number<span class="Special"> <- </span>get-address *editor, cursor-column:offset + *cursor-column<span class="Special"> <- </span>copy left ] <span class="muRecipe">recipe</span> delete-to-end-of-line [ <span class="Constant">local-scope</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># compute range to delete</span> - start:address:duplex-list<span class="Special"> <- </span>get editor:address:editor-data/deref, before-cursor:offset - end:address:duplex-list<span class="Special"> <- </span>next-duplex start:address:duplex-list + start:address:duplex-list<span class="Special"> <- </span>get *editor, before-cursor:offset + end:address:duplex-list<span class="Special"> <- </span>next-duplex start <span class="Delimiter">{</span> - at-end-of-text?:boolean<span class="Special"> <- </span>equal end:address:duplex-list, <span class="Constant">0:literal/null</span> - <span class="muControl">break-if</span> at-end-of-text?:boolean - curr:character<span class="Special"> <- </span>get end:address:duplex-list/deref, value:offset - at-end-of-line?:boolean<span class="Special"> <- </span>equal curr:character, <span class="Constant">10:literal/newline</span> - <span class="muControl">break-if</span> at-end-of-line?:boolean - end:address:duplex-list<span class="Special"> <- </span>next-duplex end:address:duplex-list + at-end-of-text?:boolean<span class="Special"> <- </span>equal end, <span class="Constant">0/null</span> + <span class="muControl">break-if</span> at-end-of-text? + curr:character<span class="Special"> <- </span>get *end, value:offset + at-end-of-line?:boolean<span class="Special"> <- </span>equal curr, <span class="Constant">10/newline</span> + <span class="muControl">break-if</span> at-end-of-line? + end<span class="Special"> <- </span>next-duplex end <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># snip it out</span> - start-next:address:address:duplex-list<span class="Special"> <- </span>get-address start:address:duplex-list/deref, next:offset - start-next:address:address:duplex-list/deref<span class="Special"> <- </span>copy end:address:duplex-list + start-next:address:address:duplex-list<span class="Special"> <- </span>get-address *start, next:offset + *start-next<span class="Special"> <- </span>copy end <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> end:address:duplex-list - end-prev:address:address:duplex-list<span class="Special"> <- </span>get-address end:address:duplex-list/deref, prev:offset - end-prev:address:address:duplex-list/deref<span class="Special"> <- </span>copy start:address:duplex-list + <span class="muControl">break-unless</span> end + end-prev:address:address:duplex-list<span class="Special"> <- </span>get-address *end, prev:offset + *end-prev<span class="Special"> <- </span>copy start <span class="Delimiter">}</span> ] @@ -1168,38 +1243,38 @@ container editor-data [ <span class="Constant">local-scope</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> env:address:programming-environment-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - screen:address<span class="Special"> <- </span>render-recipes screen:address, env:address:programming-environment-data, <span class="Constant">1:literal/clear-below</span> - screen:address<span class="Special"> <- </span>render-sandbox-side screen:address, env:address:programming-environment-data, <span class="Constant">1:literal/clear-below</span> - recipes:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, recipes:offset - current-sandbox:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, current-sandbox:offset - sandbox-in-focus?:boolean<span class="Special"> <- </span>get env:address:programming-environment-data/deref, sandbox-in-focus?:offset - update-cursor screen:address, recipes:address:editor-data, current-sandbox:address:editor-data, sandbox-in-focus?:boolean - show-screen screen:address - <span class="muControl">reply</span> screen:address/same-as-ingredient:0 + screen<span class="Special"> <- </span>render-recipes screen, env, <span class="Constant">1/clear-below</span> + screen<span class="Special"> <- </span>render-sandbox-side screen, env, <span class="Constant">1/clear-below</span> + recipes:address:editor-data<span class="Special"> <- </span>get *env, recipes:offset + current-sandbox:address:editor-data<span class="Special"> <- </span>get *env, current-sandbox:offset + sandbox-in-focus?:boolean<span class="Special"> <- </span>get *env, sandbox-in-focus?:offset + update-cursor screen, recipes, current-sandbox, sandbox-in-focus? + show-screen screen + <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> render-minimal [ <span class="Constant">local-scope</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> env:address:programming-environment-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - recipes:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, recipes:offset - current-sandbox:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, current-sandbox:offset - sandbox-in-focus?:boolean<span class="Special"> <- </span>get env:address:programming-environment-data/deref, sandbox-in-focus?:offset + recipes:address:editor-data<span class="Special"> <- </span>get *env, recipes:offset + current-sandbox:address:editor-data<span class="Special"> <- </span>get *env, current-sandbox:offset + sandbox-in-focus?:boolean<span class="Special"> <- </span>get *env, sandbox-in-focus?:offset <span class="Delimiter">{</span> - <span class="muControl">break-if</span> sandbox-in-focus?:boolean - screen:address<span class="Special"> <- </span>render-recipes screen:address, env:address:programming-environment-data - cursor-row:number<span class="Special"> <- </span>get recipes:address:editor-data/deref, cursor-row:offset - cursor-column:number<span class="Special"> <- </span>get recipes:address:editor-data/deref, cursor-column:offset + <span class="muControl">break-if</span> sandbox-in-focus? + screen<span class="Special"> <- </span>render-recipes screen, env + cursor-row:number<span class="Special"> <- </span>get *recipes, cursor-row:offset + cursor-column:number<span class="Special"> <- </span>get *recipes, cursor-column:offset <span class="Delimiter">}</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> sandbox-in-focus?:boolean - screen:address<span class="Special"> <- </span>render-sandbox-side screen:address, env:address:programming-environment-data - cursor-row:number<span class="Special"> <- </span>get current-sandbox:address:editor-data/deref, cursor-row:offset - cursor-column:number<span class="Special"> <- </span>get current-sandbox:address:editor-data/deref, cursor-column:offset + <span class="muControl">break-unless</span> sandbox-in-focus? + screen<span class="Special"> <- </span>render-sandbox-side screen, env + cursor-row:number<span class="Special"> <- </span>get *current-sandbox, cursor-row:offset + cursor-column:number<span class="Special"> <- </span>get *current-sandbox, cursor-column:offset <span class="Delimiter">}</span> - move-cursor screen:address, cursor-row:number, cursor-column:number - show-screen screen:address - <span class="muControl">reply</span> screen:address/same-as-ingredient:0 + move-cursor screen, cursor-row, cursor-column + show-screen screen + <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> render-recipes [ @@ -1207,40 +1282,40 @@ container editor-data [ screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> env:address:programming-environment-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> clear:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - recipes:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, recipes:offset + recipes:address:editor-data<span class="Special"> <- </span>get *env, recipes:offset <span class="Comment"># render recipes</span> - left:number<span class="Special"> <- </span>get recipes:address:editor-data/deref, left:offset - right:number<span class="Special"> <- </span>get recipes:address:editor-data/deref, right:offset - row:number, screen:address<span class="Special"> <- </span>render screen:address, recipes:address:editor-data - recipe-warnings:address:array:character<span class="Special"> <- </span>get env:address:programming-environment-data/deref, recipe-warnings:offset + left:number<span class="Special"> <- </span>get *recipes, left:offset + right:number<span class="Special"> <- </span>get *recipes, right:offset + row:number, screen<span class="Special"> <- </span>render screen, recipes + recipe-warnings:address:array:character<span class="Special"> <- </span>get *env, recipe-warnings:offset <span class="Delimiter">{</span> <span class="Comment"># print any warnings</span> - <span class="muControl">break-unless</span> recipe-warnings:address:array:character - row:number, screen:address<span class="Special"> <- </span>render-string screen:address, recipe-warnings:address:array:character, left:number, right:number, <span class="Constant">1:literal/red</span>, row:number + <span class="muControl">break-unless</span> recipe-warnings + row, screen<span class="Special"> <- </span>render-string screen, recipe-warnings, left, right, <span class="Constant">1/red</span>, row <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># no warnings? move to next line</span> - <span class="muControl">break-if</span> recipe-warnings:address:array:character - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> + <span class="muControl">break-if</span> recipe-warnings + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> <span class="Delimiter">}</span> <span class="Comment"># draw dotted line after recipes</span> - draw-horizontal screen:address, row:number, left:number, right:number, <span class="Constant">9480:literal/horizontal-dotted</span> + draw-horizontal screen, row, left, right, <span class="Constant">9480/horizontal-dotted</span> <span class="Comment"># clear next line, in case we just processed a backspace</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - move-cursor screen:address, row:number, left:number - clear-line-delimited screen:address, left:number, right:number + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + move-cursor screen, row, left + clear-line-delimited screen, left, right <span class="Comment"># clear rest of screen in this column, if requested</span> - <span class="muControl">reply-unless</span> clear:boolean, screen:address/same-as-ingredient:0 - screen-height:number<span class="Special"> <- </span>screen-height screen:address + <span class="muControl">reply-unless</span> clear, screen/same-as-ingredient:<span class="Constant">0</span> + screen-height:number<span class="Special"> <- </span>screen-height screen <span class="Delimiter">{</span> - at-bottom-of-screen?:boolean<span class="Special"> <- </span>greater-or-equal row:number, screen-height:number - <span class="muControl">break-if</span> at-bottom-of-screen?:boolean - move-cursor screen:address, row:number, left:number - clear-line-delimited screen:address, left:number, right:number - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> + at-bottom-of-screen?:boolean<span class="Special"> <- </span>greater-or-equal row, screen-height + <span class="muControl">break-if</span> at-bottom-of-screen? + move-cursor screen, row, left + clear-line-delimited screen, left, right + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> screen:address/same-as-ingredient:0 + <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> update-cursor [ @@ -1250,29 +1325,29 @@ container editor-data [ current-sandbox:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> sandbox-in-focus?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> sandbox-in-focus?:boolean + <span class="muControl">break-if</span> sandbox-in-focus? <span class="CommentedCode">#? $print [recipes in focus</span> <span class="CommentedCode">#? ] #? 1</span> - cursor-row:number<span class="Special"> <- </span>get recipes:address:editor-data/deref, cursor-row:offset - cursor-column:number<span class="Special"> <- </span>get recipes:address:editor-data/deref, cursor-column:offset + cursor-row:number<span class="Special"> <- </span>get *recipes, cursor-row:offset + cursor-column:number<span class="Special"> <- </span>get *recipes, cursor-column:offset <span class="Delimiter">}</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> sandbox-in-focus?:boolean + <span class="muControl">break-unless</span> sandbox-in-focus? <span class="CommentedCode">#? $print [sandboxes in focus</span> <span class="CommentedCode">#? ] #? 1</span> - cursor-row:number<span class="Special"> <- </span>get current-sandbox:address:editor-data/deref, cursor-row:offset - cursor-column:number<span class="Special"> <- </span>get current-sandbox:address:editor-data/deref, cursor-column:offset + cursor-row:number<span class="Special"> <- </span>get *current-sandbox, cursor-row:offset + cursor-column:number<span class="Special"> <- </span>get *current-sandbox, cursor-column:offset <span class="Delimiter">}</span> - move-cursor screen:address, cursor-row:number, cursor-column:number + move-cursor screen, cursor-row, cursor-column ] <span class="muScenario">scenario</span> editor-handles-empty-event-queue [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console <span class="Constant">[]</span> run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1282,16 +1357,16 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 1 <span class="Comment"># on the 'b'</span> + left-click <span class="Constant">1</span>, <span class="Constant">1</span> <span class="Comment"># on the 'b'</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1299,80 +1374,80 @@ container editor-data [ <span class="Constant"> . .</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># cursor is at row 0..</span> - 4<span class="Special"> <- </span>1 <span class="Comment"># ..and column 1</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor is at row 0..</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># ..and column 1</span> ] ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 7 <span class="Comment"># last line, to the right of text</span> + left-click <span class="Constant">1</span>, <span class="Constant">7</span> <span class="Comment"># last line, to the right of text</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># cursor row</span> - 4<span class="Special"> <- </span>3 <span class="Comment"># cursor column</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">def]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 7 <span class="Comment"># interior line, to the right of text</span> + left-click <span class="Constant">1</span>, <span class="Constant">7</span> <span class="Comment"># interior line, to the right of text</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># cursor row</span> - 4<span class="Special"> <- </span>3 <span class="Comment"># cursor column</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text-3 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">def]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 3, 7 <span class="Comment"># below text</span> + left-click <span class="Constant">3</span>, <span class="Constant">7</span> <span class="Comment"># below text</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>2 <span class="Comment"># cursor row</span> - 4<span class="Special"> <- </span>3 <span class="Comment"># cursor column</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># cursor row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-column [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> <span class="Comment"># editor occupies only left half of screen</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ <span class="Comment"># click on right half of screen</span> - left-click 3, 8 + left-click <span class="Constant">3</span>, <span class="Constant">8</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1380,20 +1455,20 @@ container editor-data [ <span class="Constant"> . .</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># no change to cursor row</span> - 4<span class="Special"> <- </span>0 <span class="Comment"># ..or column</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># no change to cursor row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># ..or column</span> ] ] <span class="muScenario">scenario</span> editor-inserts-characters-into-empty-editor [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ type <span class="Constant">[abc]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1403,16 +1478,16 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ type <span class="Constant">[0]</span> - left-click 1, 2 + left-click <span class="Constant">1</span>, <span class="Constant">2</span> type <span class="Constant">[d]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1422,15 +1497,15 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 5 <span class="Comment"># right of last line</span> + left-click <span class="Constant">1</span>, <span class="Constant">5</span> <span class="Comment"># right of last line</span> type <span class="Constant">[d]</span> <span class="Comment"># should append</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1440,15 +1515,15 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-3 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 3, 5 <span class="Comment"># below all text</span> + left-click <span class="Constant">3</span>, <span class="Constant">5</span> <span class="Comment"># below all text</span> type <span class="Constant">[d]</span> <span class="Comment"># should append</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1458,16 +1533,16 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-4 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 3, 5 <span class="Comment"># below all text</span> + left-click <span class="Constant">3</span>, <span class="Constant">5</span> <span class="Comment"># below all text</span> type <span class="Constant">[e]</span> <span class="Comment"># should append</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1478,16 +1553,16 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-5 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 3, 5 <span class="Comment"># below all text</span> + left-click <span class="Constant">3</span>, <span class="Constant">5</span> <span class="Comment"># below all text</span> type <span class="Constant">[ef]</span> <span class="Comment"># should append multiple characters in order</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1498,15 +1573,15 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-wraps-line-on-insert [ - assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># type a letter</span> assume-console [ type <span class="Constant">[e]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># no wrap yet</span> screen-should-contain [ @@ -1520,7 +1595,7 @@ container editor-data [ type <span class="Constant">[f]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># now wrap</span> screen-should-contain [ @@ -1532,14 +1607,14 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-after-inserting-characters [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ type <span class="Constant">[01]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1549,17 +1624,17 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-wraps-cursor-after-inserting-characters [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ - left-click 1, 4 <span class="Comment"># line is full; no wrap icon yet</span> + left-click <span class="Constant">1</span>, <span class="Constant">4</span> <span class="Comment"># line is full; no wrap icon yet</span> type <span class="Constant">[f]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1568,23 +1643,23 @@ container editor-data [ <span class="Constant"> . .</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>2 <span class="Comment"># cursor row</span> - 4<span class="Special"> <- </span>1 <span class="Comment"># cursor column</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># cursor row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> editor-wraps-cursor-after-inserting-characters-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ - left-click 1, 3 <span class="Comment"># right before the wrap icon</span> + left-click <span class="Constant">1</span>, <span class="Constant">3</span> <span class="Comment"># right before the wrap icon</span> type <span class="Constant">[f]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1593,21 +1668,21 @@ container editor-data [ <span class="Constant"> . .</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>2 <span class="Comment"># cursor row</span> - 4<span class="Special"> <- </span>0 <span class="Comment"># cursor column</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># cursor row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> editor-moves-cursor-down-after-inserting-newline [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ type <span class="Constant">[0</span> <span class="Constant">1]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1618,15 +1693,15 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-down-after-inserting-newline-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">1:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">1/left</span>, <span class="Constant">10/right</span> assume-console [ type <span class="Constant">[0</span> <span class="Constant">1]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1637,9 +1712,9 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-clears-previous-line-completely-after-inserting-newline [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># press just a 'newline'</span> assume-console [ type [ @@ -1653,7 +1728,7 @@ container editor-data [ <span class="Constant"> . .</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># line should be fully cleared</span> screen-should-contain [ @@ -1665,20 +1740,44 @@ container editor-data [ ] ] +<span class="muScenario">scenario</span> editor-inserts-indent-after-newline [ + assume-screen <span class="Constant">10/width</span>, <span class="Constant">10/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span> +<span class="Constant"> cd</span> +<span class="Constant">ef]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + <span class="Comment"># position cursor after 'cd' and hit 'newline'</span> + assume-console [ + left-click <span class="Constant">2</span>, <span class="Constant">8</span> + type [ +] + ] + run [ + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset + ] + <span class="Comment"># cursor should be below start of previous line</span> + memory-should-contain [ + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># cursor row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># cursor column (indented)</span> + ] +] + <span class="muScenario">scenario</span> editor-handles-backspace-key [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 1 + left-click <span class="Constant">1</span>, <span class="Constant">1</span> type <span class="Constant">[«]</span> ] - 3:event/backspace<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">171:literal/«</span>, 3:event/backspace + <span class="Constant">3</span>:event/backspace<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">8/backspace</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">171/«</span>, <span class="Constant">3</span>:event/backspace run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 5:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1686,25 +1785,25 @@ container editor-data [ <span class="Constant"> . .</span> ] memory-should-contain [ - 4<span class="Special"> <- </span>1 - 5<span class="Special"> <- </span>0 + <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">0</span> ] ] <span class="muScenario">scenario</span> editor-clears-last-line-on-backspace [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># just one character in final line</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span> <span class="Constant">cd]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ - left-click 2, 0 <span class="Comment"># cursor at only character in final line</span> + left-click <span class="Constant">2</span>, <span class="Constant">0</span> <span class="Comment"># cursor at only character in final line</span> type <span class="Constant">[«]</span> ] - 3:event/backspace<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">171:literal/«</span>, 3:event/backspace + <span class="Constant">3</span>:event/backspace<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">8/backspace</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">171/«</span>, <span class="Constant">3</span>:event/backspace run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1713,16 +1812,37 @@ container editor-data [ ] ] +<span class="muScenario">scenario</span> editor-inserts-two-spaces-on-tab [ + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Comment"># just one character in final line</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span> +<span class="Constant">cd]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + assume-console [ + type <span class="Constant">[»]</span> + ] + <span class="Constant">3</span>:event/tab<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">9/tab</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">187/»</span>, <span class="Constant">3</span>:event/tab + run [ + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + ] + screen-should-contain [ + <span class="Constant"> . .</span> + <span class="Constant"> . ab .</span> + <span class="Constant"> .cd .</span> + ] +] + <span class="muScenario">scenario</span> editor-moves-cursor-right-with-key [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - press 65514 <span class="Comment"># right arrow</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> type <span class="Constant">[0]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1732,19 +1852,19 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - press 65514 <span class="Comment"># right arrow</span> - press 65514 <span class="Comment"># right arrow</span> - press 65514 <span class="Comment"># right arrow</span> - press 65514 <span class="Comment"># right arrow - next line</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow - next line</span> type <span class="Constant">[0]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1755,19 +1875,19 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">1:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">1/left</span>, <span class="Constant">10/right</span> assume-console [ - press 65514 <span class="Comment"># right arrow</span> - press 65514 <span class="Comment"># right arrow</span> - press 65514 <span class="Comment"># right arrow</span> - press 65514 <span class="Comment"># right arrow - next line</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow - next line</span> type <span class="Constant">[0]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1778,17 +1898,17 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ - left-click 1, 3 - press 65514 <span class="Comment"># right arrow</span> + left-click <span class="Constant">1</span>, <span class="Constant">3</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1797,57 +1917,57 @@ container editor-data [ <span class="Constant"> . .</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>2 - 4<span class="Special"> <- </span>0 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># line just barely wrapping</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># position cursor at last character before wrap and hit right-arrow</span> assume-console [ - left-click 1, 3 - press 65514 <span class="Comment"># right arrow</span> + left-click <span class="Constant">1</span>, <span class="Constant">3</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>2 - 4<span class="Special"> <- </span>0 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> ] <span class="Comment"># now hit right arrow again</span> assume-console [ - press 65514 + press <span class="Constant">65514</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>2 - 4<span class="Special"> <- </span>1 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> ] ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">1:literal/left</span>, <span class="Constant">6:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">1/left</span>, <span class="Constant">6/right</span> assume-console [ - left-click 1, 4 - press 65514 <span class="Comment"># right arrow</span> + left-click <span class="Constant">1</span>, <span class="Constant">4</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1856,23 +1976,23 @@ container editor-data [ <span class="Constant"> . .</span> ] memory-should-contain [ - 3<span class="Special"> <- </span>2 - 4<span class="Special"> <- </span>1 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> ] ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 3 - press 65514 <span class="Comment"># right arrow - next line</span> + left-click <span class="Constant">1</span>, <span class="Constant">3</span> + press <span class="Constant">65514</span> <span class="Comment"># right arrow - next line</span> type <span class="Constant">[0]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1883,16 +2003,16 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-left-with-key [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 2 - press 65515 <span class="Comment"># left arrow</span> + left-click <span class="Constant">1</span>, <span class="Constant">2</span> + press <span class="Constant">65515</span> <span class="Comment"># left arrow</span> type <span class="Constant">[0]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1902,43 +2022,43 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with two lines</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">d]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># position cursor at start of second line (so there's no previous newline)</span> assume-console [ - left-click 2, 0 - press 65515 <span class="Comment"># left arrow</span> + left-click <span class="Constant">2</span>, <span class="Constant">0</span> + press <span class="Constant">65515</span> <span class="Comment"># left arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>1 - 4<span class="Special"> <- </span>3 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> ] ] <span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with three lines</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">g]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># position cursor further down (so there's a newline before the character at</span> <span class="Comment"># the cursor)</span> assume-console [ - left-click 3, 0 - press 65515 <span class="Comment"># left arrow</span> + left-click <span class="Constant">3</span>, <span class="Constant">0</span> + press <span class="Constant">65515</span> <span class="Comment"># left arrow</span> type <span class="Constant">[0]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1950,19 +2070,19 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-3 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">g]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># position cursor at start of text</span> assume-console [ - left-click 1, 0 - press 65515 <span class="Comment"># left arrow should have no effect</span> + left-click <span class="Constant">1</span>, <span class="Constant">0</span> + press <span class="Constant">65515</span> <span class="Comment"># left arrow should have no effect</span> type <span class="Constant">[0]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1974,20 +2094,20 @@ container editor-data [ ] <span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-4 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with text containing an empty line</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> d] - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># position cursor right after empty line</span> assume-console [ - left-click 3, 0 - press 65515 <span class="Comment"># left arrow</span> + left-click <span class="Constant">3</span>, <span class="Constant">0</span> + press <span class="Constant">65515</span> <span class="Comment"># left arrow</span> type <span class="Constant">[0]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1999,10 +2119,10 @@ d] ] <span class="muScenario">scenario</span> editor-moves-across-screen-lines-across-wrap-with-left-arrow [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with text containing an empty line</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcd↩ .</span> @@ -2011,227 +2131,227 @@ d] ] <span class="Comment"># position cursor right after empty line</span> assume-console [ - left-click 2, 0 - press 65515 <span class="Comment"># left arrow</span> + left-click <span class="Constant">2</span>, <span class="Constant">0</span> + press <span class="Constant">65515</span> <span class="Comment"># left arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>1 <span class="Comment"># previous row</span> - 4<span class="Special"> <- </span>3 <span class="Comment"># end of wrapped line</span> + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># previous row</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># end of wrapped line</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-previous-line-with-up-arrow [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">def]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 2, 1 - press 65517 <span class="Comment"># up arrow</span> + left-click <span class="Constant">2</span>, <span class="Constant">1</span> + press <span class="Constant">65517</span> <span class="Comment"># up arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>1 - 4<span class="Special"> <- </span>1 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-next-line-with-down-arrow [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">def]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># cursor starts out at (1, 0)</span> assume-console [ - press 65516 <span class="Comment"># down arrow</span> + press <span class="Constant">65516</span> <span class="Comment"># down arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># ..and ends at (2, 0)</span> memory-should-contain [ - 3<span class="Special"> <- </span>2 - 4<span class="Special"> <- </span>0 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> editor-adjusts-column-at-previous-line [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span> <span class="Constant">def]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 2, 3 - press 65517 <span class="Comment"># up arrow</span> + left-click <span class="Constant">2</span>, <span class="Constant">3</span> + press <span class="Constant">65517</span> <span class="Comment"># up arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>1 - 4<span class="Special"> <- </span>2 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span> ] ] <span class="muScenario">scenario</span> editor-adjusts-column-at-next-line [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span> <span class="Constant">de]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 3 - press 65516 <span class="Comment"># down arrow</span> + left-click <span class="Constant">1</span>, <span class="Constant">3</span> + press <span class="Constant">65516</span> <span class="Comment"># down arrow</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 3<span class="Special"> <- </span>2 - 4<span class="Special"> <- </span>2 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-ctrl-a [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on second line, press ctrl-a</span> assume-console [ - left-click 2, 3 + left-click <span class="Constant">2</span>, <span class="Constant">3</span> type <span class="Constant">[a]</span> <span class="Comment"># ctrl-a</span> ] - 3:event/ctrl-a<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">1:literal/ctrl-a</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">97:literal/a</span>, 3:event/ctrl-a + <span class="Constant">3</span>:event/ctrl-a<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">1/ctrl-a</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">97/a</span>, <span class="Constant">3</span>:event/ctrl-a run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 5:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># cursor moves to start of line</span> memory-should-contain [ - 4<span class="Special"> <- </span>2 - 5<span class="Special"> <- </span>0 + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-ctrl-a-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on first line (no newline before), press ctrl-a</span> assume-console [ - left-click 1, 3 + left-click <span class="Constant">1</span>, <span class="Constant">3</span> type <span class="Constant">[a]</span> <span class="Comment"># ctrl-a</span> ] - 3:event/ctrl-a<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">1:literal/ctrl-a</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">97:literal/a</span>, 3:event/ctrl-a + <span class="Constant">3</span>:event/ctrl-a<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">1/ctrl-a</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">97/a</span>, <span class="Constant">3</span>:event/ctrl-a run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 5:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># cursor moves to start of line</span> memory-should-contain [ - 4<span class="Special"> <- </span>1 - 5<span class="Special"> <- </span>0 + <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">0</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-home [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on second line, press 'home'</span> assume-console [ - left-click 2, 3 - press 65521 <span class="Comment"># 'home'</span> + left-click <span class="Constant">2</span>, <span class="Constant">3</span> + press <span class="Constant">65521</span> <span class="Comment"># 'home'</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># cursor moves to start of line</span> memory-should-contain [ - 3<span class="Special"> <- </span>2 - 4<span class="Special"> <- </span>0 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-home-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on first line (no newline before), press 'home'</span> assume-console [ - left-click 1, 3 - press 65521 <span class="Comment"># 'home'</span> + left-click <span class="Constant">1</span>, <span class="Constant">3</span> + press <span class="Constant">65521</span> <span class="Comment"># 'home'</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># cursor moves to start of line</span> memory-should-contain [ - 3<span class="Special"> <- </span>1 - 4<span class="Special"> <- </span>0 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-ctrl-e [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on first line, press ctrl-e</span> assume-console [ - left-click 1, 1 + left-click <span class="Constant">1</span>, <span class="Constant">1</span> type <span class="Constant">[e]</span> <span class="Comment"># ctrl-e</span> ] - 3:event/ctrl-e<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">5:literal/ctrl-e</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">101:literal/e</span>, 3:event/ctrl-e + <span class="Constant">3</span>:event/ctrl-e<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">5/ctrl-e</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">101/e</span>, <span class="Constant">3</span>:event/ctrl-e run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 5:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># cursor moves to end of line</span> memory-should-contain [ - 4<span class="Special"> <- </span>1 - 5<span class="Special"> <- </span>3 + <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">3</span> ] <span class="Comment"># editor inserts future characters at cursor</span> assume-console [ type <span class="Constant">[z]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 5:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 4<span class="Special"> <- </span>1 - 5<span class="Special"> <- </span>4 + <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">4</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -2242,87 +2362,87 @@ d] ] <span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-ctrl-e-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on second line (no newline after), press ctrl-e</span> assume-console [ - left-click 2, 1 + left-click <span class="Constant">2</span>, <span class="Constant">1</span> type <span class="Constant">[e]</span> <span class="Comment"># ctrl-e</span> ] - 3:event/ctrl-e<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">5:literal/ctrl-e</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">101:literal/e</span>, 3:event/ctrl-e + <span class="Constant">3</span>:event/ctrl-e<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">5/ctrl-e</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">101/e</span>, <span class="Constant">3</span>:event/ctrl-e run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 5:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># cursor moves to end of line</span> memory-should-contain [ - 4<span class="Special"> <- </span>2 - 5<span class="Special"> <- </span>3 + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">3</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-end [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on first line, press 'end'</span> assume-console [ - left-click 1, 1 - press 65520 <span class="Comment"># 'end'</span> + left-click <span class="Constant">1</span>, <span class="Constant">1</span> + press <span class="Constant">65520</span> <span class="Comment"># 'end'</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># cursor moves to end of line</span> memory-should-contain [ - 3<span class="Special"> <- </span>1 - 4<span class="Special"> <- </span>3 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> ] ] <span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-end-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on second line (no newline after), press 'end'</span> assume-console [ - left-click 2, 1 - press 65520 <span class="Comment"># 'end'</span> + left-click <span class="Constant">2</span>, <span class="Constant">1</span> + press <span class="Constant">65520</span> <span class="Comment"># 'end'</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-row:offset - 4:number<span class="Special"> <- </span>get 2:address:editor-data/deref, cursor-column:offset + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-row:offset + <span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, cursor-column:offset ] <span class="Comment"># cursor moves to end of line</span> memory-should-contain [ - 3<span class="Special"> <- </span>2 - 4<span class="Special"> <- </span>3 + <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> ] ] <span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on second line, press ctrl-u</span> assume-console [ - left-click 2, 2 + left-click <span class="Constant">2</span>, <span class="Constant">2</span> type <span class="Constant">[u]</span> <span class="Comment"># ctrl-u</span> ] - 3:event/ctrl-a<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">21:literal/ctrl-u</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">117:literal/u</span>, 3:event/ctrl-u + <span class="Constant">3</span>:event/ctrl-a<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">21/ctrl-u</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">117/u</span>, <span class="Constant">3</span>:event/ctrl-u run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to start of line</span> screen-should-contain [ @@ -2334,19 +2454,19 @@ d] ] <span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on first line (no newline before), press ctrl-u</span> assume-console [ - left-click 1, 2 + left-click <span class="Constant">1</span>, <span class="Constant">2</span> type <span class="Constant">[u]</span> <span class="Comment"># ctrl-u</span> ] - 3:event/ctrl-u<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">21:literal/ctrl-a</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">117:literal/a</span>, 3:event/ctrl-u + <span class="Constant">3</span>:event/ctrl-u<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">21/ctrl-a</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">117/a</span>, <span class="Constant">3</span>:event/ctrl-u run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to start of line</span> screen-should-contain [ @@ -2358,19 +2478,19 @@ d] ] <span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u-3 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start past end of line, press ctrl-u</span> assume-console [ - left-click 1, 3 + left-click <span class="Constant">1</span>, <span class="Constant">3</span> type <span class="Constant">[u]</span> <span class="Comment"># ctrl-u</span> ] - 3:event/ctrl-u<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">21:literal/ctrl-a</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">117:literal/a</span>, 3:event/ctrl-u + <span class="Constant">3</span>:event/ctrl-u<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">21/ctrl-a</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">117/a</span>, <span class="Constant">3</span>:event/ctrl-u run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to start of line</span> screen-should-contain [ @@ -2382,19 +2502,19 @@ d] ] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on first line, press ctrl-k</span> assume-console [ - left-click 1, 1 + left-click <span class="Constant">1</span>, <span class="Constant">1</span> type <span class="Constant">[k]</span> <span class="Comment"># ctrl-k</span> ] - 3:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">11:literal/ctrl-k</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">107:literal/k</span>, 3:event/ctrl-k + <span class="Constant">3</span>:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">11/ctrl-k</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">107/k</span>, <span class="Constant">3</span>:event/ctrl-k run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to end of line</span> screen-should-contain [ @@ -2406,19 +2526,19 @@ d] ] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-2 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start on second line (no newline after), press ctrl-k</span> assume-console [ - left-click 2, 1 + left-click <span class="Constant">2</span>, <span class="Constant">1</span> type <span class="Constant">[k]</span> <span class="Comment"># ctrl-k</span> ] - 3:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">11:literal/ctrl-k</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">107:literal/k</span>, 3:event/ctrl-k + <span class="Constant">3</span>:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">11/ctrl-k</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">107/k</span>, <span class="Constant">3</span>:event/ctrl-k run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to end of line</span> screen-should-contain [ @@ -2430,19 +2550,19 @@ d] ] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-3 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start at end of line</span> assume-console [ - left-click 1, 2 + left-click <span class="Constant">1</span>, <span class="Constant">2</span> type <span class="Constant">[k]</span> <span class="Comment"># ctrl-k</span> ] - 3:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">11:literal/ctrl-k</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">107:literal/k</span>, 3:event/ctrl-k + <span class="Constant">3</span>:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">11/ctrl-k</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">107/k</span>, <span class="Constant">3</span>:event/ctrl-k run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to end of line</span> screen-should-contain [ @@ -2454,19 +2574,19 @@ d] ] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-4 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start past end of line</span> assume-console [ - left-click 1, 3 + left-click <span class="Constant">1</span>, <span class="Constant">3</span> type <span class="Constant">[k]</span> <span class="Comment"># ctrl-k</span> ] - 3:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">11:literal/ctrl-k</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">107:literal/k</span>, 3:event/ctrl-k + <span class="Constant">3</span>:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">11/ctrl-k</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">107/k</span>, <span class="Constant">3</span>:event/ctrl-k run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to end of line</span> screen-should-contain [ @@ -2478,19 +2598,19 @@ d] ] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-5 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start at end of text</span> assume-console [ - left-click 2, 2 + left-click <span class="Constant">2</span>, <span class="Constant">2</span> type <span class="Constant">[k]</span> <span class="Comment"># ctrl-k</span> ] - 3:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">11:literal/ctrl-k</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">107:literal/k</span>, 3:event/ctrl-k + <span class="Constant">3</span>:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">11/ctrl-k</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">107/k</span>, <span class="Constant">3</span>:event/ctrl-k run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to end of line</span> screen-should-contain [ @@ -2502,19 +2622,19 @@ d] ] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-6 [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span> <span class="Constant">456]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start past end of text</span> assume-console [ - left-click 2, 3 + left-click <span class="Constant">2</span>, <span class="Constant">3</span> type <span class="Constant">[k]</span> <span class="Comment"># ctrl-k</span> ] - 3:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">11:literal/ctrl-k</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">107:literal/k</span>, 3:event/ctrl-k + <span class="Constant">3</span>:event/ctrl-k<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">11/ctrl-k</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">107/k</span>, <span class="Constant">3</span>:event/ctrl-k run [ - editor-event-loop screen:address, console:address, 2:address:editor-data + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data ] <span class="Comment"># cursor deletes to end of line</span> screen-should-contain [ @@ -2527,67 +2647,67 @@ d] <span class="muScenario">scenario</span> point-at-multiple-editors [ <span class="Constant"> $close-trace</span> - assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">30/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize both halves of screen</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[def]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[def]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character <span class="Comment"># focus on both sides</span> assume-console [ - left-click 1, 1 - left-click 1, 17 + left-click <span class="Constant">1</span>, <span class="Constant">1</span> + left-click <span class="Constant">1</span>, <span class="Constant">17</span> ] <span class="Comment"># check cursor column in each</span> run [ - event-loop screen:address, console:address, 3:address:programming-environment-data - 4:address:editor-data<span class="Special"> <- </span>get 3:address:programming-environment-data/deref, recipes:offset - 5:number<span class="Special"> <- </span>get 4:address:editor-data/deref, cursor-column:offset - 6:address:editor-data<span class="Special"> <- </span>get 3:address:programming-environment-data/deref, current-sandbox:offset - 7:number<span class="Special"> <- </span>get 6:address:editor-data/deref, cursor-column:offset + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data + <span class="Constant">4</span>:address:editor-data<span class="Special"> <- </span>get *<span class="Constant">3</span>:address:programming-environment-data, recipes:offset + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">4</span>:address:editor-data, cursor-column:offset + <span class="Constant">6</span>:address:editor-data<span class="Special"> <- </span>get *<span class="Constant">3</span>:address:programming-environment-data, current-sandbox:offset + <span class="Constant">7</span>:number<span class="Special"> <- </span>get *<span class="Constant">6</span>:address:editor-data, cursor-column:offset ] memory-should-contain [ - 5<span class="Special"> <- </span>1 - 7<span class="Special"> <- </span>17 + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">17</span> ] ] <span class="muScenario">scenario</span> edit-multiple-editors [ <span class="Constant"> $close-trace</span> - assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span> + assume-screen <span class="Constant">30/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize both halves of screen</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[def]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[def]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character <span class="Comment"># type one letter in each of them</span> assume-console [ - left-click 1, 1 + left-click <span class="Constant">1</span>, <span class="Constant">1</span> type <span class="Constant">[0]</span> - left-click 1, 17 + left-click <span class="Constant">1</span>, <span class="Constant">17</span> type <span class="Constant">[1]</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data - 4:address:editor-data<span class="Special"> <- </span>get 3:address:programming-environment-data/deref, recipes:offset - 5:number<span class="Special"> <- </span>get 4:address:editor-data/deref, cursor-column:offset - 6:address:editor-data<span class="Special"> <- </span>get 3:address:programming-environment-data/deref, current-sandbox:offset - 7:number<span class="Special"> <- </span>get 6:address:editor-data/deref, cursor-column:offset + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data + <span class="Constant">4</span>:address:editor-data<span class="Special"> <- </span>get *<span class="Constant">3</span>:address:programming-environment-data, recipes:offset + <span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">4</span>:address:editor-data, cursor-column:offset + <span class="Constant">6</span>:address:editor-data<span class="Special"> <- </span>get *<span class="Constant">3</span>:address:programming-environment-data, current-sandbox:offset + <span class="Constant">7</span>:number<span class="Special"> <- </span>get *<span class="Constant">6</span>:address:editor-data, cursor-column:offset ] screen-should-contain [ - <span class="Constant"> . run (F10) . # this line has a different background, but we don't test that yet</span> + <span class="Constant"> . run (F4) . # this line has a different background, but we don't test that yet</span> <span class="Constant"> .a0bc ┊d1ef .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> ] memory-should-contain [ - 5<span class="Special"> <- </span>2 <span class="Comment"># cursor column of recipe editor</span> - 7<span class="Special"> <- </span>18 <span class="Comment"># cursor column of sandbox editor</span> + <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># cursor column of recipe editor</span> + <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">18</span> <span class="Comment"># cursor column of sandbox editor</span> ] <span class="Comment"># show the cursor at the right window</span> run [ - screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">9251:literal/␣</span> + screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">9251/␣</span> ] screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> .a0bc ┊d1␣f .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> @@ -2596,15 +2716,15 @@ d] <span class="muScenario">scenario</span> multiple-editors-cover-only-their-own-areas [ <span class="Constant"> $close-trace</span> - assume-screen <span class="Constant">60:literal/width</span>, <span class="Constant">10:literal/height</span> + assume-screen <span class="Constant">60/width</span>, <span class="Constant">10/height</span> run [ - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[def]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[def]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character ] <span class="Comment"># divider isn't messed up</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> .abc ┊def .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> @@ -2614,19 +2734,19 @@ d] <span class="muScenario">scenario</span> editor-in-focus-keeps-cursor [ <span class="Constant"> $close-trace</span> - assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[def]</span> + assume-screen <span class="Constant">30/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[def]</span> <span class="Comment"># initialize programming environment and highlight cursor</span> assume-console <span class="Constant">[]</span> run [ - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character - event-loop screen:address, console:address, 3:address:programming-environment-data - screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">9251:literal/␣</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data + screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">9251/␣</span> ] <span class="Comment"># is cursor at the right place?</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> .␣bc ┊def .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> @@ -2636,13 +2756,13 @@ d] type <span class="Constant">[z]</span> ] run [ - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character - event-loop screen:address, console:address, 3:address:programming-environment-data - screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">9251:literal/␣</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data + screen:address<span class="Special"> <- </span>print-character screen:address, <span class="Constant">9251/␣</span> ] <span class="Comment"># cursor should still be right</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> .z␣bc ┊def .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> @@ -2662,43 +2782,43 @@ container sandbox-data [ <span class="muScenario">scenario</span> run-and-show-results [ $close-trace <span class="Comment"># trace too long for github</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">15:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Comment"># recipe editor is empty</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> <span class="Comment"># sandbox editor contains an instruction without storing outputs</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[divide-with-remainder 11:literal, 3:literal]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[divide-with-remainder 11, 3]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character <span class="Comment"># run the code in the editors</span> assume-console [ - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] <span class="Comment"># check that screen prints the results</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> - <span class="Constant"> . ┊divide-with-remainder 11:literal, 3:literal .</span> + <span class="Constant"> . ┊divide-with-remainder 11, 3 .</span> <span class="Constant"> . ┊3 .</span> <span class="Constant"> . ┊2 .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> ] - screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [ + screen-should-contain-in-color <span class="Constant">7/white</span>, [ <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> - <span class="Constant"> . divide-with-remainder 11:literal, 3:literal .</span> + <span class="Constant"> . divide-with-remainder 11, 3 .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> ] - screen-should-contain-in-color <span class="Constant">245:literal/grey</span>, [ + screen-should-contain-in-color <span class="Constant">245/grey</span>, [ <span class="Constant"> . .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> @@ -2711,24 +2831,24 @@ container sandbox-data [ ] <span class="Comment"># run another command</span> assume-console [ - left-click 1, 80 - type <span class="Constant">[add 2:literal, 2:literal]</span> - press 65526 <span class="Comment"># F10</span> + left-click <span class="Constant">1</span>, <span class="Constant">80</span> + type <span class="Constant">[add 2, 2]</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] <span class="Comment"># check that screen prints the results</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> - <span class="Constant"> . ┊add 2:literal, 2:literal .</span> + <span class="Constant"> . ┊add 2, 2 .</span> <span class="Constant"> . ┊4 .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> - <span class="Constant"> . ┊divide-with-remainder 11:literal, 3:literal .</span> + <span class="Constant"> . ┊divide-with-remainder 11, 3 .</span> <span class="Constant"> . ┊3 .</span> <span class="Constant"> . ┊2 .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> @@ -2739,55 +2859,57 @@ container sandbox-data [ <span class="muRecipe">recipe</span> run-sandboxes [ <span class="Constant">local-scope</span> env:address:programming-environment-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - recipes:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, recipes:offset - current-sandbox:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, current-sandbox:offset + recipes:address:editor-data<span class="Special"> <- </span>get *env, recipes:offset + current-sandbox:address:editor-data<span class="Special"> <- </span>get *env, current-sandbox:offset <span class="Comment"># copy code from recipe editor, persist, load into mu, save any warnings</span> - in:address:array:character<span class="Special"> <- </span>editor-contents recipes:address:editor-data - save <span class="Constant">[recipes.mu]</span>, in:address:array:character - recipe-warnings:address:address:array:character<span class="Special"> <- </span>get-address env:address:programming-environment-data/deref, recipe-warnings:offset - recipe-warnings:address:address:array:character/deref<span class="Special"> <- </span>reload in:address:array:character + in:address:array:character<span class="Special"> <- </span>editor-contents recipes + save <span class="Constant">[recipes.mu]</span>, in + recipe-warnings:address:address:array:character<span class="Special"> <- </span>get-address *env, recipe-warnings:offset + *recipe-warnings<span class="Special"> <- </span>reload in <span class="Comment"># if recipe editor has errors, stop</span> - <span class="muControl">reply-if</span> recipe-warnings:address:address:array:character/deref + <span class="muControl">reply-if</span> *recipe-warnings <span class="Comment"># check contents of right editor (sandbox)</span> <span class="Delimiter">{</span> - sandbox-contents:address:array:character<span class="Special"> <- </span>editor-contents current-sandbox:address:editor-data - <span class="muControl">break-unless</span> sandbox-contents:address:array:character + sandbox-contents:address:array:character<span class="Special"> <- </span>editor-contents current-sandbox + <span class="muControl">break-unless</span> sandbox-contents <span class="Comment"># if contents exist, first save them</span> <span class="Comment"># run them and turn them into a new sandbox-data</span> new-sandbox:address:sandbox-data<span class="Special"> <- </span>new sandbox-data:type - data:address:address:array:character<span class="Special"> <- </span>get-address new-sandbox:address:sandbox-data/deref, data:offset - data:address:address:array:character/deref<span class="Special"> <- </span>copy sandbox-contents:address:array:character + data:address:address:array:character<span class="Special"> <- </span>get-address *new-sandbox, data:offset + *data<span class="Special"> <- </span>copy sandbox-contents <span class="Comment"># push to head of sandbox list</span> - dest:address:address:sandbox-data<span class="Special"> <- </span>get-address env:address:programming-environment-data/deref, sandbox:offset - next:address:address:sandbox-data<span class="Special"> <- </span>get-address new-sandbox:address:sandbox-data/deref, next-sandbox:offset - next:address:address:sandbox-data/deref<span class="Special"> <- </span>copy dest:address:address:sandbox-data/deref - dest:address:address:sandbox-data/deref<span class="Special"> <- </span>copy new-sandbox:address:sandbox-data + dest:address:address:sandbox-data<span class="Special"> <- </span>get-address *env, sandbox:offset + next:address:address:sandbox-data<span class="Special"> <- </span>get-address *new-sandbox, next-sandbox:offset + *next<span class="Special"> <- </span>copy *dest + *dest<span class="Special"> <- </span>copy new-sandbox <span class="Comment"># clear sandbox editor</span> - init:address:address:duplex-list<span class="Special"> <- </span>get-address current-sandbox:address:editor-data/deref, data:offset - init:address:address:duplex-list/deref<span class="Special"> <- </span>push-duplex <span class="Constant">167:literal/§</span>, <span class="Constant">0:literal/tail</span> + init:address:address:duplex-list<span class="Special"> <- </span>get-address *current-sandbox, data:offset + *init<span class="Special"> <- </span>push-duplex <span class="Constant">167/§</span>, <span class="Constant">0/tail</span> <span class="Delimiter">}</span> <span class="Comment"># save all sandboxes before running, just in case we die when running</span> - curr:address:sandbox-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, sandbox:offset - filename:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + <span class="Comment"># first clear previous versions, in case we deleted some sandbox</span> + $system <span class="Constant">[rm lesson/[0-9]</span>*] + curr:address:sandbox-data<span class="Special"> <- </span>get *env, sandbox:offset + filename:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> curr:address:sandbox-data - data:address:address:array:character<span class="Special"> <- </span>get-address curr:address:sandbox-data/deref, data:offset - save filename:number, data:address:address:array:character/deref - filename:number<span class="Special"> <- </span>add filename:number, <span class="Constant">1:literal</span> - curr:address:sandbox-data<span class="Special"> <- </span>get curr:address:sandbox-data/deref, next-sandbox:offset + <span class="muControl">break-unless</span> curr + data:address:address:array:character<span class="Special"> <- </span>get-address *curr, data:offset + save filename, *data + filename<span class="Special"> <- </span>add filename, <span class="Constant">1</span> + curr<span class="Special"> <- </span>get *curr, next-sandbox:offset <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># run all sandboxes</span> - curr:address:sandbox-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, sandbox:offset + curr<span class="Special"> <- </span>get *env, sandbox:offset <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> curr:address:sandbox-data - data:address:address:array:character<span class="Special"> <- </span>get-address curr:address:sandbox-data/deref, data:offset - response:address:address:array:character<span class="Special"> <- </span>get-address curr:address:sandbox-data/deref, response:offset - warnings:address:address:array:character<span class="Special"> <- </span>get-address curr:address:sandbox-data/deref, warnings:offset - fake-screen:address:address:screen<span class="Special"> <- </span>get-address curr:address:sandbox-data/deref, screen:offset - response:address:address:array:character/deref, warnings:address:address:array:character/deref, fake-screen:address:address:screen/deref<span class="Special"> <- </span>run-interactive data:address:address:array:character/deref -<span class="CommentedCode">#? $print warnings:address:address:array:character/deref, [ ], warnings:address:address:array:character/deref/deref, 10:literal/newline</span> - curr:address:sandbox-data<span class="Special"> <- </span>get curr:address:sandbox-data/deref, next-sandbox:offset + <span class="muControl">break-unless</span> curr + data<span class="Special"> <- </span>get-address *curr, data:offset + response:address:address:array:character<span class="Special"> <- </span>get-address *curr, response:offset + warnings:address:address:array:character<span class="Special"> <- </span>get-address *curr, warnings:offset + fake-screen:address:address:screen<span class="Special"> <- </span>get-address *curr, screen:offset + *response, *warnings, *fake-screen<span class="Special"> <- </span>run-interactive *data +<span class="CommentedCode">#? $print *warnings, [ ], **warnings, 10/newline</span> + curr<span class="Special"> <- </span>get *curr, next-sandbox:offset <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -2797,29 +2919,30 @@ container sandbox-data [ screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> env:address:programming-environment-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> clear:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - current-sandbox:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, current-sandbox:offset - left:number<span class="Special"> <- </span>get current-sandbox:address:editor-data/deref, left:offset - right:number<span class="Special"> <- </span>get current-sandbox:address:editor-data/deref, right:offset - row:number, screen:address<span class="Special"> <- </span>render screen:address, current-sandbox:address:editor-data - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - draw-horizontal screen:address, row:number, left:number, right:number, <span class="Constant">9473:literal/horizontal-double</span> - sandbox:address:sandbox-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, sandbox:offset - row:number, screen:address<span class="Special"> <- </span>render-sandboxes screen:address, sandbox:address:sandbox-data, left:number, right:number, row:number +<span class="CommentedCode">#? trace [app], [render sandbox side] #? 1</span> + current-sandbox:address:editor-data<span class="Special"> <- </span>get *env, current-sandbox:offset + left:number<span class="Special"> <- </span>get *current-sandbox, left:offset + right:number<span class="Special"> <- </span>get *current-sandbox, right:offset + row:number, screen<span class="Special"> <- </span>render screen, current-sandbox + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + draw-horizontal screen, row, left, right, <span class="Constant">9473/horizontal-double</span> + sandbox:address:sandbox-data<span class="Special"> <- </span>get *env, sandbox:offset + row, screen<span class="Special"> <- </span>render-sandboxes screen, sandbox, left, right, row <span class="Comment"># clear next line, in case we just processed a backspace</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - move-cursor screen:address, row:number, left:number - clear-line-delimited screen:address, left:number, right:number - <span class="muControl">reply-unless</span> clear:boolean, screen:address/same-as-ingredient:0 - screen-height:number<span class="Special"> <- </span>screen-height screen:address + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + move-cursor screen, row, left + clear-line-delimited screen, left, right + <span class="muControl">reply-unless</span> clear, screen/same-as-ingredient:<span class="Constant">0</span> + screen-height:number<span class="Special"> <- </span>screen-height screen <span class="Delimiter">{</span> - at-bottom-of-screen?:boolean<span class="Special"> <- </span>greater-or-equal row:number, screen-height:number - <span class="muControl">break-if</span> at-bottom-of-screen?:boolean - move-cursor screen:address, row:number, left:number - clear-line-delimited screen:address, left:number, right:number - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> + at-bottom-of-screen?:boolean<span class="Special"> <- </span>greater-or-equal row, screen-height + <span class="muControl">break-if</span> at-bottom-of-screen? + move-cursor screen, row, left + clear-line-delimited screen, left, right + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> screen:address/same-as-ingredient:0 + <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="muRecipe">recipe</span> render-sandboxes [ @@ -2829,49 +2952,48 @@ container sandbox-data [ left:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> right:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> row:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - <span class="muControl">reply-unless</span> sandbox:address:sandbox-data, row:number/same-as-ingredient:4, screen:address/same-as-ingredient:0 - screen-height:number<span class="Special"> <- </span>screen-height screen:address - at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row:number screen-height:number - <span class="muControl">reply-if</span> at-bottom?:boolean, row:number/same-as-ingredient:4, screen:address/same-as-ingredient:0 -<span class="CommentedCode">#? $print [rendering sandbox ], sandbox:address:sandbox-data, 10:literal/newline</span> + <span class="muControl">reply-unless</span> sandbox, row/same-as-ingredient:<span class="Constant">4</span>, screen/same-as-ingredient:<span class="Constant">0</span> + screen-height:number<span class="Special"> <- </span>screen-height screen + at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row, screen-height + <span class="muControl">reply-if</span> at-bottom?:boolean, row/same-as-ingredient:<span class="Constant">4</span>, screen/same-as-ingredient:<span class="Constant">0</span> <span class="Comment"># render sandbox menu</span> - row:number<span class="Special"> <- </span>add row:number, <span class="Constant">1:literal</span> - move-cursor screen:address, row:number, left:number - clear-line-delimited screen:address, left:number, right:number - print-character screen:address, <span class="Constant">120:literal/x</span>, <span class="Constant">245:literal/grey</span> + row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + move-cursor screen, row, left + clear-line-delimited screen, left, right + print-character screen, <span class="Constant">120/x</span>, <span class="Constant">245/grey</span> <span class="Comment"># save menu row so we can detect clicks to it later</span> - starting-row:address:number<span class="Special"> <- </span>get-address sandbox:address:sandbox-data/deref, starting-row-on-screen:offset - starting-row:address:number/deref<span class="Special"> <- </span>copy row:number + starting-row:address:number<span class="Special"> <- </span>get-address *sandbox, starting-row-on-screen:offset + *starting-row<span class="Special"> <- </span>copy row <span class="Comment"># render sandbox contents</span> - sandbox-data:address:array:character<span class="Special"> <- </span>get sandbox:address:sandbox-data/deref, data:offset - row:number, screen:address<span class="Special"> <- </span>render-string screen:address, sandbox-data:address:array:character, left:number, right:number, <span class="Constant">7:literal/white</span>, row:number + sandbox-data:address:array:character<span class="Special"> <- </span>get *sandbox, data:offset + row, screen<span class="Special"> <- </span>render-string screen, sandbox-data, left, right, <span class="Constant">7/white</span>, row <span class="Comment"># render sandbox warnings, screen or response, in that order</span> - sandbox-response:address:array:character<span class="Special"> <- </span>get sandbox:address:sandbox-data/deref, response:offset - sandbox-warnings:address:array:character<span class="Special"> <- </span>get sandbox:address:sandbox-data/deref, warnings:offset - sandbox-screen:address<span class="Special"> <- </span>get sandbox:address:sandbox-data/deref, screen:offset + sandbox-response:address:array:character<span class="Special"> <- </span>get *sandbox, response:offset + sandbox-warnings:address:array:character<span class="Special"> <- </span>get *sandbox, warnings:offset + sandbox-screen:address<span class="Special"> <- </span>get *sandbox, screen:offset <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> sandbox-warnings:address:array:character - row:number, screen:address<span class="Special"> <- </span>render-string screen:address, sandbox-warnings:address:array:character, left:number, right:number, <span class="Constant">1:literal/red</span>, row:number + <span class="muControl">break-unless</span> sandbox-warnings + row, screen<span class="Special"> <- </span>render-string screen, sandbox-warnings, left, right, <span class="Constant">1/red</span>, row <span class="Delimiter">}</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> sandbox-warnings:address:array:character - empty-screen?:boolean<span class="Special"> <- </span>fake-screen-is-clear? sandbox-screen:address - <span class="muControl">break-if</span> empty-screen?:boolean - row:number, screen:address<span class="Special"> <- </span>render-screen screen:address, sandbox-screen:address, left:number, right:number, row:number + <span class="muControl">break-if</span> sandbox-warnings + empty-screen?:boolean<span class="Special"> <- </span>fake-screen-is-empty? sandbox-screen + <span class="muControl">break-if</span> empty-screen? + row, screen<span class="Special"> <- </span>render-screen screen, sandbox-screen, left, right, row <span class="Delimiter">}</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> sandbox-warnings:address:array:character - <span class="muControl">break-unless</span> empty-screen?:boolean - row:number, screen:address<span class="Special"> <- </span>render-string screen:address, sandbox-response:address:array:character, left:number, right:number, <span class="Constant">245:literal/grey</span>, row:number + <span class="muControl">break-if</span> sandbox-warnings + <span class="muControl">break-unless</span> empty-screen? + row, screen<span class="Special"> <- </span>render-string screen, sandbox-response, left, right, <span class="Constant">245/grey</span>, row <span class="Delimiter">}</span> - at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row:number screen-height:number - <span class="muControl">reply-if</span> at-bottom?:boolean, row:number/same-as-ingredient:4, screen:address/same-as-ingredient:0 + at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal row, screen-height + <span class="muControl">reply-if</span> at-bottom?, row/same-as-ingredient:<span class="Constant">4</span>, screen/same-as-ingredient:<span class="Constant">0</span> <span class="Comment"># draw solid line after sandbox</span> - draw-horizontal screen:address, row:number, left:number, right:number, <span class="Constant">9473:literal/horizontal-double</span> + draw-horizontal screen, row, left, right, <span class="Constant">9473/horizontal-double</span> <span class="Comment"># draw next sandbox</span> - next-sandbox:address:sandbox-data<span class="Special"> <- </span>get sandbox:address:sandbox-data/deref, next-sandbox:offset - row:number, screen:address<span class="Special"> <- </span>render-sandboxes screen:address, next-sandbox:address:sandbox-data, left:number, right:number, row:number - <span class="muControl">reply</span> row:number/same-as-ingredient:4, screen:address/same-as-ingredient:0 + next-sandbox:address:sandbox-data<span class="Special"> <- </span>get *sandbox, next-sandbox:offset + row, screen<span class="Special"> <- </span>render-sandboxes screen, next-sandbox, left, right, row + <span class="muControl">reply</span> row/same-as-ingredient:<span class="Constant">4</span>, screen/same-as-ingredient:<span class="Constant">0</span> ] <span class="Comment"># assumes programming environment has no sandboxes; restores them from previous session</span> @@ -2879,22 +3001,21 @@ container sandbox-data [ <span class="Constant">local-scope</span> env:address:programming-environment-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># read all scenarios, pushing them to end of a list of scenarios</span> - filename:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> - curr:address:address:sandbox-data<span class="Special"> <- </span>get-address env:address:programming-environment-data/deref, sandbox:offset + filename:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + curr:address:address:sandbox-data<span class="Special"> <- </span>get-address *env, sandbox:offset <span class="Delimiter">{</span> - contents:address:array:character<span class="Special"> <- </span>restore filename:number - <span class="muControl">break-unless</span> contents:address:array:character <span class="Comment"># stop at first error; assuming file didn't exist</span> -<span class="CommentedCode">#? $print contents:address:array:character, 10:literal/newline</span> + contents:address:array:character<span class="Special"> <- </span>restore filename + <span class="muControl">break-unless</span> contents <span class="Comment"># stop at first error; assuming file didn't exist</span> <span class="Comment"># create new sandbox for file</span> - curr:address:address:sandbox-data/deref<span class="Special"> <- </span>new sandbox-data:type - data:address:address:array:character<span class="Special"> <- </span>get-address curr:address:address:sandbox-data/deref/deref, data:offset - data:address:address:array:character/deref<span class="Special"> <- </span>copy contents:address:array:character + *curr<span class="Special"> <- </span>new sandbox-data:type + data:address:address:array:character<span class="Special"> <- </span>get-address **curr, data:offset + *data<span class="Special"> <- </span>copy contents <span class="Comment"># increment loop variables</span> - filename:number<span class="Special"> <- </span>add filename:number, <span class="Constant">1:literal</span> - curr:address:address:sandbox-data<span class="Special"> <- </span>get-address curr:address:address:sandbox-data/deref/deref, next-sandbox:offset + filename<span class="Special"> <- </span>add filename, <span class="Constant">1</span> + curr<span class="Special"> <- </span>get-address **curr, next-sandbox:offset <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> env:address:programming-environment-data/same-as-ingredient:0 + <span class="muControl">reply</span> env/same-as-ingredient:<span class="Constant">0</span> ] <span class="Comment"># was-deleted?:boolean <- delete-sandbox t:touch-event, env:address:programming-environment-data</span> @@ -2902,69 +3023,56 @@ container sandbox-data [ <span class="Constant">local-scope</span> t:touch-event<span class="Special"> <- </span><span class="Constant">next-ingredient</span> env:address:programming-environment-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - click-column:number<span class="Special"> <- </span>get t:touch-event, column:offset - current-sandbox:address:editor-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, current-sandbox:offset - right:number<span class="Special"> <- </span>get current-sandbox:address:editor-data/deref, right:offset -<span class="CommentedCode">#? $print [comparing column ], click-column:number, [ vs ], right:number, 10:literal/newline</span> - at-right?:boolean<span class="Special"> <- </span>equal click-column:number, right:number - <span class="muControl">reply-unless</span> at-right?:boolean, <span class="Constant">0:literal/false</span> -<span class="CommentedCode">#? $print [trying to delete</span> -<span class="CommentedCode">#? ] #? 1</span> - click-row:number<span class="Special"> <- </span>get t:touch-event, row:offset - prev:address:address:sandbox-data<span class="Special"> <- </span>get-address env:address:programming-environment-data/deref, sandbox:offset -<span class="CommentedCode">#? $print [prev: ], prev:address:address:sandbox-data, [ -> ], prev:address:address:sandbox-data/deref, 10:literal/newline</span> - curr:address:sandbox-data<span class="Special"> <- </span>get env:address:programming-environment-data/deref, sandbox:offset + click-column:number<span class="Special"> <- </span>get t, column:offset + current-sandbox:address:editor-data<span class="Special"> <- </span>get *env, current-sandbox:offset + right:number<span class="Special"> <- </span>get *current-sandbox, right:offset + at-right?:boolean<span class="Special"> <- </span>equal click-column, right + <span class="muControl">reply-unless</span> at-right?, <span class="Constant">0/false</span> + click-row:number<span class="Special"> <- </span>get t, row:offset + prev:address:address:sandbox-data<span class="Special"> <- </span>get-address *env, sandbox:offset + curr:address:sandbox-data<span class="Special"> <- </span>get *env, sandbox:offset <span class="Delimiter">{</span> -<span class="CommentedCode">#? $print [next sandbox</span> -<span class="CommentedCode">#? ] #? 1</span> - <span class="muControl">break-unless</span> curr:address:sandbox-data + <span class="muControl">break-unless</span> curr <span class="Comment"># more sandboxes to check</span> <span class="Delimiter">{</span> -<span class="CommentedCode">#? $print [checking</span> -<span class="CommentedCode">#? ] #? 1</span> - target-row:number<span class="Special"> <- </span>get curr:address:sandbox-data/deref, starting-row-on-screen:offset -<span class="CommentedCode">#? $print [comparing row ], target-row:number, [ vs ], click-row:number, 10:literal/newline</span> - delete-curr?:boolean<span class="Special"> <- </span>equal target-row:number, click-row:number - <span class="muControl">break-unless</span> delete-curr?:boolean -<span class="CommentedCode">#? $print [found!</span> -<span class="CommentedCode">#? ] #? 1</span> + target-row:number<span class="Special"> <- </span>get *curr, starting-row-on-screen:offset + delete-curr?:boolean<span class="Special"> <- </span>equal target-row, click-row + <span class="muControl">break-unless</span> delete-curr? <span class="Comment"># delete this sandbox, rerender and stop</span> - prev:address:address:sandbox-data/deref<span class="Special"> <- </span>get curr:address:sandbox-data/deref, next-sandbox:offset -<span class="CommentedCode">#? $print [setting prev: ], prev:address:address:sandbox-data, [ -> ], prev:address:address:sandbox-data/deref, 10:literal/newline</span> - <span class="muControl">reply</span> <span class="Constant">1:literal/true</span> + *prev<span class="Special"> <- </span>get *curr, next-sandbox:offset + <span class="muControl">reply</span> <span class="Constant">1/true</span> <span class="Delimiter">}</span> - prev:address:address:sandbox-data<span class="Special"> <- </span>get-address curr:address:sandbox-data/deref, next-sandbox:offset -<span class="CommentedCode">#? $print [prev: ], prev:address:address:sandbox-data, [ -> ], prev:address:address:sandbox-data/deref, 10:literal/newline</span> - curr:address:sandbox-data<span class="Special"> <- </span>get curr:address:sandbox-data/deref, next-sandbox:offset + prev<span class="Special"> <- </span>get-address *curr, next-sandbox:offset + curr<span class="Special"> <- </span>get *curr, next-sandbox:offset <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">reply</span> <span class="Constant">0:literal/false</span> + <span class="muControl">reply</span> <span class="Constant">0/false</span> ] <span class="muScenario">scenario</span> run-updates-results [ $close-trace <span class="Comment"># trace too long for github</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">12:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">12/height</span> <span class="Comment"># define a recipe (no indent for the 'add' line below so column numbers are more obvious)</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> -<span class="Constant">z:number <- add 2:literal, 2:literal</span> +<span class="Constant">z:number <- add 2, 2</span> <span class="Constant">]</span>] <span class="Comment"># sandbox editor contains an instruction without storing outputs</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[foo]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[foo]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character <span class="Comment"># run the code in the editors</span> assume-console [ - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] <span class="Comment"># check that screen prints the results</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> - <span class="Constant"> .z:number <- add 2:literal, 2:literal ┊ x.</span> + <span class="Constant"> .z:number <- add 2, 2 ┊ x.</span> <span class="Constant"> .] ┊foo .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4 .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> @@ -2972,21 +3080,21 @@ container sandbox-data [ ] <span class="Comment"># make a change (incrementing one of the args to 'add'), then rerun</span> assume-console [ - left-click 3, 28 <span class="Comment"># one past the value of the second arg</span> + left-click <span class="Constant">3</span>, <span class="Constant">28</span> <span class="Comment"># one past the value of the second arg</span> type <span class="Constant">[«3]</span> <span class="Comment"># replace</span> - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] - 4:event/backspace<span class="Special"> <- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span> - replace-in-console <span class="Constant">171:literal/«</span>, 4:event/backspace + <span class="Constant">4</span>:event/backspace<span class="Special"> <- </span>merge <span class="Constant">0/text</span>, <span class="Constant">8/backspace</span>, <span class="Constant">0/dummy</span>, <span class="Constant">0/dummy</span> + replace-in-console <span class="Constant">171/«</span>, <span class="Constant">4</span>:event/backspace run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] <span class="Comment"># check that screen updates the result on the right</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> - <span class="Constant"> .z:number <- add 2:literal, 3:literal ┊ x.</span> + <span class="Constant"> .z:number <- add 2, 3 ┊ x.</span> <span class="Constant"> .] ┊foo .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊5 .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> @@ -2996,22 +3104,22 @@ container sandbox-data [ <span class="muScenario">scenario</span> run-instruction-and-print-warnings [ $close-trace <span class="Comment"># trace too long for github</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">10:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># left editor is empty</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> <span class="Comment"># right editor contains an illegal instruction</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[get 1234:number, foo:offset]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[get 1234:number, foo:offset]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character <span class="Comment"># run the code in the editors</span> assume-console [ - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] <span class="Comment"># check that screen prints error message in red</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> @@ -3020,7 +3128,7 @@ container sandbox-data [ <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> ] - screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [ + screen-should-contain-in-color <span class="Constant">7/white</span>, [ <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> @@ -3030,7 +3138,7 @@ container sandbox-data [ <span class="Constant"> . .</span> <span class="Constant"> . .</span> ] - screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [ + screen-should-contain-in-color <span class="Constant">1/red</span>, [ <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> @@ -3039,7 +3147,7 @@ container sandbox-data [ <span class="Constant"> . unknown element foo in container number .</span> <span class="Constant"> . .</span> ] - screen-should-contain-in-color <span class="Constant">245:literal/grey</span>, [ + screen-should-contain-in-color <span class="Constant">245/grey</span>, [ <span class="Constant"> . .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> @@ -3053,23 +3161,23 @@ container sandbox-data [ <span class="muScenario">scenario</span> run-instruction-and-print-warnings-only-once [ $close-trace <span class="Comment"># trace too long for github</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">10:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># left editor is empty</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> <span class="Comment"># right editor contains an illegal instruction</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[get 1234:number, foo:offset]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[get 1234:number, foo:offset]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character <span class="Comment"># run the code in the editors multiple times</span> assume-console [ - press 65526 <span class="Comment"># F10</span> - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] <span class="Comment"># check that screen prints error message just once</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> @@ -3082,31 +3190,31 @@ container sandbox-data [ <span class="muScenario">scenario</span> deleting-sandboxes [ $close-trace <span class="Comment"># trace too long for github</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">15:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character <span class="Comment"># run a few commands</span> assume-console [ - left-click 1, 80 - type <span class="Constant">[divide-with-remainder 11:literal, 3:literal]</span> - press 65526 <span class="Comment"># F10</span> - type <span class="Constant">[add 2:literal, 2:literal]</span> - press 65526 <span class="Comment"># F10</span> + left-click <span class="Constant">1</span>, <span class="Constant">80</span> + type <span class="Constant">[divide-with-remainder 11, 3]</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> + type <span class="Constant">[add 2, 2]</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> - <span class="Constant"> . ┊add 2:literal, 2:literal .</span> + <span class="Constant"> . ┊add 2, 2 .</span> <span class="Constant"> . ┊4 .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> - <span class="Constant"> . ┊divide-with-remainder 11:literal, 3:literal .</span> + <span class="Constant"> . ┊divide-with-remainder 11, 3 .</span> <span class="Constant"> . ┊3 .</span> <span class="Constant"> . ┊2 .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> @@ -3114,17 +3222,17 @@ container sandbox-data [ ] <span class="Comment"># delete second sandbox</span> assume-console [ - left-click 7, 99 + left-click <span class="Constant">7</span>, <span class="Constant">99</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> - <span class="Constant"> . ┊add 2:literal, 2:literal .</span> + <span class="Constant"> . ┊add 2, 2 .</span> <span class="Constant"> . ┊4 .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> @@ -3132,13 +3240,13 @@ container sandbox-data [ ] <span class="Comment"># delete first sandbox</span> assume-console [ - left-click 3, 99 + left-click <span class="Constant">3</span>, <span class="Constant">99</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> @@ -3148,33 +3256,33 @@ container sandbox-data [ <span class="muScenario">scenario</span> run-instruction-manages-screen-per-sandbox [ $close-trace <span class="Comment"># trace too long for github #? 1</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">20:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">20/height</span> <span class="Comment"># left editor is empty</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[]</span> <span class="Comment"># right editor contains an illegal instruction</span> - 2:address:array:character<span class="Special"> <- </span>new <span class="Constant">[print-integer screen:address, 4]</span> - 3:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + <span class="Constant">2</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[print-integer screen:address, 4]</span> + <span class="Constant">3</span>:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, <span class="Constant">1</span>:address:array:character, <span class="Constant">2</span>:address:array:character <span class="Comment"># run the code in the editor</span> assume-console [ - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ - event-loop screen:address, console:address, 3:address:programming-environment-data + event-loop screen:address, console:address, <span class="Constant">3</span>:address:programming-environment-data ] <span class="Comment"># check that it prints a little 5x5 toy screen</span> <span class="Comment"># hack: screen address is brittle</span> screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ x.</span> <span class="Constant"> . ┊print-integer screen:address, 4 .</span> <span class="Constant"> . ┊screen: .</span> - <span class="Constant"> . ┊ .4 . .</span> - <span class="Constant"> . ┊ . . .</span> - <span class="Constant"> . ┊ . . .</span> - <span class="Constant"> . ┊ . . .</span> - <span class="Constant"> . ┊ . . .</span> + <span class="Constant"> . ┊ .4 . .</span> + <span class="Constant"> . ┊ . . .</span> + <span class="Constant"> . ┊ . . .</span> + <span class="Constant"> . ┊ . . .</span> + <span class="Constant"> . ┊ . . .</span> <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> ] @@ -3183,38 +3291,38 @@ container sandbox-data [ <span class="muRecipe">recipe</span> editor-contents [ <span class="Constant">local-scope</span> editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - buf:address:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">80:literal</span> - curr:address:duplex-list<span class="Special"> <- </span>get editor:address:editor-data/deref, data:offset + buf:address:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">80</span> + curr:address:duplex-list<span class="Special"> <- </span>get *editor, data:offset <span class="Comment"># skip § sentinel</span> - assert curr:address:duplex-list, <span class="Constant">[editor without data is illegal; must have at least a sentinel]</span> - curr:address:duplex-list<span class="Special"> <- </span>next-duplex curr:address:duplex-list - <span class="muControl">reply-unless</span> curr:address:duplex-list, <span class="Constant">0:literal</span> + assert curr, <span class="Constant">[editor without data is illegal; must have at least a sentinel]</span> + curr<span class="Special"> <- </span>next-duplex curr + <span class="muControl">reply-unless</span> curr, <span class="Constant">0</span> <span class="Delimiter">{</span> - <span class="muControl">break-unless</span> curr:address:duplex-list - c:character<span class="Special"> <- </span>get curr:address:duplex-list/deref, value:offset - buffer-append buf:address:buffer, c:character - curr:address:duplex-list<span class="Special"> <- </span>next-duplex curr:address:duplex-list + <span class="muControl">break-unless</span> curr + c:character<span class="Special"> <- </span>get *curr, value:offset + buffer-append buf, c + curr<span class="Special"> <- </span>next-duplex curr <span class="muControl">loop</span> <span class="Delimiter">}</span> - result:address:array:character<span class="Special"> <- </span>buffer-to-array buf:address:buffer - <span class="muControl">reply</span> result:address:array:character + result:address:array:character<span class="Special"> <- </span>buffer-to-array buf + <span class="muControl">reply</span> result ] <span class="muScenario">scenario</span> editor-provides-edited-contents [ - assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span> - 1:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - 2:address:editor-data<span class="Special"> <- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/left</span>, <span class="Constant">10:literal/right</span> + assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> + <span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + <span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click 1, 2 + left-click <span class="Constant">1</span>, <span class="Constant">2</span> type <span class="Constant">[def]</span> ] run [ - editor-event-loop screen:address, console:address, 2:address:editor-data - 3:address:array:character<span class="Special"> <- </span>editor-contents 2:address:editor-data - 4:array:character<span class="Special"> <- </span>copy 3:address:array:character/deref + editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data + <span class="Constant">3</span>:address:array:character<span class="Special"> <- </span>editor-contents <span class="Constant">2</span>:address:editor-data + <span class="Constant">4</span>:array:character<span class="Special"> <- </span>copy *<span class="Constant">3</span>:address:array:character ] memory-should-contain [ - 4:string<span class="Special"> <- </span><span class="Constant">[abdefc]</span> + <span class="Constant">4</span>:string<span class="Special"> <- </span><span class="Constant">[abdefc]</span> ] ] @@ -3222,9 +3330,9 @@ container sandbox-data [ <span class="muScenario">scenario</span> run-shows-warnings-in-get [ <span class="Constant"> $close-trace</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">15:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> assume-console [ - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> @@ -3236,7 +3344,7 @@ container sandbox-data [ event-loop screen:address, console:address, env:address:programming-environment-data ] screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊foo .</span> <span class="Constant"> .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . get 123:number, foo:offset ┊ .</span> @@ -3245,7 +3353,7 @@ container sandbox-data [ <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .</span> <span class="Constant"> . ┊ .</span> ] - screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [ + screen-should-contain-in-color <span class="Constant">1/red</span>, [ <span class="Constant"> . .</span> <span class="Constant"> . .</span> <span class="Constant"> . .</span> @@ -3258,28 +3366,26 @@ container sandbox-data [ <span class="muScenario">scenario</span> run-shows-missing-type-warnings [ <span class="Constant"> $close-trace</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">15:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> assume-console [ - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> -<span class="Constant"> x:number <- copy 0</span> -<span class="Constant"> copy x</span> +<span class="Constant"> x <- copy 0</span> <span class="Constant">]</span>] y:address:array:character<span class="Special"> <- </span>new <span class="Constant">[foo]</span> env:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, x:address:array:character, y:address:array:character event-loop screen:address, console:address, env:address:programming-environment-data ] screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊foo .</span> <span class="Constant"> .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> - <span class="Constant"> . x:number <- copy 0 ┊ .</span> - <span class="Constant"> . copy x ┊ .</span> + <span class="Constant"> . x <- copy 0 ┊ .</span> <span class="Constant"> .] ┊ .</span> - <span class="Constant"> .missing type in 'copy x' ┊ .</span> + <span class="Constant"> .missing type in 'x <- copy 0' ┊ .</span> <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .</span> <span class="Constant"> . ┊ .</span> ] @@ -3287,9 +3393,9 @@ container sandbox-data [ <span class="muScenario">scenario</span> run-shows-get-on-non-container-warnings [ <span class="Constant"> $close-trace</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">15:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> assume-console [ - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> @@ -3302,41 +3408,42 @@ container sandbox-data [ event-loop screen:address, console:address, env:address:programming-environment-data ] screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊ .</span> <span class="Constant"> .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . x:address:point <- new point:type ┊ x.</span> <span class="Constant"> . get x:address:point, 1:offset ┊foo .</span> - <span class="Constant"> .] ┊foo: 'get' on a non-container x:address:point .</span> -<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> + <span class="Constant"> .] ┊foo: first ingredient of 'get' should be a conta↩.</span> + <span class="Constant"> .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊iner, but got x:address:point .</span> + <span class="Constant"> . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . ┊ .</span> ] ] <span class="muScenario">scenario</span> run-shows-non-literal-get-argument-warnings [ <span class="Constant"> $close-trace</span> - assume-screen <span class="Constant">100:literal/width</span>, <span class="Constant">15:literal/height</span> + assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> assume-console [ - press 65526 <span class="Comment"># F10</span> + press <span class="Constant">65532</span> <span class="Comment"># F4</span> ] run [ x:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> x:number <- copy 0</span> <span class="Constant"> y:address:point <- new point:type</span> -<span class="Constant"> get y:address:point/deref, x:number</span> +<span class="Constant"> get *y:address:point, x:number</span> <span class="Constant">]</span>] y:address:array:character<span class="Special"> <- </span>new <span class="Constant">[foo]</span> env:address:programming-environment-data<span class="Special"> <- </span>new-programming-environment screen:address, x:address:array:character, y:address:array:character event-loop screen:address, console:address, env:address:programming-environment-data ] screen-should-contain [ - <span class="Constant"> . run (F10) .</span> + <span class="Constant"> . run (F4) .</span> <span class="Constant"> . ┊foo .</span> <span class="Constant"> .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.</span> <span class="Constant"> . x:number <- copy 0 ┊ .</span> <span class="Constant"> . y:address:point <- new point:type ┊ .</span> - <span class="Constant"> . get y:address:point/deref, x:number ┊ .</span> + <span class="Constant"> . get *y:address:point, x:number ┊ .</span> <span class="Constant"> .] ┊ .</span> <span class="Constant"> .foo: expected ingredient 1 of 'get' to have type ↩┊ .</span> <span class="Constant"> .'offset'; got x:number ┊ .</span> @@ -3357,22 +3464,22 @@ container sandbox-data [ color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">245:literal/grey</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> <span class="Comment"># top border</span> - draw-horizontal screen:address, top:number, left:number, right:number, color:number - draw-horizontal screen:address, bottom:number, left:number, right:number, color:number - draw-vertical screen:address, left:number, top:number, bottom:number, color:number - draw-vertical screen:address, right:number, top:number, bottom:number, color:number - draw-top-left screen:address, top:number, left:number, color:number - draw-top-right screen:address, top:number, right:number, color:number - draw-bottom-left screen:address, bottom:number, left:number, color:number - draw-bottom-right screen:address, bottom:number, right:number, color:number + draw-horizontal screen, top, left, right, color + draw-horizontal screen, bottom, left, right, color + draw-vertical screen, left, top, bottom, color + draw-vertical screen, right, top, bottom, color + draw-top-left screen, top, left, color + draw-top-right screen, top, right, color + draw-bottom-left screen, bottom, left, color + draw-bottom-right screen, bottom, right, color <span class="Comment"># position cursor inside box</span> - move-cursor screen:address, top:number, left:number - cursor-down screen:address - cursor-right screen:address + move-cursor screen, top, left + cursor-down screen + cursor-right screen ] <span class="muRecipe">recipe</span> draw-horizontal [ @@ -3383,26 +3490,26 @@ container sandbox-data [ right:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> style:character, style-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> style-found?:boolean - style:character<span class="Special"> <- </span>copy <span class="Constant">9472:literal/horizontal</span> + <span class="muControl">break-if</span> style-found? + style<span class="Special"> <- </span>copy <span class="Constant">9472/horizontal</span> <span class="Delimiter">}</span> color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">245:literal/grey</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> bg-color-found?:boolean - bg-color:number<span class="Special"> <- </span>copy <span class="Constant">0:literal/black</span> + bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> - move-cursor screen:address, row:number, x:number + move-cursor screen, row, x <span class="Delimiter">{</span> - continue?:boolean<span class="Special"> <- </span>lesser-or-equal x:number, right:number <span class="Comment"># right is inclusive, to match editor-data semantics</span> - <span class="muControl">break-unless</span> continue?:boolean - print-character screen:address, style:character, color:number, bg-color:number - x:number<span class="Special"> <- </span>add x:number, <span class="Constant">1:literal</span> + continue?:boolean<span class="Special"> <- </span>lesser-or-equal x, right <span class="Comment"># right is inclusive, to match editor-data semantics</span> + <span class="muControl">break-unless</span> continue? + print-character screen, style, color, bg-color + x<span class="Special"> <- </span>add x, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -3411,25 +3518,25 @@ container sandbox-data [ <span class="Constant">local-scope</span> screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> col:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - x:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + y:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> bottom:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> style:character, style-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> style-found?:boolean - style:character<span class="Special"> <- </span>copy <span class="Constant">9474:literal/vertical</span> + <span class="muControl">break-if</span> style-found? + style<span class="Special"> <- </span>copy <span class="Constant">9474/vertical</span> <span class="Delimiter">}</span> color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">245:literal/grey</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> - continue?:boolean<span class="Special"> <- </span>lesser-than x:number, bottom:number - <span class="muControl">break-unless</span> continue?:boolean - move-cursor screen:address, x:number, col:number - print-character screen:address, style:character, color:number - x:number<span class="Special"> <- </span>add x:number, <span class="Constant">1:literal</span> + continue?:boolean<span class="Special"> <- </span>lesser-than y, bottom + <span class="muControl">break-unless</span> continue? + move-cursor screen, y, col + print-character screen, style, color + y<span class="Special"> <- </span>add y, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -3442,11 +3549,11 @@ container sandbox-data [ color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">245:literal/grey</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> - move-cursor screen:address, top:number, left:number - print-character screen:address, <span class="Constant">9484:literal/down-right</span>, color:number + move-cursor screen, top, left + print-character screen, <span class="Constant">9484/down-right</span>, color ] <span class="muRecipe">recipe</span> draw-top-right [ @@ -3457,11 +3564,11 @@ container sandbox-data [ color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">245:literal/grey</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> - move-cursor screen:address, top:number, right:number - print-character screen:address, <span class="Constant">9488:literal/down-left</span>, color:number + move-cursor screen, top, right + print-character screen, <span class="Constant">9488/down-left</span>, color ] <span class="muRecipe">recipe</span> draw-bottom-left [ @@ -3472,11 +3579,11 @@ container sandbox-data [ color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">245:literal/grey</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> - move-cursor screen:address, bottom:number, left:number - print-character screen:address, <span class="Constant">9492:literal/up-right</span>, color:number + move-cursor screen, bottom, left + print-character screen, <span class="Constant">9492/up-right</span>, color ] <span class="muRecipe">recipe</span> draw-bottom-right [ @@ -3487,40 +3594,35 @@ container sandbox-data [ color:number, color-found?:boolean<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default color to white</span> - <span class="muControl">break-if</span> color-found?:boolean - color:number<span class="Special"> <- </span>copy <span class="Constant">245:literal/grey</span> + <span class="muControl">break-if</span> color-found? + color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> - move-cursor screen:address, bottom:number, right:number - print-character screen:address, <span class="Constant">9496:literal/up-left</span>, color:number + move-cursor screen, bottom, right + print-character screen, <span class="Constant">9496/up-left</span>, color ] <span class="muRecipe">recipe</span> print-string-with-gradient-background [ <span class="Constant">local-scope</span> - x:address:screen<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span> s:address:array:character<span class="Special"> <- </span><span class="Constant">next-ingredient</span> color:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> bg-color1:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> bg-color2:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> - len:number<span class="Special"> <- </span>length s:address:array:character/deref - color-range:number<span class="Special"> <- </span>subtract bg-color2:number, bg-color1:number - color-quantum:number<span class="Special"> <- </span>divide color-range:number, len:number -<span class="CommentedCode">#? close-console #? 2</span> -<span class="CommentedCode">#? $print len:number, [, ], color-range:number, [, ], color-quantum:number, 10:literal/newline</span> -<span class="CommentedCode">#? #? $exit #? 3</span> - bg-color:number<span class="Special"> <- </span>copy bg-color1:number - i:number<span class="Special"> <- </span>copy <span class="Constant">0:literal</span> + len:number<span class="Special"> <- </span>length *s + color-range:number<span class="Special"> <- </span>subtract bg-color2, bg-color1 + color-quantum:number<span class="Special"> <- </span>divide color-range, len + bg-color:number<span class="Special"> <- </span>copy bg-color1 + i:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> - done?:boolean<span class="Special"> <- </span>greater-or-equal i:number, len:number - <span class="muControl">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, color:number, bg-color:number - i:number<span class="Special"> <- </span>add i:number, <span class="Constant">1:literal</span> - bg-color:number<span class="Special"> <- </span>add bg-color:number, color-quantum:number -<span class="CommentedCode">#? $print [=> ], bg-color:number, 10:literal/newline</span> + done?:boolean<span class="Special"> <- </span>greater-or-equal i, len + <span class="muControl">break-if</span> done? + c:character<span class="Special"> <- </span>index *s, i + print-character screen, c, color, bg-color + i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + bg-color<span class="Special"> <- </span>add bg-color, color-quantum <span class="muControl">loop</span> <span class="Delimiter">}</span> -<span class="CommentedCode">#? $exit #? 1</span> - <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0 + <span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span> ] </pre> </body> diff --git a/html/factorial.mu.html b/html/factorial.mu.html index 54a70688..8cdc3ef6 100644 --- a/html/factorial.mu.html +++ b/html/factorial.mu.html @@ -13,13 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.muScenario { color: #00af00; } +.muRecipe { color: #ff8700; } .Delimiter { color: #a04060; } +.muScenario { color: #00af00; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -35,8 +35,8 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">recipe</span> main [ <span class="Constant">local-scope</span> - x:number<span class="Special"> <- </span>factorial <span class="Constant">5:literal</span> - $print <span class="Constant">[result: ]</span>, x:number, <span class="Constant">[ </span> + x:number<span class="Special"> <- </span>factorial <span class="Constant">5</span> + $print <span class="Constant">[result: ]</span>, x, <span class="Constant">[ </span> <span class="Constant">]</span> ] @@ -45,24 +45,24 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } n:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># if n=0 return 1</span> - zero?:boolean<span class="Special"> <- </span>equal n:number, <span class="Constant">0:literal</span> - <span class="muControl">break-unless</span> zero?:boolean - <span class="muControl">reply</span> <span class="Constant">1:literal</span> + zero?:boolean<span class="Special"> <- </span>equal n, <span class="Constant">0</span> + <span class="muControl">break-unless</span> zero? + <span class="muControl">reply</span> <span class="Constant">1</span> <span class="Delimiter">}</span> <span class="Comment"># return n * factorial(n-1)</span> - x:number<span class="Special"> <- </span>subtract n:number, <span class="Constant">1:literal</span> - subresult:number<span class="Special"> <- </span>factorial x:number - result:number<span class="Special"> <- </span>multiply subresult:number, n:number - <span class="muControl">reply</span> result:number + x:number<span class="Special"> <- </span>subtract n, <span class="Constant">1</span> + subresult:number<span class="Special"> <- </span>factorial x + result:number<span class="Special"> <- </span>multiply subresult, n + <span class="muControl">reply</span> result ] <span class="Comment"># unit test</span> <span class="muScenario">scenario</span> factorial-test [ run [ - 1:number<span class="Special"> <- </span>factorial <span class="Constant">5:literal</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>factorial <span class="Constant">5</span> ] memory-should-contain [ - 1<span class="Special"> <- </span>120 + <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">120</span> ] ] </pre> diff --git a/html/factorial.png b/html/factorial.png index 19249bbe..93b63e8a 100644 --- a/html/factorial.png +++ b/html/factorial.png Binary files differdiff --git a/html/fork.mu.html b/html/fork.mu.html index 4d6b367c..3f47e9a2 100644 --- a/html/fork.mu.html +++ b/html/fork.mu.html @@ -13,11 +13,11 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Constant { color: #00a0a0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -34,14 +34,14 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">recipe</span> main [ start-running thread2:<span class="muRecipe">recipe</span> <span class="Delimiter">{</span> - $print <span class="Constant">34:literal</span> + $print <span class="Constant">34</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muRecipe">recipe</span> thread2 [ <span class="Delimiter">{</span> - $print <span class="Constant">35:literal</span> + $print <span class="Constant">35</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] diff --git a/html/global.mu.html b/html/global.mu.html index aa060d5a..812e3a35 100644 --- a/html/global.mu.html +++ b/html/global.mu.html @@ -13,10 +13,10 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } -.muRecipe { color: #ff8700; } --> </style> @@ -32,9 +32,9 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">recipe</span> main [ <span class="Comment"># allocate 5 locations for globals</span> - <span class="Constant">global-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">5:literal</span> + <span class="Constant">global-space</span>:address:array:location<span class="Special"> <- </span>new location:type, <span class="Constant">5</span> <span class="Comment"># read to globals by using /space:global</span> - <span class="Special">1:number/space:global</span><span class="Special"> <- </span>copy <span class="Constant">3:literal</span> + <span class="Special">1:number/space:global</span><span class="Special"> <- </span>copy <span class="Constant">3</span> foo ] diff --git a/html/screen.mu.html b/html/screen.mu.html index 4618548a..6efea923 100644 --- a/html/screen.mu.html +++ b/html/screen.mu.html @@ -13,10 +13,10 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } -.muRecipe { color: #ff8700; } --> </style> @@ -35,24 +35,24 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">recipe</span> main [ open-console - print-character <span class="Constant">0:literal/screen</span>, <span class="Constant">97:literal</span>, <span class="Constant">2:literal/red</span> - 1:number/<span class="Special">raw</span>, 2:number/<span class="Special">raw <- </span>cursor-position <span class="Constant">0:literal/screen</span> - wait-for-event <span class="Constant">0:literal/console</span> - clear-screen <span class="Constant">0:literal/screen</span> - move-cursor <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal/row</span>, <span class="Constant">4:literal/column</span> - print-character <span class="Constant">0:literal/screen</span>, <span class="Constant">98:literal</span> - wait-for-event <span class="Constant">0:literal/console</span> - move-cursor <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal/row</span>, <span class="Constant">0:literal/column</span> - clear-line <span class="Constant">0:literal/screen</span> - wait-for-event <span class="Constant">0:literal/console</span> - cursor-down <span class="Constant">0:literal/screen</span> - wait-for-event <span class="Constant">0:literal/console</span> - cursor-right <span class="Constant">0:literal/screen</span> - wait-for-event <span class="Constant">0:literal/console</span> - cursor-left <span class="Constant">0:literal/screen</span> - wait-for-event <span class="Constant">0:literal/console</span> - cursor-up <span class="Constant">0:literal/screen</span> - wait-for-event <span class="Constant">0:literal/console</span> + print-character <span class="Constant">0/screen</span>, <span class="Constant">97/a</span>, <span class="Constant">2/red</span> + <span class="Constant">1</span>:number/<span class="Special">raw</span>, <span class="Constant">2</span>:number/<span class="Special">raw <- </span>cursor-position <span class="Constant">0/screen</span> + wait-for-event <span class="Constant">0/console</span> + clear-screen <span class="Constant">0/screen</span> + move-cursor <span class="Constant">0/screen</span>, <span class="Constant">0/row</span>, <span class="Constant">4/column</span> + print-character <span class="Constant">0/screen</span>, <span class="Constant">98/b</span> + wait-for-event <span class="Constant">0/console</span> + move-cursor <span class="Constant">0/screen</span>, <span class="Constant">0/row</span>, <span class="Constant">0/column</span> + clear-line <span class="Constant">0/screen</span> + wait-for-event <span class="Constant">0/console</span> + cursor-down <span class="Constant">0/screen</span> + wait-for-event <span class="Constant">0/console</span> + cursor-right <span class="Constant">0/screen</span> + wait-for-event <span class="Constant">0/console</span> + cursor-left <span class="Constant">0/screen</span> + wait-for-event <span class="Constant">0/console</span> + cursor-up <span class="Constant">0/screen</span> + wait-for-event <span class="Constant">0/console</span> close-console ] </pre> diff --git a/html/tangle.mu.html b/html/tangle.mu.html index 4c72404b..f4e8be60 100644 --- a/html/tangle.mu.html +++ b/html/tangle.mu.html @@ -13,12 +13,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Delimiter { color: #a04060; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } .muControl { color: #c0a020; } -.muRecipe { color: #ff8700; } --> </style> @@ -49,22 +49,22 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="muRecipe">after</span> +base-case [ <span class="Comment"># if n=0 return 1</span> - zero?:boolean<span class="Special"> <- </span>equal n:number, <span class="Constant">0:literal</span> - <span class="muControl">break-unless</span> zero?:boolean - <span class="muControl">reply</span> <span class="Constant">1:literal</span> + zero?:boolean<span class="Special"> <- </span>equal n, <span class="Constant">0</span> + <span class="muControl">break-unless</span> zero? + <span class="muControl">reply</span> <span class="Constant">1</span> ] <span class="muRecipe">after</span> +recursive-case [ <span class="Comment"># return n * factorial(n - 1)</span> - x:number<span class="Special"> <- </span>subtract n:number, <span class="Constant">1:literal</span> - subresult:number<span class="Special"> <- </span>factorial x:number - result:number<span class="Special"> <- </span>multiply subresult:number, n:number - <span class="muControl">reply</span> result:number + x:number<span class="Special"> <- </span>subtract n, <span class="Constant">1</span> + subresult:number<span class="Special"> <- </span>factorial x + result:number<span class="Special"> <- </span>multiply subresult, n + <span class="muControl">reply</span> result ] <span class="muRecipe">recipe</span> main [ - 1:number<span class="Special"> <- </span>factorial <span class="Constant">5:literal</span> - $print <span class="Constant">[result: ]</span>, 1:number, [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>factorial <span class="Constant">5</span> + $print <span class="Constant">[result: ]</span>, <span class="Constant">1</span>:number, [ ] ] </pre> diff --git a/html/x.mu.html b/html/x.mu.html index fa874a2d..7ff0e1aa 100644 --- a/html/x.mu.html +++ b/html/x.mu.html @@ -13,10 +13,10 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.muRecipe { color: #ff8700; } .Comment { color: #9090ff; } .Constant { color: #00a0a0; } .Special { color: #ff6060; } -.muRecipe { color: #ff8700; } --> </style> @@ -31,9 +31,9 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <span class="Comment"># example program: add two numbers</span> <span class="muRecipe">recipe</span> main [ - 11:number<span class="Special"> <- </span>copy <span class="Constant">1:literal</span> - 12:number<span class="Special"> <- </span>copy <span class="Constant">3:literal</span> - 13:number<span class="Special"> <- </span>add 11:number, 12:number + <span class="Constant">11</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span> + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> + <span class="Constant">13</span>:number<span class="Special"> <- </span>add <span class="Constant">11</span>:number, <span class="Constant">12</span>:number <span class="Constant"> $dump-memory</span> ] </pre> |