@@ -42,6 +42,7 @@ std::shared_ptr<ExecutableCode> Compiler::compile(std::shared_ptr<Block> startBl
4242 impl->builder = impl->builderFactory ->create (impl->target , startBlock->id (), false );
4343 impl->substackTree .clear ();
4444 impl->substackHit = false ;
45+ impl->emptySubstack = false ;
4546 impl->warp = false ;
4647 impl->block = startBlock;
4748
@@ -55,6 +56,11 @@ std::shared_ptr<ExecutableCode> Compiler::compile(std::shared_ptr<Block> startBl
5556 assert (false );
5657 }
5758
59+ if (impl->emptySubstack ) {
60+ impl->emptySubstack = false ;
61+ impl->substackEnd ();
62+ }
63+
5864 if (impl->customLoopCount > 0 ) {
5965 std::cerr << " error: loop created by block '" << impl->block ->opcode () << " ' not terminated" << std::endl;
6066 assert (false );
@@ -456,7 +462,7 @@ void Compiler::moveToIfElse(CompilerValue *cond, std::shared_ptr<Block> substack
456462 impl->builder ->beginIfStatement (cond);
457463
458464 if (!impl->block )
459- impl->substackEnd () ;
465+ impl->emptySubstack = true ;
460466}
461467
462468/* ! Jumps to the given repeat loop substack. */
@@ -468,7 +474,7 @@ void Compiler::moveToRepeatLoop(CompilerValue *count, std::shared_ptr<Block> sub
468474 impl->builder ->beginRepeatLoop (count);
469475
470476 if (!impl->block )
471- impl->substackEnd () ;
477+ impl->emptySubstack = true ;
472478}
473479
474480/* ! Jumps to the given while loop substack. */
@@ -480,7 +486,7 @@ void Compiler::moveToWhileLoop(CompilerValue *cond, std::shared_ptr<Block> subst
480486 impl->builder ->beginWhileLoop (cond);
481487
482488 if (!impl->block )
483- impl->substackEnd () ;
489+ impl->emptySubstack = true ;
484490}
485491
486492/* ! Jumps to the given until loop substack. */
@@ -492,7 +498,7 @@ void Compiler::moveToRepeatUntilLoop(CompilerValue *cond, std::shared_ptr<Block>
492498 impl->builder ->beginRepeatUntilLoop (cond);
493499
494500 if (!impl->block )
495- impl->substackEnd () ;
501+ impl->emptySubstack = true ;
496502}
497503
498504/* ! Makes current script run without screen refresh. */
0 commit comments