More module work
This commit is contained in:
83
ccodegen.cpp
83
ccodegen.cpp
@@ -400,7 +400,7 @@ gen_ast(Ast *ast){
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(FILE_NAMESPACE, Decl){unused(node); BREAK();}
|
||||
CASE(FILE_NAMESPACE, File_Namespace){unused(node); BREAK();}
|
||||
|
||||
default: {
|
||||
assert(is_flag_set(ast->flags, AST_EXPR));
|
||||
@@ -422,7 +422,6 @@ parse_file(Ast_File *file){
|
||||
pctx->currently_parsed_file = file;
|
||||
String name = string_chop_last_period(file->filename.s);
|
||||
file->name = pctx->intern(name);
|
||||
file->scope = ast_decl_scope(0, pctx->heap);
|
||||
|
||||
pctx->currently_parsed_scope = file->scope;
|
||||
lex_restream(pctx, file->filecontent, file->filename.s);
|
||||
@@ -435,7 +434,7 @@ parse_file(Ast_File *file){
|
||||
Ast_Decl *decl = parse_decl(true);
|
||||
if(!decl) break;
|
||||
|
||||
set_flag(decl->flags, AST_FILE_NAMESPACE_LEVEL);
|
||||
set_flag(decl->flags, AST_GLOBAL);
|
||||
if(decl->kind == AST_STRUCT){
|
||||
decl->type = type_type;
|
||||
decl->type_val = type_incomplete(decl);
|
||||
@@ -448,12 +447,16 @@ parse_file(Ast_File *file){
|
||||
pctx->currently_parsed_file = 0;
|
||||
}
|
||||
|
||||
global F64 parsing_time_begin;
|
||||
global F64 parsing_time_end;
|
||||
function void
|
||||
parse_files(Ast_Module *module){
|
||||
parsing_time_begin = os_time();
|
||||
for(S64 i = 0; i < module->files.len; i++){
|
||||
auto it = module->files.data[i];
|
||||
parse_file(it);
|
||||
}
|
||||
parsing_time_end = os_time();
|
||||
}
|
||||
|
||||
function void
|
||||
@@ -496,16 +499,21 @@ parse_module(String filename){
|
||||
return result;
|
||||
}
|
||||
|
||||
global F64 resolving_time_begin;
|
||||
global F64 resolving_time_end;
|
||||
function void
|
||||
resolve_everything_in_module(Ast_Module *module){
|
||||
For(module->files){
|
||||
For_It(it->scope->decls, jt){
|
||||
resolving_time_begin = os_time();
|
||||
for(S64 i = 0; i < module->files.len; i++){
|
||||
Ast_File *it = module->files[i];
|
||||
For_Named(it->scope->decls, jt){
|
||||
resolve_name(it->scope, jt->pos, jt->name);
|
||||
if(jt->kind == AST_STRUCT){
|
||||
type_complete(jt->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
resolving_time_end = os_time();
|
||||
}
|
||||
|
||||
function void
|
||||
@@ -516,8 +524,11 @@ begin_compilation(){
|
||||
parse_init(ctx, &pernament_arena, heap);
|
||||
}
|
||||
|
||||
global F64 generating_time_begin;
|
||||
global F64 generating_time_end;
|
||||
function String
|
||||
end_compilation(){
|
||||
generating_time_begin = os_time();
|
||||
For(pctx->ordered_decls){
|
||||
genln("");
|
||||
gen_ast(it);
|
||||
@@ -525,72 +536,12 @@ end_compilation(){
|
||||
|
||||
exp_destroy(pctx->heap);
|
||||
String string_result = string_flatten(pctx->perm, &pctx->gen);
|
||||
generating_time_end = os_time();
|
||||
return string_result;
|
||||
}
|
||||
|
||||
#if 0
|
||||
function String
|
||||
compile_files(Array<String> filename){
|
||||
Scratch scratch(thread_ctx.scratch);
|
||||
Array<Ast_File> files = {scratch};
|
||||
|
||||
For(filename){
|
||||
String filecontent = os_read_file(scratch, it);
|
||||
assert(filecontent.len);
|
||||
files.add(ast_file(it, filecontent));
|
||||
}
|
||||
|
||||
F64 total_time = os_time();
|
||||
OS_Heap heap = win32_os_heap_create(false, mib(16), 0);
|
||||
|
||||
Parse_Ctx ctx = {};
|
||||
parse_init(&ctx, scratch, &heap);
|
||||
|
||||
F64 parse_begin = os_time();
|
||||
pctx->packages = {&heap};
|
||||
For(files){
|
||||
Scratch file_scratch;
|
||||
lex_restream(pctx, it.filecontent, it.filename);
|
||||
|
||||
// Figure out package name
|
||||
// by default it's name of the file
|
||||
// but if you add [package name] then it's overwritten
|
||||
Token *token = token_get();
|
||||
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();
|
||||
Token *package_token = token_expect(TK_Identifier);
|
||||
it.name = package_token->intern_val;
|
||||
}
|
||||
|
||||
Ast_File_Namespace *package = find_package(it.name, &pctx->packages);
|
||||
if(package){
|
||||
package->scope->decls.add(it.decls);
|
||||
} else {
|
||||
package = ast_file_namespace(token, &heap, it.name);
|
||||
insert_builtin_types_into_package(package);
|
||||
pctx->packages.add(package);
|
||||
}
|
||||
|
||||
pctx->currently_parsed_scope = package->scope;
|
||||
while(token_expect(SAME_SCOPE)){
|
||||
Ast_Decl *decl = parse_decl(true);
|
||||
if(!decl) break;
|
||||
|
||||
set_flag(decl->flags, AST_FILE_NAMESPACE_LEVEL);
|
||||
if(decl->kind == AST_STRUCT){
|
||||
decl->type = type_type;
|
||||
decl->type_val = type_incomplete(decl);
|
||||
decl->state = DECL_RESOLVED;
|
||||
}
|
||||
|
||||
insert_into_scope(package->scope, decl);
|
||||
}
|
||||
pctx->currently_parsed_scope = 0;
|
||||
|
||||
}
|
||||
F64 parse_end = os_time();
|
||||
|
||||
For(pctx->packages){
|
||||
|
||||
Reference in New Issue
Block a user