--- linuxsampler/trunk/src/scriptvm/tree.h 2017/05/31 21:07:44 3260 +++ linuxsampler/trunk/src/scriptvm/tree.h 2019/08/01 10:22:56 3551 @@ -1,6 +1,6 @@ /* -*- c++ -*- * - * Copyright (c) 2014 - 2017 Christian Schoenebeck and Andreas Persson + * Copyright (c) 2014 - 2019 Christian Schoenebeck and Andreas Persson * * http://www.linuxsampler.org * @@ -37,6 +37,7 @@ STMT_BRANCH, STMT_LOOP, STMT_SYNC, + STMT_NOOP, }; class Node { @@ -65,12 +66,12 @@ }; typedef Ref IntExprRef; -/*class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { +class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { public: ExprType_t exprType() const { return INT_ARR_EXPR; } String evalCastToStr(); }; -typedef Ref IntArrayExprRef;*/ +typedef Ref IntArrayExprRef; class StringExpr : virtual public VMStringExpr, virtual public Expression { public: @@ -81,8 +82,8 @@ typedef Ref StringExprRef; class IntLiteral : virtual public IntExpr { - int value; public: + int value; IntLiteral(int value) : value(value) { } int evalInt(); void dump(int level = 0); @@ -173,7 +174,7 @@ }; typedef Ref PolyphonicIntVariableRef; -class IntArrayVariable : public Variable, virtual public VMIntArrayExpr { +class IntArrayVariable : public Variable, virtual public IntArrayExpr { ArrayList values; public: IntArrayVariable(ParserContext* ctx, int size); @@ -196,19 +197,19 @@ VMInt8Array* array; public: BuiltInIntArrayVariable(const String& name, VMInt8Array* array); - int arraySize() const { return array->size; } - int evalIntElement(uint i); + int arraySize() const OVERRIDE { return array->size; } + int evalIntElement(uint i) OVERRIDE; bool isAssignable() const OVERRIDE { return !array->readonly; } - void assignIntElement(uint i, int value); - void dump(int level = 0); + void assignIntElement(uint i, int value) OVERRIDE; + void dump(int level = 0) OVERRIDE; }; typedef Ref BuiltInIntArrayVariableRef; class IntArrayElement : public IntVariable { - IntArrayVariableRef array; + IntArrayExprRef array; IntExprRef index; public: - IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex); + IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex); void assign(Expression* expr); int evalInt(); void dump(int level = 0); @@ -300,7 +301,7 @@ class NoOperation : public Statement { public: NoOperation() : Statement() {} - StmtType_t statementType() const { return STMT_LEAF; } + StmtType_t statementType() const { return STMT_NOOP; } void dump(int level = 0) {} bool isPolyphonic() const { return false; } }; @@ -333,7 +334,7 @@ virtual Statements* branch(uint i) const = 0; }; -class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr { +class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr { VMDynVar* dynVar; String varName; public: @@ -347,6 +348,9 @@ int evalInt() OVERRIDE; String evalStr() OVERRIDE; String evalCastToStr() OVERRIDE; + int arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); } + int evalIntElement(uint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); } + void assignIntElement(uint i, int value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); } void dump(int level = 0) OVERRIDE; }; typedef Ref DynamicVariableCallRef; @@ -372,6 +376,13 @@ }; typedef Ref FunctionCallRef; +class NoFunctionCall : public FunctionCall { +public: + NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {} + StmtType_t statementType() const { return STMT_NOOP; } +}; +typedef Ref NoFunctionCallRef; + class EventHandler : virtual public Statements, virtual public VMEventHandler { StatementsRef statements; bool usingPolyphonics; @@ -620,6 +631,7 @@ std::vector vErrors; std::vector vWarnings; std::vector vIssues; + std::vector vPreprocessorComments; std::set builtinPreprocessorConditions; std::set userPreprocessorConditions; @@ -660,6 +672,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); @@ -668,6 +681,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); @@ -690,15 +704,20 @@ ArrayList polyphonicIntMemory; VMExecStatus_t status; + StmtFlags_t flags; ArrayList stack; int stackFrame; int suspendMicroseconds; size_t instructionsCount; + struct ExitRes { + Expression* value; + IntLiteral intLiteral; + StringLiteral stringLiteral; - ExecContext() : - status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0), - instructionsCount(0) {} + ExitRes() : intLiteral(0), stringLiteral("") { } + } exitRes; + ExecContext(); virtual ~ExecContext() {} inline void pushStack(Statement* stmt) { @@ -720,6 +739,11 @@ stack[0].statement = NULL; stack[0].subindex = -1; stackFrame = -1; + flags = STMT_SUCCESS; + } + + inline void clearExitRes() { + exitRes.value = NULL; } int suspensionTimeMicroseconds() const OVERRIDE { @@ -734,6 +758,16 @@ size_t instructionsPerformed() const OVERRIDE { return instructionsCount; } + + void signalAbort() OVERRIDE { + flags = StmtFlags_t(flags | STMT_ABORT_SIGNALLED); + } + + void forkTo(VMExecContext* ectx) const OVERRIDE; + + VMExpr* exitResult() OVERRIDE { + return exitRes.value; + } }; } // namespace LinuxSampler