82 |
virtual StmtFlags_t resultFlags() { return STMT_SUCCESS; } |
virtual StmtFlags_t resultFlags() { return STMT_SUCCESS; } |
83 |
}; |
}; |
84 |
|
|
85 |
|
/** @brief VM built-in function. |
86 |
|
* |
87 |
|
* Abstract base class for built-in script functions, defining the interface |
88 |
|
* for all built-in script function implementations. |
89 |
|
*/ |
90 |
class VMFunction { |
class VMFunction { |
91 |
public: |
public: |
92 |
|
/** |
93 |
|
* Script data type of the function's return value. If the function does |
94 |
|
* not return any value, then it returns EMPTY_EXPR here. |
95 |
|
*/ |
96 |
virtual ExprType_t returnType() = 0; |
virtual ExprType_t returnType() = 0; |
97 |
|
|
98 |
|
/** |
99 |
|
* Minimum amount of function arguments this function accepts. If a |
100 |
|
* script is calling this function with less arguments, the script |
101 |
|
* parser will throw a parser error. |
102 |
|
*/ |
103 |
virtual int minRequiredArgs() const = 0; |
virtual int minRequiredArgs() const = 0; |
104 |
|
|
105 |
|
/** |
106 |
|
* Maximum amount of function arguments this functions accepts. If a |
107 |
|
* script is calling this function with more arguments, the script |
108 |
|
* parser will throw a parser error. |
109 |
|
*/ |
110 |
virtual int maxAllowedArgs() const = 0; |
virtual int maxAllowedArgs() const = 0; |
111 |
|
|
112 |
|
/** |
113 |
|
* Script data type of the function's @c iArg 'th function argument. |
114 |
|
* The information provided here is less strong than acceptsArgType(). |
115 |
|
* The parser will compare argument data types provided in scripts by |
116 |
|
* calling cceptsArgType(). The return value of argType() is used by the |
117 |
|
* parser instead to show an appropriate parser error which data type |
118 |
|
* this function usually expects as "default" data type. Reason: a |
119 |
|
* function may accept multiple data types for a certain function |
120 |
|
* argument and would automatically cast the passed argument value in |
121 |
|
* that case to the type it actually needs. |
122 |
|
* |
123 |
|
* @param iArg - index of the function argument in question |
124 |
|
*/ |
125 |
virtual ExprType_t argType(int iArg) const = 0; |
virtual ExprType_t argType(int iArg) const = 0; |
126 |
|
|
127 |
|
/** |
128 |
|
* This function is called by the parser to check whether arguments |
129 |
|
* passed in scripts to this function are accepted by this function. If |
130 |
|
* a script calls this function with an argument's data type not |
131 |
|
* accepted by this function, the parser will throw a parser error. |
132 |
|
* |
133 |
|
* @param iArg - index of the function argument in question |
134 |
|
* @param type - script data type used for this function argument by |
135 |
|
* currently parsed script |
136 |
|
*/ |
137 |
virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0; |
virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0; |
138 |
|
|
139 |
|
/** |
140 |
|
* Implements the actual function execution. This function is called by |
141 |
|
* the VM when this function shall be executed at script runtime. |
142 |
|
* |
143 |
|
* @param args - function arguments for executing this built-in function |
144 |
|
*/ |
145 |
virtual VMFnResult* exec(VMFnArgs* args) = 0; |
virtual VMFnResult* exec(VMFnArgs* args) = 0; |
146 |
|
|
147 |
|
/** |
148 |
|
* Concenience method for function implementations to show warning |
149 |
|
* messages. |
150 |
|
* |
151 |
|
* @param txt - warning text |
152 |
|
*/ |
153 |
|
void wrnMsg(const String& txt); |
154 |
|
|
155 |
|
/** |
156 |
|
* Concenience method for function implementations to show error |
157 |
|
* messages. |
158 |
|
* |
159 |
|
* @param txt - error text |
160 |
|
*/ |
161 |
|
void errMsg(const String& txt); |
162 |
}; |
}; |
163 |
|
|
164 |
/** |
/** |
280 |
VMInt8Array() : data(NULL), size(0) {} |
VMInt8Array() : data(NULL), size(0) {} |
281 |
}; |
}; |
282 |
|
|
283 |
|
/** @brief Provider for built-in script functions and variables. |
284 |
|
* |
285 |
|
* Abstract base class defining the interface for all classes which add and |
286 |
|
* implement built-in script functions and built-in script variables. |
287 |
|
*/ |
288 |
class VMFunctionProvider { |
class VMFunctionProvider { |
289 |
public: |
public: |
290 |
|
/** |
291 |
|
* Returns pointer to the built-in function with the given function |
292 |
|
* name, or NULL if there is no built-in function with that name. |
293 |
|
* |
294 |
|
* @param name - function name |
295 |
|
*/ |
296 |
virtual VMFunction* functionByName(const String& name) = 0; |
virtual VMFunction* functionByName(const String& name) = 0; |
297 |
|
|
298 |
|
/** |
299 |
|
* Returns a variable name indexed map of all built-in script variables |
300 |
|
* which point to native "int" (usually 32 bit) variables. |
301 |
|
*/ |
302 |
virtual std::map<String,VMIntRelPtr*> builtInIntVariables() = 0; |
virtual std::map<String,VMIntRelPtr*> builtInIntVariables() = 0; |
303 |
|
|
304 |
|
/** |
305 |
|
* Returns a variable name indexed map of all built-in script variables |
306 |
|
* which point to native "int8_t" (8 bit) variables. |
307 |
|
*/ |
308 |
virtual std::map<String,VMInt8Array*> builtInIntArrayVariables() = 0; |
virtual std::map<String,VMInt8Array*> builtInIntArrayVariables() = 0; |
309 |
|
|
310 |
|
/** |
311 |
|
* Returns a variable name indexed map of all built-in constant script |
312 |
|
* variables, which never change their value at runtime. |
313 |
|
*/ |
314 |
virtual std::map<String,int> builtInConstIntVariables() = 0; |
virtual std::map<String,int> builtInConstIntVariables() = 0; |
315 |
}; |
}; |
316 |
|
|
318 |
* |
* |
319 |
* An instance of this abstract base class represents exactly one execution |
* An instance of this abstract base class represents exactly one execution |
320 |
* state of a virtual machine. This encompasses most notably the VM |
* state of a virtual machine. This encompasses most notably the VM |
321 |
* execution stack, and VM polyphonic variables. You might see it as one |
* execution stack, and VM polyphonic variables. It does not contain global |
322 |
* virtual thread of the virtual machine. |
* variable. Global variables are contained in the VMParserContext object. |
323 |
|
* You might see a VMExecContext object as one virtual thread of the virtual |
324 |
|
* machine. |
325 |
|
* |
326 |
|
* In contrast to a VMParserContext, a VMExecContext is not tied to a |
327 |
|
* ScriptVM instance. Thus you can use a VMExecContext with different |
328 |
|
* ScriptVM instances, however not concurrently at the same time. |
329 |
* |
* |
330 |
* @see VMParserContext |
* @see VMParserContext |
331 |
*/ |
*/ |