From 5e99cf1feed8be3062c83405aa4b8bbcf85ed5bd Mon Sep 17 00:00:00 2001 From: David Wells Date: Mon, 28 Mar 2022 15:43:52 -0400 Subject: [PATCH] Remove an anonymous union. --- .../include/muParserBytecode.h | 2 +- bundled/muparser_v2_3_3/src/muParserBase.cpp | 108 ++++++------ .../muparser_v2_3_3/src/muParserBytecode.cpp | 158 +++++++++--------- 3 files changed, 134 insertions(+), 134 deletions(-) diff --git a/bundled/muparser_v2_3_3/include/muParserBytecode.h b/bundled/muparser_v2_3_3/include/muParserBytecode.h index cf16e20687..85b23473e4 100644 --- a/bundled/muparser_v2_3_3/include/muParserBytecode.h +++ b/bundled/muparser_v2_3_3/include/muParserBytecode.h @@ -73,7 +73,7 @@ namespace mu value_type* ptr; int offset; } Oprt; - }; + } u; }; diff --git a/bundled/muparser_v2_3_3/src/muParserBase.cpp b/bundled/muparser_v2_3_3/src/muParserBase.cpp index a28a7fc176..e71d5e6663 100644 --- a/bundled/muparser_v2_3_3/src/muParserBase.cpp +++ b/bundled/muparser_v2_3_3/src/muParserBase.cpp @@ -1044,33 +1044,33 @@ namespace mu 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); @@ -1113,73 +1113,73 @@ namespace mu --sidx; stack[sidx] = MathImpl::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) @@ -1197,7 +1197,7 @@ namespace mu Error(ecINTERNAL_ERROR, -1); // - stack[sidx] = pTok->Fun.cb.call_multfun(&stack[sidx], -iArgCount); + stack[sidx] = pTok->u.Fun.cb.call_multfun(&stack[sidx], -iArgCount); continue; } } @@ -1205,21 +1205,21 @@ namespace mu // 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; @@ -1227,22 +1227,22 @@ namespace mu 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("")); } diff --git a/bundled/muparser_v2_3_3/src/muParserBytecode.cpp b/bundled/muparser_v2_3_3/src/muParserBytecode.cpp index 54427b9486..15007b66c9 100644 --- a/bundled/muparser_v2_3_3/src/muParserBytecode.cpp +++ b/bundled/muparser_v2_3_3/src/muParserBytecode.cpp @@ -113,9 +113,9 @@ namespace mu // 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); } @@ -140,9 +140,9 @@ namespace mu // 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); } @@ -150,8 +150,8 @@ namespace mu 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) { @@ -216,20 +216,20 @@ namespace mu // 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; @@ -247,20 +247,20 @@ namespace mu (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; } @@ -271,9 +271,9 @@ namespace mu (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; } @@ -283,23 +283,23 @@ namespace mu { // 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; @@ -309,11 +309,11 @@ namespace mu 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; } @@ -361,7 +361,7 @@ namespace mu SToken tok; tok.Cmd = cmASSIGN; - tok.Oprt.ptr = a_pVar; + tok.u.Oprt.ptr = a_pVar; m_vRPN.push_back(tok); } @@ -400,16 +400,16 @@ namespace mu 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); @@ -420,17 +420,17 @@ namespace mu 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); } @@ -452,8 +452,8 @@ namespace mu 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); } @@ -471,9 +471,9 @@ namespace mu 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); @@ -506,13 +506,13 @@ namespace mu 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: @@ -560,44 +560,44 @@ namespace mu 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(m_vRPN[i].Fun.cb._pRawFun) << _T("]"); - mu::console() << _T("[USERDATA: 0x") << std::hex << reinterpret_cast(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(m_vRPN[i].u.Fun.cb._pRawFun) << _T("]"); + mu::console() << _T("[USERDATA: 0x") << std::hex << reinterpret_cast(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(m_vRPN[i].Fun.cb._pRawFun) << _T("]"); - mu::console() << _T("[USERDATA: 0x") << std::hex << reinterpret_cast(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(m_vRPN[i].u.Fun.cb._pRawFun) << _T("]"); + mu::console() << _T("[USERDATA: 0x") << std::hex << reinterpret_cast(m_vRPN[i].u.Fun.cb._pUserData) << _T("]"); mu::console() << _T("\n"); break; @@ -616,18 +616,18 @@ namespace mu 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"); -- 2.39.5