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(" " + i[0] + ",") */ Mul, Div, Mod, LeftShift, RightShift, FirstMul = TK_Mul, LastMul = TK_RightShift, Add, Sub, FirstAdd = TK_Add, LastAdd = TK_Sub, Equals, LesserThenOrEqual, GreaterThenOrEqual, LesserThen, GreaterThen, NotEquals, FirstCompare = TK_Equals, LastCompare = TK_NotEquals, BitAnd, BitOr, BitXor, And, Or, FirstLogical = TK_BitAnd, LastLogical = TK_Or, Neg, Not, Decrement, Increment, PostDecrement, PostIncrement, Assign, ColonAssign, DivAssign, MulAssign, ModAssign, SubAssign, AddAssign, AndAssign, OrAssign, XorAssign, LeftShiftAssign, RightShiftAssign, FirstAssign = TK_Assign, 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 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);