def oct.go
bend-kit-tar@0.3.0.0 · tar.bend:34
import bend-kit-tar@0.3.0.0/tar.bend as Tar
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
34
35def oct.go(n: Nat, r: Array<U32> & U32, +j: U32, +ph: U32, +acc: U32, +ok: Bool) -> Array<U32> & U32 & Bool:
36 match n:
37 case 0n:
38 (a, c) = r
39 (a, acc, ok)
40 case 1n+p:
41 (a, +c) = r
42 +live = U32.is_ne(ph, 2)
43 +dig = live && Bytes.in(48, c, 55)
44 +bad = live && Bool.not(Bytes.in(48, c, 55) || (U32.is_eq(c, 32) || U32.is_eq(c, 0)))
45 +over = dig && U32.is_lt(536870911, acc)
46 +ph2 = Bool.pick(U32, live, Bool.pick(U32, dig, 1, Bool.pick(U32, U32.is_eq(ph, 0) && U32.is_eq(c, 32), 0, 2)), 2)
47 +acc2 = Bool.pick(U32, dig, ((acc << 3n) .|. (c - 48) : U32), acc)
48 oct.go(p, Bytes.peek(a, (j + 1 : U32)), (j + 1 : U32), ph2, acc2, ok && Bool.not(bad || over))