/[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 3054 by schoenebeck, Thu Dec 15 12:47:45 2016 UTC revision 3293 by schoenebeck, Tue Jun 27 22:19:19 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 35  enum StmtType_t { Line 36  enum StmtType_t {
36      STMT_LIST,      STMT_LIST,
37      STMT_BRANCH,      STMT_BRANCH,
38      STMT_LOOP,      STMT_LOOP,
39        STMT_SYNC,
40  };  };
41    
42  class Node {  class Node {
# Line 63  public: Line 65  public:
65  };  };
66  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
67    
68    class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression {
69    public:
70        ExprType_t exprType() const { return INT_ARR_EXPR; }
71        String evalCastToStr();
72    };
73    typedef Ref<IntArrayExpr,Node> IntArrayExprRef;
74    
75  class StringExpr : virtual public VMStringExpr, virtual public Expression {  class StringExpr : virtual public VMStringExpr, virtual public Expression {
76  public:  public:
77      ExprType_t exprType() const { return STRING_EXPR; }      ExprType_t exprType() const { return STRING_EXPR; }
# Line 164  public: Line 173  public:
173  };  };
174  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
175    
176  class IntArrayVariable : public Variable, virtual public VMIntArrayExpr {  class IntArrayVariable : public Variable, virtual public IntArrayExpr {
177      ArrayList<int> values;      ArrayList<int> values;
178  public:  public:
179      IntArrayVariable(ParserContext* ctx, int size);      IntArrayVariable(ParserContext* ctx, int size);
180      IntArrayVariable(ParserContext* ctx, int size, ArgsRef values);      IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst = false);
181      void assign(Expression* expr) {} // ignore scalar assignment      void assign(Expression* expr) {} // ignore scalar assignment
182      String evalCastToStr() { return ""; } // ignore scalar cast to string      String evalCastToStr() { return ""; } // ignore scalar cast to string
183      ExprType_t exprType() const { return INT_ARR_EXPR; }      ExprType_t exprType() const { return INT_ARR_EXPR; }
# Line 189  public: Line 198  public:
198      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
199      int arraySize() const { return array->size; }      int arraySize() const { return array->size; }
200      int evalIntElement(uint i);      int evalIntElement(uint i);
201        bool isAssignable() const OVERRIDE { return !array->readonly; }
202      void assignIntElement(uint i, int value);      void assignIntElement(uint i, int value);
203      void dump(int level = 0);      void dump(int level = 0);
204  };  };
205  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
206    
207  class IntArrayElement : public IntVariable {  class IntArrayElement : public IntVariable {
208      IntArrayVariableRef array;      IntArrayExprRef array;
209      IntExprRef index;      IntExprRef index;
210  public:  public:
211      IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex);      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);
212      void assign(Expression* expr);      void assign(Expression* expr);
213      int evalInt();      int evalInt();
214      void dump(int level = 0);      void dump(int level = 0);
# Line 323  public: Line 333  public:
333      virtual Statements* branch(uint i) const = 0;      virtual Statements* branch(uint i) const = 0;
334  };  };
335    
336  class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr {  class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr {
337      VMDynVar* dynVar;      VMDynVar* dynVar;
338      String varName;      String varName;
339  public:  public:
# Line 333  public: Line 343  public:
343      bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); }      bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); }
344      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
345      void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); }      void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); }
346        VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); }
347      int evalInt() OVERRIDE;      int evalInt() OVERRIDE;
348      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
349      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
350        int arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }
351        int evalIntElement(uint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
352        void assignIntElement(uint i, int value) { return dynVar->asIntArray()->assignIntElement(i, value); }
353      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
354  };  };
355  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
# Line 347  class FunctionCall : virtual public Leaf Line 361  class FunctionCall : virtual public Leaf
361  public:  public:
362      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :
363          functionName(function), args(args), fn(fn) { }          functionName(function), args(args), fn(fn) { }
364      void dump(int level = 0);      void dump(int level = 0) OVERRIDE;
365      StmtFlags_t exec();      StmtFlags_t exec() OVERRIDE;
366      int evalInt();      int evalInt() OVERRIDE;
367      String evalStr();      VMIntArrayExpr* asIntArray() const OVERRIDE;
368      bool isConstExpr() const { return false; }      String evalStr() OVERRIDE;
369      ExprType_t exprType() const;      bool isConstExpr() const OVERRIDE { return false; }
370      String evalCastToStr();      ExprType_t exprType() const OVERRIDE;
371      bool isPolyphonic() const { return args->isPolyphonic(); }      String evalCastToStr() OVERRIDE;
372        bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
373  protected:  protected:
374      VMFnResult* execVMFn();      VMFnResult* execVMFn();
375  };  };
# Line 484  public: Line 499  public:
499      bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }      bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
500  };  };
501    
502    class SyncBlock : public Statement {
503        StatementsRef m_statements;
504    public:
505        SyncBlock(StatementsRef statements) : m_statements(statements) {}
506        StmtType_t statementType() const { return STMT_SYNC; }
507        void dump(int level = 0);
508        Statements* statements() const;
509        bool isPolyphonic() const { return m_statements->isPolyphonic(); }
510    };
511    typedef Ref<SyncBlock,Node> SyncBlockRef;
512    
513  class Neg : public IntExpr {  class Neg : public IntExpr {
514      IntExprRef expr;      IntExprRef expr;
515  public:  public:
# Line 597  public: Line 623  public:
623      std::vector<ParserIssue> vErrors;      std::vector<ParserIssue> vErrors;
624      std::vector<ParserIssue> vWarnings;      std::vector<ParserIssue> vWarnings;
625      std::vector<ParserIssue> vIssues;      std::vector<ParserIssue> vIssues;
626        std::vector<CodeBlock>   vPreprocessorComments;
627    
628      std::set<String> builtinPreprocessorConditions;      std::set<String> builtinPreprocessorConditions;
629      std::set<String> userPreprocessorConditions;      std::set<String> userPreprocessorConditions;
# Line 637  public: Line 664  public:
664      StatementsRef userFunctionByName(const String& name);      StatementsRef userFunctionByName(const String& name);
665      void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);      void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
666      void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);      void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
667        void addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn);
668      void createScanner(std::istream* is);      void createScanner(std::istream* is);
669      void destroyScanner();      void destroyScanner();
670      bool setPreprocessorCondition(const char* name);      bool setPreprocessorCondition(const char* name);
# Line 645  public: Line 673  public:
673      std::vector<ParserIssue> issues() const OVERRIDE;      std::vector<ParserIssue> issues() const OVERRIDE;
674      std::vector<ParserIssue> errors() const OVERRIDE;      std::vector<ParserIssue> errors() const OVERRIDE;
675      std::vector<ParserIssue> warnings() const OVERRIDE;      std::vector<ParserIssue> warnings() const OVERRIDE;
676        std::vector<CodeBlock> preprocessorComments() const OVERRIDE;
677      VMEventHandler* eventHandler(uint index) OVERRIDE;      VMEventHandler* eventHandler(uint index) OVERRIDE;
678      VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;      VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
679      void registerBuiltInConstIntVariables(const std::map<String,int>& vars);      void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
# Line 667  public: Line 696  public:
696    
697      ArrayList<int> polyphonicIntMemory;      ArrayList<int> polyphonicIntMemory;
698      VMExecStatus_t status;      VMExecStatus_t status;
699        StmtFlags_t flags;
700      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
701      int stackFrame;      int stackFrame;
702      int suspendMicroseconds;      int suspendMicroseconds;
703        size_t instructionsCount;
704    
705      ExecContext() :      ExecContext() :
706          status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {}          status(VM_EXEC_NOT_RUNNING), flags(STMT_SUCCESS), stackFrame(-1),
707            suspendMicroseconds(0), instructionsCount(0) {}
708    
709      virtual ~ExecContext() {}      virtual ~ExecContext() {}
710    
# Line 695  public: Line 727  public:
727          stack[0].statement = NULL;          stack[0].statement = NULL;
728          stack[0].subindex  = -1;          stack[0].subindex  = -1;
729          stackFrame = -1;          stackFrame = -1;
730            flags = STMT_SUCCESS;
731      }      }
732    
733      int suspensionTimeMicroseconds() const OVERRIDE {      int suspensionTimeMicroseconds() const OVERRIDE {
734          return suspendMicroseconds;          return suspendMicroseconds;
735      }      }
736    
737        void resetPolyphonicData() OVERRIDE {
738            if (polyphonicIntMemory.empty()) return;
739            memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int));
740        }
741    
742        size_t instructionsPerformed() const OVERRIDE {
743            return instructionsCount;
744        }
745    
746        void signalAbort() OVERRIDE {
747            flags = StmtFlags_t(flags | STMT_ABORT_SIGNALLED);
748        }
749    
750        void forkTo(VMExecContext* ectx) const OVERRIDE;
751  };  };
752    
753  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.3054  
changed lines
  Added in v.3293

  ViewVC Help
Powered by ViewVC