diff --git a/src/sema.zig b/src/sema.zig index b099155..0a1c593 100644 --- a/src/sema.zig +++ b/src/sema.zig @@ -118,6 +118,13 @@ pub const Analyzer = struct { try self.registerTopLevelDecl(decl); } + // Implicit `context` global (the context system — `context.allocator`, + // `context.data`). Registered with its `Context` type when that's in + // scope so the field chain resolves. + if (self.struct_types.contains("Context")) { + try self.addSymbol("context", .variable, .{ .struct_type = "Context" }, .{ .start = 0, .end = 0 }); + } + // Pass 2: Analyze bodies (all top-level names are now in scope). for (root.data.root.decls) |decl| { try self.analyzeTopLevelDecl(decl); @@ -854,7 +861,7 @@ pub const Analyzer = struct { } // Built-in names that aren't declared in source - const builtins = [_][]const u8{ "io", "true", "false", "cast", "closure", "out", "size_of", "align_of", "malloc", "free", "memcpy", "memset" }; + const builtins = [_][]const u8{ "io", "true", "false", "cast", "closure", "out", "size_of", "align_of", "malloc", "free", "memcpy", "memset", "context" }; for (builtins) |b| { if (std.mem.eql(u8, name, b)) return; }