1 |
/* |
2 |
* Copyright (c) 2014-2020 Christian Schoenebeck |
3 |
* |
4 |
* http://www.linuxsampler.org |
5 |
* |
6 |
* This file is part of LinuxSampler and released under the same terms. |
7 |
* See README file for details. |
8 |
*/ |
9 |
|
10 |
#ifndef LS_COREVMFUNCTIONS_H |
11 |
#define LS_COREVMFUNCTIONS_H |
12 |
|
13 |
#include "../common/global.h" |
14 |
#include "common.h" |
15 |
|
16 |
namespace LinuxSampler { |
17 |
|
18 |
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 FINAL : public VMFnResult, public VMExpr { |
28 |
public: |
29 |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
30 |
|
31 |
VMEmptyResult() : flags(STMT_SUCCESS) {} |
32 |
ExprType_t exprType() const OVERRIDE { return EMPTY_EXPR; } |
33 |
VMExpr* resultValue() OVERRIDE { return this; } |
34 |
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
35 |
bool isConstExpr() const OVERRIDE { return false; } |
36 |
}; |
37 |
|
38 |
/** |
39 |
* An instance of this class is returned by built-in function implementations |
40 |
* which return an integer value as function return value. |
41 |
*/ |
42 |
class VMIntResult FINAL : public VMFnResult, public VMIntExpr { |
43 |
public: |
44 |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
45 |
vmint value; ///< result value of the function call |
46 |
vmfloat unitPrefixFactor; ///< unit factor of result value of the function call |
47 |
StdUnit_t unitBaseType; ///< fundamental standard measuring unit type (e.g. seconds), this is ALWAYS and ONLY set (to the actual unit type) by @c FunctionCall class for performance reasons. |
48 |
|
49 |
VMIntResult(); |
50 |
vmint evalInt() OVERRIDE { return value; } |
51 |
VMExpr* resultValue() OVERRIDE { return this; } |
52 |
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
53 |
bool isConstExpr() const OVERRIDE { return false; } |
54 |
vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; } |
55 |
StdUnit_t unitType() const OVERRIDE { return unitBaseType; } |
56 |
bool isFinal() const OVERRIDE { return false; } // actually never called, VMFunction::returnsFinal() is always used instead |
57 |
}; |
58 |
|
59 |
/** |
60 |
* An instance of this class is returned by built-in function implementations |
61 |
* which return a real number (floating point) value as function return value. |
62 |
*/ |
63 |
class VMRealResult FINAL : public VMFnResult, public VMRealExpr { |
64 |
public: |
65 |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
66 |
vmfloat value; ///< result value of the function call |
67 |
vmfloat unitPrefixFactor; ///< unit factor of result value of the function call |
68 |
StdUnit_t unitBaseType; ///< fundamental standard measuring unit type (e.g. seconds), this is ALWAYS and ONLY set (to the actual unit type) by @c FunctionCall class for performance reasons. |
69 |
|
70 |
VMRealResult(); |
71 |
vmfloat evalReal() OVERRIDE { return value; } |
72 |
VMExpr* resultValue() OVERRIDE { return this; } |
73 |
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
74 |
bool isConstExpr() const OVERRIDE { return false; } |
75 |
vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; } |
76 |
StdUnit_t unitType() const OVERRIDE { return unitBaseType; } |
77 |
bool isFinal() const OVERRIDE { return false; } // actually never called, VMFunction::returnsFinal() is always used instead |
78 |
}; |
79 |
|
80 |
/** |
81 |
* An instance of this class is returned by built-in function implementations |
82 |
* which return a string value as function return value. |
83 |
*/ |
84 |
class VMStringResult FINAL : public VMFnResult, public VMStringExpr { |
85 |
public: |
86 |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
87 |
String value; ///< result value of the function call |
88 |
|
89 |
VMStringResult() : flags(STMT_SUCCESS) {} |
90 |
String evalStr() OVERRIDE { return value; } |
91 |
VMExpr* resultValue() OVERRIDE { return this; } |
92 |
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
93 |
bool isConstExpr() const OVERRIDE { return false; } |
94 |
}; |
95 |
|
96 |
/** |
97 |
* Abstract base class for built-in script functions which do not return any |
98 |
* function return value (void). |
99 |
*/ |
100 |
class VMEmptyResultFunction : public VMFunction { |
101 |
protected: |
102 |
virtual ~VMEmptyResultFunction() {} |
103 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE { return EMPTY_EXPR; } |
104 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
105 |
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
106 |
VMFnResult* errorResult(); |
107 |
VMFnResult* successResult(); |
108 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
109 |
protected: |
110 |
VMEmptyResult result; |
111 |
}; |
112 |
|
113 |
struct VMIntFnResDef { |
114 |
vmint value = 0; //NOTE: sequence matters! Since this is usually initialized with VMIntExpr::evalInt() it should be before member unitFactor, since the latter is usually initialized with VMIntExpr::unitFactor() which does not evaluate the expression. |
115 |
vmfloat unitFactor = VM_NO_FACTOR; |
116 |
}; |
117 |
|
118 |
struct VMRealFnResDef { |
119 |
vmfloat value = vmfloat(0); //NOTE: sequence matters! Since this is usually initialized with VMRealExpr::evalReal() it should be before member unitFactor, since the latter is usually initialized with VMRealExpr::unitFactor() which does not evaluate the expression. |
120 |
vmfloat unitFactor = VM_NO_FACTOR; |
121 |
}; |
122 |
|
123 |
/** |
124 |
* Abstract base class for built-in script functions which return an integer |
125 |
* (scalar) as their function return value. |
126 |
*/ |
127 |
class VMIntResultFunction : public VMFunction { |
128 |
protected: |
129 |
virtual ~VMIntResultFunction() {} |
130 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE { return INT_EXPR; } |
131 |
VMFnResult* errorResult(vmint i = 0); |
132 |
VMFnResult* errorResult(VMIntFnResDef res); |
133 |
VMFnResult* successResult(vmint i = 0); |
134 |
VMFnResult* successResult(VMIntFnResDef res); |
135 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
136 |
protected: |
137 |
VMIntResult result; |
138 |
}; |
139 |
|
140 |
/** |
141 |
* Abstract base class for built-in script functions which return a real number |
142 |
* (floating point scalar) as their function return value. |
143 |
*/ |
144 |
class VMRealResultFunction : public VMFunction { |
145 |
protected: |
146 |
virtual ~VMRealResultFunction() {} |
147 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE { return REAL_EXPR; } |
148 |
VMFnResult* errorResult(vmfloat f = 0); |
149 |
VMFnResult* errorResult(VMRealFnResDef res); |
150 |
VMFnResult* successResult(vmfloat f = 0); |
151 |
VMFnResult* successResult(VMRealFnResDef res); |
152 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
153 |
protected: |
154 |
VMRealResult result; |
155 |
}; |
156 |
|
157 |
/** |
158 |
* Abstract base class for built-in script functions which return a string as |
159 |
* their function return value. |
160 |
*/ |
161 |
class VMStringResultFunction : public VMFunction { |
162 |
protected: |
163 |
virtual ~VMStringResultFunction() {} |
164 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE { return STRING_EXPR; } |
165 |
VMFnResult* errorResult(const String& s = ""); |
166 |
VMFnResult* successResult(const String& s = ""); |
167 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
168 |
protected: |
169 |
VMStringResult result; |
170 |
}; |
171 |
|
172 |
/** |
173 |
* Abstract base class for built-in script functions which either return an |
174 |
* integer or a real number (floating point scalar) as their function return |
175 |
* value. The actual return type is determined at parse time once after |
176 |
* potential arguments were associated with the respective function call. |
177 |
*/ |
178 |
class VMNumberResultFunction : public VMFunction { |
179 |
protected: |
180 |
virtual ~VMNumberResultFunction() {} |
181 |
VMFnResult* errorResult(vmint i); |
182 |
VMFnResult* errorResult(vmfloat f); |
183 |
VMFnResult* successResult(vmint i); |
184 |
VMFnResult* successResult(vmfloat f); |
185 |
VMFnResult* errorIntResult(VMIntFnResDef res); |
186 |
VMFnResult* errorRealResult(VMRealFnResDef res); |
187 |
VMFnResult* successIntResult(VMIntFnResDef res); |
188 |
VMFnResult* successRealResult(VMRealFnResDef res); |
189 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
190 |
protected: |
191 |
VMIntResult intResult; |
192 |
VMRealResult realResult; |
193 |
}; |
194 |
|
195 |
|
196 |
/////////////////////////////////////////////////////////////////////////// |
197 |
// implementations of core built-in script functions ... |
198 |
|
199 |
/** |
200 |
* Implements the built-in message() script function. |
201 |
*/ |
202 |
class CoreVMFunction_message FINAL : public VMEmptyResultFunction { |
203 |
public: |
204 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
205 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
206 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
207 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
208 |
}; |
209 |
|
210 |
/** |
211 |
* Implements the built-in exit() script function. |
212 |
*/ |
213 |
class CoreVMFunction_exit FINAL : public VMEmptyResultFunction { |
214 |
public: |
215 |
CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {} |
216 |
vmint minRequiredArgs() const OVERRIDE { return 0; } |
217 |
vmint maxAllowedArgs() const OVERRIDE; |
218 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
219 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE; |
220 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE; |
221 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE; |
222 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
223 |
protected: |
224 |
ScriptVM* vm; |
225 |
}; |
226 |
|
227 |
/** |
228 |
* Implements the built-in wait() script function. |
229 |
*/ |
230 |
class CoreVMFunction_wait : public VMEmptyResultFunction { |
231 |
public: |
232 |
CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {} |
233 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
234 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
235 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
236 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE; |
237 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE; |
238 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
239 |
protected: |
240 |
ScriptVM* vm; |
241 |
}; |
242 |
|
243 |
/** |
244 |
* Implements the built-in abs() script function. |
245 |
*/ |
246 |
class CoreVMFunction_abs FINAL : public VMNumberResultFunction { |
247 |
public: |
248 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE; |
249 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
250 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
251 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
252 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
253 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
254 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
255 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
256 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
257 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
258 |
}; |
259 |
|
260 |
/** |
261 |
* Implements the built-in random() script function. |
262 |
*/ |
263 |
class CoreVMFunction_random FINAL : public VMNumberResultFunction { |
264 |
using Super = VMNumberResultFunction; // just an alias for the super class |
265 |
public: |
266 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE; |
267 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
268 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
269 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
270 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
271 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
272 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
273 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
274 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
275 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
276 |
std::function<void(String)> wrn) OVERRIDE; |
277 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
278 |
}; |
279 |
|
280 |
/** |
281 |
* Implements the built-in num_elements() script function. |
282 |
*/ |
283 |
class CoreVMFunction_num_elements FINAL : public VMIntResultFunction { |
284 |
public: |
285 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
286 |
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
287 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
288 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
289 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
290 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
291 |
}; |
292 |
|
293 |
/** |
294 |
* Implements the built-in inc() script function. |
295 |
*/ |
296 |
class CoreVMFunction_inc FINAL : public VMIntResultFunction { |
297 |
using Super = VMIntResultFunction; // just an alias for the super class |
298 |
public: |
299 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
300 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
301 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
302 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
303 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
304 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
305 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
306 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
307 |
bool modifiesArg(vmint iArg) const OVERRIDE { return true; } |
308 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
309 |
std::function<void(String)> wrn) OVERRIDE; |
310 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
311 |
}; |
312 |
|
313 |
/** |
314 |
* Implements the built-in dec() script function. |
315 |
*/ |
316 |
class CoreVMFunction_dec FINAL : public VMIntResultFunction { |
317 |
using Super = VMIntResultFunction; // just an alias for the super class |
318 |
public: |
319 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
320 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
321 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
322 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
323 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
324 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
325 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
326 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
327 |
bool modifiesArg(vmint iArg) const OVERRIDE { return true; } |
328 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
329 |
std::function<void(String)> wrn) OVERRIDE; |
330 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
331 |
}; |
332 |
|
333 |
/** |
334 |
* Implements the built-in in_range() script function. |
335 |
*/ |
336 |
class CoreVMFunction_in_range FINAL : public VMIntResultFunction { |
337 |
using Super = VMIntResultFunction; // just an alias for the super class |
338 |
public: |
339 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
340 |
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
341 |
vmint minRequiredArgs() const OVERRIDE { return 3; } |
342 |
vmint maxAllowedArgs() const OVERRIDE { return 3; } |
343 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
344 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
345 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
346 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
347 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
348 |
std::function<void(String)> wrn) OVERRIDE; |
349 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
350 |
}; |
351 |
|
352 |
/** |
353 |
* Implements the built-in sh_left() script function. |
354 |
*/ |
355 |
class CoreVMFunction_sh_left FINAL : public VMIntResultFunction { |
356 |
public: |
357 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
358 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
359 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
360 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
361 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
362 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
363 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
364 |
}; |
365 |
|
366 |
/** |
367 |
* Implements the built-in sh_right() script function. |
368 |
*/ |
369 |
class CoreVMFunction_sh_right FINAL : public VMIntResultFunction { |
370 |
public: |
371 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
372 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
373 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
374 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
375 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
376 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
377 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
378 |
}; |
379 |
|
380 |
/** |
381 |
* Implements the built-in msb() script function. |
382 |
*/ |
383 |
class CoreVMFunction_msb FINAL : public VMIntResultFunction { |
384 |
public: |
385 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
386 |
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
387 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
388 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
389 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
390 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return false; } |
391 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
392 |
}; |
393 |
|
394 |
/** |
395 |
* Implements the built-in lsb() script function. |
396 |
*/ |
397 |
class CoreVMFunction_lsb FINAL : public VMIntResultFunction { |
398 |
public: |
399 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
400 |
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
401 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
402 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
403 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
404 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return false; } |
405 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
406 |
}; |
407 |
|
408 |
/** |
409 |
* Implements the built-in min() script function. |
410 |
*/ |
411 |
class CoreVMFunction_min FINAL : public VMNumberResultFunction { |
412 |
using Super = VMNumberResultFunction; // just an alias for the super class |
413 |
public: |
414 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE; |
415 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
416 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
417 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
418 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
419 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
420 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
421 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
422 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
423 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
424 |
std::function<void(String)> wrn) OVERRIDE; |
425 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
426 |
}; |
427 |
|
428 |
/** |
429 |
* Implements the built-in max() script function. |
430 |
*/ |
431 |
class CoreVMFunction_max FINAL : public VMNumberResultFunction { |
432 |
using Super = VMNumberResultFunction; // just an alias for the super class |
433 |
public: |
434 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE; |
435 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
436 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
437 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
438 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
439 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
440 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
441 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
442 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
443 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
444 |
std::function<void(String)> wrn) OVERRIDE; |
445 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
446 |
}; |
447 |
|
448 |
/** |
449 |
* Implements the built-in array_equal() script function. |
450 |
*/ |
451 |
class CoreVMFunction_array_equal FINAL : public VMIntResultFunction { |
452 |
using Super = VMIntResultFunction; // just an alias for the super class |
453 |
public: |
454 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
455 |
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
456 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
457 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
458 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
459 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
460 |
std::function<void(String)> wrn) OVERRIDE; |
461 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
462 |
}; |
463 |
|
464 |
/** |
465 |
* Implements the built-in search() script function. |
466 |
*/ |
467 |
class CoreVMFunction_search FINAL : public VMIntResultFunction { |
468 |
using Super = VMIntResultFunction; // just an alias for the super class |
469 |
public: |
470 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
471 |
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
472 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
473 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
474 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
475 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
476 |
std::function<void(String)> wrn) OVERRIDE; |
477 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
478 |
}; |
479 |
|
480 |
/** |
481 |
* Implements the built-in sort() script function. |
482 |
*/ |
483 |
class CoreVMFunction_sort FINAL : public VMEmptyResultFunction { |
484 |
public: |
485 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
486 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
487 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
488 |
bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; } |
489 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
490 |
}; |
491 |
|
492 |
/** |
493 |
* Implements the built-in real_to_int() script function and its short hand |
494 |
* variant int(). The behaviour of the two built-in script functions are |
495 |
* identical ATM. |
496 |
*/ |
497 |
class CoreVMFunction_real_to_int FINAL : public VMIntResultFunction { |
498 |
public: |
499 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
500 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
501 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
502 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
503 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
504 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
505 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
506 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
507 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
508 |
}; |
509 |
|
510 |
/** |
511 |
* Implements the built-in int_to_real() script function and its short hand |
512 |
* variant real(). The behaviour of the two built-in script functions are |
513 |
* identical ATM. |
514 |
*/ |
515 |
class CoreVMFunction_int_to_real FINAL : public VMRealResultFunction { |
516 |
public: |
517 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
518 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
519 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
520 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
521 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
522 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
523 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
524 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
525 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
526 |
}; |
527 |
|
528 |
/** |
529 |
* Implements the built-in round() script function. |
530 |
*/ |
531 |
class CoreVMFunction_round FINAL : public VMRealResultFunction { |
532 |
public: |
533 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
534 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
535 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
536 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
537 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
538 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
539 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
540 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
541 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
542 |
}; |
543 |
|
544 |
/** |
545 |
* Implements the built-in ceil() script function. |
546 |
*/ |
547 |
class CoreVMFunction_ceil FINAL : public VMRealResultFunction { |
548 |
public: |
549 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
550 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
551 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
552 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
553 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
554 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
555 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
556 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
558 |
}; |
559 |
|
560 |
/** |
561 |
* Implements the built-in floor() script function. |
562 |
*/ |
563 |
class CoreVMFunction_floor FINAL : public VMRealResultFunction { |
564 |
public: |
565 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
566 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
567 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
568 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
569 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
570 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
571 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
572 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
573 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
574 |
}; |
575 |
|
576 |
/** |
577 |
* Implements the built-in sqrt() script function. |
578 |
*/ |
579 |
class CoreVMFunction_sqrt FINAL : public VMRealResultFunction { |
580 |
public: |
581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
582 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
583 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
584 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
585 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
586 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
587 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
588 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
589 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
590 |
}; |
591 |
|
592 |
/** |
593 |
* Implements the built-in log() script function. |
594 |
*/ |
595 |
class CoreVMFunction_log FINAL : public VMRealResultFunction { |
596 |
public: |
597 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
598 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
599 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
600 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
601 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
602 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
603 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
604 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
605 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
606 |
}; |
607 |
|
608 |
/** |
609 |
* Implements the built-in log2() script function. |
610 |
*/ |
611 |
class CoreVMFunction_log2 FINAL : public VMRealResultFunction { |
612 |
public: |
613 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
614 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
615 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
616 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
617 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
618 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
619 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
620 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
621 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
622 |
}; |
623 |
|
624 |
/** |
625 |
* Implements the built-in log10() script function. |
626 |
*/ |
627 |
class CoreVMFunction_log10 FINAL : public VMRealResultFunction { |
628 |
public: |
629 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
630 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
631 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
632 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
633 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
634 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
635 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
636 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
637 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
638 |
}; |
639 |
|
640 |
/** |
641 |
* Implements the built-in exp() script function. |
642 |
*/ |
643 |
class CoreVMFunction_exp FINAL : public VMRealResultFunction { |
644 |
public: |
645 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
646 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
647 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
648 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
649 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
650 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
651 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
652 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
653 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
654 |
}; |
655 |
|
656 |
/** |
657 |
* Implements the built-in pow() script function. |
658 |
*/ |
659 |
class CoreVMFunction_pow FINAL : public VMRealResultFunction { |
660 |
using Super = VMRealResultFunction; // just an alias for the super class |
661 |
public: |
662 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
663 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
664 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
665 |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
666 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
667 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE; |
668 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE; |
669 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return iArg == 0; } |
670 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
671 |
}; |
672 |
|
673 |
/** |
674 |
* Implements the built-in sin() script function. |
675 |
*/ |
676 |
class CoreVMFunction_sin FINAL : public VMRealResultFunction { |
677 |
public: |
678 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
679 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
680 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
681 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
682 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
683 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
684 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
685 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
686 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
687 |
}; |
688 |
|
689 |
/** |
690 |
* Implements the built-in cos() script function. |
691 |
*/ |
692 |
class CoreVMFunction_cos FINAL : public VMRealResultFunction { |
693 |
public: |
694 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
695 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
696 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
697 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
698 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
699 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
700 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
701 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
702 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
703 |
}; |
704 |
|
705 |
/** |
706 |
* Implements the built-in tan() script function. |
707 |
*/ |
708 |
class CoreVMFunction_tan FINAL : public VMRealResultFunction { |
709 |
public: |
710 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
711 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
712 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
713 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
714 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
715 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
716 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
717 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
718 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
719 |
}; |
720 |
|
721 |
/** |
722 |
* Implements the built-in asin() script function. |
723 |
*/ |
724 |
class CoreVMFunction_asin FINAL : public VMRealResultFunction { |
725 |
public: |
726 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
727 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
728 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
729 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
730 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
731 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
732 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
733 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
734 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
735 |
}; |
736 |
|
737 |
/** |
738 |
* Implements the built-in acos() script function. |
739 |
*/ |
740 |
class CoreVMFunction_acos FINAL : public VMRealResultFunction { |
741 |
public: |
742 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
743 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
744 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
745 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
746 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
747 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
748 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
749 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
750 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
751 |
}; |
752 |
|
753 |
/** |
754 |
* Implements the built-in atan() script function. |
755 |
*/ |
756 |
class CoreVMFunction_atan FINAL : public VMRealResultFunction { |
757 |
public: |
758 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
759 |
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
760 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
761 |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
762 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
763 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
764 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
765 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
766 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
767 |
}; |
768 |
|
769 |
} // namespace LinuxSampler |
770 |
|
771 |
#endif // LS_COREVMFUNCTIONS_H |