From c5ffb6e1cc9c5ff880d037c53b8ebc8562be0008 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 25 May 2015 22:27:19 -0700 Subject: 1459 --- html/061channel.mu.html | 88 +++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 43 deletions(-) (limited to 'html/061channel.mu.html') diff --git a/html/061channel.mu.html b/html/061channel.mu.html index 51ec7f2b..1054ee7b 100644 --- a/html/061channel.mu.html +++ b/html/061channel.mu.html @@ -2,7 +2,7 @@ -~/Desktop/s/mu/061channel.mu +061channel.mu @@ -14,6 +14,8 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .CommentedCode { color: #6c6c6c; } +.muRecipe { color: #ff8700; } +.muScenario { color: #00af00; } .Delimiter { color: #c000c0; } .Comment { color: #8080ff; } .Constant { color: #008080; } @@ -41,7 +43,7 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } # from an empty one will put the current routine in 'waiting' state until the # operation can be completed. -scenario channel [ +scenario channel [ run [ 1:address:channel <- init-channel 3:literal/capacity 1:address:channel <- write 1:address:channel, 34:literal @@ -65,8 +67,8 @@ container channel [ ] # result:address:channel <- init-channel capacity:number -recipe init-channel [ - default-space:address:array:location <- new location:type, 30:literal +recipe init-channel [ + default-space:address:array:location <- new location:type, 30:literal # result = new channel result:address:channel <- new channel:type # result.first-full = 0 @@ -76,7 +78,7 @@ recipe init-channel [ free:address:number <- get-address result:address:channel/deref, first-free:offset free:address:number/deref <- copy 0:literal # result.data = new location[ingredient+1] - capacity:number <- next-ingredient + capacity:number <- next-ingredient capacity:number <- add capacity:number, 1:literal # unused slot for 'full?' below dest:address:address:array:location <- get-address result:address:channel/deref, data:offset dest:address:address:array:location/deref <- new location:type, capacity:number @@ -84,10 +86,10 @@ recipe init-channel [ ] # chan:address:channel <- write chan:address:channel, val:location -recipe write [ - default-space:address:array:location <- new location:type, 30:literal - chan:address:channel <- next-ingredient - val:location <- next-ingredient +recipe write [ + default-space:address:array:location <- new location:type, 30:literal + chan:address:channel <- next-ingredient + val:location <- next-ingredient { # block if chan is full full:boolean <- channel-full? chan:address:channel @@ -113,9 +115,9 @@ recipe write [ ] # result:location, chan:address:channel <- read chan:address:channel -recipe read [ - default-space:address:array:location <- new location:type, 30:literal - chan:address:channel <- next-ingredient +recipe read [ + default-space:address:array:location <- new location:type, 30:literal + chan:address:channel <- next-ingredient { # block if chan is empty empty:boolean <- channel-empty? chan:address:channel @@ -139,9 +141,9 @@ recipe read [ reply result:location, chan:address:channel/same-as-ingredient:0 ] -recipe clear-channel [ - default-space:address:address:array:location <- new location:type, 30:literal - chan:address:channel <- next-ingredient +recipe clear-channel [ + default-space:address:address:array:location <- new location:type, 30:literal + chan:address:channel <- next-ingredient { empty?:boolean <- channel-empty? chan:address:channel break-if empty?:boolean @@ -150,7 +152,7 @@ recipe clear-channel [ reply chan:address:channel/same-as-ingredient:0 ] -scenario channel-initialization [ +scenario channel-initialization [ run [ 1:address:channel <- init-channel 3:literal/capacity 2:number <- get 1:address:channel/deref, first-full:offset @@ -162,7 +164,7 @@ scenario channel-initialization [ ] ] -scenario channel-write-increments-free [ +scenario channel-write-increments-free [ run [ 1:address:channel <- init-channel 3:literal/capacity 1:address:channel <- write 1:address:channel, 34:literal @@ -175,7 +177,7 @@ scenario channel-write-increments-free [ ] ] -scenario channel-read-increments-full [ +scenario channel-read-increments-full [ run [ 1:address:channel <- init-channel 3:literal/capacity 1:address:channel <- write 1:address:channel, 34:literal @@ -189,7 +191,7 @@ scenario channel-read-increments-full [ ] ] -scenario channel-wrap [ +scenario channel-wrap [ run [ # channel with just 1 slot 1:address:channel <- init-channel 1:literal/capacity @@ -217,9 +219,9 @@ scenario channel-wrap [ ## helpers # An empty channel has first-empty and first-full both at the same value. -recipe channel-empty? [ - default-space:address:array:location <- new location:type, 30:literal - chan:address:channel <- next-ingredient +recipe channel-empty? [ + default-space:address:array:location <- new location:type, 30:literal + chan:address:channel <- next-ingredient # return chan.first-full == chan.first-free full:number <- get chan:address:channel/deref, first-full:offset free:number <- get chan:address:channel/deref, first-free:offset @@ -229,9 +231,9 @@ recipe channel-empty? [ # A full channel has first-empty just before first-full, wasting one slot. # (Other alternatives: https://en.wikipedia.org/wiki/Circular_buffer#Full_.2F_Empty_Buffer_Distinction) -recipe channel-full? [ - default-space:address:array:location <- new location:type, 30:literal - chan:address:channel <- next-ingredient +recipe channel-full? [ + default-space:address:array:location <- new location:type, 30:literal + chan:address:channel <- next-ingredient # tmp = chan.first-free + 1 tmp:number <- get chan:address:channel/deref, first-free:offset tmp:number <- add tmp:number, 1:literal @@ -249,15 +251,15 @@ recipe channel-full? [ ] # result:number <- channel-capacity chan:address:channel -recipe channel-capacity [ - default-space:address:array:location <- new location:type, 30:literal - chan:address:channel <- next-ingredient +recipe channel-capacity [ + default-space:address:array:location <- new location:type, 30:literal + chan:address:channel <- next-ingredient q:address:array:location <- get chan:address:channel/deref, data:offset result:number <- length q:address:array:location/deref reply result:number ] -scenario channel-new-empty-not-full [ +scenario channel-new-empty-not-full [ run [ 1:address:channel <- init-channel 3:literal/capacity 2:boolean <- channel-empty? 1:address:channel @@ -269,7 +271,7 @@ scenario channel-new-empty-not-full [ ] ] -scenario channel-write-not-empty [ +scenario channel-write-not-empty [ run [ 1:address:channel <- init-channel 3:literal/capacity 1:address:channel <- write 1:address:channel, 34:literal @@ -282,7 +284,7 @@ scenario channel-write-not-empty [ ] ] -scenario channel-write-full [ +scenario channel-write-full [ run [ 1:address:channel <- init-channel 1:literal/capacity 1:address:channel <- write 1:address:channel, 34:literal @@ -295,7 +297,7 @@ scenario channel-write-full [ ] ] -scenario channel-read-not-full [ +scenario channel-read-not-full [ run [ 1:address:channel <- init-channel 1:literal/capacity 1:address:channel <- write 1:address:channel, 34:literal @@ -311,12 +313,12 @@ scenario channel-read-not-full [ # helper for channels of characters in particular # out:address:channel <- buffer-lines in:address:channel, out:address:channel -recipe buffer-lines [ - default-space:address:address:array:location <- new location:type, 30:literal +recipe buffer-lines [ + default-space:address:address:array:location <- new location:type, 30:literal #? $print [buffer-lines: aaa #? ] - in:address:channel <- next-ingredient - out:address:channel <- next-ingredient + in:address:channel <- next-ingredient + out:address:channel <- next-ingredient # repeat forever { line:address:buffer <- init-buffer, 30:literal @@ -382,33 +384,33 @@ recipe buffer-lines [ reply out:address:channel/same-as-ingredient:1 ] -scenario buffer-lines-blocks-until-newline [ +scenario buffer-lines-blocks-until-newline [ run [ 1:address:channel/stdin <- init-channel 10:literal/capacity 2:address:channel/buffered-stdin <- init-channel 10:literal/capacity 3:boolean <- channel-empty? 2:address:channel/buffered-stdin assert 3:boolean, [ -F buffer-lines-blocks-until-newline: channel should be empty after init] +F buffer-lines-blocks-until-newline: channel should be empty after init] # buffer stdin into buffered-stdin, try to read from buffered-stdin - 4:number/buffer-routine <- start-running buffer-lines:recipe, 1:address:channel/stdin, 2:address:channel/buffered-stdin + 4:number/buffer-routine <- start-running buffer-lines:recipe, 1:address:channel/stdin, 2:address:channel/buffered-stdin wait-for-routine 4:number/buffer-routine 5:boolean <- channel-empty? 2:address:channel/buffered-stdin assert 5:boolean, [ -F buffer-lines-blocks-until-newline: channel should be empty after buffer-lines bring-up] +F buffer-lines-blocks-until-newline: channel should be empty after buffer-lines bring-up] # write 'a' 1:address:channel <- write 1:address:channel, 97:literal/a restart 4:number/buffer-routine wait-for-routine 4:number/buffer-routine 6:boolean <- channel-empty? 2:address:channel/buffered-stdin assert 6:boolean, [ -F buffer-lines-blocks-until-newline: channel should be empty after writing 'a'] +F buffer-lines-blocks-until-newline: channel should be empty after writing 'a'] # write 'b' 1:address:channel <- write 1:address:channel, 98:literal/b restart 4:number/buffer-routine wait-for-routine 4:number/buffer-routine 7:boolean <- channel-empty? 2:address:channel/buffered-stdin assert 7:boolean, [ -F buffer-lines-blocks-until-newline: channel should be empty after writing 'b'] +F buffer-lines-blocks-until-newline: channel should be empty after writing 'b'] # write newline 1:address:channel <- write 1:address:channel, 10:literal/newline restart 4:number/buffer-routine @@ -416,7 +418,7 @@ F buffer-lines-blocks-until-newline: channel should be empty after writing <- channel-empty? 2:address:channel/buffered-stdin 9:boolean/completed? <- not 8:boolean assert 9:boolean/completed?, [ -F buffer-lines-blocks-until-newline: channel should contain data after writing newline] +F buffer-lines-blocks-until-newline: channel should contain data after writing newline] trace [test], [reached end] ] trace-should-contain [ -- cgit 1.4.1-2-gfad0