diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-07-28 14:33:22 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-07-28 14:33:22 -0700 |
commit | bc6436927640603675e2e700007f53c5ab213869 (patch) | |
tree | e8f76a871ac4118223e03015f32e6bd687a7bd49 /061channel.mu | |
parent | aa0888459fc2ca41b0ad6bef5bfa72223ca33945 (diff) | |
download | mu-bc6436927640603675e2e700007f53c5ab213869.tar.gz |
1868 - start using naked literals everywhere
First step to reducing typing burden. Next step: inferring types.
Diffstat (limited to '061channel.mu')
-rw-r--r-- | 061channel.mu | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/061channel.mu b/061channel.mu index 2a839898..d1f4c55d 100644 --- a/061channel.mu +++ b/061channel.mu @@ -10,8 +10,8 @@ scenario channel [ run [ - 1:address:channel <- new-channel 3:literal/capacity - 1:address:channel <- write 1:address:channel, 34:literal + 1:address:channel <- new-channel 3/capacity + 1:address:channel <- write 1:address:channel, 34 2:number, 1:address:channel <- read 1:address:channel ] memory-should-contain [ @@ -38,13 +38,13 @@ recipe new-channel [ result:address:channel <- new channel:type # result.first-full = 0 full:address:number <- get-address result:address:channel/deref, first-full:offset - full:address:number/deref <- copy 0:literal + full:address:number/deref <- copy 0 # result.first-free = 0 free:address:number <- get-address result:address:channel/deref, first-free:offset - free:address:number/deref <- copy 0:literal + free:address:number/deref <- copy 0 # result.data = new location[ingredient+1] capacity:number <- next-ingredient - capacity:number <- add capacity:number, 1:literal # unused slot for 'full?' below + capacity:number <- add capacity:number, 1 # 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 reply result:address:channel @@ -68,13 +68,13 @@ recipe write [ dest:address:location <- index-address circular-buffer:address:array:location/deref, free:address:number/deref dest:address:location/deref <- copy val:location # increment free - free:address:number/deref <- add free:address:number/deref, 1:literal + free:address:number/deref <- add free:address:number/deref, 1 { # wrap free around to 0 if necessary len:number <- length circular-buffer:address:array:location/deref at-end?:boolean <- greater-or-equal free:address:number/deref, len:number break-unless at-end?:boolean - free:address:number/deref <- copy 0:literal + free:address:number/deref <- copy 0 } reply chan:address:channel/same-as-ingredient:0 ] @@ -95,13 +95,13 @@ recipe read [ circular-buffer:address:array:location <- get chan:address:channel/deref, data:offset result:location <- index circular-buffer:address:array:location/deref, full:address:number/deref # increment full - full:address:number/deref <- add full:address:number/deref, 1:literal + full:address:number/deref <- add full:address:number/deref, 1 { # wrap full around to 0 if necessary len:number <- length circular-buffer:address:array:location/deref at-end?:boolean <- greater-or-equal full:address:number/deref, len:number break-unless at-end?:boolean - full:address:number/deref <- copy 0:literal + full:address:number/deref <- copy 0 } reply result:location, chan:address:channel/same-as-ingredient:0 ] @@ -119,7 +119,7 @@ recipe clear-channel [ scenario channel-initialization [ run [ - 1:address:channel <- new-channel 3:literal/capacity + 1:address:channel <- new-channel 3/capacity 2:number <- get 1:address:channel/deref, first-full:offset 3:number <- get 1:address:channel/deref, first-free:offset ] @@ -131,8 +131,8 @@ scenario channel-initialization [ scenario channel-write-increments-free [ run [ - 1:address:channel <- new-channel 3:literal/capacity - 1:address:channel <- write 1:address:channel, 34:literal + 1:address:channel <- new-channel 3/capacity + 1:address:channel <- write 1:address:channel, 34 2:number <- get 1:address:channel/deref, first-full:offset 3:number <- get 1:address:channel/deref, first-free:offset ] @@ -144,8 +144,8 @@ scenario channel-write-increments-free [ scenario channel-read-increments-full [ run [ - 1:address:channel <- new-channel 3:literal/capacity - 1:address:channel <- write 1:address:channel, 34:literal + 1:address:channel <- new-channel 3/capacity + 1:address:channel <- write 1:address:channel, 34 _, 1:address:channel <- read 1:address:channel 2:number <- get 1:address:channel/deref, first-full:offset 3:number <- get 1:address:channel/deref, first-free:offset @@ -159,15 +159,15 @@ scenario channel-read-increments-full [ scenario channel-wrap [ run [ # channel with just 1 slot - 1:address:channel <- new-channel 1:literal/capacity + 1:address:channel <- new-channel 1/capacity # write and read a value - 1:address:channel <- write 1:address:channel, 34:literal + 1:address:channel <- write 1:address:channel, 34 _, 1:address:channel <- read 1:address:channel # first-free will now be 1 2:number <- get 1:address:channel/deref, first-free:offset 3:number <- get 1:address:channel/deref, first-free:offset # write second value, verify that first-free wraps - 1:address:channel <- write 1:address:channel, 34:literal + 1:address:channel <- write 1:address:channel, 34 4:number <- get 1:address:channel/deref, first-free:offset # read second value, verify that first-full wraps _, 1:address:channel <- read 1:address:channel @@ -201,13 +201,13 @@ recipe channel-full? [ 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 + tmp:number <- add tmp:number, 1 { # if tmp == chan.capacity, tmp = 0 len:number <- channel-capacity chan:address:channel at-end?:boolean <- greater-or-equal tmp:number, len:number break-unless at-end?:boolean - tmp:number <- copy 0:literal + tmp:number <- copy 0 } # return chan.first-full == tmp full:number <- get chan:address:channel/deref, first-full:offset @@ -226,7 +226,7 @@ recipe channel-capacity [ scenario channel-new-empty-not-full [ run [ - 1:address:channel <- new-channel 3:literal/capacity + 1:address:channel <- new-channel 3/capacity 2:boolean <- channel-empty? 1:address:channel 3:boolean <- channel-full? 1:address:channel ] @@ -238,8 +238,8 @@ scenario channel-new-empty-not-full [ scenario channel-write-not-empty [ run [ - 1:address:channel <- new-channel 3:literal/capacity - 1:address:channel <- write 1:address:channel, 34:literal + 1:address:channel <- new-channel 3/capacity + 1:address:channel <- write 1:address:channel, 34 2:boolean <- channel-empty? 1:address:channel 3:boolean <- channel-full? 1:address:channel ] @@ -251,8 +251,8 @@ scenario channel-write-not-empty [ scenario channel-write-full [ run [ - 1:address:channel <- new-channel 1:literal/capacity - 1:address:channel <- write 1:address:channel, 34:literal + 1:address:channel <- new-channel 1/capacity + 1:address:channel <- write 1:address:channel, 34 2:boolean <- channel-empty? 1:address:channel 3:boolean <- channel-full? 1:address:channel ] @@ -264,8 +264,8 @@ scenario channel-write-full [ scenario channel-read-not-full [ run [ - 1:address:channel <- new-channel 1:literal/capacity - 1:address:channel <- write 1:address:channel, 34:literal + 1:address:channel <- new-channel 1/capacity + 1:address:channel <- write 1:address:channel, 34 _, 1:address:channel <- read 1:address:channel 2:boolean <- channel-empty? 1:address:channel 3:boolean <- channel-full? 1:address:channel @@ -286,7 +286,7 @@ recipe buffer-lines [ out:address:channel <- next-ingredient # repeat forever { - line:address:buffer <- new-buffer, 30:literal + line:address:buffer <- new-buffer, 30 # read characters from 'in' until newline, copy into line { +next-character @@ -294,7 +294,7 @@ recipe buffer-lines [ # drop a character on backspace { # special-case: if it's a backspace - backspace?:boolean <- equal c:character, 8:literal + backspace?:boolean <- equal c:character, 8 break-unless backspace?:boolean # drop previous character #? close-console #? 2 @@ -302,23 +302,23 @@ recipe buffer-lines [ #? ] #? 1 { buffer-length:address:number <- get-address line:address:buffer/deref, length:offset - buffer-empty?:boolean <- equal buffer-length:address:number/deref, 0:literal + buffer-empty?:boolean <- equal buffer-length:address:number/deref, 0 break-if buffer-empty?:boolean -#? $print [before: ], buffer-length:address:number/deref, 10:literal/newline - buffer-length:address:number/deref <- subtract buffer-length:address:number/deref, 1:literal -#? $print [after: ], buffer-length:address:number/deref, 10:literal/newline +#? $print [before: ], buffer-length:address:number/deref, 10/newline + buffer-length:address:number/deref <- subtract buffer-length:address:number/deref, 1 +#? $print [after: ], buffer-length:address:number/deref, 10/newline } #? $exit #? 2 # and don't append this one loop +next-character:label } # append anything else -#? $print [buffer-lines: appending ], c:character, 10:literal/newline +#? $print [buffer-lines: appending ], c:character, 10/newline line:address:buffer <- buffer-append line:address:buffer, c:character - line-done?:boolean <- equal c:character, 10:literal/newline + line-done?:boolean <- equal c:character, 10/newline break-if line-done?:boolean # stop buffering on eof (currently only generated by fake console) - eof?:boolean <- equal c:character, 0:literal/eof + eof?:boolean <- equal c:character, 0/eof break-if eof?:boolean loop } @@ -326,7 +326,7 @@ recipe buffer-lines [ # copy line into 'out' #? $print [buffer-lines: emitting #? ] - i:number <- copy 0:literal + i:number <- copy 0 line-contents:address:array:character <- get line:address:buffer/deref, data:offset max:number <- get line:address:buffer/deref, length:offset { @@ -334,8 +334,8 @@ recipe buffer-lines [ break-if done?:boolean c:character <- index line-contents:address:array:character/deref, i:number out:address:channel <- write out:address:channel, c:character -#? $print [writing ], i:number, [: ], c:character, 10:literal/newline - i:number <- add i:number, 1:literal +#? $print [writing ], i:number, [: ], c:character, 10/newline + i:number <- add i:number, 1 loop } #? $dump-trace #? 1 @@ -347,8 +347,8 @@ recipe buffer-lines [ scenario buffer-lines-blocks-until-newline [ run [ - 1:address:channel/stdin <- new-channel 10:literal/capacity - 2:address:channel/buffered-stdin <- new-channel 10:literal/capacity + 1:address:channel/stdin <- new-channel 10/capacity + 2:address:channel/buffered-stdin <- new-channel 10/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] @@ -359,21 +359,21 @@ F buffer-lines-blocks-until-newline: channel should be empty after init] assert 5:boolean, [ 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 + 1:address:channel <- write 1:address:channel, 97/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'] # write 'b' - 1:address:channel <- write 1:address:channel, 98:literal/b + 1:address:channel <- write 1:address:channel, 98/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'] # write newline - 1:address:channel <- write 1:address:channel, 10:literal/newline + 1:address:channel <- write 1:address:channel, 10/newline restart 4:number/buffer-routine wait-for-routine 4:number/buffer-routine 8:boolean <- channel-empty? 2:address:channel/buffered-stdin |