diff options
Diffstat (limited to 'html')
50 files changed, 4603 insertions, 4603 deletions
diff --git a/html/051scenario_test.mu.html b/html/051scenario_test.mu.html index 2b1151be..ad40c9d8 100644 --- a/html/051scenario_test.mu.html +++ b/html/051scenario_test.mu.html @@ -32,20 +32,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> first_scenario_in_mu [ run [ - <span class="Constant">10</span>:num<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> + 10:num <span class="Special"><-</span> add<span class="Constant"> 2</span>,<span class="Constant"> 2</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant"> 10</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> - <span class="Constant">10</span>:num<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> + 10:num <span class="Special"><-</span> add<span class="Constant"> 2</span>,<span class="Constant"> 2</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> ] ] @@ -53,46 +53,46 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ <span class="Comment"># comment1</span> <span class="Comment"># comment2</span> - <span class="Constant">10</span>:num<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> + 10:num <span class="Special"><-</span> add<span class="Constant"> 2</span>,<span class="Constant"> 2</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> ] ] <span class="muScenario">scenario</span> check_text_in_memory [ run [ - <span class="Constant">10</span>:num<span class="Special"> <- </span>copy <span class="Constant">3</span> - <span class="Constant">11</span>:char<span class="Special"> <- </span>copy <span class="Constant">97</span> <span class="Comment"># 'a'</span> - <span class="Constant">12</span>:char<span class="Special"> <- </span>copy <span class="Constant">98</span> <span class="Comment"># 'b'</span> - <span class="Constant">13</span>:char<span class="Special"> <- </span>copy <span class="Constant">99</span> <span class="Comment"># 'c'</span> + 10:num <span class="Special"><-</span> copy<span class="Constant"> 3</span> + 11:char <span class="Special"><-</span> copy<span class="Constant"> 97</span> <span class="Comment"># 'a'</span> + 12:char <span class="Special"><-</span> copy<span class="Constant"> 98</span> <span class="Comment"># 'b'</span> + 13:char <span class="Special"><-</span> copy<span class="Constant"> 99</span> <span class="Comment"># 'c'</span> ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> check_trace [ run [ - <span class="Constant">10</span>:num<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> + 10:num <span class="Special"><-</span> add<span class="Constant"> 2</span>,<span class="Constant"> 2</span> ] trace-should-contain [ - mem: storing <span class="Constant">4</span> in location <span class="Constant">10</span> + mem: storing<span class="Constant"> 4</span> in location<span class="Constant"> 10</span> ] ] <span class="muScenario">scenario</span> check_trace_negative [ run [ - <span class="Constant">10</span>:num<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> + 10:num <span class="Special"><-</span> add<span class="Constant"> 2</span>,<span class="Constant"> 2</span> ] trace-should-not-contain [ - mem: storing <span class="Constant">3</span> in location <span class="Constant">10</span> + mem: storing<span class="Constant"> 3</span> in location<span class="Constant"> 10</span> ] ] <span class="muScenario">scenario</span> check_trace_instruction [ run [ - trace <span class="Constant">1</span>, <span class="Constant">[foo]</span>, <span class="Constant">[aaa]</span> + trace<span class="Constant"> 1</span>, <span class="Constant">[foo]</span>, <span class="Constant">[aaa]</span> ] trace-should-contain [ foo: aaa diff --git a/html/059to_text.mu.html b/html/059to_text.mu.html index baeb650e..f136c203 100644 --- a/html/059to_text.mu.html +++ b/html/059to_text.mu.html @@ -40,24 +40,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> to-text-line x:_elem<span class="muRecipe"> -> </span>y:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - y<span class="Special"> <- </span>to-text x + y <span class="Special"><-</span> to-text x ] <span class="Comment"># variant for arrays (since we can't pass them around otherwise)</span> <span class="muRecipe">def</span> array-to-text-line x:&:@:_elem<span class="muRecipe"> -> </span>y:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - y<span class="Special"> <- </span>to-text *x + y <span class="Special"><-</span> to-text *x ] <span class="muScenario">scenario</span> to-text-line-early-warning-for-static-dispatch [ - x:text<span class="Special"> <- </span>to-text-line <span class="Constant">34</span> + x:text <span class="Special"><-</span> to-text-line<span class="Constant"> 34</span> <span class="Comment"># just ensure there were no errors</span> ] <span class="muScenario">scenario</span> array-to-text-line-early-warning-for-static-dispatch [ - n:&:@:num<span class="Special"> <- </span>new <span class="Constant">number:type</span>, <span class="Constant">3</span> - x:text<span class="Special"> <- </span>array-to-text-line n + n:&:@:num <span class="Special"><-</span> new <span class="Constant">number:type</span>,<span class="Constant"> 3</span> + x:text <span class="Special"><-</span> array-to-text-line n <span class="Comment"># just ensure there were no errors</span> ] @@ -65,16 +65,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> to-text c:char<span class="muRecipe"> -> </span>y:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - y<span class="Special"> <- </span>new <span class="Constant">character:type</span>, <span class="Constant">1/capacity</span> - *y<span class="Special"> <- </span>put-index *y, <span class="Constant">0</span>, c + y <span class="Special"><-</span> new <span class="Constant">character:type</span>, <span class="Constant">1/capacity</span> + *y <span class="Special"><-</span> put-index *y,<span class="Constant"> 0</span>, c ] <span class="muScenario">scenario</span> character-to-text [ - <span class="Constant">1</span>:char<span class="Special"> <- </span>copy <span class="Constant">111/o</span> - <span class="Constant">2</span>:text<span class="Special"> <- </span>to-text <span class="Constant">1</span>:char - <span class="Constant">3</span>:@:char<span class="Special"> <- </span>copy *<span class="Constant">2</span>:text + 1:char <span class="Special"><-</span> copy <span class="Constant">111/o</span> + 2:text <span class="Special"><-</span> to-text 1:char + 3:@:char <span class="Special"><-</span> copy *2:text memory-should-contain [ - <span class="Constant">3</span>:array:character<span class="Special"> <- </span><span class="Constant">[o]</span> + 3:array:character <span class="Special"><-</span> <span class="Constant">[o]</span> ] ] </pre> diff --git a/html/061text.mu.html b/html/061text.mu.html index e5ac7644..e438b576 100644 --- a/html/061text.mu.html +++ b/html/061text.mu.html @@ -37,66 +37,66 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> equal a:text, b:text<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - a-len:num<span class="Special"> <- </span>length *a - b-len:num<span class="Special"> <- </span>length *b + a-len:num <span class="Special"><-</span> length *a + b-len:num <span class="Special"><-</span> length *b <span class="Comment"># compare lengths</span> <span class="Delimiter">{</span> - trace <span class="Constant">99</span>, <span class="Constant">[text-equal]</span>, <span class="Constant">[comparing lengths]</span> - length-equal?:bool<span class="Special"> <- </span>equal a-len, b-len + trace<span class="Constant"> 99</span>, <span class="Constant">[text-equal]</span>, <span class="Constant">[comparing lengths]</span> + length-equal?:bool <span class="Special"><-</span> equal a-len, b-len <span class="muControl">break-if</span> length-equal? - <span class="muControl">return</span> <span class="Constant">0</span> + <span class="muControl">return</span><span class="Constant"> 0</span> <span class="Delimiter">}</span> <span class="Comment"># compare each corresponding character</span> - trace <span class="Constant">99</span>, <span class="Constant">[text-equal]</span>, <span class="Constant">[comparing characters]</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + trace<span class="Constant"> 99</span>, <span class="Constant">[text-equal]</span>, <span class="Constant">[comparing characters]</span> + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, a-len + done?:bool <span class="Special"><-</span> greater-or-equal i, a-len <span class="muControl">break-if</span> done? - a2:char<span class="Special"> <- </span>index *a, i - b2:char<span class="Special"> <- </span>index *b, i + a2:char <span class="Special"><-</span> index *a, i + b2:char <span class="Special"><-</span> index *b, i <span class="Delimiter">{</span> - chars-match?:bool<span class="Special"> <- </span>equal a2, b2 + chars-match?:bool <span class="Special"><-</span> equal a2, b2 <span class="muControl">break-if</span> chars-match? - <span class="muControl">return</span> <span class="Constant">0</span> + <span class="muControl">return</span><span class="Constant"> 0</span> <span class="Delimiter">}</span> - i<span class="Special"> <- </span>add i, <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="muControl">return</span> <span class="Constant">1</span> + <span class="muControl">return</span><span class="Constant"> 1</span> ] <span class="muScenario">scenario</span> text-equal-reflexive [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal x, x + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal x, x ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># x == x for all x</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># x == x for all x</span> ] ] <span class="muScenario">scenario</span> text-equal-identical [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal x, y + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal x, y ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># abc == abc</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># abc == abc</span> ] ] <span class="muScenario">scenario</span> text-equal-distinct-lengths [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[abcd]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal x, y + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal x, y ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># abc != abcd</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># abc != abcd</span> ] trace-should-contain [ text-equal: comparing lengths @@ -108,25 +108,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> text-equal-with-empty [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[abcd]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal x, y + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal x, y ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># "" != abcd</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># "" != abcd</span> ] ] <span class="muScenario">scenario</span> text-equal-common-lengths-but-distinct [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[abd]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[abd]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal x, y + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal x, y ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># abc != abd</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># abc != abd</span> ] ] @@ -139,15 +139,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-buffer capacity:num<span class="muRecipe"> -> </span>result:&:buffer [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>new <span class="Constant">buffer:type</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">length:offset</span>, <span class="Constant">0</span> + result <span class="Special"><-</span> new <span class="Constant">buffer:type</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">length:offset</span>,<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> capacity <span class="Comment"># capacity not provided</span> - capacity<span class="Special"> <- </span>copy <span class="Constant">10</span> + capacity <span class="Special"><-</span> copy<span class="Constant"> 10</span> <span class="Delimiter">}</span> - data:text<span class="Special"> <- </span>new <span class="Constant">character:type</span>, capacity - *result<span class="Special"> <- </span>put *result, <span class="Constant">data:offset</span>, data + data:text <span class="Special"><-</span> new <span class="Constant">character:type</span>, capacity + *result <span class="Special"><-</span> put *result, <span class="Constant">data:offset</span>, data <span class="muControl">return</span> result ] @@ -155,19 +155,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># double buffer size</span> - olddata:text<span class="Special"> <- </span>get *buf, <span class="Constant">data:offset</span> - oldlen:num<span class="Special"> <- </span>length *olddata - newlen:num<span class="Special"> <- </span>multiply oldlen, <span class="Constant">2</span> - newdata:text<span class="Special"> <- </span>new <span class="Constant">character:type</span>, newlen - *buf<span class="Special"> <- </span>put *buf, <span class="Constant">data:offset</span>, newdata + olddata:text <span class="Special"><-</span> get *buf, <span class="Constant">data:offset</span> + oldlen:num <span class="Special"><-</span> length *olddata + newlen:num <span class="Special"><-</span> multiply oldlen,<span class="Constant"> 2</span> + newdata:text <span class="Special"><-</span> new <span class="Constant">character:type</span>, newlen + *buf <span class="Special"><-</span> put *buf, <span class="Constant">data:offset</span>, newdata <span class="Comment"># copy old contents</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, oldlen + done?:bool <span class="Special"><-</span> greater-or-equal i, oldlen <span class="muControl">break-if</span> done? - src:char<span class="Special"> <- </span>index *olddata, i - *newdata<span class="Special"> <- </span>put-index *newdata, i, src - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + src:char <span class="Special"><-</span> index *olddata, i + *newdata <span class="Special"><-</span> put-index *newdata, i, src + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -175,25 +175,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> buffer-full? in:&:buffer<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - len:num<span class="Special"> <- </span>get *in, <span class="Constant">length:offset</span> - s:text<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> - capacity:num<span class="Special"> <- </span>length *s - result<span class="Special"> <- </span>greater-or-equal len, capacity + len:num <span class="Special"><-</span> get *in, <span class="Constant">length:offset</span> + s:text <span class="Special"><-</span> get *in, <span class="Constant">data:offset</span> + capacity:num <span class="Special"><-</span> length *s + result <span class="Special"><-</span> greater-or-equal len, capacity ] <span class="Comment"># most broadly applicable definition of append to a buffer: just call to-text</span> <span class="muRecipe">def</span> append buf:&:buffer, x:_elem<span class="muRecipe"> -> </span>buf:&:buffer [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - text:text<span class="Special"> <- </span>to-text x - len:num<span class="Special"> <- </span>length *text - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + text:text <span class="Special"><-</span> to-text x + len:num <span class="Special"><-</span> length *text + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *text, i - buf<span class="Special"> <- </span>append buf, c - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + c:char <span class="Special"><-</span> index *text, i + buf <span class="Special"><-</span> append buf, c + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -201,135 +201,135 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> append buf:&:buffer, c:char<span class="muRecipe"> -> </span>buf:&:buffer [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - len:num<span class="Special"> <- </span>get *buf, <span class="Constant">length:offset</span> + len:num <span class="Special"><-</span> get *buf, <span class="Constant">length:offset</span> <span class="Delimiter">{</span> <span class="Comment"># backspace? just drop last character if it exists and return</span> - backspace?:bool<span class="Special"> <- </span>equal c, <span class="Constant">8/backspace</span> + backspace?:bool <span class="Special"><-</span> equal c, <span class="Constant">8/backspace</span> <span class="muControl">break-unless</span> backspace? - empty?:bool<span class="Special"> <- </span>lesser-or-equal len, <span class="Constant">0</span> + empty?:bool <span class="Special"><-</span> lesser-or-equal len,<span class="Constant"> 0</span> <span class="muControl">return-if</span> empty? - len<span class="Special"> <- </span>subtract len, <span class="Constant">1</span> - *buf<span class="Special"> <- </span>put *buf, <span class="Constant">length:offset</span>, len + len <span class="Special"><-</span> subtract len,<span class="Constant"> 1</span> + *buf <span class="Special"><-</span> put *buf, <span class="Constant">length:offset</span>, len <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># grow buffer if necessary</span> - full?:bool<span class="Special"> <- </span>buffer-full? buf + full?:bool <span class="Special"><-</span> buffer-full? buf <span class="muControl">break-unless</span> full? - buf<span class="Special"> <- </span>grow-buffer buf + buf <span class="Special"><-</span> grow-buffer buf <span class="Delimiter">}</span> - s:text<span class="Special"> <- </span>get *buf, <span class="Constant">data:offset</span> - *s<span class="Special"> <- </span>put-index *s, len, c - len<span class="Special"> <- </span>add len, <span class="Constant">1</span> - *buf<span class="Special"> <- </span>put *buf, <span class="Constant">length:offset</span>, len + s:text <span class="Special"><-</span> get *buf, <span class="Constant">data:offset</span> + *s <span class="Special"><-</span> put-index *s, len, c + len <span class="Special"><-</span> add len,<span class="Constant"> 1</span> + *buf <span class="Special"><-</span> put *buf, <span class="Constant">length:offset</span>, len ] <span class="muRecipe">def</span> append buf:&:buffer, t:text<span class="muRecipe"> -> </span>buf:&:buffer [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - len:num<span class="Special"> <- </span>length *t - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + len:num <span class="Special"><-</span> length *t + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *t, i - buf<span class="Special"> <- </span>append buf, c - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + c:char <span class="Special"><-</span> index *t, i + buf <span class="Special"><-</span> append buf, c + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muScenario">scenario</span> append-to-empty-buffer [ <span class="Constant">local-scope</span> - x:&:buffer<span class="Special"> <- </span>new-buffer + x:&:buffer <span class="Special"><-</span> new-buffer run [ - c:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - x<span class="Special"> <- </span>append x, c - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *x, <span class="Constant">length:offset</span> - s:text<span class="Special"> <- </span>get *x, <span class="Constant">data:offset</span> - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>index *s, <span class="Constant">0</span> - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>index *s, <span class="Constant">1</span> + c:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + x <span class="Special"><-</span> append x, c + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *x, <span class="Constant">length:offset</span> + s:text <span class="Special"><-</span> get *x, <span class="Constant">data:offset</span> + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> index *s,<span class="Constant"> 0</span> + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> index *s,<span class="Constant"> 1</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># buffer length</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># a</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># rest of buffer is empty</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># buffer length</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># a</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># rest of buffer is empty</span> ] ] <span class="muScenario">scenario</span> append-to-buffer [ <span class="Constant">local-scope</span> - x:&:buffer<span class="Special"> <- </span>new-buffer - c:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - x<span class="Special"> <- </span>append x, c + x:&:buffer <span class="Special"><-</span> new-buffer + c:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + x <span class="Special"><-</span> append x, c run [ - c<span class="Special"> <- </span>copy <span class="Constant">98/b</span> - x<span class="Special"> <- </span>append x, c - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *x, <span class="Constant">length:offset</span> - s:text<span class="Special"> <- </span>get *x, <span class="Constant">data:offset</span> - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>index *s, <span class="Constant">0</span> - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>index *s, <span class="Constant">1</span> - <span class="Constant">13</span>:char/<span class="Special">raw <- </span>index *s, <span class="Constant">2</span> + c <span class="Special"><-</span> copy <span class="Constant">98/b</span> + x <span class="Special"><-</span> append x, c + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *x, <span class="Constant">length:offset</span> + s:text <span class="Special"><-</span> get *x, <span class="Constant">data:offset</span> + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> index *s,<span class="Constant"> 0</span> + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> index *s,<span class="Constant"> 1</span> + 13:char/<span class="Special">raw</span> <span class="Special"><-</span> index *s,<span class="Constant"> 2</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># buffer length</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># a</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">98</span> <span class="Comment"># b</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># rest of buffer is empty</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 2</span> <span class="Comment"># buffer length</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># a</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 98</span> <span class="Comment"># b</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># rest of buffer is empty</span> ] ] <span class="muScenario">scenario</span> append-grows-buffer [ <span class="Constant">local-scope</span> - x:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">3</span> - s1:text<span class="Special"> <- </span>get *x, <span class="Constant">data:offset</span> - x<span class="Special"> <- </span>append x, <span class="Constant">[abc]</span> <span class="Comment"># buffer is now full</span> - s2:text<span class="Special"> <- </span>get *x, <span class="Constant">data:offset</span> + x:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 3</span> + s1:text <span class="Special"><-</span> get *x, <span class="Constant">data:offset</span> + x <span class="Special"><-</span> append x, <span class="Constant">[abc]</span> <span class="Comment"># buffer is now full</span> + s2:text <span class="Special"><-</span> get *x, <span class="Constant">data:offset</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal s1, s2 - <span class="Constant">11</span>:@:char/<span class="Special">raw <- </span>copy *s2 + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal s1, s2 + 11:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 <span class="Constant"> +buffer-filled</span> - c:char<span class="Special"> <- </span>copy <span class="Constant">100/d</span> - x<span class="Special"> <- </span>append x, c - s3:text<span class="Special"> <- </span>get *x, <span class="Constant">data:offset</span> - <span class="Constant">20</span>:bool/<span class="Special">raw <- </span>equal s1, s3 - <span class="Constant">21</span>:num/<span class="Special">raw <- </span>get *x, <span class="Constant">length:offset</span> - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *s3 + c:char <span class="Special"><-</span> copy <span class="Constant">100/d</span> + x <span class="Special"><-</span> append x, c + s3:text <span class="Special"><-</span> get *x, <span class="Constant">data:offset</span> + 20:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal s1, s3 + 21:num/<span class="Special">raw</span> <span class="Special"><-</span> get *x, <span class="Constant">length:offset</span> + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s3 ] memory-should-contain [ <span class="Comment"># before +buffer-filled</span> - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># no change in data pointer after original append</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># size of data</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># data</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">98</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">99</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># no change in data pointer after original append</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 3</span> <span class="Comment"># size of data</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># data</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 98</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 99</span> <span class="Comment"># in the end</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># data pointer has grown after second append</span> - <span class="Constant">21</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># final length</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># but data's capacity has doubled</span> - <span class="Constant">31</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># data</span> - <span class="Constant">32</span><span class="Special"> <- </span><span class="Constant">98</span> - <span class="Constant">33</span><span class="Special"> <- </span><span class="Constant">99</span> - <span class="Constant">34</span><span class="Special"> <- </span><span class="Constant">100</span> - <span class="Constant">35</span><span class="Special"> <- </span><span class="Constant">0</span> - <span class="Constant">36</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># data pointer has grown after second append</span> + <span class="Constant"> 21</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># final length</span> + <span class="Constant"> 30</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># but data's capacity has doubled</span> + <span class="Constant"> 31</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># data</span> + <span class="Constant"> 32</span> <span class="Special"><-</span><span class="Constant"> 98</span> + <span class="Constant"> 33</span> <span class="Special"><-</span><span class="Constant"> 99</span> + <span class="Constant"> 34</span> <span class="Special"><-</span><span class="Constant"> 100</span> + <span class="Constant"> 35</span> <span class="Special"><-</span><span class="Constant"> 0</span> + <span class="Constant"> 36</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> buffer-append-handles-backspace [ <span class="Constant">local-scope</span> - x:&:buffer<span class="Special"> <- </span>new-buffer - x<span class="Special"> <- </span>append x, <span class="Constant">[ab]</span> + x:&:buffer <span class="Special"><-</span> new-buffer + x <span class="Special"><-</span> append x, <span class="Constant">[ab]</span> run [ - c:char<span class="Special"> <- </span>copy <span class="Constant">8/backspace</span> - x<span class="Special"> <- </span>append x, c - s:text<span class="Special"> <- </span>buffer-to-array x - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *s + c:char <span class="Special"><-</span> copy <span class="Constant">8/backspace</span> + x <span class="Special"><-</span> append x, c + s:text <span class="Special"><-</span> buffer-to-array x + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># length</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># contents</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># length</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># contents</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] @@ -339,19 +339,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="Comment"># propagate null buffer</span> <span class="muControl">break-if</span> in - <span class="muControl">return</span> <span class="Constant">0</span> + <span class="muControl">return</span><span class="Constant"> 0</span> <span class="Delimiter">}</span> - len:num<span class="Special"> <- </span>get *in, <span class="Constant">length:offset</span> - s:text<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> + len:num <span class="Special"><-</span> get *in, <span class="Constant">length:offset</span> + s:text <span class="Special"><-</span> get *in, <span class="Constant">data:offset</span> <span class="Comment"># we can't just return s because it is usually the wrong length</span> - result<span class="Special"> <- </span>new <span class="Constant">character:type</span>, len - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + result <span class="Special"><-</span> new <span class="Constant">character:type</span>, len + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - src:char<span class="Special"> <- </span>index *s, i - *result<span class="Special"> <- </span>put-index *result, i, src - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + src:char <span class="Special"><-</span> index *s, i + *result <span class="Special"><-</span> put-index *result, i, src + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -367,145 +367,145 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> append first:text<span class="muRecipe"> -> </span>result:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 30</span> <span class="Comment"># append first ingredient</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> first - buf<span class="Special"> <- </span>append buf, first + buf <span class="Special"><-</span> append buf, first <span class="Delimiter">}</span> <span class="Comment"># append remaining ingredients</span> <span class="Delimiter">{</span> - arg:text, arg-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + arg:text, arg-found?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="muControl">break-unless</span> arg-found? <span class="muControl">loop-unless</span> arg - buf<span class="Special"> <- </span>append buf, arg + buf <span class="Special"><-</span> append buf, arg <span class="muControl">loop</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>buffer-to-array buf + result <span class="Special"><-</span> buffer-to-array buf ] <span class="muScenario">scenario</span> text-append-1 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[hello,]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[ world!]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[hello,]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[ world!]</span> run [ - z:text<span class="Special"> <- </span>append x, y - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *z + z:text <span class="Special"><-</span> append x, y + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[hello, world!]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[hello, world!]</span> ] ] <span class="muScenario">scenario</span> text-append-null [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>copy <span class="Constant">0</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[ world!]</span> + x:text <span class="Special"><-</span> copy<span class="Constant"> 0</span> + y:text <span class="Special"><-</span> new <span class="Constant">[ world!]</span> run [ - z:text<span class="Special"> <- </span>append x, y - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *z + z:text <span class="Special"><-</span> append x, y + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[ world!]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[ world!]</span> ] ] <span class="muScenario">scenario</span> text-append-null-2 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[hello,]</span> - y:text<span class="Special"> <- </span>copy <span class="Constant">0</span> + x:text <span class="Special"><-</span> new <span class="Constant">[hello,]</span> + y:text <span class="Special"><-</span> copy<span class="Constant"> 0</span> run [ - z:text<span class="Special"> <- </span>append x, y - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *z + z:text <span class="Special"><-</span> append x, y + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[hello,]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[hello,]</span> ] ] <span class="muScenario">scenario</span> text-append-multiary [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[hello, ]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[world]</span> - z:text<span class="Special"> <- </span>new <span class="Constant">[!]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[hello, ]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[world]</span> + z:text <span class="Special"><-</span> new <span class="Constant">[!]</span> run [ - z:text<span class="Special"> <- </span>append x, y, z - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *z + z:text <span class="Special"><-</span> append x, y, z + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[hello, world!]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[hello, world!]</span> ] ] <span class="muScenario">scenario</span> replace-character-in-text [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - x<span class="Special"> <- </span>replace x, <span class="Constant">98/b</span>, <span class="Constant">122/z</span> - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *x + x <span class="Special"><-</span> replace x, <span class="Constant">98/b</span>, <span class="Constant">122/z</span> + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *x ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[azc]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[azc]</span> ] ] <span class="muRecipe">def</span> replace s:text, oldc:char, newc:char, from:num/optional<span class="muRecipe"> -> </span>s:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - len:num<span class="Special"> <- </span>length *s - i:num<span class="Special"> <- </span>find-next s, oldc, from - done?:bool<span class="Special"> <- </span>greater-or-equal i, len - <span class="muControl">return-if</span> done?, s/same-as-ingredient:<span class="Constant">0</span> - *s<span class="Special"> <- </span>put-index *s, i, newc - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> - s<span class="Special"> <- </span>replace s, oldc, newc, i + len:num <span class="Special"><-</span> length *s + i:num <span class="Special"><-</span> find-next s, oldc, from + done?:bool <span class="Special"><-</span> greater-or-equal i, len + <span class="muControl">return-if</span> done?, s/same-as-ingredient:0 + *s <span class="Special"><-</span> put-index *s, i, newc + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> + s <span class="Special"><-</span> replace s, oldc, newc, i ] <span class="muScenario">scenario</span> replace-character-at-start [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - x<span class="Special"> <- </span>replace x, <span class="Constant">97/a</span>, <span class="Constant">122/z</span> - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *x + x <span class="Special"><-</span> replace x, <span class="Constant">97/a</span>, <span class="Constant">122/z</span> + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *x ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[zbc]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[zbc]</span> ] ] <span class="muScenario">scenario</span> replace-character-at-end [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - x<span class="Special"> <- </span>replace x, <span class="Constant">99/c</span>, <span class="Constant">122/z</span> - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *x + x <span class="Special"><-</span> replace x, <span class="Constant">99/c</span>, <span class="Constant">122/z</span> + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *x ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[abz]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[abz]</span> ] ] <span class="muScenario">scenario</span> replace-character-missing [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - x<span class="Special"> <- </span>replace x, <span class="Constant">100/d</span>, <span class="Constant">122/z</span> - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *x + x <span class="Special"><-</span> replace x, <span class="Constant">100/d</span>, <span class="Constant">122/z</span> + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *x ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> replace-all-characters [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[banana]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[banana]</span> run [ - x<span class="Special"> <- </span>replace x, <span class="Constant">97/a</span>, <span class="Constant">122/z</span> - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *x + x <span class="Special"><-</span> replace x, <span class="Constant">97/a</span>, <span class="Constant">122/z</span> + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *x ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[bznznz]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[bznznz]</span> ] ] @@ -514,112 +514,112 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># consume just the template</span> <span class="Comment"># compute result-len, space to allocate for result</span> - tem-len:num<span class="Special"> <- </span>length *template - result-len:num<span class="Special"> <- </span>copy tem-len + tem-len:num <span class="Special"><-</span> length *template + result-len:num <span class="Special"><-</span> copy tem-len <span class="Delimiter">{</span> <span class="Comment"># while ingredients remain</span> - a:text, arg-received?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + a:text, arg-received?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</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:num<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> + a-len:num <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="Constant">rewind-ingredients</span> - _<span class="Special"> <- </span><span class="Constant">next-ingredient</span> <span class="Comment"># skip template</span> - result<span class="Special"> <- </span>new <span class="Constant">character:type</span>, result-len + _ <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="Comment"># skip template</span> + result <span class="Special"><-</span> new <span class="Constant">character:type</span>, result-len <span class="Comment"># repeatedly copy sections of template and 'holes' into result</span> - result-idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + result-idx:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="Comment"># while arg received</span> - a:text, arg-received?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + a:text, arg-received?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <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?:bool<span class="Special"> <- </span>greater-or-equal i, tem-len + tem-done?:bool <span class="Special"><-</span> greater-or-equal i, tem-len <span class="muControl">break-if</span> tem-done?, <span class="Constant">+done</span> <span class="Comment"># while template[i] != '_'</span> - in:char<span class="Special"> <- </span>index *template, i - underscore?:bool<span class="Special"> <- </span>equal in, <span class="Constant">95/_</span> + in:char <span class="Special"><-</span> index *template, i + underscore?:bool <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> - *result<span class="Special"> <- </span>put-index *result, result-idx, 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> + *result <span class="Special"><-</span> put-index *result, result-idx, 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:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + j:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="Comment"># while j < a.length</span> - arg-done?:bool<span class="Special"> <- </span>greater-or-equal j, a-len + arg-done?:bool <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:char<span class="Special"> <- </span>index *a, j - *result<span class="Special"> <- </span>put-index *result, result-idx, 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> + in:char <span class="Special"><-</span> index *a, j + *result <span class="Special"><-</span> put-index *result, result-idx, 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<span class="Special"> <- </span>add i, <span class="Constant">1</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?:bool<span class="Special"> <- </span>greater-or-equal i, tem-len + tem-done?:bool <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:char<span class="Special"> <- </span>index *template, i - *result<span class="Special"> <- </span>put-index *result, result-idx, 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> + in:char <span class="Special"><-</span> index *template, i + *result <span class="Special"><-</span> put-index *result, result-idx, 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="muScenario">scenario</span> interpolate-works [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc_ghi]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[def]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc_ghi]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[def]</span> run [ - z:text<span class="Special"> <- </span>interpolate x, y - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *z + z:text <span class="Special"><-</span> interpolate x, y + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[abcdefghi]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[abcdefghi]</span> ] ] <span class="muScenario">scenario</span> interpolate-at-start [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[_, hello!]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[_, hello!]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - z:text<span class="Special"> <- </span>interpolate x, y - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *z + z:text <span class="Special"><-</span> interpolate x, y + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc, hello!]</span> - <span class="Constant">22</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># out of bounds</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[abc, hello!]</span> + <span class="Constant"> 22</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 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[hello, _]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[hello, _]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - z:text<span class="Special"> <- </span>interpolate x, y - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *z + z:text <span class="Special"><-</span> interpolate x, y + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[hello, abc]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[hello, abc]</span> ] ] @@ -628,184 +628,184 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># most common case first</span> - result<span class="Special"> <- </span>equal c, <span class="Constant">32/space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">32/space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + result <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">9/tab</span> + result <span class="Special"><-</span> equal c, <span class="Constant">9/tab</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">13/carriage-return</span> + result <span class="Special"><-</span> equal c, <span class="Constant">13/carriage-return</span> <span class="muControl">return-if</span> result <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> - result<span class="Special"> <- </span>equal c, <span class="Constant">11/ctrl-k</span> + result <span class="Special"><-</span> equal c, <span class="Constant">11/ctrl-k</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">12/ctrl-l</span> + result <span class="Special"><-</span> equal c, <span class="Constant">12/ctrl-l</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">133/ctrl-0085</span> + result <span class="Special"><-</span> equal c, <span class="Constant">133/ctrl-0085</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">160/no-break-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">160/no-break-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">5760/ogham-space-mark</span> + result <span class="Special"><-</span> equal c, <span class="Constant">5760/ogham-space-mark</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8192/en-quad</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8192/en-quad</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8193/em-quad</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8193/em-quad</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8194/en-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8194/en-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8195/em-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8195/em-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8196/three-per-em-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8196/three-per-em-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8197/four-per-em-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8197/four-per-em-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8198/six-per-em-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8198/six-per-em-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8199/figure-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8199/figure-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8200/punctuation-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8200/punctuation-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8201/thin-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8201/thin-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8202/hair-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8202/hair-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8206/left-to-right</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8206/left-to-right</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8207/right-to-left</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8207/right-to-left</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8232/line-separator</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8232/line-separator</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8233/paragraph-separator</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8233/paragraph-separator</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8239/narrow-no-break-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8239/narrow-no-break-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">8287/medium-mathematical-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">8287/medium-mathematical-space</span> <span class="muControl">return-if</span> result - result<span class="Special"> <- </span>equal c, <span class="Constant">12288/ideographic-space</span> + result <span class="Special"><-</span> equal c, <span class="Constant">12288/ideographic-space</span> ] <span class="muRecipe">def</span> trim s:text<span class="muRecipe"> -> </span>result:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - len:num<span class="Special"> <- </span>length *s + len:num <span class="Special"><-</span> length *s <span class="Comment"># left trim: compute start</span> - start:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + start:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="Delimiter">{</span> - at-end?:bool<span class="Special"> <- </span>greater-or-equal start, len + at-end?:bool <span class="Special"><-</span> greater-or-equal start, len <span class="muControl">break-unless</span> at-end? - result<span class="Special"> <- </span>new <span class="Constant">character:type</span>, <span class="Constant">0</span> + result <span class="Special"><-</span> new <span class="Constant">character:type</span>,<span class="Constant"> 0</span> <span class="muControl">return</span> <span class="Delimiter">}</span> - curr:char<span class="Special"> <- </span>index *s, start - whitespace?:bool<span class="Special"> <- </span>space? curr + curr:char <span class="Special"><-</span> index *s, start + whitespace?:bool <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> + 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:num<span class="Special"> <- </span>subtract len, <span class="Constant">1</span> + end:num <span class="Special"><-</span> subtract len,<span class="Constant"> 1</span> <span class="Delimiter">{</span> - not-at-start?:bool<span class="Special"> <- </span>greater-than end, start + not-at-start?:bool <span class="Special"><-</span> greater-than end, start assert not-at-start?, <span class="Constant">[end ran up against start]</span> - curr:char<span class="Special"> <- </span>index *s, end - whitespace?:bool<span class="Special"> <- </span>space? curr + curr:char <span class="Special"><-</span> index *s, end + whitespace?:bool <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> + 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:num<span class="Special"> <- </span>subtract end, start, <span class="Constant">-1</span> - result:text<span class="Special"> <- </span>new <span class="Constant">character:type</span>, new-len + new-len:num <span class="Special"><-</span> subtract end, start,<span class="Constant"> -1</span> + result:text <span class="Special"><-</span> new <span class="Constant">character:type</span>, new-len <span class="Comment"># copy the untrimmed parts between start and end</span> - i:num<span class="Special"> <- </span>copy start - j:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + i:num <span class="Special"><-</span> copy start + j:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="Comment"># while i <= end</span> - done?:bool<span class="Special"> <- </span>greater-than i, end + done?:bool <span class="Special"><-</span> greater-than i, end <span class="muControl">break-if</span> done? <span class="Comment"># result[j] = s[i]</span> - src:char<span class="Special"> <- </span>index *s, i - *result<span class="Special"> <- </span>put-index *result, j, 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> + src:char <span class="Special"><-</span> index *s, i + *result <span class="Special"><-</span> put-index *result, j, 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="muScenario">scenario</span> trim-unmodified [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - y:text<span class="Special"> <- </span>trim x - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *y + y:text <span class="Special"><-</span> trim x + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> trim-left [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[ abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[ abc]</span> run [ - y:text<span class="Special"> <- </span>trim x - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *y + y:text <span class="Special"><-</span> trim x + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> trim-right [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc ]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc ]</span> run [ - y:text<span class="Special"> <- </span>trim x - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *y + y:text <span class="Special"><-</span> trim x + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> trim-left-right [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[ abc ]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[ abc ]</span> run [ - y:text<span class="Special"> <- </span>trim x - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *y + y:text <span class="Special"><-</span> trim x + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> trim-newline-tab [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[ abc</span> + x:text <span class="Special"><-</span> new <span class="Constant">[ abc</span> <span class="Constant">]</span> run [ - y:text<span class="Special"> <- </span>trim x - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *y + y:text <span class="Special"><-</span> trim x + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muRecipe">def</span> find-next text:text, pattern:char, idx:num<span class="muRecipe"> -> </span>next-index:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - len:num<span class="Special"> <- </span>length *text + len:num <span class="Special"><-</span> length *text <span class="Delimiter">{</span> - eof?:bool<span class="Special"> <- </span>greater-or-equal idx, len + eof?:bool <span class="Special"><-</span> greater-or-equal idx, len <span class="muControl">break-if</span> eof? - curr:char<span class="Special"> <- </span>index *text, idx - found?:bool<span class="Special"> <- </span>equal curr, pattern + curr:char <span class="Special"><-</span> index *text, idx + found?:bool <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> + idx <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">return</span> idx @@ -813,89 +813,89 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> text-find-next [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[a/b]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> ] ] <span class="muScenario">scenario</span> text-find-next-empty [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> text-find-next-initial [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[/abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[/abc]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># prefix match</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># prefix match</span> ] ] <span class="muScenario">scenario</span> text-find-next-final [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc/]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc/]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># suffix match</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 3</span> <span class="Comment"># suffix match</span> ] ] <span class="muScenario">scenario</span> text-find-next-missing [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abcd]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># no match</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># no match</span> ] ] <span class="muScenario">scenario</span> text-find-next-invalid-index [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, <span class="Constant">47/slash</span>, <span class="Constant">4/start-index</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, <span class="Constant">47/slash</span>, <span class="Constant">4/start-index</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># no change</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># no change</span> ] ] <span class="muScenario">scenario</span> text-find-next-first [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[ab/c/]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[ab/c/]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, <span class="Constant">47/slash</span>, <span class="Constant">0/start-index</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># first '/' of multiple</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 2</span> <span class="Comment"># first '/' of multiple</span> ] ] <span class="muScenario">scenario</span> text-find-next-second [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[ab/c/]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[ab/c/]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, <span class="Constant">47/slash</span>, <span class="Constant">3/start-index</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, <span class="Constant">47/slash</span>, <span class="Constant">3/start-index</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># second '/' of multiple</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># second '/' of multiple</span> ] ] @@ -904,18 +904,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> find-next text:text, pattern:text, idx:num<span class="muRecipe"> -> </span>next-index:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - first:char<span class="Special"> <- </span>index *pattern, <span class="Constant">0</span> + first:char <span class="Special"><-</span> index *pattern,<span class="Constant"> 0</span> <span class="Comment"># repeatedly check for match at current idx</span> - len:num<span class="Special"> <- </span>length *text + len:num <span class="Special"><-</span> length *text <span class="Delimiter">{</span> <span class="Comment"># does some unnecessary work checking even when there isn't enough of text left</span> - done?:bool<span class="Special"> <- </span>greater-or-equal idx, len + done?:bool <span class="Special"><-</span> greater-or-equal idx, len <span class="muControl">break-if</span> done? - found?:bool<span class="Special"> <- </span>match-at text, pattern, idx + found?:bool <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> + 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<span class="Special"> <- </span>find-next text, first, idx + idx <span class="Special"><-</span> find-next text, first, idx <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">return</span> idx @@ -923,61 +923,61 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> find-next-text-1 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[bc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[bc]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, y, <span class="Constant">0</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, y,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> ] ] <span class="muScenario">scenario</span> find-next-text-2 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[bc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abcd]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[bc]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, y, <span class="Constant">1</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, y,<span class="Constant"> 1</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> ] ] <span class="muScenario">scenario</span> find-next-no-match [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[bd]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[bd]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, y, <span class="Constant">0</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, y,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># not found</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 3</span> <span class="Comment"># not found</span> ] ] <span class="muScenario">scenario</span> find-next-suffix-match [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[cd]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abcd]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[cd]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, y, <span class="Constant">0</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, y,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 2</span> ] ] <span class="muScenario">scenario</span> find-next-suffix-match-2 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abcd]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[cde]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abcd]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[cde]</span> run [ - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>find-next x, y, <span class="Constant">0</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> find-next x, y,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># not found</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># not found</span> ] ] @@ -985,29 +985,29 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> match-at text:text, pattern:text, idx:num<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - pattern-len:num<span class="Special"> <- </span>length *pattern + pattern-len:num <span class="Special"><-</span> length *pattern <span class="Comment"># check that there's space left for the pattern</span> <span class="Delimiter">{</span> - x:num<span class="Special"> <- </span>length *text - x<span class="Special"> <- </span>subtract x, pattern-len - enough-room?:bool<span class="Special"> <- </span>lesser-or-equal idx, x + x:num <span class="Special"><-</span> length *text + x <span class="Special"><-</span> subtract x, pattern-len + enough-room?:bool <span class="Special"><-</span> lesser-or-equal idx, x <span class="muControl">break-if</span> enough-room? <span class="muControl">return</span> <span class="Constant">0/not-found</span> <span class="Delimiter">}</span> <span class="Comment"># check each character of pattern</span> - pattern-idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + pattern-idx:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal pattern-idx, pattern-len + done?:bool <span class="Special"><-</span> greater-or-equal pattern-idx, pattern-len <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *text, idx - exp:char<span class="Special"> <- </span>index *pattern, pattern-idx + c:char <span class="Special"><-</span> index *text, idx + exp:char <span class="Special"><-</span> index *pattern, pattern-idx <span class="Delimiter">{</span> - match?:bool<span class="Special"> <- </span>equal c, exp + match?:bool <span class="Special"><-</span> equal c, exp <span class="muControl">break-if</span> match? <span class="muControl">return</span> <span class="Constant">0/not-found</span> <span class="Delimiter">}</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> + 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">return</span> <span class="Constant">1/found</span> @@ -1015,107 +1015,107 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> match-at-checks-pattern-at-index [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[ab]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[ab]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, y, <span class="Constant">0</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, y,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># match found</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># match found</span> ] ] <span class="muScenario">scenario</span> match-at-reflexive [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, x, <span class="Constant">0</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, x,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># match found</span> + <span class="Constant"> 10</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 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[a]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[a]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, y, <span class="Constant">4</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, y,<span class="Constant"> 4</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># never matches</span> + <span class="Constant"> 10</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 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, y, <span class="Constant">0</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, y,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># always matches empty pattern given a valid index</span> + <span class="Constant"> 10</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 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, y, <span class="Constant">4</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, y,<span class="Constant"> 4</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no match</span> + <span class="Constant"> 10</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 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, y, <span class="Constant">0</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, y,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no match</span> + <span class="Constant"> 10</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 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, x, <span class="Constant">0</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, x,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># matches because pattern is also empty</span> + <span class="Constant"> 10</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 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[bc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[bc]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, y, <span class="Constant">1</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, y,<span class="Constant"> 1</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># match</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># match</span> ] ] <span class="muScenario">scenario</span> match-at-inside-bounds-2 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[bc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[bc]</span> run [ - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>match-at x, y, <span class="Constant">0</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> match-at x, y,<span class="Constant"> 0</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no match</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># no match</span> ] ] @@ -1123,131 +1123,131 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># empty text? return empty array</span> - len:num<span class="Special"> <- </span>length *s + len:num <span class="Special"><-</span> length *s <span class="Delimiter">{</span> - empty?:bool<span class="Special"> <- </span>equal len, <span class="Constant">0</span> + empty?:bool <span class="Special"><-</span> equal len,<span class="Constant"> 0</span> <span class="muControl">break-unless</span> empty? - result<span class="Special"> <- </span>new <span class="Delimiter">{</span>(address array character): type<span class="Delimiter">}</span>, <span class="Constant">0</span> + result <span class="Special"><-</span> new <span class="Delimiter">{</span>(address array character): type<span class="Delimiter">}</span>,<span class="Constant"> 0</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># count #pieces we need room for</span> - count:num<span class="Special"> <- </span>copy <span class="Constant">1</span> <span class="Comment"># n delimiters = n+1 pieces</span> - idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + count:num <span class="Special"><-</span> copy<span class="Constant"> 1</span> <span class="Comment"># n delimiters = n+1 pieces</span> + idx:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - idx<span class="Special"> <- </span>find-next s, delim, idx - done?:bool<span class="Special"> <- </span>greater-or-equal idx, len + idx <span class="Special"><-</span> find-next s, delim, idx + done?:bool <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> + 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<span class="Special"> <- </span>new <span class="Delimiter">{</span>(address array character): type<span class="Delimiter">}</span>, count + result <span class="Special"><-</span> new <span class="Delimiter">{</span>(address array character): type<span class="Delimiter">}</span>, count <span class="Comment"># repeatedly copy slices start..end until delimiter into result[curr-result]</span> - curr-result:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - start:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + curr-result:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + start:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="Comment"># while next delim exists</span> - done?:bool<span class="Special"> <- </span>greater-or-equal start, len + done?:bool <span class="Special"><-</span> greater-or-equal start, len <span class="muControl">break-if</span> done? - end:num<span class="Special"> <- </span>find-next s, delim, start + end:num <span class="Special"><-</span> find-next s, delim, start <span class="Comment"># copy start..end into result[curr-result]</span> - dest:text<span class="Special"> <- </span>copy-range s, start, end - *result<span class="Special"> <- </span>put-index *result, curr-result, dest + dest:text <span class="Special"><-</span> copy-range s, start, end + *result <span class="Special"><-</span> put-index *result, curr-result, dest <span class="Comment"># slide over to next slice</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> + 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="muScenario">scenario</span> text-split-1 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[a/b]</span> run [ - y:&:@:text<span class="Special"> <- </span>split x, <span class="Constant">47/slash</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>length *y - a:text<span class="Special"> <- </span>index *y, <span class="Constant">0</span> - b:text<span class="Special"> <- </span>index *y, <span class="Constant">1</span> - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *a - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *b + y:&:@:text <span class="Special"><-</span> split x, <span class="Constant">47/slash</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> length *y + a:text <span class="Special"><-</span> index *y,<span class="Constant"> 0</span> + b:text <span class="Special"><-</span> index *y,<span class="Constant"> 1</span> + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *a + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *b ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># length of result</span> - <span class="Constant">20</span>:array:character<span class="Special"> <- </span><span class="Constant">[a]</span> - <span class="Constant">30</span>:array:character<span class="Special"> <- </span><span class="Constant">[b]</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 2</span> <span class="Comment"># length of result</span> + 20:array:character <span class="Special"><-</span> <span class="Constant">[a]</span> + 30:array:character <span class="Special"><-</span> <span class="Constant">[b]</span> ] ] <span class="muScenario">scenario</span> text-split-2 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[a/b/c]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[a/b/c]</span> run [ - y:&:@:text<span class="Special"> <- </span>split x, <span class="Constant">47/slash</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>length *y - a:text<span class="Special"> <- </span>index *y, <span class="Constant">0</span> - b:text<span class="Special"> <- </span>index *y, <span class="Constant">1</span> - c:text<span class="Special"> <- </span>index *y, <span class="Constant">2</span> - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *a - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *b - <span class="Constant">40</span>:@:char/<span class="Special">raw <- </span>copy *c + y:&:@:text <span class="Special"><-</span> split x, <span class="Constant">47/slash</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> length *y + a:text <span class="Special"><-</span> index *y,<span class="Constant"> 0</span> + b:text <span class="Special"><-</span> index *y,<span class="Constant"> 1</span> + c:text <span class="Special"><-</span> index *y,<span class="Constant"> 2</span> + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *a + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *b + 40:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *c ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># length of result</span> - <span class="Constant">20</span>:array:character<span class="Special"> <- </span><span class="Constant">[a]</span> - <span class="Constant">30</span>:array:character<span class="Special"> <- </span><span class="Constant">[b]</span> - <span class="Constant">40</span>:array:character<span class="Special"> <- </span><span class="Constant">[c]</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 3</span> <span class="Comment"># length of result</span> + 20:array:character <span class="Special"><-</span> <span class="Constant">[a]</span> + 30:array:character <span class="Special"><-</span> <span class="Constant">[b]</span> + 40:array:character <span class="Special"><-</span> <span class="Constant">[c]</span> ] ] <span class="muScenario">scenario</span> text-split-missing [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - y:&:@:text<span class="Special"> <- </span>split x, <span class="Constant">47/slash</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>length *y - a:text<span class="Special"> <- </span>index *y, <span class="Constant">0</span> - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *a + y:&:@:text <span class="Special"><-</span> split x, <span class="Constant">47/slash</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> length *y + a:text <span class="Special"><-</span> index *y,<span class="Constant"> 0</span> + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *a ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># length of result</span> - <span class="Constant">20</span>:array:character<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># length of result</span> + 20:array:character <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> text-split-empty [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[]</span> run [ - y:&:@:text<span class="Special"> <- </span>split x, <span class="Constant">47/slash</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>length *y + y:&:@:text <span class="Special"><-</span> split x, <span class="Constant">47/slash</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> length *y ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty result</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># empty result</span> ] ] <span class="muScenario">scenario</span> text-split-empty-piece [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[a/b//c]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[a/b//c]</span> run [ - y:&:@:text<span class="Special"> <- </span>split x:text, <span class="Constant">47/slash</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>length *y - a:text<span class="Special"> <- </span>index *y, <span class="Constant">0</span> - b:text<span class="Special"> <- </span>index *y, <span class="Constant">1</span> - c:text<span class="Special"> <- </span>index *y, <span class="Constant">2</span> - d:text<span class="Special"> <- </span>index *y, <span class="Constant">3</span> - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *a - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *b - <span class="Constant">40</span>:@:char/<span class="Special">raw <- </span>copy *c - <span class="Constant">50</span>:@:char/<span class="Special">raw <- </span>copy *d + y:&:@:text <span class="Special"><-</span> split x:text, <span class="Constant">47/slash</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> length *y + a:text <span class="Special"><-</span> index *y,<span class="Constant"> 0</span> + b:text <span class="Special"><-</span> index *y,<span class="Constant"> 1</span> + c:text <span class="Special"><-</span> index *y,<span class="Constant"> 2</span> + d:text <span class="Special"><-</span> index *y,<span class="Constant"> 3</span> + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *a + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *b + 40:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *c + 50:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *d ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># length of result</span> - <span class="Constant">20</span>:array:character<span class="Special"> <- </span><span class="Constant">[a]</span> - <span class="Constant">30</span>:array:character<span class="Special"> <- </span><span class="Constant">[b]</span> - <span class="Constant">40</span>:array:character<span class="Special"> <- </span><span class="Constant">[]</span> - <span class="Constant">50</span>:array:character<span class="Special"> <- </span><span class="Constant">[c]</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># length of result</span> + 20:array:character <span class="Special"><-</span> <span class="Constant">[a]</span> + 30:array:character <span class="Special"><-</span> <span class="Constant">[b]</span> + 40:array:character <span class="Special"><-</span> <span class="Constant">[]</span> + 50:array:character <span class="Special"><-</span> <span class="Constant">[c]</span> ] ] @@ -1255,31 +1255,31 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># empty text? return empty texts</span> - len:num<span class="Special"> <- </span>length *text + len:num <span class="Special"><-</span> length *text <span class="Delimiter">{</span> - empty?:bool<span class="Special"> <- </span>equal len, <span class="Constant">0</span> + empty?:bool <span class="Special"><-</span> equal len,<span class="Constant"> 0</span> <span class="muControl">break-unless</span> empty? - x:text<span class="Special"> <- </span>new <span class="Constant">[]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[]</span> <span class="muControl">return</span> <span class="Delimiter">}</span> - idx:num<span class="Special"> <- </span>find-next text, delim, <span class="Constant">0</span> - x:text<span class="Special"> <- </span>copy-range text, <span class="Constant">0</span>, idx - idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> - y:text<span class="Special"> <- </span>copy-range text, idx, len + idx:num <span class="Special"><-</span> find-next text, delim,<span class="Constant"> 0</span> + x:text <span class="Special"><-</span> copy-range text,<span class="Constant"> 0</span>, idx + idx <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> + y:text <span class="Special"><-</span> copy-range text, idx, len ] <span class="muScenario">scenario</span> text-split-first [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[a/b]</span> run [ - y:text, z:text<span class="Special"> <- </span>split-first x, <span class="Constant">47/slash</span> - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *y - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *z + y:text, z:text <span class="Special"><-</span> split-first x, <span class="Constant">47/slash</span> + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[a]</span> - <span class="Constant">20</span>:array:character<span class="Special"> <- </span><span class="Constant">[b]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[a]</span> + 20:array:character <span class="Special"><-</span> <span class="Constant">[b]</span> ] ] @@ -1287,58 +1287,58 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if end is out of bounds, trim it</span> - len:num<span class="Special"> <- </span>length *buf - end:num<span class="Special"> <- </span>min len, end + len:num <span class="Special"><-</span> length *buf + end:num <span class="Special"><-</span> min len, end <span class="Comment"># allocate space for result</span> - len<span class="Special"> <- </span>subtract end, start - result:text<span class="Special"> <- </span>new <span class="Constant">character:type</span>, len + len <span class="Special"><-</span> subtract end, start + result:text <span class="Special"><-</span> new <span class="Constant">character:type</span>, len <span class="Comment"># copy start..end into result[curr-result]</span> - src-idx:num<span class="Special"> <- </span>copy start - dest-idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + src-idx:num <span class="Special"><-</span> copy start + dest-idx:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal src-idx, end + done?:bool <span class="Special"><-</span> greater-or-equal src-idx, end <span class="muControl">break-if</span> done? - src:char<span class="Special"> <- </span>index *buf, src-idx - *result<span class="Special"> <- </span>put-index *result, dest-idx, 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> + src:char <span class="Special"><-</span> index *buf, src-idx + *result <span class="Special"><-</span> put-index *result, dest-idx, 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="muScenario">scenario</span> copy-range-works [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - y:text<span class="Special"> <- </span>copy-range x, <span class="Constant">1</span>, <span class="Constant">3</span> - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *y + y:text <span class="Special"><-</span> copy-range x,<span class="Constant"> 1</span>,<span class="Constant"> 3</span> + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[bc]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[bc]</span> ] ] <span class="muScenario">scenario</span> copy-range-out-of-bounds [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - y:text<span class="Special"> <- </span>copy-range x, <span class="Constant">2</span>, <span class="Constant">4</span> - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *y + y:text <span class="Special"><-</span> copy-range x,<span class="Constant"> 2</span>,<span class="Constant"> 4</span> + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[c]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[c]</span> ] ] <span class="muScenario">scenario</span> copy-range-out-of-bounds-2 [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> run [ - y:text<span class="Special"> <- </span>copy-range x, <span class="Constant">3</span>, <span class="Constant">3</span> - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *y + y:text <span class="Special"><-</span> copy-range x,<span class="Constant"> 3</span>,<span class="Constant"> 3</span> + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[]</span> ] ] </pre> diff --git a/html/063array.mu.html b/html/063array.mu.html index a668d466..4eb8544f 100644 --- a/html/063array.mu.html +++ b/html/063array.mu.html @@ -34,39 +34,39 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> array-from-args [ run [ <span class="Constant">local-scope</span> - x:&:@:num<span class="Special"> <- </span>new-array <span class="Constant">0</span>, <span class="Constant">1</span>, <span class="Constant">2</span> - <span class="Constant">10</span>:@:num/<span class="Special">raw <- </span>copy *x + x:&:@:num <span class="Special"><-</span> new-array<span class="Constant"> 0</span>,<span class="Constant"> 1</span>,<span class="Constant"> 2</span> + 10:@:num/<span class="Special">raw</span> <span class="Special"><-</span> copy *x ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># array length</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">1</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">2</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 3</span> <span class="Comment"># array length</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 1</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 2</span> ] ] <span class="Comment"># create an array out of a list of args</span> <span class="muRecipe">def</span> new-array<span class="muRecipe"> -> </span>result:&:@:_elem [ <span class="Constant">local-scope</span> - capacity:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + capacity:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="Comment"># while read curr-value</span> - curr-value:_elem, exists?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + curr-value:_elem, exists?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="muControl">break-unless</span> exists? - capacity<span class="Special"> <- </span>add capacity, <span class="Constant">1</span> + capacity <span class="Special"><-</span> add capacity,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>new <span class="Constant">_elem:type</span>, capacity + result <span class="Special"><-</span> new <span class="Constant">_elem:type</span>, capacity <span class="Constant">rewind-ingredients</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="Comment"># while read curr-value</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, capacity + done?:bool <span class="Special"><-</span> greater-or-equal i, capacity <span class="muControl">break-if</span> done? - curr-value:_elem, exists?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + curr-value:_elem, exists?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> assert exists?, <span class="Constant">[error in rewinding ingredients to new-array]</span> - *result<span class="Special"> <- </span>put-index *result, i, curr-value - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + *result <span class="Special"><-</span> put-index *result, i, 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">return</span> result @@ -77,62 +77,62 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> fill array:&:@:num<span class="muRecipe"> -> </span>array:&:@:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - loopn:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - length:num<span class="Special"> <- </span>length *array + loopn:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + length:num <span class="Special"><-</span> length *array <span class="Delimiter">{</span> - length?:bool<span class="Special"> <- </span>equal loopn, length + length?:bool <span class="Special"><-</span> equal loopn, length <span class="muControl">break-if</span> length? - object:num, arg-received?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + object:num, arg-received?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="muControl">break-unless</span> arg-received? - *array<span class="Special"> <- </span>put-index *array, loopn, object - loopn<span class="Special"> <- </span>add loopn, <span class="Constant">1</span> + *array <span class="Special"><-</span> put-index *array, loopn, object + loopn <span class="Special"><-</span> add loopn,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muScenario">scenario</span> fill-on-an-empty-array [ <span class="Constant">local-scope</span> - array:&:@:num<span class="Special"> <- </span>new <span class="Constant">number:type</span>, <span class="Constant">3</span> + array:&:@:num <span class="Special"><-</span> new <span class="Constant">number:type</span>,<span class="Constant"> 3</span> run [ - array<span class="Special"> <- </span>fill array, <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> - <span class="Constant">10</span>:@:num/<span class="Special">raw <- </span>copy *array + array <span class="Special"><-</span> fill array,<span class="Constant"> 1 2 3</span> + 10:@:num/<span class="Special">raw</span> <span class="Special"><-</span> copy *array ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">2</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 2</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 3</span> ] ] <span class="muScenario">scenario</span> fill-overwrites-existing-values [ <span class="Constant">local-scope</span> - array:&:@:num<span class="Special"> <- </span>new <span class="Constant">number:type</span>, <span class="Constant">3</span> - *array<span class="Special"> <- </span>put-index *array, <span class="Constant">0</span>, <span class="Constant">4</span> + array:&:@:num <span class="Special"><-</span> new <span class="Constant">number:type</span>,<span class="Constant"> 3</span> + *array <span class="Special"><-</span> put-index *array,<span class="Constant"> 0</span>,<span class="Constant"> 4</span> run [ - array<span class="Special"> <- </span>fill array, <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> - <span class="Constant">10</span>:@:num/<span class="Special">raw <- </span>copy *array + array <span class="Special"><-</span> fill array,<span class="Constant"> 1 2 3</span> + 10:@:num/<span class="Special">raw</span> <span class="Special"><-</span> copy *array ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">2</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 2</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 3</span> ] ] <span class="muScenario">scenario</span> fill-exits-gracefully-when-given-no-ingredients [ <span class="Constant">local-scope</span> - array:&:@:num<span class="Special"> <- </span>new <span class="Constant">number:type</span>, <span class="Constant">3</span> + array:&:@:num <span class="Special"><-</span> new <span class="Constant">number:type</span>,<span class="Constant"> 3</span> run [ - array<span class="Special"> <- </span>fill array - <span class="Constant">10</span>:@:num/<span class="Special">raw <- </span>copy *array + array <span class="Special"><-</span> fill array + 10:@:num/<span class="Special">raw</span> <span class="Special"><-</span> copy *array ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</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">0</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</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"> 0</span> ] ] @@ -141,24 +141,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> swap array:&:@:num, index1:num, index2:num<span class="muRecipe"> -> </span>array:&:@:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - object1:num<span class="Special"> <- </span>index *array, index1 - object2:num<span class="Special"> <- </span>index *array, index2 - *array<span class="Special"> <- </span>put-index *array, index1, object2 - *array<span class="Special"> <- </span>put-index *array, index2, object1 + object1:num <span class="Special"><-</span> index *array, index1 + object2:num <span class="Special"><-</span> index *array, index2 + *array <span class="Special"><-</span> put-index *array, index1, object2 + *array <span class="Special"><-</span> put-index *array, index2, object1 ] <span class="muScenario">scenario</span> swap-works [ <span class="Constant">local-scope</span> - array:&:@:num<span class="Special"> <- </span>new <span class="Constant">number:type</span>, <span class="Constant">4</span> - array<span class="Special"> <- </span>fill array, <span class="Constant">4</span> <span class="Constant">3</span> <span class="Constant">2</span> <span class="Constant">1</span> + array:&:@:num <span class="Special"><-</span> new <span class="Constant">number:type</span>,<span class="Constant"> 4</span> + array <span class="Special"><-</span> fill array,<span class="Constant"> 4 3 2 1</span> run [ - array<span class="Special"> <- </span>swap array, <span class="Constant">0</span>, <span class="Constant">2</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>index *array, <span class="Constant">0</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>index *array, <span class="Constant">2</span> + array <span class="Special"><-</span> swap array,<span class="Constant"> 0</span>,<span class="Constant"> 2</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> index *array,<span class="Constant"> 0</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> index *array,<span class="Constant"> 2</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">2</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 2</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 4</span> ] ] @@ -167,49 +167,49 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> reverse array:&:@:_elem<span class="muRecipe"> -> </span>array:&:@:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - start:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - length:num<span class="Special"> <- </span>length *array - end:num<span class="Special"> <- </span>subtract length, <span class="Constant">1</span> + start:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + length:num <span class="Special"><-</span> length *array + end:num <span class="Special"><-</span> subtract length,<span class="Constant"> 1</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal start, end + done?:bool <span class="Special"><-</span> greater-or-equal start, end <span class="muControl">break-if</span> done? - array<span class="Special"> <- </span>swap array, start, end - start<span class="Special"> <- </span>add start, <span class="Constant">1</span> - end<span class="Special"> <- </span>subtract end, <span class="Constant">1</span> + array <span class="Special"><-</span> swap array, start, end + start <span class="Special"><-</span> add start,<span class="Constant"> 1</span> + end <span class="Special"><-</span> subtract end,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muScenario">scenario</span> reverse-array-odd-length [ <span class="Constant">local-scope</span> - array:&:@:num<span class="Special"> <- </span>new <span class="Constant">number:type</span>, <span class="Constant">3</span> - array<span class="Special"> <- </span>fill array, <span class="Constant">3</span> <span class="Constant">2</span> <span class="Constant">1</span> + array:&:@:num <span class="Special"><-</span> new <span class="Constant">number:type</span>,<span class="Constant"> 3</span> + array <span class="Special"><-</span> fill array,<span class="Constant"> 3 2 1</span> run [ - array<span class="Special"> <- </span>reverse array - <span class="Constant">10</span>:@:num/<span class="Special">raw <- </span>copy *array + array <span class="Special"><-</span> reverse array + 10:@:num/<span class="Special">raw</span> <span class="Special"><-</span> copy *array ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">2</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 2</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 3</span> ] ] <span class="muScenario">scenario</span> reverse-array-even-length [ <span class="Constant">local-scope</span> - array:&:@:num<span class="Special"> <- </span>new <span class="Constant">number:type</span>, <span class="Constant">4</span> - array<span class="Special"> <- </span>fill array, <span class="Constant">4</span> <span class="Constant">3</span> <span class="Constant">2</span> <span class="Constant">1</span> + array:&:@:num <span class="Special"><-</span> new <span class="Constant">number:type</span>,<span class="Constant"> 4</span> + array <span class="Special"><-</span> fill array,<span class="Constant"> 4 3 2 1</span> run [ - array<span class="Special"> <- </span>reverse array - <span class="Constant">10</span>:@:num/<span class="Special">raw <- </span>copy *array + array <span class="Special"><-</span> reverse array + 10:@:num/<span class="Special">raw</span> <span class="Special"><-</span> copy *array ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">2</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">4</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 2</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 4</span> ] ] </pre> diff --git a/html/064list.mu.html b/html/064list.mu.html index 8d9a38ec..9ca8a1d7 100644 --- a/html/064list.mu.html +++ b/html/064list.mu.html @@ -45,139 +45,139 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> push x:_elem, l:&:list:_elem<span class="muRecipe"> -> </span>l:&:list:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result:&:list:_elem<span class="Special"> <- </span>new <span class="Delimiter">{</span>(list _elem): type<span class="Delimiter">}</span> - *result<span class="Special"> <- </span>merge x, l + result:&:list:_elem <span class="Special"><-</span> new <span class="Delimiter">{</span>(list _elem): type<span class="Delimiter">}</span> + *result <span class="Special"><-</span> merge x, l <span class="muControl">reply</span> result ] <span class="muRecipe">def</span> first in:&:list:_elem<span class="muRecipe"> -> </span>result:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>get *in, <span class="Constant">value:offset</span> + result <span class="Special"><-</span> get *in, <span class="Constant">value:offset</span> ] <span class="muRecipe">def</span> rest in:&:list:_elem<span class="muRecipe"> -> </span>result:&:list:_elem/contained-in:in [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>get *in, <span class="Constant">next:offset</span> + result <span class="Special"><-</span> get *in, <span class="Constant">next:offset</span> ] <span class="muScenario">scenario</span> list-handling [ run [ <span class="Constant">local-scope</span> - x:&:list:num<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - x<span class="Special"> <- </span>push <span class="Constant">4</span>, x - x<span class="Special"> <- </span>push <span class="Constant">5</span>, x - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>first x - x<span class="Special"> <- </span>rest x - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>first x - x<span class="Special"> <- </span>rest x - <span class="Constant">12</span>:num/<span class="Special">raw <- </span>first x - <span class="Constant">20</span>:&:list:num/<span class="Special">raw <- </span>rest x + x:&:list:num <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + x <span class="Special"><-</span> push<span class="Constant"> 4</span>, x + x <span class="Special"><-</span> push<span class="Constant"> 5</span>, x + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> first x + x <span class="Special"><-</span> rest x + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> first x + x <span class="Special"><-</span> rest x + 12:num/<span class="Special">raw</span> <span class="Special"><-</span> first x + 20:&:list:num/<span class="Special">raw</span> <span class="Special"><-</span> rest x ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">5</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># nothing left</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 5</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># nothing left</span> ] ] <span class="muRecipe">def</span> length l:&:list:_elem<span class="muRecipe"> -> </span>result:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">return-unless</span> l, <span class="Constant">0</span> - rest:&:list:_elem<span class="Special"> <- </span>rest l - length-of-rest:num<span class="Special"> <- </span>length rest - result<span class="Special"> <- </span>add length-of-rest, <span class="Constant">1</span> + <span class="muControl">return-unless</span> l,<span class="Constant"> 0</span> + rest:&:list:_elem <span class="Special"><-</span> rest l + length-of-rest:num <span class="Special"><-</span> length rest + result <span class="Special"><-</span> add length-of-rest,<span class="Constant"> 1</span> ] <span class="Comment"># insert 'x' after 'in'</span> <span class="muRecipe">def</span> insert x:_elem, in:&:list:_elem<span class="muRecipe"> -> </span>in:&:list:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - new-node:&:list:_elem<span class="Special"> <- </span>new <span class="Delimiter">{</span>(list _elem): type<span class="Delimiter">}</span> - *new-node<span class="Special"> <- </span>put *new-node, <span class="Constant">value:offset</span>, x - next-node:&:list:_elem<span class="Special"> <- </span>get *in, <span class="Constant">next:offset</span> - *in<span class="Special"> <- </span>put *in, <span class="Constant">next:offset</span>, new-node - *new-node<span class="Special"> <- </span>put *new-node, <span class="Constant">next:offset</span>, next-node + new-node:&:list:_elem <span class="Special"><-</span> new <span class="Delimiter">{</span>(list _elem): type<span class="Delimiter">}</span> + *new-node <span class="Special"><-</span> put *new-node, <span class="Constant">value:offset</span>, x + next-node:&:list:_elem <span class="Special"><-</span> get *in, <span class="Constant">next:offset</span> + *in <span class="Special"><-</span> put *in, <span class="Constant">next:offset</span>, new-node + *new-node <span class="Special"><-</span> put *new-node, <span class="Constant">next:offset</span>, next-node ] <span class="muScenario">scenario</span> inserting-into-list [ <span class="Constant">local-scope</span> - list:&:list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list2:&:list:char<span class="Special"> <- </span>rest list <span class="Comment"># inside list</span> - list2<span class="Special"> <- </span>insert <span class="Constant">6</span>, list2 + list2:&:list:char <span class="Special"><-</span> rest list <span class="Comment"># inside list</span> + list2 <span class="Special"><-</span> insert<span class="Constant"> 6</span>, list2 <span class="Comment"># check structure</span> - list2<span class="Special"> <- </span>copy list - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">13</span>:char/<span class="Special">raw <- </span>first list2 + list2 <span class="Special"><-</span> copy list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 13:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># inserted element</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 3</span> ] ] <span class="muScenario">scenario</span> inserting-at-end-of-list [ <span class="Constant">local-scope</span> - list:&:list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list2:&:list:char<span class="Special"> <- </span>rest list <span class="Comment"># inside list</span> - list2<span class="Special"> <- </span>rest list2 <span class="Comment"># now at end of list</span> - list2<span class="Special"> <- </span>insert <span class="Constant">6</span>, list2 + list2:&:list:char <span class="Special"><-</span> rest list <span class="Comment"># inside list</span> + list2 <span class="Special"><-</span> rest list2 <span class="Comment"># now at end of list</span> + list2 <span class="Special"><-</span> insert<span class="Constant"> 6</span>, list2 <span class="Comment"># check structure like before</span> - list2<span class="Special"> <- </span>copy list - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">13</span>:char/<span class="Special">raw <- </span>first list2 + list2 <span class="Special"><-</span> copy list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 13:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># inserted element</span> ] ] <span class="muScenario">scenario</span> inserting-after-start-of-list [ <span class="Constant">local-scope</span> - list:&:list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list<span class="Special"> <- </span>insert <span class="Constant">6</span>, list + list <span class="Special"><-</span> insert<span class="Constant"> 6</span>, list <span class="Comment"># check structure like before</span> - list2:&:list:char<span class="Special"> <- </span>copy list - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">13</span>:char/<span class="Special">raw <- </span>first list2 + list2:&:list:char <span class="Special"><-</span> copy list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 13:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># inserted element</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 3</span> ] ] @@ -190,106 +190,106 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Comment"># if 'x' is null, return</span> <span class="muControl">return-unless</span> x - next-node:&:list:_elem<span class="Special"> <- </span>rest x + next-node:&:list:_elem <span class="Special"><-</span> rest x <span class="Comment"># clear next pointer of 'x'</span> - *x<span class="Special"> <- </span>put *x, <span class="Constant">next:offset</span>, <span class="Constant">0</span> + *x <span class="Special"><-</span> put *x, <span class="Constant">next:offset</span>,<span class="Constant"> 0</span> <span class="Comment"># if 'x' is at the head of 'in', return the new head</span> - at-head?:bool<span class="Special"> <- </span>equal x, in + at-head?:bool <span class="Special"><-</span> equal x, in <span class="muControl">return-if</span> at-head?, next-node <span class="Comment"># compute prev-node</span> - prev-node:&:list:_elem<span class="Special"> <- </span>copy in - curr:&:list:_elem<span class="Special"> <- </span>rest prev-node + prev-node:&:list:_elem <span class="Special"><-</span> copy in + curr:&:list:_elem <span class="Special"><-</span> rest prev-node <span class="Delimiter">{</span> <span class="muControl">return-unless</span> curr - found?:bool<span class="Special"> <- </span>equal curr, x + found?:bool <span class="Special"><-</span> equal curr, x <span class="muControl">break-if</span> found? - prev-node<span class="Special"> <- </span>copy curr - curr<span class="Special"> <- </span>rest curr + prev-node <span class="Special"><-</span> copy curr + curr <span class="Special"><-</span> rest curr <span class="Delimiter">}</span> <span class="Comment"># set its next pointer to skip 'x'</span> - *prev-node<span class="Special"> <- </span>put *prev-node, <span class="Constant">next:offset</span>, next-node + *prev-node <span class="Special"><-</span> put *prev-node, <span class="Constant">next:offset</span>, next-node ] <span class="muScenario">scenario</span> removing-from-list [ <span class="Constant">local-scope</span> - list:&:list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list2:&:list:char<span class="Special"> <- </span>rest list <span class="Comment"># second element</span> - list<span class="Special"> <- </span>remove list2, list - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal list2, <span class="Constant">0</span> + list2:&:list:char <span class="Special"><-</span> rest list <span class="Comment"># second element</span> + list <span class="Special"><-</span> remove list2, list + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list2,<span class="Constant"> 0</span> <span class="Comment"># check structure like before</span> - list2<span class="Special"> <- </span>copy list - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">20</span>:&:list:char/<span class="Special">raw <- </span>rest list2 + list2 <span class="Special"><-</span> copy list + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 20:&:list:char/<span class="Special">raw</span> <span class="Special"><-</span> rest list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># remove returned non-null</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next, skipping deleted element</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># remove returned non-null</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># no more elements</span> ] ] <span class="muScenario">scenario</span> removing-from-start-of-list [ <span class="Constant">local-scope</span> - list:&:list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list<span class="Special"> <- </span>remove list, list + list <span class="Special"><-</span> remove list, list <span class="Comment"># check structure like before</span> - list2:&:list:char<span class="Special"> <- </span>copy list - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">20</span>:&:list:char/<span class="Special">raw <- </span>rest list2 + list2:&:list:char <span class="Special"><-</span> copy list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 20:&:list:char/<span class="Special">raw</span> <span class="Special"><-</span> rest list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># scanning next, skipping deleted element</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># no more elements</span> ] ] <span class="muScenario">scenario</span> removing-from-end-of-list [ <span class="Constant">local-scope</span> - list:&:list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ <span class="Comment"># delete last element</span> - list2:&:list:char<span class="Special"> <- </span>rest list - list2<span class="Special"> <- </span>rest list2 - list<span class="Special"> <- </span>remove list2, list - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal list2, <span class="Constant">0</span> + list2:&:list:char <span class="Special"><-</span> rest list + list2 <span class="Special"><-</span> rest list2 + list <span class="Special"><-</span> remove list2, list + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list2,<span class="Constant"> 0</span> <span class="Comment"># check structure like before</span> - list2<span class="Special"> <- </span>copy list - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>rest list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">20</span>:&:list:char/<span class="Special">raw <- </span>rest list2 + list2 <span class="Special"><-</span> copy list + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> rest list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 20:&:list:char/<span class="Special">raw</span> <span class="Special"><-</span> rest list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># remove returned non-null</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next, skipping deleted element</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># remove returned non-null</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># no more elements</span> ] ] <span class="muScenario">scenario</span> removing-from-singleton-list [ <span class="Constant">local-scope</span> - list:&:list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> + list:&:list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> run [ - list<span class="Special"> <- </span>remove list, list - <span class="Constant">1</span>:num/<span class="Special">raw <- </span>copy list + list <span class="Special"><-</span> remove list, list + 1:num/<span class="Special">raw</span> <span class="Special"><-</span> copy list ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># back to an empty list</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># back to an empty list</span> ] ] @@ -299,43 +299,43 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">reply-unless</span> list, temp - object:_elem<span class="Special"> <- </span>first, list - list<span class="Special"> <- </span>rest list - temp<span class="Special"> <- </span>push object, temp - result<span class="Special"> <- </span>reverse list, temp + object:_elem <span class="Special"><-</span> first, list + list <span class="Special"><-</span> rest list + temp <span class="Special"><-</span> push object, temp + result <span class="Special"><-</span> reverse list, temp ] <span class="muScenario">scenario</span> reverse-list [ <span class="Constant">local-scope</span> - list:&:list:number<span class="Special"> <- </span>push <span class="Constant">1</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">2</span>, list - list<span class="Special"> <- </span>push <span class="Constant">3</span>, list + list:&:list:number <span class="Special"><-</span> push<span class="Constant"> 1</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 2</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 3</span>, list run [ stash <span class="Constant">[list:]</span>, list - list<span class="Special"> <- </span>reverse list + list <span class="Special"><-</span> reverse list stash <span class="Constant">[reversed:]</span>, list ] trace-should-contain [ - app: list: <span class="Constant">3</span><span class="muRecipe"> -> </span><span class="Constant">2</span><span class="muRecipe"> -> </span><span class="Constant">1</span> - app: reversed: <span class="Constant">1</span><span class="muRecipe"> -> </span><span class="Constant">2</span><span class="muRecipe"> -> </span><span class="Constant">3</span> + app: list:<span class="Constant"> 3</span><span class="muRecipe"> -> </span>2<span class="muRecipe"> -> </span>1 + app: reversed:<span class="Constant"> 1</span><span class="muRecipe"> -> </span>2<span class="muRecipe"> -> </span>3 ] ] <span class="muRecipe">def</span> to-text in:&:list:_elem<span class="muRecipe"> -> </span>result:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">80</span> - buf<span class="Special"> <- </span>to-buffer in, buf - result<span class="Special"> <- </span>buffer-to-array buf + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 80</span> + buf <span class="Special"><-</span> to-buffer in, buf + result <span class="Special"><-</span> buffer-to-array buf ] <span class="Comment"># variant of 'to-text' which stops printing after a few elements (and so is robust to cycles)</span> <span class="muRecipe">def</span> to-text-line in:&:list:_elem<span class="muRecipe"> -> </span>result:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">80</span> - buf<span class="Special"> <- </span>to-buffer in, buf, <span class="Constant">6</span> <span class="Comment"># max elements to display</span> - result<span class="Special"> <- </span>buffer-to-array buf + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 80</span> + buf <span class="Special"><-</span> to-buffer in, buf,<span class="Constant"> 6</span> <span class="Comment"># max elements to display</span> + result <span class="Special"><-</span> buffer-to-array buf ] <span class="muRecipe">def</span> to-buffer in:&:list:_elem, buf:&:buffer<span class="muRecipe"> -> </span>buf:&:buffer [ @@ -343,30 +343,30 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> in - buf<span class="Special"> <- </span>append buf, <span class="Constant">[[]</span>] + buf <span class="Special"><-</span> append buf, <span class="Constant">[[]</span>] <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># append in.value to buf</span> - val:_elem<span class="Special"> <- </span>get *in, <span class="Constant">value:offset</span> - buf<span class="Special"> <- </span>append buf, val + val:_elem <span class="Special"><-</span> get *in, <span class="Constant">value:offset</span> + buf <span class="Special"><-</span> append buf, val <span class="Comment"># now prepare next</span> - next:&:list:_elem<span class="Special"> <- </span>rest in - nextn:num<span class="Special"> <- </span>copy next + next:&:list:_elem <span class="Special"><-</span> rest in + nextn:num <span class="Special"><-</span> copy next <span class="muControl">return-unless</span> next - buf<span class="Special"> <- </span>append buf, <span class="Constant">[ -> ]</span> + buf <span class="Special"><-</span> append buf, <span class="Constant">[ -> ]</span> <span class="Comment"># and recurse</span> - remaining:num, optional-ingredient-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + remaining:num, optional-ingredient-found?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> optional-ingredient-found? <span class="Comment"># unlimited recursion</span> - buf<span class="Special"> <- </span>to-buffer next, buf + buf <span class="Special"><-</span> to-buffer next, buf <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> remaining <span class="Comment"># limited recursion</span> - remaining<span class="Special"> <- </span>subtract remaining, <span class="Constant">1</span> - buf<span class="Special"> <- </span>to-buffer next, buf, remaining + remaining <span class="Special"><-</span> subtract remaining,<span class="Constant"> 1</span> + buf <span class="Special"><-</span> to-buffer next, buf, remaining <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># past recursion depth; insert ellipses and stop</span> @@ -375,7 +375,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> stash-empty-list [ <span class="Constant">local-scope</span> - x:&:list:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + x:&:list:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> run [ stash x ] diff --git a/html/065duplex_list.mu.html b/html/065duplex_list.mu.html index af84549a..ce239cde 100644 --- a/html/065duplex_list.mu.html +++ b/html/065duplex_list.mu.html @@ -44,11 +44,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> push x:_elem, in:&:duplex-list:_elem<span class="muRecipe"> -> </span>in:&:duplex-list:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result:&:duplex-list:_elem<span class="Special"> <- </span>new <span class="Delimiter">{</span>(duplex-list _elem): type<span class="Delimiter">}</span> - *result<span class="Special"> <- </span>merge x, in, <span class="Constant">0</span> + result:&:duplex-list:_elem <span class="Special"><-</span> new <span class="Delimiter">{</span>(duplex-list _elem): type<span class="Delimiter">}</span> + *result <span class="Special"><-</span> merge x, in,<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> in - *in<span class="Special"> <- </span>put *in, <span class="Constant">prev:offset</span>, result + *in <span class="Special"><-</span> put *in, <span class="Constant">prev:offset</span>, result <span class="Delimiter">}</span> <span class="muControl">return</span> result <span class="Comment"># needed explicitly because we need to replace 'in' with 'result'</span> ] @@ -56,22 +56,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> first in:&:duplex-list:_elem<span class="muRecipe"> -> </span>result:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">return-unless</span> in, <span class="Constant">0</span> - result<span class="Special"> <- </span>get *in, <span class="Constant">value:offset</span> + <span class="muControl">return-unless</span> in,<span class="Constant"> 0</span> + result <span class="Special"><-</span> get *in, <span class="Constant">value:offset</span> ] <span class="muRecipe">def</span> next in:&:duplex-list:_elem<span class="muRecipe"> -> </span>result:&:duplex-list:_elem/contained-in:in [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">return-unless</span> in, <span class="Constant">0</span> - result<span class="Special"> <- </span>get *in, <span class="Constant">next:offset</span> + <span class="muControl">return-unless</span> in,<span class="Constant"> 0</span> + result <span class="Special"><-</span> get *in, <span class="Constant">next:offset</span> ] <span class="muRecipe">def</span> prev in:&:duplex-list:_elem<span class="muRecipe"> -> </span>result:&:duplex-list:_elem/contained-in:in [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">return-unless</span> in, <span class="Constant">0</span> - result<span class="Special"> <- </span>get *in, <span class="Constant">prev:offset</span> + <span class="muControl">return-unless</span> in,<span class="Constant"> 0</span> + result <span class="Special"><-</span> get *in, <span class="Constant">prev:offset</span> <span class="muControl">return</span> result ] @@ -79,41 +79,41 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ <span class="Constant">local-scope</span> <span class="Comment"># reserve locations 0-9 to check for missing null check</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>copy <span class="Constant">34</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>copy <span class="Constant">35</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list - list2:&:duplex-list:char<span class="Special"> <- </span>copy list - <span class="Constant">20</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">21</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">22</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">30</span>:&:duplex-list:char/<span class="Special">raw <- </span>next list2 - <span class="Constant">31</span>:char/<span class="Special">raw <- </span>first <span class="Constant">30</span>:&:duplex-list:char/<span class="Special">raw</span> - <span class="Constant">32</span>:&:duplex-list:char/<span class="Special">raw <- </span>next <span class="Constant">30</span>:&:duplex-list:char/<span class="Special">raw</span> - <span class="Constant">33</span>:&:duplex-list:char/<span class="Special">raw <- </span>prev <span class="Constant">30</span>:&:duplex-list:char/<span class="Special">raw</span> - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">40</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">41</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">50</span>:bool/<span class="Special">raw <- </span>equal list, list2 + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> copy<span class="Constant"> 34</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> copy<span class="Constant"> 35</span> + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list + list2:&:duplex-list:char <span class="Special"><-</span> copy list + 20:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 21:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 22:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 30:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next list2 + 31:char/<span class="Special">raw</span> <span class="Special"><-</span> first 30:&:duplex-list:char/<span class="Special">raw</span> + 32:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next 30:&:duplex-list:char/<span class="Special">raw</span> + 33:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> prev 30:&:duplex-list:char/<span class="Special">raw</span> + list2 <span class="Special"><-</span> prev list2 + 40:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 41:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 50:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list, list2 ] memory-should-contain [ - <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">10</span><span class="Special"> <- </span><span class="Constant">34</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">35</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> - <span class="Constant">21</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">22</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># null</span> - <span class="Constant">31</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first of null</span> - <span class="Constant">32</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># next of null</span> - <span class="Constant">33</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># prev of null</span> - <span class="Constant">40</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># then start scanning prev</span> - <span class="Constant">41</span><span class="Special"> <- </span><span class="Constant">5</span> - <span class="Constant">50</span><span class="Special"> <- </span><span class="Constant">1</span> <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"> 10</span> <span class="Special"><-</span><span class="Constant"> 34</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 35</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next</span> + <span class="Constant"> 21</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 22</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 30</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># null</span> + <span class="Constant"> 31</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># first of null</span> + <span class="Constant"> 32</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># next of null</span> + <span class="Constant"> 33</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># prev of null</span> + <span class="Constant"> 40</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># then start scanning prev</span> + <span class="Constant"> 41</span> <span class="Special"><-</span><span class="Constant"> 5</span> + <span class="Constant"> 50</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># list back at start</span> ] ] @@ -121,125 +121,125 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> insert x:_elem, in:&:duplex-list:_elem<span class="muRecipe"> -> </span>in:&:duplex-list:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - new-node:&:duplex-list:_elem<span class="Special"> <- </span>new <span class="Delimiter">{</span>(duplex-list _elem): type<span class="Delimiter">}</span> - *new-node<span class="Special"> <- </span>put *new-node, <span class="Constant">value:offset</span>, x + new-node:&:duplex-list:_elem <span class="Special"><-</span> new <span class="Delimiter">{</span>(duplex-list _elem): type<span class="Delimiter">}</span> + *new-node <span class="Special"><-</span> put *new-node, <span class="Constant">value:offset</span>, x <span class="Comment"># save old next before changing it</span> - next-node:&:duplex-list:_elem<span class="Special"> <- </span>get *in, <span class="Constant">next:offset</span> - *in<span class="Special"> <- </span>put *in, <span class="Constant">next:offset</span>, new-node - *new-node<span class="Special"> <- </span>put *new-node, <span class="Constant">prev:offset</span>, in - *new-node<span class="Special"> <- </span>put *new-node, <span class="Constant">next:offset</span>, next-node + next-node:&:duplex-list:_elem <span class="Special"><-</span> get *in, <span class="Constant">next:offset</span> + *in <span class="Special"><-</span> put *in, <span class="Constant">next:offset</span>, new-node + *new-node <span class="Special"><-</span> put *new-node, <span class="Constant">prev:offset</span>, in + *new-node <span class="Special"><-</span> put *new-node, <span class="Constant">next:offset</span>, next-node <span class="muControl">return-unless</span> next-node - *next-node<span class="Special"> <- </span>put *next-node, <span class="Constant">prev:offset</span>, new-node + *next-node <span class="Special"><-</span> put *next-node, <span class="Constant">prev:offset</span>, new-node ] <span class="muScenario">scenario</span> inserting-into-duplex-list [ <span class="Constant">local-scope</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list2:&:duplex-list:char<span class="Special"> <- </span>next list <span class="Comment"># inside list</span> - list2<span class="Special"> <- </span>insert <span class="Constant">6</span>, list2 + list2:&:duplex-list:char <span class="Special"><-</span> next list <span class="Comment"># inside list</span> + list2 <span class="Special"><-</span> insert<span class="Constant"> 6</span>, list2 <span class="Comment"># check structure like before</span> - list2<span class="Special"> <- </span>copy list - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">13</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">20</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">21</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">22</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">30</span>:bool/<span class="Special">raw <- </span>equal list, list2 + list2 <span class="Special"><-</span> copy list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 13:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 20:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 21:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 22:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 30:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list, list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># then prev</span> - <span class="Constant">21</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">22</span><span class="Special"> <- </span><span class="Constant">5</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># inserted element</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># then prev</span> + <span class="Constant"> 21</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 22</span> <span class="Special"><-</span><span class="Constant"> 5</span> + <span class="Constant"> 30</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 [ <span class="Constant">local-scope</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list2:&:duplex-list:char<span class="Special"> <- </span>next list <span class="Comment"># inside list</span> - list2<span class="Special"> <- </span>next list2 <span class="Comment"># now at end of list</span> - list2<span class="Special"> <- </span>insert <span class="Constant">6</span>, list2 + list2:&:duplex-list:char <span class="Special"><-</span> next list <span class="Comment"># inside list</span> + list2 <span class="Special"><-</span> next list2 <span class="Comment"># now at end of list</span> + list2 <span class="Special"><-</span> insert<span class="Constant"> 6</span>, list2 <span class="Comment"># check structure like before</span> - list2<span class="Special"> <- </span>copy list - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">13</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">20</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">21</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">22</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">30</span>:bool/<span class="Special">raw <- </span>equal list, list2 + list2 <span class="Special"><-</span> copy list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 13:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 20:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 21:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 22:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 30:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list, list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># then prev</span> - <span class="Constant">21</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">22</span><span class="Special"> <- </span><span class="Constant">5</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># inserted element</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 3</span> <span class="Comment"># then prev</span> + <span class="Constant"> 21</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 22</span> <span class="Special"><-</span><span class="Constant"> 5</span> + <span class="Constant"> 30</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 [ <span class="Constant">local-scope</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list<span class="Special"> <- </span>insert <span class="Constant">6</span>, list + list <span class="Special"><-</span> insert<span class="Constant"> 6</span>, list <span class="Comment"># check structure like before</span> - list2:&:duplex-list:char<span class="Special"> <- </span>copy list - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">13</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">20</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">21</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">22</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">30</span>:bool/<span class="Special">raw <- </span>equal list, list2 + list2:&:duplex-list:char <span class="Special"><-</span> copy list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 13:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 20:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 21:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> prev list2 + 22:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 30:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list, list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># inserted element</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># then prev</span> - <span class="Constant">21</span><span class="Special"> <- </span><span class="Constant">6</span> - <span class="Constant">22</span><span class="Special"> <- </span><span class="Constant">5</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># inserted element</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># then prev</span> + <span class="Constant"> 21</span> <span class="Special"><-</span><span class="Constant"> 6</span> + <span class="Constant"> 22</span> <span class="Special"><-</span><span class="Constant"> 5</span> + <span class="Constant"> 30</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># list back at start</span> ] ] @@ -252,20 +252,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Comment"># if 'x' is null, return</span> <span class="muControl">return-unless</span> x - next-node:&:duplex-list:_elem<span class="Special"> <- </span>get *x, <span class="Constant">next:offset</span> - prev-node:&:duplex-list:_elem<span class="Special"> <- </span>get *x, <span class="Constant">prev:offset</span> + next-node:&:duplex-list:_elem <span class="Special"><-</span> get *x, <span class="Constant">next:offset</span> + prev-node:&:duplex-list:_elem <span class="Special"><-</span> get *x, <span class="Constant">prev:offset</span> <span class="Comment"># null x's pointers</span> - *x<span class="Special"> <- </span>put *x, <span class="Constant">next:offset</span>, <span class="Constant">0</span> - *x<span class="Special"> <- </span>put *x, <span class="Constant">prev:offset</span>, <span class="Constant">0</span> + *x <span class="Special"><-</span> put *x, <span class="Constant">next:offset</span>,<span class="Constant"> 0</span> + *x <span class="Special"><-</span> put *x, <span class="Constant">prev:offset</span>,<span class="Constant"> 0</span> <span class="Comment"># if next-node is not null, set its prev pointer</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> next-node - *next-node<span class="Special"> <- </span>put *next-node, <span class="Constant">prev:offset</span>, prev-node + *next-node <span class="Special"><-</span> put *next-node, <span class="Constant">prev:offset</span>, prev-node <span class="Delimiter">}</span> <span class="Comment"># if prev-node is not null, set its next pointer and return</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> prev-node - *prev-node<span class="Special"> <- </span>put *prev-node, <span class="Constant">next:offset</span>, next-node + *prev-node <span class="Special"><-</span> put *prev-node, <span class="Constant">next:offset</span>, next-node <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># if prev-node is null, then we removed the head node at 'in'</span> @@ -275,99 +275,99 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> removing-from-duplex-list [ <span class="Constant">local-scope</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list2:&:duplex-list:char<span class="Special"> <- </span>next list <span class="Comment"># second element</span> - list<span class="Special"> <- </span>remove list2, list - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal list2, <span class="Constant">0</span> + list2:&:duplex-list:char <span class="Special"><-</span> next list <span class="Comment"># second element</span> + list <span class="Special"><-</span> remove list2, list + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list2,<span class="Constant"> 0</span> <span class="Comment"># check structure like before</span> - list2<span class="Special"> <- </span>copy list - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">20</span>:&:duplex-list:char/<span class="Special">raw <- </span>next list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">30</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">40</span>:bool/<span class="Special">raw <- </span>equal list, list2 + list2 <span class="Special"><-</span> copy list + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 20:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next list2 + list2 <span class="Special"><-</span> prev list2 + 30:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 40:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list, list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># remove returned non-null</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next, skipping deleted element</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># prev of final element</span> - <span class="Constant">40</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># remove returned non-null</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># no more elements</span> + <span class="Constant"> 30</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># prev of final element</span> + <span class="Constant"> 40</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 [ <span class="Constant">local-scope</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ - list<span class="Special"> <- </span>remove list, list + list <span class="Special"><-</span> remove list, list <span class="Comment"># check structure like before</span> - list2:&:duplex-list:char<span class="Special"> <- </span>copy list - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">20</span>:&:duplex-list:char/<span class="Special">raw <- </span>next list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">30</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">40</span>:bool/<span class="Special">raw <- </span>equal list, list2 + list2:&:duplex-list:char <span class="Special"><-</span> copy list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 20:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next list2 + list2 <span class="Special"><-</span> prev list2 + 30:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 40:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list, list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># scanning next, skipping deleted element</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># prev of final element</span> - <span class="Constant">40</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># no more elements</span> + <span class="Constant"> 30</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># prev of final element</span> + <span class="Constant"> 40</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 [ <span class="Constant">local-scope</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">4</span>, list - list<span class="Special"> <- </span>push <span class="Constant">5</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 4</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 5</span>, list run [ <span class="Comment"># delete last element</span> - list2:&:duplex-list:char<span class="Special"> <- </span>next list - list2<span class="Special"> <- </span>next list2 - list<span class="Special"> <- </span>remove list2, list - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal list2, <span class="Constant">0</span> + list2:&:duplex-list:char <span class="Special"><-</span> next list + list2 <span class="Special"><-</span> next list2 + list <span class="Special"><-</span> remove list2, list + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list2,<span class="Constant"> 0</span> <span class="Comment"># check structure like before</span> - list2<span class="Special"> <- </span>copy list - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>first list2 - list2<span class="Special"> <- </span>next list2 - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">20</span>:&:duplex-list:char/<span class="Special">raw <- </span>next list2 - list2<span class="Special"> <- </span>prev list2 - <span class="Constant">30</span>:char/<span class="Special">raw <- </span>first list2 - <span class="Constant">40</span>:bool/<span class="Special">raw <- </span>equal list, list2 + list2 <span class="Special"><-</span> copy list + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + list2 <span class="Special"><-</span> next list2 + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 20:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next list2 + list2 <span class="Special"><-</span> prev list2 + 30:char/<span class="Special">raw</span> <span class="Special"><-</span> first list2 + 40:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal list, list2 ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># remove returned non-null</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># scanning next, skipping deleted element</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">4</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">5</span> <span class="Comment"># prev of final element</span> - <span class="Constant">40</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># list back at start</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># remove returned non-null</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># scanning next, skipping deleted element</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 4</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># no more elements</span> + <span class="Constant"> 30</span> <span class="Special"><-</span><span class="Constant"> 5</span> <span class="Comment"># prev of final element</span> + <span class="Constant"> 40</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-duplex-list [ <span class="Constant">local-scope</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">3</span>, <span class="Constant">0</span> + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 3</span>,<span class="Constant"> 0</span> run [ - list<span class="Special"> <- </span>remove list, list - <span class="Constant">1</span>:num/<span class="Special">raw <- </span>copy list + list <span class="Special"><-</span> remove list, list + 1:num/<span class="Special">raw</span> <span class="Special"><-</span> copy list ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># back to an empty list</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># back to an empty list</span> ] ] @@ -379,139 +379,139 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> remove-between start:&:duplex-list:_elem, end:&:duplex-list:_elem/contained-in:start<span class="muRecipe"> -> </span>start:&:duplex-list:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - next:&:duplex-list:_elem<span class="Special"> <- </span>get *start, <span class="Constant">next:offset</span> - nothing-to-delete?:bool<span class="Special"> <- </span>equal next, end + next:&:duplex-list:_elem <span class="Special"><-</span> get *start, <span class="Constant">next:offset</span> + nothing-to-delete?:bool <span class="Special"><-</span> equal next, end <span class="muControl">return-if</span> nothing-to-delete? assert next, <span class="Constant">[malformed duplex list]</span> <span class="Comment"># start->next->prev = 0</span> <span class="Comment"># start->next = end</span> - *next<span class="Special"> <- </span>put *next, <span class="Constant">prev:offset</span>, <span class="Constant">0</span> - *start<span class="Special"> <- </span>put *start, <span class="Constant">next:offset</span>, end + *next <span class="Special"><-</span> put *next, <span class="Constant">prev:offset</span>,<span class="Constant"> 0</span> + *start <span class="Special"><-</span> put *start, <span class="Constant">next:offset</span>, end <span class="muControl">return-unless</span> end <span class="Comment"># end->prev->next = 0</span> <span class="Comment"># end->prev = start</span> - prev:&:duplex-list:_elem<span class="Special"> <- </span>get *end, <span class="Constant">prev:offset</span> + prev:&:duplex-list:_elem <span class="Special"><-</span> get *end, <span class="Constant">prev:offset</span> assert prev, <span class="Constant">[malformed duplex list - 2]</span> - *prev<span class="Special"> <- </span>put *prev, <span class="Constant">next:offset</span>, <span class="Constant">0</span> - *end<span class="Special"> <- </span>put *end, <span class="Constant">prev:offset</span>, start + *prev <span class="Special"><-</span> put *prev, <span class="Constant">next:offset</span>,<span class="Constant"> 0</span> + *end <span class="Special"><-</span> put *end, <span class="Constant">prev:offset</span>, start ] <span class="muScenario">scenario</span> remove-range [ <span class="Comment"># construct a duplex list with six elements [13, 14, 15, 16, 17, 18]</span> <span class="Constant">local-scope</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">18</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">17</span>, list - list<span class="Special"> <- </span>push <span class="Constant">16</span>, list - list<span class="Special"> <- </span>push <span class="Constant">15</span>, list - list<span class="Special"> <- </span>push <span class="Constant">14</span>, list - list<span class="Special"> <- </span>push <span class="Constant">13</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 18</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 17</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 16</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 15</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 14</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 13</span>, list run [ <span class="Comment"># delete 16 onwards</span> <span class="Comment"># first pointer: to the third element</span> - list2:&:duplex-list:char<span class="Special"> <- </span>next list - list2<span class="Special"> <- </span>next list2 - list2<span class="Special"> <- </span>remove-between list2, <span class="Constant">0</span> + list2:&:duplex-list:char <span class="Special"><-</span> next list + list2 <span class="Special"><-</span> next list2 + list2 <span class="Special"><-</span> remove-between list2,<span class="Constant"> 0</span> <span class="Comment"># now check the list</span> - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - list<span class="Special"> <- </span>next list - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - list<span class="Special"> <- </span>next list - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - <span class="Constant">20</span>:&:duplex-list:char/<span class="Special">raw <- </span>next list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + list <span class="Special"><-</span> next list + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + list <span class="Special"><-</span> next list + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + 20:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next list ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">13</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">14</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">15</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 13</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 14</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 15</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> remove-range-to-final [ <span class="Constant">local-scope</span> <span class="Comment"># construct a duplex list with six elements [13, 14, 15, 16, 17, 18]</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">18</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">17</span>, list - list<span class="Special"> <- </span>push <span class="Constant">16</span>, list - list<span class="Special"> <- </span>push <span class="Constant">15</span>, list - list<span class="Special"> <- </span>push <span class="Constant">14</span>, list - list<span class="Special"> <- </span>push <span class="Constant">13</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 18</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 17</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 16</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 15</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 14</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 13</span>, list run [ <span class="Comment"># delete 15, 16 and 17</span> <span class="Comment"># start pointer: to the second element</span> - list2:&:duplex-list:char<span class="Special"> <- </span>next list + list2:&:duplex-list:char <span class="Special"><-</span> next list <span class="Comment"># end pointer: to the last (sixth) element</span> - end:&:duplex-list:char<span class="Special"> <- </span>next list2 - end<span class="Special"> <- </span>next end - end<span class="Special"> <- </span>next end - end<span class="Special"> <- </span>next end + end:&:duplex-list:char <span class="Special"><-</span> next list2 + end <span class="Special"><-</span> next end + end <span class="Special"><-</span> next end + end <span class="Special"><-</span> next end remove-between list2, end <span class="Comment"># now check the list</span> - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - list<span class="Special"> <- </span>next list - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - list<span class="Special"> <- </span>next list - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - <span class="Constant">20</span>:&:duplex-list:char/<span class="Special">raw <- </span>next list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + list <span class="Special"><-</span> next list + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + list <span class="Special"><-</span> next list + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + 20:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next list ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">13</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">14</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">18</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># no more elements</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 13</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 14</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 18</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># no more elements</span> ] ] <span class="muScenario">scenario</span> remove-range-empty [ <span class="Constant">local-scope</span> <span class="Comment"># construct a duplex list with three elements [13, 14, 15]</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">15</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">14</span>, list - list<span class="Special"> <- </span>push <span class="Constant">13</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 15</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 14</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 13</span>, list run [ <span class="Comment"># delete between first and second element (i.e. nothing)</span> - list2:&:duplex-list:char<span class="Special"> <- </span>next list + list2:&:duplex-list:char <span class="Special"><-</span> next list remove-between list, list2 <span class="Comment"># now check the list</span> - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - list<span class="Special"> <- </span>next list - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - list<span class="Special"> <- </span>next list - <span class="Constant">12</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - <span class="Constant">20</span>:&:duplex-list:char/<span class="Special">raw <- </span>next list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + list <span class="Special"><-</span> next list + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + list <span class="Special"><-</span> next list + 12:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + 20:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next list ] <span class="Comment"># no change</span> memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">13</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">14</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">15</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 13</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 14</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 15</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> remove-range-to-end [ <span class="Constant">local-scope</span> <span class="Comment"># construct a duplex list with six elements [13, 14, 15, 16, 17, 18]</span> - list:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">18</span>, <span class="Constant">0</span> - list<span class="Special"> <- </span>push <span class="Constant">17</span>, list - list<span class="Special"> <- </span>push <span class="Constant">16</span>, list - list<span class="Special"> <- </span>push <span class="Constant">15</span>, list - list<span class="Special"> <- </span>push <span class="Constant">14</span>, list - list<span class="Special"> <- </span>push <span class="Constant">13</span>, list + list:&:duplex-list:char <span class="Special"><-</span> push<span class="Constant"> 18</span>,<span class="Constant"> 0</span> + list <span class="Special"><-</span> push<span class="Constant"> 17</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 16</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 15</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 14</span>, list + list <span class="Special"><-</span> push<span class="Constant"> 13</span>, list run [ <span class="Comment"># remove the third element and beyond</span> - list2:&:duplex-list:char<span class="Special"> <- </span>next list - remove-between list2, <span class="Constant">0</span> + list2:&:duplex-list:char <span class="Special"><-</span> next list + remove-between list2,<span class="Constant"> 0</span> <span class="Comment"># now check the list</span> - <span class="Constant">10</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - list<span class="Special"> <- </span>next list - <span class="Constant">11</span>:char/<span class="Special">raw <- </span>get *list, <span class="Constant">value:offset</span> - <span class="Constant">20</span>:&:duplex-list:char/<span class="Special">raw <- </span>next list + 10:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + list <span class="Special"><-</span> next list + 11:char/<span class="Special">raw</span> <span class="Special"><-</span> get *list, <span class="Constant">value:offset</span> + 20:&:duplex-list:char/<span class="Special">raw</span> <span class="Special"><-</span> next list ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">13</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">14</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 13</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 14</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] @@ -521,40 +521,40 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="muControl">return-unless</span> in <span class="muControl">return-unless</span> start - end:&:duplex-list:_elem<span class="Special"> <- </span>copy start + end:&:duplex-list:_elem <span class="Special"><-</span> copy start <span class="Delimiter">{</span> - next:&:duplex-list:_elem<span class="Special"> <- </span>next end/insert-range + next:&:duplex-list:_elem <span class="Special"><-</span> next end/insert-range <span class="muControl">break-unless</span> next - end<span class="Special"> <- </span>copy next + end <span class="Special"><-</span> copy next <span class="muControl">loop</span> <span class="Delimiter">}</span> - next:&:duplex-list:_elem<span class="Special"> <- </span>next in - *end<span class="Special"> <- </span>put *end, <span class="Constant">next:offset</span>, next + next:&:duplex-list:_elem <span class="Special"><-</span> next in + *end <span class="Special"><-</span> put *end, <span class="Constant">next:offset</span>, next <span class="Delimiter">{</span> <span class="muControl">break-unless</span> next - *next<span class="Special"> <- </span>put *next, <span class="Constant">prev:offset</span>, end + *next <span class="Special"><-</span> put *next, <span class="Constant">prev:offset</span>, end <span class="Delimiter">}</span> - *in<span class="Special"> <- </span>put *in, <span class="Constant">next:offset</span>, start - *start<span class="Special"> <- </span>put *start, <span class="Constant">prev:offset</span>, in + *in <span class="Special"><-</span> put *in, <span class="Constant">next:offset</span>, start + *start <span class="Special"><-</span> put *start, <span class="Constant">prev:offset</span>, in ] <span class="muRecipe">def</span> append in:&:duplex-list:_elem, new:&:duplex-list:_elem/contained-in:in<span class="muRecipe"> -> </span>in:&:duplex-list:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - last:&:duplex-list:_elem<span class="Special"> <- </span>last in - *last<span class="Special"> <- </span>put *last, <span class="Constant">next:offset</span>, new + last:&:duplex-list:_elem <span class="Special"><-</span> last in + *last <span class="Special"><-</span> put *last, <span class="Constant">next:offset</span>, new <span class="muControl">return-unless</span> new - *new<span class="Special"> <- </span>put *new, <span class="Constant">prev:offset</span>, last + *new <span class="Special"><-</span> put *new, <span class="Constant">prev:offset</span>, last ] <span class="muRecipe">def</span> last in:&:duplex-list:_elem<span class="muRecipe"> -> </span>result:&:duplex-list:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>copy in + result <span class="Special"><-</span> copy in <span class="Delimiter">{</span> - next:&:duplex-list:_elem<span class="Special"> <- </span>next result + next:&:duplex-list:_elem <span class="Special"><-</span> next result <span class="muControl">break-unless</span> next - result<span class="Special"> <- </span>copy next + result <span class="Special"><-</span> copy next <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -566,11 +566,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color $print x, <span class="Constant">[: ]</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> x - c:_elem<span class="Special"> <- </span>get *x, <span class="Constant">value:offset</span> + c:_elem <span class="Special"><-</span> get *x, <span class="Constant">value:offset</span> $print c, <span class="Constant">[ ]</span> - x<span class="Special"> <- </span>next x + x <span class="Special"><-</span> next x <span class="Delimiter">{</span> - is-newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + is-newline?:bool <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> is-newline? $print <span class="Constant">10/newline</span> $print x, <span class="Constant">[: ]</span> diff --git a/html/066stream.mu.html b/html/066stream.mu.html index c477233c..4c3cd3a6 100644 --- a/html/066stream.mu.html +++ b/html/066stream.mu.html @@ -40,70 +40,70 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-stream s:&:@:_elem<span class="muRecipe"> -> </span>result:&:stream:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>new <span class="Delimiter">{</span>(stream _elem): type<span class="Delimiter">}</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">index:offset</span>, <span class="Constant">0</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">data:offset</span>, s + result <span class="Special"><-</span> new <span class="Delimiter">{</span>(stream _elem): type<span class="Delimiter">}</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">index:offset</span>,<span class="Constant"> 0</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">data:offset</span>, s ] <span class="muRecipe">def</span> rewind in:&:stream:_elem<span class="muRecipe"> -> </span>in:&:stream:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - *in<span class="Special"> <- </span>put *in, <span class="Constant">index:offset</span>, <span class="Constant">0</span> + *in <span class="Special"><-</span> put *in, <span class="Constant">index:offset</span>,<span class="Constant"> 0</span> ] <span class="muRecipe">def</span> read in:&:stream:_elem<span class="muRecipe"> -> </span>result:_elem, empty?:bool, in:&:stream:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - empty?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> - idx:num<span class="Special"> <- </span>get *in, <span class="Constant">index:offset</span> - s:&:@:_elem<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> - len:num<span class="Special"> <- </span>length *s - at-end?:bool<span class="Special"> <- </span>greater-or-equal idx len + empty? <span class="Special"><-</span> copy <span class="Constant">0/false</span> + idx:num <span class="Special"><-</span> get *in, <span class="Constant">index:offset</span> + s:&:@:_elem <span class="Special"><-</span> get *in, <span class="Constant">data:offset</span> + len:num <span class="Special"><-</span> length *s + at-end?:bool <span class="Special"><-</span> greater-or-equal idx len <span class="Delimiter">{</span> <span class="muControl">break-unless</span> at-end? - empty-result:&:_elem<span class="Special"> <- </span>new <span class="Constant">_elem:type</span> + empty-result:&:_elem <span class="Special"><-</span> new <span class="Constant">_elem:type</span> <span class="muControl">return</span> *empty-result, <span class="Constant">1/true</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>index *s, idx - idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> - *in<span class="Special"> <- </span>put *in, <span class="Constant">index:offset</span>, idx + result <span class="Special"><-</span> index *s, idx + idx <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> + *in <span class="Special"><-</span> put *in, <span class="Constant">index:offset</span>, idx ] <span class="muRecipe">def</span> peek in:&:stream:_elem<span class="muRecipe"> -> </span>result:_elem, empty?:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - empty?:bool<span class="Special"> <- </span>copy <span class="Constant">0/false</span> - idx:num<span class="Special"> <- </span>get *in, <span class="Constant">index:offset</span> - s:&:@:_elem<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> - len:num<span class="Special"> <- </span>length *s - at-end?:bool<span class="Special"> <- </span>greater-or-equal idx len + empty?:bool <span class="Special"><-</span> copy <span class="Constant">0/false</span> + idx:num <span class="Special"><-</span> get *in, <span class="Constant">index:offset</span> + s:&:@:_elem <span class="Special"><-</span> get *in, <span class="Constant">data:offset</span> + len:num <span class="Special"><-</span> length *s + at-end?:bool <span class="Special"><-</span> greater-or-equal idx len <span class="Delimiter">{</span> <span class="muControl">break-unless</span> at-end? - empty-result:&:_elem<span class="Special"> <- </span>new <span class="Constant">_elem:type</span> + empty-result:&:_elem <span class="Special"><-</span> new <span class="Constant">_elem:type</span> <span class="muControl">return</span> *empty-result, <span class="Constant">1/true</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>index *s, idx + result <span class="Special"><-</span> index *s, idx ] <span class="muRecipe">def</span> read-line in:&:stream:char<span class="muRecipe"> -> </span>result:text, in:&:stream:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - idx:num<span class="Special"> <- </span>get *in, <span class="Constant">index:offset</span> - s:text<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> - next-idx:num<span class="Special"> <- </span>find-next s, <span class="Constant">10/newline</span>, idx - result<span class="Special"> <- </span>copy-range s, idx, next-idx - idx<span class="Special"> <- </span>add next-idx, <span class="Constant">1</span> <span class="Comment"># skip newline</span> + idx:num <span class="Special"><-</span> get *in, <span class="Constant">index:offset</span> + s:text <span class="Special"><-</span> get *in, <span class="Constant">data:offset</span> + next-idx:num <span class="Special"><-</span> find-next s, <span class="Constant">10/newline</span>, idx + result <span class="Special"><-</span> copy-range 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="Comment"># write back</span> - *in<span class="Special"> <- </span>put *in, <span class="Constant">index:offset</span>, idx + *in <span class="Special"><-</span> put *in, <span class="Constant">index:offset</span>, idx ] <span class="muRecipe">def</span> end-of-stream? in:&:stream:_elem<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - idx:num<span class="Special"> <- </span>get *in, <span class="Constant">index:offset</span> - s:&:@:_elem<span class="Special"> <- </span>get *in, <span class="Constant">data:offset</span> - len:num<span class="Special"> <- </span>length *s - result<span class="Special"> <- </span>greater-or-equal idx, len + idx:num <span class="Special"><-</span> get *in, <span class="Constant">index:offset</span> + s:&:@:_elem <span class="Special"><-</span> get *in, <span class="Constant">data:offset</span> + len:num <span class="Special"><-</span> length *s + result <span class="Special"><-</span> greater-or-equal idx, len ] </pre> </body> diff --git a/html/068random.mu.html b/html/068random.mu.html index 20b26659..05765f4e 100644 --- a/html/068random.mu.html +++ b/html/068random.mu.html @@ -37,10 +37,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="muControl">break-if</span> generator <span class="Comment"># generator is 0? use real random-number generator</span> - result<span class="Special"> <- </span>real-random + result <span class="Special"><-</span> real-random <span class="muControl">reply</span> result, <span class="Constant">0/false</span> <span class="Delimiter">}</span> - result, fail?, generator<span class="Special"> <- </span>read generator + result, fail?, generator <span class="Special"><-</span> read generator ] <span class="Comment"># helper for tests</span> @@ -48,61 +48,61 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># compute result-len, space to allocate in result</span> - result-len:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + result-len:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - _, arg-received?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + _, arg-received?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="muControl">break-unless</span> arg-received? - result-len<span class="Special"> <- </span>add result-len, <span class="Constant">1</span> + result-len <span class="Special"><-</span> add result-len,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Constant">rewind-ingredients</span> - result-data:&:@:num<span class="Special"> <- </span>new <span class="Constant">number:type</span>, result-len - idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + result-data:&:@:num <span class="Special"><-</span> new <span class="Constant">number:type</span>, result-len + idx:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - curr:num, arg-received?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + curr:num, arg-received?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="muControl">break-unless</span> arg-received? - *result-data<span class="Special"> <- </span>put-index *result-data, idx, curr - idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> + *result-data <span class="Special"><-</span> put-index *result-data, idx, curr + idx <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>new-stream result-data + result <span class="Special"><-</span> new-stream result-data ] <span class="muScenario">scenario</span> random-numbers-in-scenario [ <span class="Constant">local-scope</span> - source:&:stream:num<span class="Special"> <- </span>assume-random-numbers <span class="Constant">34</span>, <span class="Constant">35</span>, <span class="Constant">37</span> - <span class="Constant">1</span>:num/<span class="Special">raw</span>, <span class="Constant">2</span>:bool/<span class="Special">raw <- </span>random source - <span class="Constant">3</span>:num/<span class="Special">raw</span>, <span class="Constant">4</span>:bool/<span class="Special">raw <- </span>random source - <span class="Constant">5</span>:num/<span class="Special">raw</span>, <span class="Constant">6</span>:bool/<span class="Special">raw <- </span>random source - <span class="Constant">7</span>:num/<span class="Special">raw</span>, <span class="Constant">8</span>:bool/<span class="Special">raw <- </span>random source + source:&:stream:num <span class="Special"><-</span> assume-random-numbers<span class="Constant"> 34</span>,<span class="Constant"> 35</span>,<span class="Constant"> 37</span> + 1:num/<span class="Special">raw</span>, 2:bool/<span class="Special">raw</span> <span class="Special"><-</span> random source + 3:num/<span class="Special">raw</span>, 4:bool/<span class="Special">raw</span> <span class="Special"><-</span> random source + 5:num/<span class="Special">raw</span>, 6:bool/<span class="Special">raw</span> <span class="Special"><-</span> random source + 7:num/<span class="Special">raw</span>, 8:bool/<span class="Special">raw</span> <span class="Special"><-</span> random source memory-should-contain [ - <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">0</span> <span class="Comment"># everything went well</span> - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">35</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># everything went well</span> - <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">37</span> - <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># everything went well</span> - <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty result</span> - <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># end of stream</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"> 0</span> <span class="Comment"># everything went well</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 35</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># everything went well</span> + <span class="Constant"> 5</span> <span class="Special"><-</span><span class="Constant"> 37</span> + <span class="Constant"> 6</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># everything went well</span> + <span class="Constant"> 7</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># empty result</span> + <span class="Constant"> 8</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># end of stream</span> ] ] <span class="muRecipe">def</span> random-in-range generator:&:stream:num, start:num, end:num<span class="muRecipe"> -> </span>result:num, fail?:bool, generator:&:stream:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result, fail?, generator<span class="Special"> <- </span>random generator + result, fail?, generator <span class="Special"><-</span> random generator <span class="muControl">return-if</span> fail? - delta:num<span class="Special"> <- </span>subtract end, start - _, result<span class="Special"> <- </span>divide-with-remainder result, delta - result<span class="Special"> <- </span>add result, start + delta:num <span class="Special"><-</span> subtract end, start + _, result <span class="Special"><-</span> divide-with-remainder result, delta + result <span class="Special"><-</span> add result, start ] <span class="muScenario">scenario</span> random-in-range [ <span class="Constant">local-scope</span> - source:&:stream:num<span class="Special"> <- </span>assume-random-numbers <span class="Constant">91</span> - <span class="Constant">1</span>:num/<span class="Special">raw <- </span>random-in-range source, <span class="Constant">40</span>, <span class="Constant">50</span> + source:&:stream:num <span class="Special"><-</span> assume-random-numbers<span class="Constant"> 91</span> + 1:num/<span class="Special">raw</span> <span class="Special"><-</span> random-in-range source,<span class="Constant"> 40</span>,<span class="Constant"> 50</span> memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">41</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 41</span> ] ] </pre> diff --git a/html/070table.mu.html b/html/070table.mu.html index b144969e..91999624 100644 --- a/html/070table.mu.html +++ b/html/070table.mu.html @@ -37,26 +37,26 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> table-read-write [ <span class="Constant">local-scope</span> - tab:&:table:num:num<span class="Special"> <- </span>new-table <span class="Constant">30</span> + tab:&:table:num:num <span class="Special"><-</span> new-table<span class="Constant"> 30</span> run [ - put-index tab, <span class="Constant">12</span>, <span class="Constant">34</span> - <span class="Constant">1</span>:num/<span class="Special">raw <- </span>index tab, <span class="Constant">12</span> + put-index tab,<span class="Constant"> 12</span>,<span class="Constant"> 34</span> + 1:num/<span class="Special">raw</span> <span class="Special"><-</span> index tab,<span class="Constant"> 12</span> ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">34</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 34</span> ] ] <span class="muScenario">scenario</span> table-read-write-non-integer [ <span class="Constant">local-scope</span> - key:text<span class="Special"> <- </span>new <span class="Constant">[abc def]</span> - <span class="Delimiter">{</span>tab: (address table text number)<span class="Delimiter">}</span><span class="Special"> <- </span>new-table <span class="Constant">30</span> + key:text <span class="Special"><-</span> new <span class="Constant">[abc def]</span> + <span class="Delimiter">{</span>tab: (address table text number)<span class="Delimiter">}</span> <span class="Special"><-</span> new-table<span class="Constant"> 30</span> run [ - put-index tab, key, <span class="Constant">34</span> - <span class="Constant">1</span>:num/<span class="Special">raw <- </span>index tab, key + put-index tab, key,<span class="Constant"> 34</span> + 1:num/<span class="Special">raw</span> <span class="Special"><-</span> index tab, key ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">34</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 34</span> ] ] @@ -75,49 +75,49 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-table capacity:num<span class="muRecipe"> -> </span>result:&:table:_key:_value [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>new <span class="Delimiter">{</span>(table _key _value): type<span class="Delimiter">}</span> - data:&:@:table_row:_key:_value<span class="Special"> <- </span>new <span class="Delimiter">{</span>(table_row _key _value): type<span class="Delimiter">}</span>, capacity - *result<span class="Special"> <- </span>merge <span class="Constant">0/length</span>, capacity, data + result <span class="Special"><-</span> new <span class="Delimiter">{</span>(table _key _value): type<span class="Delimiter">}</span> + data:&:@:table_row:_key:_value <span class="Special"><-</span> new <span class="Delimiter">{</span>(table_row _key _value): type<span class="Delimiter">}</span>, capacity + *result <span class="Special"><-</span> merge <span class="Constant">0/length</span>, capacity, data ] <span class="muRecipe">def</span> put-index table:&:table:_key:_value, key:_key, value:_value<span class="muRecipe"> -> </span>table:&:table:_key:_value [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - hash:num<span class="Special"> <- </span>hash key - hash<span class="Special"> <- </span>abs hash - capacity:num<span class="Special"> <- </span>get *table, <span class="Constant">capacity:offset</span> - _, hash<span class="Special"> <- </span>divide-with-remainder hash, capacity - hash<span class="Special"> <- </span>abs hash <span class="Comment"># in case hash overflows into a negative integer</span> - table-data:&:@:table_row:_key:_value<span class="Special"> <- </span>get *table, <span class="Constant">data:offset</span> - x:table_row:_key:_value<span class="Special"> <- </span>index *table-data, hash - occupied?:bool<span class="Special"> <- </span>get x, <span class="Constant">occupied?:offset</span> - not-occupied?:bool<span class="Special"> <- </span>not occupied?:bool + hash:num <span class="Special"><-</span> hash key + hash <span class="Special"><-</span> abs hash + capacity:num <span class="Special"><-</span> get *table, <span class="Constant">capacity:offset</span> + _, hash <span class="Special"><-</span> divide-with-remainder hash, capacity + hash <span class="Special"><-</span> abs hash <span class="Comment"># in case hash overflows into a negative integer</span> + table-data:&:@:table_row:_key:_value <span class="Special"><-</span> get *table, <span class="Constant">data:offset</span> + x:table_row:_key:_value <span class="Special"><-</span> index *table-data, hash + occupied?:bool <span class="Special"><-</span> get x, <span class="Constant">occupied?:offset</span> + not-occupied?:bool <span class="Special"><-</span> not occupied?:bool assert not-occupied?, <span class="Constant">[can't handle collisions yet]</span> - new-row:table_row:_key:_value<span class="Special"> <- </span>merge <span class="Constant">1/true</span>, key, value - *table-data<span class="Special"> <- </span>put-index *table-data, hash, new-row + new-row:table_row:_key:_value <span class="Special"><-</span> merge <span class="Constant">1/true</span>, key, value + *table-data <span class="Special"><-</span> put-index *table-data, hash, new-row ] <span class="muRecipe">def</span> abs n:num<span class="muRecipe"> -> </span>result:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - positive?:bool<span class="Special"> <- </span>greater-or-equal n, <span class="Constant">0</span> + positive?:bool <span class="Special"><-</span> greater-or-equal n,<span class="Constant"> 0</span> <span class="muControl">return-if</span> positive?, n - result<span class="Special"> <- </span>multiply n, <span class="Constant">-1</span> + result <span class="Special"><-</span> multiply n,<span class="Constant"> -1</span> ] <span class="muRecipe">def</span> index table:&:table:_key:_value, key:_key<span class="muRecipe"> -> </span>result:_value [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - hash:num<span class="Special"> <- </span>hash key - hash<span class="Special"> <- </span>abs hash - capacity:num<span class="Special"> <- </span>get *table, <span class="Constant">capacity:offset</span> - _, hash<span class="Special"> <- </span>divide-with-remainder hash, capacity - hash<span class="Special"> <- </span>abs hash <span class="Comment"># in case hash overflows into a negative integer</span> - table-data:&:@:table_row:_key:_value<span class="Special"> <- </span>get *table, <span class="Constant">data:offset</span> - x:table_row:_key:_value<span class="Special"> <- </span>index *table-data, hash - occupied?:bool<span class="Special"> <- </span>get x, <span class="Constant">occupied?:offset</span> + hash:num <span class="Special"><-</span> hash key + hash <span class="Special"><-</span> abs hash + capacity:num <span class="Special"><-</span> get *table, <span class="Constant">capacity:offset</span> + _, hash <span class="Special"><-</span> divide-with-remainder hash, capacity + hash <span class="Special"><-</span> abs hash <span class="Comment"># in case hash overflows into a negative integer</span> + table-data:&:@:table_row:_key:_value <span class="Special"><-</span> get *table, <span class="Constant">data:offset</span> + x:table_row:_key:_value <span class="Special"><-</span> index *table-data, hash + occupied?:bool <span class="Special"><-</span> get x, <span class="Constant">occupied?:offset</span> assert occupied?, <span class="Constant">[can't handle missing elements yet]</span> - result<span class="Special"> <- </span>get x, <span class="Constant">value:offset</span> + result <span class="Special"><-</span> get x, <span class="Constant">value:offset</span> ] </pre> </body> diff --git a/html/075channel.mu.html b/html/075channel.mu.html index 94355181..42e8fda8 100644 --- a/html/075channel.mu.html +++ b/html/075channel.mu.html @@ -49,13 +49,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> channel [ run [ <span class="Constant">local-scope</span> - source:&:source:num, sink:&:sink:num<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">34</span> - <span class="Constant">10</span>:num/<span class="Special">raw</span>, <span class="Constant">11</span>:bool/<span class="Special">raw</span>, source<span class="Special"> <- </span>read source + source:&:source:num, sink:&:sink:num <span class="Special"><-</span> new-channel <span class="Constant">3/capacity</span> + sink <span class="Special"><-</span> write sink,<span class="Constant"> 34</span> + 10:num/<span class="Special">raw</span>, 11:bool/<span class="Special">raw</span>, source <span class="Special"><-</span> read source ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">34</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># read was successful</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 34</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># read was successful</span> ] ] @@ -83,32 +83,32 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-channel capacity:num<span class="muRecipe"> -> </span>in:&:source:_elem, out:&:sink:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result:&:channel:_elem<span class="Special"> <- </span>new <span class="Delimiter">{</span>(channel _elem): type<span class="Delimiter">}</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">first-full:offset</span>, <span class="Constant">0</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">first-free:offset</span>, <span class="Constant">0</span> - capacity<span class="Special"> <- </span>add capacity, <span class="Constant">1</span> <span class="Comment"># unused slot for 'full?' below</span> - data:&:@:_elem<span class="Special"> <- </span>new <span class="Constant">_elem:type</span>, capacity - *result<span class="Special"> <- </span>put *result, <span class="Constant">data:offset</span>, data - in<span class="Special"> <- </span>new <span class="Delimiter">{</span>(source _elem): type<span class="Delimiter">}</span> - *in<span class="Special"> <- </span>put *in, <span class="Constant">chan:offset</span>, result - out<span class="Special"> <- </span>new <span class="Delimiter">{</span>(sink _elem): type<span class="Delimiter">}</span> - *out<span class="Special"> <- </span>put *out, <span class="Constant">chan:offset</span>, result + result:&:channel:_elem <span class="Special"><-</span> new <span class="Delimiter">{</span>(channel _elem): type<span class="Delimiter">}</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">first-full:offset</span>,<span class="Constant"> 0</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">first-free:offset</span>,<span class="Constant"> 0</span> + capacity <span class="Special"><-</span> add capacity,<span class="Constant"> 1</span> <span class="Comment"># unused slot for 'full?' below</span> + data:&:@:_elem <span class="Special"><-</span> new <span class="Constant">_elem:type</span>, capacity + *result <span class="Special"><-</span> put *result, <span class="Constant">data:offset</span>, data + in <span class="Special"><-</span> new <span class="Delimiter">{</span>(source _elem): type<span class="Delimiter">}</span> + *in <span class="Special"><-</span> put *in, <span class="Constant">chan:offset</span>, result + out <span class="Special"><-</span> new <span class="Delimiter">{</span>(sink _elem): type<span class="Delimiter">}</span> + *out <span class="Special"><-</span> put *out, <span class="Constant">chan:offset</span>, result ] <span class="muRecipe">def</span> write out:&:sink:_elem, val:_elem<span class="muRecipe"> -> </span>out:&:sink:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> assert out, <span class="Constant">[write to null channel]</span> - chan:&:channel:_elem<span class="Special"> <- </span>get *out, <span class="Constant">chan:offset</span> + chan:&:channel:_elem <span class="Special"><-</span> get *out, <span class="Constant">chan:offset</span> <span class="Constant"> <channel-write-initial></span> <span class="Comment"># block until lock is acquired AND queue has room</span> - lock:location<span class="Special"> <- </span>get-location *chan, <span class="Constant">lock:offset</span> + lock:location <span class="Special"><-</span> get-location *chan, <span class="Constant">lock:offset</span> <span class="CommentedCode">#? $print [write], 10/newline</span> <span class="Delimiter">{</span> <span class="CommentedCode">#? $print [trying to acquire lock for writing], 10/newline</span> wait-for-reset-then-set lock <span class="CommentedCode">#? $print [lock acquired for writing], 10/newline</span> - full?:bool<span class="Special"> <- </span>channel-full? chan + full?:bool <span class="Special"><-</span> channel-full? chan <span class="muControl">break-unless</span> full? <span class="CommentedCode">#? $print [but channel is full; relinquishing lock], 10/newline</span> <span class="Comment"># channel is full; relinquish lock and give a reader the opportunity to</span> @@ -121,21 +121,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color current-routine-is-unblocked <span class="CommentedCode">#? $print [performing write], 10/newline</span> <span class="Comment"># store a deep copy of val</span> - circular-buffer:&:@:_elem<span class="Special"> <- </span>get *chan, <span class="Constant">data:offset</span> - free:num<span class="Special"> <- </span>get *chan, <span class="Constant">first-free:offset</span> - val-copy:_elem<span class="Special"> <- </span>deep-copy val <span class="Comment"># on this instruction rests all Mu's concurrency-safety</span> - *circular-buffer<span class="Special"> <- </span>put-index *circular-buffer, free, val-copy + circular-buffer:&:@:_elem <span class="Special"><-</span> get *chan, <span class="Constant">data:offset</span> + free:num <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> + val-copy:_elem <span class="Special"><-</span> deep-copy val <span class="Comment"># on this instruction rests all Mu's concurrency-safety</span> + *circular-buffer <span class="Special"><-</span> put-index *circular-buffer, free, val-copy <span class="Comment"># mark its slot as filled</span> - free<span class="Special"> <- </span>add free, <span class="Constant">1</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:num<span class="Special"> <- </span>length *circular-buffer - at-end?:bool<span class="Special"> <- </span>greater-or-equal free, len + len:num <span class="Special"><-</span> length *circular-buffer + at-end?:bool <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> + free <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">}</span> <span class="Comment"># write back</span> - *chan<span class="Special"> <- </span>put *chan, <span class="Constant">first-free:offset</span>, free + *chan <span class="Special"><-</span> put *chan, <span class="Constant">first-free:offset</span>, free <span class="CommentedCode">#? $print [relinquishing lock after writing], 10/newline</span> reset lock ] @@ -144,16 +144,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> assert in, <span class="Constant">[read on null channel]</span> - eof?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> <span class="Comment"># default result</span> - chan:&:channel:_elem<span class="Special"> <- </span>get *in, <span class="Constant">chan:offset</span> + eof? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="Comment"># default result</span> + chan:&:channel:_elem <span class="Special"><-</span> get *in, <span class="Constant">chan:offset</span> <span class="Comment"># block until lock is acquired AND queue has data</span> - lock:location<span class="Special"> <- </span>get-location *chan, <span class="Constant">lock:offset</span> + lock:location <span class="Special"><-</span> get-location *chan, <span class="Constant">lock:offset</span> <span class="CommentedCode">#? $print [read], 10/newline</span> <span class="Delimiter">{</span> <span class="CommentedCode">#? $print [trying to acquire lock for reading], 10/newline</span> wait-for-reset-then-set lock <span class="CommentedCode">#? $print [lock acquired for reading], 10/newline</span> - empty?:bool<span class="Special"> <- </span>channel-empty? chan + empty?:bool <span class="Special"><-</span> channel-empty? chan <span class="muControl">break-unless</span> empty? <span class="CommentedCode">#? $print [but channel is empty; relinquishing lock], 10/newline</span> <span class="Comment"># channel is empty; relinquish lock and give a writer the opportunity to</span> @@ -166,23 +166,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">}</span> current-routine-is-unblocked <span class="Comment"># pull result off</span> - full:num<span class="Special"> <- </span>get *chan, <span class="Constant">first-full:offset</span> - circular-buffer:&:@:_elem<span class="Special"> <- </span>get *chan, <span class="Constant">data:offset</span> - result<span class="Special"> <- </span>index *circular-buffer, full + full:num <span class="Special"><-</span> get *chan, <span class="Constant">first-full:offset</span> + circular-buffer:&:@:_elem <span class="Special"><-</span> get *chan, <span class="Constant">data:offset</span> + result <span class="Special"><-</span> index *circular-buffer, full <span class="Comment"># clear the slot</span> - empty:&:_elem<span class="Special"> <- </span>new <span class="Constant">_elem:type</span> - *circular-buffer<span class="Special"> <- </span>put-index *circular-buffer, full, *empty + empty:&:_elem <span class="Special"><-</span> new <span class="Constant">_elem:type</span> + *circular-buffer <span class="Special"><-</span> put-index *circular-buffer, full, *empty <span class="Comment"># mark its slot as empty</span> - full<span class="Special"> <- </span>add full, <span class="Constant">1</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:num<span class="Special"> <- </span>length *circular-buffer - at-end?:bool<span class="Special"> <- </span>greater-or-equal full, len + len:num <span class="Special"><-</span> length *circular-buffer + at-end?:bool <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> + full <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">}</span> <span class="Comment"># write back</span> - *chan<span class="Special"> <- </span>put *chan, <span class="Constant">first-full:offset</span>, full + *chan <span class="Special"><-</span> put *chan, <span class="Constant">first-full:offset</span>, full <span class="CommentedCode">#? $print [relinquishing lock after reading], 10/newline</span> reset lock ] @@ -190,143 +190,143 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> clear in:&:source:_elem<span class="muRecipe"> -> </span>in:&:source:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - chan:&:channel:_elem<span class="Special"> <- </span>get *in, <span class="Constant">chan:offset</span> + chan:&:channel:_elem <span class="Special"><-</span> get *in, <span class="Constant">chan:offset</span> <span class="Delimiter">{</span> - empty?:bool<span class="Special"> <- </span>channel-empty? chan + empty?:bool <span class="Special"><-</span> channel-empty? chan <span class="muControl">break-if</span> empty? - _, _, in<span class="Special"> <- </span>read in + _, _, in <span class="Special"><-</span> read in <span class="Delimiter">}</span> ] <span class="muScenario">scenario</span> channel-initialization [ run [ <span class="Constant">local-scope</span> - source:&:source:num<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> - chan:&:channel:num<span class="Special"> <- </span>get *source, <span class="Constant">chan:offset</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-full:offset</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-free:offset</span> + source:&:source:num <span class="Special"><-</span> new-channel <span class="Constant">3/capacity</span> + chan:&:channel:num <span class="Special"><-</span> get *source, <span class="Constant">chan:offset</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-full:offset</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-full</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-free</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># first-full</span> + <span class="Constant"> 11</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 [ <span class="Constant">local-scope</span> - _, sink:&:sink:num<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> + _, sink:&:sink:num <span class="Special"><-</span> new-channel <span class="Constant">3/capacity</span> run [ - sink<span class="Special"> <- </span>write sink, <span class="Constant">34</span> - chan:&:channel:num<span class="Special"> <- </span>get *sink, <span class="Constant">chan:offset</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-full:offset</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-free:offset</span> + sink <span class="Special"><-</span> write sink,<span class="Constant"> 34</span> + chan:&:channel:num <span class="Special"><-</span> get *sink, <span class="Constant">chan:offset</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-full:offset</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-full</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-free</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># first-full</span> + <span class="Constant"> 11</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 [ <span class="Constant">local-scope</span> - source:&:source:num, sink:&:sink:num<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">34</span> + source:&:source:num, sink:&:sink:num <span class="Special"><-</span> new-channel <span class="Constant">3/capacity</span> + sink <span class="Special"><-</span> write sink,<span class="Constant"> 34</span> run [ - _, _, source<span class="Special"> <- </span>read source - chan:&:channel:num<span class="Special"> <- </span>get *source, <span class="Constant">chan:offset</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-full:offset</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-free:offset</span> + _, _, source <span class="Special"><-</span> read source + chan:&:channel:num <span class="Special"><-</span> get *source, <span class="Constant">chan:offset</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-full:offset</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-full</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-free</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># first-full</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># first-free</span> ] ] <span class="muScenario">scenario</span> channel-wrap [ <span class="Constant">local-scope</span> <span class="Comment"># channel with just 1 slot</span> - source:&:source:num, sink:&:sink:num<span class="Special"> <- </span>new-channel <span class="Constant">1/capacity</span> - chan:&:channel:num<span class="Special"> <- </span>get *source, <span class="Constant">chan:offset</span> + source:&:source:num, sink:&:sink:num <span class="Special"><-</span> new-channel <span class="Constant">1/capacity</span> + chan:&:channel:num <span class="Special"><-</span> get *source, <span class="Constant">chan:offset</span> <span class="Comment"># write and read a value</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">34</span> - _, _, source<span class="Special"> <- </span>read source + sink <span class="Special"><-</span> write sink,<span class="Constant"> 34</span> + _, _, source <span class="Special"><-</span> read source run [ <span class="Comment"># first-free will now be 1</span> - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-free:offset</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-free:offset</span> + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> <span class="Comment"># write second value, verify that first-free wraps</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">34</span> - <span class="Constant">20</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-free:offset</span> + sink <span class="Special"><-</span> write sink,<span class="Constant"> 34</span> + 20:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> <span class="Comment"># read second value, verify that first-full wraps</span> - _, _, source<span class="Special"> <- </span>read source - <span class="Constant">30</span>:num/<span class="Special">raw <- </span>get *chan, <span class="Constant">first-full:offset</span> + _, _, source <span class="Special"><-</span> read source + 30:num/<span class="Special">raw</span> <span class="Special"><-</span> get *chan, <span class="Constant">first-full:offset</span> ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-free after first write</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first-full after first read</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-free after second write, wrapped</span> - <span class="Constant">30</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first-full after second read, wrapped</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># first-free after first write</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># first-full after first read</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># first-free after second write, wrapped</span> + <span class="Constant"> 30</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># first-full after second read, wrapped</span> ] ] <span class="muScenario">scenario</span> channel-new-empty-not-full [ run [ <span class="Constant">local-scope</span> - source:&:source:num<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> - chan:&:channel:num<span class="Special"> <- </span>get *source, <span class="Constant">chan:offset</span> - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>channel-empty? chan - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>channel-full? chan + source:&:source:num <span class="Special"><-</span> new-channel <span class="Constant">3/capacity</span> + chan:&:channel:num <span class="Special"><-</span> get *source, <span class="Constant">chan:offset</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> channel-empty? chan + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> channel-full? chan ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># empty?</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># full?</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># empty?</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># full?</span> ] ] <span class="muScenario">scenario</span> channel-write-not-empty [ <span class="Constant">local-scope</span> - source:&:source:num, sink:&:sink:num<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> - chan:&:channel:num<span class="Special"> <- </span>get *source, <span class="Constant">chan:offset</span> + source:&:source:num, sink:&:sink:num <span class="Special"><-</span> new-channel <span class="Constant">3/capacity</span> + chan:&:channel:num <span class="Special"><-</span> get *source, <span class="Constant">chan:offset</span> run [ - sink<span class="Special"> <- </span>write sink, <span class="Constant">34</span> - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>channel-empty? chan - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>channel-full? chan + sink <span class="Special"><-</span> write sink,<span class="Constant"> 34</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> channel-empty? chan + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> channel-full? chan ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty?</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># full?</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># empty?</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># full?</span> ] ] <span class="muScenario">scenario</span> channel-write-full [ <span class="Constant">local-scope</span> - source:&:source:num, sink:&:sink:num<span class="Special"> <- </span>new-channel <span class="Constant">1/capacity</span> - chan:&:channel:num<span class="Special"> <- </span>get *source, <span class="Constant">chan:offset</span> + source:&:source:num, sink:&:sink:num <span class="Special"><-</span> new-channel <span class="Constant">1/capacity</span> + chan:&:channel:num <span class="Special"><-</span> get *source, <span class="Constant">chan:offset</span> run [ - sink<span class="Special"> <- </span>write sink, <span class="Constant">34</span> - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>channel-empty? chan - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>channel-full? chan + sink <span class="Special"><-</span> write sink,<span class="Constant"> 34</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> channel-empty? chan + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> channel-full? chan ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># empty?</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># full?</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># empty?</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># full?</span> ] ] <span class="muScenario">scenario</span> channel-read-not-full [ <span class="Constant">local-scope</span> - source:&:source:num, sink:&:sink:num<span class="Special"> <- </span>new-channel <span class="Constant">1/capacity</span> - chan:&:channel:num<span class="Special"> <- </span>get *source, <span class="Constant">chan:offset</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">34</span> + source:&:source:num, sink:&:sink:num <span class="Special"><-</span> new-channel <span class="Constant">1/capacity</span> + chan:&:channel:num <span class="Special"><-</span> get *source, <span class="Constant">chan:offset</span> + sink <span class="Special"><-</span> write sink,<span class="Constant"> 34</span> run [ - _, _, source<span class="Special"> <- </span>read source - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>channel-empty? chan - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>channel-full? chan + _, _, source <span class="Special"><-</span> read source + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> channel-empty? chan + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> channel-full? chan ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># empty?</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># full?</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># empty?</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># full?</span> ] ] @@ -343,14 +343,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> close x:&:source:_elem<span class="muRecipe"> -> </span>x:&:source:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - chan:&:channel:_elem<span class="Special"> <- </span>get *x, <span class="Constant">chan:offset</span> - *chan<span class="Special"> <- </span>put *chan, <span class="Constant">closed?:offset</span>, <span class="Constant">1/true</span> + chan:&:channel:_elem <span class="Special"><-</span> get *x, <span class="Constant">chan:offset</span> + *chan <span class="Special"><-</span> put *chan, <span class="Constant">closed?:offset</span>, <span class="Constant">1/true</span> ] <span class="muRecipe">def</span> close x:&:sink:_elem<span class="muRecipe"> -> </span>x:&:sink:_elem [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - chan:&:channel:_elem<span class="Special"> <- </span>get *x, <span class="Constant">chan:offset</span> - *chan<span class="Special"> <- </span>put *chan, <span class="Constant">closed?:offset</span>, <span class="Constant">1/true</span> + chan:&:channel:_elem <span class="Special"><-</span> get *x, <span class="Constant">chan:offset</span> + *chan <span class="Special"><-</span> put *chan, <span class="Constant">closed?:offset</span>, <span class="Constant">1/true</span> ] <span class="Comment"># once a channel is closed from one side, no further operations are expected from that side</span> @@ -360,14 +360,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># future reads continue until the channel empties,</span> <span class="Comment"># then the channel is also closed for reading</span> <span class="muRecipe">after</span> <span class="Constant"><channel-write-initial></span> [ - closed?:bool<span class="Special"> <- </span>get *chan, <span class="Constant">closed?:offset</span> + closed?:bool <span class="Special"><-</span> get *chan, <span class="Constant">closed?:offset</span> <span class="muControl">return-if</span> closed? ] <span class="muRecipe">after</span> <span class="Constant"><channel-read-empty></span> [ - closed?:bool<span class="Special"> <- </span>get *chan, <span class="Constant">closed?:offset</span> + closed?:bool <span class="Special"><-</span> get *chan, <span class="Constant">closed?:offset</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> closed? - empty-result:&:_elem<span class="Special"> <- </span>new <span class="Constant">_elem:type</span> + empty-result:&:_elem <span class="Special"><-</span> new <span class="Constant">_elem:type</span> current-routine-is-unblocked <span class="muControl">return</span> *empty-result, <span class="Constant">1/true</span> <span class="Delimiter">}</span> @@ -380,9 +380,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># return chan.first-full == chan.first-free</span> - full:num<span class="Special"> <- </span>get *chan, <span class="Constant">first-full:offset</span> - free:num<span class="Special"> <- </span>get *chan, <span class="Constant">first-free:offset</span> - result<span class="Special"> <- </span>equal full, free + full:num <span class="Special"><-</span> get *chan, <span class="Constant">first-full:offset</span> + free:num <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> + result <span class="Special"><-</span> equal full, free ] <span class="Comment"># A full channel has first-empty just before first-full, wasting one slot.</span> @@ -391,25 +391,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># tmp = chan.first-free + 1</span> - tmp:num<span class="Special"> <- </span>get *chan, <span class="Constant">first-free:offset</span> - tmp<span class="Special"> <- </span>add tmp, <span class="Constant">1</span> + tmp:num <span class="Special"><-</span> get *chan, <span class="Constant">first-free:offset</span> + 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:num<span class="Special"> <- </span>capacity chan - at-end?:bool<span class="Special"> <- </span>greater-or-equal tmp, len + len:num <span class="Special"><-</span> capacity chan + at-end?:bool <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> + 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:num<span class="Special"> <- </span>get *chan, <span class="Constant">first-full:offset</span> - result<span class="Special"> <- </span>equal full, tmp + full:num <span class="Special"><-</span> get *chan, <span class="Constant">first-full:offset</span> + result <span class="Special"><-</span> equal full, tmp ] <span class="muRecipe">def</span> capacity chan:&:channel:_elem<span class="muRecipe"> -> </span>result:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - q:&:@:_elem<span class="Special"> <- </span>get *chan, <span class="Constant">data:offset</span> - result<span class="Special"> <- </span>length *q + q:&:@:_elem <span class="Special"><-</span> get *chan, <span class="Constant">data:offset</span> + result <span class="Special"><-</span> length *q ] <span class="SalientComment">## helpers for channels of characters in particular</span> @@ -418,51 +418,51 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># repeat forever</span> - eof?:bool<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + eof?:bool <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="Delimiter">{</span> - line:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> + line:&: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:char, eof?:bool, in<span class="Special"> <- </span>read in + c:char, eof?:bool, in <span class="Special"><-</span> read in <span class="muControl">break-if</span> eof? <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?:bool<span class="Special"> <- </span>equal c, <span class="Constant">8</span> + backspace?:bool <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="Delimiter">{</span> - buffer-length:num<span class="Special"> <- </span>get *line, <span class="Constant">length:offset</span> - buffer-empty?:bool<span class="Special"> <- </span>equal buffer-length, <span class="Constant">0</span> + buffer-length:num <span class="Special"><-</span> get *line, <span class="Constant">length:offset</span> + buffer-empty?:bool <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> - *line<span class="Special"> <- </span>put *line, <span class="Constant">length:offset</span>, buffer-length + buffer-length <span class="Special"><-</span> subtract buffer-length,<span class="Constant"> 1</span> + *line <span class="Special"><-</span> put *line, <span class="Constant">length:offset</span>, buffer-length <span class="Delimiter">}</span> <span class="Comment"># and don't append this one</span> <span class="muControl">loop</span> <span class="Constant">+next-character</span> <span class="Delimiter">}</span> <span class="Comment"># append anything else</span> - line<span class="Special"> <- </span>append line, c - line-done?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + line <span class="Special"><-</span> append line, c + line-done?:bool <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> line-done? <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># copy line into 'buffered-out'</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - line-contents:text<span class="Special"> <- </span>get *line, <span class="Constant">data:offset</span> - max:num<span class="Special"> <- </span>get *line, <span class="Constant">length:offset</span> + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + line-contents:text <span class="Special"><-</span> get *line, <span class="Constant">data:offset</span> + max:num <span class="Special"><-</span> get *line, <span class="Constant">length:offset</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, max + done?:bool <span class="Special"><-</span> greater-or-equal i, max <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *line-contents, i - buffered-out<span class="Special"> <- </span>write buffered-out, c - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + c:char <span class="Special"><-</span> index *line-contents, i + buffered-out <span class="Special"><-</span> write buffered-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="Delimiter">{</span> <span class="muControl">break-unless</span> eof? - buffered-out<span class="Special"> <- </span>close buffered-out + buffered-out <span class="Special"><-</span> close buffered-out <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="muControl">loop</span> @@ -472,41 +472,41 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> buffer-lines-blocks-until-newline [ run [ <span class="Constant">local-scope</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">10/capacity</span> - _, buffered-stdin:&:sink:char/buffered-stdin<span class="Special"> <- </span>new-channel <span class="Constant">10/capacity</span> - buffered-chan:&:channel:char<span class="Special"> <- </span>get *buffered-stdin, <span class="Constant">chan:offset</span> - empty?:bool<span class="Special"> <- </span>channel-empty? buffered-chan + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">10/capacity</span> + _, buffered-stdin:&:sink:char/buffered-stdin <span class="Special"><-</span> new-channel <span class="Constant">10/capacity</span> + buffered-chan:&:channel:char <span class="Special"><-</span> get *buffered-stdin, <span class="Constant">chan:offset</span> + empty?:bool <span class="Special"><-</span> channel-empty? buffered-chan assert empty?, <span class="Constant">[ </span> <span class="Constant">F buffer-lines-blocks-until-newline: channel should be empty after init]</span> <span class="Comment"># buffer stdin into buffered-stdin, try to read from buffered-stdin</span> - buffer-routine:num<span class="Special"> <- </span>start-running buffer-lines, source, buffered-stdin + buffer-routine:num <span class="Special"><-</span> start-running buffer-lines, source, buffered-stdin wait-for-routine-to-block buffer-routine - empty?<span class="Special"> <- </span>channel-empty? buffered-chan + empty? <span class="Special"><-</span> channel-empty? buffered-chan assert empty?:bool, <span class="Constant">[ </span> <span class="Constant">F buffer-lines-blocks-until-newline: channel should be empty after buffer-lines bring-up]</span> <span class="Comment"># write 'a'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">97/a</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">97/a</span> restart buffer-routine wait-for-routine-to-block buffer-routine - empty?<span class="Special"> <- </span>channel-empty? buffered-chan + empty? <span class="Special"><-</span> channel-empty? buffered-chan assert empty?:bool, <span class="Constant">[ </span> <span class="Constant">F buffer-lines-blocks-until-newline: channel should be empty after writing 'a']</span> <span class="Comment"># write 'b'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">98/b</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">98/b</span> restart buffer-routine wait-for-routine-to-block buffer-routine - empty?<span class="Special"> <- </span>channel-empty? buffered-chan + empty? <span class="Special"><-</span> channel-empty? buffered-chan assert empty?:bool, <span class="Constant">[ </span> <span class="Constant">F buffer-lines-blocks-until-newline: channel should be empty after writing 'b']</span> <span class="Comment"># write newline</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">10/newline</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">10/newline</span> restart buffer-routine wait-for-routine-to-block buffer-routine - empty?<span class="Special"> <- </span>channel-empty? buffered-chan - data-emitted?:bool<span class="Special"> <- </span>not empty? + empty? <span class="Special"><-</span> channel-empty? buffered-chan + data-emitted?:bool <span class="Special"><-</span> not empty? assert data-emitted?, <span class="Constant">[ </span> <span class="Constant">F buffer-lines-blocks-until-newline: channel should contain data after writing newline]</span> - trace <span class="Constant">1</span>, <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> + trace<span class="Constant"> 1</span>, <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> ] trace-should-contain [ test: reached end @@ -516,14 +516,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> drain source:&:source:char<span class="muRecipe"> -> </span>result:text, source:&:source:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 30</span> <span class="Delimiter">{</span> - c:char, done?:bool<span class="Special"> <- </span>read source + c:char, done?:bool <span class="Special"><-</span> read source <span class="muControl">break-if</span> done? - buf<span class="Special"> <- </span>append buf, c + buf <span class="Special"><-</span> append buf, c <span class="muControl">loop</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>buffer-to-array buf + result <span class="Special"><-</span> buffer-to-array buf ] </pre> </body> diff --git a/html/081print.mu.html b/html/081print.mu.html index e4dffe1e..4955c3b1 100644 --- a/html/081print.mu.html +++ b/html/081print.mu.html @@ -52,11 +52,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-fake-screen w:num, h:num<span class="muRecipe"> -> </span>result:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>new <span class="Constant">screen:type</span> - bufsize:num<span class="Special"> <- </span>multiply w, h - data:&:@:screen-cell<span class="Special"> <- </span>new <span class="Constant">screen-cell:type</span>, bufsize - *result<span class="Special"> <- </span>merge h/num-rows, w/num-columns, <span class="Constant">0/cursor-row</span>, <span class="Constant">0/cursor-column</span>, data - result<span class="Special"> <- </span>clear-screen result + result <span class="Special"><-</span> new <span class="Constant">screen:type</span> + bufsize:num <span class="Special"><-</span> multiply w, h + data:&:@:screen-cell <span class="Special"><-</span> new <span class="Constant">screen-cell:type</span>, bufsize + *result <span class="Special"><-</span> merge h/num-rows, w/num-columns, <span class="Constant">0/cursor-row</span>, <span class="Constant">0/cursor-column</span>, data + result <span class="Special"><-</span> clear-screen result ] <span class="muRecipe">def</span> clear-screen screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ @@ -66,20 +66,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="Comment"># clear fake screen</span> - buf:&:@:screen-cell<span class="Special"> <- </span>get *screen, <span class="Constant">data:offset</span> - max:num<span class="Special"> <- </span>length *buf - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + buf:&:@:screen-cell <span class="Special"><-</span> get *screen, <span class="Constant">data:offset</span> + max:num <span class="Special"><-</span> length *buf + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, max + done?:bool <span class="Special"><-</span> greater-or-equal i, max <span class="muControl">break-if</span> done? - curr:screen-cell<span class="Special"> <- </span>merge <span class="Constant">0/empty</span>, <span class="Constant">7/white</span> - *buf<span class="Special"> <- </span>put-index *buf, i, curr - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + curr:screen-cell <span class="Special"><-</span> merge <span class="Constant">0/empty</span>, <span class="Constant">7/white</span> + *buf <span class="Special"><-</span> put-index *buf, i, curr + 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> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-row:offset</span>, <span class="Constant">0</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-column:offset</span>, <span class="Constant">0</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-row:offset</span>,<span class="Constant"> 0</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-column:offset</span>,<span class="Constant"> 0</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> @@ -100,15 +100,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">return-unless</span> screen, <span class="Constant">1/true</span> - buf:&:@:screen-cell<span class="Special"> <- </span>get *screen, <span class="Constant">data:offset</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - len:num<span class="Special"> <- </span>length *buf + buf:&:@:screen-cell <span class="Special"><-</span> get *screen, <span class="Constant">data:offset</span> + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + len:num <span class="Special"><-</span> length *buf <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <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:char<span class="Special"> <- </span>get curr, <span class="Constant">contents:offset</span> - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + curr:screen-cell <span class="Special"><-</span> index *buf, i + curr-contents:char <span class="Special"><-</span> get curr, <span class="Constant">contents:offset</span> + 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">return</span> <span class="Constant">0/false</span> @@ -119,86 +119,86 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> print screen:&:screen, c:char<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - color:num, color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + color:num, color-found?:bool <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? - color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> + color <span class="Special"><-</span> copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> - bg-color:num, bg-color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + bg-color:num, bg-color-found?:bool <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? - bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> + bg-color <span class="Special"><-</span> copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> - c2:num<span class="Special"> <- </span>character-to-code c - trace <span class="Constant">90</span>, <span class="Constant">[print-character]</span>, c2 + c2:num <span class="Special"><-</span> character-to-code c + trace<span class="Constant"> 90</span>, <span class="Constant">[print-character]</span>, c2 <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> screen - width:num<span class="Special"> <- </span>get *screen, <span class="Constant">num-columns:offset</span> - height:num<span class="Special"> <- </span>get *screen, <span class="Constant">num-rows:offset</span> + width:num <span class="Special"><-</span> get *screen, <span class="Constant">num-columns:offset</span> + height:num <span class="Special"><-</span> get *screen, <span class="Constant">num-rows:offset</span> <span class="Comment"># if cursor is out of bounds, silently exit</span> - row:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-row:offset</span> - legal?:bool<span class="Special"> <- </span>greater-or-equal row, <span class="Constant">0</span> + row:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-row:offset</span> + legal?:bool <span class="Special"><-</span> greater-or-equal row,<span class="Constant"> 0</span> <span class="muControl">return-unless</span> legal? - legal?<span class="Special"> <- </span>lesser-than row, height + legal? <span class="Special"><-</span> lesser-than row, height <span class="muControl">return-unless</span> legal? - column:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-column:offset</span> - legal?<span class="Special"> <- </span>greater-or-equal column, <span class="Constant">0</span> + column:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-column:offset</span> + legal? <span class="Special"><-</span> greater-or-equal column,<span class="Constant"> 0</span> <span class="muControl">return-unless</span> legal? - legal?<span class="Special"> <- </span>lesser-than column, width + legal? <span class="Special"><-</span> lesser-than column, width <span class="muControl">return-unless</span> legal? <span class="CommentedCode">#? $print [print-character (], row, [, ], column, [): ], c, 10/newline</span> <span class="Comment"># special-case: newline</span> <span class="Delimiter">{</span> - newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + newline?:bool <span class="Special"><-</span> equal c, <span class="Constant">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:num<span class="Special"> <- </span>subtract height, <span class="Constant">1</span> - at-bottom?:bool<span class="Special"> <- </span>greater-or-equal row, bottom + bottom:num <span class="Special"><-</span> subtract height,<span class="Constant"> 1</span> + at-bottom?:bool <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<span class="Special"> <- </span>copy <span class="Constant">0</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-column:offset</span>, column - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-row:offset</span>, row + column <span class="Special"><-</span> copy<span class="Constant"> 0</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-column:offset</span>, column + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-row:offset</span>, row <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># save character in fake screen</span> - index:num<span class="Special"> <- </span>multiply row, width - index<span class="Special"> <- </span>add index, column - buf:&:@:screen-cell<span class="Special"> <- </span>get *screen, <span class="Constant">data:offset</span> - len:num<span class="Special"> <- </span>length *buf + index:num <span class="Special"><-</span> multiply row, width + index <span class="Special"><-</span> add index, column + buf:&:@:screen-cell <span class="Special"><-</span> get *screen, <span class="Constant">data:offset</span> + len:num <span class="Special"><-</span> length *buf <span class="Comment"># special-case: backspace</span> <span class="Delimiter">{</span> - backspace?:bool<span class="Special"> <- </span>equal c, <span class="Constant">8</span> + backspace?:bool <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?:bool<span class="Special"> <- </span>lesser-or-equal column, <span class="Constant">0</span> + at-left?:bool <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<span class="Special"> <- </span>subtract column, <span class="Constant">1</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-column:offset</span>, column - index<span class="Special"> <- </span>subtract index, <span class="Constant">1</span> - cursor:screen-cell<span class="Special"> <- </span>merge <span class="Constant">32/space</span>, <span class="Constant">7/white</span> - *buf<span class="Special"> <- </span>put-index *buf, index, cursor + column <span class="Special"><-</span> subtract column,<span class="Constant"> 1</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-column:offset</span>, column + index <span class="Special"><-</span> subtract index,<span class="Constant"> 1</span> + cursor:screen-cell <span class="Special"><-</span> merge <span class="Constant">32/space</span>, <span class="Constant">7/white</span> + *buf <span class="Special"><-</span> put-index *buf, index, cursor <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> - cursor:screen-cell<span class="Special"> <- </span>merge c, color - *buf<span class="Special"> <- </span>put-index *buf, index, cursor + cursor:screen-cell <span class="Special"><-</span> merge c, color + *buf <span class="Special"><-</span> put-index *buf, index, cursor <span class="Comment"># increment column unless it's already all the way to the right</span> <span class="Delimiter">{</span> - right:num<span class="Special"> <- </span>subtract width, <span class="Constant">1</span> - at-right?:bool<span class="Special"> <- </span>greater-or-equal column, right + right:num <span class="Special"><-</span> subtract width,<span class="Constant"> 1</span> + at-right?:bool <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> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-column:offset</span>, column + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-column:offset</span>, column <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -208,215 +208,215 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> print-character-at-top-left [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> run [ - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - fake-screen<span class="Special"> <- </span>print fake-screen, a:char - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">1</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + fake-screen <span class="Special"><-</span> print fake-screen, a:char + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 1:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> - <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># width*height</span> + <span class="Constant"> 2</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># 'a'</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> print-character-in-color [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> run [ - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - fake-screen<span class="Special"> <- </span>print fake-screen, a:char, <span class="Constant">1/red</span> - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">1</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + fake-screen <span class="Special"><-</span> print fake-screen, a:char, <span class="Constant">1/red</span> + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 1:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> - <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># red</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># width*height</span> + <span class="Constant"> 2</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># 'a'</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># red</span> <span class="Comment"># rest of screen is empty</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> print-backspace-character [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - fake-screen<span class="Special"> <- </span>print fake-screen, a + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + fake-screen <span class="Special"><-</span> print fake-screen, a run [ - backspace:char<span class="Special"> <- </span>copy <span class="Constant">8/backspace</span> - fake-screen<span class="Special"> <- </span>print fake-screen, backspace - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">11</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + backspace:char <span class="Special"><-</span> copy <span class="Constant">8/backspace</span> + fake-screen <span class="Special"><-</span> print fake-screen, backspace + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-column:offset</span> + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 11:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">32</span> <span class="Comment"># space, not 'a'</span> - <span class="Constant">13</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"> 0</span> <span class="Comment"># cursor column</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># width*height</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 32</span> <span class="Comment"># space, not 'a'</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> print-extra-backspace-character [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - fake-screen<span class="Special"> <- </span>print fake-screen, a + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + fake-screen <span class="Special"><-</span> print fake-screen, a run [ - backspace:char<span class="Special"> <- </span>copy <span class="Constant">8/backspace</span> - fake-screen<span class="Special"> <- </span>print fake-screen, backspace - fake-screen<span class="Special"> <- </span>print fake-screen, backspace <span class="Comment"># cursor already at left margin</span> - <span class="Constant">1</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">3</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + backspace:char <span class="Special"><-</span> copy <span class="Constant">8/backspace</span> + fake-screen <span class="Special"><-</span> print fake-screen, backspace + fake-screen <span class="Special"><-</span> print fake-screen, backspace <span class="Comment"># cursor already at left margin</span> + 1:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-column:offset</span> + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 3:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> - <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">32</span> <span class="Comment"># space, not 'a'</span> - <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># cursor column</span> + <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"> 32</span> <span class="Comment"># space, not 'a'</span> + <span class="Constant"> 5</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> - <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 6</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> print-character-at-right-margin [ <span class="Comment"># fill top row of screen with text</span> <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span> - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - fake-screen<span class="Special"> <- </span>print fake-screen, a - b:char<span class="Special"> <- </span>copy <span class="Constant">98/b</span> - fake-screen<span class="Special"> <- </span>print fake-screen, b + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span> + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + fake-screen <span class="Special"><-</span> print fake-screen, a + b:char <span class="Special"><-</span> copy <span class="Constant">98/b</span> + fake-screen <span class="Special"><-</span> print fake-screen, b run [ <span class="Comment"># cursor now at right margin</span> - c:char<span class="Special"> <- </span>copy <span class="Constant">99/c</span> - fake-screen<span class="Special"> <- </span>print fake-screen, c - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">11</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + c:char <span class="Special"><-</span> copy <span class="Constant">99/c</span> + fake-screen <span class="Special"><-</span> print fake-screen, c + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-column:offset</span> + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 11:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor column</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># width*height</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</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">99</span> <span class="Comment"># 'c' over 'b'</span> - <span class="Constant">15</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"> 1</span> <span class="Comment"># cursor column</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># width*height</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># 'a'</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"> 99</span> <span class="Comment"># 'c' over 'b'</span> + <span class="Constant"> 15</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> - <span class="Constant">16</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 16</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> print-newline-character [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - fake-screen<span class="Special"> <- </span>print fake-screen, a + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + fake-screen <span class="Special"><-</span> print fake-screen, a run [ - newline:char<span class="Special"> <- </span>copy <span class="Constant">10/newline</span> - fake-screen<span class="Special"> <- </span>print fake-screen, newline - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-row:offset</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">12</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + newline:char <span class="Special"><-</span> copy <span class="Constant">10/newline</span> + fake-screen <span class="Special"><-</span> print fake-screen, newline + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-row:offset</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-column:offset</span> + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 12:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> - <span class="Constant">14</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"> 1</span> <span class="Comment"># cursor row</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># cursor column</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># width*height</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># 'a'</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> - <span class="Constant">15</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 15</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> print-newline-at-bottom-line [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> - newline:char<span class="Special"> <- </span>copy <span class="Constant">10/newline</span> - fake-screen<span class="Special"> <- </span>print fake-screen, newline - fake-screen<span class="Special"> <- </span>print fake-screen, newline + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + newline:char <span class="Special"><-</span> copy <span class="Constant">10/newline</span> + fake-screen <span class="Special"><-</span> print fake-screen, newline + fake-screen <span class="Special"><-</span> print fake-screen, newline run [ <span class="Comment"># cursor now at bottom of screen</span> - fake-screen<span class="Special"> <- </span>print fake-screen, newline - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-row:offset</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> + fake-screen <span class="Special"><-</span> print fake-screen, newline + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-row:offset</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># doesn't move further down</span> memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># cursor row</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> print-character-at-bottom-right [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span> - newline:char<span class="Special"> <- </span>copy <span class="Constant">10/newline</span> - fake-screen<span class="Special"> <- </span>print fake-screen, newline - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - fake-screen<span class="Special"> <- </span>print fake-screen, a - b:char<span class="Special"> <- </span>copy <span class="Constant">98/b</span> - fake-screen<span class="Special"> <- </span>print fake-screen, b - c:char<span class="Special"> <- </span>copy <span class="Constant">99/c</span> - fake-screen<span class="Special"> <- </span>print fake-screen, c - fake-screen<span class="Special"> <- </span>print fake-screen, newline + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span> + newline:char <span class="Special"><-</span> copy <span class="Constant">10/newline</span> + fake-screen <span class="Special"><-</span> print fake-screen, newline + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + fake-screen <span class="Special"><-</span> print fake-screen, a + b:char <span class="Special"><-</span> copy <span class="Constant">98/b</span> + fake-screen <span class="Special"><-</span> print fake-screen, b + c:char <span class="Special"><-</span> copy <span class="Constant">99/c</span> + fake-screen <span class="Special"><-</span> print fake-screen, c + fake-screen <span class="Special"><-</span> print fake-screen, newline run [ <span class="Comment"># cursor now at bottom right</span> - d:char<span class="Special"> <- </span>copy <span class="Constant">100/d</span> - fake-screen<span class="Special"> <- </span>print fake-screen, d - <span class="Constant">10</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-row:offset</span> - <span class="Constant">11</span>:num/<span class="Special">raw <- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">20</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + d:char <span class="Special"><-</span> copy <span class="Constant">100/d</span> + fake-screen <span class="Special"><-</span> print fake-screen, d + 10:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-row:offset</span> + 11:num/<span class="Special">raw</span> <span class="Special"><-</span> get *fake-screen, <span class="Constant">cursor-column:offset</span> + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 20:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor column</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># width*height</span> - <span class="Constant">21</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># unused</span> - <span class="Constant">22</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> - <span class="Constant">23</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># unused</span> - <span class="Constant">24</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> - <span class="Constant">25</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> - <span class="Constant">26</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> - <span class="Constant">27</span><span class="Special"> <- </span><span class="Constant">100</span> <span class="Comment"># 'd' over 'b' and 'c' and newline</span> - <span class="Constant">28</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"> 1</span> <span class="Comment"># cursor row</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># cursor column</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># width*height</span> + <span class="Constant"> 21</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># unused</span> + <span class="Constant"> 22</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> + <span class="Constant"> 23</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># unused</span> + <span class="Constant"> 24</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> + <span class="Constant"> 25</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># 'a'</span> + <span class="Constant"> 26</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> + <span class="Constant"> 27</span> <span class="Special"><-</span><span class="Constant"> 100</span> <span class="Comment"># 'd' over 'b' and 'c' and newline</span> + <span class="Constant"> 28</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> - <span class="Constant">29</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 29</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muRecipe">def</span> clear-line screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - space:char<span class="Special"> <- </span>copy <span class="Constant">0/nul</span> + space:char <span class="Special"><-</span> copy <span class="Constant">0/nul</span> <span class="Comment"># if x exists, clear line in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen - width:num<span class="Special"> <- </span>get *screen, <span class="Constant">num-columns:offset</span> - column:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-column:offset</span> - original-column:num<span class="Special"> <- </span>copy column + width:num <span class="Special"><-</span> get *screen, <span class="Constant">num-columns:offset</span> + column:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-column:offset</span> + original-column:num <span class="Special"><-</span> copy column <span class="Comment"># space over the entire line</span> <span class="Delimiter">{</span> - right:num<span class="Special"> <- </span>subtract width, <span class="Constant">1</span> - done?:bool<span class="Special"> <- </span>greater-or-equal column, right + right:num <span class="Special"><-</span> subtract width,<span class="Constant"> 1</span> + done?:bool <span class="Special"><-</span> greater-or-equal column, right <span class="muControl">break-if</span> done? print screen, space - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># now back to where the cursor was</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-column:offset</span>, original-column + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-column:offset</span>, original-column <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> @@ -426,19 +426,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> clear-line-until screen:&:screen, right:num/inclusive<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - _, column:num<span class="Special"> <- </span>cursor-position screen - space:char<span class="Special"> <- </span>copy <span class="Constant">32/space</span> - bg-color:num, bg-color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + _, column:num <span class="Special"><-</span> cursor-position screen + space:char <span class="Special"><-</span> copy <span class="Constant">32/space</span> + bg-color:num, bg-color-found?:bool <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? - bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> + bg-color <span class="Special"><-</span> copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-than column, right + done?:bool <span class="Special"><-</span> greater-than column, right <span class="muControl">break-if</span> done? - screen<span class="Special"> <- </span>print screen, space, <span class="Constant">7/white</span>, bg-color <span class="Comment"># foreground color is mostly unused except if the cursor shows up at this cell</span> - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + screen <span class="Special"><-</span> print screen, space, <span class="Constant">7/white</span>, bg-color <span class="Comment"># foreground color is mostly unused except if the cursor shows up at this cell</span> + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -449,11 +449,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># if x exists, lookup cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen - row:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-row:offset</span> - column:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-column:offset</span> + row:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-row:offset</span> + column:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-column:offset</span> <span class="muControl">return</span> <span class="Delimiter">}</span> - row, column<span class="Special"> <- </span>cursor-position-on-display + row, column <span class="Special"><-</span> cursor-position-on-display ] <span class="muRecipe">def</span> move-cursor screen:&:screen, new-row:num, new-column:num<span class="muRecipe"> -> </span>screen:&:screen [ @@ -462,8 +462,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-row:offset</span>, new-row - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-column:offset</span>, new-column + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-row:offset</span>, new-row + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-column:offset</span>, new-column <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> @@ -472,32 +472,32 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> clear-line-erases-printed-characters [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + fake-screen:&: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> - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - fake-screen<span class="Special"> <- </span>print fake-screen, a + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + fake-screen <span class="Special"><-</span> print fake-screen, a <span class="Comment"># move cursor to start of line</span> - fake-screen<span class="Special"> <- </span>move-cursor fake-screen, <span class="Constant">0/row</span>, <span class="Constant">0/column</span> + fake-screen <span class="Special"><-</span> move-cursor fake-screen, <span class="Constant">0/row</span>, <span class="Constant">0/column</span> run [ - fake-screen<span class="Special"> <- </span>clear-line fake-screen - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">10</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + fake-screen <span class="Special"><-</span> clear-line fake-screen + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 10:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] <span class="Comment"># screen should be blank</span> memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">7</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">0</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">7</span> - <span class="Constant">15</span><span class="Special"> <- </span><span class="Constant">0</span> - <span class="Constant">16</span><span class="Special"> <- </span><span class="Constant">7</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">7</span> - <span class="Constant">19</span><span class="Special"> <- </span><span class="Constant">0</span> - <span class="Constant">20</span><span class="Special"> <- </span><span class="Constant">7</span> - <span class="Constant">21</span><span class="Special"> <- </span><span class="Constant">0</span> - <span class="Constant">22</span><span class="Special"> <- </span><span class="Constant">7</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 6</span> <span class="Comment"># width*height</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 7</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 0</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 7</span> + <span class="Constant"> 15</span> <span class="Special"><-</span><span class="Constant"> 0</span> + <span class="Constant"> 16</span> <span class="Special"><-</span><span class="Constant"> 7</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"> 7</span> + <span class="Constant"> 19</span> <span class="Special"><-</span><span class="Constant"> 0</span> + <span class="Constant"> 20</span> <span class="Special"><-</span><span class="Constant"> 7</span> + <span class="Constant"> 21</span> <span class="Special"><-</span><span class="Constant"> 0</span> + <span class="Constant"> 22</span> <span class="Special"><-</span><span class="Constant"> 7</span> ] ] @@ -509,13 +509,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-unless</span> screen <span class="Delimiter">{</span> <span class="Comment"># increment row unless it's already all the way down</span> - height:num<span class="Special"> <- </span>get *screen, <span class="Constant">num-rows:offset</span> - row:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-row:offset</span> - max:num<span class="Special"> <- </span>subtract height, <span class="Constant">1</span> - at-bottom?:bool<span class="Special"> <- </span>greater-or-equal row, max + height:num <span class="Special"><-</span> get *screen, <span class="Constant">num-rows:offset</span> + row:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-row:offset</span> + max:num <span class="Special"><-</span> subtract height,<span class="Constant"> 1</span> + at-bottom?:bool <span class="Special"><-</span> greater-or-equal row, max <span class="muControl">break-if</span> at-bottom? - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-row:offset</span>, row + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-row:offset</span>, row <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -531,11 +531,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-unless</span> screen <span class="Delimiter">{</span> <span class="Comment"># decrement row unless it's already all the way up</span> - row:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-row:offset</span> - at-top?:bool<span class="Special"> <- </span>lesser-or-equal row, <span class="Constant">0</span> + row:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-row:offset</span> + at-top?:bool <span class="Special"><-</span> lesser-or-equal row,<span class="Constant"> 0</span> <span class="muControl">break-if</span> at-top? - row<span class="Special"> <- </span>subtract row, <span class="Constant">1</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-row:offset</span>, row + row <span class="Special"><-</span> subtract row,<span class="Constant"> 1</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-row:offset</span>, row <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -551,13 +551,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-unless</span> screen <span class="Delimiter">{</span> <span class="Comment"># increment column unless it's already all the way to the right</span> - width:num<span class="Special"> <- </span>get *screen, <span class="Constant">num-columns:offset</span> - column:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-column:offset</span> - max:num<span class="Special"> <- </span>subtract width, <span class="Constant">1</span> - at-bottom?:bool<span class="Special"> <- </span>greater-or-equal column, max + width:num <span class="Special"><-</span> get *screen, <span class="Constant">num-columns:offset</span> + column:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-column:offset</span> + max:num <span class="Special"><-</span> subtract width,<span class="Constant"> 1</span> + at-bottom?:bool <span class="Special"><-</span> greater-or-equal column, max <span class="muControl">break-if</span> at-bottom? - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-column:offset</span>, column + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-column:offset</span>, column <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -573,11 +573,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-unless</span> screen <span class="Delimiter">{</span> <span class="Comment"># decrement column unless it's already all the way to the left</span> - column:num<span class="Special"> <- </span>get *screen, <span class="Constant">cursor-column:offset</span> - at-top?:bool<span class="Special"> <- </span>lesser-or-equal column, <span class="Constant">0</span> + column:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-column:offset</span> + at-top?:bool <span class="Special"><-</span> lesser-or-equal column,<span class="Constant"> 0</span> <span class="muControl">break-if</span> at-top? - column<span class="Special"> <- </span>subtract column, <span class="Constant">1</span> - *screen<span class="Special"> <- </span>put *screen, <span class="Constant">cursor-column:offset</span>, column + column <span class="Special"><-</span> subtract column,<span class="Constant"> 1</span> + *screen <span class="Special"><-</span> put *screen, <span class="Constant">cursor-column:offset</span>, column <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -588,22 +588,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> cursor-to-start-of-line screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - row:num<span class="Special"> <- </span>cursor-position screen - column:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - screen<span class="Special"> <- </span>move-cursor screen, row, column + row:num <span class="Special"><-</span> cursor-position screen + column:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + screen <span class="Special"><-</span> move-cursor screen, row, column ] <span class="muRecipe">def</span> cursor-to-next-line screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - screen<span class="Special"> <- </span>cursor-down screen - screen<span class="Special"> <- </span>cursor-to-start-of-line screen + screen <span class="Special"><-</span> cursor-down screen + screen <span class="Special"><-</span> cursor-to-start-of-line screen ] <span class="muRecipe">def</span> move-cursor-to-column screen:&:screen, column:num<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - row:num, _<span class="Special"> <- </span>cursor-position screen + row:num, _ <span class="Special"><-</span> cursor-position screen move-cursor screen, row, column ] @@ -613,11 +613,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen - width<span class="Special"> <- </span>get *screen, <span class="Constant">num-columns:offset</span> + width <span class="Special"><-</span> get *screen, <span class="Constant">num-columns:offset</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> - width<span class="Special"> <- </span>display-width + width <span class="Special"><-</span> display-width ] <span class="muRecipe">def</span> screen-height screen:&:screen<span class="muRecipe"> -> </span>height:num [ @@ -626,11 +626,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen - height<span class="Special"> <- </span>get *screen, <span class="Constant">num-rows:offset</span> + height <span class="Special"><-</span> get *screen, <span class="Constant">num-rows:offset</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> - height<span class="Special"> <- </span>display-height + height <span class="Special"><-</span> display-height ] <span class="muRecipe">def</span> hide-cursor screen:&:screen<span class="muRecipe"> -> </span>screen:&:screen [ @@ -686,108 +686,108 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> print screen:&:screen, s:text<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - color:num, color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + color:num, color-found?:bool <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? - color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> + color <span class="Special"><-</span> copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> - bg-color:num, bg-color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + bg-color:num, bg-color-found?:bool <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? - bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> + bg-color <span class="Special"><-</span> copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> - len:num<span class="Special"> <- </span>length *s - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + len:num <span class="Special"><-</span> length *s + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *s, i + c:char <span class="Special"><-</span> index *s, i print screen, c, color, bg-color - i<span class="Special"> <- </span>add i, <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="muScenario">scenario</span> print-text-stops-at-right-margin [ <span class="Constant">local-scope</span> - fake-screen:&:screen<span class="Special"> <- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> + fake-screen:&:screen <span class="Special"><-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> run [ - fake-screen<span class="Special"> <- </span>print fake-screen, <span class="Constant">[abcd]</span> - cell:&:@:screen-cell<span class="Special"> <- </span>get *fake-screen, <span class="Constant">data:offset</span> - <span class="Constant">10</span>:@:screen-cell/<span class="Special">raw <- </span>copy *cell + fake-screen <span class="Special"><-</span> print fake-screen, <span class="Constant">[abcd]</span> + cell:&:@:screen-cell <span class="Special"><-</span> get *fake-screen, <span class="Constant">data:offset</span> + 10:@:screen-cell/<span class="Special">raw</span> <span class="Special"><-</span> copy *cell ] memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">98</span> <span class="Comment"># 'b'</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">7</span> <span class="Comment"># white</span> - <span class="Constant">15</span><span class="Special"> <- </span><span class="Constant">100</span> <span class="Comment"># 'd' overwrites 'c'</span> - <span class="Constant">16</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"> 6</span> <span class="Comment"># width*height</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 97</span> <span class="Comment"># 'a'</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 98</span> <span class="Comment"># 'b'</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> + <span class="Constant"> 15</span> <span class="Special"><-</span><span class="Constant"> 100</span> <span class="Comment"># 'd' overwrites 'c'</span> + <span class="Constant"> 16</span> <span class="Special"><-</span><span class="Constant"> 7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> - <span class="Constant">17</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 17</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muRecipe">def</span> print-integer screen:&:screen, n:num<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - color:num, color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + color:num, color-found?:bool <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? - color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> + color <span class="Special"><-</span> copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> - bg-color:num, bg-color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + bg-color:num, bg-color-found?:bool <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? - bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> + 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:text<span class="Special"> <- </span>to-text n - screen<span class="Special"> <- </span>print screen, s, color, bg-color + s:text <span class="Special"><-</span> to-text n + screen <span class="Special"><-</span> print screen, s, color, bg-color ] <span class="Comment"># for now, we can only print integers</span> <span class="muRecipe">def</span> print screen:&:screen, n:num<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - color:num, color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + color:num, color-found?:bool <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? - color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> + color <span class="Special"><-</span> copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> - bg-color:num, bg-color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + bg-color:num, bg-color-found?:bool <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? - bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> + bg-color <span class="Special"><-</span> copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> - screen<span class="Special"> <- </span>print-integer screen, n, color, bg-color + screen <span class="Special"><-</span> print-integer screen, n, color, bg-color ] <span class="Comment"># addresses</span> <span class="muRecipe">def</span> print screen:&:screen, n:&:_elem<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - color:num, color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + color:num, color-found?:bool <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? - color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> + color <span class="Special"><-</span> copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> - bg-color:num, bg-color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + bg-color:num, bg-color-found?:bool <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? - bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> + bg-color <span class="Special"><-</span> copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> - n2:num<span class="Special"> <- </span>copy n - screen<span class="Special"> <- </span>print-integer screen, n2, color, bg-color + n2:num <span class="Special"><-</span> copy n + screen <span class="Special"><-</span> print-integer screen, n2, color, bg-color ] </pre> </body> diff --git a/html/083scenario_screen_test.mu.html b/html/083scenario_screen_test.mu.html index 26383209..0e0e6bbc 100644 --- a/html/083scenario_screen_test.mu.html +++ b/html/083scenario_screen_test.mu.html @@ -34,8 +34,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> run [ - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - screen:&:screen<span class="Special"> <- </span>print screen:&:screen, a + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + screen:&:screen <span class="Special"><-</span> print screen:&:screen, a ] screen-should-contain [ <span class="Constant"> .a .</span> @@ -47,12 +47,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">3/height</span> <span class="Comment"># print a character</span> - a:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - screen:&:screen<span class="Special"> <- </span>print screen:&:screen, a + a:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + screen:&:screen <span class="Special"><-</span> print screen:&:screen, a <span class="Comment"># move cursor to start of line</span> - screen:&:screen<span class="Special"> <- </span>move-cursor screen:&:screen, <span class="Constant">0/row</span>, <span class="Constant">0/column</span> + screen:&:screen <span class="Special"><-</span> move-cursor screen:&:screen, <span class="Constant">0/row</span>, <span class="Constant">0/column</span> run [ - screen:&:screen<span class="Special"> <- </span>clear-line screen:&:screen + screen:&:screen <span class="Special"><-</span> clear-line screen:&:screen ] screen-should-contain [ <span class="Constant"> . .</span> diff --git a/html/084console.mu.html b/html/084console.mu.html index 42938cfe..9271231a 100644 --- a/html/084console.mu.html +++ b/html/084console.mu.html @@ -61,8 +61,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-fake-console events:&:@:event<span class="muRecipe"> -> </span>result:&:console [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result:&:console<span class="Special"> <- </span>new <span class="Constant">console:type</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">events:offset</span>, events + result:&:console <span class="Special"><-</span> new <span class="Constant">console:type</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">events:offset</span>, events ] <span class="muRecipe">def</span> read-event console:&:console<span class="muRecipe"> -> </span>result:event, found?:bool, quit?:bool, console:&:console [ @@ -70,22 +70,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> console - current-event-index:num<span class="Special"> <- </span>get *console, <span class="Constant">current-event-index:offset</span> - buf:&:@:event<span class="Special"> <- </span>get *console, <span class="Constant">events:offset</span> + current-event-index:num <span class="Special"><-</span> get *console, <span class="Constant">current-event-index:offset</span> + buf:&:@:event <span class="Special"><-</span> get *console, <span class="Constant">events:offset</span> <span class="Delimiter">{</span> - max:num<span class="Special"> <- </span>length *buf - done?:bool<span class="Special"> <- </span>greater-or-equal current-event-index, max + max:num <span class="Special"><-</span> length *buf + done?:bool <span class="Special"><-</span> greater-or-equal current-event-index, max <span class="muControl">break-unless</span> done? - dummy:&:event<span class="Special"> <- </span>new <span class="Constant">event:type</span> + dummy:&:event <span class="Special"><-</span> new <span class="Constant">event:type</span> <span class="muControl">return</span> *dummy, <span class="Constant">1/found</span>, <span class="Constant">1/quit</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>index *buf, current-event-index - current-event-index<span class="Special"> <- </span>add current-event-index, <span class="Constant">1</span> - *console<span class="Special"> <- </span>put *console, <span class="Constant">current-event-index:offset</span>, current-event-index + result <span class="Special"><-</span> index *buf, current-event-index + current-event-index <span class="Special"><-</span> add current-event-index,<span class="Constant"> 1</span> + *console <span class="Special"><-</span> put *console, <span class="Constant">current-event-index:offset</span>, current-event-index <span class="muControl">return</span> result, <span class="Constant">1/found</span>, <span class="Constant">0/quit</span> <span class="Delimiter">}</span> switch <span class="Comment"># real event source is infrequent; avoid polling it too much</span> - result:event, found?:bool<span class="Special"> <- </span>check-for-interaction + result:event, found?:bool <span class="Special"><-</span> check-for-interaction <span class="muControl">return</span> result, found?, <span class="Constant">0/quit</span> ] @@ -95,11 +95,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> read-key console:&:console<span class="muRecipe"> -> </span>result:char, found?:bool, quit?:bool, console:&:console [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - x:event, found?:bool, quit?:bool, console<span class="Special"> <- </span>read-event console - <span class="muControl">return-if</span> quit?, <span class="Constant">0</span>, found?, quit? - <span class="muControl">return-unless</span> found?, <span class="Constant">0</span>, found?, quit? - c:char, converted?:bool<span class="Special"> <- </span>maybe-convert x, <span class="Constant">text:variant</span> - <span class="muControl">return-unless</span> converted?, <span class="Constant">0</span>, <span class="Constant">0/found</span>, <span class="Constant">0/quit</span> + x:event, found?:bool, quit?:bool, console <span class="Special"><-</span> read-event console + <span class="muControl">return-if</span> quit?,<span class="Constant"> 0</span>, found?, quit? + <span class="muControl">return-unless</span> found?,<span class="Constant"> 0</span>, found?, quit? + c:char, converted?:bool <span class="Special"><-</span> maybe-convert x, <span class="Constant">text:variant</span> + <span class="muControl">return-unless</span> converted?,<span class="Constant"> 0</span>, <span class="Constant">0/found</span>, <span class="Constant">0/quit</span> <span class="muControl">return</span> c, <span class="Constant">1/found</span>, <span class="Constant">0/quit</span> ] @@ -107,22 +107,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> - c:char, found?:bool, quit?:bool, console<span class="Special"> <- </span>read-key console + c:char, found?:bool, quit?:bool, console <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 screen, c - chan<span class="Special"> <- </span>write chan, c + screen <span class="Special"><-</span> print screen, c + chan <span class="Special"><-</span> write chan, c <span class="muControl">loop</span> <span class="Delimiter">}</span> - chan<span class="Special"> <- </span>close chan + chan <span class="Special"><-</span> close chan ] <span class="muRecipe">def</span> wait-for-event console:&:console<span class="muRecipe"> -> </span>console:&:console [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> - _, found?:bool<span class="Special"> <- </span>read-event console + _, found?:bool <span class="Special"><-</span> read-event console <span class="muControl">loop-unless</span> found? <span class="Delimiter">}</span> ] @@ -136,7 +136,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># fake consoles should be plenty fast; never skip</span> <span class="muControl">return</span> <span class="Constant">0/false</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>interactions-left? + result <span class="Special"><-</span> interactions-left? ] </pre> </body> diff --git a/html/086scenario_console_test.mu.html b/html/086scenario_console_test.mu.html index b8922ca0..8d9206d9 100644 --- a/html/086scenario_console_test.mu.html +++ b/html/086scenario_console_test.mu.html @@ -37,20 +37,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color type <span class="Constant">[abc]</span> ] run [ - <span class="Constant">1</span>:char, <span class="Constant">2</span>:bool<span class="Special"> <- </span>read-key console - <span class="Constant">3</span>:char, <span class="Constant">4</span>:bool<span class="Special"> <- </span>read-key console - <span class="Constant">5</span>:char, <span class="Constant">6</span>:bool<span class="Special"> <- </span>read-key console - <span class="Constant">7</span>:char, <span class="Constant">8</span>:bool<span class="Special"> <- </span>read-key console + 1:char, 2:bool <span class="Special"><-</span> read-key console + 3:char, 4:bool <span class="Special"><-</span> read-key console + 5:char, 6:bool <span class="Special"><-</span> read-key console + 7:char, 8:bool <span class="Special"><-</span> read-key console ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> - <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">1</span> - <span class="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> + <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/088file.mu.html b/html/088file.mu.html index 4dd739ea..e6ef6e98 100644 --- a/html/088file.mu.html +++ b/html/088file.mu.html @@ -49,26 +49,26 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="muControl">break-if</span> resources <span class="Comment"># real file system</span> - file:num<span class="Special"> <- </span>$open-file-for-reading filename + file:num <span class="Special"><-</span> $open-file-for-reading filename assert file, <span class="Constant">[file not found]</span> - contents:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">30</span> + contents:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> start-running receive-from-file file, sink <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># fake file system</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - data:&:@:resource<span class="Special"> <- </span>get *resources, <span class="Constant">data:offset</span> - len:num<span class="Special"> <- </span>length *data + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + data:&:@:resource <span class="Special"><-</span> get *resources, <span class="Constant">data:offset</span> + len:num <span class="Special"><-</span> length *data <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - tmp:resource<span class="Special"> <- </span>index *data, i - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> - curr-filename:text<span class="Special"> <- </span>get tmp, <span class="Constant">name:offset</span> - found?:bool<span class="Special"> <- </span>equal filename, curr-filename + tmp:resource <span class="Special"><-</span> index *data, i + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> + curr-filename:text <span class="Special"><-</span> get tmp, <span class="Constant">name:offset</span> + found?:bool <span class="Special"><-</span> equal filename, curr-filename <span class="muControl">loop-unless</span> found? - contents:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">30</span> - curr-contents:text<span class="Special"> <- </span>get tmp, <span class="Constant">contents:offset</span> + contents:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> + curr-contents:text <span class="Special"><-</span> get tmp, <span class="Constant">contents:offset</span> start-running receive-from-text curr-contents, sink <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -79,99 +79,99 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> - c:char, eof?:bool<span class="Special"> <- </span>$read-from-file file + c:char, eof?:bool <span class="Special"><-</span> $read-from-file file <span class="muControl">break-if</span> eof? - sink<span class="Special"> <- </span>write sink, c + sink <span class="Special"><-</span> write sink, c <span class="muControl">loop</span> <span class="Delimiter">}</span> - sink<span class="Special"> <- </span>close sink - file<span class="Special"> <- </span>$close-file file + sink <span class="Special"><-</span> close sink + file <span class="Special"><-</span> $close-file file ] <span class="muRecipe">def</span> receive-from-text contents:text, sink:&:sink:char<span class="muRecipe"> -> </span>sink:&:sink:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - len:num<span class="Special"> <- </span>length *contents + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + len:num <span class="Special"><-</span> length *contents <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *contents, i - sink<span class="Special"> <- </span>write sink, c - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + c:char <span class="Special"><-</span> index *contents, i + sink <span class="Special"><-</span> write sink, c + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - sink<span class="Special"> <- </span>close sink + sink <span class="Special"><-</span> close sink ] <span class="muRecipe">def</span> start-writing resources:&:resources, filename:text<span class="muRecipe"> -> </span>sink:&:sink:char, routine-id:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">30</span> + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> resources <span class="Comment"># real file system</span> - file:num<span class="Special"> <- </span>$open-file-for-writing filename + file:num <span class="Special"><-</span> $open-file-for-writing filename assert file, <span class="Constant">[no such file]</span> - routine-id<span class="Special"> <- </span>start-running transmit-to-file file, source + routine-id <span class="Special"><-</span> start-running transmit-to-file file, source <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># fake file system</span> <span class="Comment"># beware: doesn't support multiple concurrent writes yet</span> - routine-id<span class="Special"> <- </span>start-running transmit-to-fake-file resources, filename, source + routine-id <span class="Special"><-</span> start-running transmit-to-fake-file resources, filename, source ] <span class="muRecipe">def</span> transmit-to-file file:num, source:&:source:char<span class="muRecipe"> -> </span>source:&:source:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> - c:char, done?:bool, source<span class="Special"> <- </span>read source + c:char, done?:bool, source <span class="Special"><-</span> read source <span class="muControl">break-if</span> done? $write-to-file file, c <span class="muControl">loop</span> <span class="Delimiter">}</span> - file<span class="Special"> <- </span>$close-file file + file <span class="Special"><-</span> $close-file file ] <span class="muRecipe">def</span> transmit-to-fake-file resources:&:resources, filename:text, source:&:source:char<span class="muRecipe"> -> </span>resources:&:resources, source:&:source:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># compute new file contents</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 30</span> <span class="Delimiter">{</span> - c:char, done?:bool, source<span class="Special"> <- </span>read source + c:char, done?:bool, source <span class="Special"><-</span> read source <span class="muControl">break-if</span> done? - buf<span class="Special"> <- </span>append buf, c + buf <span class="Special"><-</span> append buf, c <span class="muControl">loop</span> <span class="Delimiter">}</span> - contents:text<span class="Special"> <- </span>buffer-to-array buf - new-resource:resource<span class="Special"> <- </span>merge filename, contents + contents:text <span class="Special"><-</span> buffer-to-array buf + new-resource:resource <span class="Special"><-</span> merge filename, contents <span class="Comment"># write to resources</span> - curr-filename:text<span class="Special"> <- </span>copy <span class="Constant">0</span> - data:&:@:resource<span class="Special"> <- </span>get *resources, <span class="Constant">data:offset</span> + curr-filename:text <span class="Special"><-</span> copy<span class="Constant"> 0</span> + data:&:@:resource <span class="Special"><-</span> get *resources, <span class="Constant">data:offset</span> <span class="Comment"># replace file contents if it already exists</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - len:num<span class="Special"> <- </span>length *data + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + len:num <span class="Special"><-</span> length *data <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - tmp:resource<span class="Special"> <- </span>index *data, i - curr-filename<span class="Special"> <- </span>get tmp, <span class="Constant">name:offset</span> - found?:bool<span class="Special"> <- </span>equal filename, curr-filename + tmp:resource <span class="Special"><-</span> index *data, i + curr-filename <span class="Special"><-</span> get tmp, <span class="Constant">name:offset</span> + found?:bool <span class="Special"><-</span> equal filename, curr-filename <span class="muControl">loop-unless</span> found? put-index *data, i, new-resource <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># if file didn't already exist, make room for it</span> - new-len:num<span class="Special"> <- </span>add len, <span class="Constant">1</span> - new-data:&:@:resource<span class="Special"> <- </span>new <span class="Constant">resource:type</span>, new-len + new-len:num <span class="Special"><-</span> add len,<span class="Constant"> 1</span> + new-data:&:@:resource <span class="Special"><-</span> new <span class="Constant">resource:type</span>, new-len put *resources, <span class="Constant">data:offset</span>, new-data <span class="Comment"># copy over old files</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - tmp:resource<span class="Special"> <- </span>index *data, i + tmp:resource <span class="Special"><-</span> index *data, i put-index *new-data, i, tmp <span class="Delimiter">}</span> <span class="Comment"># write new file</span> diff --git a/html/090scenario_filesystem_test.mu.html b/html/090scenario_filesystem_test.mu.html index 4bb717c3..f82e26e0 100644 --- a/html/090scenario_filesystem_test.mu.html +++ b/html/090scenario_filesystem_test.mu.html @@ -36,22 +36,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> read-from-fake-file [ <span class="Constant">local-scope</span> assume-resources [ - <span class="Constant">[a]</span><span class="Special"> <- </span>[ + <span class="Constant">[a]</span> <span class="Special"><-</span> [ <span class="Constant"> |xyz|</span> ] ] - contents:&:source:char<span class="Special"> <- </span>start-reading resources, <span class="Constant">[a]</span> - <span class="Constant">1</span>:char/<span class="Special">raw <- </span>read contents - <span class="Constant">2</span>:char/<span class="Special">raw <- </span>read contents - <span class="Constant">3</span>:char/<span class="Special">raw <- </span>read contents - <span class="Constant">4</span>:char/<span class="Special">raw <- </span>read contents - _, <span class="Constant">5</span>:bool/<span class="Special">raw <- </span>read contents + contents:&:source:char <span class="Special"><-</span> start-reading resources, <span class="Constant">[a]</span> + 1:char/<span class="Special">raw</span> <span class="Special"><-</span> read contents + 2:char/<span class="Special">raw</span> <span class="Special"><-</span> read contents + 3:char/<span class="Special">raw</span> <span class="Special"><-</span> read contents + 4:char/<span class="Special">raw</span> <span class="Special"><-</span> read contents + _, 5:bool/<span class="Special">raw</span> <span class="Special"><-</span> read contents memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">120</span> <span class="Comment"># x</span> - <span class="Constant">2</span><span class="Special"> <- </span><span class="Constant">121</span> <span class="Comment"># y</span> - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">122</span> <span class="Comment"># z</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">10</span> <span class="Comment"># newline</span> - <span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># eof</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 120</span> <span class="Comment"># x</span> + <span class="Constant"> 2</span> <span class="Special"><-</span><span class="Constant"> 121</span> <span class="Comment"># y</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 122</span> <span class="Comment"># z</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 10</span> <span class="Comment"># newline</span> + <span class="Constant"> 5</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># eof</span> ] ] @@ -59,71 +59,71 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-resources [ ] - sink:&:sink:char, writer:num/routine<span class="Special"> <- </span>start-writing resources, <span class="Constant">[a]</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">120/x</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">121/y</span> + sink:&:sink:char, writer:num/routine <span class="Special"><-</span> start-writing resources, <span class="Constant">[a]</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">120/x</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">121/y</span> close sink wait-for-routine writer - contents-read-back:text<span class="Special"> <- </span>slurp resources, <span class="Constant">[a]</span> - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal contents-read-back, <span class="Constant">[xy]</span> + contents-read-back:text <span class="Special"><-</span> slurp resources, <span class="Constant">[a]</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal contents-read-back, <span class="Constant">[xy]</span> memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># file contents read back exactly match what was written</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># file contents read back exactly match what was written</span> ] ] <span class="muScenario">scenario</span> write-to-fake-file-that-exists [ <span class="Constant">local-scope</span> assume-resources [ - <span class="Constant">[a]</span><span class="Special"> <- </span><span class="Constant">[]</span> + <span class="Constant">[a]</span> <span class="Special"><-</span> <span class="Constant">[]</span> ] - sink:&:sink:char, writer:num/routine<span class="Special"> <- </span>start-writing resources, <span class="Constant">[a]</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">120/x</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">121/y</span> + sink:&:sink:char, writer:num/routine <span class="Special"><-</span> start-writing resources, <span class="Constant">[a]</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">120/x</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">121/y</span> close sink wait-for-routine writer - contents-read-back:text<span class="Special"> <- </span>slurp resources, <span class="Constant">[a]</span> - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal contents-read-back, <span class="Constant">[xy]</span> + contents-read-back:text <span class="Special"><-</span> slurp resources, <span class="Constant">[a]</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal contents-read-back, <span class="Constant">[xy]</span> memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># file contents read back exactly match what was written</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># file contents read back exactly match what was written</span> ] ] <span class="muScenario">scenario</span> write-to-existing-file-preserves-other-files [ <span class="Constant">local-scope</span> assume-resources [ - <span class="Constant">[a]</span><span class="Special"> <- </span><span class="Constant">[]</span> - <span class="Constant">[b]</span><span class="Special"> <- </span>[ + <span class="Constant">[a]</span> <span class="Special"><-</span> <span class="Constant">[]</span> + <span class="Constant">[b]</span> <span class="Special"><-</span> [ <span class="Constant"> |bcd|</span> ] ] - sink:&:sink:char, writer:num/routine<span class="Special"> <- </span>start-writing resources, <span class="Constant">[a]</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">120/x</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">121/y</span> + sink:&:sink:char, writer:num/routine <span class="Special"><-</span> start-writing resources, <span class="Constant">[a]</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">120/x</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">121/y</span> close sink wait-for-routine writer - contents-read-back:text<span class="Special"> <- </span>slurp resources, <span class="Constant">[a]</span> - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal contents-read-back, <span class="Constant">[xy]</span> - other-file-contents:text<span class="Special"> <- </span>slurp resources, <span class="Constant">[b]</span> - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>equal other-file-contents, <span class="Constant">[bcd</span> + contents-read-back:text <span class="Special"><-</span> slurp resources, <span class="Constant">[a]</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal contents-read-back, <span class="Constant">[xy]</span> + other-file-contents:text <span class="Special"><-</span> slurp resources, <span class="Constant">[b]</span> + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal other-file-contents, <span class="Constant">[bcd</span> <span class="Constant">]</span> memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># file contents read back exactly match what was written</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># other files also continue to persist unchanged</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># file contents read back exactly match what was written</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># other files also continue to persist unchanged</span> ] ] <span class="muRecipe">def</span> slurp resources:&:resources, filename:text<span class="muRecipe"> -> </span>contents:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - source:&:source:char<span class="Special"> <- </span>start-reading resources, filename - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30/capacity</span> + source:&:source:char <span class="Special"><-</span> start-reading resources, filename + buf:&:buffer <span class="Special"><-</span> new-buffer <span class="Constant">30/capacity</span> <span class="Delimiter">{</span> - c:char, done?:bool, source<span class="Special"> <- </span>read source + c:char, done?:bool, source <span class="Special"><-</span> read source <span class="muControl">break-if</span> done? - buf<span class="Special"> <- </span>append buf, c + buf <span class="Special"><-</span> append buf, c <span class="muControl">loop</span> <span class="Delimiter">}</span> - contents<span class="Special"> <- </span>buffer-to-array buf + contents <span class="Special"><-</span> buffer-to-array buf ] </pre> </body> diff --git a/html/092socket.mu.html b/html/092socket.mu.html index b8c44663..3b18e2cd 100644 --- a/html/092socket.mu.html +++ b/html/092socket.mu.html @@ -64,31 +64,31 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-port-connection port:num, contents:text<span class="muRecipe"> -> </span>p:&:port-connection [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - p:&:port-connection<span class="Special"> <- </span>new <span class="Constant">port-connection:type</span> - *p<span class="Special"> <- </span>merge port, contents + p:&:port-connection <span class="Special"><-</span> new <span class="Constant">port-connection:type</span> + *p <span class="Special"><-</span> merge port, contents ] <span class="muRecipe">def</span> new-fake-network<span class="muRecipe"> -> </span>n:&:local-network [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - n:&:local-network<span class="Special"> <- </span>new <span class="Constant">local-network:type</span> - local-network-ports:&:@:port-connection<span class="Special"> <- </span>new <span class="Constant">port-connection:type</span>, <span class="Constant">0</span> - *n<span class="Special"> <- </span>put *n, <span class="Constant">data:offset</span>, local-network-ports + n:&:local-network <span class="Special"><-</span> new <span class="Constant">local-network:type</span> + local-network-ports:&:@:port-connection <span class="Special"><-</span> new <span class="Constant">port-connection:type</span>,<span class="Constant"> 0</span> + *n <span class="Special"><-</span> put *n, <span class="Constant">data:offset</span>, local-network-ports ] <span class="muScenario">scenario</span> write-to-fake-socket [ <span class="Constant">local-scope</span> - single-port-network:&:local-network<span class="Special"> <- </span>new-fake-network - sink:&:sink:char, writer:num/routine<span class="Special"> <- </span>start-writing-socket single-port-network, <span class="Constant">8080</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">120/x</span> + single-port-network:&:local-network <span class="Special"><-</span> new-fake-network + sink:&:sink:char, writer:num/routine <span class="Special"><-</span> start-writing-socket single-port-network,<span class="Constant"> 8080</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">120/x</span> close sink wait-for-routine writer - tested-port-connections:&:@:port-connection<span class="Special"> <- </span>get *single-port-network, <span class="Constant">data:offset</span> - tested-port-connection:port-connection<span class="Special"> <- </span>index *tested-port-connections, <span class="Constant">0</span> - contents:text<span class="Special"> <- </span>get tested-port-connection, <span class="Constant">contents:offset</span> - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *contents + tested-port-connections:&:@:port-connection <span class="Special"><-</span> get *single-port-network, <span class="Constant">data:offset</span> + tested-port-connection:port-connection <span class="Special"><-</span> index *tested-port-connections,<span class="Constant"> 0</span> + contents:text <span class="Special"><-</span> get tested-port-connection, <span class="Constant">contents:offset</span> + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *contents memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[x]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[x]</span> ] ] @@ -98,12 +98,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="muControl">break-if</span> resources <span class="Comment"># real network</span> - host:text, path:text<span class="Special"> <- </span>split-at uri, <span class="Constant">47/slash</span> - socket:num<span class="Special"> <- </span>$open-client-socket host, <span class="Constant">80/http-port</span> + host:text, path:text <span class="Special"><-</span> split-at uri, <span class="Constant">47/slash</span> + socket:num <span class="Special"><-</span> $open-client-socket host, <span class="Constant">80/http-port</span> assert socket, <span class="Constant">[contents]</span> - req:text<span class="Special"> <- </span>interpolate <span class="Constant">[GET _ HTTP/1.1]</span>, path + req:text <span class="Special"><-</span> interpolate <span class="Constant">[GET _ HTTP/1.1]</span>, path request-socket socket, req - contents:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">10000</span> + contents:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 10000</span> start-running receive-from-socket socket, sink <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -141,57 +141,57 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> start-writing-socket network:&:local-network, port:num<span class="muRecipe"> -> </span>sink:&:sink:char, routine-id:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">30</span> + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> network - socket:num<span class="Special"> <- </span>$open-server-socket port - session:num<span class="Special"> <- </span>$accept socket + socket:num <span class="Special"><-</span> $open-server-socket port + session:num <span class="Special"><-</span> $accept socket <span class="Comment"># TODO Create channel implementation of write-to-socket.</span> <span class="muControl">return</span> sink, <span class="Constant">0/routine-id</span> <span class="Delimiter">}</span> <span class="Comment"># fake network</span> - routine-id<span class="Special"> <- </span>start-running transmit-to-fake-socket network, port, source + routine-id <span class="Special"><-</span> start-running transmit-to-fake-socket network, port, source ] <span class="muRecipe">def</span> transmit-to-fake-socket network:&:local-network, port:num, source:&:source:char<span class="muRecipe"> -> </span>network:&:local-network, source:&:source:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># compute new port connection contents</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 30</span> <span class="Delimiter">{</span> - c:char, done?:bool, source<span class="Special"> <- </span>read source + c:char, done?:bool, source <span class="Special"><-</span> read source <span class="muControl">break-unless</span> c - buf<span class="Special"> <- </span>append buf, c + buf <span class="Special"><-</span> append buf, c <span class="muControl">break-if</span> done? <span class="muControl">loop</span> <span class="Delimiter">}</span> - contents:text<span class="Special"> <- </span>buffer-to-array buf - new-port-connection:&:port-connection<span class="Special"> <- </span>new-port-connection port, contents + contents:text <span class="Special"><-</span> buffer-to-array buf + new-port-connection:&:port-connection <span class="Special"><-</span> new-port-connection port, contents <span class="Comment"># Got the contents of the channel, time to write to fake port.</span> - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - port-connections:&:@:port-connection<span class="Special"> <- </span>get *network, <span class="Constant">data:offset</span> - len:num<span class="Special"> <- </span>length *port-connections + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + port-connections:&:@:port-connection <span class="Special"><-</span> get *network, <span class="Constant">data:offset</span> + len:num <span class="Special"><-</span> length *port-connections <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - current:port-connection<span class="Special"> <- </span>index *port-connections, i - current-port:num<span class="Special"> <- </span>get current, <span class="Constant">port:offset</span> - ports-match?:bool<span class="Special"> <- </span>equal current-port, port - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + current:port-connection <span class="Special"><-</span> index *port-connections, i + current-port:num <span class="Special"><-</span> get current, <span class="Constant">port:offset</span> + ports-match?:bool <span class="Special"><-</span> equal current-port, port + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> <span class="muControl">loop-unless</span> ports-match? <span class="Comment"># Found an existing connection on this port, overwrite.</span> put-index *port-connections, i, *new-port-connection <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># Couldn't find an existing connection on this port, initialize a new one.</span> - new-len:num<span class="Special"> <- </span>add len, <span class="Constant">1</span> - new-port-connections:&:@:port-connection<span class="Special"> <- </span>new <span class="Constant">port-connection:type</span>, new-len + new-len:num <span class="Special"><-</span> add len,<span class="Constant"> 1</span> + new-port-connections:&:@:port-connection <span class="Special"><-</span> new <span class="Constant">port-connection:type</span>, new-len put *network, <span class="Constant">data:offset</span>, new-port-connections - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - tmp:port-connection<span class="Special"> <- </span>index *port-connections, i + tmp:port-connection <span class="Special"><-</span> index *port-connections, i put-index *new-port-connections, i, tmp <span class="Delimiter">}</span> put-index *new-port-connections, len, *new-port-connection @@ -201,33 +201,33 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> - req:text, eof?:bool<span class="Special"> <- </span>$read-from-socket socket, <span class="Constant">4096/bytes</span> - bytes-read:num<span class="Special"> <- </span>length *req - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + req:text, eof?:bool <span class="Special"><-</span> $read-from-socket socket, <span class="Constant">4096/bytes</span> + bytes-read:num <span class="Special"><-</span> length *req + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, bytes-read + done?:bool <span class="Special"><-</span> greater-or-equal i, bytes-read <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *req, i <span class="Comment"># todo: unicode</span> - sink<span class="Special"> <- </span>write sink, c - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + c:char <span class="Special"><-</span> index *req, i <span class="Comment"># todo: unicode</span> + sink <span class="Special"><-</span> write sink, c + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">loop-unless</span> eof? <span class="Delimiter">}</span> - sink<span class="Special"> <- </span>close sink + sink <span class="Special"><-</span> close sink ] <span class="muRecipe">def</span> write-to-socket socket:num, s:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - len:num<span class="Special"> <- </span>length *s - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + len:num <span class="Special"><-</span> length *s + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <span class="Special"><-</span> greater-or-equal i, len <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *s, i + c:char <span class="Special"><-</span> index *s, i $write-to-socket socket, c - i<span class="Special"> <- </span>add i, <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> ] @@ -237,30 +237,30 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># empty text? return empty texts</span> - len:num<span class="Special"> <- </span>length *text + len:num <span class="Special"><-</span> length *text <span class="Delimiter">{</span> - empty?:bool<span class="Special"> <- </span>equal len, <span class="Constant">0</span> + empty?:bool <span class="Special"><-</span> equal len,<span class="Constant"> 0</span> <span class="muControl">break-unless</span> empty? - x:text<span class="Special"> <- </span>new <span class="Constant">[]</span> - y:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[]</span> + y:text <span class="Special"><-</span> new <span class="Constant">[]</span> <span class="muControl">return</span> <span class="Delimiter">}</span> - idx:num<span class="Special"> <- </span>find-next text, delim, <span class="Constant">0</span> - x:text<span class="Special"> <- </span>copy-range text, <span class="Constant">0</span>, idx - y:text<span class="Special"> <- </span>copy-range text, idx, len + idx:num <span class="Special"><-</span> find-next text, delim,<span class="Constant"> 0</span> + x:text <span class="Special"><-</span> copy-range text,<span class="Constant"> 0</span>, idx + y:text <span class="Special"><-</span> copy-range text, idx, len ] <span class="muScenario">scenario</span> text-split-at [ <span class="Constant">local-scope</span> - x:text<span class="Special"> <- </span>new <span class="Constant">[a/b]</span> + x:text <span class="Special"><-</span> new <span class="Constant">[a/b]</span> run [ - y:text, z:text<span class="Special"> <- </span>split-at x, <span class="Constant">47/slash</span> - <span class="Constant">10</span>:@:char/<span class="Special">raw <- </span>copy *y - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *z + y:text, z:text <span class="Special"><-</span> split-at x, <span class="Constant">47/slash</span> + 10:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *y + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *z ] memory-should-contain [ - <span class="Constant">10</span>:array:character<span class="Special"> <- </span><span class="Constant">[a]</span> - <span class="Constant">20</span>:array:character<span class="Special"> <- </span><span class="Constant">[/b]</span> + 10:array:character <span class="Special"><-</span> <span class="Constant">[a]</span> + 20:array:character <span class="Special"><-</span> <span class="Constant">[/b]</span> ] ] </pre> diff --git a/html/channel.mu.html b/html/channel.mu.html index 3970a8c2..a6dcc4f2 100644 --- a/html/channel.mu.html +++ b/html/channel.mu.html @@ -37,15 +37,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># n = 0</span> - n:char<span class="Special"> <- </span>copy <span class="Constant">0</span> + n:char <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>lesser-than n, <span class="Constant">5</span> + done?:bool <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, <span class="Constant">[ </span> <span class="Constant">]</span> - sink<span class="Special"> <- </span>write sink, n - n<span class="Special"> <- </span>add n, <span class="Constant">1</span> + sink <span class="Special"><-</span> write sink, n + n <span class="Special"><-</span> add n,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> close sink @@ -57,7 +57,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> <span class="Comment"># read an integer from the channel</span> - n:char, eof?:bool, source<span class="Special"> <- </span>read source + n:char, eof?:bool, source <span class="Special"><-</span> read source <span class="muControl">break-if</span> eof? <span class="Comment"># other threads might get between these prints</span> $print <span class="Constant">[consume: ]</span>, n:char, <span class="Constant">[ </span> @@ -68,10 +68,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">3/capacity</span> + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">3/capacity</span> <span class="Comment"># create two background 'routines' that communicate by a channel</span> - routine1:num<span class="Special"> <- </span>start-running producer, sink - routine2:num<span class="Special"> <- </span>start-running consumer, source + routine1:num <span class="Special"><-</span> start-running producer, sink + routine2:num <span class="Special"><-</span> start-running consumer, source wait-for-routine routine1 wait-for-routine routine2 ] diff --git a/html/chessboard.mu.html b/html/chessboard.mu.html index 8054e613..3a79e84f 100644 --- a/html/chessboard.mu.html +++ b/html/chessboard.mu.html @@ -66,10 +66,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">]</span> ] run [ - screen:&:screen, console:&:console<span class="Special"> <- </span>chessboard screen:&:screen, console:&:console + screen:&:screen, console:&:console <span class="Special"><-</span> chessboard screen:&:screen, console:&:console <span class="Comment"># icon for the cursor</span> - cursor-icon:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> - screen<span class="Special"> <- </span>print screen, cursor-icon + cursor-icon:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> + screen <span class="Special"><-</span> print screen, cursor-icon ] screen-should-contain [ <span class="Comment"># 1 2 3 4 5 6 7 8 9 10 11</span> @@ -104,12 +104,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> chessboard screen:&:screen, console:&:console<span class="muRecipe"> -> </span>screen:&:screen, console:&:console [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - board:board<span class="Special"> <- </span>initial-position + board:board <span class="Special"><-</span> initial-position <span class="Comment"># hook up stdin</span> - stdin-in:&:source:char, stdin-out:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">10/capacity</span> + stdin-in:&:source:char, stdin-out:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">10/capacity</span> start-running send-keys-to-channel, console, stdin-out, screen <span class="Comment"># buffer lines in stdin</span> - buffered-stdin-in:&:source:char, buffered-stdin-out:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">10/capacity</span> + buffered-stdin-in:&:source:char, buffered-stdin-out:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">10/capacity</span> start-running buffer-lines, stdin-in, buffered-stdin-out <span class="Delimiter">{</span> print screen, <span class="Constant">[Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves.</span> @@ -124,14 +124,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">]</span> <span class="Delimiter">{</span> cursor-to-next-line screen - screen<span class="Special"> <- </span>print screen, <span class="Constant">[move: ]</span> - m:&:move, quit:bool, error:bool<span class="Special"> <- </span>read-move buffered-stdin-in, screen + screen <span class="Special"><-</span> print screen, <span class="Constant">[move: ]</span> + m:&:move, quit:bool, error:bool <span class="Special"><-</span> read-move buffered-stdin-in, screen <span class="muControl">break-if</span> quit, <span class="Constant">+quit</span> - buffered-stdin-in<span class="Special"> <- </span>clear buffered-stdin-in <span class="Comment"># cleanup after error. todo: test this?</span> + buffered-stdin-in <span class="Special"><-</span> clear buffered-stdin-in <span class="Comment"># cleanup after error. todo: test this?</span> <span class="muControl">loop-if</span> error <span class="Delimiter">}</span> - board<span class="Special"> <- </span>make-move board, m - screen<span class="Special"> <- </span>clear-screen screen + board <span class="Special"><-</span> make-move board, m + screen <span class="Special"><-</span> clear-screen screen <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Constant"> +quit</span> @@ -143,18 +143,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># assert(length(initial-position) == 64)</span> - len:num<span class="Special"> <- </span>length *initial-position - correct-length?:bool<span class="Special"> <- </span>equal len, <span class="Constant">64</span> + len:num <span class="Special"><-</span> length *initial-position + correct-length?:bool <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<span class="Special"> <- </span>new <span class="Delimiter">{</span>(address array character): type<span class="Delimiter">}</span>, <span class="Constant">8</span> - col:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + board <span class="Special"><-</span> new <span class="Delimiter">{</span>(address array character): type<span class="Delimiter">}</span>,<span class="Constant"> 8</span> + col:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>equal col, <span class="Constant">8</span> + done?:bool <span class="Special"><-</span> equal col,<span class="Constant"> 8</span> <span class="muControl">break-if</span> done? - file:&:@:char<span class="Special"> <- </span>new-file initial-position, col - *board<span class="Special"> <- </span>put-index *board, col, file - col<span class="Special"> <- </span>add col, <span class="Constant">1</span> + file:&:@:char <span class="Special"><-</span> new-file initial-position, col + *board <span class="Special"><-</span> put-index *board, col, file + col <span class="Special"><-</span> add col,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -162,16 +162,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-file position:&:@:char, index:num<span class="muRecipe"> -> </span>result:&:@:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - index<span class="Special"> <- </span>multiply index, <span class="Constant">8</span> - result<span class="Special"> <- </span>new <span class="Constant">character:type</span>, <span class="Constant">8</span> - row:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + index <span class="Special"><-</span> multiply index,<span class="Constant"> 8</span> + result <span class="Special"><-</span> new <span class="Constant">character:type</span>,<span class="Constant"> 8</span> + row:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>equal row, <span class="Constant">8</span> + done?:bool <span class="Special"><-</span> equal row,<span class="Constant"> 8</span> <span class="muControl">break-if</span> done? - square:char<span class="Special"> <- </span>index *position, index - *result<span class="Special"> <- </span>put-index *result, row, square - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - index<span class="Special"> <- </span>add index, <span class="Constant">1</span> + square:char <span class="Special"><-</span> index *position, index + *result <span class="Special"><-</span> put-index *result, row, square + 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> ] @@ -179,29 +179,29 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> print-board screen:&:screen, board:board<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - row:num<span class="Special"> <- </span>copy <span class="Constant">7</span> <span class="Comment"># start printing from the top of the board</span> - space:char<span class="Special"> <- </span>copy <span class="Constant">32/space</span> + row:num <span class="Special"><-</span> copy<span class="Constant"> 7</span> <span class="Comment"># start printing from the top of the board</span> + space:char <span class="Special"><-</span> copy <span class="Constant">32/space</span> <span class="Comment"># print each row</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>lesser-than row, <span class="Constant">0</span> + done?:bool <span class="Special"><-</span> lesser-than row,<span class="Constant"> 0</span> <span class="muControl">break-if</span> done? <span class="Comment"># print rank number as a legend</span> - rank:num<span class="Special"> <- </span>add row, <span class="Constant">1</span> + rank:num <span class="Special"><-</span> add row,<span class="Constant"> 1</span> print-integer screen, rank print screen, <span class="Constant">[ | ]</span> <span class="Comment"># print each square in the row</span> - col:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + col:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>equal col:num, <span class="Constant">8</span> + done?:bool <span class="Special"><-</span> equal col:num,<span class="Constant"> 8</span> <span class="muControl">break-if</span> done?:bool - f:&:@:char<span class="Special"> <- </span>index *board, col - c:char<span class="Special"> <- </span>index *f, row + f:&:@:char <span class="Special"><-</span> index *board, col + c:char <span class="Special"><-</span> index *f, row print screen, c print screen, space - col<span class="Special"> <- </span>add col, <span class="Constant">1</span> + col <span class="Special"><-</span> add col,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - row<span class="Special"> <- </span>subtract row, <span class="Constant">1</span> + 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> @@ -223,7 +223,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <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:&:@:char<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> + initial-position:&:@:char <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> @@ -232,15 +232,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <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<span class="Special"> <- </span>new-board initial-position + board <span class="Special"><-</span> new-board initial-position ] <span class="muScenario">scenario</span> printing-the-board [ <span class="Constant">local-scope</span> - board:board<span class="Special"> <- </span>initial-position + board:board <span class="Special"><-</span> initial-position assume-screen <span class="Constant">30/width</span>, <span class="Constant">12/height</span> run [ - screen:&:screen<span class="Special"> <- </span>print-board screen:&:screen, board + screen:&:screen <span class="Special"><-</span> print-board screen:&:screen, board ] screen-should-contain [ <span class="Comment"># 012345678901234567890123456789</span> @@ -273,27 +273,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> read-move stdin:&:source:char, screen:&:screen<span class="muRecipe"> -> </span>result:&:move, quit?:bool, error?:bool, stdin:&:source:char, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - from-file:num, quit?:bool, error?:bool<span class="Special"> <- </span>read-file stdin, screen + from-file:num, quit?:bool, error?:bool <span class="Special"><-</span> read-file stdin, screen <span class="muControl">return-if</span> quit?, <span class="Constant">0/dummy</span> <span class="muControl">return-if</span> error?, <span class="Constant">0/dummy</span> <span class="Comment"># construct the move object</span> - result:&:move<span class="Special"> <- </span>new <span class="Constant">move:type</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">from-file:offset</span>, from-file - from-rank:num, quit?, error?<span class="Special"> <- </span>read-rank stdin, screen + result:&:move <span class="Special"><-</span> new <span class="Constant">move:type</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">from-file:offset</span>, from-file + from-rank:num, quit?, error? <span class="Special"><-</span> read-rank stdin, screen <span class="muControl">return-if</span> quit?, <span class="Constant">0/dummy</span> <span class="muControl">return-if</span> error?, <span class="Constant">0/dummy</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">from-rank:offset</span>, from-rank - error?<span class="Special"> <- </span>expect-from-channel stdin, <span class="Constant">45/dash</span>, screen + *result <span class="Special"><-</span> put *result, <span class="Constant">from-rank:offset</span>, from-rank + error? <span class="Special"><-</span> expect-from-channel stdin, <span class="Constant">45/dash</span>, screen <span class="muControl">return-if</span> error?, <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span> - to-file:num, quit?, error?<span class="Special"> <- </span>read-file stdin, screen + to-file:num, quit?, error? <span class="Special"><-</span> read-file stdin, screen <span class="muControl">return-if</span> quit?:bool, <span class="Constant">0/dummy</span> <span class="muControl">return-if</span> error?:bool, <span class="Constant">0/dummy</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">to-file:offset</span>, to-file - to-rank:num, quit?, error?<span class="Special"> <- </span>read-rank stdin, screen + *result <span class="Special"><-</span> put *result, <span class="Constant">to-file:offset</span>, to-file + to-rank:num, quit?, error? <span class="Special"><-</span> read-rank stdin, screen <span class="muControl">return-if</span> quit?, <span class="Constant">0/dummy</span> <span class="muControl">return-if</span> error?, <span class="Constant">0/dummy</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">to-rank:offset</span>, to-rank - error?<span class="Special"> <- </span>expect-from-channel stdin, <span class="Constant">10/newline</span>, screen + *result <span class="Special"><-</span> put *result, <span class="Constant">to-rank:offset</span>, to-rank + error? <span class="Special"><-</span> expect-from-channel stdin, <span class="Constant">10/newline</span>, screen <span class="muControl">return-if</span> error?, <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span> ] @@ -301,33 +301,33 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> read-file stdin:&:source:char, screen:&:screen<span class="muRecipe"> -> </span>file:num, quit:bool, error:bool, stdin:&:source:char, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - c:char, eof?:bool, stdin<span class="Special"> <- </span>read stdin + c:char, eof?:bool, stdin <span class="Special"><-</span> read stdin <span class="muControl">return-if</span> eof?, <span class="Constant">0/dummy</span>, <span class="Constant">1/quit</span>, <span class="Constant">0/error</span> <span class="Delimiter">{</span> - q-pressed?:bool<span class="Special"> <- </span>equal c, <span class="Constant">81/Q</span> + q-pressed?:bool <span class="Special"><-</span> equal c, <span class="Constant">81/Q</span> <span class="muControl">break-unless</span> q-pressed? <span class="muControl">return</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?<span class="Special"> <- </span>equal c, <span class="Constant">113/q</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">return</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?:bool<span class="Special"> <- </span>equal c, <span class="Constant">0/eof</span> + empty-fake-keyboard?:bool <span class="Special"><-</span> equal c, <span class="Constant">0/eof</span> <span class="muControl">break-unless</span> empty-fake-keyboard? <span class="muControl">return</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?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + newline?:bool <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> newline? print screen, <span class="Constant">[that's not enough]</span> <span class="muControl">return</span> <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, <span class="Constant">1/error</span> <span class="Delimiter">}</span> - file:num<span class="Special"> <- </span>subtract c, <span class="Constant">97/a</span> + file:num <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:bool<span class="Special"> <- </span>greater-or-equal file, <span class="Constant">0</span> + above-min:bool <span class="Special"><-</span> greater-or-equal file,<span class="Constant"> 0</span> <span class="muControl">break-if</span> above-min print screen, <span class="Constant">[file too low: ]</span> print screen, c @@ -335,7 +335,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">return</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:bool<span class="Special"> <- </span>lesser-than file, <span class="Constant">8</span> + below-max:bool <span class="Special"><-</span> lesser-than file,<span class="Constant"> 8</span> <span class="muControl">break-if</span> below-max print screen, <span class="Constant">[file too high: ]</span> print screen, c @@ -348,35 +348,35 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> read-rank stdin:&:source:char, screen:&:screen<span class="muRecipe"> -> </span>rank:num, quit?:bool, error?:bool, stdin:&:source:char, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - c:char, eof?:bool, stdin<span class="Special"> <- </span>read stdin + c:char, eof?:bool, stdin <span class="Special"><-</span> read stdin <span class="muControl">return-if</span> eof?, <span class="Constant">0/dummy</span>, <span class="Constant">1/quit</span>, <span class="Constant">0/error</span> <span class="Delimiter">{</span> - q-pressed?:bool<span class="Special"> <- </span>equal c, <span class="Constant">8/Q</span> + q-pressed?:bool <span class="Special"><-</span> equal c, <span class="Constant">8/Q</span> <span class="muControl">break-unless</span> q-pressed? <span class="muControl">return</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?<span class="Special"> <- </span>equal c, <span class="Constant">113/q</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">return</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?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10</span> <span class="Comment"># newline</span> + newline?:bool <span class="Special"><-</span> equal c,<span class="Constant"> 10</span> <span class="Comment"># newline</span> <span class="muControl">break-unless</span> newline? print screen, <span class="Constant">[that's not enough]</span> <span class="muControl">return</span> <span class="Constant">0/dummy</span>, <span class="Constant">0/quit</span>, <span class="Constant">1/error</span> <span class="Delimiter">}</span> - rank:num<span class="Special"> <- </span>subtract c, <span class="Constant">49/'1'</span> + rank:num <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:bool<span class="Special"> <- </span>greater-or-equal rank, <span class="Constant">0</span> + above-min:bool <span class="Special"><-</span> greater-or-equal rank,<span class="Constant"> 0</span> <span class="muControl">break-if</span> above-min print screen, <span class="Constant">[rank too low: ]</span> print screen, c <span class="muControl">return</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:bool<span class="Special"> <- </span>lesser-or-equal rank, <span class="Constant">7</span> + below-max:bool <span class="Special"><-</span> lesser-or-equal rank,<span class="Constant"> 7</span> <span class="muControl">break-if</span> below-max print screen, <span class="Constant">[rank too high: ]</span> print screen, c @@ -390,83 +390,83 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> expect-from-channel stdin:&:source:char, expected:char, screen:&:screen<span class="muRecipe"> -> </span>result:bool, stdin:&:source:char, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - c:char, eof?:bool, stdin<span class="Special"> <- </span>read stdin + c:char, eof?:bool, stdin <span class="Special"><-</span> read stdin <span class="muControl">return-if</span> eof? <span class="Constant">1/true</span> <span class="Delimiter">{</span> - match?:bool<span class="Special"> <- </span>equal c, expected + match?:bool <span class="Special"><-</span> equal c, expected <span class="muControl">break-if</span> match? print screen, <span class="Constant">[expected character not found]</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>not match? + result <span class="Special"><-</span> not match? ] <span class="muScenario">scenario</span> read-move-blocking [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">2/capacity</span> - read-move-routine:num/routine<span class="Special"> <- </span>start-running read-move, source, screen:&:screen + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">2/capacity</span> + read-move-routine:num/routine <span class="Special"><-</span> start-running read-move, source, screen:&:screen run [ <span class="Comment"># 'read-move' is waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state:num<span class="Special"> <- </span>routine-state read-move-routine - waiting?:bool<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state:num <span class="Special"><-</span> routine-state read-move-routine + waiting?:bool <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-blocking: routine failed to pause after coming up (before any keys were pressed)]</span> <span class="Comment"># press 'a'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">97/a</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">97/a</span> restart read-move-routine <span class="Comment"># 'read-move' still waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state<span class="Special"> <- </span>routine-state read-move-routine - waiting?<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state <span class="Special"><-</span> routine-state read-move-routine + waiting? <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-blocking: routine failed to pause after rank 'a']</span> <span class="Comment"># press '2'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">50/'2'</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">50/'2'</span> restart read-move-routine <span class="Comment"># 'read-move' still waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state<span class="Special"> <- </span>routine-state read-move-routine - waiting?<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state <span class="Special"><-</span> routine-state read-move-routine + waiting? <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-blocking: routine failed to pause after file 'a2']</span> <span class="Comment"># press '-'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">45/'-'</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">45/'-'</span> restart read-move-routine <span class="Comment"># 'read-move' still waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state<span class="Special"> <- </span>routine-state read-move-routine - waiting?<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state <span class="Special"><-</span> routine-state read-move-routine + waiting? <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-blocking: routine failed to pause after hyphen 'a2-']</span> <span class="Comment"># press 'a'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">97/a</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">97/a</span> restart read-move-routine <span class="Comment"># 'read-move' still waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state<span class="Special"> <- </span>routine-state read-move-routine - waiting?<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state <span class="Special"><-</span> routine-state read-move-routine + waiting? <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-blocking: routine failed to pause after rank 'a2-a']</span> <span class="Comment"># press '4'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">52/'4'</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">52/'4'</span> restart read-move-routine <span class="Comment"># 'read-move' still waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state<span class="Special"> <- </span>routine-state read-move-routine - waiting?<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state <span class="Special"><-</span> routine-state read-move-routine + waiting? <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-blocking: routine failed to pause after file 'a2-a4']</span> <span class="Comment"># press 'newline'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">10</span> <span class="Comment"># newline</span> + sink <span class="Special"><-</span> write sink,<span class="Constant"> 10</span> <span class="Comment"># newline</span> restart read-move-routine <span class="Comment"># 'read-move' now completes</span> wait-for-routine-to-block read-move-routine - read-move-state<span class="Special"> <- </span>routine-state read-move-routine - completed?:bool<span class="Special"> <- </span>equal read-move-state, <span class="Constant">1/completed</span> + read-move-state <span class="Special"><-</span> routine-state read-move-routine + completed?:bool <span class="Special"><-</span> equal read-move-state, <span class="Constant">1/completed</span> assert completed?, <span class="Constant">[ </span> <span class="Constant">F read-move-blocking: routine failed to terminate on newline]</span> - trace <span class="Constant">1</span>, <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> + trace<span class="Constant"> 1</span>, <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> ] trace-should-contain [ test: reached end @@ -476,25 +476,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> read-move-quit [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">2/capacity</span> - read-move-routine:num<span class="Special"> <- </span>start-running read-move, source, screen:&:screen + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">2/capacity</span> + read-move-routine:num <span class="Special"><-</span> start-running read-move, source, screen:&:screen run [ <span class="Comment"># 'read-move' is waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state:num<span class="Special"> <- </span>routine-state read-move-routine - waiting?:bool<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state:num <span class="Special"><-</span> routine-state read-move-routine + waiting?:bool <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-quit: routine failed to pause after coming up (before any keys were pressed)]</span> <span class="Comment"># press 'q'</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">113/q</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">113/q</span> restart read-move-routine <span class="Comment"># 'read-move' completes</span> wait-for-routine-to-block read-move-routine - read-move-state<span class="Special"> <- </span>routine-state read-move-routine - completed?:bool<span class="Special"> <- </span>equal read-move-state, <span class="Constant">1/completed</span> + read-move-state <span class="Special"><-</span> routine-state read-move-routine + completed?:bool <span class="Special"><-</span> equal read-move-state, <span class="Constant">1/completed</span> assert completed?, <span class="Constant">[ </span> <span class="Constant">F read-move-quit: routine failed to terminate on 'q']</span> - trace <span class="Constant">1</span>, <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> + trace<span class="Constant"> 1</span>, <span class="Constant">[test]</span>, <span class="Constant">[reached end]</span> ] trace-should-contain [ test: reached end @@ -504,16 +504,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> read-move-illegal-file [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">2/capacity</span> - read-move-routine:num<span class="Special"> <- </span>start-running read-move, source, screen:&:screen + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">2/capacity</span> + read-move-routine:num <span class="Special"><-</span> start-running read-move, source, screen:&:screen run [ <span class="Comment"># 'read-move' is waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state:num<span class="Special"> <- </span>routine-state read-move-routine - waiting?:bool<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state:num <span class="Special"><-</span> routine-state read-move-routine + waiting?:bool <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-illegal-file: routine failed to pause after coming up (before any keys were pressed)]</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">50/'2'</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">50/'2'</span> restart read-move-routine wait-for-routine-to-block read-move-routine ] @@ -526,17 +526,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> read-move-illegal-rank [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">2/capacity</span> - read-move-routine:num<span class="Special"> <- </span>start-running read-move, source, screen:&:screen + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">2/capacity</span> + read-move-routine:num <span class="Special"><-</span> start-running read-move, source, screen:&:screen run [ <span class="Comment"># 'read-move' is waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state:num<span class="Special"> <- </span>routine-state read-move-routine - waiting?:bool<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state:num <span class="Special"><-</span> routine-state read-move-routine + waiting?:bool <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-illegal-rank: routine failed to pause after coming up (before any keys were pressed)]</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">97/a</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">97/a</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">97/a</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">97/a</span> restart read-move-routine wait-for-routine-to-block read-move-routine ] @@ -549,17 +549,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> read-move-empty [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">20/width</span>, <span class="Constant">2/height</span> - source:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">2/capacity</span> - read-move-routine:num<span class="Special"> <- </span>start-running read-move, source, screen:&:screen + source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel <span class="Constant">2/capacity</span> + read-move-routine:num <span class="Special"><-</span> start-running read-move, source, screen:&:screen run [ <span class="Comment"># 'read-move' is waiting for input</span> wait-for-routine-to-block read-move-routine - read-move-state:num<span class="Special"> <- </span>routine-state read-move-routine - waiting?:bool<span class="Special"> <- </span>not-equal read-move-state, <span class="Constant">2/discontinued</span> + read-move-state:num <span class="Special"><-</span> routine-state read-move-routine + waiting?:bool <span class="Special"><-</span> not-equal read-move-state, <span class="Constant">2/discontinued</span> assert waiting?, <span class="Constant">[ </span> <span class="Constant">F read-move-empty: routine failed to pause after coming up (before any keys were pressed)]</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">10/newline</span> - sink<span class="Special"> <- </span>write sink, <span class="Constant">97/a</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">10/newline</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">97/a</span> restart read-move-routine wait-for-routine-to-block read-move-routine ] @@ -572,26 +572,26 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> make-move board:board, m:&:move<span class="muRecipe"> -> </span>board:board [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - from-file:num<span class="Special"> <- </span>get *m, <span class="Constant">from-file:offset</span> - from-rank:num<span class="Special"> <- </span>get *m, <span class="Constant">from-rank:offset</span> - to-file:num<span class="Special"> <- </span>get *m, <span class="Constant">to-file:offset</span> - to-rank:num<span class="Special"> <- </span>get *m, <span class="Constant">to-rank:offset</span> - from-f:&:@:char<span class="Special"> <- </span>index *board, from-file - to-f:&:@:char<span class="Special"> <- </span>index *board, to-file - src:char/square<span class="Special"> <- </span>index *from-f, from-rank - *to-f<span class="Special"> <- </span>put-index *to-f, to-rank, src - *from-f<span class="Special"> <- </span>put-index *from-f, from-rank, <span class="Constant">32/space</span> + from-file:num <span class="Special"><-</span> get *m, <span class="Constant">from-file:offset</span> + from-rank:num <span class="Special"><-</span> get *m, <span class="Constant">from-rank:offset</span> + to-file:num <span class="Special"><-</span> get *m, <span class="Constant">to-file:offset</span> + to-rank:num <span class="Special"><-</span> get *m, <span class="Constant">to-rank:offset</span> + from-f:&:@:char <span class="Special"><-</span> index *board, from-file + to-f:&:@:char <span class="Special"><-</span> index *board, to-file + src:char/square <span class="Special"><-</span> index *from-f, from-rank + *to-f <span class="Special"><-</span> put-index *to-f, to-rank, src + *from-f <span class="Special"><-</span> put-index *from-f, from-rank, <span class="Constant">32/space</span> ] <span class="muScenario">scenario</span> making-a-move [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">30/width</span>, <span class="Constant">12/height</span> - board:board<span class="Special"> <- </span>initial-position - move:&:move<span class="Special"> <- </span>new <span class="Constant">move:type</span> - *move<span class="Special"> <- </span>merge <span class="Constant">6/g</span>, <span class="Constant">1/'2'</span>, <span class="Constant">6/g</span>, <span class="Constant">3/'4'</span> + board:board <span class="Special"><-</span> initial-position + move:&:move <span class="Special"><-</span> new <span class="Constant">move:type</span> + *move <span class="Special"><-</span> merge <span class="Constant">6/g</span>, <span class="Constant">1/'2'</span>, <span class="Constant">6/g</span>, <span class="Constant">3/'4'</span> run [ - board<span class="Special"> <- </span>make-move board, move - screen:&:screen<span class="Special"> <- </span>print-board screen:&:screen, board + board <span class="Special"><-</span> make-move board, move + screen:&:screen <span class="Special"><-</span> print-board screen:&:screen, board ] screen-should-contain [ <span class="Comment"># 012345678901234567890123456789</span> diff --git a/html/console.mu.html b/html/console.mu.html index f77fda40..c03eb11e 100644 --- a/html/console.mu.html +++ b/html/console.mu.html @@ -38,9 +38,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> open-console <span class="Delimiter">{</span> - e:event, found?:bool<span class="Special"> <- </span>check-for-interaction + e:event, found?:bool <span class="Special"><-</span> check-for-interaction <span class="muControl">break-if</span> found? - print-character-to-display <span class="Constant">97</span>, <span class="Constant">7/white</span> + 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 eab79e04..e6ae8b09 100644 --- a/html/counters.mu.html +++ b/html/counters.mu.html @@ -32,27 +32,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># (spaces)</span> <span class="muRecipe">def</span> new-counter n:num<span class="muRecipe"> -> </span><span class="Constant">default-space</span>:space [ - <span class="Constant">default-space</span><span class="Special"> <- </span>new <span class="Constant">location:type</span>, <span class="Constant">30</span> + <span class="Constant">default-space</span> <span class="Special"><-</span> new <span class="Constant">location:type</span>,<span class="Constant"> 30</span> <span class="Constant">load-ingredients</span> ] -<span class="muRecipe">def</span> increment-counter outer:space/names:new-counter, x:num<span class="muRecipe"> -> </span>n:num/space:<span class="Constant">1</span> [ +<span class="muRecipe">def</span> increment-counter outer:space/names:new-counter, x:num<span class="muRecipe"> -> </span>n:num/space:1 [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="Constant">0</span>:space/names:new-counter<span class="Special"> <- </span>copy outer <span class="Comment"># setup outer space; it *must* come from 'new-counter'</span> - n/space:<span class="Constant">1</span><span class="Special"> <- </span>add n/space:<span class="Constant">1</span>, x + 0:space/names:new-counter <span class="Special"><-</span> copy outer <span class="Comment"># setup outer space; it *must* come from 'new-counter'</span> + n/space:1 <span class="Special"><-</span> add n/space:1, x ] <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> <span class="Comment"># counter A</span> - a:space<span class="Special"> <- </span>new-counter <span class="Constant">34</span> + a:space <span class="Special"><-</span> new-counter<span class="Constant"> 34</span> <span class="Comment"># counter B</span> - b:space<span class="Special"> <- </span>new-counter <span class="Constant">23</span> + b:space <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, <span class="Constant">1</span> - b-value:num<span class="Special"> <- </span>increment-counter b, <span class="Constant">2</span> - a-value:num<span class="Special"> <- </span>increment-counter a, <span class="Constant">1</span> + increment-counter a,<span class="Constant"> 1</span> + b-value:num <span class="Special"><-</span> increment-counter b,<span class="Constant"> 2</span> + a-value:num <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">10/newline</span> $print <span class="Constant">[a: ]</span>, a-value, <span class="Constant">[ b: ]</span>, b-value, <span class="Constant">10/newline</span> diff --git a/html/display.mu.html b/html/display.mu.html index 75ccd75d..75a76413 100644 --- a/html/display.mu.html +++ b/html/display.mu.html @@ -32,14 +32,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ open-console - 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>:num/<span class="Special">raw</span>, <span class="Constant">2</span>:num/<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> + 1:num/<span class="Special">raw</span>, 2:num/<span class="Special">raw</span> <span class="Special"><-</span> cursor-position-on-display wait-for-some-interaction clear-display - move-cursor-on-display <span class="Constant">0</span>, <span class="Constant">4</span> - print-character-to-display <span class="Constant">98</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</span>, <span class="Constant">0</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/001-editor.mu.html b/html/edit/001-editor.mu.html index a0044e7a..01b0bf0a 100644 --- a/html/edit/001-editor.mu.html +++ b/html/edit/001-editor.mu.html @@ -87,22 +87,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># no clipping of bounds</span> - right<span class="Special"> <- </span>subtract right, <span class="Constant">1</span> - result<span class="Special"> <- </span>new <span class="Constant">editor:type</span> + right <span class="Special"><-</span> subtract right,<span class="Constant"> 1</span> + result <span class="Special"><-</span> new <span class="Constant">editor:type</span> <span class="Comment"># initialize screen-related fields</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">left:offset</span>, left - *result<span class="Special"> <- </span>put *result, <span class="Constant">right:offset</span>, right + *result <span class="Special"><-</span> put *result, <span class="Constant">left:offset</span>, left + *result <span class="Special"><-</span> put *result, <span class="Constant">right:offset</span>, right <span class="Comment"># initialize cursor coordinates</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">cursor-row:offset</span>, <span class="Constant">1/top</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">cursor-column:offset</span>, left + *result <span class="Special"><-</span> put *result, <span class="Constant">cursor-row:offset</span>, <span class="Constant">1/top</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">cursor-column:offset</span>, left <span class="Comment"># initialize empty contents</span> - init:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">167/§</span>, <span class="Constant">0/tail</span> - *result<span class="Special"> <- </span>put *result, <span class="Constant">data:offset</span>, init - *result<span class="Special"> <- </span>put *result, <span class="Constant">top-of-screen:offset</span>, init - *result<span class="Special"> <- </span>put *result, <span class="Constant">before-cursor:offset</span>, init - result<span class="Special"> <- </span>insert-text result, s + init:&:duplex-list:char <span class="Special"><-</span> push <span class="Constant">167/§</span>, <span class="Constant">0/tail</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">data:offset</span>, init + *result <span class="Special"><-</span> put *result, <span class="Constant">top-of-screen:offset</span>, init + *result <span class="Special"><-</span> put *result, <span class="Constant">before-cursor:offset</span>, init + result <span class="Special"><-</span> insert-text result, s <span class="Comment"># initial render to screen, just for some old tests</span> - _, _, screen, result<span class="Special"> <- </span>render screen, result + _, _, screen, result <span class="Special"><-</span> render screen, result <span class="Constant"> <editor-initialization></span> ] @@ -110,42 +110,42 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># early exit if text is empty</span> - <span class="muControl">return-unless</span> text, editor/same-as-ingredient:<span class="Constant">0</span> - len:num<span class="Special"> <- </span>length *text - <span class="muControl">return-unless</span> len, editor/same-as-ingredient:<span class="Constant">0</span> - idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="muControl">return-unless</span> text, editor/same-as-ingredient:0 + len:num <span class="Special"><-</span> length *text + <span class="muControl">return-unless</span> len, editor/same-as-ingredient:0 + idx:num <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:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> + curr:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal idx, len + done?:bool <span class="Special"><-</span> greater-or-equal idx, len <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *text, idx + c:char <span class="Special"><-</span> index *text, idx insert c, curr <span class="Comment"># next iter</span> - curr<span class="Special"> <- </span>next curr - idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> + curr <span class="Special"><-</span> next curr + idx <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - <span class="muControl">return</span> editor/same-as-ingredient:<span class="Constant">0</span> + <span class="muControl">return</span> editor/same-as-ingredient:0 ] <span class="muScenario">scenario</span> editor-initializes-without-data [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">3/height</span> run [ - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">0/data</span>, screen:&:screen, <span class="Constant">2/left</span>, <span class="Constant">5/right</span> - <span class="Constant">2</span>:editor/<span class="Special">raw <- </span>copy *e + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">0/data</span>, screen:&:screen, <span class="Constant">2/left</span>, <span class="Constant">5/right</span> + 2:editor/<span class="Special">raw</span> <span class="Special"><-</span> copy *e ] memory-should-contain [ <span class="Comment"># 2 (data) <- just the § sentinel</span> <span class="Comment"># 3 (top of screen) <- the § sentinel</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># bottom-of-screen; null since text fits on screen</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># bottom-of-screen; null since text fits on screen</span> <span class="Comment"># 5 (before cursor) <- the § sentinel</span> - <span class="Constant">6</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># left</span> - <span class="Constant">7</span><span class="Special"> <- </span><span class="Constant">4</span> <span class="Comment"># right (inclusive)</span> - <span class="Constant">8</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># bottom</span> - <span class="Constant">9</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># cursor column</span> + <span class="Constant"> 6</span> <span class="Special"><-</span><span class="Constant"> 2</span> <span class="Comment"># left</span> + <span class="Constant"> 7</span> <span class="Special"><-</span><span class="Constant"> 4</span> <span class="Comment"># right (inclusive)</span> + <span class="Constant"> 8</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># bottom</span> + <span class="Constant"> 9</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># cursor row</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 2</span> <span class="Comment"># cursor column</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -160,102 +160,102 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> render screen:&:screen, editor:&:editor<span class="muRecipe"> -> </span>last-row:num, last-column:num, screen:&:screen, editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">return-unless</span> editor, <span class="Constant">1/top</span>, <span class="Constant">0/left</span>, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - screen-height:num<span class="Special"> <- </span>screen-height screen - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> + <span class="muControl">return-unless</span> editor, <span class="Constant">1/top</span>, <span class="Constant">0/left</span>, screen/same-as-ingredient:0, editor/same-as-ingredient:1 + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + screen-height:num <span class="Special"><-</span> screen-height screen + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> <span class="Comment"># traversing editor</span> - curr:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - prev:&:duplex-list:char<span class="Special"> <- </span>copy curr <span class="Comment"># just in case curr becomes null and we can't compute prev</span> - curr<span class="Special"> <- </span>next curr + curr:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + prev:&:duplex-list:char <span class="Special"><-</span> copy curr <span class="Comment"># just in case curr becomes null and we can't compute prev</span> + curr <span class="Special"><-</span> next curr <span class="Comment"># traversing screen</span> <span class="Constant"> +render-loop-initialization</span> - color:num<span class="Special"> <- </span>copy <span class="Constant">7/white</span> - row:num<span class="Special"> <- </span>copy <span class="Constant">1/top</span> - column:num<span class="Special"> <- </span>copy left - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - screen<span class="Special"> <- </span>move-cursor screen, row, column + color:num <span class="Special"><-</span> copy <span class="Constant">7/white</span> + row:num <span class="Special"><-</span> copy <span class="Constant">1/top</span> + column:num <span class="Special"><-</span> copy left + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="Delimiter">{</span> <span class="Constant"> +next-character</span> <span class="muControl">break-unless</span> curr - off-screen?:bool<span class="Special"> <- </span>greater-or-equal row, screen-height + off-screen?:bool <span class="Special"><-</span> greater-or-equal row, screen-height <span class="muControl">break-if</span> off-screen? <span class="Comment"># update editor.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?:bool<span class="Special"> <- </span>equal row, cursor-row + at-cursor-row?:bool <span class="Special"><-</span> equal row, cursor-row <span class="muControl">break-unless</span> at-cursor-row? - at-cursor?:bool<span class="Special"> <- </span>equal column, cursor-column + at-cursor?:bool <span class="Special"><-</span> equal column, cursor-column <span class="muControl">break-unless</span> at-cursor? - before-cursor<span class="Special"> <- </span>copy prev + before-cursor <span class="Special"><-</span> copy prev <span class="Delimiter">}</span> - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> <span class="Constant"> <character-c-received></span> <span class="Delimiter">{</span> <span class="Comment"># newline? move to left rather than 0</span> - newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + newline?:bool <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?:bool<span class="Special"> <- </span>equal row, cursor-row + at-cursor-row?:bool <span class="Special"><-</span> equal row, cursor-row <span class="muControl">break-unless</span> at-cursor-row? - left-of-cursor?:bool<span class="Special"> <- </span>lesser-than column, cursor-column + left-of-cursor?:bool <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 curr + cursor-column <span class="Special"><-</span> copy column + before-cursor <span class="Special"><-</span> prev curr <span class="Delimiter">}</span> <span class="Comment"># clear rest of line in this window</span> clear-line-until screen, right <span class="Comment"># skip to next line</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - column<span class="Special"> <- </span>copy left - screen<span class="Special"> <- </span>move-cursor screen, row, column - curr<span class="Special"> <- </span>next curr - prev<span class="Special"> <- </span>next prev + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + column <span class="Special"><-</span> copy left + screen <span class="Special"><-</span> move-cursor screen, row, column + curr <span class="Special"><-</span> next curr + prev <span class="Special"><-</span> next prev <span class="muControl">loop</span> <span class="Constant">+next-character</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?:bool<span class="Special"> <- </span>equal column, right + at-right?:bool <span class="Special"><-</span> equal column, right <span class="muControl">break-unless</span> at-right? <span class="Comment"># print wrap icon</span> - wrap-icon:char<span class="Special"> <- </span>copy <span class="Constant">8617/loop-back-to-left</span> + wrap-icon:char <span class="Special"><-</span> copy <span class="Constant">8617/loop-back-to-left</span> print screen, wrap-icon, <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> - screen<span class="Special"> <- </span>move-cursor screen, row, column + column <span class="Special"><-</span> copy left + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="Comment"># don't increment curr</span> <span class="muControl">loop</span> <span class="Constant">+next-character</span> <span class="Delimiter">}</span> print screen, c, color - curr<span class="Special"> <- </span>next curr - prev<span class="Special"> <- </span>next prev - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + curr <span class="Special"><-</span> next curr + prev <span class="Special"><-</span> next 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"># save first character off-screen</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">bottom-of-screen:offset</span>, curr + *editor <span class="Special"><-</span> put *editor, <span class="Constant">bottom-of-screen:offset</span>, curr <span class="Comment"># is cursor to the right of the last line? move to end</span> <span class="Delimiter">{</span> - at-cursor-row?:bool<span class="Special"> <- </span>equal row, cursor-row - cursor-outside-line?:bool<span class="Special"> <- </span>lesser-or-equal column, cursor-column - before-cursor-on-same-line?:bool<span class="Special"> <- </span>and at-cursor-row?, cursor-outside-line? - above-cursor-row?:bool<span class="Special"> <- </span>lesser-than row, cursor-row - before-cursor?:bool<span class="Special"> <- </span>or before-cursor-on-same-line?, above-cursor-row? + at-cursor-row?:bool <span class="Special"><-</span> equal row, cursor-row + cursor-outside-line?:bool <span class="Special"><-</span> lesser-or-equal column, cursor-column + before-cursor-on-same-line?:bool <span class="Special"><-</span> and at-cursor-row?, cursor-outside-line? + above-cursor-row?:bool <span class="Special"><-</span> lesser-than row, cursor-row + before-cursor?:bool <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 - before-cursor<span class="Special"> <- </span>copy prev + cursor-row <span class="Special"><-</span> copy row + cursor-column <span class="Special"><-</span> copy column + before-cursor <span class="Special"><-</span> copy prev <span class="Delimiter">}</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">bottom:offset</span>, row - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - <span class="muControl">return</span> row, column, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">bottom:offset</span>, row + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + <span class="muControl">return</span> row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 ] <span class="muRecipe">def</span> clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num<span class="muRecipe"> -> </span>screen:&:screen [ @@ -265,27 +265,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="muControl">break-if</span> screen clear-display-from row, column, left, right - <span class="muControl">return</span> screen/same-as-ingredient:<span class="Constant">0</span> + <span class="muControl">return</span> screen/same-as-ingredient:0 <span class="Delimiter">}</span> <span class="Comment"># if not, go the slower route</span> - screen<span class="Special"> <- </span>move-cursor screen, row, column + screen <span class="Special"><-</span> move-cursor screen, row, column clear-line-until screen, right clear-rest-of-screen screen, row, left, right - <span class="muControl">return</span> screen/same-as-ingredient:<span class="Constant">0</span> + <span class="muControl">return</span> screen/same-as-ingredient:0 ] <span class="muRecipe">def</span> clear-rest-of-screen screen:&:screen, row:num, left:num, right:num<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - screen<span class="Special"> <- </span>move-cursor screen, row, left - screen-height:num<span class="Special"> <- </span>screen-height screen + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + screen <span class="Special"><-</span> move-cursor screen, row, left + screen-height:num <span class="Special"><-</span> screen-height screen <span class="Delimiter">{</span> - at-bottom-of-screen?:bool<span class="Special"> <- </span>greater-or-equal row, screen-height + at-bottom-of-screen?:bool <span class="Special"><-</span> greater-or-equal row, screen-height <span class="muControl">break-if</span> at-bottom-of-screen? - screen<span class="Special"> <- </span>move-cursor screen, row, left + screen <span class="Special"><-</span> move-cursor screen, row, left clear-line-until screen, right - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -294,7 +294,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> new-editor s, screen:&:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> ] @@ -310,7 +310,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ - s:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> new-editor s, screen:&:screen, <span class="Constant">1/left</span>, <span class="Constant">5/right</span> ] screen-should-contain [ @@ -324,7 +324,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> new-editor s, screen:&:screen, <span class="Constant">1/left</span>, <span class="Constant">5/right</span> ] @@ -340,7 +340,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ - s:text<span class="Special"> <- </span>new <span class="Constant">[abc def]</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc def]</span> new-editor s, screen:&:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> ] screen-should-contain [ @@ -361,7 +361,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ - s:text<span class="Special"> <- </span>new <span class="Constant">[abcde]</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcde]</span> new-editor s, screen:&:screen, <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> @@ -384,9 +384,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen:&:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen:&:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -394,8 +394,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] ] @@ -405,7 +405,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> run [ - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant"># de</span> <span class="Constant">f]</span> new-editor s, screen:&:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> @@ -434,48 +434,48 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><character-c-received></span> [ - color<span class="Special"> <- </span>get-color color, c + color <span class="Special"><-</span> get-color color, c ] <span class="Comment"># so far the previous color is all the information we need; that may change</span> <span class="muRecipe">def</span> get-color color:num, c:char<span class="muRecipe"> -> </span>color:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - color-is-white?:bool<span class="Special"> <- </span>equal color, <span class="Constant">7/white</span> + color-is-white?:bool <span class="Special"><-</span> equal color, <span class="Constant">7/white</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? - starting-comment?:bool<span class="Special"> <- </span>equal c, <span class="Constant">35/#</span> + starting-comment?:bool <span class="Special"><-</span> equal c, <span class="Constant">35/#</span> <span class="muControl">break-unless</span> starting-comment? - trace <span class="Constant">90</span>, <span class="Constant">[app]</span>, <span class="Constant">[switch color back to blue]</span> - color<span class="Special"> <- </span>copy <span class="Constant">12/lightblue</span> + trace<span class="Constant"> 90</span>, <span class="Constant">[app]</span>, <span class="Constant">[switch color back to blue]</span> + color <span class="Special"><-</span> copy <span class="Constant">12/lightblue</span> <span class="muControl">jump</span> <span class="Constant">+exit</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?:bool<span class="Special"> <- </span>equal color, <span class="Constant">12/lightblue</span> + color-is-blue?:bool <span class="Special"><-</span> equal color, <span class="Constant">12/lightblue</span> <span class="muControl">break-unless</span> color-is-blue? - ending-comment?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + ending-comment?:bool <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> ending-comment? - trace <span class="Constant">90</span>, <span class="Constant">[app]</span>, <span class="Constant">[switch color back to white]</span> - color<span class="Special"> <- </span>copy <span class="Constant">7/white</span> + trace<span class="Constant"> 90</span>, <span class="Constant">[app]</span>, <span class="Constant">[switch color back to white]</span> + color <span class="Special"><-</span> copy <span class="Constant">7/white</span> <span class="muControl">jump</span> <span class="Constant">+exit</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? - starting-assignment?:bool<span class="Special"> <- </span>equal c, <span class="Constant">60/<</span> + starting-assignment?:bool <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> + color <span class="Special"><-</span> copy <span class="Constant">1/red</span> <span class="muControl">jump</span> <span class="Constant">+exit</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?:bool<span class="Special"> <- </span>equal color, <span class="Constant">1/red</span> + color-is-red?:bool <span class="Special"><-</span> equal color, <span class="Constant">1/red</span> <span class="muControl">break-unless</span> color-is-red? - ending-assignment?:bool<span class="Special"> <- </span>equal c, <span class="Constant">32/space</span> + ending-assignment?:bool <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> + color <span class="Special"><-</span> copy <span class="Constant">7/white</span> <span class="muControl">jump</span> <span class="Constant">+exit</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise no change</span> @@ -487,7 +487,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">8/width</span>, <span class="Constant">5/height</span> run [ - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">d <- e</span> <span class="Constant">f]</span> new-editor s, screen:&:screen, <span class="Constant">0/left</span>, <span class="Constant">8/right</span> diff --git a/html/edit/002-typing.mu.html b/html/edit/002-typing.mu.html index 325e7f6e..dbca61b2 100644 --- a/html/edit/002-typing.mu.html +++ b/html/edit/002-typing.mu.html @@ -41,7 +41,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> open-console - editor:&:editor<span class="Special"> <- </span>new-editor text, <span class="Constant">0/screen</span>, <span class="Constant">5/left</span>, <span class="Constant">45/right</span> + editor:&:editor <span class="Special"><-</span> new-editor text, <span class="Constant">0/screen</span>, <span class="Constant">5/left</span>, <span class="Constant">45/right</span> editor-event-loop <span class="Constant">0/screen</span>, <span class="Constant">0/console</span>, editor close-console ] @@ -52,15 +52,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="Comment"># looping over each (keyboard or touch) event as it occurs</span> <span class="Constant"> +next-event</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - screen<span class="Special"> <- </span>move-cursor screen, cursor-row, cursor-column - e:event, found?:bool, quit?:bool, console<span class="Special"> <- </span>read-event console + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + screen <span class="Special"><-</span> move-cursor screen, cursor-row, cursor-column + e:event, found?:bool, quit?:bool, console <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">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span> <span class="Comment"># 'touch' event</span> - t:touch-event, is-touch?:bool<span class="Special"> <- </span>maybe-convert e, <span class="Constant">touch:variant</span> + t:touch-event, is-touch?:bool <span class="Special"><-</span> maybe-convert e, <span class="Constant">touch:variant</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> is-touch? move-cursor-in-editor screen, editor, t @@ -69,10 +69,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># keyboard events</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> is-touch? - screen, editor, go-render?:bool<span class="Special"> <- </span>handle-keyboard-event screen, editor, e + screen, editor, go-render?:bool <span class="Special"><-</span> handle-keyboard-event screen, editor, e <span class="Delimiter">{</span> <span class="muControl">break-unless</span> go-render? - screen<span class="Special"> <- </span>editor-render screen, editor + screen <span class="Special"><-</span> editor-render screen, editor <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="muControl">loop</span> @@ -84,19 +84,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">return-unless</span> editor, <span class="Constant">0/false</span> - click-row:num<span class="Special"> <- </span>get t, <span class="Constant">row:offset</span> + click-row:num <span class="Special"><-</span> get t, <span class="Constant">row:offset</span> <span class="muControl">return-unless</span> click-row, <span class="Constant">0/false</span> <span class="Comment"># ignore clicks on 'menu'</span> - click-column:num<span class="Special"> <- </span>get t, <span class="Constant">column:offset</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - too-far-left?:bool<span class="Special"> <- </span>lesser-than click-column, left + click-column:num <span class="Special"><-</span> get t, <span class="Constant">column:offset</span> + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + too-far-left?:bool <span class="Special"><-</span> lesser-than click-column, left <span class="muControl">return-if</span> too-far-left?, <span class="Constant">0/false</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - too-far-right?:bool<span class="Special"> <- </span>greater-than click-column, right + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + too-far-right?:bool <span class="Special"><-</span> greater-than click-column, right <span class="muControl">return-if</span> too-far-right?, <span class="Constant">0/false</span> <span class="Comment"># position cursor</span> <span class="Constant"> <move-cursor-begin></span> - editor<span class="Special"> <- </span>snap-cursor screen, editor, click-row, click-column - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + editor <span class="Special"><-</span> snap-cursor screen, editor, click-row, click-column + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> <span class="Comment"># gain focus</span> <span class="muControl">return</span> <span class="Constant">1/true</span> @@ -109,88 +109,88 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">return-unless</span> editor - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - screen-height:num<span class="Special"> <- </span>screen-height screen + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + screen-height:num <span class="Special"><-</span> screen-height screen <span class="Comment"># count newlines until screen row</span> - curr:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - prev:&:duplex-list:char<span class="Special"> <- </span>copy curr <span class="Comment"># just in case curr becomes null and we can't compute prev</span> - curr<span class="Special"> <- </span>next curr - row:num<span class="Special"> <- </span>copy <span class="Constant">1/top</span> - column:num<span class="Special"> <- </span>copy left - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, target-row - cursor-row:num<span class="Special"> <- </span>copy target-row - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, target-column - cursor-column:num<span class="Special"> <- </span>copy target-column - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> + curr:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + prev:&:duplex-list:char <span class="Special"><-</span> copy curr <span class="Comment"># just in case curr becomes null and we can't compute prev</span> + curr <span class="Special"><-</span> next curr + row:num <span class="Special"><-</span> copy <span class="Constant">1/top</span> + column:num <span class="Special"><-</span> copy left + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, target-row + cursor-row:num <span class="Special"><-</span> copy target-row + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, target-column + cursor-column:num <span class="Special"><-</span> copy target-column + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> <span class="Delimiter">{</span> <span class="Constant"> +next-character</span> <span class="muControl">break-unless</span> curr - off-screen?:bool<span class="Special"> <- </span>greater-or-equal row, screen-height + off-screen?:bool <span class="Special"><-</span> greater-or-equal row, screen-height <span class="muControl">break-if</span> off-screen? <span class="Comment"># update editor.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?:bool<span class="Special"> <- </span>equal row, cursor-row + at-cursor-row?:bool <span class="Special"><-</span> equal row, cursor-row <span class="muControl">break-unless</span> at-cursor-row? - at-cursor?:bool<span class="Special"> <- </span>equal column, cursor-column + at-cursor?:bool <span class="Special"><-</span> equal column, cursor-column <span class="muControl">break-unless</span> at-cursor? - before-cursor<span class="Special"> <- </span>copy prev - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + before-cursor <span class="Special"><-</span> copy prev + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor <span class="Delimiter">}</span> - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> <span class="Delimiter">{</span> <span class="Comment"># newline? move to left rather than 0</span> - newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + newline?:bool <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?:bool<span class="Special"> <- </span>equal row, cursor-row + at-cursor-row?:bool <span class="Special"><-</span> equal row, cursor-row <span class="muControl">break-unless</span> at-cursor-row? - left-of-cursor?:bool<span class="Special"> <- </span>lesser-than column, cursor-column + left-of-cursor?:bool <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 - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - before-cursor<span class="Special"> <- </span>copy prev - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + cursor-column <span class="Special"><-</span> copy column + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + before-cursor <span class="Special"><-</span> copy prev + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor <span class="Delimiter">}</span> <span class="Comment"># skip to next line</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - column<span class="Special"> <- </span>copy left - curr<span class="Special"> <- </span>next curr - prev<span class="Special"> <- </span>next prev + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + column <span class="Special"><-</span> copy left + curr <span class="Special"><-</span> next curr + prev <span class="Special"><-</span> next prev <span class="muControl">loop</span> <span class="Constant">+next-character</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?:bool<span class="Special"> <- </span>equal column, right + at-right?:bool <span class="Special"><-</span> equal column, right <span class="muControl">break-unless</span> at-right? - column<span class="Special"> <- </span>copy left - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + column <span class="Special"><-</span> copy left + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> <span class="Comment"># don't increment curr/prev</span> <span class="muControl">loop</span> <span class="Constant">+next-character</span> <span class="Delimiter">}</span> - curr<span class="Special"> <- </span>next curr - prev<span class="Special"> <- </span>next prev - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + curr <span class="Special"><-</span> next curr + prev <span class="Special"><-</span> next 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?:bool<span class="Special"> <- </span>equal row, cursor-row - cursor-outside-line?:bool<span class="Special"> <- </span>lesser-or-equal column, cursor-column - before-cursor-on-same-line?:bool<span class="Special"> <- </span>and at-cursor-row?, cursor-outside-line? - above-cursor-row?:bool<span class="Special"> <- </span>lesser-than row, cursor-row - before-cursor?:bool<span class="Special"> <- </span>or before-cursor-on-same-line?, above-cursor-row? + at-cursor-row?:bool <span class="Special"><-</span> equal row, cursor-row + cursor-outside-line?:bool <span class="Special"><-</span> lesser-or-equal column, cursor-column + before-cursor-on-same-line?:bool <span class="Special"><-</span> and at-cursor-row?, cursor-outside-line? + above-cursor-row?:bool <span class="Special"><-</span> lesser-than row, cursor-row + before-cursor?:bool <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 - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>copy column - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - before-cursor<span class="Special"> <- </span>copy prev - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + cursor-row <span class="Special"><-</span> copy row + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> copy column + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + before-cursor <span class="Special"><-</span> copy prev + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor <span class="Delimiter">}</span> ] @@ -199,105 +199,105 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> handle-keyboard-event screen:&:screen, editor:&:editor, e:event<span class="muRecipe"> -> </span>screen:&:screen, editor:&:editor, go-render?:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-unless</span> editor - screen-width:num<span class="Special"> <- </span>screen-width screen - screen-height:num<span class="Special"> <- </span>screen-height screen - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - save-row:num<span class="Special"> <- </span>copy cursor-row - save-column:num<span class="Special"> <- </span>copy cursor-column + screen-width:num <span class="Special"><-</span> screen-width screen + screen-height:num <span class="Special"><-</span> screen-height screen + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + save-row:num <span class="Special"><-</span> copy cursor-row + save-column:num <span class="Special"><-</span> copy cursor-column <span class="Comment"># character</span> <span class="Delimiter">{</span> - c:char, is-unicode?:bool<span class="Special"> <- </span>maybe-convert e, <span class="Constant">text:variant</span> + c:char, is-unicode?:bool <span class="Special"><-</span> maybe-convert e, <span class="Constant">text:variant</span> <span class="muControl">break-unless</span> is-unicode? - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[handle-keyboard-event: special character]</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[handle-keyboard-event: special character]</span> <span class="Comment"># exceptions for special characters go here</span> <span class="Constant"> <handle-special-character></span> <span class="Comment"># ignore any other special characters</span> - regular-character?:bool<span class="Special"> <- </span>greater-or-equal c, <span class="Constant">32/space</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + regular-character?:bool <span class="Special"><-</span> greater-or-equal c, <span class="Constant">32/space</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-unless</span> regular-character? <span class="Comment"># otherwise type it in</span> <span class="Constant"> <insert-character-begin></span> - editor, screen, go-render?:bool<span class="Special"> <- </span>insert-at-cursor editor, c, screen + editor, screen, go-render?:bool <span class="Special"><-</span> insert-at-cursor editor, c, screen <span class="Constant"> <insert-character-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># special key to modify the text or move the cursor</span> - k:num, is-keycode?:bool<span class="Special"> <- </span>maybe-convert e:event, <span class="Constant">keycode:variant</span> + k:num, is-keycode?:bool <span class="Special"><-</span> maybe-convert e:event, <span class="Constant">keycode:variant</span> assert is-keycode?, <span class="Constant">[event was of unknown type; neither keyboard nor mouse]</span> <span class="Comment"># handlers for each special key will go here</span> <span class="Constant"> <handle-special-key></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> ] <span class="muRecipe">def</span> insert-at-cursor editor:&:editor, c:char, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen, go-render?:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> insert c, before-cursor - before-cursor<span class="Special"> <- </span>next before-cursor - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - save-row:num<span class="Special"> <- </span>copy cursor-row - save-column:num<span class="Special"> <- </span>copy cursor-column - screen-width:num<span class="Special"> <- </span>screen-width screen - screen-height:num<span class="Special"> <- </span>screen-height screen + before-cursor <span class="Special"><-</span> next before-cursor + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + save-row:num <span class="Special"><-</span> copy cursor-row + save-column:num <span class="Special"><-</span> copy cursor-column + screen-width:num <span class="Special"><-</span> screen-width screen + screen-height:num <span class="Special"><-</span> screen-height screen <span class="Comment"># occasionally we'll need to mess with the cursor</span> <span class="Constant"> <insert-character-special-case></span> <span class="Comment"># but mostly we'll just move the cursor right</span> - cursor-column<span class="Special"> <- </span>add cursor-column, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - next:&:duplex-list:char<span class="Special"> <- </span>next before-cursor + cursor-column <span class="Special"><-</span> add cursor-column,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + next:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="Delimiter">{</span> <span class="Comment"># at end of all text? no need to scroll? just print the character and leave</span> - at-end?:bool<span class="Special"> <- </span>equal next, <span class="Constant">0/null</span> + at-end?:bool <span class="Special"><-</span> equal next, <span class="Constant">0/null</span> <span class="muControl">break-unless</span> at-end? - bottom:num<span class="Special"> <- </span>subtract screen-height, <span class="Constant">1</span> - at-bottom?:bool<span class="Special"> <- </span>equal save-row, bottom - at-right?:bool<span class="Special"> <- </span>equal save-column, right - overflow?:bool<span class="Special"> <- </span>and at-bottom?, at-right? + bottom:num <span class="Special"><-</span> subtract screen-height,<span class="Constant"> 1</span> + at-bottom?:bool <span class="Special"><-</span> equal save-row, bottom + at-right?:bool <span class="Special"><-</span> equal save-column, right + overflow?:bool <span class="Special"><-</span> and at-bottom?, at-right? <span class="muControl">break-if</span> overflow? move-cursor screen, save-row, save-column print screen, c - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># not at right margin? print the character and rest of line</span> <span class="muControl">break-unless</span> next - at-right?:bool<span class="Special"> <- </span>greater-or-equal cursor-column, screen-width + at-right?:bool <span class="Special"><-</span> greater-or-equal cursor-column, screen-width <span class="muControl">break-if</span> at-right? - curr:&:duplex-list:char<span class="Special"> <- </span>copy before-cursor + curr:&:duplex-list:char <span class="Special"><-</span> copy before-cursor move-cursor screen, save-row, save-column - curr-column:num<span class="Special"> <- </span>copy save-column + curr-column:num <span class="Special"><-</span> copy save-column <span class="Delimiter">{</span> <span class="Comment"># hit right margin? give up and let caller render</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> - at-right?:bool<span class="Special"> <- </span>greater-than curr-column, right + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> + at-right?:bool <span class="Special"><-</span> greater-than curr-column, right <span class="muControl">return-if</span> at-right? <span class="muControl">break-unless</span> curr <span class="Comment"># newline? done.</span> - currc:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span> + currc:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <span class="Special"><-</span> equal currc, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? print screen, currc - curr-column<span class="Special"> <- </span>add curr-column, <span class="Constant">1</span> - curr<span class="Special"> <- </span>next curr + curr-column <span class="Special"><-</span> add curr-column,<span class="Constant"> 1</span> + curr <span class="Special"><-</span> next curr <span class="muControl">loop</span> <span class="Delimiter">}</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> ] @@ -305,20 +305,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> editor-render screen:&:screen, editor:&:editor<span class="muRecipe"> -> </span>screen:&:screen, editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - row:num, column:num<span class="Special"> <- </span>render screen, editor + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + row:num, column:num <span class="Special"><-</span> render screen, editor clear-line-until screen, right - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> draw-horizontal screen, row, left, right, <span class="Constant">9480/horizontal-dotted</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> clear-screen-from screen, row, left, left, right ] <span class="muScenario">scenario</span> editor-handles-empty-event-queue [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console <span class="Constant">[]</span> run [ @@ -335,16 +335,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-handles-mouse-clicks [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">1</span> <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, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -353,91 +353,91 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">7</span> <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, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">7</span> <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, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text-3 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">7</span> <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, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-column [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># editor occupies only left half of screen</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ <span class="Comment"># click on right half of screen</span> - left-click <span class="Constant">3</span>, <span class="Constant">8</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 8</span> ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -446,38 +446,38 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-handles-mouse-clicks-in-menu-area [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ <span class="Comment"># click on first, 'menu' row</span> - left-click <span class="Constant">0</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 0</span>,<span class="Constant"> 3</span> ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># no change to cursor</span> memory-should-contain [ - <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="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-inserts-characters-into-empty-editor [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ @@ -492,19 +492,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌ .</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 3</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># type two letters at different places</span> assume-console [ type <span class="Constant">[0]</span> - left-click <span class="Constant">1</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 2</span> type <span class="Constant">[d]</span> ] run [ @@ -516,17 +516,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">7</span>, <span class="Constant">[print-character]</span> <span class="Comment"># 4 for first letter, 3 for second</span> + check-trace-count-for-label<span class="Constant"> 7</span>, <span class="Constant">[print-character]</span> <span class="Comment"># 4 for first letter, 3 for second</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">5</span> <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> ] run [ @@ -538,19 +538,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 1</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-5 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">5</span> <span class="Comment"># right of non-last line</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 5</span> <span class="Comment"># right of non-last line</span> type <span class="Constant">[e]</span> ] run [ @@ -563,17 +563,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 1</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-3 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">5</span> <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> ] run [ @@ -585,19 +585,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 1</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-4 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">5</span> <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> ] run [ @@ -610,19 +610,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 1</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-6 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">5</span> <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> ] run [ @@ -635,13 +635,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 2</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-after-inserting-characters [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[ab]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[ab]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e assume-console [ type <span class="Constant">[01]</span> @@ -662,7 +662,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-wraps-line-on-insert [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Comment"># type a letter</span> assume-console [ @@ -700,24 +700,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abcdefg</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcdefg</span> <span class="Constant">defg]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Comment"># type more text at the start</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> type <span class="Constant">[abc]</span> ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor is not wrapped</span> memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 3</span> ] <span class="Comment"># but line is wrapped</span> screen-should-contain [ @@ -735,47 +735,47 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># if either:</span> <span class="Comment"># a) we're at the end of the line and at the column of the wrap indicator, or</span> <span class="Comment"># b) we're not at end of line and just before the column of the wrap indicator</span> - wrap-column:num<span class="Special"> <- </span>copy right - before-wrap-column:num<span class="Special"> <- </span>subtract wrap-column, <span class="Constant">1</span> - at-wrap?:bool<span class="Special"> <- </span>greater-or-equal cursor-column, wrap-column - just-before-wrap?:bool<span class="Special"> <- </span>greater-or-equal cursor-column, before-wrap-column - next:&:duplex-list:char<span class="Special"> <- </span>next before-cursor + wrap-column:num <span class="Special"><-</span> copy right + before-wrap-column:num <span class="Special"><-</span> subtract wrap-column,<span class="Constant"> 1</span> + at-wrap?:bool <span class="Special"><-</span> greater-or-equal cursor-column, wrap-column + just-before-wrap?:bool <span class="Special"><-</span> greater-or-equal cursor-column, before-wrap-column + next:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="Comment"># at end of line? next == 0 || next.value == 10/newline</span> - at-end-of-line?:bool<span class="Special"> <- </span>equal next, <span class="Constant">0</span> + at-end-of-line?:bool <span class="Special"><-</span> equal next,<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> at-end-of-line? - next-character:char<span class="Special"> <- </span>get *next, <span class="Constant">value:offset</span> - at-end-of-line?<span class="Special"> <- </span>equal next-character, <span class="Constant">10/newline</span> + next-character:char <span class="Special"><-</span> get *next, <span class="Constant">value:offset</span> + at-end-of-line? <span class="Special"><-</span> equal next-character, <span class="Constant">10/newline</span> <span class="Delimiter">}</span> <span class="Comment"># break unless ((eol? and at-wrap?) or (~eol? and just-before-wrap?))</span> - move-cursor-to-next-line?:bool<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + move-cursor-to-next-line?:bool <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> at-end-of-line? - move-cursor-to-next-line?<span class="Special"> <- </span>copy just-before-wrap? + move-cursor-to-next-line? <span class="Special"><-</span> copy just-before-wrap? <span class="Comment"># if we're moving the cursor because it's in the middle of a wrapping</span> <span class="Comment"># line, adjust it to left-most column</span> - potential-new-cursor-column:num<span class="Special"> <- </span>copy left + potential-new-cursor-column:num <span class="Special"><-</span> copy left <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> at-end-of-line? - move-cursor-to-next-line?<span class="Special"> <- </span>copy at-wrap? + move-cursor-to-next-line? <span class="Special"><-</span> copy at-wrap? <span class="Comment"># if we're moving the cursor because it's at the end of a wrapping line,</span> <span class="Comment"># adjust it to one past the left-most column to make room for the</span> <span class="Comment"># newly-inserted wrap-indicator</span> - potential-new-cursor-column:num<span class="Special"> <- </span>add left, <span class="Constant">1/make-room-for-wrap-indicator</span> + potential-new-cursor-column:num <span class="Special"><-</span> add left, <span class="Constant">1/make-room-for-wrap-indicator</span> <span class="Delimiter">}</span> <span class="muControl">break-unless</span> move-cursor-to-next-line? - cursor-column<span class="Special"> <- </span>copy potential-new-cursor-column - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - cursor-row<span class="Special"> <- </span>add cursor-row, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> copy potential-new-cursor-column + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + cursor-row <span class="Special"><-</span> add cursor-row,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row <span class="Comment"># if we're out of the screen, scroll down</span> <span class="Delimiter">{</span> - below-screen?:bool<span class="Special"> <- </span>greater-or-equal cursor-row, screen-height + below-screen?:bool <span class="Special"><-</span> greater-or-equal cursor-row, screen-height <span class="muControl">break-unless</span> below-screen? <span class="Constant"> <scroll-down></span> <span class="Delimiter">}</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -783,15 +783,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-wraps-cursor-after-inserting-characters-in-middle-of-line [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abcde]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abcde]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">3</span> <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, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -801,8 +801,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] ] @@ -810,9 +810,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># create an editor containing two lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">xyz]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abc .</span> @@ -820,7 +820,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">4</span> <span class="Comment"># at end of first line</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 4</span> <span class="Comment"># at end of first line</span> type <span class="Constant">[de]</span> <span class="Comment"># trigger wrap</span> ] run [ @@ -838,15 +838,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-wraps-cursor-to-left-margin [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abcde]</span>, screen, <span class="Constant">2/left</span>, <span class="Constant">7/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abcde]</span>, screen, <span class="Constant">2/left</span>, <span class="Constant">7/right</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">5</span> <span class="Comment"># line is full; no wrap icon yet</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 5</span> <span class="Comment"># line is full; no wrap icon yet</span> type <span class="Constant">[01]</span> ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -856,8 +856,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] ] @@ -868,13 +868,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><editor-initialization></span> [ - *result<span class="Special"> <- </span>put *result, <span class="Constant">indent?:offset</span>, <span class="Constant">1/true</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">indent?:offset</span>, <span class="Constant">1/true</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-down-after-inserting-newline [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <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> @@ -893,12 +893,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + newline?:bool <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> newline? <span class="Constant"> <insert-enter-begin></span> - editor<span class="Special"> <- </span>insert-new-line-and-indent editor, screen + editor <span class="Special"><-</span> insert-new-line-and-indent editor, screen <span class="Constant"> <insert-enter-end></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -906,41 +906,41 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> insert-new-line-and-indent editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen, go-render?:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - screen-height:num<span class="Special"> <- </span>screen-height screen + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + screen-height:num <span class="Special"><-</span> screen-height screen <span class="Comment"># insert newline</span> insert <span class="Constant">10/newline</span>, before-cursor - before-cursor<span class="Special"> <- </span>next before-cursor - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - cursor-row<span class="Special"> <- </span>add cursor-row, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>copy left - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + before-cursor <span class="Special"><-</span> next before-cursor + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + cursor-row <span class="Special"><-</span> add cursor-row,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> copy left + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="Comment"># maybe scroll</span> <span class="Delimiter">{</span> - below-screen?:bool<span class="Special"> <- </span>greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal, never greater</span> + below-screen?:bool <span class="Special"><-</span> greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal, never greater</span> <span class="muControl">break-unless</span> below-screen? <span class="Constant"> <scroll-down></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> - cursor-row<span class="Special"> <- </span>subtract cursor-row, <span class="Constant">1</span> <span class="Comment"># bring back into screen range</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> + cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> <span class="Comment"># bring back into screen range</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row <span class="Delimiter">}</span> <span class="Comment"># indent if necessary</span> - indent?:bool<span class="Special"> <- </span>get *editor, <span class="Constant">indent?:offset</span> + indent?:bool <span class="Special"><-</span> get *editor, <span class="Constant">indent?:offset</span> <span class="muControl">return-unless</span> indent? - d:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> - end-of-previous-line:&:duplex-list:char<span class="Special"> <- </span>prev before-cursor - indent:num<span class="Special"> <- </span>line-indent end-of-previous-line, d - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + d:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> + end-of-previous-line:&:duplex-list:char <span class="Special"><-</span> prev before-cursor + indent:num <span class="Special"><-</span> line-indent end-of-previous-line, d + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - indent-done?:bool<span class="Special"> <- </span>greater-or-equal i, indent + indent-done?:bool <span class="Special"><-</span> greater-or-equal i, indent <span class="muControl">break-if</span> indent-done? - editor, screen, go-render?:bool<span class="Special"> <- </span>insert-at-cursor editor, <span class="Constant">32/space</span>, screen - i<span class="Special"> <- </span>add i, <span class="Constant">1</span> + editor, screen, go-render?:bool <span class="Special"><-</span> 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> ] @@ -950,28 +950,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> line-indent curr:&:duplex-list:char, start:&:duplex-list:char<span class="muRecipe"> -> </span>result:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + result:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="muControl">return-unless</span> curr - at-start?:bool<span class="Special"> <- </span>equal curr, start + at-start?:bool <span class="Special"><-</span> equal curr, start <span class="muControl">return-if</span> at-start? <span class="Delimiter">{</span> - curr<span class="Special"> <- </span>prev curr + curr <span class="Special"><-</span> prev curr <span class="muControl">break-unless</span> curr - at-start?:bool<span class="Special"> <- </span>equal curr, start + at-start?:bool <span class="Special"><-</span> equal curr, start <span class="muControl">break-if</span> at-start? - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <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?:bool<span class="Special"> <- </span>equal c, <span class="Constant">32/space</span> + is-space?:bool <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> + 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> + result <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">}</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> @@ -980,7 +980,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-moves-cursor-down-after-inserting-newline-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">1/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <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> @@ -1000,7 +1000,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-clears-previous-line-completely-after-inserting-newline [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abcde]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abcde]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ press enter ] @@ -1027,70 +1027,70 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-inserts-indent-after-newline [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">10/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[ab</span> + s:text <span class="Special"><-</span> new <span class="Constant">[ab</span> <span class="Constant"> cd</span> <span class="Constant">ef]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 8</span> type [ ] ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <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="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-skips-indent-around-paste [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">10/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[ab</span> + s:text <span class="Special"><-</span> new <span class="Constant">[ab</span> <span class="Constant"> cd</span> <span class="Constant">ef]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># position cursor after 'cd' and hit 'newline' surrounded by paste markers</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">8</span> - press <span class="Constant">65507</span> <span class="Comment"># start paste</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 8</span> + press<span class="Constant"> 65507</span> <span class="Comment"># start paste</span> press enter - press <span class="Constant">65506</span> <span class="Comment"># end paste</span> + press<span class="Constant"> 65506</span> <span class="Comment"># end paste</span> ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <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">0</span> <span class="Comment"># cursor column (not indented)</span> + <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"> 0</span> <span class="Comment"># cursor column (not indented)</span> ] ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - paste-start?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65507/paste-start</span> + paste-start?:bool <span class="Special"><-</span> equal k, <span class="Constant">65507/paste-start</span> <span class="muControl">break-unless</span> paste-start? - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">indent?:offset</span>, <span class="Constant">0/false</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">indent?:offset</span>, <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - paste-end?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65506/paste-end</span> + paste-end?:bool <span class="Special"><-</span> equal k, <span class="Constant">65506/paste-end</span> <span class="muControl">break-unless</span> paste-end? - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">indent?:offset</span>, <span class="Constant">1/true</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">indent?:offset</span>, <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -1100,28 +1100,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> draw-horizontal screen:&:screen, row:num, x:num, right:num<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - style:char, style-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + style:char, style-found?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> style-found? - style<span class="Special"> <- </span>copy <span class="Constant">9472/horizontal</span> + style <span class="Special"><-</span> copy <span class="Constant">9472/horizontal</span> <span class="Delimiter">}</span> - color:num, color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + color:num, color-found?:bool <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? - color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> + color <span class="Special"><-</span> copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> - bg-color:num, bg-color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + bg-color:num, bg-color-found?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> bg-color-found? - bg-color<span class="Special"> <- </span>copy <span class="Constant">0/black</span> + bg-color <span class="Special"><-</span> copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> - screen<span class="Special"> <- </span>move-cursor screen, row, x + screen <span class="Special"><-</span> move-cursor screen, row, x <span class="Delimiter">{</span> - continue?:bool<span class="Special"> <- </span>lesser-or-equal x, right <span class="Comment"># right is inclusive, to match editor semantics</span> + continue?:bool <span class="Special"><-</span> lesser-or-equal x, right <span class="Comment"># right is inclusive, to match editor semantics</span> <span class="muControl">break-unless</span> continue? print screen, style, color, bg-color - x<span class="Special"> <- </span>add x, <span class="Constant">1</span> + x <span class="Special"><-</span> add x,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] diff --git a/html/edit/003-shortcuts.mu.html b/html/edit/003-shortcuts.mu.html index 2dc6965f..cc243281 100644 --- a/html/edit/003-shortcuts.mu.html +++ b/html/edit/003-shortcuts.mu.html @@ -42,9 +42,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</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> - s:text<span class="Special"> <- </span>new <span class="Constant">[ab</span> + s:text <span class="Special"><-</span> new <span class="Constant">[ab</span> <span class="Constant">cd]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ press tab ] @@ -60,13 +60,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - tab?:bool<span class="Special"> <- </span>equal c, <span class="Constant">9/tab</span> + tab?:bool <span class="Special"><-</span> equal c, <span class="Constant">9/tab</span> <span class="muControl">break-unless</span> tab? <span class="Constant"> <insert-character-begin></span> - editor, screen, go-render?:bool<span class="Special"> <- </span>insert-at-cursor editor, <span class="Constant">32/space</span>, screen - editor, screen, go-render?:bool<span class="Special"> <- </span>insert-at-cursor editor, <span class="Constant">32/space</span>, screen + editor, screen, go-render?:bool <span class="Special"><-</span> insert-at-cursor editor, <span class="Constant">32/space</span>, screen + editor, screen, go-render?:bool <span class="Special"><-</span> insert-at-cursor editor, <span class="Constant">32/space</span>, screen <span class="Constant"> <insert-character-end></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -76,17 +76,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-handles-backspace-key [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 1</span> press backspace ] run [ editor-event-loop screen, console, e - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -95,18 +95,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of original line to overwrite</span> + check-trace-count-for-label<span class="Constant"> 3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of original line to overwrite</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - delete-previous-character?:bool<span class="Special"> <- </span>equal c, <span class="Constant">8/backspace</span> + delete-previous-character?:bool <span class="Special"><-</span> equal c, <span class="Constant">8/backspace</span> <span class="muControl">break-unless</span> delete-previous-character? <span class="Constant"> <backspace-character-begin></span> - editor, screen, go-render?:bool, backspaced-cell:&:duplex-list:char<span class="Special"> <- </span>delete-before-cursor editor, screen + editor, screen, go-render?:bool, backspaced-cell:&:duplex-list:char <span class="Special"><-</span> delete-before-cursor editor, screen <span class="Constant"> <backspace-character-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -118,114 +118,114 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> delete-before-cursor editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen, go-render?:bool, backspaced-cell:&:duplex-list:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - data:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + data:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> <span class="Comment"># if at start of text (before-cursor at § sentinel), return</span> - prev:&:duplex-list:char<span class="Special"> <- </span>prev before-cursor - go-render?, backspaced-cell<span class="Special"> <- </span>copy <span class="Constant">0/no-more-render</span>, <span class="Constant">0/nothing-deleted</span> + prev:&:duplex-list:char <span class="Special"><-</span> prev before-cursor + go-render?, backspaced-cell <span class="Special"><-</span> copy <span class="Constant">0/no-more-render</span>, <span class="Constant">0/nothing-deleted</span> <span class="muControl">return-unless</span> prev - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[delete-before-cursor]</span> - original-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - editor, scroll?:bool<span class="Special"> <- </span>move-cursor-coordinates-left editor - backspaced-cell:&:duplex-list:char<span class="Special"> <- </span>copy before-cursor - data<span class="Special"> <- </span>remove before-cursor, data <span class="Comment"># will also neatly trim next/prev pointers in backspaced-cell/before-cursor</span> - before-cursor<span class="Special"> <- </span>copy prev - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[delete-before-cursor]</span> + original-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + editor, scroll?:bool <span class="Special"><-</span> move-cursor-coordinates-left editor + backspaced-cell:&:duplex-list:char <span class="Special"><-</span> copy before-cursor + data <span class="Special"><-</span> remove before-cursor, data <span class="Comment"># will also neatly trim next/prev pointers in backspaced-cell/before-cursor</span> + before-cursor <span class="Special"><-</span> copy prev + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return-if</span> scroll? - screen-width:num<span class="Special"> <- </span>screen-width screen - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> + screen-width:num <span class="Special"><-</span> screen-width screen + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> <span class="Comment"># did we just backspace over a newline?</span> - same-row?:bool<span class="Special"> <- </span>equal cursor-row, original-row - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + same-row?:bool <span class="Special"><-</span> equal cursor-row, original-row + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return-unless</span> same-row? - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - curr:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - screen<span class="Special"> <- </span>move-cursor screen, cursor-row, cursor-column - curr-column:num<span class="Special"> <- </span>copy cursor-column + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + curr:&:duplex-list:char <span class="Special"><-</span> next before-cursor + screen <span class="Special"><-</span> move-cursor screen, cursor-row, cursor-column + curr-column:num <span class="Special"><-</span> copy cursor-column <span class="Delimiter">{</span> <span class="Comment"># hit right margin? give up and let caller render</span> - at-right?:bool<span class="Special"> <- </span>greater-or-equal curr-column, right - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + at-right?:bool <span class="Special"><-</span> greater-or-equal curr-column, right + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return-if</span> at-right? <span class="muControl">break-unless</span> curr <span class="Comment"># newline? done.</span> - currc:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span> + currc:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <span class="Special"><-</span> equal currc, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? - screen<span class="Special"> <- </span>print screen, currc - curr-column<span class="Special"> <- </span>add curr-column, <span class="Constant">1</span> - curr<span class="Special"> <- </span>next curr + screen <span class="Special"><-</span> print screen, currc + curr-column <span class="Special"><-</span> add curr-column,<span class="Constant"> 1</span> + curr <span class="Special"><-</span> next curr <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># we're guaranteed not to be at the right margin</span> - space:char<span class="Special"> <- </span>copy <span class="Constant">32/space</span> - screen<span class="Special"> <- </span>print screen, space - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + space:char <span class="Special"><-</span> copy <span class="Constant">32/space</span> + screen <span class="Special"><-</span> print screen, space + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> ] <span class="muRecipe">def</span> move-cursor-coordinates-left editor:&:editor<span class="muRecipe"> -> </span>editor:&:editor, go-render?:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> <span class="Comment"># if not at left margin, move one character left</span> <span class="Delimiter">{</span> - at-left-margin?:bool<span class="Special"> <- </span>equal cursor-column, left + at-left-margin?:bool <span class="Special"><-</span> equal cursor-column, left <span class="muControl">break-if</span> at-left-margin? - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[decrementing cursor column]</span> - cursor-column<span class="Special"> <- </span>subtract cursor-column, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[decrementing cursor column]</span> + cursor-column <span class="Special"><-</span> subtract cursor-column,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># if at left margin, we must move to previous row:</span> - top-of-screen?:bool<span class="Special"> <- </span>equal cursor-row, <span class="Constant">1</span> <span class="Comment"># exclude menu bar</span> - go-render?:bool<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + top-of-screen?:bool <span class="Special"><-</span> equal cursor-row,<span class="Constant"> 1</span> <span class="Comment"># exclude menu bar</span> + go-render?:bool <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> top-of-screen? - cursor-row<span class="Special"> <- </span>subtract cursor-row, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> top-of-screen? <span class="Constant"> <scroll-up></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># case 1: if previous character was newline, figure out how long the previous line is</span> - previous-character:char<span class="Special"> <- </span>get *before-cursor, <span class="Constant">value:offset</span> - previous-character-is-newline?:bool<span class="Special"> <- </span>equal previous-character, <span class="Constant">10/newline</span> + previous-character:char <span class="Special"><-</span> get *before-cursor, <span class="Constant">value:offset</span> + previous-character-is-newline?:bool <span class="Special"><-</span> equal previous-character, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> previous-character-is-newline? <span class="Comment"># compute length of previous line</span> - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[switching to previous line]</span> - d:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> - end-of-line:num<span class="Special"> <- </span>previous-line-length before-cursor, d - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - width:num<span class="Special"> <- </span>subtract right, left - wrap?:bool<span class="Special"> <- </span>greater-than end-of-line, width + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[switching to previous line]</span> + d:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> + end-of-line:num <span class="Special"><-</span> previous-line-length before-cursor, d + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + width:num <span class="Special"><-</span> subtract right, left + wrap?:bool <span class="Special"><-</span> greater-than end-of-line, width <span class="Delimiter">{</span> <span class="muControl">break-unless</span> wrap? - _, column-offset:num<span class="Special"> <- </span>divide-with-remainder end-of-line, width - cursor-column<span class="Special"> <- </span>add left, column-offset - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + _, column-offset:num <span class="Special"><-</span> divide-with-remainder end-of-line, width + cursor-column <span class="Special"><-</span> add left, column-offset + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> wrap? - cursor-column<span class="Special"> <- </span>add left, end-of-line - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + cursor-column <span class="Special"><-</span> add left, end-of-line + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># case 2: if previous-character was not newline, we're just at a wrapped line</span> - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[wrapping to previous line]</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - cursor-column<span class="Special"> <- </span>subtract right, <span class="Constant">1</span> <span class="Comment"># leave room for wrap icon</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[wrapping to previous line]</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + cursor-column <span class="Special"><-</span> subtract right,<span class="Constant"> 1</span> <span class="Comment"># leave room for wrap icon</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column ] <span class="Comment"># takes a pointer 'curr' into the doubly-linked list and its sentinel, counts</span> @@ -233,19 +233,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> previous-line-length curr:&:duplex-list:char, start:&:duplex-list:char<span class="muRecipe"> -> </span>result:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + result:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="muControl">return-unless</span> curr - at-start?:bool<span class="Special"> <- </span>equal curr, start + at-start?:bool <span class="Special"><-</span> equal curr, start <span class="muControl">return-if</span> at-start? <span class="Delimiter">{</span> - curr<span class="Special"> <- </span>prev curr + curr <span class="Special"><-</span> prev curr <span class="muControl">break-unless</span> curr - at-start?:bool<span class="Special"> <- </span>equal curr, start + at-start?:bool <span class="Special"><-</span> equal curr, start <span class="muControl">break-if</span> at-start? - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <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> + result <span class="Special"><-</span> add result,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -254,17 +254,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</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> - s:text<span class="Special"> <- </span>new <span class="Constant">[ab</span> + s:text <span class="Special"><-</span> new <span class="Constant">[ab</span> <span class="Constant">cd]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">0</span> <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> press backspace ] run [ editor-event-loop screen, console, e - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -273,8 +273,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] ] @@ -282,14 +282,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with two long-ish but non-wrapping lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc def</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc def</span> <span class="Constant">ghi jkl]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># position the cursor at the start of the second and hit backspace</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 0</span> press backspace ] run [ @@ -309,7 +309,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor in part of the screen with a long line</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc def ghij]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">8/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc def ghij]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">8/right</span> editor-render screen, e <span class="Comment"># confirm that it wraps</span> screen-should-contain [ @@ -321,7 +321,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> $clear-trace</span> <span class="Comment"># position the cursor somewhere in the middle of the top screen line and hit backspace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">4</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 4</span> press backspace ] run [ @@ -342,7 +342,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-handles-delete-key [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ @@ -357,7 +357,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of original line to overwrite</span> + check-trace-count-for-label<span class="Constant"> 3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of original line to overwrite</span> <span class="Constant"> $clear-trace</span> assume-console [ press delete @@ -371,15 +371,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span> <span class="Comment"># new length to overwrite</span> + check-trace-count-for-label<span class="Constant"> 2</span>, <span class="Constant">[print-character]</span> <span class="Comment"># new length to overwrite</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - delete-next-character?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65522/delete</span> + delete-next-character?:bool <span class="Special"><-</span> equal k, <span class="Constant">65522/delete</span> <span class="muControl">break-unless</span> delete-next-character? <span class="Constant"> <delete-character-begin></span> - editor, screen, go-render?:bool, deleted-cell:&:duplex-list:char<span class="Special"> <- </span>delete-at-cursor editor, screen + editor, screen, go-render?:bool, deleted-cell:&:duplex-list:char <span class="Special"><-</span> delete-at-cursor editor, screen <span class="Constant"> <delete-character-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -388,42 +388,42 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> delete-at-cursor editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen, go-render?:bool, deleted-cell:&:duplex-list:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - data:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> - deleted-cell:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + data:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> + deleted-cell:&:duplex-list:char <span class="Special"><-</span> next before-cursor + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-unless</span> deleted-cell - currc:char<span class="Special"> <- </span>get *deleted-cell, <span class="Constant">value:offset</span> - data<span class="Special"> <- </span>remove deleted-cell, data - deleted-newline?:bool<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + currc:char <span class="Special"><-</span> get *deleted-cell, <span class="Constant">value:offset</span> + data <span class="Special"><-</span> remove deleted-cell, data + deleted-newline?:bool <span class="Special"><-</span> equal currc, <span class="Constant">10/newline</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return-if</span> deleted-newline? <span class="Comment"># wasn't a newline? render rest of line</span> - curr:&:duplex-list:char<span class="Special"> <- </span>next before-cursor <span class="Comment"># refresh after remove above</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - screen<span class="Special"> <- </span>move-cursor screen, cursor-row, cursor-column - curr-column:num<span class="Special"> <- </span>copy cursor-column - screen-width:num<span class="Special"> <- </span>screen-width screen + curr:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="Comment"># refresh after remove above</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + screen <span class="Special"><-</span> move-cursor screen, cursor-row, cursor-column + curr-column:num <span class="Special"><-</span> copy cursor-column + screen-width:num <span class="Special"><-</span> screen-width screen <span class="Delimiter">{</span> <span class="Comment"># hit right margin? give up and let caller render</span> - at-right?:bool<span class="Special"> <- </span>greater-or-equal curr-column, screen-width - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + at-right?:bool <span class="Special"><-</span> greater-or-equal curr-column, screen-width + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return-if</span> at-right? <span class="muControl">break-unless</span> curr <span class="Comment"># newline? done.</span> - currc:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span> + currc:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <span class="Special"><-</span> equal currc, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? - screen<span class="Special"> <- </span>print screen, currc - curr-column<span class="Special"> <- </span>add curr-column, <span class="Constant">1</span> - curr<span class="Special"> <- </span>next curr + screen <span class="Special"><-</span> print screen, currc + curr-column <span class="Special"><-</span> add curr-column,<span class="Constant"> 1</span> + curr <span class="Special"><-</span> next curr <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># we're guaranteed not to be at the right margin</span> - space:char<span class="Special"> <- </span>copy <span class="Constant">32/space</span> - screen<span class="Special"> <- </span>print screen, space - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + space:char <span class="Special"><-</span> copy <span class="Constant">32/space</span> + screen <span class="Special"><-</span> print screen, space + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> ] <span class="Comment"># right arrow</span> @@ -431,7 +431,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-moves-cursor-right-with-key [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ @@ -447,23 +447,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># 0 and following characters</span> + check-trace-count-for-label<span class="Constant"> 3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># 0 and following characters</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - move-to-next-character?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65514/right-arrow</span> + move-to-next-character?:bool <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> - next-cursor:&:duplex-list:char<span class="Special"> <- </span>next before-cursor + next-cursor:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="muControl">break-unless</span> next-cursor <span class="Comment"># scan to next character</span> <span class="Constant"> <move-cursor-begin></span> - before-cursor<span class="Special"> <- </span>copy next-cursor - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - editor, go-render?:bool<span class="Special"> <- </span>move-cursor-coordinates-right editor, screen-height - screen<span class="Special"> <- </span>move-cursor screen, cursor-row, cursor-column - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">2/right-arrow</span> + before-cursor <span class="Special"><-</span> copy next-cursor + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + editor, go-render?:bool <span class="Special"><-</span> move-cursor-coordinates-right editor, screen-height + screen <span class="Special"><-</span> move-cursor screen, cursor-row, cursor-column + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">2/right-arrow</span> <span class="Constant"> <move-cursor-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -472,65 +472,65 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> move-cursor-coordinates-right editor:&:editor, screen-height:num<span class="muRecipe"> -> </span>editor:&:editor, go-render?:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor <span class="Constant">before-cursor:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor <span class="Constant">before-cursor:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> <span class="Comment"># if crossed a newline, move cursor to start of next row</span> <span class="Delimiter">{</span> - old-cursor-character:char<span class="Special"> <- </span>get *before-cursor, <span class="Constant">value:offset</span> - was-at-newline?:bool<span class="Special"> <- </span>equal old-cursor-character, <span class="Constant">10/newline</span> + old-cursor-character:char <span class="Special"><-</span> get *before-cursor, <span class="Constant">value:offset</span> + was-at-newline?:bool <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> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>copy left - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - below-screen?:bool<span class="Special"> <- </span>greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + cursor-row <span class="Special"><-</span> add cursor-row,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> copy left + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + below-screen?:bool <span class="Special"><-</span> greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-unless</span> below-screen? <span class="Constant"> <scroll-down></span> - cursor-row<span class="Special"> <- </span>subtract cursor-row, <span class="Constant">1</span> <span class="Comment"># bring back into screen range</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> <span class="Comment"># bring back into screen range</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</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:num<span class="Special"> <- </span>subtract right, <span class="Constant">1</span> - at-wrap?:bool<span class="Special"> <- </span>equal cursor-column, wrap-column + wrap-column:num <span class="Special"><-</span> subtract right,<span class="Constant"> 1</span> + at-wrap?:bool <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> - next:&:duplex-list:char<span class="Special"> <- </span>next before-cursor + next:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="muControl">break-unless</span> next - next-character:char<span class="Special"> <- </span>get *next, <span class="Constant">value:offset</span> - newline?:bool<span class="Special"> <- </span>equal next-character, <span class="Constant">10/newline</span> + next-character:char <span class="Special"><-</span> get *next, <span class="Constant">value:offset</span> + newline?:bool <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> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>copy left - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - below-screen?:bool<span class="Special"> <- </span>greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal</span> - <span class="muControl">return-unless</span> below-screen?, editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span> + cursor-row <span class="Special"><-</span> add cursor-row,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> copy left + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + below-screen?:bool <span class="Special"><-</span> greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal</span> + <span class="muControl">return-unless</span> below-screen?, editor/same-as-ingredient:0, <span class="Constant">0/no-more-render</span> <span class="Constant"> <scroll-down></span> - cursor-row<span class="Special"> <- </span>subtract cursor-row, <span class="Constant">1</span> <span class="Comment"># bring back into screen range</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> <span class="Comment"># bring back into screen range</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise move cursor one character right</span> - cursor-column<span class="Special"> <- </span>add cursor-column, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + cursor-column <span class="Special"><-</span> add cursor-column,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># type right-arrow a few times to get to start of second line</span> @@ -543,7 +543,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> <span class="Comment"># type something and ensure it goes where it should</span> assume-console [ type <span class="Constant">[0]</span> @@ -558,15 +558,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span> <span class="Comment"># new length of second line</span> + check-trace-count-for-label<span class="Constant"> 2</span>, <span class="Constant">[print-character]</span> <span class="Comment"># new length of second line</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">1/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">1/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console [ press right-arrow @@ -590,17 +590,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abcdef]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abcdef]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 3</span> press right-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -610,32 +610,32 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># line just barely wrapping</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abcde]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abcde]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># position cursor at last character before wrap and hit right-arrow</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 3</span> press right-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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 [ @@ -643,30 +643,30 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abcdef]</span>, screen, <span class="Constant">1/left</span>, <span class="Constant">6/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abcdef]</span>, screen, <span class="Constant">1/left</span>, <span class="Constant">6/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">4</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 4</span> press right-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -676,23 +676,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># move to end of line, press right-arrow, type a character</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 3</span> press right-arrow type <span class="Constant">[0]</span> ] @@ -707,7 +707,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 2</span>, <span class="Constant">[print-character]</span> ] <span class="Comment"># todo: ctrl-right: next word-end</span> @@ -717,11 +717,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> editor-moves-cursor-left-with-key [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 2</span> press left-arrow type <span class="Constant">[0]</span> ] @@ -734,23 +734,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 3</span>, <span class="Constant">[print-character]</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - move-to-previous-character?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65515/left-arrow</span> + move-to-previous-character?:bool <span class="Special"><-</span> equal k, <span class="Constant">65515/left-arrow</span> <span class="muControl">break-unless</span> move-to-previous-character? - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[left arrow]</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[left arrow]</span> <span class="Comment"># if not at start of text (before-cursor at § sentinel)</span> - prev:&:duplex-list:char<span class="Special"> <- </span>prev before-cursor - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + prev:&:duplex-list:char <span class="Special"><-</span> prev before-cursor + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-unless</span> prev <span class="Constant"> <move-cursor-begin></span> - editor, go-render?<span class="Special"> <- </span>move-cursor-coordinates-left editor - before-cursor<span class="Special"> <- </span>copy prev - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">1/left-arrow</span> + editor, go-render? <span class="Special"><-</span> move-cursor-coordinates-left editor + before-cursor <span class="Special"><-</span> copy prev + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">1/left-arrow</span> <span class="Constant"> <move-cursor-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -760,42 +760,42 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with two lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># position cursor at start of second line (so there's no previous newline)</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 0</span> press left-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with three lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">g]</span> - e:&:editor<span class="Special"> <- </span>new-editor s:text, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s:text, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</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 <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> press left-arrow type <span class="Constant">[0]</span> ] @@ -809,21 +809,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .g .</span> <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> ] - check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> <span class="Comment"># just the '0'</span> + check-trace-count-for-label<span class="Constant"> 1</span>, <span class="Constant">[print-character]</span> <span class="Comment"># just the '0'</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-3 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">g]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># position cursor at start of text, press left-arrow, then type a character</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 0</span> press left-arrow type <span class="Constant">[0]</span> ] @@ -838,22 +838,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .g .</span> <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> ] - check-trace-count-for-label <span class="Constant">4</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of first line</span> + check-trace-count-for-label<span class="Constant"> 4</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of first line</span> ] <span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-4 [ <span class="Constant">local-scope</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> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> d] - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e:&:editor <span class="Constant"> $clear-trace</span> <span class="Comment"># position cursor right after empty line</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> press left-arrow type <span class="Constant">[0]</span> ] @@ -867,14 +867,14 @@ d] <span class="Constant"> .d .</span> <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> ] - check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> <span class="Comment"># just the '0'</span> + check-trace-count-for-label<span class="Constant"> 1</span>, <span class="Constant">[print-character]</span> <span class="Comment"># just the '0'</span> ] <span class="muScenario">scenario</span> editor-moves-across-screen-lines-across-wrap-with-left-arrow [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with a wrapping line</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abcdef]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abcdef]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> screen-should-contain [ @@ -886,28 +886,28 @@ d] ] <span class="Comment"># position cursor right after empty line</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 0</span> press left-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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"># right margin except wrap icon</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"># right margin except wrap icon</span> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-across-screen-lines-to-wrapping-line-with-left-arrow [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with a wrapping line followed by a second line</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abcdef</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcdef</span> <span class="Constant">g]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> screen-should-contain [ @@ -919,28 +919,28 @@ d] ] <span class="Comment"># position cursor right after empty line</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> press left-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># previous row</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span> <span class="Comment"># end of wrapped line</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 2</span> <span class="Comment"># previous row</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 2</span> <span class="Comment"># end of wrapped line</span> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-across-screen-lines-to-non-wrapping-line-with-left-arrow [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize editor with a line on the verge of wrapping, followed by a second line</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abcd</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcd</span> <span class="Constant">e]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> screen-should-contain [ @@ -952,19 +952,19 @@ d] ] <span class="Comment"># position cursor right after empty line</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 0</span> press left-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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">4</span> <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"> 4</span> <span class="Comment"># end of wrapped line</span> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="Comment"># todo: ctrl-left: previous word-start</span> @@ -974,25 +974,25 @@ d] <span class="muScenario">scenario</span> editor-moves-to-previous-line-with-up-arrow [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press up-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> assume-console [ type <span class="Constant">[0]</span> ] @@ -1010,11 +1010,11 @@ d] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - move-to-previous-line?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65517/up-arrow</span> + move-to-previous-line?:bool <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="Constant"> <move-cursor-begin></span> - editor, go-render?<span class="Special"> <- </span>move-to-previous-line editor - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">3/up-arrow</span> + editor, go-render? <span class="Special"><-</span> move-to-previous-line editor + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">3/up-arrow</span> <span class="Constant"> <move-cursor-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -1023,67 +1023,67 @@ d] <span class="muRecipe">def</span> move-to-previous-line editor:&:editor<span class="muRecipe"> -> </span>editor:&:editor, go-render?:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - already-at-top?:bool<span class="Special"> <- </span>lesser-or-equal cursor-row, <span class="Constant">1/top</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + already-at-top?:bool <span class="Special"><-</span> lesser-or-equal cursor-row, <span class="Constant">1/top</span> <span class="Delimiter">{</span> <span class="Comment"># if cursor not at top, move it</span> <span class="muControl">break-if</span> already-at-top? <span class="Comment"># if not at newline, move to start of line (previous newline)</span> <span class="Comment"># then scan back another line</span> <span class="Comment"># if either step fails, give up without modifying cursor or coordinates</span> - curr:&:duplex-list:char<span class="Special"> <- </span>copy before-cursor + curr:&:duplex-list:char <span class="Special"><-</span> copy before-cursor <span class="Delimiter">{</span> - old:&:duplex-list:char<span class="Special"> <- </span>copy curr - c2:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal c2, <span class="Constant">10/newline</span> + old:&:duplex-list:char <span class="Special"><-</span> copy curr + c2:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <span class="Special"><-</span> equal c2, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? - curr:&:duplex-list:char<span class="Special"> <- </span>before-previous-line curr, editor - no-motion?:bool<span class="Special"> <- </span>equal curr, old - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + curr:&:duplex-list:char <span class="Special"><-</span> before-previous-line curr, editor + no-motion?:bool <span class="Special"><-</span> equal curr, old + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-if</span> no-motion? <span class="Delimiter">}</span> <span class="Delimiter">{</span> - old<span class="Special"> <- </span>copy curr - curr<span class="Special"> <- </span>before-previous-line curr, editor - no-motion?:bool<span class="Special"> <- </span>equal curr, old - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + old <span class="Special"><-</span> copy curr + curr <span class="Special"><-</span> before-previous-line curr, editor + no-motion?:bool <span class="Special"><-</span> equal curr, old + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-if</span> no-motion? <span class="Delimiter">}</span> - before-cursor<span class="Special"> <- </span>copy curr - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - cursor-row<span class="Special"> <- </span>subtract cursor-row, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + before-cursor <span class="Special"><-</span> copy curr + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row <span class="Comment"># scan ahead to right column or until end of line</span> - target-column:num<span class="Special"> <- </span>copy cursor-column - cursor-column<span class="Special"> <- </span>copy left - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + target-column:num <span class="Special"><-</span> copy cursor-column + cursor-column <span class="Special"><-</span> copy left + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal cursor-column, target-column + done?:bool <span class="Special"><-</span> greater-or-equal cursor-column, target-column <span class="muControl">break-if</span> done? - curr:&:duplex-list:char<span class="Special"> <- </span>next before-cursor + curr:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="muControl">break-unless</span> curr - currc:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span> + currc:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <span class="Special"><-</span> equal currc, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? <span class="Comment">#</span> - before-cursor<span class="Special"> <- </span>copy curr - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - cursor-column<span class="Special"> <- </span>add cursor-column, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + before-cursor <span class="Special"><-</span> copy curr + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + cursor-column <span class="Special"><-</span> add cursor-column,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="muControl">loop</span> <span class="Delimiter">}</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># if cursor already at top, scroll up</span> <span class="muControl">break-unless</span> already-at-top? <span class="Constant"> <scroll-up></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -1091,25 +1091,25 @@ d] <span class="muScenario">scenario</span> editor-adjusts-column-at-previous-line [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[ab</span> + s:text <span class="Special"><-</span> new <span class="Constant">[ab</span> <span class="Constant">def]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 3</span> press up-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> assume-console [ type <span class="Constant">[0]</span> ] @@ -1128,25 +1128,25 @@ d] <span class="muScenario">scenario</span> editor-adjusts-column-at-empty-line [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new [ + s:text <span class="Special"><-</span> new [ <span class="muRecipe">def</span>] - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 3</span> press up-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> assume-console [ type <span class="Constant">[0]</span> ] @@ -1166,27 +1166,27 @@ d] <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># start out with three lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># click on the third line and hit up-arrow, so you end up just after a newline</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> press up-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> assume-console [ type <span class="Constant">[0]</span> ] @@ -1207,9 +1207,9 @@ d] <span class="muScenario">scenario</span> editor-moves-to-next-line-with-down-arrow [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># cursor starts out at (1, 0)</span> @@ -1218,15 +1218,15 @@ d] ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># ..and ends at (2, 0)</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> assume-console [ type <span class="Constant">[0]</span> ] @@ -1244,11 +1244,11 @@ d] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - move-to-next-line?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65516/down-arrow</span> + move-to-next-line?:bool <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="Constant"> <move-cursor-begin></span> - editor, go-render?<span class="Special"> <- </span>move-to-next-line editor, screen-height - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">4/down-arrow</span> + editor, go-render? <span class="Special"><-</span> move-to-next-line editor, screen-height + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">4/down-arrow</span> <span class="Constant"> <move-cursor-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -1257,81 +1257,81 @@ d] <span class="muRecipe">def</span> move-to-next-line editor:&:editor, screen-height:num<span class="muRecipe"> -> </span>editor:&:editor, go-render?:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - last-line:num<span class="Special"> <- </span>subtract screen-height, <span class="Constant">1</span> - already-at-bottom?:bool<span class="Special"> <- </span>greater-or-equal cursor-row, last-line + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + last-line:num <span class="Special"><-</span> subtract screen-height,<span class="Constant"> 1</span> + already-at-bottom?:bool <span class="Special"><-</span> greater-or-equal cursor-row, last-line <span class="Delimiter">{</span> <span class="Comment"># if cursor not at bottom, move it</span> <span class="muControl">break-if</span> already-at-bottom? <span class="Comment"># scan to start of next line, then to right column or until end of line</span> - max:num<span class="Special"> <- </span>subtract right, left - next-line:&:duplex-list:char<span class="Special"> <- </span>before-start-of-next-line before-cursor, max + max:num <span class="Special"><-</span> subtract right, left + next-line:&:duplex-list:char <span class="Special"><-</span> before-start-of-next-line before-cursor, max <span class="Delimiter">{</span> <span class="Comment"># already at end of buffer? try to scroll up (so we can see more</span> <span class="Comment"># warnings or sandboxes below)</span> - no-motion?:bool<span class="Special"> <- </span>equal next-line, before-cursor + no-motion?:bool <span class="Special"><-</span> equal next-line, before-cursor <span class="muControl">break-unless</span> no-motion? - scroll?:bool<span class="Special"> <- </span>greater-than cursor-row, <span class="Constant">1</span> + scroll?:bool <span class="Special"><-</span> greater-than cursor-row,<span class="Constant"> 1</span> <span class="muControl">break-if</span> scroll?, <span class="Constant">+try-to-scroll</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> - cursor-row<span class="Special"> <- </span>add cursor-row, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - before-cursor<span class="Special"> <- </span>copy next-line - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - target-column:num<span class="Special"> <- </span>copy cursor-column - cursor-column<span class="Special"> <- </span>copy left - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + cursor-row <span class="Special"><-</span> add cursor-row,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + before-cursor <span class="Special"><-</span> copy next-line + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + target-column:num <span class="Special"><-</span> copy cursor-column + cursor-column <span class="Special"><-</span> copy left + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal cursor-column, target-column + done?:bool <span class="Special"><-</span> greater-or-equal cursor-column, target-column <span class="muControl">break-if</span> done? - curr:&:duplex-list:char<span class="Special"> <- </span>next before-cursor + curr:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="muControl">break-unless</span> curr - currc:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span> + currc:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <span class="Special"><-</span> equal currc, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? <span class="Comment">#</span> - before-cursor<span class="Special"> <- </span>copy curr - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - cursor-column<span class="Special"> <- </span>add cursor-column, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + before-cursor <span class="Special"><-</span> copy curr + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + cursor-column <span class="Special"><-</span> add cursor-column,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="muControl">loop</span> <span class="Delimiter">}</span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Constant"> +try-to-scroll</span> <span class="Constant"> <scroll-down></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> ] <span class="muScenario">scenario</span> editor-adjusts-column-at-next-line [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">de]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 3</span> press down-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> assume-console [ type <span class="Constant">[0]</span> ] @@ -1352,51 +1352,51 @@ d] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-ctrl-a [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># start on second line, press ctrl-a</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 3</span> press ctrl-a ] run [ editor-event-loop screen, console, e - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves to start of line</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - move-to-start-of-line?:bool<span class="Special"> <- </span>equal c, <span class="Constant">1/ctrl-a</span> + move-to-start-of-line?:bool <span class="Special"><-</span> equal c, <span class="Constant">1/ctrl-a</span> <span class="muControl">break-unless</span> move-to-start-of-line? <span class="Constant"> <move-cursor-begin></span> move-to-start-of-line editor - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - move-to-start-of-line?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65521/home</span> + move-to-start-of-line?:bool <span class="Special"><-</span> equal k, <span class="Constant">65521/home</span> <span class="muControl">break-unless</span> move-to-start-of-line? <span class="Constant"> <move-cursor-begin></span> move-to-start-of-line editor - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -1405,21 +1405,21 @@ d] <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># update cursor column</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - cursor-column:num<span class="Special"> <- </span>copy left - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + cursor-column:num <span class="Special"><-</span> copy left + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="Comment"># update before-cursor</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - init:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + init:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> <span class="Comment"># while not at start of line, move </span> <span class="Delimiter">{</span> - at-start-of-text?:bool<span class="Special"> <- </span>equal before-cursor, init + at-start-of-text?:bool <span class="Special"><-</span> equal before-cursor, init <span class="muControl">break-if</span> at-start-of-text? - prev:char<span class="Special"> <- </span>get *before-cursor, <span class="Constant">value:offset</span> - at-start-of-line?:bool<span class="Special"> <- </span>equal prev, <span class="Constant">10/newline</span> + prev:char <span class="Special"><-</span> get *before-cursor, <span class="Constant">value:offset</span> + at-start-of-line?:bool <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 before-cursor - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + before-cursor <span class="Special"><-</span> prev before-cursor + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, 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> @@ -1428,78 +1428,78 @@ d] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-ctrl-a-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># start on first line (no newline before), press ctrl-a</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 3</span> press ctrl-a ] run [ editor-event-loop screen, console, e - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves to start of line</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-home [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Constant"> $clear-trace</span> <span class="Comment"># start on second line, press 'home'</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 3</span> press home ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves to start of line</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-home-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># start on first line (no newline before), press 'home'</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 3</span> press home ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves to start of line</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="Comment"># ctrl-e/end - move cursor to end of line</span> @@ -1507,39 +1507,39 @@ d] <span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-ctrl-e [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># start on first line, press ctrl-e</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 1</span> press ctrl-e ] run [ editor-event-loop screen, console, e - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves to end of line</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> <span class="Comment"># editor inserts future characters at cursor</span> assume-console [ type <span class="Constant">[z]</span> ] run [ editor-event-loop screen, console, e - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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> + <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> @@ -1548,31 +1548,31 @@ d] <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 1</span>, <span class="Constant">[print-character]</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - move-to-end-of-line?:bool<span class="Special"> <- </span>equal c, <span class="Constant">5/ctrl-e</span> + move-to-end-of-line?:bool <span class="Special"><-</span> equal c, <span class="Constant">5/ctrl-e</span> <span class="muControl">break-unless</span> move-to-end-of-line? <span class="Constant"> <move-cursor-begin></span> move-to-end-of-line editor - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - move-to-end-of-line?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65520/end</span> + move-to-end-of-line?:bool <span class="Special"><-</span> equal k, <span class="Constant">65520/end</span> <span class="muControl">break-unless</span> move-to-end-of-line? <span class="Constant"> <move-cursor-begin></span> move-to-end-of-line editor - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -1580,19 +1580,19 @@ d] <span class="muRecipe">def</span> move-to-end-of-line editor:&:editor<span class="muRecipe"> -> </span>editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> <span class="Comment"># while not at start of line, move </span> <span class="Delimiter">{</span> - next:&:duplex-list:char<span class="Special"> <- </span>next before-cursor + next:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="muControl">break-unless</span> next <span class="Comment"># end of text</span> - nextc:char<span class="Special"> <- </span>get *next, <span class="Constant">value:offset</span> - at-end-of-line?:bool<span class="Special"> <- </span>equal nextc, <span class="Constant">10/newline</span> + nextc:char <span class="Special"><-</span> get *next, <span class="Constant">value:offset</span> + at-end-of-line?:bool <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 - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - cursor-column<span class="Special"> <- </span>add cursor-column, <span class="Constant">1</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + before-cursor <span class="Special"><-</span> copy next + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + cursor-column <span class="Special"><-</span> add cursor-column,<span class="Constant"> 1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -1600,79 +1600,79 @@ d] <span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-ctrl-e-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># start on second line (no newline after), press ctrl-e</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press ctrl-e ] run [ editor-event-loop screen, console, e - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves to end of line</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-end [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># start on first line, press 'end'</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 1</span> press end ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves to end of line</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-end-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># start on second line (no newline after), press 'end'</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press end ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves to end of line</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> ] <span class="Comment"># ctrl-u - delete text from start of line until (but not at) cursor</span> @@ -1680,12 +1680,12 @@ d] <span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">2</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 2</span> press ctrl-u ] run [ @@ -1703,12 +1703,12 @@ d] <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - delete-to-start-of-line?:bool<span class="Special"> <- </span>equal c, <span class="Constant">21/ctrl-u</span> + delete-to-start-of-line?:bool <span class="Special"><-</span> equal c, <span class="Constant">21/ctrl-u</span> <span class="muControl">break-unless</span> delete-to-start-of-line? <span class="Constant"> <delete-to-start-of-line-begin></span> - deleted-cells:&:duplex-list:char<span class="Special"> <- </span>delete-to-start-of-line editor + deleted-cells:&:duplex-list:char <span class="Special"><-</span> delete-to-start-of-line editor <span class="Constant"> <delete-to-start-of-line-end></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -1717,39 +1717,39 @@ d] <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># compute range to delete</span> - init:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - start:&:duplex-list:char<span class="Special"> <- </span>copy before-cursor - end:&:duplex-list:char<span class="Special"> <- </span>next before-cursor + init:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + start:&:duplex-list:char <span class="Special"><-</span> copy before-cursor + end:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="Delimiter">{</span> - at-start-of-text?:bool<span class="Special"> <- </span>equal start, init + at-start-of-text?:bool <span class="Special"><-</span> equal start, init <span class="muControl">break-if</span> at-start-of-text? - curr:char<span class="Special"> <- </span>get *start, <span class="Constant">value:offset</span> - at-start-of-line?:bool<span class="Special"> <- </span>equal curr, <span class="Constant">10/newline</span> + curr:char <span class="Special"><-</span> get *start, <span class="Constant">value:offset</span> + at-start-of-line?:bool <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 start + start <span class="Special"><-</span> prev 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> - result:&:duplex-list:char<span class="Special"> <- </span>next start + result:&:duplex-list:char <span class="Special"><-</span> next start remove-between start, end <span class="Comment"># adjust cursor</span> - before-cursor<span class="Special"> <- </span>copy start - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, left + before-cursor <span class="Special"><-</span> copy start + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, left ] <span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">1</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 2</span> press ctrl-u ] run [ @@ -1768,12 +1768,12 @@ d] <span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u-3 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">1</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 3</span> press ctrl-u ] run [ @@ -1792,12 +1792,12 @@ d] <span class="muScenario">scenario</span> editor-deletes-to-start-of-final-line-with-ctrl-u [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> <span class="Comment"># start past end of final line, press ctrl-u</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 3</span> press ctrl-u ] run [ @@ -1818,12 +1818,12 @@ d] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">1</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 1</span> press ctrl-k ] run [ @@ -1841,12 +1841,12 @@ d] <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - delete-to-end-of-line?:bool<span class="Special"> <- </span>equal c, <span class="Constant">11/ctrl-k</span> + delete-to-end-of-line?:bool <span class="Special"><-</span> equal c, <span class="Constant">11/ctrl-k</span> <span class="muControl">break-unless</span> delete-to-end-of-line? <span class="Constant"> <delete-to-end-of-line-begin></span> - deleted-cells:&:duplex-list:char<span class="Special"> <- </span>delete-to-end-of-line editor + deleted-cells:&:duplex-list:char <span class="Special"><-</span> delete-to-end-of-line editor <span class="Constant"> <delete-to-end-of-line-end></span> - go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -1855,31 +1855,31 @@ d] <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># compute range to delete</span> - start:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - end:&:duplex-list:char<span class="Special"> <- </span>next start + start:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + end:&:duplex-list:char <span class="Special"><-</span> next start <span class="Delimiter">{</span> - at-end-of-text?:bool<span class="Special"> <- </span>equal end, <span class="Constant">0/null</span> + at-end-of-text?:bool <span class="Special"><-</span> equal end, <span class="Constant">0/null</span> <span class="muControl">break-if</span> at-end-of-text? - curr:char<span class="Special"> <- </span>get *end, <span class="Constant">value:offset</span> - at-end-of-line?:bool<span class="Special"> <- </span>equal curr, <span class="Constant">10/newline</span> + curr:char <span class="Special"><-</span> get *end, <span class="Constant">value:offset</span> + at-end-of-line?:bool <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 end + end <span class="Special"><-</span> next end <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># snip it out</span> - result<span class="Special"> <- </span>next start + result <span class="Special"><-</span> next start remove-between start, end ] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-2 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press ctrl-k ] run [ @@ -1898,12 +1898,12 @@ d] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-3 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">1</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 2</span> press ctrl-k ] run [ @@ -1922,12 +1922,12 @@ d] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-4 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">1</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 3</span> press ctrl-k ] run [ @@ -1946,12 +1946,12 @@ d] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-5 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">2</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 2</span> press ctrl-k ] run [ @@ -1970,12 +1970,12 @@ d] <span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-6 [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[123</span> + s:text <span class="Special"><-</span> new <span class="Constant">[123</span> <span class="Constant">456]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <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 <span class="Constant">2</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 3</span> press ctrl-k ] run [ @@ -1998,11 +1998,11 @@ d] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with >3 lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .a .</span> @@ -2011,7 +2011,7 @@ d] ] <span class="Comment"># position cursor at last line, then try to move further down</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> press down-arrow ] run [ @@ -2027,16 +2027,16 @@ d] ] <span class="muRecipe">after</span> <span class="Constant"><scroll-down></span> [ - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[scroll down]</span> - top-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - max:num<span class="Special"> <- </span>subtract right, left - old-top:&:duplex-list:char<span class="Special"> <- </span>copy top-of-screen - top-of-screen<span class="Special"> <- </span>before-start-of-next-line top-of-screen, max - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top-of-screen - no-movement?:bool<span class="Special"> <- </span>equal old-top, top-of-screen - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[scroll down]</span> + top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + max:num <span class="Special"><-</span> subtract right, left + old-top:&:duplex-list:char <span class="Special"><-</span> copy top-of-screen + top-of-screen <span class="Special"><-</span> before-start-of-next-line top-of-screen, max + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top-of-screen + no-movement?:bool <span class="Special"><-</span> equal old-top, top-of-screen + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-if</span> no-movement? ] @@ -2046,25 +2046,25 @@ d] <span class="muRecipe">def</span> before-start-of-next-line original:&:duplex-list:char, max:num<span class="muRecipe"> -> </span>curr:&:duplex-list:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - count:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - curr:&:duplex-list:char<span class="Special"> <- </span>copy original + count:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + curr:&:duplex-list:char <span class="Special"><-</span> copy original <span class="Comment"># skip the initial newline if it exists</span> <span class="Delimiter">{</span> - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> at-newline? - curr<span class="Special"> <- </span>next curr - count<span class="Special"> <- </span>add count, <span class="Constant">1</span> + curr <span class="Special"><-</span> next curr + count <span class="Special"><-</span> add count,<span class="Constant"> 1</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">return-unless</span> curr, original - done?:bool<span class="Special"> <- </span>greater-or-equal count, max + done?:bool <span class="Special"><-</span> greater-or-equal count, max <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - at-newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + at-newline?:bool <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">break-if</span> at-newline? - curr<span class="Special"> <- </span>next curr - count<span class="Special"> <- </span>add count, <span class="Constant">1</span> + curr <span class="Special"><-</span> next curr + count <span class="Special"><-</span> add count,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">return-unless</span> curr, original @@ -2077,11 +2077,11 @@ d] assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with a long, wrapped line and more than a screen of</span> <span class="Comment"># other lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abcdef</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcdef</span> <span class="Constant">g</span> <span class="Constant">h</span> <span class="Constant">i]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcd↩ .</span> @@ -2090,7 +2090,7 @@ d] ] <span class="Comment"># position cursor at last line, then try to move further down</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> press down-arrow ] run [ @@ -2110,14 +2110,14 @@ d] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor starts with a long line wrapping twice</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abcdefghij</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcdefghij</span> <span class="Constant">k</span> <span class="Constant">l</span> <span class="Constant">m]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># position cursor at last line, then try to move further down</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> press down-arrow ] run [ @@ -2151,19 +2151,19 @@ d] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor contains a long line in the third line</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">cdef]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># position cursor at end, type a character</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">4</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 4</span> type <span class="Constant">[g]</span> ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># screen scrolls</span> screen-should-contain [ @@ -2173,8 +2173,8 @@ d] <span class="Constant"> .g .</span> ] memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 1</span> ] ] @@ -2182,19 +2182,19 @@ d] <span class="Constant">local-scope</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span> <span class="Comment"># position cursor after last line and type newline</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">4</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 4</span> type [ ] ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># screen scrolls</span> screen-should-contain [ @@ -2204,8 +2204,8 @@ d] <span class="Constant"> . .</span> ] memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] @@ -2214,19 +2214,19 @@ d] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor contains a wrapped line</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">cdefgh]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># position cursor at end of screen and try to move right</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 3</span> press right-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># screen scrolls</span> screen-should-contain [ @@ -2236,8 +2236,8 @@ d] <span class="Constant"> .gh .</span> ] memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] @@ -2246,20 +2246,20 @@ d] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor contains more lines than can fit on screen</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># position cursor at end of screen and try to move right</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 3</span> press right-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># screen scrolls</span> screen-should-contain [ @@ -2269,33 +2269,33 @@ d] <span class="Constant"> .d .</span> ] memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> editor-scrolls-at-end-on-down-arrow [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">de]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Constant"> $clear-trace</span> <span class="Comment"># try to move down past end of text</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 0</span> press down-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># screen should scroll, moving cursor to end of text</span> memory-should-contain [ - <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="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> ] assume-console [ type <span class="Constant">[0]</span> @@ -2312,20 +2312,20 @@ d] <span class="Comment"># try to move down again</span> <span class="Constant"> $clear-trace</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 0</span> press down-arrow ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># screen stops scrolling because cursor is already at top</span> memory-should-contain [ - <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="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> ] - check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span> + check-trace-count-for-label<span class="Constant"> 0</span>, <span class="Constant">[print-character]</span> assume-console [ type <span class="Constant">[1]</span> ] @@ -2345,18 +2345,18 @@ d] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with a few pages of lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d</span> <span class="Constant">e</span> <span class="Constant">f</span> <span class="Constant">g]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># scroll down one page and one line</span> assume-console [ press page-down - left-click <span class="Constant">3</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 0</span> press down-arrow ] run [ @@ -2378,11 +2378,11 @@ d] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with >3 lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .a .</span> @@ -2407,13 +2407,13 @@ d] ] <span class="muRecipe">after</span> <span class="Constant"><scroll-up></span> [ - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[scroll up]</span> - top-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - old-top:&:duplex-list:char<span class="Special"> <- </span>copy top-of-screen - top-of-screen<span class="Special"> <- </span>before-previous-line top-of-screen, editor - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top-of-screen - no-movement?:bool<span class="Special"> <- </span>equal old-top, top-of-screen - go-render?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[scroll up]</span> + top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + old-top:&:duplex-list:char <span class="Special"><-</span> copy top-of-screen + top-of-screen <span class="Special"><-</span> before-previous-line top-of-screen, editor + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top-of-screen + no-movement?:bool <span class="Special"><-</span> equal old-top, top-of-screen + go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-if</span> no-movement? ] @@ -2423,39 +2423,39 @@ d] <span class="muRecipe">def</span> before-previous-line in:&:duplex-list:char, editor:&:editor<span class="muRecipe"> -> </span>out:&:duplex-list:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - curr:&:duplex-list:char<span class="Special"> <- </span>copy in - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> + curr:&:duplex-list:char <span class="Special"><-</span> copy in + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> <span class="Comment"># compute max, number of characters to skip</span> <span class="Comment"># 1 + len%(width-1)</span> <span class="Comment"># except rotate second term to vary from 1 to width-1 rather than 0 to width-2</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - max-line-length:num<span class="Special"> <- </span>subtract right, left, <span class="Constant">-1/exclusive-right</span>, <span class="Constant">1/wrap-icon</span> - sentinel:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> - len:num<span class="Special"> <- </span>previous-line-length curr, sentinel + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + max-line-length:num <span class="Special"><-</span> subtract right, left, <span class="Constant">-1/exclusive-right</span>, <span class="Constant">1/wrap-icon</span> + sentinel:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> + len:num <span class="Special"><-</span> previous-line-length curr, sentinel <span class="Delimiter">{</span> <span class="muControl">break-if</span> len <span class="Comment"># empty line; just skip this newline</span> - prev:&:duplex-list:char<span class="Special"> <- </span>prev curr + prev:&:duplex-list:char <span class="Special"><-</span> prev curr <span class="muControl">return-unless</span> prev, curr <span class="muControl">return</span> prev <span class="Delimiter">}</span> - _, max:num<span class="Special"> <- </span>divide-with-remainder len, max-line-length + _, max:num <span class="Special"><-</span> divide-with-remainder len, max-line-length <span class="Comment"># remainder 0 => scan one width-worth</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> max - max<span class="Special"> <- </span>copy max-line-length + max <span class="Special"><-</span> copy max-line-length <span class="Delimiter">}</span> - max<span class="Special"> <- </span>add max, <span class="Constant">1</span> - count:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + max <span class="Special"><-</span> add max,<span class="Constant"> 1</span> + count:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Comment"># skip 'max' characters</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal count, max + done?:bool <span class="Special"><-</span> greater-or-equal count, max <span class="muControl">break-if</span> done? - prev:&:duplex-list:char<span class="Special"> <- </span>prev curr + prev:&:duplex-list:char <span class="Special"><-</span> prev curr <span class="muControl">break-unless</span> prev - curr<span class="Special"> <- </span>copy prev - count<span class="Special"> <- </span>add count, <span class="Constant">1</span> + curr <span class="Special"><-</span> copy prev + count <span class="Special"><-</span> add count,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">return</span> curr @@ -2467,11 +2467,11 @@ d] assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with a long, wrapped line and more than a screen of</span> <span class="Comment"># other lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abcdef</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcdef</span> <span class="Constant">g</span> <span class="Constant">h</span> <span class="Constant">i]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcd↩ .</span> @@ -2512,11 +2512,11 @@ d] <span class="Comment"># screen has 1 line for menu + 4 lines</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> <span class="Comment"># editor starts with a long line wrapping twice, occupying 3 of the 4 lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abcdefghij</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcdefghij</span> <span class="Constant">k</span> <span class="Constant">l</span> <span class="Constant">m]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># position cursor at top of second page</span> assume-console [ press page-down @@ -2586,11 +2586,11 @@ d] assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with a long, wrapped line and more than a screen of</span> <span class="Comment"># other lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abcdef</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abcdef</span> <span class="Constant">g</span> <span class="Constant">h</span> <span class="Constant">i]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">6/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">6/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .abcde↩ .</span> @@ -2631,13 +2631,13 @@ d] <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with some lines around an empty line</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> c d e] - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">6/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">6/right</span> assume-console [ press page-down ] @@ -2681,12 +2681,12 @@ e] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor contains >3 lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d</span> <span class="Constant">e]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># position cursor at top of second page</span> assume-console [ press page-down @@ -2706,8 +2706,8 @@ e] ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># screen scrolls</span> screen-should-contain [ @@ -2717,8 +2717,8 @@ e] <span class="Constant"> .d .</span> ] memory-should-contain [ - <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="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> ] ] @@ -2727,11 +2727,11 @@ e] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with >3 lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .a .</span> @@ -2776,11 +2776,11 @@ e] <span class="muScenario">scenario</span> editor-can-scroll [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .a .</span> @@ -2805,32 +2805,32 @@ e] <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - page-down?:bool<span class="Special"> <- </span>equal c, <span class="Constant">6/ctrl-f</span> + page-down?:bool <span class="Special"><-</span> equal c, <span class="Constant">6/ctrl-f</span> <span class="muControl">break-unless</span> page-down? - old-top:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + old-top:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> <span class="Constant"> <move-cursor-begin></span> page-down editor - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - top-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - no-movement?:bool<span class="Special"> <- </span>equal top-of-screen, old-top - go-render?<span class="Special"> <- </span>not no-movement? + top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + no-movement?:bool <span class="Special"><-</span> equal top-of-screen, old-top + go-render? <span class="Special"><-</span> not no-movement? <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - page-down?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65518/page-down</span> + page-down?:bool <span class="Special"><-</span> equal k, <span class="Constant">65518/page-down</span> <span class="muControl">break-unless</span> page-down? - old-top:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + old-top:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> <span class="Constant"> <move-cursor-begin></span> page-down editor - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - top-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - no-movement?:bool<span class="Special"> <- </span>equal top-of-screen, old-top - go-render?<span class="Special"> <- </span>not no-movement? + top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + no-movement?:bool <span class="Special"><-</span> equal top-of-screen, old-top + go-render? <span class="Special"><-</span> not no-movement? <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -2841,32 +2841,32 @@ e] <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if editor contents don't overflow screen, do nothing</span> - bottom-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">bottom-of-screen:offset</span> + bottom-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">bottom-of-screen:offset</span> <span class="muControl">return-unless</span> bottom-of-screen <span class="Comment"># if not, position cursor at final character</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>prev bottom-of-screen - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> prev bottom-of-screen + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor <span class="Comment"># keep one line in common with previous page</span> <span class="Delimiter">{</span> - last:char<span class="Special"> <- </span>get *before-cursor, <span class="Constant">value:offset</span> - newline?:bool<span class="Special"> <- </span>equal last, <span class="Constant">10/newline</span> + last:char <span class="Special"><-</span> get *before-cursor, <span class="Constant">value:offset</span> + newline?:bool <span class="Special"><-</span> equal last, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> newline?:bool - before-cursor<span class="Special"> <- </span>prev before-cursor - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + before-cursor <span class="Special"><-</span> prev before-cursor + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor <span class="Delimiter">}</span> <span class="Comment"># move cursor and top-of-screen to start of that line</span> move-to-start-of-line editor - before-cursor<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, before-cursor + before-cursor <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, before-cursor ] <span class="muScenario">scenario</span> editor-does-not-scroll-past-end [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e screen-should-contain [ <span class="Constant"> . .</span> @@ -2895,11 +2895,11 @@ e] <span class="Comment"># screen has 1 line for menu + 3 lines for text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor contains a long last line</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">cdefgh]</span> <span class="Comment"># editor screen triggers wrap of last line</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> <span class="Comment"># some part of last line is not displayed</span> screen-should-contain [ <span class="Constant"> . .</span> @@ -2929,9 +2929,9 @@ e] assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor contains a very long line that occupies last two lines of screen</span> <span class="Comment"># and still has something left over</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">bcdefgh]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> <span class="Comment"># some part of last line is not displayed</span> screen-should-contain [ <span class="Constant"> . .</span> @@ -2960,11 +2960,11 @@ e] <span class="muScenario">scenario</span> editor-can-scroll-up [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .a .</span> @@ -3003,33 +3003,33 @@ e] <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - page-up?:bool<span class="Special"> <- </span>equal c, <span class="Constant">2/ctrl-b</span> + page-up?:bool <span class="Special"><-</span> equal c, <span class="Constant">2/ctrl-b</span> <span class="muControl">break-unless</span> page-up? - old-top:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + old-top:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> <span class="Constant"> <move-cursor-begin></span> - editor<span class="Special"> <- </span>page-up editor, screen-height - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + editor <span class="Special"><-</span> page-up editor, screen-height + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - top-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - no-movement?:bool<span class="Special"> <- </span>equal top-of-screen, old-top - go-render?<span class="Special"> <- </span>not no-movement? + top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + no-movement?:bool <span class="Special"><-</span> equal top-of-screen, old-top + go-render? <span class="Special"><-</span> not no-movement? <span class="muControl">return</span> <span class="Delimiter">}</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [ <span class="Delimiter">{</span> - page-up?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65519/page-up</span> + page-up?:bool <span class="Special"><-</span> equal k, <span class="Constant">65519/page-up</span> <span class="muControl">break-unless</span> page-up? - old-top:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + old-top:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> <span class="Constant"> <move-cursor-begin></span> - editor<span class="Special"> <- </span>page-up editor, screen-height - undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span> + editor <span class="Special"><-</span> page-up editor, screen-height + undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - top-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - no-movement?:bool<span class="Special"> <- </span>equal top-of-screen, old-top + top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + no-movement?:bool <span class="Special"><-</span> equal top-of-screen, old-top <span class="Comment"># don't bother re-rendering if nothing changed. todo: test this</span> - go-render?<span class="Special"> <- </span>not no-movement? + go-render? <span class="Special"><-</span> not no-movement? <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -3037,17 +3037,17 @@ e] <span class="muRecipe">def</span> page-up editor:&:editor, screen-height:num<span class="muRecipe"> -> </span>editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - max:num<span class="Special"> <- </span>subtract screen-height, <span class="Constant">1/menu-bar</span>, <span class="Constant">1/overlapping-line</span> - count:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - top-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + max:num <span class="Special"><-</span> subtract screen-height, <span class="Constant">1/menu-bar</span>, <span class="Constant">1/overlapping-line</span> + count:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal count, max + done?:bool <span class="Special"><-</span> greater-or-equal count, max <span class="muControl">break-if</span> done? - prev:&:duplex-list:char<span class="Special"> <- </span>before-previous-line top-of-screen, editor + prev:&:duplex-list:char <span class="Special"><-</span> before-previous-line top-of-screen, editor <span class="muControl">break-unless</span> prev - top-of-screen<span class="Special"> <- </span>copy prev - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top-of-screen - count<span class="Special"> <- </span>add count, <span class="Constant">1</span> + top-of-screen <span class="Special"><-</span> copy prev + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top-of-screen + count <span class="Special"><-</span> add count,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -3057,7 +3057,7 @@ e] <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># initialize editor with 8 lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d</span> @@ -3065,7 +3065,7 @@ e] <span class="Constant">f</span> <span class="Constant">g</span> <span class="Constant">h]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .a .</span> @@ -3122,7 +3122,7 @@ e] <span class="Comment"># screen has 1 line for menu + 5 lines for text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">6/height</span> <span class="Comment"># editor contains a long line in the first page</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">cdefgh</span> <span class="Constant">i</span> @@ -3133,7 +3133,7 @@ e] <span class="Constant">n</span> <span class="Constant">o]</span> <span class="Comment"># editor screen triggers wrap of last line</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> <span class="Comment"># some part of last line is not displayed</span> screen-should-contain [ <span class="Constant"> . .</span> @@ -3146,7 +3146,7 @@ e] <span class="Comment"># scroll down a page and a line</span> assume-console [ press page-down - left-click <span class="Constant">5</span>, <span class="Constant">0</span> + left-click<span class="Constant"> 5</span>,<span class="Constant"> 0</span> press down-arrow ] run [ @@ -3185,9 +3185,9 @@ e] assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor contains a very long line that occupies last two lines of screen</span> <span class="Comment"># and still has something left over</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + s:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">bcdefgh]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> <span class="Comment"># some part of last line is not displayed</span> screen-should-contain [ <span class="Constant"> . .</span> @@ -3229,7 +3229,7 @@ e] <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># text with empty line in second screen</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[axx</span> + s:text <span class="Special"><-</span> new <span class="Constant">[axx</span> <span class="Constant">bxx</span> <span class="Constant">cxx</span> <span class="Constant">dxx</span> @@ -3238,7 +3238,7 @@ e] <span class="Constant">gxx</span> <span class="Constant">hxx</span> <span class="Constant">]</span> - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .axx .</span> @@ -3288,7 +3288,7 @@ e] <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span> <span class="Comment"># text with empty line in second screen</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[axy</span> + s:text <span class="Special"><-</span> new <span class="Constant">[axy</span> <span class="Constant">bxy</span> <span class="Constant">cxy</span> @@ -3297,7 +3297,7 @@ exy fxy gxy ] - e:&:editor<span class="Special"> <- </span>new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> + e:&:editor <span class="Special"><-</span> new-editor s, screen, <span class="Constant">0/left</span>, <span class="Constant">4/right</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .axy .</span> diff --git a/html/edit/004-programming-environment.mu.html b/html/edit/004-programming-environment.mu.html index 14ff221b..9019e0d1 100644 --- a/html/edit/004-programming-environment.mu.html +++ b/html/edit/004-programming-environment.mu.html @@ -41,10 +41,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def!</span> main [ <span class="Constant">local-scope</span> open-console - initial-recipe:text<span class="Special"> <- </span>restore <span class="Constant">[recipes.mu]</span> - initial-sandbox:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + initial-recipe:text <span class="Special"><-</span> restore <span class="Constant">[recipes.mu]</span> + initial-sandbox:text <span class="Special"><-</span> new <span class="Constant">[]</span> hide-screen <span class="Constant">0/screen</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment <span class="Constant">0/screen</span>, initial-recipe, initial-sandbox + env:&:environment <span class="Special"><-</span> new-programming-environment <span class="Constant">0/screen</span>, initial-recipe, initial-sandbox render-all <span class="Constant">0/screen</span>, env, render event-loop <span class="Constant">0/screen</span>, <span class="Constant">0/console</span>, env <span class="Comment"># never gets here</span> @@ -59,111 +59,111 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-programming-environment screen:&:screen, initial-recipe-contents:text, initial-sandbox-contents:text<span class="muRecipe"> -> </span>result:&:environment, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - width:num<span class="Special"> <- </span>screen-width screen - height:num<span class="Special"> <- </span>screen-height screen + width:num <span class="Special"><-</span> screen-width screen + height:num <span class="Special"><-</span> screen-height screen <span class="Comment"># top menu</span> - result<span class="Special"> <- </span>new <span class="Constant">environment:type</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:num<span class="Special"> <- </span>subtract width, <span class="Constant">20</span> - button-on-screen?:bool<span class="Special"> <- </span>greater-or-equal button-start, <span class="Constant">0</span> + result <span class="Special"><-</span> new <span class="Constant">environment:type</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:num <span class="Special"><-</span> subtract width,<span class="Constant"> 20</span> + button-on-screen?:bool <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> - screen<span class="Special"> <- </span>move-cursor screen, <span class="Constant">0/row</span>, button-start + screen <span class="Special"><-</span> move-cursor screen, <span class="Constant">0/row</span>, button-start print screen, <span class="Constant">[ run (F4) ]</span>, <span class="Constant">255/white</span>, <span class="Constant">161/reddish</span> <span class="Comment"># dotted line down the middle</span> - divider:num, _<span class="Special"> <- </span>divide-with-remainder width, <span class="Constant">2</span> + divider:num, _ <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:&:editor<span class="Special"> <- </span>new-editor initial-recipe-contents, screen, <span class="Constant">0/left</span>, divider/right + recipes:&:editor <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> - sandbox-left:num<span class="Special"> <- </span>add divider, <span class="Constant">1</span> - current-sandbox:&:editor<span class="Special"> <- </span>new-editor initial-sandbox-contents, screen, sandbox-left, width/right - *result<span class="Special"> <- </span>put *result, <span class="Constant">recipes:offset</span>, recipes - *result<span class="Special"> <- </span>put *result, <span class="Constant">current-sandbox:offset</span>, current-sandbox - *result<span class="Special"> <- </span>put *result, <span class="Constant">sandbox-in-focus?:offset</span>, <span class="Constant">0/false</span> + sandbox-left:num <span class="Special"><-</span> add divider,<span class="Constant"> 1</span> + current-sandbox:&:editor <span class="Special"><-</span> new-editor initial-sandbox-contents, screen, sandbox-left, width/right + *result <span class="Special"><-</span> put *result, <span class="Constant">recipes:offset</span>, recipes + *result <span class="Special"><-</span> put *result, <span class="Constant">current-sandbox:offset</span>, current-sandbox + *result <span class="Special"><-</span> put *result, <span class="Constant">sandbox-in-focus?:offset</span>, <span class="Constant">0/false</span> <span class="Constant"> <programming-environment-initialization></span> ] <span class="muRecipe">def</span> event-loop screen:&:screen, console:&:console, env:&:environment<span class="muRecipe"> -> </span>screen:&:screen, console:&:console, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - recipes:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - sandbox-in-focus?:bool<span class="Special"> <- </span>get *env, <span class="Constant">sandbox-in-focus?:offset</span> + recipes:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + sandbox-in-focus?:bool <span class="Special"><-</span> get *env, <span class="Constant">sandbox-in-focus?:offset</span> <span class="Comment"># if we fall behind we'll stop updating the screen, but then we have to</span> <span class="Comment"># render the entire screen when we catch up.</span> <span class="Comment"># todo: test this</span> - render-all-on-no-more-events?:bool<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + render-all-on-no-more-events?:bool <span class="Special"><-</span> copy <span class="Constant">0/false</span> <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, found?:bool, quit?:bool, console<span class="Special"> <- </span>read-event console + e:event, found?:bool, quit?:bool, console <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">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span> <span class="Constant"> <handle-event></span> <span class="Comment"># check for global events that will trigger regardless of which editor has focus</span> <span class="Delimiter">{</span> - k:num, is-keycode?:bool<span class="Special"> <- </span>maybe-convert e:event, <span class="Constant">keycode:variant</span> + k:num, is-keycode?:bool <span class="Special"><-</span> maybe-convert e:event, <span class="Constant">keycode:variant</span> <span class="muControl">break-unless</span> is-keycode? <span class="Constant"> <global-keypress></span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> - c:char, is-unicode?:bool<span class="Special"> <- </span>maybe-convert e:event, <span class="Constant">text:variant</span> + c:char, is-unicode?:bool <span class="Special"><-</span> maybe-convert e:event, <span class="Constant">text:variant</span> <span class="muControl">break-unless</span> is-unicode? <span class="Constant"> <global-type></span> <span class="Delimiter">}</span> <span class="Comment"># 'touch' event - send to both sides, see what picks it up</span> <span class="Delimiter">{</span> - t:touch-event, is-touch?:bool<span class="Special"> <- </span>maybe-convert e:event, <span class="Constant">touch:variant</span> + t:touch-event, is-touch?:bool <span class="Special"><-</span> maybe-convert e:event, <span class="Constant">touch:variant</span> <span class="muControl">break-unless</span> is-touch? <span class="Comment"># ignore all but 'left-click' events for now</span> <span class="Comment"># todo: test this</span> - touch-type:num<span class="Special"> <- </span>get t, <span class="Constant">type:offset</span> - is-left-click?:bool<span class="Special"> <- </span>equal touch-type, <span class="Constant">65513/mouse-left</span> + touch-type:num <span class="Special"><-</span> get t, <span class="Constant">type:offset</span> + is-left-click?:bool <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</span> - click-row:num<span class="Special"> <- </span>get t, <span class="Constant">row:offset</span> - click-column:num<span class="Special"> <- </span>get t, <span class="Constant">column:offset</span> + click-row:num <span class="Special"><-</span> get t, <span class="Constant">row:offset</span> + click-column:num <span class="Special"><-</span> get t, <span class="Constant">column:offset</span> <span class="Comment"># later exceptions for non-editor touches will go here</span> <span class="Constant"> <global-touch></span> <span class="Comment"># send to both editors</span> - _<span class="Special"> <- </span>move-cursor-in-editor screen, recipes, t - sandbox-in-focus?:bool<span class="Special"> <- </span>move-cursor-in-editor screen, current-sandbox, t - *env<span class="Special"> <- </span>put *env, <span class="Constant">sandbox-in-focus?:offset</span>, sandbox-in-focus? - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + _ <span class="Special"><-</span> move-cursor-in-editor screen, recipes, t + sandbox-in-focus?:bool <span class="Special"><-</span> move-cursor-in-editor screen, current-sandbox, t + *env <span class="Special"><-</span> put *env, <span class="Constant">sandbox-in-focus?:offset</span>, sandbox-in-focus? + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> <span class="Comment"># 'resize' event - redraw editor</span> <span class="Comment"># todo: test this after supporting resize in assume-console</span> <span class="Delimiter">{</span> - r:resize-event, is-resize?:bool<span class="Special"> <- </span>maybe-convert e:event, <span class="Constant">resize:variant</span> + r:resize-event, is-resize?:bool <span class="Special"><-</span> maybe-convert e:event, <span class="Constant">resize:variant</span> <span class="muControl">break-unless</span> is-resize? <span class="Comment"># if more events, we're still resizing; wait until we stop</span> - more-events?:bool<span class="Special"> <- </span>has-more-events? console + more-events?:bool <span class="Special"><-</span> has-more-events? console <span class="Delimiter">{</span> <span class="muControl">break-unless</span> more-events? - render-all-on-no-more-events?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> <span class="Comment"># no rendering now, full rendering on some future event</span> + render-all-on-no-more-events? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="Comment"># no rendering now, full rendering on some future event</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> more-events? - env, screen<span class="Special"> <- </span>resize screen, env - screen<span class="Special"> <- </span>render-all screen, env, render-without-moving-cursor - render-all-on-no-more-events?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> <span class="Comment"># full render done</span> + env, screen <span class="Special"><-</span> resize screen, env + screen <span class="Special"><-</span> render-all screen, env, render-without-moving-cursor + render-all-on-no-more-events? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="Comment"># full render done</span> <span class="Delimiter">}</span> <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> <span class="Comment"># if it's not global and not a touch event, send to appropriate editor</span> <span class="Delimiter">{</span> hide-screen screen - sandbox-in-focus?:bool<span class="Special"> <- </span>get *env, <span class="Constant">sandbox-in-focus?:offset</span> + sandbox-in-focus?:bool <span class="Special"><-</span> get *env, <span class="Constant">sandbox-in-focus?:offset</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> sandbox-in-focus? - screen, recipes, render?:bool<span class="Special"> <- </span>handle-keyboard-event screen, recipes, e:event + screen, recipes, render?:bool <span class="Special"><-</span> handle-keyboard-event screen, recipes, e:event <span class="Comment"># refresh screen only if no more events</span> <span class="Comment"># if there are more events to process, wait for them to clear up, then make sure you render-all afterward.</span> - more-events?:bool<span class="Special"> <- </span>has-more-events? console + more-events?:bool <span class="Special"><-</span> has-more-events? console <span class="Delimiter">{</span> <span class="muControl">break-unless</span> more-events? - render-all-on-no-more-events?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> <span class="Comment"># no rendering now, full rendering on some future event</span> + render-all-on-no-more-events? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="Comment"># no rendering now, full rendering on some future event</span> <span class="muControl">jump</span> <span class="Constant">+finish-event</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> @@ -171,27 +171,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="muControl">break-unless</span> render-all-on-no-more-events? <span class="Comment"># no more events, and we have to force render</span> - screen<span class="Special"> <- </span>render-all screen, env, render - render-all-on-no-more-events?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + screen <span class="Special"><-</span> render-all screen, env, render + render-all-on-no-more-events? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">jump</span> <span class="Constant">+finish-event</span> <span class="Delimiter">}</span> <span class="Comment"># no more events, no force render</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> render? - screen<span class="Special"> <- </span>render-recipes screen, env, render + screen <span class="Special"><-</span> render-recipes screen, env, render <span class="muControl">jump</span> <span class="Constant">+finish-event</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> sandbox-in-focus? - screen, current-sandbox, render?:bool<span class="Special"> <- </span>handle-keyboard-event screen, current-sandbox, e:event + screen, current-sandbox, render?:bool <span class="Special"><-</span> handle-keyboard-event screen, current-sandbox, e:event <span class="Comment"># refresh screen only if no more events</span> <span class="Comment"># if there are more events to process, wait for them to clear up, then make sure you render-all afterward.</span> - more-events?:bool<span class="Special"> <- </span>has-more-events? console + more-events?:bool <span class="Special"><-</span> has-more-events? console <span class="Delimiter">{</span> <span class="muControl">break-unless</span> more-events? - render-all-on-no-more-events?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> <span class="Comment"># no rendering now, full rendering on some future event</span> + render-all-on-no-more-events? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="Comment"># no rendering now, full rendering on some future event</span> <span class="muControl">jump</span> <span class="Constant">+finish-event</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> @@ -199,20 +199,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="muControl">break-unless</span> render-all-on-no-more-events? <span class="Comment"># no more events, and we have to force render</span> - screen<span class="Special"> <- </span>render-all screen, env, render - render-all-on-no-more-events?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + screen <span class="Special"><-</span> render-all screen, env, render + render-all-on-no-more-events? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">jump</span> <span class="Constant">+finish-event</span> <span class="Delimiter">}</span> <span class="Comment"># no more events, no force render</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> render? - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render + screen <span class="Special"><-</span> render-sandbox-side screen, env, render <span class="muControl">jump</span> <span class="Constant">+finish-event</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Constant"> +finish-event</span> - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env show-screen screen <span class="Delimiter">}</span> <span class="muControl">loop</span> @@ -223,24 +223,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> clear-screen screen <span class="Comment"># update screen dimensions</span> - width:num<span class="Special"> <- </span>screen-width screen - divider:num, _<span class="Special"> <- </span>divide-with-remainder width, <span class="Constant">2</span> + width:num <span class="Special"><-</span> screen-width screen + divider:num, _ <span class="Special"><-</span> divide-with-remainder width,<span class="Constant"> 2</span> <span class="Comment"># update recipe editor</span> - recipes:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> - right:num<span class="Special"> <- </span>subtract divider, <span class="Constant">1</span> - *recipes<span class="Special"> <- </span>put *recipes, <span class="Constant">right:offset</span>, right + recipes:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> + right:num <span class="Special"><-</span> subtract divider,<span class="Constant"> 1</span> + *recipes <span class="Special"><-</span> put *recipes, <span class="Constant">right:offset</span>, right <span class="Comment"># reset cursor (later we'll try to preserve its position)</span> - *recipes<span class="Special"> <- </span>put *recipes, <span class="Constant">cursor-row:offset</span>, <span class="Constant">1</span> - *recipes<span class="Special"> <- </span>put *recipes, <span class="Constant">cursor-column:offset</span>, <span class="Constant">0</span> + *recipes <span class="Special"><-</span> put *recipes, <span class="Constant">cursor-row:offset</span>,<span class="Constant"> 1</span> + *recipes <span class="Special"><-</span> put *recipes, <span class="Constant">cursor-column:offset</span>,<span class="Constant"> 0</span> <span class="Comment"># update sandbox editor</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - left:num<span class="Special"> <- </span>add divider, <span class="Constant">1</span> - *current-sandbox<span class="Special"> <- </span>put *current-sandbox, <span class="Constant">left:offset</span>, left - right:num<span class="Special"> <- </span>subtract width, <span class="Constant">1</span> - *current-sandbox<span class="Special"> <- </span>put *current-sandbox, <span class="Constant">right:offset</span>, right + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + left:num <span class="Special"><-</span> add divider,<span class="Constant"> 1</span> + *current-sandbox <span class="Special"><-</span> put *current-sandbox, <span class="Constant">left:offset</span>, left + right:num <span class="Special"><-</span> subtract width,<span class="Constant"> 1</span> + *current-sandbox <span class="Special"><-</span> put *current-sandbox, <span class="Constant">right:offset</span>, right <span class="Comment"># reset cursor (later we'll try to preserve its position)</span> - *current-sandbox<span class="Special"> <- </span>put *current-sandbox, <span class="Constant">cursor-row:offset</span>, <span class="Constant">1</span> - *current-sandbox<span class="Special"> <- </span>put *current-sandbox, <span class="Constant">cursor-column:offset</span>, left + *current-sandbox <span class="Special"><-</span> put *current-sandbox, <span class="Constant">cursor-row:offset</span>,<span class="Constant"> 1</span> + *current-sandbox <span class="Special"><-</span> put *current-sandbox, <span class="Constant">cursor-column:offset</span>, left ] <span class="Comment"># Variant of 'render' that updates cursor-row and cursor-column based on</span> @@ -249,81 +249,81 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> render-without-moving-cursor screen:&:screen, editor:&:editor<span class="muRecipe"> -> </span>last-row:num, last-column:num, screen:&:screen, editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - <span class="muControl">return-unless</span> editor, <span class="Constant">1/top</span>, <span class="Constant">0/left</span>, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span> - left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span> - screen-height:num<span class="Special"> <- </span>screen-height screen - right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span> - curr:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - prev:&:duplex-list:char<span class="Special"> <- </span>copy curr <span class="Comment"># just in case curr becomes null and we can't compute prev</span> - curr<span class="Special"> <- </span>next curr + <span class="muControl">return-unless</span> editor, <span class="Constant">1/top</span>, <span class="Constant">0/left</span>, screen/same-as-ingredient:0, editor/same-as-ingredient:1 + left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> + screen-height:num <span class="Special"><-</span> screen-height screen + right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> + curr:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + prev:&:duplex-list:char <span class="Special"><-</span> copy curr <span class="Comment"># just in case curr becomes null and we can't compute prev</span> + curr <span class="Special"><-</span> next curr <span class="Constant"> +render-loop-initialization</span> - color:num<span class="Special"> <- </span>copy <span class="Constant">7/white</span> - row:num<span class="Special"> <- </span>copy <span class="Constant">1/top</span> - column:num<span class="Special"> <- </span>copy left + color:num <span class="Special"><-</span> copy <span class="Constant">7/white</span> + row:num <span class="Special"><-</span> copy <span class="Constant">1/top</span> + column:num <span class="Special"><-</span> copy left <span class="Comment"># save before-cursor</span> - old-before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> + old-before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> <span class="Comment"># initialze cursor-row/cursor-column/before-cursor to the top of the screen</span> <span class="Comment"># by default</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, row - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, column - top-of-screen:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, top-of-screen - screen<span class="Special"> <- </span>move-cursor screen, row, column + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, row + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, column + top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, top-of-screen + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="Delimiter">{</span> <span class="Constant"> +next-character</span> <span class="muControl">break-unless</span> curr - off-screen?:bool<span class="Special"> <- </span>greater-or-equal row, screen-height + off-screen?:bool <span class="Special"><-</span> greater-or-equal row, screen-height <span class="muControl">break-if</span> off-screen? <span class="Comment"># if we find old-before-cursor still on the new resized screen, update</span> <span class="Comment"># editor.cursor-row and editor.cursor-column based on</span> <span class="Comment"># old-before-cursor</span> <span class="Delimiter">{</span> - at-cursor?:bool<span class="Special"> <- </span>equal old-before-cursor, prev + at-cursor?:bool <span class="Special"><-</span> equal old-before-cursor, prev <span class="muControl">break-unless</span> at-cursor? - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, row - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, column - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, old-before-cursor + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, row + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, column + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, old-before-cursor <span class="Delimiter">}</span> - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> <span class="Constant"> <character-c-received></span> <span class="Delimiter">{</span> <span class="Comment"># newline? move to left rather than 0</span> - newline?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + newline?:bool <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> clear-line-until screen, right <span class="Comment"># skip to next line</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - column<span class="Special"> <- </span>copy left - screen<span class="Special"> <- </span>move-cursor screen, row, column - curr<span class="Special"> <- </span>next curr - prev<span class="Special"> <- </span>next prev + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + column <span class="Special"><-</span> copy left + screen <span class="Special"><-</span> move-cursor screen, row, column + curr <span class="Special"><-</span> next curr + prev <span class="Special"><-</span> next prev <span class="muControl">loop</span> <span class="Constant">+next-character</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?:bool<span class="Special"> <- </span>equal column, right + at-right?:bool <span class="Special"><-</span> equal column, right <span class="muControl">break-unless</span> at-right? <span class="Comment"># print wrap icon</span> - wrap-icon:char<span class="Special"> <- </span>copy <span class="Constant">8617/loop-back-to-left</span> + wrap-icon:char <span class="Special"><-</span> copy <span class="Constant">8617/loop-back-to-left</span> print screen, wrap-icon, <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> - screen<span class="Special"> <- </span>move-cursor screen, row, column + column <span class="Special"><-</span> copy left + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="Comment"># don't increment curr</span> <span class="muControl">loop</span> <span class="Constant">+next-character</span> <span class="Delimiter">}</span> print screen, c, color - curr<span class="Special"> <- </span>next curr - prev<span class="Special"> <- </span>next prev - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + curr <span class="Special"><-</span> next curr + prev <span class="Special"><-</span> next 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"># save first character off-screen</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">bottom-of-screen:offset</span>, curr - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">bottom:offset</span>, row - <span class="muControl">return</span> row, column, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">bottom-of-screen:offset</span>, curr + *editor <span class="Special"><-</span> put *editor, <span class="Constant">bottom:offset</span>, row + <span class="muControl">return</span> row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 ] @@ -332,23 +332,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">30/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize both halves of screen</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[abc]</span>, <span class="Constant">[def]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[abc]</span>, <span class="Constant">[def]</span> <span class="Comment"># focus on both sides</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">1</span> - left-click <span class="Constant">1</span>, <span class="Constant">17</span> + 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, console, env - recipes:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *recipes, <span class="Constant">cursor-column:offset</span> - sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - <span class="Constant">7</span>:num/<span class="Special">raw <- </span>get *sandbox, <span class="Constant">cursor-column:offset</span> + recipes:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *recipes, <span class="Constant">cursor-column:offset</span> + sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + 7:num/<span class="Special">raw</span> <span class="Special"><-</span> get *sandbox, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ - <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="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> ] ] @@ -357,21 +357,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">30/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize both halves of screen</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[abc]</span>, <span class="Constant">[def]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[abc]</span>, <span class="Constant">[def]</span> render-all screen, env, render <span class="Comment"># type one letter in each of them</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 1</span> type <span class="Constant">[0]</span> - left-click <span class="Constant">1</span>, <span class="Constant">17</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 17</span> type <span class="Constant">[1]</span> ] run [ event-loop screen, console, env - recipes:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> - <span class="Constant">5</span>:num/<span class="Special">raw <- </span>get *recipes, <span class="Constant">cursor-column:offset</span> - sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - <span class="Constant">7</span>:num/<span class="Special">raw <- </span>get *sandbox, <span class="Constant">cursor-column:offset</span> + recipes:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> + 5:num/<span class="Special">raw</span> <span class="Special"><-</span> get *recipes, <span class="Constant">cursor-column:offset</span> + sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + 7:num/<span class="Special">raw</span> <span class="Special"><-</span> get *sandbox, <span class="Constant">cursor-column:offset</span> ] screen-should-contain [ <span class="Constant"> . run (F4) . # this line has a different background, but we don't test that yet</span> @@ -380,12 +380,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . ╎ .</span> ] memory-should-contain [ - <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="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 [ - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] screen-should-contain [ @@ -401,7 +401,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">60/width</span>, <span class="Constant">10/height</span> run [ - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[abc]</span>, <span class="Constant">[def]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[abc]</span>, <span class="Constant">[def]</span> render-all screen, env, render ] <span class="Comment"># divider isn't messed up</span> @@ -418,13 +418,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">30/width</span>, <span class="Constant">5/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[abc]</span>, <span class="Constant">[def]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[abc]</span>, <span class="Constant">[def]</span> render-all screen, env, render <span class="Comment"># initialize programming environment and highlight cursor</span> assume-console <span class="Constant">[]</span> run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># is cursor at the right place?</span> @@ -440,7 +440,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># cursor should still be right</span> @@ -457,9 +457,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">30/width</span>, <span class="Constant">5/height</span> <span class="Comment"># initialize sandbox side with two lines</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + s:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, s:text + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, s:text render-all screen, env, render screen-should-contain [ <span class="Constant"> . run (F4) .</span> @@ -470,12 +470,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># position cursor at start of second line and hit backspace</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">16</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 16</span> press backspace ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># cursor moves to end of old line</span> @@ -490,31 +490,31 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> render-all screen:&:screen, env:&:environment, <span class="Delimiter">{</span>render-editor: (recipe (address screen) (address editor)<span class="muRecipe"> -> </span>number number (address screen) (address editor))<span class="Delimiter">}</span><span class="muRecipe"> -> </span>screen:&:screen, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[render all]</span> + trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[render all]</span> hide-screen screen <span class="Comment"># top menu</span> - trace <span class="Constant">11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render top menu]</span> - width:num<span class="Special"> <- </span>screen-width screen - 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:num<span class="Special"> <- </span>subtract width, <span class="Constant">20</span> - button-on-screen?:bool<span class="Special"> <- </span>greater-or-equal button-start, <span class="Constant">0</span> + trace<span class="Constant"> 11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render top menu]</span> + width:num <span class="Special"><-</span> screen-width screen + 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:num <span class="Special"><-</span> subtract width,<span class="Constant"> 20</span> + button-on-screen?:bool <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> - screen<span class="Special"> <- </span>move-cursor screen, <span class="Constant">0/row</span>, button-start + screen <span class="Special"><-</span> move-cursor screen, <span class="Constant">0/row</span>, button-start print screen, <span class="Constant">[ run (F4) ]</span>, <span class="Constant">255/white</span>, <span class="Constant">161/reddish</span> <span class="Comment"># dotted line down the middle</span> - trace <span class="Constant">11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render divider]</span> - divider:num, _<span class="Special"> <- </span>divide-with-remainder width, <span class="Constant">2</span> - height:num<span class="Special"> <- </span>screen-height screen + trace<span class="Constant"> 11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render divider]</span> + divider:num, _ <span class="Special"><-</span> divide-with-remainder width,<span class="Constant"> 2</span> + height:num <span class="Special"><-</span> screen-height screen draw-vertical screen, divider, <span class="Constant">1/top</span>, height, <span class="Constant">9482/vertical-dotted</span> <span class="Comment">#</span> - screen<span class="Special"> <- </span>render-recipes screen, env, render-editor - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render-editor + screen <span class="Special"><-</span> render-recipes screen, env, render-editor + screen <span class="Special"><-</span> render-sandbox-side screen, env, render-editor <span class="Constant"> <render-components-end></span> <span class="Comment">#</span> - recipes:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - sandbox-in-focus?:bool<span class="Special"> <- </span>get *env, <span class="Constant">sandbox-in-focus?:offset</span> - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + recipes:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + sandbox-in-focus?:bool <span class="Special"><-</span> get *env, <span class="Constant">sandbox-in-focus?:offset</span> + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env <span class="Comment">#</span> show-screen screen ] @@ -522,18 +522,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> render-recipes screen:&:screen, env:&:environment, <span class="Delimiter">{</span>render-editor: (recipe (address screen) (address editor)<span class="muRecipe"> -> </span>number number (address screen) (address editor))<span class="Delimiter">}</span><span class="muRecipe"> -> </span>screen:&:screen, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - trace <span class="Constant">11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render recipes]</span> - recipes:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> + trace<span class="Constant"> 11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render recipes]</span> + recipes:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> <span class="Comment"># render recipes</span> - left:num<span class="Special"> <- </span>get *recipes, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *recipes, <span class="Constant">right:offset</span> - row:num, column:num, screen<span class="Special"> <- </span>call render-editor, screen, recipes + left:num <span class="Special"><-</span> get *recipes, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *recipes, <span class="Constant">right:offset</span> + row:num, column:num, screen <span class="Special"><-</span> call render-editor, screen, recipes clear-line-until screen, right - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> <span class="Constant"> <render-recipe-components-end></span> <span class="Comment"># draw dotted line after recipes</span> draw-horizontal screen, row, left, right, <span class="Constant">9480/horizontal-dotted</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> clear-screen-from screen, row, left, left, right ] @@ -541,15 +541,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> render-sandbox-side screen:&:screen, env:&:environment, <span class="Delimiter">{</span>render-editor: (recipe (address screen) (address editor)<span class="muRecipe"> -> </span>number number (address screen) (address editor))<span class="Delimiter">}</span><span class="muRecipe"> -> </span>screen:&:screen, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - left:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">right:offset</span> - row:num, column:num, screen, current-sandbox<span class="Special"> <- </span>call render-editor, screen, current-sandbox + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + left:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">right:offset</span> + row:num, column:num, screen, current-sandbox <span class="Special"><-</span> call render-editor, screen, current-sandbox clear-line-until screen, right - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> <span class="Comment"># draw solid line after code (you'll see why in later layers)</span> draw-horizontal screen, row, left, right - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> clear-screen-from screen, row, left, left, right ] @@ -559,15 +559,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> <update-cursor-special-cases></span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> sandbox-in-focus? - cursor-row:num<span class="Special"> <- </span>get *recipes, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *recipes, <span class="Constant">cursor-column:offset</span> + cursor-row:num <span class="Special"><-</span> get *recipes, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *recipes, <span class="Constant">cursor-column:offset</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> sandbox-in-focus? - cursor-row:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">cursor-column:offset</span> + cursor-row:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">cursor-column:offset</span> <span class="Delimiter">}</span> - screen<span class="Special"> <- </span>move-cursor screen, cursor-row, cursor-column + screen <span class="Special"><-</span> move-cursor screen, cursor-row, cursor-column ] <span class="Comment"># like 'render' for texts, but with colorization for comments like in the editor</span> @@ -575,60 +575,60 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">return-unless</span> s - color:num<span class="Special"> <- </span>copy <span class="Constant">7/white</span> - column:num<span class="Special"> <- </span>copy left - screen<span class="Special"> <- </span>move-cursor screen, row, column - screen-height:num<span class="Special"> <- </span>screen-height screen - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - len:num<span class="Special"> <- </span>length *s + color:num <span class="Special"><-</span> copy <span class="Constant">7/white</span> + column:num <span class="Special"><-</span> copy left + screen <span class="Special"><-</span> move-cursor screen, row, column + screen-height:num <span class="Special"><-</span> screen-height screen + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + len:num <span class="Special"><-</span> length *s <span class="Delimiter">{</span> <span class="Constant"> +next-character</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <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 + done? <span class="Special"><-</span> greater-or-equal row, screen-height <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *s, i + c:char <span class="Special"><-</span> index *s, i <span class="Constant"><character-c-received></span> <span class="Comment"># only line different from render</span> <span class="Delimiter">{</span> <span class="Comment"># at right? wrap.</span> - at-right?:bool<span class="Special"> <- </span>equal column, right + at-right?:bool <span class="Special"><-</span> equal column, right <span class="muControl">break-unless</span> at-right? <span class="Comment"># print wrap icon</span> - wrap-icon:char<span class="Special"> <- </span>copy <span class="Constant">8617/loop-back-to-left</span> + wrap-icon:char <span class="Special"><-</span> copy <span class="Constant">8617/loop-back-to-left</span> print screen, wrap-icon, <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> - screen<span class="Special"> <- </span>move-cursor screen, row, column + column <span class="Special"><-</span> copy left + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="muControl">loop</span> <span class="Constant">+next-character</span> <span class="Comment"># retry i</span> <span class="Delimiter">}</span> - i<span class="Special"> <- </span>add i, <span class="Constant">1</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?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + newline?:bool <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?:bool<span class="Special"> <- </span>greater-than column, right + done?:bool <span class="Special"><-</span> greater-than column, right <span class="muControl">break-if</span> done? - space:char<span class="Special"> <- </span>copy <span class="Constant">32/space</span> + space:char <span class="Special"><-</span> copy <span class="Constant">32/space</span> print screen, space - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - column<span class="Special"> <- </span>copy left - screen<span class="Special"> <- </span>move-cursor screen, row, column + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + column <span class="Special"><-</span> copy left + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="muControl">loop</span> <span class="Constant">+next-character</span> <span class="Delimiter">}</span> print screen, c, color - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - was-at-left?:bool<span class="Special"> <- </span>equal column, left + was-at-left?:bool <span class="Special"><-</span> equal column, left clear-line-until screen, right <span class="Delimiter">{</span> <span class="muControl">break-if</span> was-at-left? - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> <span class="Delimiter">}</span> move-cursor screen, row, left ] @@ -637,9 +637,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-type></span> [ <span class="Delimiter">{</span> - redraw-screen?:bool<span class="Special"> <- </span>equal c, <span class="Constant">12/ctrl-l</span> + redraw-screen?:bool <span class="Special"><-</span> equal c, <span class="Constant">12/ctrl-l</span> <span class="muControl">break-unless</span> redraw-screen? - screen<span class="Special"> <- </span>render-all screen, env:&:environment, render + screen <span class="Special"><-</span> render-all screen, env:&:environment, render sync-screen screen <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> @@ -650,12 +650,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-type></span> [ <span class="Delimiter">{</span> - switch-side?:bool<span class="Special"> <- </span>equal c, <span class="Constant">14/ctrl-n</span> + switch-side?:bool <span class="Special"><-</span> equal c, <span class="Constant">14/ctrl-n</span> <span class="muControl">break-unless</span> switch-side? - sandbox-in-focus?:bool<span class="Special"> <- </span>get *env, <span class="Constant">sandbox-in-focus?:offset</span> - sandbox-in-focus?<span class="Special"> <- </span>not sandbox-in-focus? - *env<span class="Special"> <- </span>put *env, <span class="Constant">sandbox-in-focus?:offset</span>, sandbox-in-focus? - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + sandbox-in-focus?:bool <span class="Special"><-</span> get *env, <span class="Constant">sandbox-in-focus?:offset</span> + sandbox-in-focus? <span class="Special"><-</span> not sandbox-in-focus? + *env <span class="Special"><-</span> put *env, <span class="Constant">sandbox-in-focus?:offset</span>, sandbox-in-focus? + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> ] @@ -665,23 +665,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> draw-vertical screen:&:screen, col:num, y:num, bottom:num<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - style:char, style-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + style:char, style-found?:bool <span class="Special"><-</span> <span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> style-found? - style<span class="Special"> <- </span>copy <span class="Constant">9474/vertical</span> + style <span class="Special"><-</span> copy <span class="Constant">9474/vertical</span> <span class="Delimiter">}</span> - color:num, color-found?:bool<span class="Special"> <- </span><span class="Constant">next-ingredient</span> + color:num, color-found?:bool <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? - color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> + color <span class="Special"><-</span> copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> - continue?:bool<span class="Special"> <- </span>lesser-than y, bottom + continue?:bool <span class="Special"><-</span> lesser-than y, bottom <span class="muControl">break-unless</span> continue? - screen<span class="Special"> <- </span>move-cursor screen, y, col + screen <span class="Special"><-</span> move-cursor screen, y, col print screen, style, color - y<span class="Special"> <- </span>add y, <span class="Constant">1</span> + y <span class="Special"><-</span> add y,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] diff --git a/html/edit/005-sandbox.mu.html b/html/edit/005-sandbox.mu.html index 735a45de..91e61166 100644 --- a/html/edit/005-sandbox.mu.html +++ b/html/edit/005-sandbox.mu.html @@ -45,11 +45,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def!</span> main [ <span class="Constant">local-scope</span> open-console - initial-recipe:text<span class="Special"> <- </span>restore <span class="Constant">[recipes.mu]</span> - initial-sandbox:text<span class="Special"> <- </span>new <span class="Constant">[]</span> + initial-recipe:text <span class="Special"><-</span> restore <span class="Constant">[recipes.mu]</span> + initial-sandbox:text <span class="Special"><-</span> new <span class="Constant">[]</span> hide-screen <span class="Constant">0/screen</span> - env:&:environment<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 + env:&:environment <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, render event-loop <span class="Constant">0/screen</span>, <span class="Constant">0/console</span>, env <span class="Comment"># never gets here</span> @@ -62,7 +62,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><programming-environment-initialization></span> [ - *result<span class="Special"> <- </span>put *result, <span class="Constant">render-from:offset</span>, <span class="Constant">-1</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">render-from:offset</span>,<span class="Constant"> -1</span> ] <span class="muData">container</span> sandbox [ @@ -82,7 +82,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Comment"># recipe editor is empty</span> <span class="Comment"># sandbox editor contains an instruction without storing outputs</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[divide-with-remainder 11, 3]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[divide-with-remainder 11, 3]</span> <span class="Comment"># run the code in the editors</span> assume-console [ press F4 @@ -133,7 +133,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># run another command</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">80</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 80</span> type <span class="Constant">[add 2, 2]</span> press F4 ] @@ -161,17 +161,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-keypress></span> [ <span class="Comment"># F4? load all code and run all sandboxes.</span> <span class="Delimiter">{</span> - do-run?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65532/F4</span> + do-run?:bool <span class="Special"><-</span> equal k, <span class="Constant">65532/F4</span> <span class="muControl">break-unless</span> do-run? - screen<span class="Special"> <- </span>update-status screen, <span class="Constant">[running... ]</span>, <span class="Constant">245/grey</span> - error?:bool, env, screen<span class="Special"> <- </span>run-sandboxes env, screen + screen <span class="Special"><-</span> update-status screen, <span class="Constant">[running... ]</span>, <span class="Constant">245/grey</span> + error?:bool, env, screen <span class="Special"><-</span> run-sandboxes env, screen <span class="Comment"># F4 might update warnings and results on both sides</span> - screen<span class="Special"> <- </span>render-all screen, env, render + screen <span class="Special"><-</span> render-all screen, env, render <span class="Delimiter">{</span> <span class="muControl">break-if</span> error? - screen<span class="Special"> <- </span>update-status screen, <span class="Constant">[ ]</span>, <span class="Constant">245/grey</span> + screen <span class="Special"><-</span> update-status screen, <span class="Constant">[ ]</span>, <span class="Constant">245/grey</span> <span class="Delimiter">}</span> - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> ] @@ -179,41 +179,41 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> run-sandboxes env:&:environment, screen:&:screen<span class="muRecipe"> -> </span>errors-found?:bool, env:&:environment, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - errors-found?:bool, env, screen<span class="Special"> <- </span>update-recipes env, screen + errors-found?:bool, env, screen <span class="Special"><-</span> update-recipes env, screen <span class="muControl">return-if</span> errors-found? <span class="Comment"># check contents of right editor (sandbox)</span> <span class="Constant"> <run-sandboxes-begin></span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> <span class="Delimiter">{</span> - sandbox-contents:text<span class="Special"> <- </span>editor-contents current-sandbox + sandbox-contents:text <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</span> - new-sandbox:&:sandbox<span class="Special"> <- </span>new <span class="Constant">sandbox:type</span> - *new-sandbox<span class="Special"> <- </span>put *new-sandbox, <span class="Constant">data:offset</span>, sandbox-contents + new-sandbox:&:sandbox <span class="Special"><-</span> new <span class="Constant">sandbox:type</span> + *new-sandbox <span class="Special"><-</span> put *new-sandbox, <span class="Constant">data:offset</span>, sandbox-contents <span class="Comment"># push to head of sandbox list</span> - dest:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> - *new-sandbox<span class="Special"> <- </span>put *new-sandbox, <span class="Constant">next-sandbox:offset</span>, dest - *env<span class="Special"> <- </span>put *env, <span class="Constant">sandbox:offset</span>, new-sandbox + dest:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> + *new-sandbox <span class="Special"><-</span> put *new-sandbox, <span class="Constant">next-sandbox:offset</span>, dest + *env <span class="Special"><-</span> put *env, <span class="Constant">sandbox:offset</span>, new-sandbox <span class="Comment"># update sandbox count</span> - sandbox-count:num<span class="Special"> <- </span>get *env, <span class="Constant">number-of-sandboxes:offset</span> - sandbox-count<span class="Special"> <- </span>add sandbox-count, <span class="Constant">1</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">number-of-sandboxes:offset</span>, sandbox-count + sandbox-count:num <span class="Special"><-</span> get *env, <span class="Constant">number-of-sandboxes:offset</span> + sandbox-count <span class="Special"><-</span> add sandbox-count,<span class="Constant"> 1</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">number-of-sandboxes:offset</span>, sandbox-count <span class="Comment"># clear sandbox editor</span> - init:&:duplex-list:char<span class="Special"> <- </span>push <span class="Constant">167/§</span>, <span class="Constant">0/tail</span> - *current-sandbox<span class="Special"> <- </span>put *current-sandbox, <span class="Constant">data:offset</span>, init - *current-sandbox<span class="Special"> <- </span>put *current-sandbox, <span class="Constant">top-of-screen:offset</span>, init + init:&:duplex-list:char <span class="Special"><-</span> push <span class="Constant">167/§</span>, <span class="Constant">0/tail</span> + *current-sandbox <span class="Special"><-</span> put *current-sandbox, <span class="Constant">data:offset</span>, init + *current-sandbox <span class="Special"><-</span> put *current-sandbox, <span class="Constant">top-of-screen:offset</span>, init <span class="Delimiter">}</span> <span class="Comment"># save all sandboxes before running, just in case we die when running</span> save-sandboxes env <span class="Comment"># run all sandboxes</span> - curr:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> - idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + curr:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> + idx:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> curr - curr<span class="Special"> <- </span>update-sandbox curr, env, idx - curr<span class="Special"> <- </span>get *curr, <span class="Constant">next-sandbox:offset</span> - idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> + curr <span class="Special"><-</span> update-sandbox curr, env, idx + curr <span class="Special"><-</span> get *curr, <span class="Constant">next-sandbox:offset</span> + idx <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Constant"> <run-sandboxes-end></span> @@ -224,46 +224,46 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> update-recipes env:&:environment, screen:&:screen<span class="muRecipe"> -> </span>errors-found?:bool, env:&:environment, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - recipes:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> - in:text<span class="Special"> <- </span>editor-contents recipes + recipes:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> + in:text <span class="Special"><-</span> editor-contents recipes save <span class="Constant">[recipes.mu]</span>, in <span class="Comment"># newlayer: persistence</span> reload in - errors-found?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + errors-found? <span class="Special"><-</span> copy <span class="Constant">0/false</span> ] <span class="Comment"># replaced in a later layer</span> <span class="muRecipe">def!</span> update-sandbox sandbox:&:sandbox, env:&:environment, idx:num<span class="muRecipe"> -> </span>sandbox:&:sandbox, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - data:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">data:offset</span> - response:text, _, fake-screen:&:screen<span class="Special"> <- </span>run-sandboxed data - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">response:offset</span>, response - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">screen:offset</span>, fake-screen + data:text <span class="Special"><-</span> get *sandbox, <span class="Constant">data:offset</span> + response:text, _, fake-screen:&:screen <span class="Special"><-</span> run-sandboxed data + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">response:offset</span>, response + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">screen:offset</span>, fake-screen ] <span class="muRecipe">def</span> update-status screen:&:screen, msg:text, color:num<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - screen<span class="Special"> <- </span>move-cursor screen, <span class="Constant">0</span>, <span class="Constant">2</span> - screen<span class="Special"> <- </span>print screen, msg, color, <span class="Constant">238/grey/background</span> + screen <span class="Special"><-</span> move-cursor screen,<span class="Constant"> 0</span>,<span class="Constant"> 2</span> + screen <span class="Special"><-</span> print screen, msg, color, <span class="Constant">238/grey/background</span> ] <span class="muRecipe">def</span> save-sandboxes env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> <span class="Comment"># first clear previous versions, in case we deleted some sandbox</span> - $system <span class="Constant">[rm lesson/[0-9]</span>* <span class="Constant">>/dev/null</span> <span class="Constant">2</span>>/dev/null] <span class="Comment"># some shells can't handle '>&'</span> - curr:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> - idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + $system <span class="Constant">[rm lesson/[0-9]</span>* <span class="Constant">>/dev/null</span> 2>/dev/null] <span class="Comment"># some shells can't handle '>&'</span> + curr:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> + idx:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> curr - data:text<span class="Special"> <- </span>get *curr, <span class="Constant">data:offset</span> - filename:text<span class="Special"> <- </span>to-text idx + data:text <span class="Special"><-</span> get *curr, <span class="Constant">data:offset</span> + filename:text <span class="Special"><-</span> to-text idx save filename, data <span class="Constant"> <end-save-sandbox></span> - idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> - curr<span class="Special"> <- </span>get *curr, <span class="Constant">next-sandbox:offset</span> + idx <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> + curr <span class="Special"><-</span> get *curr, <span class="Constant">next-sandbox:offset</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -271,24 +271,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def!</span> render-sandbox-side screen:&:screen, env:&:environment, <span class="Delimiter">{</span>render-editor: (recipe (address screen) (address editor)<span class="muRecipe"> -> </span>number number (address screen) (address editor))<span class="Delimiter">}</span><span class="muRecipe"> -> </span>screen:&:screen, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - trace <span class="Constant">11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render sandbox side]</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - row:num, column:num<span class="Special"> <- </span>copy <span class="Constant">1</span>, <span class="Constant">0</span> - left:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">left:offset</span> - right:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">right:offset</span> + trace<span class="Constant"> 11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render sandbox side]</span> + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + row:num, column:num <span class="Special"><-</span> copy<span class="Constant"> 1</span>,<span class="Constant"> 0</span> + left:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">left:offset</span> + right:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">right:offset</span> <span class="Comment"># render sandbox editor</span> - render-from:num<span class="Special"> <- </span>get *env, <span class="Constant">render-from:offset</span> + render-from:num <span class="Special"><-</span> get *env, <span class="Constant">render-from:offset</span> <span class="Delimiter">{</span> - render-current-sandbox?:bool<span class="Special"> <- </span>equal render-from, <span class="Constant">-1</span> + render-current-sandbox?:bool <span class="Special"><-</span> equal render-from,<span class="Constant"> -1</span> <span class="muControl">break-unless</span> render-current-sandbox? - row, column, screen, current-sandbox<span class="Special"> <- </span>call render-editor, screen, current-sandbox + row, column, screen, current-sandbox <span class="Special"><-</span> call render-editor, screen, current-sandbox clear-screen-from screen, row, column, left, right - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> <span class="Delimiter">}</span> <span class="Comment"># render sandboxes</span> draw-horizontal screen, row, left, right - sandbox:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> - row, screen<span class="Special"> <- </span>render-sandboxes screen, sandbox, left, right, row, render-from + sandbox:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> + row, screen <span class="Special"><-</span> render-sandboxes screen, sandbox, left, right, row, render-from clear-rest-of-screen screen, row, left, right ] @@ -296,40 +296,40 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">return-unless</span> sandbox - screen-height:num<span class="Special"> <- </span>screen-height screen - at-bottom?:bool<span class="Special"> <- </span>greater-or-equal row, screen-height + screen-height:num <span class="Special"><-</span> screen-height screen + at-bottom?:bool <span class="Special"><-</span> greater-or-equal row, screen-height <span class="muControl">return-if</span> at-bottom?:bool - hidden?:bool<span class="Special"> <- </span>lesser-than idx, render-from + hidden?:bool <span class="Special"><-</span> lesser-than idx, render-from <span class="Delimiter">{</span> <span class="muControl">break-if</span> hidden? <span class="Comment"># render sandbox menu</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - screen<span class="Special"> <- </span>move-cursor screen, row, left - screen<span class="Special"> <- </span>render-sandbox-menu screen, idx, left, right + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + screen <span class="Special"><-</span> move-cursor screen, row, left + screen <span class="Special"><-</span> render-sandbox-menu screen, idx, left, right <span class="Comment"># save menu row so we can detect clicks to it later</span> - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">starting-row-on-screen:offset</span>, row + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">starting-row-on-screen:offset</span>, row <span class="Comment"># render sandbox contents</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - screen<span class="Special"> <- </span>move-cursor screen, row, left - sandbox-data:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">data:offset</span> - row, screen<span class="Special"> <- </span>render-code screen, sandbox-data, left, right, row - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">code-ending-row-on-screen:offset</span>, row + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + screen <span class="Special"><-</span> move-cursor screen, row, left + sandbox-data:text <span class="Special"><-</span> get *sandbox, <span class="Constant">data:offset</span> + row, screen <span class="Special"><-</span> render-code screen, sandbox-data, left, right, row + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">code-ending-row-on-screen:offset</span>, row <span class="Comment"># render sandbox warnings, screen or response, in that order</span> - sandbox-response:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">response:offset</span> + sandbox-response:text <span class="Special"><-</span> get *sandbox, <span class="Constant">response:offset</span> <span class="Constant"> <render-sandbox-results></span> <span class="Delimiter">{</span> - sandbox-screen:&:screen<span class="Special"> <- </span>get *sandbox, <span class="Constant">screen:offset</span> - empty-screen?:bool<span class="Special"> <- </span>fake-screen-is-empty? sandbox-screen + sandbox-screen:&:screen <span class="Special"><-</span> get *sandbox, <span class="Constant">screen:offset</span> + empty-screen?:bool <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 + 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-unless</span> empty-screen? <span class="Constant"> <render-sandbox-response></span> - row, screen<span class="Special"> <- </span>render-text screen, sandbox-response, left, right, <span class="Constant">245/grey</span>, row + row, screen <span class="Special"><-</span> render-text screen, sandbox-response, left, right, <span class="Constant">245/grey</span>, row <span class="Delimiter">}</span> <span class="Constant"> +render-sandbox-end</span> - at-bottom?:bool<span class="Special"> <- </span>greater-or-equal row, screen-height + at-bottom?:bool <span class="Special"><-</span> greater-or-equal row, screen-height <span class="muControl">return-if</span> at-bottom? <span class="Comment"># draw solid line after sandbox</span> draw-horizontal screen, row, left, right @@ -337,33 +337,33 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># if hidden, reset row attributes</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> hidden? - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">starting-row-on-screen:offset</span>, <span class="Constant">0</span> - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">code-ending-row-on-screen:offset</span>, <span class="Constant">0</span> + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">starting-row-on-screen:offset</span>,<span class="Constant"> 0</span> + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">code-ending-row-on-screen:offset</span>,<span class="Constant"> 0</span> <span class="Constant"> <end-render-sandbox-reset-hidden></span> <span class="Delimiter">}</span> <span class="Comment"># draw next sandbox</span> - next-sandbox:&:sandbox<span class="Special"> <- </span>get *sandbox, <span class="Constant">next-sandbox:offset</span> - next-idx:num<span class="Special"> <- </span>add idx, <span class="Constant">1</span> - row, screen<span class="Special"> <- </span>render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx + next-sandbox:&:sandbox <span class="Special"><-</span> get *sandbox, <span class="Constant">next-sandbox:offset</span> + next-idx:num <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> + row, screen <span class="Special"><-</span> render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx ] <span class="muRecipe">def</span> render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num<span class="muRecipe"> -> </span>screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> move-cursor-to-column screen, left - edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num<span class="Special"> <- </span>sandbox-menu-columns left, right + edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num <span class="Special"><-</span> sandbox-menu-columns left, right print screen, sandbox-index, <span class="Constant">232/dark-grey</span>, <span class="Constant">245/grey</span> - start-buttons:num<span class="Special"> <- </span>subtract edit-button-left, <span class="Constant">1</span> + start-buttons:num <span class="Special"><-</span> subtract edit-button-left,<span class="Constant"> 1</span> clear-line-until screen, start-buttons, <span class="Constant">245/grey</span> print screen, <span class="Constant">[edit]</span>, <span class="Constant">232/black</span>, <span class="Constant">94/background-orange</span> clear-line-until screen, edit-button-right, <span class="Constant">94/background-orange</span> - _, col:num<span class="Special"> <- </span>cursor-position screen - at-start-of-copy-button?:bool<span class="Special"> <- </span>equal col, copy-button-left + _, col:num <span class="Special"><-</span> cursor-position screen + at-start-of-copy-button?:bool <span class="Special"><-</span> equal col, copy-button-left assert at-start-of-copy-button?, <span class="Constant">[aaa]</span> print screen, <span class="Constant">[copy]</span>, <span class="Constant">232/black</span>, <span class="Constant">58/background-green</span> clear-line-until screen, copy-button-right, <span class="Constant">58/background-green</span> - _, col:num<span class="Special"> <- </span>cursor-position screen - at-start-of-delete-button?:bool<span class="Special"> <- </span>equal col, delete-button-left + _, col:num <span class="Special"><-</span> cursor-position screen + at-start-of-delete-button?:bool <span class="Special"><-</span> equal col, delete-button-left assert at-start-of-delete-button?, <span class="Constant">[bbb]</span> print screen, <span class="Constant">[delete]</span>, <span class="Constant">232/black</span>, <span class="Constant">52/background-red</span> clear-line-until screen, right, <span class="Constant">52/background-red</span> @@ -375,16 +375,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> sandbox-menu-columns left:num, right:num<span class="muRecipe"> -> </span>edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - start-buttons:num<span class="Special"> <- </span>add left, <span class="Constant">4/space-for-sandbox-index</span> - buttons-space:num<span class="Special"> <- </span>subtract right, start-buttons - button-width:num<span class="Special"> <- </span>divide-with-remainder buttons-space, <span class="Constant">3</span> <span class="Comment"># integer division</span> - buttons-wide-enough?:bool<span class="Special"> <- </span>greater-or-equal button-width, <span class="Constant">8</span> + start-buttons:num <span class="Special"><-</span> add left, <span class="Constant">4/space-for-sandbox-index</span> + buttons-space:num <span class="Special"><-</span> subtract right, start-buttons + button-width:num <span class="Special"><-</span> divide-with-remainder buttons-space,<span class="Constant"> 3</span> <span class="Comment"># integer division</span> + buttons-wide-enough?:bool <span class="Special"><-</span> greater-or-equal button-width,<span class="Constant"> 8</span> assert buttons-wide-enough?, <span class="Constant">[sandbox must be at least 30 or so characters wide]</span> - edit-button-left:num<span class="Special"> <- </span>copy start-buttons - copy-button-left:num<span class="Special"> <- </span>add start-buttons, button-width - edit-button-right:num<span class="Special"> <- </span>subtract copy-button-left, <span class="Constant">1</span> - delete-button-left:num<span class="Special"> <- </span>subtract right, button-width - copy-button-right:num<span class="Special"> <- </span>subtract delete-button-left, <span class="Constant">1</span> + edit-button-left:num <span class="Special"><-</span> copy start-buttons + copy-button-left:num <span class="Special"><-</span> add start-buttons, button-width + edit-button-right:num <span class="Special"><-</span> subtract copy-button-left,<span class="Constant"> 1</span> + delete-button-left:num <span class="Special"><-</span> subtract right, button-width + copy-button-right:num <span class="Special"><-</span> subtract delete-button-left,<span class="Constant"> 1</span> ] <span class="Comment"># print a text 's' to 'editor' in 'color' starting at 'row'</span> @@ -393,58 +393,58 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">return-unless</span> s - column:num<span class="Special"> <- </span>copy left - screen<span class="Special"> <- </span>move-cursor screen, row, column - screen-height:num<span class="Special"> <- </span>screen-height screen - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - len:num<span class="Special"> <- </span>length *s + column:num <span class="Special"><-</span> copy left + screen <span class="Special"><-</span> move-cursor screen, row, column + screen-height:num <span class="Special"><-</span> screen-height screen + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + len:num <span class="Special"><-</span> length *s <span class="Delimiter">{</span> <span class="Constant"> +next-character</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <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 + done? <span class="Special"><-</span> greater-or-equal row, screen-height <span class="muControl">break-if</span> done? - c:char<span class="Special"> <- </span>index *s, i + c:char <span class="Special"><-</span> index *s, i <span class="Delimiter">{</span> <span class="Comment"># at right? wrap.</span> - at-right?:bool<span class="Special"> <- </span>equal column, right + at-right?:bool <span class="Special"><-</span> equal column, right <span class="muControl">break-unless</span> at-right? <span class="Comment"># print wrap icon</span> - wrap-icon:char<span class="Special"> <- </span>copy <span class="Constant">8617/loop-back-to-left</span> + wrap-icon:char <span class="Special"><-</span> copy <span class="Constant">8617/loop-back-to-left</span> print screen, wrap-icon, <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> - screen<span class="Special"> <- </span>move-cursor screen, row, column + column <span class="Special"><-</span> copy left + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="muControl">loop</span> <span class="Constant">+next-character</span> <span class="Comment"># retry i</span> <span class="Delimiter">}</span> - i<span class="Special"> <- </span>add i, <span class="Constant">1</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?:bool<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span> + newline?:bool <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?:bool<span class="Special"> <- </span>greater-than column, right + done?:bool <span class="Special"><-</span> greater-than column, right <span class="muControl">break-if</span> done? - space:char<span class="Special"> <- </span>copy <span class="Constant">32/space</span> + space:char <span class="Special"><-</span> copy <span class="Constant">32/space</span> print screen, space - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> - column<span class="Special"> <- </span>copy left - screen<span class="Special"> <- </span>move-cursor screen, row, column + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> + column <span class="Special"><-</span> copy left + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="muControl">loop</span> <span class="Constant">+next-character</span> <span class="Delimiter">}</span> print screen, c, color - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - was-at-left?:bool<span class="Special"> <- </span>equal column, left + was-at-left?:bool <span class="Special"><-</span> equal column, left clear-line-until screen, right <span class="Delimiter">{</span> <span class="muControl">break-if</span> was-at-left? - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> <span class="Delimiter">}</span> move-cursor screen, row, left ] @@ -454,32 +454,32 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># read all scenarios, pushing them to end of a list of scenarios</span> - idx:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - curr:&:sandbox<span class="Special"> <- </span>copy <span class="Constant">0</span> - prev:&:sandbox<span class="Special"> <- </span>copy <span class="Constant">0</span> + idx:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + curr:&:sandbox <span class="Special"><-</span> copy<span class="Constant"> 0</span> + prev:&:sandbox <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - filename:text<span class="Special"> <- </span>to-text idx - contents:text<span class="Special"> <- </span>restore filename + filename:text <span class="Special"><-</span> to-text idx + contents:text <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"># todo: handle empty sandbox</span> <span class="Comment"># create new sandbox for file</span> - curr<span class="Special"> <- </span>new <span class="Constant">sandbox:type</span> - *curr<span class="Special"> <- </span>put *curr, <span class="Constant">data:offset</span>, contents + curr <span class="Special"><-</span> new <span class="Constant">sandbox:type</span> + *curr <span class="Special"><-</span> put *curr, <span class="Constant">data:offset</span>, contents <span class="Constant"> <end-restore-sandbox></span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> idx - *env<span class="Special"> <- </span>put *env, <span class="Constant">sandbox:offset</span>, curr + *env <span class="Special"><-</span> put *env, <span class="Constant">sandbox:offset</span>, curr <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> idx - *prev<span class="Special"> <- </span>put *prev, <span class="Constant">next-sandbox:offset</span>, curr + *prev <span class="Special"><-</span> put *prev, <span class="Constant">next-sandbox:offset</span>, curr <span class="Delimiter">}</span> - idx<span class="Special"> <- </span>add idx, <span class="Constant">1</span> - prev<span class="Special"> <- </span>copy curr + idx <span class="Special"><-</span> add idx,<span class="Constant"> 1</span> + prev <span class="Special"><-</span> copy curr <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># update sandbox count</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">number-of-sandboxes:offset</span>, idx + *env <span class="Special"><-</span> put *env, <span class="Constant">number-of-sandboxes:offset</span>, idx ] <span class="Comment"># print the fake sandbox screen to 'screen' with appropriate delimiters</span> @@ -489,62 +489,62 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="muControl">return-unless</span> sandbox-screen <span class="Comment"># print 'screen:'</span> - row<span class="Special"> <- </span>render-text screen, <span class="Constant">[screen:]</span>, left, right, <span class="Constant">245/grey</span>, row - screen<span class="Special"> <- </span>move-cursor screen, row, left + row <span class="Special"><-</span> render-text screen, <span class="Constant">[screen:]</span>, left, right, <span class="Constant">245/grey</span>, row + screen <span class="Special"><-</span> move-cursor screen, row, left <span class="Comment"># start printing sandbox-screen</span> - column:num<span class="Special"> <- </span>copy left - s-width:num<span class="Special"> <- </span>screen-width sandbox-screen - s-height:num<span class="Special"> <- </span>screen-height sandbox-screen - buf:&:@:screen-cell<span class="Special"> <- </span>get *sandbox-screen, <span class="Constant">data:offset</span> - stop-printing:num<span class="Special"> <- </span>add left, s-width, <span class="Constant">3</span> - max-column:num<span class="Special"> <- </span>min stop-printing, right - i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - len:num<span class="Special"> <- </span>length *buf - screen-height:num<span class="Special"> <- </span>screen-height screen + column:num <span class="Special"><-</span> copy left + s-width:num <span class="Special"><-</span> screen-width sandbox-screen + s-height:num <span class="Special"><-</span> screen-height sandbox-screen + buf:&:@:screen-cell <span class="Special"><-</span> get *sandbox-screen, <span class="Constant">data:offset</span> + stop-printing:num <span class="Special"><-</span> add left, s-width,<span class="Constant"> 3</span> + max-column:num <span class="Special"><-</span> min stop-printing, right + i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + len:num <span class="Special"><-</span> length *buf + screen-height:num <span class="Special"><-</span> screen-height screen <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal i, len + done?:bool <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 + 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 - screen<span class="Special"> <- </span>move-cursor screen, row, column + column <span class="Special"><-</span> copy left + screen <span class="Special"><-</span> move-cursor screen, row, column <span class="Comment"># initial leader for each row: two spaces and a '.'</span> - space:char<span class="Special"> <- </span>copy <span class="Constant">32/space</span> + space:char <span class="Special"><-</span> copy <span class="Constant">32/space</span> print screen, space, <span class="Constant">245/grey</span> print screen, space, <span class="Constant">245/grey</span> - full-stop:char<span class="Special"> <- </span>copy <span class="Constant">46/period</span> + full-stop:char <span class="Special"><-</span> copy <span class="Constant">46/period</span> print screen, full-stop, <span class="Constant">245/grey</span> - column<span class="Special"> <- </span>add left, <span class="Constant">3</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?:bool<span class="Special"> <- </span>greater-or-equal column, max-column + row-done?:bool <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:char<span class="Special"> <- </span>get curr, <span class="Constant">contents:offset</span> - color:num<span class="Special"> <- </span>get curr, <span class="Constant">color:offset</span> + curr:screen-cell <span class="Special"><-</span> index *buf, i + c:char <span class="Special"><-</span> get curr, <span class="Constant">contents:offset</span> + color:num <span class="Special"><-</span> get curr, <span class="Constant">color:offset</span> <span class="Delimiter">{</span> <span class="Comment"># damp whites down to grey</span> - white?:bool<span class="Special"> <- </span>equal color, <span class="Constant">7/white</span> + white?:bool <span class="Special"><-</span> equal color, <span class="Constant">7/white</span> <span class="muControl">break-unless</span> white? - color<span class="Special"> <- </span>copy <span class="Constant">245/grey</span> + color <span class="Special"><-</span> copy <span class="Constant">245/grey</span> <span class="Delimiter">}</span> print screen, c, color - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> - i<span class="Special"> <- </span>add i, <span class="Constant">1</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 screen, full-stop, <span class="Constant">245/grey</span> - column<span class="Special"> <- </span>add column, <span class="Constant">1</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?:bool<span class="Special"> <- </span>greater-than column, right + line-done?:bool <span class="Special"><-</span> greater-than column, right <span class="muControl">break-if</span> line-done? print screen, space - column<span class="Special"> <- </span>add column, <span class="Constant">1</span> + column <span class="Special"><-</span> add column,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - row<span class="Special"> <- </span>add row, <span class="Constant">1</span> + row <span class="Special"><-</span> add row,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -554,14 +554,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">12/height</span> <span class="Comment"># define a recipe (no indent for the 'add' line below so column numbers are more obvious)</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant">local-scope</span> <span class="Constant">z:num <- add 2, 2</span> <span class="Constant">reply z</span> <span class="Constant">]</span>] <span class="Comment"># sandbox editor contains an instruction without storing outputs</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run the code in the editors</span> assume-console [ press F4 @@ -580,7 +580,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># make a change (incrementing one of the args to 'add'), then rerun</span> assume-console [ - left-click <span class="Constant">4</span>, <span class="Constant">28</span> <span class="Comment"># one past the value of the second arg</span> + left-click<span class="Constant"> 4</span>,<span class="Constant"> 28</span> <span class="Comment"># one past the value of the second arg</span> press backspace type <span class="Constant">[3]</span> press F4 @@ -608,7 +608,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen <span class="Constant">100/width</span>, <span class="Constant">20/height</span> <span class="Comment"># left editor is empty</span> <span class="Comment"># right editor contains an instruction</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[print-integer screen, 4]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[print-integer screen, 4]</span> <span class="Comment"># run the code in the editor</span> assume-console [ press F4 @@ -637,37 +637,37 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> editor-contents editor:&:editor<span class="muRecipe"> -> </span>result:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">80</span> - curr:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 80</span> + curr:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> <span class="Comment"># skip § sentinel</span> assert curr, <span class="Constant">[editor without data is illegal; must have at least a sentinel]</span> - curr<span class="Special"> <- </span>next curr - <span class="muControl">return-unless</span> curr, <span class="Constant">0</span> + curr <span class="Special"><-</span> next curr + <span class="muControl">return-unless</span> curr,<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> curr - c:char<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span> - buf<span class="Special"> <- </span>append buf, c - curr<span class="Special"> <- </span>next curr + c:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> + buf <span class="Special"><-</span> append buf, c + curr <span class="Special"><-</span> next curr <span class="muControl">loop</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>buffer-to-array buf + result <span class="Special"><-</span> buffer-to-array buf ] <span class="muScenario">scenario</span> editor-provides-edited-contents [ <span class="Constant">local-scope</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 2</span> type <span class="Constant">[def]</span> ] run [ editor-event-loop screen, console, e - s:text<span class="Special"> <- </span>editor-contents e - <span class="Constant">1</span>:@:char/<span class="Special">raw <- </span>copy *s + s:text <span class="Special"><-</span> editor-contents e + 1:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s ] memory-should-contain [ - <span class="Constant">1</span>:array:character<span class="Special"> <- </span><span class="Constant">[abdefc]</span> + 1:array:character <span class="Special"><-</span> <span class="Constant">[abdefc]</span> ] ] @@ -677,7 +677,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render assume-console [ press enter @@ -698,7 +698,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render assume-console [ press enter @@ -706,7 +706,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color press down-arrow <span class="Comment"># while cursor isn't at bottom</span> ] event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor <span class="Comment"># cursor moves back to bottom</span> screen-should-contain [ @@ -726,28 +726,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><render-recipe-components-end></span> [ - *env<span class="Special"> <- </span>put *env, <span class="Constant">recipe-bottom:offset</span>, row + *env <span class="Special"><-</span> put *env, <span class="Constant">recipe-bottom:offset</span>, row ] <span class="muRecipe">after</span> <span class="Constant"><global-keypress></span> [ <span class="Delimiter">{</span> <span class="muControl">break-if</span> sandbox-in-focus? - down-arrow?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65516/down-arrow</span> + down-arrow?:bool <span class="Special"><-</span> equal k, <span class="Constant">65516/down-arrow</span> <span class="muControl">break-unless</span> down-arrow? - recipe-editor:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> - recipe-cursor-row:num<span class="Special"> <- </span>get *recipe-editor, <span class="Constant">cursor-row:offset</span> - recipe-editor-bottom:num<span class="Special"> <- </span>get *recipe-editor, <span class="Constant">bottom:offset</span> - at-bottom-of-editor?:bool<span class="Special"> <- </span>greater-or-equal recipe-cursor-row, recipe-editor-bottom + recipe-editor:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> + recipe-cursor-row:num <span class="Special"><-</span> get *recipe-editor, <span class="Constant">cursor-row:offset</span> + recipe-editor-bottom:num <span class="Special"><-</span> get *recipe-editor, <span class="Constant">bottom:offset</span> + at-bottom-of-editor?:bool <span class="Special"><-</span> greater-or-equal recipe-cursor-row, recipe-editor-bottom <span class="muControl">break-unless</span> at-bottom-of-editor? - more-to-scroll?:bool<span class="Special"> <- </span>more-to-scroll? env, screen + more-to-scroll?:bool <span class="Special"><-</span> more-to-scroll? env, screen <span class="muControl">break-if</span> more-to-scroll? <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> sandbox-in-focus? - page-down?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65518/page-down</span> + page-down?:bool <span class="Special"><-</span> equal k, <span class="Constant">65518/page-down</span> <span class="muControl">break-unless</span> page-down? - more-to-scroll?:bool<span class="Special"> <- </span>more-to-scroll? env, screen + more-to-scroll?:bool <span class="Special"><-</span> more-to-scroll? env, screen <span class="muControl">break-if</span> more-to-scroll? <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> @@ -756,9 +756,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-type></span> [ <span class="Delimiter">{</span> <span class="muControl">break-if</span> sandbox-in-focus? - page-down?:bool<span class="Special"> <- </span>equal k, <span class="Constant">6/ctrl-f</span> + page-down?:bool <span class="Special"><-</span> equal k, <span class="Constant">6/ctrl-f</span> <span class="muControl">break-unless</span> page-down? - more-to-scroll?:bool<span class="Special"> <- </span>more-to-scroll? env, screen + more-to-scroll?:bool <span class="Special"><-</span> more-to-scroll? env, screen <span class="muControl">break-if</span> more-to-scroll? <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> @@ -767,16 +767,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> more-to-scroll? env:&:environment, screen:&:screen<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - recipe-bottom:num<span class="Special"> <- </span>get *env, <span class="Constant">recipe-bottom:offset</span> - height:num<span class="Special"> <- </span>screen-height screen - result<span class="Special"> <- </span>greater-or-equal recipe-bottom, height + recipe-bottom:num <span class="Special"><-</span> get *env, <span class="Constant">recipe-bottom:offset</span> + height:num <span class="Special"><-</span> screen-height screen + result <span class="Special"><-</span> greater-or-equal recipe-bottom, height ] <span class="muScenario">scenario</span> scrolling-down-past-bottom-of-recipe-editor-2 [ <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render assume-console [ <span class="Comment"># add a line</span> @@ -801,7 +801,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[ab</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[ab</span> <span class="Constant">cd]</span> render-all screen, env, render assume-console [ @@ -813,7 +813,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color press down-arrow ] event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor <span class="Comment"># no scroll on recipe side, cursor moves on sandbox side</span> screen-should-contain [ @@ -832,7 +832,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize sandbox side</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[add 2, 2]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[add 2, 2]</span> render-all screen, env, render assume-console [ <span class="Comment"># create a sandbox</span> @@ -853,7 +853,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># sandbox editor hidden; first sandbox displayed</span> @@ -871,7 +871,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># sandbox editor displays again, cursor is in editor</span> @@ -888,22 +888,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-keypress></span> [ <span class="Delimiter">{</span> <span class="muControl">break-unless</span> sandbox-in-focus? - page-down?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65518/page-down</span> + page-down?:bool <span class="Special"><-</span> equal k, <span class="Constant">65518/page-down</span> <span class="muControl">break-unless</span> page-down? - sandbox:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> + sandbox:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> <span class="muControl">break-unless</span> sandbox <span class="Comment"># slide down if possible</span> <span class="Delimiter">{</span> - render-from:num<span class="Special"> <- </span>get *env, <span class="Constant">render-from:offset</span> - number-of-sandboxes:num<span class="Special"> <- </span>get *env, <span class="Constant">number-of-sandboxes:offset</span> - max:num<span class="Special"> <- </span>subtract number-of-sandboxes, <span class="Constant">1</span> - at-end?:bool<span class="Special"> <- </span>greater-or-equal render-from, max + render-from:num <span class="Special"><-</span> get *env, <span class="Constant">render-from:offset</span> + number-of-sandboxes:num <span class="Special"><-</span> get *env, <span class="Constant">number-of-sandboxes:offset</span> + max:num <span class="Special"><-</span> subtract number-of-sandboxes,<span class="Constant"> 1</span> + at-end?:bool <span class="Special"><-</span> greater-or-equal render-from, max <span class="muControl">jump-if</span> at-end?, <span class="Constant">+finish-event</span> <span class="Comment"># render nothing</span> - render-from<span class="Special"> <- </span>add render-from, <span class="Constant">1</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">render-from:offset</span>, render-from + render-from <span class="Special"><-</span> add render-from,<span class="Constant"> 1</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">render-from:offset</span>, render-from <span class="Delimiter">}</span> hide-screen screen - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render + screen <span class="Special"><-</span> render-sandbox-side screen, env, render show-screen screen <span class="muControl">jump</span> <span class="Constant">+finish-event</span> <span class="Delimiter">}</span> @@ -913,11 +913,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><update-cursor-special-cases></span> [ <span class="Delimiter">{</span> <span class="muControl">break-unless</span> sandbox-in-focus? - render-from:num<span class="Special"> <- </span>get *env, <span class="Constant">render-from:offset</span> - scrolling?:bool<span class="Special"> <- </span>greater-or-equal render-from, <span class="Constant">0</span> + render-from:num <span class="Special"><-</span> get *env, <span class="Constant">render-from:offset</span> + scrolling?:bool <span class="Special"><-</span> greater-or-equal render-from,<span class="Constant"> 0</span> <span class="muControl">break-unless</span> scrolling? - cursor-column:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">left:offset</span> - screen<span class="Special"> <- </span>move-cursor screen, <span class="Constant">2/row</span>, cursor-column <span class="Comment"># highlighted sandbox will always start at row 2</span> + cursor-column:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">left:offset</span> + screen <span class="Special"><-</span> move-cursor screen, <span class="Constant">2/row</span>, cursor-column <span class="Comment"># highlighted sandbox will always start at row 2</span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] @@ -926,15 +926,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-keypress></span> [ <span class="Delimiter">{</span> <span class="muControl">break-unless</span> sandbox-in-focus? - page-up?:bool<span class="Special"> <- </span>equal k, <span class="Constant">65519/page-up</span> + page-up?:bool <span class="Special"><-</span> equal k, <span class="Constant">65519/page-up</span> <span class="muControl">break-unless</span> page-up? - render-from:num<span class="Special"> <- </span>get *env, <span class="Constant">render-from:offset</span> - at-beginning?:bool<span class="Special"> <- </span>equal render-from, <span class="Constant">-1</span> + render-from:num <span class="Special"><-</span> get *env, <span class="Constant">render-from:offset</span> + at-beginning?:bool <span class="Special"><-</span> equal render-from,<span class="Constant"> -1</span> <span class="muControl">break-if</span> at-beginning? - render-from<span class="Special"> <- </span>subtract render-from, <span class="Constant">1</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">render-from:offset</span>, render-from + render-from <span class="Special"><-</span> subtract render-from,<span class="Constant"> 1</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">render-from:offset</span>, render-from hide-screen screen - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render + screen <span class="Special"><-</span> render-sandbox-side screen, env, render show-screen screen <span class="muControl">jump</span> <span class="Constant">+finish-event</span> <span class="Delimiter">}</span> @@ -945,15 +945,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> previous-sandbox env:&:environment, in:&:sandbox<span class="muRecipe"> -> </span>out:&:sandbox [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - curr:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> + curr:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> <span class="muControl">return-unless</span> curr, <span class="Constant">0/nil</span> - next:&:sandbox<span class="Special"> <- </span>get *curr, <span class="Constant">next-sandbox:offset</span> + next:&:sandbox <span class="Special"><-</span> get *curr, <span class="Constant">next-sandbox:offset</span> <span class="Delimiter">{</span> <span class="muControl">return-unless</span> next, <span class="Constant">0/nil</span> - found?:bool<span class="Special"> <- </span>equal next, in + found?:bool <span class="Special"><-</span> equal next, in <span class="muControl">break-if</span> found? - curr<span class="Special"> <- </span>copy next - next<span class="Special"> <- </span>get *curr, <span class="Constant">next-sandbox:offset</span> + curr <span class="Special"><-</span> copy next + next <span class="Special"><-</span> get *curr, <span class="Constant">next-sandbox:offset</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">return</span> curr @@ -964,10 +964,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize sandbox side and create a sandbox</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">]</span> <span class="Comment"># create a sandbox</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes:text, <span class="Constant">[add 2, 2]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes:text, <span class="Constant">[add 2, 2]</span> render-all screen, env, render assume-console [ press F4 @@ -979,7 +979,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># cursor moves down on recipe side</span> @@ -997,7 +997,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize environment</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render <span class="Comment"># create 2 sandboxes</span> assume-console [ @@ -1008,7 +1008,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color press F4 ] event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor screen-should-contain [ <span class="Constant"> . run (F4) .</span> @@ -1028,7 +1028,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># sandbox editor hidden; first sandbox displayed</span> @@ -1103,7 +1103,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># back to displaying both sandboxes as well as editor</span> @@ -1125,7 +1125,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># no change</span> @@ -1148,7 +1148,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize environment</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render <span class="Comment"># create a sandbox</span> assume-console [ diff --git a/html/edit/006-sandbox-copy.mu.html b/html/edit/006-sandbox-copy.mu.html index 8f96e319..0ae24c18 100644 --- a/html/edit/006-sandbox-copy.mu.html +++ b/html/edit/006-sandbox-copy.mu.html @@ -40,11 +40,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># basic recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> reply 4</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run it</span> assume-console [ press F4 @@ -62,7 +62,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click at left edge of 'copy' button</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">69</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 69</span> ] run [ event-loop screen, console, env @@ -102,11 +102,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># basic recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> reply 4</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run it</span> assume-console [ press F4 @@ -124,7 +124,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click at right edge of 'copy' button (just before 'delete')</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">84</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 84</span> ] run [ event-loop screen, console, env @@ -162,13 +162,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-touch></span> [ <span class="Comment"># support 'copy' button</span> <span class="Delimiter">{</span> - copy?:bool<span class="Special"> <- </span>should-attempt-copy? click-row, click-column, env + copy?:bool <span class="Special"><-</span> should-attempt-copy? click-row, click-column, env <span class="muControl">break-unless</span> copy? - copy?, env<span class="Special"> <- </span>try-copy-sandbox click-row, env + copy?, env <span class="Special"><-</span> try-copy-sandbox click-row, env <span class="muControl">break-unless</span> copy? hide-screen screen - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <span class="Special"><-</span> render-sandbox-side screen, env, render + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env show-screen screen <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> @@ -179,47 +179,47 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># are we below the sandbox editor?</span> - click-sandbox-area?:bool<span class="Special"> <- </span>click-on-sandbox-area? click-row, click-column, env + click-sandbox-area?:bool <span class="Special"><-</span> click-on-sandbox-area? click-row, click-column, env <span class="muControl">reply-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> <span class="Comment"># narrower, is the click in the columns spanning the 'copy' button?</span> - first-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> + first-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> assert first-sandbox, <span class="Constant">[!!]</span> - sandbox-left-margin:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">left:offset</span> - sandbox-right-margin:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">right:offset</span> - _, _, copy-button-left:num, copy-button-right:num, _<span class="Special"> <- </span>sandbox-menu-columns sandbox-left-margin, sandbox-right-margin - copy-button-vertical-area?:bool<span class="Special"> <- </span>within-range? click-column, copy-button-left, copy-button-right + sandbox-left-margin:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">left:offset</span> + sandbox-right-margin:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">right:offset</span> + _, _, copy-button-left:num, copy-button-right:num, _ <span class="Special"><-</span> sandbox-menu-columns sandbox-left-margin, sandbox-right-margin + copy-button-vertical-area?:bool <span class="Special"><-</span> within-range? click-column, copy-button-left, copy-button-right <span class="muControl">reply-unless</span> copy-button-vertical-area?, <span class="Constant">0/false</span> <span class="Comment"># finally, is sandbox editor empty?</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - result<span class="Special"> <- </span>empty-editor? current-sandbox + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + result <span class="Special"><-</span> empty-editor? current-sandbox ] <span class="muRecipe">def</span> try-copy-sandbox click-row:num, env:&:environment<span class="muRecipe"> -> </span>clicked-on-copy-button?:bool, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># identify the sandbox to copy, if the click was actually on the 'copy' button</span> - sandbox:&:sandbox<span class="Special"> <- </span>find-sandbox env, click-row + sandbox:&:sandbox <span class="Special"><-</span> find-sandbox env, click-row <span class="muControl">return-unless</span> sandbox, <span class="Constant">0/false</span> - clicked-on-copy-button?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> - text:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">data:offset</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - current-sandbox<span class="Special"> <- </span>insert-text current-sandbox, text + clicked-on-copy-button? <span class="Special"><-</span> copy <span class="Constant">1/true</span> + text:text <span class="Special"><-</span> get *sandbox, <span class="Constant">data:offset</span> + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + current-sandbox <span class="Special"><-</span> insert-text current-sandbox, text <span class="Comment"># reset scroll</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">render-from:offset</span>, <span class="Constant">-1</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">render-from:offset</span>,<span class="Constant"> -1</span> <span class="Comment"># position cursor in sandbox editor</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">sandbox-in-focus?:offset</span>, <span class="Constant">1/true</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">sandbox-in-focus?:offset</span>, <span class="Constant">1/true</span> ] <span class="muRecipe">def</span> find-sandbox env:&:environment, click-row:num<span class="muRecipe"> -> </span>result:&:sandbox [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - curr-sandbox:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> + curr-sandbox:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> curr-sandbox - start:num<span class="Special"> <- </span>get *curr-sandbox, <span class="Constant">starting-row-on-screen:offset</span> - found?:bool<span class="Special"> <- </span>equal click-row, start + start:num <span class="Special"><-</span> get *curr-sandbox, <span class="Constant">starting-row-on-screen:offset</span> + found?:bool <span class="Special"><-</span> equal click-row, start <span class="muControl">return-if</span> found?, curr-sandbox - curr-sandbox<span class="Special"> <- </span>get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> + curr-sandbox <span class="Special"><-</span> get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Constant">0/not-found</span> @@ -228,30 +228,30 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> click-on-sandbox-area? click-row:num, click-column:num, env:&:environment<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - sandbox-left-margin:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">left:offset</span> - on-sandbox-side?:bool<span class="Special"> <- </span>greater-or-equal click-column, sandbox-left-margin + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + sandbox-left-margin:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">left:offset</span> + on-sandbox-side?:bool <span class="Special"><-</span> greater-or-equal click-column, sandbox-left-margin <span class="muControl">return-unless</span> on-sandbox-side?, <span class="Constant">0/false</span> - first-sandbox:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> + first-sandbox:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> <span class="muControl">return-unless</span> first-sandbox, <span class="Constant">0/false</span> - first-sandbox-begins:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">starting-row-on-screen:offset</span> - result<span class="Special"> <- </span>greater-or-equal click-row, first-sandbox-begins + first-sandbox-begins:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">starting-row-on-screen:offset</span> + result <span class="Special"><-</span> greater-or-equal click-row, first-sandbox-begins ] <span class="muRecipe">def</span> empty-editor? editor:&:editor<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - head:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> - first:&:duplex-list:char<span class="Special"> <- </span>next head - result<span class="Special"> <- </span>not first + head:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> + first:&:duplex-list:char <span class="Special"><-</span> next head + result <span class="Special"><-</span> not first ] <span class="muRecipe">def</span> within-range? x:num, low:num, high:num<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - not-too-far-left?:bool<span class="Special"> <- </span>greater-or-equal x, low - not-too-far-right?:bool<span class="Special"> <- </span>lesser-or-equal x, high - result<span class="Special"> <- </span>and not-too-far-left? not-too-far-right? + not-too-far-left?:bool <span class="Special"><-</span> greater-or-equal x, low + not-too-far-right?:bool <span class="Special"><-</span> lesser-or-equal x, high + result <span class="Special"><-</span> and not-too-far-left? not-too-far-right? ] <span class="muScenario">scenario</span> copy-fails-if-sandbox-editor-not-empty [ @@ -259,11 +259,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># basic recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> reply 4</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run it</span> assume-console [ press F4 @@ -281,9 +281,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># type something into the sandbox editor, then click on the 'copy' button</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">70</span> <span class="Comment"># put cursor in sandbox editor</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 70</span> <span class="Comment"># put cursor in sandbox editor</span> type <span class="Constant">[0]</span> <span class="Comment"># type something</span> - left-click <span class="Constant">3</span>, <span class="Constant">70</span> <span class="Comment"># click 'copy' button</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 70</span> <span class="Comment"># click 'copy' button</span> ] run [ event-loop screen, console, env diff --git a/html/edit/007-sandbox-delete.mu.html b/html/edit/007-sandbox-delete.mu.html index ffae21e3..5fbf7441 100644 --- a/html/edit/007-sandbox-delete.mu.html +++ b/html/edit/007-sandbox-delete.mu.html @@ -38,10 +38,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> <span class="Comment"># run a few commands</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">80</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 80</span> type <span class="Constant">[divide-with-remainder 11, 3]</span> press F4 type <span class="Constant">[add 2, 2]</span> @@ -65,7 +65,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># delete second sandbox by clicking on left edge of 'delete' button</span> assume-console [ - left-click <span class="Constant">7</span>, <span class="Constant">85</span> + left-click<span class="Constant"> 7</span>,<span class="Constant"> 85</span> ] run [ event-loop screen, console, env @@ -83,7 +83,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># delete first sandbox by clicking at right edge of 'delete' button</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">99</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 99</span> ] run [ event-loop screen, console, env @@ -100,13 +100,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-touch></span> [ <span class="Comment"># support 'delete' button</span> <span class="Delimiter">{</span> - delete?:bool<span class="Special"> <- </span>should-attempt-delete? click-row, click-column, env + delete?:bool <span class="Special"><-</span> should-attempt-delete? click-row, click-column, env <span class="muControl">break-unless</span> delete? - delete?, env<span class="Special"> <- </span>try-delete-sandbox click-row, env + delete?, env <span class="Special"><-</span> try-delete-sandbox click-row, env <span class="muControl">break-unless</span> delete? hide-screen screen - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <span class="Special"><-</span> render-sandbox-side screen, env, render + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env show-screen screen <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> @@ -117,66 +117,66 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># are we below the sandbox editor?</span> - click-sandbox-area?:bool<span class="Special"> <- </span>click-on-sandbox-area? click-row, click-column, env + click-sandbox-area?:bool <span class="Special"><-</span> click-on-sandbox-area? click-row, click-column, env <span class="muControl">reply-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> <span class="Comment"># narrower, is the click in the columns spanning the 'copy' button?</span> - first-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> + first-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> assert first-sandbox, <span class="Constant">[!!]</span> - sandbox-left-margin:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">left:offset</span> - sandbox-right-margin:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">right:offset</span> - _, _, _, _, delete-button-left:num<span class="Special"> <- </span>sandbox-menu-columns sandbox-left-margin, sandbox-right-margin - result<span class="Special"> <- </span>within-range? click-column, delete-button-left, sandbox-right-margin + sandbox-left-margin:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">left:offset</span> + sandbox-right-margin:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">right:offset</span> + _, _, _, _, delete-button-left:num <span class="Special"><-</span> sandbox-menu-columns sandbox-left-margin, sandbox-right-margin + result <span class="Special"><-</span> within-range? click-column, delete-button-left, sandbox-right-margin ] <span class="muRecipe">def</span> try-delete-sandbox click-row:num, env:&:environment<span class="muRecipe"> -> </span>clicked-on-delete-button?:bool, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># identify the sandbox to delete, if the click was actually on the 'delete' button</span> - sandbox:&:sandbox<span class="Special"> <- </span>find-sandbox env, click-row + sandbox:&:sandbox <span class="Special"><-</span> find-sandbox env, click-row <span class="muControl">return-unless</span> sandbox, <span class="Constant">0/false</span> - clicked-on-delete-button?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> - env<span class="Special"> <- </span>delete-sandbox env, sandbox + clicked-on-delete-button? <span class="Special"><-</span> copy <span class="Constant">1/true</span> + env <span class="Special"><-</span> delete-sandbox env, sandbox ] <span class="muRecipe">def</span> delete-sandbox env:&:environment, sandbox:&:sandbox<span class="muRecipe"> -> </span>env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - curr-sandbox:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> - first-sandbox?:bool<span class="Special"> <- </span>equal curr-sandbox, sandbox + curr-sandbox:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> + first-sandbox?:bool <span class="Special"><-</span> equal curr-sandbox, sandbox <span class="Delimiter">{</span> <span class="Comment"># first sandbox? pop</span> <span class="muControl">break-unless</span> first-sandbox? - next-sandbox:&:sandbox<span class="Special"> <- </span>get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">sandbox:offset</span>, next-sandbox + next-sandbox:&:sandbox <span class="Special"><-</span> get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">sandbox:offset</span>, next-sandbox <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># not first sandbox?</span> <span class="muControl">break-if</span> first-sandbox? - prev-sandbox:&:sandbox<span class="Special"> <- </span>copy curr-sandbox - curr-sandbox<span class="Special"> <- </span>get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> + prev-sandbox:&:sandbox <span class="Special"><-</span> copy curr-sandbox + curr-sandbox <span class="Special"><-</span> get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> <span class="Delimiter">{</span> assert curr-sandbox, <span class="Constant">[sandbox not found! something is wrong.]</span> - found?:bool<span class="Special"> <- </span>equal curr-sandbox, sandbox + found?:bool <span class="Special"><-</span> equal curr-sandbox, sandbox <span class="muControl">break-if</span> found? - prev-sandbox<span class="Special"> <- </span>copy curr-sandbox - curr-sandbox<span class="Special"> <- </span>get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> + prev-sandbox <span class="Special"><-</span> copy curr-sandbox + curr-sandbox <span class="Special"><-</span> get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># snip sandbox out of its list</span> - next-sandbox:&:sandbox<span class="Special"> <- </span>get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> - *prev-sandbox<span class="Special"> <- </span>put *prev-sandbox, <span class="Constant">next-sandbox:offset</span>, next-sandbox + next-sandbox:&:sandbox <span class="Special"><-</span> get *curr-sandbox, <span class="Constant">next-sandbox:offset</span> + *prev-sandbox <span class="Special"><-</span> put *prev-sandbox, <span class="Constant">next-sandbox:offset</span>, next-sandbox <span class="Delimiter">}</span> <span class="Comment"># update sandbox count</span> - sandbox-count:num<span class="Special"> <- </span>get *env, <span class="Constant">number-of-sandboxes:offset</span> - sandbox-count<span class="Special"> <- </span>subtract sandbox-count, <span class="Constant">1</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">number-of-sandboxes:offset</span>, sandbox-count + sandbox-count:num <span class="Special"><-</span> get *env, <span class="Constant">number-of-sandboxes:offset</span> + sandbox-count <span class="Special"><-</span> subtract sandbox-count,<span class="Constant"> 1</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">number-of-sandboxes:offset</span>, sandbox-count <span class="Comment"># reset scroll if deleted sandbox was last</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> next-sandbox - render-from:num<span class="Special"> <- </span>get *env, <span class="Constant">render-from:offset</span> - reset-scroll?:bool<span class="Special"> <- </span>equal render-from, sandbox-count + render-from:num <span class="Special"><-</span> get *env, <span class="Constant">render-from:offset</span> + reset-scroll?:bool <span class="Special"><-</span> equal render-from, sandbox-count <span class="muControl">break-unless</span> reset-scroll? - *env<span class="Special"> <- </span>put *env, <span class="Constant">render-from:offset</span>, <span class="Constant">-1</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">render-from:offset</span>,<span class="Constant"> -1</span> <span class="Delimiter">}</span> ] @@ -185,7 +185,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize environment</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render <span class="Comment"># create 2 sandboxes and scroll to second</span> assume-console [ @@ -208,7 +208,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># delete the second sandbox</span> assume-console [ - left-click <span class="Constant">6</span>, <span class="Constant">99</span> + left-click<span class="Constant"> 6</span>,<span class="Constant"> 99</span> ] run [ event-loop screen, console, env @@ -230,7 +230,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize environment</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render <span class="Comment"># create 2 sandboxes and scroll to second</span> assume-console [ @@ -253,7 +253,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># delete the second sandbox</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">99</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 99</span> ] run [ event-loop screen, console, env @@ -275,7 +275,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize environment</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render <span class="Comment"># create 2 sandboxes and scroll to second</span> assume-console [ @@ -299,7 +299,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># delete the second sandbox</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">99</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 99</span> ] run [ event-loop screen, console, env @@ -322,7 +322,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize environment</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render <span class="Comment"># create 2 sandboxes</span> assume-console [ @@ -347,7 +347,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># delete the second sandbox, then try to scroll down twice</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">99</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 99</span> press page-down press page-down ] diff --git a/html/edit/008-sandbox-edit.mu.html b/html/edit/008-sandbox-edit.mu.html index 6b8599b5..43481161 100644 --- a/html/edit/008-sandbox-edit.mu.html +++ b/html/edit/008-sandbox-edit.mu.html @@ -39,11 +39,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># basic recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> reply 4</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run it</span> assume-console [ press F4 @@ -61,7 +61,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click at left edge of 'edit' button</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">55</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 55</span> ] run [ event-loop screen, console, env @@ -99,11 +99,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># basic recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> reply 4</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run it</span> assume-console [ press F4 @@ -121,7 +121,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click at right edge of 'edit' button (just before 'copy')</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">68</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 68</span> ] run [ event-loop screen, console, env @@ -157,13 +157,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-touch></span> [ <span class="Comment"># support 'edit' button</span> <span class="Delimiter">{</span> - edit?:bool<span class="Special"> <- </span>should-attempt-edit? click-row, click-column, env + edit?:bool <span class="Special"><-</span> should-attempt-edit? click-row, click-column, env <span class="muControl">break-unless</span> edit? - edit?, env<span class="Special"> <- </span>try-edit-sandbox click-row, env + edit?, env <span class="Special"><-</span> try-edit-sandbox click-row, env <span class="muControl">break-unless</span> edit? hide-screen screen - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <span class="Special"><-</span> render-sandbox-side screen, env, render + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env show-screen screen <span class="muControl">loop</span> <span class="Constant">+next-event</span> <span class="Delimiter">}</span> @@ -174,37 +174,37 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># are we below the sandbox editor?</span> - click-sandbox-area?:bool<span class="Special"> <- </span>click-on-sandbox-area? click-row, click-column, env + click-sandbox-area?:bool <span class="Special"><-</span> click-on-sandbox-area? click-row, click-column, env <span class="muControl">reply-unless</span> click-sandbox-area?, <span class="Constant">0/false</span> <span class="Comment"># narrower, is the click in the columns spanning the 'edit' button?</span> - first-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> + first-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> assert first-sandbox, <span class="Constant">[!!]</span> - sandbox-left-margin:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">left:offset</span> - sandbox-right-margin:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">right:offset</span> - edit-button-left:num, edit-button-right:num, _<span class="Special"> <- </span>sandbox-menu-columns sandbox-left-margin, sandbox-right-margin - edit-button-vertical-area?:bool<span class="Special"> <- </span>within-range? click-column, edit-button-left, edit-button-right + sandbox-left-margin:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">left:offset</span> + sandbox-right-margin:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">right:offset</span> + edit-button-left:num, edit-button-right:num, _ <span class="Special"><-</span> sandbox-menu-columns sandbox-left-margin, sandbox-right-margin + edit-button-vertical-area?:bool <span class="Special"><-</span> within-range? click-column, edit-button-left, edit-button-right <span class="muControl">reply-unless</span> edit-button-vertical-area?, <span class="Constant">0/false</span> <span class="Comment"># finally, is sandbox editor empty?</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - result<span class="Special"> <- </span>empty-editor? current-sandbox + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + result <span class="Special"><-</span> empty-editor? current-sandbox ] <span class="muRecipe">def</span> try-edit-sandbox click-row:num, env:&:environment<span class="muRecipe"> -> </span>clicked-on-edit-button?:bool, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># identify the sandbox to edit, if the click was actually on the 'edit' button</span> - sandbox:&:sandbox<span class="Special"> <- </span>find-sandbox env, click-row + sandbox:&:sandbox <span class="Special"><-</span> find-sandbox env, click-row <span class="muControl">return-unless</span> sandbox, <span class="Constant">0/false</span> - clicked-on-edit-button?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + clicked-on-edit-button? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="Comment"># 'edit' button = 'copy' button + 'delete' button</span> - text:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">data:offset</span> - current-sandbox:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">current-sandbox:offset</span> - current-sandbox<span class="Special"> <- </span>insert-text current-sandbox, text - env<span class="Special"> <- </span>delete-sandbox env, sandbox + text:text <span class="Special"><-</span> get *sandbox, <span class="Constant">data:offset</span> + current-sandbox:&:editor <span class="Special"><-</span> get *env, <span class="Constant">current-sandbox:offset</span> + current-sandbox <span class="Special"><-</span> insert-text current-sandbox, text + env <span class="Special"><-</span> delete-sandbox env, sandbox <span class="Comment"># reset scroll</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">render-from:offset</span>, <span class="Constant">-1</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">render-from:offset</span>,<span class="Constant"> -1</span> <span class="Comment"># position cursor in sandbox editor</span> - *env<span class="Special"> <- </span>put *env, <span class="Constant">sandbox-in-focus?:offset</span>, <span class="Constant">1/true</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">sandbox-in-focus?:offset</span>, <span class="Constant">1/true</span> ] <span class="muScenario">scenario</span> sandbox-with-print-can-be-edited [ @@ -213,7 +213,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen <span class="Constant">100/width</span>, <span class="Constant">20/height</span> <span class="Comment"># left editor is empty</span> <span class="Comment"># right editor contains an instruction</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[print-integer screen, 4]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[print-integer screen, 4]</span> <span class="Comment"># run the sandbox</span> assume-console [ press F4 @@ -236,7 +236,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># edit the sandbox</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">65</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 65</span> ] run [ event-loop screen, console, env @@ -255,7 +255,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize environment</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render <span class="Comment"># create 2 sandboxes and scroll to second</span> assume-console [ @@ -279,7 +279,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># edit the second sandbox</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">55</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 55</span> ] run [ event-loop screen, console, env @@ -302,7 +302,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># initialize environment</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> render-all screen, env, render <span class="Comment"># create 2 sandboxes</span> assume-console [ @@ -327,7 +327,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># edit the second sandbox, then resave</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">60</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 60</span> press F4 ] run [ diff --git a/html/edit/009-sandbox-test.mu.html b/html/edit/009-sandbox-test.mu.html index 1c350a57..30c731ea 100644 --- a/html/edit/009-sandbox-test.mu.html +++ b/html/edit/009-sandbox-test.mu.html @@ -40,11 +40,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># basic recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> reply 4</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes:text, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes:text, <span class="Constant">[foo]</span> <span class="Comment"># run it</span> assume-console [ press F4 @@ -62,7 +62,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click on the '4' in the result</span> assume-console [ - left-click <span class="Constant">5</span>, <span class="Constant">51</span> + left-click<span class="Constant"> 5</span>,<span class="Constant"> 51</span> ] run [ event-loop screen, console, env @@ -80,7 +80,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># cursor should remain unmoved</span> run [ - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] screen-should-contain [ @@ -98,7 +98,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># now change the result</span> <span class="Comment"># then rerun</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">11</span> <span class="Comment"># cursor to end of line</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 11</span> <span class="Comment"># cursor to end of line</span> press backspace type <span class="Constant">[3]</span> press F4 @@ -128,19 +128,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># include expected response when saving or restoring a sandbox</span> <span class="muRecipe">before</span> <span class="Constant"><end-save-sandbox></span> [ <span class="Delimiter">{</span> - expected-response:text<span class="Special"> <- </span>get *curr, <span class="Constant">expected-response:offset</span> + expected-response:text <span class="Special"><-</span> get *curr, <span class="Constant">expected-response:offset</span> <span class="muControl">break-unless</span> expected-response - filename<span class="Special"> <- </span>append filename, <span class="Constant">[.out]</span> + filename <span class="Special"><-</span> append filename, <span class="Constant">[.out]</span> save filename, expected-response <span class="Delimiter">}</span> ] <span class="muRecipe">before</span> <span class="Constant"><end-restore-sandbox></span> [ <span class="Delimiter">{</span> - filename<span class="Special"> <- </span>append filename, <span class="Constant">[.out]</span> - contents<span class="Special"> <- </span>restore filename + filename <span class="Special"><-</span> append filename, <span class="Constant">[.out]</span> + contents <span class="Special"><-</span> restore filename <span class="muControl">break-unless</span> contents - *curr<span class="Special"> <- </span>put *curr, <span class="Constant">expected-response:offset</span>, contents + *curr <span class="Special"><-</span> put *curr, <span class="Constant">expected-response:offset</span>, contents <span class="Delimiter">}</span> ] @@ -148,25 +148,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><global-touch></span> [ <span class="Comment"># check if it's inside the output of any sandbox</span> <span class="Delimiter">{</span> - sandbox-left-margin:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">left:offset</span> - click-column:num<span class="Special"> <- </span>get t, <span class="Constant">column:offset</span> - on-sandbox-side?:bool<span class="Special"> <- </span>greater-or-equal click-column, sandbox-left-margin + sandbox-left-margin:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">left:offset</span> + click-column:num <span class="Special"><-</span> get t, <span class="Constant">column:offset</span> + on-sandbox-side?:bool <span class="Special"><-</span> greater-or-equal click-column, sandbox-left-margin <span class="muControl">break-unless</span> on-sandbox-side? - first-sandbox:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> + first-sandbox:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> <span class="muControl">break-unless</span> first-sandbox - first-sandbox-begins:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">starting-row-on-screen:offset</span> - click-row:num<span class="Special"> <- </span>get t, <span class="Constant">row:offset</span> - below-sandbox-editor?:bool<span class="Special"> <- </span>greater-or-equal click-row, first-sandbox-begins + first-sandbox-begins:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">starting-row-on-screen:offset</span> + click-row:num <span class="Special"><-</span> get t, <span class="Constant">row:offset</span> + below-sandbox-editor?:bool <span class="Special"><-</span> greater-or-equal click-row, first-sandbox-begins <span class="muControl">break-unless</span> below-sandbox-editor? <span class="Comment"># identify the sandbox whose output is being clicked on</span> - sandbox:&:sandbox<span class="Special"> <- </span>find-click-in-sandbox-output env, click-row + sandbox:&:sandbox <span class="Special"><-</span> find-click-in-sandbox-output env, click-row <span class="muControl">break-unless</span> sandbox <span class="Comment"># toggle its expected-response, and save session</span> - sandbox<span class="Special"> <- </span>toggle-expected-response sandbox + sandbox <span class="Special"><-</span> toggle-expected-response sandbox save-sandboxes env hide-screen screen - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <span class="Special"><-</span> render-sandbox-side screen, env, render + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env <span class="Comment"># no change in cursor</span> show-screen screen <span class="muControl">loop</span> <span class="Constant">+next-event</span> @@ -177,24 +177,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># assert click-row >= sandbox.starting-row-on-screen</span> - sandbox:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> - start:num<span class="Special"> <- </span>get *sandbox, <span class="Constant">starting-row-on-screen:offset</span> - clicked-on-sandboxes?:bool<span class="Special"> <- </span>greater-or-equal click-row, start + sandbox:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> + start:num <span class="Special"><-</span> get *sandbox, <span class="Constant">starting-row-on-screen:offset</span> + clicked-on-sandboxes?:bool <span class="Special"><-</span> greater-or-equal click-row, start assert clicked-on-sandboxes?, <span class="Constant">[extract-sandbox called on click to sandbox editor]</span> <span class="Comment"># while click-row < sandbox.next-sandbox.starting-row-on-screen</span> <span class="Delimiter">{</span> - next-sandbox:&:sandbox<span class="Special"> <- </span>get *sandbox, <span class="Constant">next-sandbox:offset</span> + next-sandbox:&:sandbox <span class="Special"><-</span> get *sandbox, <span class="Constant">next-sandbox:offset</span> <span class="muControl">break-unless</span> next-sandbox - next-start:num<span class="Special"> <- </span>get *next-sandbox, <span class="Constant">starting-row-on-screen:offset</span> - found?:bool<span class="Special"> <- </span>lesser-than click-row, next-start + next-start:num <span class="Special"><-</span> get *next-sandbox, <span class="Constant">starting-row-on-screen:offset</span> + found?:bool <span class="Special"><-</span> lesser-than click-row, next-start <span class="muControl">break-if</span> found? - sandbox<span class="Special"> <- </span>copy next-sandbox + sandbox <span class="Special"><-</span> copy next-sandbox <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># return sandbox if click is in its output region</span> - response-starting-row:num<span class="Special"> <- </span>get *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span> + response-starting-row:num <span class="Special"><-</span> get *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span> <span class="muControl">return-unless</span> response-starting-row, <span class="Constant">0/no-click-in-sandbox-output</span> - click-in-response?:bool<span class="Special"> <- </span>greater-or-equal click-row, response-starting-row + click-in-response?:bool <span class="Special"><-</span> greater-or-equal click-row, response-starting-row <span class="muControl">return-unless</span> click-in-response?, <span class="Constant">0/no-click-in-sandbox-output</span> <span class="muControl">return</span> sandbox ] @@ -202,17 +202,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> toggle-expected-response sandbox:&:sandbox<span class="muRecipe"> -> </span>sandbox:&:sandbox [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - expected-response:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">expected-response:offset</span> + expected-response:text <span class="Special"><-</span> get *sandbox, <span class="Constant">expected-response:offset</span> <span class="Delimiter">{</span> <span class="Comment"># if expected-response is set, reset</span> <span class="muControl">break-unless</span> expected-response - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">expected-response:offset</span>, <span class="Constant">0</span> + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">expected-response:offset</span>,<span class="Constant"> 0</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># if not, set expected response to the current response</span> <span class="muControl">break-if</span> expected-response - response:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">response:offset</span> - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">expected-response:offset</span>, response + response:text <span class="Special"><-</span> get *sandbox, <span class="Constant">response:offset</span> + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">expected-response:offset</span>, response <span class="Delimiter">}</span> ] @@ -220,24 +220,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><render-sandbox-response></span> [ <span class="Delimiter">{</span> <span class="muControl">break-unless</span> sandbox-response - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span>, row - expected-response:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">expected-response:offset</span> + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span>, row + expected-response:text <span class="Special"><-</span> get *sandbox, <span class="Constant">expected-response:offset</span> <span class="muControl">break-unless</span> expected-response <span class="Comment"># fall-through to print in grey</span> - response-is-expected?:bool<span class="Special"> <- </span>equal expected-response, sandbox-response + response-is-expected?:bool <span class="Special"><-</span> equal expected-response, sandbox-response <span class="Delimiter">{</span> <span class="muControl">break-if</span> response-is-expected?:bool - row, screen<span class="Special"> <- </span>render-text screen, sandbox-response, left, right, <span class="Constant">1/red</span>, row + row, screen <span class="Special"><-</span> render-text screen, sandbox-response, left, right, <span class="Constant">1/red</span>, row <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> response-is-expected?:bool - row, screen<span class="Special"> <- </span>render-text screen, sandbox-response, left, right, <span class="Constant">2/green</span>, row + row, screen <span class="Special"><-</span> render-text screen, sandbox-response, left, right, <span class="Constant">2/green</span>, row <span class="Delimiter">}</span> <span class="muControl">jump</span> <span class="Constant">+render-sandbox-end</span> <span class="Delimiter">}</span> ] <span class="muRecipe">before</span> <span class="Constant"><end-render-sandbox-reset-hidden></span> [ - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span>, <span class="Constant">0</span> + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span>,<span class="Constant"> 0</span> ] </pre> </body> diff --git a/html/edit/010-sandbox-trace.mu.html b/html/edit/010-sandbox-trace.mu.html index ece61dee..66943462 100644 --- a/html/edit/010-sandbox-trace.mu.html +++ b/html/edit/010-sandbox-trace.mu.html @@ -40,11 +40,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># basic recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> stash [abc]</span> ]] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run it</span> assume-console [ press F4 @@ -61,11 +61,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click on the code in the sandbox</span> assume-console [ - left-click <span class="Constant">4</span>, <span class="Constant">51</span> + left-click<span class="Constant"> 4</span>,<span class="Constant"> 51</span> ] run [ event-loop screen, console, env - cursor:char<span class="Special"> <- </span>copy <span class="Constant">9251/␣</span> + cursor:char <span class="Special"><-</span> copy <span class="Constant">9251/␣</span> print screen, cursor ] <span class="Comment"># trace now printed and cursor shouldn't have budged</span> @@ -87,7 +87,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click again on the same region</span> assume-console [ - left-click <span class="Constant">4</span>, <span class="Constant">55</span> + left-click<span class="Constant"> 4</span>,<span class="Constant"> 55</span> ] run [ event-loop screen, console, env @@ -110,12 +110,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># basic recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> stash [abc]</span> - <span class="muControl">reply</span> <span class="Constant">4</span> + <span class="muControl">reply</span><span class="Constant"> 4</span> ]] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run it</span> assume-console [ press F4 @@ -133,7 +133,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click on the code in the sandbox</span> assume-console [ - left-click <span class="Constant">4</span>, <span class="Constant">51</span> + left-click<span class="Constant"> 4</span>,<span class="Constant"> 51</span> ] run [ event-loop screen, console, env @@ -157,11 +157,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[stash 123456789]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[stash 123456789]</span> <span class="Comment"># create and expand the trace</span> assume-console [ press F4 - left-click <span class="Constant">4</span>, <span class="Constant">51</span> + left-click<span class="Constant"> 4</span>,<span class="Constant"> 51</span> ] event-loop screen, console, env screen-should-contain [ @@ -174,7 +174,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># click on the stash under the edit-button region (or any of the other buttons, really)</span> assume-console [ - left-click <span class="Constant">5</span>, <span class="Constant">57</span> + left-click<span class="Constant"> 5</span>,<span class="Constant"> 57</span> ] run [ event-loop screen, console, env @@ -199,37 +199,37 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def!</span> update-sandbox sandbox:&:sandbox, env:&:environment, idx:num<span class="muRecipe"> -> </span>sandbox:&:sandbox, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - data:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">data:offset</span> - response:text, _, fake-screen:&:screen, trace:text<span class="Special"> <- </span>run-sandboxed data - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">response:offset</span>, response - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">screen:offset</span>, fake-screen - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">trace:offset</span>, trace + data:text <span class="Special"><-</span> get *sandbox, <span class="Constant">data:offset</span> + response:text, _, fake-screen:&:screen, trace:text <span class="Special"><-</span> run-sandboxed data + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">response:offset</span>, response + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">screen:offset</span>, fake-screen + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">trace:offset</span>, trace ] <span class="Comment"># clicks on sandbox code toggle its display-trace? flag</span> <span class="muRecipe">after</span> <span class="Constant"><global-touch></span> [ <span class="Comment"># check if it's inside the code of any sandbox</span> <span class="Delimiter">{</span> - sandbox-left-margin:num<span class="Special"> <- </span>get *current-sandbox, <span class="Constant">left:offset</span> - click-column:num<span class="Special"> <- </span>get t, <span class="Constant">column:offset</span> - on-sandbox-side?:bool<span class="Special"> <- </span>greater-or-equal click-column, sandbox-left-margin + sandbox-left-margin:num <span class="Special"><-</span> get *current-sandbox, <span class="Constant">left:offset</span> + click-column:num <span class="Special"><-</span> get t, <span class="Constant">column:offset</span> + on-sandbox-side?:bool <span class="Special"><-</span> greater-or-equal click-column, sandbox-left-margin <span class="muControl">break-unless</span> on-sandbox-side? - first-sandbox:&:sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> + first-sandbox:&:sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> <span class="muControl">break-unless</span> first-sandbox - first-sandbox-begins:num<span class="Special"> <- </span>get *first-sandbox, <span class="Constant">starting-row-on-screen:offset</span> - click-row:num<span class="Special"> <- </span>get t, <span class="Constant">row:offset</span> - below-sandbox-editor?:bool<span class="Special"> <- </span>greater-or-equal click-row, first-sandbox-begins + first-sandbox-begins:num <span class="Special"><-</span> get *first-sandbox, <span class="Constant">starting-row-on-screen:offset</span> + click-row:num <span class="Special"><-</span> get t, <span class="Constant">row:offset</span> + below-sandbox-editor?:bool <span class="Special"><-</span> greater-or-equal click-row, first-sandbox-begins <span class="muControl">break-unless</span> below-sandbox-editor? <span class="Comment"># identify the sandbox whose code is being clicked on</span> - sandbox:&:sandbox<span class="Special"> <- </span>find-click-in-sandbox-code env, click-row + sandbox:&:sandbox <span class="Special"><-</span> find-click-in-sandbox-code env, click-row <span class="muControl">break-unless</span> sandbox <span class="Comment"># toggle its display-trace? property</span> - x:bool<span class="Special"> <- </span>get *sandbox, <span class="Constant">display-trace?:offset</span> - x<span class="Special"> <- </span>not x - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">display-trace?:offset</span>, x + x:bool <span class="Special"><-</span> get *sandbox, <span class="Constant">display-trace?:offset</span> + x <span class="Special"><-</span> not x + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">display-trace?:offset</span>, x hide-screen screen - screen<span class="Special"> <- </span>render-sandbox-side screen, env, render - screen<span class="Special"> <- </span>update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <span class="Special"><-</span> render-sandbox-side screen, env, render + screen <span class="Special"><-</span> update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env <span class="Comment"># no change in cursor</span> show-screen screen <span class="muControl">loop</span> <span class="Constant">+next-event</span> @@ -240,26 +240,26 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># assert click-row >= sandbox.starting-row-on-screen</span> - sandbox<span class="Special"> <- </span>get *env, <span class="Constant">sandbox:offset</span> - start:num<span class="Special"> <- </span>get *sandbox, <span class="Constant">starting-row-on-screen:offset</span> - clicked-on-sandboxes?:bool<span class="Special"> <- </span>greater-or-equal click-row, start + sandbox <span class="Special"><-</span> get *env, <span class="Constant">sandbox:offset</span> + start:num <span class="Special"><-</span> get *sandbox, <span class="Constant">starting-row-on-screen:offset</span> + clicked-on-sandboxes?:bool <span class="Special"><-</span> greater-or-equal click-row, start assert clicked-on-sandboxes?, <span class="Constant">[extract-sandbox called on click to sandbox editor]</span> <span class="Comment"># while click-row < sandbox.next-sandbox.starting-row-on-screen</span> <span class="Delimiter">{</span> - next-sandbox:&:sandbox<span class="Special"> <- </span>get *sandbox, <span class="Constant">next-sandbox:offset</span> + next-sandbox:&:sandbox <span class="Special"><-</span> get *sandbox, <span class="Constant">next-sandbox:offset</span> <span class="muControl">break-unless</span> next-sandbox - next-start:num<span class="Special"> <- </span>get *next-sandbox, <span class="Constant">starting-row-on-screen:offset</span> - found?:bool<span class="Special"> <- </span>lesser-than click-row, next-start + next-start:num <span class="Special"><-</span> get *next-sandbox, <span class="Constant">starting-row-on-screen:offset</span> + found?:bool <span class="Special"><-</span> lesser-than click-row, next-start <span class="muControl">break-if</span> found? - sandbox<span class="Special"> <- </span>copy next-sandbox + sandbox <span class="Special"><-</span> copy next-sandbox <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># return sandbox if click is in its code region</span> - code-ending-row:num<span class="Special"> <- </span>get *sandbox, <span class="Constant">code-ending-row-on-screen:offset</span> - click-above-response?:bool<span class="Special"> <- </span>lesser-than click-row, code-ending-row - start:num<span class="Special"> <- </span>get *sandbox, <span class="Constant">starting-row-on-screen:offset</span> - click-below-menu?:bool<span class="Special"> <- </span>greater-than click-row, start - click-on-sandbox-code?:bool<span class="Special"> <- </span>and click-above-response?, click-below-menu? + code-ending-row:num <span class="Special"><-</span> get *sandbox, <span class="Constant">code-ending-row-on-screen:offset</span> + click-above-response?:bool <span class="Special"><-</span> lesser-than click-row, code-ending-row + start:num <span class="Special"><-</span> get *sandbox, <span class="Constant">starting-row-on-screen:offset</span> + click-below-menu?:bool <span class="Special"><-</span> greater-than click-row, start + click-on-sandbox-code?:bool <span class="Special"><-</span> and click-above-response?, click-below-menu? <span class="Delimiter">{</span> <span class="muControl">break-if</span> click-on-sandbox-code? <span class="muControl">return</span> <span class="Constant">0/no-click-in-sandbox-output</span> @@ -270,11 +270,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># when rendering a sandbox, dump its trace before response/warning if display-trace? property is set</span> <span class="muRecipe">after</span> <span class="Constant"><render-sandbox-results></span> [ <span class="Delimiter">{</span> - display-trace?:bool<span class="Special"> <- </span>get *sandbox, <span class="Constant">display-trace?:offset</span> + display-trace?:bool <span class="Special"><-</span> get *sandbox, <span class="Constant">display-trace?:offset</span> <span class="muControl">break-unless</span> display-trace? - sandbox-trace:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">trace:offset</span> + sandbox-trace:text <span class="Special"><-</span> get *sandbox, <span class="Constant">trace:offset</span> <span class="muControl">break-unless</span> sandbox-trace <span class="Comment"># nothing to print; move on</span> - row, screen<span class="Special"> <- </span>render-text screen, sandbox-trace, left, right, <span class="Constant">245/grey</span>, row + row, screen <span class="Special"><-</span> render-text screen, sandbox-trace, left, right, <span class="Constant">245/grey</span>, row <span class="Delimiter">}</span> <span class="Constant"> <render-sandbox-trace-done></span> ] diff --git a/html/edit/011-errors.mu.html b/html/edit/011-errors.mu.html index 146b2b15..2bdf811a 100644 --- a/html/edit/011-errors.mu.html +++ b/html/edit/011-errors.mu.html @@ -43,24 +43,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def!</span> update-recipes env:&:environment, screen:&:screen<span class="muRecipe"> -> </span>errors-found?:bool, env:&:environment, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - recipes:&:editor<span class="Special"> <- </span>get *env, <span class="Constant">recipes:offset</span> - in:text<span class="Special"> <- </span>editor-contents recipes + recipes:&:editor <span class="Special"><-</span> get *env, <span class="Constant">recipes:offset</span> + in:text <span class="Special"><-</span> editor-contents recipes save <span class="Constant">[recipes.mu]</span>, in - recipe-errors:text<span class="Special"> <- </span>reload in - *env<span class="Special"> <- </span>put *env, <span class="Constant">recipe-errors:offset</span>, recipe-errors + recipe-errors:text <span class="Special"><-</span> reload in + *env <span class="Special"><-</span> put *env, <span class="Constant">recipe-errors:offset</span>, recipe-errors <span class="Comment"># if recipe editor has errors, stop</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> recipe-errors update-status screen, <span class="Constant">[errors found ]</span>, <span class="Constant">1/red</span> - errors-found?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + errors-found? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="muControl">return</span> <span class="Delimiter">}</span> - errors-found?<span class="Special"> <- </span>copy <span class="Constant">0/false</span> + errors-found? <span class="Special"><-</span> copy <span class="Constant">0/false</span> ] <span class="muRecipe">before</span> <span class="Constant"><render-components-end></span> [ - trace <span class="Constant">11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render status]</span> - recipe-errors:text<span class="Special"> <- </span>get *env, <span class="Constant">recipe-errors:offset</span> + trace<span class="Constant"> 11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render status]</span> + recipe-errors:text <span class="Special"><-</span> get *env, <span class="Constant">recipe-errors:offset</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> recipe-errors update-status screen, <span class="Constant">[errors found ]</span>, <span class="Constant">1/red</span> @@ -69,9 +69,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">before</span> <span class="Constant"><render-recipe-components-end></span> [ <span class="Delimiter">{</span> - recipe-errors:text<span class="Special"> <- </span>get *env, <span class="Constant">recipe-errors:offset</span> + recipe-errors:text <span class="Special"><-</span> get *env, <span class="Constant">recipe-errors:offset</span> <span class="muControl">break-unless</span> recipe-errors - row, screen<span class="Special"> <- </span>render-text screen, recipe-errors, left, right, <span class="Constant">1/red</span>, row + row, screen <span class="Special"><-</span> render-text screen, recipe-errors, left, right, <span class="Constant">1/red</span>, row <span class="Delimiter">}</span> ] @@ -80,30 +80,30 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><programming-environment-initialization></span> [ - *result<span class="Special"> <- </span>put *result, <span class="Constant">error-index:offset</span>, <span class="Constant">-1</span> + *result <span class="Special"><-</span> put *result, <span class="Constant">error-index:offset</span>,<span class="Constant"> -1</span> ] <span class="muRecipe">after</span> <span class="Constant"><run-sandboxes-begin></span> [ - *env<span class="Special"> <- </span>put *env, <span class="Constant">error-index:offset</span>, <span class="Constant">-1</span> + *env <span class="Special"><-</span> put *env, <span class="Constant">error-index:offset</span>,<span class="Constant"> -1</span> ] <span class="muRecipe">before</span> <span class="Constant"><run-sandboxes-end></span> [ <span class="Delimiter">{</span> - error-index:num<span class="Special"> <- </span>get *env, <span class="Constant">error-index:offset</span> - sandboxes-completed-successfully?:bool<span class="Special"> <- </span>equal error-index, <span class="Constant">-1</span> + error-index:num <span class="Special"><-</span> get *env, <span class="Constant">error-index:offset</span> + sandboxes-completed-successfully?:bool <span class="Special"><-</span> equal error-index,<span class="Constant"> -1</span> <span class="muControl">break-if</span> sandboxes-completed-successfully? - errors-found?<span class="Special"> <- </span>copy <span class="Constant">1/true</span> + errors-found? <span class="Special"><-</span> copy <span class="Constant">1/true</span> <span class="Delimiter">}</span> ] <span class="muRecipe">before</span> <span class="Constant"><render-components-end></span> [ <span class="Delimiter">{</span> <span class="muControl">break-if</span> recipe-errors - error-index:num<span class="Special"> <- </span>get *env, <span class="Constant">error-index:offset</span> - sandboxes-completed-successfully?:bool<span class="Special"> <- </span>equal error-index, <span class="Constant">-1</span> + error-index:num <span class="Special"><-</span> get *env, <span class="Constant">error-index:offset</span> + sandboxes-completed-successfully?:bool <span class="Special"><-</span> equal error-index,<span class="Constant"> -1</span> <span class="muControl">break-if</span> sandboxes-completed-successfully? - error-index-text:text<span class="Special"> <- </span>to-text error-index - status:text<span class="Special"> <- </span>interpolate <span class="Constant">[errors found (_) ]</span>, error-index-text + error-index-text:text <span class="Special"><-</span> to-text error-index + status:text <span class="Special"><-</span> interpolate <span class="Constant">[errors found (_) ]</span>, error-index-text update-status screen, status, <span class="Constant">1/red</span> <span class="Delimiter">}</span> ] @@ -115,35 +115,35 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def!</span> update-sandbox sandbox:&:sandbox, env:&:environment, idx:num<span class="muRecipe"> -> </span>sandbox:&:sandbox, env:&:environment [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - data:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">data:offset</span> - response:text, errors:text, fake-screen:&:screen, trace:text, completed?:bool<span class="Special"> <- </span>run-sandboxed data - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">response:offset</span>, response - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">errors:offset</span>, errors - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">screen:offset</span>, fake-screen - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">trace:offset</span>, trace + data:text <span class="Special"><-</span> get *sandbox, <span class="Constant">data:offset</span> + response:text, errors:text, fake-screen:&:screen, trace:text, completed?:bool <span class="Special"><-</span> run-sandboxed data + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">response:offset</span>, response + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">errors:offset</span>, errors + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">screen:offset</span>, fake-screen + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">trace:offset</span>, trace <span class="Delimiter">{</span> <span class="muControl">break-if</span> errors <span class="muControl">break-if</span> completed?:bool - errors<span class="Special"> <- </span>new <span class="Constant">[took too long!</span> + errors <span class="Special"><-</span> new <span class="Constant">[took too long!</span> <span class="Constant">]</span> - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">errors:offset</span>, errors + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">errors:offset</span>, errors <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> errors - error-index:num<span class="Special"> <- </span>get *env, <span class="Constant">error-index:offset</span> - error-not-set?:bool<span class="Special"> <- </span>equal error-index, <span class="Constant">-1</span> + error-index:num <span class="Special"><-</span> get *env, <span class="Constant">error-index:offset</span> + error-not-set?:bool <span class="Special"><-</span> equal error-index,<span class="Constant"> -1</span> <span class="muControl">break-unless</span> error-not-set? - *env<span class="Special"> <- </span>put *env, <span class="Constant">error-index:offset</span>, idx + *env <span class="Special"><-</span> put *env, <span class="Constant">error-index:offset</span>, idx <span class="Delimiter">}</span> ] <span class="Comment"># make sure we render any trace</span> <span class="muRecipe">after</span> <span class="Constant"><render-sandbox-trace-done></span> [ <span class="Delimiter">{</span> - sandbox-errors:text<span class="Special"> <- </span>get *sandbox, <span class="Constant">errors:offset</span> + sandbox-errors:text <span class="Special"><-</span> get *sandbox, <span class="Constant">errors:offset</span> <span class="muControl">break-unless</span> sandbox-errors - *sandbox<span class="Special"> <- </span>put *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span>, <span class="Constant">0</span> <span class="Comment"># no response</span> - row, screen<span class="Special"> <- </span>render-text screen, sandbox-errors, left, right, <span class="Constant">1/red</span>, row + *sandbox <span class="Special"><-</span> put *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span>,<span class="Constant"> 0</span> <span class="Comment"># no response</span> + row, screen <span class="Special"><-</span> render-text screen, sandbox-errors, left, right, <span class="Constant">1/red</span>, row <span class="Comment"># don't try to print anything more for this sandbox</span> <span class="muControl">jump</span> <span class="Constant">+render-sandbox-end</span> <span class="Delimiter">}</span> @@ -153,11 +153,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> get 123:num, foo:offset</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> assume-console [ press F4 ] @@ -193,9 +193,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">80</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 80</span> <span class="Comment"># create invalid sandbox 1</span> type <span class="Constant">[get foo, x:offset]</span> press F4 @@ -216,9 +216,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">80</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 80</span> <span class="Comment"># create invalid sandbox 2</span> type <span class="Constant">[get foo, x:offset]</span> press F4 @@ -242,7 +242,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[get foo, x:offset]</span> <span class="Comment"># invalid</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[get foo, x:offset]</span> <span class="Comment"># invalid</span> assume-console [ press F4 <span class="Comment"># generate error</span> ] @@ -250,7 +250,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color event-loop screen, console, env ] assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">58</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 58</span> press ctrl-k type <span class="Constant">[add 2, 2]</span> <span class="Comment"># valid code</span> press F4 <span class="Comment"># update sandbox</span> @@ -276,13 +276,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Comment"># define a shape-shifting recipe with an error</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[recipe foo x:_elem -> z:_elem [</span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[recipe foo x:_elem -> z:_elem [</span> <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Constant">y:&:num <- copy 0</span> <span class="Constant">z <- add x, y</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo 2]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo 2]</span> assume-console [ press F4 ] @@ -324,12 +324,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Comment"># overload a well-known shape-shifting recipe</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[recipe length l:&:list:_elem -> n:num [</span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[recipe length l:&:list:_elem -> n:num [</span> <span class="Constant">]</span>] <span class="Comment"># call code that uses other variants of it, but not it itself</span> - sandbox:text<span class="Special"> <- </span>new <span class="Constant">[x:&:list:num <- copy 0</span> + sandbox:text <span class="Special"><-</span> new <span class="Constant">[x:&:list:num <- copy 0</span> <span class="Constant">to-text x]</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, sandbox + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, sandbox <span class="Comment"># run it once</span> assume-console [ press F4 @@ -384,11 +384,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> x <- copy 0</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> assume-console [ press F4 ] @@ -410,11 +410,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> <span class="Comment"># recipe is incomplete (unbalanced '[')</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo \\[</span> <span class="Constant"> x <- copy 0</span> <span class="Constant">]</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> assume-console [ press F4 ] @@ -437,13 +437,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> local-scope</span> <span class="Constant"> x:&:point <- new point:type</span> <span class="Constant"> get x:&:point, 1:offset</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> assume-console [ press F4 ] @@ -469,14 +469,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> local-scope</span> <span class="Constant"> x:num <- copy 0</span> <span class="Constant"> y:&:point <- new point:type</span> <span class="Constant"> get *y:&:point, x:num</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> assume-console [ press F4 ] @@ -504,12 +504,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> <span class="Comment"># try to run a file with an error</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[ </span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[ </span> <span class="Constant">recipe foo [</span> <span class="Constant"> local-scope</span> <span class="Constant"> x:num <- copy y:num</span> <span class="Constant">]</span>] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> assume-console [ press F4 ] @@ -550,8 +550,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># right editor contains an illegal instruction</span> - sandbox:text<span class="Special"> <- </span>new <span class="Constant">[get 1234:num, foo:offset]</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, sandbox + sandbox:text <span class="Special"><-</span> new <span class="Constant">[get 1234:num, foo:offset]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, sandbox <span class="Comment"># run the code in the editors</span> assume-console [ press F4 @@ -612,8 +612,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># right editor contains an illegal instruction</span> - sandbox:text<span class="Special"> <- </span>new <span class="Constant">[get 1234:num, foo:offset]</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, <span class="Constant">[]</span>, sandbox + sandbox:text <span class="Special"><-</span> new <span class="Constant">[get 1234:num, foo:offset]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, <span class="Constant">[]</span>, sandbox <span class="Comment"># run the code in the editors multiple times</span> assume-console [ press F4 @@ -642,13 +642,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">20/height</span> <span class="Comment"># left editor is empty</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[recipe foo [</span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[recipe foo [</span> <span class="Constant"> {</span> <span class="Constant"> loop</span> <span class="Constant"> }</span> <span class="Constant">]</span>] <span class="Comment"># right editor contains an instruction</span> - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span> <span class="Comment"># run the sandbox</span> assume-console [ press F4 @@ -673,15 +673,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until <span class="Constant">100/app</span> <span class="Comment"># trace too long</span> assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span> <span class="Comment"># generate a stash and a error</span> - recipes:text<span class="Special"> <- </span>new <span class="Constant">[recipe foo [</span> + recipes:text <span class="Special"><-</span> new <span class="Constant">[recipe foo [</span> <span class="Constant">local-scope</span> <span class="Constant">a:num <- next-ingredient</span> <span class="Constant">b:num <- next-ingredient</span> <span class="Constant">stash [dividing by]</span>, b -_, c:num<span class="Special"> <- </span>divide-with-remainder a, b +_, c:num <span class="Special"><-</span> divide-with-remainder a, b <span class="muControl">reply</span> b ]] - env:&:environment<span class="Special"> <- </span>new-programming-environment screen, recipes, <span class="Constant">[foo 4, 0]</span> + env:&:environment <span class="Special"><-</span> new-programming-environment screen, recipes, <span class="Constant">[foo 4, 0]</span> <span class="Comment"># run</span> assume-console [ press F4 @@ -701,7 +701,7 @@ _, c:num<span class="Special"> <- </span>divide-with-remainder a, b ] <span class="Comment"># click on the call in the sandbox</span> assume-console [ - left-click <span class="Constant">4</span>, <span class="Constant">55</span> + left-click<span class="Constant"> 4</span>,<span class="Constant"> 55</span> ] run [ event-loop screen, console, env diff --git a/html/edit/012-editor-undo.mu.html b/html/edit/012-editor-undo.mu.html index 0953fed1..56b85dbf 100644 --- a/html/edit/012-editor-undo.mu.html +++ b/html/edit/012-editor-undo.mu.html @@ -98,36 +98,36 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># ctrl-z - undo operation</span> <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - undo?:bool<span class="Special"> <- </span>equal c, <span class="Constant">26/ctrl-z</span> + undo?:bool <span class="Special"><-</span> equal c, <span class="Constant">26/ctrl-z</span> <span class="muControl">break-unless</span> undo? - undo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">undo:offset</span> + undo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">undo:offset</span> <span class="muControl">break-unless</span> undo - op:&:operation<span class="Special"> <- </span>first undo - undo<span class="Special"> <- </span>rest undo - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">undo:offset</span>, undo - redo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">redo:offset</span> - redo<span class="Special"> <- </span>push op, redo - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">redo:offset</span>, redo + op:&:operation <span class="Special"><-</span> first undo + undo <span class="Special"><-</span> rest undo + *editor <span class="Special"><-</span> put *editor, <span class="Constant">undo:offset</span>, undo + redo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">redo:offset</span> + redo <span class="Special"><-</span> push op, redo + *editor <span class="Special"><-</span> put *editor, <span class="Constant">redo:offset</span>, redo <span class="Constant"> <handle-undo></span> - <span class="muControl">return</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span> + <span class="muControl">return</span> screen/same-as-ingredient:0, editor/same-as-ingredient:1, <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] <span class="Comment"># ctrl-y - redo operation</span> <span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [ <span class="Delimiter">{</span> - redo?:bool<span class="Special"> <- </span>equal c, <span class="Constant">25/ctrl-y</span> + redo?:bool <span class="Special"><-</span> equal c, <span class="Constant">25/ctrl-y</span> <span class="muControl">break-unless</span> redo? - redo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">redo:offset</span> + redo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">redo:offset</span> <span class="muControl">break-unless</span> redo - op:&:operation<span class="Special"> <- </span>first redo - redo<span class="Special"> <- </span>rest redo - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">redo:offset</span>, redo - undo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">undo:offset</span> - undo<span class="Special"> <- </span>push op, undo - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">undo:offset</span>, undo + op:&:operation <span class="Special"><-</span> first redo + redo <span class="Special"><-</span> rest redo + *editor <span class="Special"><-</span> put *editor, <span class="Constant">redo:offset</span>, redo + undo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">undo:offset</span> + undo <span class="Special"><-</span> push op, undo + *editor <span class="Special"><-</span> put *editor, <span class="Constant">undo:offset</span>, undo <span class="Constant"> <handle-redo></span> - <span class="muControl">return</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span> + <span class="muControl">return</span> screen/same-as-ingredient:0, editor/same-as-ingredient:1, <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] @@ -137,7 +137,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor and type a character</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console [ type <span class="Constant">[0]</span> @@ -174,58 +174,58 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># save operation to undo</span> <span class="muRecipe">after</span> <span class="Constant"><insert-character-begin></span> [ - top-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - cursor-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> + top-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> ] <span class="muRecipe">before</span> <span class="Constant"><insert-character-end></span> [ - top-after:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - undo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">undo:offset</span> + top-after:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + undo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">undo:offset</span> <span class="Delimiter">{</span> <span class="Comment"># if previous operation was an insert, coalesce this operation with it</span> <span class="muControl">break-unless</span> undo - op:&:operation<span class="Special"> <- </span>first undo - typing:insert-operation, is-insert?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">typing:variant</span> + op:&:operation <span class="Special"><-</span> first undo + typing:insert-operation, is-insert?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">typing:variant</span> <span class="muControl">break-unless</span> is-insert? - previous-coalesce-tag:num<span class="Special"> <- </span>get typing, <span class="Constant">tag:offset</span> + previous-coalesce-tag:num <span class="Special"><-</span> get typing, <span class="Constant">tag:offset</span> <span class="muControl">break-unless</span> previous-coalesce-tag - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - insert-until:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - typing<span class="Special"> <- </span>put typing, <span class="Constant">insert-until:offset</span>, insert-until - typing<span class="Special"> <- </span>put typing, <span class="Constant">after-row:offset</span>, cursor-row - typing<span class="Special"> <- </span>put typing, <span class="Constant">after-column:offset</span>, cursor-column - typing<span class="Special"> <- </span>put typing, <span class="Constant">after-top-of-screen:offset</span>, top-after - *op<span class="Special"> <- </span>merge <span class="Constant">0/insert-operation</span>, typing + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + insert-until:&:duplex-list:char <span class="Special"><-</span> next before-cursor + typing <span class="Special"><-</span> put typing, <span class="Constant">insert-until:offset</span>, insert-until + typing <span class="Special"><-</span> put typing, <span class="Constant">after-row:offset</span>, cursor-row + typing <span class="Special"><-</span> put typing, <span class="Constant">after-column:offset</span>, cursor-column + typing <span class="Special"><-</span> put typing, <span class="Constant">after-top-of-screen:offset</span>, top-after + *op <span class="Special"><-</span> merge <span class="Constant">0/insert-operation</span>, typing <span class="muControl">break</span> <span class="Constant">+done-adding-insert-operation</span> <span class="Delimiter">}</span> <span class="Comment"># if not, create a new operation</span> - insert-from:&:duplex-list:char<span class="Special"> <- </span>next cursor-before - insert-to:&:duplex-list:char<span class="Special"> <- </span>next insert-from - op:&:operation<span class="Special"> <- </span>new <span class="Constant">operation:type</span> - *op<span class="Special"> <- </span>merge <span class="Constant">0/insert-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, <span class="Constant">1/coalesce</span> - editor<span class="Special"> <- </span>add-operation editor, op + insert-from:&:duplex-list:char <span class="Special"><-</span> next cursor-before + insert-to:&:duplex-list:char <span class="Special"><-</span> next insert-from + op:&:operation <span class="Special"><-</span> new <span class="Constant">operation:type</span> + *op <span class="Special"><-</span> merge <span class="Constant">0/insert-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, <span class="Constant">1/coalesce</span> + editor <span class="Special"><-</span> add-operation editor, op <span class="Constant"> +done-adding-insert-operation</span> ] <span class="Comment"># enter operations never coalesce with typing before or after</span> <span class="muRecipe">after</span> <span class="Constant"><insert-enter-begin></span> [ - cursor-row-before:num<span class="Special"> <- </span>copy cursor-row - cursor-column-before:num<span class="Special"> <- </span>copy cursor-column - top-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - cursor-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> + cursor-row-before:num <span class="Special"><-</span> copy cursor-row + cursor-column-before:num <span class="Special"><-</span> copy cursor-column + top-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> ] <span class="muRecipe">before</span> <span class="Constant"><insert-enter-end></span> [ - top-after:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> + top-after:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> <span class="Comment"># never coalesce</span> - insert-from:&:duplex-list:char<span class="Special"> <- </span>next cursor-before - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - insert-to:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - op:&:operation<span class="Special"> <- </span>new <span class="Constant">operation:type</span> - *op<span class="Special"> <- </span>merge <span class="Constant">0/insert-operation</span>, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, <span class="Constant">0/never-coalesce</span> - editor<span class="Special"> <- </span>add-operation editor, op + insert-from:&:duplex-list:char <span class="Special"><-</span> next cursor-before + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + insert-to:&:duplex-list:char <span class="Special"><-</span> next before-cursor + op:&:operation <span class="Special"><-</span> new <span class="Constant">operation:type</span> + *op <span class="Special"><-</span> merge <span class="Constant">0/insert-operation</span>, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, <span class="Constant">0/never-coalesce</span> + editor <span class="Special"><-</span> add-operation editor, op ] <span class="Comment"># Everytime you add a new operation to the undo stack, be sure to clear the</span> @@ -235,31 +235,31 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> add-operation editor:&:editor, op:&:operation<span class="muRecipe"> -> </span>editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - undo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">undo:offset</span> - undo<span class="Special"> <- </span>push op undo - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">undo:offset</span>, undo - redo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">redo:offset</span> - redo<span class="Special"> <- </span>copy <span class="Constant">0</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">redo:offset</span>, redo - <span class="muControl">return</span> editor/same-as-ingredient:<span class="Constant">0</span> + undo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">undo:offset</span> + undo <span class="Special"><-</span> push op undo + *editor <span class="Special"><-</span> put *editor, <span class="Constant">undo:offset</span>, undo + redo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">redo:offset</span> + redo <span class="Special"><-</span> copy<span class="Constant"> 0</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">redo:offset</span>, redo + <span class="muControl">return</span> editor/same-as-ingredient:0 ] <span class="muRecipe">after</span> <span class="Constant"><handle-undo></span> [ <span class="Delimiter">{</span> - typing:insert-operation, is-insert?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">typing:variant</span> + typing:insert-operation, is-insert?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">typing:variant</span> <span class="muControl">break-unless</span> is-insert? - start:&:duplex-list:char<span class="Special"> <- </span>get typing, <span class="Constant">insert-from:offset</span> - end:&:duplex-list:char<span class="Special"> <- </span>get typing, <span class="Constant">insert-until:offset</span> + start:&:duplex-list:char <span class="Special"><-</span> get typing, <span class="Constant">insert-from:offset</span> + end:&:duplex-list:char <span class="Special"><-</span> get typing, <span class="Constant">insert-until:offset</span> <span class="Comment"># assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>prev start - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor + before-cursor:&:duplex-list:char <span class="Special"><-</span> prev start + *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor remove-between before-cursor, end - cursor-row<span class="Special"> <- </span>get typing, <span class="Constant">before-row:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>get typing, <span class="Constant">before-column:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - top:&:duplex-list:char<span class="Special"> <- </span>get typing, <span class="Constant">before-top-of-screen:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top + cursor-row <span class="Special"><-</span> get typing, <span class="Constant">before-row:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> get typing, <span class="Constant">before-column:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + top:&:duplex-list:char <span class="Special"><-</span> get typing, <span class="Constant">before-top-of-screen:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top <span class="Delimiter">}</span> ] @@ -267,7 +267,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor and type multiple characters</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console [ type <span class="Constant">[012]</span> @@ -293,7 +293,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[a]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[a]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># type some characters</span> assume-console [ @@ -339,11 +339,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[ abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[ abc]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># new line</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">8</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 8</span> press enter ] editor-event-loop screen, console, e @@ -355,11 +355,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] <span class="Comment"># line is indented</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># undo</span> assume-console [ @@ -368,11 +368,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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">5</span> + <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"> 5</span> ] <span class="Comment"># back to original text</span> screen-should-contain [ @@ -402,7 +402,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor, type something, undo</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[a]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[a]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console [ type <span class="Constant">[012]</span> @@ -446,19 +446,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><handle-redo></span> [ <span class="Delimiter">{</span> - typing:insert-operation, is-insert?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">typing:variant</span> + typing:insert-operation, is-insert?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">typing:variant</span> <span class="muControl">break-unless</span> is-insert? - before-cursor<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - insert-from:&:duplex-list:char<span class="Special"> <- </span>get typing, <span class="Constant">insert-from:offset</span> <span class="Comment"># ignore insert-to because it's already been spliced away</span> + before-cursor <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + insert-from:&:duplex-list:char <span class="Special"><-</span> get typing, <span class="Constant">insert-from:offset</span> <span class="Comment"># ignore insert-to because it's already been spliced away</span> <span class="Comment"># assert insert-to matches next(before-cursor)</span> insert-range before-cursor, insert-from <span class="Comment"># assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen</span> - cursor-row<span class="Special"> <- </span>get typing, <span class="Constant">after-row:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>get typing, <span class="Constant">after-column:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - top:&:duplex-list:char<span class="Special"> <- </span>get typing, <span class="Constant">after-top-of-screen:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top + cursor-row <span class="Special"><-</span> get typing, <span class="Constant">after-row:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> get typing, <span class="Constant">after-column:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + top:&:duplex-list:char <span class="Special"><-</span> get typing, <span class="Constant">after-top-of-screen:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top <span class="Delimiter">}</span> ] @@ -466,7 +466,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor, type something, undo</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console [ type <span class="Constant">[012]</span> @@ -512,10 +512,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text, do some work, undo</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console [ type <span class="Constant">[1]</span> @@ -555,7 +555,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># insert some text and tabs, hit enter, some more text and tabs</span> assume-console [ @@ -575,11 +575,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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">7</span> + <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"> 7</span> ] <span class="Comment"># undo</span> assume-console [ @@ -589,11 +589,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># typing in second line deleted, but not indent</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -610,11 +610,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># indent and newline deleted</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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">8</span> + <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"> 8</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -630,11 +630,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># empty screen</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -650,11 +650,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># first line inserted</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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">8</span> + <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"> 8</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -670,11 +670,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># newline and indent inserted</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -691,11 +691,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># indent and newline deleted</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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">7</span> + <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"> 7</span> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -712,14 +712,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 1</span> ] editor-event-loop screen, console, e <span class="Comment"># undo</span> @@ -730,11 +730,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># click undone</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># cursor should be in the right place</span> assume-console [ @@ -753,49 +753,49 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><move-cursor-begin></span> [ - cursor-row-before:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column-before:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - top-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-row-before:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column-before:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + top-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> ] <span class="muRecipe">before</span> <span class="Constant"><move-cursor-end></span> [ - top-after:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> + top-after:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> undo-coalesce-tag <span class="Comment"># if previous operation was also a move, and also had the same coalesce</span> <span class="Comment"># tag, coalesce with it</span> - undo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">undo:offset</span> + undo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">undo:offset</span> <span class="muControl">break-unless</span> undo - op:&:operation<span class="Special"> <- </span>first undo - move:move-operation, is-move?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">move:variant</span> + op:&:operation <span class="Special"><-</span> first undo + move:move-operation, is-move?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">move:variant</span> <span class="muControl">break-unless</span> is-move? - previous-coalesce-tag:num<span class="Special"> <- </span>get move, <span class="Constant">tag:offset</span> - coalesce?:bool<span class="Special"> <- </span>equal undo-coalesce-tag, previous-coalesce-tag + previous-coalesce-tag:num <span class="Special"><-</span> get move, <span class="Constant">tag:offset</span> + coalesce?:bool <span class="Special"><-</span> equal undo-coalesce-tag, previous-coalesce-tag <span class="muControl">break-unless</span> coalesce? - move<span class="Special"> <- </span>put move, <span class="Constant">after-row:offset</span>, cursor-row - move<span class="Special"> <- </span>put move, <span class="Constant">after-column:offset</span>, cursor-column - move<span class="Special"> <- </span>put move, <span class="Constant">after-top-of-screen:offset</span>, top-after - *op<span class="Special"> <- </span>merge <span class="Constant">1/move-operation</span>, move + move <span class="Special"><-</span> put move, <span class="Constant">after-row:offset</span>, cursor-row + move <span class="Special"><-</span> put move, <span class="Constant">after-column:offset</span>, cursor-column + move <span class="Special"><-</span> put move, <span class="Constant">after-top-of-screen:offset</span>, top-after + *op <span class="Special"><-</span> merge <span class="Constant">1/move-operation</span>, move <span class="muControl">break</span> <span class="Constant">+done-adding-move-operation</span> <span class="Delimiter">}</span> - op:&:operation<span class="Special"> <- </span>new <span class="Constant">operation:type</span> - *op<span class="Special"> <- </span>merge <span class="Constant">1/move-operation</span>, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, undo-coalesce-tag - editor<span class="Special"> <- </span>add-operation editor, op + op:&:operation <span class="Special"><-</span> new <span class="Constant">operation:type</span> + *op <span class="Special"><-</span> merge <span class="Constant">1/move-operation</span>, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, undo-coalesce-tag + editor <span class="Special"><-</span> add-operation editor, op <span class="Constant"> +done-adding-move-operation</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-undo></span> [ <span class="Delimiter">{</span> - move:move-operation, is-move?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">move:variant</span> + move:move-operation, is-move?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">move:variant</span> <span class="muControl">break-unless</span> is-move? <span class="Comment"># assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen</span> - cursor-row<span class="Special"> <- </span>get move, <span class="Constant">before-row:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>get move, <span class="Constant">before-column:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - top:&:duplex-list:char<span class="Special"> <- </span>get move, <span class="Constant">before-top-of-screen:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top + cursor-row <span class="Special"><-</span> get move, <span class="Constant">before-row:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> get move, <span class="Constant">before-column:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + top:&:duplex-list:char <span class="Special"><-</span> get move, <span class="Constant">before-top-of-screen:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top <span class="Delimiter">}</span> ] @@ -804,18 +804,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># screen has 1 line for menu + 3 lines</span> assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span> <span class="Comment"># editor contains a wrapped line</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">cdefgh]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span> <span class="Comment"># position cursor at end of screen and try to move right</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">3</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 3</span> press right-arrow ] editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> <span class="Comment"># screen scrolls</span> screen-should-contain [ <span class="Constant"> . .</span> @@ -824,8 +824,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .gh .</span> ] memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] <span class="Comment"># undo</span> assume-console [ @@ -835,11 +835,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moved back</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 3</span> ] <span class="Comment"># scroll undone</span> screen-should-contain [ @@ -867,14 +867,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 1</span> press left-arrow ] editor-event-loop screen, console, e @@ -886,11 +886,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moves back</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 1</span> ] <span class="Comment"># cursor should be in the right place</span> assume-console [ @@ -912,22 +912,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor</span> assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 1</span> press up-arrow ] editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># undo</span> assume-console [ @@ -937,11 +937,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moves back</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 1</span> ] <span class="Comment"># cursor should be in the right place</span> assume-console [ @@ -963,14 +963,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press down-arrow ] editor-event-loop screen, console, e @@ -982,11 +982,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moves back</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># cursor should be in the right place</span> assume-console [ @@ -1008,13 +1008,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with multiple pages of text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d</span> <span class="Constant">e</span> <span class="Constant">f]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># scroll the page</span> assume-console [ @@ -1042,13 +1042,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with multiple pages of text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d</span> <span class="Constant">e</span> <span class="Constant">f]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># scroll the page</span> assume-console [ @@ -1076,13 +1076,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with multiple pages of text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d</span> <span class="Constant">e</span> <span class="Constant">f]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># scroll the page down and up</span> assume-console [ @@ -1111,13 +1111,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with multiple pages of text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[a</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[a</span> <span class="Constant">b</span> <span class="Constant">c</span> <span class="Constant">d</span> <span class="Constant">e</span> <span class="Constant">f]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># scroll the page down and up</span> assume-console [ @@ -1146,14 +1146,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor, then to start of line</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press ctrl-a ] editor-event-loop screen, console, e @@ -1165,11 +1165,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moves back</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># cursor should be in the right place</span> assume-console [ @@ -1191,14 +1191,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor, then to start of line</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press home ] editor-event-loop screen, console, e @@ -1210,11 +1210,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moves back</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># cursor should be in the right place</span> assume-console [ @@ -1236,14 +1236,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor, then to start of line</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press ctrl-e ] editor-event-loop screen, console, e @@ -1255,11 +1255,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moves back</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># cursor should be in the right place</span> assume-console [ @@ -1281,14 +1281,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor, then to start of line</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press end ] editor-event-loop screen, console, e @@ -1300,11 +1300,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moves back</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># cursor should be in the right place</span> assume-console [ @@ -1326,24 +1326,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># move the cursor</span> assume-console [ - left-click <span class="Constant">2</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 2</span>,<span class="Constant"> 1</span> press right-arrow press right-arrow press up-arrow ] editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># undo</span> assume-console [ @@ -1353,11 +1353,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># up-arrow is undone</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># undo again</span> assume-console [ @@ -1367,11 +1367,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># both right-arrows are undone</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] ] @@ -1381,13 +1381,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor with some text, click on a character, undo</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def</span> <span class="Constant">ghi]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console [ - left-click <span class="Constant">3</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 3</span>,<span class="Constant"> 1</span> press ctrl-z ] editor-event-loop screen, console, e @@ -1399,11 +1399,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># cursor moves to left-click</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span> - <span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant"> 3</span> <span class="Special"><-</span><span class="Constant"> 3</span> + <span class="Constant"> 4</span> <span class="Special"><-</span><span class="Constant"> 1</span> ] <span class="Comment"># cursor should be in the right place</span> assume-console [ @@ -1423,15 +1423,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><handle-redo></span> [ <span class="Delimiter">{</span> - move:move-operation, is-move?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">move:variant</span> + move:move-operation, is-move?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">move:variant</span> <span class="muControl">break-unless</span> is-move? <span class="Comment"># assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen</span> - cursor-row<span class="Special"> <- </span>get move, <span class="Constant">after-row:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>get move, <span class="Constant">after-column:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - top:&:duplex-list:char<span class="Special"> <- </span>get move, <span class="Constant">after-top-of-screen:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top + cursor-row <span class="Special"><-</span> get move, <span class="Constant">after-row:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> get move, <span class="Constant">after-column:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + top:&:duplex-list:char <span class="Special"><-</span> get move, <span class="Constant">after-top-of-screen:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top <span class="Delimiter">}</span> ] @@ -1439,16 +1439,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor, type some text, move the cursor, type some more text</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e assume-console [ type <span class="Constant">[abc]</span> - left-click <span class="Constant">1</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 1</span> type <span class="Constant">[d]</span> ] editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> screen-should-contain [ <span class="Constant"> . .</span> <span class="Constant"> .adbc .</span> @@ -1456,8 +1456,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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="Comment"># undo</span> assume-console [ @@ -1465,8 +1465,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># last letter typed is deleted</span> screen-should-contain [ @@ -1476,8 +1476,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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="Comment"># undo again</span> assume-console [ @@ -1485,8 +1485,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># no change to screen; cursor moves</span> screen-should-contain [ @@ -1496,8 +1496,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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="Comment"># undo again</span> assume-console [ @@ -1505,8 +1505,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># screen empty</span> screen-should-contain [ @@ -1516,8 +1516,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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="Comment"># redo</span> assume-console [ @@ -1525,8 +1525,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># first insert</span> screen-should-contain [ @@ -1536,8 +1536,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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="Comment"># redo again</span> assume-console [ @@ -1545,8 +1545,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># cursor moves</span> screen-should-contain [ @@ -1557,8 +1557,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="Comment"># cursor moves</span> memory-should-contain [ - <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="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="Comment"># redo again</span> assume-console [ @@ -1566,8 +1566,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> ] <span class="Comment"># second insert</span> screen-should-contain [ @@ -1577,8 +1577,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> . .</span> ] memory-should-contain [ - <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="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> ] ] @@ -1588,7 +1588,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># insert some text and hit backspace</span> assume-console [ @@ -1603,11 +1603,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># undo</span> assume-console [ @@ -1616,11 +1616,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1635,11 +1635,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1651,79 +1651,79 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># save operation to undo</span> <span class="muRecipe">after</span> <span class="Constant"><backspace-character-begin></span> [ - top-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + top-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> ] <span class="muRecipe">before</span> <span class="Constant"><backspace-character-end></span> [ <span class="Delimiter">{</span> <span class="muControl">break-unless</span> backspaced-cell <span class="Comment"># backspace failed; don't add an undo operation</span> - top-after:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - undo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">undo:offset</span> + top-after:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + undo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">undo:offset</span> <span class="Delimiter">{</span> <span class="Comment"># if previous operation was an insert, coalesce this operation with it</span> <span class="muControl">break-unless</span> undo - op:&:operation<span class="Special"> <- </span>first undo - deletion:delete-operation, is-delete?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">delete:variant</span> + op:&:operation <span class="Special"><-</span> first undo + deletion:delete-operation, is-delete?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">delete:variant</span> <span class="muControl">break-unless</span> is-delete? - previous-coalesce-tag:num<span class="Special"> <- </span>get deletion, <span class="Constant">tag:offset</span> - coalesce?:bool<span class="Special"> <- </span>equal previous-coalesce-tag, <span class="Constant">1/coalesce-backspace</span> + previous-coalesce-tag:num <span class="Special"><-</span> get deletion, <span class="Constant">tag:offset</span> + coalesce?:bool <span class="Special"><-</span> equal previous-coalesce-tag, <span class="Constant">1/coalesce-backspace</span> <span class="muControl">break-unless</span> coalesce? - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">delete-from:offset</span>, before-cursor - backspaced-so-far:&:duplex-list:char<span class="Special"> <- </span>get deletion, <span class="Constant">deleted-text:offset</span> + deletion <span class="Special"><-</span> put deletion, <span class="Constant">delete-from:offset</span>, before-cursor + backspaced-so-far:&:duplex-list:char <span class="Special"><-</span> get deletion, <span class="Constant">deleted-text:offset</span> insert-range backspaced-cell, backspaced-so-far - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">deleted-text:offset</span>, backspaced-cell - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">after-row:offset</span>, cursor-row - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">after-column:offset</span>, cursor-column - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">after-top-of-screen:offset</span>, top-after - *op<span class="Special"> <- </span>merge <span class="Constant">2/delete-operation</span>, deletion + deletion <span class="Special"><-</span> put deletion, <span class="Constant">deleted-text:offset</span>, backspaced-cell + deletion <span class="Special"><-</span> put deletion, <span class="Constant">after-row:offset</span>, cursor-row + deletion <span class="Special"><-</span> put deletion, <span class="Constant">after-column:offset</span>, cursor-column + deletion <span class="Special"><-</span> put deletion, <span class="Constant">after-top-of-screen:offset</span>, top-after + *op <span class="Special"><-</span> merge <span class="Constant">2/delete-operation</span>, deletion <span class="muControl">break</span> <span class="Constant">+done-adding-backspace-operation</span> <span class="Delimiter">}</span> <span class="Comment"># if not, create a new operation</span> - op:&:operation<span class="Special"> <- </span>new <span class="Constant">operation:type</span> - deleted-until:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - *op<span class="Special"> <- </span>merge <span class="Constant">2/delete-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, backspaced-cell/deleted, before-cursor/delete-from, deleted-until, <span class="Constant">1/coalesce-backspace</span> - editor<span class="Special"> <- </span>add-operation editor, op + op:&:operation <span class="Special"><-</span> new <span class="Constant">operation:type</span> + deleted-until:&:duplex-list:char <span class="Special"><-</span> next before-cursor + *op <span class="Special"><-</span> merge <span class="Constant">2/delete-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, backspaced-cell/deleted, before-cursor/delete-from, deleted-until, <span class="Constant">1/coalesce-backspace</span> + editor <span class="Special"><-</span> add-operation editor, op <span class="Constant"> +done-adding-backspace-operation</span> <span class="Delimiter">}</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-undo></span> [ <span class="Delimiter">{</span> - deletion:delete-operation, is-delete?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">delete:variant</span> + deletion:delete-operation, is-delete?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">delete:variant</span> <span class="muControl">break-unless</span> is-delete? - anchor:&:duplex-list:char<span class="Special"> <- </span>get deletion, <span class="Constant">delete-from:offset</span> + anchor:&:duplex-list:char <span class="Special"><-</span> get deletion, <span class="Constant">delete-from:offset</span> <span class="muControl">break-unless</span> anchor - deleted:&:duplex-list:char<span class="Special"> <- </span>get deletion, <span class="Constant">deleted-text:offset</span> - old-cursor:&:duplex-list:char<span class="Special"> <- </span>last deleted + deleted:&:duplex-list:char <span class="Special"><-</span> get deletion, <span class="Constant">deleted-text:offset</span> + old-cursor:&:duplex-list:char <span class="Special"><-</span> last deleted insert-range anchor, deleted <span class="Comment"># assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen</span> - before-cursor<span class="Special"> <- </span>copy old-cursor - cursor-row<span class="Special"> <- </span>get deletion, <span class="Constant">before-row:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>get deletion, <span class="Constant">before-column:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - top:&:duplex-list:char<span class="Special"> <- </span>get deletion, <span class="Constant">before-top-of-screen:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top + before-cursor <span class="Special"><-</span> copy old-cursor + cursor-row <span class="Special"><-</span> get deletion, <span class="Constant">before-row:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> get deletion, <span class="Constant">before-column:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + top:&:duplex-list:char <span class="Special"><-</span> get deletion, <span class="Constant">before-top-of-screen:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top <span class="Delimiter">}</span> ] <span class="muRecipe">after</span> <span class="Constant"><handle-redo></span> [ <span class="Delimiter">{</span> - deletion:delete-operation, is-delete?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">delete:variant</span> + deletion:delete-operation, is-delete?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">delete:variant</span> <span class="muControl">break-unless</span> is-delete? - start:&:duplex-list:char<span class="Special"> <- </span>get deletion, <span class="Constant">delete-from:offset</span> - end:&:duplex-list:char<span class="Special"> <- </span>get deletion, <span class="Constant">delete-until:offset</span> - data:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span> + start:&:duplex-list:char <span class="Special"><-</span> get deletion, <span class="Constant">delete-from:offset</span> + end:&:duplex-list:char <span class="Special"><-</span> get deletion, <span class="Constant">delete-until:offset</span> + data:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> remove-between start, end <span class="Comment"># assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen</span> - cursor-row<span class="Special"> <- </span>get deletion, <span class="Constant">after-row:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - cursor-column<span class="Special"> <- </span>get deletion, <span class="Constant">after-column:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - top:&:duplex-list:char<span class="Special"> <- </span>get deletion, <span class="Constant">before-top-of-screen:offset</span> - *editor<span class="Special"> <- </span>put *editor, <span class="Constant">top-of-screen:offset</span>, top + cursor-row <span class="Special"><-</span> get deletion, <span class="Constant">after-row:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row + cursor-column <span class="Special"><-</span> get deletion, <span class="Constant">after-column:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column + top:&:duplex-list:char <span class="Special"><-</span> get deletion, <span class="Constant">before-top-of-screen:offset</span> + *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top <span class="Delimiter">}</span> ] @@ -1733,12 +1733,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># insert some text and hit delete and backspace a few times</span> assume-console [ type <span class="Constant">[abcdef]</span> - left-click <span class="Constant">1</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 2</span> press delete press backspace press delete @@ -1751,11 +1751,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># undo deletes</span> assume-console [ @@ -1764,11 +1764,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1783,11 +1783,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1802,11 +1802,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1822,11 +1822,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># first line inserted</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1842,11 +1842,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># first line inserted</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1862,11 +1862,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] <span class="Comment"># first line inserted</span> - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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> ] screen-should-contain [ <span class="Constant"> . .</span> @@ -1877,41 +1877,41 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><delete-character-begin></span> [ - top-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + top-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> ] <span class="muRecipe">before</span> <span class="Constant"><delete-character-end></span> [ <span class="Delimiter">{</span> <span class="muControl">break-unless</span> deleted-cell <span class="Comment"># delete failed; don't add an undo operation</span> - top-after:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - undo:&:list:&:operation<span class="Special"> <- </span>get *editor, <span class="Constant">undo:offset</span> + top-after:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + undo:&:list:&:operation <span class="Special"><-</span> get *editor, <span class="Constant">undo:offset</span> <span class="Delimiter">{</span> <span class="Comment"># if previous operation was an insert, coalesce this operation with it</span> <span class="muControl">break-unless</span> undo - op:&:operation<span class="Special"> <- </span>first undo - deletion:delete-operation, is-delete?:bool<span class="Special"> <- </span>maybe-convert *op, <span class="Constant">delete:variant</span> + op:&:operation <span class="Special"><-</span> first undo + deletion:delete-operation, is-delete?:bool <span class="Special"><-</span> maybe-convert *op, <span class="Constant">delete:variant</span> <span class="muControl">break-unless</span> is-delete? - previous-coalesce-tag:num<span class="Special"> <- </span>get deletion, <span class="Constant">tag:offset</span> - coalesce?:bool<span class="Special"> <- </span>equal previous-coalesce-tag, <span class="Constant">2/coalesce-delete</span> + previous-coalesce-tag:num <span class="Special"><-</span> get deletion, <span class="Constant">tag:offset</span> + coalesce?:bool <span class="Special"><-</span> equal previous-coalesce-tag, <span class="Constant">2/coalesce-delete</span> <span class="muControl">break-unless</span> coalesce? - delete-until:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">delete-until:offset</span>, delete-until - deleted-so-far:&:duplex-list:char<span class="Special"> <- </span>get deletion, <span class="Constant">deleted-text:offset</span> - deleted-so-far<span class="Special"> <- </span>append deleted-so-far, deleted-cell - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">deleted-text:offset</span>, deleted-so-far - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">after-row:offset</span>, cursor-row - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">after-column:offset</span>, cursor-column - deletion<span class="Special"> <- </span>put deletion, <span class="Constant">after-top-of-screen:offset</span>, top-after - *op<span class="Special"> <- </span>merge <span class="Constant">2/delete-operation</span>, deletion + delete-until:&:duplex-list:char <span class="Special"><-</span> next before-cursor + deletion <span class="Special"><-</span> put deletion, <span class="Constant">delete-until:offset</span>, delete-until + deleted-so-far:&:duplex-list:char <span class="Special"><-</span> get deletion, <span class="Constant">deleted-text:offset</span> + deleted-so-far <span class="Special"><-</span> append deleted-so-far, deleted-cell + deletion <span class="Special"><-</span> put deletion, <span class="Constant">deleted-text:offset</span>, deleted-so-far + deletion <span class="Special"><-</span> put deletion, <span class="Constant">after-row:offset</span>, cursor-row + deletion <span class="Special"><-</span> put deletion, <span class="Constant">after-column:offset</span>, cursor-column + deletion <span class="Special"><-</span> put deletion, <span class="Constant">after-top-of-screen:offset</span>, top-after + *op <span class="Special"><-</span> merge <span class="Constant">2/delete-operation</span>, deletion <span class="muControl">break</span> <span class="Constant">+done-adding-delete-operation</span> <span class="Delimiter">}</span> <span class="Comment"># if not, create a new operation</span> - op:&:operation<span class="Special"> <- </span>new <span class="Constant">operation:type</span> - deleted-until:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - *op<span class="Special"> <- </span>merge <span class="Constant">2/delete-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cell/deleted, before-cursor/delete-from, deleted-until, <span class="Constant">2/coalesce-delete</span> - editor<span class="Special"> <- </span>add-operation editor, op + op:&:operation <span class="Special"><-</span> new <span class="Constant">operation:type</span> + deleted-until:&:duplex-list:char <span class="Special"><-</span> next before-cursor + *op <span class="Special"><-</span> merge <span class="Constant">2/delete-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cell/deleted, before-cursor/delete-from, deleted-until, <span class="Constant">2/coalesce-delete</span> + editor <span class="Special"><-</span> add-operation editor, op <span class="Constant"> +done-adding-delete-operation</span> <span class="Delimiter">}</span> ] @@ -1922,13 +1922,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># insert some text and hit delete and backspace a few times</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">1</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 1</span> press ctrl-k ] editor-event-loop screen, console, e @@ -1939,11 +1939,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># undo</span> assume-console [ @@ -1959,11 +1959,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># redo</span> assume-console [ @@ -1980,11 +1980,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># cursor should be in the right place</span> assume-console [ @@ -2003,18 +2003,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><delete-to-end-of-line-begin></span> [ - top-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + top-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> ] <span class="muRecipe">before</span> <span class="Constant"><delete-to-end-of-line-end></span> [ <span class="Delimiter">{</span> <span class="muControl">break-unless</span> deleted-cells <span class="Comment"># delete failed; don't add an undo operation</span> - top-after:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - deleted-until:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - op:&:operation<span class="Special"> <- </span>new <span class="Constant">operation:type</span> - *op<span class="Special"> <- </span>merge <span class="Constant">2/delete-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, <span class="Constant">0/never-coalesce</span> - editor<span class="Special"> <- </span>add-operation editor, op + top-after:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + deleted-until:&:duplex-list:char <span class="Special"><-</span> next before-cursor + op:&:operation <span class="Special"><-</span> new <span class="Constant">operation:type</span> + *op <span class="Special"><-</span> merge <span class="Constant">2/delete-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, <span class="Constant">0/never-coalesce</span> + editor <span class="Special"><-</span> add-operation editor, op <span class="Constant"> +done-adding-delete-operation</span> <span class="Delimiter">}</span> ] @@ -2025,13 +2025,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - contents:text<span class="Special"> <- </span>new <span class="Constant">[abc</span> + contents:text <span class="Special"><-</span> new <span class="Constant">[abc</span> <span class="Constant">def]</span> - e:&:editor<span class="Special"> <- </span>new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor contents, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># insert some text and hit delete and backspace a few times</span> assume-console [ - left-click <span class="Constant">1</span>, <span class="Constant">2</span> + left-click<span class="Constant"> 1</span>,<span class="Constant"> 2</span> press ctrl-u ] editor-event-loop screen, console, e @@ -2042,11 +2042,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># undo</span> assume-console [ @@ -2062,11 +2062,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># redo</span> assume-console [ @@ -2083,11 +2083,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌.</span> <span class="Constant"> . .</span> ] - <span class="Constant">3</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-row:offset</span> - <span class="Constant">4</span>:num/<span class="Special">raw <- </span>get *e, <span class="Constant">cursor-column:offset</span> + 3:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-row:offset</span> + 4:num/<span class="Special">raw</span> <span class="Special"><-</span> get *e, <span class="Constant">cursor-column:offset</span> memory-should-contain [ - <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="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="Comment"># cursor should be in the right place</span> assume-console [ @@ -2106,19 +2106,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] <span class="muRecipe">after</span> <span class="Constant"><delete-to-start-of-line-begin></span> [ - top-before:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> + top-before:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> ] <span class="muRecipe">before</span> <span class="Constant"><delete-to-start-of-line-end></span> [ <span class="Delimiter">{</span> <span class="muControl">break-unless</span> deleted-cells <span class="Comment"># delete failed; don't add an undo operation</span> - top-after:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span> - op:&:operation<span class="Special"> <- </span>new <span class="Constant">operation:type</span> - before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span> - deleted-until:&:duplex-list:char<span class="Special"> <- </span>next before-cursor - cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span> - cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span> - *op<span class="Special"> <- </span>merge <span class="Constant">2/delete-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, <span class="Constant">0/never-coalesce</span> - editor<span class="Special"> <- </span>add-operation editor, op + top-after:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> + op:&:operation <span class="Special"><-</span> new <span class="Constant">operation:type</span> + before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> + deleted-until:&:duplex-list:char <span class="Special"><-</span> next before-cursor + cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> + cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> + *op <span class="Special"><-</span> merge <span class="Constant">2/delete-operation</span>, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, <span class="Constant">0/never-coalesce</span> + editor <span class="Special"><-</span> add-operation editor, op <span class="Constant"> +done-adding-delete-operation</span> <span class="Delimiter">}</span> ] @@ -2127,7 +2127,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Comment"># create an editor</span> assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span> - e:&:editor<span class="Special"> <- </span>new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> + e:&:editor <span class="Special"><-</span> new-editor <span class="Constant">[]</span>, screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span> editor-render screen, e <span class="Comment"># insert some text and hit delete and backspace a few times</span> assume-console [ diff --git a/html/example1.mu.html b/html/example1.mu.html index 3d4d40eb..eeeaf4b8 100644 --- a/html/example1.mu.html +++ b/html/example1.mu.html @@ -29,8 +29,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <pre id='vimCodeElement'> <span class="muRecipe">def</span> example1 [ <span class="Constant">local-scope</span> - a:num<span class="Special"> <- </span>add <span class="Constant">2</span>, <span class="Constant">2</span> - a<span class="Special"> <- </span>multiply a, <span class="Constant">3</span> + a:num <span class="Special"><-</span> add<span class="Constant"> 2</span>,<span class="Constant"> 2</span> + a <span class="Special"><-</span> multiply a,<span class="Constant"> 3</span> ] </pre> </body> diff --git a/html/factorial.mu.html b/html/factorial.mu.html index a7deb772..921d3ca7 100644 --- a/html/factorial.mu.html +++ b/html/factorial.mu.html @@ -35,7 +35,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - x:num<span class="Special"> <- </span>factorial <span class="Constant">5</span> + x:num <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,23 +45,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> <span class="Comment"># if n=0 return 1</span> - zero?:bool<span class="Special"> <- </span>equal n, <span class="Constant">0</span> + zero?:bool <span class="Special"><-</span> equal n,<span class="Constant"> 0</span> <span class="muControl">break-unless</span> zero? - <span class="muControl">return</span> <span class="Constant">1</span> + <span class="muControl">return</span><span class="Constant"> 1</span> <span class="Delimiter">}</span> <span class="Comment"># return n * factorial(n-1)</span> - x:num<span class="Special"> <- </span>subtract n, <span class="Constant">1</span> - subresult:num<span class="Special"> <- </span>factorial x - result<span class="Special"> <- </span>multiply subresult, n + x:num <span class="Special"><-</span> subtract n,<span class="Constant"> 1</span> + subresult:num <span class="Special"><-</span> factorial x + result <span class="Special"><-</span> multiply subresult, n ] <span class="Comment"># unit test</span> <span class="muScenario">scenario</span> factorial-test [ run [ - <span class="Constant">1</span>:num<span class="Special"> <- </span>factorial <span class="Constant">5</span> + 1:num <span class="Special"><-</span> factorial<span class="Constant"> 5</span> ] memory-should-contain [ - <span class="Constant">1</span><span class="Special"> <- </span><span class="Constant">120</span> + <span class="Constant"> 1</span> <span class="Special"><-</span><span class="Constant"> 120</span> ] ] </pre> diff --git a/html/filesystem.mu.html b/html/filesystem.mu.html index f25f8a2f..da62136f 100644 --- a/html/filesystem.mu.html +++ b/html/filesystem.mu.html @@ -37,12 +37,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - source-file:&:source:char<span class="Special"> <- </span>start-reading <span class="Constant">0/real-filesystem</span>, <span class="Constant">[/tmp/mu-x]</span> - sink-file:&:sink:char, write-routine:num<span class="Special"> <- </span>start-writing <span class="Constant">0/real-filesystem</span>, <span class="Constant">[/tmp/mu-y]</span> + source-file:&:source:char <span class="Special"><-</span> start-reading <span class="Constant">0/real-filesystem</span>, <span class="Constant">[/tmp/mu-x]</span> + sink-file:&:sink:char, write-routine:num <span class="Special"><-</span> start-writing <span class="Constant">0/real-filesystem</span>, <span class="Constant">[/tmp/mu-y]</span> <span class="Delimiter">{</span> - c:char, done?:bool, source-file<span class="Special"> <- </span>read source-file + c:char, done?:bool, source-file <span class="Special"><-</span> read source-file <span class="muControl">break-if</span> done? - sink-file<span class="Special"> <- </span>write sink-file, c + sink-file <span class="Special"><-</span> write sink-file, c <span class="muControl">loop</span> <span class="Delimiter">}</span> close sink-file diff --git a/html/fork.mu.html b/html/fork.mu.html index b1565526..3008fbdc 100644 --- a/html/fork.mu.html +++ b/html/fork.mu.html @@ -34,14 +34,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ start-running thread2 <span class="Delimiter">{</span> - $print <span class="Constant">34</span> + $print<span class="Constant"> 34</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muRecipe">def</span> thread2 [ <span class="Delimiter">{</span> - $print <span class="Constant">35</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 32e227e0..2119e8b0 100644 --- a/html/global.mu.html +++ b/html/global.mu.html @@ -32,9 +32,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Comment"># allocate 5 locations for globals</span> - <span class="Constant">global-space</span>:space<span class="Special"> <- </span>new <span class="Constant">location:type</span>, <span class="Constant">5</span> + <span class="Constant">global-space</span>:space <span class="Special"><-</span> new <span class="Constant">location:type</span>,<span class="Constant"> 5</span> <span class="Comment"># read to globals by using /space:global</span> - <span class="Special">1:num/space:global</span><span class="Special"> <- </span>copy <span class="Constant">3</span> + <span class="Special">1:num/space:global</span> <span class="Special"><-</span> copy<span class="Constant"> 3</span> foo ] diff --git a/html/http-client.mu.html b/html/http-client.mu.html index 20691582..264f56ed 100644 --- a/html/http-client.mu.html +++ b/html/http-client.mu.html @@ -35,21 +35,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - google:&:source:char<span class="Special"> <- </span>start-reading-from-network <span class="Constant">0/real-resources</span>, <span class="Constant">[google.com/]</span> - n:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> + google:&:source:char <span class="Special"><-</span> start-reading-from-network <span class="Constant">0/real-resources</span>, <span class="Constant">[google.com/]</span> + n:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 30</span> <span class="Delimiter">{</span> - c:char, done?:bool<span class="Special"> <- </span>read google + c:char, done?:bool <span class="Special"><-</span> read google <span class="muControl">break-if</span> done? - n<span class="Special"> <- </span>add n, <span class="Constant">1</span> - buf<span class="Special"> <- </span>append buf, c + n <span class="Special"><-</span> add n,<span class="Constant"> 1</span> + buf <span class="Special"><-</span> append buf, c <span class="CommentedCode">#? trunc?:bool <- greater-or-equal n, 10000</span> <span class="CommentedCode">#? loop-unless trunc?</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> - result:text<span class="Special"> <- </span>buffer-to-array buf + result:text <span class="Special"><-</span> buffer-to-array buf open-console - len:num<span class="Special"> <- </span>length *result + len:num <span class="Special"><-</span> length *result print <span class="Constant">0/real-screen</span>, result wait-for-some-interaction close-console diff --git a/html/http-server.mu.html b/html/http-server.mu.html index cdc4d661..97220e9b 100644 --- a/html/http-server.mu.html +++ b/html/http-server.mu.html @@ -40,13 +40,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - socket:num<span class="Special"> <- </span>$open-server-socket <span class="Constant">8080/port</span> + socket:num <span class="Special"><-</span> $open-server-socket <span class="Constant">8080/port</span> $print <span class="Constant">[Mu socket creation returned ]</span>, socket, <span class="Constant">10/newline</span> <span class="muControl">return-unless</span> socket - session:num<span class="Special"> <- </span>$accept socket - contents:&:source:char, sink:&:sink:char<span class="Special"> <- </span>new-channel <span class="Constant">30</span> - sink<span class="Special"> <- </span>start-running receive-from-socket session, sink - query:text<span class="Special"> <- </span>drain contents + session:num <span class="Special"><-</span> $accept socket + contents:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> + sink <span class="Special"><-</span> start-running receive-from-socket session, sink + query:text <span class="Special"><-</span> drain contents $print <span class="Constant">[Done reading from socket.]</span>, <span class="Constant">10/newline</span> write-to-socket session, <span class="Constant">[HTTP/1.0 200 OK</span> <span class="Constant">Content-type: text/plain</span> diff --git a/html/immutable-error.mu.html b/html/immutable-error.mu.html index 93afe020..8c26fbb3 100644 --- a/html/immutable-error.mu.html +++ b/html/immutable-error.mu.html @@ -32,14 +32,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - x:&:num<span class="Special"> <- </span>new <span class="Constant">number:type</span> + x:&:num <span class="Special"><-</span> new <span class="Constant">number:type</span> foo x ] <span class="muRecipe">def</span> foo x:&:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - *x<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># will cause an error because x is immutable in this function</span> + *x <span class="Special"><-</span> copy<span class="Constant"> 34</span> <span class="Comment"># will cause an error because x is immutable in this function</span> ] </pre> </body> diff --git a/html/lambda-to-mu.mu.html b/html/lambda-to-mu.mu.html index 98b868fc..b4d44558 100644 --- a/html/lambda-to-mu.mu.html +++ b/html/lambda-to-mu.mu.html @@ -40,11 +40,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> convert-lambda [ run [ <span class="Constant">local-scope</span> - <span class="Constant">1</span>:text/<span class="Special">raw <- </span>lambda-to-mu <span class="Constant">[(add a (multiply b c))]</span> - <span class="Constant">2</span>:@:char/<span class="Special">raw <- </span>copy *<span class="Constant">1</span>:text/<span class="Special">raw</span> + 1:text/<span class="Special">raw</span> <span class="Special"><-</span> lambda-to-mu <span class="Constant">[(add a (multiply b c))]</span> + 2:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *1:text/<span class="Special">raw</span> ] memory-should-contain [ - <span class="Constant">2</span>:@:char<span class="Special"> <- </span><span class="Constant">[t1 <- multiply b c</span> + 2:@:char <span class="Special"><-</span> <span class="Constant">[t1 <- multiply b c</span> <span class="Constant">result <- add a t1]</span> ] ] @@ -52,9 +52,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> lambda-to-mu in:text<span class="muRecipe"> -> </span>out:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - out<span class="Special"> <- </span>copy <span class="Constant">0</span> - cells:&:cell<span class="Special"> <- </span>parse in - out<span class="Special"> <- </span>to-mu cells + out <span class="Special"><-</span> copy<span class="Constant"> 0</span> + cells:&:cell <span class="Special"><-</span> parse in + out <span class="Special"><-</span> to-mu cells ] <span class="Comment"># 'parse' will turn lambda expressions into trees made of cells</span> @@ -72,132 +72,132 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> new-atom name:text<span class="muRecipe"> -> </span>result:&:cell [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>new <span class="Constant">cell:type</span> - *result<span class="Special"> <- </span>merge <span class="Constant">0/tag:atom</span>, name + result <span class="Special"><-</span> new <span class="Constant">cell:type</span> + *result <span class="Special"><-</span> merge <span class="Constant">0/tag:atom</span>, name ] <span class="muRecipe">def</span> new-pair a:&:cell, b:&:cell<span class="muRecipe"> -> </span>result:&:cell [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result<span class="Special"> <- </span>new <span class="Constant">cell:type</span> - *result<span class="Special"> <- </span>merge <span class="Constant">1/tag:pair</span>, a/first, b/rest + result <span class="Special"><-</span> new <span class="Constant">cell:type</span> + *result <span class="Special"><-</span> merge <span class="Constant">1/tag:pair</span>, a/first, b/rest ] <span class="muRecipe">def</span> is-atom? x:&:cell<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">reply-unless</span> x, <span class="Constant">0/false</span> - _, result<span class="Special"> <- </span>maybe-convert *x, <span class="Constant">atom:variant</span> + _, result <span class="Special"><-</span> maybe-convert *x, <span class="Constant">atom:variant</span> ] <span class="muRecipe">def</span> is-pair? x:&:cell<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="muControl">reply-unless</span> x, <span class="Constant">0/false</span> - _, result<span class="Special"> <- </span>maybe-convert *x, <span class="Constant">pair:variant</span> + _, result <span class="Special"><-</span> maybe-convert *x, <span class="Constant">pair:variant</span> ] <span class="muScenario">scenario</span> atom-is-not-pair [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a]</span> - x:&:cell<span class="Special"> <- </span>new-atom s - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-atom? x - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>is-pair? x + s:text <span class="Special"><-</span> new <span class="Constant">[a]</span> + x:&:cell <span class="Special"><-</span> new-atom s + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-atom? x + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> ] ] <span class="muScenario">scenario</span> pair-is-not-atom [ <span class="Constant">local-scope</span> <span class="Comment"># construct (a . nil)</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a]</span> - x:&:cell<span class="Special"> <- </span>new-atom s - y:&:cell<span class="Special"> <- </span>new-pair x, <span class="Constant">0/nil</span> - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-atom? y - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>is-pair? y + s:text <span class="Special"><-</span> new <span class="Constant">[a]</span> + x:&:cell <span class="Special"><-</span> new-atom s + y:&:cell <span class="Special"><-</span> new-pair x, <span class="Constant">0/nil</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-atom? y + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? y memory-should-contain [ - <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">1</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"> 1</span> ] ] <span class="muRecipe">def</span> atom-match? x:&:cell, pat:text<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - s:text, is-atom?:bool<span class="Special"> <- </span>maybe-convert *x, <span class="Constant">atom:variant</span> + s:text, is-atom?:bool <span class="Special"><-</span> maybe-convert *x, <span class="Constant">atom:variant</span> <span class="muControl">reply-unless</span> is-atom?, <span class="Constant">0/false</span> - result<span class="Special"> <- </span>equal pat, s + result <span class="Special"><-</span> equal pat, s ] <span class="muScenario">scenario</span> atom-match [ <span class="Constant">local-scope</span> - x:&:cell<span class="Special"> <- </span>new-atom <span class="Constant">[abc]</span> - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>atom-match? x, <span class="Constant">[abc]</span> + x:&:cell <span class="Special"><-</span> new-atom <span class="Constant">[abc]</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> atom-match? x, <span class="Constant">[abc]</span> memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> ] ] <span class="muRecipe">def</span> first x:&:cell<span class="muRecipe"> -> </span>result:&:cell [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - pair:pair, pair?:bool<span class="Special"> <- </span>maybe-convert *x, <span class="Constant">pair:variant</span> + pair:pair, pair?:bool <span class="Special"><-</span> maybe-convert *x, <span class="Constant">pair:variant</span> <span class="muControl">reply-unless</span> pair?, <span class="Constant">0/nil</span> - result<span class="Special"> <- </span>get pair, <span class="Constant">first:offset</span> + result <span class="Special"><-</span> get pair, <span class="Constant">first:offset</span> ] <span class="muRecipe">def</span> rest x:&:cell<span class="muRecipe"> -> </span>result:&:cell [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - pair:pair, pair?:bool<span class="Special"> <- </span>maybe-convert *x, <span class="Constant">pair:variant</span> + pair:pair, pair?:bool <span class="Special"><-</span> maybe-convert *x, <span class="Constant">pair:variant</span> <span class="muControl">reply-unless</span> pair?, <span class="Constant">0/nil</span> - result<span class="Special"> <- </span>get pair, <span class="Constant">rest:offset</span> + result <span class="Special"><-</span> get pair, <span class="Constant">rest:offset</span> ] <span class="muRecipe">def</span> set-first base:&:cell, new-first:&:cell<span class="muRecipe"> -> </span>base:&:cell [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - pair:pair, is-pair?:bool<span class="Special"> <- </span>maybe-convert *base, <span class="Constant">pair:variant</span> + pair:pair, is-pair?:bool <span class="Special"><-</span> maybe-convert *base, <span class="Constant">pair:variant</span> <span class="muControl">reply-unless</span> is-pair? - pair<span class="Special"> <- </span>put pair, <span class="Constant">first:offset</span>, new-first - *base<span class="Special"> <- </span>merge <span class="Constant">1/pair</span>, pair + pair <span class="Special"><-</span> put pair, <span class="Constant">first:offset</span>, new-first + *base <span class="Special"><-</span> merge <span class="Constant">1/pair</span>, pair ] <span class="muRecipe">def</span> set-rest base:&:cell, new-rest:&:cell<span class="muRecipe"> -> </span>base:&:cell [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - pair:pair, is-pair?:bool<span class="Special"> <- </span>maybe-convert *base, <span class="Constant">pair:variant</span> + pair:pair, is-pair?:bool <span class="Special"><-</span> maybe-convert *base, <span class="Constant">pair:variant</span> <span class="muControl">reply-unless</span> is-pair? - pair<span class="Special"> <- </span>put pair, <span class="Constant">rest:offset</span>, new-rest - *base<span class="Special"> <- </span>merge <span class="Constant">1/pair</span>, pair + pair <span class="Special"><-</span> put pair, <span class="Constant">rest:offset</span>, new-rest + *base <span class="Special"><-</span> merge <span class="Constant">1/pair</span>, pair ] <span class="muScenario">scenario</span> cell-operations-on-atom [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a]</span> - x:&:cell<span class="Special"> <- </span>new-atom s - <span class="Constant">10</span>:&:cell/<span class="Special">raw <- </span>first x - <span class="Constant">11</span>:&:cell/<span class="Special">raw <- </span>rest x + s:text <span class="Special"><-</span> new <span class="Constant">[a]</span> + x:&:cell <span class="Special"><-</span> new-atom s + 10:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> first x + 11:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest x memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># first is nil</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># rest is nil</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># first is nil</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># rest is nil</span> ] ] <span class="muScenario">scenario</span> cell-operations-on-pair [ <span class="Constant">local-scope</span> <span class="Comment"># construct (a . nil)</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a]</span> - x:&:cell<span class="Special"> <- </span>new-atom s - y:&:cell<span class="Special"> <- </span>new-pair x, <span class="Constant">0/nil</span> - x2:&:cell<span class="Special"> <- </span>first y - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>equal x, x2 - <span class="Constant">11</span>:&:cell/<span class="Special">raw <- </span>rest y + s:text <span class="Special"><-</span> new <span class="Constant">[a]</span> + x:&:cell <span class="Special"><-</span> new-atom s + y:&:cell <span class="Special"><-</span> new-pair x, <span class="Constant">0/nil</span> + x2:&:cell <span class="Special"><-</span> first y + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal x, x2 + 11:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest y memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># first is correct</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># rest is nil</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># first is correct</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># rest is nil</span> ] ] @@ -206,93 +206,93 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> parse in:text<span class="muRecipe"> -> </span>out:&:cell [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - s:&:stream:char<span class="Special"> <- </span>new-stream in - out, s<span class="Special"> <- </span>parse s - trace <span class="Constant">2</span>, <span class="Constant">[app/parse]</span>, out + s:&:stream:char <span class="Special"><-</span> new-stream in + out, s <span class="Special"><-</span> parse s + trace<span class="Constant"> 2</span>, <span class="Constant">[app/parse]</span>, out ] <span class="muRecipe">def</span> parse in:&:stream:char<span class="muRecipe"> -> </span>out:&:cell, in:&:stream:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># skip whitespace</span> - in<span class="Special"> <- </span>skip-whitespace in - c:char, eof?:bool<span class="Special"> <- </span>peek in + in <span class="Special"><-</span> skip-whitespace in + c:char, eof?:bool <span class="Special"><-</span> peek in <span class="muControl">reply-if</span> eof?, <span class="Constant">0/nil</span> - pair?:bool<span class="Special"> <- </span>equal c, <span class="Constant">40/open-paren</span> + pair?:bool <span class="Special"><-</span> equal c, <span class="Constant">40/open-paren</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> pair? <span class="Comment"># atom</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 30</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>end-of-stream? in + done?:bool <span class="Special"><-</span> end-of-stream? in <span class="muControl">break-if</span> done? <span class="Comment"># stop before close paren or space</span> - c:char<span class="Special"> <- </span>peek in - done?<span class="Special"> <- </span>equal c, <span class="Constant">41/close-paren</span> + c:char <span class="Special"><-</span> peek in + done? <span class="Special"><-</span> equal c, <span class="Constant">41/close-paren</span> <span class="muControl">break-if</span> done? - done?<span class="Special"> <- </span>space? c + done? <span class="Special"><-</span> space? c <span class="muControl">break-if</span> done? - c<span class="Special"> <- </span>read in - buf<span class="Special"> <- </span>append buf, c + c <span class="Special"><-</span> read in + buf <span class="Special"><-</span> append buf, c <span class="muControl">loop</span> <span class="Delimiter">}</span> - s:text<span class="Special"> <- </span>buffer-to-array buf - out<span class="Special"> <- </span>new-atom s + s:text <span class="Special"><-</span> buffer-to-array buf + out <span class="Special"><-</span> new-atom s <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> pair? <span class="Comment"># pair</span> read in <span class="Comment"># skip the open-paren</span> - out<span class="Special"> <- </span>new <span class="Constant">cell:type</span> <span class="Comment"># start out with nil</span> + out <span class="Special"><-</span> new <span class="Constant">cell:type</span> <span class="Comment"># start out with nil</span> <span class="Comment"># read in first element of pair</span> <span class="Delimiter">{</span> - end?:bool<span class="Special"> <- </span>end-of-stream? in - not-end?:bool<span class="Special"> <- </span>not end? + end?:bool <span class="Special"><-</span> end-of-stream? in + not-end?:bool <span class="Special"><-</span> not end? assert not-end?, <span class="Constant">[unbalanced '(' in expression]</span> - c<span class="Special"> <- </span>peek in - close-paren?:bool<span class="Special"> <- </span>equal c, <span class="Constant">41/close-paren</span> + c <span class="Special"><-</span> peek in + close-paren?:bool <span class="Special"><-</span> equal c, <span class="Constant">41/close-paren</span> <span class="muControl">break-if</span> close-paren? - first:&:cell, in<span class="Special"> <- </span>parse in - *out<span class="Special"> <- </span>merge <span class="Constant">1/pair</span>, first, <span class="Constant">0/nil</span> + first:&:cell, in <span class="Special"><-</span> parse in + *out <span class="Special"><-</span> merge <span class="Constant">1/pair</span>, first, <span class="Constant">0/nil</span> <span class="Delimiter">}</span> <span class="Comment"># read in any remaining elements</span> - curr:&:cell<span class="Special"> <- </span>copy out + curr:&:cell <span class="Special"><-</span> copy out <span class="Delimiter">{</span> - in<span class="Special"> <- </span>skip-whitespace in - end?:bool<span class="Special"> <- </span>end-of-stream? in - not-end?:bool<span class="Special"> <- </span>not end? + in <span class="Special"><-</span> skip-whitespace in + end?:bool <span class="Special"><-</span> end-of-stream? in + not-end?:bool <span class="Special"><-</span> not end? assert not-end?, <span class="Constant">[unbalanced '(' in expression]</span> <span class="Comment"># termination check: ')'</span> - c<span class="Special"> <- </span>peek in + c <span class="Special"><-</span> peek in <span class="Delimiter">{</span> - close-paren?:bool<span class="Special"> <- </span>equal c, <span class="Constant">41/close-paren</span> + close-paren?:bool <span class="Special"><-</span> equal c, <span class="Constant">41/close-paren</span> <span class="muControl">break-unless</span> close-paren? read in <span class="Comment"># skip ')'</span> <span class="muControl">break</span> <span class="Constant">+end-pair</span> <span class="Delimiter">}</span> <span class="Comment"># still here? read next element of pair</span> - next:&:cell, in<span class="Special"> <- </span>parse in - is-dot?:bool<span class="Special"> <- </span>atom-match? next, <span class="Constant">[.]</span> + next:&:cell, in <span class="Special"><-</span> parse in + is-dot?:bool <span class="Special"><-</span> atom-match? next, <span class="Constant">[.]</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> is-dot? - next-curr:&:cell<span class="Special"> <- </span>new-pair next, <span class="Constant">0/nil</span> - curr<span class="Special"> <- </span>set-rest curr, next-curr - curr<span class="Special"> <- </span>rest curr + next-curr:&:cell <span class="Special"><-</span> new-pair next, <span class="Constant">0/nil</span> + curr <span class="Special"><-</span> set-rest curr, next-curr + curr <span class="Special"><-</span> rest curr <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> is-dot? <span class="Comment"># deal with dotted pair</span> - in<span class="Special"> <- </span>skip-whitespace in - c<span class="Special"> <- </span>peek in - not-close-paren?:bool<span class="Special"> <- </span>not-equal c, <span class="Constant">41/close-paren</span> + in <span class="Special"><-</span> skip-whitespace in + c <span class="Special"><-</span> peek in + not-close-paren?:bool <span class="Special"><-</span> not-equal c, <span class="Constant">41/close-paren</span> assert not-close-paren?, <span class="Constant">[')' cannot immediately follow '.']</span> - final:&:cell<span class="Special"> <- </span>parse in - curr<span class="Special"> <- </span>set-rest curr, final + final:&:cell <span class="Special"><-</span> parse in + curr <span class="Special"><-</span> set-rest curr, final <span class="Comment"># we're not gonna update curr, so better make sure the next iteration</span> <span class="Comment"># is going to end the pair</span> - in<span class="Special"> <- </span>skip-whitespace in - c<span class="Special"> <- </span>peek in - close-paren?:bool<span class="Special"> <- </span>equal c, <span class="Constant">41/close-paren</span> + in <span class="Special"><-</span> skip-whitespace in + c <span class="Special"><-</span> peek in + close-paren?:bool <span class="Special"><-</span> equal c, <span class="Constant">41/close-paren</span> assert close-paren?, <span class="Constant">['.' must be followed by exactly one expression before ')']</span> <span class="Delimiter">}</span> <span class="muControl">loop</span> @@ -305,10 +305,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>end-of-stream? in + done?:bool <span class="Special"><-</span> end-of-stream? in <span class="muControl">reply-if</span> done?, <span class="Constant">0/null</span> - c:char<span class="Special"> <- </span>peek in - space?:bool<span class="Special"> <- </span>space? c + c:char <span class="Special"><-</span> peek in + space?:bool <span class="Special"><-</span> space? c <span class="muControl">break-unless</span> space? read in <span class="Comment"># skip</span> <span class="muControl">loop</span> @@ -318,9 +318,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> to-text x:&:cell<span class="muRecipe"> -> </span>out:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> - buf<span class="Special"> <- </span>to-buffer x, buf - out<span class="Special"> <- </span>buffer-to-array buf + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 30</span> + buf <span class="Special"><-</span> to-buffer x, buf + out <span class="Special"><-</span> buffer-to-array buf ] <span class="muRecipe">def</span> to-buffer x:&:cell, buf:&:buffer<span class="muRecipe"> -> </span>buf:&:buffer [ @@ -329,195 +329,195 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># base case: empty cell</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> x - buf<span class="Special"> <- </span>append buf, <span class="Constant">[<>]</span> + buf <span class="Special"><-</span> append buf, <span class="Constant">[<>]</span> <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># base case: atom</span> <span class="Delimiter">{</span> - s:text, atom?:bool<span class="Special"> <- </span>maybe-convert *x, <span class="Constant">atom:variant</span> + s:text, atom?:bool <span class="Special"><-</span> maybe-convert *x, <span class="Constant">atom:variant</span> <span class="muControl">break-unless</span> atom? - buf<span class="Special"> <- </span>append buf, s + buf <span class="Special"><-</span> append buf, s <span class="muControl">reply</span> <span class="Delimiter">}</span> <span class="Comment"># recursive case: pair</span> - buf<span class="Special"> <- </span>append buf, <span class="Constant">[< ]</span> - first:&:cell<span class="Special"> <- </span>first x - buf<span class="Special"> <- </span>to-buffer first, buf - buf<span class="Special"> <- </span>append buf, <span class="Constant">[ | ]</span> - rest:&:cell<span class="Special"> <- </span>rest x - buf<span class="Special"> <- </span>to-buffer rest, buf - buf<span class="Special"> <- </span>append buf, <span class="Constant">[ >]</span> + buf <span class="Special"><-</span> append buf, <span class="Constant">[< ]</span> + first:&:cell <span class="Special"><-</span> first x + buf <span class="Special"><-</span> to-buffer first, buf + buf <span class="Special"><-</span> append buf, <span class="Constant">[ | ]</span> + rest:&:cell <span class="Special"><-</span> rest x + buf <span class="Special"><-</span> to-buffer rest, buf + buf <span class="Special"><-</span> append buf, <span class="Constant">[ >]</span> ] <span class="muScenario">scenario</span> parse-single-letter-atom [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[a]</span> - x:&:cell<span class="Special"> <- </span>parse s - s2:text, <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>maybe-convert *x, <span class="Constant">atom:variant</span> - <span class="Constant">11</span>:@:char/<span class="Special">raw <- </span>copy *s2 + s:text <span class="Special"><-</span> new <span class="Constant">[a]</span> + x:&:cell <span class="Special"><-</span> parse s + s2:text, 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x, <span class="Constant">atom:variant</span> + 11:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is an atom</span> - <span class="Constant">11</span>:@:char<span class="Special"> <- </span><span class="Constant">[a]</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is an atom</span> + 11:@:char <span class="Special"><-</span> <span class="Constant">[a]</span> ] ] <span class="muScenario">scenario</span> parse-atom [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[abc]</span> - x:&:cell<span class="Special"> <- </span>parse s - s2:text, <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>maybe-convert *x, <span class="Constant">atom:variant</span> - <span class="Constant">11</span>:@:char/<span class="Special">raw <- </span>copy *s2 + s:text <span class="Special"><-</span> new <span class="Constant">[abc]</span> + x:&:cell <span class="Special"><-</span> parse s + s2:text, 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x, <span class="Constant">atom:variant</span> + 11:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is an atom</span> - <span class="Constant">11</span>:@:char<span class="Special"> <- </span><span class="Constant">[abc]</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is an atom</span> + 11:@:char <span class="Special"><-</span> <span class="Constant">[abc]</span> ] ] <span class="muScenario">scenario</span> parse-list-of-two-atoms [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[(abc def)]</span> - x:&:cell<span class="Special"> <- </span>parse s + s:text <span class="Special"><-</span> new <span class="Constant">[(abc def)]</span> + x:&:cell <span class="Special"><-</span> parse s trace-should-contain [ app/parse: <span class="Constant"><</span> abc <span class="Constant">|</span> <span class="Constant"><</span> def <span class="Constant">|</span> <span class="Constant"><></span> <span class="Constant">></span> <span class="Constant">></span> ] - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-pair? x - x1:&:cell<span class="Special"> <- </span>first x - x2:&:cell<span class="Special"> <- </span>rest x - s1:text, <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>maybe-convert *x1, <span class="Constant">atom:variant</span> - <span class="Constant">12</span>:bool/<span class="Special">raw <- </span>is-pair? x2 - x3:&:cell<span class="Special"> <- </span>first x2 - s2:text, <span class="Constant">13</span>:bool/<span class="Special">raw <- </span>maybe-convert *x3, <span class="Constant">atom:variant</span> - <span class="Constant">14</span>:&:cell/<span class="Special">raw <- </span>rest x2 - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *s1 - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *s2 + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x1:&:cell <span class="Special"><-</span> first x + x2:&:cell <span class="Special"><-</span> rest x + s1:text, 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x1, <span class="Constant">atom:variant</span> + 12:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x2 + x3:&:cell <span class="Special"><-</span> first x2 + s2:text, 13:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x3, <span class="Constant">atom:variant</span> + 14:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest x2 + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s1 + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is a pair</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first is an atom</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest is a pair</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest.first is an atom</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># result.rest.rest is nil</span> - <span class="Constant">20</span>:@:char<span class="Special"> <- </span><span class="Constant">[abc]</span> <span class="Comment"># result.first</span> - <span class="Constant">30</span>:@:char<span class="Special"> <- </span><span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is a pair</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first is an atom</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is a pair</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest.rest is nil</span> + 20:@:char <span class="Special"><-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span> + 30:@:char <span class="Special"><-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> ] ] <span class="muScenario">scenario</span> parse-list-with-extra-spaces [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[ ( abc def ) ]</span> <span class="Comment"># extra spaces</span> - x:&:cell<span class="Special"> <- </span>parse s + s:text <span class="Special"><-</span> new <span class="Constant">[ ( abc def ) ]</span> <span class="Comment"># extra spaces</span> + x:&:cell <span class="Special"><-</span> parse s trace-should-contain [ app/parse: <span class="Constant"><</span> abc <span class="Constant">|</span> <span class="Constant"><</span> def <span class="Constant">|</span> <span class="Constant"><></span> <span class="Constant">></span> <span class="Constant">></span> ] - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-pair? x - x1:&:cell<span class="Special"> <- </span>first x - x2:&:cell<span class="Special"> <- </span>rest x - s1:text, <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>maybe-convert *x1, <span class="Constant">atom:variant</span> - <span class="Constant">12</span>:bool/<span class="Special">raw <- </span>is-pair? x2 - x3:&:cell<span class="Special"> <- </span>first x2 - s2:text, <span class="Constant">13</span>:bool/<span class="Special">raw <- </span>maybe-convert *x3, <span class="Constant">atom:variant</span> - <span class="Constant">14</span>:&:cell/<span class="Special">raw <- </span>rest x2 - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *s1 - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *s2 + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x1:&:cell <span class="Special"><-</span> first x + x2:&:cell <span class="Special"><-</span> rest x + s1:text, 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x1, <span class="Constant">atom:variant</span> + 12:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x2 + x3:&:cell <span class="Special"><-</span> first x2 + s2:text, 13:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x3, <span class="Constant">atom:variant</span> + 14:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest x2 + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s1 + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is a pair</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first is an atom</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest is a pair</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest.first is an atom</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># result.rest.rest is nil</span> - <span class="Constant">20</span>:@:char<span class="Special"> <- </span><span class="Constant">[abc]</span> <span class="Comment"># result.first</span> - <span class="Constant">30</span>:@:char<span class="Special"> <- </span><span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is a pair</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first is an atom</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is a pair</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest.rest is nil</span> + 20:@:char <span class="Special"><-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span> + 30:@:char <span class="Special"><-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> ] ] <span class="muScenario">scenario</span> parse-list-of-more-than-two-atoms [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[(abc def ghi)]</span> - x:&:cell<span class="Special"> <- </span>parse s + s:text <span class="Special"><-</span> new <span class="Constant">[(abc def ghi)]</span> + x:&:cell <span class="Special"><-</span> parse s trace-should-contain [ app/parse: <span class="Constant"><</span> abc <span class="Constant">|</span> <span class="Constant"><</span> def <span class="Constant">|</span> <span class="Constant"><</span> ghi <span class="Constant">|</span> <span class="Constant"><></span> <span class="Constant">></span> <span class="Constant">></span> <span class="Constant">></span> ] - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-pair? x - x1:&:cell<span class="Special"> <- </span>first x - x2:&:cell<span class="Special"> <- </span>rest x - s1:text, <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>maybe-convert *x1, <span class="Constant">atom:variant</span> - <span class="Constant">12</span>:bool/<span class="Special">raw <- </span>is-pair? x2 - x3:&:cell<span class="Special"> <- </span>first x2 - s2:text, <span class="Constant">13</span>:bool/<span class="Special">raw <- </span>maybe-convert *x3, <span class="Constant">atom:variant</span> - x4:&:cell<span class="Special"> <- </span>rest x2 - <span class="Constant">14</span>:bool/<span class="Special">raw <- </span>is-pair? x4 - x5:&:cell<span class="Special"> <- </span>first x4 - s3:text, <span class="Constant">15</span>:bool/<span class="Special">raw <- </span>maybe-convert *x5, <span class="Constant">atom:variant</span> - <span class="Constant">16</span>:&:cell/<span class="Special">raw <- </span>rest x4 - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *s1 - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *s2 - <span class="Constant">40</span>:@:char/<span class="Special">raw <- </span>copy *s3 + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x1:&:cell <span class="Special"><-</span> first x + x2:&:cell <span class="Special"><-</span> rest x + s1:text, 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x1, <span class="Constant">atom:variant</span> + 12:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x2 + x3:&:cell <span class="Special"><-</span> first x2 + s2:text, 13:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x3, <span class="Constant">atom:variant</span> + x4:&:cell <span class="Special"><-</span> rest x2 + 14:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x4 + x5:&:cell <span class="Special"><-</span> first x4 + s3:text, 15:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x5, <span class="Constant">atom:variant</span> + 16:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest x4 + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s1 + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 + 40:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s3 memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is a pair</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first is an atom</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest is a pair</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest.first is an atom</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest.rest is a pair</span> - <span class="Constant">15</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest.rest.first is an atom</span> - <span class="Constant">16</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># result.rest.rest.rest is nil</span> - <span class="Constant">20</span>:@:char<span class="Special"> <- </span><span class="Constant">[abc]</span> <span class="Comment"># result.first</span> - <span class="Constant">30</span>:@:char<span class="Special"> <- </span><span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> - <span class="Constant">40</span>:@:char<span class="Special"> <- </span><span class="Constant">[ghi]</span> <span class="Comment"># result.rest.rest</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is a pair</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first is an atom</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is a pair</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.rest is a pair</span> + <span class="Constant"> 15</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.rest.first is an atom</span> + <span class="Constant"> 16</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest.rest.rest is nil</span> + 20:@:char <span class="Special"><-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span> + 30:@:char <span class="Special"><-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> + 40:@:char <span class="Special"><-</span> <span class="Constant">[ghi]</span> <span class="Comment"># result.rest.rest</span> ] ] <span class="muScenario">scenario</span> parse-nested-list [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[((abc))]</span> - x:&:cell<span class="Special"> <- </span>parse s + s:text <span class="Special"><-</span> new <span class="Constant">[((abc))]</span> + x:&:cell <span class="Special"><-</span> parse s trace-should-contain [ app/parse: <span class="Constant"><</span> <span class="Constant"><</span> abc <span class="Constant">|</span> <span class="Constant"><></span> <span class="Constant">></span> <span class="Constant">|</span> <span class="Constant"><></span> <span class="Constant">></span> ] - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-pair? x - x1:&:cell<span class="Special"> <- </span>first x - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>is-pair? x - x2:&:cell<span class="Special"> <- </span>first x1 - s1:text, <span class="Constant">12</span>:bool/<span class="Special">raw <- </span>maybe-convert *x2, <span class="Constant">atom:variant</span> - <span class="Constant">13</span>:&:cell/<span class="Special">raw <- </span>rest x1 - <span class="Constant">14</span>:&:cell/<span class="Special">raw <- </span>rest x - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *s1 + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x1:&:cell <span class="Special"><-</span> first x + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x2:&:cell <span class="Special"><-</span> first x1 + s1:text, 12:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x2, <span class="Constant">atom:variant</span> + 13:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest x1 + 14:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest x + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s1 memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is a pair</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first is a pair</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first.first is an atom</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># result.first.rest is nil</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># result.rest is nil</span> - <span class="Constant">20</span>:@:char<span class="Special"> <- </span><span class="Constant">[abc]</span> <span class="Comment"># result.first.first</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is a pair</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first is a pair</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first.first is an atom</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># result.first.rest is nil</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest is nil</span> + 20:@:char <span class="Special"><-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first.first</span> ] ] <span class="muScenario">scenario</span> parse-nested-list-2 [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[((abc) def)]</span> - x:&:cell<span class="Special"> <- </span>parse s + s:text <span class="Special"><-</span> new <span class="Constant">[((abc) def)]</span> + x:&:cell <span class="Special"><-</span> parse s trace-should-contain [ app/parse: <span class="Constant"><</span> <span class="Constant"><</span> abc <span class="Constant">|</span> <span class="Constant"><></span> <span class="Constant">></span> <span class="Constant">|</span> <span class="Constant"><</span> def <span class="Constant">|</span> <span class="Constant"><></span> <span class="Constant">></span> <span class="Constant">></span> ] - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-pair? x - x1:&:cell<span class="Special"> <- </span>first x - <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>is-pair? x - x2:&:cell<span class="Special"> <- </span>first x1 - s1:text, <span class="Constant">12</span>:bool/<span class="Special">raw <- </span>maybe-convert *x2, <span class="Constant">atom:variant</span> - <span class="Constant">13</span>:&:cell/<span class="Special">raw <- </span>rest x1 - x3:&:cell<span class="Special"> <- </span>rest x - x4:&:cell<span class="Special"> <- </span>first x3 - s2:text, <span class="Constant">14</span>:bool/<span class="Special">raw <- </span>maybe-convert *x4, <span class="Constant">atom:variant</span> - <span class="Constant">15</span>:&:cell/<span class="Special">raw <- </span>rest x3 - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *s1 - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *s2 + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x1:&:cell <span class="Special"><-</span> first x + 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x2:&:cell <span class="Special"><-</span> first x1 + s1:text, 12:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x2, <span class="Constant">atom:variant</span> + 13:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest x1 + x3:&:cell <span class="Special"><-</span> rest x + x4:&:cell <span class="Special"><-</span> first x3 + s2:text, 14:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x4, <span class="Constant">atom:variant</span> + 15:&:cell/<span class="Special">raw</span> <span class="Special"><-</span> rest x3 + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s1 + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is a pair</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first is a pair</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first.first is an atom</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># result.first.rest is nil</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest.first is an atom</span> - <span class="Constant">15</span><span class="Special"> <- </span><span class="Constant">0</span> <span class="Comment"># result.rest.rest is nil</span> - <span class="Constant">20</span>:@:char<span class="Special"> <- </span><span class="Constant">[abc]</span> <span class="Comment"># result.first.first</span> - <span class="Constant">30</span>:@:char<span class="Special"> <- </span><span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is a pair</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first is a pair</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first.first is an atom</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># result.first.rest is nil</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span> + <span class="Constant"> 15</span> <span class="Special"><-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest.rest is nil</span> + 20:@:char <span class="Special"><-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first.first</span> + 30:@:char <span class="Special"><-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> ] ] @@ -547,56 +547,56 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muScenario">scenario</span> parse-dotted-list-of-two-atoms [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[(abc . def)]</span> - x:&:cell<span class="Special"> <- </span>parse s + s:text <span class="Special"><-</span> new <span class="Constant">[(abc . def)]</span> + x:&:cell <span class="Special"><-</span> parse s trace-should-contain [ app/parse: <span class="Constant"><</span> abc <span class="Constant">|</span> def <span class="Constant">></span> ] - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-pair? x - x1:&:cell<span class="Special"> <- </span>first x - x2:&:cell<span class="Special"> <- </span>rest x - s1:text, <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>maybe-convert *x1, <span class="Constant">atom:variant</span> - s2:text, <span class="Constant">12</span>:bool/<span class="Special">raw <- </span>maybe-convert *x2, <span class="Constant">atom:variant</span> - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *s1 - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *s2 + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x1:&:cell <span class="Special"><-</span> first x + x2:&:cell <span class="Special"><-</span> rest x + s1:text, 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x1, <span class="Constant">atom:variant</span> + s2:text, 12:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x2, <span class="Constant">atom:variant</span> + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s1 + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 memory-should-contain [ <span class="Comment"># parses to < abc | def ></span> - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is a pair</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first is an atom</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest is an atom</span> - <span class="Constant">20</span>:@:char<span class="Special"> <- </span><span class="Constant">[abc]</span> <span class="Comment"># result.first</span> - <span class="Constant">30</span>:@:char<span class="Special"> <- </span><span class="Constant">[def]</span> <span class="Comment"># result.rest</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is a pair</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first is an atom</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is an atom</span> + 20:@:char <span class="Special"><-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span> + 30:@:char <span class="Special"><-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest</span> ] ] <span class="muScenario">scenario</span> parse-dotted-list-of-more-than-two-atoms [ <span class="Constant">local-scope</span> - s:text<span class="Special"> <- </span>new <span class="Constant">[(abc def . ghi)]</span> - x:&:cell<span class="Special"> <- </span>parse s + s:text <span class="Special"><-</span> new <span class="Constant">[(abc def . ghi)]</span> + x:&:cell <span class="Special"><-</span> parse s trace-should-contain [ app/parse: <span class="Constant"><</span> abc <span class="Constant">|</span> <span class="Constant"><</span> def <span class="Constant">|</span> ghi <span class="Constant">></span> <span class="Constant">></span> ] - <span class="Constant">10</span>:bool/<span class="Special">raw <- </span>is-pair? x - x1:&:cell<span class="Special"> <- </span>first x - x2:&:cell<span class="Special"> <- </span>rest x - s1:text, <span class="Constant">11</span>:bool/<span class="Special">raw <- </span>maybe-convert *x1, <span class="Constant">atom:variant</span> - <span class="Constant">12</span>:bool/<span class="Special">raw <- </span>is-pair? x2 - x3:&:cell<span class="Special"> <- </span>first x2 - s2:text, <span class="Constant">13</span>:bool/<span class="Special">raw <- </span>maybe-convert *x3, <span class="Constant">atom:variant</span> - x4:&:cell<span class="Special"> <- </span>rest x2 - s3:text, <span class="Constant">14</span>:bool/<span class="Special">raw <- </span>maybe-convert *x4, <span class="Constant">atom:variant</span> - <span class="Constant">20</span>:@:char/<span class="Special">raw <- </span>copy *s1 - <span class="Constant">30</span>:@:char/<span class="Special">raw <- </span>copy *s2 - <span class="Constant">40</span>:@:char/<span class="Special">raw <- </span>copy *s3 + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x + x1:&:cell <span class="Special"><-</span> first x + x2:&:cell <span class="Special"><-</span> rest x + s1:text, 11:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x1, <span class="Constant">atom:variant</span> + 12:bool/<span class="Special">raw</span> <span class="Special"><-</span> is-pair? x2 + x3:&:cell <span class="Special"><-</span> first x2 + s2:text, 13:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x3, <span class="Constant">atom:variant</span> + x4:&:cell <span class="Special"><-</span> rest x2 + s3:text, 14:bool/<span class="Special">raw</span> <span class="Special"><-</span> maybe-convert *x4, <span class="Constant">atom:variant</span> + 20:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s1 + 30:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s2 + 40:@:char/<span class="Special">raw</span> <span class="Special"><-</span> copy *s3 memory-should-contain [ - <span class="Constant">10</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># parse result is a pair</span> - <span class="Constant">11</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.first is an atom</span> - <span class="Constant">12</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest is a pair</span> - <span class="Constant">13</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest.first is an atom</span> - <span class="Constant">14</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># result.rest.rest is an atom</span> - <span class="Constant">20</span>:@:char<span class="Special"> <- </span><span class="Constant">[abc]</span> <span class="Comment"># result.first</span> - <span class="Constant">30</span>:@:char<span class="Special"> <- </span><span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> - <span class="Constant">40</span>:@:char<span class="Special"> <- </span><span class="Constant">[ghi]</span> <span class="Comment"># result.rest.rest</span> + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is a pair</span> + <span class="Constant"> 11</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.first is an atom</span> + <span class="Constant"> 12</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is a pair</span> + <span class="Constant"> 13</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span> + <span class="Constant"> 14</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.rest is an atom</span> + 20:@:char <span class="Special"><-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span> + 30:@:char <span class="Special"><-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span> + 40:@:char <span class="Special"><-</span> <span class="Constant">[ghi]</span> <span class="Comment"># result.rest.rest</span> ] ] @@ -605,9 +605,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> to-mu in:&:cell<span class="muRecipe"> -> </span>out:text [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - buf:&:buffer<span class="Special"> <- </span>new-buffer <span class="Constant">30</span> - buf<span class="Special"> <- </span>to-mu in, buf - out<span class="Special"> <- </span>buffer-to-array buf + buf:&:buffer <span class="Special"><-</span> new-buffer<span class="Constant"> 30</span> + buf <span class="Special"><-</span> to-mu in, buf + out <span class="Special"><-</span> buffer-to-array buf ] <span class="muRecipe">def</span> to-mu in:&:cell, buf:&:buffer<span class="muRecipe"> -> </span>buf:&:buffer, result-name:text [ @@ -616,7 +616,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># null cell? no change.</span> <span class="Comment"># pair with all atoms? gensym a new variable</span> <span class="Comment"># pair containing other pairs? recurse</span> - result-name<span class="Special"> <- </span>copy <span class="Constant">0</span> + result-name <span class="Special"><-</span> copy<span class="Constant"> 0</span> ] </pre> </body> diff --git a/html/mutable.mu.html b/html/mutable.mu.html index 82c7ae10..a1c3e593 100644 --- a/html/mutable.mu.html +++ b/html/mutable.mu.html @@ -32,14 +32,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - x:&:num<span class="Special"> <- </span>new <span class="Constant">number:type</span> + x:&:num <span class="Special"><-</span> new <span class="Constant">number:type</span> foo x ] <span class="muRecipe">def</span> foo x:&:num<span class="muRecipe"> -> </span>x:&:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - *x<span class="Special"> <- </span>copy <span class="Constant">34</span> + *x <span class="Special"><-</span> copy<span class="Constant"> 34</span> ] </pre> </body> diff --git a/html/nqueens.mu.html b/html/nqueens.mu.html index c5e06d2d..022bb1bc 100644 --- a/html/nqueens.mu.html +++ b/html/nqueens.mu.html @@ -45,35 +45,35 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if 'queens' is already long enough, print it and return</span> - added-so-far:num<span class="Special"> <- </span>length queens + added-so-far:num <span class="Special"><-</span> length queens <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal added-so-far, n + done?:bool <span class="Special"><-</span> greater-or-equal added-so-far, n <span class="muControl">break-unless</span> done? stash queens - <span class="muControl">return</span> <span class="Constant">1</span> + <span class="muControl">return</span><span class="Constant"> 1</span> <span class="Delimiter">}</span> <span class="Comment"># still work to do</span> - next-rank:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + next-rank:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> queens - first:square<span class="Special"> <- </span>first queens - existing-rank:num<span class="Special"> <- </span>get first, <span class="Constant">rank:offset</span> - next-rank<span class="Special"> <- </span>add existing-rank, <span class="Constant">1</span> + first:square <span class="Special"><-</span> first queens + existing-rank:num <span class="Special"><-</span> get first, <span class="Constant">rank:offset</span> + next-rank <span class="Special"><-</span> add existing-rank,<span class="Constant"> 1</span> <span class="Delimiter">}</span> - result<span class="Special"> <- </span>copy <span class="Constant">0</span> - next-file:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + result <span class="Special"><-</span> copy<span class="Constant"> 0</span> + next-file:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool<span class="Special"> <- </span>greater-or-equal next-file, n + done?:bool <span class="Special"><-</span> greater-or-equal next-file, n <span class="muControl">break-if</span> done? - curr:square<span class="Special"> <- </span>merge next-rank, next-file + curr:square <span class="Special"><-</span> merge next-rank, next-file <span class="Delimiter">{</span> - curr-conflicts?:bool<span class="Special"> <- </span>conflict? curr, queens + curr-conflicts?:bool <span class="Special"><-</span> conflict? curr, queens <span class="muControl">break-if</span> curr-conflicts? - new-queens:&:list:square<span class="Special"> <- </span>push curr, queens - sub-result:num<span class="Special"> <- </span>nqueens n, new-queens - result<span class="Special"> <- </span>add result, sub-result + new-queens:&:list:square <span class="Special"><-</span> push curr, queens + sub-result:num <span class="Special"><-</span> nqueens n, new-queens + result <span class="Special"><-</span> add result, sub-result <span class="Delimiter">}</span> - next-file<span class="Special"> <- </span>add next-file, <span class="Constant">1</span> + next-file <span class="Special"><-</span> add next-file,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] @@ -81,23 +81,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> conflict? curr:square, queens:&:list:square<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - result1:bool<span class="Special"> <- </span>conflicting-file? curr, queens + result1:bool <span class="Special"><-</span> conflicting-file? curr, queens <span class="muControl">reply-if</span> result1, result1 - result2:bool<span class="Special"> <- </span>conflicting-diagonal? curr, queens + result2:bool <span class="Special"><-</span> conflicting-diagonal? curr, queens <span class="muControl">reply</span> result2 ] <span class="muRecipe">def</span> conflicting-file? curr:square, queens:&:list:square<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - curr-file:num<span class="Special"> <- </span>get curr, <span class="Constant">file:offset</span> + curr-file:num <span class="Special"><-</span> get curr, <span class="Constant">file:offset</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> queens - q:square<span class="Special"> <- </span>first queens - qfile:num<span class="Special"> <- </span>get q, <span class="Constant">file:offset</span> - file-match?:bool<span class="Special"> <- </span>equal curr-file, qfile + q:square <span class="Special"><-</span> first queens + qfile:num <span class="Special"><-</span> get q, <span class="Constant">file:offset</span> + file-match?:bool <span class="Special"><-</span> equal curr-file, qfile <span class="muControl">reply-if</span> file-match?, <span class="Constant">1/conflict-found</span> - queens<span class="Special"> <- </span>rest queens + queens <span class="Special"><-</span> rest queens <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">reply</span> <span class="Constant">0/no-conflict-found</span> @@ -106,27 +106,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> conflicting-diagonal? curr:square, queens:&:list:square<span class="muRecipe"> -> </span>result:bool [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - curr-rank:num<span class="Special"> <- </span>get curr, <span class="Constant">rank:offset</span> - curr-file:num<span class="Special"> <- </span>get curr, <span class="Constant">file:offset</span> + curr-rank:num <span class="Special"><-</span> get curr, <span class="Constant">rank:offset</span> + curr-file:num <span class="Special"><-</span> get curr, <span class="Constant">file:offset</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> queens - q:square<span class="Special"> <- </span>first queens - qrank:num<span class="Special"> <- </span>get q, <span class="Constant">rank:offset</span> - qfile:num<span class="Special"> <- </span>get q, <span class="Constant">file:offset</span> - rank-delta:num<span class="Special"> <- </span>subtract qrank, curr-rank - file-delta:num<span class="Special"> <- </span>subtract qfile, curr-file - rank-delta<span class="Special"> <- </span>abs rank-delta - file-delta<span class="Special"> <- </span>abs file-delta - diagonal-match?:bool<span class="Special"> <- </span>equal rank-delta, file-delta + q:square <span class="Special"><-</span> first queens + qrank:num <span class="Special"><-</span> get q, <span class="Constant">rank:offset</span> + qfile:num <span class="Special"><-</span> get q, <span class="Constant">file:offset</span> + rank-delta:num <span class="Special"><-</span> subtract qrank, curr-rank + file-delta:num <span class="Special"><-</span> subtract qfile, curr-file + rank-delta <span class="Special"><-</span> abs rank-delta + file-delta <span class="Special"><-</span> abs file-delta + diagonal-match?:bool <span class="Special"><-</span> equal rank-delta, file-delta <span class="muControl">reply-if</span> diagonal-match?, <span class="Constant">1/conflict-found</span> - queens<span class="Special"> <- </span>rest queens + queens <span class="Special"><-</span> rest queens <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="muControl">reply</span> <span class="Constant">0/no-conflict-found</span> ] <span class="muRecipe">def</span> main [ - nqueens <span class="Constant">4</span> + nqueens<span class="Constant"> 4</span> $dump-trace <span class="Constant">[app]</span> ] </pre> diff --git a/html/real-files.mu.html b/html/real-files.mu.html index 2ffe5dfc..67d2f7b3 100644 --- a/html/real-files.mu.html +++ b/html/real-files.mu.html @@ -35,16 +35,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - f:num/file<span class="Special"> <- </span>$open-file-for-reading <span class="Constant">[/tmp/mu-x]</span> + f:num/file <span class="Special"><-</span> $open-file-for-reading <span class="Constant">[/tmp/mu-x]</span> $print <span class="Constant">[file to read from: ]</span>, f, <span class="Constant">10/newline</span> - c:char, eof?:bool<span class="Special"> <- </span>$read-from-file f + c:char, eof?:bool <span class="Special"><-</span> $read-from-file f $print <span class="Constant">[copying ]</span>, c, <span class="Constant">10/newline</span> - f<span class="Special"> <- </span>$close-file f + f <span class="Special"><-</span> $close-file f $print <span class="Constant">[file after closing: ]</span>, f, <span class="Constant">10/newline</span> - f<span class="Special"> <- </span>$open-file-for-writing <span class="Constant">[/tmp/mu-y]</span> + f <span class="Special"><-</span> $open-file-for-writing <span class="Constant">[/tmp/mu-y]</span> $print <span class="Constant">[file to write to: ]</span>, f, <span class="Constant">10/newline</span> $write-to-file f, c - f<span class="Special"> <- </span>$close-file f + f <span class="Special"><-</span> $close-file f ] </pre> </body> diff --git a/html/screen.mu.html b/html/screen.mu.html index 5e8d25ca..1f203815 100644 --- a/html/screen.mu.html +++ b/html/screen.mu.html @@ -34,14 +34,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># screens.</span> <span class="muRecipe">def</span> main [ open-console - <span class="Constant">10</span>:char<span class="Special"> <- </span>copy <span class="Constant">97/a</span> - print <span class="Constant">0/screen</span>, <span class="Constant">10</span>:char/a, <span class="Constant">2/red</span> - <span class="Constant">1</span>:num/<span class="Special">raw</span>, <span class="Constant">2</span>:num/<span class="Special">raw <- </span>cursor-position <span class="Constant">0/screen</span> + 10:char <span class="Special"><-</span> copy <span class="Constant">97/a</span> + print <span class="Constant">0/screen</span>, 10:char/a, <span class="Constant">2/red</span> + 1:num/<span class="Special">raw</span>, 2:num/<span class="Special">raw</span> <span class="Special"><-</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> - <span class="Constant">10</span>:char<span class="Special"> <- </span>copy <span class="Constant">98/b</span> - print <span class="Constant">0/screen</span>, <span class="Constant">10</span>:char + 10:char <span class="Special"><-</span> copy <span class="Constant">98/b</span> + print <span class="Constant">0/screen</span>, 10:char 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> diff --git a/html/static-dispatch.mu.html b/html/static-dispatch.mu.html index 2797735b..6b69da47 100644 --- a/html/static-dispatch.mu.html +++ b/html/static-dispatch.mu.html @@ -31,22 +31,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">def</span> test a:num<span class="muRecipe"> -> </span>b:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - b<span class="Special"> <- </span>add a, <span class="Constant">1</span> + b <span class="Special"><-</span> add a,<span class="Constant"> 1</span> ] <span class="muRecipe">def</span> test a:num, b:num<span class="muRecipe"> -> </span>c:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - c<span class="Special"> <- </span>add a, b + c <span class="Special"><-</span> add a, b ] <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - a:num<span class="Special"> <- </span>test <span class="Constant">3</span> <span class="Comment"># selects single-ingredient version</span> + a:num <span class="Special"><-</span> test<span class="Constant"> 3</span> <span class="Comment"># selects single-ingredient version</span> $print a, <span class="Constant">10/newline</span> - b:num<span class="Special"> <- </span>test <span class="Constant">3</span>, <span class="Constant">4</span> <span class="Comment"># selects double-ingredient version</span> + b:num <span class="Special"><-</span> test<span class="Constant"> 3</span>,<span class="Constant"> 4</span> <span class="Comment"># selects double-ingredient version</span> $print b, <span class="Constant">10/newline</span> - c:num<span class="Special"> <- </span>test <span class="Constant">3</span>, <span class="Constant">4</span>, <span class="Constant">5</span> <span class="Comment"># prefers double- to single-ingredient version</span> + c:num <span class="Special"><-</span> test<span class="Constant"> 3</span>,<span class="Constant"> 4</span>,<span class="Constant"> 5</span> <span class="Comment"># prefers double- to single-ingredient version</span> $print c, <span class="Constant">10/newline</span> ] </pre> diff --git a/html/tangle.mu.html b/html/tangle.mu.html index 039eacf4..ce74c293 100644 --- a/html/tangle.mu.html +++ b/html/tangle.mu.html @@ -49,22 +49,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muRecipe">after</span> <span class="Constant"><base-case></span> [ <span class="Comment"># if n=0 return 1</span> - zero?:bool<span class="Special"> <- </span>equal n, <span class="Constant">0</span> + zero?:bool <span class="Special"><-</span> equal n,<span class="Constant"> 0</span> <span class="muControl">break-unless</span> zero? - <span class="muControl">return</span> <span class="Constant">1</span> + <span class="muControl">return</span><span class="Constant"> 1</span> ] <span class="muRecipe">after</span> <span class="Constant"><recursive-case></span> [ <span class="Comment"># return n * factorial(n - 1)</span> - x:num<span class="Special"> <- </span>subtract n, <span class="Constant">1</span> - subresult:num<span class="Special"> <- </span>factorial x - result<span class="Special"> <- </span>multiply subresult, n + x:num <span class="Special"><-</span> subtract n,<span class="Constant"> 1</span> + subresult:num <span class="Special"><-</span> factorial x + result <span class="Special"><-</span> multiply subresult, n ] <span class="muRecipe">def</span> main [ - <span class="Constant">1</span>:num<span class="Special"> <- </span>factorial <span class="Constant">5</span> + 1:num <span class="Special"><-</span> factorial<span class="Constant"> 5</span> <span class="Comment"># trailing space in next line is to help with syntax highlighting</span> - $print <span class="Constant">[result: ]</span>, <span class="Constant">1</span>:num, <span class="Constant">[ </span> + $print <span class="Constant">[result: ]</span>, 1:num, <span class="Constant">[ </span> <span class="Constant">]</span> ] </pre> diff --git a/html/x.mu.html b/html/x.mu.html index 2e5b580e..e8502b27 100644 --- a/html/x.mu.html +++ b/html/x.mu.html @@ -31,9 +31,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># example program: add two numbers</span> <span class="muRecipe">def</span> main [ - <span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span> - <span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">3</span> - <span class="Constant">13</span>:num<span class="Special"> <- </span>add <span class="Constant">11</span>:num, <span class="Constant">12</span>:num + 11:num <span class="Special"><-</span> copy<span class="Constant"> 1</span> + 12:num <span class="Special"><-</span> copy<span class="Constant"> 3</span> + 13:num <span class="Special"><-</span> add 11:num, 12:num <span class="Constant"> $dump-memory</span> ] </pre> |