50 |
|
|
51 |
class VMIntExpr; |
class VMIntExpr; |
52 |
class VMStringExpr; |
class VMStringExpr; |
53 |
|
class VMIntArrayExpr; |
54 |
|
class VMStringArrayExpr; |
55 |
|
|
56 |
class VMExpr { |
class VMExpr { |
57 |
public: |
public: |
58 |
virtual ExprType_t exprType() const = 0; |
virtual ExprType_t exprType() const = 0; |
59 |
VMIntExpr* asInt() const; |
VMIntExpr* asInt() const; |
60 |
VMStringExpr* asString() const; |
VMStringExpr* asString() const; |
61 |
|
VMIntArrayExpr* asIntArray() const; |
62 |
}; |
}; |
63 |
|
|
64 |
class VMIntExpr : virtual public VMExpr { |
class VMIntExpr : virtual public VMExpr { |
73 |
ExprType_t exprType() const { return STRING_EXPR; } |
ExprType_t exprType() const { return STRING_EXPR; } |
74 |
}; |
}; |
75 |
|
|
76 |
|
class VMArrayExpr : virtual public VMExpr { |
77 |
|
public: |
78 |
|
virtual int arraySize() const = 0; |
79 |
|
}; |
80 |
|
|
81 |
|
class VMIntArrayExpr : virtual public VMArrayExpr { |
82 |
|
public: |
83 |
|
virtual int evalIntElement(uint i) = 0; |
84 |
|
virtual void assignIntElement(uint i, int value) = 0; |
85 |
|
ExprType_t exprType() const { return INT_ARR_EXPR; } |
86 |
|
}; |
87 |
|
|
88 |
class VMFnArgs { |
class VMFnArgs { |
89 |
public: |
public: |
90 |
virtual int argsCount() const = 0; |
virtual int argsCount() const = 0; |
97 |
virtual StmtFlags_t resultFlags() { return STMT_SUCCESS; } |
virtual StmtFlags_t resultFlags() { return STMT_SUCCESS; } |
98 |
}; |
}; |
99 |
|
|
100 |
|
/** @brief VM built-in function. |
101 |
|
* |
102 |
|
* Abstract base class for built-in script functions, defining the interface |
103 |
|
* for all built-in script function implementations. |
104 |
|
*/ |
105 |
class VMFunction { |
class VMFunction { |
106 |
public: |
public: |
107 |
|
/** |
108 |
|
* Script data type of the function's return value. If the function does |
109 |
|
* not return any value, then it returns EMPTY_EXPR here. |
110 |
|
*/ |
111 |
virtual ExprType_t returnType() = 0; |
virtual ExprType_t returnType() = 0; |
112 |
|
|
113 |
|
/** |
114 |
|
* Minimum amount of function arguments this function accepts. If a |
115 |
|
* script is calling this function with less arguments, the script |
116 |
|
* parser will throw a parser error. |
117 |
|
*/ |
118 |
virtual int minRequiredArgs() const = 0; |
virtual int minRequiredArgs() const = 0; |
119 |
|
|
120 |
|
/** |
121 |
|
* Maximum amount of function arguments this functions accepts. If a |
122 |
|
* script is calling this function with more arguments, the script |
123 |
|
* parser will throw a parser error. |
124 |
|
*/ |
125 |
virtual int maxAllowedArgs() const = 0; |
virtual int maxAllowedArgs() const = 0; |
126 |
|
|
127 |
|
/** |
128 |
|
* Script data type of the function's @c iArg 'th function argument. |
129 |
|
* The information provided here is less strong than acceptsArgType(). |
130 |
|
* The parser will compare argument data types provided in scripts by |
131 |
|
* calling cceptsArgType(). The return value of argType() is used by the |
132 |
|
* parser instead to show an appropriate parser error which data type |
133 |
|
* this function usually expects as "default" data type. Reason: a |
134 |
|
* function may accept multiple data types for a certain function |
135 |
|
* argument and would automatically cast the passed argument value in |
136 |
|
* that case to the type it actually needs. |
137 |
|
* |
138 |
|
* @param iArg - index of the function argument in question |
139 |
|
*/ |
140 |
virtual ExprType_t argType(int iArg) const = 0; |
virtual ExprType_t argType(int iArg) const = 0; |
141 |
|
|
142 |
|
/** |
143 |
|
* This function is called by the parser to check whether arguments |
144 |
|
* passed in scripts to this function are accepted by this function. If |
145 |
|
* a script calls this function with an argument's data type not |
146 |
|
* accepted by this function, the parser will throw a parser error. |
147 |
|
* |
148 |
|
* @param iArg - index of the function argument in question |
149 |
|
* @param type - script data type used for this function argument by |
150 |
|
* currently parsed script |
151 |
|
*/ |
152 |
virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0; |
virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0; |
153 |
|
|
154 |
|
/** |
155 |
|
* Implements the actual function execution. This function is called by |
156 |
|
* the VM when this function shall be executed at script runtime. |
157 |
|
* |
158 |
|
* @param args - function arguments for executing this built-in function |
159 |
|
*/ |
160 |
virtual VMFnResult* exec(VMFnArgs* args) = 0; |
virtual VMFnResult* exec(VMFnArgs* args) = 0; |
161 |
|
|
162 |
|
/** |
163 |
|
* Concenience method for function implementations to show warning |
164 |
|
* messages. |
165 |
|
* |
166 |
|
* @param txt - warning text |
167 |
|
*/ |
168 |
|
void wrnMsg(const String& txt); |
169 |
|
|
170 |
|
/** |
171 |
|
* Concenience method for function implementations to show error |
172 |
|
* messages. |
173 |
|
* |
174 |
|
* @param txt - error text |
175 |
|
*/ |
176 |
|
void errMsg(const String& txt); |
177 |
}; |
}; |
178 |
|
|
179 |
/** |
/** |
295 |
VMInt8Array() : data(NULL), size(0) {} |
VMInt8Array() : data(NULL), size(0) {} |
296 |
}; |
}; |
297 |
|
|
298 |
|
/** @brief Provider for built-in script functions and variables. |
299 |
|
* |
300 |
|
* Abstract base class defining the interface for all classes which add and |
301 |
|
* implement built-in script functions and built-in script variables. |
302 |
|
*/ |
303 |
class VMFunctionProvider { |
class VMFunctionProvider { |
304 |
public: |
public: |
305 |
|
/** |
306 |
|
* Returns pointer to the built-in function with the given function |
307 |
|
* name, or NULL if there is no built-in function with that name. |
308 |
|
* |
309 |
|
* @param name - function name |
310 |
|
*/ |
311 |
virtual VMFunction* functionByName(const String& name) = 0; |
virtual VMFunction* functionByName(const String& name) = 0; |
312 |
|
|
313 |
|
/** |
314 |
|
* Returns a variable name indexed map of all built-in script variables |
315 |
|
* which point to native "int" (usually 32 bit) variables. |
316 |
|
*/ |
317 |
virtual std::map<String,VMIntRelPtr*> builtInIntVariables() = 0; |
virtual std::map<String,VMIntRelPtr*> builtInIntVariables() = 0; |
318 |
|
|
319 |
|
/** |
320 |
|
* Returns a variable name indexed map of all built-in script variables |
321 |
|
* which point to native "int8_t" (8 bit) variables. |
322 |
|
*/ |
323 |
virtual std::map<String,VMInt8Array*> builtInIntArrayVariables() = 0; |
virtual std::map<String,VMInt8Array*> builtInIntArrayVariables() = 0; |
324 |
|
|
325 |
|
/** |
326 |
|
* Returns a variable name indexed map of all built-in constant script |
327 |
|
* variables, which never change their value at runtime. |
328 |
|
*/ |
329 |
virtual std::map<String,int> builtInConstIntVariables() = 0; |
virtual std::map<String,int> builtInConstIntVariables() = 0; |
330 |
}; |
}; |
331 |
|
|
333 |
* |
* |
334 |
* An instance of this abstract base class represents exactly one execution |
* An instance of this abstract base class represents exactly one execution |
335 |
* state of a virtual machine. This encompasses most notably the VM |
* state of a virtual machine. This encompasses most notably the VM |
336 |
* execution stack, and VM polyphonic variables. You might see it as one |
* execution stack, and VM polyphonic variables. It does not contain global |
337 |
* virtual thread of the virtual machine. |
* variable. Global variables are contained in the VMParserContext object. |
338 |
|
* You might see a VMExecContext object as one virtual thread of the virtual |
339 |
|
* machine. |
340 |
|
* |
341 |
|
* In contrast to a VMParserContext, a VMExecContext is not tied to a |
342 |
|
* ScriptVM instance. Thus you can use a VMExecContext with different |
343 |
|
* ScriptVM instances, however not concurrently at the same time. |
344 |
* |
* |
345 |
* @see VMParserContext |
* @see VMParserContext |
346 |
*/ |
*/ |