switch (tok->Cmd)
{
case cmVAL:
- return tok->Val.data2;
+ return tok->u.Val.data2;
case cmVAR:
- return *tok->Val.ptr;
+ return *tok->u.Val.ptr;
case cmVARMUL:
- return *tok->Val.ptr * tok->Val.data + tok->Val.data2;
+ return *tok->u.Val.ptr * tok->u.Val.data + tok->u.Val.data2;
case cmVARPOW2:
- buf = *(tok->Val.ptr);
+ buf = *(tok->u.Val.ptr);
return buf * buf;
case cmVARPOW3:
- buf = *(tok->Val.ptr);
+ buf = *(tok->u.Val.ptr);
return buf * buf * buf;
case cmVARPOW4:
- buf = *(tok->Val.ptr);
+ buf = *(tok->u.Val.ptr);
return buf * buf * buf * buf;
// numerical function without any argument
case cmFUNC:
- return tok->Fun.cb.call_fun<0>();
+ return tok->u.Fun.cb.call_fun<0>();
// String function without a numerical argument
case cmFUNC_STR:
- return tok->Fun.cb.call_strfun<1>(m_vStringBuf[0].c_str());
+ return tok->u.Fun.cb.call_strfun<1>(m_vStringBuf[0].c_str());
default:
throw ParserError(ecINTERNAL_ERROR);
--sidx; stack[sidx] = MathImpl<value_type>::Pow(stack[sidx], stack[1 + sidx]);
continue;
- case cmLAND: --sidx; stack[sidx] = stack[sidx] && stack[sidx + 1]; continue;
- case cmLOR: --sidx; stack[sidx] = stack[sidx] || stack[sidx + 1]; continue;
+ case cmLAND: --sidx; stack[sidx] = (stack[sidx] != 0.0) && (stack[sidx + 1] != 0.0); continue;
+ case cmLOR: --sidx; stack[sidx] = (stack[sidx] != 0.0) || (stack[sidx + 1] != 0.0); continue;
case cmASSIGN:
// Bugfix for Bulkmode:
// for details see:
// https://groups.google.com/forum/embed/?place=forum/muparser-dev&showsearch=true&showpopout=true&showtabs=false&parenturl=http://muparser.beltoforion.de/mup_forum.html&afterlogin&pli=1#!topic/muparser-dev/szgatgoHTws
--sidx;
- stack[sidx] = *(pTok->Oprt.ptr + nOffset) = stack[sidx + 1];
+ stack[sidx] = *(pTok->u.Oprt.ptr + nOffset) = stack[sidx + 1];
continue;
// original code:
- //--sidx; Stack[sidx] = *pTok->Oprt.ptr = Stack[sidx+1]; continue;
+ //--sidx; Stack[sidx] = *pTok->u.Oprt.ptr = Stack[sidx+1]; continue;
case cmIF:
if (stack[sidx--] == 0)
{
MUP_ASSERT(sidx >= 0);
- pTok += pTok->Oprt.offset;
+ pTok += pTok->u.Oprt.offset;
}
continue;
case cmELSE:
- pTok += pTok->Oprt.offset;
+ pTok += pTok->u.Oprt.offset;
continue;
case cmENDIF:
continue;
// value and variable tokens
- case cmVAR: stack[++sidx] = *(pTok->Val.ptr + nOffset); continue;
- case cmVAL: stack[++sidx] = pTok->Val.data2; continue;
+ case cmVAR: stack[++sidx] = *(pTok->u.Val.ptr + nOffset); continue;
+ case cmVAL: stack[++sidx] = pTok->u.Val.data2; continue;
- case cmVARPOW2: buf = *(pTok->Val.ptr + nOffset);
+ case cmVARPOW2: buf = *(pTok->u.Val.ptr + nOffset);
stack[++sidx] = buf * buf;
continue;
- case cmVARPOW3: buf = *(pTok->Val.ptr + nOffset);
+ case cmVARPOW3: buf = *(pTok->u.Val.ptr + nOffset);
stack[++sidx] = buf * buf * buf;
continue;
- case cmVARPOW4: buf = *(pTok->Val.ptr + nOffset);
+ case cmVARPOW4: buf = *(pTok->u.Val.ptr + nOffset);
stack[++sidx] = buf * buf * buf * buf;
continue;
case cmVARMUL:
- stack[++sidx] = *(pTok->Val.ptr + nOffset) * pTok->Val.data + pTok->Val.data2;
+ stack[++sidx] = *(pTok->u.Val.ptr + nOffset) * pTok->u.Val.data + pTok->u.Val.data2;
continue;
// Next is treatment of numeric functions
case cmFUNC:
{
- int iArgCount = pTok->Fun.argc;
+ int iArgCount = pTok->u.Fun.argc;
// switch according to argument count
switch (iArgCount)
{
- case 0: sidx += 1; stack[sidx] = pTok->Fun.cb.call_fun<0 >(); continue;
- case 1: stack[sidx] = pTok->Fun.cb.call_fun<1 >(stack[sidx]); continue;
- case 2: sidx -= 1; stack[sidx] = pTok->Fun.cb.call_fun<2 >(stack[sidx], stack[sidx + 1]); continue;
- case 3: sidx -= 2; stack[sidx] = pTok->Fun.cb.call_fun<3 >(stack[sidx], stack[sidx + 1], stack[sidx + 2]); continue;
- case 4: sidx -= 3; stack[sidx] = pTok->Fun.cb.call_fun<4 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3]); continue;
- case 5: sidx -= 4; stack[sidx] = pTok->Fun.cb.call_fun<5 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4]); continue;
- case 6: sidx -= 5; stack[sidx] = pTok->Fun.cb.call_fun<6 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5]); continue;
- case 7: sidx -= 6; stack[sidx] = pTok->Fun.cb.call_fun<7 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6]); continue;
- case 8: sidx -= 7; stack[sidx] = pTok->Fun.cb.call_fun<8 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7]); continue;
- case 9: sidx -= 8; stack[sidx] = pTok->Fun.cb.call_fun<9 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7], stack[sidx + 8]); continue;
- case 10:sidx -= 9; stack[sidx] = pTok->Fun.cb.call_fun<10>(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7], stack[sidx + 8], stack[sidx + 9]); continue;
+ case 0: sidx += 1; stack[sidx] = pTok->u.Fun.cb.call_fun<0 >(); continue;
+ case 1: stack[sidx] = pTok->u.Fun.cb.call_fun<1 >(stack[sidx]); continue;
+ case 2: sidx -= 1; stack[sidx] = pTok->u.Fun.cb.call_fun<2 >(stack[sidx], stack[sidx + 1]); continue;
+ case 3: sidx -= 2; stack[sidx] = pTok->u.Fun.cb.call_fun<3 >(stack[sidx], stack[sidx + 1], stack[sidx + 2]); continue;
+ case 4: sidx -= 3; stack[sidx] = pTok->u.Fun.cb.call_fun<4 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3]); continue;
+ case 5: sidx -= 4; stack[sidx] = pTok->u.Fun.cb.call_fun<5 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4]); continue;
+ case 6: sidx -= 5; stack[sidx] = pTok->u.Fun.cb.call_fun<6 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5]); continue;
+ case 7: sidx -= 6; stack[sidx] = pTok->u.Fun.cb.call_fun<7 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6]); continue;
+ case 8: sidx -= 7; stack[sidx] = pTok->u.Fun.cb.call_fun<8 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7]); continue;
+ case 9: sidx -= 8; stack[sidx] = pTok->u.Fun.cb.call_fun<9 >(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7], stack[sidx + 8]); continue;
+ case 10:sidx -= 9; stack[sidx] = pTok->u.Fun.cb.call_fun<10>(stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7], stack[sidx + 8], stack[sidx + 9]); continue;
default:
// function with variable arguments store the number as a negative value
if (iArgCount > 0)
Error(ecINTERNAL_ERROR, -1);
// </ibg>
- stack[sidx] = pTok->Fun.cb.call_multfun(&stack[sidx], -iArgCount);
+ stack[sidx] = pTok->u.Fun.cb.call_multfun(&stack[sidx], -iArgCount);
continue;
}
}
// Next is treatment of string functions
case cmFUNC_STR:
{
- sidx -= pTok->Fun.argc - 1;
+ sidx -= pTok->u.Fun.argc - 1;
// The index of the string argument in the string table
- int iIdxStack = pTok->Fun.idx;
+ int iIdxStack = pTok->u.Fun.idx;
if (iIdxStack < 0 || iIdxStack >= (int)m_vStringBuf.size())
Error(ecINTERNAL_ERROR, m_pTokenReader->GetPos());
- switch (pTok->Fun.argc) // switch according to argument count
+ switch (pTok->u.Fun.argc) // switch according to argument count
{
- case 0: stack[sidx] = pTok->Fun.cb.call_strfun<1>(m_vStringBuf[iIdxStack].c_str()); continue;
- case 1: stack[sidx] = pTok->Fun.cb.call_strfun<2>(m_vStringBuf[iIdxStack].c_str(), stack[sidx]); continue;
- case 2: stack[sidx] = pTok->Fun.cb.call_strfun<3>(m_vStringBuf[iIdxStack].c_str(), stack[sidx], stack[sidx + 1]); continue;
- case 3: stack[sidx] = pTok->Fun.cb.call_strfun<4>(m_vStringBuf[iIdxStack].c_str(), stack[sidx], stack[sidx + 1], stack[sidx + 2]); continue;
- case 4: stack[sidx] = pTok->Fun.cb.call_strfun<5>(m_vStringBuf[iIdxStack].c_str(), stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3]); continue;
- case 5: stack[sidx] = pTok->Fun.cb.call_strfun<6>(m_vStringBuf[iIdxStack].c_str(), stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4]); continue;
+ case 0: stack[sidx] = pTok->u.Fun.cb.call_strfun<1>(m_vStringBuf[iIdxStack].c_str()); continue;
+ case 1: stack[sidx] = pTok->u.Fun.cb.call_strfun<2>(m_vStringBuf[iIdxStack].c_str(), stack[sidx]); continue;
+ case 2: stack[sidx] = pTok->u.Fun.cb.call_strfun<3>(m_vStringBuf[iIdxStack].c_str(), stack[sidx], stack[sidx + 1]); continue;
+ case 3: stack[sidx] = pTok->u.Fun.cb.call_strfun<4>(m_vStringBuf[iIdxStack].c_str(), stack[sidx], stack[sidx + 1], stack[sidx + 2]); continue;
+ case 4: stack[sidx] = pTok->u.Fun.cb.call_strfun<5>(m_vStringBuf[iIdxStack].c_str(), stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3]); continue;
+ case 5: stack[sidx] = pTok->u.Fun.cb.call_strfun<6>(m_vStringBuf[iIdxStack].c_str(), stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4]); continue;
}
continue;
case cmFUNC_BULK:
{
- int iArgCount = pTok->Fun.argc;
+ int iArgCount = pTok->u.Fun.argc;
// switch according to argument count
switch (iArgCount)
{
- case 0: sidx += 1; stack[sidx] = pTok->Fun.cb.call_bulkfun<0 >(nOffset, nThreadID); continue;
- case 1: stack[sidx] = pTok->Fun.cb.call_bulkfun<1 >(nOffset, nThreadID, stack[sidx]); continue;
- case 2: sidx -= 1; stack[sidx] = pTok->Fun.cb.call_bulkfun<2 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1]); continue;
- case 3: sidx -= 2; stack[sidx] = pTok->Fun.cb.call_bulkfun<3 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2]); continue;
- case 4: sidx -= 3; stack[sidx] = pTok->Fun.cb.call_bulkfun<4 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3]); continue;
- case 5: sidx -= 4; stack[sidx] = pTok->Fun.cb.call_bulkfun<5 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4]); continue;
- case 6: sidx -= 5; stack[sidx] = pTok->Fun.cb.call_bulkfun<6 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5]); continue;
- case 7: sidx -= 6; stack[sidx] = pTok->Fun.cb.call_bulkfun<7 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6]); continue;
- case 8: sidx -= 7; stack[sidx] = pTok->Fun.cb.call_bulkfun<8 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7]); continue;
- case 9: sidx -= 8; stack[sidx] = pTok->Fun.cb.call_bulkfun<9 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7], stack[sidx + 8]); continue;
- case 10:sidx -= 9; stack[sidx] = pTok->Fun.cb.call_bulkfun<10>(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7], stack[sidx + 8], stack[sidx + 9]); continue;
+ case 0: sidx += 1; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<0 >(nOffset, nThreadID); continue;
+ case 1: stack[sidx] = pTok->u.Fun.cb.call_bulkfun<1 >(nOffset, nThreadID, stack[sidx]); continue;
+ case 2: sidx -= 1; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<2 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1]); continue;
+ case 3: sidx -= 2; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<3 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2]); continue;
+ case 4: sidx -= 3; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<4 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3]); continue;
+ case 5: sidx -= 4; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<5 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4]); continue;
+ case 6: sidx -= 5; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<6 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5]); continue;
+ case 7: sidx -= 6; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<7 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6]); continue;
+ case 8: sidx -= 7; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<8 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7]); continue;
+ case 9: sidx -= 8; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<9 >(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7], stack[sidx + 8]); continue;
+ case 10:sidx -= 9; stack[sidx] = pTok->u.Fun.cb.call_bulkfun<10>(nOffset, nThreadID, stack[sidx], stack[sidx + 1], stack[sidx + 2], stack[sidx + 3], stack[sidx + 4], stack[sidx + 5], stack[sidx + 6], stack[sidx + 7], stack[sidx + 8], stack[sidx + 9]); continue;
default:
throw exception_type(ecINTERNAL_ERROR, 2, _T(""));
}
// optimization does not apply
SToken tok;
tok.Cmd = cmVAR;
- tok.Val.ptr = a_pVar;
- tok.Val.data = 1;
- tok.Val.data2 = 0;
+ tok.u.Val.ptr = a_pVar;
+ tok.u.Val.data = 1;
+ tok.u.Val.data2 = 0;
m_vRPN.push_back(tok);
}
// If optimization does not apply
SToken tok;
tok.Cmd = cmVAL;
- tok.Val.ptr = nullptr;
- tok.Val.data = 0;
- tok.Val.data2 = a_fVal;
+ tok.u.Val.ptr = nullptr;
+ tok.u.Val.data = 0;
+ tok.u.Val.data2 = a_fVal;
m_vRPN.push_back(tok);
}
void ParserByteCode::ConstantFolding(ECmdCode a_Oprt)
{
std::size_t sz = m_vRPN.size();
- value_type& x = m_vRPN[sz - 2].Val.data2;
- value_type& y = m_vRPN[sz - 1].Val.data2;
+ value_type& x = m_vRPN[sz - 2].u.Val.data2;
+ value_type& y = m_vRPN[sz - 1].u.Val.data2;
switch (a_Oprt)
{
// Optimization for polynomials of low order
if (m_vRPN[sz - 2].Cmd == cmVAR && m_vRPN[sz - 1].Cmd == cmVAL)
{
- if (m_vRPN[sz - 1].Val.data2 == 0)
+ if (m_vRPN[sz - 1].u.Val.data2 == 0)
{
m_vRPN[sz - 2].Cmd = cmVAL;
- m_vRPN[sz - 2].Val.ptr = nullptr;
- m_vRPN[sz - 2].Val.data = 0;
- m_vRPN[sz - 2].Val.data2 = 1;
+ m_vRPN[sz - 2].u.Val.ptr = nullptr;
+ m_vRPN[sz - 2].u.Val.data = 0;
+ m_vRPN[sz - 2].u.Val.data2 = 1;
}
- else if (m_vRPN[sz - 1].Val.data2 == 1)
+ else if (m_vRPN[sz - 1].u.Val.data2 == 1)
m_vRPN[sz - 2].Cmd = cmVAR;
- else if (m_vRPN[sz - 1].Val.data2 == 2)
+ else if (m_vRPN[sz - 1].u.Val.data2 == 2)
m_vRPN[sz - 2].Cmd = cmVARPOW2;
- else if (m_vRPN[sz - 1].Val.data2 == 3)
+ else if (m_vRPN[sz - 1].u.Val.data2 == 3)
m_vRPN[sz - 2].Cmd = cmVARPOW3;
- else if (m_vRPN[sz - 1].Val.data2 == 4)
+ else if (m_vRPN[sz - 1].u.Val.data2 == 4)
m_vRPN[sz - 2].Cmd = cmVARPOW4;
else
break;
(m_vRPN[sz - 1].Cmd == cmVAL && m_vRPN[sz - 2].Cmd == cmVAR) ||
(m_vRPN[sz - 1].Cmd == cmVAL && m_vRPN[sz - 2].Cmd == cmVARMUL) ||
(m_vRPN[sz - 1].Cmd == cmVARMUL && m_vRPN[sz - 2].Cmd == cmVAL) ||
- (m_vRPN[sz - 1].Cmd == cmVAR && m_vRPN[sz - 2].Cmd == cmVAR && m_vRPN[sz - 2].Val.ptr == m_vRPN[sz - 1].Val.ptr) ||
- (m_vRPN[sz - 1].Cmd == cmVAR && m_vRPN[sz - 2].Cmd == cmVARMUL && m_vRPN[sz - 2].Val.ptr == m_vRPN[sz - 1].Val.ptr) ||
- (m_vRPN[sz - 1].Cmd == cmVARMUL && m_vRPN[sz - 2].Cmd == cmVAR && m_vRPN[sz - 2].Val.ptr == m_vRPN[sz - 1].Val.ptr) ||
- (m_vRPN[sz - 1].Cmd == cmVARMUL && m_vRPN[sz - 2].Cmd == cmVARMUL && m_vRPN[sz - 2].Val.ptr == m_vRPN[sz - 1].Val.ptr))
+ (m_vRPN[sz - 1].Cmd == cmVAR && m_vRPN[sz - 2].Cmd == cmVAR && m_vRPN[sz - 2].u.Val.ptr == m_vRPN[sz - 1].u.Val.ptr) ||
+ (m_vRPN[sz - 1].Cmd == cmVAR && m_vRPN[sz - 2].Cmd == cmVARMUL && m_vRPN[sz - 2].u.Val.ptr == m_vRPN[sz - 1].u.Val.ptr) ||
+ (m_vRPN[sz - 1].Cmd == cmVARMUL && m_vRPN[sz - 2].Cmd == cmVAR && m_vRPN[sz - 2].u.Val.ptr == m_vRPN[sz - 1].u.Val.ptr) ||
+ (m_vRPN[sz - 1].Cmd == cmVARMUL && m_vRPN[sz - 2].Cmd == cmVARMUL && m_vRPN[sz - 2].u.Val.ptr == m_vRPN[sz - 1].u.Val.ptr))
{
MUP_ASSERT(
- (m_vRPN[sz - 2].Val.ptr == nullptr && m_vRPN[sz - 1].Val.ptr != nullptr) ||
- (m_vRPN[sz - 2].Val.ptr != nullptr && m_vRPN[sz - 1].Val.ptr == nullptr) ||
- (m_vRPN[sz - 2].Val.ptr == m_vRPN[sz - 1].Val.ptr));
+ (m_vRPN[sz - 2].u.Val.ptr == nullptr && m_vRPN[sz - 1].u.Val.ptr != nullptr) ||
+ (m_vRPN[sz - 2].u.Val.ptr != nullptr && m_vRPN[sz - 1].u.Val.ptr == nullptr) ||
+ (m_vRPN[sz - 2].u.Val.ptr == m_vRPN[sz - 1].u.Val.ptr));
m_vRPN[sz - 2].Cmd = cmVARMUL;
- m_vRPN[sz - 2].Val.ptr = (value_type*)((long long)(m_vRPN[sz - 2].Val.ptr) | (long long)(m_vRPN[sz - 1].Val.ptr)); // variable
- m_vRPN[sz - 2].Val.data2 += ((a_Oprt == cmSUB) ? -1 : 1) * m_vRPN[sz - 1].Val.data2; // offset
- m_vRPN[sz - 2].Val.data += ((a_Oprt == cmSUB) ? -1 : 1) * m_vRPN[sz - 1].Val.data; // multiplicand
+ m_vRPN[sz - 2].u.Val.ptr = (value_type*)((long long)(m_vRPN[sz - 2].u.Val.ptr) | (long long)(m_vRPN[sz - 1].u.Val.ptr)); // variable
+ m_vRPN[sz - 2].u.Val.data2 += ((a_Oprt == cmSUB) ? -1 : 1) * m_vRPN[sz - 1].u.Val.data2; // offset
+ m_vRPN[sz - 2].u.Val.data += ((a_Oprt == cmSUB) ? -1 : 1) * m_vRPN[sz - 1].u.Val.data; // multiplicand
m_vRPN.pop_back();
bOptimized = true;
}
(m_vRPN[sz - 1].Cmd == cmVAL && m_vRPN[sz - 2].Cmd == cmVAR))
{
m_vRPN[sz - 2].Cmd = cmVARMUL;
- m_vRPN[sz - 2].Val.ptr = (value_type*)((long long)(m_vRPN[sz - 2].Val.ptr) | (long long)(m_vRPN[sz - 1].Val.ptr));
- m_vRPN[sz - 2].Val.data = m_vRPN[sz - 2].Val.data2 + m_vRPN[sz - 1].Val.data2;
- m_vRPN[sz - 2].Val.data2 = 0;
+ m_vRPN[sz - 2].u.Val.ptr = (value_type*)((long long)(m_vRPN[sz - 2].u.Val.ptr) | (long long)(m_vRPN[sz - 1].u.Val.ptr));
+ m_vRPN[sz - 2].u.Val.data = m_vRPN[sz - 2].u.Val.data2 + m_vRPN[sz - 1].u.Val.data2;
+ m_vRPN[sz - 2].u.Val.data2 = 0;
m_vRPN.pop_back();
bOptimized = true;
}
{
// Optimization: 2*(3*b+1) or (3*b+1)*2 -> 6*b+2
m_vRPN[sz - 2].Cmd = cmVARMUL;
- m_vRPN[sz - 2].Val.ptr = (value_type*)((long long)(m_vRPN[sz - 2].Val.ptr) | (long long)(m_vRPN[sz - 1].Val.ptr));
+ m_vRPN[sz - 2].u.Val.ptr = (value_type*)((long long)(m_vRPN[sz - 2].u.Val.ptr) | (long long)(m_vRPN[sz - 1].u.Val.ptr));
if (m_vRPN[sz - 1].Cmd == cmVAL)
{
- m_vRPN[sz - 2].Val.data *= m_vRPN[sz - 1].Val.data2;
- m_vRPN[sz - 2].Val.data2 *= m_vRPN[sz - 1].Val.data2;
+ m_vRPN[sz - 2].u.Val.data *= m_vRPN[sz - 1].u.Val.data2;
+ m_vRPN[sz - 2].u.Val.data2 *= m_vRPN[sz - 1].u.Val.data2;
}
else
{
- m_vRPN[sz - 2].Val.data = m_vRPN[sz - 1].Val.data * m_vRPN[sz - 2].Val.data2;
- m_vRPN[sz - 2].Val.data2 = m_vRPN[sz - 1].Val.data2 * m_vRPN[sz - 2].Val.data2;
+ m_vRPN[sz - 2].u.Val.data = m_vRPN[sz - 1].u.Val.data * m_vRPN[sz - 2].u.Val.data2;
+ m_vRPN[sz - 2].u.Val.data2 = m_vRPN[sz - 1].u.Val.data2 * m_vRPN[sz - 2].u.Val.data2;
}
m_vRPN.pop_back();
bOptimized = true;
}
else if (
m_vRPN[sz - 1].Cmd == cmVAR && m_vRPN[sz - 2].Cmd == cmVAR &&
- m_vRPN[sz - 1].Val.ptr == m_vRPN[sz - 2].Val.ptr)
+ m_vRPN[sz - 1].u.Val.ptr == m_vRPN[sz - 2].u.Val.ptr)
{
// Optimization: a*a -> a^2
m_vRPN[sz - 2].Cmd = cmVARPOW2;
break;
case cmDIV:
- if (m_vRPN[sz - 1].Cmd == cmVAL && m_vRPN[sz - 2].Cmd == cmVARMUL && m_vRPN[sz - 1].Val.data2 != 0)
+ if (m_vRPN[sz - 1].Cmd == cmVAL && m_vRPN[sz - 2].Cmd == cmVARMUL && m_vRPN[sz - 1].u.Val.data2 != 0)
{
// Optimization: 4*a/2 -> 2*a
- m_vRPN[sz - 2].Val.data /= m_vRPN[sz - 1].Val.data2;
- m_vRPN[sz - 2].Val.data2 /= m_vRPN[sz - 1].Val.data2;
+ m_vRPN[sz - 2].u.Val.data /= m_vRPN[sz - 1].u.Val.data2;
+ m_vRPN[sz - 2].u.Val.data2 /= m_vRPN[sz - 1].u.Val.data2;
m_vRPN.pop_back();
bOptimized = true;
}
SToken tok;
tok.Cmd = cmASSIGN;
- tok.Oprt.ptr = a_pVar;
+ tok.u.Oprt.ptr = a_pVar;
m_vRPN.push_back(tok);
}
value_type val = 0;
switch (a_iArgc)
{
- case 1: val = a_pFun.call_fun<1>(m_vRPN[sz - 1].Val.data2); break;
- case 2: val = a_pFun.call_fun<2>(m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
- case 3: val = a_pFun.call_fun<3>(m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
- case 4: val = a_pFun.call_fun<4>(m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
- case 5: val = a_pFun.call_fun<5>(m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
- case 6: val = a_pFun.call_fun<6>(m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
- case 7: val = a_pFun.call_fun<7>(m_vRPN[sz - 7].Val.data2, m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
- case 8: val = a_pFun.call_fun<8>(m_vRPN[sz - 8].Val.data2, m_vRPN[sz - 7].Val.data2, m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
- case 9: val = a_pFun.call_fun<9>(m_vRPN[sz - 9].Val.data2, m_vRPN[sz - 8].Val.data2, m_vRPN[sz - 7].Val.data2, m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
- case 10: val = a_pFun.call_fun<10>(m_vRPN[sz - 10].Val.data2, m_vRPN[sz - 9].Val.data2, m_vRPN[sz - 8].Val.data2, m_vRPN[sz - 7].Val.data2, m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break;
+ case 1: val = a_pFun.call_fun<1>(m_vRPN[sz - 1].u.Val.data2); break;
+ case 2: val = a_pFun.call_fun<2>(m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
+ case 3: val = a_pFun.call_fun<3>(m_vRPN[sz - 3].u.Val.data2, m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
+ case 4: val = a_pFun.call_fun<4>(m_vRPN[sz - 4].u.Val.data2, m_vRPN[sz - 3].u.Val.data2, m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
+ case 5: val = a_pFun.call_fun<5>(m_vRPN[sz - 5].u.Val.data2, m_vRPN[sz - 4].u.Val.data2, m_vRPN[sz - 3].u.Val.data2, m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
+ case 6: val = a_pFun.call_fun<6>(m_vRPN[sz - 6].u.Val.data2, m_vRPN[sz - 5].u.Val.data2, m_vRPN[sz - 4].u.Val.data2, m_vRPN[sz - 3].u.Val.data2, m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
+ case 7: val = a_pFun.call_fun<7>(m_vRPN[sz - 7].u.Val.data2, m_vRPN[sz - 6].u.Val.data2, m_vRPN[sz - 5].u.Val.data2, m_vRPN[sz - 4].u.Val.data2, m_vRPN[sz - 3].u.Val.data2, m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
+ case 8: val = a_pFun.call_fun<8>(m_vRPN[sz - 8].u.Val.data2, m_vRPN[sz - 7].u.Val.data2, m_vRPN[sz - 6].u.Val.data2, m_vRPN[sz - 5].u.Val.data2, m_vRPN[sz - 4].u.Val.data2, m_vRPN[sz - 3].u.Val.data2, m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
+ case 9: val = a_pFun.call_fun<9>(m_vRPN[sz - 9].u.Val.data2, m_vRPN[sz - 8].u.Val.data2, m_vRPN[sz - 7].u.Val.data2, m_vRPN[sz - 6].u.Val.data2, m_vRPN[sz - 5].u.Val.data2, m_vRPN[sz - 4].u.Val.data2, m_vRPN[sz - 3].u.Val.data2, m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
+ case 10: val = a_pFun.call_fun<10>(m_vRPN[sz - 10].u.Val.data2, m_vRPN[sz - 9].u.Val.data2, m_vRPN[sz - 8].u.Val.data2, m_vRPN[sz - 7].u.Val.data2, m_vRPN[sz - 6].u.Val.data2, m_vRPN[sz - 5].u.Val.data2, m_vRPN[sz - 4].u.Val.data2, m_vRPN[sz - 3].u.Val.data2, m_vRPN[sz - 2].u.Val.data2, m_vRPN[sz - 1].u.Val.data2); break;
default:
// For now functions with unlimited number of arguments are not optimized
throw ParserError(ecINTERNAL_ERROR);
SToken tok;
tok.Cmd = cmVAL;
- tok.Val.data = 0;
- tok.Val.data2 = val;
- tok.Val.ptr = nullptr;
+ tok.u.Val.data = 0;
+ tok.u.Val.data2 = val;
+ tok.u.Val.ptr = nullptr;
m_vRPN.push_back(tok);
}
else
{
SToken tok;
tok.Cmd = cmFUNC;
- tok.Fun.argc = a_iArgc;
- tok.Fun.cb = a_pFun;
+ tok.u.Fun.argc = a_iArgc;
+ tok.u.Fun.cb = a_pFun;
m_vRPN.push_back(tok);
}
SToken tok;
tok.Cmd = cmFUNC_BULK;
- tok.Fun.argc = a_iArgc;
- tok.Fun.cb = a_pFun;
+ tok.u.Fun.argc = a_iArgc;
+ tok.u.Fun.cb = a_pFun;
m_vRPN.push_back(tok);
}
SToken tok;
tok.Cmd = cmFUNC_STR;
- tok.Fun.argc = a_iArgc;
- tok.Fun.idx = a_iIdx;
- tok.Fun.cb = a_pFun;
+ tok.u.Fun.argc = a_iArgc;
+ tok.u.Fun.idx = a_iIdx;
+ tok.u.Fun.cb = a_pFun;
m_vRPN.push_back(tok);
m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos);
stElse.push(i);
idx = stIf.top();
stIf.pop();
- m_vRPN[idx].Oprt.offset = i - idx;
+ m_vRPN[idx].u.Oprt.offset = i - idx;
break;
case cmENDIF:
idx = stElse.top();
stElse.pop();
- m_vRPN[idx].Oprt.offset = i - idx;
+ m_vRPN[idx].u.Oprt.offset = i - idx;
break;
default:
switch (m_vRPN[i].Cmd)
{
case cmVAL: mu::console() << _T("VAL \t");
- mu::console() << _T("[") << m_vRPN[i].Val.data2 << _T("]\n");
+ mu::console() << _T("[") << m_vRPN[i].u.Val.data2 << _T("]\n");
break;
case cmVAR: mu::console() << _T("VAR \t");
- mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]\n");
+ mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]\n");
break;
case cmVARPOW2: mu::console() << _T("VARPOW2 \t");
- mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]\n");
+ mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]\n");
break;
case cmVARPOW3: mu::console() << _T("VARPOW3 \t");
- mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]\n");
+ mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]\n");
break;
case cmVARPOW4: mu::console() << _T("VARPOW4 \t");
- mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]\n");
+ mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]\n");
break;
case cmVARMUL: mu::console() << _T("VARMUL \t");
- mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]");
- mu::console() << _T(" * [") << m_vRPN[i].Val.data << _T("]");
- mu::console() << _T(" + [") << m_vRPN[i].Val.data2 << _T("]\n");
+ mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]");
+ mu::console() << _T(" * [") << m_vRPN[i].u.Val.data << _T("]");
+ mu::console() << _T(" + [") << m_vRPN[i].u.Val.data2 << _T("]\n");
break;
case cmFUNC: mu::console() << _T("CALL\t");
- mu::console() << _T("[ARG:") << std::dec << m_vRPN[i].Fun.argc << _T("]");
- mu::console() << _T("[ADDR: 0x") << std::hex << reinterpret_cast<void*>(m_vRPN[i].Fun.cb._pRawFun) << _T("]");
- mu::console() << _T("[USERDATA: 0x") << std::hex << reinterpret_cast<void*>(m_vRPN[i].Fun.cb._pUserData) << _T("]");
+ mu::console() << _T("[ARG:") << std::dec << m_vRPN[i].u.Fun.argc << _T("]");
+ mu::console() << _T("[ADDR: 0x") << std::hex << reinterpret_cast<void*>(m_vRPN[i].u.Fun.cb._pRawFun) << _T("]");
+ mu::console() << _T("[USERDATA: 0x") << std::hex << reinterpret_cast<void*>(m_vRPN[i].u.Fun.cb._pUserData) << _T("]");
mu::console() << _T("\n");
break;
case cmFUNC_STR:
mu::console() << _T("CALL STRFUNC\t");
- mu::console() << _T("[ARG:") << std::dec << m_vRPN[i].Fun.argc << _T("]");
- mu::console() << _T("[IDX:") << std::dec << m_vRPN[i].Fun.idx << _T("]");
- mu::console() << _T("[ADDR: 0x") << std::hex << reinterpret_cast<void*>(m_vRPN[i].Fun.cb._pRawFun) << _T("]");
- mu::console() << _T("[USERDATA: 0x") << std::hex << reinterpret_cast<void*>(m_vRPN[i].Fun.cb._pUserData) << _T("]");
+ mu::console() << _T("[ARG:") << std::dec << m_vRPN[i].u.Fun.argc << _T("]");
+ mu::console() << _T("[IDX:") << std::dec << m_vRPN[i].u.Fun.idx << _T("]");
+ mu::console() << _T("[ADDR: 0x") << std::hex << reinterpret_cast<void*>(m_vRPN[i].u.Fun.cb._pRawFun) << _T("]");
+ mu::console() << _T("[USERDATA: 0x") << std::hex << reinterpret_cast<void*>(m_vRPN[i].u.Fun.cb._pUserData) << _T("]");
mu::console() << _T("\n");
break;
case cmPOW: mu::console() << _T("POW\n"); break;
case cmIF: mu::console() << _T("IF\t");
- mu::console() << _T("[OFFSET:") << std::dec << m_vRPN[i].Oprt.offset << _T("]\n");
+ mu::console() << _T("[OFFSET:") << std::dec << m_vRPN[i].u.Oprt.offset << _T("]\n");
break;
case cmELSE: mu::console() << _T("ELSE\t");
- mu::console() << _T("[OFFSET:") << std::dec << m_vRPN[i].Oprt.offset << _T("]\n");
+ mu::console() << _T("[OFFSET:") << std::dec << m_vRPN[i].u.Oprt.offset << _T("]\n");
break;
case cmENDIF: mu::console() << _T("ENDIF\n"); break;
case cmASSIGN:
mu::console() << _T("ASSIGN\t");
- mu::console() << _T("[ADDR: 0x") << m_vRPN[i].Oprt.ptr << _T("]\n");
+ mu::console() << _T("[ADDR: 0x") << m_vRPN[i].u.Oprt.ptr << _T("]\n");
break;
default: mu::console() << _T("(unknown code: ") << m_vRPN[i].Cmd << _T(")\n");