Using arena as token array, remove arenas idea
This commit is contained in:
@@ -10,10 +10,12 @@ static void core_init_compiler(Core_Ctx *ctx, Allocator *allocator) {
|
||||
ctx->color_codes_enabled = true;
|
||||
ctx->same_scope_token = { SAME_SCOPE };
|
||||
|
||||
ctx->perm_push_only = make_push_arena(allocator);
|
||||
arena_init(&ctx->perm_push_only, "Perm Push Only"_s);
|
||||
arena_init(&ctx->scratch_, "Scratch"_s);
|
||||
arena_init(&ctx->stage_arena_, "Stage Arena"_s);
|
||||
ctx->scratch = &ctx->scratch_;
|
||||
ctx->stage_arena = &ctx->stage_arena_;
|
||||
ctx->perm = &ctx->perm_push_only;
|
||||
ctx->scratch = allocate_scratch_arena(ctx->perm, mib(1));
|
||||
ctx->stage_arena = allocate_scratch_arena(ctx->perm, mib(1));
|
||||
ctx->heap = allocator;
|
||||
ctx->type_map = map_make(ctx->heap, 2048);
|
||||
ctx->gen = {ctx->perm};
|
||||
@@ -197,40 +199,46 @@ parse_all_modules() {
|
||||
}
|
||||
|
||||
CORE_Static Ast_Module *
|
||||
add_module(Token *pos, Intern_String filename, B32 command_line_module) {
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
add_module(Token *pos, Intern_String filename, B32 command_line_module, bool string_only_module) {
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope _scope(scratch);
|
||||
String absolute_file_path = {};
|
||||
String absolute_base_folder = {};
|
||||
|
||||
//
|
||||
// Find in working directory
|
||||
//
|
||||
if (command_line_module) {
|
||||
if (os_does_file_exist(filename.s)) {
|
||||
String path = os_get_absolute_path(scratch, filename.s);
|
||||
string_path_normalize(path);
|
||||
absolute_file_path = string_copy(scratch, path);
|
||||
absolute_base_folder = string_chop_last_slash(path);
|
||||
}
|
||||
if (string_only_module) {
|
||||
absolute_file_path = filename.s;
|
||||
absolute_base_folder = filename.s;
|
||||
}
|
||||
|
||||
//
|
||||
// Find in module folder
|
||||
//
|
||||
else {
|
||||
For(pctx->module_folders) {
|
||||
String path = string_fmt(scratch, "%Q/%Q", it, filename);
|
||||
if (os_does_file_exist(path)) {
|
||||
absolute_file_path = path;
|
||||
//
|
||||
// Find in working directory
|
||||
//
|
||||
if (command_line_module) {
|
||||
if (os_does_file_exist(filename.s)) {
|
||||
String path = os_get_absolute_path(scratch, filename.s);
|
||||
string_path_normalize(path);
|
||||
absolute_file_path = string_copy(scratch, path);
|
||||
absolute_base_folder = string_chop_last_slash(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (absolute_file_path.len == 0) {
|
||||
compiler_error(pos, "Couldn't find the module with name %Q", filename);
|
||||
//
|
||||
// Find in module folder
|
||||
//
|
||||
else {
|
||||
For(pctx->module_folders) {
|
||||
String path = string_fmt(scratch, "%Q/%Q", it, filename);
|
||||
if (os_does_file_exist(path)) {
|
||||
absolute_file_path = path;
|
||||
absolute_base_folder = string_chop_last_slash(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (absolute_file_path.len == 0) {
|
||||
compiler_error(pos, "Couldn't find the module with name %Q", filename);
|
||||
}
|
||||
}
|
||||
|
||||
For(pctx->modules) {
|
||||
@@ -280,7 +288,69 @@ compile_file_to_string(Allocator *allocator, String filename) {
|
||||
pctx->time.total = total_time;
|
||||
pctx->time.start = total_time;
|
||||
{
|
||||
Ast_Module *module = add_module(0, pctx->intern("Language.core"_s));
|
||||
Ast_Module *module = add_module(0, pctx->intern("Language.core"_s), false, true);
|
||||
get(&module->all_loaded_files, 0)->filecontent =
|
||||
R"(
|
||||
Any :: struct
|
||||
data: *void
|
||||
type: Type
|
||||
|
||||
Type_Info_Kind :: enum
|
||||
S64 // FIRST_NUMERIC
|
||||
S32
|
||||
S16
|
||||
S8
|
||||
INT
|
||||
CHAR
|
||||
U64
|
||||
U32
|
||||
U16
|
||||
U8
|
||||
F32
|
||||
F64
|
||||
POINTER
|
||||
BOOL // LAST_NUMERIC
|
||||
STRING
|
||||
VOID
|
||||
ARRAY
|
||||
LAMBDA
|
||||
STRUCT
|
||||
UNION
|
||||
ENUM
|
||||
TYPE
|
||||
SLICE
|
||||
TUPLE
|
||||
|
||||
Type_Info_Struct_Member :: struct
|
||||
name: String
|
||||
type: Type
|
||||
offset: S64
|
||||
|
||||
Type_Info :: struct
|
||||
kind: Type_Info_Kind
|
||||
size: S64
|
||||
align: S64
|
||||
is_unsigned: Bool
|
||||
type: Type
|
||||
|
||||
base_type: Type
|
||||
array_size: S64
|
||||
struct_member_count: S64
|
||||
struct_members: *Type_Info_Struct_Member
|
||||
lambda_argument_count: S64
|
||||
lambda_arguments: *Type_Info
|
||||
lambda_return: Type
|
||||
|
||||
type_infos_len: S64 #foreign
|
||||
type_infos : *Type_Info #foreign
|
||||
|
||||
GetTypeInfo :: (type: Type): *Type_Info
|
||||
id := type->S64
|
||||
if id >= type_infos_len
|
||||
return 0
|
||||
return type_infos + id
|
||||
)"_s;
|
||||
|
||||
{
|
||||
insert_builtin_type_into_scope(module, "S64"_s, pctx->type_s64);
|
||||
insert_builtin_type_into_scope(module, "S32"_s, pctx->type_s32);
|
||||
@@ -300,6 +370,11 @@ compile_file_to_string(Allocator *allocator, String filename) {
|
||||
insert_builtin_type_into_scope(module, "Type"_s, pctx->type_type);
|
||||
}
|
||||
|
||||
/*
|
||||
Ast_Decl *namespace = core_create_namespace("name");
|
||||
Ast_Decl *core_create_constant("name",
|
||||
*/
|
||||
|
||||
{
|
||||
Ast_Scope *scope = ast_decl_scope(&pctx->null_token, pctx->perm, get(&module->all_loaded_files, 0));
|
||||
Ast_Decl * decl = ast_namespace(&pctx->null_token, scope, pctx->intern("Const"_s));
|
||||
@@ -340,7 +415,7 @@ compile_file_to_string(Allocator *allocator, String filename) {
|
||||
assert(module);
|
||||
resolve_everything_in_module(module);
|
||||
|
||||
|
||||
|
||||
pctx->stage_arena->len = 0;
|
||||
String result = compile_to_c_code();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user