From 2503a6d680e288cafc1935fdf6e0fec8bebe89b4 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 13 Jun 2022 15:24:50 +0200 Subject: [PATCH] Fix adding loads multiple times --- ast.cpp | 5 +---- globals.kl | 3 +++ parsing.cpp | 23 ++++++++++++++++++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ast.cpp b/ast.cpp index 82a345b..2470ec3 100644 --- a/ast.cpp +++ b/ast.cpp @@ -200,6 +200,7 @@ enum Ast_Decl_State{ }; struct Ast_Scope: Ast{ + Intern_String name; // for debugging Array implicit_imports; Array decls; Array stmts; @@ -210,16 +211,12 @@ struct Ast_Scope: Ast{ struct Ast_Module: Ast_Scope{ - Intern_String name; Array all_loaded_files; }; struct Ast_File: Ast_Scope{ Intern_String filename; - - B32 global_implicit_load; String filecontent; - Intern_String name; }; struct Ast_Decl: Ast{ diff --git a/globals.kl b/globals.kl index c0cefe1..92a2f7e 100644 --- a/globals.kl +++ b/globals.kl @@ -1,5 +1,8 @@ lambdas :: #load "lambdas.kl" Memory :: #load "enums.kl" +#load "lambdas.kl" +#load "lambdas.kl" +#import "order1.kl" #import "order1.kl" order :: #import "order1.kl" diff --git a/parsing.cpp b/parsing.cpp index e797013..4c8637d 100644 --- a/parsing.cpp +++ b/parsing.cpp @@ -583,6 +583,20 @@ parse_enum(Token *pos){ return result; } +function void +add_implicit_import(Ast_Scope *scope, Ast_Scope *add){ + B32 found = false; + For(scope->implicit_imports){ + if(it == add){ + found = true; + break; + } + } + if(!found){ + scope->implicit_imports.add(add); + } +} + function Ast_File * register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implicit_load){ Ast_File *file = 0; @@ -593,8 +607,8 @@ register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implici } } if(!file){ - file = exp_alloc_type(pctx->perm, Ast_File, AF_ZeroMemory); - file->kind = AST_FILE; + AST_NEW(File, FILE, 0, 0); + file = result; file->filename = filename; file->module = module; file->file = file; // @warning: self referential! @@ -604,8 +618,7 @@ register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implici } if(global_implicit_load) { - file->global_implicit_load = true; - module->implicit_imports.add(file); + add_implicit_import(module, file); } return file; @@ -624,7 +637,7 @@ parse_import(B32 global_implicit_import){ Token *file = token_expect(TK_StringLit); Ast_Module *result = add_module(file->intern_val); if(global_implicit_import){ - pctx->currently_parsed_file->module->implicit_imports.add(result); + add_implicit_import(pctx->currently_parsed_file->module, result); } return result; }