# Prints one line a tensor (name, dtype, shape, data_offsets as hex) for the file given as the argument, sorted by # offset, then the metadata count and the data size; or the reason the file is refused. test/check_list.py compares # the output with Python's json reading of the same header. import Base import ../w64.bend as W import ../header.bend as H import ../st.bend as ST def dims(xs: List<&2, U32>) -> String: match xs: case []: "" case h <> []: U32.show(h) case h <> t: U32.show(h) ++ "," ++ dims(t) def line(e: H.Ent) -> String: match e: case H.Ent{n, d, s, b, f}: n ++ "\t" ++ H.DType.name(d) ++ "\t" ++ dims(s) ++ "\t" ++ W.W64.show(b) ++ "\t" ++ W.W64.show(f) def show_all(es: List<&2, H.Ent>) -> IO(Unit): match es: case []: IO.pure(Unit, Unit{}) case e <> t: do IO: IO.print(line(e)) show_all(t) def len(xs: List<&2, H.KV>, +n: U32) -> U32: match xs: case []: n case h <> t: len(t, (n + 1 : U32)) def report(r: Result<&2, &2, String, ST.St>) -> IO(Unit): match r: case Done{ST.St{p, st, H.Header{es, m, n}}}: do IO: show_all(es) IO.print("meta\t" ++ U32.show(len(m, 0)) ++ "\tsize\t" ++ W.W64.show(n) ++ "\tstart\t" ++ W.W64.show(st)) case Fail{why}: IO.print("REFUSED\t" ++ why) def arg(xs: List) -> IO(Unit): match xs: case [prog, p]: do IO: r : Result<&2, &2, String, ST.St> <- ST.St.open(p) report(r) case _: IO.print("usage: list ") def main() -> IO(Unit): do IO: a : List <- IO.args() arg(a)