/[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 3690 - (show annotations) (download) (as text)
Fri Jan 3 10:18:21 2020 UTC (9 months, 2 weeks ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 39613 byte(s)
NKSP: Added support for RPN and NRPN event handlers:

* NKSP language: Added support for RPN event handler
  ("on rpn ... end on" in instrument scripts).

* NKSP language: Added support for NRPN event handler
  ("on nrpn ... end on" in instrument scripts).

* Added built-in read-only variables "$RPN_ADDRESS" and "$RPN_VALUE" which
  may be read from the new RPN/NRPN script handlers to get the (N)RPN
  parameter that had been changed and its new value.

* Added built-in const variables "$NI_CB_TYPE_RPN" and "$NI_CB_TYPE_NRPN"
  which are identifying the new (N)RPN handlers as such at script runtime.

* Bumped version (2.1.1.svn30).

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

  ViewVC Help
Powered by ViewVC