feat: error message for unknown global variables

This commit is contained in:
Brett Broadhurst 2026-03-18 19:21:56 -06:00
parent c940374f27
commit 47351cd6f9
Failed to generate hash of commit
6 changed files with 184 additions and 89 deletions

View file

@ -53,6 +53,7 @@ pub const Compilation = struct {
try w.splatByteAll(' ', column - 1);
}
try w.writeAll("^\n");
return w.flush();
}
pub const CompileOptions = struct {
@ -78,7 +79,10 @@ pub const Compilation = struct {
var sema: Sema = .{
.gpa = gpa,
.ir = &ir,
.arena = arena,
.tree = ast,
.ir = ir,
.errors = &errors,
};
defer sema.deinit();
@ -119,7 +123,12 @@ pub const Compilation = struct {
}
break :fatal true;
} else fatal: {
try sema.analyzeFile(.file_inst);
sema.analyzeFile(.file_inst) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.AnalysisFail => break :fatal true,
// TODO: These errors should be handled...
else => |e| return e,
};
break :fatal false;
};
return .{
@ -195,13 +204,13 @@ pub const Compilation = struct {
}
};
const Loc = struct {
pub const Loc = struct {
line: usize,
column: usize,
source_line: []const u8,
};
fn findLineColumn(source: []const u8, byte_offset: usize) Loc {
pub fn findLineColumn(source: []const u8, byte_offset: usize) Loc {
var line: usize = 0;
var column: usize = 0;
var line_start: usize = 0;