Getting packages out of resolve_name
This commit is contained in:
4
ast.cpp
4
ast.cpp
@@ -82,7 +82,6 @@ struct Ast_Atom: Ast_Expr{
|
||||
|
||||
struct Ast_Call_Item: Ast_Expr{
|
||||
Ast_Atom *name; // index | name
|
||||
Ast_Expr *index;
|
||||
Ast_Expr *item;
|
||||
};
|
||||
|
||||
@@ -293,10 +292,9 @@ ast_call(Token *pos, Ast_Expr *name, Array<Ast_Call_Item *> exprs){
|
||||
}
|
||||
|
||||
function Ast_Call_Item *
|
||||
ast_call_item(Token *pos, Ast_Expr *index, Ast_Atom *name, Ast_Expr *item){
|
||||
ast_call_item(Token *pos, Ast_Atom *name, Ast_Expr *item){
|
||||
AST_NEW(Call_Item, CALL_ITEM, pos, AST_EXPR);
|
||||
result->name = name;
|
||||
result->index = index;
|
||||
result->item = item;
|
||||
return result;
|
||||
}
|
||||
|
||||
11
ccodegen.cpp
11
ccodegen.cpp
@@ -536,7 +536,7 @@ compile_files(Array<String> filename){
|
||||
parse_init(&ctx, scratch, &heap);
|
||||
|
||||
F64 parse_begin = os_time();
|
||||
Array<Ast_Package *> packages = {&heap};
|
||||
pctx->packages = {&heap};
|
||||
For(files){
|
||||
Scratch file_scratch;
|
||||
lex_restream(pctx, it.filecontent, it.filename);
|
||||
@@ -545,7 +545,8 @@ compile_files(Array<String> filename){
|
||||
// by default it's name of the file
|
||||
// but if you add [package name] then it's overwritten
|
||||
Token *token = token_get();
|
||||
it.name = token->file;
|
||||
String filename_without_ext = string_chop_last_period(token->file.s);
|
||||
it.name = pctx->intern(filename_without_ext);
|
||||
|
||||
if(token_is(SAME_SCOPE) && token_is_keyword(keyword_package, 1)){
|
||||
token_next(); token_next();
|
||||
@@ -553,13 +554,13 @@ compile_files(Array<String> filename){
|
||||
it.name = package_token->intern_val;
|
||||
}
|
||||
|
||||
Ast_Package *package = find_package(it.name, &packages);
|
||||
Ast_Package *package = find_package(it.name, &pctx->packages);
|
||||
if(package){
|
||||
package->decls.add(it.decls);
|
||||
} else {
|
||||
package = ast_package(token, &heap, it.name);
|
||||
insert_builtin_types_into_package(package);
|
||||
packages.add(package);
|
||||
pctx->packages.add(package);
|
||||
|
||||
}
|
||||
|
||||
@@ -582,7 +583,7 @@ compile_files(Array<String> filename){
|
||||
}
|
||||
F64 parse_end = os_time();
|
||||
|
||||
For(packages){
|
||||
For(pctx->packages){
|
||||
resolve_package(it);
|
||||
}
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ struct Parse_Ctx:Lexer{
|
||||
U64 unique_ids;
|
||||
Map type_map;
|
||||
|
||||
Array<Ast_Package *> packages;
|
||||
Ast_Scope *currently_parsed_scope;
|
||||
Ast_Package *resolving_package;
|
||||
Array<Ast_Decl *> ordered_decls;
|
||||
|
||||
@@ -17,3 +17,4 @@ CONSTANT_VAL :: 10
|
||||
|
||||
global_thing: a_type = 10
|
||||
|
||||
arena: order2.Arena
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
|
||||
Str16 :: String16
|
||||
arena_pointer: *Arena = 0
|
||||
thing: Arena
|
||||
no_type := thing
|
||||
order2_arena: Arena
|
||||
no_type := order2_arena
|
||||
|
||||
Arena :: struct
|
||||
next: *Arena
|
||||
@@ -15,7 +16,7 @@ String16 :: struct
|
||||
data: *void
|
||||
len : S64
|
||||
|
||||
with_type: Arena = thing
|
||||
with_type: Arena = order2_arena
|
||||
pointer := &with_type
|
||||
deref := *pointer
|
||||
|
||||
|
||||
10
parsing.cpp
10
parsing.cpp
@@ -153,22 +153,16 @@ parse_expr_call(Ast_Expr *left){
|
||||
|
||||
while(!token_is(TK_CloseParen)){
|
||||
Token *token = token_get();
|
||||
Ast_Expr *index = 0;
|
||||
Ast_Atom *name = 0;
|
||||
if(token_match(TK_OpenBracket)){
|
||||
index = parse_expr();
|
||||
token_expect(TK_CloseBracket);
|
||||
token_expect(TK_Assign);
|
||||
}
|
||||
|
||||
Ast_Expr *item = parse_expr();
|
||||
if(!index && token_match(TK_Assign)){
|
||||
if(token_match(TK_Assign)){
|
||||
assert(is_flag_set(item->flags, AST_ATOM));
|
||||
name = (Ast_Atom *)item;
|
||||
item = parse_expr();
|
||||
}
|
||||
|
||||
Ast_Call_Item *item_comp = ast_call_item(token, index, name, item);
|
||||
Ast_Call_Item *item_comp = ast_call_item(token, name, item);
|
||||
exprs.add(item_comp);
|
||||
|
||||
if(!token_match(TK_Comma)){
|
||||
|
||||
@@ -520,6 +520,14 @@ search_for_decl(Ast_Scope *scope, Intern_String name){
|
||||
result = _search_for_decl(it, name);
|
||||
if(result) break;
|
||||
}
|
||||
if(!result){
|
||||
For(pctx->packages){
|
||||
if(name == it->name){
|
||||
result = (Ast_Decl *)it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -648,8 +656,7 @@ resolve_stmt(Ast *ast, Ast_Resolved_Type *ret){
|
||||
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);
|
||||
For(node->scope->stmts)
|
||||
resolve_stmt(it, ret);
|
||||
For(node->scope->stmts) resolve_stmt(it, ret);
|
||||
BREAK();
|
||||
}
|
||||
|
||||
@@ -681,7 +688,6 @@ resolve_cast(Ast_Cast *node){
|
||||
Ast_Resolved_Type *original_type = expr.type;
|
||||
node->before_type = expr.type;
|
||||
|
||||
// @todo: cleanup, probably just want one big if
|
||||
switch(expr.type->kind){
|
||||
case TYPE_POINTER:{
|
||||
if(is_pointer(type))
|
||||
@@ -865,7 +871,6 @@ resolve_expr(Ast_Expr *ast, B32 flags){
|
||||
|
||||
Ast_Call_Item *item = 0;
|
||||
For(node->exprs){
|
||||
if(it->index) compiler_error(it->index->pos, "Function call indexing is illegal");
|
||||
|
||||
if(it->name){
|
||||
Ast_Atom *name = it->name;
|
||||
@@ -892,10 +897,9 @@ resolve_expr(Ast_Expr *ast, B32 flags){
|
||||
items.add(item);
|
||||
}
|
||||
else{
|
||||
// default values are typechecked when they get resolved
|
||||
// @note: default values are typechecked when they get resolved
|
||||
if(lambda_arg->expr){
|
||||
Ast_Call_Item *item_default = ast_call_item(lambda_arg->expr->pos, 0, 0, lambda_arg->expr);
|
||||
items.add(item_default);
|
||||
items.add(ast_call_item(lambda_arg->expr->pos, 0, lambda_arg->expr));
|
||||
}
|
||||
else compiler_error(lambda_arg->pos, "Required value in lambda call was not passed");
|
||||
}
|
||||
@@ -919,8 +923,13 @@ resolve_expr(Ast_Expr *ast, B32 flags){
|
||||
invalid_return;
|
||||
}
|
||||
|
||||
// @todo: I hate this, package is a scope so it cant
|
||||
// be a DECL, I don't personally like this meme
|
||||
function void
|
||||
resolve_decl(Ast_Decl *ast){
|
||||
if(ast->kind == AST_PACKAGE){
|
||||
return;
|
||||
}
|
||||
if(ast->state == DECL_RESOLVED){
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user