/[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 2879 by schoenebeck, Tue Apr 19 14:07:53 2016 UTC revision 3257 by schoenebeck, Tue May 30 17:20:02 2017 UTC
# Line 1  Line 1 
1  /*                                                              -*- c++ -*-  /*                                                              -*- c++ -*-
2   *   *
3   * Copyright (c) 2014 - 2016 Christian Schoenebeck and Andreas Persson   * Copyright (c) 2014 - 2017 Christian Schoenebeck and Andreas Persson
4   *   *
5   * http://www.linuxsampler.org   * http://www.linuxsampler.org
6   *   *
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <map>  #include <map>
22  #include <set>  #include <set>
23    #include <string.h> // for memset()
24  #include "../common/global.h"  #include "../common/global.h"
25  #include "../common/Ref.h"  #include "../common/Ref.h"
26  #include "../common/ArrayList.h"  #include "../common/ArrayList.h"
# Line 63  public: Line 64  public:
64  };  };
65  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
66    
67    /*class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression {
68    public:
69        ExprType_t exprType() const { return INT_ARR_EXPR; }
70        String evalCastToStr();
71    };
72    typedef Ref<IntArrayExpr,Node> IntArrayExprRef;*/
73    
74  class StringExpr : virtual public VMStringExpr, virtual public Expression {  class StringExpr : virtual public VMStringExpr, virtual public Expression {
75  public:  public:
76      ExprType_t exprType() const { return STRING_EXPR; }      ExprType_t exprType() const { return STRING_EXPR; }
# Line 98  public: Line 106  public:
106      std::vector<ExpressionRef> args;      std::vector<ExpressionRef> args;
107      void add(ExpressionRef arg) { args.push_back(arg); }      void add(ExpressionRef arg) { args.push_back(arg); }
108      void dump(int level = 0);      void dump(int level = 0);
109      int argsCount() const { return args.size(); }      int argsCount() const { return (int) args.size(); }
110      VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; }      VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; }
111      bool isPolyphonic() const;      bool isPolyphonic() const;
112  };  };
113  typedef Ref<Args,Node> ArgsRef;  typedef Ref<Args,Node> ArgsRef;
114    
115  class Variable : virtual public Expression {  class Variable : virtual public VMVariable, virtual public Expression {
116  public:  public:
117      virtual bool isConstExpr() const { return bConst; }      bool isConstExpr() const OVERRIDE { return bConst; }
118        bool isAssignable() const OVERRIDE { return !bConst; }
119      virtual void assign(Expression* expr) = 0;      virtual void assign(Expression* expr) = 0;
120        void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }
121  protected:  protected:
122      Variable(ParserContext* ctx, int _memPos, bool _bConst)      Variable(ParserContext* ctx, int _memPos, bool _bConst)
123          : context(ctx), memPos(_memPos), bConst(_bConst) {}          : context(ctx), memPos(_memPos), bConst(_bConst) {}
# Line 148  class BuiltInIntVariable : public IntVar Line 158  class BuiltInIntVariable : public IntVar
158      VMIntRelPtr* ptr;      VMIntRelPtr* ptr;
159  public:  public:
160      BuiltInIntVariable(const String& name, VMIntRelPtr* ptr);      BuiltInIntVariable(const String& name, VMIntRelPtr* ptr);
161      void assign(Expression* expr);      bool isAssignable() const OVERRIDE { return !ptr->readonly; }
162      int evalInt();      void assign(Expression* expr) OVERRIDE;
163      void dump(int level = 0);      int evalInt() OVERRIDE;
164        void dump(int level = 0) OVERRIDE;
165  };  };
166  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
167    
# Line 165  class IntArrayVariable : public Variable Line 176  class IntArrayVariable : public Variable
176      ArrayList<int> values;      ArrayList<int> values;
177  public:  public:
178      IntArrayVariable(ParserContext* ctx, int size);      IntArrayVariable(ParserContext* ctx, int size);
179      IntArrayVariable(ParserContext* ctx, int size, ArgsRef values);      IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst = false);
180      void assign(Expression* expr) {} // ignore scalar assignment      void assign(Expression* expr) {} // ignore scalar assignment
181      String evalCastToStr() { return ""; } // ignore scalar cast to string      String evalCastToStr() { return ""; } // ignore scalar cast to string
182      ExprType_t exprType() const { return INT_ARR_EXPR; }      ExprType_t exprType() const { return INT_ARR_EXPR; }
# Line 186  public: Line 197  public:
197      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
198      int arraySize() const { return array->size; }      int arraySize() const { return array->size; }
199      int evalIntElement(uint i);      int evalIntElement(uint i);
200        bool isAssignable() const OVERRIDE { return !array->readonly; }
201      void assignIntElement(uint i, int value);      void assignIntElement(uint i, int value);
202      void dump(int level = 0);      void dump(int level = 0);
203  };  };
# Line 320  public: Line 332  public:
332      virtual Statements* branch(uint i) const = 0;      virtual Statements* branch(uint i) const = 0;
333  };  };
334    
335    class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr {
336        VMDynVar* dynVar;
337        String varName;
338    public:
339        DynamicVariableCall(const String& name, ParserContext* ctx, VMDynVar* v);
340        ExprType_t exprType() const OVERRIDE { return dynVar->exprType(); }
341        bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); }
342        bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); }
343        bool isPolyphonic() const OVERRIDE { return false; }
344        void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); }
345        VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); }
346        int evalInt() OVERRIDE;
347        String evalStr() OVERRIDE;
348        String evalCastToStr() OVERRIDE;
349        void dump(int level = 0) OVERRIDE;
350    };
351    typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
352    
353  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {
354      String functionName;      String functionName;
355      ArgsRef args;      ArgsRef args;
# Line 327  class FunctionCall : virtual public Leaf Line 357  class FunctionCall : virtual public Leaf
357  public:  public:
358      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :
359          functionName(function), args(args), fn(fn) { }          functionName(function), args(args), fn(fn) { }
360      void dump(int level = 0);      void dump(int level = 0) OVERRIDE;
361      StmtFlags_t exec();      StmtFlags_t exec() OVERRIDE;
362      int evalInt();      int evalInt() OVERRIDE;
363      String evalStr();      VMIntArrayExpr* asIntArray() const OVERRIDE;
364      bool isConstExpr() const { return false; }      String evalStr() OVERRIDE;
365      ExprType_t exprType() const;      bool isConstExpr() const OVERRIDE { return false; }
366      String evalCastToStr();      ExprType_t exprType() const OVERRIDE;
367      bool isPolyphonic() const { return args->isPolyphonic(); }      String evalCastToStr() OVERRIDE;
368        bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
369  protected:  protected:
370      VMFnResult* execVMFn();      VMFnResult* execVMFn();
371  };  };
# Line 394  public: Line 425  public:
425      int evalInt() { return 0; }      int evalInt() { return 0; }
426      EventHandler* eventHandlerByName(const String& name) const;      EventHandler* eventHandlerByName(const String& name) const;
427      EventHandler* eventHandler(uint index) const;      EventHandler* eventHandler(uint index) const;
428      inline uint size() const { return args.size(); }      inline uint size() const { return (int) args.size(); }
429      bool isPolyphonic() const;      bool isPolyphonic() const;
430  };  };
431  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
# Line 518  public: Line 549  public:
549  };  };
550  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
551    
552    class BitwiseOr : virtual public BinaryOp, virtual public IntExpr {
553    public:
554        BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
555        int evalInt();
556        void dump(int level = 0);
557    };
558    typedef Ref<BitwiseOr,Node> BitwiseOrRef;
559    
560  class And : virtual public BinaryOp, virtual public IntExpr {  class And : virtual public BinaryOp, virtual public IntExpr {
561  public:  public:
562      And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
# Line 526  public: Line 565  public:
565  };  };
566  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
567    
568    class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr {
569    public:
570        BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
571        int evalInt();
572        void dump(int level = 0);
573    };
574    typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
575    
576  class Not : virtual public IntExpr {  class Not : virtual public IntExpr {
577      IntExprRef expr;      IntExprRef expr;
578  public:  public:
# Line 537  public: Line 584  public:
584  };  };
585  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
586    
587    class BitwiseNot : virtual public IntExpr {
588        IntExprRef expr;
589    public:
590        BitwiseNot(IntExprRef expr) : expr(expr) {}
591        int evalInt() { return ~expr->evalInt(); }
592        void dump(int level = 0);
593        bool isConstExpr() const { return expr->isConstExpr(); }
594        bool isPolyphonic() const { return expr->isPolyphonic(); }
595    };
596    typedef Ref<BitwiseNot,Node> BitwiseNotRef;
597    
598  class ParserContext : public VMParserContext {  class ParserContext : public VMParserContext {
599  public:  public:
600      struct Error {      struct Error {
# Line 555  public: Line 613  public:
613      std::set<String> userPreprocessorConditions;      std::set<String> userPreprocessorConditions;
614    
615      std::map<String,VariableRef> vartable;      std::map<String,VariableRef> vartable;
616        std::map<String,StatementsRef> userFnTable;
617      int globalIntVarCount;      int globalIntVarCount;
618      int globalStrVarCount;      int globalStrVarCount;
619      int polyphonicIntVarCount;      int polyphonicIntVarCount;
# Line 586  public: Line 645  public:
645      IntVariableRef globalIntVar(const String& name);      IntVariableRef globalIntVar(const String& name);
646      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
647      VariableRef variableByName(const String& name);      VariableRef variableByName(const String& name);
648      void addErr(int line, const char* txt);      StatementsRef userFunctionByName(const String& name);
649      void addWrn(int line, const char* txt);      void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
650        void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
651      void createScanner(std::istream* is);      void createScanner(std::istream* is);
652      void destroyScanner();      void destroyScanner();
653      bool setPreprocessorCondition(const char* name);      bool setPreprocessorCondition(const char* name);
# Line 601  public: Line 661  public:
661      void registerBuiltInConstIntVariables(const std::map<String,int>& vars);      void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
662      void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);      void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);
663      void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);      void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
664        void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
665  };  };
666    
667  class ExecContext : public VMExecContext {  class ExecContext : public VMExecContext {
# Line 620  public: Line 681  public:
681      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
682      int stackFrame;      int stackFrame;
683      int suspendMicroseconds;      int suspendMicroseconds;
684        size_t instructionsCount;
685    
686      ExecContext() :      ExecContext() :
687          status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {}          status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0),
688            instructionsCount(0) {}
689    
690      virtual ~ExecContext() {}      virtual ~ExecContext() {}
691    
# Line 650  public: Line 713  public:
713      int suspensionTimeMicroseconds() const OVERRIDE {      int suspensionTimeMicroseconds() const OVERRIDE {
714          return suspendMicroseconds;          return suspendMicroseconds;
715      }      }
716    
717        void resetPolyphonicData() OVERRIDE {
718            if (polyphonicIntMemory.empty()) return;
719            memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int));
720        }
721    
722        size_t instructionsPerformed() const OVERRIDE {
723            return instructionsCount;
724        }
725  };  };
726    
727  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2879  
changed lines
  Added in v.3257

  ViewVC Help
Powered by ViewVC