Moving more code to list
This commit is contained in:
@@ -757,9 +757,10 @@ typedef struct String{
|
||||
)==");
|
||||
|
||||
// Generate struct forward decls
|
||||
For(pctx->ordered_decls){
|
||||
if(it->kind == AST_STRUCT){
|
||||
genln("typedef struct %Q %Q;", it->name, it->name);
|
||||
Iter(&pctx->ordered_decls){
|
||||
auto i = it.item[0];
|
||||
if(i->kind == AST_STRUCT){
|
||||
genln("typedef struct %Q %Q;", i->name, i->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -801,20 +802,20 @@ typedef struct String{
|
||||
Ast_Decl *win_main = 0;
|
||||
|
||||
// Generate lambda forward decls
|
||||
For(pctx->ordered_decls){
|
||||
if(it->kind == AST_LAMBDA){
|
||||
if(it->name == intern_main){
|
||||
main = it;
|
||||
it->unique_name = it->name;
|
||||
Iter(&pctx->ordered_decls){
|
||||
if(it.item[0]->kind == AST_LAMBDA){
|
||||
if(it.item[0]->name == intern_main){
|
||||
main = it.item[0];
|
||||
it.item[0]->unique_name = it.item[0]->name;
|
||||
}
|
||||
|
||||
if(it->name == intern_win_main){
|
||||
win_main = it;
|
||||
it->unique_name = it->name;
|
||||
if(it.item[0]->name == intern_win_main){
|
||||
win_main = it.item[0];
|
||||
it.item[0]->unique_name = it.item[0]->name;
|
||||
}
|
||||
|
||||
genln("");
|
||||
gen_lambda(it->unique_name, it->lambda, false);
|
||||
gen_lambda(it.item[0]->unique_name, it.item[0]->lambda, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -824,7 +825,7 @@ typedef struct String{
|
||||
|
||||
// Generate language.kl
|
||||
for(S32 i = 0; i < pctx->base_language_ordered_decl_len; i++){
|
||||
Ast_Decl *it = pctx->ordered_decls[i];
|
||||
Ast_Decl *it = get(&pctx->ordered_decls, i);
|
||||
genln("");
|
||||
gen_ast(it);
|
||||
}
|
||||
@@ -872,10 +873,11 @@ typedef struct String{
|
||||
gen("};");
|
||||
|
||||
// Generate actual code
|
||||
for(S32 i = pctx->base_language_ordered_decl_len; i < pctx->ordered_decls.len; i++){
|
||||
Ast_Decl *it = pctx->ordered_decls[i];
|
||||
genln("");
|
||||
gen_ast(it);
|
||||
Iter(&pctx->ordered_decls){
|
||||
if(it.index >= pctx->base_language_ordered_decl_len){
|
||||
genln("");
|
||||
gen_ast(it.item[0]);
|
||||
}
|
||||
}
|
||||
|
||||
String string_result = string_flatten(pctx->perm, &pctx->gen);
|
||||
|
||||
@@ -82,15 +82,11 @@ function void
|
||||
parse_init(Parse_Ctx *ctx, Arena *perm_allocator, Allocator *heap_allocator){
|
||||
pctx = ctx;
|
||||
ctx->perm = perm_allocator;
|
||||
ctx->perm_arena = perm_allocator;
|
||||
ctx->heap = heap_allocator;
|
||||
ctx->gen = {ctx->heap};
|
||||
ctx->ordered_decls = {ctx->heap};
|
||||
ctx->type_map = {ctx->heap};
|
||||
ctx->modules = {ctx->heap};
|
||||
ctx->all_types = {ctx->heap};
|
||||
ctx->helper_builder= {ctx->heap};
|
||||
ctx->files = {ctx->heap};
|
||||
ctx->scope_ids = 1;
|
||||
bigint_allocator = ctx->perm;
|
||||
arena_init(&ctx->stage_arena, "Compiler stage arena"_s);
|
||||
@@ -102,9 +98,8 @@ parse_init(Parse_Ctx *ctx, Arena *perm_allocator, Allocator *heap_allocator){
|
||||
ctx->exe_folder = os_get_exe_dir(ctx->perm);
|
||||
ctx->working_folder = os_get_working_dir(ctx->perm);
|
||||
|
||||
ctx->module_folders = {ctx->heap};
|
||||
String main_module = string_fmt(ctx->perm, "%Q/modules", ctx->exe_folder);
|
||||
ctx->module_folders.add(main_module);
|
||||
add(ctx->perm, &ctx->module_folders, main_module);
|
||||
}
|
||||
|
||||
|
||||
@@ -162,8 +157,9 @@ global F64 parsing_time_end;
|
||||
function void
|
||||
parse_all_modules(){
|
||||
parsing_time_begin = os_time();
|
||||
for(S64 i = 0; i < pctx->modules.len; i++){
|
||||
Ast_Module *module = pctx->modules[i];
|
||||
|
||||
Iter_Named(&pctx->modules, mod_it){
|
||||
Ast_Module *module = mod_it.item[0];
|
||||
if(module->state != MODULE_REGISTERED) continue;
|
||||
|
||||
Iter(&module->all_loaded_files){
|
||||
@@ -200,8 +196,8 @@ add_module(Token *pos, Intern_String filename, B32 command_line_module){
|
||||
// Find in module folder
|
||||
//
|
||||
else{
|
||||
For(pctx->module_folders){
|
||||
String path = string_fmt(scratch, "%Q/%Q", it, filename);
|
||||
Iter(&pctx->module_folders){
|
||||
String path = string_fmt(scratch, "%Q/%Q", it.item[0], filename);
|
||||
if(os_does_file_exist(path)){
|
||||
absolute_file_path = path;
|
||||
absolute_base_folder = string_chop_last_slash(path);
|
||||
@@ -214,10 +210,10 @@ add_module(Token *pos, Intern_String filename, B32 command_line_module){
|
||||
compiler_error(pos, "Couldn't find the module with name %Q", filename);
|
||||
}
|
||||
|
||||
For(pctx->modules){
|
||||
if(string_compare(it->absolute_file_path, absolute_file_path)){
|
||||
Iter(&pctx->modules){
|
||||
if(string_compare(it.item[0]->absolute_file_path, absolute_file_path)){
|
||||
log_trace("Returning registered module: %Q\n", absolute_file_path);
|
||||
return it;
|
||||
return it.item[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +230,7 @@ add_module(Token *pos, Intern_String filename, B32 command_line_module){
|
||||
result->scope_id = pctx->scope_ids++;
|
||||
|
||||
register_ast_file(pos, result->absolute_file_path, result, GLOBAL_IMPLICIT_LOAD);
|
||||
pctx->modules.add(result);
|
||||
add(pctx->perm, &pctx->modules, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -267,7 +263,7 @@ compile_file_to_string(String filename){
|
||||
resolve_everything_in_module(module);
|
||||
// @note: language stuff needs to be declared before type_info data
|
||||
// so we mark where it ends
|
||||
pctx->base_language_ordered_decl_len = pctx->ordered_decls.len;
|
||||
pctx->base_language_ordered_decl_len = length(&pctx->ordered_decls);
|
||||
Ast_Decl *any_decl = search_for_single_decl(module, pctx->intern("Any"_s));
|
||||
assert(any_decl->type == type_type);
|
||||
type_any = any_decl->type_val;
|
||||
|
||||
@@ -157,8 +157,7 @@ struct Lexer{
|
||||
//
|
||||
|
||||
struct Parse_Ctx:Lexer{
|
||||
Allocator *perm; // Stores: AST, tokens, interns
|
||||
Arena *perm_arena;
|
||||
Arena *perm; // Stores: AST, tokens, interns
|
||||
Allocator *heap;
|
||||
Arena stage_arena;
|
||||
|
||||
@@ -170,9 +169,9 @@ struct Parse_Ctx:Lexer{
|
||||
|
||||
Ast_Module *language_base_module;
|
||||
|
||||
Array<Ast_File *> files;
|
||||
Array<Ast_Module *> modules;
|
||||
Array<Ast_Decl *> ordered_decls;
|
||||
List<Ast_File *> files;
|
||||
List<Ast_Module *> modules;
|
||||
List<Ast_Decl *> ordered_decls;
|
||||
S32 base_language_ordered_decl_len;
|
||||
|
||||
Ast_Scope *currently_parsed_scope;
|
||||
@@ -180,7 +179,7 @@ struct Parse_Ctx:Lexer{
|
||||
U32 scope_ids;
|
||||
U32 scope_visit_id;
|
||||
|
||||
Array<String> module_folders;
|
||||
List<String> module_folders;
|
||||
String module_folder;
|
||||
String exe_folder;
|
||||
String working_folder;
|
||||
|
||||
@@ -726,15 +726,16 @@ function Ast_File *
|
||||
register_ast_file(Token *pos, String absolute_file_path, Ast_Module *module, B32 global_implicit_load){
|
||||
Ast_File *file = 0;
|
||||
|
||||
For(pctx->files){
|
||||
if(string_compare(it->absolute_file_path, absolute_file_path)){
|
||||
if(module == it->module){
|
||||
Iter(&pctx->files){
|
||||
Ast_File *it_file = it.item[0];
|
||||
if(string_compare(it_file->absolute_file_path, absolute_file_path)){
|
||||
if(module == it_file->module){
|
||||
log_trace("%Q :: Returning registered file: %Q\n", module->absolute_file_path, absolute_file_path);
|
||||
file = it;
|
||||
file = it_file;
|
||||
break;
|
||||
}
|
||||
|
||||
compiler_error(it->pos, pos, "This file is already loaded by module: %Q, try importing that module to get access to it", module->absolute_file_path);
|
||||
compiler_error(it_file->pos, pos, "This file is already loaded by module: %Q, try importing that module to get access to it", module->absolute_file_path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,9 +751,9 @@ register_ast_file(Token *pos, String absolute_file_path, Ast_Module *module, B32
|
||||
file->implicit_imports = {pctx->heap};
|
||||
file->pos = pos;
|
||||
file->debug_name = string_skip_to_last_slash(absolute_file_path);
|
||||
add(pctx->perm_arena, &file->module->all_loaded_files, file);
|
||||
add(pctx->perm, &file->module->all_loaded_files, file);
|
||||
file->scope_id = pctx->scope_ids++;
|
||||
pctx->files.add(file);
|
||||
add(pctx->perm, &pctx->files, file);
|
||||
}
|
||||
|
||||
if(global_implicit_load) {
|
||||
|
||||
@@ -353,7 +353,7 @@ type_complete(Ast_Type *type){
|
||||
}
|
||||
|
||||
type_struct_complete(type, (Ast_Decl *)type->ast);
|
||||
pctx->ordered_decls.add((Ast_Decl *)type->ast);
|
||||
add(pctx->perm, &pctx->ordered_decls, (Ast_Decl *)type->ast);
|
||||
}
|
||||
|
||||
function void
|
||||
@@ -2061,5 +2061,5 @@ resolve_decl(Ast_Decl *ast){
|
||||
ast->state = DECL_RESOLVED;
|
||||
|
||||
if(is_flag_set(ast->flags, AST_GLOBAL))
|
||||
pctx->ordered_decls.add(ast);
|
||||
add(pctx->perm, &pctx->ordered_decls, ast);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user