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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2727 by schoenebeck, Tue Mar 31 17:46:11 2015 UTC revision 3561 by schoenebeck, Fri Aug 23 11:44:00 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2015 Christian Schoenebeck   * Copyright (c) 2014-2019 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 29  public: Line 29  public:
29      StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call      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 OVERRIDE { return EMPTY_EXPR; }
33      VMExpr* resultValue() { return this; }      VMExpr* resultValue() OVERRIDE { return this; }
34      StmtFlags_t resultFlags() { return flags; }      StmtFlags_t resultFlags() OVERRIDE { return flags; }
35        bool isConstExpr() const OVERRIDE { return false; }
36  };  };
37    
38  /**  /**
# Line 41  public: Line 42  public:
42  class VMIntResult : public VMFnResult, public VMIntExpr {  class VMIntResult : public VMFnResult, public VMIntExpr {
43  public:  public:
44      StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call      StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
45      int value; ///< result value of the function call      vmint value; ///< result value of the function call
46    
47      VMIntResult() : flags(STMT_SUCCESS) {}      VMIntResult() : flags(STMT_SUCCESS), value(0) {}
48      int evalInt() { return value; }      vmint evalInt() OVERRIDE { return value; }
49      VMExpr* resultValue() { return this; }      VMExpr* resultValue() OVERRIDE { return this; }
50      StmtFlags_t resultFlags() { return flags; }      StmtFlags_t resultFlags() OVERRIDE { return flags; }
51        bool isConstExpr() const OVERRIDE { return false; }
52        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
53        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
54        bool isFinal() const OVERRIDE { return false; }
55  };  };
56    
57  /**  /**
# Line 59  public: Line 64  public:
64      String value; ///< result value of the function call      String value; ///< result value of the function call
65    
66      VMStringResult() : flags(STMT_SUCCESS) {}      VMStringResult() : flags(STMT_SUCCESS) {}
67      String evalStr() { return value; }      String evalStr() OVERRIDE { return value; }
68      VMExpr* resultValue() { return this; }      VMExpr* resultValue() OVERRIDE { return this; }
69      StmtFlags_t resultFlags() { return flags; }      StmtFlags_t resultFlags() OVERRIDE { return flags; }
70        bool isConstExpr() const OVERRIDE { return false; }
71  };  };
72    
73  /**  /**
# Line 70  public: Line 76  public:
76   */   */
77  class VMEmptyResultFunction : public VMFunction {  class VMEmptyResultFunction : public VMFunction {
78  protected:  protected:
79      ExprType_t returnType() { return EMPTY_EXPR; }      virtual ~VMEmptyResultFunction() {}
80        ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; }
81      VMFnResult* errorResult();      VMFnResult* errorResult();
82      VMFnResult* successResult();      VMFnResult* successResult();
83        bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
84  protected:  protected:
85      VMEmptyResult result;      VMEmptyResult result;
86  };  };
# Line 83  protected: Line 91  protected:
91   */   */
92  class VMIntResultFunction : public VMFunction {  class VMIntResultFunction : public VMFunction {
93  protected:  protected:
94      ExprType_t returnType() { return INT_EXPR; }      virtual ~VMIntResultFunction() {}
95      VMFnResult* errorResult(int i = 0);      ExprType_t returnType() OVERRIDE { return INT_EXPR; }
96      VMFnResult* successResult(int i = 0);      VMFnResult* errorResult(vmint i = 0);
97        VMFnResult* successResult(vmint i = 0);
98        bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
99  protected:  protected:
100      VMIntResult result;      VMIntResult result;
101  };  };
# Line 96  protected: Line 106  protected:
106   */   */
107  class VMStringResultFunction : public VMFunction {  class VMStringResultFunction : public VMFunction {
108  protected:  protected:
109      ExprType_t returnType() { return STRING_EXPR; }      virtual ~VMStringResultFunction() {}
110        ExprType_t returnType() OVERRIDE { return STRING_EXPR; }
111      VMFnResult* errorResult(const String& s = "");      VMFnResult* errorResult(const String& s = "");
112      VMFnResult* successResult(const String& s = "");      VMFnResult* successResult(const String& s = "");
113        bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
114  protected:  protected:
115      VMStringResult result;      VMStringResult result;
116  };  };
# Line 112  protected: Line 124  protected:
124   */   */
125  class CoreVMFunction_message : public VMEmptyResultFunction {  class CoreVMFunction_message : public VMEmptyResultFunction {
126  public:  public:
127      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
128      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
129      bool acceptsArgType(int iArg, ExprType_t type) const;      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
130      ExprType_t argType(int iArg) const { return STRING_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return STRING_EXPR; }
131      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
132  };  };
133    
134  /**  /**
# Line 124  public: Line 136  public:
136   */   */
137  class CoreVMFunction_exit : public VMEmptyResultFunction {  class CoreVMFunction_exit : public VMEmptyResultFunction {
138  public:  public:
139      int minRequiredArgs() const { return 0; }      CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {}
140      int maxAllowedArgs() const { return 0; }      vmint minRequiredArgs() const OVERRIDE { return 0; }
141      bool acceptsArgType(int iArg, ExprType_t type) const { return false; }      vmint maxAllowedArgs() const OVERRIDE;
142      ExprType_t argType(int iArg) const { return INT_EXPR; /*whatever*/ }      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
143      VMFnResult* exec(VMFnArgs* args);      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
144        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
145    protected:
146        ScriptVM* vm;
147  };  };
148    
149  /**  /**
# Line 137  public: Line 152  public:
152  class CoreVMFunction_wait : public VMEmptyResultFunction {  class CoreVMFunction_wait : public VMEmptyResultFunction {
153  public:  public:
154      CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}      CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
155      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
156      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
157      bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
158      ExprType_t argType(int iArg) const { return INT_EXPR; }      bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
159      VMFnResult* exec(VMFnArgs* args);      bool acceptsArgUnitPrefix(vmint iArg) const OVERRIDE;
160        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
161        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
162  protected:  protected:
163      ScriptVM* vm;      ScriptVM* vm;
164  };  };
# Line 151  protected: Line 168  protected:
168   */   */
169  class CoreVMFunction_abs : public VMIntResultFunction {  class CoreVMFunction_abs : public VMIntResultFunction {
170  public:  public:
171      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
172      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
173      bool acceptsArgType(int iArg, ExprType_t type) const;      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
174      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
175      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
176  };  };
177    
178  /**  /**
# Line 163  public: Line 180  public:
180   */   */
181  class CoreVMFunction_random : public VMIntResultFunction {  class CoreVMFunction_random : public VMIntResultFunction {
182  public:  public:
183      int minRequiredArgs() const { return 2; }      vmint minRequiredArgs() const OVERRIDE { return 2; }
184      int maxAllowedArgs() const { return 2; }      vmint maxAllowedArgs() const OVERRIDE { return 2; }
185      bool acceptsArgType(int iArg, ExprType_t type) const;      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
186      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
187      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
188  };  };
189    
190  /**  /**
# Line 175  public: Line 192  public:
192   */   */
193  class CoreVMFunction_num_elements : public VMIntResultFunction {  class CoreVMFunction_num_elements : public VMIntResultFunction {
194  public:  public:
195      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
196      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
197      bool acceptsArgType(int iArg, ExprType_t type) const;      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
198      ExprType_t argType(int iArg) const { return INT_ARR_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; }
199      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
200    };
201    
202    /**
203     * Implements the built-in inc() script function.
204     */
205    class CoreVMFunction_inc : public VMIntResultFunction {
206    public:
207        vmint minRequiredArgs() const OVERRIDE { return 1; }
208        vmint maxAllowedArgs() const OVERRIDE { return 1; }
209        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
210        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
211        bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
212        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
213    };
214    
215    /**
216     * Implements the built-in dec() script function.
217     */
218    class CoreVMFunction_dec : public VMIntResultFunction {
219    public:
220        vmint minRequiredArgs() const OVERRIDE { return 1; }
221        vmint maxAllowedArgs() const OVERRIDE { return 1; }
222        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
223        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
224        bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
225        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
226    };
227    
228    /**
229     * Implements the built-in in_range() script function.
230     */
231    class CoreVMFunction_in_range : public VMIntResultFunction {
232    public:
233        vmint minRequiredArgs() const OVERRIDE { return 3; }
234        vmint maxAllowedArgs() const OVERRIDE { return 3; }
235        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
236        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
237        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
238    };
239    
240    /**
241     * Implements the built-in sh_left() script function.
242     */
243    class CoreVMFunction_sh_left : public VMIntResultFunction {
244    public:
245        vmint minRequiredArgs() const OVERRIDE { return 2; }
246        vmint maxAllowedArgs() const OVERRIDE { return 2; }
247        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
248        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
249        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
250    };
251    
252    /**
253     * Implements the built-in sh_right() script function.
254     */
255    class CoreVMFunction_sh_right : public VMIntResultFunction {
256    public:
257        vmint minRequiredArgs() const OVERRIDE { return 2; }
258        vmint maxAllowedArgs() const OVERRIDE { return 2; }
259        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
260        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
261        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
262    };
263    
264    /**
265     * Implements the built-in min() script function.
266     */
267    class CoreVMFunction_min : public VMIntResultFunction {
268    public:
269        vmint minRequiredArgs() const OVERRIDE { return 2; }
270        vmint maxAllowedArgs() const OVERRIDE { return 2; }
271        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
272        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
273        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
274    };
275    
276    /**
277     * Implements the built-in max() script function.
278     */
279    class CoreVMFunction_max : public VMIntResultFunction {
280    public:
281        vmint minRequiredArgs() const OVERRIDE { return 2; }
282        vmint maxAllowedArgs() const OVERRIDE { return 2; }
283        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
284        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
285        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
286    };
287    
288    /**
289     * Implements the built-in array_equal() script function.
290     */
291    class CoreVMFunction_array_equal : public VMIntResultFunction {
292    public:
293        vmint minRequiredArgs() const OVERRIDE { return 2; }
294        vmint maxAllowedArgs() const OVERRIDE { return 2; }
295        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_ARR_EXPR; }
296        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; }
297        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
298    };
299    
300    /**
301     * Implements the built-in search() script function.
302     */
303    class CoreVMFunction_search : public VMIntResultFunction {
304    public:
305        vmint minRequiredArgs() const OVERRIDE { return 2; }
306        vmint maxAllowedArgs() const OVERRIDE { return 2; }
307        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
308        ExprType_t argType(vmint iArg) const OVERRIDE;
309        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
310    };
311    
312    /**
313     * Implements the built-in sort() script function.
314     */
315    class CoreVMFunction_sort : public VMEmptyResultFunction {
316    public:
317        vmint minRequiredArgs() const OVERRIDE { return 1; }
318        vmint maxAllowedArgs() const OVERRIDE { return 2; }
319        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
320        ExprType_t argType(vmint iArg) const OVERRIDE;
321        bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; }
322        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
323  };  };
324    
325  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2727  
changed lines
  Added in v.3561

  ViewVC Help
Powered by ViewVC