From 13f6e92cec9bba6a96464e382f97d14e28628290 Mon Sep 17 00:00:00 2001 From: couriersud Date: Fri, 1 May 2020 10:04:22 +0200 Subject: netlist: Add the NE566 as a macro device. [Couriersud] The device can be found in nlm_other.cpp. Removed nld_ne566.* Added SYS_SW, SYS_SW2 and SYS_COMP. These are single switch, alternating switch and a analog comparator with digital outputs. Renamed RES_SWITCH to SYS_SW. Added example ne566.cpp in netlist/examples. --- src/lib/netlist/plib/pfunction.cpp | 45 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 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 292bd9bb9c6..b5c1a46dda2 100644 --- a/src/lib/netlist/plib/pfunction.cpp +++ b/src/lib/netlist/plib/pfunction.cpp @@ -11,11 +11,44 @@ #include #include +#include +#include namespace plib { static constexpr const std::size_t MAX_STACK = 32; + // FIXME: Exa parsing conflicts with e,E parsing + template + static const std::map &units_si() + { + static std::map units_si_stat = + { + //{ "Y", static_cast(1e24) }, // NOLINT: Yotta + //{ "Z", static_cast(1e21) }, // NOLINT: Zetta + //{ "E", static_cast(1e18) }, // NOLINT: Exa + { "P", static_cast(1e15) }, // NOLINT: Peta + { "T", static_cast(1e12) }, // NOLINT: Tera + { "G", static_cast( 1e9) }, // NOLINT: Giga + { "M", static_cast( 1e6) }, // NOLINT: Mega + { "k", static_cast( 1e3) }, // NOLINT: Kilo + { "h", static_cast( 1e2) }, // NOLINT: Hekto + //{ "da", static_cast(1e1) }, // NOLINT: Deka + { "d", static_cast(1e-1) }, // NOLINT: Dezi + { "c", static_cast(1e-2) }, // NOLINT: Zenti + { "m", static_cast(1e-3) }, // NOLINT: Milli + { "μ", static_cast(1e-6) }, // NOLINT: Mikro + { "n", static_cast(1e-9) }, // NOLINT: Nano + { "p", static_cast(1e-12) }, // NOLINT: Piko + { "f", static_cast(1e-15) }, // NOLINT: Femto + { "a", static_cast(1e-18) }, // NOLINT: Atto + { "z", static_cast(1e-21) }, // NOLINT: Zepto + { "y", static_cast(1e-24) }, // NOLINT: Yokto + }; + return units_si_stat; + } + + template void pfunction::compile(const pstring &expr, const inputs_container &inputs) noexcept(false) { @@ -78,9 +111,15 @@ namespace plib { } if (rc.m_cmd != PUSH_INPUT) { + using fl_t = decltype(rc.m_param); rc.m_cmd = PUSH_CONST; bool err(false); - rc.m_param = plib::pstonum_ne(cmd, err); + auto rs(plib::right(cmd,1)); + auto r=units_si().find(rs); + if (r == units_si().end()) + rc.m_param = plib::pstonum_ne(cmd, err); + else + rc.m_param = plib::pstonum_ne(plib::left(cmd, cmd.size()-1), err) * r->second; if (err) throw pexception(plib::pfmt("pfunction: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr)); stk += 1; @@ -166,7 +205,9 @@ namespace plib { auto l(plib::left(sexpr1[i], 1)); auto r(plib::right(sexpr1[i], 1)); auto ne(sexpr1[i+1]); - if ((l >= "0") && (l <= "9") && (r == "e" || r == "E") && (ne == "-" || ne == "+")) + if ((l >= "0") && (l <= "9") + && (r == "e" || r == "E") + && (ne == "-" || ne == "+")) { sexpr.push_back(sexpr1[i] + ne + sexpr1[i+2]); i+=3; -- cgit v1.2.3-70-g09d2