--- linuxsampler/trunk/src/scriptvm/tree.h 2016/12/16 12:57:59 3056 +++ linuxsampler/trunk/src/scriptvm/tree.h 2017/06/22 10:45:38 3285 @@ -1,6 +1,6 @@ /* -*- c++ -*- * - * Copyright (c) 2014 - 2016 Christian Schoenebeck and Andreas Persson + * Copyright (c) 2014 - 2017 Christian Schoenebeck and Andreas Persson * * http://www.linuxsampler.org * @@ -20,6 +20,7 @@ #include #include #include +#include // for memset() #include "../common/global.h" #include "../common/Ref.h" #include "../common/ArrayList.h" @@ -35,6 +36,7 @@ STMT_LIST, STMT_BRANCH, STMT_LOOP, + STMT_SYNC, }; class Node { @@ -175,7 +177,7 @@ ArrayList values; public: IntArrayVariable(ParserContext* ctx, int size); - IntArrayVariable(ParserContext* ctx, int size, ArgsRef values); + IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst = false); void assign(Expression* expr) {} // ignore scalar assignment String evalCastToStr() { return ""; } // ignore scalar cast to string ExprType_t exprType() const { return INT_ARR_EXPR; } @@ -196,6 +198,7 @@ BuiltInIntArrayVariable(const String& name, VMInt8Array* array); int arraySize() const { return array->size; } int evalIntElement(uint i); + bool isAssignable() const OVERRIDE { return !array->readonly; } void assignIntElement(uint i, int value); void dump(int level = 0); }; @@ -340,6 +343,7 @@ bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); } bool isPolyphonic() const OVERRIDE { return false; } void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); } + VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); } int evalInt() OVERRIDE; String evalStr() OVERRIDE; String evalCastToStr() OVERRIDE; @@ -354,15 +358,15 @@ public: FunctionCall(const char* function, ArgsRef args, VMFunction* fn) : functionName(function), args(args), fn(fn) { } - void dump(int level = 0); - StmtFlags_t exec(); - int evalInt(); + void dump(int level = 0) OVERRIDE; + StmtFlags_t exec() OVERRIDE; + int evalInt() OVERRIDE; VMIntArrayExpr* asIntArray() const OVERRIDE; - String evalStr(); - bool isConstExpr() const { return false; } - ExprType_t exprType() const; - String evalCastToStr(); - bool isPolyphonic() const { return args->isPolyphonic(); } + String evalStr() OVERRIDE; + bool isConstExpr() const OVERRIDE { return false; } + ExprType_t exprType() const OVERRIDE; + String evalCastToStr() OVERRIDE; + bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } protected: VMFnResult* execVMFn(); }; @@ -492,6 +496,17 @@ bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); } }; +class SyncBlock : public Statement { + StatementsRef m_statements; +public: + SyncBlock(StatementsRef statements) : m_statements(statements) {} + StmtType_t statementType() const { return STMT_SYNC; } + void dump(int level = 0); + Statements* statements() const; + bool isPolyphonic() const { return m_statements->isPolyphonic(); } +}; +typedef Ref SyncBlockRef; + class Neg : public IntExpr { IntExprRef expr; public: @@ -605,6 +620,7 @@ std::vector vErrors; std::vector vWarnings; std::vector vIssues; + std::vector vPreprocessorComments; std::set builtinPreprocessorConditions; std::set userPreprocessorConditions; @@ -645,6 +661,7 @@ StatementsRef userFunctionByName(const String& name); void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt); void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt); + void addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn); void createScanner(std::istream* is); void destroyScanner(); bool setPreprocessorCondition(const char* name); @@ -653,6 +670,7 @@ std::vector issues() const OVERRIDE; std::vector errors() const OVERRIDE; std::vector warnings() const OVERRIDE; + std::vector preprocessorComments() const OVERRIDE; VMEventHandler* eventHandler(uint index) OVERRIDE; VMEventHandler* eventHandlerByName(const String& name) OVERRIDE; void registerBuiltInConstIntVariables(const std::map& vars); @@ -675,12 +693,15 @@ ArrayList polyphonicIntMemory; VMExecStatus_t status; + StmtFlags_t flags; ArrayList stack; int stackFrame; int suspendMicroseconds; + size_t instructionsCount; ExecContext() : - status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {} + status(VM_EXEC_NOT_RUNNING), flags(STMT_SUCCESS), stackFrame(-1), + suspendMicroseconds(0), instructionsCount(0) {} virtual ~ExecContext() {} @@ -703,11 +724,25 @@ stack[0].statement = NULL; stack[0].subindex = -1; stackFrame = -1; + flags = STMT_SUCCESS; } int suspensionTimeMicroseconds() const OVERRIDE { return suspendMicroseconds; } + + void resetPolyphonicData() OVERRIDE { + if (polyphonicIntMemory.empty()) return; + memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int)); + } + + size_t instructionsPerformed() const OVERRIDE { + return instructionsCount; + } + + void signalAbort() OVERRIDE { + flags = StmtFlags_t(flags | STMT_ABORT_SIGNALLED); + } }; } // namespace LinuxSampler