1 |
/* |
/* |
2 |
* Copyright (c) 2014 Christian Schoenebeck |
* Copyright (c) 2014-2015 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
16 |
namespace LinuxSampler { |
namespace LinuxSampler { |
17 |
|
|
18 |
class ScriptVM; |
class ScriptVM; |
19 |
|
|
20 |
|
/////////////////////////////////////////////////////////////////////////// |
21 |
|
// convenience base classes for built-in script functions ... |
22 |
|
|
23 |
|
/** |
24 |
|
* An instance of this class is returned by built-in function implementations |
25 |
|
* which do not return a function return value. |
26 |
|
*/ |
27 |
class VMEmptyResult : public VMFnResult, public VMExpr { |
class VMEmptyResult : public VMFnResult, public VMExpr { |
28 |
public: |
public: |
29 |
StmtFlags_t flags; |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
30 |
|
|
31 |
VMEmptyResult() : flags(STMT_SUCCESS) {} |
VMEmptyResult() : flags(STMT_SUCCESS) {} |
32 |
ExprType_t exprType() const { return EMPTY_EXPR; } |
ExprType_t exprType() const { return EMPTY_EXPR; } |
34 |
StmtFlags_t resultFlags() { return flags; } |
StmtFlags_t resultFlags() { return flags; } |
35 |
}; |
}; |
36 |
|
|
37 |
|
/** |
38 |
|
* An instance of this class is returned by built-in function implementations |
39 |
|
* which return an integer value as function return value. |
40 |
|
*/ |
41 |
class VMIntResult : public VMFnResult, public VMIntExpr { |
class VMIntResult : public VMFnResult, public VMIntExpr { |
42 |
public: |
public: |
43 |
StmtFlags_t flags; |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
44 |
int value; |
int value; ///< result value of the function call |
45 |
|
|
46 |
VMIntResult() : flags(STMT_SUCCESS) {} |
VMIntResult() : flags(STMT_SUCCESS) {} |
47 |
int evalInt() { return value; } |
int evalInt() { return value; } |
49 |
StmtFlags_t resultFlags() { return flags; } |
StmtFlags_t resultFlags() { return flags; } |
50 |
}; |
}; |
51 |
|
|
52 |
|
/** |
53 |
|
* An instance of this class is returned by built-in function implementations |
54 |
|
* which return a string value as function return value. |
55 |
|
*/ |
56 |
class VMStringResult : public VMFnResult, public VMStringExpr { |
class VMStringResult : public VMFnResult, public VMStringExpr { |
57 |
public: |
public: |
58 |
StmtFlags_t flags; |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
59 |
String value; |
String value; ///< result value of the function call |
60 |
|
|
61 |
VMStringResult() : flags(STMT_SUCCESS) {} |
VMStringResult() : flags(STMT_SUCCESS) {} |
62 |
String evalStr() { return value; } |
String evalStr() { return value; } |
64 |
StmtFlags_t resultFlags() { return flags; } |
StmtFlags_t resultFlags() { return flags; } |
65 |
}; |
}; |
66 |
|
|
67 |
|
/** |
68 |
|
* Abstract base class for built-in script functions which do not return any |
69 |
|
* function return value (void). |
70 |
|
*/ |
71 |
class VMEmptyResultFunction : public VMFunction { |
class VMEmptyResultFunction : public VMFunction { |
72 |
protected: |
protected: |
73 |
ExprType_t returnType() { return EMPTY_EXPR; } |
ExprType_t returnType() { return EMPTY_EXPR; } |
77 |
VMEmptyResult result; |
VMEmptyResult result; |
78 |
}; |
}; |
79 |
|
|
80 |
|
/** |
81 |
|
* Abstract base class for built-in script functions which return an integer |
82 |
|
* (scalar) as their function return value. |
83 |
|
*/ |
84 |
class VMIntResultFunction : public VMFunction { |
class VMIntResultFunction : public VMFunction { |
85 |
protected: |
protected: |
86 |
ExprType_t returnType() { return INT_EXPR; } |
ExprType_t returnType() { return INT_EXPR; } |
90 |
VMIntResult result; |
VMIntResult result; |
91 |
}; |
}; |
92 |
|
|
93 |
|
/** |
94 |
|
* Abstract base class for built-in script functions which return a string as |
95 |
|
* their function return value. |
96 |
|
*/ |
97 |
class VMStringResultFunction : public VMFunction { |
class VMStringResultFunction : public VMFunction { |
98 |
protected: |
protected: |
99 |
ExprType_t returnType() { return STRING_EXPR; } |
ExprType_t returnType() { return STRING_EXPR; } |
103 |
VMStringResult result; |
VMStringResult result; |
104 |
}; |
}; |
105 |
|
|
106 |
|
|
107 |
|
/////////////////////////////////////////////////////////////////////////// |
108 |
|
// implementations of core built-in script functions ... |
109 |
|
|
110 |
|
/** |
111 |
|
* Implements the built-in message() script function. |
112 |
|
*/ |
113 |
class CoreVMFunction_message : public VMEmptyResultFunction { |
class CoreVMFunction_message : public VMEmptyResultFunction { |
114 |
public: |
public: |
115 |
int minRequiredArgs() const { return 1; } |
int minRequiredArgs() const { return 1; } |
119 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args); |
120 |
}; |
}; |
121 |
|
|
122 |
|
/** |
123 |
|
* Implements the built-in exit() script function. |
124 |
|
*/ |
125 |
class CoreVMFunction_exit : public VMEmptyResultFunction { |
class CoreVMFunction_exit : public VMEmptyResultFunction { |
126 |
public: |
public: |
127 |
int minRequiredArgs() const { return 0; } |
int minRequiredArgs() const { return 0; } |
131 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args); |
132 |
}; |
}; |
133 |
|
|
134 |
|
/** |
135 |
|
* Implements the built-in wait() script function. |
136 |
|
*/ |
137 |
class CoreVMFunction_wait : public VMEmptyResultFunction { |
class CoreVMFunction_wait : public VMEmptyResultFunction { |
138 |
public: |
public: |
139 |
CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {} |
CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {} |
146 |
ScriptVM* vm; |
ScriptVM* vm; |
147 |
}; |
}; |
148 |
|
|
149 |
|
/** |
150 |
|
* Implements the built-in abs() script function. |
151 |
|
*/ |
152 |
class CoreVMFunction_abs : public VMIntResultFunction { |
class CoreVMFunction_abs : public VMIntResultFunction { |
153 |
public: |
public: |
154 |
int minRequiredArgs() const { return 1; } |
int minRequiredArgs() const { return 1; } |
158 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args); |
159 |
}; |
}; |
160 |
|
|
161 |
|
/** |
162 |
|
* Implements the built-in random() script function. |
163 |
|
*/ |
164 |
class CoreVMFunction_random : public VMIntResultFunction { |
class CoreVMFunction_random : public VMIntResultFunction { |
165 |
public: |
public: |
166 |
int minRequiredArgs() const { return 2; } |
int minRequiredArgs() const { return 2; } |
170 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args); |
171 |
}; |
}; |
172 |
|
|
173 |
|
/** |
174 |
|
* Implements the built-in num_elements() script function. |
175 |
|
*/ |
176 |
class CoreVMFunction_num_elements : public VMIntResultFunction { |
class CoreVMFunction_num_elements : public VMIntResultFunction { |
177 |
public: |
public: |
178 |
int minRequiredArgs() const { return 1; } |
int minRequiredArgs() const { return 1; } |