Factor
This commit is contained in:
@@ -342,6 +342,7 @@ enum Ast_Kind : uint32_t {
|
|||||||
AST_ENUM,
|
AST_ENUM,
|
||||||
AST_ENUM_MEMBER,
|
AST_ENUM_MEMBER,
|
||||||
AST_STRUCT,
|
AST_STRUCT,
|
||||||
|
AST_UNION,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef uint32_t Ast_Flag;
|
typedef uint32_t Ast_Flag;
|
||||||
|
|||||||
@@ -225,10 +225,9 @@ parse_init_stmt(Ast_Expr *expr) {
|
|||||||
|
|
||||||
CORE_Static Ast_Call *
|
CORE_Static Ast_Call *
|
||||||
parse_expr_call(Ast_Expr *left, Token_Kind close_kind) {
|
parse_expr_call(Ast_Expr *left, Token_Kind close_kind) {
|
||||||
Arena *scratch = pctx->scratch;
|
Scratch_Scope scratch(pctx->scratch);
|
||||||
Scratch_Scope __scope(scratch);
|
|
||||||
Token *pos = token_get();
|
Token *pos = token_get();
|
||||||
Array<Ast_Call_Item *> exprs = {scratch};
|
Array<Ast_Call_Item *> exprs = {scratch.arena};
|
||||||
|
|
||||||
while (!token_is(close_kind)) {
|
while (!token_is(close_kind)) {
|
||||||
Ast_Call_Item *item_comp = ast_new(Ast_Call_Item, AST_CALL_ITEM, token_get(), AST_EXPR);
|
Ast_Call_Item *item_comp = ast_new(Ast_Call_Item, AST_CALL_ITEM, token_get(), AST_EXPR);
|
||||||
@@ -278,14 +277,13 @@ 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
|
if (token_expect(OPEN_SCOPE)) { // @todo: Fix error message here, it doesn't show proper token context
|
||||||
Token *token_block = token_get();
|
Token *token_block = token_get();
|
||||||
|
|
||||||
Arena *scratch = pctx->scratch;
|
Scratch_Scope scratch(pctx->scratch);
|
||||||
Scratch_Scope __scope(scratch);
|
if (!scope_defined_outside) scope = begin_stmt_scope(scratch.arena, token_block);
|
||||||
if (!scope_defined_outside) scope = begin_stmt_scope(scratch, token_block);
|
|
||||||
do {
|
do {
|
||||||
Token *token = token_get();
|
Token *token = token_get();
|
||||||
|
|
||||||
if (token_match_keyword(pctx->keyword_return)) {
|
if (token_match_keyword(pctx->keyword_return)) {
|
||||||
Array<Ast_Expr *> expr = {scratch};
|
Array<Ast_Expr *> expr = {scratch.arena};
|
||||||
if (!token_is_scope()) {
|
if (!token_is_scope()) {
|
||||||
do {
|
do {
|
||||||
Ast_Expr *subexpr = parse_expr();
|
Ast_Expr *subexpr = parse_expr();
|
||||||
@@ -306,7 +304,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0) {
|
|||||||
else if (token_match_keyword(pctx->keyword_switch)) {
|
else if (token_match_keyword(pctx->keyword_switch)) {
|
||||||
Ast_Switch *result = ast_new(Ast_Switch, AST_SWITCH, token, AST_STMT);
|
Ast_Switch *result = ast_new(Ast_Switch, AST_SWITCH, token, AST_STMT);
|
||||||
result->value = parse_expr();
|
result->value = parse_expr();
|
||||||
result->cases = {scratch};
|
result->cases = {scratch.arena};
|
||||||
|
|
||||||
token_expect(OPEN_SCOPE);
|
token_expect(OPEN_SCOPE);
|
||||||
do {
|
do {
|
||||||
@@ -319,7 +317,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0) {
|
|||||||
if (token_match_pound(pctx->intern("fallthrough"_s)))
|
if (token_match_pound(pctx->intern("fallthrough"_s)))
|
||||||
switch_case->fallthrough = true;
|
switch_case->fallthrough = true;
|
||||||
|
|
||||||
switch_case->labels = {scratch};
|
switch_case->labels = {scratch.arena};
|
||||||
do {
|
do {
|
||||||
switch_case->labels.add(parse_expr());
|
switch_case->labels.add(parse_expr());
|
||||||
} while (token_match(TK_Comma));
|
} while (token_match(TK_Comma));
|
||||||
@@ -359,7 +357,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (token_match_keyword(pctx->keyword_for)) {
|
else if (token_match_keyword(pctx->keyword_for)) {
|
||||||
Ast_Scope *for_scope = begin_stmt_scope(scratch, token_get());
|
Ast_Scope *for_scope = begin_stmt_scope(scratch.arena, token_get());
|
||||||
Ast_Expr *init = 0;
|
Ast_Expr *init = 0;
|
||||||
Ast_Expr *cond = 0;
|
Ast_Expr *cond = 0;
|
||||||
Ast_Expr *iter = 0;
|
Ast_Expr *iter = 0;
|
||||||
@@ -385,7 +383,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (token_match_keyword(pctx->keyword_if)) {
|
else if (token_match_keyword(pctx->keyword_if)) {
|
||||||
Array<Ast_If_Node *> if_nodes = {scratch};
|
Array<Ast_If_Node *> if_nodes = {scratch.arena};
|
||||||
Ast_Expr *expr = parse_expr();
|
Ast_Expr *expr = parse_expr();
|
||||||
Ast_Expr *init_val = parse_init_stmt(expr);
|
Ast_Expr *init_val = parse_init_stmt(expr);
|
||||||
if (init_val != expr) {
|
if (init_val != expr) {
|
||||||
@@ -421,7 +419,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0) {
|
|||||||
scope->stmts.add(result_if);
|
scope->stmts.add(result_if);
|
||||||
}
|
}
|
||||||
else if (token_is(TK_Identifier) && token_is(TK_Comma, 1)) {
|
else if (token_is(TK_Identifier) && token_is(TK_Comma, 1)) {
|
||||||
Array<Ast_Decl *> decls = {scratch};
|
Array<Ast_Decl *> decls = {scratch.arena};
|
||||||
do {
|
do {
|
||||||
Token *name = token_match(TK_Identifier);
|
Token *name = token_match(TK_Identifier);
|
||||||
Ast_Decl *decl = ast_var(name, 0, name->intern_val, 0);
|
Ast_Decl *decl = ast_var(name, 0, name->intern_val, 0);
|
||||||
@@ -461,10 +459,9 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0) {
|
|||||||
|
|
||||||
CORE_Static Ast_Lambda *
|
CORE_Static Ast_Lambda *
|
||||||
parse_lambda(Token *token) {
|
parse_lambda(Token *token) {
|
||||||
Arena *scratch = pctx->scratch;
|
Scratch_Scope scratch(pctx->scratch);
|
||||||
Scratch_Scope __scope(scratch);
|
|
||||||
|
|
||||||
Array<Ast_Decl *> params = {scratch};
|
Array<Ast_Decl *> params = {scratch.arena};
|
||||||
if (!token_is(TK_CloseParen)) {
|
if (!token_is(TK_CloseParen)) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Token *name = token_get();
|
Token *name = token_get();
|
||||||
@@ -487,7 +484,7 @@ parse_lambda(Token *token) {
|
|||||||
}
|
}
|
||||||
token_expect(TK_CloseParen);
|
token_expect(TK_CloseParen);
|
||||||
|
|
||||||
Array<Ast_Expr *> ret = {scratch};
|
Array<Ast_Expr *> ret = {scratch.arena};
|
||||||
if (token_match(TK_Colon)) {
|
if (token_match(TK_Colon)) {
|
||||||
do {
|
do {
|
||||||
Ast_Expr *typespec = parse_expr();
|
Ast_Expr *typespec = parse_expr();
|
||||||
@@ -696,11 +693,10 @@ parse_assign_expr() {
|
|||||||
|
|
||||||
CORE_Static Ast_Decl *
|
CORE_Static Ast_Decl *
|
||||||
parse_struct(Token *pos) {
|
parse_struct(Token *pos) {
|
||||||
Arena *scratch = pctx->scratch;
|
Scratch_Scope scratch(pctx->scratch);
|
||||||
Scratch_Scope __scope(scratch);
|
|
||||||
|
|
||||||
token_match(OPEN_SCOPE);
|
token_match(OPEN_SCOPE);
|
||||||
Ast_Scope *scope = begin_decl_scope(scratch, token_get());
|
Ast_Scope *scope = begin_decl_scope(scratch.arena, token_get());
|
||||||
do {
|
do {
|
||||||
Token *token = token_expect(TK_Identifier);
|
Token *token = token_expect(TK_Identifier);
|
||||||
token_expect(TK_Colon);
|
token_expect(TK_Colon);
|
||||||
@@ -721,13 +717,12 @@ parse_struct(Token *pos) {
|
|||||||
|
|
||||||
CORE_Static Ast_Decl *
|
CORE_Static Ast_Decl *
|
||||||
parse_enum(Token *pos) {
|
parse_enum(Token *pos) {
|
||||||
Arena *scratch = pctx->scratch;
|
Scratch_Scope scratch(pctx->scratch);
|
||||||
Scratch_Scope __scope(scratch);
|
|
||||||
Ast_Expr *typespec = parse_optional_type();
|
Ast_Expr *typespec = parse_optional_type();
|
||||||
Token *flag = token_match_pound(pctx->intern_flag);
|
Token *flag = token_match_pound(pctx->intern_flag);
|
||||||
|
|
||||||
token_match(OPEN_SCOPE);
|
token_match(OPEN_SCOPE);
|
||||||
Ast_Scope *scope = begin_decl_scope(scratch, token_get());
|
Ast_Scope *scope = begin_decl_scope(scratch.arena, token_get());
|
||||||
do {
|
do {
|
||||||
Token *name = token_expect(TK_Identifier);
|
Token *name = token_expect(TK_Identifier);
|
||||||
Ast_Expr *value = 0;
|
Ast_Expr *value = 0;
|
||||||
@@ -947,8 +942,7 @@ parse_decl(B32 is_global) {
|
|||||||
CORE_Static void
|
CORE_Static void
|
||||||
parse_file(Ast_File *file) {
|
parse_file(Ast_File *file) {
|
||||||
assert(file);
|
assert(file);
|
||||||
Arena *scratch = pctx->scratch;
|
Scratch_Scope scratch(pctx->scratch);
|
||||||
Scratch_Scope __scope(scratch);
|
|
||||||
|
|
||||||
if (!file->filecontent.len) {
|
if (!file->filecontent.len) {
|
||||||
file->filecontent = os_read_file(pctx->perm, file->absolute_file_path);
|
file->filecontent = os_read_file(pctx->perm, file->absolute_file_path);
|
||||||
|
|||||||
Reference in New Issue
Block a user