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

@ -166,16 +166,24 @@ pub const Inst = struct {
declaration,
decl_knot,
decl_var,
/// Uses the `str_tok` union field.
decl_ref,
alloc,
load,
store,
/// Uses the `bin` union field.
add,
/// Uses the `bin` union field.
sub,
/// Uses the `bin` union field.
mul,
/// Uses the `bin` union field.
div,
/// Uses the `bin` union field.
mod,
/// Uses the `un` union field.
neg,
/// Uses the `un` union field.
not,
cmp_eq,
cmp_neq,
@ -183,8 +191,10 @@ pub const Inst = struct {
cmp_gte,
cmp_lt,
cmp_lte,
integer,
string,
/// Uses the `int` union field.
int,
/// Uses the `str` union field.
str,
block,
condbr,
@"break",
@ -212,17 +222,22 @@ pub const Inst = struct {
lhs: Ref,
rhs: Ref,
},
integer: struct {
value: u64,
},
string: struct {
int: u64,
str: struct {
/// Offset into `string_bytes`.
start: NullTerminatedString,
/// Number of bytes in the string.
len: u32,
pub fn get(self: @This(), ir: Ir) []const u8 {
return nullTerminatedString(ir, self.start);
pub fn get(self: @This(), code: Ir) []const u8 {
return code.string_bytes[@intFromEnum(self.start)..][0..self.len];
}
},
str_tok: struct {
/// Offset into `string_bytes`.
start: NullTerminatedString,
src_offset: u32,
},
};
pub const Declaration = struct {