mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 16:54:25 +00:00
The compiler carries its runtime and std inside itself; host module for the system it runs on
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
This commit is contained in:
parent
a0c54a1252
commit
837ad45177
12 changed files with 354 additions and 59 deletions
77
src/host.fch
Normal file
77
src/host.fch
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
// What differs between the systems the compiler itself runs on: how a command line is quoted and run,
|
||||
// where temporary files go, making and removing files. This one is for Linux and macOS (name_windows.fch has
|
||||
// the Windows one).
|
||||
import "stdlib.h"
|
||||
import "unistd.h"
|
||||
|
||||
fn quote(str a) -> str {
|
||||
return "'" + a.replace("'", "'\\''") + "'"
|
||||
}
|
||||
|
||||
// run a command line through the shell; its exit code
|
||||
fn run(str cmd) -> int {
|
||||
return shell(cmd)
|
||||
}
|
||||
|
||||
fn nullDevice() -> str {
|
||||
return "/dev/null"
|
||||
}
|
||||
|
||||
// the folder for temporary files
|
||||
fn tempDir() -> str {
|
||||
t := getenv("TMPDIR")
|
||||
if t.len > 0 {
|
||||
if t.ends_with("/") {
|
||||
return t.sub(0, t.len - 1)
|
||||
}
|
||||
return t
|
||||
}
|
||||
return "/tmp"
|
||||
}
|
||||
|
||||
fn pathSeparator() -> str {
|
||||
return ":"
|
||||
}
|
||||
|
||||
fn pid() -> int {
|
||||
return int(getpid())
|
||||
}
|
||||
|
||||
// the folder the compiler was started in
|
||||
fn cwd() -> str {
|
||||
return getenv("PWD")
|
||||
}
|
||||
|
||||
// where files that are made once and kept go
|
||||
fn cacheDir() -> str {
|
||||
x := getenv("XDG_CACHE_HOME")
|
||||
if x.len > 0 {
|
||||
return x + "/finch"
|
||||
}
|
||||
h := getenv("HOME")
|
||||
if h.len > 0 {
|
||||
return h + "/.cache/finch"
|
||||
}
|
||||
return tempDir() + "/finch-cache"
|
||||
}
|
||||
|
||||
// the editor protocol is bytes, not text lines
|
||||
fn binaryStdio() {
|
||||
}
|
||||
|
||||
fn makeDirs(str path) {
|
||||
shell("mkdir -p " + quote(path))
|
||||
}
|
||||
|
||||
fn remove(str path) {
|
||||
delete_file(path)
|
||||
}
|
||||
|
||||
fn removeTree(str path) {
|
||||
shell("rm -rf " + quote(path))
|
||||
}
|
||||
|
||||
// move a file over another
|
||||
fn move(str from, str to) {
|
||||
shell("mv " + quote(from) + " " + quote(to))
|
||||
}
|
||||
Loading…
Reference in a new issue