diff --git a/build/rtsgame/map.core b/build/rtsgame/map.core index 6279727..ce62e52 100644 --- a/build/rtsgame/map.core +++ b/build/rtsgame/map.core @@ -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 diff --git a/core_ast.cpp b/core_ast.cpp index 9682588..37c9275 100644 --- a/core_ast.cpp +++ b/core_ast.cpp @@ -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 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; diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index 8f5a39b..654a5f1 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -635,6 +635,12 @@ gen_ast(Ast *ast) { BREAK(); } + CASE(CONTINUE, Pass) { + unused(node); + gen("continue;"); + BREAK(); + } + CASE(BREAK, Break) { unused(node); gen("break;"); diff --git a/core_compiler.cpp b/core_compiler.cpp index 9237fc6..a9b6dfb 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -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); } diff --git a/core_compiler.h b/core_compiler.h index b9b8c8a..daab2cd 100644 --- a/core_compiler.h +++ b/core_compiler.h @@ -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; diff --git a/core_compiler_interface.hpp b/core_compiler_interface.hpp index 6e34b4f..db1480a 100644 --- a/core_compiler_interface.hpp +++ b/core_compiler_interface.hpp @@ -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, diff --git a/core_parsing.cpp b/core_parsing.cpp index b3d2553..d65f003 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -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)); } diff --git a/core_polymorph.cpp b/core_polymorph.cpp index 1a0d144..1d17eae 100644 --- a/core_polymorph.cpp +++ b/core_polymorph.cpp @@ -323,8 +323,9 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope, Array *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; diff --git a/core_printer.cpp b/core_printer.cpp index 127d526..1c0ce95 100644 --- a/core_printer.cpp +++ b/core_printer.cpp @@ -250,6 +250,10 @@ void core__stringify(Ast *ast) { genln("pass"); } break; + case AST_CONTINUE: { + genln("continue"); + } break; + case AST_BREAK: { genln("break"); } break; diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 54e9bb1..ff33de6 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -790,6 +790,7 @@ resolve_stmt(Ast *ast, Ast_Type *ret) { BREAK(); } + case AST_CONTINUE: case AST_BREAK: CASE(PASS, Pass) { unused(node); diff --git a/meta.py b/meta.py index 9216816..3fbd48b 100644 --- a/meta.py +++ b/meta.py @@ -103,6 +103,7 @@ keywords = [ "union", "true", "default", + "continue", "break", "false", "return",