/[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 3729 - (show annotations) (download) (as text)
Fri Jan 31 10:57:53 2020 UTC (4 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 40183 byte(s)
NKSP parser: track code locations also by raw byte position and length.

* NKSP VM API: Added member variables 'firstByte' and 'lengthBytes' to
  struct 'CodeBlock'.

* NKSP Editor API: Added methods firstByte() and lengthBytes() to
  class 'VMSourceToken'.

* NKSP VM language parser: track all positions also by raw byte offset
  and length (along to the already existing tracking by line/column).

* NKSP editor syntax highlighting scanner: track all positions also by
  raw byte offset and length (along to the already existing tracking by
  line/column).

* Bumped version (2.1.1.svn45).

1 /* -*- c++ -*-
2 *
3 * Copyright (c) 2014 - 2019 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 <string.h> // for memset()
24 #include <assert.h>
25 #include "../common/global.h"
26 #include "../common/Ref.h"
27 #include "../common/ArrayList.h"
28 #include "common.h"
29
30 namespace LinuxSampler {
31
32 class ParserContext;
33 class ExecContext;
34
35 enum StmtType_t {
36 STMT_LEAF,
37 STMT_LIST,
38 STMT_BRANCH,
39 STMT_LOOP,
40 STMT_SYNC,
41 STMT_NOOP,
42 };
43
44 enum Qualifier_t {
45 QUALIFIER_NONE = 0,
46 QUALIFIER_CONST = 1,
47 QUALIFIER_POLYPHONIC = (1<<1),
48 };
49
50 /**
51 * Convenience function used for retrieving the (assumed) data type of a given
52 * script variable name.
53 *
54 * @param name - some script variable name (e.g. "$foo")
55 * @return variable's assumed data type (e.g. INT_EXPR for example above)
56 */
57 inline ExprType_t exprTypeOfVarName(const String& name) {
58 if (name.empty()) return (ExprType_t) -1;
59 const char prefix = name[0];
60 switch (prefix) {
61 case '$': return INT_EXPR;
62 case '%': return INT_ARR_EXPR;
63 case '~': return REAL_EXPR;
64 case '?': return REAL_ARR_EXPR;
65 case '@': return STRING_EXPR;
66 case '!': return STRING_ARR_EXPR;
67 }
68 return (ExprType_t) -1;
69 }
70
71 inline ExprType_t scalarTypeOfArray(ExprType_t arrayType) {
72 if (arrayType == INT_ARR_EXPR) return INT_EXPR;
73 if (arrayType == REAL_ARR_EXPR) return REAL_EXPR;
74 if (arrayType == STRING_ARR_EXPR) return STRING_EXPR;
75 assert(false);
76 return EMPTY_EXPR; // just to shut up the compiler
77 }
78
79 inline String qualifierStr(Qualifier_t qualifier) {
80 switch (qualifier) {
81 case QUALIFIER_NONE: return "none";
82 case QUALIFIER_CONST: return "const";
83 case QUALIFIER_POLYPHONIC: return "polyphonic";
84 }
85 return "unknown";
86 }
87
88 /**
89 * Used by parser for parser error messages to provide a text with all data
90 * types accepted by the given built-in function @a fn for the respective
91 * function argument @a iArg.
92 */
93 String acceptedArgTypesStr(VMFunction* fn, vmint iArg);
94
95 class Node {
96 public:
97 Node();
98 virtual ~Node();
99 virtual void dump(int level = 0) = 0;
100 virtual bool isPolyphonic() const = 0;
101 void printIndents(int n);
102 };
103 typedef Ref<Node> NodeRef;
104
105 class Expression : virtual public VMExpr, virtual public Node {
106 public:
107 virtual ExprType_t exprType() const = 0;
108 virtual bool isConstExpr() const = 0;
109 virtual String evalCastToStr() = 0;
110 };
111 typedef Ref<Expression,Node> ExpressionRef;
112
113 class Unit : virtual public VMUnit, virtual public Node {
114 StdUnit_t unit;
115 public:
116 Unit(StdUnit_t type) : unit(type) {}
117 StdUnit_t unitType() const OVERRIDE { return unit; }
118 static vmint convIntToUnitFactor(vmint iValue, VMUnit* srcUnit, VMUnit* dstUnit);
119 static vmint convIntToUnitFactor(vmint iValue, vmfloat srcFactor, vmfloat dstFactor);
120 static vmfloat convRealToUnitFactor(vmfloat fValue, VMUnit* srcUnit, VMUnit* dstUnit);
121 static vmfloat convRealToUnitFactor(vmfloat fValue, vmfloat srcFactor, vmfloat dstFactor);
122 };
123 typedef Ref<Unit,Node> UnitRef;
124
125 class NumberExpr : virtual public Unit, virtual public VMNumberExpr, virtual public Expression {
126 public:
127 };
128 typedef Ref<NumberExpr,Node> NumberExprRef;
129
130 class IntExpr : virtual public NumberExpr, virtual public VMIntExpr {
131 public:
132 ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
133 vmint evalIntToUnitFactor(vmfloat unitFactor);
134 String evalCastToStr() OVERRIDE;
135 };
136 typedef Ref<IntExpr,Node> IntExprRef;
137
138 class RealExpr : virtual public NumberExpr, virtual public VMRealExpr {
139 public:
140 ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
141 vmfloat evalRealToUnitFactor(vmfloat unitFactor);
142 String evalCastToStr() OVERRIDE;
143 };
144 typedef Ref<RealExpr,Node> RealExprRef;
145
146 class ArrayExpr : virtual public VMArrayExpr, virtual public Expression {
147 public:
148 };
149 typedef Ref<ArrayExpr,Node> ArrayExprRef;
150
151 class IntArrayExpr : virtual public VMIntArrayExpr, virtual public ArrayExpr {
152 public:
153 ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
154 String evalCastToStr() OVERRIDE;
155 };
156 typedef Ref<IntArrayExpr,Node> IntArrayExprRef;
157
158 class RealArrayExpr : virtual public VMRealArrayExpr, virtual public ArrayExpr {
159 public:
160 ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
161 String evalCastToStr() OVERRIDE;
162 };
163 typedef Ref<RealArrayExpr,Node> RealArrayExprRef;
164
165 class StringExpr : virtual public VMStringExpr, virtual public Expression {
166 public:
167 ExprType_t exprType() const OVERRIDE { return STRING_EXPR; }
168 String evalCastToStr() OVERRIDE { return evalStr(); }
169 };
170 typedef Ref<StringExpr,Node> StringExprRef;
171
172 struct IntLitDef {
173 vmint value; //NOTE: sequence matters! Since this is usually initialized with VMIntExpr::evalInt() it should be before member unitFactor, since the latter is usually initialized with VMIntExpr::unitFactor() which does not evaluate the expression.
174 vmfloat unitFactor = VM_NO_FACTOR;
175 StdUnit_t unitType = VM_NO_UNIT;
176 bool isFinal;
177 };
178
179 class IntLiteral FINAL : public IntExpr {
180 bool finalVal;
181 vmfloat unitPrefixFactor;
182 vmint value;
183 public:
184 IntLiteral(const IntLitDef& def);
185 vmint evalInt() OVERRIDE;
186 vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
187 void dump(int level = 0) OVERRIDE;
188 bool isConstExpr() const OVERRIDE { return true; }
189 bool isPolyphonic() const OVERRIDE { return false; }
190 bool isFinal() const OVERRIDE { return finalVal; }
191 };
192 typedef Ref<IntLiteral,Node> IntLiteralRef;
193
194 struct RealLitDef {
195 vmfloat value; //NOTE: sequence matters! Since this is usually initialized with VMRealExpr::evalReal() it should be before member unitFactor, since the latter is usually initialized with VMRealExpr::unitFactor() which does not evaluate the expression.
196 vmfloat unitFactor = VM_NO_FACTOR;
197 StdUnit_t unitType = VM_NO_UNIT;
198 bool isFinal;
199 };
200
201 class RealLiteral FINAL : public RealExpr {
202 bool finalVal;
203 vmfloat unitPrefixFactor;
204 vmfloat value;
205 public:
206 RealLiteral(const RealLitDef& def);
207 vmfloat evalReal() OVERRIDE;
208 vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
209 void dump(int level = 0) OVERRIDE;
210 bool isConstExpr() const OVERRIDE { return true; }
211 bool isPolyphonic() const OVERRIDE { return false; }
212 bool isFinal() const OVERRIDE { return finalVal; }
213 };
214 typedef Ref<RealLiteral,Node> RealLiteralRef;
215
216 class StringLiteral FINAL : public StringExpr {
217 String value;
218 public:
219 StringLiteral(const String& value) : value(value) { }
220 bool isConstExpr() const OVERRIDE { return true; }
221 void dump(int level = 0) OVERRIDE;
222 String evalStr() OVERRIDE { return value; }
223 bool isPolyphonic() const OVERRIDE { return false; }
224 };
225 typedef Ref<StringLiteral,Node> StringLiteralRef;
226
227 class Args FINAL : virtual public VMFnArgs, virtual public Node {
228 public:
229 std::vector<ExpressionRef> args;
230 void add(ExpressionRef arg) { args.push_back(arg); }
231 void dump(int level = 0) OVERRIDE;
232 vmint argsCount() const OVERRIDE { return (vmint) args.size(); }
233 VMExpr* arg(vmint i) OVERRIDE { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; }
234 bool isPolyphonic() const OVERRIDE;
235 };
236 typedef Ref<Args,Node> ArgsRef;
237
238 struct VariableDecl {
239 ParserContext* ctx;
240 bool isPolyphonic;
241 bool isConst;
242 vmint elements = 1;
243 vmint memPos;
244 vmint unitFactorMemPos;
245 StdUnit_t unitType = VM_NO_UNIT;
246 bool isFinal;
247 };
248
249 class Variable : virtual public VMVariable, virtual public Expression {
250 public:
251 bool isConstExpr() const OVERRIDE { return bConst; }
252 bool isAssignable() const OVERRIDE { return !bConst; }
253 virtual void assign(Expression* expr) = 0;
254 void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }
255 protected:
256 Variable(const VariableDecl& decl);
257
258 ParserContext* context;
259 vmint memPos;
260 bool bConst;
261 };
262 typedef Ref<Variable,Node> VariableRef;
263
264 class NumberVariable : public Variable, virtual public NumberExpr {
265 bool polyphonic;
266 bool finalVal;
267 protected:
268 vmint unitFactorMemPos;
269 public:
270 bool isPolyphonic() const OVERRIDE { return polyphonic; }
271 bool isFinal() const OVERRIDE { return finalVal; }
272 vmfloat unitFactor() const OVERRIDE;
273 protected:
274 NumberVariable(const VariableDecl& decl);
275 };
276 typedef Ref<NumberVariable,Node> NumberVariableRef;
277
278 class IntVariable : public NumberVariable, virtual public IntExpr {
279 public:
280 IntVariable(const VariableDecl& decl);
281 void assign(Expression* expr) OVERRIDE;
282 vmint evalInt() OVERRIDE;
283 void dump(int level = 0) OVERRIDE;
284 };
285 typedef Ref<IntVariable,Node> IntVariableRef;
286
287 class RealVariable : public NumberVariable, virtual public RealExpr {
288 public:
289 RealVariable(const VariableDecl& decl);
290 void assign(Expression* expr) OVERRIDE;
291 vmfloat evalReal() OVERRIDE;
292 void dump(int level = 0) OVERRIDE;
293 };
294 typedef Ref<RealVariable,Node> RealVariableRef;
295
296 struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
297 // additions for RealVarDef
298 vmint value = 0; //NOTE: sequence matters! Since this is usually initialized with VMIntExpr::evalInt() it should be before member unitFactor, since the latter is usually initialized with VMIntExpr::unitFactor() which does not evaluate the expression.
299 vmfloat unitFactor = VM_NO_FACTOR;
300 // copied from VariableDecl
301 ParserContext* ctx;
302 bool isPolyphonic;
303 bool isConst;
304 vmint elements = 1;
305 vmint memPos;
306 vmint unitFactorMemPos;
307 StdUnit_t unitType = VM_NO_UNIT;
308 bool isFinal;
309 };
310
311 class ConstIntVariable FINAL : public IntVariable {
312 vmfloat unitPrefixFactor;
313 vmint value;
314 public:
315 ConstIntVariable(const IntVarDef& def);
316 void assign(Expression* expr) OVERRIDE;
317 vmint evalInt() OVERRIDE;
318 vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
319 void dump(int level = 0) OVERRIDE;
320 };
321 typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
322
323 struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
324 // additions for RealVarDef
325 vmfloat value = vmfloat(0); //NOTE: sequence matters! Since this is usually initialized with VMRealExpr::evalReal() it should be before member unitFactor, since the latter is usually initialized with VMRealExpr::unitFactor() which does not evaluate the expression.
326 vmfloat unitFactor = VM_NO_FACTOR;
327 // copied from VariableDecl
328 ParserContext* ctx;
329 bool isPolyphonic;
330 bool isConst;
331 vmint elements = 1;
332 vmint memPos;
333 vmint unitFactorMemPos;
334 StdUnit_t unitType = VM_NO_UNIT;
335 bool isFinal;
336 };
337
338 class ConstRealVariable FINAL : public RealVariable {
339 vmfloat unitPrefixFactor;
340 vmfloat value;
341 public:
342 ConstRealVariable(const RealVarDef& def);
343 void assign(Expression* expr) OVERRIDE;
344 vmfloat evalReal() OVERRIDE;
345 vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
346 void dump(int level = 0) OVERRIDE;
347 };
348 typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;
349
350 class BuiltInIntVariable FINAL : public IntVariable {
351 String name;
352 VMIntPtr* ptr;
353 public:
354 BuiltInIntVariable(const String& name, VMIntPtr* ptr);
355 bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }
356 void assign(Expression* expr) OVERRIDE;
357 vmint evalInt() OVERRIDE;
358 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
359 void dump(int level = 0) OVERRIDE;
360 };
361 typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
362
363 class PolyphonicIntVariable FINAL : public IntVariable {
364 public:
365 PolyphonicIntVariable(const VariableDecl& decl);
366 void dump(int level = 0) OVERRIDE;
367 };
368 typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
369
370 class PolyphonicRealVariable FINAL : public RealVariable {
371 public:
372 PolyphonicRealVariable(const VariableDecl& decl);
373 void dump(int level = 0) OVERRIDE;
374 };
375 typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;
376
377 class IntArrayVariable : public Variable, virtual public IntArrayExpr {
378 ArrayList<vmint> values;
379 ArrayList<vmfloat> unitFactors;
380 public:
381 IntArrayVariable(ParserContext* ctx, vmint size);
382 IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
383 void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment
384 ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
385 virtual vmint arraySize() const OVERRIDE { return values.size(); }
386 virtual vmint evalIntElement(vmuint i) OVERRIDE;
387 virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;
388 vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
389 void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
390 void dump(int level = 0) OVERRIDE;
391 bool isPolyphonic() const OVERRIDE { return false; }
392 protected:
393 IntArrayVariable(ParserContext* ctx, bool bConst);
394 };
395 typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
396
397 class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {
398 ArrayList<vmfloat> values;
399 ArrayList<vmfloat> unitFactors;
400 public:
401 RealArrayVariable(ParserContext* ctx, vmint size);
402 RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
403 void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment
404 ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
405 virtual vmint arraySize() const OVERRIDE { return values.size(); }
406 virtual vmfloat evalRealElement(vmuint i) OVERRIDE;
407 virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;
408 vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
409 void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
410 void dump(int level = 0) OVERRIDE;
411 bool isPolyphonic() const OVERRIDE { return false; }
412 protected:
413 RealArrayVariable(ParserContext* ctx, bool bConst);
414 };
415 typedef Ref<RealArrayVariable,Node> RealArrayVariableRef;
416
417 class BuiltInIntArrayVariable FINAL : public IntArrayVariable {
418 String name;
419 VMInt8Array* array;
420 public:
421 BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
422 vmint arraySize() const OVERRIDE { return array->size; }
423 vmint evalIntElement(vmuint i) OVERRIDE;
424 void assignIntElement(vmuint i, vmint value) OVERRIDE;
425 vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
426 void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
427 bool isAssignable() const OVERRIDE { return !array->readonly; }
428 void dump(int level = 0) OVERRIDE;
429 };
430 typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
431
432 class IntArrayElement FINAL : public IntVariable {
433 IntArrayExprRef array;
434 IntExprRef index;
435 vmint currentIndex;
436 public:
437 IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);
438 void assign(Expression* expr) OVERRIDE;
439 vmint evalInt() OVERRIDE;
440 vmfloat unitFactor() const OVERRIDE;
441 void dump(int level = 0) OVERRIDE;
442 };
443 typedef Ref<IntArrayElement,Node> IntArrayElementRef;
444
445 class RealArrayElement FINAL : public RealVariable {
446 RealArrayExprRef array;
447 IntExprRef index;
448 vmint currentIndex;
449 public:
450 RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);
451 void assign(Expression* expr) OVERRIDE;
452 vmfloat evalReal() OVERRIDE;
453 vmfloat unitFactor() const OVERRIDE;
454 void dump(int level = 0) OVERRIDE;
455 };
456 typedef Ref<RealArrayElement,Node> RealArrayElementRef;
457
458 class StringVariable : public Variable, virtual public StringExpr {
459 public:
460 StringVariable(ParserContext* ctx);
461 void assign(Expression* expr) OVERRIDE;
462 String evalStr() OVERRIDE;
463 void dump(int level = 0) OVERRIDE;
464 bool isPolyphonic() const OVERRIDE { return false; }
465 protected:
466 StringVariable(ParserContext* ctx, bool bConst);
467 };
468 typedef Ref<StringVariable,Node> StringVariableRef;
469
470 class ConstStringVariable FINAL : public StringVariable {
471 String value;
472 public:
473 ConstStringVariable(ParserContext* ctx, String value = "");
474 void assign(Expression* expr) OVERRIDE;
475 String evalStr() OVERRIDE;
476 void dump(int level = 0) OVERRIDE;
477 };
478 typedef Ref<ConstStringVariable,Node> ConstStringVariableRef;
479
480 class BinaryOp : virtual public Expression {
481 protected:
482 ExpressionRef lhs;
483 ExpressionRef rhs;
484 public:
485 BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }
486 bool isConstExpr() const OVERRIDE { return lhs->isConstExpr() && rhs->isConstExpr(); }
487 bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
488 };
489 typedef Ref<BinaryOp,Node> BinaryOpRef;
490
491 class NumberBinaryOp : public BinaryOp, virtual public NumberExpr {
492 public:
493 NumberBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : BinaryOp(lhs, rhs) { }
494 bool isFinal() const OVERRIDE;
495 };
496 typedef Ref<NumberBinaryOp,Node> NumberBinaryOpRef;
497
498 class IntBinaryOp : public NumberBinaryOp, virtual public IntExpr {
499 public:
500 IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
501 };
502 typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;
503
504 class VaritypeScalarBinaryOp : public NumberBinaryOp, virtual public IntExpr, virtual public RealExpr {
505 public:
506 VaritypeScalarBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
507 ExprType_t exprType() const OVERRIDE;
508 String evalCastToStr() OVERRIDE;
509 };
510 typedef Ref<VaritypeScalarBinaryOp,Node> VaritypeScalarBinaryOpRef;
511
512 class Add FINAL : public VaritypeScalarBinaryOp {
513 public:
514 Add(NumberExprRef lhs, NumberExprRef rhs);
515 vmint evalInt() OVERRIDE;
516 vmfloat evalReal() OVERRIDE;
517 vmfloat unitFactor() const OVERRIDE;
518 void dump(int level = 0) OVERRIDE;
519 };
520 typedef Ref<Add,Node> AddRef;
521
522 class Sub FINAL : public VaritypeScalarBinaryOp {
523 public:
524 Sub(NumberExprRef lhs, NumberExprRef rhs);
525 vmint evalInt() OVERRIDE;
526 vmfloat evalReal() OVERRIDE;
527 vmfloat unitFactor() const OVERRIDE;
528 void dump(int level = 0) OVERRIDE;
529 };
530 typedef Ref<Sub,Node> SubRef;
531
532 class Mul FINAL : public VaritypeScalarBinaryOp {
533 public:
534 Mul(NumberExprRef lhs, NumberExprRef rhs);
535 vmint evalInt() OVERRIDE;
536 vmfloat evalReal() OVERRIDE;
537 vmfloat unitFactor() const OVERRIDE;
538 void dump(int level = 0) OVERRIDE;
539 };
540 typedef Ref<Mul,Node> MulRef;
541
542 class Div FINAL : public VaritypeScalarBinaryOp {
543 public:
544 Div(NumberExprRef lhs, NumberExprRef rhs);
545 vmint evalInt() OVERRIDE;
546 vmfloat evalReal() OVERRIDE;
547 void dump(int level = 0) OVERRIDE;
548 vmfloat unitFactor() const OVERRIDE;
549 };
550 typedef Ref<Div,Node> DivRef;
551
552 class Mod FINAL : public IntBinaryOp {
553 public:
554 Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs), Unit(VM_NO_UNIT) { }
555 vmint evalInt() OVERRIDE;
556 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
557 void dump(int level = 0) OVERRIDE;
558 };
559 typedef Ref<Mod,Node> ModRef;
560
561 class Statement : virtual public Node {
562 public:
563 virtual StmtType_t statementType() const = 0;
564 };
565 typedef Ref<Statement,Node> StatementRef;
566
567 // Just used by parser to avoid "not a statement" parser warning, will be
568 // filtered out by parser. So it will not be part of the VM tree after parsing.
569 class NoOperation FINAL : public Statement {
570 public:
571 NoOperation() : Statement() {}
572 StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
573 void dump(int level = 0) OVERRIDE {}
574 bool isPolyphonic() const OVERRIDE { return false; }
575 };
576 typedef Ref<NoOperation,Node> NoOperationRef;
577
578 bool isNoOperation(StatementRef statement);
579
580 class LeafStatement : public Statement {
581 public:
582 virtual StmtFlags_t exec() = 0;
583 StmtType_t statementType() const OVERRIDE { return STMT_LEAF; }
584 };
585 typedef Ref<LeafStatement,Node> LeafStatementRef;
586
587 class Statements : public Statement {
588 std::vector<StatementRef> args;
589 public:
590 void add(StatementRef arg) { args.push_back(arg); }
591 void dump(int level = 0) OVERRIDE;
592 StmtType_t statementType() const OVERRIDE { return STMT_LIST; }
593 virtual Statement* statement(uint i);
594 bool isPolyphonic() const OVERRIDE;
595 };
596 typedef Ref<Statements,Node> StatementsRef;
597
598 class BranchStatement : public Statement {
599 public:
600 StmtType_t statementType() const OVERRIDE { return STMT_BRANCH; }
601 virtual vmint evalBranch() = 0;
602 virtual Statements* branch(vmuint i) const = 0;
603 };
604
605 class DynamicVariableCall FINAL : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr {
606 VMDynVar* dynVar;
607 String varName;
608 public:
609 DynamicVariableCall(const String& name, ParserContext* ctx, VMDynVar* v);
610 ExprType_t exprType() const OVERRIDE { return dynVar->exprType(); }
611 bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); }
612 bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); }
613 bool isPolyphonic() const OVERRIDE { return false; }
614 void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); }
615 VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); }
616 vmint evalInt() OVERRIDE;
617 String evalStr() OVERRIDE;
618 String evalCastToStr() OVERRIDE;
619 vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }
620 vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
621 void assignIntElement(vmuint i, vmint value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); }
622 vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
623 void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
624 void dump(int level = 0) OVERRIDE;
625 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
626 bool isFinal() const OVERRIDE { return false; }
627 };
628 typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
629
630 class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public RealExpr, virtual public StringExpr {
631 String functionName;
632 ArgsRef args;
633 VMFunction* fn;
634 VMFnResult* result;
635 public:
636 FunctionCall(const char* function, ArgsRef args, VMFunction* fn);
637 void dump(int level = 0) OVERRIDE;
638 StmtFlags_t exec() OVERRIDE;
639 vmint evalInt() OVERRIDE;
640 vmfloat evalReal() OVERRIDE;
641 VMIntArrayExpr* asIntArray() const OVERRIDE;
642 VMRealArrayExpr* asRealArray() const OVERRIDE;
643 String evalStr() OVERRIDE;
644 bool isConstExpr() const OVERRIDE { return false; }
645 ExprType_t exprType() const OVERRIDE;
646 String evalCastToStr() OVERRIDE;
647 bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
648 vmfloat unitFactor() const OVERRIDE;
649 bool isFinal() const OVERRIDE;
650 protected:
651 VMFnResult* execVMFn();
652 };
653 typedef Ref<FunctionCall,Node> FunctionCallRef;
654
655 class NoFunctionCall FINAL : public FunctionCall {
656 public:
657 NoFunctionCall() : FunctionCall("nothing", new Args, NULL), Unit(VM_NO_UNIT) {}
658 StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
659 };
660 typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;
661
662 class EventHandler : virtual public Statements, virtual public VMEventHandler {
663 StatementsRef statements;
664 bool usingPolyphonics;
665 public:
666 void dump(int level = 0) OVERRIDE;
667 StmtFlags_t exec();
668 EventHandler(StatementsRef statements);
669 Statement* statement(uint i) OVERRIDE { return statements->statement(i); }
670 bool isPolyphonic() const OVERRIDE { return usingPolyphonics; }
671 };
672 typedef Ref<EventHandler,Node> EventHandlerRef;
673
674 class OnNote FINAL : public EventHandler {
675 public:
676 OnNote(StatementsRef statements) : EventHandler(statements) {}
677 VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }
678 String eventHandlerName() const OVERRIDE { return "note"; }
679 };
680 typedef Ref<OnNote,Node> OnNoteRef;
681
682 class OnInit FINAL : public EventHandler {
683 public:
684 OnInit(StatementsRef statements) : EventHandler(statements) {}
685 VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }
686 String eventHandlerName() const OVERRIDE { return "init"; }
687 };
688 typedef Ref<OnInit,Node> OnInitRef;
689
690 class OnRelease FINAL : public EventHandler {
691 public:
692 OnRelease(StatementsRef statements) : EventHandler(statements) {}
693 VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }
694 String eventHandlerName() const OVERRIDE { return "release"; }
695 };
696 typedef Ref<OnRelease,Node> OnReleaseRef;
697
698 class OnController FINAL : public EventHandler {
699 public:
700 OnController(StatementsRef statements) : EventHandler(statements) {}
701 VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }
702 String eventHandlerName() const OVERRIDE { return "controller"; }
703 };
704 typedef Ref<OnController,Node> OnControllerRef;
705
706 class OnRpn FINAL : public EventHandler {
707 public:
708 OnRpn(StatementsRef statements) : EventHandler(statements) {}
709 VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RPN; }
710 String eventHandlerName() const OVERRIDE { return "rpn"; }
711 };
712 typedef Ref<OnRpn,Node> OnRpnRef;
713
714 class OnNrpn FINAL : public EventHandler {
715 public:
716 OnNrpn(StatementsRef statements) : EventHandler(statements) {}
717 VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NRPN; }
718 String eventHandlerName() const OVERRIDE { return "nrpn"; }
719 };
720 typedef Ref<OnNrpn,Node> OnNrpnRef;
721
722 class EventHandlers FINAL : virtual public Node {
723 std::vector<EventHandlerRef> args;
724 public:
725 EventHandlers();
726 ~EventHandlers();
727 void add(EventHandlerRef arg);
728 void dump(int level = 0) OVERRIDE;
729 EventHandler* eventHandlerByName(const String& name) const;
730 EventHandler* eventHandler(uint index) const;
731 inline uint size() const { return (int) args.size(); }
732 bool isPolyphonic() const OVERRIDE;
733 };
734 typedef Ref<EventHandlers,Node> EventHandlersRef;
735
736 class Assignment FINAL : public LeafStatement {
737 protected:
738 VariableRef variable;
739 ExpressionRef value;
740 public:
741 Assignment(VariableRef variable, ExpressionRef value);
742 void dump(int level = 0) OVERRIDE;
743 StmtFlags_t exec() OVERRIDE;
744 bool isPolyphonic() const OVERRIDE { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); }
745 };
746 typedef Ref<Assignment,Node> AssignmentRef;
747
748 class If FINAL : public BranchStatement {
749 IntExprRef condition;
750 StatementsRef ifStatements;
751 StatementsRef elseStatements;
752 public:
753 If(IntExprRef condition, StatementsRef ifStatements, StatementsRef elseStatements) :
754 condition(condition), ifStatements(ifStatements), elseStatements(elseStatements) { }
755 If(IntExprRef condition, StatementsRef statements) :
756 condition(condition), ifStatements(statements) { }
757 void dump(int level = 0) OVERRIDE;
758 vmint evalBranch() OVERRIDE;
759 Statements* branch(vmuint i) const OVERRIDE;
760 bool isPolyphonic() const OVERRIDE;
761 };
762 typedef Ref<If,Node> IfRef;
763
764 struct CaseBranch FINAL {
765 IntExprRef from;
766 IntExprRef to;
767 StatementsRef statements;
768 };
769 typedef std::vector<CaseBranch> CaseBranches;
770
771 class SelectCase FINAL : public BranchStatement {
772 IntExprRef select;
773 CaseBranches branches;
774 public:
775 SelectCase(IntExprRef select, const CaseBranches& branches) : select(select), branches(branches) { }
776 void dump(int level = 0) OVERRIDE;
777 vmint evalBranch() OVERRIDE;
778 Statements* branch(vmuint i) const OVERRIDE;
779 bool isPolyphonic() const OVERRIDE;
780 };
781 typedef Ref<SelectCase,Node> SelectCaseRef;
782
783 class While FINAL : public Statement {
784 IntExprRef m_condition;
785 StatementsRef m_statements;
786 public:
787 While(IntExprRef condition, StatementsRef statements) :
788 m_condition(condition), m_statements(statements) {}
789 StmtType_t statementType() const OVERRIDE { return STMT_LOOP; }
790 void dump(int level = 0) OVERRIDE;
791 bool evalLoopStartCondition();
792 Statements* statements() const;
793 bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
794 };
795
796 class SyncBlock FINAL : public Statement {
797 StatementsRef m_statements;
798 public:
799 SyncBlock(StatementsRef statements) : m_statements(statements) {}
800 StmtType_t statementType() const OVERRIDE { return STMT_SYNC; }
801 void dump(int level = 0) OVERRIDE;
802 Statements* statements() const;
803 bool isPolyphonic() const OVERRIDE { return m_statements->isPolyphonic(); }
804 };
805 typedef Ref<SyncBlock,Node> SyncBlockRef;
806
807 class Neg FINAL : virtual public IntExpr, virtual public RealExpr {
808 NumberExprRef expr;
809 public:
810 Neg(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) { }
811 ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
812 vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; }
813 vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); }
814 String evalCastToStr() OVERRIDE;
815 void dump(int level = 0) OVERRIDE;
816 bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
817 bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
818 vmfloat unitFactor() const OVERRIDE { return expr->unitFactor(); }
819 bool isFinal() const OVERRIDE { return expr->isFinal(); }
820 };
821 typedef Ref<Neg,Node> NegRef;
822
823 class ConcatString FINAL : public StringExpr {
824 ExpressionRef lhs;
825 ExpressionRef rhs;
826 public:
827 ConcatString(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) {}
828 String evalStr() OVERRIDE;
829 void dump(int level = 0) OVERRIDE;
830 bool isConstExpr() const OVERRIDE;
831 bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
832 };
833 typedef Ref<ConcatString,Node> ConcatStringRef;
834
835 class Relation FINAL : public IntExpr {
836 public:
837 enum Type {
838 LESS_THAN,
839 GREATER_THAN,
840 LESS_OR_EQUAL,
841 GREATER_OR_EQUAL,
842 EQUAL,
843 NOT_EQUAL
844 };
845 Relation(ExpressionRef lhs, Type type, ExpressionRef rhs);
846 vmint evalInt() OVERRIDE;
847 void dump(int level = 0) OVERRIDE;
848 bool isConstExpr() const OVERRIDE;
849 bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
850 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
851 bool isFinal() const OVERRIDE { return false; }
852 private:
853 ExpressionRef lhs;
854 ExpressionRef rhs;
855 Type type;
856 };
857 typedef Ref<Relation,Node> RelationRef;
858
859 class Or FINAL : public IntBinaryOp {
860 public:
861 Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
862 vmint evalInt() OVERRIDE;
863 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
864 void dump(int level = 0) OVERRIDE;
865 };
866 typedef Ref<Or,Node> OrRef;
867
868 class BitwiseOr FINAL : public IntBinaryOp {
869 public:
870 BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
871 vmint evalInt() OVERRIDE;
872 void dump(int level = 0) OVERRIDE;
873 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
874 };
875 typedef Ref<BitwiseOr,Node> BitwiseOrRef;
876
877 class And FINAL : public IntBinaryOp {
878 public:
879 And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
880 vmint evalInt() OVERRIDE;
881 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
882 void dump(int level = 0) OVERRIDE;
883 };
884 typedef Ref<And,Node> AndRef;
885
886 class BitwiseAnd FINAL : public IntBinaryOp {
887 public:
888 BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
889 vmint evalInt() OVERRIDE;
890 void dump(int level = 0) OVERRIDE;
891 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
892 };
893 typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
894
895 class Not FINAL : virtual public IntExpr {
896 IntExprRef expr;
897 public:
898 Not(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
899 vmint evalInt() OVERRIDE { return !expr->evalInt(); }
900 void dump(int level = 0) OVERRIDE;
901 bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
902 bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
903 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
904 bool isFinal() const OVERRIDE { return expr->isFinal(); }
905 };
906 typedef Ref<Not,Node> NotRef;
907
908 class BitwiseNot FINAL : virtual public IntExpr {
909 IntExprRef expr;
910 public:
911 BitwiseNot(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
912 vmint evalInt() OVERRIDE { return ~expr->evalInt(); }
913 void dump(int level = 0) OVERRIDE;
914 bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
915 bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
916 vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
917 bool isFinal() const OVERRIDE { return expr->isFinal(); }
918 };
919 typedef Ref<BitwiseNot,Node> BitwiseNotRef;
920
921 class Final FINAL : virtual public IntExpr, virtual public RealExpr {
922 NumberExprRef expr;
923 public:
924 Final(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}
925 ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
926 vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
927 vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }
928 String evalCastToStr() OVERRIDE;
929 void dump(int level = 0) OVERRIDE;
930 bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
931 bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
932 vmfloat unitFactor() const OVERRIDE { return expr->unitFactor(); }
933 bool isFinal() const OVERRIDE { return true; }
934 };
935 typedef Ref<Final,Node> FinalRef;
936
937 class ParserContext FINAL : public VMParserContext {
938 public:
939 struct Error {
940 String txt;
941 int line;
942 };
943 typedef Error Warning;
944
945 void* scanner;
946 std::istream* is;
947 int nbytes;
948 std::vector<ParserIssue> vErrors;
949 std::vector<ParserIssue> vWarnings;
950 std::vector<ParserIssue> vIssues;
951 std::vector<CodeBlock> vPreprocessorComments;
952
953 std::set<String> builtinPreprocessorConditions;
954 std::set<String> userPreprocessorConditions;
955
956 std::map<String,VariableRef> vartable;
957 std::map<String,StatementsRef> userFnTable;
958 vmint globalIntVarCount;
959 vmint globalRealVarCount;
960 vmint globalStrVarCount;
961 vmint globalUnitFactorCount;
962 vmint polyphonicIntVarCount;
963 vmint polyphonicRealVarCount;
964 vmint polyphonicUnitFactorCount;
965
966 EventHandlersRef handlers;
967
968 OnInitRef onInit;
969 OnNoteRef onNote;
970 OnReleaseRef onRelease;
971 OnControllerRef onController;
972 OnRpnRef onRpn;
973 OnNrpnRef onNrpn;
974
975 ArrayList<vmint>* globalIntMemory;
976 ArrayList<vmfloat>* globalRealMemory;
977 ArrayList<String>* globalStrMemory;
978 ArrayList<vmfloat>* globalUnitFactorMemory;
979 vmint requiredMaxStackSize;
980
981 VMFunctionProvider* functionProvider;
982
983 ExecContext* execContext;
984
985 ParserContext(VMFunctionProvider* parent) :
986 scanner(NULL), is(NULL), nbytes(0),
987 globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),
988 globalUnitFactorCount(0),
989 polyphonicIntVarCount(0), polyphonicRealVarCount(0),
990 polyphonicUnitFactorCount(0),
991 globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),
992 globalUnitFactorMemory(NULL),
993 requiredMaxStackSize(-1),
994 functionProvider(parent), execContext(NULL)
995 {
996 }
997 virtual ~ParserContext();
998 VariableRef globalVar(const String& name);
999 IntVariableRef globalIntVar(const String& name);
1000 RealVariableRef globalRealVar(const String& name);
1001 StringVariableRef globalStrVar(const String& name);
1002 VariableRef variableByName(const String& name);
1003 StatementsRef userFunctionByName(const String& name);
1004 void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn,
1005 int firstByte, int lengthBytes, const char* txt);
1006 void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn,
1007 int firstByte, int lengthBytes, const char* txt);
1008 void addPreprocessorComment(int firstLine, int lastLine, int firstColumn,
1009 int lastColumn, int firstByte, int lengthBytes);
1010 void createScanner(std::istream* is);
1011 void destroyScanner();
1012 bool setPreprocessorCondition(const char* name);
1013 bool resetPreprocessorCondition(const char* name);
1014 bool isPreprocessorConditionSet(const char* name);
1015 std::vector<ParserIssue> issues() const OVERRIDE;
1016 std::vector<ParserIssue> errors() const OVERRIDE;
1017 std::vector<ParserIssue> warnings() const OVERRIDE;
1018 std::vector<CodeBlock> preprocessorComments() const OVERRIDE;
1019 VMEventHandler* eventHandler(uint index) OVERRIDE;
1020 VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
1021 void registerBuiltInConstIntVariables(const std::map<String,vmint>& vars);
1022 void registerBuiltInConstRealVariables(const std::map<String,vmfloat>& vars);
1023 void registerBuiltInIntVariables(const std::map<String,VMIntPtr*>& vars);
1024 void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
1025 void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
1026 };
1027
1028 class ExecContext FINAL : public VMExecContext {
1029 public:
1030 struct StackFrame {
1031 Statement* statement;
1032 int subindex;
1033
1034 StackFrame() {
1035 statement = NULL;
1036 subindex = -1;
1037 }
1038 };
1039
1040 ArrayList<vmint> polyphonicIntMemory;
1041 ArrayList<vmfloat> polyphonicRealMemory;
1042 ArrayList<vmfloat> polyphonicUnitFactorMemory;
1043 VMExecStatus_t status;
1044 StmtFlags_t flags;
1045 ArrayList<StackFrame> stack;
1046 int stackFrame;
1047 vmint suspendMicroseconds;
1048 size_t instructionsCount;
1049 struct ExitRes {
1050 Expression* value;
1051 IntLiteral intLiteral;
1052 RealLiteral realLiteral;
1053 StringLiteral stringLiteral;
1054
1055 ExitRes() :
1056 intLiteral({ .value = 0 }), realLiteral({ .value = 0.0 }),
1057 stringLiteral("") { }
1058 } exitRes;
1059
1060 ExecContext();
1061 virtual ~ExecContext() {}
1062
1063 inline void pushStack(Statement* stmt) {
1064 stackFrame++;
1065 //printf("pushStack() -> %d\n", stackFrame);
1066 if (stackFrame >= stack.size()) return;
1067 stack[stackFrame].statement = stmt;
1068 stack[stackFrame].subindex = 0;
1069 }
1070
1071 inline void popStack() {
1072 stack[stackFrame].statement = NULL;
1073 stack[stackFrame].subindex = -1;
1074 stackFrame--;
1075 //printf("popStack() -> %d\n", stackFrame);
1076 }
1077
1078 inline void reset() {
1079 stack[0].statement = NULL;
1080 stack[0].subindex = -1;
1081 stackFrame = -1;
1082 flags = STMT_SUCCESS;
1083 }
1084
1085 inline void clearExitRes() {
1086 exitRes.value = NULL;
1087 }
1088
1089 vmint suspensionTimeMicroseconds() const OVERRIDE {
1090 return suspendMicroseconds;
1091 }
1092
1093 void resetPolyphonicData() OVERRIDE {
1094 if (!polyphonicIntMemory.empty())
1095 memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));
1096 if (!polyphonicRealMemory.empty())
1097 memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));
1098 if (!polyphonicUnitFactorMemory.empty()) {
1099 const vmint sz = polyphonicUnitFactorMemory.size();
1100 for (vmint i = 0; i < sz; ++i)
1101 polyphonicUnitFactorMemory[i] = VM_NO_FACTOR;
1102 }
1103 }
1104
1105 size_t instructionsPerformed() const OVERRIDE {
1106 return instructionsCount;
1107 }
1108
1109 void signalAbort() OVERRIDE {
1110 flags = StmtFlags_t(flags | STMT_ABORT_SIGNALLED);
1111 }
1112
1113 void forkTo(VMExecContext* ectx) const OVERRIDE;
1114
1115 VMExpr* exitResult() OVERRIDE {
1116 return exitRes.value;
1117 }
1118 };
1119
1120 } // namespace LinuxSampler
1121
1122 #endif // LS_INSTRPARSERTREE_H

  ViewVC Help
Powered by ViewVC