git-svn-id: svn://db.shs.com.ru/pip@649 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2018-10-17 12:55:40 +00:00
parent 74a0743045
commit b8db3b5010
5 changed files with 19 additions and 11 deletions

View File

@@ -42,6 +42,8 @@ public:
}; };
int main() { int main() {
PIEvaluator eval, eval2; PIEvaluator eval, eval2;
//eval.check("1-1+1");
//piCout << eval.evaluate().real();
eval.setVariable("t", complexd(1, 2)); eval.setVariable("t", complexd(1, 2));
eval.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))"); eval.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
PIByteArray ba = eval.save(); PIByteArray ba = eval.save();
@@ -59,12 +61,14 @@ int main() {
tm.reset(); tm.reset();
PIEvaluator e2; PIEvaluator e2;
piForTimes(100) { e2.load(ba);
e2.load(ba); piForTimes(10000) {
e2.setVariable("t", complexd(1, 2)); e2.setVariable("t", complexd(1, 2));
complexd ret = e2.evaluate(); complexd ret = e2.evaluate();
} }
us = tm.elapsed_u(); piCout << " save" << us / 100.; us = tm.elapsed_u(); piCout << " save" << us / 10000.;
/*A a; /*A a;
CONNECTU(PICout::Notifier::object(), finished, &a, pcf); CONNECTU(PICout::Notifier::object(), finished, &a, pcf);

View File

@@ -259,8 +259,10 @@ void PIBroadcast::mcastRead(uchar * data, int size) {
void PIBroadcast::run() { void PIBroadcast::run() {
PIVector<PIEthernet::Address> al = PIEthernet::allAddresses(); PIVector<PIEthernet::Address> al = PIEthernet::allAddresses();
mcast_mutex.lock(); mcast_mutex.lock();
bool r = _reinit; bool r = _reinit, ac = (al != prev_al);
mcast_mutex.unlock(); mcast_mutex.unlock();
if (al != prev_al || r) if (ac || r)
reinit(); reinit();
if (ac)
addressesChanged();
} }

View File

@@ -125,6 +125,9 @@ protected:
//! Called when packet received //! Called when packet received
virtual void received(PIByteArray data) {} virtual void received(PIByteArray data) {}
//! Called when addresses are changed
virtual void addressesChanged() {}
private: private:
EVENT_HANDLER2(void, mcastRead, uchar * , data, int, size); EVENT_HANDLER2(void, mcastRead, uchar * , data, int, size);
void destroyAll(); void destroyAll();

View File

@@ -863,7 +863,7 @@ int PIEvaluator::parse(const PIString & string, int offset) {
if (args.size_s() > 0) return args.back(); if (args.size_s() > 0) return args.back();
else return -666; else return -666;
} }
for (int i = 0; i < PIEvaluatorTypes::operationCount; i++) { for (int i = 0; i < PIEvaluatorTypes::oOperatorsCount; i++) {
coper = operationInOrder(i); coper = operationInOrder(i);
for (int j = 0; j < opers.size_s(); j++) { for (int j = 0; j < opers.size_s(); j++) {
if (coper == PIEvaluatorTypes::oDivide || coper == PIEvaluatorTypes::oMultiply) { if (coper == PIEvaluatorTypes::oDivide || coper == PIEvaluatorTypes::oMultiply) {
@@ -1016,7 +1016,7 @@ inline complexd PIEvaluator::residue(const complexd & f, const complexd & s) {
inline void PIEvaluator::execFunction(const PIEvaluatorTypes::Instruction & ci) { inline void PIEvaluator::execFunction(const PIEvaluatorTypes::Instruction & ci) {
PIEvaluatorTypes::Function cfunc = content.function(ci.function); const PIEvaluatorTypes::Function & cfunc(content.function(ci.function));
int oi = -ci.out - 1; int oi = -ci.out - 1;
complexd tmp, stmp, ttmp; complexd tmp, stmp, ttmp;
//qDebug() << "function " << (int)cfunc.type; //qDebug() << "function " << (int)cfunc.type;
@@ -1181,13 +1181,12 @@ inline void PIEvaluator::execFunction(const PIEvaluatorTypes::Instruction & ci)
inline bool PIEvaluator::execInstructions() { inline bool PIEvaluator::execInstructions() {
kvars = &(content.variables); kvars = &(content.variables);
PIEvaluatorTypes::Instruction ci;
int oi; int oi;
complexd tmp; complexd tmp;
tmpvars = variables; tmpvars = variables;
//cout << "var count " << tmpvars.size_s() << endl; //cout << "var count " << tmpvars.size_s() << endl;
for (int i = 0; i < instructions.size_s(); i++) { for (int i = 0; i < instructions.size_s(); i++) {
ci = instructions[i]; const PIEvaluatorTypes::Instruction & ci(instructions[i]);
oi = -ci.out - 1; oi = -ci.out - 1;
//cout << value(ci.operators[0]) << operationChar(ci.operation) << value(ci.operators[1]) << ", " << oi << endl; //cout << value(ci.operators[0]) << operationChar(ci.operation) << value(ci.operators[1]) << ", " << oi << endl;
switch (ci.operation) { switch (ci.operation) {
@@ -1241,6 +1240,7 @@ inline bool PIEvaluator::execInstructions() {
case PIEvaluatorTypes::oNone: case PIEvaluatorTypes::oNone:
tmpvars[oi].value = value(ci.operators[0]); tmpvars[oi].value = value(ci.operators[0]);
break; break;
default: break;
} }
} }
if (!instructions.isEmpty()) if (!instructions.isEmpty())

View File

@@ -29,12 +29,11 @@
typedef complexd (*FuncFunc)(void * , int, complexd * ); typedef complexd (*FuncFunc)(void * , int, complexd * );
namespace PIEvaluatorTypes { namespace PIEvaluatorTypes {
static const int operationCount = 14;
enum PIP_EXPORT eType {etNumber, etOperator, etVariable, etFunction}; enum PIP_EXPORT eType {etNumber, etOperator, etVariable, etFunction};
enum PIP_EXPORT Operation {oNone, oAdd, oSubtract, oMultiply, oDivide, oResidue, oPower, enum PIP_EXPORT Operation {oNone, oAdd, oSubtract, oMultiply, oDivide, oResidue, oPower,
oEqual, oNotEqual, oGreater, oSmaller, oGreaterEqual, oSmallerEqual, oEqual, oNotEqual, oGreater, oSmaller, oGreaterEqual, oSmallerEqual,
oAnd, oOr, oFunction oAnd, oOr, oOperatorsCount, oFunction
}; };
enum PIP_EXPORT BaseFunctions {bfUnknown, bfSin, bfCos, bfTg, bfCtg, enum PIP_EXPORT BaseFunctions {bfUnknown, bfSin, bfCos, bfTg, bfCtg,
bfArcsin, bfArccos, bfArctg, bfArcctg, bfArcsin, bfArccos, bfArctg, bfArcctg,