Skip to content

Commit f004d98

Browse files
committed
Compiler: Add createVariableWrite() method
1 parent e2b3534 commit f004d98

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

include/scratchcpp/dev/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class LIBSCRATCHCPP_EXPORT Compiler
7878
void createExp();
7979
void createExp10();
8080

81+
void createVariableWrite(Variable *variable);
82+
8183
void moveToIf(std::shared_ptr<Block> substack);
8284
void moveToIfElse(std::shared_ptr<Block> substack1, std::shared_ptr<Block> substack2);
8385
void moveToRepeatLoop(std::shared_ptr<Block> substack);

src/dev/engine/compiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ void Compiler::createExp10()
256256
impl->builder->createExp10();
257257
}
258258

259+
/*! Creates a variable write operation using the last value. */
260+
void Compiler::createVariableWrite(Variable *variable)
261+
{
262+
impl->builder->createVariableWrite(variable);
263+
}
264+
259265
/*! Jumps to the given if substack. */
260266
void Compiler::moveToIf(std::shared_ptr<Block> substack)
261267
{

test/dev/compiler/compiler_test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,20 @@ TEST_F(CompilerTest, CreateExp10)
557557
compile(compiler, block);
558558
}
559559

560+
TEST_F(CompilerTest, CreateVariableWrite)
561+
{
562+
Compiler compiler(&m_engine, &m_target);
563+
auto block = std::make_shared<Block>("", "");
564+
565+
block->setCompileFunction([](Compiler *compiler) {
566+
auto var = std::make_shared<Variable>("", "");
567+
EXPECT_CALL(*m_builder, createVariableWrite(var.get()));
568+
compiler->createVariableWrite(var.get());
569+
});
570+
571+
compile(compiler, block);
572+
}
573+
560574
TEST_F(CompilerTest, MoveToIf)
561575
{
562576
Compiler compiler(&m_engine, &m_target);

0 commit comments

Comments
 (0)