compact compiler ids and spans to reduce memory usage

This commit is contained in:
2026-06-12 16:55:16 +02:00
parent 99ba907f59
commit 4112b79c6b
16 changed files with 972 additions and 573 deletions
+7 -7
View File
@@ -34,11 +34,11 @@ append_token :: proc(
kind: token.Kind,
start, end: int,
id := symbol.INVALID,
diagnostic := -1,
diagnostic := source.INVALID_DIAGNOSTIC,
) {
append(&stream.items, token.Token{
kind=kind,
span=source.Span{file=source_file.id, start=start, end=end},
span=source.Span{file=source_file.id, start=source.Offset(start), end=source.Offset(end)},
symbol=id,
diagnostic=diagnostic,
})
@@ -74,7 +74,7 @@ lex :: proc(
cursor += 1
append_token(&stream, source_file, .Colon_Colon, start, cursor)
} else {
id := source.add(diagnostics, source.Span{file=source_file.id, start=start, end=cursor}, "expected a second ':'")
id := source.add(diagnostics, source.Span{file=source_file.id, start=source.Offset(start), end=source.Offset(cursor)}, "expected a second ':'")
append_token(&stream, source_file, .Invalid, start, cursor, diagnostic=id)
}
case '=':
@@ -111,7 +111,7 @@ lex :: proc(
if cursor >= len(bytes) || (bytes[cursor] != '\\' && bytes[cursor] != '"') {
source.add(
diagnostics,
source.Span{file=source_file.id, start=max(cursor-1, start), end=min(cursor+1, len(bytes))},
source.Span{file=source_file.id, start=source.Offset(max(cursor-1, start)), end=source.Offset(min(cursor+1, len(bytes)))},
"import strings only support '\\\\' and '\\\"' escapes",
)
valid = false
@@ -127,7 +127,7 @@ lex :: proc(
} else {
id := source.add(
diagnostics,
source.Span{file=source_file.id, start=start, end=cursor},
source.Span{file=source_file.id, start=source.Offset(start), end=source.Offset(cursor)},
"unterminated import string",
)
append_token(&stream, source_file, .Invalid, start, cursor, diagnostic=id)
@@ -135,7 +135,7 @@ lex :: proc(
case ';':
id := source.add(
diagnostics,
source.Span{file=source_file.id, start=cursor, end=cursor+1},
source.Span{file=source_file.id, start=source.Offset(cursor), end=source.Offset(cursor+1)},
"semicolons are invalid; terminate statements with a newline",
)
append_token(&stream, source_file, .Invalid, cursor, cursor+1, diagnostic=id)
@@ -162,7 +162,7 @@ lex :: proc(
} else {
id := source.addf(
diagnostics,
source.Span{file=source_file.id, start=cursor, end=cursor+1},
source.Span{file=source_file.id, start=source.Offset(cursor), end=source.Offset(cursor+1)},
"invalid source byte 0x%02x",
value,
)