From e95ac6fb065dfc6a94d565f4b028984786800b79 Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Sun, 4 May 2025 17:51:53 -0400 Subject: [PATCH] Recover from errors even inside `REPT`/`FOR` loops (#1683) --- include/asm/fstack.hpp | 1 - src/asm/fstack.cpp | 6 +----- src/asm/parser.y | 1 - test/asm/error-recovery.asm | 2 +- test/asm/error-recovery.err | 6 +++++- test/asm/error-recovery.out | 6 +++++- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/asm/fstack.hpp b/include/asm/fstack.hpp index 7b4befa9..a53aab13 100644 --- a/include/asm/fstack.hpp +++ b/include/asm/fstack.hpp @@ -71,7 +71,6 @@ void fstk_RunFor( int32_t reptLineNo, ContentSpan const &span ); -void fstk_StopRept(); bool fstk_Break(); void fstk_NewRecursionDepth(size_t newDepth); diff --git a/src/asm/fstack.cpp b/src/asm/fstack.cpp index 40d396ec..a855f46f 100644 --- a/src/asm/fstack.cpp +++ b/src/asm/fstack.cpp @@ -392,17 +392,13 @@ void fstk_RunFor( context.forName = symName; } -void fstk_StopRept() { - contextStack.top().nbReptIters = 0; // Prevent more iterations -} - bool fstk_Break() { if (contextStack.top().fileInfo->type != NODE_REPT) { error("BREAK can only be used inside a REPT/FOR block\n"); return false; } - fstk_StopRept(); + contextStack.top().nbReptIters = 0; // Prevent more iterations return true; } diff --git a/src/asm/parser.y b/src/asm/parser.y index f5ee2437..64ed5f47 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -425,7 +425,6 @@ lines: lexer_SetMode(LEXER_NORMAL); lexer_ToggleStringExpansion(true); } endofline { - fstk_StopRept(); yyerrok; } ; diff --git a/test/asm/error-recovery.asm b/test/asm/error-recovery.asm index 3136bc51..12a30978 100644 --- a/test/asm/error-recovery.asm +++ b/test/asm/error-recovery.asm @@ -2,7 +2,7 @@ println 42, 1 2 3 4 -for n, 5 +for n, 3 println "start {d:n}" println syntax error println "finish {d:n}" diff --git a/test/asm/error-recovery.err b/test/asm/error-recovery.err index 2ebd07c4..1166f948 100644 --- a/test/asm/error-recovery.err +++ b/test/asm/error-recovery.err @@ -2,4 +2,8 @@ error: error-recovery.asm(3): syntax error, unexpected number error: error-recovery.asm(5) -> error-recovery.asm::REPT~1(7): syntax error, unexpected symbol -error: Assembly aborted (2 errors)! +error: error-recovery.asm(5) -> error-recovery.asm::REPT~2(7): + syntax error, unexpected symbol +error: error-recovery.asm(5) -> error-recovery.asm::REPT~3(7): + syntax error, unexpected symbol +error: Assembly aborted (4 errors)! diff --git a/test/asm/error-recovery.out b/test/asm/error-recovery.out index c8f0b99a..e3b6138a 100644 --- a/test/asm/error-recovery.out +++ b/test/asm/error-recovery.out @@ -1,4 +1,8 @@ begin $2Astart 0 finish 0 -end 0 +start 1 +finish 1 +start 2 +finish 2 +end 3