From b83e1ee47fd6e8a9bfa539f5f486401c6fbed342 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Wed, 7 Aug 2024 16:56:22 -0500 Subject: Fixed memory leaks --- src/main.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index d748461..319801a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -58,7 +58,9 @@ pub fn main() !void { try pop.populateSymtable(&treeNode); // Codegen - var generator = gen.Generator.init(allocator, tree); + var arena = std.heap.ArenaAllocator.init(allocator); + defer arena.deinit(); + var generator = gen.Generator.init(arena.allocator(), tree); defer generator.deinit(); const code = try generator.generate(); try outWriter.writeAll(code); -- cgit v1.2.3 From d6688321f204b817da6072a198a2534e3aa97504 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Wed, 7 Aug 2024 17:09:30 -0500 Subject: All unit tests pass --- src/codegen.zig | 4 +++- src/main.zig | 1 - src/symtable.zig | 5 ----- 3 files changed, 3 insertions(+), 7 deletions(-) (limited to 'src/main.zig') diff --git a/src/codegen.zig b/src/codegen.zig index 6dde45d..dfccc43 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -223,7 +223,9 @@ test "Codegen exit" { var pop = symb.Populator.init(std.testing.allocator); var treeNode = parseTree.asNode(); try pop.populateSymtable(&treeNode); - var gen = Generator.init(std.testing.allocator, parseTree); + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + var gen = Generator.init(arena.allocator(), parseTree); defer gen.deinit(); const actual = try gen.generate(); try expect(std.mem.eql(u8, actual, expected)); diff --git a/src/main.zig b/src/main.zig index 319801a..1e54dec 100644 --- a/src/main.zig +++ b/src/main.zig @@ -71,7 +71,6 @@ pub fn main() !void { const ldproc = try std.process.Child.run(.{ .argv = &ldargv, .allocator = allocator }); defer allocator.free(ldproc.stdout); defer allocator.free(ldproc.stderr); - std.debug.print("code: \n{s}", .{code}); } /// Get file extension based on filename diff --git a/src/symtable.zig b/src/symtable.zig index cc041c5..60e871c 100644 --- a/src/symtable.zig +++ b/src/symtable.zig @@ -161,7 +161,6 @@ pub const Populator = struct { const table: *SymbolTable = stmt.symtable; switch (stmt.kind) { .defVar => |variable| { - std.debug.print("Populated {s}\n", .{variable.ident.ident}); const symbol: Symbol = try self.buildValueSymb( table, if (variable.expr.typ) |typ| typ else pars.TypeIdent{ .ident = "i32", .list = false }, @@ -175,15 +174,12 @@ pub const Populator = struct { if (value.expr.typ) |typ| typ else pars.TypeIdent{ .ident = "i32", .list = false }, false, ); - std.debug.print("Populated {s}\n", .{value.ident.ident}); if (!try table.insert(value.ident.ident, symbol)) return error.FailedToInsert; }, .block => { const children = try stmt.children(self.allocator); defer self.allocator.free(children); - std.debug.print("Populated Block\n", .{}); for (children) |child| { - std.debug.print("Child: {d}\n", .{child.Stmt.id}); try self.populateSymtable(&child); } }, @@ -193,7 +189,6 @@ pub const Populator = struct { fun.args, fun.retType, ); - std.debug.print("Populated Function {s}\n", .{fun.ident.ident}); if (!try table.insert(fun.ident.ident, symbol)) return error.FailedToInsert; const children = try stmt.children(self.allocator); defer self.allocator.free(children); -- cgit v1.2.3