Update check to reset globals:
fn check(input: []const u8, expected: i64) void {
source = input;
pos = 0;
num_vars = 0;
num_globals = 0; // ← add this
fn_count = 0;
return_flag = false;
save_depth = 0;
in_function = false; // ← add this
skip();
const got: i64 = program();
// ...
}
Now test:
check("var x: i64 = 42; fn get() i64 { return x; } get()", 42);
ok 42. The function sees the global.