1 |
/* |
/* |
2 |
* Copyright (c) 2014 Christian Schoenebeck |
* Copyright (c) 2014 - 2016 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
10 |
#include "ScriptVM.h" |
#include "ScriptVM.h" |
11 |
|
|
12 |
#include <string.h> |
#include <string.h> |
13 |
|
#include <assert.h> |
14 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
15 |
#include "tree.h" |
#include "tree.h" |
16 |
|
|
89 |
return max; |
return max; |
90 |
} |
} |
91 |
|
|
92 |
ScriptVM::ScriptVM() : m_parserContext(NULL), fnWait(this) { |
ScriptVM::ScriptVM() : m_eventHandler(NULL), m_parserContext(NULL), fnWait(this) { |
93 |
} |
} |
94 |
|
|
95 |
ScriptVM::~ScriptVM() { |
ScriptVM::~ScriptVM() { |
111 |
context->createScanner(is); |
context->createScanner(is); |
112 |
|
|
113 |
InstrScript_parse(context); |
InstrScript_parse(context); |
114 |
dmsg(2,("Allocating %d bytes of global int VM memory.\n", context->globalIntVarCount * sizeof(int))); |
dmsg(2,("Allocating %ld bytes of global int VM memory.\n", long(context->globalIntVarCount * sizeof(int)))); |
115 |
dmsg(2,("Allocating %d of global VM string variables.\n", context->globalStrVarCount)); |
dmsg(2,("Allocating %d of global VM string variables.\n", context->globalStrVarCount)); |
116 |
if (!context->globalIntMemory) |
if (!context->globalIntMemory) |
117 |
context->globalIntMemory = new ArrayList<int>(); |
context->globalIntMemory = new ArrayList<int>(); |
153 |
_requiredMaxStackSizeFor(&*parserCtx->handlers); |
_requiredMaxStackSizeFor(&*parserCtx->handlers); |
154 |
} |
} |
155 |
execCtx->stack.resize(parserCtx->requiredMaxStackSize); |
execCtx->stack.resize(parserCtx->requiredMaxStackSize); |
156 |
dmsg(2,("Created VM exec context with %d bytes VM stack size.\n", |
dmsg(2,("Created VM exec context with %ld bytes VM stack size.\n", |
157 |
parserCtx->requiredMaxStackSize * sizeof(ExecContext::StackFrame))); |
long(parserCtx->requiredMaxStackSize * sizeof(ExecContext::StackFrame)))); |
158 |
//printf("execCtx=0x%lx\n", (uint64_t)execCtx); |
//printf("execCtx=0x%lx\n", (uint64_t)execCtx); |
159 |
const int polySize = parserCtx->polyphonicIntVarCount; |
const int polySize = parserCtx->polyphonicIntVarCount; |
160 |
execCtx->polyphonicIntMemory.resize(polySize); |
execCtx->polyphonicIntMemory.resize(polySize); |
161 |
memset(&execCtx->polyphonicIntMemory[0], 0, polySize * sizeof(int)); |
memset(&execCtx->polyphonicIntMemory[0], 0, polySize * sizeof(int)); |
162 |
|
|
163 |
dmsg(2,("Allocated %d bytes polyphonic memory.\n", polySize * sizeof(int))); |
dmsg(2,("Allocated %ld bytes polyphonic memory.\n", long(polySize * sizeof(int)))); |
164 |
return execCtx; |
return execCtx; |
165 |
} |
} |
166 |
|
|
168 |
if (name == "message") return &fnMessage; |
if (name == "message") return &fnMessage; |
169 |
else if (name == "exit") return &fnExit; |
else if (name == "exit") return &fnExit; |
170 |
else if (name == "wait") return &fnWait; |
else if (name == "wait") return &fnWait; |
171 |
|
else if (name == "abs") return &fnAbs; |
172 |
|
else if (name == "random") return &fnRandom; |
173 |
|
else if (name == "num_elements") return &fnNumElements; |
174 |
return NULL; |
return NULL; |
175 |
} |
} |
176 |
|
|
186 |
return std::map<String,int>(); |
return std::map<String,int>(); |
187 |
} |
} |
188 |
|
|
189 |
|
VMEventHandler* ScriptVM::currentVMEventHandler() { |
190 |
|
return m_eventHandler; |
191 |
|
} |
192 |
|
|
193 |
VMParserContext* ScriptVM::currentVMParserContext() { |
VMParserContext* ScriptVM::currentVMParserContext() { |
194 |
return m_parserContext; |
return m_parserContext; |
195 |
} |
} |
216 |
} |
} |
217 |
EventHandler* h = dynamic_cast<EventHandler*>(handler); |
EventHandler* h = dynamic_cast<EventHandler*>(handler); |
218 |
if (!h) return VM_EXEC_NOT_RUNNING; |
if (!h) return VM_EXEC_NOT_RUNNING; |
219 |
|
m_eventHandler = handler; |
220 |
|
|
221 |
m_parserContext->execContext = ctx; |
m_parserContext->execContext = ctx; |
222 |
|
|
312 |
ctx->reset(); |
ctx->reset(); |
313 |
} |
} |
314 |
|
|
315 |
|
m_eventHandler = NULL; |
316 |
m_parserContext->execContext = NULL; |
m_parserContext->execContext = NULL; |
317 |
m_parserContext = NULL; |
m_parserContext = NULL; |
318 |
return ctx->status; |
return ctx->status; |