This commit is contained in:
Luna 2019-09-26 14:32:23 -03:00
parent ae27995eb6
commit e91c2dfdaf
2 changed files with 19 additions and 13 deletions

View file

@ -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 {

View file

@ -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);
}
},