1 |
/* |
/* |
2 |
* Copyright (c) 2014-2015 Christian Schoenebeck |
* Copyright (c) 2014-2016 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
40 |
* - 1. Create an instance of this ScriptVM class (or of one of its deriving |
* - 1. Create an instance of this ScriptVM class (or of one of its deriving |
41 |
* classes). |
* classes). |
42 |
* - 2. Load a script by passing its source code to method loadScript(), |
* - 2. Load a script by passing its source code to method loadScript(), |
43 |
* which will return the parsed represenation of the script. |
* which will return the parsed representation of the script. |
44 |
* - 3. Create a VM execution context by calling createExecContext(). |
* - 3. Create a VM execution context by calling createExecContext(). |
45 |
* - 4. Execute the script by calling method exec(). |
* - 4. Execute the script by calling method exec(). |
46 |
* |
* |
61 |
|
|
62 |
/** |
/** |
63 |
* Loads a script given by its source code (passed as argument @a s to |
* Loads a script given by its source code (passed as argument @a s to |
64 |
* this method) and returns the parsed represenation of that script. |
* this method) and returns the parsed representation of that script. |
65 |
* After calling this method you must check the returned VMParserContext |
* After calling this method you must check the returned VMParserContext |
66 |
* object whether there had been any parser errors. If there were no |
* object whether there had been any parser errors. If there were no |
67 |
* parser errors, you may pass the VMParserContext object to method |
* parser errors, you may pass the VMParserContext object to method |
68 |
* exec() for actually executing the script. |
* exec() for actually executing the script. |
69 |
* |
* |
70 |
* @param s - entire source code of the script to be loaded |
* @param s - entire source code of the script to be loaded |
71 |
* @returns parsed represenation of the script |
* @returns parsed representation of the script |
72 |
*/ |
*/ |
73 |
VMParserContext* loadScript(const String& s); |
VMParserContext* loadScript(const String& s); |
74 |
|
|
78 |
* |
* |
79 |
* @param is - input stream from which the entire source code of the |
* @param is - input stream from which the entire source code of the |
80 |
* script is to be read and loaded from |
* script is to be read and loaded from |
81 |
* @returns parsed represenation of the script |
* @returns parsed representation of the script |
82 |
*/ |
*/ |
83 |
VMParserContext* loadScript(std::istream* is); |
VMParserContext* loadScript(std::istream* is); |
84 |
|
|
87 |
* argument @a context, to stdout. This method is for debugging purposes |
* argument @a context, to stdout. This method is for debugging purposes |
88 |
* only. |
* only. |
89 |
* |
* |
90 |
* @param context - parsed represenation of the script |
* @param context - parsed representation of the script |
91 |
|
* @see loadScript() |
92 |
*/ |
*/ |
93 |
void dumpParsedScript(VMParserContext* context); |
void dumpParsedScript(VMParserContext* context); |
94 |
|
|
98 |
* general real-time design of this virtual machine, the VM execution |
* general real-time design of this virtual machine, the VM execution |
99 |
* context differs for every script. So you must (re)create the |
* context differs for every script. So you must (re)create the |
100 |
* execution context for each script being loaded. |
* execution context for each script being loaded. |
101 |
|
* |
102 |
|
* @param parserContext - parsed representation of the script |
103 |
|
* @see loadScript() |
104 |
*/ |
*/ |
105 |
VMExecContext* createExecContext(VMParserContext* parserContext); |
VMExecContext* createExecContext(VMParserContext* parserContext); |
106 |
|
|
114 |
* This method usually blocks until the entire script event handler |
* This method usually blocks until the entire script event handler |
115 |
* block has been executed completely. It may however also return before |
* block has been executed completely. It may however also return before |
116 |
* completion if either a) a script runtime error occurred or b) the |
* completion if either a) a script runtime error occurred or b) the |
117 |
* script was suspened by the VM (either because script execution |
* script was suspended by the VM (either because script execution |
118 |
* exceeded a certain limit of time or the script called the built-in |
* exceeded a certain limit of time or the script called the built-in |
119 |
* wait() function). You must check the return value of this method to |
* wait() function). You must check the return value of this method to |
120 |
* find out which case applies. |
* find out which case applies. |
121 |
* |
* |
122 |
* @param parserContext - parsed represenation of the script |
* @param parserContext - parsed representation of the script (see loadScript()) |
123 |
* @param execContext - VM execution context (see createExecContext()) |
* @param execContext - VM execution context (see createExecContext()) |
124 |
* @param handler - precise event handler (i.e. "on note ... end on" |
* @param handler - precise event handler (i.e. "on note ... end on" |
125 |
* code block) to be executed |
* code block) to be executed |
181 |
*/ |
*/ |
182 |
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
183 |
|
|
184 |
|
VMEventHandler* currentVMEventHandler(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
185 |
VMParserContext* currentVMParserContext(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
VMParserContext* currentVMParserContext(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
186 |
VMExecContext* currentVMExecContext(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
VMExecContext* currentVMExecContext(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
187 |
|
|
188 |
protected: |
protected: |
189 |
|
VMEventHandler* m_eventHandler; |
190 |
ParserContext* m_parserContext; |
ParserContext* m_parserContext; |
191 |
CoreVMFunction_message fnMessage; |
CoreVMFunction_message fnMessage; |
192 |
CoreVMFunction_exit fnExit; |
CoreVMFunction_exit fnExit; |