// finch run tools/pack.fch src/embedded.fch runtime/finch_rt.c std/json.fch ... // Writes a Finch module that holds the given files as text, so the compiler can carry its runtime and standard library // inside itself (bootstrap/build.sh runs this; tests/run.sh checks the result is up to date). fn literal(str text) -> str { []str parts = ["\""] for c in text { if c == '\\' { parts.push("\\\\") } else if c == '"' { parts.push("\\\"") } else if c == '\n' { parts.push("\\n") } else if c == '\t' { parts.push("\\t") } else if c == '\r' { parts.push("\\r") } else { parts.push(str(c)) } } parts.push("\"") return parts.join("") } fn main([]str args) -> int { if args.len < 3 { print("usage: pack out.fch file...") return 1 } []str out = [ "// The runtime and the standard library, as text. Made by tools/pack.fch: don't edit it, run bootstrap/build.sh.", "// Used when the compiler can't find runtime/ and std/ next to itself.", "", "fn names() -> []str {", " []str list", ] for i in 2..args.len { out.push(" list.push(" + literal(args[i]) + ")") } out.push(" return list") out.push("}") out.push("") out.push("fn texts() -> []str {") out.push(" []str list") for i in 2..args.len { out.push(" list.push(" + literal(read_file(args[i])) + ")") } out.push(" return list") out.push("}") out.push("") write_file(args[1], out.join("\n")) return 0 }