From 201458e3bd2f1d79a0ea0b853552e9df267e92b1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 26 Dec 2016 20:44:10 -0800 Subject: 3713 - cross-link calls with definitions in html --- html/061text.mu.html | 152 +++++++++++++++++++++++++-------------------------- 1 file changed, 76 insertions(+), 76 deletions(-) (limited to 'html/061text.mu.html') diff --git a/html/061text.mu.html b/html/061text.mu.html index bde24f55..ecae0b15 100644 --- a/html/061text.mu.html +++ b/html/061text.mu.html @@ -182,27 +182,27 @@ if ('onhashchange' in window) { 124 125 # A new type to help incrementally construct texts. 126 # todo: make this shape-shifting. - 127 container buffer [ + 127 container buffer [ 128 length:num 129 data:text 130 ] 131 - 132 def new-buffer capacity:num -> result:&:buffer [ + 132 def new-buffer capacity:num -> result:&:buffer [ 133 local-scope 134 load-ingredients - 135 result <- new buffer:type + 135 result <- new buffer:type 136 *result <- put *result, length:offset, 0 137 { - 138 break-if capacity + 138 break-if capacity 139 # capacity not provided - 140 capacity <- copy 10 + 140 capacity <- copy 10 141 } - 142 data:text <- new character:type, capacity + 142 data:text <- new character:type, capacity 143 *result <- put *result, data:offset, data 144 return result 145 ] 146 - 147 def grow-buffer buf:&:buffer -> buf:&:buffer [ + 147 def grow-buffer buf:&:buffer -> buf:&:buffer [ 148 local-scope 149 load-ingredients 150 # double buffer size @@ -223,17 +223,17 @@ if ('onhashchange' in window) { 165 } 166 ] 167 - 168 def buffer-full? in:&:buffer -> result:bool [ + 168 def buffer-full? in:&:buffer -> result:bool [ 169 local-scope 170 load-ingredients 171 len:num <- get *in, length:offset 172 s:text <- get *in, data:offset - 173 capacity:num <- length *s - 174 result <- greater-or-equal len, capacity + 173 capacity:num <- length *s + 174 result <- greater-or-equal len, capacity 175 ] 176 177 # most broadly applicable definition of append to a buffer: just call to-text - 178 def append buf:&:buffer, x:_elem -> buf:&:buffer [ + 178 def append buf:&:buffer, x:_elem -> buf:&:buffer [ 179 local-scope 180 load-ingredients 181 text:text <- to-text x @@ -249,7 +249,7 @@ if ('onhashchange' in window) { 191 } 192 ] 193 - 194 def append buf:&:buffer, c:char -> buf:&:buffer [ + 194 def append buf:&:buffer, c:char -> buf:&:buffer [ 195 local-scope 196 load-ingredients 197 len:num <- get *buf, length:offset @@ -265,9 +265,9 @@ if ('onhashchange' in window) { 207 } 208 { 209 # grow buffer if necessary - 210 full?:bool <- buffer-full? buf + 210 full?:bool <- buffer-full? buf 211 break-unless full? - 212 buf <- grow-buffer buf + 212 buf <- grow-buffer buf 213 } 214 s:text <- get *buf, data:offset 215 *s <- put-index *s, len, c @@ -275,7 +275,7 @@ if ('onhashchange' in window) { 217 *buf <- put *buf, length:offset, len 218 ] 219 - 220 def append buf:&:buffer, t:text -> buf:&:buffer [ + 220 def append buf:&:buffer, t:text -> buf:&:buffer [ 221 local-scope 222 load-ingredients 223 len:num <- length *t @@ -292,7 +292,7 @@ if ('onhashchange' in window) { 234 235 scenario append-to-empty-buffer [ 236 local-scope - 237 x:&:buffer <- new-buffer + 237 x:&:buffer <- new-buffer 238 run [ 239 c:char <- copy 97/a 240 x <- append x, c @@ -310,7 +310,7 @@ if ('onhashchange' in window) { 252 253 scenario append-to-buffer [ 254 local-scope - 255 x:&:buffer <- new-buffer + 255 x:&:buffer <- new-buffer 256 c:char <- copy 97/a 257 x <- append x, c 258 run [ @@ -332,7 +332,7 @@ if ('onhashchange' in window) { 274 275 scenario append-grows-buffer [ 276 local-scope - 277 x:&:buffer <- new-buffer 3 + 277 x:&:buffer <- new-buffer 3 278 s1:text <- get *x, data:offset 279 x <- append x, [abc] # buffer is now full 280 s2:text <- get *x, data:offset @@ -369,12 +369,12 @@ if ('onhashchange' in window) { 311 312 scenario buffer-append-handles-backspace [ 313 local-scope - 314 x:&:buffer <- new-buffer + 314 x:&:buffer <- new-buffer 315 x <- append x, [ab] 316 run [ 317 c:char <- copy 8/backspace 318 x <- append x, c - 319 s:text <- buffer-to-array x + 319 s:text <- buffer-to-array x 320 10:@:char/raw <- copy *s 321 ] 322 memory-should-contain [ @@ -384,7 +384,7 @@ if ('onhashchange' in window) { 326 ] 327 ] 328 - 329 def buffer-to-array in:&:buffer -> result:text [ + 329 def buffer-to-array in:&:buffer -> result:text [ 330 local-scope 331 load-ingredients 332 { @@ -418,7 +418,7 @@ if ('onhashchange' in window) { 360 def append first:text -> result:text [ 361 local-scope 362 load-ingredients - 363 buf:&:buffer <- new-buffer 30 + 363 buf:&:buffer <- new-buffer 30 364 # append first ingredient 365 { 366 break-unless first @@ -432,7 +432,7 @@ if ('onhashchange' in window) { 374 buf <- append buf, arg 375 loop 376 } - 377 result <- buffer-to-array buf + 377 result <- buffer-to-array buf 378 ] 379 380 scenario text-append-1 [ @@ -492,7 +492,7 @@ if ('onhashchange' in window) { 434 local-scope 435 x:text <- new [abc] 436 run [ - 437 x <- replace x, 98/b, 122/z + 437 x <- replace x, 98/b, 122/z 438 10:@:char/raw <- copy *x 439 ] 440 memory-should-contain [ @@ -500,7 +500,7 @@ if ('onhashchange' in window) { 442 ] 443 ] 444 - 445 def replace s:text, oldc:char, newc:char, from:num/optional -> s:text [ + 445 def replace s:text, oldc:char, newc:char, from:num/optional -> s:text [ 446 local-scope 447 load-ingredients 448 len:num <- length *s @@ -509,14 +509,14 @@ if ('onhashchange' in window) { 451 return-if done? 452 *s <- put-index *s, i, newc 453 i <- add i, 1 - 454 s <- replace s, oldc, newc, i + 454 s <- replace s, oldc, newc, i 455 ] 456 457 scenario replace-character-at-start [ 458 local-scope 459 x:text <- new [abc] 460 run [ - 461 x <- replace x, 97/a, 122/z + 461 x <- replace x, 97/a, 122/z 462 10:@:char/raw <- copy *x 463 ] 464 memory-should-contain [ @@ -528,7 +528,7 @@ if ('onhashchange' in window) { 470 local-scope 471 x:text <- new [abc] 472 run [ - 473 x <- replace x, 99/c, 122/z + 473 x <- replace x, 99/c, 122/z 474 10:@:char/raw <- copy *x 475 ] 476 memory-should-contain [ @@ -540,7 +540,7 @@ if ('onhashchange' in window) { 482 local-scope 483 x:text <- new [abc] 484 run [ - 485 x <- replace x, 100/d, 122/z + 485 x <- replace x, 100/d, 122/z 486 10:@:char/raw <- copy *x 487 ] 488 memory-should-contain [ @@ -552,7 +552,7 @@ if ('onhashchange' in window) { 494 local-scope 495 x:text <- new [banana] 496 run [ - 497 x <- replace x, 97/a, 122/z + 497 x <- replace x, 97/a, 122/z 498 10:@:char/raw <- copy *x 499 ] 500 memory-should-contain [ @@ -561,7 +561,7 @@ if ('onhashchange' in window) { 503 ] 504 505 # replace underscores in first with remaining args - 506 def interpolate template:text -> result:text [ + 506 def interpolate template:text -> result:text [ 507 local-scope 508 load-ingredients # consume just the template 509 # compute result-len, space to allocate for result @@ -639,7 +639,7 @@ if ('onhashchange' in window) { 581 x:text <- new [abc_ghi] 582 y:text <- new [def] 583 run [ - 584 z:text <- interpolate x, y + 584 z:text <- interpolate x, y 585 10:@:char/raw <- copy *z 586 ] 587 memory-should-contain [ @@ -652,7 +652,7 @@ if ('onhashchange' in window) { 594 x:text <- new [_, hello!] 595 y:text <- new [abc] 596 run [ - 597 z:text <- interpolate x, y + 597 z:text <- interpolate x, y 598 10:@:char/raw <- copy *z 599 ] 600 memory-should-contain [ @@ -666,7 +666,7 @@ if ('onhashchange' in window) { 608 x:text <- new [hello, _] 609 y:text <- new [abc] 610 run [ - 611 z:text <- interpolate x, y + 611 z:text <- interpolate x, y 612 10:@:char/raw <- copy *z 613 ] 614 memory-should-contain [ @@ -675,7 +675,7 @@ if ('onhashchange' in window) { 617 ] 618 619 # result:bool <- space? c:char - 620 def space? c:char -> result:bool [ + 620 def space? c:char -> result:bool [ 621 local-scope 622 load-ingredients 623 # most common case first @@ -736,7 +736,7 @@ if ('onhashchange' in window) { 678 result <- equal c, 12288/ideographic-space 679 ] 680 - 681 def trim s:text -> result:text [ + 681 def trim s:text -> result:text [ 682 local-scope 683 load-ingredients 684 len:num <- length *s @@ -750,7 +750,7 @@ if ('onhashchange' in window) { 692 return 693 } 694 curr:char <- index *s, start - 695 whitespace?:bool <- space? curr + 695 whitespace?:bool <- space? curr 696 break-unless whitespace? 697 start <- add start, 1 698 loop @@ -761,7 +761,7 @@ if ('onhashchange' in window) { 703 not-at-start?:bool <- greater-than end, start 704 assert not-at-start?, [end ran up against start] 705 curr:char <- index *s, end - 706 whitespace?:bool <- space? curr + 706 whitespace?:bool <- space? curr 707 break-unless whitespace? 708 end <- subtract end, 1 709 loop @@ -789,7 +789,7 @@ if ('onhashchange' in window) { 731 local-scope 732 x:text <- new [abc] 733 run [ - 734 y:text <- trim x + 734 y:text <- trim x 735 1:@:char/raw <- copy *y 736 ] 737 memory-should-contain [ @@ -801,7 +801,7 @@ if ('onhashchange' in window) { 743 local-scope 744 x:text <- new [ abc] 745 run [ - 746 y:text <- trim x + 746 y:text <- trim x 747 1:@:char/raw <- copy *y 748 ] 749 memory-should-contain [ @@ -813,7 +813,7 @@ if ('onhashchange' in window) { 755 local-scope 756 x:text <- new [abc ] 757 run [ - 758 y:text <- trim x + 758 y:text <- trim x 759 1:@:char/raw <- copy *y 760 ] 761 memory-should-contain [ @@ -825,7 +825,7 @@ if ('onhashchange' in window) { 767 local-scope 768 x:text <- new [ abc ] 769 run [ - 770 y:text <- trim x + 770 y:text <- trim x 771 1:@:char/raw <- copy *y 772 ] 773 memory-should-contain [ @@ -838,7 +838,7 @@ if ('onhashchange' in window) { 780 x:text <- new [ abc 781 ] 782 run [ - 783 y:text <- trim x + 783 y:text <- trim x 784 1:@:char/raw <- copy *y 785 ] 786 memory-should-contain [ @@ -962,7 +962,7 @@ if ('onhashchange' in window) { 904 # does some unnecessary work checking even when there isn't enough of text left 905 done?:bool <- greater-or-equal idx, len 906 break-if done? - 907 found?:bool <- match-at text, pattern, idx + 907 found?:bool <- match-at text, pattern, idx 908 break-if found? 909 idx <- add idx, 1 910 # optimization: skip past indices that definitely won't match @@ -1033,7 +1033,7 @@ if ('onhashchange' in window) { 975 ] 976 977 # checks if pattern matches at index 'idx' - 978 def match-at text:text, pattern:text, idx:num -> result:bool [ + 978 def match-at text:text, pattern:text, idx:num -> result:bool [ 979 local-scope 980 load-ingredients 981 pattern-len:num <- length *pattern @@ -1069,7 +1069,7 @@ if ('onhashchange' in window) { 1011 x:text <- new [abc] 1012 y:text <- new [ab] 1013 run [ -1014 10:bool/raw <- match-at x, y, 0 +1014 10:bool/raw <- match-at x, y, 0 1015 ] 1016 memory-should-contain [ 1017 10 <- 1 # match found @@ -1080,7 +1080,7 @@ if ('onhashchange' in window) { 1022 local-scope 1023 x:text <- new [abc] 1024 run [ -1025 10:bool/raw <- match-at x, x, 0 +1025 10:bool/raw <- match-at x, x, 0 1026 ] 1027 memory-should-contain [ 1028 10 <- 1 # match found @@ -1092,7 +1092,7 @@ if ('onhashchange' in window) { 1034 x:text <- new [abc] 1035 y:text <- new [a] 1036 run [ -1037 10:bool/raw <- match-at x, y, 4 +1037 10:bool/raw <- match-at x, y, 4 1038 ] 1039 memory-should-contain [ 1040 10 <- 0 # never matches @@ -1104,7 +1104,7 @@ if ('onhashchange' in window) { 1046 x:text <- new [abc] 1047 y:text <- new [] 1048 run [ -1049 10:bool/raw <- match-at x, y, 0 +1049 10:bool/raw <- match-at x, y, 0 1050 ] 1051 memory-should-contain [ 1052 10 <- 1 # always matches empty pattern given a valid index @@ -1116,7 +1116,7 @@ if ('onhashchange' in window) { 1058 x:text <- new [abc] 1059 y:text <- new [] 1060 run [ -1061 10:bool/raw <- match-at x, y, 4 +1061 10:bool/raw <- match-at x, y, 4 1062 ] 1063 memory-should-contain [ 1064 10 <- 0 # no match @@ -1128,7 +1128,7 @@ if ('onhashchange' in window) { 1070 x:text <- new [] 1071 y:text <- new [abc] 1072 run [ -1073 10:bool/raw <- match-at x, y, 0 +1073 10:bool/raw <- match-at x, y, 0 1074 ] 1075 memory-should-contain [ 1076 10 <- 0 # no match @@ -1139,7 +1139,7 @@ if ('onhashchange' in window) { 1081 local-scope 1082 x:text <- new [] 1083 run [ -1084 10:bool/raw <- match-at x, x, 0 +1084 10:bool/raw <- match-at x, x, 0 1085 ] 1086 memory-should-contain [ 1087 10 <- 1 # matches because pattern is also empty @@ -1151,7 +1151,7 @@ if ('onhashchange' in window) { 1093 x:text <- new [abc] 1094 y:text <- new [bc] 1095 run [ -1096 10:bool/raw <- match-at x, y, 1 +1096 10:bool/raw <- match-at x, y, 1 1097 ] 1098 memory-should-contain [ 1099 10 <- 1 # match @@ -1163,14 +1163,14 @@ if ('onhashchange' in window) { 1105 x:text <- new [abc] 1106 y:text <- new [bc] 1107 run [ -1108 10:bool/raw <- match-at x, y, 0 +1108 10:bool/raw <- match-at x, y, 0 1109 ] 1110 memory-should-contain [ 1111 10 <- 0 # no match 1112 ] 1113 ] 1114 -1115 def split s:text, delim:char -> result:&:@:text [ +1115 def split s:text, delim:char -> result:&:@:text [ 1116 local-scope 1117 load-ingredients 1118 # empty text? return empty array @@ -1203,7 +1203,7 @@ if ('onhashchange' in window) { 1145 break-if done? 1146 end:num <- find-next s, delim, start 1147 # copy start..end into result[curr-result] -1148 dest:text <- copy-range s, start, end +1148 dest:text <- copy-range s, start, end 1149 *result <- put-index *result, curr-result, dest 1150 # slide over to next slice 1151 start <- add end, 1 @@ -1216,7 +1216,7 @@ if ('onhashchange' in window) { 1158 local-scope 1159 x:text <- new [a/b] 1160 run [ -1161 y:&:@:text <- split x, 47/slash +1161 y:&:@:text <- split x, 47/slash 1162 10:num/raw <- length *y 1163 a:text <- index *y, 0 1164 b:text <- index *y, 1 @@ -1234,7 +1234,7 @@ if ('onhashchange' in window) { 1176 local-scope 1177 x:text <- new [a/b/c] 1178 run [ -1179 y:&:@:text <- split x, 47/slash +1179 y:&:@:text <- split x, 47/slash 1180 10:num/raw <- length *y 1181 a:text <- index *y, 0 1182 b:text <- index *y, 1 @@ -1255,7 +1255,7 @@ if ('onhashchange' in window) { 1197 local-scope 1198 x:text <- new [abc] 1199 run [ -1200 y:&:@:text <- split x, 47/slash +1200 y:&:@:text <- split x, 47/slash 1201 10:num/raw <- length *y 1202 a:text <- index *y, 0 1203 20:@:char/raw <- copy *a @@ -1270,7 +1270,7 @@ if ('onhashchange' in window) { 1212 local-scope 1213 x:text <- new [] 1214 run [ -1215 y:&:@:text <- split x, 47/slash +1215 y:&:@:text <- split x, 47/slash 1216 10:num/raw <- length *y 1217 ] 1218 memory-should-contain [ @@ -1282,7 +1282,7 @@ if ('onhashchange' in window) { 1224 local-scope 1225 x:text <- new [a/b//c] 1226 run [ -1227 y:&:@:text <- split x:text, 47/slash +1227 y:&:@:text <- split x:text, 47/slash 1228 10:num/raw <- length *y 1229 a:text <- index *y, 0 1230 b:text <- index *y, 1 @@ -1302,7 +1302,7 @@ if ('onhashchange' in window) { 1244 ] 1245 ] 1246 -1247 def split-first text:text, delim:char -> x:text, y:text [ +1247 def split-first text:text, delim:char -> x:text, y:text [ 1248 local-scope 1249 load-ingredients 1250 # empty text? return empty texts @@ -1315,16 +1315,16 @@ if ('onhashchange' in window) { 1257 return 1258 } 1259 idx:num <- find-next text, delim, 0 -1260 x:text <- copy-range text, 0, idx +1260 x:text <- copy-range text, 0, idx 1261 idx <- add idx, 1 -1262 y:text <- copy-range text, idx, len +1262 y:text <- copy-range text, idx, len 1263 ] 1264 1265 scenario text-split-first [ 1266 local-scope 1267 x:text <- new [a/b] 1268 run [ -1269 y:text, z:text <- split-first x, 47/slash +1269 y:text, z:text <- split-first x, 47/slash 1270 10:@:char/raw <- copy *y 1271 20:@:char/raw <- copy *z 1272 ] @@ -1334,7 +1334,7 @@ if ('onhashchange' in window) { 1276 ] 1277 ] 1278 -1279 def copy-range buf:text, start:num, end:num -> result:text [ +1279 def copy-range buf:text, start:num, end:num -> result:text [ 1280 local-scope 1281 load-ingredients 1282 # if end is out of bounds, trim it @@ -1361,7 +1361,7 @@ if ('onhashchange' in window) { 1303 local-scope 1304 x:text <- new [abc] 1305 run [ -1306 y:text <- copy-range x, 1, 3 +1306 y:text <- copy-range x, 1, 3 1307 1:@:char/raw <- copy *y 1308 ] 1309 memory-should-contain [ @@ -1373,7 +1373,7 @@ if ('onhashchange' in window) { 1315 local-scope 1316 x:text <- new [abc] 1317 run [ -1318 y:text <- copy-range x, 2, 4 +1318 y:text <- copy-range x, 2, 4 1319 1:@:char/raw <- copy *y 1320 ] 1321 memory-should-contain [ @@ -1385,7 +1385,7 @@ if ('onhashchange' in window) { 1327 local-scope 1328 x:text <- new [abc] 1329 run [ -1330 y:text <- copy-range x, 3, 3 +1330 y:text <- copy-range x, 3, 3 1331 1:@:char/raw <- copy *y 1332 ] 1333 memory-should-contain [ @@ -1393,7 +1393,7 @@ if ('onhashchange' in window) { 1335 ] 1336 ] 1337 -1338 def parse-whole-number in:text -> out:num, error?:bool [ +1338 def parse-whole-number in:text -> out:num, error?:bool [ 1339 local-scope 1340 load-ingredients 1341 out <- copy 0 @@ -1405,7 +1405,7 @@ if ('onhashchange' in window) { 1347 break-if done? 1348 c:char <- index *in, i 1349 x:num <- character-to-code c -1350 digit:num, error?:bool <- character-code-to-digit x +1350 digit:num, error?:bool <- character-code-to-digit x 1351 reply-if error? 1352 result <- multiply result, 10 1353 result <- add result, digit @@ -1417,7 +1417,7 @@ if ('onhashchange' in window) { 1359 ] 1360 1361 # (contributed by Ella Couch) -1362 recipe character-code-to-digit character-code:number -> result:number, error?:boolean [ +1362 recipe character-code-to-digit character-code:number -> result:number, error?:boolean [ 1363 local-scope 1364 load-ingredients 1365 result <- copy 0 @@ -1432,7 +1432,7 @@ if ('onhashchange' in window) { 1374 local-scope 1375 a:number <- copy 48 # character code for '0' 1376 run [ -1377 10:number/raw, 11:boolean/raw <- character-code-to-digit a +1377 10:number/raw, 11:boolean/raw <- character-code-to-digit a 1378 ] 1379 memory-should-contain [ 1380 10 <- 0 @@ -1444,7 +1444,7 @@ if ('onhashchange' in window) { 1386 local-scope 1387 a:number <- copy 57 # character code for '9' 1388 run [ -1389 1:number/raw, 2:boolean/raw <- character-code-to-digit a +1389 1:number/raw, 2:boolean/raw <- character-code-to-digit a 1390 ] 1391 memory-should-contain [ 1392 1 <- 9 @@ -1456,7 +1456,7 @@ if ('onhashchange' in window) { 1398 local-scope 1399 a:number <- copy 47 1400 run [ -1401 10:number/raw, 11:boolean/raw <- character-code-to-digit a +1401 10:number/raw, 11:boolean/raw <- character-code-to-digit a 1402 ] 1403 memory-should-contain [ 1404 10 <- 0 @@ -1468,7 +1468,7 @@ if ('onhashchange' in window) { 1410 local-scope 1411 a:number <- copy 58 1412 run [ -1413 10:number/raw, 11:boolean/raw <- character-code-to-digit a +1413 10:number/raw, 11:boolean/raw <- character-code-to-digit a 1414 ] 1415 memory-should-contain [ 1416 10 <- 0 -- cgit 1.4.1-2-gfad0