/[svn]/linuxsampler/trunk/src/scriptvm/tree.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/scriptvm/tree.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2935 - (show annotations) (download) (as text)
Sun Jul 10 14:24:13 2016 UTC (3 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 21132 byte(s)
* NKSP: Added & implemented built-in script function "change_cutoff()".
* NKSP: Added & implemented built-in script function "change_reso()".
* NKSP: Added & implemented built-in script function "event_status()".
* NKSP: Added built-in script constants "$EVENT_STATUS_INACTIVE" and
  "$EVENT_STATUS_NOTE_QUEUE" both for being used as flags for
  built-in "event_status()" script function.
* NKSP language: Added support for bitwise operators ".or.", ".and."
  and ".not.".
* NKSP language scanner: Fixed IDs matching to require at least one
  character (i.e. when matching function names or variable names).
* NKSP language scanner: disabled unusued rules.
* Bumped version (2.0.0.svn12).

1 /* -*- c++ -*-
2 *
3 * Copyright (c) 2014 - 2016 Christian Schoenebeck and Andreas Persson
4 *
5 * http://www.linuxsampler.org
6 *
7 * This file is part of LinuxSampler and released under the same terms.
8 * See README file for details.
9 */
10
11 // This header defines VM core implementation internal data types only used
12 // inside the parser and core VM implementation of this source directory. Not
13 // intended to be used in other source code parts (other source code
14 // directories) of the sampler.
15
16 #ifndef LS_INSTRPARSERTREE_H
17 #define LS_INSTRPARSERTREE_H
18
19 #include <vector>
20 #include <iostream>
21 #include <map>
22 #include <set>
23 #include "../common/global.h"
24 #include "../common/Ref.h"
25 #include "../common/ArrayList.h"
26 #include "common.h"
27
28 namespace LinuxSampler {
29
30 class ParserContext;
31 class ExecContext;
32
33 enum StmtType_t {
34 STMT_LEAF,
35 STMT_LIST,
36 STMT_BRANCH,
37 STMT_LOOP,
38 };
39
40 class Node {
41 public:
42 Node();
43 virtual ~Node();
44 virtual void dump(int level = 0) = 0;
45 virtual bool isPolyphonic() const = 0;
46 void printIndents(int n);
47 };
48 typedef Ref<Node> NodeRef;
49
50 class Expression : virtual public VMExpr, virtual public Node {
51 public:
52 virtual ExprType_t exprType() const = 0;
53 virtual bool isConstExpr() const = 0;
54 virtual String evalCastToStr() = 0;
55 };
56 typedef Ref<Expression,Node> ExpressionRef;
57
58 class IntExpr : virtual public VMIntExpr, virtual public Expression {
59 public:
60 ExprType_t exprType() const { return INT_EXPR; }
61 virtual int evalInt() = 0;
62 String evalCastToStr();
63 };
64 typedef Ref<IntExpr,Node> IntExprRef;
65
66 class StringExpr : virtual public VMStringExpr, virtual public Expression {
67 public:
68 ExprType_t exprType() const { return STRING_EXPR; }
69 virtual String evalStr() = 0;
70 String evalCastToStr() { return evalStr(); }
71 };
72 typedef Ref<StringExpr,Node> StringExprRef;
73
74 class IntLiteral : virtual public IntExpr {
75 int value;
76 public:
77 IntLiteral(int value) : value(value) { }
78 int evalInt();
79 void dump(int level = 0);
80 bool isConstExpr() const { return true; }
81 bool isPolyphonic() const { return false; }
82 };
83 typedef Ref<IntLiteral,Node> IntLiteralRef;
84
85 class StringLiteral : virtual public StringExpr {
86 public:
87 String value;
88 StringLiteral(const String& value) : value(value) { }
89 bool isConstExpr() const { return true; }
90 void dump(int level = 0);
91 String evalStr() { return value; }
92 bool isPolyphonic() const { return false; }
93 };
94 typedef Ref<StringLiteral,Node> StringLiteralRef;
95
96 class Args : virtual public VMFnArgs, virtual public Node {
97 public:
98 std::vector<ExpressionRef> args;
99 void add(ExpressionRef arg) { args.push_back(arg); }
100 void dump(int level = 0);
101 int argsCount() const { return args.size(); }
102 VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; }
103 bool isPolyphonic() const;
104 };
105 typedef Ref<Args,Node> ArgsRef;
106
107 class Variable : virtual public Expression {
108 public:
109 virtual bool isConstExpr() const { return bConst; }
110 virtual void assign(Expression* expr) = 0;
111 protected:
112 Variable(ParserContext* ctx, int _memPos, bool _bConst)
113 : context(ctx), memPos(_memPos), bConst(_bConst) {}
114
115 ParserContext* context;
116 int memPos;
117 bool bConst;
118 };
119 typedef Ref<Variable,Node> VariableRef;
120
121 class IntVariable : public Variable, virtual public IntExpr {
122 bool polyphonic;
123 public:
124 IntVariable(ParserContext* ctx);
125 void assign(Expression* expr);
126 int evalInt();
127 void dump(int level = 0);
128 bool isPolyphonic() const { return polyphonic; }
129 protected:
130 IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, int size = 1);
131 };
132 typedef Ref<IntVariable,Node> IntVariableRef;
133
134 class ConstIntVariable : public IntVariable {
135 public:
136 int value;
137
138 ConstIntVariable(int value);
139 //ConstIntVariable(ParserContext* ctx, int value = 0);
140 void assign(Expression* expr);
141 int evalInt();
142 void dump(int level = 0);
143 };
144 typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
145
146 class BuiltInIntVariable : public IntVariable {
147 String name;
148 VMIntRelPtr* ptr;
149 public:
150 BuiltInIntVariable(const String& name, VMIntRelPtr* ptr);
151 void assign(Expression* expr);
152 int evalInt();
153 void dump(int level = 0);
154 };
155 typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
156
157 class PolyphonicIntVariable : public IntVariable {
158 public:
159 PolyphonicIntVariable(ParserContext* ctx);
160 void dump(int level = 0);
161 };
162 typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
163
164 class IntArrayVariable : public Variable, virtual public VMIntArrayExpr {
165 ArrayList<int> values;
166 public:
167 IntArrayVariable(ParserContext* ctx, int size);
168 IntArrayVariable(ParserContext* ctx, int size, ArgsRef values);
169 void assign(Expression* expr) {} // ignore scalar assignment
170 String evalCastToStr() { return ""; } // ignore scalar cast to string
171 ExprType_t exprType() const { return INT_ARR_EXPR; }
172 virtual int arraySize() const { return values.size(); }
173 virtual int evalIntElement(uint i);
174 virtual void assignIntElement(uint i, int value);
175 void dump(int level = 0);
176 bool isPolyphonic() const { return false; }
177 protected:
178 IntArrayVariable(ParserContext* ctx, bool bConst);
179 };
180 typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
181
182 class BuiltInIntArrayVariable : public IntArrayVariable {
183 String name;
184 VMInt8Array* array;
185 public:
186 BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
187 int arraySize() const { return array->size; }
188 int evalIntElement(uint i);
189 void assignIntElement(uint i, int value);
190 void dump(int level = 0);
191 };
192 typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
193
194 class IntArrayElement : public IntVariable {
195 IntArrayVariableRef array;
196 IntExprRef index;
197 public:
198 IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex);
199 void assign(Expression* expr);
200 int evalInt();
201 void dump(int level = 0);
202 };
203 typedef Ref<IntArrayElement,Node> IntArrayElementRef;
204
205 class StringVariable : public Variable, virtual public StringExpr {
206 public:
207 StringVariable(ParserContext* ctx);
208 void assign(Expression* expr);
209 String evalStr();
210 void dump(int level = 0);
211 bool isPolyphonic() const { return false; }
212 protected:
213 StringVariable(ParserContext* ctx, bool bConst);
214 };
215 typedef Ref<StringVariable,Node> StringVariableRef;
216
217 class ConstStringVariable : public StringVariable {
218 public:
219 String value;
220
221 ConstStringVariable(ParserContext* ctx, String value = "");
222 void assign(Expression* expr);
223 String evalStr();
224 void dump(int level = 0);
225 };
226 typedef Ref<ConstStringVariable,Node> ConstStringVariableRef;
227
228 class BinaryOp : virtual public Expression {
229 protected:
230 ExpressionRef lhs;
231 ExpressionRef rhs;
232 public:
233 BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }
234 bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); }
235 bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
236 };
237 typedef Ref<BinaryOp,Node> BinaryOpRef;
238
239 class Add : virtual public BinaryOp, virtual public IntExpr {
240 public:
241 Add(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
242 int evalInt();
243 void dump(int level = 0);
244 };
245 typedef Ref<Add,Node> AddRef;
246
247 class Sub : virtual public BinaryOp, virtual public IntExpr {
248 public:
249 Sub(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
250 int evalInt();
251 void dump(int level = 0);
252 };
253 typedef Ref<Sub,Node> SubRef;
254
255 class Mul : virtual public BinaryOp, virtual public IntExpr {
256 public:
257 Mul(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
258 int evalInt();
259 void dump(int level = 0);
260 };
261 typedef Ref<Mul,Node> MulRef;
262
263 class Div : virtual public BinaryOp, virtual public IntExpr {
264 public:
265 Div(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
266 int evalInt();
267 void dump(int level = 0);
268 };
269 typedef Ref<Div,Node> DivRef;
270
271 class Mod : virtual public BinaryOp, virtual public IntExpr {
272 public:
273 Mod(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
274 int evalInt();
275 void dump(int level = 0);
276 };
277 typedef Ref<Mod,Node> ModRef;
278
279 class Statement : virtual public Node {
280 public:
281 virtual StmtType_t statementType() const = 0;
282 };
283 typedef Ref<Statement,Node> StatementRef;
284
285 // Just used by parser to avoid "not a statement" parser warning, will be
286 // filtered out by parser. So it will not be part of the VM tree after parsing.
287 class NoOperation : public Statement {
288 public:
289 NoOperation() : Statement() {}
290 StmtType_t statementType() const { return STMT_LEAF; }
291 void dump(int level = 0) {}
292 bool isPolyphonic() const { return false; }
293 };
294 typedef Ref<NoOperation,Node> NoOperationRef;
295
296 bool isNoOperation(StatementRef statement);
297
298 class LeafStatement : public Statement {
299 public:
300 virtual StmtFlags_t exec() = 0;
301 virtual StmtType_t statementType() const { return STMT_LEAF; }
302 };
303 typedef Ref<LeafStatement,Node> LeafStatementRef;
304
305 class Statements : public Statement {
306 std::vector<StatementRef> args;
307 public:
308 void add(StatementRef arg) { args.push_back(arg); }
309 void dump(int level = 0);
310 StmtType_t statementType() const { return STMT_LIST; }
311 virtual Statement* statement(uint i);
312 bool isPolyphonic() const;
313 };
314 typedef Ref<Statements,Node> StatementsRef;
315
316 class BranchStatement : public Statement {
317 public:
318 StmtType_t statementType() const { return STMT_BRANCH; }
319 virtual int evalBranch() = 0;
320 virtual Statements* branch(uint i) const = 0;
321 };
322
323 class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {
324 String functionName;
325 ArgsRef args;
326 VMFunction* fn;
327 public:
328 FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :
329 functionName(function), args(args), fn(fn) { }
330 void dump(int level = 0);
331 StmtFlags_t exec();
332 int evalInt();
333 String evalStr();
334 bool isConstExpr() const { return false; }
335 ExprType_t exprType() const;
336 String evalCastToStr();
337 bool isPolyphonic() const { return args->isPolyphonic(); }
338 protected:
339 VMFnResult* execVMFn();
340 };
341 typedef Ref<FunctionCall,Node> FunctionCallRef;
342
343 class EventHandler : virtual public Statements, virtual public VMEventHandler {
344 StatementsRef statements;
345 bool usingPolyphonics;
346 public:
347 void dump(int level = 0);
348 StmtFlags_t exec();
349 EventHandler(StatementsRef statements);
350 Statement* statement(uint i) { return statements->statement(i); }
351 bool isPolyphonic() const { return usingPolyphonics; }
352 };
353 typedef Ref<EventHandler,Node> EventHandlerRef;
354
355 class OnNote : public EventHandler {
356 public:
357 OnNote(StatementsRef statements) : EventHandler(statements) {}
358 VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_NOTE; }
359 String eventHandlerName() const { return "note"; }
360 };
361 typedef Ref<OnNote,Node> OnNoteRef;
362
363 class OnInit : public EventHandler {
364 public:
365 OnInit(StatementsRef statements) : EventHandler(statements) {}
366 VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_INIT; }
367 String eventHandlerName() const { return "init"; }
368 };
369 typedef Ref<OnInit,Node> OnInitRef;
370
371 class OnRelease : public EventHandler {
372 public:
373 OnRelease(StatementsRef statements) : EventHandler(statements) {}
374 VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_RELEASE; }
375 String eventHandlerName() const { return "release"; }
376 };
377 typedef Ref<OnRelease,Node> OnReleaseRef;
378
379 class OnController : public EventHandler {
380 public:
381 OnController(StatementsRef statements) : EventHandler(statements) {}
382 VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_CONTROLLER; }
383 String eventHandlerName() const { return "controller"; }
384 };
385 typedef Ref<OnController,Node> OnControllerRef;
386
387 class EventHandlers : virtual public Node {
388 std::vector<EventHandlerRef> args;
389 public:
390 EventHandlers();
391 ~EventHandlers();
392 void add(EventHandlerRef arg);
393 void dump(int level = 0);
394 int evalInt() { return 0; }
395 EventHandler* eventHandlerByName(const String& name) const;
396 EventHandler* eventHandler(uint index) const;
397 inline uint size() const { return args.size(); }
398 bool isPolyphonic() const;
399 };
400 typedef Ref<EventHandlers,Node> EventHandlersRef;
401
402 class Assignment : public LeafStatement {
403 protected:
404 VariableRef variable;
405 ExpressionRef value;
406 public:
407 Assignment(VariableRef variable, ExpressionRef value);
408 void dump(int level = 0);
409 StmtFlags_t exec();
410 bool isPolyphonic() const { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); }
411 };
412 typedef Ref<Assignment,Node> AssignmentRef;
413
414 class If : public BranchStatement {
415 IntExprRef condition;
416 StatementsRef ifStatements;
417 StatementsRef elseStatements;
418 public:
419 If(IntExprRef condition, StatementsRef ifStatements, StatementsRef elseStatements) :
420 condition(condition), ifStatements(ifStatements), elseStatements(elseStatements) { }
421 If(IntExprRef condition, StatementsRef statements) :
422 condition(condition), ifStatements(statements) { }
423 void dump(int level = 0);
424 int evalBranch();
425 Statements* branch(uint i) const;
426 bool isPolyphonic() const;
427 };
428 typedef Ref<If,Node> IfRef;
429
430 struct CaseBranch {
431 IntExprRef from;
432 IntExprRef to;
433 StatementsRef statements;
434 };
435
436 typedef std::vector<CaseBranch> CaseBranches;
437
438 class SelectCase : public BranchStatement {
439 IntExprRef select;
440 CaseBranches branches;
441 public:
442 SelectCase(IntExprRef select, const CaseBranches& branches) : select(select), branches(branches) { }
443 void dump(int level = 0);
444 int evalBranch();
445 Statements* branch(uint i) const;
446 //void addBranch(IntExprRef condition, StatementsRef statements);
447 //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);
448 //void addBranch(CaseBranchRef branch);
449 //void addBranches(CaseBranchesRef branches);
450 bool isPolyphonic() const;
451 };
452 typedef Ref<SelectCase,Node> SelectCaseRef;
453
454 class While : public Statement {
455 IntExprRef m_condition;
456 StatementsRef m_statements;
457 public:
458 While(IntExprRef condition, StatementsRef statements) :
459 m_condition(condition), m_statements(statements) {}
460 StmtType_t statementType() const { return STMT_LOOP; }
461 void dump(int level = 0);
462 bool evalLoopStartCondition();
463 Statements* statements() const;
464 bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
465 };
466
467 class Neg : public IntExpr {
468 IntExprRef expr;
469 public:
470 Neg(IntExprRef expr) : expr(expr) { }
471 int evalInt() { return (expr) ? -expr->evalInt() : 0; }
472 void dump(int level = 0);
473 bool isConstExpr() const { return expr->isConstExpr(); }
474 bool isPolyphonic() const { return expr->isPolyphonic(); }
475 };
476 typedef Ref<Neg,Node> NegRef;
477
478 class ConcatString : public StringExpr {
479 ExpressionRef lhs;
480 ExpressionRef rhs;
481 public:
482 ConcatString(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) {}
483 String evalStr();
484 void dump(int level = 0);
485 bool isConstExpr() const;
486 bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
487 };
488 typedef Ref<ConcatString,Node> ConcatStringRef;
489
490 class Relation : public IntExpr {
491 public:
492 enum Type {
493 LESS_THAN,
494 GREATER_THAN,
495 LESS_OR_EQUAL,
496 GREATER_OR_EQUAL,
497 EQUAL,
498 NOT_EQUAL
499 };
500 Relation(IntExprRef lhs, Type type, IntExprRef rhs) :
501 lhs(lhs), rhs(rhs), type(type) {}
502 int evalInt();
503 void dump(int level = 0);
504 bool isConstExpr() const;
505 bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
506 private:
507 IntExprRef lhs;
508 IntExprRef rhs;
509 Type type;
510 };
511 typedef Ref<Relation,Node> RelationRef;
512
513 class Or : virtual public BinaryOp, virtual public IntExpr {
514 public:
515 Or(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
516 int evalInt();
517 void dump(int level = 0);
518 };
519 typedef Ref<Or,Node> OrRef;
520
521 class BitwiseOr : virtual public BinaryOp, virtual public IntExpr {
522 public:
523 BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
524 int evalInt();
525 void dump(int level = 0);
526 };
527 typedef Ref<BitwiseOr,Node> BitwiseOrRef;
528
529 class And : virtual public BinaryOp, virtual public IntExpr {
530 public:
531 And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
532 int evalInt();
533 void dump(int level = 0);
534 };
535 typedef Ref<And,Node> AndRef;
536
537 class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr {
538 public:
539 BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
540 int evalInt();
541 void dump(int level = 0);
542 };
543 typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
544
545 class Not : virtual public IntExpr {
546 IntExprRef expr;
547 public:
548 Not(IntExprRef expr) : expr(expr) {}
549 int evalInt() { return !expr->evalInt(); }
550 void dump(int level = 0);
551 bool isConstExpr() const { return expr->isConstExpr(); }
552 bool isPolyphonic() const { return expr->isPolyphonic(); }
553 };
554 typedef Ref<Not,Node> NotRef;
555
556 class BitwiseNot : virtual public IntExpr {
557 IntExprRef expr;
558 public:
559 BitwiseNot(IntExprRef expr) : expr(expr) {}
560 int evalInt() { return ~expr->evalInt(); }
561 void dump(int level = 0);
562 bool isConstExpr() const { return expr->isConstExpr(); }
563 bool isPolyphonic() const { return expr->isPolyphonic(); }
564 };
565 typedef Ref<BitwiseNot,Node> BitwiseNotRef;
566
567 class ParserContext : public VMParserContext {
568 public:
569 struct Error {
570 String txt;
571 int line;
572 };
573 typedef Error Warning;
574
575 void* scanner;
576 std::istream* is;
577 std::vector<ParserIssue> vErrors;
578 std::vector<ParserIssue> vWarnings;
579 std::vector<ParserIssue> vIssues;
580
581 std::set<String> builtinPreprocessorConditions;
582 std::set<String> userPreprocessorConditions;
583
584 std::map<String,VariableRef> vartable;
585 int globalIntVarCount;
586 int globalStrVarCount;
587 int polyphonicIntVarCount;
588
589 EventHandlersRef handlers;
590
591 OnInitRef onInit;
592 OnNoteRef onNote;
593 OnReleaseRef onRelease;
594 OnControllerRef onController;
595
596 ArrayList<int>* globalIntMemory;
597 ArrayList<String>* globalStrMemory;
598 int requiredMaxStackSize;
599
600 VMFunctionProvider* functionProvider;
601
602 ExecContext* execContext;
603
604 ParserContext(VMFunctionProvider* parent) :
605 scanner(NULL), is(NULL),
606 globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),
607 globalIntMemory(NULL), globalStrMemory(NULL), requiredMaxStackSize(-1),
608 functionProvider(parent), execContext(NULL)
609 {
610 }
611 virtual ~ParserContext();
612 VariableRef globalVar(const String& name);
613 IntVariableRef globalIntVar(const String& name);
614 StringVariableRef globalStrVar(const String& name);
615 VariableRef variableByName(const String& name);
616 void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
617 void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
618 void createScanner(std::istream* is);
619 void destroyScanner();
620 bool setPreprocessorCondition(const char* name);
621 bool resetPreprocessorCondition(const char* name);
622 bool isPreprocessorConditionSet(const char* name);
623 std::vector<ParserIssue> issues() const OVERRIDE;
624 std::vector<ParserIssue> errors() const OVERRIDE;
625 std::vector<ParserIssue> warnings() const OVERRIDE;
626 VMEventHandler* eventHandler(uint index) OVERRIDE;
627 VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
628 void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
629 void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);
630 void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
631 };
632
633 class ExecContext : public VMExecContext {
634 public:
635 struct StackFrame {
636 Statement* statement;
637 int subindex;
638
639 StackFrame() {
640 statement = NULL;
641 subindex = -1;
642 }
643 };
644
645 ArrayList<int> polyphonicIntMemory;
646 VMExecStatus_t status;
647 ArrayList<StackFrame> stack;
648 int stackFrame;
649 int suspendMicroseconds;
650
651 ExecContext() :
652 status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {}
653
654 virtual ~ExecContext() {}
655
656 inline void pushStack(Statement* stmt) {
657 stackFrame++;
658 //printf("pushStack() -> %d\n", stackFrame);
659 if (stackFrame >= stack.size()) return;
660 stack[stackFrame].statement = stmt;
661 stack[stackFrame].subindex = 0;
662 }
663
664 inline void popStack() {
665 stack[stackFrame].statement = NULL;
666 stack[stackFrame].subindex = -1;
667 stackFrame--;
668 //printf("popStack() -> %d\n", stackFrame);
669 }
670
671 inline void reset() {
672 stack[0].statement = NULL;
673 stack[0].subindex = -1;
674 stackFrame = -1;
675 }
676
677 int suspensionTimeMicroseconds() const OVERRIDE {
678 return suspendMicroseconds;
679 }
680 };
681
682 } // namespace LinuxSampler
683
684 #endif // LS_INSTRPARSERTREE_H

  ViewVC Help
Powered by ViewVC