20.10.2013 - Modified PIObject - virtual debugName() for macro piCoutObj, improved timer measurements and timers on Windows
This commit is contained in:
@@ -56,6 +56,11 @@ PIEvaluatorContent::PIEvaluatorContent() {
|
||||
addFunction("y0", 1);
|
||||
addFunction("y1", 1);
|
||||
addFunction("yn", 2);
|
||||
addFunction("min", -2); // (x0,x1,...)
|
||||
addFunction("max", -2); // (x0,x1,...)
|
||||
addFunction("clamp", 3); // (x,a,b) = x < a ? a : (x > b ? b : x)
|
||||
addFunction("step", 2); // (x,s) = x >= s ? 1. : 0. (1 if 'x' >= 's', else 0)
|
||||
addFunction("mix", 3); // (x,a,b) = a*(1.-x) + b*x (interpolate between 'a' and 'b' linear for 'x')
|
||||
clearCustomVariables();
|
||||
//addVariable("n", 0.);
|
||||
//addVariable("x1", 123);
|
||||
@@ -138,6 +143,11 @@ PIEvaluatorTypes::BaseFunctions PIEvaluatorContent::getBaseFunction(const PIStri
|
||||
if (name == "y0") return PIEvaluatorTypes::bfY0;
|
||||
if (name == "y1") return PIEvaluatorTypes::bfY1;
|
||||
if (name == "yn") return PIEvaluatorTypes::bfYN;
|
||||
if (name == "min") return PIEvaluatorTypes::bfMin;
|
||||
if (name == "max") return PIEvaluatorTypes::bfMax;
|
||||
if (name == "clamp") return PIEvaluatorTypes::bfClamp;
|
||||
if (name == "step") return PIEvaluatorTypes::bfStep;
|
||||
if (name == "mix") return PIEvaluatorTypes::bfMix;
|
||||
return PIEvaluatorTypes::bfUnknown;
|
||||
}
|
||||
|
||||
@@ -788,18 +798,43 @@ bool PIEvaluator::check() {
|
||||
for (int i = 0; i < instructions.size_s(); i++) {
|
||||
error = false;
|
||||
ci = instructions[i];
|
||||
PIEvaluatorTypes::Function cf;
|
||||
int fac, gac;
|
||||
switch (ci.operation) {
|
||||
case PIEvaluatorTypes::oNone: break;
|
||||
case PIEvaluatorTypes::oFunction:
|
||||
cf = content.function(ci.function);
|
||||
fac = cf.arguments;
|
||||
gac = ci.operators.size_s();
|
||||
for (int j = 0; j < ci.operators.size_s(); j++) {
|
||||
if (ci.operators[j] == -666) { //(ci.operators[j] < -variables.size_s() || ci.operators[j] >= kvars->size()) {
|
||||
error = true;
|
||||
break;
|
||||
gac--;
|
||||
}
|
||||
}
|
||||
if (ci.operators.size_s() != content.function(ci.function).arguments || error) {
|
||||
lastError = "Invalid arguments count for function \"" + content.function(ci.function).identifier + "\"";
|
||||
return false;
|
||||
if (fac > 0) {
|
||||
if (gac != fac) {
|
||||
lastError = "Invalid arguments count for function \"" + cf.identifier +
|
||||
"\", expected " + PIString::fromNumber(fac) + " but " +
|
||||
PIString::fromNumber(gac) + " given";
|
||||
return false;
|
||||
}
|
||||
if (error) {
|
||||
lastError = "Invalid at least one of function \"" + cf.identifier + "\" argument";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (fac < 0) {
|
||||
if (gac < -fac) {
|
||||
lastError = "Invalid arguments count for function \"" + cf.identifier +
|
||||
"\", expected at least " + PIString::fromNumber(-fac) + " but " +
|
||||
PIString::fromNumber(gac) + " given";
|
||||
return false;
|
||||
}
|
||||
if (error) {
|
||||
lastError = "Invalid at least one of function \"" + cf.identifier + "\" argument";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -872,7 +907,7 @@ inline complexd PIEvaluator::residue(const complexd & f, const complexd & s) {
|
||||
inline void PIEvaluator::execFunction(const PIEvaluatorTypes::Instruction & ci) {
|
||||
PIEvaluatorTypes::Function cfunc = content.function(ci.function);
|
||||
int oi = -ci.out - 1;
|
||||
complexd tmp, stmp;
|
||||
complexd tmp, stmp, ttmp;
|
||||
ldouble ldtmp;
|
||||
//qDebug() << "function " << (int)cfunc.type;
|
||||
switch (cfunc.type) {
|
||||
@@ -987,6 +1022,37 @@ inline void PIEvaluator::execFunction(const PIEvaluatorTypes::Instruction & ci)
|
||||
case PIEvaluatorTypes::bfYN:
|
||||
tmpvars[oi].value = piYn(piRoundd(value(ci.operators[1]).real()), value(ci.operators[0]).real());
|
||||
break;
|
||||
case PIEvaluatorTypes::bfMin:
|
||||
tmp = value(ci.operators[0]);
|
||||
for (int i = 1; i < ci.operators.size_s(); ++i) {
|
||||
stmp = value(ci.operators[i]);
|
||||
tmp = complexd(piMind(tmp.real(), stmp.real()), piMind(tmp.imag(), stmp.imag()));
|
||||
}
|
||||
tmpvars[oi].value = tmp;
|
||||
break;
|
||||
case PIEvaluatorTypes::bfMax:
|
||||
tmp = value(ci.operators[0]);
|
||||
for (int i = 1; i < ci.operators.size_s(); ++i) {
|
||||
stmp = value(ci.operators[i]);
|
||||
tmp = complexd(piMaxd(tmp.real(), stmp.real()), piMaxd(tmp.imag(), stmp.imag()));
|
||||
}
|
||||
tmpvars[oi].value = tmp;
|
||||
break;
|
||||
case PIEvaluatorTypes::bfClamp:
|
||||
tmp = value(ci.operators[0]);
|
||||
stmp = value(ci.operators[1]);
|
||||
ttmp = value(ci.operators[2]);
|
||||
tmpvars[oi].value = complexd(piClampd(tmp.real(), stmp.real(), ttmp.real()), piClampd(tmp.imag(), stmp.imag(), ttmp.imag()));
|
||||
break;
|
||||
case PIEvaluatorTypes::bfStep:
|
||||
tmpvars[oi].value = value(ci.operators[0]).real() >= value(ci.operators[1]).real() ? complexld_1 : complexld_0;
|
||||
break;
|
||||
case PIEvaluatorTypes::bfMix:
|
||||
tmp = value(ci.operators[0]);
|
||||
stmp = value(ci.operators[1]);
|
||||
ttmp = value(ci.operators[2]);
|
||||
tmpvars[oi].value = stmp.real() * (1. - tmp.real()) + ttmp.real() * tmp.real();
|
||||
break;
|
||||
case PIEvaluatorTypes::bfRandom:
|
||||
tmp = static_cast<ldouble>(rand()) / RAND_MAX;
|
||||
stmp = value(ci.operators[1]) - value(ci.operators[0]);
|
||||
@@ -1068,8 +1134,11 @@ inline bool PIEvaluator::execInstructions() {
|
||||
|
||||
bool PIEvaluator::check(const PIString & string) {
|
||||
currentString = preprocess(string);
|
||||
if (!check())
|
||||
correct = check();
|
||||
if (!correct) {
|
||||
instructions.clear();
|
||||
return false;
|
||||
}
|
||||
lastError = "Correct";
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user