--- linuxsampler/trunk/src/scriptvm/CoreVMFunctions.h 2015/03/31 17:46:11 2727 +++ linuxsampler/trunk/src/scriptvm/CoreVMFunctions.h 2019/08/23 11:44:00 3561 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2015 Christian Schoenebeck + * Copyright (c) 2014-2019 Christian Schoenebeck * * http://www.linuxsampler.org * @@ -29,9 +29,10 @@ StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call VMEmptyResult() : flags(STMT_SUCCESS) {} - ExprType_t exprType() const { return EMPTY_EXPR; } - VMExpr* resultValue() { return this; } - StmtFlags_t resultFlags() { return flags; } + ExprType_t exprType() const OVERRIDE { return EMPTY_EXPR; } + VMExpr* resultValue() OVERRIDE { return this; } + StmtFlags_t resultFlags() OVERRIDE { return flags; } + bool isConstExpr() const OVERRIDE { return false; } }; /** @@ -41,12 +42,16 @@ class VMIntResult : public VMFnResult, public VMIntExpr { public: StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call - int value; ///< result value of the function call + vmint value; ///< result value of the function call - VMIntResult() : flags(STMT_SUCCESS) {} - int evalInt() { return value; } - VMExpr* resultValue() { return this; } - StmtFlags_t resultFlags() { return flags; } + VMIntResult() : flags(STMT_SUCCESS), value(0) {} + vmint evalInt() OVERRIDE { return value; } + VMExpr* resultValue() OVERRIDE { return this; } + StmtFlags_t resultFlags() OVERRIDE { return flags; } + bool isConstExpr() const OVERRIDE { return false; } + MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } + StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } + bool isFinal() const OVERRIDE { return false; } }; /** @@ -59,9 +64,10 @@ String value; ///< result value of the function call VMStringResult() : flags(STMT_SUCCESS) {} - String evalStr() { return value; } - VMExpr* resultValue() { return this; } - StmtFlags_t resultFlags() { return flags; } + String evalStr() OVERRIDE { return value; } + VMExpr* resultValue() OVERRIDE { return this; } + StmtFlags_t resultFlags() OVERRIDE { return flags; } + bool isConstExpr() const OVERRIDE { return false; } }; /** @@ -70,9 +76,11 @@ */ class VMEmptyResultFunction : public VMFunction { protected: - ExprType_t returnType() { return EMPTY_EXPR; } + virtual ~VMEmptyResultFunction() {} + ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; } VMFnResult* errorResult(); VMFnResult* successResult(); + bool modifiesArg(vmint iArg) const OVERRIDE { return false; } protected: VMEmptyResult result; }; @@ -83,9 +91,11 @@ */ class VMIntResultFunction : public VMFunction { protected: - ExprType_t returnType() { return INT_EXPR; } - VMFnResult* errorResult(int i = 0); - VMFnResult* successResult(int i = 0); + virtual ~VMIntResultFunction() {} + ExprType_t returnType() OVERRIDE { return INT_EXPR; } + VMFnResult* errorResult(vmint i = 0); + VMFnResult* successResult(vmint i = 0); + bool modifiesArg(vmint iArg) const OVERRIDE { return false; } protected: VMIntResult result; }; @@ -96,9 +106,11 @@ */ class VMStringResultFunction : public VMFunction { protected: - ExprType_t returnType() { return STRING_EXPR; } + virtual ~VMStringResultFunction() {} + ExprType_t returnType() OVERRIDE { return STRING_EXPR; } VMFnResult* errorResult(const String& s = ""); VMFnResult* successResult(const String& s = ""); + bool modifiesArg(vmint iArg) const OVERRIDE { return false; } protected: VMStringResult result; }; @@ -112,11 +124,11 @@ */ class CoreVMFunction_message : public VMEmptyResultFunction { public: - int minRequiredArgs() const { return 1; } - int maxAllowedArgs() const { return 1; } - bool acceptsArgType(int iArg, ExprType_t type) const; - ExprType_t argType(int iArg) const { return STRING_EXPR; } - VMFnResult* exec(VMFnArgs* args); + vmint minRequiredArgs() const OVERRIDE { return 1; } + vmint maxAllowedArgs() const OVERRIDE { return 1; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; + ExprType_t argType(vmint iArg) const OVERRIDE { return STRING_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; }; /** @@ -124,11 +136,14 @@ */ class CoreVMFunction_exit : public VMEmptyResultFunction { public: - int minRequiredArgs() const { return 0; } - int maxAllowedArgs() const { return 0; } - bool acceptsArgType(int iArg, ExprType_t type) const { return false; } - ExprType_t argType(int iArg) const { return INT_EXPR; /*whatever*/ } - VMFnResult* exec(VMFnArgs* args); + CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {} + vmint minRequiredArgs() const OVERRIDE { return 0; } + vmint maxAllowedArgs() const OVERRIDE; + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +protected: + ScriptVM* vm; }; /** @@ -137,11 +152,13 @@ class CoreVMFunction_wait : public VMEmptyResultFunction { public: CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {} - int minRequiredArgs() const { return 1; } - int maxAllowedArgs() const { return 1; } - bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } - ExprType_t argType(int iArg) const { return INT_EXPR; } - VMFnResult* exec(VMFnArgs* args); + vmint minRequiredArgs() const OVERRIDE { return 1; } + vmint maxAllowedArgs() const OVERRIDE { return 1; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } + bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE; + bool acceptsArgUnitPrefix(vmint iArg) const OVERRIDE; + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; protected: ScriptVM* vm; }; @@ -151,11 +168,11 @@ */ class CoreVMFunction_abs : public VMIntResultFunction { public: - int minRequiredArgs() const { return 1; } - int maxAllowedArgs() const { return 1; } - bool acceptsArgType(int iArg, ExprType_t type) const; - ExprType_t argType(int iArg) const { return INT_EXPR; } - VMFnResult* exec(VMFnArgs* args); + vmint minRequiredArgs() const OVERRIDE { return 1; } + vmint maxAllowedArgs() const OVERRIDE { return 1; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; }; /** @@ -163,11 +180,11 @@ */ class CoreVMFunction_random : public VMIntResultFunction { public: - int minRequiredArgs() const { return 2; } - int maxAllowedArgs() const { return 2; } - bool acceptsArgType(int iArg, ExprType_t type) const; - ExprType_t argType(int iArg) const { return INT_EXPR; } - VMFnResult* exec(VMFnArgs* args); + vmint minRequiredArgs() const OVERRIDE { return 2; } + vmint maxAllowedArgs() const OVERRIDE { return 2; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; }; /** @@ -175,11 +192,134 @@ */ class CoreVMFunction_num_elements : public VMIntResultFunction { public: - int minRequiredArgs() const { return 1; } - int maxAllowedArgs() const { return 1; } - bool acceptsArgType(int iArg, ExprType_t type) const; - ExprType_t argType(int iArg) const { return INT_ARR_EXPR; } - VMFnResult* exec(VMFnArgs* args); + vmint minRequiredArgs() const OVERRIDE { return 1; } + vmint maxAllowedArgs() const OVERRIDE { return 1; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in inc() script function. + */ +class CoreVMFunction_inc : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 1; } + vmint maxAllowedArgs() const OVERRIDE { return 1; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + bool modifiesArg(vmint iArg) const OVERRIDE { return true; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in dec() script function. + */ +class CoreVMFunction_dec : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 1; } + vmint maxAllowedArgs() const OVERRIDE { return 1; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + bool modifiesArg(vmint iArg) const OVERRIDE { return true; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in in_range() script function. + */ +class CoreVMFunction_in_range : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 3; } + vmint maxAllowedArgs() const OVERRIDE { return 3; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in sh_left() script function. + */ +class CoreVMFunction_sh_left : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 2; } + vmint maxAllowedArgs() const OVERRIDE { return 2; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in sh_right() script function. + */ +class CoreVMFunction_sh_right : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 2; } + vmint maxAllowedArgs() const OVERRIDE { return 2; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in min() script function. + */ +class CoreVMFunction_min : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 2; } + vmint maxAllowedArgs() const OVERRIDE { return 2; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in max() script function. + */ +class CoreVMFunction_max : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 2; } + vmint maxAllowedArgs() const OVERRIDE { return 2; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in array_equal() script function. + */ +class CoreVMFunction_array_equal : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 2; } + vmint maxAllowedArgs() const OVERRIDE { return 2; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_ARR_EXPR; } + ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in search() script function. + */ +class CoreVMFunction_search : public VMIntResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 2; } + vmint maxAllowedArgs() const OVERRIDE { return 2; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; + ExprType_t argType(vmint iArg) const OVERRIDE; + VMFnResult* exec(VMFnArgs* args) OVERRIDE; +}; + +/** + * Implements the built-in sort() script function. + */ +class CoreVMFunction_sort : public VMEmptyResultFunction { +public: + vmint minRequiredArgs() const OVERRIDE { return 1; } + vmint maxAllowedArgs() const OVERRIDE { return 2; } + bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; + ExprType_t argType(vmint iArg) const OVERRIDE; + bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; } + VMFnResult* exec(VMFnArgs* args) OVERRIDE; }; } // namespace LinuxSampler