refactor: query diagnostic message table directly

This commit is contained in:
2026-10-24 02:44:47 +02:00
parent e9478dcf3f
commit 7551ce5f6d
2 changed files with 7 additions and 7 deletions
+1 -6
View File
@@ -77,8 +77,7 @@ count proc(store @Store) usize {
return store.list.items.len return store.list.items.len
} }
# a missing entry leaves an undefined payload, which static initialization rejects. #! constructed at compile time so missing entries fail compilation; message bytes live for the process lifetime.
@hide:file
messages :: $enummap.init(Code, []u8, { messages :: $enummap.init(Code, []u8, {
invalid_character = "invalid character", invalid_character = "invalid character",
float_must_end_with_digit = "float literal must end with a digit", float_must_end_with_digit = "float literal must end with a digit",
@@ -109,7 +108,3 @@ messages :: $enummap.init(Code, []u8, {
integer_overflow = "integer arithmetic overflow", integer_overflow = "integer arithmetic overflow",
}) })
#! returns a borrowed static message; all Code entries are required at compile time.
message proc(code Code) []u8 {
return enummap.get(Code, []u8, &messages, code)?
}
+6 -1
View File
@@ -1,5 +1,6 @@
import "@std/mem" import "@std/mem"
import "@std/arraylist" import "@std/arraylist"
import "@std/enummap"
import "@std/io" import "@std/io"
import "@std/process" import "@std/process"
@@ -182,7 +183,11 @@ report_diagnostics proc(
if (id == diagnostics.DiagnosticId(index)) label = "runtime trap" if (id == diagnostics.DiagnosticId(index)) label = "runtime trap"
} }
try io.print("{s}:{}:{}: {s}: {s}\n", output, { try io.print("{s}:{}:{}: {s}: {s}\n", output, {
path, line + 1, offset - starts.items[line] + 1, label, diagnostics.message(diagnostic.code), path,
line + 1,
offset - starts.items[line] + 1,
label,
enummap.get(diagnostics.Code, []u8, &diagnostics.messages, diagnostic.code)?,
}) })
} }
} }