Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ebce257
LLVMCodeBuilder: Implement add operator
adazem009 Oct 13, 2024
3260662
LLVMCodeBuilder: Implement subtract operator
adazem009 Oct 13, 2024
e75947e
LLVMCodeBuilder: Implement multiply operator
adazem009 Oct 13, 2024
31a4e36
Fix conversion of -0.0 to string
adazem009 Oct 13, 2024
9183e2b
LLVMCodeBuilder: Implement divide operator
adazem009 Oct 13, 2024
9e7d3d0
Compiler: Add methods for add, sub, mul and div operators
adazem009 Oct 13, 2024
833565b
LLVMConstValue: Return constant in castConstValue()
adazem009 Oct 14, 2024
361fbb0
LLVMCodeBuilder: Fix ValueData definition
adazem009 Oct 14, 2024
0e92dc8
LLVMCodeBuilder: Make createOp() universal
adazem009 Oct 14, 2024
9752ff9
LLVMCodeBuilder: Don't print optimized IR
adazem009 Oct 15, 2024
6243928
LLVMCodeBuilder: Make operator tests easier to debug
adazem009 Oct 15, 2024
ff36261
Compiler: Add Unknown static type
adazem009 Oct 15, 2024
29859b5
LLVMCodeBuilder: Implement equal comparison
adazem009 Oct 15, 2024
c847df4
Fix GT and LT value comparison to match Scratch
adazem009 Oct 15, 2024
a70d280
LLVMCodeBuilder: Remove expected result from comparison test
adazem009 Oct 15, 2024
cdbba2e
Add more comparison edge case tests
adazem009 Oct 15, 2024
d146cf3
LLVMCodeBuilder: Implement greater than comparison
adazem009 Oct 15, 2024
379a12e
LLVMCodeBuilder: Implement lower than comparison
adazem009 Oct 15, 2024
e6edce7
Compiler: Add methods for comparison operators
adazem009 Oct 15, 2024
e1ad826
Fix conversion of NaN to bool
adazem009 Oct 16, 2024
eca7a73
LLVMCodeBuilder: Implement 'and' and 'or' gates
adazem009 Oct 16, 2024
4d9f6fa
LLVMCodeBuilder: Implement not gate
adazem009 Oct 16, 2024
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
12 changes: 11 additions & 1 deletion include/scratchcpp/dev/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class LIBSCRATCHCPP_EXPORT Compiler
Void,
Number,
Bool,
String
String,
Unknown
};

Compiler(IEngine *engine, Target *target);
Expand All @@ -47,6 +48,15 @@ class LIBSCRATCHCPP_EXPORT Compiler
void addListContents(List *list);
void addInput(const std::string &name);

void createAdd();
void createSub();
void createMul();
void createDiv();

void createCmpEQ();
void createCmpGT();
void createCmpLT();

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
42 changes: 42 additions & 0 deletions src/dev/engine/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,48 @@ void Compiler::addInput(const std::string &name)
addInput(impl->block->inputAt(impl->block->findInput(name)).get());
}

/*! Creates an add instruction from the last 2 values. */
void Compiler::createAdd()
{
impl->builder->createAdd();
}

/*! Creates a subtract instruction from the last 2 values. */
void Compiler::createSub()
{
impl->builder->createSub();
}

/*! Creates a multiply instruction from the last 2 values. */
void Compiler::createMul()
{
impl->builder->createMul();
}

/*! Creates a divide instruction from the last 2 values. */
void Compiler::createDiv()
{
impl->builder->createDiv();
}

/*! Creates an equality comparison instruction using the last 2 values. */
void Compiler::createCmpEQ()
{
impl->builder->createCmpEQ();
}

/*! Creates a greater than comparison instruction using the last 2 values. */
void Compiler::createCmpGT()
{
impl->builder->createCmpGT();
}

/*! Creates a lower than comparison instruction using the last 2 values. */
void Compiler::createCmpLT()
{
impl->builder->createCmpLT();
}

/*! Jumps to the given if substack. */
void Compiler::moveToIf(std::shared_ptr<Block> substack)
{
Expand Down
13 changes: 13 additions & 0 deletions src/dev/engine/internal/icodebuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ class ICodeBuilder
virtual void addVariableValue(Variable *variable) = 0;
virtual void addListContents(List *list) = 0;

virtual void createAdd() = 0;
virtual void createSub() = 0;
virtual void createMul() = 0;
virtual void createDiv() = 0;

virtual void createCmpEQ() = 0;
virtual void createCmpGT() = 0;
virtual void createCmpLT() = 0;

virtual void createAnd() = 0;
virtual void createOr() = 0;
virtual void createNot() = 0;

virtual void beginIfStatement() = 0;
virtual void beginElseBranch() = 0;
virtual void endIf() = 0;
Expand Down
Loading
Loading