/[svn]/linuxsampler/trunk/src/scriptvm/common.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/common.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

  ViewVC Help
Powered by ViewVC