Move interns into Core_Ctx
This commit is contained in:
@@ -282,7 +282,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
do{
|
||||
Token *token = token_get();
|
||||
|
||||
if(token_match_keyword(keyword_return)){
|
||||
if(token_match_keyword(pctx->keyword_return)){
|
||||
Array<Ast_Expr *> expr = {scratch};
|
||||
if(!token_is_scope()) {
|
||||
do{
|
||||
@@ -293,22 +293,22 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
scope->stmts.add(ast_return(token, expr));
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_break)){
|
||||
else if(token_match_keyword(pctx->keyword_break)){
|
||||
scope->stmts.add(ast_break(token));
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_pass)){
|
||||
else if(token_match_keyword(pctx->keyword_pass)){
|
||||
scope->stmts.add(ast_pass(token));
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_switch)){
|
||||
else if(token_match_keyword(pctx->keyword_switch)){
|
||||
Ast_Switch *result = ast_new(Ast_Switch, AST_SWITCH, token, AST_STMT);
|
||||
result->value = parse_expr();
|
||||
result->cases = {scratch};
|
||||
|
||||
token_expect(OPEN_SCOPE);
|
||||
do{
|
||||
if(token_match_keyword(keyword_default)){
|
||||
if(token_match_keyword(pctx->keyword_default)){
|
||||
result->default_scope = parse_stmt_scope();
|
||||
continue;
|
||||
}
|
||||
@@ -332,7 +332,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
scope->stmts.add(result);
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_assert)){
|
||||
else if(token_match_keyword(pctx->keyword_assert)){
|
||||
token_expect(TK_OpenParen);
|
||||
Ast_Expr *expr = parse_expr();
|
||||
Intern_String message = {};
|
||||
@@ -344,7 +344,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
scope->stmts.add(ast_runtime_assert(token, expr, message));
|
||||
}
|
||||
|
||||
else if(token_match_pound(keyword_assert)){
|
||||
else if(token_match_pound(pctx->keyword_assert)){
|
||||
token_expect(TK_OpenParen);
|
||||
Ast_Expr *expr = parse_expr();
|
||||
Intern_String message = {};
|
||||
@@ -356,7 +356,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
scope->stmts.add(ast_constant_assert(token, expr, message));
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_for)){
|
||||
else if(token_match_keyword(pctx->keyword_for)){
|
||||
Ast_Scope *for_scope = begin_stmt_scope(scratch, token_get());
|
||||
Ast_Expr *init = 0;
|
||||
Ast_Expr *cond = 0;
|
||||
@@ -382,7 +382,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
scope->stmts.add(ast_for(token, init, cond, iter, for_scope));
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_if)){
|
||||
else if(token_match_keyword(pctx->keyword_if)){
|
||||
Array<Ast_If_Node *> if_nodes = {scratch};
|
||||
Ast_Expr *expr = parse_expr();
|
||||
Ast_Expr *init_val = parse_init_stmt(expr);
|
||||
@@ -396,19 +396,19 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
Ast_If_Node *if_node = ast_if_node(token, init_val, expr, if_block);
|
||||
if_nodes.add(if_node);
|
||||
|
||||
while(token_is(SAME_SCOPE) && (token_is_keyword(keyword_elif, 1) || (token_is_keyword(keyword_else, 1)))){
|
||||
while(token_is(SAME_SCOPE) && (token_is_keyword(pctx->keyword_elif, 1) || (token_is_keyword(pctx->keyword_else, 1)))){
|
||||
token_next();
|
||||
token = token_get();
|
||||
if(token_match_keyword(keyword_elif)){
|
||||
assert(token->intern_val == keyword_elif);
|
||||
if(token_match_keyword(pctx->keyword_elif)){
|
||||
assert(token->intern_val == pctx->keyword_elif);
|
||||
Ast_Expr *expr = parse_expr();
|
||||
Ast_Scope *else_if_block = parse_stmt_scope();
|
||||
Ast_If_Node *if_node = ast_if_node(token, 0, expr, else_if_block);
|
||||
if_nodes.add(if_node);
|
||||
}
|
||||
else{
|
||||
token_match_keyword(keyword_else);
|
||||
assert(token->intern_val == keyword_else);
|
||||
token_match_keyword(pctx->keyword_else);
|
||||
assert(token->intern_val == pctx->keyword_else);
|
||||
Ast_Scope *else_block = parse_stmt_scope();
|
||||
Ast_If_Node *if_node = ast_if_node(token, 0, 0, else_block);
|
||||
if_nodes.add(if_node);
|
||||
@@ -494,7 +494,7 @@ parse_lambda(Token *token){
|
||||
ret.add(typespec);
|
||||
}while(token_match(TK_Comma));
|
||||
}
|
||||
else ret.add(ast_ident(token, intern_void));
|
||||
else ret.add(ast_ident(token, pctx->intern_void));
|
||||
|
||||
Ast_Scope *scope = token_is(OPEN_SCOPE) ? parse_stmt_scope() : 0;
|
||||
Ast_Lambda *result = ast_lambda(token, params, ret, scope);
|
||||
@@ -612,9 +612,9 @@ parse_expr(S64 min_bp){
|
||||
}break;
|
||||
|
||||
case TK_Keyword: {
|
||||
if(token->intern_val == keyword_true)
|
||||
if(token->intern_val == pctx->keyword_true)
|
||||
left = ast_bool(token, 1);
|
||||
else if(token->intern_val == keyword_false)
|
||||
else if(token->intern_val == pctx->keyword_false)
|
||||
left = ast_bool(token, 0);
|
||||
else compiler_error(token, "Unexpected keyword: [%s]", token->intern_val.str);
|
||||
}break;
|
||||
@@ -717,7 +717,7 @@ parse_enum(Token *pos){
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope __scope(scratch);
|
||||
Ast_Expr *typespec = parse_optional_type();
|
||||
Token *flag = token_match_pound(intern_flag);
|
||||
Token *flag = token_match_pound(pctx->intern_flag);
|
||||
|
||||
token_match(OPEN_SCOPE);
|
||||
Ast_Scope *scope = begin_decl_scope(scratch, token_get());
|
||||
@@ -845,18 +845,18 @@ parse_decl(B32 is_global){
|
||||
Token *tname = token_get();
|
||||
if(token_match(TK_Identifier, TK_DoubleColon)){
|
||||
|
||||
if(token_match_pound(intern_foreign)){
|
||||
if(token_match_pound(pctx->intern_foreign)){
|
||||
set_flag(flags, AST_FOREIGN);
|
||||
} else if(token_match_pound(intern_strict)){
|
||||
} else if(token_match_pound(pctx->intern_strict)){
|
||||
set_flag(flags, AST_STRICT);
|
||||
}
|
||||
|
||||
// @note parse struct binding
|
||||
if(token_match_keyword(keyword_struct)){
|
||||
if(token_match_keyword(pctx->keyword_struct)){
|
||||
result = parse_struct(tname);
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_enum)){
|
||||
else if(token_match_keyword(pctx->keyword_enum)){
|
||||
result = parse_enum(tname);
|
||||
}
|
||||
|
||||
@@ -914,7 +914,7 @@ parse_decl(B32 is_global){
|
||||
else if(token_match(TK_Identifier, TK_Colon)){
|
||||
Ast_Expr *typespec = parse_expr();
|
||||
Ast_Expr *expr = parse_assign_expr();
|
||||
if(token_match_pound(intern_foreign))
|
||||
if(token_match_pound(pctx->intern_foreign))
|
||||
set_flag(flags, AST_FOREIGN);
|
||||
|
||||
result = ast_var(tname, typespec, tname->intern_val, expr);
|
||||
@@ -952,13 +952,13 @@ parse_file(Ast_File *file){
|
||||
pctx->currently_parsed_scope = file;
|
||||
lex_restream(pctx, file->filecontent, file->absolute_file_path);
|
||||
while (token_expect(SAME_SCOPE)) {
|
||||
if (token_match_pound(intern_load)) {
|
||||
if (token_match_pound(pctx->intern_load)) {
|
||||
parse_load(true);
|
||||
continue;
|
||||
} else if (token_match_pound(intern_import)) {
|
||||
} else if (token_match_pound(pctx->intern_import)) {
|
||||
parse_import(true);
|
||||
continue;
|
||||
} else if (token_match_pound(intern_link)) {
|
||||
} else if (token_match_pound(pctx->intern_link)) {
|
||||
Token *file = token_expect(TK_StringLit);
|
||||
add(pctx->perm, &pctx->files_to_link, file);
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user