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

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

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

revision 2729 by schoenebeck, Tue Mar 31 17:56:21 2015 UTC revision 3311 by schoenebeck, Sat Jul 15 16:24:59 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2015 Christian Schoenebeck   * Copyright (c) 2014-2017 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 15  Line 15 
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    
# Line 67  namespace LinuxSampler { Line 66  namespace LinuxSampler {
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 representation of the script           * @returns parsed representation of the script
74           */           */
# Line 83  namespace LinuxSampler { Line 85  namespace LinuxSampler {
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.
# Line 114  namespace LinuxSampler { Line 143  namespace LinuxSampler {
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.
# Line 144  namespace LinuxSampler { Line 173  namespace LinuxSampler {
173          VMFunction* functionByName(const String& name) OVERRIDE;          VMFunction* functionByName(const String& name) OVERRIDE;
174    
175          /**          /**
176             * Whether the passed built-in function is disabled and should thus be
177             * ignored by the parser at the passed parser context (parser state
178             * where the built-in function call occurs).
179             *
180             * @param fn - built-in function to be checked
181             * @param ctx - parser context at the position where the built-in
182             *              function call is located within the script
183             */
184            bool isFunctionDisabled(VMFunction* fn, VMParserContext* ctx) OVERRIDE;
185    
186            /**
187           * Returns all built-in integer script variables. This method returns a           * Returns all built-in integer script variables. This method returns a
188           * STL map, where the map's key is the variable name and the map's value           * STL map, where the map's key is the variable name and the map's value
189           * is the native pointer to the actual built-in variable.           * is the native pointer to the actual built-in variable.
# Line 165  namespace LinuxSampler { Line 205  namespace LinuxSampler {
205          std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE;          std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE;
206    
207          /**          /**
208           * Returns all built-in constant integer script variables, which can           * Returns all built-in constant integer script variables, which are
209           * only be read, but not be altered by scripts. This method returns a           * constant and their final data is already available at parser time
210           * STL map, where the map's key is the variable name and the map's value           * and won't change during runtime. Providing your built-in constants
211           * is the native pointer to the actual built-in constant variable.           * this way may lead to performance benefits compared to using other
212             * ways of providing built-in variables, because the script parser
213             * can perform optimizations when the script is refering to such
214             * constants.
215             *
216             * This type of built-in variable can only be read, but not be altered
217             * by scripts. This method returns a STL map, where the map's key is
218             * the variable name and the map's value is the final constant data.
219           *           *
220           * This method is re-implemented by deriving classes to add more use           * This method is re-implemented by deriving classes to add more use
221           * case specific built-in constant integers.           * case specific built-in constant integers.
222           *           *
223           * @b Note: the term "constant" is a bit misleading here, since           * @b Note: In case your built-in variable should be read-only but its
224           * built-in constant integer variables may indeed change, i.e. for           * value is not already available at parser time (i.e. because its
225           * built-in constant integers which i.e. reflect some kind of status of           * value may change at runtime), then you should add it to
226           * the sampler. So rather see them as "read only" variables, not as           * builtInIntVariables() instead and use the macro
227           * being actually consistent in time.           * DECLARE_VMINT_READONLY() to define the variable for read-only
228             * access by scripts.
229           */           */
230          std::map<String,int> builtInConstIntVariables() OVERRIDE;          std::map<String,int> builtInConstIntVariables() OVERRIDE;
231    
232            /**
233             * Returns all built-in dynamic variables. This method returns a STL
234             * map, where the map's key is the dynamic variable's name and the
235             * map's value is the pointer to the actual object implementing the
236             * behavior which is actually generating the content of the dynamic
237             * variable.
238             *
239             * This method is re-implemented by deriving classes to add more use
240             * case specific built-in dynamic variables.
241             */
242            std::map<String,VMDynVar*> builtInDynamicVariables() OVERRIDE;
243    
244            /**
245             * Enables or disables automatic suspension of scripts by the VM.
246             * If automatic suspension is enabled then scripts are monitored
247             * regarding their execution time and in case they are execution
248             * for too long, then they are automatically suspended by the VM for
249             * a certain amount of time in order to avoid any RT instablity
250             * issues caused by bugs in the script, i.e. endless while() loops
251             * or very large scripts.
252             *
253             * Automatic suspension is enabled by default due to the aimed
254             * real-time context of this virtual machine.
255             *
256             * @param b - true: enable auto suspension [default],
257             *            false: disable auto suspension
258             */
259            void setAutoSuspendEnabled(bool b = true);
260    
261            /**
262             * Returns true in case automatic suspension of scripts by the VM is
263             * enabled. See setAutoSuspendEnabled() for details.
264             *
265             * Automatic suspension is enabled by default due to the aimed
266             * real-time context of this virtual machine.
267             */
268            bool isAutoSuspendEnabled() const;
269    
270            VMEventHandler* currentVMEventHandler(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions)
271          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)
272          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)
273    
274      protected:      protected:
275            VMEventHandler* m_eventHandler;
276          ParserContext* m_parserContext;          ParserContext* m_parserContext;
277          CoreVMFunction_message fnMessage;          bool m_autoSuspend;
278          CoreVMFunction_exit fnExit;          class CoreVMFunction_message* m_fnMessage;
279          CoreVMFunction_wait fnWait;          class CoreVMFunction_exit* m_fnExit;
280          CoreVMFunction_abs fnAbs;          class CoreVMFunction_wait* m_fnWait;
281          CoreVMFunction_random fnRandom;          class CoreVMFunction_abs* m_fnAbs;
282          CoreVMFunction_num_elements fnNumElements;          class CoreVMFunction_random* m_fnRandom;
283            class CoreVMFunction_num_elements* m_fnNumElements;
284            class CoreVMFunction_inc* m_fnInc;
285            class CoreVMFunction_dec* m_fnDec;
286            class CoreVMFunction_in_range* m_fnInRange;
287            class CoreVMFunction_sh_left* m_fnShLeft;
288            class CoreVMFunction_sh_right* m_fnShRight;
289            class CoreVMFunction_min* m_fnMin;
290            class CoreVMFunction_max* m_fnMax;
291            class CoreVMFunction_array_equal* m_fnArrayEqual;
292            class CoreVMFunction_search* m_fnSearch;
293            class CoreVMFunction_sort* m_fnSort;
294            class CoreVMDynVar_NKSP_REAL_TIMER* m_varRealTimer;
295            class CoreVMDynVar_NKSP_PERF_TIMER* m_varPerfTimer;
296      };      };
297    
298  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2729  
changed lines
  Added in v.3311

  ViewVC Help
Powered by ViewVC