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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3557 - (hide annotations) (download) (as text)
Sun Aug 18 00:06:04 2019 UTC (4 years, 8 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 11436 byte(s)
* NKSP: Introducing 64 bit support for NKSP integer scripts
  variables (declare $foo).
* Require C++11 compiler support.
* Autoconf: Added m4/ax_cxx_compile_stdcxx.m4 macro which is used
  for checking in configure for C++11 support (as mandatory
  requirement) and automatically adds compiler argument if required
  (e.g. -std=C++11).
* Bumped version (2.1.1.svn3).

1 schoenebeck 2581 /*
2 schoenebeck 3551 * Copyright (c) 2014-2019 Christian Schoenebeck
3 schoenebeck 2581 *
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 schoenebeck 2727
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 schoenebeck 2581 class VMEmptyResult : public VMFnResult, public VMExpr {
28     public:
29 schoenebeck 2727 StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
30 schoenebeck 2581
31     VMEmptyResult() : flags(STMT_SUCCESS) {}
32 schoenebeck 3054 ExprType_t exprType() const OVERRIDE { return EMPTY_EXPR; }
33     VMExpr* resultValue() OVERRIDE { return this; }
34     StmtFlags_t resultFlags() OVERRIDE { return flags; }
35 schoenebeck 2945 bool isConstExpr() const OVERRIDE { return false; }
36 schoenebeck 2581 };
37    
38 schoenebeck 2727 /**
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 schoenebeck 2598 class VMIntResult : public VMFnResult, public VMIntExpr {
43     public:
44 schoenebeck 2727 StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
45 schoenebeck 3557 vmint value; ///< result value of the function call
46 schoenebeck 2598
47     VMIntResult() : flags(STMT_SUCCESS) {}
48 schoenebeck 3557 vmint evalInt() OVERRIDE { return value; }
49 schoenebeck 3054 VMExpr* resultValue() OVERRIDE { return this; }
50     StmtFlags_t resultFlags() OVERRIDE { return flags; }
51 schoenebeck 2945 bool isConstExpr() const OVERRIDE { return false; }
52 schoenebeck 2598 };
53    
54 schoenebeck 2727 /**
55     * An instance of this class is returned by built-in function implementations
56     * which return a string value as function return value.
57     */
58 schoenebeck 2581 class VMStringResult : public VMFnResult, public VMStringExpr {
59     public:
60 schoenebeck 2727 StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
61     String value; ///< result value of the function call
62 schoenebeck 2581
63     VMStringResult() : flags(STMT_SUCCESS) {}
64 schoenebeck 3054 String evalStr() OVERRIDE { return value; }
65     VMExpr* resultValue() OVERRIDE { return this; }
66     StmtFlags_t resultFlags() OVERRIDE { return flags; }
67 schoenebeck 2945 bool isConstExpr() const OVERRIDE { return false; }
68 schoenebeck 2581 };
69    
70 schoenebeck 2727 /**
71     * Abstract base class for built-in script functions which do not return any
72     * function return value (void).
73     */
74 schoenebeck 2581 class VMEmptyResultFunction : public VMFunction {
75     protected:
76 schoenebeck 3034 virtual ~VMEmptyResultFunction() {}
77 schoenebeck 3054 ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; }
78 schoenebeck 2581 VMFnResult* errorResult();
79     VMFnResult* successResult();
80 schoenebeck 3557 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
81 schoenebeck 2581 protected:
82     VMEmptyResult result;
83     };
84    
85 schoenebeck 2727 /**
86     * Abstract base class for built-in script functions which return an integer
87     * (scalar) as their function return value.
88     */
89 schoenebeck 2598 class VMIntResultFunction : public VMFunction {
90     protected:
91 schoenebeck 3034 virtual ~VMIntResultFunction() {}
92 schoenebeck 3054 ExprType_t returnType() OVERRIDE { return INT_EXPR; }
93 schoenebeck 3557 VMFnResult* errorResult(vmint i = 0);
94     VMFnResult* successResult(vmint i = 0);
95     bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
96 schoenebeck 2598 protected:
97     VMIntResult result;
98     };
99    
100 schoenebeck 2727 /**
101     * Abstract base class for built-in script functions which return a string as
102     * their function return value.
103     */
104 schoenebeck 2581 class VMStringResultFunction : public VMFunction {
105     protected:
106 schoenebeck 3034 virtual ~VMStringResultFunction() {}
107 schoenebeck 3054 ExprType_t returnType() OVERRIDE { return STRING_EXPR; }
108 schoenebeck 2581 VMFnResult* errorResult(const String& s = "");
109     VMFnResult* successResult(const String& s = "");
110 schoenebeck 3557 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
111 schoenebeck 2581 protected:
112     VMStringResult result;
113     };
114    
115 schoenebeck 2727
116     ///////////////////////////////////////////////////////////////////////////
117     // implementations of core built-in script functions ...
118    
119     /**
120     * Implements the built-in message() script function.
121     */
122 schoenebeck 2581 class CoreVMFunction_message : public VMEmptyResultFunction {
123     public:
124 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
125     vmint maxAllowedArgs() const OVERRIDE { return 1; }
126     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
127     ExprType_t argType(vmint iArg) const OVERRIDE { return STRING_EXPR; }
128     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
129 schoenebeck 2581 };
130    
131 schoenebeck 2727 /**
132     * Implements the built-in exit() script function.
133     */
134 schoenebeck 2581 class CoreVMFunction_exit : public VMEmptyResultFunction {
135     public:
136 schoenebeck 3551 CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {}
137 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 0; }
138     vmint maxAllowedArgs() const OVERRIDE;
139     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
140     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
141     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
142 schoenebeck 3551 protected:
143     ScriptVM* vm;
144 schoenebeck 2581 };
145    
146 schoenebeck 2727 /**
147     * Implements the built-in wait() script function.
148     */
149 schoenebeck 2581 class CoreVMFunction_wait : public VMEmptyResultFunction {
150     public:
151     CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
152 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
153     vmint maxAllowedArgs() const OVERRIDE { return 1; }
154     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
155     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
156     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
157 schoenebeck 2581 protected:
158     ScriptVM* vm;
159     };
160    
161 schoenebeck 2727 /**
162     * Implements the built-in abs() script function.
163     */
164 schoenebeck 2619 class CoreVMFunction_abs : public VMIntResultFunction {
165     public:
166 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
167     vmint maxAllowedArgs() const OVERRIDE { return 1; }
168     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
169     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
170     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
171 schoenebeck 2619 };
172    
173 schoenebeck 2727 /**
174     * Implements the built-in random() script function.
175     */
176 schoenebeck 2619 class CoreVMFunction_random : public VMIntResultFunction {
177     public:
178 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
179     vmint maxAllowedArgs() const OVERRIDE { return 2; }
180     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
181     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
182     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
183 schoenebeck 2619 };
184    
185 schoenebeck 2727 /**
186     * Implements the built-in num_elements() script function.
187     */
188 schoenebeck 2619 class CoreVMFunction_num_elements : public VMIntResultFunction {
189     public:
190 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
191     vmint maxAllowedArgs() const OVERRIDE { return 1; }
192     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
193     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; }
194     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
195 schoenebeck 2619 };
196    
197 schoenebeck 2945 /**
198     * Implements the built-in inc() script function.
199     */
200     class CoreVMFunction_inc : public VMIntResultFunction {
201     public:
202 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
203     vmint maxAllowedArgs() const OVERRIDE { return 1; }
204     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
205     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
206     bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
207     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
208 schoenebeck 2945 };
209    
210     /**
211     * Implements the built-in dec() script function.
212     */
213     class CoreVMFunction_dec : public VMIntResultFunction {
214     public:
215 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
216     vmint maxAllowedArgs() const OVERRIDE { return 1; }
217     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
218     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
219     bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
220     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
221 schoenebeck 2945 };
222    
223 schoenebeck 2965 /**
224 schoenebeck 3076 * Implements the built-in in_range() script function.
225     */
226     class CoreVMFunction_in_range : public VMIntResultFunction {
227     public:
228 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 3; }
229     vmint maxAllowedArgs() const OVERRIDE { return 3; }
230     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
231     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
232     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
233 schoenebeck 3076 };
234    
235     /**
236 schoenebeck 2965 * Implements the built-in sh_left() script function.
237     */
238     class CoreVMFunction_sh_left : public VMIntResultFunction {
239     public:
240 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
241     vmint maxAllowedArgs() const OVERRIDE { return 2; }
242     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
243     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
244     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
245 schoenebeck 2965 };
246    
247     /**
248     * Implements the built-in sh_right() script function.
249     */
250     class CoreVMFunction_sh_right : public VMIntResultFunction {
251     public:
252 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
253     vmint maxAllowedArgs() const OVERRIDE { return 2; }
254     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
255     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
256     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
257 schoenebeck 2965 };
258    
259 schoenebeck 2970 /**
260     * Implements the built-in min() script function.
261     */
262     class CoreVMFunction_min : public VMIntResultFunction {
263     public:
264 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
265     vmint maxAllowedArgs() const OVERRIDE { return 2; }
266     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
267     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
268     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
269 schoenebeck 2970 };
270    
271     /**
272     * Implements the built-in max() script function.
273     */
274     class CoreVMFunction_max : public VMIntResultFunction {
275     public:
276 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
277     vmint maxAllowedArgs() const OVERRIDE { return 2; }
278     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
279     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
280     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
281 schoenebeck 2970 };
282    
283 schoenebeck 3221 /**
284     * Implements the built-in array_equal() script function.
285     */
286     class CoreVMFunction_array_equal : public VMIntResultFunction {
287     public:
288 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
289     vmint maxAllowedArgs() const OVERRIDE { return 2; }
290     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_ARR_EXPR; }
291     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; }
292     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
293 schoenebeck 3221 };
294    
295     /**
296     * Implements the built-in search() script function.
297     */
298     class CoreVMFunction_search : public VMIntResultFunction {
299     public:
300 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
301     vmint maxAllowedArgs() const OVERRIDE { return 2; }
302     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
303     ExprType_t argType(vmint iArg) const OVERRIDE;
304     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
305 schoenebeck 3221 };
306    
307     /**
308     * Implements the built-in sort() script function.
309     */
310     class CoreVMFunction_sort : public VMEmptyResultFunction {
311     public:
312 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
313     vmint maxAllowedArgs() const OVERRIDE { return 2; }
314     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
315     ExprType_t argType(vmint iArg) const OVERRIDE;
316     bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; }
317     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
318 schoenebeck 3221 };
319    
320 schoenebeck 2581 } // namespace LinuxSampler
321    
322     #endif // LS_COREVMFUNCTIONS_H

  ViewVC Help
Powered by ViewVC