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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3573 - (hide annotations) (download) (as text)
Tue Aug 27 21:36:53 2019 UTC (4 years, 7 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 34697 byte(s)
NKSP: Introducing floating point support.

* NKSP language: Added support for NKSP real number literals and
  arithmetic operations on them (e.g. "(3.9 + 2.9) / 12.3 - 42.0").

* NKSP language: Added support for NKSP real number (floating point)
  script variables (declare ~foo := 3.4).

* NKSP language: Added support for NKSP real number (floating point)
  array script variables (declare ?foo[3] := ( 1.1, 2.7, 49.0 )).

* NKSP built-in script function "message()" accepts now real number
  argument as well.

* Added built-in NKSP script function "real_to_int()" and its short
  hand form "int()" for casting from real number to integer in NKSP
  scripts.

* Added built-in NKSP script function "int_to_real()" and its short
  hand form "real()" for casting from integer to real number in NKSP
  scripts.

* Bumped version (2.1.1.svn6).

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

  ViewVC Help
Powered by ViewVC