From e91c2dfdafdfb88cd39ec19bed78ce9d3d418998 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 26 Sep 2019 14:32:23 -0300 Subject: [PATCH] fix errs --- src/comp_ctx.zig | 7 ++++++- src/types.zig | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/comp_ctx.zig b/src/comp_ctx.zig index f223bf9..ddb8e89 100644 --- a/src/comp_ctx.zig +++ b/src/comp_ctx.zig @@ -45,7 +45,12 @@ pub const FunctionSymbol = struct { /// Parameters for a function are also a table instead of an ArrayList /// because we want to resolve identifiers to them. parameters: UnderlyingTypeMap, - env: *Environment, + + // TODO rm + symbols: SymbolTable, + + // use this instead + //env: *Environment, /// Find a given identifier in the function. Can resolve to either a parameter pub fn findSymbol(self: *const @This(), identifier: []const u8) ?SymbolData { diff --git a/src/types.zig b/src/types.zig index 733112a..f5f031e 100644 --- a/src/types.zig +++ b/src/types.zig @@ -97,8 +97,8 @@ pub const TypeSolver = struct { ) anyerror!SymbolUnderlyingType { switch (expr.*) { .Binary => |binary| { - var left_type = self.resolveExprType(ctx, binary.left); - var right_type = self.resolveExprType(ctx, binary.right); + var left_type = try self.resolveExprType(ctx, binary.left); + var right_type = try self.resolveExprType(ctx, binary.right); return switch (binary.op) { // all numeric operations return numeric types @@ -114,7 +114,7 @@ pub const TypeSolver = struct { // for now, unary operators only have .Not .Unary => |unary| { - var right_type = self.resolveExprType(ctx, unary.right); + var right_type = try self.resolveExprType(ctx, unary.right); return switch (unary.op) { .Negate => right_type, .Not => right_type, @@ -174,14 +174,15 @@ pub const TypeSolver = struct { self: *@This(), ctx: *comp.CompilationContext, stmt: ast.Stmt, - ) !void { + ) anyerror!void { switch (stmt) { // There are no side-effects to the type system when the statement // is just an expression or a println. we just resolve it // to ensure we dont have type errors. - .Expr => |expr_ptr| try self.resolveExprType(ctx, expr_ptr), - .Println => |expr_ptr| try self.resolveExprType(ctx, expr_ptr), + .Expr, .Println => |expr_ptr| { + _ = try self.resolveExprType(ctx, expr_ptr); + }, // VarDecl means we check the type of the expression and // insert it into the context, however we need to know a pointer @@ -200,19 +201,19 @@ pub const TypeSolver = struct { // If create two scopes for each branch of the if .If => |ifstmt| { - try self.resolveExprType(ifstmt.condition); + _ = try self.resolveExprType(ctx, ifstmt.condition); // TODO assert condition's type is bool // TODO bump-dump scope for (ifstmt.then_branch.toSlice()) |then_stmt| { - try self.stmtPass(ctx, &then_stmt); + try self.stmtPass(ctx, then_stmt); } if (ifstmt.else_branch) |else_branch| { // TODO bump-dump scope for (else_branch.toSlice()) |else_stmt| { - try self.stmtPass(ctx, &else_stmt); + try self.stmtPass(ctx, else_stmt); } } }, @@ -220,13 +221,13 @@ pub const TypeSolver = struct { // Loop (creates 1 scope) asserts that the expression // type is a bool .Loop => |loop| { - try self.resolveExprType(loop.condition); - + if (loop.condition) |cond| // TODO assert condition's type is bool + _ = try self.resolveExprType(ctx, cond); // TODO bump-dump scope for (loop.then_branch.toSlice()) |then_stmt| { - try self.stmtPass(ctx, &then_stmt); + try self.stmtPass(ctx, then_stmt); } },