Core: Add continue keyword

This commit is contained in:
Krzosa Karol
2023-04-21 08:02:58 +02:00
parent e6bf6b680e
commit 200b5e4f9f
11 changed files with 33 additions and 11 deletions

View File

@@ -197,14 +197,11 @@ 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
p := V2I{it.p.x + x, it.p.y + y}
MAP_InsertOpenPath(s, p, it.p)
if x == 0 && y == 0 ;; continue
p := V2I{it.p.x + x, it.p.y + y}
MAP_InsertOpenPath(s, p, it.p)
if compute_history ;; MAP_RecomputeHistory(s)
return false

View File

@@ -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;

View File

@@ -635,6 +635,12 @@ gen_ast(Ast *ast) {
BREAK();
}
CASE(CONTINUE, Pass) {
unused(node);
gen("continue;");
BREAK();
}
CASE(BREAK, Break) {
unused(node);
gen("break;");

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -203,7 +203,7 @@ enum Ast_Type_Kind {
TYPE_U64,
TYPE_U32,
TYPE_U16,
TYPE_U8, //is_int end
TYPE_U8, // is_int end
TYPE_F32,
TYPE_F64,
@@ -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,

View File

@@ -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));
}

View File

@@ -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;

View File

@@ -250,6 +250,10 @@ void core__stringify(Ast *ast) {
genln("pass");
} break;
case AST_CONTINUE: {
genln("continue");
} break;
case AST_BREAK: {
genln("break");
} break;

View File

@@ -790,6 +790,7 @@ resolve_stmt(Ast *ast, Ast_Type *ret) {
BREAK();
}
case AST_CONTINUE:
case AST_BREAK:
CASE(PASS, Pass) {
unused(node);

View File

@@ -103,6 +103,7 @@ keywords = [
"union",
"true",
"default",
"continue",
"break",
"false",
"return",