diff options
| author | Baitinq <[email protected]> | 2025-07-13 23:41:40 +0200 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-07-13 23:41:40 +0200 |
| commit | ed094396f380fb0679194b1e3c51faf996dc2bfe (patch) | |
| tree | f38e80a4ece3a7ee03f6c1abde80ac8d58c67be4 | |
| parent | Boostrap: Support newtype (diff) | |
| download | pry-lang-ed094396f380fb0679194b1e3c51faf996dc2bfe.tar.gz pry-lang-ed094396f380fb0679194b1e3c51faf996dc2bfe.tar.bz2 pry-lang-ed094396f380fb0679194b1e3c51faf996dc2bfe.zip | |
Boostrap: Support break and continue
| -rw-r--r-- | src/bootstrap/codegen.pry | 20 | ||||
| -rw-r--r-- | src/bootstrap/parser.pry | 33 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/bootstrap/codegen.pry b/src/bootstrap/codegen.pry index 99324fb..5f63038 100644 --- a/src/bootstrap/codegen.pry +++ b/src/bootstrap/codegen.pry @@ -1127,6 +1127,18 @@ let codegen_generate_function_call_statement = (c: *codegen, statement: *Node) = return codegen_create_variable(c, v); }; +let codegen_generate_break_statement = (c: *codegen) => i64 { + assert((*c).whil_loop_exit != cast(LLVMBasicBlockRef, null)); + LLVMBuildBr((*c).builder, (*c).whil_loop_exit); + return 0; +}; + +let codegen_generate_continue_statement = (c: *codegen) => i64 { + assert((*c).whil_block != cast(LLVMBasicBlockRef, null)); + LLVMBuildBr((*c).builder, (*c).whil_block); + return 0; +}; + let codegen_generate_if_statement = (c: *codegen, statement: *NODE_IF_STATEMENT_DATA) => *void { let condition_value = codegen_generate_expression_value(c, (*statement).condition, cast(*i8, null)); assert(condition_value != cast(*Variable, null)); @@ -1230,6 +1242,14 @@ let codegen_generate_statement = (c: *codegen, statement: *Node) => i64 { return codegen_generate_import_declaration(c, cast(*NODE_IMPORT_DECLARATION_DATA, stmt.data)); }; + if stmt.type == NODE_CONTINUE_STATEMENT { + return codegen_generate_continue_statement(c); + }; + + if stmt.type == NODE_BREAK_STATEMENT { + return codegen_generate_break_statement(c); + }; + printf("ASSERT 3 %d\n", stmt.type); assert(false); diff --git a/src/bootstrap/parser.pry b/src/bootstrap/parser.pry index cf5cabd..f77bc77 100644 --- a/src/bootstrap/parser.pry +++ b/src/bootstrap/parser.pry @@ -1389,6 +1389,39 @@ let parser_parse_statement = (p: *parser) => *Node { }; return retu; }; + + /* Break and continue */ + let retu = parser_accept_parse(p, (ip: *parser) => *Node { + if parser_accept_token(ip, TOKEN_BREAK) == cast(*token, null) { + return cast(*Node, null); + }; + + let n = Node{}; + n.type = NODE_BREAK_STATEMENT; + return create_node(ip, n); + }); + if retu != cast(*Node, null) { + if parser_accept_token(p, TOKEN_SEMICOLON) == cast(*token, null) { + return cast(*Node, null); + }; + return retu; + }; + + let retu = parser_accept_parse(p, (ip: *parser) => *Node { + if parser_accept_token(ip, TOKEN_CONTINUE) == cast(*token, null) { + return cast(*Node, null); + }; + + let n = Node{}; + n.type = NODE_CONTINUE_STATEMENT; + return create_node(ip, n); + }); + if retu != cast(*Node, null) { + if parser_accept_token(p, TOKEN_SEMICOLON) == cast(*token, null) { + return cast(*Node, null); + }; + return retu; + }; printf("None\n"); |