Core: Add continue keyword
This commit is contained in:
@@ -197,12 +197,9 @@ MAP_PathFindStep :: (s: *MAP_Actor, compute_history: bool = true): bool
|
||||
Add(&s.close_paths, it)
|
||||
|
||||
|
||||
// @language_todo: Add continue keyword
|
||||
// if x == 0 && y == 0 ;; continue
|
||||
|
||||
for y := -1, y <= 1, y += 1
|
||||
for x := -1, x <= 1, x += 1
|
||||
if (x == 0 && y == 0) == false
|
||||
if x == 0 && y == 0 ;; continue
|
||||
p := V2I{it.p.x + x, it.p.y + y}
|
||||
MAP_InsertOpenPath(s, p, it.p)
|
||||
|
||||
|
||||
@@ -156,6 +156,12 @@ ast_break(Token *pos) {
|
||||
return result;
|
||||
}
|
||||
|
||||
CORE_Static Ast_Pass *
|
||||
ast_continue(Token *pos) {
|
||||
AST_NEW(Pass, CONTINUE, pos, AST_STMT);
|
||||
return result;
|
||||
}
|
||||
|
||||
CORE_Static Ast_Return *
|
||||
ast_return(Token *pos, Array<Ast_Expr *> expr) {
|
||||
AST_NEW(Return, RETURN, pos, AST_STMT);
|
||||
@@ -541,8 +547,9 @@ void next(Ast_Iter *iter) {
|
||||
For(node->vars) iter->stack.add(it);
|
||||
} break;
|
||||
|
||||
case AST_BREAK:
|
||||
case AST_PASS:
|
||||
case AST_BREAK: {
|
||||
case AST_CONTINUE: {
|
||||
Ast *node = (Ast *)ast;
|
||||
} break;
|
||||
|
||||
|
||||
@@ -635,6 +635,12 @@ gen_ast(Ast *ast) {
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(CONTINUE, Pass) {
|
||||
unused(node);
|
||||
gen("continue;");
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(BREAK, Break) {
|
||||
unused(node);
|
||||
gen("break;");
|
||||
|
||||
@@ -54,6 +54,7 @@ for i in meta.token_simple_expr:
|
||||
pctx->keyword_union = pctx->intern("union"_s);
|
||||
pctx->keyword_true = pctx->intern("true"_s);
|
||||
pctx->keyword_default = pctx->intern("default"_s);
|
||||
pctx->keyword_continue = pctx->intern("continue"_s);
|
||||
pctx->keyword_break = pctx->intern("break"_s);
|
||||
pctx->keyword_false = pctx->intern("false"_s);
|
||||
pctx->keyword_return = pctx->intern("return"_s);
|
||||
@@ -310,8 +311,6 @@ resolve_everything_in_module(Ast_Module *module) {
|
||||
For2(file->decls, decl) {
|
||||
if (decl->flags & AST_POLYMORPH) continue;
|
||||
|
||||
// @cleanup: Why I'm not calling resolve_decl here?
|
||||
// resolve_name(file, decl->pos, decl->name);
|
||||
resolve_decl(decl);
|
||||
if (decl->kind == AST_STRUCT || decl->kind == AST_UNION) type_complete(decl->type_val);
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ for i in meta.interns: print(f'Intern_String intern_{i.lower()};')
|
||||
Intern_String keyword_union;
|
||||
Intern_String keyword_true;
|
||||
Intern_String keyword_default;
|
||||
Intern_String keyword_continue;
|
||||
Intern_String keyword_break;
|
||||
Intern_String keyword_false;
|
||||
Intern_String keyword_return;
|
||||
|
||||
@@ -339,6 +339,7 @@ enum Ast_Kind : uint32_t {
|
||||
AST_SWITCH_CASE,
|
||||
AST_VAR_UNPACK,
|
||||
AST_BREAK,
|
||||
AST_CONTINUE,
|
||||
AST_COMPOUND,
|
||||
AST_TYPE,
|
||||
AST_VAR,
|
||||
|
||||
@@ -295,6 +295,10 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0) {
|
||||
scope->stmts.add(ast_return(token, expr));
|
||||
}
|
||||
|
||||
else if (token_match_keyword(pctx->keyword_continue)) {
|
||||
scope->stmts.add(ast_continue(token));
|
||||
}
|
||||
|
||||
else if (token_match_keyword(pctx->keyword_break)) {
|
||||
scope->stmts.add(ast_break(token));
|
||||
}
|
||||
|
||||
@@ -323,8 +323,9 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope, Array<Poly_Replacement> *repl)
|
||||
result = dst;
|
||||
} break;
|
||||
|
||||
case AST_BREAK:
|
||||
case AST_PASS:
|
||||
case AST_BREAK: {
|
||||
case AST_CONTINUE: {
|
||||
Ast *src = (Ast *)ast;
|
||||
Ast *dst = ast_create_copy(parent_scope, Ast, ast);
|
||||
result = dst;
|
||||
|
||||
@@ -250,6 +250,10 @@ void core__stringify(Ast *ast) {
|
||||
genln("pass");
|
||||
} break;
|
||||
|
||||
case AST_CONTINUE: {
|
||||
genln("continue");
|
||||
} break;
|
||||
|
||||
case AST_BREAK: {
|
||||
genln("break");
|
||||
} break;
|
||||
|
||||
@@ -790,6 +790,7 @@ resolve_stmt(Ast *ast, Ast_Type *ret) {
|
||||
BREAK();
|
||||
}
|
||||
|
||||
case AST_CONTINUE:
|
||||
case AST_BREAK:
|
||||
CASE(PASS, Pass) {
|
||||
unused(node);
|
||||
|
||||
Reference in New Issue
Block a user