struct Ast_Scope; struct Ast_Decl; struct Ast_File_Namespace; struct Ast_File; struct Ast_Module; struct Ast_Type; struct Ast; struct Ast_Expr; enum Token_Kind{ TK_End, /*# import meta for i in meta.token_kinds: print(" TK_" + i[0] + ",") */ TK_Mul, TK_Div, TK_Mod, TK_LeftShift, TK_RightShift, TK_FirstMul = TK_Mul, TK_LastMul = TK_RightShift, TK_Add, TK_Sub, TK_FirstAdd = TK_Add, TK_LastAdd = TK_Sub, TK_Equals, TK_LesserThenOrEqual, TK_GreaterThenOrEqual, TK_LesserThen, TK_GreaterThen, TK_NotEquals, TK_FirstCompare = TK_Equals, TK_LastCompare = TK_NotEquals, TK_BitAnd, TK_BitOr, TK_BitXor, TK_And, TK_Or, TK_FirstLogical = TK_BitAnd, TK_LastLogical = TK_Or, TK_Neg, TK_Not, TK_Decrement, TK_Increment, TK_PostDecrement, TK_PostIncrement, TK_Assign, TK_ColonAssign, TK_DivAssign, TK_MulAssign, TK_ModAssign, TK_SubAssign, TK_AddAssign, TK_AndAssign, TK_OrAssign, TK_XorAssign, TK_LeftShiftAssign, TK_RightShiftAssign, TK_FirstAssign = TK_Assign, TK_LastAssign = TK_RightShiftAssign, TK_OpenParen, TK_CloseParen, TK_OpenBrace, TK_CloseBrace, TK_OpenBracket, TK_CloseBracket, TK_Comma, TK_Pound, TK_Question, TK_ThreeDots, TK_Semicolon, TK_Dot, TK_TwoDots, TK_NewLine, TK_Colon, TK_DoubleColon, TK_At, TK_Arrow, TK_ExprSizeof, TK_DocComment, TK_Comment, TK_Identifier, TK_UnicodeLit, TK_StringLit, TK_Error, TK_Float, TK_Integer, TK_Keyword, /*END*/ TK_Pointer = TK_Mul, TK_Dereference = TK_BitAnd, OPEN_SCOPE = 128, CLOSE_SCOPE, SAME_SCOPE, }; struct Token{ Token_Kind kind; U32 di; // debug_id union{ String string; struct{U8 *str; S64 len;}; }; union { U32 unicode; BigInt int_val; F64 f64_val; String error_val; Intern_String intern_val; S64 indent; }; Intern_String file; S32 line; U8 *line_begin; }; struct Lex_Stream{ String stream; S64 iter; U8 *line_begin; Intern_String file; S32 line; S32 inside_brace_paren; Array indent_stack; }; struct Lexer{ Allocator *arena; Lex_Stream stream; Array tokens; Intern_Table interns; S64 token_iter; U32 token_debug_ids; Intern_String first_op; Intern_String last_op ; Intern_String intern(String string){ return intern_string(&interns, string); } }; // Lexer::interns::map::allocator - array allocator, resizing // Lexer::tokens - array allocator, resizing // // Parser::ast_arena - arena for asts // Lexer::interns::string_allocator - arena for interns // struct Parse_Ctx:Lexer{ Allocator *perm; // Stores: AST, tokens, interns Arena *perm_arena; Allocator *heap; Arena stage_arena; Array all_types; S32 type_ids; int lambda_ids; U64 unique_ids; // @Debug Map type_map; Ast_Module *language_base_module; Array files; Array modules; Array 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; Array module_folders; String module_folder; String exe_folder; String working_folder; S64 indent; String_Builder gen; String_Builder helper_builder; }; function void init_type(); function void lex_init(Allocator *token_string_arena, Allocator *map_allocator, Lexer *l); function String compile_to_c_code(); function Ast_Module *ast_module(Token *pos, Intern_String filename); function void insert_builtin_types_into_scope(Ast_Scope *p); function void insert_into_scope(Ast_Scope *scope, Ast_Decl *decl); function Ast_Type *type_incomplete(Ast *ast); function Ast_Expr *parse_expr(S64 minbp = 0);