Rename the Finch file extension from .fn to .fch

.fn is already used by other tools (e.g. Fennel). Modules are now looked up as name.fch;
a leftover name.fn gets a clear message telling you to rename it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nexoniarz 2026-10-08 19:27:42 +02:00
commit f897fb3140
92 changed files with 160 additions and 144 deletions

View file

@ -298,10 +298,10 @@ struct Import {
struct Link {
Pos pos;
std::string lib; // "glfw" -> libglfw.so; "helpers.c" / ".o" / ".a" -> a file next to the .fn file
std::string lib; // "glfw" -> libglfw.so; "helpers.c" / ".o" / ".a" -> a file next to the .fch file
};
// One .fn file.
// One .fch file.
struct Program {
std::string module; // "" for the main file, else the module's name
std::string path;

View file

@ -52,5 +52,5 @@ struct CImports {
std::map<std::string, CStruct> structs;
};
// `dirs`: folders searched first for "local.h" headers (the .fn files' folders).
// `dirs`: folders searched first for "local.h" headers (the .fch files' folders).
CImports importHeaders(const std::vector<Import> &imports, const std::vector<std::string> &dirs);

View file

@ -34,9 +34,9 @@ static void usage() {
std::fprintf(stderr,
"Finch " FINCH_VERSION " - small, quick, sharp.\n\n"
"usage:\n"
" finch run <file.fn> [args...] compile and run\n"
" finch build <file.fn> [-o name] compile to a program\n"
" finch ir <file.fn> show the generated LLVM IR\n"
" finch run <file.fch> [args...] compile and run\n"
" finch build <file.fch> [-o name] compile to a program\n"
" finch ir <file.fch> show the generated LLVM IR\n"
" finch version show the version\n"
"\n"
" -l <lib> link a C library, same as link \"lib\" in the file\n"
@ -68,7 +68,12 @@ struct Loader {
void load(const std::string &path, const std::string &module, Pos from) {
std::string text;
if (!readFile(path, text)) {
if (from.line) failAt(from.file, from.line, from.col, "can't find the module '" + module + "' (looked for " + path + ")");
if (from.line) {
std::string old = path.substr(0, path.size() - 4) + ".fn";
if (sys::fs::exists(old))
failAt(from.file, from.line, from.col, "found " + old + ", but Finch files now end in .fch: rename it to " + path);
failAt(from.file, from.line, from.col, "can't find the module '" + module + "' (looked for " + path + ")");
}
std::fprintf(stderr, "error: can't open '%s'\n", path.c_str());
std::exit(1);
}
@ -91,12 +96,12 @@ struct Loader {
// next to the importing file, then in $FINCH_PATH folders
static std::string findModule(const std::string &dir, const std::string &name) {
std::string here = dir + "/" + name + ".fn";
std::string here = dir + "/" + name + ".fch";
if (sys::fs::exists(here)) return here;
if (const char *fp = std::getenv("FINCH_PATH")) {
std::stringstream ss(fp);
for (std::string d; std::getline(ss, d, ':');)
if (!d.empty() && sys::fs::exists(d + "/" + name + ".fn")) return d + "/" + name + ".fn";
if (!d.empty() && sys::fs::exists(d + "/" + name + ".fch")) return d + "/" + name + ".fch";
}
return here;
}

View file

@ -137,7 +137,7 @@ private:
expect(Tok::Link);
l.lib = expect(Tok::String, "a library name in quotes, like link \"glfw\"").text;
auto ends = [&](const char *x) { size_t n = std::strlen(x); return l.lib.size() > n && l.lib.compare(l.lib.size() - n, n, x) == 0; };
if (ends(".c") || ends(".o") || ends(".a")) return l; // your own C code, next to the .fn file
if (ends(".c") || ends(".o") || ends(".a")) return l; // your own C code, next to the .fch file
if (l.lib.rfind("lib", 0) == 0 || l.lib.find(".so") != std::string::npos || l.lib.find('/') != std::string::npos)
fail(l.pos.line, l.pos.col, "write just the library's name: for libglfw.so that's link \"glfw\"");
return l;