/[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 2726 by schoenebeck, Wed Jun 11 13:24:32 2014 UTC revision 2727 by schoenebeck, Tue Mar 31 17:46:11 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014 Christian Schoenebeck   * Copyright (c) 2014-2015 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 { return EMPTY_EXPR; }
# Line 27  public: Line 34  public:
34      StmtFlags_t resultFlags() { return flags; }      StmtFlags_t resultFlags() { return flags; }
35  };  };
36    
37    /**
38     * An instance of this class is returned by built-in function implementations
39     * which return an integer value as function return value.
40     */
41  class VMIntResult : public VMFnResult, public VMIntExpr {  class VMIntResult : public VMFnResult, public VMIntExpr {
42  public:  public:
43      StmtFlags_t flags;      StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
44      int value;      int value; ///< result value of the function call
45    
46      VMIntResult() : flags(STMT_SUCCESS) {}      VMIntResult() : flags(STMT_SUCCESS) {}
47      int evalInt() { return value; }      int evalInt() { return value; }
# Line 38  public: Line 49  public:
49      StmtFlags_t resultFlags() { return flags; }      StmtFlags_t resultFlags() { return flags; }
50  };  };
51    
52    /**
53     * An instance of this class is returned by built-in function implementations
54     * which return a string value as function return value.
55     */
56  class VMStringResult : public VMFnResult, public VMStringExpr {  class VMStringResult : public VMFnResult, public VMStringExpr {
57  public:  public:
58      StmtFlags_t flags;      StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
59      String value;      String value; ///< result value of the function call
60    
61      VMStringResult() : flags(STMT_SUCCESS) {}      VMStringResult() : flags(STMT_SUCCESS) {}
62      String evalStr() { return value; }      String evalStr() { return value; }
# Line 49  public: Line 64  public:
64      StmtFlags_t resultFlags() { return flags; }      StmtFlags_t resultFlags() { return flags; }
65  };  };
66    
67    /**
68     * Abstract base class for built-in script functions which do not return any
69     * function return value (void).
70     */
71  class VMEmptyResultFunction : public VMFunction {  class VMEmptyResultFunction : public VMFunction {
72  protected:  protected:
73      ExprType_t returnType() { return EMPTY_EXPR; }      ExprType_t returnType() { return EMPTY_EXPR; }
# Line 58  protected: Line 77  protected:
77      VMEmptyResult result;      VMEmptyResult result;
78  };  };
79    
80    /**
81     * Abstract base class for built-in script functions which return an integer
82     * (scalar) as their function return value.
83     */
84  class VMIntResultFunction : public VMFunction {  class VMIntResultFunction : public VMFunction {
85  protected:  protected:
86      ExprType_t returnType() { return INT_EXPR; }      ExprType_t returnType() { return INT_EXPR; }
# Line 67  protected: Line 90  protected:
90      VMIntResult result;      VMIntResult result;
91  };  };
92    
93    /**
94     * Abstract base class for built-in script functions which return a string as
95     * their function return value.
96     */
97  class VMStringResultFunction : public VMFunction {  class VMStringResultFunction : public VMFunction {
98  protected:  protected:
99      ExprType_t returnType() { return STRING_EXPR; }      ExprType_t returnType() { return STRING_EXPR; }
# Line 76  protected: Line 103  protected:
103      VMStringResult result;      VMStringResult result;
104  };  };
105    
106    
107    ///////////////////////////////////////////////////////////////////////////
108    // implementations of core built-in script functions ...
109    
110    /**
111     * Implements the built-in message() script function.
112     */
113  class CoreVMFunction_message : public VMEmptyResultFunction {  class CoreVMFunction_message : public VMEmptyResultFunction {
114  public:  public:
115      int minRequiredArgs() const { return 1; }      int minRequiredArgs() const { return 1; }
# Line 85  public: Line 119  public:
119      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
120  };  };
121    
122    /**
123     * Implements the built-in exit() script function.
124     */
125  class CoreVMFunction_exit : public VMEmptyResultFunction {  class CoreVMFunction_exit : public VMEmptyResultFunction {
126  public:  public:
127      int minRequiredArgs() const { return 0; }      int minRequiredArgs() const { return 0; }
# Line 94  public: Line 131  public:
131      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
132  };  };
133    
134    /**
135     * Implements the built-in wait() script function.
136     */
137  class CoreVMFunction_wait : public VMEmptyResultFunction {  class CoreVMFunction_wait : public VMEmptyResultFunction {
138  public:  public:
139      CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}      CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
# Line 106  protected: Line 146  protected:
146      ScriptVM* vm;      ScriptVM* vm;
147  };  };
148    
149    /**
150     * Implements the built-in abs() script function.
151     */
152  class CoreVMFunction_abs : public VMIntResultFunction {  class CoreVMFunction_abs : public VMIntResultFunction {
153  public:  public:
154      int minRequiredArgs() const { return 1; }      int minRequiredArgs() const { return 1; }
# Line 115  public: Line 158  public:
158      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
159  };  };
160    
161    /**
162     * Implements the built-in random() script function.
163     */
164  class CoreVMFunction_random : public VMIntResultFunction {  class CoreVMFunction_random : public VMIntResultFunction {
165  public:  public:
166      int minRequiredArgs() const { return 2; }      int minRequiredArgs() const { return 2; }
# Line 124  public: Line 170  public:
170      VMFnResult* exec(VMFnArgs* args);      VMFnResult* exec(VMFnArgs* args);
171  };  };
172    
173    /**
174     * Implements the built-in num_elements() script function.
175     */
176  class CoreVMFunction_num_elements : public VMIntResultFunction {  class CoreVMFunction_num_elements : public VMIntResultFunction {
177  public:  public:
178      int minRequiredArgs() const { return 1; }      int minRequiredArgs() const { return 1; }

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

  ViewVC Help
Powered by ViewVC