refactor: query diagnostic message table directly
This commit is contained in:
@@ -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
@@ -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)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user