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" |
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 { |
65 |
}; |
}; |
66 |
typedef Ref<IntExpr,Node> IntExprRef; |
typedef Ref<IntExpr,Node> IntExprRef; |
67 |
|
|
68 |
|
/*class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { |
69 |
|
public: |
70 |
|
ExprType_t exprType() const { return INT_ARR_EXPR; } |
71 |
|
String evalCastToStr(); |
72 |
|
}; |
73 |
|
typedef Ref<IntArrayExpr,Node> IntArrayExprRef;*/ |
74 |
|
|
75 |
class StringExpr : virtual public VMStringExpr, virtual public Expression { |
class StringExpr : virtual public VMStringExpr, virtual public Expression { |
76 |
public: |
public: |
77 |
ExprType_t exprType() const { return STRING_EXPR; } |
ExprType_t exprType() const { return STRING_EXPR; } |
107 |
std::vector<ExpressionRef> args; |
std::vector<ExpressionRef> args; |
108 |
void add(ExpressionRef arg) { args.push_back(arg); } |
void add(ExpressionRef arg) { args.push_back(arg); } |
109 |
void dump(int level = 0); |
void dump(int level = 0); |
110 |
int argsCount() const { return args.size(); } |
int argsCount() const { return (int) args.size(); } |
111 |
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; } |
112 |
bool isPolyphonic() const; |
bool isPolyphonic() const; |
113 |
}; |
}; |
159 |
VMIntRelPtr* ptr; |
VMIntRelPtr* ptr; |
160 |
public: |
public: |
161 |
BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); |
BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); |
162 |
void assign(Expression* expr); |
bool isAssignable() const OVERRIDE { return !ptr->readonly; } |
163 |
int evalInt(); |
void assign(Expression* expr) OVERRIDE; |
164 |
void dump(int level = 0); |
int evalInt() OVERRIDE; |
165 |
|
void dump(int level = 0) OVERRIDE; |
166 |
}; |
}; |
167 |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
168 |
|
|
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; } |
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 |
}; |
}; |
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; |
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 |
String evalStr(); |
VMIntArrayExpr* asIntArray() const OVERRIDE; |
365 |
bool isConstExpr() const { return false; } |
String evalStr() OVERRIDE; |
366 |
ExprType_t exprType() const; |
bool isConstExpr() const OVERRIDE { return false; } |
367 |
String evalCastToStr(); |
ExprType_t exprType() const OVERRIDE; |
368 |
bool isPolyphonic() const { return args->isPolyphonic(); } |
String evalCastToStr() OVERRIDE; |
369 |
|
bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } |
370 |
protected: |
protected: |
371 |
VMFnResult* execVMFn(); |
VMFnResult* execVMFn(); |
372 |
}; |
}; |
426 |
int evalInt() { return 0; } |
int evalInt() { return 0; } |
427 |
EventHandler* eventHandlerByName(const String& name) const; |
EventHandler* eventHandlerByName(const String& name) const; |
428 |
EventHandler* eventHandler(uint index) const; |
EventHandler* eventHandler(uint index) const; |
429 |
inline uint size() const { return args.size(); } |
inline uint size() const { return (int) args.size(); } |
430 |
bool isPolyphonic() const; |
bool isPolyphonic() const; |
431 |
}; |
}; |
432 |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
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: |
625 |
std::set<String> userPreprocessorConditions; |
std::set<String> userPreprocessorConditions; |
626 |
|
|
627 |
std::map<String,VariableRef> vartable; |
std::map<String,VariableRef> vartable; |
628 |
|
std::map<String,StatementsRef> userFnTable; |
629 |
int globalIntVarCount; |
int globalIntVarCount; |
630 |
int globalStrVarCount; |
int globalStrVarCount; |
631 |
int polyphonicIntVarCount; |
int polyphonicIntVarCount; |
657 |
IntVariableRef globalIntVar(const String& name); |
IntVariableRef globalIntVar(const String& name); |
658 |
StringVariableRef globalStrVar(const String& name); |
StringVariableRef globalStrVar(const String& name); |
659 |
VariableRef variableByName(const String& name); |
VariableRef variableByName(const String& name); |
660 |
|
StatementsRef userFunctionByName(const String& name); |
661 |
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); |
662 |
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); |
663 |
void createScanner(std::istream* is); |
void createScanner(std::istream* is); |
693 |
ArrayList<StackFrame> stack; |
ArrayList<StackFrame> stack; |
694 |
int stackFrame; |
int stackFrame; |
695 |
int suspendMicroseconds; |
int suspendMicroseconds; |
696 |
|
size_t instructionsCount; |
697 |
|
|
698 |
ExecContext() : |
ExecContext() : |
699 |
status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {} |
status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0), |
700 |
|
instructionsCount(0) {} |
701 |
|
|
702 |
virtual ~ExecContext() {} |
virtual ~ExecContext() {} |
703 |
|
|
725 |
int suspensionTimeMicroseconds() const OVERRIDE { |
int suspensionTimeMicroseconds() const OVERRIDE { |
726 |
return suspendMicroseconds; |
return suspendMicroseconds; |
727 |
} |
} |
728 |
|
|
729 |
|
void resetPolyphonicData() OVERRIDE { |
730 |
|
if (polyphonicIntMemory.empty()) return; |
731 |
|
memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int)); |
732 |
|
} |
733 |
|
|
734 |
|
size_t instructionsPerformed() const OVERRIDE { |
735 |
|
return instructionsCount; |
736 |
|
} |
737 |
}; |
}; |
738 |
|
|
739 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |