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

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

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

revision 2837 by persson, Sun Aug 23 06:14:00 2015 UTC revision 2945 by schoenebeck, Thu Jul 14 00:22:26 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 13  Line 13 
13  #include <assert.h>  #include <assert.h>
14  #include "../common/global_private.h"  #include "../common/global_private.h"
15  #include "tree.h"  #include "tree.h"
16    #include "CoreVMFunctions.h"
17    #include "CoreVMDynVars.h"
18    #include "editor/NkspScanner.h"
19    
20  #define DEBUG_SCRIPTVM_CORE 0  #define DEBUG_SCRIPTVM_CORE 0
21    
# Line 89  namespace LinuxSampler { Line 92  namespace LinuxSampler {
92          return max;          return max;
93      }      }
94    
95      ScriptVM::ScriptVM() : m_parserContext(NULL), fnWait(this) {      ScriptVM::ScriptVM() : m_eventHandler(NULL), m_parserContext(NULL) {
96            m_fnMessage = new CoreVMFunction_message;
97            m_fnExit = new CoreVMFunction_exit;
98            m_fnWait = new CoreVMFunction_wait(this);
99            m_fnAbs = new CoreVMFunction_abs;
100            m_fnRandom = new CoreVMFunction_random;
101            m_fnNumElements = new CoreVMFunction_num_elements;
102            m_fnInc = new CoreVMFunction_inc;
103            m_fnDec = new CoreVMFunction_dec;
104            m_varRealTimer = new CoreVMDynVar_NKSP_REAL_TIMER;
105            m_varPerfTimer = new CoreVMDynVar_NKSP_PERF_TIMER;
106      }      }
107    
108      ScriptVM::~ScriptVM() {      ScriptVM::~ScriptVM() {
109            delete m_fnMessage;
110            delete m_fnExit;
111            delete m_fnWait;
112            delete m_fnAbs;
113            delete m_fnRandom;
114            delete m_fnNumElements;
115            delete m_fnInc;
116            delete m_fnDec;
117            delete m_varRealTimer;
118            delete m_varPerfTimer;
119      }      }
120    
121      VMParserContext* ScriptVM::loadScript(const String& s) {      VMParserContext* ScriptVM::loadScript(const String& s) {
# Line 107  namespace LinuxSampler { Line 130  namespace LinuxSampler {
130          context->registerBuiltInConstIntVariables( builtInConstIntVariables() );          context->registerBuiltInConstIntVariables( builtInConstIntVariables() );
131          context->registerBuiltInIntVariables( builtInIntVariables() );          context->registerBuiltInIntVariables( builtInIntVariables() );
132          context->registerBuiltInIntArrayVariables( builtInIntArrayVariables() );          context->registerBuiltInIntArrayVariables( builtInIntArrayVariables() );
133            context->registerBuiltInDynVariables( builtInDynamicVariables() );
134    
135          context->createScanner(is);          context->createScanner(is);
136    
# Line 164  namespace LinuxSampler { Line 188  namespace LinuxSampler {
188          return execCtx;          return execCtx;
189      }      }
190    
191        std::vector<VMSourceToken> ScriptVM::syntaxHighlighting(const String& s) {
192            std::istringstream iss(s);
193            return syntaxHighlighting(&iss);
194        }
195    
196        std::vector<VMSourceToken> ScriptVM::syntaxHighlighting(std::istream* is) {
197            NkspScanner scanner(is);
198            std::vector<SourceToken> tokens = scanner.tokens();
199            std::vector<VMSourceToken> result;
200            result.resize(tokens.size());
201            for (int i = 0; i < tokens.size(); ++i) {
202                SourceToken* st = new SourceToken;
203                *st = tokens[i];
204                result[i] = VMSourceToken(st);
205            }
206            return result;
207        }
208    
209      VMFunction* ScriptVM::functionByName(const String& name) {      VMFunction* ScriptVM::functionByName(const String& name) {
210          if (name == "message") return &fnMessage;          if (name == "message") return m_fnMessage;
211          else if (name == "exit") return &fnExit;          else if (name == "exit") return m_fnExit;
212          else if (name == "wait") return &fnWait;          else if (name == "wait") return m_fnWait;
213          else if (name == "abs") return &fnAbs;          else if (name == "abs") return m_fnAbs;
214          else if (name == "random") return &fnRandom;          else if (name == "random") return m_fnRandom;
215          else if (name == "num_elements") return &fnNumElements;          else if (name == "num_elements") return m_fnNumElements;
216            else if (name == "inc") return m_fnInc;
217            else if (name == "dec") return m_fnDec;
218          return NULL;          return NULL;
219      }      }
220    
# Line 182  namespace LinuxSampler { Line 226  namespace LinuxSampler {
226          return std::map<String,VMInt8Array*>();          return std::map<String,VMInt8Array*>();
227      }      }
228    
229        std::map<String,VMDynVar*> ScriptVM::builtInDynamicVariables() {
230            std::map<String,VMDynVar*> m;
231    
232            m["$NKSP_PERF_TIMER"] = m_varPerfTimer;
233            m["$NKSP_REAL_TIMER"] = m_varRealTimer;
234            m["$KSP_TIMER"] = m_varRealTimer;
235    
236            return m;
237        }
238    
239      std::map<String,int> ScriptVM::builtInConstIntVariables() {      std::map<String,int> ScriptVM::builtInConstIntVariables() {
240          return std::map<String,int>();          return std::map<String,int>();
241      }      }
242    
243        VMEventHandler* ScriptVM::currentVMEventHandler() {
244            return m_eventHandler;
245        }
246    
247      VMParserContext* ScriptVM::currentVMParserContext() {      VMParserContext* ScriptVM::currentVMParserContext() {
248          return m_parserContext;          return m_parserContext;
249      }      }
# Line 212  namespace LinuxSampler { Line 270  namespace LinuxSampler {
270          }          }
271          EventHandler* h = dynamic_cast<EventHandler*>(handler);          EventHandler* h = dynamic_cast<EventHandler*>(handler);
272          if (!h) return VM_EXEC_NOT_RUNNING;          if (!h) return VM_EXEC_NOT_RUNNING;
273            m_eventHandler = handler;
274    
275          m_parserContext->execContext = ctx;          m_parserContext->execContext = ctx;
276    
# Line 307  namespace LinuxSampler { Line 366  namespace LinuxSampler {
366              ctx->reset();              ctx->reset();
367          }          }
368    
369            m_eventHandler = NULL;
370          m_parserContext->execContext = NULL;          m_parserContext->execContext = NULL;
371          m_parserContext = NULL;          m_parserContext = NULL;
372          return ctx->status;          return ctx->status;

Legend:
Removed from v.2837  
changed lines
  Added in v.2945

  ViewVC Help
Powered by ViewVC