feat: naive variable observers

This commit is contained in:
Brett Broadhurst 2026-04-03 15:40:49 -06:00
parent 48b0e3a806
commit faac9b54d8
Failed to generate hash of commit
3 changed files with 115 additions and 22 deletions

View file

@ -1134,12 +1134,13 @@ fn assign(gi: *GenIr, scope: *Scope, node: *const Ast.Node) InnerError!void {
const expr_node = node.data.bin.rhs.?;
const name_str = try astgen.strFromNode(identifier_node);
if (scope.lookup(name_str.index)) |decl| {
const expr_result = try expr(gi, scope, expr_node);
_ = try gi.addBinaryNode(.store, decl.inst_index.toRef(), expr_result);
return;
}
_ = try gi.addStrTok(.decl_ref, name_str.index, node.loc.start);
const lhs = if (scope.lookup(name_str.index)) |decl| blk: {
break :blk decl.inst_index.toRef();
} else blk: {
break :blk try gi.addStrTok(.decl_ref, name_str.index, node.loc.start);
};
const rhs = try expr(gi, scope, expr_node);
_ = try gi.addBinaryNode(.store, lhs, rhs);
}
fn assignOp(