--- linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp 2014/06/05 19:39:12 2596 +++ linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp 2014/06/11 13:24:32 2619 @@ -10,6 +10,8 @@ #include "CoreVMFunctions.h" #include +#include +#include #include "tree.h" #include "ScriptVM.h" @@ -20,16 +22,20 @@ return &result; } -void VMEmptyResultFunction::wrnMsg(const String& txt) { - std::cout << "[ScriptVM] " << txt << std::endl; +VMFnResult* VMEmptyResultFunction::successResult() { + result.flags = STMT_SUCCESS; + return &result; } -void VMEmptyResultFunction::errMsg(const String& txt) { - std::cerr << "[ScriptVM] " << txt << std::endl; +VMFnResult* VMIntResultFunction::errorResult(int i) { + result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); + result.value = i; + return &result; } -VMFnResult* VMEmptyResultFunction::successResult() { +VMFnResult* VMIntResultFunction::successResult(int i) { result.flags = STMT_SUCCESS; + result.value = i; return &result; } @@ -80,4 +86,33 @@ return &result; } +bool CoreVMFunction_abs::acceptsArgType(int iArg, ExprType_t type) const { + return type == INT_EXPR; +} + +VMFnResult* CoreVMFunction_abs::exec(VMFnArgs* args) { + return successResult( ::abs(args->arg(0)->asInt()->evalInt()) ); +} + +bool CoreVMFunction_random::acceptsArgType(int iArg, ExprType_t type) const { + return type == INT_EXPR; +} + +VMFnResult* CoreVMFunction_random::exec(VMFnArgs* args) { + int iMin = args->arg(0)->asInt()->evalInt(); + int iMax = args->arg(1)->asInt()->evalInt(); + float f = float(::random()) / float(RAND_MAX); + return successResult( + iMin + roundf( f * float(iMax - iMin) ) + ); +} + +bool CoreVMFunction_num_elements::acceptsArgType(int iArg, ExprType_t type) const { + return type == INT_ARR_EXPR; +} + +VMFnResult* CoreVMFunction_num_elements::exec(VMFnArgs* args) { + return successResult( args->arg(0)->asIntArray()->arraySize() ); +} + } // namespace LinuxSampler