--- linuxsampler/trunk/src/scriptvm/tree.h 2016/04/19 14:07:53 2879 +++ linuxsampler/trunk/src/scriptvm/tree.h 2017/05/25 10:53:45 3207 @@ -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 * @@ -63,6 +63,13 @@ }; typedef Ref IntExprRef; +/*class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { +public: + ExprType_t exprType() const { return INT_ARR_EXPR; } + String evalCastToStr(); +}; +typedef Ref IntArrayExprRef;*/ + class StringExpr : virtual public VMStringExpr, virtual public Expression { public: ExprType_t exprType() const { return STRING_EXPR; } @@ -98,16 +105,18 @@ std::vector args; void add(ExpressionRef arg) { args.push_back(arg); } void dump(int level = 0); - int argsCount() const { return args.size(); } + int argsCount() const { return (int) args.size(); } VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; } bool isPolyphonic() const; }; typedef Ref ArgsRef; -class Variable : virtual public Expression { +class Variable : virtual public VMVariable, virtual public Expression { public: - virtual bool isConstExpr() const { return bConst; } + bool isConstExpr() const OVERRIDE { return bConst; } + bool isAssignable() const OVERRIDE { return !bConst; } virtual void assign(Expression* expr) = 0; + void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast(expr); if (e) assign(e); } protected: Variable(ParserContext* ctx, int _memPos, bool _bConst) : context(ctx), memPos(_memPos), bConst(_bConst) {} @@ -148,9 +157,10 @@ VMIntRelPtr* ptr; public: BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); - void assign(Expression* expr); - int evalInt(); - void dump(int level = 0); + bool isAssignable() const OVERRIDE { return !ptr->readonly; } + void assign(Expression* expr) OVERRIDE; + int evalInt() OVERRIDE; + void dump(int level = 0) OVERRIDE; }; typedef Ref BuiltInIntVariableRef; @@ -320,6 +330,24 @@ virtual Statements* branch(uint i) const = 0; }; +class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr { + VMDynVar* dynVar; + String varName; +public: + DynamicVariableCall(const String& name, ParserContext* ctx, VMDynVar* v); + ExprType_t exprType() const OVERRIDE { return dynVar->exprType(); } + bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); } + 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; + void dump(int level = 0) OVERRIDE; +}; +typedef Ref DynamicVariableCallRef; + class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr { String functionName; ArgsRef args; @@ -327,14 +355,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(); - String evalStr(); - bool isConstExpr() const { return false; } - ExprType_t exprType() const; - String evalCastToStr(); - bool isPolyphonic() const { return args->isPolyphonic(); } + void dump(int level = 0) OVERRIDE; + StmtFlags_t exec() OVERRIDE; + int evalInt() OVERRIDE; + VMIntArrayExpr* asIntArray() const OVERRIDE; + 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(); }; @@ -394,7 +423,7 @@ int evalInt() { return 0; } EventHandler* eventHandlerByName(const String& name) const; EventHandler* eventHandler(uint index) const; - inline uint size() const { return args.size(); } + inline uint size() const { return (int) args.size(); } bool isPolyphonic() const; }; typedef Ref EventHandlersRef; @@ -518,6 +547,14 @@ }; typedef Ref OrRef; +class BitwiseOr : virtual public BinaryOp, virtual public IntExpr { +public: + BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} + int evalInt(); + void dump(int level = 0); +}; +typedef Ref BitwiseOrRef; + class And : virtual public BinaryOp, virtual public IntExpr { public: And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} @@ -526,6 +563,14 @@ }; typedef Ref AndRef; +class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr { +public: + BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} + int evalInt(); + void dump(int level = 0); +}; +typedef Ref BitwiseAndRef; + class Not : virtual public IntExpr { IntExprRef expr; public: @@ -537,6 +582,17 @@ }; typedef Ref NotRef; +class BitwiseNot : virtual public IntExpr { + IntExprRef expr; +public: + BitwiseNot(IntExprRef expr) : expr(expr) {} + int evalInt() { return ~expr->evalInt(); } + void dump(int level = 0); + bool isConstExpr() const { return expr->isConstExpr(); } + bool isPolyphonic() const { return expr->isPolyphonic(); } +}; +typedef Ref BitwiseNotRef; + class ParserContext : public VMParserContext { public: struct Error { @@ -555,6 +611,7 @@ std::set userPreprocessorConditions; std::map vartable; + std::map userFnTable; int globalIntVarCount; int globalStrVarCount; int polyphonicIntVarCount; @@ -586,8 +643,9 @@ IntVariableRef globalIntVar(const String& name); StringVariableRef globalStrVar(const String& name); VariableRef variableByName(const String& name); - void addErr(int line, const char* txt); - void addWrn(int line, const char* txt); + 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 createScanner(std::istream* is); void destroyScanner(); bool setPreprocessorCondition(const char* name); @@ -601,6 +659,7 @@ void registerBuiltInConstIntVariables(const std::map& vars); void registerBuiltInIntVariables(const std::map& vars); void registerBuiltInIntArrayVariables(const std::map& vars); + void registerBuiltInDynVariables(const std::map& vars); }; class ExecContext : public VMExecContext { @@ -650,6 +709,11 @@ int suspensionTimeMicroseconds() const OVERRIDE { return suspendMicroseconds; } + + void resetPolyphonicData() OVERRIDE { + if (polyphonicIntMemory.empty()) return; + memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int)); + } }; } // namespace LinuxSampler