diff options
-rw-r--r-- | 022arithmetic.cc | 12 | ||||
-rw-r--r-- | 081print.mu | 21 | ||||
-rw-r--r-- | html/022arithmetic.cc.html | 12 | ||||
-rw-r--r-- | html/081print.mu.html | 21 |
4 files changed, 66 insertions, 0 deletions
diff --git a/022arithmetic.cc b/022arithmetic.cc index 23f9a39d..dfd3b149 100644 --- a/022arithmetic.cc +++ b/022arithmetic.cc @@ -714,6 +714,18 @@ def main [ ] +mem: storing 12 in location 1 +:(scenario round_halves_toward_zero) +def main [ + 1:num <- round 12.5 +] ++mem: storing 12 in location 1 + +:(scenario round_halves_toward_zero_2) +def main [ + 1:num <- round -12.5 +] ++mem: storing -12 in location 1 + :(before "End Primitive Recipe Declarations") CHARACTER_TO_CODE, :(before "End Primitive Recipe Numbers") diff --git a/081print.mu b/081print.mu index adda5db9..9eecf6d3 100644 --- a/081print.mu +++ b/081print.mu @@ -106,11 +106,13 @@ def print screen:&:screen, c:char -> screen:&:screen [ height:num <- get *screen, num-rows:offset # if cursor is out of bounds, silently exit row:num <- get *screen, cursor-row:offset + row <- round row legal?:bool <- greater-or-equal row, 0 return-unless legal? legal? <- lesser-than row, height return-unless legal? column:num <- get *screen, cursor-column:offset + column <- round column legal? <- greater-or-equal column, 0 return-unless legal? legal? <- lesser-than column, width @@ -185,6 +187,25 @@ scenario print-character-at-top-left [ ] ] +scenario print-character-at-fractional-coordinate [ + local-scope + fake-screen:&:screen <- new-fake-screen 3/width, 2/height + a:char <- copy 97/a + run [ + move-cursor fake-screen, 0.5, 0 + fake-screen <- print fake-screen, a:char + cell:&:@:screen-cell <- get *fake-screen, data:offset + 1:@:screen-cell/raw <- copy *cell + ] + memory-should-contain [ + 1 <- 6 # width*height + 2 <- 97 # 'a' + 3 <- 7 # white + # rest of screen is empty + 4 <- 0 + ] +] + scenario print-character-in-color [ local-scope fake-screen:&:screen <- new-fake-screen 3/width, 2/height diff --git a/html/022arithmetic.cc.html b/html/022arithmetic.cc.html index 4d2b454e..b18bc7d2 100644 --- a/html/022arithmetic.cc.html +++ b/html/022arithmetic.cc.html @@ -750,6 +750,18 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span ] <span class="traceContains">+mem: storing 12 in location 1</span> +<span class="Delimiter">:(scenario round_halves_toward_zero)</span> +<span class="muRecipe">def</span> main [ + <span class="Constant">1</span>:num<span class="Special"> <- </span>round <span class="Constant">12.5</span> +] +<span class="traceContains">+mem: storing 12 in location 1</span> + +<span class="Delimiter">:(scenario round_halves_toward_zero_2)</span> +<span class="muRecipe">def</span> main [ + <span class="Constant">1</span>:num<span class="Special"> <- </span>round -<span class="Constant">12.5</span> +] +<span class="traceContains">+mem: storing -12 in location 1</span> + <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> CHARACTER_TO_CODE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> diff --git a/html/081print.mu.html b/html/081print.mu.html index 241cf857..5214e80c 100644 --- a/html/081print.mu.html +++ b/html/081print.mu.html @@ -141,11 +141,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color 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> + row <span class="Special"><-</span> round row 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 <span class="muControl">return-unless</span> legal? column:num <span class="Special"><-</span> get *screen, <span class="Constant">cursor-column:offset</span> + column <span class="Special"><-</span> round column 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 @@ -220,6 +222,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] ] +<span class="muScenario">scenario</span> print-character-at-fractional-coordinate [ + <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> + run [ + move-cursor fake-screen, 0.5,<span class="Constant"> 0</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="Comment"># rest of screen is empty</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> |