/[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 3056 by schoenebeck, Fri Dec 16 12:57:59 2016 UTC revision 3285 by schoenebeck, Thu Jun 22 10:45:38 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 175  class IntArrayVariable : public Variable Line 177  class IntArrayVariable : public Variable
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 196  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  };  };
# Line 340  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;
# Line 354  class FunctionCall : virtual public Leaf Line 358  class FunctionCall : virtual public Leaf
358  public:  public:
359      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :
360          functionName(function), args(args), fn(fn) { }          functionName(function), args(args), fn(fn) { }
361      void dump(int level = 0);      void dump(int level = 0) OVERRIDE;
362      StmtFlags_t exec();      StmtFlags_t exec() OVERRIDE;
363      int evalInt();      int evalInt() OVERRIDE;
364      VMIntArrayExpr* asIntArray() const OVERRIDE;      VMIntArrayExpr* asIntArray() const OVERRIDE;
365      String evalStr();      String evalStr() OVERRIDE;
366      bool isConstExpr() const { return false; }      bool isConstExpr() const OVERRIDE { return false; }
367      ExprType_t exprType() const;      ExprType_t exprType() const OVERRIDE;
368      String evalCastToStr();      String evalCastToStr() OVERRIDE;
369      bool isPolyphonic() const { return args->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
370  protected:  protected:
371      VMFnResult* execVMFn();      VMFnResult* execVMFn();
372  };  };
# Line 492  public: Line 496  public:
496      bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }      bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
497  };  };
498    
499    class SyncBlock : public Statement {
500        StatementsRef m_statements;
501    public:
502        SyncBlock(StatementsRef statements) : m_statements(statements) {}
503        StmtType_t statementType() const { return STMT_SYNC; }
504        void dump(int level = 0);
505        Statements* statements() const;
506        bool isPolyphonic() const { return m_statements->isPolyphonic(); }
507    };
508    typedef Ref<SyncBlock,Node> SyncBlockRef;
509    
510  class Neg : public IntExpr {  class Neg : public IntExpr {
511      IntExprRef expr;      IntExprRef expr;
512  public:  public:
# Line 605  public: Line 620  public:
620      std::vector<ParserIssue> vErrors;      std::vector<ParserIssue> vErrors;
621      std::vector<ParserIssue> vWarnings;      std::vector<ParserIssue> vWarnings;
622      std::vector<ParserIssue> vIssues;      std::vector<ParserIssue> vIssues;
623        std::vector<CodeBlock>   vPreprocessorComments;
624    
625      std::set<String> builtinPreprocessorConditions;      std::set<String> builtinPreprocessorConditions;
626      std::set<String> userPreprocessorConditions;      std::set<String> userPreprocessorConditions;
# Line 645  public: Line 661  public:
661      StatementsRef userFunctionByName(const String& name);      StatementsRef userFunctionByName(const String& name);
662      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);
663      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);
664        void addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn);
665      void createScanner(std::istream* is);      void createScanner(std::istream* is);
666      void destroyScanner();      void destroyScanner();
667      bool setPreprocessorCondition(const char* name);      bool setPreprocessorCondition(const char* name);
# Line 653  public: Line 670  public:
670      std::vector<ParserIssue> issues() const OVERRIDE;      std::vector<ParserIssue> issues() const OVERRIDE;
671      std::vector<ParserIssue> errors() const OVERRIDE;      std::vector<ParserIssue> errors() const OVERRIDE;
672      std::vector<ParserIssue> warnings() const OVERRIDE;      std::vector<ParserIssue> warnings() const OVERRIDE;
673        std::vector<CodeBlock> preprocessorComments() const OVERRIDE;
674      VMEventHandler* eventHandler(uint index) OVERRIDE;      VMEventHandler* eventHandler(uint index) OVERRIDE;
675      VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;      VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
676      void registerBuiltInConstIntVariables(const std::map<String,int>& vars);      void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
# Line 675  public: Line 693  public:
693    
694      ArrayList<int> polyphonicIntMemory;      ArrayList<int> polyphonicIntMemory;
695      VMExecStatus_t status;      VMExecStatus_t status;
696        StmtFlags_t flags;
697      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
698      int stackFrame;      int stackFrame;
699      int suspendMicroseconds;      int suspendMicroseconds;
700        size_t instructionsCount;
701    
702      ExecContext() :      ExecContext() :
703          status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {}          status(VM_EXEC_NOT_RUNNING), flags(STMT_SUCCESS), stackFrame(-1),
704            suspendMicroseconds(0), instructionsCount(0) {}
705    
706      virtual ~ExecContext() {}      virtual ~ExecContext() {}
707    
# Line 703  public: Line 724  public:
724          stack[0].statement = NULL;          stack[0].statement = NULL;
725          stack[0].subindex  = -1;          stack[0].subindex  = -1;
726          stackFrame = -1;          stackFrame = -1;
727            flags = STMT_SUCCESS;
728      }      }
729    
730      int suspensionTimeMicroseconds() const OVERRIDE {      int suspensionTimeMicroseconds() const OVERRIDE {
731          return suspendMicroseconds;          return suspendMicroseconds;
732      }      }
733    
734        void resetPolyphonicData() OVERRIDE {
735            if (polyphonicIntMemory.empty()) return;
736            memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int));
737        }
738    
739        size_t instructionsPerformed() const OVERRIDE {
740            return instructionsCount;
741        }
742    
743        void signalAbort() OVERRIDE {
744            flags = StmtFlags_t(flags | STMT_ABORT_SIGNALLED);
745        }
746  };  };
747    
748  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.3056  
changed lines
  Added in v.3285

  ViewVC Help
Powered by ViewVC