13 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
14 |
#include "../common/RTMath.h" |
#include "../common/RTMath.h" |
15 |
#include <assert.h> |
#include <assert.h> |
16 |
|
#include "CoreVMFunctions.h" // for VMIntResult, VMRealResult |
17 |
|
|
18 |
namespace LinuxSampler { |
namespace LinuxSampler { |
19 |
|
|
123 |
} |
} |
124 |
} |
} |
125 |
|
|
126 |
static String _unitToStr(Unit* unit) { |
static String _unitToStr(VMUnit* unit) { |
127 |
const StdUnit_t type = unit->unitType(); |
const StdUnit_t type = unit->unitType(); |
128 |
String sType; |
String sType; |
129 |
switch (type) { |
switch (type) { |
613 |
if (!fn) return NULL; |
if (!fn) return NULL; |
614 |
// assuming here that all argument checks (amount and types) have been made |
// assuming here that all argument checks (amount and types) have been made |
615 |
// at parse time, to avoid time intensive checks on each function call |
// at parse time, to avoid time intensive checks on each function call |
616 |
return fn->exec(dynamic_cast<VMFnArgs*>(&*args)); |
VMFnResult* res = fn->exec(dynamic_cast<VMFnArgs*>(&*args)); |
617 |
|
if (!res) return res; |
618 |
|
|
619 |
|
VMExpr* expr = res->resultValue(); |
620 |
|
if (!expr) return res; |
621 |
|
|
622 |
|
// For performance reasons we always only let 'FunctionCall' assign the unit |
623 |
|
// type to the function's result expression, never by the function |
624 |
|
// implementation itself, nor by other classes, because a FunctionCall |
625 |
|
// object solely knows the unit type in O(1). |
626 |
|
ExprType_t type = expr->exprType(); |
627 |
|
if (type == INT_EXPR) { |
628 |
|
VMIntResult* intRes = dynamic_cast<VMIntResult*>(res); |
629 |
|
intRes->unitBaseType = unitType(); |
630 |
|
} else if (type == REAL_EXPR) { |
631 |
|
VMRealResult* realRes = dynamic_cast<VMRealResult*>(res); |
632 |
|
realRes->unitBaseType = unitType(); |
633 |
|
} |
634 |
|
|
635 |
|
return res; |
636 |
} |
} |
637 |
|
|
638 |
StmtFlags_t FunctionCall::exec() { |
StmtFlags_t FunctionCall::exec() { |
705 |
return strExpr ? strExpr->evalStr() : ""; |
return strExpr ? strExpr->evalStr() : ""; |
706 |
} else if (resultType == REAL_EXPR) { |
} else if (resultType == REAL_EXPR) { |
707 |
VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue()); |
VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue()); |
708 |
return realExpr ? ToString(realExpr->evalReal()) : ""; |
return realExpr ? ToString(realExpr->evalReal()) + _unitToStr(realExpr) : ""; |
709 |
} else { |
} else { |
710 |
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue()); |
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue()); |
711 |
return intExpr ? ToString(intExpr->evalInt()) : ""; |
return intExpr ? ToString(intExpr->evalInt()) + _unitToStr(intExpr) : ""; |
712 |
} |
} |
713 |
} |
} |
714 |
|
|