From 97b67170277437131adf6ed4d60139c172529e4f Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 26 Mar 2019 11:13:37 +1100 Subject: (nw) Clean up the mess on master MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This effectively reverts b380514764cf857469bae61c11143a19f79a74c5 and c24473ddff715ecec2e258a6eb38960cf8c8e98e, restoring the state at 598cd5227223c3b04ca31f0dbc1981256d9ea3ff. Before pushing, please check that what you're about to push is sane. Check your local commit log and ensure there isn't anything out-of-place before pushing to mainline. When things like this happen, it wastes everyone's time. I really don't need this in a week when real work™ is busting my balls and I'm behind where I want to be with preparing for MAME release. --- src/lib/netlist/plib/pfunction.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/lib/netlist/plib/pfunction.cpp') diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp index 79f09cb4a46..6a2179e0e6f 100644 --- a/src/lib/netlist/plib/pfunction.cpp +++ b/src/lib/netlist/plib/pfunction.cpp @@ -6,9 +6,9 @@ */ #include "pfunction.h" +#include "pexception.h" #include "pfmtlog.h" #include "putil.h" -#include "pexception.h" #include #include @@ -17,7 +17,7 @@ namespace plib { void pfunction::compile(const std::vector &inputs, const pstring &expr) { - if (expr.startsWith("rpn:")) + if (plib::startsWith(expr, "rpn:")) compile_postfix(inputs, expr.substr(4)); else compile_infix(inputs, expr); @@ -56,7 +56,7 @@ void pfunction::compile_postfix(const std::vector &inputs, { rc.m_cmd = RAND; stk += 1; } else { - for (unsigned i = 0; i < inputs.size(); i++) + for (std::size_t i = 0; i < inputs.size(); i++) { if (inputs[i] == cmd) { @@ -68,9 +68,9 @@ void pfunction::compile_postfix(const std::vector &inputs, } if (rc.m_cmd != PUSH_INPUT) { - bool err = false; rc.m_cmd = PUSH_CONST; - rc.m_param = cmd.as_double(&err); + bool err; + rc.m_param = plib::pstonum_ne(cmd, err); if (err) throw plib::pexception(plib::pfmt("nld_function: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr)); stk += 1; @@ -84,11 +84,11 @@ void pfunction::compile_postfix(const std::vector &inputs, throw plib::pexception(plib::pfmt("nld_function: stack count different to one on <{2}>")(expr)); } -static int get_prio(pstring v) +static int get_prio(const pstring &v) { if (v == "(" || v == ")") return 1; - else if (v.left(1) >= "a" && v.left(1) <= "z") + else if (plib::left(v, 1) >= "a" && plib::left(v, 1) <= "z") return 0; else if (v == "*" || v == "/") return 20; @@ -113,12 +113,11 @@ void pfunction::compile_infix(const std::vector &inputs, const pstring { // Shunting-yard infix parsing std::vector sep = {"(", ")", ",", "*", "/", "+", "-", "^"}; - std::vector sexpr(plib::psplit(expr.replace_all(" ",""), sep)); + std::vector sexpr(plib::psplit(plib::replace_all(expr, pstring(" "), pstring("")), sep)); std::stack opstk; std::vector postfix; - //printf("dbg: %s\n", expr.c_str()); - for (unsigned i = 0; i < sexpr.size(); i++) + for (std::size_t i = 0; i < sexpr.size(); i++) { pstring &s = sexpr[i]; if (s=="(") @@ -182,14 +181,15 @@ void pfunction::compile_infix(const std::vector &inputs, const pstring #define OP(OP, ADJ, EXPR) \ case OP: \ - ptr-=ADJ; \ - stack[ptr-1] = EXPR; \ + ptr-= (ADJ); \ + stack[ptr-1] = (EXPR); \ break; double pfunction::evaluate(const std::vector &values) { - double stack[20]; + std::array stack = { 0 }; unsigned ptr = 0; + stack[0] = 0.0; for (auto &rc : m_precompiled) { switch (rc.m_cmd) @@ -199,8 +199,8 @@ double pfunction::evaluate(const std::vector &values) OP(SUB, 1, ST2 - ST1) OP(DIV, 1, ST2 / ST1) OP(POW, 1, std::pow(ST2, ST1)) - OP(SIN, 0, std::sin(ST2)); - OP(COS, 0, std::cos(ST2)); + OP(SIN, 0, std::sin(ST2)) + OP(COS, 0, std::cos(ST2)) case RAND: stack[ptr++] = lfsr_random(); break; @@ -215,4 +215,4 @@ double pfunction::evaluate(const std::vector &values) return stack[ptr-1]; } -} +} // namespace plib -- cgit v1.2.3-70-g09d2