Skip to content

Commit f6ee558

Browse files
committed
Compiler: Add createYield() method
1 parent 5744b3d commit f6ee558

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

include/scratchcpp/dev/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class LIBSCRATCHCPP_EXPORT Compiler
115115
void moveToRepeatUntilLoop(CompilerValue *cond, std::shared_ptr<Block> substack);
116116
void warp();
117117

118+
void createYield();
118119
void createStop();
119120

120121
Input *input(const std::string &name) const;

src/dev/engine/compiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,12 @@ void Compiler::warp()
495495
impl->warp = true;
496496
}
497497

498+
/*! Creates a suspend instruction. */
499+
void Compiler::createYield()
500+
{
501+
impl->builder->yield();
502+
}
503+
498504
/*! Creates a stop script instruction. */
499505
void Compiler::createStop()
500506
{

test/dev/compiler/compiler_test.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,13 +1418,26 @@ TEST_F(CompilerTest, MoveToRepeatUntilLoop)
14181418
compile(compiler, l1);
14191419
}
14201420

1421+
TEST_F(CompilerTest, CreateYield)
1422+
{
1423+
Compiler compiler(&m_engine, &m_target);
1424+
auto block = std::make_shared<Block>("", "");
1425+
1426+
block->setCompileFunction([](Compiler *compiler) -> CompilerValue * {
1427+
EXPECT_CALL(*m_builder, yield());
1428+
compiler->createYield();
1429+
return nullptr;
1430+
});
1431+
1432+
compile(compiler, block);
1433+
}
1434+
14211435
TEST_F(CompilerTest, CreateStop)
14221436
{
14231437
Compiler compiler(&m_engine, &m_target);
14241438
auto block = std::make_shared<Block>("", "");
14251439

14261440
block->setCompileFunction([](Compiler *compiler) -> CompilerValue * {
1427-
CompilerValue arg(Compiler::StaticType::Unknown);
14281441
EXPECT_CALL(*m_builder, createStop());
14291442
compiler->createStop();
14301443
return nullptr;

0 commit comments

Comments
 (0)