/[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 3076 by schoenebeck, Thu Jan 5 18:00:52 2017 UTC revision 3573 by schoenebeck, Tue Aug 27 21:36:53 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2016 Christian Schoenebeck   * Copyright (c) 2014-2019 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 42  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() OVERRIDE { return value; }      vmint evalInt() OVERRIDE { return value; }
49      VMExpr* resultValue() OVERRIDE { return this; }      VMExpr* resultValue() OVERRIDE { return this; }
50      StmtFlags_t resultFlags() OVERRIDE { return flags; }      StmtFlags_t resultFlags() OVERRIDE { return flags; }
51      bool isConstExpr() const OVERRIDE { return false; }      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    /**
58     * An instance of this class is returned by built-in function implementations
59     * which return a real number (floating point) value as function return value.
60     */
61    class VMRealResult : public VMFnResult, public VMRealExpr {
62    public:
63        StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
64        vmfloat value; ///< result value of the function call
65    
66        VMRealResult() : flags(STMT_SUCCESS), value(0) {}
67        vmfloat evalReal() OVERRIDE { return value; }
68        VMExpr* resultValue() OVERRIDE { return this; }
69        StmtFlags_t resultFlags() OVERRIDE { return flags; }
70        bool isConstExpr() const OVERRIDE { return false; }
71        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
72        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
73        bool isFinal() const OVERRIDE { return false; }
74  };  };
75    
76  /**  /**
# Line 77  protected: Line 99  protected:
99      ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; }      ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; }
100      VMFnResult* errorResult();      VMFnResult* errorResult();
101      VMFnResult* successResult();      VMFnResult* successResult();
102      bool modifiesArg(int iArg) const OVERRIDE { return false; }      bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
103  protected:  protected:
104      VMEmptyResult result;      VMEmptyResult result;
105  };  };
# Line 90  class VMIntResultFunction : public VMFun Line 112  class VMIntResultFunction : public VMFun
112  protected:  protected:
113      virtual ~VMIntResultFunction() {}      virtual ~VMIntResultFunction() {}
114      ExprType_t returnType() OVERRIDE { return INT_EXPR; }      ExprType_t returnType() OVERRIDE { return INT_EXPR; }
115      VMFnResult* errorResult(int i = 0);      VMFnResult* errorResult(vmint i = 0);
116      VMFnResult* successResult(int i = 0);      VMFnResult* successResult(vmint i = 0);
117      bool modifiesArg(int iArg) const OVERRIDE { return false; }      bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
118  protected:  protected:
119      VMIntResult result;      VMIntResult result;
120  };  };
121    
122  /**  /**
123     * Abstract base class for built-in script functions which return a real number
124     * (floating point scalar) as their function return value.
125     */
126    class VMRealResultFunction : public VMFunction {
127    protected:
128        virtual ~VMRealResultFunction() {}
129        ExprType_t returnType() OVERRIDE { return REAL_EXPR; }
130        VMFnResult* errorResult(vmfloat f = 0);
131        VMFnResult* successResult(vmfloat f = 0);
132        bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
133    protected:
134        VMRealResult result;
135    };
136    
137    /**
138   * Abstract base class for built-in script functions which return a string as   * Abstract base class for built-in script functions which return a string as
139   * their function return value.   * their function return value.
140   */   */
# Line 107  protected: Line 144  protected:
144      ExprType_t returnType() OVERRIDE { return STRING_EXPR; }      ExprType_t returnType() OVERRIDE { return STRING_EXPR; }
145      VMFnResult* errorResult(const String& s = "");      VMFnResult* errorResult(const String& s = "");
146      VMFnResult* successResult(const String& s = "");      VMFnResult* successResult(const String& s = "");
147      bool modifiesArg(int iArg) const OVERRIDE { return false; }      bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
148  protected:  protected:
149      VMStringResult result;      VMStringResult result;
150  };  };
# Line 121  protected: Line 158  protected:
158   */   */
159  class CoreVMFunction_message : public VMEmptyResultFunction {  class CoreVMFunction_message : public VMEmptyResultFunction {
160  public:  public:
161      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
162      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
163      bool acceptsArgType(int iArg, ExprType_t type) const;      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
164      ExprType_t argType(int iArg) const { return STRING_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return STRING_EXPR; }
165      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
166  };  };
167    
168  /**  /**
# Line 133  public: Line 170  public:
170   */   */
171  class CoreVMFunction_exit : public VMEmptyResultFunction {  class CoreVMFunction_exit : public VMEmptyResultFunction {
172  public:  public:
173      int minRequiredArgs() const { return 0; }      CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {}
174      int maxAllowedArgs() const { return 0; }      vmint minRequiredArgs() const OVERRIDE { return 0; }
175      bool acceptsArgType(int iArg, ExprType_t type) const { return false; }      vmint maxAllowedArgs() const OVERRIDE;
176      ExprType_t argType(int iArg) const { return INT_EXPR; /*whatever*/ }      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
177      VMFnResult* exec(VMFnArgs* args);      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
178        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
179    protected:
180        ScriptVM* vm;
181  };  };
182    
183  /**  /**
# Line 146  public: Line 186  public:
186  class CoreVMFunction_wait : public VMEmptyResultFunction {  class CoreVMFunction_wait : public VMEmptyResultFunction {
187  public:  public:
188      CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}      CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
189      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
190      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
191      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; }
192      ExprType_t argType(int iArg) const { return INT_EXPR; }      bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
193      VMFnResult* exec(VMFnArgs* args);      bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE;
194        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
195        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
196  protected:  protected:
197      ScriptVM* vm;      ScriptVM* vm;
198  };  };
# Line 160  protected: Line 202  protected:
202   */   */
203  class CoreVMFunction_abs : public VMIntResultFunction {  class CoreVMFunction_abs : public VMIntResultFunction {
204  public:  public:
205      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
206      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
207      bool acceptsArgType(int iArg, ExprType_t type) const;      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
208      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
209      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
210  };  };
211    
212  /**  /**
# Line 172  public: Line 214  public:
214   */   */
215  class CoreVMFunction_random : public VMIntResultFunction {  class CoreVMFunction_random : public VMIntResultFunction {
216  public:  public:
217      int minRequiredArgs() const { return 2; }      vmint minRequiredArgs() const OVERRIDE { return 2; }
218      int maxAllowedArgs() const { return 2; }      vmint maxAllowedArgs() const OVERRIDE { return 2; }
219      bool acceptsArgType(int iArg, ExprType_t type) const;      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
220      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
221      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
222  };  };
223    
224  /**  /**
# Line 184  public: Line 226  public:
226   */   */
227  class CoreVMFunction_num_elements : public VMIntResultFunction {  class CoreVMFunction_num_elements : public VMIntResultFunction {
228  public:  public:
229      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
230      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
231      bool acceptsArgType(int iArg, ExprType_t type) const;      bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
232      ExprType_t argType(int iArg) const { return INT_ARR_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; }
233      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
234  };  };
235    
236  /**  /**
# Line 196  public: Line 238  public:
238   */   */
239  class CoreVMFunction_inc : public VMIntResultFunction {  class CoreVMFunction_inc : public VMIntResultFunction {
240  public:  public:
241      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
242      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
243      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; }
244      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
245      bool modifiesArg(int iArg) const { return true; }      bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
246      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
247  };  };
248    
249  /**  /**
# Line 209  public: Line 251  public:
251   */   */
252  class CoreVMFunction_dec : public VMIntResultFunction {  class CoreVMFunction_dec : public VMIntResultFunction {
253  public:  public:
254      int minRequiredArgs() const { return 1; }      vmint minRequiredArgs() const OVERRIDE { return 1; }
255      int maxAllowedArgs() const { return 1; }      vmint maxAllowedArgs() const OVERRIDE { return 1; }
256      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; }
257      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
258      bool modifiesArg(int iArg) const { return true; }      bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
259      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
260  };  };
261    
262  /**  /**
# Line 222  public: Line 264  public:
264   */   */
265  class CoreVMFunction_in_range : public VMIntResultFunction {  class CoreVMFunction_in_range : public VMIntResultFunction {
266  public:  public:
267      int minRequiredArgs() const { return 3; }      vmint minRequiredArgs() const OVERRIDE { return 3; }
268      int maxAllowedArgs() const { return 3; }      vmint maxAllowedArgs() const OVERRIDE { return 3; }
269      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; }
270      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
271      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
272  };  };
273    
274  /**  /**
# Line 234  public: Line 276  public:
276   */   */
277  class CoreVMFunction_sh_left : public VMIntResultFunction {  class CoreVMFunction_sh_left : public VMIntResultFunction {
278  public:  public:
279      int minRequiredArgs() const { return 2; }      vmint minRequiredArgs() const OVERRIDE { return 2; }
280      int maxAllowedArgs() const { return 2; }      vmint maxAllowedArgs() const OVERRIDE { return 2; }
281      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; }
282      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
283      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
284  };  };
285    
286  /**  /**
# Line 246  public: Line 288  public:
288   */   */
289  class CoreVMFunction_sh_right : public VMIntResultFunction {  class CoreVMFunction_sh_right : public VMIntResultFunction {
290  public:  public:
291      int minRequiredArgs() const { return 2; }      vmint minRequiredArgs() const OVERRIDE { return 2; }
292      int maxAllowedArgs() const { return 2; }      vmint maxAllowedArgs() const OVERRIDE { return 2; }
293      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; }
294      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
295      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
296  };  };
297    
298  /**  /**
# Line 258  public: Line 300  public:
300   */   */
301  class CoreVMFunction_min : public VMIntResultFunction {  class CoreVMFunction_min : public VMIntResultFunction {
302  public:  public:
303      int minRequiredArgs() const { return 2; }      vmint minRequiredArgs() const OVERRIDE { return 2; }
304      int maxAllowedArgs() const { return 2; }      vmint maxAllowedArgs() const OVERRIDE { return 2; }
305      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; }
306      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
307      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
308  };  };
309    
310  /**  /**
# Line 270  public: Line 312  public:
312   */   */
313  class CoreVMFunction_max : public VMIntResultFunction {  class CoreVMFunction_max : public VMIntResultFunction {
314  public:  public:
315      int minRequiredArgs() const { return 2; }      vmint minRequiredArgs() const OVERRIDE { return 2; }
316      int maxAllowedArgs() const { return 2; }      vmint maxAllowedArgs() const OVERRIDE { return 2; }
317      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; }
318      ExprType_t argType(int iArg) const { return INT_EXPR; }      ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
319      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args) OVERRIDE;
320    };
321    
322    /**
323     * Implements the built-in array_equal() script function.
324     */
325    class CoreVMFunction_array_equal : public VMIntResultFunction {
326    public:
327        vmint minRequiredArgs() const OVERRIDE { return 2; }
328        vmint maxAllowedArgs() const OVERRIDE { return 2; }
329        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_ARR_EXPR; }
330        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; }
331        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
332    };
333    
334    /**
335     * Implements the built-in search() script function.
336     */
337    class CoreVMFunction_search : public VMIntResultFunction {
338    public:
339        vmint minRequiredArgs() const OVERRIDE { return 2; }
340        vmint maxAllowedArgs() const OVERRIDE { return 2; }
341        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
342        ExprType_t argType(vmint iArg) const OVERRIDE;
343        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
344    };
345    
346    /**
347     * Implements the built-in sort() script function.
348     */
349    class CoreVMFunction_sort : public VMEmptyResultFunction {
350    public:
351        vmint minRequiredArgs() const OVERRIDE { return 1; }
352        vmint maxAllowedArgs() const OVERRIDE { return 2; }
353        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
354        ExprType_t argType(vmint iArg) const OVERRIDE;
355        bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; }
356        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
357    };
358    
359    /**
360     * Implements the built-in real_to_int() script function and its short hand
361     * variant int(). The behaviour of the two built-in script functions are
362     * identical ATM.
363     */
364    class CoreVMFunction_real_to_int : public VMIntResultFunction {
365    public:
366        vmint minRequiredArgs() const OVERRIDE { return 1; }
367        vmint maxAllowedArgs() const OVERRIDE { return 1; }
368        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
369        ExprType_t argType(vmint iArg) const OVERRIDE { return REAL_EXPR; }
370        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
371    };
372    
373    /**
374     * Implements the built-in int_to_real() script function and its short hand
375     * variant real(). The behaviour of the two built-in script functions are
376     * identical ATM.
377     */
378    class CoreVMFunction_int_to_real : public VMRealResultFunction {
379    public:
380        vmint minRequiredArgs() const OVERRIDE { return 1; }
381        vmint maxAllowedArgs() const OVERRIDE { return 1; }
382        bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
383        ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
384        VMFnResult* exec(VMFnArgs* args) OVERRIDE;
385  };  };
386    
387  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.3076  
changed lines
  Added in v.3573

  ViewVC Help
Powered by ViewVC