diff options
Diffstat (limited to '070text.mu')
-rw-r--r-- | 070text.mu | 442 |
1 files changed, 221 insertions, 221 deletions
diff --git a/070text.mu b/070text.mu index 93fe3f41..49317557 100644 --- a/070text.mu +++ b/070text.mu @@ -2,27 +2,27 @@ # to-text-line gets called implicitly in various places # define it to be identical to 'to-text' by default -def to-text-line x:_elem -> y:address:shared:array:character [ +def to-text-line x:_elem -> y:address:array:character [ local-scope load-ingredients y <- to-text x ] # variant for arrays (since we can't pass them around otherwise) -def array-to-text-line x:address:shared:array:_elem -> y:address:shared:array:character [ +def array-to-text-line x:address:array:_elem -> y:address:array:character [ local-scope load-ingredients y <- to-text *x ] # to-text on text is just the identity function -def to-text x:address:shared:array:character -> y:address:shared:array:character [ +def to-text x:address:array:character -> y:address:array:character [ local-scope load-ingredients return x ] -def equal a:address:shared:array:character, b:address:shared:array:character -> result:boolean [ +def equal a:address:array:character, b:address:array:character -> result:boolean [ local-scope load-ingredients a-len:number <- length *a @@ -55,8 +55,8 @@ def equal a:address:shared:array:character, b:address:shared:array:character -> scenario text-equal-reflexive [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [abc] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [abc] 3:boolean/raw <- equal x, x ] memory-should-contain [ @@ -66,9 +66,9 @@ scenario text-equal-reflexive [ scenario text-equal-identical [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [abc] - y:address:shared:array:character <- new [abc] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [abc] + y:address:array:character <- new [abc] 3:boolean/raw <- equal x, y ] memory-should-contain [ @@ -78,9 +78,9 @@ scenario text-equal-identical [ scenario text-equal-distinct-lengths [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [abc] - y:address:shared:array:character <- new [abcd] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [abc] + y:address:array:character <- new [abcd] 3:boolean/raw <- equal x, y ] memory-should-contain [ @@ -96,9 +96,9 @@ scenario text-equal-distinct-lengths [ scenario text-equal-with-empty [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [] - y:address:shared:array:character <- new [abcd] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [] + y:address:array:character <- new [abcd] 3:boolean/raw <- equal x, y ] memory-should-contain [ @@ -108,9 +108,9 @@ scenario text-equal-with-empty [ scenario text-equal-common-lengths-but-distinct [ run [ - default-space:address:shared:array:location <- new location:type, 30 - x:address:shared:array:character <- new [abc] - y:address:shared:array:character <- new [abd] + default-space:address:array:location <- new location:type, 30 + x:address:array:character <- new [abc] + y:address:array:character <- new [abd] 3:boolean/raw <- equal x, y ] memory-should-contain [ @@ -121,27 +121,27 @@ scenario text-equal-common-lengths-but-distinct [ # A new type to help incrementally construct texts. container buffer [ length:number - data:address:shared:array:character + data:address:array:character ] -def new-buffer capacity:number -> result:address:shared:buffer [ +def new-buffer capacity:number -> result:address:buffer [ local-scope load-ingredients result <- new buffer:type *result <- put *result, length:offset, 0 - data:address:shared:array:character <- new character:type, capacity + data:address:array:character <- new character:type, capacity *result <- put *result, data:offset, data return result ] -def grow-buffer in:address:shared:buffer -> in:address:shared:buffer [ +def grow-buffer in:address:buffer -> in:address:buffer [ local-scope load-ingredients # double buffer size - olddata:address:shared:array:character <- get *in, data:offset + olddata:address:array:character <- get *in, data:offset oldlen:number <- length *olddata newlen:number <- multiply oldlen, 2 - newdata:address:shared:array:character <- new character:type, newlen + newdata:address:array:character <- new character:type, newlen *in <- put *in, data:offset, newdata # copy old contents i:number <- copy 0 @@ -155,20 +155,20 @@ def grow-buffer in:address:shared:buffer -> in:address:shared:buffer [ } ] -def buffer-full? in:address:shared:buffer -> result:boolean [ +def buffer-full? in:address:buffer -> result:boolean [ local-scope load-ingredients len:number <- get *in, length:offset - s:address:shared:array:character <- get *in, data:offset + s:address:array:character <- get *in, data:offset capacity:number <- length *s result <- greater-or-equal len, capacity ] # most broadly applicable definition of append to a buffer: just call to-text -def append buf:address:shared:buffer, x:_elem -> buf:address:shared:buffer [ +def append buf:address:buffer, x:_elem -> buf:address:buffer [ local-scope load-ingredients - text:address:shared:array:character <- to-text x + text:address:array:character <- to-text x len:number <- length *text i:number <- copy 0 { @@ -181,7 +181,7 @@ def append buf:address:shared:buffer, x:_elem -> buf:address:shared:buffer [ } ] -def append in:address:shared:buffer, c:character -> in:address:shared:buffer [ +def append in:address:buffer, c:character -> in:address:buffer [ local-scope load-ingredients len:number <- get *in, length:offset @@ -201,7 +201,7 @@ def append in:address:shared:buffer, c:character -> in:address:shared:buffer [ break-unless full? in <- grow-buffer in } - s:address:shared:array:character <- get *in, data:offset + s:address:array:character <- get *in, data:offset *s <- put-index *s, len, c len <- add len, 1 *in <- put *in, length:offset, len @@ -210,21 +210,21 @@ def append in:address:shared:buffer, c:character -> in:address:shared:buffer [ scenario buffer-append-works [ run [ local-scope - x:address:shared:buffer <- new-buffer 3 - s1:address:shared:array:character <- get *x, data:offset + x:address:buffer <- new-buffer 3 + s1:address:array:character <- get *x, data:offset c:character <- copy 97/a x <- append x, c c:character <- copy 98/b x <- append x, c c:character <- copy 99/c x <- append x, c - s2:address:shared:array:character <- get *x, data:offset + s2:address:array:character <- get *x, data:offset 1:boolean/raw <- equal s1, s2 2:array:character/raw <- copy *s2 +buffer-filled c:character <- copy 100/d x <- append x, c - s3:address:shared:array:character <- get *x, data:offset + s3:address:array:character <- get *x, data:offset 10:boolean/raw <- equal s1, s3 11:number/raw <- get *x, length:offset 12:array:character/raw <- copy *s3 @@ -252,14 +252,14 @@ scenario buffer-append-works [ scenario buffer-append-handles-backspace [ run [ local-scope - x:address:shared:buffer <- new-buffer 3 + x:address:buffer <- new-buffer 3 c:character <- copy 97/a x <- append x, c c:character <- copy 98/b x <- append x, c c:character <- copy 8/backspace x <- append x, c - s:address:shared:array:character <- buffer-to-array x + s:address:array:character <- buffer-to-array x 1:array:character/raw <- copy *s ] memory-should-contain [ @@ -269,7 +269,7 @@ scenario buffer-append-handles-backspace [ ] ] -def to-text n:number -> result:address:shared:array:character [ +def to-text n:number -> result:address:array:character [ local-scope load-ingredients # is n zero? @@ -287,14 +287,14 @@ def to-text n:number -> result:address:shared:array:character [ n <- multiply n, -1 } # add digits from right to left into intermediate buffer - tmp:address:shared:buffer <- new-buffer 30 + tmp:address:buffer <- new-buffer 30 digit-base:number <- copy 48 # '0' { done?:boolean <- equal n, 0 break-if done? n, digit:number <- divide-with-remainder n, 10 c:character <- add digit-base, digit - tmp:address:shared:buffer <- append tmp, c + tmp:address:buffer <- append tmp, c loop } # add sign @@ -305,7 +305,7 @@ def to-text n:number -> result:address:shared:array:character [ } # reverse buffer into text result len:number <- get *tmp, length:offset - buf:address:shared:array:character <- get *tmp, data:offset + buf:address:array:character <- get *tmp, data:offset result <- new character:type, len i:number <- subtract len, 1 # source index, decreasing j:number <- copy 0 # destination index, increasing @@ -322,21 +322,21 @@ def to-text n:number -> result:address:shared:array:character [ } ] -def to-text x:boolean -> result:address:shared:array:character [ +def to-text x:boolean -> result:address:array:character [ local-scope load-ingredients n:number <- copy x:boolean result <- to-text n ] -def to-text x:address:_elem -> result:address:shared:array:character [ +def to-text x:address:_elem -> result:address:array:character [ local-scope load-ingredients n:number <- copy x result <- to-text n ] -def buffer-to-array in:address:shared:buffer -> result:address:shared:array:character [ +def buffer-to-array in:address:buffer -> result:address:array:character [ local-scope load-ingredients { @@ -345,7 +345,7 @@ def buffer-to-array in:address:shared:buffer -> result:address:shared:array:char return 0 } len:number <- get *in, length:offset - s:address:shared:array:character <- get *in, data:offset + s:address:array:character <- get *in, data:offset # we can't just return s because it is usually the wrong length result <- new character:type, len i:number <- copy 0 @@ -361,8 +361,8 @@ def buffer-to-array in:address:shared:buffer -> result:address:shared:array:char scenario integer-to-decimal-digit-zero [ run [ - 1:address:shared:array:character/raw <- to-text 0 - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- to-text 0 + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [0] @@ -371,8 +371,8 @@ scenario integer-to-decimal-digit-zero [ scenario integer-to-decimal-digit-positive [ run [ - 1:address:shared:array:character/raw <- to-text 234 - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- to-text 234 + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [234] @@ -381,8 +381,8 @@ scenario integer-to-decimal-digit-positive [ scenario integer-to-decimal-digit-negative [ run [ - 1:address:shared:array:character/raw <- to-text -1 - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- to-text -1 + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2 <- 2 @@ -391,7 +391,7 @@ scenario integer-to-decimal-digit-negative [ ] ] -def append a:address:shared:array:character, b:address:shared:array:character -> result:address:shared:array:character [ +def append a:address:array:character, b:address:array:character -> result:address:array:character [ local-scope load-ingredients # result = new character[a.length + b.length] @@ -430,10 +430,10 @@ def append a:address:shared:array:character, b:address:shared:array:character -> scenario text-append-1 [ run [ - 1:address:shared:array:character/raw <- new [hello,] - 2:address:shared:array:character/raw <- new [ world!] - 3:address:shared:array:character/raw <- append 1:address:shared:array:character/raw, 2:address:shared:array:character/raw - 4:array:character/raw <- copy *3:address:shared:array:character/raw + 1:address:array:character/raw <- new [hello,] + 2:address:array:character/raw <- new [ world!] + 3:address:array:character/raw <- append 1:address:array:character/raw, 2:address:array:character/raw + 4:array:character/raw <- copy *3:address:array:character/raw ] memory-should-contain [ 4:array:character <- [hello, world!] @@ -442,16 +442,16 @@ scenario text-append-1 [ scenario replace-character-in-text [ run [ - 1:address:shared:array:character/raw <- new [abc] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 98/b, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 98/b, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [azc] ] ] -def replace s:address:shared:array:character, oldc:character, newc:character, from:number/optional -> s:address:shared:array:character [ +def replace s:address:array:character, oldc:character, newc:character, from:number/optional -> s:address:array:character [ local-scope load-ingredients len:number <- length *s @@ -465,9 +465,9 @@ def replace s:address:shared:array:character, oldc:character, newc:character, fr scenario replace-character-at-start [ run [ - 1:address:shared:array:character/raw <- new [abc] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 97/a, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 97/a, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [zbc] @@ -476,9 +476,9 @@ scenario replace-character-at-start [ scenario replace-character-at-end [ run [ - 1:address:shared:array:character/raw <- new [abc] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 99/c, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 99/c, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [abz] @@ -487,9 +487,9 @@ scenario replace-character-at-end [ scenario replace-character-missing [ run [ - 1:address:shared:array:character/raw <- new [abc] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 100/d, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 100/d, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [abc] @@ -498,9 +498,9 @@ scenario replace-character-missing [ scenario replace-all-characters [ run [ - 1:address:shared:array:character/raw <- new [banana] - 1:address:shared:array:character/raw <- replace 1:address:shared:array:character/raw, 97/a, 122/z - 2:array:character/raw <- copy *1:address:shared:array:character/raw + 1:address:array:character/raw <- new [banana] + 1:address:array:character/raw <- replace 1:address:array:character/raw, 97/a, 122/z + 2:array:character/raw <- copy *1:address:array:character/raw ] memory-should-contain [ 2:array:character <- [bznznz] @@ -508,7 +508,7 @@ scenario replace-all-characters [ ] # replace underscores in first with remaining args -def interpolate template:address:shared:array:character -> result:address:shared:array:character [ +def interpolate template:address:array:character -> result:address:array:character [ local-scope load-ingredients # consume just the template # compute result-len, space to allocate for result @@ -516,7 +516,7 @@ def interpolate template:address:shared:array:character -> result:address:shared result-len:number <- copy tem-len { # while ingredients remain - a:address:shared:array:character, arg-received?:boolean <- next-ingredient + a:address:array:character, arg-received?:boolean <- next-ingredient break-unless arg-received? # result-len = result-len + arg.length - 1 (for the 'underscore' being replaced) a-len:number <- length *a @@ -532,7 +532,7 @@ def interpolate template:address:shared:array:character -> result:address:shared i:number <- copy 0 { # while arg received - a:address:shared:array:character, arg-received?:boolean <- next-ingredient + a:address:array:character, arg-received?:boolean <- next-ingredient break-unless arg-received? # copy template into result until '_' { @@ -583,10 +583,10 @@ def interpolate template:address:shared:array:character -> result:address:shared scenario interpolate-works [ run [ - 1:address:shared:array:character/raw <- new [abc _] - 2:address:shared:array:character/raw <- new [def] - 3:address:shared:array:character/raw <- interpolate 1:address:shared:array:character/raw, 2:address:shared:array:character/raw - 4:array:character/raw <- copy *3:address:shared:array:character/raw + 1:address:array:character/raw <- new [abc _] + 2:address:array:character/raw <- new [def] + 3:address:array:character/raw <- interpolate 1:address:array:character/raw, 2:address:array:character/raw + 4:array:character/raw <- copy *3:address:array:character/raw ] memory-should-contain [ 4:array:character <- [abc def] @@ -595,10 +595,10 @@ scenario interpolate-works [ scenario interpolate-at-start [ run [ - 1:address:shared:array:character/raw <- new [_, hello!] - 2:address:shared:array:character/raw <- new [abc] - 3:address:shared:array:character/raw <- interpolate 1:address:shared:array:character/raw, 2:address:shared:array:character/raw - 4:array:character/raw <- copy *3:address:shared:array:character/raw + 1:address:array:character/raw <- new [_, hello!] + 2:address:array:character/raw <- new [abc] + 3:address:array:character/raw <- interpolate 1:address:array:character/raw, 2:address:array:character/raw + 4:array:character/raw <- copy *3:address:array:character/raw ] memory-should-contain [ 4:array:character <- [abc, hello!] @@ -608,10 +608,10 @@ scenario interpolate-at-start [ scenario interpolate-at-end [ run [ - 1:address:shared:array:character/raw <- new [hello, _] - 2:address:shared:array:character/raw <- new [abc] - 3:address:shared:array:character/raw <- interpolate 1:address:shared:array:character/raw, 2:address:shared:array:character/raw - 4:array:character/raw <- copy *3:address:shared:array:character/raw + 1:address:array:character/raw <- new [hello, _] + 2:address:array:character/raw <- new [abc] + 3:address:array:character/raw <- interpolate 1:address:array:character/raw, 2:address:array:character/raw + 4:array:character/raw <- copy *3:address:array:character/raw ] memory-should-contain [ 4:array:character <- [hello, abc] @@ -680,7 +680,7 @@ def space? c:character -> result:boolean [ result <- equal c, 12288/ideographic-space ] -def trim s:address:shared:array:character -> result:address:shared:array:character [ +def trim s:address:array:character -> result:address:array:character [ local-scope load-ingredients len:number <- length *s @@ -712,7 +712,7 @@ def trim s:address:shared:array:character -> result:address:shared:array:charact } # result = new character[end+1 - start] new-len:number <- subtract end, start, -1 - result:address:shared:array:character <- new character:type, new-len + result:address:array:character <- new character:type, new-len # copy the untrimmed parts between start and end i:number <- copy start j:number <- copy 0 @@ -731,9 +731,9 @@ def trim s:address:shared:array:character -> result:address:shared:array:charact scenario trim-unmodified [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] @@ -742,9 +742,9 @@ scenario trim-unmodified [ scenario trim-left [ run [ - 1:address:shared:array:character <- new [ abc] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [ abc] + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] @@ -753,9 +753,9 @@ scenario trim-left [ scenario trim-right [ run [ - 1:address:shared:array:character <- new [abc ] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc ] + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] @@ -764,9 +764,9 @@ scenario trim-right [ scenario trim-left-right [ run [ - 1:address:shared:array:character <- new [ abc ] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [ abc ] + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] @@ -775,17 +775,17 @@ scenario trim-left-right [ scenario trim-newline-tab [ run [ - 1:address:shared:array:character <- new [ abc + 1:address:array:character <- new [ abc ] - 2:address:shared:array:character <- trim 1:address:shared:array:character - 3:array:character <- copy *2:address:shared:array:character + 2:address:array:character <- trim 1:address:array:character + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [abc] ] ] -def find-next text:address:shared:array:character, pattern:character, idx:number -> next-index:number [ +def find-next text:address:array:character, pattern:character, idx:number -> next-index:number [ local-scope load-ingredients len:number <- length *text @@ -803,8 +803,8 @@ def find-next text:address:shared:array:character, pattern:character, idx:number scenario text-find-next [ run [ - 1:address:shared:array:character <- new [a/b] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [a/b] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 1 @@ -813,8 +813,8 @@ scenario text-find-next [ scenario text-find-next-empty [ run [ - 1:address:shared:array:character <- new [] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 0 @@ -823,8 +823,8 @@ scenario text-find-next-empty [ scenario text-find-next-initial [ run [ - 1:address:shared:array:character <- new [/abc] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [/abc] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 0 # prefix match @@ -833,8 +833,8 @@ scenario text-find-next-initial [ scenario text-find-next-final [ run [ - 1:address:shared:array:character <- new [abc/] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [abc/] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 3 # suffix match @@ -843,8 +843,8 @@ scenario text-find-next-final [ scenario text-find-next-missing [ run [ - 1:address:shared:array:character <- new [abc] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [abc] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 3 # no match @@ -853,8 +853,8 @@ scenario text-find-next-missing [ scenario text-find-next-invalid-index [ run [ - 1:address:shared:array:character <- new [abc] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 4/start-index + 1:address:array:character <- new [abc] + 2:number <- find-next 1:address:array:character, 47/slash, 4/start-index ] memory-should-contain [ 2 <- 4 # no change @@ -863,8 +863,8 @@ scenario text-find-next-invalid-index [ scenario text-find-next-first [ run [ - 1:address:shared:array:character <- new [ab/c/] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 0/start-index + 1:address:array:character <- new [ab/c/] + 2:number <- find-next 1:address:array:character, 47/slash, 0/start-index ] memory-should-contain [ 2 <- 2 # first '/' of multiple @@ -873,8 +873,8 @@ scenario text-find-next-first [ scenario text-find-next-second [ run [ - 1:address:shared:array:character <- new [ab/c/] - 2:number <- find-next 1:address:shared:array:character, 47/slash, 3/start-index + 1:address:array:character <- new [ab/c/] + 2:number <- find-next 1:address:array:character, 47/slash, 3/start-index ] memory-should-contain [ 2 <- 4 # second '/' of multiple @@ -883,7 +883,7 @@ scenario text-find-next-second [ # search for a pattern of multiple characters # fairly dumb algorithm -def find-next text:address:shared:array:character, pattern:address:shared:array:character, idx:number -> next-index:number [ +def find-next text:address:array:character, pattern:address:array:character, idx:number -> next-index:number [ local-scope load-ingredients first:character <- index *pattern, 0 @@ -905,9 +905,9 @@ def find-next text:address:shared:array:character, pattern:address:shared:array: scenario find-next-text-1 [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [bc] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [bc] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 1 @@ -916,9 +916,9 @@ scenario find-next-text-1 [ scenario find-next-text-2 [ run [ - 1:address:shared:array:character <- new [abcd] - 2:address:shared:array:character <- new [bc] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 1 + 1:address:array:character <- new [abcd] + 2:address:array:character <- new [bc] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 1 ] memory-should-contain [ 3 <- 1 @@ -927,9 +927,9 @@ scenario find-next-text-2 [ scenario find-next-no-match [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [bd] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [bd] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 3 # not found @@ -938,9 +938,9 @@ scenario find-next-no-match [ scenario find-next-suffix-match [ run [ - 1:address:shared:array:character <- new [abcd] - 2:address:shared:array:character <- new [cd] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abcd] + 2:address:array:character <- new [cd] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 2 @@ -949,9 +949,9 @@ scenario find-next-suffix-match [ scenario find-next-suffix-match-2 [ run [ - 1:address:shared:array:character <- new [abcd] - 2:address:shared:array:character <- new [cde] - 3:number <- find-next 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abcd] + 2:address:array:character <- new [cde] + 3:number <- find-next 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 4 # not found @@ -959,7 +959,7 @@ scenario find-next-suffix-match-2 [ ] # checks if pattern matches at index 'idx' -def match-at text:address:shared:array:character, pattern:address:shared:array:character, idx:number -> result:boolean [ +def match-at text:address:array:character, pattern:address:array:character, idx:number -> result:boolean [ local-scope load-ingredients pattern-len:number <- length *pattern @@ -992,9 +992,9 @@ def match-at text:address:shared:array:character, pattern:address:shared:array:c scenario match-at-checks-pattern-at-index [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [ab] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [ab] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 1 # match found @@ -1003,8 +1003,8 @@ scenario match-at-checks-pattern-at-index [ scenario match-at-reflexive [ run [ - 1:address:shared:array:character <- new [abc] - 3:boolean <- match-at 1:address:shared:array:character, 1:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 3:boolean <- match-at 1:address:array:character, 1:address:array:character, 0 ] memory-should-contain [ 3 <- 1 # match found @@ -1013,9 +1013,9 @@ scenario match-at-reflexive [ scenario match-at-outside-bounds [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [a] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 4 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [a] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 4 ] memory-should-contain [ 3 <- 0 # never matches @@ -1024,9 +1024,9 @@ scenario match-at-outside-bounds [ scenario match-at-empty-pattern [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 1 # always matches empty pattern given a valid index @@ -1035,9 +1035,9 @@ scenario match-at-empty-pattern [ scenario match-at-empty-pattern-outside-bound [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 4 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 4 ] memory-should-contain [ 3 <- 0 # no match @@ -1046,9 +1046,9 @@ scenario match-at-empty-pattern-outside-bound [ scenario match-at-empty-text [ run [ - 1:address:shared:array:character <- new [] - 2:address:shared:array:character <- new [abc] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [] + 2:address:array:character <- new [abc] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 0 # no match @@ -1057,8 +1057,8 @@ scenario match-at-empty-text [ scenario match-at-empty-against-empty [ run [ - 1:address:shared:array:character <- new [] - 3:boolean <- match-at 1:address:shared:array:character, 1:address:shared:array:character, 0 + 1:address:array:character <- new [] + 3:boolean <- match-at 1:address:array:character, 1:address:array:character, 0 ] memory-should-contain [ 3 <- 1 # matches because pattern is also empty @@ -1067,9 +1067,9 @@ scenario match-at-empty-against-empty [ scenario match-at-inside-bounds [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [bc] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 1 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [bc] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 1 ] memory-should-contain [ 3 <- 1 # match @@ -1078,16 +1078,16 @@ scenario match-at-inside-bounds [ scenario match-at-inside-bounds-2 [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- new [bc] - 3:boolean <- match-at 1:address:shared:array:character, 2:address:shared:array:character, 0 + 1:address:array:character <- new [abc] + 2:address:array:character <- new [bc] + 3:boolean <- match-at 1:address:array:character, 2:address:array:character, 0 ] memory-should-contain [ 3 <- 0 # no match ] ] -def split s:address:shared:array:character, delim:character -> result:address:shared:array:address:shared:array:character [ +def split s:address:array:character, delim:character -> result:address:array:address:array:character [ local-scope load-ingredients # empty text? return empty array @@ -1095,7 +1095,7 @@ def split s:address:shared:array:character, delim:character -> result:address:sh { empty?:boolean <- equal len, 0 break-unless empty? - result <- new {(address shared array character): type}, 0 + result <- new {(address array character): type}, 0 return } # count #pieces we need room for @@ -1110,7 +1110,7 @@ def split s:address:shared:array:character, delim:character -> result:address:sh loop } # allocate space - result <- new {(address shared array character): type}, count + result <- new {(address array character): type}, count # repeatedly copy slices start..end until delimiter into result[curr-result] curr-result:number <- copy 0 start:number <- copy 0 @@ -1120,7 +1120,7 @@ def split s:address:shared:array:character, delim:character -> result:address:sh break-if done? end:number <- find-next s, delim, start # copy start..end into result[curr-result] - dest:address:shared:array:character <- copy-range s, start, end + dest:address:array:character <- copy-range s, start, end *result <- put-index *result, curr-result, dest # slide over to next slice start <- add end, 1 @@ -1131,13 +1131,13 @@ def split s:address:shared:array:character, delim:character -> result:address:sh scenario text-split-1 [ run [ - 1:address:shared:array:character <- new [a/b] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character - 4:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 0 - 5:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 1 - 10:array:character <- copy *4:address:shared:array:character - 20:array:character <- copy *5:address:shared:array:character + 1:address:array:character <- new [a/b] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character + 4:address:array:character <- index *2:address:array:address:array:character, 0 + 5:address:array:character <- index *2:address:array:address:array:character, 1 + 10:array:character <- copy *4:address:array:character + 20:array:character <- copy *5:address:array:character ] memory-should-contain [ 3 <- 2 # length of result @@ -1148,15 +1148,15 @@ scenario text-split-1 [ scenario text-split-2 [ run [ - 1:address:shared:array:character <- new [a/b/c] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character - 4:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 0 - 5:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 1 - 6:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 2 - 10:array:character <- copy *4:address:shared:array:character - 20:array:character <- copy *5:address:shared:array:character - 30:array:character <- copy *6:address:shared:array:character + 1:address:array:character <- new [a/b/c] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character + 4:address:array:character <- index *2:address:array:address:array:character, 0 + 5:address:array:character <- index *2:address:array:address:array:character, 1 + 6:address:array:character <- index *2:address:array:address:array:character, 2 + 10:array:character <- copy *4:address:array:character + 20:array:character <- copy *5:address:array:character + 30:array:character <- copy *6:address:array:character ] memory-should-contain [ 3 <- 3 # length of result @@ -1168,11 +1168,11 @@ scenario text-split-2 [ scenario text-split-missing [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character - 4:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 0 - 10:array:character <- copy *4:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character + 4:address:array:character <- index *2:address:array:address:array:character, 0 + 10:array:character <- copy *4:address:array:character ] memory-should-contain [ 3 <- 1 # length of result @@ -1182,9 +1182,9 @@ scenario text-split-missing [ scenario text-split-empty [ run [ - 1:address:shared:array:character <- new [] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character + 1:address:array:character <- new [] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character ] memory-should-contain [ 3 <- 0 # empty result @@ -1193,17 +1193,17 @@ scenario text-split-empty [ scenario text-split-empty-piece [ run [ - 1:address:shared:array:character <- new [a/b//c] - 2:address:shared:array:address:shared:array:character <- split 1:address:shared:array:character, 47/slash - 3:number <- length *2:address:shared:array:address:shared:array:character - 4:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 0 - 5:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 1 - 6:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 2 - 7:address:shared:array:character <- index *2:address:shared:array:address:shared:array:character, 3 - 10:array:character <- copy *4:address:shared:array:character - 20:array:character <- copy *5:address:shared:array:character - 30:array:character <- copy *6:address:shared:array:character - 40:array:character <- copy *7:address:shared:array:character + 1:address:array:character <- new [a/b//c] + 2:address:array:address:array:character <- split 1:address:array:character, 47/slash + 3:number <- length *2:address:array:address:array:character + 4:address:array:character <- index *2:address:array:address:array:character, 0 + 5:address:array:character <- index *2:address:array:address:array:character, 1 + 6:address:array:character <- index *2:address:array:address:array:character, 2 + 7:address:array:character <- index *2:address:array:address:array:character, 3 + 10:array:character <- copy *4:address:array:character + 20:array:character <- copy *5:address:array:character + 30:array:character <- copy *6:address:array:character + 40:array:character <- copy *7:address:array:character ] memory-should-contain [ 3 <- 4 # length of result @@ -1214,7 +1214,7 @@ scenario text-split-empty-piece [ ] ] -def split-first text:address:shared:array:character, delim:character -> x:address:shared:array:character, y:address:shared:array:character [ +def split-first text:address:array:character, delim:character -> x:address:array:character, y:address:array:character [ local-scope load-ingredients # empty text? return empty texts @@ -1222,22 +1222,22 @@ def split-first text:address:shared:array:character, delim:character -> x:addres { empty?:boolean <- equal len, 0 break-unless empty? - x:address:shared:array:character <- new [] - y:address:shared:array:character <- new [] + x:address:array:character <- new [] + y:address:array:character <- new [] return } idx:number <- find-next text, delim, 0 - x:address:shared:array:character <- copy-range text, 0, idx + x:address:array:character <- copy-range text, 0, idx idx <- add idx, 1 - y:address:shared:array:character <- copy-range text, idx, len + y:address:array:character <- copy-range text, idx, len ] scenario text-split-first [ run [ - 1:address:shared:array:character <- new [a/b] - 2:address:shared:array:character, 3:address:shared:array:character <- split-first 1:address:shared:array:character, 47/slash - 10:array:character <- copy *2:address:shared:array:character - 20:array:character <- copy *3:address:shared:array:character + 1:address:array:character <- new [a/b] + 2:address:array:character, 3:address:array:character <- split-first 1:address:array:character, 47/slash + 10:array:character <- copy *2:address:array:character + 20:array:character <- copy *3:address:array:character ] memory-should-contain [ 10:array:character <- [a] @@ -1245,7 +1245,7 @@ scenario text-split-first [ ] ] -def copy-range buf:address:shared:array:character, start:number, end:number -> result:address:shared:array:character [ +def copy-range buf:address:array:character, start:number, end:number -> result:address:array:character [ local-scope load-ingredients # if end is out of bounds, trim it @@ -1253,7 +1253,7 @@ def copy-range buf:address:shared:array:character, start:number, end:number -> r end:number <- min len, end # allocate space for result len <- subtract end, start - result:address:shared:array:character <- new character:type, len + result:address:array:character <- new character:type, len # copy start..end into result[curr-result] src-idx:number <- copy start dest-idx:number <- copy 0 @@ -1270,9 +1270,9 @@ def copy-range buf:address:shared:array:character, start:number, end:number -> r scenario text-copy-copies-partial-text [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- copy-range 1:address:shared:array:character, 1, 3 - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- copy-range 1:address:array:character, 1, 3 + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [bc] @@ -1281,9 +1281,9 @@ scenario text-copy-copies-partial-text [ scenario text-copy-out-of-bounds [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- copy-range 1:address:shared:array:character, 2, 4 - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- copy-range 1:address:array:character, 2, 4 + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [c] @@ -1292,9 +1292,9 @@ scenario text-copy-out-of-bounds [ scenario text-copy-out-of-bounds-2 [ run [ - 1:address:shared:array:character <- new [abc] - 2:address:shared:array:character <- copy-range 1:address:shared:array:character, 3, 3 - 3:array:character <- copy *2:address:shared:array:character + 1:address:array:character <- new [abc] + 2:address:array:character <- copy-range 1:address:array:character, 3, 3 + 3:array:character <- copy *2:address:array:character ] memory-should-contain [ 3:array:character <- [] |