mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 16:54:25 +00:00
src/embedded.fch (made by tools/pack.fch, checked by tests/run.sh) holds runtime/finch_rt.c and std/; when they aren't beside the binary they're written to the cache folder once. All the sh/cmd specifics of the driver (quoting, temp dir, mkdir, rm, mv, null device, path separator, cache dir, binary stdio) moved into host.fch / host_windows.fch. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015f73FesGZGYPkmDvUcj6QX
54 lines
1.6 KiB
Text
54 lines
1.6 KiB
Text
// 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
|
|
}
|