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
+5 -5
View File
@@ -2,14 +2,14 @@ import "@std/mem"
import "@std/arraylist"
import "@std/hashmap"
# cross-cutting concern, hence global singleton (owned by main.hon)
strings StringPool := undefined
InternError :: enum { out_of_space }
StringId :: alias u32
NO_ID_STR :: maxval!(StringId)
NO_STR :: maxval!(StringId)
# cross-cutting concern, hence global singleton (owned by main.hon)
STRINGS StringPool := undefined
StringPool :: struct {
ids hashmap.StringHashMap(StringId) # string → id
@@ -36,7 +36,7 @@ deinit proc(pool @mut StringPool) void {
intern proc(pool @mut StringPool, str []u8) StringId ! (mem.AllocError | InternError) {
if hashmap.get(&pool.ids, str) |id| return id
if (pool.strings.items.len >= usize(NO_ID_STR)) return .out_of_space
if (pool.strings.items.len >= usize(NO_STR)) return .out_of_space
id StringId :: StringId(pool.strings.items.len)
owned_str []mut u8 :: try mem.alloc(u8, pool.allocator, str.len)