27#include "../../kernel.hpp"
28#include "../utils/stringtools.hpp"
50 , m_bEnableOptimizer(true)
89 if (
this == &a_ByteCode)
148 std::size_t sz =
m_vRPN.size();
150 &y =
m_vRPN[sz - 1].Val.data2;
154 x = x != 0.0 && y != 0.0;
158 x = x != 0.0 || y != 0.0;
162 x = x.real() < y.real();
166 x = x.real() > y.real();
170 x = x.real() <= y.real();
174 x = x.real() >= y.real();
199#if defined(MUP_MATH_EXCEPTIONS)
231 bool bOptimized =
false;
235 std::size_t sz =
m_vRPN.size();
254 if (
m_vRPN[sz - 1].Val.data2 == 2.0)
256 else if (
m_vRPN[sz - 1].Val.data2 == 3.0)
258 else if (
m_vRPN[sz - 1].Val.data2 == 4.0)
286 assert((
m_vRPN[sz-2].Val.ptr == NULL &&
m_vRPN[sz-1].Val.ptr != NULL)
287 || (
m_vRPN[sz-2].Val.ptr != NULL &&
m_vRPN[sz-1].Val.ptr == NULL)
292 m_vRPN[sz-2].Val.data2 += ((a_Oprt ==
cmSUB) ? -1.0 : 1.0) *
m_vRPN[sz-1].Val.data2;
293 m_vRPN[sz-2].Val.data += ((a_Oprt ==
cmSUB) ? -1.0 : 1.0) *
m_vRPN[sz-1].Val.data;
294 m_vRPN[sz-2].Val.isVect =
false;
307 m_vRPN[sz-2].Val.data2 = 0;
308 m_vRPN[sz-2].Val.isVect =
false;
318 m_vRPN[sz-2].Val.isVect =
false;
347 &&
m_vRPN[sz-1].Val.data2 != 0.0)
420 std::size_t sz =
m_vRPN.size();
421 std::size_t nArg =
std::abs(a_iArgc);
430 for (
size_t s = sz-nArg; s < sz; s++)
435 optimizeAway =
false;
540 std::vector<mu::value_type> vStack;
543 for (
size_t s = sz-nArg; s < sz; s++)
545 vStack.push_back(
m_vRPN[s].Val.data2);
631 for (
int i = 0; i < (int)
m_vRPN.size(); ++i)
642 m_vRPN[idx].Oprt.offset = i - idx;
647 m_vRPN[idx].Oprt.offset = i - idx;
671 for (
size_t i = 0; i <
m_vRPN.size(); ++i)
675 m_vRPN[i].Val.ptr = a_pNewVar;
676 m_vRPN[i].Val.isVect = isVect;
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
static void toggleTableStatus()
Toggles the table writing status, which will reduce the number or events send to the terminal.
Bytecode implementation of the Math Parser.
void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx)
Add Strung function entry to the parser bytecode.
rpn_type m_vRPN
The actual rpn storage.
ParserByteCode & operator=(const ParserByteCode &a_ByteCode)
Assignment operator.
void ConstantFolding(ECmdCode a_Oprt)
void EnableOptimizer(bool bStat)
std::size_t GetMaxStackSize() const
void AddOp(ECmdCode a_Oprt)
Add an operator identifier to bytecode.
const SToken * GetBase() const
void ChangeVar(value_type *a_pOldVar, value_type *a_pNewVar, bool isVect)
Changes all old variable pointers to the new addresses. Will be used to compensate for different loca...
void Assign(const ParserByteCode &a_ByteCode)
Copy state of another object to this.
void AddVal(value_type a_fVal)
Add a Variable pointer to bytecode.
void AddBulkFun(generic_fun_type a_pFun, int a_iArgc)
Add a bulk function to bytecode.
ParserByteCode()
Bytecode default constructor.
void clear()
Delete the bytecode.
std::size_t GetSize() const
Returns the number of entries in the bytecode.
void AddFun(generic_fun_type a_pFun, int a_iArgc, bool optimizeAway)
Add a function to the bytecode.
void AsciiDump()
Dump bytecode (for debugging only!).
void AddVar(value_type *a_pVar)
Add a Variable pointer to bytecode.
std::vector< SToken > rpn_type
Token vector for storing the RPN.
std::size_t m_iMaxStackSize
Maximum size needed for the stack.
unsigned m_iStackPos
Position in the Calculation array.
void Finalize()
Add end marker to bytecode.
void AddAssignOp(value_type *a_pVar)
Add an assignement operator.
void AddIfElse(ECmdCode a_Oprt)
Error class of the parser.
Parser stack implementation.
void push(const TValueType &a_Val)
Push an object into the stack.
TValueType pop()
Pop a value from the stack.
Definition of the parser bytecode class.
This file contains standard definitions used by the parser.
This file defines the error class used by the parser.
This file defines the stack used by muparser.
This file contains the parser token definition.
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
Namespace for mathematical applications.
value_type(* multfun_type)(const value_type *, int)
Callback type used for functions with a variable argument list.
value_type(* fun_type9)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
value_type(* fun_type6)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
value_type(* fun_type10)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
value_type(* fun_type2)(const value_type &, const value_type &)
Callback type used for functions with two arguments.
value_type(* fun_type7)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
value_type(* fun_type5)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
value_type(* fun_type1)(const value_type &)
Callback type used for functions with a single arguments.
@ cmFUNC_BULK
Special callbacks for Bulk mode with an additional parameter for the bulk index.
@ cmADD
Operator item: add.
@ cmGE
Operator item: greater or equal.
@ cmLT
Operator item: less than.
@ cmPOW
Operator item: y to the power of ...
@ cmASSIGN
Operator item: Assignment operator.
@ cmLE
Operator item: less or equal.
@ cmMUL
Operator item: multiply.
@ cmDIV
Operator item: division.
@ cmENDIF
For use in the ternary if-then-else operator.
@ cmVAR_END
Only for identifying the end of the variable block.
@ cmIF
For use in the ternary if-then-else operator.
@ cmNEQ
Operator item: not equal.
@ cmGT
Operator item: greater than.
@ cmEQ
Operator item: equals.
@ cmSUB
Operator item: subtract.
@ cmFUNC_STR
Code for a function with a string parameter.
@ cmFUNC
Code for a generic function item.
@ cmELSE
For use in the ternary if-then-else operator.
@ ecINTERNAL_ERROR
Internal error of any kind.
@ ecDIV_BY_ZERO
Division by zero (currently unused)
value_type(* fun_type8)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
value_type(* generic_fun_type)()
Callback type used for functions without arguments.
value_type(* fun_type4)(const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with four arguments.
value_type(* fun_type0)()
Callback type used for functions without arguments.
value_type(* fun_type3)(const value_type &, const value_type &, const value_type &)
Callback type used for functions with three arguments.
static T Pow(const T &v1, const T &v2)
struct mu::SToken::@11::@14 Fun
struct mu::SToken::@11::@13 Val
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
std::string toString(int)
Converts an integer to a string without the Settings bloat.