cleanup (isle 6 again?)

This commit is contained in:
2026-08-11 21:29:27 +02:00
parent 8dd06afde2
commit 101795c0b8
8 changed files with 63 additions and 42 deletions
+2 -2
View File
@@ -245,9 +245,9 @@ scan_ident proc(start usize, program []u8) ScanIdentResult {
# don't intern keywords (already O(1) lookup via token kind)
str_id :: if (kind == .ident)
strpool.intern(&strpool.strings, program[start..cursor]) catch strpool.NO_ID_STR
strpool.intern(&strpool.STRINGS, program[start..cursor]) catch strpool.NO_STR
else
strpool.NO_ID_STR
strpool.NO_STR
return ScanIdentResult{
end = cursor,
+3 -3
View File
@@ -3,8 +3,8 @@ import "@std/mem"
import "@std/testing"
handles_keywords_identifiers_and_error_progress test {
strpool.strings = strpool.init(mem.c_allocator)
defer strpool.deinit(&strpool.strings)
strpool.STRINGS = strpool.init(mem.c_allocator)
defer strpool.deinit(&strpool.STRINGS)
state State := init(mem.c_allocator)
defer deinit(&state)
@@ -20,5 +20,5 @@ handles_keywords_identifiers_and_error_progress test {
try testing.expect_equal(TokenKind.string, state.tokens.items[6].kind)
try testing.expect_equal(TokenKind.eof, state.tokens.items[7].kind)
try testing.expect_equal(2, state.diagnostics.items.len)
try testing.expect_equal("name", strpool.get_str(&strpool.strings, state.tokens.items[1].str_id)?)
try testing.expect_equal("name", strpool.get_str(&strpool.STRINGS, state.tokens.items[1].str_id)?)
}
+27 -3
View File
@@ -3,12 +3,12 @@ import "@source/strpool"
TokenId :: distinct u32
NO_ID_TOKEN :: maxval!(TokenId)
NO_TOKEN :: maxval!(TokenId)
Token :: struct {
start uint
kind TokenKind
str_id strpool.StringId = strpool.NO_ID_STR
str_id strpool.StringId = strpool.NO_STR
}
TokenKind :: enum {
@@ -51,8 +51,32 @@ TokenKind :: enum {
invalid
}
render_token proc(tok Token, program []u8) void {
match tok.kind {
.ident: {
str :: strpool.get_str(&strpool.STRINGS, tok.str_id) orelse "null"
debug.print("{}({})\n", {tok.kind, str})
}
.string: {
res :: scan_string(tok.start, program) catch |_| {
debug.print("{}({})\n", {tok.kind, "null"})
return
}
debug.print("{}({})\n", {tok.kind, program[tok.start..res.end]})
}
.int, .float: {
res :: scan_number(tok.start, program) catch |_| {
debug.print("{}({})\n", {tok.kind, "null"})
return
}
debug.print("{}({})\n", {tok.kind, program[tok.start..res.end]})
}
else: debug.print("{}\n", {tok.kind})
}
}
@hide
token_id proc(idx uint) TokenId {
debug.assert(u64(idx) < u64(NO_ID_TOKEN))
debug.assert(u64(idx) < u64(NO_TOKEN))
return TokenId(idx)
}