/[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 2619 by schoenebeck, Wed Jun 11 13:24:32 2014 UTC revision 3076 by schoenebeck, Thu Jan 5 18:00:52 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014 Christian Schoenebeck   * Copyright (c) 2014-2016 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 16  Line 16 
16  namespace LinuxSampler {  namespace LinuxSampler {
17            
18  class ScriptVM;  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 : public VMFnResult, public VMExpr {  class VMEmptyResult : public VMFnResult, public VMExpr {
28  public:  public:
29      StmtFlags_t flags;      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    /**
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 : public VMFnResult, public VMIntExpr {  class VMIntResult : public VMFnResult, public VMIntExpr {
43  public:  public:
44      StmtFlags_t flags;      StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
45      int value;      int value; ///< result value of the function call
46    
47      VMIntResult() : flags(STMT_SUCCESS) {}      VMIntResult() : flags(STMT_SUCCESS) {}
48      int evalInt() { return value; }      int 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  };  };
53    
54    /**
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  class VMStringResult : public VMFnResult, public VMStringExpr {  class VMStringResult : public VMFnResult, public VMStringExpr {
59  public:  public:
60      StmtFlags_t flags;      StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
61      String value;      String value; ///< result value of the function call
62    
63      VMStringResult() : flags(STMT_SUCCESS) {}      VMStringResult() : flags(STMT_SUCCESS) {}
64      String evalStr() { return value; }      String evalStr() OVERRIDE { return value; }
65      VMExpr* resultValue() { return this; }      VMExpr* resultValue() OVERRIDE { return this; }
66      StmtFlags_t resultFlags() { return flags; }      StmtFlags_t resultFlags() OVERRIDE { return flags; }
67        bool isConstExpr() const OVERRIDE { return false; }
68  };  };
69    
70    /**
71     * Abstract base class for built-in script functions which do not return any
72     * function return value (void).
73     */
74  class VMEmptyResultFunction : public VMFunction {  class VMEmptyResultFunction : public VMFunction {
75  protected:  protected:
76      ExprType_t returnType() { return EMPTY_EXPR; }      virtual ~VMEmptyResultFunction() {}
77        ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; }
78      VMFnResult* errorResult();      VMFnResult* errorResult();
79      VMFnResult* successResult();      VMFnResult* successResult();
80        bool modifiesArg(int iArg) const OVERRIDE { return false; }
81  protected:  protected:
82      VMEmptyResult result;      VMEmptyResult result;
83  };  };
84    
85    /**
86     * Abstract base class for built-in script functions which return an integer
87     * (scalar) as their function return value.
88     */
89  class VMIntResultFunction : public VMFunction {  class VMIntResultFunction : public VMFunction {
90  protected:  protected:
91      ExprType_t returnType() { return INT_EXPR; }      virtual ~VMIntResultFunction() {}
92        ExprType_t returnType() OVERRIDE { return INT_EXPR; }
93      VMFnResult* errorResult(int i = 0);      VMFnResult* errorResult(int i = 0);
94      VMFnResult* successResult(int i = 0);      VMFnResult* successResult(int i = 0);
95        bool modifiesArg(int iArg) const OVERRIDE { return false; }
96  protected:  protected:
97      VMIntResult result;      VMIntResult result;
98  };  };
99    
100    /**
101     * Abstract base class for built-in script functions which return a string as
102     * their function return value.
103     */
104  class VMStringResultFunction : public VMFunction {  class VMStringResultFunction : public VMFunction {
105  protected:  protected:
106      ExprType_t returnType() { return STRING_EXPR; }      virtual ~VMStringResultFunction() {}
107        ExprType_t returnType() OVERRIDE { return STRING_EXPR; }
108      VMFnResult* errorResult(const String& s = "");      VMFnResult* errorResult(const String& s = "");
109      VMFnResult* successResult(const String& s = "");      VMFnResult* successResult(const String& s = "");
110        bool modifiesArg(int iArg) const OVERRIDE { return false; }
111  protected:  protected:
112      VMStringResult result;      VMStringResult result;
113  };  };
114    
115    
116    ///////////////////////////////////////////////////////////////////////////
117    // implementations of core built-in script functions ...
118    
119    /**
120     * Implements the built-in message() script function.
121     */
122  class CoreVMFunction_message : public VMEmptyResultFunction {  class CoreVMFunction_message : public VMEmptyResultFunction {
123  public:  public:
124      int minRequiredArgs() const { return 1; }      int minRequiredArgs() const { return 1; }
# Line 85  public: Line 128  public:
128      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
129  };  };
130    
131    /**
132     * Implements the built-in exit() script function.
133     */
134  class CoreVMFunction_exit : public VMEmptyResultFunction {  class CoreVMFunction_exit : public VMEmptyResultFunction {
135  public:  public:
136      int minRequiredArgs() const { return 0; }      int minRequiredArgs() const { return 0; }
# Line 94  public: Line 140  public:
140      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
141  };  };
142    
143    /**
144     * Implements the built-in wait() script function.
145     */
146  class CoreVMFunction_wait : public VMEmptyResultFunction {  class CoreVMFunction_wait : public VMEmptyResultFunction {
147  public:  public:
148      CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}      CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
# Line 106  protected: Line 155  protected:
155      ScriptVM* vm;      ScriptVM* vm;
156  };  };
157    
158    /**
159     * Implements the built-in abs() script function.
160     */
161  class CoreVMFunction_abs : public VMIntResultFunction {  class CoreVMFunction_abs : public VMIntResultFunction {
162  public:  public:
163      int minRequiredArgs() const { return 1; }      int minRequiredArgs() const { return 1; }
# Line 115  public: Line 167  public:
167      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
168  };  };
169    
170    /**
171     * Implements the built-in random() script function.
172     */
173  class CoreVMFunction_random : public VMIntResultFunction {  class CoreVMFunction_random : public VMIntResultFunction {
174  public:  public:
175      int minRequiredArgs() const { return 2; }      int minRequiredArgs() const { return 2; }
# Line 124  public: Line 179  public:
179      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
180  };  };
181    
182    /**
183     * Implements the built-in num_elements() script function.
184     */
185  class CoreVMFunction_num_elements : public VMIntResultFunction {  class CoreVMFunction_num_elements : public VMIntResultFunction {
186  public:  public:
187      int minRequiredArgs() const { return 1; }      int minRequiredArgs() const { return 1; }
# Line 133  public: Line 191  public:
191      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
192  };  };
193    
194    /**
195     * Implements the built-in inc() script function.
196     */
197    class CoreVMFunction_inc : public VMIntResultFunction {
198    public:
199        int minRequiredArgs() const { return 1; }
200        int maxAllowedArgs() const { return 1; }
201        bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }
202        ExprType_t argType(int iArg) const { return INT_EXPR; }
203        bool modifiesArg(int iArg) const { return true; }
204        VMFnResult* exec(VMFnArgs* args);
205    };
206    
207    /**
208     * Implements the built-in dec() script function.
209     */
210    class CoreVMFunction_dec : public VMIntResultFunction {
211    public:
212        int minRequiredArgs() const { return 1; }
213        int maxAllowedArgs() const { return 1; }
214        bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }
215        ExprType_t argType(int iArg) const { return INT_EXPR; }
216        bool modifiesArg(int iArg) const { return true; }
217        VMFnResult* exec(VMFnArgs* args);
218    };
219    
220    /**
221     * Implements the built-in in_range() script function.
222     */
223    class CoreVMFunction_in_range : public VMIntResultFunction {
224    public:
225        int minRequiredArgs() const { return 3; }
226        int maxAllowedArgs() const { return 3; }
227        bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }
228        ExprType_t argType(int iArg) const { return INT_EXPR; }
229        VMFnResult* exec(VMFnArgs* args);
230    };
231    
232    /**
233     * Implements the built-in sh_left() script function.
234     */
235    class CoreVMFunction_sh_left : public VMIntResultFunction {
236    public:
237        int minRequiredArgs() const { return 2; }
238        int maxAllowedArgs() const { return 2; }
239        bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }
240        ExprType_t argType(int iArg) const { return INT_EXPR; }
241        VMFnResult* exec(VMFnArgs* args);
242    };
243    
244    /**
245     * Implements the built-in sh_right() script function.
246     */
247    class CoreVMFunction_sh_right : public VMIntResultFunction {
248    public:
249        int minRequiredArgs() const { return 2; }
250        int maxAllowedArgs() const { return 2; }
251        bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }
252        ExprType_t argType(int iArg) const { return INT_EXPR; }
253        VMFnResult* exec(VMFnArgs* args);
254    };
255    
256    /**
257     * Implements the built-in min() script function.
258     */
259    class CoreVMFunction_min : public VMIntResultFunction {
260    public:
261        int minRequiredArgs() const { return 2; }
262        int maxAllowedArgs() const { return 2; }
263        bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }
264        ExprType_t argType(int iArg) const { return INT_EXPR; }
265        VMFnResult* exec(VMFnArgs* args);
266    };
267    
268    /**
269     * Implements the built-in max() script function.
270     */
271    class CoreVMFunction_max : public VMIntResultFunction {
272    public:
273        int minRequiredArgs() const { return 2; }
274        int maxAllowedArgs() const { return 2; }
275        bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; }
276        ExprType_t argType(int iArg) const { return INT_EXPR; }
277        VMFnResult* exec(VMFnArgs* args);
278    };
279    
280  } // namespace LinuxSampler  } // namespace LinuxSampler
281    
282  #endif // LS_COREVMFUNCTIONS_H  #endif // LS_COREVMFUNCTIONS_H

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

  ViewVC Help
Powered by ViewVC