/[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 2727 by schoenebeck, Tue Mar 31 17:46:11 2015 UTC revision 2889 by schoenebeck, Mon Apr 25 17:28:23 2016 UTC
# Line 1  Line 1 
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   *   *
# 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    
21      class ParserContext;      class ParserContext;
22      class ExecContext;      class ExecContext;
23        class CoreVMFunction_message;
24        class CoreVMFunction_exit;
25        class CoreVMFunction_wait;
26        class CoreVMFunction_abs;
27        class CoreVMFunction_random;
28        class CoreVMFunction_num_elements;
29    
30      /** @brief Core virtual machine for real-time instrument scripts.      /** @brief Core virtual machine for real-time instrument scripts.
31       *       *
# Line 40  namespace LinuxSampler { Line 45  namespace LinuxSampler {
45       * - 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
46       *      classes).       *      classes).
47       * - 2. Load a script by passing its source code to method loadScript(),       * - 2. Load a script by passing its source code to method loadScript(),
48       *      which will return the parsed represenation of the script.       *      which will return the parsed representation of the script.
49       * - 3. Create a VM execution context by calling createExecContext().       * - 3. Create a VM execution context by calling createExecContext().
50       * - 4. Execute the script by calling method exec().       * - 4. Execute the script by calling method exec().
51       *       *
# Line 61  namespace LinuxSampler { Line 66  namespace LinuxSampler {
66    
67          /**          /**
68           * 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
69           * this method) and returns the parsed represenation of that script.           * this method) and returns the parsed representation of that script.
70           * After calling this method you must check the returned VMParserContext           * After calling this method you must check the returned VMParserContext
71           * object whether there had been any parser errors. If there were no           * object whether there had been any parser errors. If there were no
72           * parser errors, you may pass the VMParserContext object to method           * parser errors, you may pass the VMParserContext object to method
73           * exec() for actually executing the script.           * exec() for actually executing the script.
74           *           *
75             * It is your responsibility to free the returned VMParserContext
76             * object once you don't need it anymore.
77             *
78           * @param s - entire source code of the script to be loaded           * @param s - entire source code of the script to be loaded
79           * @returns parsed represenation of the script           * @returns parsed representation of the script
80           */           */
81          VMParserContext* loadScript(const String& s);          VMParserContext* loadScript(const String& s);
82    
# Line 78  namespace LinuxSampler { Line 86  namespace LinuxSampler {
86           *           *
87           * @param is - input stream from which the entire source code of the           * @param is - input stream from which the entire source code of the
88           *             script is to be read and loaded from           *             script is to be read and loaded from
89           * @returns parsed represenation of the script           * @returns parsed representation of the script
90           */           */
91          VMParserContext* loadScript(std::istream* is);          VMParserContext* loadScript(std::istream* is);
92    
93          /**          /**
94             * Parses a script's source code (passed as argument @a s to this
95             * method), splits that input up in its individual tokens (i.e.
96             * keyword, variable name, event name, etc.) and returns all those
97             * tokens, for the purpose that the caller can provide syntax syntax
98             * highlighting for the passed script.
99             *
100             * This method is actually not used by the sampler at all, it is rather
101             * provided for external script editor applications, to provide them a
102             * convenient backend for parsing scripts and providing syntax
103             * highlighting.
104             *
105             * @returns recognized tokens of passed script's source code
106             */
107            std::vector<VMSourceToken> syntaxHighlighting(const String& s);
108    
109            /**
110             * Same as above's syntaxHighlighting() method, but this one reads the
111             * script's source code from an input stream object (i.e. stdin or a
112             * file).
113             *
114             * @param is - input stream from which the entire source code of the
115             *             script is to be read and loaded from
116             * @returns recognized tokens of passed script's source code
117             */
118            std::vector<VMSourceToken> syntaxHighlighting(std::istream* is);
119    
120            /**
121           * Dumps the translated tree of the already parsed script, given by           * Dumps the translated tree of the already parsed script, given by
122           * argument @a context, to stdout. This method is for debugging purposes           * argument @a context, to stdout. This method is for debugging purposes
123           * only.           * only.
124           *           *
125           * @param context - parsed represenation of the script           * @param context - parsed representation of the script
126             * @see loadScript()
127           */           */
128          void dumpParsedScript(VMParserContext* context);          void dumpParsedScript(VMParserContext* context);
129    
# Line 97  namespace LinuxSampler { Line 133  namespace LinuxSampler {
133           * general real-time design of this virtual machine, the VM execution           * general real-time design of this virtual machine, the VM execution
134           * context differs for every script. So you must (re)create the           * context differs for every script. So you must (re)create the
135           * execution context for each script being loaded.           * execution context for each script being loaded.
136             *
137             * @param parserContext - parsed representation of the script
138             * @see loadScript()
139           */           */
140          VMExecContext* createExecContext(VMParserContext* parserContext);          VMExecContext* createExecContext(VMParserContext* parserContext);
141    
# Line 110  namespace LinuxSampler { Line 149  namespace LinuxSampler {
149           * This method usually blocks until the entire script event handler           * This method usually blocks until the entire script event handler
150           * block has been executed completely. It may however also return before           * block has been executed completely. It may however also return before
151           * completion if either a) a script runtime error occurred or b) the           * completion if either a) a script runtime error occurred or b) the
152           * script was suspened by the VM (either because script execution           * script was suspended by the VM (either because script execution
153           * 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
154           * wait() function). You must check the return value of this method to           * wait() function). You must check the return value of this method to
155           * find out which case applies.           * find out which case applies.
156           *           *
157           * @param parserContext - parsed represenation of the script           * @param parserContext - parsed representation of the script (see loadScript())
158           * @param execContext - VM execution context (see createExecContext())           * @param execContext - VM execution context (see createExecContext())
159           * @param handler - precise event handler (i.e. "on note ... end on"           * @param handler - precise event handler (i.e. "on note ... end on"
160           *                  code block) to be executed           *                  code block) to be executed
# Line 177  namespace LinuxSampler { Line 216  namespace LinuxSampler {
216           */           */
217          std::map<String,int> builtInConstIntVariables() OVERRIDE;          std::map<String,int> builtInConstIntVariables() OVERRIDE;
218    
219            VMEventHandler* currentVMEventHandler(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions)
220          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)
221          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)
222    
223      protected:      protected:
224            VMEventHandler* m_eventHandler;
225          ParserContext* m_parserContext;          ParserContext* m_parserContext;
226          CoreVMFunction_message fnMessage;          CoreVMFunction_message* m_fnMessage;
227          CoreVMFunction_exit fnExit;          CoreVMFunction_exit* m_fnExit;
228          CoreVMFunction_wait fnWait;          CoreVMFunction_wait* m_fnWait;
229          CoreVMFunction_abs fnAbs;          CoreVMFunction_abs* m_fnAbs;
230          CoreVMFunction_random fnRandom;          CoreVMFunction_random* m_fnRandom;
231          CoreVMFunction_num_elements fnNumElements;          CoreVMFunction_num_elements* m_fnNumElements;
232      };      };
233    
234  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2727  
changed lines
  Added in v.2889

  ViewVC Help
Powered by ViewVC