diff --git a/source/diagnostics/diagnostics.hon b/source/diagnostics/diagnostics.hon index 02d0a1b..57f3ded 100644 --- a/source/diagnostics/diagnostics.hon +++ b/source/diagnostics/diagnostics.hon @@ -77,8 +77,7 @@ count proc(store @Store) usize { return store.list.items.len } -# a missing entry leaves an undefined payload, which static initialization rejects. -@hide:file +#! constructed at compile time so missing entries fail compilation; message bytes live for the process lifetime. messages :: $enummap.init(Code, []u8, { invalid_character = "invalid character", 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", }) -#! 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)? -} diff --git a/source/main.hon b/source/main.hon index fed34e7..0344299 100644 --- a/source/main.hon +++ b/source/main.hon @@ -1,5 +1,6 @@ import "@std/mem" import "@std/arraylist" +import "@std/enummap" import "@std/io" import "@std/process" @@ -182,7 +183,11 @@ report_diagnostics proc( if (id == diagnostics.DiagnosticId(index)) label = "runtime trap" } 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)?, }) } }