Skip to content

Commit 5b37719

Browse files
committed
Compiler: Add createStop() method
1 parent 59daa77 commit 5b37719

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

include/scratchcpp/dev/compiler.h

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

118+
void createStop();
119+
118120
Input *input(const std::string &name) const;
119121
Field *field(const std::string &name) const;
120122

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 stop script instruction. */
499+
void Compiler::createStop()
500+
{
501+
impl->builder->createStop();
502+
}
503+
498504
/*! Convenience method which returns the field with the given name. */
499505
Input *Compiler::input(const std::string &name) const
500506
{

test/dev/compiler/compiler_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,21 @@ TEST_F(CompilerTest, MoveToRepeatUntilLoop)
14181418
compile(compiler, l1);
14191419
}
14201420

1421+
TEST_F(CompilerTest, CreateStop)
1422+
{
1423+
Compiler compiler(&m_engine, &m_target);
1424+
auto block = std::make_shared<Block>("", "");
1425+
1426+
block->setCompileFunction([](Compiler *compiler) -> CompilerValue * {
1427+
CompilerValue arg(Compiler::StaticType::Unknown);
1428+
EXPECT_CALL(*m_builder, createStop());
1429+
compiler->createStop();
1430+
return nullptr;
1431+
});
1432+
1433+
compile(compiler, block);
1434+
}
1435+
14211436
TEST_F(CompilerTest, Input)
14221437
{
14231438
Compiler compiler(&m_engine, &m_target);

0 commit comments

Comments
 (0)