102 |
VMParserContext* ScriptVM::loadScript(std::istream* is) { |
VMParserContext* ScriptVM::loadScript(std::istream* is) { |
103 |
ParserContext* context = new ParserContext(this); |
ParserContext* context = new ParserContext(this); |
104 |
//printf("parserCtx=0x%lx\n", (uint64_t)context); |
//printf("parserCtx=0x%lx\n", (uint64_t)context); |
105 |
|
|
106 |
|
context->registerBuiltInConstIntVariables( builtInConstIntVariables() ); |
107 |
|
context->registerBuiltInIntVariables( builtInIntVariables() ); |
108 |
|
context->registerBuiltInIntArrayVariables( builtInIntArrayVariables() ); |
109 |
|
|
110 |
context->createScanner(is); |
context->createScanner(is); |
111 |
|
|
112 |
InstrScript_parse(context); |
InstrScript_parse(context); |
113 |
std::cout << "Allocating " << context->globalIntVarCount * sizeof(int) << " bytes of global int VM memory.\n"; |
dmsg(2,("Allocating %d bytes of global int VM memory.\n", context->globalIntVarCount * sizeof(int))); |
114 |
std::cout << "Allocating " << context->globalStrVarCount << " of global VM string variables.\n"; |
dmsg(2,("Allocating %d of global VM string variables.\n", context->globalStrVarCount)); |
115 |
if (!context->globalIntMemory) |
if (!context->globalIntMemory) |
116 |
context->globalIntMemory = new ArrayList<int>(); |
context->globalIntMemory = new ArrayList<int>(); |
117 |
if (!context->globalStrMemory) |
if (!context->globalStrMemory) |
152 |
_requiredMaxStackSizeFor(&*parserCtx->handlers); |
_requiredMaxStackSizeFor(&*parserCtx->handlers); |
153 |
} |
} |
154 |
execCtx->stack.resize(parserCtx->requiredMaxStackSize); |
execCtx->stack.resize(parserCtx->requiredMaxStackSize); |
155 |
std::cout << "Created VM exec context with " |
dmsg(2,("Created VM exec context with %d bytes VM stack size.\n", |
156 |
<< parserCtx->requiredMaxStackSize * sizeof(ExecContext::StackFrame) |
parserCtx->requiredMaxStackSize * sizeof(ExecContext::StackFrame))); |
|
<< " bytes VM stack size.\n"; |
|
157 |
//printf("execCtx=0x%lx\n", (uint64_t)execCtx); |
//printf("execCtx=0x%lx\n", (uint64_t)execCtx); |
158 |
const int polySize = parserCtx->polyphonicIntVarCount; |
const int polySize = parserCtx->polyphonicIntVarCount; |
159 |
execCtx->polyphonicIntMemory.resize(polySize); |
execCtx->polyphonicIntMemory.resize(polySize); |
160 |
memset(&execCtx->polyphonicIntMemory[0], 0, polySize * sizeof(int)); |
memset(&execCtx->polyphonicIntMemory[0], 0, polySize * sizeof(int)); |
161 |
|
|
162 |
std::cout << "Allocated " << polySize * sizeof(int) |
dmsg(2,("Allocated %d bytes polyphonic memory.\n", polySize * sizeof(int))); |
|
<< " bytes polyphonic memory.\n"; |
|
163 |
return execCtx; |
return execCtx; |
164 |
} |
} |
165 |
|
|
170 |
return NULL; |
return NULL; |
171 |
} |
} |
172 |
|
|
173 |
|
std::map<String,VMIntRelPtr*> ScriptVM::builtInIntVariables() { |
174 |
|
return std::map<String,VMIntRelPtr*>(); |
175 |
|
} |
176 |
|
|
177 |
|
std::map<String,VMInt8Array*> ScriptVM::builtInIntArrayVariables() { |
178 |
|
return std::map<String,VMInt8Array*>(); |
179 |
|
} |
180 |
|
|
181 |
|
std::map<String,int> ScriptVM::builtInConstIntVariables() { |
182 |
|
return std::map<String,int>(); |
183 |
|
} |
184 |
|
|
185 |
VMParserContext* ScriptVM::currentVMParserContext() { |
VMParserContext* ScriptVM::currentVMParserContext() { |
186 |
return m_parserContext; |
return m_parserContext; |
187 |
} |
} |
198 |
return VMExecStatus_t(VM_EXEC_NOT_RUNNING | VM_EXEC_ERROR); |
return VMExecStatus_t(VM_EXEC_NOT_RUNNING | VM_EXEC_ERROR); |
199 |
} |
} |
200 |
|
|
201 |
|
// a ParserContext object is always tied to exactly one ScriptVM object |
202 |
|
assert(m_parserContext->functionProvider == this); |
203 |
|
|
204 |
ExecContext* ctx = dynamic_cast<ExecContext*>(execContex); |
ExecContext* ctx = dynamic_cast<ExecContext*>(execContex); |
205 |
if (!ctx) { |
if (!ctx) { |
206 |
std::cerr << "Invalid VM exec context.\n"; |
std::cerr << "Invalid VM exec context.\n"; |