summaryrefslogtreecommitdiff
path: root/src/parser.zig
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2024-08-08 19:21:12 -0500
committerNic Gaffney <gaffney_nic@protonmail.com>2024-08-08 19:21:12 -0500
commit6566a8e77a7804612f0045d483775ee489b07cda (patch)
treee8a21ffc903e6a62f930d84338efb64183eaa57d /src/parser.zig
parentc3af878d4919635cd1c6a4bd866042a92c4d8e93 (diff)
parentd6688321f204b817da6072a198a2534e3aa97504 (diff)
downloadcalico-6566a8e77a7804612f0045d483775ee489b07cda.tar.gz
Merge branch 'main' of github.com-Nic:nic-gaffney/calico
Diffstat (limited to 'src/parser.zig')
-rw-r--r--src/parser.zig30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/parser.zig b/src/parser.zig
index 8cd539f..08f098c 100644
--- a/src/parser.zig
+++ b/src/parser.zig
@@ -113,16 +113,30 @@ pub const Parser = struct {
};
}
+ fn dinitHelper(self: *Parser, node: NodeStmt) !void {
+ switch (node.kind) {
+ .block => |blk| {
+ const children = try node.children(self.allocator);
+ defer self.allocator.free(children);
+ for (children) |child| try self.dinitHelper(child.Stmt);
+ self.allocator.free(blk);
+ node.symtable.deinit();
+ },
+ .function => |fun| {
+ const children = try node.children(self.allocator);
+ defer self.allocator.free(children);
+ for (children) |child| try self.dinitHelper(child.Stmt);
+ self.allocator.destroy(fun.block);
+ },
+ else => {},
+ }
+ }
+
pub fn deinit(self: *Parser) void {
for (self.nodes.items) |node| {
- switch (node.kind) {
- .block => |blk| self.allocator.free(blk),
- .function => |fun| {
- self.allocator.free(fun.block.kind.block);
- self.allocator.destroy(fun.block);
- },
- else => {},
- }
+ self.dinitHelper(node) catch |err| {
+ if (err == error.OutOfMemory) {}
+ };
}
self.nodes.deinit();
}