Compile string, working on scopes
This commit is contained in:
@@ -70,7 +70,7 @@ scope_pop(S64 local_sym_count){
|
||||
|
||||
function Sym *
|
||||
sym_new(Sym_Kind kind, Intern_String name, Ast_Resolved_Type *type, Ast *ast){
|
||||
Sym *result = exp_alloc_type(pctx->perm, Sym);
|
||||
Sym *result = exp_alloc_type(pctx->perm, Sym, AF_ZeroMemory);
|
||||
result->name = name;
|
||||
result->kind = kind;
|
||||
result->type = type;
|
||||
@@ -189,22 +189,12 @@ resolve_type_pair(Token *pos, Ast_Resolved_Type *a, Ast_Resolved_Type *b){
|
||||
return result;
|
||||
}
|
||||
|
||||
function void
|
||||
eval_var(Ast_Decl *node){
|
||||
Ast_Resolved_Type *type = eval_typespec(node->var.typespec);
|
||||
Operand expr = node->var.expr ? eval_expr(node->var.expr, type) : Operand{};
|
||||
Ast_Resolved_Type *resolved_type = resolve_type_pair(node->pos, type, expr.type);
|
||||
|
||||
Sym *sym = sym_new(SYM_Var, node->name, resolved_type, node);
|
||||
sym_insert(sym);
|
||||
}
|
||||
|
||||
function void eval_decl(Ast *ast);
|
||||
function void
|
||||
eval_stmt(Ast *ast, Ast_Resolved_Type *ret){
|
||||
// @todo: need to check if all paths return a value
|
||||
|
||||
switch(ast->kind){
|
||||
Ast_Begin(AST_RETURN, Ast_Return){
|
||||
Ast_Begin(AST_RETURN, Ast_Return){ // @todo: need to check if all paths return a value
|
||||
Operand op = {};
|
||||
if(node->expr) op = eval_expr(node->expr);
|
||||
if(!op.type && ret != type_void) parsing_error(node->pos, "Function expects a void return value but the returned value is [x]");
|
||||
@@ -214,7 +204,12 @@ eval_stmt(Ast *ast, Ast_Resolved_Type *ret){
|
||||
}
|
||||
|
||||
Ast_Begin(AST_VAR, Ast_Decl){
|
||||
eval_var(node);
|
||||
eval_decl(node);
|
||||
Ast_End();
|
||||
}
|
||||
|
||||
Ast_Begin(AST_CONST, Ast_Decl){
|
||||
eval_decl(node);
|
||||
Ast_End();
|
||||
}
|
||||
|
||||
@@ -435,7 +430,12 @@ eval_decl(Ast *ast){
|
||||
}
|
||||
|
||||
Ast_Begin(AST_VAR, Ast_Decl){
|
||||
eval_var(node);
|
||||
Ast_Resolved_Type *type = eval_typespec(node->var.typespec);
|
||||
Operand expr = node->var.expr ? eval_expr(node->var.expr, type) : Operand{};
|
||||
Ast_Resolved_Type *resolved_type = resolve_type_pair(node->pos, type, expr.type);
|
||||
|
||||
Sym *sym = sym_new(SYM_Var, node->name, resolved_type, node);
|
||||
sym_insert(sym);
|
||||
Ast_End();
|
||||
}
|
||||
|
||||
@@ -458,14 +458,3 @@ eval_decl(Ast *ast){
|
||||
}
|
||||
}
|
||||
|
||||
function void
|
||||
test_resolve(){
|
||||
TEST_PARSER();
|
||||
String filename = "globals.kl"_s;
|
||||
String file_content = os_read_file(scratch, filename);
|
||||
lex_restream(&ctx, file_content, filename);
|
||||
Ast_Package *result = parse_file();
|
||||
sym_insert_builtins();
|
||||
eval_decl(result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user