Skip to content

Commit 53e30e2

Browse files
committed
Compiler: Allow custom code in empty substacks
1 parent cc2aca9 commit 53e30e2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/dev/engine/compiler.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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. */

src/dev/engine/compiler_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct CompilerPrivate
3636
int customLoopCount = 0;
3737
std::vector<std::pair<std::pair<std::shared_ptr<Block>, std::shared_ptr<Block>>, SubstackType>> substackTree;
3838
bool substackHit = false;
39+
bool emptySubstack = false;
3940
bool warp = false;
4041

4142
static inline ICodeBuilderFactory *builderFactory = nullptr;

0 commit comments

Comments
 (0)