summaryrefslogtreecommitdiff
path: root/src/symtable.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/symtable.zig')
-rw-r--r--src/symtable.zig24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/symtable.zig b/src/symtable.zig
index f37ee12..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,9 +189,9 @@ 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);
for (children) |child| try self.populateSymtable(&child);
},
@@ -221,17 +217,21 @@ pub const Populator = struct {
const output = try self.allocator.create(SymbType);
output.* = if (retType) |typ| table.getType(typ).? else SymbType.Void;
+ const typ = SymbType{
+ .Function = .{
+ .output = output,
+ .input = input,
+ },
+ };
+ const id = self.reserveId();
+
+ _ = try table.insert("func_" ++ .{@as(u8, @truncate(id))}, typ.toSymb());
return Symbol{
.Value = SymbValue{
.mut = true,
- .id = self.reserveId(),
- .typ = SymbType{
- .Function = .{
- .input = input,
- .output = output,
- },
- },
+ .id = id,
+ .typ = typ,
},
};
}