Skip to content

Commit 9f3749d

Browse files
committed
Compiler: Add invalidateTarget() method
1 parent da1bac8 commit 9f3749d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

include/scratchcpp/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class LIBSCRATCHCPP_EXPORT Compiler
153153
void createThreadStop();
154154
void createStopWithoutSync();
155155

156+
void invalidateTarget();
157+
156158
void createProcedureCall(BlockPrototype *prototype, const Compiler::Args &args);
157159

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

src/engine/compiler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,15 @@ void Compiler::createStopWithoutSync()
721721
impl->builder->createStopWithoutSync();
722722
}
723723

724+
/*!
725+
* Creates a sprite/stage invalidation point.\n
726+
* Use this if synchronization is not possible because the target has been deleted.
727+
*/
728+
void Compiler::invalidateTarget()
729+
{
730+
impl->builder->invalidateTarget();
731+
}
732+
724733
/*! Creates a call to the procedure with the given prototype. */
725734
void Compiler::createProcedureCall(BlockPrototype *prototype, const libscratchcpp::Compiler::Args &args)
726735
{

test/compiler/compiler_test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,20 @@ TEST_F(CompilerTest, CreateStopWithoutSync)
17011701
compile(m_compiler.get(), block.get());
17021702
}
17031703

1704+
TEST_F(CompilerTest, InvalidateTarget)
1705+
{
1706+
1707+
auto block = std::make_shared<Block>("", "");
1708+
1709+
block->setCompileFunction([](Compiler *compiler) -> CompilerValue * {
1710+
EXPECT_CALL(*m_builder, invalidateTarget());
1711+
compiler->invalidateTarget();
1712+
return nullptr;
1713+
});
1714+
1715+
compile(m_compiler.get(), block.get());
1716+
}
1717+
17041718
TEST_F(CompilerTest, CreateProcedureCall)
17051719
{
17061720

0 commit comments

Comments
 (0)