Using arena as token array, remove arenas idea
This commit is contained in:
@@ -43,33 +43,33 @@ String core_stringify_message(Core_Ctx *pctx, Allocator *allocator, Core_Message
|
||||
|
||||
b.addf("%Q", msg->string);
|
||||
|
||||
for (int i = 0; i < buff_cap(msg->tokens); i += 1) {
|
||||
for (S64 i = 0; i < buff_cap(msg->tokens); i += 1) {
|
||||
Token *token = msg->tokens[i];
|
||||
if (token) {
|
||||
b.addf("\n");
|
||||
// Print from line begin to token
|
||||
int i1 = token->str - token->line_begin;
|
||||
S64 i1 = token->str - token->line_begin;
|
||||
b.addf("%.*s", i1, token->line_begin);
|
||||
|
||||
// Print token part
|
||||
if(color_codes_enabled){
|
||||
b.addf( PRINTF_RED "%.*s" PRINTF_RESET, (int)token->len, token->str);
|
||||
b.addf( PRINTF_RED "%.*s" PRINTF_RESET, (S64)token->len, token->str);
|
||||
} else {
|
||||
b.addf("%.*s", (int)token->len, token->str);
|
||||
b.addf("%.*s", (S64)token->len, token->str);
|
||||
}
|
||||
|
||||
// Print to end of line from token
|
||||
int iend = 0;
|
||||
S64 iend = 0;
|
||||
U8 *pointer = token->str + token->len;
|
||||
while(pointer[iend]!='\n' && pointer[iend]!=0) iend++;
|
||||
b.addf("%.*s", iend, pointer);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < buff_cap(msg->tokens); i += 1) {
|
||||
for (S64 i = 0; i < buff_cap(msg->tokens); i += 1) {
|
||||
Token *it = msg->tokens[i];
|
||||
if (it) {
|
||||
b.addf("\n%s:%d", it->file.str, (int)it->line + 1);
|
||||
b.addf("\n%s:%d", it->file.str, (S64)it->line + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ parse_init_stmt(Ast_Expr *expr){
|
||||
|
||||
CORE_Static Ast_Call *
|
||||
parse_expr_call(Ast_Expr *left, Token_Kind close_kind){
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope __scope(scratch);
|
||||
Token *pos = token_get();
|
||||
Array<Ast_Call_Item *> exprs = {scratch};
|
||||
@@ -275,7 +275,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
if(token_expect(OPEN_SCOPE)){ // @todo: Fix error message here, it doesn't show proper token context
|
||||
Token *token_block = token_get();
|
||||
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope __scope(scratch);
|
||||
if(!scope_defined_outside) scope = begin_stmt_scope(scratch, token_block);
|
||||
do{
|
||||
@@ -460,7 +460,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
|
||||
CORE_Static Ast_Lambda *
|
||||
parse_lambda(Token *token){
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope __scope(scratch);
|
||||
|
||||
Array<Ast_Decl *> params = {scratch};
|
||||
@@ -688,7 +688,7 @@ parse_assign_expr(){
|
||||
|
||||
CORE_Static Ast_Decl *
|
||||
parse_struct(Token *pos){
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope __scope(scratch);
|
||||
|
||||
token_match(OPEN_SCOPE);
|
||||
@@ -713,7 +713,7 @@ parse_struct(Token *pos){
|
||||
|
||||
CORE_Static Ast_Decl *
|
||||
parse_enum(Token *pos){
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope __scope(scratch);
|
||||
Ast_Expr *typespec = parse_optional_type();
|
||||
Token *flag = token_match_pound(pctx->intern_flag);
|
||||
@@ -756,15 +756,15 @@ CORE_Static Ast_File *
|
||||
register_ast_file(Token *pos, String absolute_file_path, Ast_Module *module, B32 global_implicit_load){
|
||||
Ast_File *file = 0;
|
||||
|
||||
For_Named(pctx->files, it_file){
|
||||
if(string_compare(it_file->absolute_file_path, absolute_file_path)){
|
||||
if(module == it_file->module){
|
||||
For(pctx->files){
|
||||
if(string_compare(it->absolute_file_path, absolute_file_path)){
|
||||
if(module == it->module){
|
||||
log_trace("%Q :: Returning registered file: %Q\n", module->absolute_file_path, absolute_file_path);
|
||||
file = it_file;
|
||||
file = it;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ parse_load(B32 global_implicit_load){
|
||||
return result;
|
||||
}
|
||||
|
||||
CORE_Static Ast_Module *add_module(Token *pos, Intern_String filename, B32 command_line_module = false);
|
||||
CORE_Static Ast_Module *add_module(Token *pos, Intern_String filename, B32 command_line_module = false, bool string_only_module = false);
|
||||
CORE_Static Ast_Module *
|
||||
parse_import(B32 global_implicit_import){
|
||||
Token *file = token_expect(TK_StringLit);
|
||||
@@ -938,12 +938,14 @@ parse_decl(B32 is_global){
|
||||
CORE_Static void
|
||||
parse_file(Ast_File *file){
|
||||
assert(file);
|
||||
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope __scope(scratch);
|
||||
file->filecontent = os_read_file(pctx->perm, file->absolute_file_path);
|
||||
if(file->filecontent.len == 0){
|
||||
compiler_error(file->pos, "Failed to open file \"%Q\"", file->absolute_file_path);
|
||||
|
||||
if (!file->filecontent.len) {
|
||||
file->filecontent = os_read_file(pctx->perm, file->absolute_file_path);
|
||||
if(file->filecontent.len == 0){
|
||||
compiler_error(file->pos, "Failed to open file \"%Q\"", file->absolute_file_path);
|
||||
}
|
||||
}
|
||||
|
||||
pctx->currently_parsed_file = file;
|
||||
|
||||
Reference in New Issue
Block a user