From 63cc530899ffa8ab9d96f95f1a0354044223b0ee Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 2 Feb 2025 16:15:20 +1100 Subject: [PATCH] Fixed continue keyword, was pointing at break's target --- scripts/yuki.toy | 11 ++++++++ source/toy_module_builder.c | 2 +- .../test_keyword_while_break_continue.toy | 28 ++++++++++++------- 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 scripts/yuki.toy diff --git a/scripts/yuki.toy b/scripts/yuki.toy new file mode 100644 index 0000000..080deee --- /dev/null +++ b/scripts/yuki.toy @@ -0,0 +1,11 @@ +var loops = 0; + +while (true) { + if (++loops < 15532) { + continue; + } + + break; +} + +assert loops == 15532, "Yuki loop failed (break + continue)"; diff --git a/source/toy_module_builder.c b/source/toy_module_builder.c index f83261a..dbdf5b0 100644 --- a/source/toy_module_builder.c +++ b/source/toy_module_builder.c @@ -617,7 +617,7 @@ static unsigned int writeInstructionWhileThen(Toy_ModuleBuilder** mb, Toy_AstWhi unsigned int diff = depth - (*mb)->currentScopeDepth; - OVERWRITE_INT(mb, code, addr, CURRENT_ADDRESS(mb, code) - (addr + 8)); //tell continue to return to the start AFTER reading the instruction + OVERWRITE_INT(mb, code, addr, beginAddr - (addr + 8)); //tell continue to return to the start AFTER reading the instruction OVERWRITE_INT(mb, code, addr, diff); //tick down diff --git a/tests/integrations/test_keyword_while_break_continue.toy b/tests/integrations/test_keyword_while_break_continue.toy index 9b528be..b07a39a 100644 --- a/tests/integrations/test_keyword_while_break_continue.toy +++ b/tests/integrations/test_keyword_while_break_continue.toy @@ -16,8 +16,6 @@ while (flag1) { assert false, "continue failed"; } -print "done"; - //------------------------- //test break @@ -34,8 +32,6 @@ while (flag2) { assert false, "continue failed"; } -print "done"; - //------------------------- //test break @@ -52,8 +48,6 @@ while (flag3) { assert false, "continue failed"; } -print "done"; - //------------------------- { @@ -70,8 +64,6 @@ print "done"; continue; assert false, "continue failed"; } - - print "done"; } //------------------------- @@ -94,8 +86,6 @@ print "done"; } assert false, "continue failed"; } - - print "done"; } //------------------------- @@ -122,3 +112,21 @@ print "done"; count += 1; } } + +//------------------------- + +{ + //make sure break and continue point to the correct locations + var loops = 0; + + while (true) { + if (++loops < 15532) { + continue; + } + + break; + } + + assert loops == 15532, "Yuki loop failed (break + continue)"; +} +