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
17 changes: 17 additions & 0 deletions include/scratchcpp/dev/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ class LIBSCRATCHCPP_EXPORT Compiler
void createOr();
void createNot();

void createMod();
void createRound();
void createAbs();
void createFloor();
void createCeil();
void createSqrt();
void createSin();
void createCos();
void createTan();
void createAsin();
void createAcos();
void createAtan();
void createLn();
void createLog10();
void createExp();
void createExp10();

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
96 changes: 96 additions & 0 deletions src/dev/engine/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,102 @@ void Compiler::createNot()
impl->builder->createNot();
}

/*! Creates a remainder operation using the last 2 values. */
void Compiler::createMod()
{
impl->builder->createMod();
}

/*! Creates a round operation using the last value. */
void Compiler::createRound()
{
impl->builder->createRound();
}

/*! Creates an abs operation using the last value. */
void Compiler::createAbs()
{
impl->builder->createAbs();
}

/*! Creates a floor operation using the last value. */
void Compiler::createFloor()
{
impl->builder->createFloor();
}

/*! Creates a ceiling operation using the last value. */
void Compiler::createCeil()
{
impl->builder->createCeil();
}

/*! Creates a square root operation using the last value. */
void Compiler::createSqrt()
{
impl->builder->createSqrt();
}

/*! Creates a sin operation using the last value. */
void Compiler::createSin()
{
impl->builder->createSin();
}

/*! Creates a cos operation using the last value. */
void Compiler::createCos()
{
impl->builder->createCos();
}

/*! Creates a tan operation using the last value. */
void Compiler::createTan()
{
impl->builder->createTan();
}

/*! Creates an asin operation using the last value. */
void Compiler::createAsin()
{
impl->builder->createAsin();
}

/*! Creates an acos operation using the last value. */
void Compiler::createAcos()
{
impl->builder->createAcos();
}

/*! Creates an atan operation using the last value. */
void Compiler::createAtan()
{
impl->builder->createAtan();
}

/*! Creates an ln operation using the last value. */
void Compiler::createLn()
{
impl->builder->createLn();
}

/*! Creates a log10 operation using the last value. */
void Compiler::createLog10()
{
impl->builder->createLog10();
}

/*! Creates an e^x operation using the last value. */
void Compiler::createExp()
{
impl->builder->createExp();
}

/*! Creates a 10^x operation using the last value. */
void Compiler::createExp10()
{
impl->builder->createExp10();
}

/*! Jumps to the given if substack. */
void Compiler::moveToIf(std::shared_ptr<Block> substack)
{
Expand Down
17 changes: 17 additions & 0 deletions src/dev/engine/internal/icodebuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ class ICodeBuilder
virtual void createOr() = 0;
virtual void createNot() = 0;

virtual void createMod() = 0;
virtual void createRound() = 0;
virtual void createAbs() = 0;
virtual void createFloor() = 0;
virtual void createCeil() = 0;
virtual void createSqrt() = 0;
virtual void createSin() = 0;
virtual void createCos() = 0;
virtual void createTan() = 0;
virtual void createAsin() = 0;
virtual void createAcos() = 0;
virtual void createAtan() = 0;
virtual void createLn() = 0;
virtual void createLog10() = 0;
virtual void createExp() = 0;
virtual void createExp10() = 0;

virtual void beginIfStatement() = 0;
virtual void beginElseBranch() = 0;
virtual void endIf() = 0;
Expand Down
294 changes: 294 additions & 0 deletions src/dev/engine/internal/llvmcodebuilder.cpp

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/dev/engine/internal/llvmcodebuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ class LLVMCodeBuilder : public ICodeBuilder
void createOr() override;
void createNot() override;

void createMod() override;
void createRound() override;
void createAbs() override;
void createFloor() override;
void createCeil() override;
void createSqrt() override;
void createSin() override;
void createCos() override;
void createTan() override;
void createAsin() override;
void createAcos() override;
void createAtan() override;
void createLn() override;
void createLog10() override;
void createExp() override;
void createExp10() override;

void beginIfStatement() override;
void beginElseBranch() override;
void endIf() override;
Expand Down Expand Up @@ -81,6 +98,22 @@ class LLVMCodeBuilder : public ICodeBuilder
And,
Or,
Not,
Mod,
Round,
Abs,
Floor,
Ceil,
Sqrt,
Sin,
Cos,
Tan,
Asin,
Acos,
Atan,
Ln,
Log10,
Exp,
Exp10,
Yield,
BeginIf,
BeginElse,
Expand Down
14 changes: 3 additions & 11 deletions src/scratch/value_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,9 @@ extern "C"
/*! Calculates the modulo the given values and writes the result to dst. */
void value_mod(const libscratchcpp::ValueData *v1, const libscratchcpp::ValueData *v2, ValueData *dst)
{
double a = value_toDouble(v1);
double b = value_toDouble(v2);

if ((b == 0) || std::isinf(a))
value_assign_double(dst, std::numeric_limits<double>::quiet_NaN());
else if (std::isinf(b))
value_assign_double(dst, value_toDouble(v1));
else if (value_isNegative(v1) || value_isNegative(v2))
value_assign_double(dst, fmod(value_toDouble(v2) + fmod(value_toDouble(v1), -value_toDouble(v2)), value_toDouble(v2)));
else
value_assign_double(dst, fmod(value_toDouble(v1), value_toDouble(v2)));
const double a = value_toDouble(v1);
const double b = value_toDouble(v2);
value_assign_double(dst, fmod(a, b) / b < 0.0 ? fmod(a, b) + b : fmod(a, b));
}

/* comparison */
Expand Down
4 changes: 2 additions & 2 deletions src/scratch/value_functions_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern "C"
return v < 0 && std::isinf(v);
}

inline long value_convert_int_str(const char *str, int n, bool *ok)
inline double value_convert_int_str(const char *str, int n, bool *ok)
{
if (ok)
*ok = false;
Expand Down Expand Up @@ -80,7 +80,7 @@ extern "C"
*ok = true;

if (isNegative)
return -ret;
return -static_cast<double>(ret); // for negative zero
else
return ret;
}
Expand Down
Loading
Loading