diff options
-rw-r--r-- | 051scenario_test.mu | 30 | ||||
-rw-r--r-- | 072channel.mu | 195 | ||||
-rw-r--r-- | 073array.mu | 13 | ||||
-rw-r--r-- | 074list.mu | 27 | ||||
-rw-r--r-- | 076duplex_list.mu | 514 | ||||
-rw-r--r-- | 079table.mu | 22 | ||||
-rw-r--r-- | 081print.mu | 289 |
7 files changed, 569 insertions, 521 deletions
diff --git a/051scenario_test.mu b/051scenario_test.mu index 4f86c188..c9f10d27 100644 --- a/051scenario_test.mu +++ b/051scenario_test.mu @@ -2,20 +2,20 @@ scenario first_scenario_in_mu [ run [ - 1:number <- add 2, 2 + 10:number <- add 2, 2 ] memory-should-contain [ - 1 <- 4 + 10 <- 4 ] ] scenario scenario_with_comment_in_mu [ run [ # comment - 1:number <- add 2, 2 + 10:number <- add 2, 2 ] memory-should-contain [ - 1 <- 4 + 10 <- 4 ] ] @@ -23,40 +23,40 @@ scenario scenario_with_multiple_comments_in_mu [ run [ # comment1 # comment2 - 1:number <- add 2, 2 + 10:number <- add 2, 2 ] memory-should-contain [ - 1 <- 4 + 10 <- 4 ] ] scenario check_text_in_memory [ run [ - 1:number <- copy 3 - 2:character <- copy 97 # 'a' - 3:character <- copy 98 # 'b' - 4:character <- copy 99 # 'c' + 10:number <- copy 3 + 11:character <- copy 97 # 'a' + 12:character <- copy 98 # 'b' + 13:character <- copy 99 # 'c' ] memory-should-contain [ - 1:array:character <- [abc] + 10:array:character <- [abc] ] ] scenario check_trace [ run [ - 1:number <- add 2, 2 + 10:number <- add 2, 2 ] trace-should-contain [ - mem: storing 4 in location 1 + mem: storing 4 in location 10 ] ] scenario check_trace_negative [ run [ - 1:number <- add 2, 2 + 10:number <- add 2, 2 ] trace-should-not-contain [ - mem: storing 5 in location 1 + mem: storing 3 in location 10 ] ] diff --git a/072channel.mu b/072channel.mu index d391aeeb..c7e3dae0 100644 --- a/072channel.mu +++ b/072channel.mu @@ -10,13 +10,14 @@ scenario channel [ run [ - 1:address:source:number, 2:address:sink:number <- new-channel 3/capacity - 2:address:sink:number <- write 2:address:sink:number, 34 - 3:number, 4:boolean, 1:address:source:number <- read 1:address:source:number + local-scope + source:address:source:number, sink:address:sink:number <- new-channel 3/capacity + sink <- write sink, 34 + 10:number/raw, 11:boolean/raw, source <- read source ] memory-should-contain [ - 3 <- 34 - 4 <- 0 # read was successful + 10 <- 34 + 11 <- 0 # read was successful ] ] @@ -133,125 +134,132 @@ def clear in:address:source:_elem -> in:address:source:_elem [ scenario channel-initialization [ run [ - 1:address:source:number <- new-channel 3/capacity - 2:address:channel:number <- get *1:address:source:number, chan:offset - 3:number <- get *2:address:channel:number, first-full:offset - 4:number <- get *2:address:channel:number, first-free:offset + local-scope + source:address:source:number <- new-channel 3/capacity + chan:address:channel:number <- get *source, chan:offset + 10:number/raw <- get *chan, first-full:offset + 11:number/raw <- get *chan, first-free:offset ] memory-should-contain [ - 3 <- 0 # first-full - 4 <- 0 # first-free + 10 <- 0 # first-full + 11 <- 0 # first-free ] ] scenario channel-write-increments-free [ run [ - _, 1:address:sink:number <- new-channel 3/capacity - 1:address:sink:number <- write 1:address:sink:number, 34 - 2:address:channel:number <- get *1:address:sink:number, chan:offset - 3:number <- get *2:address:channel:character, first-full:offset - 4:number <- get *2:address:channel:character, first-free:offset + local-scope + _, sink:address:sink:number <- new-channel 3/capacity + sink <- write sink, 34 + chan:address:channel:number <- get *sink, chan:offset + 10:number/raw <- get *chan, first-full:offset + 11:number/raw <- get *chan, first-free:offset ] memory-should-contain [ - 3 <- 0 # first-full - 4 <- 1 # first-free + 10 <- 0 # first-full + 11 <- 1 # first-free ] ] scenario channel-read-increments-full [ run [ - 1:address:source:number, 2:address:sink:number <- new-channel 3/capacity - 2:address:sink:number <- write 2:address:sink:number, 34 - _, _, 1:address:source:number <- read 1:address:source:number - 3:address:channel:number <- get *1:address:source:number, chan:offset - 4:number <- get *3:address:channel:number, first-full:offset - 5:number <- get *3:address:channel:number, first-free:offset + local-scope + source:address:source:number, sink:address:sink:number <- new-channel 3/capacity + sink <- write sink, 34 + _, _, source <- read source + chan:address:channel:number <- get *source, chan:offset + 10:number/raw <- get *chan, first-full:offset + 11:number/raw <- get *chan, first-free:offset ] memory-should-contain [ - 4 <- 1 # first-full - 5 <- 1 # first-free + 10 <- 1 # first-full + 11 <- 1 # first-free ] ] scenario channel-wrap [ run [ + local-scope # channel with just 1 slot - 1:address:source:number, 2:address:sink:number <- new-channel 1/capacity - 3:address:channel:number <- get *1:address:source:number, chan:offset + source:address:source:number, sink:address:sink:number <- new-channel 1/capacity + chan:address:channel:number <- get *source, chan:offset # write and read a value - 2:address:sink:number <- write 2:address:sink:number, 34 - _, _, 1:address:source:number <- read 1:address:source:number + sink <- write sink, 34 + _, _, source <- read source # first-free will now be 1 - 4:number <- get *3:address:channel:number, first-free:offset - 5:number <- get *3:address:channel:number, first-free:offset + 10:number/raw <- get *chan, first-free:offset + 11:number/raw <- get *chan, first-free:offset # write second value, verify that first-free wraps - 2:address:sink:number <- write 2:address:sink:number, 34 - 6:number <- get *3:address:channel:number, first-free:offset + sink <- write sink, 34 + 20:number/raw <- get *chan, first-free:offset # read second value, verify that first-full wraps - _, _, 1:address:source:number <- read 1:address:source:number - 7:number <- get *3:address:channel:number, first-full:offset + _, _, source <- read source + 30:number/raw <- get *chan, first-full:offset ] memory-should-contain [ - 4 <- 1 # first-free after first write - 5 <- 1 # first-full after first read - 6 <- 0 # first-free after second write, wrapped - 7 <- 0 # first-full after second read, wrapped + 10 <- 1 # first-free after first write + 11 <- 1 # first-full after first read + 20 <- 0 # first-free after second write, wrapped + 30 <- 0 # first-full after second read, wrapped ] ] scenario channel-new-empty-not-full [ run [ - 1:address:source:number, 2:address:sink:number <- new-channel 3/capacity - 3:address:channel:number <- get *1:address:source:number, chan:offset - 4:boolean <- channel-empty? 3:address:channel:number - 5:boolean <- channel-full? 3:address:channel:number + local-scope + source:address:source:number <- new-channel 3/capacity + chan:address:channel:number <- get *source, chan:offset + 10:boolean/raw <- channel-empty? chan + 11:boolean/raw <- channel-full? chan ] memory-should-contain [ - 4 <- 1 # empty? - 5 <- 0 # full? + 10 <- 1 # empty? + 11 <- 0 # full? ] ] scenario channel-write-not-empty [ run [ - 1:address:source:number, 2:address:sink:number <- new-channel 3/capacity - 3:address:channel:number <- get *1:address:source:number, chan:offset - 2:address:sink:number <- write 2:address:sink:number, 34 - 4:boolean <- channel-empty? 3:address:channel:number - 5:boolean <- channel-full? 3:address:channel:number + source:address:source:number, sink:address:sink:number <- new-channel 3/capacity + chan:address:channel:number <- get *source, chan:offset + sink <- write sink, 34 + 10:boolean/raw <- channel-empty? chan + 11:boolean/raw <- channel-full? chan ] memory-should-contain [ - 4 <- 0 # empty? - 5 <- 0 # full? + 10 <- 0 # empty? + 11 <- 0 # full? ] ] scenario channel-write-full [ run [ - 1:address:source:number, 2:address:sink:number <- new-channel 1/capacity - 3:address:channel:number <- get *1:address:source:number, chan:offset - 2:address:sink:number <- write 2:address:sink:number, 34 - 4:boolean <- channel-empty? 3:address:channel:number - 5:boolean <- channel-full? 3:address:channel:number + local-scope + source:address:source:number, sink:address:sink:number <- new-channel 1/capacity + chan:address:channel:number <- get *source, chan:offset + sink <- write sink, 34 + 10:boolean/raw <- channel-empty? chan + 11:boolean/raw <- channel-full? chan ] memory-should-contain [ - 4 <- 0 # empty? - 5 <- 1 # full? + 10 <- 0 # empty? + 11 <- 1 # full? ] ] scenario channel-read-not-full [ run [ - 1:address:source:number, 2:address:sink:number <- new-channel 1/capacity - 3:address:channel:number <- get *1:address:source:number, chan:offset - 2:address:sink:number <- write 2:address:sink:number, 34 - _, _, 1:address:source:number <- read 1:address:source:number - 4:boolean <- channel-empty? 3:address:channel:number - 5:boolean <- channel-full? 3:address:channel:number + local-scope + source:address:source:number, sink:address:sink:number <- new-channel 1/capacity + chan:address:channel:number <- get *source, chan:offset + sink <- write sink, 34 + _, _, source <- read source + 10:boolean/raw <- channel-empty? chan + 11:boolean/raw <- channel-full? chan ] memory-should-contain [ - 4 <- 1 # empty? - 5 <- 0 # full? + 10 <- 1 # empty? + 11 <- 0 # full? ] ] @@ -395,39 +403,40 @@ def buffer-lines in:address:source:character, buffered-out:address:sink:characte scenario buffer-lines-blocks-until-newline [ run [ - 1:address:source:number, 2:address:sink:number <- new-channel 10/capacity - _, 3:address:sink:number/buffered-stdin <- new-channel 10/capacity - 4:address:channel:number/buffered-stdin <- get *3:address:source:number, chan:offset - 5:boolean <- channel-empty? 4:address:channel:character/buffered-stdin - assert 5:boolean, [ + local-scope + source:address:source:character, sink:address:sink:character <- new-channel 10/capacity + _, buffered-stdin:address:sink:character/buffered-stdin <- new-channel 10/capacity + buffered-chan:address:channel:character <- get *buffered-stdin, chan:offset + empty?:boolean <- channel-empty? buffered-chan + assert empty?, [ F buffer-lines-blocks-until-newline: channel should be empty after init] # buffer stdin into buffered-stdin, try to read from buffered-stdin - 6:number/buffer-routine <- start-running buffer-lines, 1:address:source:character/stdin, 3:address:sink:character/buffered-stdin - wait-for-routine 6:number/buffer-routine - 7:boolean <- channel-empty? 4:address:channel:character/buffered-stdin - assert 7:boolean, [ + buffer-routine:number <- start-running buffer-lines, source, buffered-stdin + wait-for-routine buffer-routine + empty? <- channel-empty? buffered-chan + assert empty?:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty after buffer-lines bring-up] # write 'a' - 2:address:sink:character <- write 2:address:sink:character, 97/a - restart 6:number/buffer-routine - wait-for-routine 6:number/buffer-routine - 8:boolean <- channel-empty? 4:address:channel:character/buffered-stdin - assert 8:boolean, [ + sink <- write sink, 97/a + restart buffer-routine + wait-for-routine buffer-routine + empty? <- channel-empty? buffered-chan + assert empty?:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty after writing 'a'] # write 'b' - 2:address:sink:character <- write 2:address:sink:character, 98/b - restart 6:number/buffer-routine - wait-for-routine 6:number/buffer-routine - 9:boolean <- channel-empty? 4:address:channel:character/buffered-stdin - assert 9:boolean, [ + sink <- write sink, 98/b + restart buffer-routine + wait-for-routine buffer-routine + empty? <- channel-empty? buffered-chan + assert empty?:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty after writing 'b'] # write newline - 2:address:sink:character <- write 2:address:sink:character, 10/newline - restart 6:number/buffer-routine - wait-for-routine 6:number/buffer-routine - 10:boolean <- channel-empty? 4:address:channel:character/buffered-stdin - 11:boolean/completed? <- not 10:boolean - assert 11:boolean/completed?, [ + sink <- write sink, 10/newline + restart buffer-routine + wait-for-routine buffer-routine + empty? <- channel-empty? buffered-chan + data-emitted?:boolean <- not empty? + assert data-emitted?, [ F buffer-lines-blocks-until-newline: channel should contain data after writing newline] trace 1, [test], [reached end] ] diff --git a/073array.mu b/073array.mu index 7e1bf807..8272a865 100644 --- a/073array.mu +++ b/073array.mu @@ -1,13 +1,14 @@ scenario array-from-args [ run [ - 1:address:array:character <- new-array 0, 1, 2 - 2:array:character <- copy *1:address:array:character + local-scope + x:address:array:character <- new-array 0, 1, 2 + 10:array:character/raw <- copy *x ] memory-should-contain [ - 2 <- 3 # array length - 3 <- 0 - 4 <- 1 - 5 <- 2 + 10 <- 3 # array length + 11 <- 0 + 12 <- 1 + 13 <- 2 ] ] diff --git a/074list.mu b/074list.mu index 79fed038..80613694 100644 --- a/074list.mu +++ b/074list.mu @@ -29,21 +29,22 @@ def rest in:address:list:_elem -> result:address:list:_elem/contained-in:in [ scenario list-handling [ run [ - 1:address:list:number <- push 3, 0 - 1:address:list:number <- push 4, 1:address:list:number - 1:address:list:number <- push 5, 1:address:list:number - 2:number <- first 1:address:list:number - 1:address:list:number <- rest 1:address:list:number - 3:number <- first 1:address:list:number - 1:address:list:number <- rest 1:address:list:number - 4:number <- first 1:address:list:number - 1:address:list:number <- rest 1:address:list:number + local-scope + x:address:list:number <- push 3, 0 + x <- push 4, x + x <- push 5, x + 10:number/raw <- first x + x <- rest x + 11:number/raw <- first x + x <- rest x + 12:number/raw <- first x + 20:address:list:number/raw <- rest x ] memory-should-contain [ - 1 <- 0 # empty to empty, dust to dust.. - 2 <- 5 - 3 <- 4 - 4 <- 3 + 10 <- 5 + 11 <- 4 + 12 <- 3 + 20 <- 0 # nothing left ] ] diff --git a/076duplex_list.mu b/076duplex_list.mu index b8db1981..d9f41cb0 100644 --- a/076duplex_list.mu +++ b/076duplex_list.mu @@ -43,42 +43,42 @@ def prev in:address:duplex-list:_elem -> result:address:duplex-list:_elem/contai scenario duplex-list-handling [ run [ - # reserve locations 0, 1 and 2 to check for missing null check - 1:number <- copy 34 - 2:number <- copy 35 - 3:address:duplex-list:character <- push 3, 0 - 3:address:duplex-list:character <- push 4, 3:address:duplex-list:character - 3:address:duplex-list:character <- push 5, 3:address:duplex-list:character - 4:address:duplex-list:character <- copy 3:address:duplex-list:character - 5:character <- first 4:address:duplex-list:character - 4:address:duplex-list:character <- next 4:address:duplex-list:character - 6:character <- first 4:address:duplex-list:character - 4:address:duplex-list:character <- next 4:address:duplex-list:character - 7:character <- first 4:address:duplex-list:character - 8:address:duplex-list:character <- next 4:address:duplex-list:character - 9:character <- first 8:address:duplex-list:character - 10:address:duplex-list:character <- next 8:address:duplex-list:character - 11:address:duplex-list:character <- prev 8:address:duplex-list:character - 4:address:duplex-list:character <- prev 4:address:duplex-list:character - 12:character <- first 4:address:duplex-list:character - 4:address:duplex-list:character <- prev 4:address:duplex-list:character - 13:character <- first 4:address:duplex-list:character - 14:boolean <- equal 3:address:duplex-list:character, 4:address:duplex-list:character + # reserve locations 0-9 to check for missing null check + 10:number/raw <- copy 34 + 11:number/raw <- copy 35 + list:address:duplex-list:character <- push 3, 0 + list <- push 4, list + list <- push 5, list + list2:address:duplex-list:character <- copy list + 20:character/raw <- first list2 + list2 <- next list2 + 21:character/raw <- first list2 + list2 <- next list2 + 22:character/raw <- first list2 + 30:address:duplex-list:character/raw <- next list2 + 31:character/raw <- first 30:address:duplex-list:character/raw + 32:address:duplex-list:character/raw <- next 30:address:duplex-list:character/raw + 33:address:duplex-list:character/raw <- prev 30:address:duplex-list:character/raw + list2 <- prev list2 + 40:character/raw <- first list2 + list2 <- prev list2 + 41:character/raw <- first list2 + 50:boolean/raw <- equal list, list2 ] memory-should-contain [ 0 <- 0 # no modifications to null pointers - 1 <- 34 - 2 <- 35 - 5 <- 5 # scanning next - 6 <- 4 - 7 <- 3 - 8 <- 0 # null - 9 <- 0 # first of null - 10 <- 0 # next of null - 11 <- 0 # prev of null - 12 <- 4 # then start scanning prev - 13 <- 5 - 14 <- 1 # list back at start + 10 <- 34 + 11 <- 35 + 20 <- 5 # scanning next + 21 <- 4 + 22 <- 3 + 30 <- 0 # null + 31 <- 0 # first of null + 32 <- 0 # next of null + 33 <- 0 # prev of null + 40 <- 4 # then start scanning prev + 41 <- 5 + 50 <- 1 # list back at start ] ] @@ -99,109 +99,109 @@ def insert x:_elem, in:address:duplex-list:_elem -> in:address:duplex-list:_elem scenario inserting-into-duplex-list [ run [ - 1:address:duplex-list:character <- push 3, 0 - 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character - 2:address:duplex-list:character <- next 1:address:duplex-list:character # 2 points inside list - 2:address:duplex-list:character <- insert 6, 2:address:duplex-list:character + list:address:duplex-list:character <- push 3, 0 + list <- push 4, list + list <- push 5, list + list2:address:duplex-list:character <- next list # inside list + list2 <- insert 6, list2 # check structure like before - 2:address:duplex-list:character <- copy 1:address:duplex-list:character - 3:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 4:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 5:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 6:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 7:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 8:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 9:character <- first 2:address:duplex-list:character - 10:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character + list2 <- copy list + 10:character/raw <- first list2 + list2 <- next list2 + 11:character/raw <- first list2 + list2 <- next list2 + 12:character/raw <- first list2 + list2 <- next list2 + 13:character/raw <- first list2 + list2 <- prev list2 + 20:character/raw <- first list2 + list2 <- prev list2 + 21:character/raw <- first list2 + list2 <- prev list2 + 22:character/raw <- first list2 + 30:boolean/raw <- equal list, list2 ] memory-should-contain [ - 3 <- 5 # scanning next - 4 <- 4 - 5 <- 6 # inserted element - 6 <- 3 - 7 <- 6 # then prev - 8 <- 4 - 9 <- 5 - 10 <- 1 # list back at start + 10 <- 5 # scanning next + 11 <- 4 + 12 <- 6 # inserted element + 13 <- 3 + 20 <- 6 # then prev + 21 <- 4 + 22 <- 5 + 30 <- 1 # list back at start ] ] scenario inserting-at-end-of-duplex-list [ run [ - 1:address:duplex-list:character <- push 3, 0 - 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character - 2:address:duplex-list:character <- next 1:address:duplex-list:character # 2 points inside list - 2:address:duplex-list:character <- next 2:address:duplex-list:character # now at end of list - 2:address:duplex-list:character <- insert 6, 2:address:duplex-list:character + list:address:duplex-list:character <- push 3, 0 + list <- push 4, list + list <- push 5, list + list2:address:duplex-list:character <- next list # inside list + list2 <- next list2 # now at end of list + list2 <- insert 6, list2 # check structure like before - 2:address:duplex-list:character <- copy 1:address:duplex-list:character - 3:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 4:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 5:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 6:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 7:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 8:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 9:character <- first 2:address:duplex-list:character - 10:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character + list2 <- copy list + 10:character/raw <- first list2 + list2 <- next list2 + 11:character/raw <- first list2 + list2 <- next list2 + 12:character/raw <- first list2 + list2 <- next list2 + 13:character/raw <- first list2 + list2 <- prev list2 + 20:character/raw <- first list2 + list2 <- prev list2 + 21:character/raw <- first list2 + list2 <- prev list2 + 22:character/raw <- first list2 + 30:boolean/raw <- equal list, list2 ] memory-should-contain [ - 3 <- 5 # scanning next - 4 <- 4 - 5 <- 3 - 6 <- 6 # inserted element - 7 <- 3 # then prev - 8 <- 4 - 9 <- 5 - 10 <- 1 # list back at start + 10 <- 5 # scanning next + 11 <- 4 + 12 <- 3 + 13 <- 6 # inserted element + 20 <- 3 # then prev + 21 <- 4 + 22 <- 5 + 30 <- 1 # list back at start ] ] scenario inserting-after-start-of-duplex-list [ run [ - 1:address:duplex-list:character <- push 3, 0 - 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character - 1:address:duplex-list:character <- insert 6, 1:address:duplex-list:character + list:address:duplex-list:character <- push 3, 0 + list <- push 4, list + list <- push 5, list + list <- insert 6, list # check structure like before - 2:address:duplex-list:character <- copy 1:address:duplex-list:character - 3:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 4:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 5:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 6:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 7:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 8:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 9:character <- first 2:address:duplex-list:character - 10:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character + list2:address:duplex-list:character <- copy list + 10:character/raw <- first list2 + list2 <- next list2 + 11:character/raw <- first list2 + list2 <- next list2 + 12:character/raw <- first list2 + list2 <- next list2 + 13:character/raw <- first list2 + list2 <- prev list2 + 20:character/raw <- first list2 + list2 <- prev list2 + 21:character/raw <- first list2 + list2 <- prev list2 + 22:character/raw <- first list2 + 30:boolean/raw <- equal list, list2 ] memory-should-contain [ - 3 <- 5 # scanning next - 4 <- 6 # inserted element - 5 <- 4 - 6 <- 3 - 7 <- 4 # then prev - 8 <- 6 - 9 <- 5 - 10 <- 1 # list back at start + 10 <- 5 # scanning next + 11 <- 6 # inserted element + 12 <- 4 + 13 <- 3 + 20 <- 4 # then prev + 21 <- 6 + 22 <- 5 + 30 <- 1 # list back at start ] ] @@ -237,91 +237,93 @@ def remove x:address:duplex-list:_elem/contained-in:in, in:address:duplex-list:_ scenario removing-from-duplex-list [ run [ - 1:address:duplex-list:character <- push 3, 0 - 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character - 2:address:duplex-list:character <- next 1:address:duplex-list:character # 2 points at second element - 1:address:duplex-list:character <- remove 2:address:duplex-list:character, 1:address:duplex-list:character - 3:boolean <- equal 2:address:duplex-list:character, 0 + list:address:duplex-list:character <- push 3, 0 + list <- push 4, list + list <- push 5, list + list2:address:duplex-list:character <- next list # second element + list <- remove list2, list + 10:boolean/raw <- equal list2, 0 # check structure like before - 2:address:duplex-list:character <- copy 1:address:duplex-list:character - 4:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 5:character <- first 2:address:duplex-list:character - 6:address:duplex-list:character <- next 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 7:character <- first 2:address:duplex-list:character - 8:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character + list2 <- copy list + 11:character/raw <- first list2 + list2 <- next list2 + 12:character/raw <- first list2 + 20:address:duplex-list:character/raw <- next list2 + list2 <- prev list2 + 30:character/raw <- first list2 + 40:boolean/raw <- equal list, list2 ] memory-should-contain [ - 3 <- 0 # remove returned non-null - 4 <- 5 # scanning next, skipping deleted element - 5 <- 3 - 6 <- 0 # no more elements - 7 <- 5 # prev of final element - 8 <- 1 # list back at start + 10 <- 0 # remove returned non-null + 11 <- 5 # scanning next, skipping deleted element + 12 <- 3 + 20 <- 0 # no more elements + 30 <- 5 # prev of final element + 40 <- 1 # list back at start ] ] scenario removing-from-start-of-duplex-list [ run [ - 1:address:duplex-list:character <- push 3, 0 - 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character - 1:address:duplex-list:character <- remove 1:address:duplex-list:character, 1:address:duplex-list:character + list:address:duplex-list:character <- push 3, 0 + list <- push 4, list + list <- push 5, list + list <- remove list, list # check structure like before - 2:address:duplex-list:character <- copy 1:address:duplex-list:character - 3:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 4:character <- first 2:address:duplex-list:character - 5:address:duplex-list:character <- next 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 6:character <- first 2:address:duplex-list:character - 7:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character + list2:address:duplex-list:character <- copy list + 10:character/raw <- first list2 + list2 <- next list2 + 11:character/raw <- first list2 + 20:address:duplex-list:character/raw <- next list2 + list2 <- prev list2 + 30:character/raw <- first list2 + 40:boolean/raw <- equal list, list2 ] memory-should-contain [ - 3 <- 4 # scanning next, skipping deleted element - 4 <- 3 - 5 <- 0 # no more elements - 6 <- 4 # prev of final element - 7 <- 1 # list back at start + 10 <- 4 # scanning next, skipping deleted element + 11 <- 3 + 20 <- 0 # no more elements + 30 <- 4 # prev of final element + 40 <- 1 # list back at start ] ] scenario removing-from-end-of-duplex-list [ run [ - 1:address:duplex-list:character <- push 3, 0 - 1:address:duplex-list:character <- push 4, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 5, 1:address:duplex-list:character + list:address:duplex-list:character <- push 3, 0 + list <- push 4, list + list <- push 5, list # delete last element - 2:address:duplex-list:character <- next 1:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 1:address:duplex-list:character <- remove 2:address:duplex-list:character, 1:address:duplex-list:character - 3:boolean <- equal 2:address:duplex-list:character, 0 + list2:address:duplex-list:character <- next list + list2 <- next list2 + list <- remove list2, list + 10:boolean/raw <- equal list2, 0 # check structure like before - 2:address:duplex-list:character <- copy 1:address:duplex-list:character - 4:character <- first 2:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 5:character <- first 2:address:duplex-list:character - 6:address:duplex-list:character <- next 2:address:duplex-list:character - 2:address:duplex-list:character <- prev 2:address:duplex-list:character - 7:character <- first 2:address:duplex-list:character - 8:boolean <- equal 1:address:duplex-list:character, 2:address:duplex-list:character + list2 <- copy list + 11:character/raw <- first list2 + list2 <- next list2 + 12:character/raw <- first list2 + 20:address:duplex-list:character/raw <- next list2 + list2 <- prev list2 + 30:character/raw <- first list2 + 40:boolean/raw <- equal list, list2 ] memory-should-contain [ - 3 <- 0 # remove returned non-null - 4 <- 5 # scanning next, skipping deleted element - 5 <- 4 - 6 <- 0 # no more elements - 7 <- 5 # prev of final element - 8 <- 1 # list back at start + 10 <- 0 # remove returned non-null + 11 <- 5 # scanning next, skipping deleted element + 12 <- 4 + 20 <- 0 # no more elements + 30 <- 5 # prev of final element + 40 <- 1 # list back at start ] ] scenario removing-from-singleton-list [ run [ - 1:address:duplex-list:character <- push 3, 0 - 1:address:duplex-list:character <- remove 1:address:duplex-list:character, 1:address:duplex-list:character + local-scope + list:address:duplex-list:character <- push 3, 0 + list <- remove list, list + 1:number/raw <- copy list ] memory-should-contain [ 1 <- 0 # back to an empty list @@ -355,116 +357,132 @@ def remove-between start:address:duplex-list:_elem, end:address:duplex-list:_ele scenario remove-range [ # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:duplex-list:character <- push 18, 0 - 1:address:duplex-list:character <- push 17, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 16, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 15, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 14, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 13, 1:address:duplex-list:character + local-scope + list:address:duplex-list:character <- push 18, 0 + list <- push 17, list + list <- push 16, list + list <- push 15, list + list <- push 14, list + list <- push 13, list + 1:address:duplex-list:character/raw <- copy list # save list run [ + local-scope + list:address:duplex-list:character <- copy 1:address:duplex-list:character/raw # restore list # delete 16 onwards # first pointer: to the third element - 2:address:duplex-list:character <- next 1:address:duplex-list:character - 2:address:duplex-list:character <- next 2:address:duplex-list:character - 2:address:duplex-list:character <- remove-between 2:address:duplex-list:character, 0 + list2:address:duplex-list:character <- next list + list2 <- next list2 + list2 <- remove-between list2, 0 # now check the list - 4:character <- get *1:address:duplex-list:character, value:offset - 5:address:duplex-list:character <- next 1:address:duplex-list:character - 6:character <- get *5:address:duplex-list:character, value:offset - 7:address:duplex-list:character <- next 5:address:duplex-list:character - 8:character <- get *7:address:duplex-list:character, value:offset - 9:address:duplex-list:character <- next 7:address:duplex-list:character + 10:character/raw <- get *list, value:offset + list <- next list + 11:character/raw <- get *list, value:offset + list <- next list + 12:character/raw <- get *list, value:offset + 20:address:duplex-list:character/raw <- next list ] memory-should-contain [ - 4 <- 13 - 6 <- 14 - 8 <- 15 - 9 <- 0 + 10 <- 13 + 11 <- 14 + 12 <- 15 + 20 <- 0 ] ] scenario remove-range-to-final [ + local-scope # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:duplex-list:character <- push 18, 0 - 1:address:duplex-list:character <- push 17, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 16, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 15, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 14, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 13, 1:address:duplex-list:character + list:address:duplex-list:character <- push 18, 0 + list <- push 17, list + list <- push 16, list + list <- push 15, list + list <- push 14, list + list <- push 13, list + 1:address:duplex-list:character/raw <- copy list # save list run [ + local-scope + list:address:duplex-list:character <- copy 1:address:duplex-list:character/raw # restore list # delete 15, 16 and 17 # start pointer: to the second element - 2:address:duplex-list:character <- next 1:address:duplex-list:character + list2:address:duplex-list:character <- next list # end pointer: to the last (sixth) element - 3:address:duplex-list:character <- next 2:address:duplex-list:character - 3:address:duplex-list:character <- next 3:address:duplex-list:character - 3:address:duplex-list:character <- next 3:address:duplex-list:character - 3:address:duplex-list:character <- next 3:address:duplex-list:character - remove-between 2:address:duplex-list:character, 3:address:duplex-list:character + end:address:duplex-list:character <- next list2 + end <- next end + end <- next end + end <- next end + remove-between list2, end # now check the list - 4:character <- get *1:address:duplex-list:character, value:offset - 5:address:duplex-list:character <- next 1:address:duplex-list:character - 6:character <- get *5:address:duplex-list:character, value:offset - 7:address:duplex-list:character <- next 5:address:duplex-list:character - 8:character <- get *7:address:duplex-list:character, value:offset - 9:address:duplex-list:character <- next 7:address:duplex-list:character + 10:character/raw <- get *list, value:offset + list <- next list + 11:character/raw <- get *list, value:offset + list <- next list + 12:character/raw <- get *list, value:offset + 20:address:duplex-list:character/raw <- next list ] memory-should-contain [ - 4 <- 13 - 6 <- 14 - 8 <- 18 - 9 <- 0 + 10 <- 13 + 11 <- 14 + 12 <- 18 + 20 <- 0 # no more elements ] ] scenario remove-range-empty [ + local-scope # construct a duplex list with three elements [13, 14, 15] - 1:address:duplex-list:character <- push 15, 0 - 1:address:duplex-list:character <- push 14, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 13, 1:address:duplex-list:character + list:address:duplex-list:character <- push 15, 0 + list <- push 14, list + list <- push 13, list + 1:address:duplex-list:character/raw <- copy list # save list run [ + local-scope + list:address:duplex-list:character <- copy 1:address:duplex-list:character/raw # restore list # delete between first and second element (i.e. nothing) - 2:address:duplex-list:character <- next 1:address:duplex-list:character - remove-between 1:address:duplex-list:character, 2:address:duplex-list:character + list2:address:duplex-list:character <- next list + remove-between list, list2 # now check the list - 4:character <- get *1:address:duplex-list:character, value:offset - 5:address:duplex-list:character <- next 1:address:duplex-list:character - 6:character <- get *5:address:duplex-list:character, value:offset - 7:address:duplex-list:character <- next 5:address:duplex-list:character - 8:character <- get *7:address:duplex-list:character, value:offset - 9:address:duplex-list:character <- next 7:address:duplex-list:character + 10:character/raw <- get *list, value:offset + list <- next list + 11:character/raw <- get *list, value:offset + list <- next list + 12:character/raw <- get *list, value:offset + 20:address:duplex-list:character/raw <- next list ] # no change memory-should-contain [ - 4 <- 13 - 6 <- 14 - 8 <- 15 - 9 <- 0 + 10 <- 13 + 11 <- 14 + 12 <- 15 + 20 <- 0 ] ] scenario remove-range-to-end [ + local-scope # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:duplex-list:character <- push 18, 0 - 1:address:duplex-list:character <- push 17, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 16, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 15, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 14, 1:address:duplex-list:character - 1:address:duplex-list:character <- push 13, 1:address:duplex-list:character + list:address:duplex-list:character <- push 18, 0 + list <- push 17, list + list <- push 16, list + list <- push 15, list + list <- push 14, list + list <- push 13, list + 1:address:duplex-list:character/raw <- copy list # save list run [ + local-scope + list:address:duplex-list:character <- copy 1:address:duplex-list:character/raw # restore list # remove the third element and beyond - 2:address:duplex-list:character <- next 1:address:duplex-list:character - remove-between 2:address:duplex-list:character, 0 + list2:address:duplex-list:character <- next list + remove-between list2, 0 # now check the list - 4:character <- get *1:address:duplex-list:character, value:offset - 5:address:duplex-list:character <- next 1:address:duplex-list:character - 6:character <- get *5:address:duplex-list:character, value:offset - 7:address:duplex-list:character <- next 5:address:duplex-list:character + 10:character/raw <- get *list, value:offset + list <- next list + 11:character/raw <- get *list, value:offset + 20:address:duplex-list:character/raw <- next list ] memory-should-contain [ - 4 <- 13 - 6 <- 14 - 7 <- 0 + 10 <- 13 + 11 <- 14 + 20 <- 0 ] ] diff --git a/079table.mu b/079table.mu index 40b3ff34..4c98cf91 100644 --- a/079table.mu +++ b/079table.mu @@ -3,24 +3,26 @@ scenario table-read-write [ run [ - 1:address:table:number:number <- new-table 30 - put 1:address:table:number:number, 12, 34 - 2:number <- index 1:address:table:number:number, 12 + local-scope + tab:address:table:number:number <- new-table 30 + put-index tab, 12, 34 + 1:number/raw <- index tab, 12 ] memory-should-contain [ - 2 <- 34 + 1 <- 34 ] ] scenario table-read-write-non-integer [ run [ - 1:address:array:character <- new [abc def] - {2: (address table (address array character) number)} <- new-table 30 - put {2: (address table (address array character) number)}, 1:address:array:character, 34 - 3:number <- index {2: (address table (address array character) number)}, 1:address:array:character + local-scope + key:address:array:character <- new [abc def] + {tab: (address table (address array character) number)} <- new-table 30 + put-index tab, key, 34 + 1:number/raw <- index tab, key ] memory-should-contain [ - 3 <- 34 + 1 <- 34 ] ] @@ -44,7 +46,7 @@ def new-table capacity:number -> result:address:table:_key:_value [ *result <- merge 0/length, capacity, data ] -def put table:address:table:_key:_value, key:_key, value:_value -> table:address:table:_key:_value [ +def put-index table:address:table:_key:_value, key:_key, value:_value -> table:address:table:_key:_value [ local-scope load-ingredients hash:number <- hash key diff --git a/081print.mu b/081print.mu index 1d6b1f65..5efafd2b 100644 --- a/081print.mu +++ b/081print.mu @@ -172,162 +172,175 @@ def print screen:address:screen, c:character -> screen:address:screen [ scenario print-character-at-top-left [ run [ - 1:address:screen <- new-fake-screen 3/width, 2/height - 11:character <- copy 97/a - 1:address:screen <- print 1:address:screen, 11:character/a - 2:address:array:screen-cell <- get *1:address:screen, data:offset - 3:array:screen-cell <- copy *2:address:array:screen-cell + local-scope + fake-screen:address:screen <- new-fake-screen 3/width, 2/height + a:character <- copy 97/a + fake-screen <- print fake-screen, a:character + cell:address:array:screen-cell <- get *fake-screen, data:offset + 1:array:screen-cell/raw <- copy *cell ] memory-should-contain [ - 3 <- 6 # width*height - 4 <- 97 # 'a' - 5 <- 7 # white - 6 <- 0 + 1 <- 6 # width*height + 2 <- 97 # 'a' + 3 <- 7 # white + # rest of screen is empty + 4 <- 0 ] ] scenario print-character-in-color [ run [ - 1:address:screen <- new-fake-screen 3/width, 2/height - 11:character <- copy 97/a - 1:address:screen <- print 1:address:screen, 11:character/a, 1/red - 2:address:array:screen-cell <- get *1:address:screen, data:offset - 3:array:screen-cell <- copy *2:address:array:screen-cell + local-scope + fake-screen:address:screen <- new-fake-screen 3/width, 2/height + a:character <- copy 97/a + fake-screen <- print fake-screen, a:character, 1/red + cell:address:array:screen-cell <- get *fake-screen, data:offset + 1:array:screen-cell/raw <- copy *cell ] memory-should-contain [ - 3 <- 6 # width*height - 4 <- 97 # 'a' - 5 <- 1 # red - 6 <- 0 + 1 <- 6 # width*height + 2 <- 97 # 'a' + 3 <- 1 # red + # rest of screen is empty + 4 <- 0 ] ] scenario print-backspace-character [ run [ - 1:address:screen <- new-fake-screen 3/width, 2/height - 11:character <- copy 97/a - 1:address:screen <- print 1:address:screen, 11:character/a - 12:character <- copy 8/backspace - 1:address:screen <- print 1:address:screen, 12:character/backspace - 2:number <- get *1:address:screen, cursor-column:offset - 3:address:array:screen-cell <- get *1:address:screen, data:offset - 4:array:screen-cell <- copy *3:address:array:screen-cell + local-scope + fake-screen:address:screen <- new-fake-screen 3/width, 2/height + a:character <- copy 97/a + fake-screen <- print fake-screen, a + backspace:character <- copy 8/backspace + fake-screen <- print fake-screen, backspace + 10:number/raw <- get *fake-screen, cursor-column:offset + cell:address:array:screen-cell <- get *fake-screen, data:offset + 11:array:screen-cell/raw <- copy *cell ] memory-should-contain [ - 2 <- 0 # cursor column - 4 <- 6 # width*height - 5 <- 32 # space, not 'a' - 6 <- 7 # white - 7 <- 0 + 10 <- 0 # cursor column + 11 <- 6 # width*height + 12 <- 32 # space, not 'a' + 13 <- 7 # white + # rest of screen is empty + 14 <- 0 ] ] scenario print-extra-backspace-character [ run [ - 1:address:screen <- new-fake-screen 3/width, 2/height - 11:character <- copy 97/a - 1:address:screen <- print 1:address:screen, 11:character/a - 12:character <- copy 8/backspace - 1:address:screen <- print 1:address:screen, 12:character/backspace - 12:character <- copy 8/backspace - 1:address:screen <- print 1:address:screen, 12:character/backspace - 2:number <- get *1:address:screen, cursor-column:offset - 3:address:array:screen-cell <- get *1:address:screen, data:offset - 4:array:screen-cell <- copy *3:address:array:screen-cell + local-scope + fake-screen:address:screen <- new-fake-screen 3/width, 2/height + a:character <- copy 97/a + fake-screen <- print fake-screen, a + backspace:character <- copy 8/backspace + fake-screen <- print fake-screen, backspace + fake-screen <- print fake-screen, backspace + 1:number/raw <- get *fake-screen, cursor-column:offset + cell:address:array:screen-cell <- get *fake-screen, data:offset + 3:array:screen-cell/raw <- copy *cell ] memory-should-contain [ - 2 <- 0 # cursor column - 4 <- 6 # width*height - 5 <- 32 # space, not 'a' - 6 <- 7 # white - 7 <- 0 + 1 <- 0 # cursor column + 3 <- 6 # width*height + 4 <- 32 # space, not 'a' + 5 <- 7 # white + # rest of screen is empty + 6 <- 0 ] ] scenario print-character-at-right-margin [ run [ - 1:address:screen <- new-fake-screen 2/width, 2/height - 11:character <- copy 97/a - 1:address:screen <- print 1:address:screen, 11:character/a - 12:character <- copy 98/b - 1:address:screen <- print 1:address:screen, 12:character/b - 13:character <- copy 99/b - 1:address:screen <- print 1:address:screen, 13:character/c - 2:number <- get *1:address:screen, cursor-column:offset - 3:address:array:screen-cell <- get *1:address:screen, data:offset - 4:array:screen-cell <- copy *3:address:array:screen-cell + local-scope + fake-screen:address:screen <- new-fake-screen 2/width, 2/height + a:character <- copy 97/a + fake-screen <- print fake-screen, a + b:character <- copy 98/b + fake-screen <- print fake-screen, b + c:character <- copy 99/c + fake-screen <- print fake-screen, c + 10:number/raw <- get *fake-screen, cursor-column:offset + cell:address:array:screen-cell <- get *fake-screen, data:offset + 11:array:screen-cell/raw <- copy *cell ] memory-should-contain [ - 2 <- 1 # cursor column - 4 <- 4 # width*height - 5 <- 97 # 'a' - 6 <- 7 # white - 7 <- 99 # 'c' over 'b' - 8 <- 7 # white - 9 <- 0 + 10 <- 1 # cursor column + 11 <- 4 # width*height + 12 <- 97 # 'a' + 13 <- 7 # white + 14 <- 99 # 'c' over 'b' + 15 <- 7 # white + # rest of screen is empty + 16 <- 0 ] ] scenario print-newline-character [ run [ - 1:address:screen <- new-fake-screen 3/width, 2/height - 10:character <- copy 10/newline - 11:character <- copy 97/a - 1:address:screen <- print 1:address:screen, 11:character/a - 1:address:screen <- print 1:address:screen, 10:character/newline - 2:number <- get *1:address:screen, cursor-row:offset - 3:number <- get *1:address:screen, cursor-column:offset - 4:address:array:screen-cell <- get *1:address:screen, data:offset - 5:array:screen-cell <- copy *4:address:array:screen-cell + local-scope + fake-screen:address:screen <- new-fake-screen 3/width, 2/height + newline:character <- copy 10/newline + a:character <- copy 97/a + fake-screen <- print fake-screen, a + fake-screen <- print fake-screen, newline + 10:number/raw <- get *fake-screen, cursor-row:offset + 11:number/raw <- get *fake-screen, cursor-column:offset + cell:address:array:screen-cell <- get *fake-screen, data:offset + 12:array:screen-cell/raw <- copy *cell ] memory-should-contain [ - 2 <- 1 # cursor row - 3 <- 0 # cursor column - 5 <- 6 # width*height - 6 <- 97 # 'a' - 7 <- 7 # white - 8 <- 0 + 10 <- 1 # cursor row + 11 <- 0 # cursor column + 12 <- 6 # width*height + 13 <- 97 # 'a' + 14 <- 7 # white + # rest of screen is empty + 15 <- 0 ] ] scenario print-newline-at-bottom-line [ run [ - 1:address:screen <- new-fake-screen 3/width, 2/height - 10:character <- copy 10/newline - 1:address:screen <- print 1:address:screen, 10:character/newline - 1:address:screen <- print 1:address:screen, 10:character/newline - 1:address:screen <- print 1:address:screen, 10:character/newline - 2:number <- get *1:address:screen, cursor-row:offset - 3:number <- get *1:address:screen, cursor-column:offset + local-scope + fake-screen:address:screen <- new-fake-screen 3/width, 2/height + newline:character <- copy 10/newline + fake-screen <- print fake-screen, newline + fake-screen <- print fake-screen, newline + fake-screen <- print fake-screen, newline + 10:number/raw <- get *fake-screen, cursor-row:offset + 11:number/raw <- get *fake-screen, cursor-column:offset ] memory-should-contain [ - 2 <- 1 # cursor row - 3 <- 0 # cursor column + 10 <- 1 # cursor row + 11 <- 0 # cursor column ] ] scenario print-character-at-bottom-right [ run [ - 1:address:screen <- new-fake-screen 2/width, 2/height - 10:character <- copy 10/newline - 1:address:screen <- print 1:address:screen, 10:character/newline - 11:character <- copy 97/a - 1:address:screen <- print 1:address:screen, 11:character/a - 12:character <- copy 98/b - 1:address:screen <- print 1:address:screen, 12:character/b - 13:character <- copy 99/c - 1:address:screen <- print 1:address:screen, 13:character/c - 1:address:screen <- print 1:address:screen, 10:character/newline - 14:character <- copy 100/d - 1:address:screen <- print 1:address:screen, 14:character/d - 2:number <- get *1:address:screen, cursor-row:offset - 3:number <- get *1:address:screen, cursor-column:offset - 4:address:array:screen-cell <- get *1:address:screen, data:offset - 20:array:screen-cell <- copy *4:address:array:screen-cell + local-scope + fake-screen:address:screen <- new-fake-screen 2/width, 2/height + newline:character <- copy 10/newline + fake-screen <- print fake-screen, newline + a:character <- copy 97/a + fake-screen <- print fake-screen, a + b:character <- copy 98/b + fake-screen <- print fake-screen, b + c:character <- copy 99/c + fake-screen <- print fake-screen, c + fake-screen <- print fake-screen, newline + d:character <- copy 100/d + fake-screen <- print fake-screen, d + 10:number/raw <- get *fake-screen, cursor-row:offset + 11:number/raw <- get *fake-screen, cursor-column:offset + cell:address:array:screen-cell <- get *fake-screen, data:offset + 20:array:screen-cell/raw <- copy *cell ] memory-should-contain [ - 2 <- 1 # cursor row - 3 <- 1 # cursor column + 10 <- 1 # cursor row + 11 <- 1 # cursor column 20 <- 4 # width*height 21 <- 0 # unused 22 <- 7 # white @@ -337,6 +350,7 @@ scenario print-character-at-bottom-right [ 26 <- 7 # white 27 <- 100 # 'd' over 'b' and 'c' and newline 28 <- 7 # white + # rest of screen is empty 29 <- 0 ] ] @@ -417,32 +431,33 @@ def move-cursor screen:address:screen, new-row:number, new-column:number -> scre scenario clear-line-erases-printed-characters [ run [ - 1:address:screen <- new-fake-screen 3/width, 2/height + local-scope + fake-screen:address:screen <- new-fake-screen 3/width, 2/height # print a character - 10:character <- copy 97/a - 1:address:screen <- print 1:address:screen, 10:character/a + a:character <- copy 97/a + fake-screen <- print fake-screen, a # move cursor to start of line - 1:address:screen <- move-cursor 1:address:screen, 0/row, 0/column + fake-screen <- move-cursor fake-screen, 0/row, 0/column # clear line - 1:address:screen <- clear-line 1:address:screen - 2:address:array:screen-cell <- get *1:address:screen, data:offset - 20:array:screen-cell <- copy *2:address:array:screen-cell + fake-screen <- clear-line fake-screen + cell:address:array:screen-cell <- get *fake-screen, data:offset + 10:array:screen-cell/raw <- copy *cell ] # screen should be blank memory-should-contain [ - 20 <- 6 # width*height + 10 <- 6 # width*height + 11 <- 0 + 12 <- 7 + 13 <- 0 + 14 <- 7 + 15 <- 0 + 16 <- 7 + 17 <- 0 + 18 <- 7 + 19 <- 0 + 20 <- 7 21 <- 0 22 <- 7 - 23 <- 0 - 24 <- 7 - 25 <- 0 - 26 <- 7 - 27 <- 0 - 28 <- 7 - 29 <- 0 - 30 <- 7 - 31 <- 0 - 32 <- 7 ] ] @@ -657,21 +672,23 @@ def print screen:address:screen, s:address:array:character -> screen:address:scr scenario print-text-stops-at-right-margin [ run [ - 1:address:screen <- new-fake-screen 3/width, 2/height - 2:address:array:character <- new [abcd] - 1:address:screen <- print 1:address:screen, 2:address:array:character - 3:address:array:screen-cell <- get *1:address:screen, data:offset - 4:array:screen-cell <- copy *3:address:array:screen-cell + local-scope + fake-screen:address:screen <- new-fake-screen 3/width, 2/height + s:address:array:character <- new [abcd] + fake-screen <- print fake-screen, s:address:array:character + cell:address:array:screen-cell <- get *fake-screen, data:offset + 10:array:screen-cell/raw <- copy *cell ] memory-should-contain [ - 4 <- 6 # width*height - 5 <- 97 # 'a' - 6 <- 7 # white - 7 <- 98 # 'b' - 8 <- 7 # white - 9 <- 100 # 'd' overwrites 'c' - 10 <- 7 # white - 11 <- 0 # unused + 10 <- 6 # width*height + 11 <- 97 # 'a' + 12 <- 7 # white + 13 <- 98 # 'b' + 14 <- 7 # white + 15 <- 100 # 'd' overwrites 'c' + 16 <- 7 # white + # rest of screen is empty + 17 <- 0 ] ] |