--- linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp 2014/06/11 13:24:32 2619 +++ linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp 2016/07/14 00:22:26 2945 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Christian Schoenebeck + * Copyright (c) 2014-2015 Christian Schoenebeck * * http://www.linuxsampler.org * @@ -17,6 +17,9 @@ namespace LinuxSampler { +/////////////////////////////////////////////////////////////////////////// +// class VMEmptyResultFunction + VMFnResult* VMEmptyResultFunction::errorResult() { result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); return &result; @@ -27,6 +30,9 @@ return &result; } +/////////////////////////////////////////////////////////////////////////// +// class VMIntResultFunction + VMFnResult* VMIntResultFunction::errorResult(int i) { result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); result.value = i; @@ -39,6 +45,9 @@ return &result; } +/////////////////////////////////////////////////////////////////////////// +// class VMStringResultFunction + VMFnResult* VMStringResultFunction::errorResult(const String& s) { result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); result.value = s; @@ -51,6 +60,9 @@ return &result; } +/////////////////////////////////////////////////////////////////////////// +// built-in script function: message() + bool CoreVMFunction_message::acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR || type == STRING_EXPR; } @@ -73,11 +85,17 @@ return errorResult(); } +/////////////////////////////////////////////////////////////////////////// +// built-in script function: exit() + VMFnResult* CoreVMFunction_exit::exec(VMFnArgs* args) { this->result.flags = STMT_ABORT_SIGNALLED; return &result; } +/////////////////////////////////////////////////////////////////////////// +// built-in script function: wait() + VMFnResult* CoreVMFunction_wait::exec(VMFnArgs* args) { ExecContext* ctx = dynamic_cast(vm->currentVMExecContext()); VMIntExpr* expr = dynamic_cast(args->arg(0)); @@ -86,6 +104,9 @@ return &result; } +/////////////////////////////////////////////////////////////////////////// +// built-in script function: abs() + bool CoreVMFunction_abs::acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } @@ -94,6 +115,9 @@ return successResult( ::abs(args->arg(0)->asInt()->evalInt()) ); } +/////////////////////////////////////////////////////////////////////////// +// built-in script function: random() + bool CoreVMFunction_random::acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } @@ -101,12 +125,15 @@ 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); + float f = float(::rand()) / float(RAND_MAX); return successResult( iMin + roundf( f * float(iMax - iMin) ) ); } +/////////////////////////////////////////////////////////////////////////// +// built-in script function: num_elements() + bool CoreVMFunction_num_elements::acceptsArgType(int iArg, ExprType_t type) const { return type == INT_ARR_EXPR; } @@ -115,4 +142,32 @@ return successResult( args->arg(0)->asIntArray()->arraySize() ); } +/////////////////////////////////////////////////////////////////////////// +// built-in script function: inc() + +VMFnResult* CoreVMFunction_inc::exec(VMFnArgs* args) { + VMExpr* arg = args->arg(0); + VMIntExpr* in = dynamic_cast(arg); + VMVariable* out = dynamic_cast(arg); + if (!in || !out) successResult(0); + int i = in->evalInt() + 1; + IntLiteral tmp(i); + out->assignExpr(&tmp); + return successResult(i); +} + +/////////////////////////////////////////////////////////////////////////// +// built-in script function: dec() + +VMFnResult* CoreVMFunction_dec::exec(VMFnArgs* args) { + VMExpr* arg = args->arg(0); + VMIntExpr* in = dynamic_cast(arg); + VMVariable* out = dynamic_cast(arg); + if (!in || !out) successResult(0); + int i = in->evalInt() - 1; + IntLiteral tmp(i); + out->assignExpr(&tmp); + return successResult(i); +} + } // namespace LinuxSampler