aboutsummaryrefslogtreecommitdiff
path: root/src/util.cff
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cff')
-rw-r--r--src/util.cff18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/util.cff b/src/util.cff
index 33bce84..c3a08cb 100644
--- a/src/util.cff
+++ b/src/util.cff
@@ -47,3 +47,21 @@ extern fn addfilepath(s *const u8) int {
filepaths[i] = s;
return i;
}
+
+fn fileid2path(id int) *const u8 {
+ assert(id >= 0 and id < filepaths.#len, "fileid");
+ let s = filepaths[id];
+ assert(s != #null, "fileid");
+ return s;
+}
+
+extern fn fatal(P *Parser, loc Loc, fmt *const u8, ...) void {
+ let ap va_list #?;
+ ap->start(fmt);
+
+ efmt("%s:%i:%i: error: ", fileid2path(loc.fileid), loc.line, loc.col);
+ vefmt(fmt, ap);
+ efmt("\n");
+ ap->end();
+ exit(1);
+}