Skip to content

Commit

Permalink
fix(semantic): create root symbol for @this()
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Nov 4, 2024
1 parent 5d8dc8e commit bc81dac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
15 changes: 10 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
"configurations": [
{
"name": "zlint",
"type": "lldb-mi",
"type": "lldb",
"request": "launch",
"target": "./zig-out/bin/zlint",
"program": "./zig-out/bin/zlint",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText"
},

{
"name": "zlint --print-ast",
"type": "lldb",
Expand All @@ -21,6 +19,13 @@
"program": "${workspaceRoot}/zig-out/bin/zlint",
"cwd": "${workspaceRoot}",
"preLaunchTask": "build"
}
},
{
"name": "test-e2e",
"type": "lldb",
"request": "launch",
"program": "./zig-out/bin/test-e2e",
"cwd": "${workspaceRoot}",
},
]
}
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,18 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
e2e_tests.root_module.addImport("zlint", zlint);
b.installArtifact(e2e_tests);

// e2e_tests.linkLibrary(lib);
// e2e_tests.

const run_e2e_tests = b.addRunArtifact(e2e_tests);
run_e2e_tests.step.dependOn((b.getInstallStep()));
if (b.args) |args| {
run_e2e_tests.addArgs(args);
}
const e2e_step = b.step("test-e2e", "Run end-to-end tests");

e2e_step.dependOn(&lib.step);
e2e_step.dependOn(&run_e2e_tests.step);
}
Expand Down
5 changes: 5 additions & 0 deletions src/semantic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub const Builder = struct {
// initialize root scope
try builder.enterRootScope();
builder.assertRootScope(); // sanity check
const root_symbol_id = try builder.declareSymbol(Semantic.ROOT_NODE_ID, "@This()", .public, .{ .s_const = true });
try builder.enterContainerSymbol(root_symbol_id);

// Zig guarantees that the root node ID is 0. We should be careful- they may decide to change this contract.
// if (builtin.mode == .Debug) {
Expand Down Expand Up @@ -312,6 +314,9 @@ pub const Builder = struct {
/// Unconditionally get the most recent container symbol. Panics if no
/// symbol has been entered.
inline fn currentContainerSymbolUnwrap(self: *const Builder) Symbol.Id {
if (IS_DEBUG and self._symbol_stack.items.len == 0) {
std.debug.panic("Cannot get current container symbol: symbol stack is empty", .{});
}
return self._symbol_stack.getLast();
}

Expand Down
1 change: 1 addition & 0 deletions src/semantic/Semantic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ _gpa: Allocator,
_arena: ArenaAllocator,

pub const ROOT_SCOPE_ID: Scope.Id = 0;
pub const ROOT_NODE_ID: Ast.Node.Index = 0;

pub fn deinit(self: *Semantic) void {
// NOTE: ast is arena allocated, so no need to deinit it. freeing the arena
Expand Down

0 comments on commit bc81dac

Please sign in to comment.