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 |
* |
* |
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" |
64 |
}; |
}; |
65 |
typedef Ref<IntExpr,Node> IntExprRef; |
typedef Ref<IntExpr,Node> IntExprRef; |
66 |
|
|
67 |
|
/*class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { |
68 |
|
public: |
69 |
|
ExprType_t exprType() const { return INT_ARR_EXPR; } |
70 |
|
String evalCastToStr(); |
71 |
|
}; |
72 |
|
typedef Ref<IntArrayExpr,Node> IntArrayExprRef;*/ |
73 |
|
|
74 |
class StringExpr : virtual public VMStringExpr, virtual public Expression { |
class StringExpr : virtual public VMStringExpr, virtual public Expression { |
75 |
public: |
public: |
76 |
ExprType_t exprType() const { return STRING_EXPR; } |
ExprType_t exprType() const { return STRING_EXPR; } |
106 |
std::vector<ExpressionRef> args; |
std::vector<ExpressionRef> args; |
107 |
void add(ExpressionRef arg) { args.push_back(arg); } |
void add(ExpressionRef arg) { args.push_back(arg); } |
108 |
void dump(int level = 0); |
void dump(int level = 0); |
109 |
int argsCount() const { return args.size(); } |
int argsCount() const { return (int) args.size(); } |
110 |
VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; } |
VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; } |
111 |
bool isPolyphonic() const; |
bool isPolyphonic() const; |
112 |
}; |
}; |
113 |
typedef Ref<Args,Node> ArgsRef; |
typedef Ref<Args,Node> ArgsRef; |
114 |
|
|
115 |
class Variable : virtual public Expression { |
class Variable : virtual public VMVariable, virtual public Expression { |
116 |
public: |
public: |
117 |
virtual bool isConstExpr() const { return bConst; } |
bool isConstExpr() const OVERRIDE { return bConst; } |
118 |
virtual bool isAssignable() const { return !bConst; } |
bool isAssignable() const OVERRIDE { return !bConst; } |
119 |
virtual void assign(Expression* expr) = 0; |
virtual void assign(Expression* expr) = 0; |
120 |
|
void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); } |
121 |
protected: |
protected: |
122 |
Variable(ParserContext* ctx, int _memPos, bool _bConst) |
Variable(ParserContext* ctx, int _memPos, bool _bConst) |
123 |
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
158 |
VMIntRelPtr* ptr; |
VMIntRelPtr* ptr; |
159 |
public: |
public: |
160 |
BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); |
BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); |
161 |
void assign(Expression* expr); |
bool isAssignable() const OVERRIDE { return !ptr->readonly; } |
162 |
int evalInt(); |
void assign(Expression* expr) OVERRIDE; |
163 |
void dump(int level = 0); |
int evalInt() OVERRIDE; |
164 |
|
void dump(int level = 0) OVERRIDE; |
165 |
}; |
}; |
166 |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
167 |
|
|
197 |
BuiltInIntArrayVariable(const String& name, VMInt8Array* array); |
BuiltInIntArrayVariable(const String& name, VMInt8Array* array); |
198 |
int arraySize() const { return array->size; } |
int arraySize() const { return array->size; } |
199 |
int evalIntElement(uint i); |
int evalIntElement(uint i); |
200 |
|
bool isAssignable() const OVERRIDE { return !array->readonly; } |
201 |
void assignIntElement(uint i, int value); |
void assignIntElement(uint i, int value); |
202 |
void dump(int level = 0); |
void dump(int level = 0); |
203 |
}; |
}; |
341 |
bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); } |
342 |
bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); } |
bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); } |
343 |
bool isPolyphonic() const OVERRIDE { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
344 |
void assign(Expression* expr) OVERRIDE { dynVar->assign(expr); } |
void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); } |
345 |
|
VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); } |
346 |
int evalInt() OVERRIDE; |
int evalInt() OVERRIDE; |
347 |
String evalStr() OVERRIDE; |
String evalStr() OVERRIDE; |
348 |
String evalCastToStr() OVERRIDE; |
String evalCastToStr() OVERRIDE; |
357 |
public: |
public: |
358 |
FunctionCall(const char* function, ArgsRef args, VMFunction* fn) : |
FunctionCall(const char* function, ArgsRef args, VMFunction* fn) : |
359 |
functionName(function), args(args), fn(fn) { } |
functionName(function), args(args), fn(fn) { } |
360 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
361 |
StmtFlags_t exec(); |
StmtFlags_t exec() OVERRIDE; |
362 |
int evalInt(); |
int evalInt() OVERRIDE; |
363 |
String evalStr(); |
VMIntArrayExpr* asIntArray() const OVERRIDE; |
364 |
bool isConstExpr() const { return false; } |
String evalStr() OVERRIDE; |
365 |
ExprType_t exprType() const; |
bool isConstExpr() const OVERRIDE { return false; } |
366 |
String evalCastToStr(); |
ExprType_t exprType() const OVERRIDE; |
367 |
bool isPolyphonic() const { return args->isPolyphonic(); } |
String evalCastToStr() OVERRIDE; |
368 |
|
bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } |
369 |
protected: |
protected: |
370 |
VMFnResult* execVMFn(); |
VMFnResult* execVMFn(); |
371 |
}; |
}; |
425 |
int evalInt() { return 0; } |
int evalInt() { return 0; } |
426 |
EventHandler* eventHandlerByName(const String& name) const; |
EventHandler* eventHandlerByName(const String& name) const; |
427 |
EventHandler* eventHandler(uint index) const; |
EventHandler* eventHandler(uint index) const; |
428 |
inline uint size() const { return args.size(); } |
inline uint size() const { return (int) args.size(); } |
429 |
bool isPolyphonic() const; |
bool isPolyphonic() const; |
430 |
}; |
}; |
431 |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
613 |
std::set<String> userPreprocessorConditions; |
std::set<String> userPreprocessorConditions; |
614 |
|
|
615 |
std::map<String,VariableRef> vartable; |
std::map<String,VariableRef> vartable; |
616 |
|
std::map<String,StatementsRef> userFnTable; |
617 |
int globalIntVarCount; |
int globalIntVarCount; |
618 |
int globalStrVarCount; |
int globalStrVarCount; |
619 |
int polyphonicIntVarCount; |
int polyphonicIntVarCount; |
645 |
IntVariableRef globalIntVar(const String& name); |
IntVariableRef globalIntVar(const String& name); |
646 |
StringVariableRef globalStrVar(const String& name); |
StringVariableRef globalStrVar(const String& name); |
647 |
VariableRef variableByName(const String& name); |
VariableRef variableByName(const String& name); |
648 |
|
StatementsRef userFunctionByName(const String& name); |
649 |
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); |
650 |
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); |
651 |
void createScanner(std::istream* is); |
void createScanner(std::istream* is); |
681 |
ArrayList<StackFrame> stack; |
ArrayList<StackFrame> stack; |
682 |
int stackFrame; |
int stackFrame; |
683 |
int suspendMicroseconds; |
int suspendMicroseconds; |
684 |
|
size_t instructionsCount; |
685 |
|
|
686 |
ExecContext() : |
ExecContext() : |
687 |
status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {} |
status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0), |
688 |
|
instructionsCount(0) {} |
689 |
|
|
690 |
virtual ~ExecContext() {} |
virtual ~ExecContext() {} |
691 |
|
|
713 |
int suspensionTimeMicroseconds() const OVERRIDE { |
int suspensionTimeMicroseconds() const OVERRIDE { |
714 |
return suspendMicroseconds; |
return suspendMicroseconds; |
715 |
} |
} |
716 |
|
|
717 |
|
void resetPolyphonicData() OVERRIDE { |
718 |
|
if (polyphonicIntMemory.empty()) return; |
719 |
|
memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int)); |
720 |
|
} |
721 |
|
|
722 |
|
size_t instructionsPerformed() const OVERRIDE { |
723 |
|
return instructionsCount; |
724 |
|
} |
725 |
}; |
}; |
726 |
|
|
727 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |