def fill

ezx@1.11.0.0 · src/share/sha.bend:45

import ezx@1.11.0.0/src/share/sha.bend as Sha
import Base

45# the string packed into the array, four bytes to a word. A short tail packs
46# zeros in the unused bytes; the byte length says they are padding. The walk
47# calls itself on the tail, which is the string shrinking.
48def fill(text: String, +index: U32, arr: Array<U32>) -> Array<U32>:
49  match text:
50    case SNil{}:
51      arr
52    case SCon{w, SNil{}}:
53      Array.set(U32, arr, index, pack(byte(w), 0, 0, 0))
54    case SCon{w, SCon{x, SNil{}}}:
55      Array.set(U32, arr, index, pack(byte(w), byte(x), 0, 0))
56    case SCon{w, SCon{x, SCon{y, SNil{}}}}:
57      Array.set(U32, arr, index, pack(byte(w), byte(x), byte(y), 0))
58    case SCon{w, SCon{x, SCon{y, SCon{z, t}}}}:
59      fill(t, U32.inc(index), Array.set(U32, arr, index, pack(byte(w), byte(x), byte(y), byte(z))))

Uses (7)

Used by (1)