175 |
printf("StringLiteral: '%s'\n", value.c_str()); |
printf("StringLiteral: '%s'\n", value.c_str()); |
176 |
} |
} |
177 |
|
|
178 |
Add::Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : |
Add::Add(NumberExprRef lhs, NumberExprRef rhs) : |
179 |
VaritypeScalarBinaryOp(lhs, rhs), |
VaritypeScalarBinaryOp(lhs, rhs), |
180 |
Unit( |
Unit( |
181 |
// lhs and rhs are forced to be same unit type at parse time, so either one is fine here |
// lhs and rhs are forced to be same unit type at parse time, so either one is fine here |
215 |
} |
} |
216 |
|
|
217 |
vmfloat Add::unitFactor() const { |
vmfloat Add::unitFactor() const { |
218 |
const ScalarNumberExpr* pLHS = dynamic_cast<const ScalarNumberExpr*>(&*lhs); |
const NumberExpr* pLHS = dynamic_cast<const NumberExpr*>(&*lhs); |
219 |
const ScalarNumberExpr* pRHS = dynamic_cast<const ScalarNumberExpr*>(&*rhs); |
const NumberExpr* pRHS = dynamic_cast<const NumberExpr*>(&*rhs); |
220 |
return (pLHS->unitFactor() < pRHS->unitFactor()) ? pLHS->unitFactor() : pRHS->unitFactor(); |
return (pLHS->unitFactor() < pRHS->unitFactor()) ? pLHS->unitFactor() : pRHS->unitFactor(); |
221 |
} |
} |
222 |
|
|
231 |
printf(")\n"); |
printf(")\n"); |
232 |
} |
} |
233 |
|
|
234 |
Sub::Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : |
Sub::Sub(NumberExprRef lhs, NumberExprRef rhs) : |
235 |
VaritypeScalarBinaryOp(lhs, rhs), |
VaritypeScalarBinaryOp(lhs, rhs), |
236 |
Unit( |
Unit( |
237 |
// lhs and rhs are forced to be same unit type at parse time, so either one is fine here |
// lhs and rhs are forced to be same unit type at parse time, so either one is fine here |
271 |
} |
} |
272 |
|
|
273 |
vmfloat Sub::unitFactor() const { |
vmfloat Sub::unitFactor() const { |
274 |
const ScalarNumberExpr* pLHS = dynamic_cast<const ScalarNumberExpr*>(&*lhs); |
const NumberExpr* pLHS = dynamic_cast<const NumberExpr*>(&*lhs); |
275 |
const ScalarNumberExpr* pRHS = dynamic_cast<const ScalarNumberExpr*>(&*rhs); |
const NumberExpr* pRHS = dynamic_cast<const NumberExpr*>(&*rhs); |
276 |
return (pLHS->unitFactor() < pRHS->unitFactor()) ? pLHS->unitFactor() : pRHS->unitFactor(); |
return (pLHS->unitFactor() < pRHS->unitFactor()) ? pLHS->unitFactor() : pRHS->unitFactor(); |
277 |
} |
} |
278 |
|
|
287 |
printf(")\n"); |
printf(")\n"); |
288 |
} |
} |
289 |
|
|
290 |
Mul::Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : |
Mul::Mul(NumberExprRef lhs, NumberExprRef rhs) : |
291 |
VaritypeScalarBinaryOp(lhs, rhs), |
VaritypeScalarBinaryOp(lhs, rhs), |
292 |
Unit( |
Unit( |
293 |
// currently the NKSP parser only allows a unit type on either side on multiplications |
// currently the NKSP parser only allows a unit type on either side on multiplications |
320 |
} |
} |
321 |
|
|
322 |
vmfloat Mul::unitFactor() const { |
vmfloat Mul::unitFactor() const { |
323 |
const ScalarNumberExpr* pLHS = dynamic_cast<const ScalarNumberExpr*>(&*lhs); |
const NumberExpr* pLHS = dynamic_cast<const NumberExpr*>(&*lhs); |
324 |
const ScalarNumberExpr* pRHS = dynamic_cast<const ScalarNumberExpr*>(&*rhs); |
const NumberExpr* pRHS = dynamic_cast<const NumberExpr*>(&*rhs); |
325 |
return pLHS->unitFactor() * pRHS->unitFactor(); |
return pLHS->unitFactor() * pRHS->unitFactor(); |
326 |
} |
} |
327 |
|
|
328 |
Div::Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : |
Div::Div(NumberExprRef lhs, NumberExprRef rhs) : |
329 |
VaritypeScalarBinaryOp(lhs, rhs), |
VaritypeScalarBinaryOp(lhs, rhs), |
330 |
Unit( |
Unit( |
331 |
// the NKSP parser only allows either A) a unit type on left side and none |
// the NKSP parser only allows either A) a unit type on left side and none |
367 |
} |
} |
368 |
|
|
369 |
vmfloat Div::unitFactor() const { |
vmfloat Div::unitFactor() const { |
370 |
const ScalarNumberExpr* pLHS = dynamic_cast<const ScalarNumberExpr*>(&*lhs); |
const NumberExpr* pLHS = dynamic_cast<const NumberExpr*>(&*lhs); |
371 |
const ScalarNumberExpr* pRHS = dynamic_cast<const ScalarNumberExpr*>(&*rhs); |
const NumberExpr* pRHS = dynamic_cast<const NumberExpr*>(&*rhs); |
372 |
return pLHS->unitFactor() / pRHS->unitFactor(); |
return pLHS->unitFactor() / pRHS->unitFactor(); |
373 |
} |
} |
374 |
|
|
560 |
if (!fn || !result) return VM_NO_FACTOR; |
if (!fn || !result) return VM_NO_FACTOR; |
561 |
VMExpr* expr = result->resultValue(); |
VMExpr* expr = result->resultValue(); |
562 |
if (!expr) return VM_NO_FACTOR; |
if (!expr) return VM_NO_FACTOR; |
563 |
VMScalarNumberExpr* scalar = expr->asScalarNumberExpr(); |
VMNumberExpr* scalar = expr->asNumber(); |
564 |
if (!scalar) return VM_NO_FACTOR; |
if (!scalar) return VM_NO_FACTOR; |
565 |
return scalar->unitFactor(); |
return scalar->unitFactor(); |
566 |
} |
} |
642 |
{ |
{ |
643 |
} |
} |
644 |
|
|
645 |
ScalarNumberVariable::ScalarNumberVariable(const VariableDecl& decl) : |
NumberVariable::NumberVariable(const VariableDecl& decl) : |
646 |
Variable(decl), |
Variable(decl), |
647 |
Unit(decl.unitType), |
Unit(decl.unitType), |
648 |
unitFactorMemPos(decl.unitFactorMemPos), polyphonic(decl.isPolyphonic), |
unitFactorMemPos(decl.unitFactorMemPos), polyphonic(decl.isPolyphonic), |
650 |
{ |
{ |
651 |
} |
} |
652 |
|
|
653 |
vmfloat ScalarNumberVariable::unitFactor() const { |
vmfloat NumberVariable::unitFactor() const { |
654 |
if (isPolyphonic()) { |
if (isPolyphonic()) { |
655 |
return context->execContext->polyphonicUnitFactorMemory[unitFactorMemPos]; |
return context->execContext->polyphonicUnitFactorMemory[unitFactorMemPos]; |
656 |
} |
} |
664 |
} |
} |
665 |
|
|
666 |
IntVariable::IntVariable(const VariableDecl& decl) : |
IntVariable::IntVariable(const VariableDecl& decl) : |
667 |
ScalarNumberVariable({ |
NumberVariable({ |
668 |
.ctx = decl.ctx, |
.ctx = decl.ctx, |
669 |
.isPolyphonic = decl.isPolyphonic, |
.isPolyphonic = decl.isPolyphonic, |
670 |
.isConst = decl.isConst, |
.isConst = decl.isConst, |
720 |
} |
} |
721 |
|
|
722 |
RealVariable::RealVariable(const VariableDecl& decl) : |
RealVariable::RealVariable(const VariableDecl& decl) : |
723 |
ScalarNumberVariable({ |
NumberVariable({ |
724 |
.ctx = decl.ctx, |
.ctx = decl.ctx, |
725 |
.isPolyphonic = decl.isPolyphonic, |
.isPolyphonic = decl.isPolyphonic, |
726 |
.isConst = decl.isConst, |
.isConst = decl.isConst, |
1271 |
printf("ConstStringVariable val='%s'\n", value.c_str()); |
printf("ConstStringVariable val='%s'\n", value.c_str()); |
1272 |
} |
} |
1273 |
|
|
1274 |
bool ScalarNumberBinaryOp::isFinal() const { |
bool NumberBinaryOp::isFinal() const { |
1275 |
ScalarNumberExprRef l = (ScalarNumberExprRef) lhs; |
NumberExprRef l = (NumberExprRef) lhs; |
1276 |
ScalarNumberExprRef r = (ScalarNumberExprRef) rhs; |
NumberExprRef r = (NumberExprRef) rhs; |
1277 |
return l->isFinal() || r->isFinal(); |
return l->isFinal() || r->isFinal(); |
1278 |
} |
} |
1279 |
|
|