refactor: clarify diagnostics and adopt ptrcast inference

This commit is contained in:
2026-09-19 23:16:18 +02:00
parent 8bb539359b
commit 438f660e76
7 changed files with 27 additions and 28 deletions
+10 -10
View File
@@ -21,30 +21,30 @@ Diagnostic :: struct {
span Span
}
Store :: struct { items arraylist.ArrayList(Diagnostic) }
Store :: struct { list arraylist.ArrayList(Diagnostic) }
CapacityError :: enum { diagnostic_limit_reached }
init proc(allocator mem.Allocator) Store {
return Store{ items = arraylist.init(allocator) }
return Store{ list = arraylist.init(allocator) }
}
deinit proc(store @mut Store) void {
arraylist.deinit(&store.items)
arraylist.deinit(&store.list)
}
add proc(store @mut Store, code Code, span Span) DiagnosticId ! (mem.AllocError | CapacityError) {
if (store.items.items.len >= usize(NO_DIAGNOSTIC)) return .diagnostic_limit_reached
id :: DiagnosticId(store.items.items.len)
try arraylist.append(&store.items, Diagnostic{ code = code, span = span })
if (store.list.items.len >= usize(NO_DIAGNOSTIC)) return .diagnostic_limit_reached
id :: DiagnosticId(store.list.items.len)
try arraylist.append(&store.list, Diagnostic{ code = code, span = span })
return id
}
get proc(store @Store, id DiagnosticId) ?Diagnostic {
if (usize(id) >= store.items.items.len) return null
return store.items.items[usize(id)]
if (usize(id) >= store.list.items.len) return null
return store.list.items[usize(id)]
}
len proc(store @Store) usize {
return store.items.items.len
count proc(store @Store) usize {
return store.list.items.len
}
+1 -1
View File
@@ -22,7 +22,7 @@ reports_invalid_input_and_keeps_scanning test {
try testing.expect_equal(TokenKind.float, state.tokens.items[5].kind)
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, diagnostics.len(&diagnostic_store))
try testing.expect_equal(2, diagnostics.count(&diagnostic_store))
try testing.expect_equal("name", strpool.get_str(&strpool.STRINGS, state.tokens.items[1].data.str_id)?)
try testing.expect_equal(u32(3), state.tokens.items[1].span.start)
try testing.expect_equal(u32(7), state.tokens.items[1].span.end)
+1 -1
View File
@@ -59,5 +59,5 @@ main proc() void! {
try ast_renderer.render(&renderer, &tree)
debug.print("{s}", {renderer.bytes.items})
debug.print("diagnostics: {}\n", {diagnostics.len(&diagnostic_store)})
debug.print("diagnostics: {}\n", {diagnostics.count(&diagnostic_store)})
}
+2 -2
View File
@@ -30,7 +30,7 @@ parses_expression_precedence_through_tree_views test {
try testing.expect_equal(ast.ExprKind.binary, ast.expr_kind(&tree, add.right))
multiply :: ast.binary_expr(&tree, add.right)
try testing.expect_equal(ast.BinaryOperator.multiply, multiply.operator)
try testing.expect_equal(0, diagnostics.len(&diagnostic_store))
try testing.expect_equal(0, diagnostics.count(&diagnostic_store))
}
parses_function_structure_through_tree_views test {
@@ -63,7 +63,7 @@ parses_function_structure_through_tree_views test {
try testing.expect_equal(first.type, second.type)
try testing.expect(first.type != third.type)
try testing.expect_equal(1, ast.block_statement_count(&tree, function.body))
try testing.expect_equal(0, diagnostics.len(&diagnostic_store))
try testing.expect_equal(0, diagnostics.count(&diagnostic_store))
}
recovers_invalid_declaration_and_preserves_sibling test {