feat: error reporting for global reference usage

This commit is contained in:
Brett Broadhurst 2026-03-19 01:54:33 -06:00
parent 47351cd6f9
commit be297047d1
Failed to generate hash of commit
8 changed files with 401 additions and 371 deletions

View file

@ -15,7 +15,6 @@ pub const Compilation = struct {
errors: []Error,
knots: []Knot,
constants: []Constant,
globals: []u32,
pub const Error = struct {
line: usize,
@ -138,7 +137,6 @@ pub const Compilation = struct {
.ir = ir,
.errors = try errors.toOwnedSlice(gpa),
.constants = if (fatal) &.{} else try sema.constants.toOwnedSlice(gpa),
.globals = if (fatal) &.{} else try sema.globals.toOwnedSlice(gpa),
.knots = if (fatal) &.{} else try sema.knots.toOwnedSlice(gpa),
};
}
@ -146,7 +144,7 @@ pub const Compilation = struct {
pub fn setupStoryRuntime(cu: *Compilation, gpa: std.mem.Allocator, story: *Story) !void {
assert(cu.errors.len == 0);
const globals_len = cu.globals.len + cu.knots.len;
const globals_len = cu.ir.globals.len;
const constants_pool = &story.constants_pool;
try constants_pool.ensureUnusedCapacity(gpa, cu.constants.len);
try story.globals.ensureUnusedCapacity(gpa, @intCast(globals_len));
@ -166,9 +164,8 @@ pub const Compilation = struct {
},
}
}
for (cu.globals) |global_index| {
const str = cu.constants[global_index];
const name_bytes = cu.ir.nullTerminatedString(str.string);
for (cu.ir.globals) |global| {
const name_bytes = cu.ir.nullTerminatedString(global.name);
story.globals.putAssumeCapacity(name_bytes, null);
}
for (cu.knots) |*knot| {
@ -195,7 +192,6 @@ pub const Compilation = struct {
gpa.free(cu.knots);
gpa.free(cu.errors);
gpa.free(cu.globals);
gpa.free(cu.constants);
cu.ir.deinit(gpa);