/[svn]/linuxsampler/trunk/src/scriptvm/CoreVMFunctions.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/scriptvm/CoreVMFunctions.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3747 - (show annotations) (download) (as text)
Sun Feb 16 11:31:46 2020 UTC (4 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 35348 byte(s)
* NKSP: Fixed re-entrant issue with function calls which caused wrong
  result values if the same function was called multiple times in a term
  (specifically if metric prefixes were used).

* Tests: Added NKSP core language test cases to guard this fixed issue.

* Bumped version (2.1.1.svn50).

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 VMEmptyResultFunction() : result(NULL) {}
103 virtual ~VMEmptyResultFunction() {}
104 ExprType_t returnType(VMFnArgs* args) OVERRIDE { return EMPTY_EXPR; }
105 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
106 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
107 VMFnResult* errorResult();
108 VMFnResult* successResult();
109 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
110 VMFnResult* allocResult(VMFnArgs* args) OVERRIDE { return new VMEmptyResult(); }
111 void bindResult(VMFnResult* res) OVERRIDE;
112 VMFnResult* boundResult() const OVERRIDE;
113 protected:
114 VMEmptyResult* result;
115 };
116
117 struct VMIntFnResDef {
118 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.
119 vmfloat unitFactor = VM_NO_FACTOR;
120 };
121
122 struct VMRealFnResDef {
123 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.
124 vmfloat unitFactor = VM_NO_FACTOR;
125 };
126
127 /**
128 * Abstract base class for built-in script functions which return an integer
129 * (scalar) as their function return value.
130 */
131 class VMIntResultFunction : public VMFunction {
132 protected:
133 VMIntResultFunction() : result(NULL) {}
134 virtual ~VMIntResultFunction() {}
135 ExprType_t returnType(VMFnArgs* args) OVERRIDE { return INT_EXPR; }
136 VMFnResult* errorResult(vmint i = 0);
137 VMFnResult* errorResult(VMIntFnResDef res);
138 VMFnResult* successResult(vmint i = 0);
139 VMFnResult* successResult(VMIntFnResDef res);
140 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
141 VMFnResult* allocResult(VMFnArgs* args) OVERRIDE { return new VMIntResult(); }
142 void bindResult(VMFnResult* res) OVERRIDE;
143 VMFnResult* boundResult() const OVERRIDE;
144 protected:
145 VMIntResult* result;
146 };
147
148 /**
149 * Abstract base class for built-in script functions which return a real number
150 * (floating point scalar) as their function return value.
151 */
152 class VMRealResultFunction : public VMFunction {
153 protected:
154 VMRealResultFunction() : result(NULL) {}
155 virtual ~VMRealResultFunction() {}
156 ExprType_t returnType(VMFnArgs* args) OVERRIDE { return REAL_EXPR; }
157 VMFnResult* errorResult(vmfloat f = 0);
158 VMFnResult* errorResult(VMRealFnResDef res);
159 VMFnResult* successResult(vmfloat f = 0);
160 VMFnResult* successResult(VMRealFnResDef res);
161 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
162 VMFnResult* allocResult(VMFnArgs* args) OVERRIDE { return new VMRealResult(); }
163 void bindResult(VMFnResult* res) OVERRIDE;
164 VMFnResult* boundResult() const OVERRIDE;
165 protected:
166 VMRealResult* result;
167 };
168
169 /**
170 * Abstract base class for built-in script functions which return a string as
171 * their function return value.
172 */
173 class VMStringResultFunction : public VMFunction {
174 protected:
175 VMStringResultFunction() : result(NULL) {}
176 virtual ~VMStringResultFunction() {}
177 ExprType_t returnType(VMFnArgs* args) OVERRIDE { return STRING_EXPR; }
178 VMFnResult* errorResult(const String& s = "");
179 VMFnResult* successResult(const String& s = "");
180 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
181 VMFnResult* allocResult(VMFnArgs* args) OVERRIDE { return new VMStringResult(); }
182 void bindResult(VMFnResult* res) OVERRIDE;
183 VMFnResult* boundResult() const OVERRIDE;
184 protected:
185 VMStringResult* result;
186 };
187
188 /**
189 * Abstract base class for built-in script functions which either return an
190 * integer or a real number (floating point scalar) as their function return
191 * value. The actual return type is determined at parse time once after
192 * potential arguments were associated with the respective function call.
193 */
194 class VMNumberResultFunction : public VMFunction {
195 protected:
196 VMNumberResultFunction() : intResult(NULL), realResult(NULL) {}
197 virtual ~VMNumberResultFunction() {}
198 VMFnResult* errorResult(vmint i);
199 VMFnResult* errorResult(vmfloat f);
200 VMFnResult* successResult(vmint i);
201 VMFnResult* successResult(vmfloat f);
202 VMFnResult* errorIntResult(VMIntFnResDef res);
203 VMFnResult* errorRealResult(VMRealFnResDef res);
204 VMFnResult* successIntResult(VMIntFnResDef res);
205 VMFnResult* successRealResult(VMRealFnResDef res);
206 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
207 VMFnResult* allocResult(VMFnArgs* args) OVERRIDE;
208 void bindResult(VMFnResult* res) OVERRIDE;
209 VMFnResult* boundResult() const OVERRIDE;
210 protected:
211 VMIntResult* intResult;
212 VMRealResult* realResult;
213 };
214
215
216 ///////////////////////////////////////////////////////////////////////////
217 // implementations of core built-in script functions ...
218
219 /**
220 * Implements the built-in message() script function.
221 */
222 class CoreVMFunction_message FINAL : public VMEmptyResultFunction {
223 public:
224 vmint minRequiredArgs() const OVERRIDE { return 1; }
225 vmint maxAllowedArgs() const OVERRIDE { return 1; }
226 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
227 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
228 };
229
230 /**
231 * Implements the built-in exit() script function.
232 */
233 class CoreVMFunction_exit FINAL : public VMEmptyResultFunction {
234 public:
235 CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {}
236 vmint minRequiredArgs() const OVERRIDE { return 0; }
237 vmint maxAllowedArgs() const OVERRIDE;
238 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
239 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
240 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE;
241 bool acceptsArgFinal(vmint iArg) const OVERRIDE;
242 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
243 protected:
244 ScriptVM* vm;
245 };
246
247 /**
248 * Implements the built-in wait() script function.
249 */
250 class CoreVMFunction_wait : public VMEmptyResultFunction {
251 public:
252 CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
253 vmint minRequiredArgs() const OVERRIDE { return 1; }
254 vmint maxAllowedArgs() const OVERRIDE { return 1; }
255 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
256 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
257 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE;
258 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
259 protected:
260 ScriptVM* vm;
261 };
262
263 /**
264 * Implements the built-in abs() script function.
265 */
266 class CoreVMFunction_abs FINAL : public VMNumberResultFunction {
267 public:
268 ExprType_t returnType(VMFnArgs* args) OVERRIDE;
269 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
270 bool returnsFinal(VMFnArgs* args) OVERRIDE;
271 vmint minRequiredArgs() const OVERRIDE { return 1; }
272 vmint maxAllowedArgs() const OVERRIDE { return 1; }
273 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
274 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
275 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
276 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
277 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
278 };
279
280 /**
281 * Implements the built-in random() script function.
282 */
283 class CoreVMFunction_random FINAL : public VMNumberResultFunction {
284 using Super = VMNumberResultFunction; // just an alias for the super class
285 public:
286 ExprType_t returnType(VMFnArgs* args) OVERRIDE;
287 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
288 bool returnsFinal(VMFnArgs* args) OVERRIDE;
289 vmint minRequiredArgs() const OVERRIDE { return 2; }
290 vmint maxAllowedArgs() const OVERRIDE { return 2; }
291 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
292 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
293 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
294 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
295 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
296 std::function<void(String)> wrn) OVERRIDE;
297 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
298 };
299
300 /**
301 * Implements the built-in num_elements() script function.
302 */
303 class CoreVMFunction_num_elements FINAL : public VMIntResultFunction {
304 public:
305 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
306 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
307 vmint minRequiredArgs() const OVERRIDE { return 1; }
308 vmint maxAllowedArgs() const OVERRIDE { return 1; }
309 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
310 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
311 };
312
313 /**
314 * Implements the built-in inc() script function.
315 */
316 class CoreVMFunction_inc 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 dec() script function.
335 */
336 class CoreVMFunction_dec FINAL : public VMIntResultFunction {
337 using Super = VMIntResultFunction; // just an alias for the super class
338 public:
339 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
340 bool returnsFinal(VMFnArgs* args) OVERRIDE;
341 vmint minRequiredArgs() const OVERRIDE { return 1; }
342 vmint maxAllowedArgs() const OVERRIDE { return 1; }
343 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
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 bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
348 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
349 std::function<void(String)> wrn) OVERRIDE;
350 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
351 };
352
353 /**
354 * Implements the built-in in_range() script function.
355 */
356 class CoreVMFunction_in_range FINAL : public VMIntResultFunction {
357 using Super = VMIntResultFunction; // just an alias for the super class
358 public:
359 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
360 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
361 vmint minRequiredArgs() const OVERRIDE { return 3; }
362 vmint maxAllowedArgs() const OVERRIDE { return 3; }
363 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
364 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
365 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
366 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
367 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
368 std::function<void(String)> wrn) OVERRIDE;
369 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
370 };
371
372 /**
373 * Implements the built-in sh_left() script function.
374 */
375 class CoreVMFunction_sh_left FINAL : public VMIntResultFunction {
376 public:
377 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
378 bool returnsFinal(VMFnArgs* args) OVERRIDE;
379 vmint minRequiredArgs() const OVERRIDE { return 2; }
380 vmint maxAllowedArgs() const OVERRIDE { return 2; }
381 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
382 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
383 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
384 };
385
386 /**
387 * Implements the built-in sh_right() script function.
388 */
389 class CoreVMFunction_sh_right FINAL : public VMIntResultFunction {
390 public:
391 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
392 bool returnsFinal(VMFnArgs* args) OVERRIDE;
393 vmint minRequiredArgs() const OVERRIDE { return 2; }
394 vmint maxAllowedArgs() const OVERRIDE { return 2; }
395 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
396 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
397 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
398 };
399
400 /**
401 * Implements the built-in msb() script function.
402 */
403 class CoreVMFunction_msb FINAL : public VMIntResultFunction {
404 public:
405 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
406 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
407 vmint minRequiredArgs() const OVERRIDE { return 1; }
408 vmint maxAllowedArgs() const OVERRIDE { return 1; }
409 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
410 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return false; }
411 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
412 };
413
414 /**
415 * Implements the built-in lsb() script function.
416 */
417 class CoreVMFunction_lsb FINAL : public VMIntResultFunction {
418 public:
419 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
420 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
421 vmint minRequiredArgs() const OVERRIDE { return 1; }
422 vmint maxAllowedArgs() const OVERRIDE { return 1; }
423 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
424 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return false; }
425 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
426 };
427
428 /**
429 * Implements the built-in min() script function.
430 */
431 class CoreVMFunction_min 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 max() script function.
450 */
451 class CoreVMFunction_max FINAL : public VMNumberResultFunction {
452 using Super = VMNumberResultFunction; // just an alias for the super class
453 public:
454 ExprType_t returnType(VMFnArgs* args) OVERRIDE;
455 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
456 bool returnsFinal(VMFnArgs* args) OVERRIDE;
457 vmint minRequiredArgs() const OVERRIDE { return 2; }
458 vmint maxAllowedArgs() const OVERRIDE { return 2; }
459 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
460 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
461 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
462 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
463 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
464 std::function<void(String)> wrn) OVERRIDE;
465 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
466 };
467
468 /**
469 * Implements the built-in array_equal() script function.
470 */
471 class CoreVMFunction_array_equal FINAL : public VMIntResultFunction {
472 using Super = VMIntResultFunction; // just an alias for the super class
473 public:
474 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
475 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
476 vmint minRequiredArgs() const OVERRIDE { return 2; }
477 vmint maxAllowedArgs() const OVERRIDE { return 2; }
478 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
479 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
480 std::function<void(String)> wrn) OVERRIDE;
481 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
482 };
483
484 /**
485 * Implements the built-in search() script function.
486 */
487 class CoreVMFunction_search FINAL : public VMIntResultFunction {
488 using Super = VMIntResultFunction; // just an alias for the super class
489 public:
490 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
491 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
492 vmint minRequiredArgs() const OVERRIDE { return 2; }
493 vmint maxAllowedArgs() const OVERRIDE { return 2; }
494 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
495 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
496 std::function<void(String)> wrn) OVERRIDE;
497 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
498 };
499
500 /**
501 * Implements the built-in sort() script function.
502 */
503 class CoreVMFunction_sort FINAL : public VMEmptyResultFunction {
504 public:
505 vmint minRequiredArgs() const OVERRIDE { return 1; }
506 vmint maxAllowedArgs() const OVERRIDE { return 2; }
507 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
508 bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; }
509 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
510 };
511
512 /**
513 * Implements the built-in real_to_int() script function and its short hand
514 * variant int(). The behaviour of the two built-in script functions are
515 * identical ATM.
516 */
517 class CoreVMFunction_real_to_int FINAL : public VMIntResultFunction {
518 public:
519 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
520 bool returnsFinal(VMFnArgs* args) OVERRIDE;
521 vmint minRequiredArgs() const OVERRIDE { return 1; }
522 vmint maxAllowedArgs() const OVERRIDE { return 1; }
523 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
524 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
525 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
526 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
527 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
528 };
529
530 /**
531 * Implements the built-in int_to_real() script function and its short hand
532 * variant real(). The behaviour of the two built-in script functions are
533 * identical ATM.
534 */
535 class CoreVMFunction_int_to_real FINAL : public VMRealResultFunction {
536 public:
537 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
538 bool returnsFinal(VMFnArgs* args) OVERRIDE;
539 vmint minRequiredArgs() const OVERRIDE { return 1; }
540 vmint maxAllowedArgs() const OVERRIDE { return 1; }
541 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
542 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
543 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
544 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
545 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
546 };
547
548 /**
549 * Implements the built-in round() script function.
550 */
551 class CoreVMFunction_round FINAL : public VMRealResultFunction {
552 public:
553 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
554 bool returnsFinal(VMFnArgs* args) OVERRIDE;
555 vmint minRequiredArgs() const OVERRIDE { return 1; }
556 vmint maxAllowedArgs() const OVERRIDE { return 1; }
557 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
558 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
559 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
560 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
561 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
562 };
563
564 /**
565 * Implements the built-in ceil() script function.
566 */
567 class CoreVMFunction_ceil FINAL : public VMRealResultFunction {
568 public:
569 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
570 bool returnsFinal(VMFnArgs* args) OVERRIDE;
571 vmint minRequiredArgs() const OVERRIDE { return 1; }
572 vmint maxAllowedArgs() const OVERRIDE { return 1; }
573 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
574 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
575 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
576 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
577 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
578 };
579
580 /**
581 * Implements the built-in floor() script function.
582 */
583 class CoreVMFunction_floor FINAL : public VMRealResultFunction {
584 public:
585 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
586 bool returnsFinal(VMFnArgs* args) OVERRIDE;
587 vmint minRequiredArgs() const OVERRIDE { return 1; }
588 vmint maxAllowedArgs() const OVERRIDE { return 1; }
589 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
590 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
591 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
592 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
593 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
594 };
595
596 /**
597 * Implements the built-in sqrt() script function.
598 */
599 class CoreVMFunction_sqrt FINAL : public VMRealResultFunction {
600 public:
601 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
602 bool returnsFinal(VMFnArgs* args) OVERRIDE;
603 vmint minRequiredArgs() const OVERRIDE { return 1; }
604 vmint maxAllowedArgs() const OVERRIDE { return 1; }
605 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
606 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
607 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
608 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
609 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
610 };
611
612 /**
613 * Implements the built-in log() script function.
614 */
615 class CoreVMFunction_log FINAL : public VMRealResultFunction {
616 public:
617 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
618 bool returnsFinal(VMFnArgs* args) OVERRIDE;
619 vmint minRequiredArgs() const OVERRIDE { return 1; }
620 vmint maxAllowedArgs() const OVERRIDE { return 1; }
621 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
622 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
623 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
624 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
625 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
626 };
627
628 /**
629 * Implements the built-in log2() script function.
630 */
631 class CoreVMFunction_log2 FINAL : public VMRealResultFunction {
632 public:
633 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
634 bool returnsFinal(VMFnArgs* args) OVERRIDE;
635 vmint minRequiredArgs() const OVERRIDE { return 1; }
636 vmint maxAllowedArgs() const OVERRIDE { return 1; }
637 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
638 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
639 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
640 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
641 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
642 };
643
644 /**
645 * Implements the built-in log10() script function.
646 */
647 class CoreVMFunction_log10 FINAL : public VMRealResultFunction {
648 public:
649 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
650 bool returnsFinal(VMFnArgs* args) OVERRIDE;
651 vmint minRequiredArgs() const OVERRIDE { return 1; }
652 vmint maxAllowedArgs() const OVERRIDE { return 1; }
653 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
654 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
655 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
656 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
657 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
658 };
659
660 /**
661 * Implements the built-in exp() script function.
662 */
663 class CoreVMFunction_exp FINAL : public VMRealResultFunction {
664 public:
665 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
666 bool returnsFinal(VMFnArgs* args) OVERRIDE;
667 vmint minRequiredArgs() const OVERRIDE { return 1; }
668 vmint maxAllowedArgs() const OVERRIDE { return 1; }
669 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
670 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
671 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
672 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
673 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
674 };
675
676 /**
677 * Implements the built-in pow() script function.
678 */
679 class CoreVMFunction_pow FINAL : public VMRealResultFunction {
680 using Super = VMRealResultFunction; // just an alias for the super class
681 public:
682 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
683 bool returnsFinal(VMFnArgs* args) OVERRIDE;
684 vmint minRequiredArgs() const OVERRIDE { return 2; }
685 vmint maxAllowedArgs() const OVERRIDE { return 2; }
686 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
687 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
688 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE;
689 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return iArg == 0; }
690 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
691 };
692
693 /**
694 * Implements the built-in sin() script function.
695 */
696 class CoreVMFunction_sin FINAL : public VMRealResultFunction {
697 public:
698 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
699 bool returnsFinal(VMFnArgs* args) OVERRIDE;
700 vmint minRequiredArgs() const OVERRIDE { return 1; }
701 vmint maxAllowedArgs() const OVERRIDE { return 1; }
702 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
703 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
704 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
705 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
706 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
707 };
708
709 /**
710 * Implements the built-in cos() script function.
711 */
712 class CoreVMFunction_cos FINAL : public VMRealResultFunction {
713 public:
714 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
715 bool returnsFinal(VMFnArgs* args) OVERRIDE;
716 vmint minRequiredArgs() const OVERRIDE { return 1; }
717 vmint maxAllowedArgs() const OVERRIDE { return 1; }
718 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
719 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
720 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
721 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
722 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
723 };
724
725 /**
726 * Implements the built-in tan() script function.
727 */
728 class CoreVMFunction_tan FINAL : public VMRealResultFunction {
729 public:
730 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
731 bool returnsFinal(VMFnArgs* args) OVERRIDE;
732 vmint minRequiredArgs() const OVERRIDE { return 1; }
733 vmint maxAllowedArgs() const OVERRIDE { return 1; }
734 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
735 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
736 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
737 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
738 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
739 };
740
741 /**
742 * Implements the built-in asin() script function.
743 */
744 class CoreVMFunction_asin FINAL : public VMRealResultFunction {
745 public:
746 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
747 bool returnsFinal(VMFnArgs* args) OVERRIDE;
748 vmint minRequiredArgs() const OVERRIDE { return 1; }
749 vmint maxAllowedArgs() const OVERRIDE { return 1; }
750 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
751 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
752 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
753 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
754 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
755 };
756
757 /**
758 * Implements the built-in acos() script function.
759 */
760 class CoreVMFunction_acos FINAL : public VMRealResultFunction {
761 public:
762 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
763 bool returnsFinal(VMFnArgs* args) OVERRIDE;
764 vmint minRequiredArgs() const OVERRIDE { return 1; }
765 vmint maxAllowedArgs() const OVERRIDE { return 1; }
766 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
767 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
768 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
769 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
770 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
771 };
772
773 /**
774 * Implements the built-in atan() script function.
775 */
776 class CoreVMFunction_atan FINAL : public VMRealResultFunction {
777 public:
778 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
779 bool returnsFinal(VMFnArgs* args) OVERRIDE;
780 vmint minRequiredArgs() const OVERRIDE { return 1; }
781 vmint maxAllowedArgs() const OVERRIDE { return 1; }
782 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
783 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
784 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
785 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
786 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
787 };
788
789 } // namespace LinuxSampler
790
791 #endif // LS_COREVMFUNCTIONS_H

  ViewVC Help
Powered by ViewVC