From 0c8d018238abefa5b40145151fd9645081d5da0d Mon Sep 17 00:00:00 2001 From: Ugric Date: Mon, 14 Jul 2025 19:50:44 +0100 Subject: [PATCH] add jump for else statement --- src/translator/if/if.c | 6 +++--- test.ar | 5 +++-- testing.ar | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/translator/if/if.c b/src/translator/if/if.c index 486222f..31c8295 100644 --- a/src/translator/if/if.c +++ b/src/translator/if/if.c @@ -38,12 +38,12 @@ size_t translate_parsed_if(Translated *translated, DArray *parsedIf) { } else { translate_parsed(translated, condition->content); push_instruction_byte(translated, OP_POP_SCOPE); - jump_after_body_positions[i] = 0; + push_instruction_byte(translated, OP_JUMP); + jump_after_body_positions[i] = push_instruction_code(translated, 0); } } for (uint64_t i = 0; i < parsedIf->size; i++) { - if (jump_after_body_positions[i]) - set_instruction_code(translated, jump_after_body_positions[i], + set_instruction_code(translated, jump_after_body_positions[i], translated->bytecode.size); } free(jump_after_body_positions); diff --git a/test.ar b/test.ar index 93be391..04ba1bc 100644 --- a/test.ar +++ b/test.ar @@ -59,7 +59,8 @@ let a, sum = a, another, another_function(), - just_null_here + just_null_here, + x @@ -77,7 +78,7 @@ else term.log("bruh") mm=x/2/4/2/4354/534/534//534//3422*404203420234+3432423324&&430234230||4320423040230423^384239423043024923%4432042304920.3432423423 -let x = [ +let X = [ 'hello world', 'wow', 10 diff --git a/testing.ar b/testing.ar index ae2ef9e..45011fa 100644 --- a/testing.ar +++ b/testing.ar @@ -1,10 +1,10 @@ # SPDX-FileCopyrightText: 2025 William Bell # SPDX-License-Identifier: GPL-3.0-or-later - let y = 1 -let term = y let x = do - y - return term \ No newline at end of file + do + return y + x +return y \ No newline at end of file