160 |
* @see exprType() |
* @see exprType() |
161 |
*/ |
*/ |
162 |
VMIntArrayExpr* asIntArray() const; |
VMIntArrayExpr* asIntArray() const; |
163 |
|
|
164 |
|
/** |
165 |
|
* Returns true in case this expression can be considered to be a |
166 |
|
* constant expression. A constant expression will retain the same |
167 |
|
* value throughout the entire life time of a script and the |
168 |
|
* expression's constant value may be evaluated already at script |
169 |
|
* parse time, which may result in performance benefits during script |
170 |
|
* runtime. |
171 |
|
* |
172 |
|
* @b NOTE: A constant expression is per se always also non modifyable. |
173 |
|
* But a non modifyable expression may not necessarily be a constant |
174 |
|
* expression! |
175 |
|
* |
176 |
|
* @see isModifyable() |
177 |
|
*/ |
178 |
|
virtual bool isConstExpr() const = 0; |
179 |
|
|
180 |
|
/** |
181 |
|
* Returns true in case this expression is allowed to be modified. |
182 |
|
* If this method returns @c false then this expression must be handled |
183 |
|
* as read-only expression, which means that assigning a new value to it |
184 |
|
* is either not possible or not allowed. |
185 |
|
* |
186 |
|
* @b NOTE: A constant expression is per se always also non modifyable. |
187 |
|
* But a non modifyable expression may not necessarily be a constant |
188 |
|
* expression! |
189 |
|
* |
190 |
|
* @see isConstExpr() |
191 |
|
*/ |
192 |
|
bool isModifyable() const; |
193 |
}; |
}; |
194 |
|
|
195 |
/** @brief Virtual machine integer expression |
/** @brief Virtual machine integer expression |
396 |
virtual ExprType_t argType(int iArg) const = 0; |
virtual ExprType_t argType(int iArg) const = 0; |
397 |
|
|
398 |
/** |
/** |
399 |
* This function is called by the parser to check whether arguments |
* This method is called by the parser to check whether arguments |
400 |
* passed in scripts to this function are accepted by this function. If |
* passed in scripts to this function are accepted by this function. If |
401 |
* a script calls this function with an argument's data type not |
* a script calls this function with an argument's data type not |
402 |
* accepted by this function, the parser will throw a parser error. On |
* accepted by this function, the parser will throw a parser error. On |
414 |
virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0; |
virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0; |
415 |
|
|
416 |
/** |
/** |
417 |
|
* This method is called by the parser to check whether some arguments |
418 |
|
* (and if yes which ones) passed to this script function will be |
419 |
|
* modified by this script function. Most script functions simply use |
420 |
|
* their arguments as inputs, that is they only read the argument's |
421 |
|
* values. However some script function may also use passed |
422 |
|
* argument(s) as output variables. In this case the function |
423 |
|
* implementation must return @c true for the respective argument |
424 |
|
* index here. |
425 |
|
* |
426 |
|
* @param iArg - index of the function argument in question |
427 |
|
* (must be between 0 .. maxAllowedArgs() - 1) |
428 |
|
*/ |
429 |
|
virtual bool modifiesArg(int iArg) const = 0; |
430 |
|
|
431 |
|
/** |
432 |
* Implements the actual function execution. This exec() method is |
* Implements the actual function execution. This exec() method is |
433 |
* called by the VM whenever this function implementation shall be |
* called by the VM whenever this function implementation shall be |
434 |
* executed at script runtime. This method blocks until the function |
* executed at script runtime. This method blocks until the function |
468 |
struct VMRelPtr { |
struct VMRelPtr { |
469 |
void** base; ///< Base pointer. |
void** base; ///< Base pointer. |
470 |
int offset; ///< Offset (in bytes) relative to base pointer. |
int offset; ///< Offset (in bytes) relative to base pointer. |
471 |
|
bool readonly; ///< Whether the pointed data may be modified or just be read. |
472 |
}; |
}; |
473 |
|
|
474 |
/** @brief Pointer to built-in VM integer variable (of C/C++ type int). |
/** @brief Pointer to built-in VM integer variable (of C/C++ type int). |
496 |
VMIntRelPtr() { |
VMIntRelPtr() { |
497 |
base = NULL; |
base = NULL; |
498 |
offset = 0; |
offset = 0; |
499 |
|
readonly = false; |
500 |
} |
} |
501 |
VMIntRelPtr(const VMRelPtr& data) { |
VMIntRelPtr(const VMRelPtr& data) { |
502 |
base = data.base; |
base = data.base; |
503 |
offset = data.offset; |
offset = data.offset; |
504 |
|
readonly = false; |
505 |
} |
} |
506 |
virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; } |
virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; } |
507 |
virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; } |
virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; } |
584 |
#define DECLARE_VMINT(basePtr, T_struct, T_member) ( \ |
#define DECLARE_VMINT(basePtr, T_struct, T_member) ( \ |
585 |
(VMRelPtr) { \ |
(VMRelPtr) { \ |
586 |
(void**) &basePtr, \ |
(void**) &basePtr, \ |
587 |
offsetof(T_struct, T_member) \ |
offsetof(T_struct, T_member), \ |
588 |
|
false \ |
589 |
} \ |
} \ |
590 |
) \ |
) \ |
591 |
|
|
592 |
|
/** |
593 |
|
* Same as DECLARE_VMINT(), but this one defines the VMIntRelPtr and |
594 |
|
* VMInt8RelPtr structures to be of read-only type. That means the script |
595 |
|
* parser will abort any script at parser time if the script is trying to |
596 |
|
* modify such a read-only built-in variable. |
597 |
|
* |
598 |
|
* @b NOTE: this is only intended for built-in read-only variables that |
599 |
|
* may change during runtime! If your built-in variable's data is rather |
600 |
|
* already available at parser time and won't change during runtime, then |
601 |
|
* you should rather register a built-in constant in your VM class instead! |
602 |
|
* |
603 |
|
* @see ScriptVM::builtInConstIntVariables() |
604 |
|
*/ |
605 |
|
#define DECLARE_VMINT_READONLY(basePtr, T_struct, T_member) ( \ |
606 |
|
(VMRelPtr) { \ |
607 |
|
(void**) &basePtr, \ |
608 |
|
offsetof(T_struct, T_member), \ |
609 |
|
true \ |
610 |
|
} \ |
611 |
|
) \ |
612 |
|
|
613 |
/** @brief Built-in VM 8 bit integer array variable. |
/** @brief Built-in VM 8 bit integer array variable. |
614 |
* |
* |
615 |
* Used for defining built-in integer array script variables (8 bit per |
* Used for defining built-in integer array script variables (8 bit per |
623 |
VMInt8Array() : data(NULL), size(0) {} |
VMInt8Array() : data(NULL), size(0) {} |
624 |
}; |
}; |
625 |
|
|
626 |
|
/** @brief Virtual machine script variable. |
627 |
|
* |
628 |
|
* Common interface for all variables accessed in scripts. |
629 |
|
*/ |
630 |
|
class VMVariable : virtual public VMExpr { |
631 |
|
public: |
632 |
|
/** |
633 |
|
* Whether a script may modify the content of this variable by |
634 |
|
* assigning a new value to it. |
635 |
|
* |
636 |
|
* @see isConstExpr(), assign() |
637 |
|
*/ |
638 |
|
virtual bool isAssignable() const = 0; |
639 |
|
|
640 |
|
/** |
641 |
|
* In case this variable is assignable, this method will be called to |
642 |
|
* perform the value assignment to this variable with @a expr |
643 |
|
* reflecting the new value to be assigned. |
644 |
|
* |
645 |
|
* @param expr - new value to be assigned to this variable |
646 |
|
*/ |
647 |
|
virtual void assignExpr(VMExpr* expr) = 0; |
648 |
|
}; |
649 |
|
|
650 |
/** @brief Dynamically executed variable (abstract base class). |
/** @brief Dynamically executed variable (abstract base class). |
651 |
* |
* |
652 |
* Interface for the implementation of a dynamically generated content of |
* Interface for the implementation of a dynamically generated content of |
657 |
* to a dynamic variable some native code is executed to actually generate |
* to a dynamic variable some native code is executed to actually generate |
658 |
* and provide the content (value) of this type of variable. |
* and provide the content (value) of this type of variable. |
659 |
*/ |
*/ |
660 |
class VMDynVar : virtual public VMExpr { |
class VMDynVar : public VMVariable { |
661 |
public: |
public: |
662 |
/** |
/** |
|
* Whether a script may modify the content of this dynamic variable by |
|
|
* assigning a new value to it. |
|
|
* |
|
|
* @see isConstExpr(), assign() |
|
|
*/ |
|
|
virtual bool isAssignable() const = 0; |
|
|
|
|
|
/** |
|
663 |
* Returns true in case this dynamic variable can be considered to be a |
* Returns true in case this dynamic variable can be considered to be a |
664 |
* constant expression. A constant expression will retain the same value |
* constant expression. A constant expression will retain the same value |
665 |
* throughout the entire life time of a script and the expression's |
* throughout the entire life time of a script and the expression's |
695 |
* |
* |
696 |
* @see isAssignable() |
* @see isAssignable() |
697 |
*/ |
*/ |
698 |
virtual bool isConstExpr() const { return false; } |
bool isConstExpr() const OVERRIDE { return false; } |
699 |
|
|
700 |
/** |
/** |
701 |
* In case this dynamic variable is assignable, the new value (content) |
* In case this dynamic variable is assignable, the new value (content) |
707 |
* |
* |
708 |
* @param expr - new value to be assigned to this variable |
* @param expr - new value to be assigned to this variable |
709 |
*/ |
*/ |
710 |
virtual void assign(VMExpr* expr) {} |
void assignExpr(VMExpr* expr) OVERRIDE {} |
711 |
}; |
}; |
712 |
|
|
713 |
/** @brief Dynamically executed variable (of integer data type). |
/** @brief Dynamically executed variable (of integer data type). |