fix errs
This commit is contained in:
parent
ae27995eb6
commit
e91c2dfdaf
2 changed files with 19 additions and 13 deletions
|
@ -45,7 +45,12 @@ pub const FunctionSymbol = struct {
|
||||||
/// Parameters for a function are also a table instead of an ArrayList
|
/// Parameters for a function are also a table instead of an ArrayList
|
||||||
/// because we want to resolve identifiers to them.
|
/// because we want to resolve identifiers to them.
|
||||||
parameters: UnderlyingTypeMap,
|
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
|
/// Find a given identifier in the function. Can resolve to either a parameter
|
||||||
pub fn findSymbol(self: *const @This(), identifier: []const u8) ?SymbolData {
|
pub fn findSymbol(self: *const @This(), identifier: []const u8) ?SymbolData {
|
||||||
|
|
|
@ -97,8 +97,8 @@ pub const TypeSolver = struct {
|
||||||
) anyerror!SymbolUnderlyingType {
|
) anyerror!SymbolUnderlyingType {
|
||||||
switch (expr.*) {
|
switch (expr.*) {
|
||||||
.Binary => |binary| {
|
.Binary => |binary| {
|
||||||
var left_type = self.resolveExprType(ctx, binary.left);
|
var left_type = try self.resolveExprType(ctx, binary.left);
|
||||||
var right_type = self.resolveExprType(ctx, binary.right);
|
var right_type = try self.resolveExprType(ctx, binary.right);
|
||||||
|
|
||||||
return switch (binary.op) {
|
return switch (binary.op) {
|
||||||
// all numeric operations return numeric types
|
// all numeric operations return numeric types
|
||||||
|
@ -114,7 +114,7 @@ pub const TypeSolver = struct {
|
||||||
|
|
||||||
// for now, unary operators only have .Not
|
// for now, unary operators only have .Not
|
||||||
.Unary => |unary| {
|
.Unary => |unary| {
|
||||||
var right_type = self.resolveExprType(ctx, unary.right);
|
var right_type = try self.resolveExprType(ctx, unary.right);
|
||||||
return switch (unary.op) {
|
return switch (unary.op) {
|
||||||
.Negate => right_type,
|
.Negate => right_type,
|
||||||
.Not => right_type,
|
.Not => right_type,
|
||||||
|
@ -174,14 +174,15 @@ pub const TypeSolver = struct {
|
||||||
self: *@This(),
|
self: *@This(),
|
||||||
ctx: *comp.CompilationContext,
|
ctx: *comp.CompilationContext,
|
||||||
stmt: ast.Stmt,
|
stmt: ast.Stmt,
|
||||||
) !void {
|
) anyerror!void {
|
||||||
switch (stmt) {
|
switch (stmt) {
|
||||||
|
|
||||||
// There are no side-effects to the type system when the statement
|
// There are no side-effects to the type system when the statement
|
||||||
// is just an expression or a println. we just resolve it
|
// is just an expression or a println. we just resolve it
|
||||||
// to ensure we dont have type errors.
|
// to ensure we dont have type errors.
|
||||||
.Expr => |expr_ptr| try self.resolveExprType(ctx, expr_ptr),
|
.Expr, .Println => |expr_ptr| {
|
||||||
.Println => |expr_ptr| try self.resolveExprType(ctx, expr_ptr),
|
_ = try self.resolveExprType(ctx, expr_ptr);
|
||||||
|
},
|
||||||
|
|
||||||
// VarDecl means we check the type of the expression and
|
// VarDecl means we check the type of the expression and
|
||||||
// insert it into the context, however we need to know a pointer
|
// 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 create two scopes for each branch of the if
|
||||||
.If => |ifstmt| {
|
.If => |ifstmt| {
|
||||||
try self.resolveExprType(ifstmt.condition);
|
_ = try self.resolveExprType(ctx, ifstmt.condition);
|
||||||
|
|
||||||
// TODO assert condition's type is bool
|
// TODO assert condition's type is bool
|
||||||
|
|
||||||
// TODO bump-dump scope
|
// TODO bump-dump scope
|
||||||
for (ifstmt.then_branch.toSlice()) |then_stmt| {
|
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| {
|
if (ifstmt.else_branch) |else_branch| {
|
||||||
// TODO bump-dump scope
|
// TODO bump-dump scope
|
||||||
for (else_branch.toSlice()) |else_stmt| {
|
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
|
// Loop (creates 1 scope) asserts that the expression
|
||||||
// type is a bool
|
// type is a bool
|
||||||
.Loop => |loop| {
|
.Loop => |loop| {
|
||||||
try self.resolveExprType(loop.condition);
|
if (loop.condition) |cond|
|
||||||
|
|
||||||
// TODO assert condition's type is bool
|
// TODO assert condition's type is bool
|
||||||
|
_ = try self.resolveExprType(ctx, cond);
|
||||||
|
|
||||||
// TODO bump-dump scope
|
// TODO bump-dump scope
|
||||||
for (loop.then_branch.toSlice()) |then_stmt| {
|
for (loop.then_branch.toSlice()) |then_stmt| {
|
||||||
try self.stmtPass(ctx, &then_stmt);
|
try self.stmtPass(ctx, then_stmt);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue