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 |
* |
* |
15 |
|
|
16 |
#include "../common/global.h" |
#include "../common/global.h" |
17 |
#include "common.h" |
#include "common.h" |
|
#include "CoreVMFunctions.h" |
|
18 |
|
|
19 |
namespace LinuxSampler { |
namespace LinuxSampler { |
20 |
|
|
39 |
* - 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 |
40 |
* classes). |
* classes). |
41 |
* - 2. Load a script by passing its source code to method loadScript(), |
* - 2. Load a script by passing its source code to method loadScript(), |
42 |
* which will return the parsed represenation of the script. |
* which will return the parsed representation of the script. |
43 |
* - 3. Create a VM execution context by calling createExecContext(). |
* - 3. Create a VM execution context by calling createExecContext(). |
44 |
* - 4. Execute the script by calling method exec(). |
* - 4. Execute the script by calling method exec(). |
45 |
* |
* |
60 |
|
|
61 |
/** |
/** |
62 |
* 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 |
63 |
* this method) and returns the parsed represenation of that script. |
* this method) and returns the parsed representation of that script. |
64 |
* After calling this method you must check the returned VMParserContext |
* After calling this method you must check the returned VMParserContext |
65 |
* object whether there had been any parser errors. If there were no |
* object whether there had been any parser errors. If there were no |
66 |
* parser errors, you may pass the VMParserContext object to method |
* parser errors, you may pass the VMParserContext object to method |
67 |
* exec() for actually executing the script. |
* exec() for actually executing the script. |
68 |
* |
* |
69 |
|
* It is your responsibility to free the returned VMParserContext |
70 |
|
* object once you don't need it anymore. |
71 |
|
* |
72 |
* @param s - entire source code of the script to be loaded |
* @param s - entire source code of the script to be loaded |
73 |
* @returns parsed represenation of the script |
* @returns parsed representation of the script |
74 |
*/ |
*/ |
75 |
VMParserContext* loadScript(const String& s); |
VMParserContext* loadScript(const String& s); |
76 |
|
|
80 |
* |
* |
81 |
* @param is - input stream from which the entire source code of the |
* @param is - input stream from which the entire source code of the |
82 |
* script is to be read and loaded from |
* script is to be read and loaded from |
83 |
* @returns parsed represenation of the script |
* @returns parsed representation of the script |
84 |
*/ |
*/ |
85 |
VMParserContext* loadScript(std::istream* is); |
VMParserContext* loadScript(std::istream* is); |
86 |
|
|
87 |
/** |
/** |
88 |
|
* Parses a script's source code (passed as argument @a s to this |
89 |
|
* method), splits that input up in its individual tokens (i.e. |
90 |
|
* keyword, variable name, event name, etc.) and returns all those |
91 |
|
* tokens, for the purpose that the caller can provide syntax syntax |
92 |
|
* highlighting for the passed script. |
93 |
|
* |
94 |
|
* This method is actually not used by the sampler at all, it is rather |
95 |
|
* provided for external script editor applications, to provide them a |
96 |
|
* convenient backend for parsing scripts and providing syntax |
97 |
|
* highlighting. |
98 |
|
* |
99 |
|
* @returns recognized tokens of passed script's source code |
100 |
|
*/ |
101 |
|
std::vector<VMSourceToken> syntaxHighlighting(const String& s); |
102 |
|
|
103 |
|
/** |
104 |
|
* Same as above's syntaxHighlighting() method, but this one reads the |
105 |
|
* script's source code from an input stream object (i.e. stdin or a |
106 |
|
* file). |
107 |
|
* |
108 |
|
* @param is - input stream from which the entire source code of the |
109 |
|
* script is to be read and loaded from |
110 |
|
* @returns recognized tokens of passed script's source code |
111 |
|
*/ |
112 |
|
std::vector<VMSourceToken> syntaxHighlighting(std::istream* is); |
113 |
|
|
114 |
|
/** |
115 |
* Dumps the translated tree of the already parsed script, given by |
* Dumps the translated tree of the already parsed script, given by |
116 |
* argument @a context, to stdout. This method is for debugging purposes |
* argument @a context, to stdout. This method is for debugging purposes |
117 |
* only. |
* only. |
118 |
* |
* |
119 |
* @param context - parsed represenation of the script |
* @param context - parsed representation of the script |
120 |
|
* @see loadScript() |
121 |
*/ |
*/ |
122 |
void dumpParsedScript(VMParserContext* context); |
void dumpParsedScript(VMParserContext* context); |
123 |
|
|
127 |
* general real-time design of this virtual machine, the VM execution |
* general real-time design of this virtual machine, the VM execution |
128 |
* context differs for every script. So you must (re)create the |
* context differs for every script. So you must (re)create the |
129 |
* execution context for each script being loaded. |
* execution context for each script being loaded. |
130 |
|
* |
131 |
|
* @param parserContext - parsed representation of the script |
132 |
|
* @see loadScript() |
133 |
*/ |
*/ |
134 |
VMExecContext* createExecContext(VMParserContext* parserContext); |
VMExecContext* createExecContext(VMParserContext* parserContext); |
135 |
|
|
143 |
* This method usually blocks until the entire script event handler |
* This method usually blocks until the entire script event handler |
144 |
* block has been executed completely. It may however also return before |
* block has been executed completely. It may however also return before |
145 |
* completion if either a) a script runtime error occurred or b) the |
* completion if either a) a script runtime error occurred or b) the |
146 |
* script was suspened by the VM (either because script execution |
* script was suspended by the VM (either because script execution |
147 |
* 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 |
148 |
* wait() function). You must check the return value of this method to |
* wait() function). You must check the return value of this method to |
149 |
* find out which case applies. |
* find out which case applies. |
150 |
* |
* |
151 |
* @param parserContext - parsed represenation of the script |
* @param parserContext - parsed representation of the script (see loadScript()) |
152 |
* @param execContext - VM execution context (see createExecContext()) |
* @param execContext - VM execution context (see createExecContext()) |
153 |
* @param handler - precise event handler (i.e. "on note ... end on" |
* @param handler - precise event handler (i.e. "on note ... end on" |
154 |
* code block) to be executed |
* code block) to be executed |
210 |
*/ |
*/ |
211 |
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
212 |
|
|
213 |
|
/** |
214 |
|
* Returns all built-in dynamic variables. This method returns a STL |
215 |
|
* map, where the map's key is the dynamic variable's name and the |
216 |
|
* map's value is the pointer to the actual object implementing the |
217 |
|
* behavior which is actually generating the content of the dynamic |
218 |
|
* variable. |
219 |
|
* |
220 |
|
* This method is re-implemented by deriving classes to add more use |
221 |
|
* case specific built-in dynamic variables. |
222 |
|
*/ |
223 |
|
std::map<String,VMDynVar*> builtInDynamicVariables() OVERRIDE; |
224 |
|
|
225 |
|
VMEventHandler* currentVMEventHandler(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
226 |
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) |
227 |
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) |
228 |
|
|
229 |
protected: |
protected: |
230 |
|
VMEventHandler* m_eventHandler; |
231 |
ParserContext* m_parserContext; |
ParserContext* m_parserContext; |
232 |
CoreVMFunction_message fnMessage; |
class CoreVMFunction_message* m_fnMessage; |
233 |
CoreVMFunction_exit fnExit; |
class CoreVMFunction_exit* m_fnExit; |
234 |
CoreVMFunction_wait fnWait; |
class CoreVMFunction_wait* m_fnWait; |
235 |
CoreVMFunction_abs fnAbs; |
class CoreVMFunction_abs* m_fnAbs; |
236 |
CoreVMFunction_random fnRandom; |
class CoreVMFunction_random* m_fnRandom; |
237 |
CoreVMFunction_num_elements fnNumElements; |
class CoreVMFunction_num_elements* m_fnNumElements; |
238 |
|
class CoreVMDynVar_NKSP_REAL_TIMER* m_varRealTimer; |
239 |
|
class CoreVMDynVar_NKSP_PERF_TIMER* m_varPerfTimer; |
240 |
}; |
}; |
241 |
|
|
242 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |