summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-06-30 14:06:52 +0200
committerJo-Philipp Wich <jo@mein.io>2022-06-30 14:44:47 +0200
commit35c6b73c347caf45d74431890c1885ef58bfae24 (patch)
tree78a721a850c72be2715993763cbeae2d1fcbfa34 /include
parentf7c7aa615eb49c7a03e2ee2abe4df5bd18dd0f40 (diff)
compiler: fix stack mismatch on continue statements nested in switches
When compiling continue statements nested in switches, the compiler only emitted pop statements for the local variables in the switch body scope, but not for the locals in the scope(s) leading up to the containing loop body. Extend the compilers internal patchlist structure to keep track of the type of scope tied to the patchlist and extend `continue` statement compilation logic to select the appropriate parent patch list in order to determine the amount of locals (stack slots) to clear before the emitted jump instruction. As a result, the `uc_compiler_backpatch()` implementation can be simplified somewhat since we do not need to propagate entries to parent lists anymore. Also add a further regression test case to cover this issue. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'include')
-rw-r--r--include/ucode/compiler.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/ucode/compiler.h b/include/ucode/compiler.h
index 15b77b3..db3d676 100644
--- a/include/ucode/compiler.h
+++ b/include/ucode/compiler.h
@@ -69,6 +69,7 @@ typedef enum {
typedef struct uc_patchlist {
struct uc_patchlist *parent;
size_t depth, count, *entries;
+ uc_tokentype_t token;
} uc_patchlist_t;
typedef struct uc_exprstack {