/[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 3574 by schoenebeck, Wed Aug 28 08:26:54 2019 UTC revision 3804 by schoenebeck, Thu Aug 6 12:15:02 2020 UTC
# Line 21  Line 21 
21  #include <map>  #include <map>
22  #include <set>  #include <set>
23  #include <string.h> // for memset()  #include <string.h> // for memset()
24    #include <assert.h>
25  #include "../common/global.h"  #include "../common/global.h"
26  #include "../common/Ref.h"  #include "../common/Ref.h"
27  #include "../common/ArrayList.h"  #include "../common/ArrayList.h"
28    #include "../common/optional.h"
29  #include "common.h"  #include "common.h"
30    
31  namespace LinuxSampler {  namespace LinuxSampler {
# Line 40  enum StmtType_t { Line 42  enum StmtType_t {
42      STMT_NOOP,      STMT_NOOP,
43  };  };
44    
45    enum Qualifier_t {
46        QUALIFIER_NONE = 0,
47        QUALIFIER_CONST = 1,
48        QUALIFIER_POLYPHONIC = (1<<1),
49        QUALIFIER_PATCH = (1<<2),
50    };
51    
52    struct PatchVarBlock {
53        CodeBlock nameBlock;
54        optional<CodeBlock> exprBlock;
55    };
56    
57    /**
58     * Convenience function used for retrieving the (assumed) data type of a given
59     * script variable name.
60     *
61     * @param name - some script variable name (e.g. "$foo")
62     * @return variable's assumed data type (e.g. INT_EXPR for example above)
63     */
64    inline ExprType_t exprTypeOfVarName(const String& name) {
65        if (name.empty()) return (ExprType_t) -1;
66        const char prefix = name[0];
67        switch (prefix) {
68            case '$': return INT_EXPR;
69            case '%': return INT_ARR_EXPR;
70            case '~': return REAL_EXPR;
71            case '?': return REAL_ARR_EXPR;
72            case '@': return STRING_EXPR;
73            case '!': return STRING_ARR_EXPR;
74        }
75        return (ExprType_t) -1;
76    }
77    
78    inline ExprType_t scalarTypeOfArray(ExprType_t arrayType) {
79        if (arrayType == INT_ARR_EXPR) return INT_EXPR;
80        if (arrayType == REAL_ARR_EXPR) return REAL_EXPR;
81        if (arrayType == STRING_ARR_EXPR) return STRING_EXPR;
82        assert(false);
83        return EMPTY_EXPR; // just to shut up the compiler
84    }
85    
86    inline String qualifierStr(Qualifier_t qualifier) {
87        switch (qualifier) {
88            case QUALIFIER_NONE:          return "none";
89            case QUALIFIER_CONST:         return "const";
90            case QUALIFIER_POLYPHONIC:    return "polyphonic";
91            case QUALIFIER_PATCH:         return "patch";
92        }
93        return "unknown";
94    }
95    
96    /**
97     * Used by parser for parser error messages to provide a text with all data
98     * types accepted by the given built-in function @a fn for the respective
99     * function argument @a iArg.
100     */
101    String acceptedArgTypesStr(VMFunction* fn, vmint iArg);
102    
103  class Node {  class Node {
104  public:  public:
105      Node();      Node();
# Line 59  public: Line 119  public:
119  typedef Ref<Expression,Node> ExpressionRef;  typedef Ref<Expression,Node> ExpressionRef;
120    
121  class Unit : virtual public VMUnit, virtual public Node {  class Unit : virtual public VMUnit, virtual public Node {
     ArrayList<MetricPrefix_t> prefix;  
122      StdUnit_t unit;      StdUnit_t unit;
123  public:  public:
124      Unit() : unit(VM_NO_UNIT) {}      Unit(StdUnit_t type) : unit(type) {}
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
125      StdUnit_t unitType() const OVERRIDE { return unit; }      StdUnit_t unitType() const OVERRIDE { return unit; }
126      void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type);      static vmint convIntToUnitFactor(vmint iValue, VMUnit* srcUnit, VMUnit* dstUnit);
127      void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type);      static vmint convIntToUnitFactor(vmint iValue, vmfloat srcFactor, vmfloat dstFactor);
128      void copyUnitFrom(const Ref<Unit,Node>& src);      static vmfloat convRealToUnitFactor(vmfloat fValue, VMUnit* srcUnit, VMUnit* dstUnit);
129        static vmfloat convRealToUnitFactor(vmfloat fValue, vmfloat srcFactor, vmfloat dstFactor);
130  };  };
131  typedef Ref<Unit,Node> UnitRef;  typedef Ref<Unit,Node> UnitRef;
132    
133  class ScalarNumberExpr : virtual public Unit, virtual public VMScalarNumberExpr, virtual public Expression {  class NumberExpr : virtual public Unit, virtual public VMNumberExpr, virtual public Expression {
134  public:  public:
135  };  };
136  typedef Ref<ScalarNumberExpr,Node> ScalarNumberExprRef;  typedef Ref<NumberExpr,Node> NumberExprRef;
137    
138  class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr {  class IntExpr : virtual public NumberExpr, virtual public VMIntExpr {
139  public:  public:
140      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
141        vmint evalIntToUnitFactor(vmfloat unitFactor);
142      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
143  };  };
144  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
145    
146  class RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr  {  class RealExpr : virtual public NumberExpr, virtual public VMRealExpr  {
147  public:  public:
148      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
149        vmfloat evalRealToUnitFactor(vmfloat unitFactor);
150      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
151  };  };
152  typedef Ref<RealExpr,Node> RealExprRef;  typedef Ref<RealExpr,Node> RealExprRef;
# Line 116  public: Line 177  public:
177  };  };
178  typedef Ref<StringExpr,Node> StringExprRef;  typedef Ref<StringExpr,Node> StringExprRef;
179    
180    struct IntLitDef {
181        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.
182        vmfloat unitFactor = VM_NO_FACTOR;
183        StdUnit_t unitType = VM_NO_UNIT;
184        bool isFinal;
185    };
186    
187  class IntLiteral FINAL : public IntExpr {  class IntLiteral FINAL : public IntExpr {
188      bool finalVal;      bool finalVal;
189  public:      vmfloat unitPrefixFactor;
190      vmint value;      vmint value;
191      IntLiteral(vmint value) : IntExpr(),  public:
192          value(value), finalVal(false) { }      IntLiteral(const IntLitDef& def);
193      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
194        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
195      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
196      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
197      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
198      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
199  };  };
200  typedef Ref<IntLiteral,Node> IntLiteralRef;  typedef Ref<IntLiteral,Node> IntLiteralRef;
201    
202    struct RealLitDef {
203        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.
204        vmfloat unitFactor = VM_NO_FACTOR;
205        StdUnit_t unitType = VM_NO_UNIT;
206        bool isFinal;
207    };
208    
209  class RealLiteral FINAL : public RealExpr {  class RealLiteral FINAL : public RealExpr {
     vmfloat value;  
210      bool finalVal;      bool finalVal;
211        vmfloat unitPrefixFactor;
212        vmfloat value;
213  public:  public:
214      RealLiteral(vmfloat value) : RealExpr(),      RealLiteral(const RealLitDef& def);
         value(value), finalVal(false) { }  
215      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
216        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
217      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
218      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
219      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
220      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
221  };  };
222  typedef Ref<RealLiteral,Node> RealLiteralRef;  typedef Ref<RealLiteral,Node> RealLiteralRef;
223    
224  class StringLiteral FINAL : public StringExpr {  class StringLiteral FINAL : public StringExpr {
 public:  
225      String value;      String value;
226    public:
227      StringLiteral(const String& value) : value(value) { }      StringLiteral(const String& value) : value(value) { }
228      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
229      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
# Line 168  public: Line 243  public:
243  };  };
244  typedef Ref<Args,Node> ArgsRef;  typedef Ref<Args,Node> ArgsRef;
245    
246    struct VariableDecl {
247        ParserContext* ctx;
248        bool isPolyphonic;
249        bool isConst;
250        vmint elements = 1;
251        vmint memPos;
252        vmint unitFactorMemPos;
253        StdUnit_t unitType = VM_NO_UNIT;
254        bool isFinal;
255    };
256    
257  class Variable : virtual public VMVariable, virtual public Expression {  class Variable : virtual public VMVariable, virtual public Expression {
258  public:  public:
259      bool isConstExpr() const OVERRIDE { return bConst; }      bool isConstExpr() const OVERRIDE { return bConst; }
# Line 175  public: Line 261  public:
261      virtual void assign(Expression* expr) = 0;      virtual void assign(Expression* expr) = 0;
262      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); }
263  protected:  protected:
264      Variable(ParserContext* ctx, vmint _memPos, bool _bConst)      Variable(const VariableDecl& decl);
         : context(ctx), memPos(_memPos), bConst(_bConst) {}  
265    
266      ParserContext* context;      ParserContext* context;
267      vmint memPos;      vmint memPos;
# Line 184  protected: Line 269  protected:
269  };  };
270  typedef Ref<Variable,Node> VariableRef;  typedef Ref<Variable,Node> VariableRef;
271    
272  class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr {  class NumberVariable : public Variable, virtual public NumberExpr {
273      bool polyphonic;      bool polyphonic;
274      bool finalVal;      bool finalVal;
275    protected:
276        vmint unitFactorMemPos;
277  public:  public:
278      bool isPolyphonic() const OVERRIDE { return polyphonic; }      bool isPolyphonic() const OVERRIDE { return polyphonic; }
279      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
280      void setFinal(bool b = true) { finalVal = b; }      vmfloat unitFactor() const OVERRIDE;
281  protected:  protected:
282      ScalarNumberVariable(ParserContext* ctx, vmint _memPos,      NumberVariable(const VariableDecl& decl);
                          bool _bConst = false, bool _bPolyphonic = false,  
                          bool _bFinal = false);  
283  };  };
284  typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef;  typedef Ref<NumberVariable,Node> NumberVariableRef;
285    
286  class IntVariable : public ScalarNumberVariable, virtual public IntExpr {  class IntVariable : public NumberVariable, virtual public IntExpr {
287  public:  public:
288      IntVariable(ParserContext* ctx);      IntVariable(const VariableDecl& decl);
289      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
290      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
291      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
 protected:  
     IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);  
292  };  };
293  typedef Ref<IntVariable,Node> IntVariableRef;  typedef Ref<IntVariable,Node> IntVariableRef;
294    
295  class RealVariable : public ScalarNumberVariable, virtual public RealExpr {  class RealVariable : public NumberVariable, virtual public RealExpr {
296  public:  public:
297      RealVariable(ParserContext* ctx);      RealVariable(const VariableDecl& decl);
298      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
299      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
300      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
 protected:  
     RealVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);  
301  };  };
302  typedef Ref<RealVariable,Node> RealVariableRef;  typedef Ref<RealVariable,Node> RealVariableRef;
303    
304    struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
305        // additions for RealVarDef
306        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.
307        vmfloat unitFactor = VM_NO_FACTOR;
308        // copied from VariableDecl
309        ParserContext* ctx;
310        bool isPolyphonic;
311        bool isConst;
312        vmint elements = 1;
313        vmint memPos;
314        vmint unitFactorMemPos;
315        StdUnit_t unitType = VM_NO_UNIT;
316        bool isFinal;
317    };
318    
319  class ConstIntVariable FINAL : public IntVariable {  class ConstIntVariable FINAL : public IntVariable {
320  public:      vmfloat unitPrefixFactor;
321      vmint value;      vmint value;
322    public:
323      ConstIntVariable(vmint value);      ConstIntVariable(const IntVarDef& def);
324      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
325      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
326        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
327      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
328  };  };
329  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
330    
331    struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
332        // additions for RealVarDef
333        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.
334        vmfloat unitFactor = VM_NO_FACTOR;
335        // copied from VariableDecl
336        ParserContext* ctx;
337        bool isPolyphonic;
338        bool isConst;
339        vmint elements = 1;
340        vmint memPos;
341        vmint unitFactorMemPos;
342        StdUnit_t unitType = VM_NO_UNIT;
343        bool isFinal;
344    };
345    
346  class ConstRealVariable FINAL : public RealVariable {  class ConstRealVariable FINAL : public RealVariable {
347  public:      vmfloat unitPrefixFactor;
348      vmfloat value;      vmfloat value;
349    public:
350      ConstRealVariable(vmfloat value);      ConstRealVariable(const RealVarDef& def);
351      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
352      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
353        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
354      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
355  };  };
356  typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;  typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;
# Line 250  public: Line 363  public:
363      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }
364      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
365      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
366        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
367      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
368  };  };
369  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
370    
371  class PolyphonicIntVariable FINAL : public IntVariable {  class PolyphonicIntVariable FINAL : public IntVariable {
372  public:  public:
373      PolyphonicIntVariable(ParserContext* ctx);      PolyphonicIntVariable(const VariableDecl& decl);
374      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
375  };  };
376  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
377    
378  class PolyphonicRealVariable FINAL : public RealVariable {  class PolyphonicRealVariable FINAL : public RealVariable {
379  public:  public:
380      PolyphonicRealVariable(ParserContext* ctx);      PolyphonicRealVariable(const VariableDecl& decl);
381      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
382  };  };
383  typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;  typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;
384    
385  class IntArrayVariable : public Variable, virtual public IntArrayExpr {  class IntArrayVariable : public Variable, virtual public IntArrayExpr {
386      ArrayList<vmint> values;      ArrayList<vmint> values;
387        ArrayList<vmfloat> unitFactors;
388  public:  public:
389      IntArrayVariable(ParserContext* ctx, vmint size);      IntArrayVariable(ParserContext* ctx, vmint size);
390      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
391      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  
392      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
393      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
394      virtual vmint evalIntElement(vmuint i) OVERRIDE;      virtual vmint evalIntElement(vmuint i) OVERRIDE;
395      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;
396        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
397        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
398      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
399      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
400  protected:  protected:
# Line 288  typedef Ref<IntArrayVariable,Node> IntAr Line 404  typedef Ref<IntArrayVariable,Node> IntAr
404    
405  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {
406      ArrayList<vmfloat> values;      ArrayList<vmfloat> values;
407        ArrayList<vmfloat> unitFactors;
408  public:  public:
409      RealArrayVariable(ParserContext* ctx, vmint size);      RealArrayVariable(ParserContext* ctx, vmint size);
410      RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
411      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  
412      ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
413      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
414      virtual vmfloat evalRealElement(vmuint i) OVERRIDE;      virtual vmfloat evalRealElement(vmuint i) OVERRIDE;
415      virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;      virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;
416        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
417        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
418      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
419      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
420  protected:  protected:
# Line 311  public: Line 429  public:
429      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
430      vmint arraySize() const OVERRIDE { return array->size; }      vmint arraySize() const OVERRIDE { return array->size; }
431      vmint evalIntElement(vmuint i) OVERRIDE;      vmint evalIntElement(vmuint i) OVERRIDE;
     bool isAssignable() const OVERRIDE { return !array->readonly; }  
432      void assignIntElement(vmuint i, vmint value) OVERRIDE;      void assignIntElement(vmuint i, vmint value) OVERRIDE;
433        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
434        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
435        bool isAssignable() const OVERRIDE { return !array->readonly; }
436      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
437  };  };
438  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
# Line 320  typedef Ref<BuiltInIntArrayVariable,Node Line 440  typedef Ref<BuiltInIntArrayVariable,Node
440  class IntArrayElement FINAL : public IntVariable {  class IntArrayElement FINAL : public IntVariable {
441      IntArrayExprRef array;      IntArrayExprRef array;
442      IntExprRef index;      IntExprRef index;
443        vmint currentIndex;
444  public:  public:
445      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);
446      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
447      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
448        vmfloat unitFactor() const OVERRIDE;
449      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
450  };  };
451  typedef Ref<IntArrayElement,Node> IntArrayElementRef;  typedef Ref<IntArrayElement,Node> IntArrayElementRef;
# Line 331  typedef Ref<IntArrayElement,Node> IntArr Line 453  typedef Ref<IntArrayElement,Node> IntArr
453  class RealArrayElement FINAL : public RealVariable {  class RealArrayElement FINAL : public RealVariable {
454      RealArrayExprRef array;      RealArrayExprRef array;
455      IntExprRef index;      IntExprRef index;
456        vmint currentIndex;
457  public:  public:
458      RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);      RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);
459      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
460      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
461        vmfloat unitFactor() const OVERRIDE;
462      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
463  };  };
464  typedef Ref<RealArrayElement,Node> RealArrayElementRef;  typedef Ref<RealArrayElement,Node> RealArrayElementRef;
# Line 352  protected: Line 476  protected:
476  typedef Ref<StringVariable,Node> StringVariableRef;  typedef Ref<StringVariable,Node> StringVariableRef;
477    
478  class ConstStringVariable FINAL : public StringVariable {  class ConstStringVariable FINAL : public StringVariable {
 public:  
479      String value;      String value;
480    public:
481      ConstStringVariable(ParserContext* ctx, String value = "");      ConstStringVariable(ParserContext* ctx, String value = "");
482      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
483      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
# Line 373  public: Line 496  public:
496  };  };
497  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
498    
499  class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr {  class NumberBinaryOp : public BinaryOp, virtual public NumberExpr {
500  public:  public:
501      ScalarNumberBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : BinaryOp(lhs, rhs) { }      NumberBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : BinaryOp(lhs, rhs) { }
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
502      bool isFinal() const OVERRIDE;      bool isFinal() const OVERRIDE;
503  };  };
504  typedef Ref<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef;  typedef Ref<NumberBinaryOp,Node> NumberBinaryOpRef;
505    
506  class IntBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr {  class IntBinaryOp : public NumberBinaryOp, virtual public IntExpr {
507  public:  public:
508      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
509  };  };
510  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;
511    
512  class VaritypeScalarBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr, virtual public RealExpr {  class VaritypeScalarBinaryOp : public NumberBinaryOp, virtual public IntExpr, virtual public RealExpr {
513  public:  public:
514      VaritypeScalarBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }      VaritypeScalarBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
515      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
516      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
517  };  };
# Line 398  typedef Ref<VaritypeScalarBinaryOp,Node> Line 519  typedef Ref<VaritypeScalarBinaryOp,Node>
519    
520  class Add FINAL : public VaritypeScalarBinaryOp {  class Add FINAL : public VaritypeScalarBinaryOp {
521  public:  public:
522      Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Add(NumberExprRef lhs, NumberExprRef rhs);
523      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
524      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
525        vmfloat unitFactor() const OVERRIDE;
526      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
527  };  };
528  typedef Ref<Add,Node> AddRef;  typedef Ref<Add,Node> AddRef;
529    
530  class Sub FINAL : public VaritypeScalarBinaryOp {  class Sub FINAL : public VaritypeScalarBinaryOp {
531  public:  public:
532      Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Sub(NumberExprRef lhs, NumberExprRef rhs);
533      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
534      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
535        vmfloat unitFactor() const OVERRIDE;
536      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
537  };  };
538  typedef Ref<Sub,Node> SubRef;  typedef Ref<Sub,Node> SubRef;
539    
540  class Mul FINAL : public VaritypeScalarBinaryOp {  class Mul FINAL : public VaritypeScalarBinaryOp {
541  public:  public:
542      Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Mul(NumberExprRef lhs, NumberExprRef rhs);
543      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
544      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
545        vmfloat unitFactor() const OVERRIDE;
546      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
547  };  };
548  typedef Ref<Mul,Node> MulRef;  typedef Ref<Mul,Node> MulRef;
549    
550  class Div FINAL : public VaritypeScalarBinaryOp {  class Div FINAL : public VaritypeScalarBinaryOp {
551  public:  public:
552      Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Div(NumberExprRef lhs, NumberExprRef rhs);
553      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
554      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
555      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
556      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
     StdUnit_t unitType() const OVERRIDE;  
557  };  };
558  typedef Ref<Div,Node> DivRef;  typedef Ref<Div,Node> DivRef;
559    
560  class Mod FINAL : public IntBinaryOp {  class Mod FINAL : public IntBinaryOp {
561  public:  public:
562      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs), Unit(VM_NO_UNIT) { }
563      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
564        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
565      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
566  };  };
567  typedef Ref<Mod,Node> ModRef;  typedef Ref<Mod,Node> ModRef;
# Line 505  public: Line 627  public:
627      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }
628      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
629      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); }
630        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
631        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
632      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
633      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; }  
634      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
635  };  };
636  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
# Line 516  class FunctionCall : virtual public Leaf Line 639  class FunctionCall : virtual public Leaf
639      String functionName;      String functionName;
640      ArgsRef args;      ArgsRef args;
641      VMFunction* fn;      VMFunction* fn;
642        VMFnResult* result;
643  public:  public:
644      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn);
645          functionName(function), args(args), fn(fn) { }      virtual ~FunctionCall();
646      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
647      StmtFlags_t exec() OVERRIDE;      StmtFlags_t exec() OVERRIDE;
648      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
# Line 530  public: Line 654  public:
654      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
655      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
656      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
657      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE;
658      StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }      bool isFinal() const OVERRIDE;
     bool isFinal() const OVERRIDE { return false; }  
659  protected:  protected:
660      VMFnResult* execVMFn();      VMFnResult* execVMFn();
661  };  };
# Line 540  typedef Ref<FunctionCall,Node> FunctionC Line 663  typedef Ref<FunctionCall,Node> FunctionC
663    
664  class NoFunctionCall FINAL : public FunctionCall {  class NoFunctionCall FINAL : public FunctionCall {
665  public:  public:
666      NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {}      NoFunctionCall() : FunctionCall("nothing", new Args, NULL), Unit(VM_NO_UNIT) {}
667      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
668  };  };
669  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;
670    
671  class EventHandler : virtual public Statements, virtual public VMEventHandler {  class Subroutine : public Statements {
672      StatementsRef statements;      StatementsRef statements;
673    public:
674        Subroutine(StatementsRef statements);
675        Statement* statement(uint i) OVERRIDE { return statements->statement(i); }
676        void dump(int level = 0) OVERRIDE;
677    };
678    typedef Ref<Subroutine,Node> SubroutineRef;
679    
680    class UserFunction : public Subroutine {
681    public:
682        UserFunction(StatementsRef statements);
683    };
684    typedef Ref<UserFunction,Node> UserFunctionRef;
685    
686    class EventHandler : public Subroutine, virtual public VMEventHandler {
687      bool usingPolyphonics;      bool usingPolyphonics;
688  public:  public:
689      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
     StmtFlags_t exec();  
690      EventHandler(StatementsRef statements);      EventHandler(StatementsRef statements);
     Statement* statement(uint i) OVERRIDE { return statements->statement(i); }  
691      bool isPolyphonic() const OVERRIDE { return usingPolyphonics; }      bool isPolyphonic() const OVERRIDE { return usingPolyphonics; }
692  };  };
693  typedef Ref<EventHandler,Node> EventHandlerRef;  typedef Ref<EventHandler,Node> EventHandlerRef;
# Line 589  public: Line 724  public:
724  };  };
725  typedef Ref<OnController,Node> OnControllerRef;  typedef Ref<OnController,Node> OnControllerRef;
726    
727    class OnRpn FINAL : public EventHandler {
728    public:
729        OnRpn(StatementsRef statements) : EventHandler(statements) {}
730        VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RPN; }
731        String eventHandlerName() const OVERRIDE { return "rpn"; }
732    };
733    typedef Ref<OnRpn,Node> OnRpnRef;
734    
735    class OnNrpn FINAL : public EventHandler {
736    public:
737        OnNrpn(StatementsRef statements) : EventHandler(statements) {}
738        VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NRPN; }
739        String eventHandlerName() const OVERRIDE { return "nrpn"; }
740    };
741    typedef Ref<OnNrpn,Node> OnNrpnRef;
742    
743  class EventHandlers FINAL : virtual public Node {  class EventHandlers FINAL : virtual public Node {
744      std::vector<EventHandlerRef> args;      std::vector<EventHandlerRef> args;
745  public:  public:
# Line 646  public: Line 797  public:
797      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
798      vmint evalBranch() OVERRIDE;      vmint evalBranch() OVERRIDE;
799      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);  
800      bool isPolyphonic() const OVERRIDE;      bool isPolyphonic() const OVERRIDE;
801  };  };
802  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
# Line 678  public: Line 825  public:
825  };  };
826  typedef Ref<SyncBlock,Node> SyncBlockRef;  typedef Ref<SyncBlock,Node> SyncBlockRef;
827    
828  class Neg FINAL : public IntExpr {  class Neg FINAL : virtual public IntExpr, virtual public RealExpr {
829      IntExprRef expr;      NumberExprRef expr;
830  public:  public:
831      Neg(IntExprRef expr) : expr(expr) { }      Neg(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) { }
832      vmint evalInt() OVERRIDE { return (expr) ? -expr->evalInt() : 0; }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
833        vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; }
834        vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); }
835        String evalCastToStr() OVERRIDE;
836      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
837      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
838      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
839      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(); }  
840      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
841  };  };
842  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
# Line 714  public: Line 863  public:
863          EQUAL,          EQUAL,
864          NOT_EQUAL          NOT_EQUAL
865      };      };
866      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs) :      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs);
         lhs(lhs), rhs(rhs), type(type) {}  
867      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
868      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
869      bool isConstExpr() const OVERRIDE;      bool isConstExpr() const OVERRIDE;
870      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
871      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; }  
872      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
873  private:  private:
874      ExpressionRef lhs;      ExpressionRef lhs;
# Line 732  typedef Ref<Relation,Node> RelationRef; Line 879  typedef Ref<Relation,Node> RelationRef;
879    
880  class Or FINAL : public IntBinaryOp {  class Or FINAL : public IntBinaryOp {
881  public:  public:
882      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
883      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
884        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
885      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
886  };  };
887  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
888    
889  class BitwiseOr FINAL : public IntBinaryOp {  class BitwiseOr FINAL : public IntBinaryOp {
890  public:  public:
891      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
892      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
893      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
894      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; }  
895  };  };
896  typedef Ref<BitwiseOr,Node> BitwiseOrRef;  typedef Ref<BitwiseOr,Node> BitwiseOrRef;
897    
898  class And FINAL : public IntBinaryOp {  class And FINAL : public IntBinaryOp {
899  public:  public:
900      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
901      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
902        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
903      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
904  };  };
905  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
906    
907  class BitwiseAnd FINAL : public IntBinaryOp {  class BitwiseAnd FINAL : public IntBinaryOp {
908  public:  public:
909      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
910      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
911      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
912      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; }  
913  };  };
914  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
915    
916  class Not FINAL : virtual public IntExpr {  class Not FINAL : virtual public IntExpr {
917      IntExprRef expr;      IntExprRef expr;
918  public:  public:
919      Not(IntExprRef expr) : expr(expr) {}      Not(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
920      vmint evalInt() OVERRIDE { return !expr->evalInt(); }      vmint evalInt() OVERRIDE { return !expr->evalInt(); }
921      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
922      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
923      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
924      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; }  
925      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
926  };  };
927  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
# Line 783  typedef Ref<Not,Node> NotRef; Line 929  typedef Ref<Not,Node> NotRef;
929  class BitwiseNot FINAL : virtual public IntExpr {  class BitwiseNot FINAL : virtual public IntExpr {
930      IntExprRef expr;      IntExprRef expr;
931  public:  public:
932      BitwiseNot(IntExprRef expr) : expr(expr) {}      BitwiseNot(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
933      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }
934      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
935      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
936      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
937      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; }  
938      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
939  };  };
940  typedef Ref<BitwiseNot,Node> BitwiseNotRef;  typedef Ref<BitwiseNot,Node> BitwiseNotRef;
941    
942  class Final FINAL : virtual public IntExpr, virtual public RealExpr {  class Final FINAL : virtual public IntExpr, virtual public RealExpr {
943      ScalarNumberExprRef expr;      NumberExprRef expr;
944  public:  public:
945      Final(ScalarNumberExprRef expr) : expr(expr) {}      Final(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}
946      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
947      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
948      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }
# Line 805  public: Line 950  public:
950      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
951      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
952      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
953      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(); }  
954      bool isFinal() const OVERRIDE { return true; }      bool isFinal() const OVERRIDE { return true; }
955  };  };
956  typedef Ref<Final,Node> FinalRef;  typedef Ref<Final,Node> FinalRef;
# Line 821  public: Line 965  public:
965    
966      void* scanner;      void* scanner;
967      std::istream* is;      std::istream* is;
968        int nbytes;
969      std::vector<ParserIssue> vErrors;      std::vector<ParserIssue> vErrors;
970      std::vector<ParserIssue> vWarnings;      std::vector<ParserIssue> vWarnings;
971      std::vector<ParserIssue> vIssues;      std::vector<ParserIssue> vIssues;
972      std::vector<CodeBlock>   vPreprocessorComments;      std::vector<CodeBlock>   vPreprocessorComments;
973        std::map<String,PatchVarBlock> patchVars;
974    
975      std::set<String> builtinPreprocessorConditions;      std::set<String> builtinPreprocessorConditions;
976      std::set<String> userPreprocessorConditions;      std::set<String> userPreprocessorConditions;
977    
978      std::map<String,VariableRef> vartable;      std::map<String,VariableRef> vartable;
979      std::map<String,StatementsRef> userFnTable;      std::map<String,UserFunctionRef> userFnTable;
980      vmint globalIntVarCount;      vmint globalIntVarCount;
981      vmint globalRealVarCount;      vmint globalRealVarCount;
982      vmint globalStrVarCount;      vmint globalStrVarCount;
983        vmint globalUnitFactorCount;
984      vmint polyphonicIntVarCount;      vmint polyphonicIntVarCount;
985      vmint polyphonicRealVarCount;      vmint polyphonicRealVarCount;
986        vmint polyphonicUnitFactorCount;
987    
988      EventHandlersRef handlers;      EventHandlersRef handlers;
989    
# Line 843  public: Line 991  public:
991      OnNoteRef onNote;      OnNoteRef onNote;
992      OnReleaseRef onRelease;      OnReleaseRef onRelease;
993      OnControllerRef onController;      OnControllerRef onController;
994        OnRpnRef onRpn;
995        OnNrpnRef onNrpn;
996    
997      ArrayList<vmint>* globalIntMemory;      ArrayList<vmint>* globalIntMemory;
998      ArrayList<vmfloat>* globalRealMemory;      ArrayList<vmfloat>* globalRealMemory;
999      ArrayList<String>* globalStrMemory;      ArrayList<String>* globalStrMemory;
1000        ArrayList<vmfloat>* globalUnitFactorMemory;
1001      vmint requiredMaxStackSize;      vmint requiredMaxStackSize;
1002    
1003      VMFunctionProvider* functionProvider;      VMFunctionProvider* functionProvider;
# Line 854  public: Line 1005  public:
1005      ExecContext* execContext;      ExecContext* execContext;
1006    
1007      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
1008          scanner(NULL), is(NULL),          scanner(NULL), is(NULL), nbytes(0),
1009          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),
1010            globalUnitFactorCount(0),
1011          polyphonicIntVarCount(0), polyphonicRealVarCount(0),          polyphonicIntVarCount(0), polyphonicRealVarCount(0),
1012            polyphonicUnitFactorCount(0),
1013          globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),          globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),
1014            globalUnitFactorMemory(NULL),
1015          requiredMaxStackSize(-1),          requiredMaxStackSize(-1),
1016          functionProvider(parent), execContext(NULL)          functionProvider(parent), execContext(NULL)
1017      {      {
# Line 868  public: Line 1022  public:
1022      RealVariableRef globalRealVar(const String& name);      RealVariableRef globalRealVar(const String& name);
1023      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
1024      VariableRef variableByName(const String& name);      VariableRef variableByName(const String& name);
1025      StatementsRef userFunctionByName(const String& name);      UserFunctionRef userFunctionByName(const String& name);
1026      void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);      void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn,
1027      void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);                  int firstByte, int lengthBytes, const char* txt);
1028      void addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn);      void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn,
1029                    int firstByte, int lengthBytes, const char* txt);
1030        void addPreprocessorComment(int firstLine, int lastLine, int firstColumn,
1031                                    int lastColumn, int firstByte, int lengthBytes);
1032      void createScanner(std::istream* is);      void createScanner(std::istream* is);
1033      void destroyScanner();      void destroyScanner();
1034      bool setPreprocessorCondition(const char* name);      bool setPreprocessorCondition(const char* name);
# Line 884  public: Line 1041  public:
1041      VMEventHandler* eventHandler(uint index) OVERRIDE;      VMEventHandler* eventHandler(uint index) OVERRIDE;
1042      VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;      VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
1043      void registerBuiltInConstIntVariables(const std::map<String,vmint>& vars);      void registerBuiltInConstIntVariables(const std::map<String,vmint>& vars);
1044        void registerBuiltInConstRealVariables(const std::map<String,vmfloat>& vars);
1045      void registerBuiltInIntVariables(const std::map<String,VMIntPtr*>& vars);      void registerBuiltInIntVariables(const std::map<String,VMIntPtr*>& vars);
1046      void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);      void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
1047      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
# Line 903  public: Line 1061  public:
1061    
1062      ArrayList<vmint> polyphonicIntMemory;      ArrayList<vmint> polyphonicIntMemory;
1063      ArrayList<vmfloat> polyphonicRealMemory;      ArrayList<vmfloat> polyphonicRealMemory;
1064        ArrayList<vmfloat> polyphonicUnitFactorMemory;
1065      VMExecStatus_t status;      VMExecStatus_t status;
1066      StmtFlags_t flags;      StmtFlags_t flags;
1067      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
# Line 912  public: Line 1071  public:
1071      struct ExitRes {      struct ExitRes {
1072          Expression* value;          Expression* value;
1073          IntLiteral intLiteral;          IntLiteral intLiteral;
1074            RealLiteral realLiteral;
1075          StringLiteral stringLiteral;          StringLiteral stringLiteral;
1076    
1077          ExitRes() : intLiteral(0), stringLiteral("") { }          ExitRes() :
1078                intLiteral({ .value = 0 }), realLiteral({ .value = 0.0 }),
1079                stringLiteral("") { }
1080      } exitRes;      } exitRes;
1081    
1082      ExecContext();      ExecContext();
# Line 955  public: Line 1117  public:
1117              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));
1118          if (!polyphonicRealMemory.empty())          if (!polyphonicRealMemory.empty())
1119              memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));              memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));
1120            if (!polyphonicUnitFactorMemory.empty()) {
1121                const vmint sz = polyphonicUnitFactorMemory.size();
1122                for (vmint i = 0; i < sz; ++i)
1123                    polyphonicUnitFactorMemory[i] = VM_NO_FACTOR;
1124            }
1125      }      }
1126    
1127      size_t instructionsPerformed() const OVERRIDE {      size_t instructionsPerformed() const OVERRIDE {

Legend:
Removed from v.3574  
changed lines
  Added in v.3804

  ViewVC Help
Powered by ViewVC