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

@ -2,6 +2,7 @@ const std = @import("std");
const Story = @import("../Story.zig");
const Object = Story.Object;
const Opcode = Story.Opcode;
const assert = std.debug.assert;
const Dumper = @This();
story: *const Story,
@ -35,9 +36,10 @@ fn dumpGlobalInst(
const arg = context.bytes[offset + 1];
const constant_index = context.const_pool[arg];
const global_constant = d.story.constants_pool.items[constant_index];
assert(global_constant.tag == .string);
const global_name: *Object.String = @ptrCast(global_constant);
const name_bytes = global_name.bytes[0..global_name.length];
try d.writer.print("{s} {x} '{s}'\n", .{ @tagName(op), arg, name_bytes });
return offset + 2;
}
@ -134,9 +136,10 @@ pub fn dump(d: Dumper, path: *const Object.ContentPath) !void {
const name_object = path.name;
const name_bytes = name_object.bytes[0..name_object.length];
try d.writer.print("=== {s}(args: {d}, locals: {d}) ===\n", .{
try d.writer.print("=== {s}(args: {d}, constants: {d}, locals: {d}) ===\n", .{
name_bytes,
path.arity,
path.const_pool.len,
path.locals_count,
});