analyze: make VarDecl statements insert symbols to current scope
This commit is contained in:
parent
466243fc2b
commit
3f94082477
|
@ -3,7 +3,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
fn f() i32 {
|
fn f() i32 {
|
||||||
// var a = 3;
|
var a = 3;
|
||||||
// return a;
|
// return a;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,10 @@ fn test_function() B {
|
||||||
fn multwo(num: i32, double_flag: bool) i32 {
|
fn multwo(num: i32, double_flag: bool) i32 {
|
||||||
// TODO resolve expr variables
|
// TODO resolve expr variables
|
||||||
if (true) {
|
if (true) {
|
||||||
|
var truthy = true;
|
||||||
return 1 * 2;
|
return 1 * 2;
|
||||||
} else {
|
} else {
|
||||||
|
var falsey = false;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,7 +344,16 @@ pub const TypeSolver = struct {
|
||||||
// insert it into the context, however we need to know a pointer
|
// insert it into the context, however we need to know a pointer
|
||||||
// to where we are, scope-wise, we don't have that info here,
|
// to where we are, scope-wise, we don't have that info here,
|
||||||
// so it should be implicit into the context.
|
// so it should be implicit into the context.
|
||||||
.VarDecl => @panic("TODO vardecl"),
|
.VarDecl => |vardecl| {
|
||||||
|
self.setErrToken(vardecl.name);
|
||||||
|
const name = vardecl.name.lexeme;
|
||||||
|
|
||||||
|
var var_type = try self.resolveExprType(ctx, vardecl.value);
|
||||||
|
|
||||||
|
// TODO check current_scope being null
|
||||||
|
|
||||||
|
_ = try ctx.current_scope.?.env.put(name, var_type);
|
||||||
|
},
|
||||||
|
|
||||||
// Returns dont cause any type system things as they deal with
|
// Returns dont cause any type system things as they deal with
|
||||||
// values, however, we must ensure that the expression type
|
// values, however, we must ensure that the expression type
|
||||||
|
|
|
@ -376,7 +376,7 @@ pub fn printScope(scope: *Scope, ident: usize) void {
|
||||||
|
|
||||||
var it = scope.env.iterator();
|
var it = scope.env.iterator();
|
||||||
while (it.next()) |kv| {
|
while (it.next()) |kv| {
|
||||||
print(ident, "sym: {}, typ: {}\n", kv.key, prettyType(kv.value));
|
print(ident + 1, "sym: {}, typ: {}\n", kv.key, prettyType(kv.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (scope.children.toSlice()) |child| {
|
for (scope.children.toSlice()) |child| {
|
||||||
|
|
Loading…
Reference in New Issue