Skip to content

Commit 8c440e9

Browse files
committed
Compiler: Add createPrint() method
1 parent 7e04a52 commit 8c440e9

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

include/scratchcpp/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class LIBSCRATCHCPP_EXPORT Compiler
157157

158158
void createProcedureCall(BlockPrototype *prototype, const Compiler::Args &args);
159159

160+
void createPrint(CompilerValue *string);
161+
160162
Input *input(const std::string &name) const;
161163
Field *field(const std::string &name) const;
162164

src/engine/compiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,12 @@ void Compiler::createProcedureCall(BlockPrototype *prototype, const libscratchcp
726726
impl->builder->createProcedureCall(prototype, args);
727727
}
728728

729+
/*! Creates a print instruction. */
730+
void Compiler::createPrint(CompilerValue *string)
731+
{
732+
impl->builder->createPrint(string);
733+
}
734+
729735
/*! Convenience method which returns the field with the given name. */
730736
Input *Compiler::input(const std::string &name) const
731737
{

test/compiler/compiler_test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,22 @@ TEST_F(CompilerTest, CreateProcedureCall)
17201720
compile(m_compiler.get(), block.get());
17211721
}
17221722

1723+
TEST_F(CompilerTest, CreatePrint)
1724+
{
1725+
1726+
auto block = std::make_shared<Block>("", "");
1727+
1728+
block->setCompileFunction([](Compiler *compiler) -> CompilerValue * {
1729+
CompilerValue arg(Compiler::StaticType::Unknown);
1730+
1731+
EXPECT_CALL(*m_builder, createPrint(&arg));
1732+
compiler->createPrint(&arg);
1733+
return nullptr;
1734+
});
1735+
1736+
compile(m_compiler.get(), block.get());
1737+
}
1738+
17231739
TEST_F(CompilerTest, Input)
17241740
{
17251741

0 commit comments

Comments
 (0)