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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3590 - (show annotations) (download)
Mon Sep 2 09:03:31 2019 UTC (4 years, 6 months ago) by schoenebeck
File size: 24016 byte(s)
NKSP: Implemented common real number math functions.

* Added built-in real number functions "round()", "ceil()", "floor()",
  "sqrt()", "log()", "log2()", "log10()", "exp()", "pow()", "sin()",
  "cos()", "tan()", "asin()", "acos()", "atan()".

* Added built-in script real number constant "~NI_MATH_PI".

* Added built-in script real number constant "~NI_MATH_E".

* Added NKSP test cases for built-in functions "round()", "ceil()",
  "floor()", "sqrt()", "log()", "log2()", "log10()", "exp()", "pow()",
  "sin()", "cos()", "tan()", "asin()", "acos()", "atan()".

* Bumped version (2.1.1.svn14).

1 /*
2 * Copyright (c) 2014 - 2019 Christian Schoenebeck
3 *
4 * http://www.linuxsampler.org
5 *
6 * This file is part of LinuxSampler and released under the same terms.
7 * See README file for details.
8 */
9
10 #include "ScriptVM.h"
11
12 #include <string.h>
13 #include <assert.h>
14 #include "../common/global_private.h"
15 #include "tree.h"
16 #include "CoreVMFunctions.h"
17 #include "CoreVMDynVars.h"
18 #include "editor/NkspScanner.h"
19
20 #define DEBUG_SCRIPTVM_CORE 0
21
22 /**
23 * Maximum amount of VM instructions to be executed per ScriptVM::exec() call
24 * in case loops are involved, before the script got automatically suspended
25 * for a certain amount of time to avoid any RT instability issues.
26 *
27 * The following value takes a max. execution time of 300 microseconds as aimed
28 * target, assuming an execution time of approximately 5 microseconds per
29 * instruction this leads to the very approximate value set below.
30 */
31 #define SCRIPTVM_MAX_INSTR_PER_CYCLE_SOFT 70
32
33 /**
34 * Absolute maximum amount of VM instructions to be executed per
35 * ScriptVM::exec() call (even if no loops are involved), before the script got
36 * automatically suspended for a certain amount of time to avoid any RT
37 * instability issues.
38 *
39 * A distinction between "soft" and "hard" limit is done here ATM because a
40 * script author typically expects that his script might be interrupted
41 * automatically if he is using while() loops, however he might not be
42 * prepared that his script might also be interrupted if no loop is involved
43 * (i.e. on very large scripts).
44 *
45 * The following value takes a max. execution time of 1000 microseconds as
46 * aimed target, assuming an execution time of approximately 5 microseconds per
47 * instruction this leads to the very approximate value set below.
48 */
49 #define SCRIPTVM_MAX_INSTR_PER_CYCLE_HARD 210
50
51 /**
52 * In case either SCRIPTVM_MAX_INSTR_PER_CYCLE_SOFT or
53 * SCRIPTVM_MAX_INSTR_PER_CYCLE_HARD was exceeded when calling
54 * ScriptVM::exec() : the amount of microseconds the respective script
55 * execution instance should be automatically suspended by the VM.
56 */
57 #define SCRIPT_VM_FORCE_SUSPENSION_MICROSECONDS 1000
58
59 int InstrScript_parse(LinuxSampler::ParserContext*);
60
61 namespace LinuxSampler {
62
63 #if DEBUG_SCRIPTVM_CORE
64 static void _printIndents(int n) {
65 for (int i = 0; i < n; ++i) printf(" ");
66 fflush(stdout);
67 }
68 #endif
69
70 static vmint _requiredMaxStackSizeFor(Statement* statement, vmint depth = 0) {
71 if (!statement) return 1;
72
73 switch (statement->statementType()) {
74 case STMT_LEAF:
75 #if DEBUG_SCRIPTVM_CORE
76 _printIndents(depth);
77 printf("-> STMT_LEAF\n");
78 #endif
79 return 1;
80
81 case STMT_LIST: {
82 #if DEBUG_SCRIPTVM_CORE
83 _printIndents(depth);
84 printf("-> STMT_LIST\n");
85 #endif
86 Statements* stmts = (Statements*) statement;
87 vmint max = 0;
88 for (int i = 0; stmts->statement(i); ++i) {
89 vmint size = _requiredMaxStackSizeFor( stmts->statement(i), depth+1 );
90 if (max < size) max = size;
91 }
92 return max + 1;
93 }
94
95 case STMT_BRANCH: {
96 #if DEBUG_SCRIPTVM_CORE
97 _printIndents(depth);
98 printf("-> STMT_BRANCH\n");
99 #endif
100 BranchStatement* branchStmt = (BranchStatement*) statement;
101 vmint max = 0;
102 for (int i = 0; branchStmt->branch(i); ++i) {
103 vmint size = _requiredMaxStackSizeFor( branchStmt->branch(i), depth+1 );
104 if (max < size) max = size;
105 }
106 return max + 1;
107 }
108
109 case STMT_LOOP: {
110 #if DEBUG_SCRIPTVM_CORE
111 _printIndents(depth);
112 printf("-> STMT_LOOP\n");
113 #endif
114 While* whileStmt = (While*) statement;
115 if (whileStmt->statements())
116 return _requiredMaxStackSizeFor( whileStmt->statements() ) + 1;
117 else
118 return 1;
119 }
120
121 case STMT_SYNC: {
122 #if DEBUG_SCRIPTVM_CORE
123 _printIndents(depth);
124 printf("-> STMT_SYNC\n");
125 #endif
126 SyncBlock* syncStmt = (SyncBlock*) statement;
127 if (syncStmt->statements())
128 return _requiredMaxStackSizeFor( syncStmt->statements() ) + 1;
129 else
130 return 1;
131 }
132
133 case STMT_NOOP:
134 break; // no operation like the name suggests
135 }
136
137 return 1; // actually just to avoid compiler warning
138 }
139
140 static vmint _requiredMaxStackSizeFor(EventHandlers* handlers) {
141 vmint max = 1;
142 for (int i = 0; i < handlers->size(); ++i) {
143 vmint size = _requiredMaxStackSizeFor(handlers->eventHandler(i));
144 if (max < size) max = size;
145 }
146 return max;
147 }
148
149 ScriptVM::ScriptVM() :
150 m_eventHandler(NULL), m_parserContext(NULL), m_autoSuspend(true),
151 m_acceptExitRes(false)
152 {
153 m_fnMessage = new CoreVMFunction_message;
154 m_fnExit = new CoreVMFunction_exit(this);
155 m_fnWait = new CoreVMFunction_wait(this);
156 m_fnAbs = new CoreVMFunction_abs;
157 m_fnRandom = new CoreVMFunction_random;
158 m_fnNumElements = new CoreVMFunction_num_elements;
159 m_fnInc = new CoreVMFunction_inc;
160 m_fnDec = new CoreVMFunction_dec;
161 m_fnInRange = new CoreVMFunction_in_range;
162 m_varRealTimer = new CoreVMDynVar_NKSP_REAL_TIMER;
163 m_varPerfTimer = new CoreVMDynVar_NKSP_PERF_TIMER;
164 m_fnShLeft = new CoreVMFunction_sh_left;
165 m_fnShRight = new CoreVMFunction_sh_right;
166 m_fnMin = new CoreVMFunction_min;
167 m_fnMax = new CoreVMFunction_max;
168 m_fnArrayEqual = new CoreVMFunction_array_equal;
169 m_fnSearch = new CoreVMFunction_search;
170 m_fnSort = new CoreVMFunction_sort;
171 m_fnIntToReal = new CoreVMFunction_int_to_real;
172 m_fnRealToInt = new CoreVMFunction_real_to_int;
173 m_fnRound = new CoreVMFunction_round;
174 m_fnCeil = new CoreVMFunction_ceil;
175 m_fnFloor = new CoreVMFunction_floor;
176 m_fnSqrt = new CoreVMFunction_sqrt;
177 m_fnLog = new CoreVMFunction_log;
178 m_fnLog2 = new CoreVMFunction_log2;
179 m_fnLog10 = new CoreVMFunction_log10;
180 m_fnExp = new CoreVMFunction_exp;
181 m_fnPow = new CoreVMFunction_pow;
182 m_fnSin = new CoreVMFunction_sin;
183 m_fnCos = new CoreVMFunction_cos;
184 m_fnTan = new CoreVMFunction_tan;
185 m_fnAsin = new CoreVMFunction_asin;
186 m_fnAcos = new CoreVMFunction_acos;
187 m_fnAtan = new CoreVMFunction_atan;
188 }
189
190 ScriptVM::~ScriptVM() {
191 delete m_fnMessage;
192 delete m_fnExit;
193 delete m_fnWait;
194 delete m_fnAbs;
195 delete m_fnRandom;
196 delete m_fnNumElements;
197 delete m_fnInc;
198 delete m_fnDec;
199 delete m_fnInRange;
200 delete m_fnShLeft;
201 delete m_fnShRight;
202 delete m_fnMin;
203 delete m_fnMax;
204 delete m_fnArrayEqual;
205 delete m_fnSearch;
206 delete m_fnSort;
207 delete m_fnIntToReal;
208 delete m_fnRealToInt;
209 delete m_fnRound;
210 delete m_fnCeil;
211 delete m_fnFloor;
212 delete m_fnSqrt;
213 delete m_fnLog;
214 delete m_fnLog2;
215 delete m_fnLog10;
216 delete m_fnExp;
217 delete m_fnPow;
218 delete m_fnSin;
219 delete m_fnCos;
220 delete m_fnTan;
221 delete m_fnAsin;
222 delete m_fnAcos;
223 delete m_fnAtan;
224 delete m_varRealTimer;
225 delete m_varPerfTimer;
226 }
227
228 VMParserContext* ScriptVM::loadScript(const String& s) {
229 std::istringstream iss(s);
230 return loadScript(&iss);
231 }
232
233 VMParserContext* ScriptVM::loadScript(std::istream* is) {
234 ParserContext* context = new ParserContext(this);
235 //printf("parserCtx=0x%lx\n", (uint64_t)context);
236
237 context->registerBuiltInConstIntVariables( builtInConstIntVariables() );
238 context->registerBuiltInConstRealVariables( builtInConstRealVariables() );
239 context->registerBuiltInIntVariables( builtInIntVariables() );
240 context->registerBuiltInIntArrayVariables( builtInIntArrayVariables() );
241 context->registerBuiltInDynVariables( builtInDynamicVariables() );
242
243 context->createScanner(is);
244
245 InstrScript_parse(context);
246 dmsg(2,("Allocating %lld bytes of global int VM memory.\n", context->globalIntVarCount * sizeof(vmint)));
247 dmsg(2,("Allocating %lld bytes of global real VM memory.\n", context->globalRealVarCount * sizeof(vmfloat)));
248 dmsg(2,("Allocating %lld bytes of global unit factor VM memory.\n", context->globalUnitFactorCount * sizeof(vmfloat)));
249 dmsg(2,("Allocating %lld of global VM string variables.\n", context->globalStrVarCount));
250 if (!context->globalIntMemory)
251 context->globalIntMemory = new ArrayList<vmint>();
252 if (!context->globalRealMemory)
253 context->globalRealMemory = new ArrayList<vmfloat>();
254 if (!context->globalUnitFactorMemory)
255 context->globalUnitFactorMemory = new ArrayList<vmfloat>();
256 if (!context->globalStrMemory)
257 context->globalStrMemory = new ArrayList<String>();
258 context->globalIntMemory->resize(context->globalIntVarCount);
259 context->globalRealMemory->resize(context->globalRealVarCount);
260 context->globalUnitFactorMemory->resize(context->globalUnitFactorCount);
261 memset(&((*context->globalIntMemory)[0]), 0, context->globalIntVarCount * sizeof(vmint));
262 memset(&((*context->globalRealMemory)[0]), 0, context->globalRealVarCount * sizeof(vmfloat));
263 for (vmint i = 0; i < context->globalUnitFactorCount; ++i)
264 (*context->globalUnitFactorMemory)[i] = VM_NO_FACTOR;
265 context->globalStrMemory->resize(context->globalStrVarCount);
266
267 context->destroyScanner();
268
269 return context;
270 }
271
272 void ScriptVM::dumpParsedScript(VMParserContext* context) {
273 ParserContext* ctx = dynamic_cast<ParserContext*>(context);
274 if (!ctx) {
275 std::cerr << "No VM context. So nothing to dump.\n";
276 return;
277 }
278 if (!ctx->handlers) {
279 std::cerr << "No event handlers defined in script. So nothing to dump.\n";
280 return;
281 }
282 if (!ctx->globalIntMemory) {
283 std::cerr << "Internal error: no global integer memory assigend to script VM.\n";
284 return;
285 }
286 if (!ctx->globalRealMemory) {
287 std::cerr << "Internal error: no global real number memory assigend to script VM.\n";
288 return;
289 }
290 ctx->handlers->dump();
291 }
292
293 VMExecContext* ScriptVM::createExecContext(VMParserContext* parserContext) {
294 ParserContext* parserCtx = dynamic_cast<ParserContext*>(parserContext);
295 ExecContext* execCtx = new ExecContext();
296
297 if (parserCtx->requiredMaxStackSize < 0) {
298 parserCtx->requiredMaxStackSize =
299 _requiredMaxStackSizeFor(&*parserCtx->handlers);
300 }
301 execCtx->stack.resize(parserCtx->requiredMaxStackSize);
302 dmsg(2,("Created VM exec context with %lld bytes VM stack size.\n",
303 parserCtx->requiredMaxStackSize * sizeof(ExecContext::StackFrame)));
304 //printf("execCtx=0x%lx\n", (uint64_t)execCtx);
305 const vmint polyIntSize = parserCtx->polyphonicIntVarCount;
306 execCtx->polyphonicIntMemory.resize(polyIntSize);
307 memset(&execCtx->polyphonicIntMemory[0], 0, polyIntSize * sizeof(vmint));
308
309 const vmint polyRealSize = parserCtx->polyphonicRealVarCount;
310 execCtx->polyphonicRealMemory.resize(polyRealSize);
311 memset(&execCtx->polyphonicRealMemory[0], 0, polyRealSize * sizeof(vmfloat));
312
313 const vmint polyFactorSize = parserCtx->polyphonicUnitFactorCount;
314 execCtx->polyphonicUnitFactorMemory.resize(polyFactorSize);
315 for (vmint i = 0; i < polyFactorSize; ++i)
316 execCtx->polyphonicUnitFactorMemory[i] = VM_NO_FACTOR;
317
318 dmsg(2,("Allocated %lld bytes polyphonic int memory.\n", polyIntSize * sizeof(vmint)));
319 dmsg(2,("Allocated %lld bytes polyphonic real memory.\n", polyRealSize * sizeof(vmfloat)));
320 dmsg(2,("Allocated %lld bytes unit factor memory.\n", polyFactorSize * sizeof(vmfloat)));
321 return execCtx;
322 }
323
324 std::vector<VMSourceToken> ScriptVM::syntaxHighlighting(const String& s) {
325 std::istringstream iss(s);
326 return syntaxHighlighting(&iss);
327 }
328
329 std::vector<VMSourceToken> ScriptVM::syntaxHighlighting(std::istream* is) {
330 try {
331 NkspScanner scanner(is);
332 std::vector<SourceToken> tokens = scanner.tokens();
333 std::vector<VMSourceToken> result;
334 result.resize(tokens.size());
335 for (vmint i = 0; i < tokens.size(); ++i) {
336 SourceToken* st = new SourceToken;
337 *st = tokens[i];
338 result[i] = VMSourceToken(st);
339 }
340 return result;
341 } catch (...) {
342 return std::vector<VMSourceToken>();
343 }
344 }
345
346 VMFunction* ScriptVM::functionByName(const String& name) {
347 if (name == "message") return m_fnMessage;
348 else if (name == "exit") return m_fnExit;
349 else if (name == "wait") return m_fnWait;
350 else if (name == "abs") return m_fnAbs;
351 else if (name == "random") return m_fnRandom;
352 else if (name == "num_elements") return m_fnNumElements;
353 else if (name == "inc") return m_fnInc;
354 else if (name == "dec") return m_fnDec;
355 else if (name == "in_range") return m_fnInRange;
356 else if (name == "sh_left") return m_fnShLeft;
357 else if (name == "sh_right") return m_fnShRight;
358 else if (name == "min") return m_fnMin;
359 else if (name == "max") return m_fnMax;
360 else if (name == "array_equal") return m_fnArrayEqual;
361 else if (name == "search") return m_fnSearch;
362 else if (name == "sort") return m_fnSort;
363 else if (name == "int_to_real") return m_fnIntToReal;
364 else if (name == "real") return m_fnIntToReal;
365 else if (name == "real_to_int") return m_fnRealToInt;
366 else if (name == "int") return m_fnRealToInt;
367 else if (name == "round") return m_fnRound;
368 else if (name == "ceil") return m_fnCeil;
369 else if (name == "floor") return m_fnFloor;
370 else if (name == "sqrt") return m_fnSqrt;
371 else if (name == "log") return m_fnLog;
372 else if (name == "log2") return m_fnLog2;
373 else if (name == "log10") return m_fnLog10;
374 else if (name == "exp") return m_fnExp;
375 else if (name == "pow") return m_fnPow;
376 else if (name == "sin") return m_fnSin;
377 else if (name == "cos") return m_fnCos;
378 else if (name == "tan") return m_fnTan;
379 else if (name == "asin") return m_fnAsin;
380 else if (name == "acos") return m_fnAcos;
381 else if (name == "atan") return m_fnAtan;
382 return NULL;
383 }
384
385 bool ScriptVM::isFunctionDisabled(VMFunction* fn, VMParserContext* ctx) {
386 ParserContext* parserCtx = dynamic_cast<ParserContext*>(ctx);
387 if (!parserCtx) return false;
388
389 if (fn == m_fnMessage && parserCtx->userPreprocessorConditions.count("NKSP_NO_MESSAGE"))
390 return true;
391
392 return false;
393 }
394
395 std::map<String,VMIntPtr*> ScriptVM::builtInIntVariables() {
396 return std::map<String,VMIntPtr*>();
397 }
398
399 std::map<String,VMInt8Array*> ScriptVM::builtInIntArrayVariables() {
400 return std::map<String,VMInt8Array*>();
401 }
402
403 std::map<String,VMDynVar*> ScriptVM::builtInDynamicVariables() {
404 std::map<String,VMDynVar*> m;
405
406 m["$NKSP_PERF_TIMER"] = m_varPerfTimer;
407 m["$NKSP_REAL_TIMER"] = m_varRealTimer;
408 m["$KSP_TIMER"] = m_varRealTimer;
409
410 return m;
411 }
412
413 std::map<String,vmint> ScriptVM::builtInConstIntVariables() {
414 std::map<String,vmint> m;
415
416 m["$NI_CB_TYPE_INIT"] = VM_EVENT_HANDLER_INIT;
417 m["$NI_CB_TYPE_NOTE"] = VM_EVENT_HANDLER_NOTE;
418 m["$NI_CB_TYPE_RELEASE"] = VM_EVENT_HANDLER_RELEASE;
419 m["$NI_CB_TYPE_CONTROLLER"] = VM_EVENT_HANDLER_CONTROLLER;
420
421 return m;
422 }
423
424 std::map<String,vmfloat> ScriptVM::builtInConstRealVariables() {
425 std::map<String,vmfloat> m;
426
427 m["~NI_MATH_PI"] = M_PI;
428 m["~NI_MATH_E"] = M_E;
429
430 return m;
431 }
432
433 VMEventHandler* ScriptVM::currentVMEventHandler() {
434 return m_eventHandler;
435 }
436
437 VMParserContext* ScriptVM::currentVMParserContext() {
438 return m_parserContext;
439 }
440
441 VMExecContext* ScriptVM::currentVMExecContext() {
442 if (!m_parserContext) return NULL;
443 return m_parserContext->execContext;
444 }
445
446 void ScriptVM::setAutoSuspendEnabled(bool b) {
447 m_autoSuspend = b;
448 }
449
450 bool ScriptVM::isAutoSuspendEnabled() const {
451 return m_autoSuspend;
452 }
453
454 void ScriptVM::setExitResultEnabled(bool b) {
455 m_acceptExitRes = b;
456 }
457
458 bool ScriptVM::isExitResultEnabled() const {
459 return m_acceptExitRes;
460 }
461
462 VMExecStatus_t ScriptVM::exec(VMParserContext* parserContext, VMExecContext* execContex, VMEventHandler* handler) {
463 m_parserContext = dynamic_cast<ParserContext*>(parserContext);
464 if (!m_parserContext) {
465 std::cerr << "No VM parser context provided. Did you load a script?\n";
466 return VMExecStatus_t(VM_EXEC_NOT_RUNNING | VM_EXEC_ERROR);
467 }
468
469 // a ParserContext object is always tied to exactly one ScriptVM object
470 assert(m_parserContext->functionProvider == this);
471
472 ExecContext* ctx = dynamic_cast<ExecContext*>(execContex);
473 if (!ctx) {
474 std::cerr << "Invalid VM exec context.\n";
475 return VMExecStatus_t(VM_EXEC_NOT_RUNNING | VM_EXEC_ERROR);
476 }
477 EventHandler* h = dynamic_cast<EventHandler*>(handler);
478 if (!h) return VM_EXEC_NOT_RUNNING;
479 m_eventHandler = handler;
480
481 m_parserContext->execContext = ctx;
482
483 ctx->status = VM_EXEC_RUNNING;
484 ctx->instructionsCount = 0;
485 ctx->clearExitRes();
486 StmtFlags_t& flags = ctx->flags;
487 vmint instructionsCounter = 0;
488 vmint synced = m_autoSuspend ? 0 : 1;
489
490 int& frameIdx = ctx->stackFrame;
491 if (frameIdx < 0) { // start condition ...
492 frameIdx = -1;
493 ctx->pushStack(h);
494 }
495
496 while (flags == STMT_SUCCESS && frameIdx >= 0) {
497 if (frameIdx >= ctx->stack.size()) { // should never happen, otherwise it's a bug ...
498 std::cerr << "CRITICAL: VM stack overflow! (" << frameIdx << ")\n";
499 flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);
500 break;
501 }
502
503 ExecContext::StackFrame& frame = ctx->stack[frameIdx];
504 switch (frame.statement->statementType()) {
505 case STMT_LEAF: {
506 #if DEBUG_SCRIPTVM_CORE
507 _printIndents(frameIdx);
508 printf("-> STMT_LEAF\n");
509 #endif
510 LeafStatement* leaf = (LeafStatement*) frame.statement;
511 flags = leaf->exec();
512 ctx->popStack();
513 break;
514 }
515
516 case STMT_LIST: {
517 #if DEBUG_SCRIPTVM_CORE
518 _printIndents(frameIdx);
519 printf("-> STMT_LIST subidx=%d\n", frame.subindex);
520 #endif
521 Statements* stmts = (Statements*) frame.statement;
522 if (stmts->statement(frame.subindex)) {
523 ctx->pushStack(
524 stmts->statement(frame.subindex++)
525 );
526 } else {
527 #if DEBUG_SCRIPTVM_CORE
528 _printIndents(frameIdx);
529 printf("[END OF LIST] subidx=%d\n", frame.subindex);
530 #endif
531 ctx->popStack();
532 }
533 break;
534 }
535
536 case STMT_BRANCH: {
537 #if DEBUG_SCRIPTVM_CORE
538 _printIndents(frameIdx);
539 printf("-> STMT_BRANCH\n");
540 #endif
541 if (frame.subindex < 0) ctx->popStack();
542 else {
543 BranchStatement* branchStmt = (BranchStatement*) frame.statement;
544 frame.subindex =
545 (decltype(frame.subindex))
546 branchStmt->evalBranch();
547 if (frame.subindex >= 0) {
548 ctx->pushStack(
549 branchStmt->branch(frame.subindex)
550 );
551 frame.subindex = -1;
552 } else ctx->popStack();
553 }
554 break;
555 }
556
557 case STMT_LOOP: {
558 #if DEBUG_SCRIPTVM_CORE
559 _printIndents(frameIdx);
560 printf("-> STMT_LOOP\n");
561 #endif
562 While* whileStmt = (While*) frame.statement;
563 if (whileStmt->evalLoopStartCondition() && whileStmt->statements()) {
564 ctx->pushStack(
565 whileStmt->statements()
566 );
567 if (flags == STMT_SUCCESS && !synced &&
568 instructionsCounter > SCRIPTVM_MAX_INSTR_PER_CYCLE_SOFT)
569 {
570 flags = StmtFlags_t(STMT_SUSPEND_SIGNALLED);
571 ctx->suspendMicroseconds = SCRIPT_VM_FORCE_SUSPENSION_MICROSECONDS;
572 }
573 } else ctx->popStack();
574 break;
575 }
576
577 case STMT_SYNC: {
578 #if DEBUG_SCRIPTVM_CORE
579 _printIndents(frameIdx);
580 printf("-> STMT_SYNC\n");
581 #endif
582 SyncBlock* syncStmt = (SyncBlock*) frame.statement;
583 if (!frame.subindex++ && syncStmt->statements()) {
584 ++synced;
585 ctx->pushStack(
586 syncStmt->statements()
587 );
588 } else {
589 ctx->popStack();
590 --synced;
591 }
592 break;
593 }
594
595 case STMT_NOOP:
596 break; // no operation like the name suggests
597 }
598
599 if (flags == STMT_SUCCESS && !synced &&
600 instructionsCounter > SCRIPTVM_MAX_INSTR_PER_CYCLE_HARD)
601 {
602 flags = StmtFlags_t(STMT_SUSPEND_SIGNALLED);
603 ctx->suspendMicroseconds = SCRIPT_VM_FORCE_SUSPENSION_MICROSECONDS;
604 }
605
606 ++instructionsCounter;
607 }
608
609 if ((flags & STMT_SUSPEND_SIGNALLED) && !(flags & STMT_ABORT_SIGNALLED)) {
610 ctx->status = VM_EXEC_SUSPENDED;
611 ctx->flags = STMT_SUCCESS;
612 } else {
613 ctx->status = VM_EXEC_NOT_RUNNING;
614 if (flags & STMT_ERROR_OCCURRED)
615 ctx->status = VM_EXEC_ERROR;
616 ctx->reset();
617 }
618
619 ctx->instructionsCount = instructionsCounter;
620
621 m_eventHandler = NULL;
622 m_parserContext->execContext = NULL;
623 m_parserContext = NULL;
624 return ctx->status;
625 }
626
627 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC