Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/scratchcpp/dev/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class LIBSCRATCHCPP_EXPORT Compiler
void createExp();
void createExp10();

void createVariableWrite(Variable *variable);

void moveToIf(std::shared_ptr<Block> substack);
void moveToIfElse(std::shared_ptr<Block> substack1, std::shared_ptr<Block> substack2);
void moveToRepeatLoop(std::shared_ptr<Block> substack);
Expand Down
5 changes: 4 additions & 1 deletion include/scratchcpp/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace libscratchcpp
{

class Variable;
struct ValueData;
class List;
class Block;
class Comment;
Expand All @@ -28,7 +29,7 @@ class LIBSCRATCHCPP_EXPORT Target : public Drawable
public:
Target();
Target(const Target &) = delete;
virtual ~Target() { }
virtual ~Target();

bool isTarget() const override final;

Expand All @@ -44,6 +45,8 @@ class LIBSCRATCHCPP_EXPORT Target : public Drawable
int findVariable(const std::string &variableName) const;
int findVariableById(const std::string &id) const;

ValueData **variableData();

const std::vector<std::shared_ptr<List>> &lists() const;
int addList(std::shared_ptr<List> list);
std::shared_ptr<List> listAt(int index) const;
Expand Down
8 changes: 7 additions & 1 deletion src/dev/engine/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ std::shared_ptr<libscratchcpp::Block> Compiler::block() const
/*! Compiles the script starting with the given block. */
std::shared_ptr<ExecutableCode> Compiler::compile(std::shared_ptr<Block> startBlock)
{
impl->builder = impl->builderFactory->create(startBlock->id(), false);
impl->builder = impl->builderFactory->create(impl->target, startBlock->id(), false);
impl->substackTree.clear();
impl->substackHit = false;
impl->warp = false;
Expand Down Expand Up @@ -256,6 +256,12 @@ void Compiler::createExp10()
impl->builder->createExp10();
}

/*! Creates a variable write operation using the last value. */
void Compiler::createVariableWrite(Variable *variable)
{
impl->builder->createVariableWrite(variable);
}

/*! Jumps to the given if substack. */
void Compiler::moveToIf(std::shared_ptr<Block> substack)
{
Expand Down
4 changes: 2 additions & 2 deletions src/dev/engine/internal/codebuilderfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ std::shared_ptr<CodeBuilderFactory> CodeBuilderFactory::instance()
return m_instance;
}

std::shared_ptr<ICodeBuilder> CodeBuilderFactory::create(const std::string &id, bool warp) const
std::shared_ptr<ICodeBuilder> CodeBuilderFactory::create(Target *target, const std::string &id, bool warp) const
{
return std::make_shared<LLVMCodeBuilder>(id, warp);
return std::make_shared<LLVMCodeBuilder>(target, id, warp);
}
2 changes: 1 addition & 1 deletion src/dev/engine/internal/codebuilderfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CodeBuilderFactory : public ICodeBuilderFactory
{
public:
static std::shared_ptr<CodeBuilderFactory> instance();
std::shared_ptr<ICodeBuilder> create(const std::string &id, bool warp) const override;
std::shared_ptr<ICodeBuilder> create(Target *target, const std::string &id, bool warp) const override;

private:
static std::shared_ptr<CodeBuilderFactory> m_instance;
Expand Down
2 changes: 2 additions & 0 deletions src/dev/engine/internal/icodebuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class ICodeBuilder
virtual void createExp() = 0;
virtual void createExp10() = 0;

virtual void createVariableWrite(Variable *variable) = 0;

virtual void beginIfStatement() = 0;
virtual void beginElseBranch() = 0;
virtual void endIf() = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/dev/engine/internal/icodebuilderfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ namespace libscratchcpp
{

class ICodeBuilder;
class Target;

class ICodeBuilderFactory
{
public:
virtual ~ICodeBuilderFactory() { }

virtual std::shared_ptr<ICodeBuilder> create(const std::string &id, bool warp) const = 0;
virtual std::shared_ptr<ICodeBuilder> create(Target *target, const std::string &id, bool warp) const = 0;
};

} // namespace libscratchcpp
Loading
Loading