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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3561 by schoenebeck, Fri Aug 23 11:44:00 2019 UTC revision 3581 by schoenebeck, Fri Aug 30 11:40:25 2019 UTC
# Line 58  public: Line 58  public:
58  };  };
59  typedef Ref<Expression,Node> ExpressionRef;  typedef Ref<Expression,Node> ExpressionRef;
60    
61  class IntExpr : virtual public VMIntExpr, virtual public Expression {  class Unit : virtual public VMUnit, virtual public Node {
62        StdUnit_t unit;
63    public:
64        Unit(StdUnit_t type) : unit(type) {}
65        StdUnit_t unitType() const OVERRIDE { return unit; }
66        static vmint convIntToUnitFactor(vmint iValue, VMUnit* srcUnit, VMUnit* dstUnit);
67        static vmint convIntToUnitFactor(vmint iValue, vmfloat srcFactor, vmfloat dstFactor);
68        static vmfloat convRealToUnitFactor(vmfloat fValue, VMUnit* srcUnit, VMUnit* dstUnit);
69        static vmfloat convRealToUnitFactor(vmfloat fValue, vmfloat srcFactor, vmfloat dstFactor);
70    };
71    typedef Ref<Unit,Node> UnitRef;
72    
73    class ScalarNumberExpr : virtual public Unit, virtual public VMScalarNumberExpr, virtual public Expression {
74    public:
75    };
76    typedef Ref<ScalarNumberExpr,Node> ScalarNumberExprRef;
77    
78    class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr {
79  public:  public:
80      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
81        vmint evalIntToUnitFactor(vmfloat unitFactor);
82      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
83  };  };
84  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
85    
86  class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression {  class RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr  {
87    public:
88        ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
89        vmfloat evalRealToUnitFactor(vmfloat unitFactor);
90        String evalCastToStr() OVERRIDE;
91    };
92    typedef Ref<RealExpr,Node> RealExprRef;
93    
94    class ArrayExpr : virtual public VMArrayExpr, virtual public Expression {
95    public:
96    };
97    typedef Ref<ArrayExpr,Node> ArrayExprRef;
98    
99    class IntArrayExpr : virtual public VMIntArrayExpr, virtual public ArrayExpr {
100  public:  public:
101      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
102      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
103  };  };
104  typedef Ref<IntArrayExpr,Node> IntArrayExprRef;  typedef Ref<IntArrayExpr,Node> IntArrayExprRef;
105    
106    class RealArrayExpr : virtual public VMRealArrayExpr, virtual public ArrayExpr {
107    public:
108        ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
109        String evalCastToStr() OVERRIDE;
110    };
111    typedef Ref<RealArrayExpr,Node> RealArrayExprRef;
112    
113  class StringExpr : virtual public VMStringExpr, virtual public Expression {  class StringExpr : virtual public VMStringExpr, virtual public Expression {
114  public:  public:
115      ExprType_t exprType() const OVERRIDE { return STRING_EXPR; }      ExprType_t exprType() const OVERRIDE { return STRING_EXPR; }
# Line 79  public: Line 117  public:
117  };  };
118  typedef Ref<StringExpr,Node> StringExprRef;  typedef Ref<StringExpr,Node> StringExprRef;
119    
120  class Unit : virtual public VMUnit {  struct IntLitDef {
121      ArrayList<MetricPrefix_t> prefix;      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.
122      StdUnit_t unit;      vmfloat unitFactor = VM_NO_FACTOR;
123  public:      StdUnit_t unitType = VM_NO_UNIT;
124      Unit() : unit(VM_NO_UNIT) {}      bool isFinal;
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE { return unit; }  
     void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type);  
     void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type);  
     void copyUnitFrom(const IntExprRef& src);  
125  };  };
126    
127  class IntLiteral : public Unit, virtual public IntExpr {  class IntLiteral FINAL : public IntExpr {
128      bool finalVal;      bool finalVal;
129  public:      vmfloat unitPrefixFactor;
130      vmint value;      vmint value;
131      IntLiteral(vmint value) : Unit(),  public:
132          value(value), finalVal(false) { }      IntLiteral(const IntLitDef& def);
133      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
134        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
135      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
136      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
137      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
138      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
139  };  };
140  typedef Ref<IntLiteral,Node> IntLiteralRef;  typedef Ref<IntLiteral,Node> IntLiteralRef;
141    
142  class StringLiteral : virtual public StringExpr {  struct RealLitDef {
143        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.
144        vmfloat unitFactor = VM_NO_FACTOR;
145        StdUnit_t unitType = VM_NO_UNIT;
146        bool isFinal;
147    };
148    
149    class RealLiteral FINAL : public RealExpr {
150        bool finalVal;
151        vmfloat unitPrefixFactor;
152        vmfloat value;
153  public:  public:
154        RealLiteral(const RealLitDef& def);
155        vmfloat evalReal() OVERRIDE;
156        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
157        void dump(int level = 0) OVERRIDE;
158        bool isConstExpr() const OVERRIDE { return true; }
159        bool isPolyphonic() const OVERRIDE { return false; }
160        bool isFinal() const OVERRIDE { return finalVal; }
161    };
162    typedef Ref<RealLiteral,Node> RealLiteralRef;
163    
164    class StringLiteral FINAL : public StringExpr {
165      String value;      String value;
166    public:
167      StringLiteral(const String& value) : value(value) { }      StringLiteral(const String& value) : value(value) { }
168      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
169      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
# Line 117  public: Line 172  public:
172  };  };
173  typedef Ref<StringLiteral,Node> StringLiteralRef;  typedef Ref<StringLiteral,Node> StringLiteralRef;
174    
175  class Args : virtual public VMFnArgs, virtual public Node {  class Args FINAL : virtual public VMFnArgs, virtual public Node {
176  public:  public:
177      std::vector<ExpressionRef> args;      std::vector<ExpressionRef> args;
178      void add(ExpressionRef arg) { args.push_back(arg); }      void add(ExpressionRef arg) { args.push_back(arg); }
# Line 128  public: Line 183  public:
183  };  };
184  typedef Ref<Args,Node> ArgsRef;  typedef Ref<Args,Node> ArgsRef;
185    
186    struct VariableDecl {
187        ParserContext* ctx;
188        bool isPolyphonic;
189        bool isConst;
190        bool isFinal;
191        vmint elements = 1;
192        vmint memPos;
193        vmint unitFactorMemPos;
194        StdUnit_t unitType = VM_NO_UNIT;
195    };
196    
197  class Variable : virtual public VMVariable, virtual public Expression {  class Variable : virtual public VMVariable, virtual public Expression {
198  public:  public:
199      bool isConstExpr() const OVERRIDE { return bConst; }      bool isConstExpr() const OVERRIDE { return bConst; }
# Line 135  public: Line 201  public:
201      virtual void assign(Expression* expr) = 0;      virtual void assign(Expression* expr) = 0;
202      void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }      void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }
203  protected:  protected:
204      Variable(ParserContext* ctx, vmint _memPos, bool _bConst)      Variable(const VariableDecl& decl);
         : context(ctx), memPos(_memPos), bConst(_bConst) {}  
205    
206      ParserContext* context;      ParserContext* context;
207      vmint memPos;      vmint memPos;
# Line 144  protected: Line 209  protected:
209  };  };
210  typedef Ref<Variable,Node> VariableRef;  typedef Ref<Variable,Node> VariableRef;
211    
212  class IntVariable : public Variable, public Unit, virtual public IntExpr {  class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr {
213      bool polyphonic;      bool polyphonic;
214      bool finalVal;      bool finalVal;
215    protected:
216        vmint unitFactorMemPos;
217  public:  public:
     IntVariable(ParserContext* ctx);  
     void assign(Expression* expr) OVERRIDE;  
     vmint evalInt() OVERRIDE;  
     void dump(int level = 0) OVERRIDE;  
218      bool isPolyphonic() const OVERRIDE { return polyphonic; }      bool isPolyphonic() const OVERRIDE { return polyphonic; }
219      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
220      void setFinal(bool b = true) { finalVal = b; }      vmfloat unitFactor() const OVERRIDE;
221  protected:  protected:
222      IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);      ScalarNumberVariable(const VariableDecl& decl);
223    };
224    typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef;
225    
226    class IntVariable : public ScalarNumberVariable, virtual public IntExpr {
227    public:
228        IntVariable(const VariableDecl& decl);
229        void assign(Expression* expr) OVERRIDE;
230        vmint evalInt() OVERRIDE;
231        void dump(int level = 0) OVERRIDE;
232  };  };
233  typedef Ref<IntVariable,Node> IntVariableRef;  typedef Ref<IntVariable,Node> IntVariableRef;
234    
235  class ConstIntVariable : public IntVariable {  class RealVariable : public ScalarNumberVariable, virtual public RealExpr {
236  public:  public:
237      vmint value;      RealVariable(const VariableDecl& decl);
238        void assign(Expression* expr) OVERRIDE;
239        vmfloat evalReal() OVERRIDE;
240        void dump(int level = 0) OVERRIDE;
241    };
242    typedef Ref<RealVariable,Node> RealVariableRef;
243    
244      ConstIntVariable(vmint value);  struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
245      //ConstIntVariable(ParserContext* ctx, int value = 0);      // copied from VariableDecl
246        ParserContext* ctx;
247        bool isPolyphonic;
248        bool isConst;
249        bool isFinal;
250        vmint elements = 1;
251        vmint memPos;
252        vmint unitFactorMemPos;
253        StdUnit_t unitType = VM_NO_UNIT;
254        // additions for RealVarDef
255        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.
256        vmfloat unitFactor = VM_NO_FACTOR;
257    };
258    
259    class ConstIntVariable FINAL : public IntVariable {
260        vmfloat unitPrefixFactor;
261        vmint value;
262    public:
263        ConstIntVariable(const IntVarDef& def);
264      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
265      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
266        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
267      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
268  };  };
269  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
270    
271  class BuiltInIntVariable : public IntVariable {  struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
272        // copied from VariableDecl
273        ParserContext* ctx;
274        bool isPolyphonic;
275        bool isConst;
276        bool isFinal;
277        vmint elements = 1;
278        vmint memPos;
279        vmint unitFactorMemPos;
280        StdUnit_t unitType = VM_NO_UNIT;
281        // additions for RealVarDef
282        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.
283        vmfloat unitFactor = VM_NO_FACTOR;
284    };
285    
286    class ConstRealVariable FINAL : public RealVariable {
287        vmfloat unitPrefixFactor;
288        vmfloat value;
289    public:
290        ConstRealVariable(const RealVarDef& def);
291        void assign(Expression* expr) OVERRIDE;
292        vmfloat evalReal() OVERRIDE;
293        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
294        void dump(int level = 0) OVERRIDE;
295    };
296    typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;
297    
298    class BuiltInIntVariable FINAL : public IntVariable {
299      String name;      String name;
300      VMIntPtr* ptr;      VMIntPtr* ptr;
301  public:  public:
# Line 180  public: Line 303  public:
303      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }
304      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
305      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
306        vmfloat unitFactor() const OVERRIDE { return VM_NO_UNIT; }
307      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
308  };  };
309  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
310    
311  class PolyphonicIntVariable : public IntVariable {  class PolyphonicIntVariable FINAL : public IntVariable {
312  public:  public:
313      PolyphonicIntVariable(ParserContext* ctx);      PolyphonicIntVariable(const VariableDecl& decl);
314      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
315  };  };
316  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
317    
318    class PolyphonicRealVariable FINAL : public RealVariable {
319    public:
320        PolyphonicRealVariable(const VariableDecl& decl);
321        void dump(int level = 0) OVERRIDE;
322    };
323    typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;
324    
325  class IntArrayVariable : public Variable, virtual public IntArrayExpr {  class IntArrayVariable : public Variable, virtual public IntArrayExpr {
326      ArrayList<vmint> values;      ArrayList<vmint> values;
327        ArrayList<vmfloat> unitFactors;
328  public:  public:
329      IntArrayVariable(ParserContext* ctx, vmint size);      IntArrayVariable(ParserContext* ctx, vmint size);
330      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
331      void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment      void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment
     String evalCastToStr() OVERRIDE { return ""; } // ignore scalar cast to string  
332      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
333      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
334      virtual vmint evalIntElement(vmuint i) OVERRIDE;      virtual vmint evalIntElement(vmuint i) OVERRIDE;
335      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;
336        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
337        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
338      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
339      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
340  protected:  protected:
# Line 209  protected: Line 342  protected:
342  };  };
343  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
344    
345  class BuiltInIntArrayVariable : public IntArrayVariable {  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {
346        ArrayList<vmfloat> values;
347        ArrayList<vmfloat> unitFactors;
348    public:
349        RealArrayVariable(ParserContext* ctx, vmint size);
350        RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
351        void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment
352        ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
353        virtual vmint arraySize() const OVERRIDE { return values.size(); }
354        virtual vmfloat evalRealElement(vmuint i) OVERRIDE;
355        virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;
356        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
357        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
358        void dump(int level = 0) OVERRIDE;
359        bool isPolyphonic() const OVERRIDE { return false; }
360    protected:
361        RealArrayVariable(ParserContext* ctx, bool bConst);
362    };
363    typedef Ref<RealArrayVariable,Node> RealArrayVariableRef;
364    
365    class BuiltInIntArrayVariable FINAL : public IntArrayVariable {
366      String name;      String name;
367      VMInt8Array* array;      VMInt8Array* array;
368  public:  public:
369      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
370      vmint arraySize() const OVERRIDE { return array->size; }      vmint arraySize() const OVERRIDE { return array->size; }
371      vmint evalIntElement(vmuint i) OVERRIDE;      vmint evalIntElement(vmuint i) OVERRIDE;
     bool isAssignable() const OVERRIDE { return !array->readonly; }  
372      void assignIntElement(vmuint i, vmint value) OVERRIDE;      void assignIntElement(vmuint i, vmint value) OVERRIDE;
373        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
374        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
375        bool isAssignable() const OVERRIDE { return !array->readonly; }
376      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
377  };  };
378  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
379    
380  class IntArrayElement : public IntVariable {  class IntArrayElement FINAL : public IntVariable {
381      IntArrayExprRef array;      IntArrayExprRef array;
382      IntExprRef index;      IntExprRef index;
383        vmint currentIndex;
384  public:  public:
385      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);
386      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
387      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
388        vmfloat unitFactor() const OVERRIDE;
389      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
390  };  };
391  typedef Ref<IntArrayElement,Node> IntArrayElementRef;  typedef Ref<IntArrayElement,Node> IntArrayElementRef;
392    
393    class RealArrayElement FINAL : public RealVariable {
394        RealArrayExprRef array;
395        IntExprRef index;
396        vmint currentIndex;
397    public:
398        RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);
399        void assign(Expression* expr) OVERRIDE;
400        vmfloat evalReal() OVERRIDE;
401        vmfloat unitFactor() const OVERRIDE;
402        void dump(int level = 0) OVERRIDE;
403    };
404    typedef Ref<RealArrayElement,Node> RealArrayElementRef;
405    
406  class StringVariable : public Variable, virtual public StringExpr {  class StringVariable : public Variable, virtual public StringExpr {
407  public:  public:
408      StringVariable(ParserContext* ctx);      StringVariable(ParserContext* ctx);
# Line 245  protected: Line 415  protected:
415  };  };
416  typedef Ref<StringVariable,Node> StringVariableRef;  typedef Ref<StringVariable,Node> StringVariableRef;
417    
418  class ConstStringVariable : public StringVariable {  class ConstStringVariable FINAL : public StringVariable {
 public:  
419      String value;      String value;
420    public:
421      ConstStringVariable(ParserContext* ctx, String value = "");      ConstStringVariable(ParserContext* ctx, String value = "");
422      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
423      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
# Line 267  public: Line 436  public:
436  };  };
437  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
438    
439  class IntBinaryOp : public BinaryOp, virtual public IntExpr {  class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr {
440  public:  public:
441      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }      ScalarNumberBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : BinaryOp(lhs, rhs) { }
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
442      bool isFinal() const OVERRIDE;      bool isFinal() const OVERRIDE;
443  };  };
444    typedef Ref<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef;
445    
446    class IntBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr {
447    public:
448        IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }
449    };
450  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;
451    
452  class Add : public IntBinaryOp {  class VaritypeScalarBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr, virtual public RealExpr {
453    public:
454        VaritypeScalarBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }
455        ExprType_t exprType() const OVERRIDE;
456        String evalCastToStr() OVERRIDE;
457    };
458    typedef Ref<VaritypeScalarBinaryOp,Node> VaritypeScalarBinaryOpRef;
459    
460    class Add FINAL : public VaritypeScalarBinaryOp {
461  public:  public:
462      Add(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);
463      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
464        vmfloat evalReal() OVERRIDE;
465        vmfloat unitFactor() const OVERRIDE;
466      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
467  };  };
468  typedef Ref<Add,Node> AddRef;  typedef Ref<Add,Node> AddRef;
469    
470  class Sub : public IntBinaryOp {  class Sub FINAL : public VaritypeScalarBinaryOp {
471  public:  public:
472      Sub(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);
473      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
474        vmfloat evalReal() OVERRIDE;
475        vmfloat unitFactor() const OVERRIDE;
476      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
477  };  };
478  typedef Ref<Sub,Node> SubRef;  typedef Ref<Sub,Node> SubRef;
479    
480  class Mul : public IntBinaryOp {  class Mul FINAL : public VaritypeScalarBinaryOp {
481  public:  public:
482      Mul(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);
483      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
484        vmfloat evalReal() OVERRIDE;
485        vmfloat unitFactor() const OVERRIDE;
486      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
487  };  };
488  typedef Ref<Mul,Node> MulRef;  typedef Ref<Mul,Node> MulRef;
489    
490  class Div : public IntBinaryOp {  class Div FINAL : public VaritypeScalarBinaryOp {
491  public:  public:
492      Div(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);
493      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
494        vmfloat evalReal() OVERRIDE;
495      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
496      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
     StdUnit_t unitType() const OVERRIDE;  
497  };  };
498  typedef Ref<Div,Node> DivRef;  typedef Ref<Div,Node> DivRef;
499    
500  class Mod : public IntBinaryOp {  class Mod FINAL : public IntBinaryOp {
501  public:  public:
502      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs), Unit(VM_NO_UNIT) { }
503      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
504        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
505      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
506  };  };
507  typedef Ref<Mod,Node> ModRef;  typedef Ref<Mod,Node> ModRef;
# Line 328  typedef Ref<Statement,Node> StatementRef Line 514  typedef Ref<Statement,Node> StatementRef
514    
515  // Just used by parser to avoid "not a statement" parser warning, will be  // Just used by parser to avoid "not a statement" parser warning, will be
516  // filtered out by parser. So it will not be part of the VM tree after parsing.  // filtered out by parser. So it will not be part of the VM tree after parsing.
517  class NoOperation : public Statement {  class NoOperation FINAL : public Statement {
518  public:  public:
519      NoOperation() : Statement() {}      NoOperation() : Statement() {}
520      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
# Line 364  public: Line 550  public:
550      virtual Statements* branch(vmuint i) const = 0;      virtual Statements* branch(vmuint i) const = 0;
551  };  };
552    
553  class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr {  class DynamicVariableCall FINAL : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr {
554      VMDynVar* dynVar;      VMDynVar* dynVar;
555      String varName;      String varName;
556  public:  public:
# Line 381  public: Line 567  public:
567      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }
568      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
569      void assignIntElement(vmuint i, vmint value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); }      void assignIntElement(vmuint i, vmint value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); }
570        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
571        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
572      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
573      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
574      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
575  };  };
576  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
577    
578  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public RealExpr, virtual public StringExpr {
579      String functionName;      String functionName;
580      ArgsRef args;      ArgsRef args;
581      VMFunction* fn;      VMFunction* fn;
582        VMFnResult* result;
583  public:  public:
584      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn);
         functionName(function), args(args), fn(fn) { }  
585      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
586      StmtFlags_t exec() OVERRIDE;      StmtFlags_t exec() OVERRIDE;
587      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
588        vmfloat evalReal() OVERRIDE;
589      VMIntArrayExpr* asIntArray() const OVERRIDE;      VMIntArrayExpr* asIntArray() const OVERRIDE;
590        VMRealArrayExpr* asRealArray() const OVERRIDE;
591      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
592      bool isConstExpr() const OVERRIDE { return false; }      bool isConstExpr() const OVERRIDE { return false; }
593      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
594      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
595      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
596      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE;
597      StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }      bool isFinal() const OVERRIDE;
     bool isFinal() const OVERRIDE { return false; }  
598  protected:  protected:
599      VMFnResult* execVMFn();      VMFnResult* execVMFn();
600  };  };
601  typedef Ref<FunctionCall,Node> FunctionCallRef;  typedef Ref<FunctionCall,Node> FunctionCallRef;
602    
603  class NoFunctionCall : public FunctionCall {  class NoFunctionCall FINAL : public FunctionCall {
604  public:  public:
605      NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {}      NoFunctionCall() : FunctionCall("nothing", new Args, NULL), Unit(VM_NO_UNIT) {}
606      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
607  };  };
608  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;
# Line 431  public: Line 619  public:
619  };  };
620  typedef Ref<EventHandler,Node> EventHandlerRef;  typedef Ref<EventHandler,Node> EventHandlerRef;
621    
622  class OnNote : public EventHandler {  class OnNote FINAL : public EventHandler {
623  public:  public:
624      OnNote(StatementsRef statements) : EventHandler(statements) {}      OnNote(StatementsRef statements) : EventHandler(statements) {}
625      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }
# Line 439  public: Line 627  public:
627  };  };
628  typedef Ref<OnNote,Node> OnNoteRef;  typedef Ref<OnNote,Node> OnNoteRef;
629    
630  class OnInit : public EventHandler {  class OnInit FINAL : public EventHandler {
631  public:  public:
632      OnInit(StatementsRef statements) : EventHandler(statements) {}      OnInit(StatementsRef statements) : EventHandler(statements) {}
633      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }
# Line 447  public: Line 635  public:
635  };  };
636  typedef Ref<OnInit,Node> OnInitRef;  typedef Ref<OnInit,Node> OnInitRef;
637    
638  class OnRelease : public EventHandler {  class OnRelease FINAL : public EventHandler {
639  public:  public:
640      OnRelease(StatementsRef statements) : EventHandler(statements) {}      OnRelease(StatementsRef statements) : EventHandler(statements) {}
641      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }
# Line 455  public: Line 643  public:
643  };  };
644  typedef Ref<OnRelease,Node> OnReleaseRef;  typedef Ref<OnRelease,Node> OnReleaseRef;
645    
646  class OnController : public EventHandler {  class OnController FINAL : public EventHandler {
647  public:  public:
648      OnController(StatementsRef statements) : EventHandler(statements) {}      OnController(StatementsRef statements) : EventHandler(statements) {}
649      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }
# Line 463  public: Line 651  public:
651  };  };
652  typedef Ref<OnController,Node> OnControllerRef;  typedef Ref<OnController,Node> OnControllerRef;
653    
654  class EventHandlers : virtual public Node {  class EventHandlers FINAL : virtual public Node {
655      std::vector<EventHandlerRef> args;      std::vector<EventHandlerRef> args;
656  public:  public:
657      EventHandlers();      EventHandlers();
# Line 477  public: Line 665  public:
665  };  };
666  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
667    
668  class Assignment : public LeafStatement {  class Assignment FINAL : public LeafStatement {
669  protected:  protected:
670      VariableRef variable;      VariableRef variable;
671      ExpressionRef value;      ExpressionRef value;
# Line 489  public: Line 677  public:
677  };  };
678  typedef Ref<Assignment,Node> AssignmentRef;  typedef Ref<Assignment,Node> AssignmentRef;
679    
680  class If : public BranchStatement {  class If FINAL : public BranchStatement {
681      IntExprRef condition;      IntExprRef condition;
682      StatementsRef ifStatements;      StatementsRef ifStatements;
683      StatementsRef elseStatements;      StatementsRef elseStatements;
# Line 505  public: Line 693  public:
693  };  };
694  typedef Ref<If,Node> IfRef;  typedef Ref<If,Node> IfRef;
695    
696  struct CaseBranch {  struct CaseBranch FINAL {
697      IntExprRef from;      IntExprRef from;
698      IntExprRef to;      IntExprRef to;
699      StatementsRef statements;      StatementsRef statements;
700  };  };
   
701  typedef std::vector<CaseBranch> CaseBranches;  typedef std::vector<CaseBranch> CaseBranches;
702    
703  class SelectCase : public BranchStatement {  class SelectCase FINAL : public BranchStatement {
704      IntExprRef select;      IntExprRef select;
705      CaseBranches branches;      CaseBranches branches;
706  public:  public:
# Line 521  public: Line 708  public:
708      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
709      vmint evalBranch() OVERRIDE;      vmint evalBranch() OVERRIDE;
710      Statements* branch(vmuint i) const OVERRIDE;      Statements* branch(vmuint i) const OVERRIDE;
     //void addBranch(IntExprRef condition, StatementsRef statements);  
     //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);  
     //void addBranch(CaseBranchRef branch);  
     //void addBranches(CaseBranchesRef branches);  
711      bool isPolyphonic() const OVERRIDE;      bool isPolyphonic() const OVERRIDE;
712  };  };
713  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
714    
715  class While : public Statement {  class While FINAL : public Statement {
716      IntExprRef m_condition;      IntExprRef m_condition;
717      StatementsRef m_statements;      StatementsRef m_statements;
718  public:  public:
# Line 542  public: Line 725  public:
725      bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
726  };  };
727    
728  class SyncBlock : public Statement {  class SyncBlock FINAL : public Statement {
729      StatementsRef m_statements;      StatementsRef m_statements;
730  public:  public:
731      SyncBlock(StatementsRef statements) : m_statements(statements) {}      SyncBlock(StatementsRef statements) : m_statements(statements) {}
# Line 553  public: Line 736  public:
736  };  };
737  typedef Ref<SyncBlock,Node> SyncBlockRef;  typedef Ref<SyncBlock,Node> SyncBlockRef;
738    
739  class Neg : public IntExpr {  class Neg FINAL : virtual public IntExpr, virtual public RealExpr {
740      IntExprRef expr;      ScalarNumberExprRef expr;
741  public:  public:
742      Neg(IntExprRef expr) : expr(expr) { }      Neg(ScalarNumberExprRef expr) : Unit(expr->unitType()), expr(expr) { }
743      vmint evalInt() OVERRIDE { return (expr) ? -expr->evalInt() : 0; }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
744        vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; }
745        vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); }
746        String evalCastToStr() OVERRIDE;
747      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
748      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
749      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
750      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); }      vmfloat unitFactor() const OVERRIDE { return expr->unitFactor(); }
     StdUnit_t unitType() const OVERRIDE { return expr->unitType(); }  
751      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
752  };  };
753  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
754    
755  class ConcatString : public StringExpr {  class ConcatString FINAL : public StringExpr {
756      ExpressionRef lhs;      ExpressionRef lhs;
757      ExpressionRef rhs;      ExpressionRef rhs;
758  public:  public:
# Line 579  public: Line 764  public:
764  };  };
765  typedef Ref<ConcatString,Node> ConcatStringRef;  typedef Ref<ConcatString,Node> ConcatStringRef;
766    
767  class Relation : public IntExpr {  class Relation FINAL : public IntExpr {
768  public:  public:
769      enum Type {      enum Type {
770          LESS_THAN,          LESS_THAN,
# Line 589  public: Line 774  public:
774          EQUAL,          EQUAL,
775          NOT_EQUAL          NOT_EQUAL
776      };      };
777      Relation(IntExprRef lhs, Type type, IntExprRef rhs) :      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs);
         lhs(lhs), rhs(rhs), type(type) {}  
778      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
779      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
780      bool isConstExpr() const OVERRIDE;      bool isConstExpr() const OVERRIDE;
781      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
782      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
783      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
784  private:  private:
785      IntExprRef lhs;      ExpressionRef lhs;
786      IntExprRef rhs;      ExpressionRef rhs;
787      Type type;      Type type;
788  };  };
789  typedef Ref<Relation,Node> RelationRef;  typedef Ref<Relation,Node> RelationRef;
790    
791  class Or : public IntBinaryOp {  class Or FINAL : public IntBinaryOp {
792  public:  public:
793      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
794      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
795        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
796      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
797  };  };
798  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
799    
800  class BitwiseOr : public IntBinaryOp {  class BitwiseOr FINAL : public IntBinaryOp {
801  public:  public:
802      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
803      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
804      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
805      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
806  };  };
807  typedef Ref<BitwiseOr,Node> BitwiseOrRef;  typedef Ref<BitwiseOr,Node> BitwiseOrRef;
808    
809  class And : public IntBinaryOp {  class And FINAL : public IntBinaryOp {
810  public:  public:
811      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
812      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
813        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
814      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
815  };  };
816  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
817    
818  class BitwiseAnd : public IntBinaryOp {  class BitwiseAnd FINAL : public IntBinaryOp {
819  public:  public:
820      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
821      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
822      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
823      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
824  };  };
825  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
826    
827  class Not : virtual public IntExpr {  class Not FINAL : virtual public IntExpr {
828      IntExprRef expr;      IntExprRef expr;
829  public:  public:
830      Not(IntExprRef expr) : expr(expr) {}      Not(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
831      vmint evalInt() OVERRIDE { return !expr->evalInt(); }      vmint evalInt() OVERRIDE { return !expr->evalInt(); }
832      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
833      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
834      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
835      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
836      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
837  };  };
838  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
839    
840  class BitwiseNot : virtual public IntExpr {  class BitwiseNot FINAL : virtual public IntExpr {
841      IntExprRef expr;      IntExprRef expr;
842  public:  public:
843      BitwiseNot(IntExprRef expr) : expr(expr) {}      BitwiseNot(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
844      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }
845      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
846      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
847      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
848      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
849      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
850  };  };
851  typedef Ref<BitwiseNot,Node> BitwiseNotRef;  typedef Ref<BitwiseNot,Node> BitwiseNotRef;
852    
853  class Final : virtual public IntExpr {  class Final FINAL : virtual public IntExpr, virtual public RealExpr {
854      IntExprRef expr;      ScalarNumberExprRef expr;
855  public:  public:
856      Final(IntExprRef expr) : expr(expr) {}      Final(ScalarNumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}
857      vmint evalInt() OVERRIDE { return expr->evalInt(); }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
858        vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
859        vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }
860        String evalCastToStr() OVERRIDE;
861      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
862      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
863      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
864      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); }      vmfloat unitFactor() const OVERRIDE { return expr->unitFactor(); }
     StdUnit_t unitType() const OVERRIDE { return expr->unitType(); }  
865      bool isFinal() const OVERRIDE { return true; }      bool isFinal() const OVERRIDE { return true; }
866  };  };
867  typedef Ref<Final,Node> FinalRef;  typedef Ref<Final,Node> FinalRef;
868    
869  class ParserContext : public VMParserContext {  class ParserContext FINAL : public VMParserContext {
870  public:  public:
871      struct Error {      struct Error {
872          String txt;          String txt;
# Line 704  public: Line 887  public:
887      std::map<String,VariableRef> vartable;      std::map<String,VariableRef> vartable;
888      std::map<String,StatementsRef> userFnTable;      std::map<String,StatementsRef> userFnTable;
889      vmint globalIntVarCount;      vmint globalIntVarCount;
890        vmint globalRealVarCount;
891      vmint globalStrVarCount;      vmint globalStrVarCount;
892        vmint globalUnitFactorCount;
893      vmint polyphonicIntVarCount;      vmint polyphonicIntVarCount;
894        vmint polyphonicRealVarCount;
895        vmint polyphonicUnitFactorCount;
896    
897      EventHandlersRef handlers;      EventHandlersRef handlers;
898    
# Line 715  public: Line 902  public:
902      OnControllerRef onController;      OnControllerRef onController;
903    
904      ArrayList<vmint>* globalIntMemory;      ArrayList<vmint>* globalIntMemory;
905        ArrayList<vmfloat>* globalRealMemory;
906      ArrayList<String>* globalStrMemory;      ArrayList<String>* globalStrMemory;
907        ArrayList<vmfloat>* globalUnitFactorMemory;
908      vmint requiredMaxStackSize;      vmint requiredMaxStackSize;
909    
910      VMFunctionProvider* functionProvider;      VMFunctionProvider* functionProvider;
# Line 724  public: Line 913  public:
913    
914      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
915          scanner(NULL), is(NULL),          scanner(NULL), is(NULL),
916          globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),
917          globalIntMemory(NULL), globalStrMemory(NULL), requiredMaxStackSize(-1),          globalUnitFactorCount(0),
918            polyphonicIntVarCount(0), polyphonicRealVarCount(0),
919            polyphonicUnitFactorCount(0),
920            globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),
921            globalUnitFactorMemory(NULL),
922            requiredMaxStackSize(-1),
923          functionProvider(parent), execContext(NULL)          functionProvider(parent), execContext(NULL)
924      {      {
925      }      }
926      virtual ~ParserContext();      virtual ~ParserContext();
927      VariableRef globalVar(const String& name);      VariableRef globalVar(const String& name);
928      IntVariableRef globalIntVar(const String& name);      IntVariableRef globalIntVar(const String& name);
929        RealVariableRef globalRealVar(const String& name);
930      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
931      VariableRef variableByName(const String& name);      VariableRef variableByName(const String& name);
932      StatementsRef userFunctionByName(const String& name);      StatementsRef userFunctionByName(const String& name);
# Line 755  public: Line 950  public:
950      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
951  };  };
952    
953  class ExecContext : public VMExecContext {  class ExecContext FINAL : public VMExecContext {
954  public:  public:
955      struct StackFrame {      struct StackFrame {
956          Statement* statement;          Statement* statement;
# Line 768  public: Line 963  public:
963      };      };
964    
965      ArrayList<vmint> polyphonicIntMemory;      ArrayList<vmint> polyphonicIntMemory;
966        ArrayList<vmfloat> polyphonicRealMemory;
967        ArrayList<vmfloat> polyphonicUnitFactorMemory;
968      VMExecStatus_t status;      VMExecStatus_t status;
969      StmtFlags_t flags;      StmtFlags_t flags;
970      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
# Line 777  public: Line 974  public:
974      struct ExitRes {      struct ExitRes {
975          Expression* value;          Expression* value;
976          IntLiteral intLiteral;          IntLiteral intLiteral;
977            RealLiteral realLiteral;
978          StringLiteral stringLiteral;          StringLiteral stringLiteral;
979    
980          ExitRes() : intLiteral(0), stringLiteral("") { }          ExitRes() :
981                intLiteral({ .value = 0 }), realLiteral({ .value = 0.0 }),
982                stringLiteral("") { }
983      } exitRes;      } exitRes;
984    
985      ExecContext();      ExecContext();
# Line 816  public: Line 1016  public:
1016      }      }
1017    
1018      void resetPolyphonicData() OVERRIDE {      void resetPolyphonicData() OVERRIDE {
1019          if (polyphonicIntMemory.empty()) return;          if (!polyphonicIntMemory.empty())
1020          memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));
1021            if (!polyphonicRealMemory.empty())
1022                memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));
1023            if (!polyphonicUnitFactorMemory.empty()) {
1024                const vmint sz = polyphonicUnitFactorMemory.size();
1025                for (vmint i = 0; i < sz; ++i)
1026                    polyphonicUnitFactorMemory[i] = VM_NO_FACTOR;
1027            }
1028      }      }
1029    
1030      size_t instructionsPerformed() const OVERRIDE {      size_t instructionsPerformed() const OVERRIDE {

Legend:
Removed from v.3561  
changed lines
  Added in v.3581

  ViewVC Help
Powered by ViewVC