Files
corelang/core_compiler.h
2023-01-01 10:48:06 +01:00

89 lines
2.0 KiB
C

/*
* Get rid of Scratch, move that concept onto the main context, create scratch memory from user allocator
* Simplify allocators, only should be derived from the user allocator
* Cleanup big int allocator
* Replace iterator interface
* Reset compiler
*/
struct Lex_Stream{
String stream;
S64 iter;
U8 *line_begin;
Intern_String file;
S32 line;
S32 inside_brace_paren;
Array<Token *> indent_stack;
};
struct Core_Ctx{
Arena *perm; // Stores: AST, tokens, interns
Allocator *heap;
Scratch_Arena *scratch;
Arena stage_arena;
// Lexer stuff
Lex_Stream stream;
Array<Token> tokens;
Intern_Table interns;
S64 token_iter;
U32 token_debug_ids;
// Types
List<Ast_Type *> all_types;
S32 type_ids;
int lambda_ids;
U64 unique_ids; // @Debug
Map type_map;
Ast_Module *language_base_module;
List<Ast_File *> files;
List<Ast_Module *> modules;
List<Ast_Decl *> ordered_decls;
S32 base_language_ordered_decl_len;
Ast_Scope *currently_parsed_scope;
Ast_File *currently_parsed_file;
U32 scope_ids;
U32 scope_visit_id;
List<String> module_folders;
String module_folder;
String exe_folder;
String working_folder;
List<Token *> files_to_link;
S64 indent;
String_Builder gen;
String_Builder helper_builder;
F64 generating_time_begin;
F64 generating_time_end;
F64 resolving_time_begin;
F64 resolving_time_end;
F64 total_time;
F64 init_ctx_time_begin;
F64 init_ctx_time_end;
F64 parsing_time_begin;
F64 parsing_time_end;
Intern_String intern(String string){
assert(string.len > 0);
return intern_string(&interns, string);
}
};
CORE_Static void init_type();
CORE_Static String compile_to_c_code();
CORE_Static Ast_Module *ast_module(Token *pos, Intern_String filename);
CORE_Static void insert_builtin_types_into_scope(Ast_Scope *p);
CORE_Static void insert_into_scope(Ast_Scope *scope, Ast_Decl *decl);
CORE_Static Ast_Type *type_incomplete(Ast *ast);
CORE_Static Ast_Expr *parse_expr(S64 minbp = 0);