|
|
|
|
@@ -503,29 +503,8 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define Enter_Scope(x) Enter_Scope_Defer package_scope(x)
|
|
|
|
|
struct Enter_Scope_Defer{
|
|
|
|
|
Ast_Scope *scope = 0;
|
|
|
|
|
Ast_Package *package = 0;
|
|
|
|
|
Enter_Scope_Defer(Ast_Scope *new_p){
|
|
|
|
|
pctx->scopes.add(new_p);
|
|
|
|
|
scope = new_p;
|
|
|
|
|
if(new_p->kind == AST_PACKAGE){
|
|
|
|
|
package = pctx->resolving_package;
|
|
|
|
|
pctx->resolving_package = (Ast_Package *)new_p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
~Enter_Scope_Defer(){
|
|
|
|
|
Ast_Scope *poped = pctx->scopes.pop();
|
|
|
|
|
assert(poped == scope);
|
|
|
|
|
if(package){
|
|
|
|
|
pctx->resolving_package = package;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function Ast_Decl *
|
|
|
|
|
search_for_decl(Ast_Scope *scope, Intern_String name){
|
|
|
|
|
_search_for_decl(Ast_Scope *scope, Intern_String name){
|
|
|
|
|
For(scope->decls){
|
|
|
|
|
if(it->name == name){
|
|
|
|
|
return it;
|
|
|
|
|
@@ -535,16 +514,13 @@ search_for_decl(Ast_Scope *scope, Intern_String name){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Ast_Decl *
|
|
|
|
|
search_for_decl_in_current_context(Intern_String name){
|
|
|
|
|
search_for_decl(Ast_Scope *scope, Intern_String name){
|
|
|
|
|
Ast_Decl *result = 0;
|
|
|
|
|
for(S64 i = pctx->scopes.len - 1; i >= 0; i--){
|
|
|
|
|
result = search_for_decl(pctx->scopes[i], name);
|
|
|
|
|
for(Ast_Scope *it = scope; it; it=it->parent_scope){
|
|
|
|
|
result = _search_for_decl(it, name);
|
|
|
|
|
if(result) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!result)
|
|
|
|
|
result = search_for_decl(pctx->resolving_package, name);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -558,11 +534,6 @@ insert_into_scope(Ast_Scope *scope, Ast_Decl *decl){
|
|
|
|
|
scope->decls.add(decl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function void
|
|
|
|
|
insert_into_current_scope(Ast_Decl *decl){
|
|
|
|
|
insert_into_scope(*pctx->scopes.last(), decl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function void
|
|
|
|
|
insert_type_into_package(Ast_Package *p, String name, Ast_Resolved_Type *type){
|
|
|
|
|
Intern_String string = pctx->intern(name);
|
|
|
|
|
@@ -656,7 +627,7 @@ resolve_stmt(Ast *ast, Ast_Resolved_Type *ret){
|
|
|
|
|
case AST_VAR:
|
|
|
|
|
CASE(CONST, Decl){
|
|
|
|
|
resolve_decl(node, IS_NOT_PACKAGE_GLOBAL);
|
|
|
|
|
insert_into_current_scope(node);
|
|
|
|
|
insert_into_scope(node->parent_scope, node);
|
|
|
|
|
BREAK();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -674,7 +645,6 @@ resolve_stmt(Ast *ast, Ast_Resolved_Type *ret){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Enter_Scope(node->scope);
|
|
|
|
|
resolve_expr(node->init, AST_CAN_BE_NULL);
|
|
|
|
|
resolve_and_require_bool("Conditional in a for loop condition", node->cond, AST_CAN_BE_NULL);
|
|
|
|
|
resolve_expr(node->iter, AST_CAN_BE_NULL);
|
|
|
|
|
@@ -688,7 +658,6 @@ resolve_stmt(Ast *ast, Ast_Resolved_Type *ret){
|
|
|
|
|
For(node->ifs){
|
|
|
|
|
resolve_stmt(it->init, ret);
|
|
|
|
|
{
|
|
|
|
|
Enter_Scope(it->scope);
|
|
|
|
|
// @todo: maybe add else kind ?? and then make sure other then else are AST_CANT_BE_NULL
|
|
|
|
|
resolve_and_require_bool("Conditional in a if condition", it->expr, AST_CAN_BE_NULL);
|
|
|
|
|
For_It(it->scope->stmts, jt)
|
|
|
|
|
@@ -794,7 +763,7 @@ resolve_expr(Ast_Expr *ast, B32 flags){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CASE(IDENT, Atom){
|
|
|
|
|
Ast_Decl *decl = resolve_name(node->pos, node->intern_val);
|
|
|
|
|
Ast_Decl *decl = resolve_name(node->parent_scope, node->pos, node->intern_val);
|
|
|
|
|
|
|
|
|
|
node->resolved_decl = decl;
|
|
|
|
|
Operand result = operand(decl);
|
|
|
|
|
@@ -994,9 +963,8 @@ resolve_decl(Ast_Decl *ast, B32 flags){
|
|
|
|
|
// @todo: We also need to make sure there is a return value when ret type is not void
|
|
|
|
|
// @note: then try resolving the block of lambda
|
|
|
|
|
if(lambda->scope){
|
|
|
|
|
Enter_Scope(lambda->scope);
|
|
|
|
|
For(lambda->args){
|
|
|
|
|
insert_into_current_scope(it);
|
|
|
|
|
insert_into_scope(lambda->scope, it);
|
|
|
|
|
}
|
|
|
|
|
For(lambda->scope->stmts){
|
|
|
|
|
resolve_stmt(it, ret_type);
|
|
|
|
|
@@ -1038,7 +1006,6 @@ resolve_decl(Ast_Decl *ast, B32 flags){
|
|
|
|
|
CASE(ENUM, Decl){
|
|
|
|
|
node->type = type_type;
|
|
|
|
|
node->type_val = type_enum(node);
|
|
|
|
|
Enter_Scope(node->scope);
|
|
|
|
|
S64 value = 0;
|
|
|
|
|
For(node->scope->decls){
|
|
|
|
|
Operand op = {};
|
|
|
|
|
@@ -1066,8 +1033,8 @@ resolve_decl(Ast_Decl *ast, B32 flags){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Ast_Decl *
|
|
|
|
|
resolve_name(Token *pos, Intern_String name){
|
|
|
|
|
Ast_Decl *decl = search_for_decl_in_current_context(name);
|
|
|
|
|
resolve_name(Ast_Scope *scope, Token *pos, Intern_String name){
|
|
|
|
|
Ast_Decl *decl = search_for_decl(scope, name);
|
|
|
|
|
if(!decl) compiler_error(pos, "Unidentified name [%s]", name.str);
|
|
|
|
|
resolve_decl(decl);
|
|
|
|
|
return decl;
|
|
|
|
|
@@ -1075,9 +1042,8 @@ resolve_name(Token *pos, Intern_String name){
|
|
|
|
|
|
|
|
|
|
function void
|
|
|
|
|
resolve_package(Ast_Package *package){
|
|
|
|
|
Enter_Scope(package);
|
|
|
|
|
For(package->decls){
|
|
|
|
|
resolve_name(it->pos, it->name);
|
|
|
|
|
resolve_name(package, it->pos, it->name);
|
|
|
|
|
if(it->kind == AST_STRUCT){
|
|
|
|
|
type_complete(it->type);
|
|
|
|
|
}
|
|
|
|
|
|