60 |
|
|
61 |
class IntExpr : virtual public VMIntExpr, virtual public Expression { |
class IntExpr : virtual public VMIntExpr, virtual public Expression { |
62 |
public: |
public: |
63 |
ExprType_t exprType() const { return INT_EXPR; } |
ExprType_t exprType() const OVERRIDE { return INT_EXPR; } |
64 |
virtual int evalInt() = 0; |
String evalCastToStr() OVERRIDE; |
|
String evalCastToStr(); |
|
65 |
}; |
}; |
66 |
typedef Ref<IntExpr,Node> IntExprRef; |
typedef Ref<IntExpr,Node> IntExprRef; |
67 |
|
|
68 |
class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { |
class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { |
69 |
public: |
public: |
70 |
ExprType_t exprType() const { return INT_ARR_EXPR; } |
ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; } |
71 |
String evalCastToStr(); |
String evalCastToStr() OVERRIDE; |
72 |
}; |
}; |
73 |
typedef Ref<IntArrayExpr,Node> IntArrayExprRef; |
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 OVERRIDE { return STRING_EXPR; } |
78 |
virtual String evalStr() = 0; |
String evalCastToStr() OVERRIDE { return evalStr(); } |
|
String evalCastToStr() { return evalStr(); } |
|
79 |
}; |
}; |
80 |
typedef Ref<StringExpr,Node> StringExprRef; |
typedef Ref<StringExpr,Node> StringExprRef; |
81 |
|
|
82 |
class IntLiteral : virtual public IntExpr { |
class IntLiteral : virtual public IntExpr { |
83 |
public: |
public: |
84 |
int value; |
vmint value; |
85 |
IntLiteral(int value) : value(value) { } |
IntLiteral(vmint value) : value(value) { } |
86 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
87 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
88 |
bool isConstExpr() const { return true; } |
bool isConstExpr() const OVERRIDE { return true; } |
89 |
bool isPolyphonic() const { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
90 |
}; |
}; |
91 |
typedef Ref<IntLiteral,Node> IntLiteralRef; |
typedef Ref<IntLiteral,Node> IntLiteralRef; |
92 |
|
|
94 |
public: |
public: |
95 |
String value; |
String value; |
96 |
StringLiteral(const String& value) : value(value) { } |
StringLiteral(const String& value) : value(value) { } |
97 |
bool isConstExpr() const { return true; } |
bool isConstExpr() const OVERRIDE { return true; } |
98 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
99 |
String evalStr() { return value; } |
String evalStr() OVERRIDE { return value; } |
100 |
bool isPolyphonic() const { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
101 |
}; |
}; |
102 |
typedef Ref<StringLiteral,Node> StringLiteralRef; |
typedef Ref<StringLiteral,Node> StringLiteralRef; |
103 |
|
|
105 |
public: |
public: |
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) OVERRIDE; |
109 |
int argsCount() const { return (int) args.size(); } |
vmint argsCount() const OVERRIDE { return (vmint) args.size(); } |
110 |
VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; } |
VMExpr* arg(vmint i) OVERRIDE { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; } |
111 |
bool isPolyphonic() const; |
bool isPolyphonic() const OVERRIDE; |
112 |
}; |
}; |
113 |
typedef Ref<Args,Node> ArgsRef; |
typedef Ref<Args,Node> ArgsRef; |
114 |
|
|
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); } |
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, vmint _memPos, bool _bConst) |
123 |
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
124 |
|
|
125 |
ParserContext* context; |
ParserContext* context; |
126 |
int memPos; |
vmint memPos; |
127 |
bool bConst; |
bool bConst; |
128 |
}; |
}; |
129 |
typedef Ref<Variable,Node> VariableRef; |
typedef Ref<Variable,Node> VariableRef; |
132 |
bool polyphonic; |
bool polyphonic; |
133 |
public: |
public: |
134 |
IntVariable(ParserContext* ctx); |
IntVariable(ParserContext* ctx); |
135 |
void assign(Expression* expr); |
void assign(Expression* expr) OVERRIDE; |
136 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
137 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
138 |
bool isPolyphonic() const { return polyphonic; } |
bool isPolyphonic() const OVERRIDE { return polyphonic; } |
139 |
protected: |
protected: |
140 |
IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, int size = 1); |
IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1); |
141 |
}; |
}; |
142 |
typedef Ref<IntVariable,Node> IntVariableRef; |
typedef Ref<IntVariable,Node> IntVariableRef; |
143 |
|
|
144 |
class ConstIntVariable : public IntVariable { |
class ConstIntVariable : public IntVariable { |
145 |
public: |
public: |
146 |
int value; |
vmint value; |
147 |
|
|
148 |
ConstIntVariable(int value); |
ConstIntVariable(vmint value); |
149 |
//ConstIntVariable(ParserContext* ctx, int value = 0); |
//ConstIntVariable(ParserContext* ctx, int value = 0); |
150 |
void assign(Expression* expr); |
void assign(Expression* expr) OVERRIDE; |
151 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
152 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
153 |
}; |
}; |
154 |
typedef Ref<ConstIntVariable,Node> ConstIntVariableRef; |
typedef Ref<ConstIntVariable,Node> ConstIntVariableRef; |
155 |
|
|
156 |
class BuiltInIntVariable : public IntVariable { |
class BuiltInIntVariable : public IntVariable { |
157 |
String name; |
String name; |
158 |
VMIntRelPtr* ptr; |
VMIntPtr* ptr; |
159 |
public: |
public: |
160 |
BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); |
BuiltInIntVariable(const String& name, VMIntPtr* ptr); |
161 |
bool isAssignable() const OVERRIDE { return !ptr->readonly; } |
bool isAssignable() const OVERRIDE { return ptr->isAssignable(); } |
162 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
163 |
int evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
164 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
165 |
}; |
}; |
166 |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
168 |
class PolyphonicIntVariable : public IntVariable { |
class PolyphonicIntVariable : public IntVariable { |
169 |
public: |
public: |
170 |
PolyphonicIntVariable(ParserContext* ctx); |
PolyphonicIntVariable(ParserContext* ctx); |
171 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
172 |
}; |
}; |
173 |
typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef; |
typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef; |
174 |
|
|
175 |
class IntArrayVariable : public Variable, virtual public IntArrayExpr { |
class IntArrayVariable : public Variable, virtual public IntArrayExpr { |
176 |
ArrayList<int> values; |
ArrayList<vmint> values; |
177 |
public: |
public: |
178 |
IntArrayVariable(ParserContext* ctx, int size); |
IntArrayVariable(ParserContext* ctx, vmint size); |
179 |
IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst = false); |
IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false); |
180 |
void assign(Expression* expr) {} // ignore scalar assignment |
void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment |
181 |
String evalCastToStr() { return ""; } // ignore scalar cast to string |
String evalCastToStr() OVERRIDE { return ""; } // ignore scalar cast to string |
182 |
ExprType_t exprType() const { return INT_ARR_EXPR; } |
ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; } |
183 |
virtual int arraySize() const { return values.size(); } |
virtual vmint arraySize() const OVERRIDE { return values.size(); } |
184 |
virtual int evalIntElement(uint i); |
virtual vmint evalIntElement(vmuint i) OVERRIDE; |
185 |
virtual void assignIntElement(uint i, int value); |
virtual void assignIntElement(vmuint i, vmint value) OVERRIDE; |
186 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
187 |
bool isPolyphonic() const { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
188 |
protected: |
protected: |
189 |
IntArrayVariable(ParserContext* ctx, bool bConst); |
IntArrayVariable(ParserContext* ctx, bool bConst); |
190 |
}; |
}; |
195 |
VMInt8Array* array; |
VMInt8Array* array; |
196 |
public: |
public: |
197 |
BuiltInIntArrayVariable(const String& name, VMInt8Array* array); |
BuiltInIntArrayVariable(const String& name, VMInt8Array* array); |
198 |
int arraySize() const OVERRIDE { return array->size; } |
vmint arraySize() const OVERRIDE { return array->size; } |
199 |
int evalIntElement(uint i) OVERRIDE; |
vmint evalIntElement(vmuint i) OVERRIDE; |
200 |
bool isAssignable() const OVERRIDE { return !array->readonly; } |
bool isAssignable() const OVERRIDE { return !array->readonly; } |
201 |
void assignIntElement(uint i, int value) OVERRIDE; |
void assignIntElement(vmuint i, vmint value) OVERRIDE; |
202 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
203 |
}; |
}; |
204 |
typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef; |
typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef; |
208 |
IntExprRef index; |
IntExprRef index; |
209 |
public: |
public: |
210 |
IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex); |
IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex); |
211 |
void assign(Expression* expr); |
void assign(Expression* expr) OVERRIDE; |
212 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
213 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
214 |
}; |
}; |
215 |
typedef Ref<IntArrayElement,Node> IntArrayElementRef; |
typedef Ref<IntArrayElement,Node> IntArrayElementRef; |
216 |
|
|
217 |
class StringVariable : public Variable, virtual public StringExpr { |
class StringVariable : public Variable, virtual public StringExpr { |
218 |
public: |
public: |
219 |
StringVariable(ParserContext* ctx); |
StringVariable(ParserContext* ctx); |
220 |
void assign(Expression* expr); |
void assign(Expression* expr) OVERRIDE; |
221 |
String evalStr(); |
String evalStr() OVERRIDE; |
222 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
223 |
bool isPolyphonic() const { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
224 |
protected: |
protected: |
225 |
StringVariable(ParserContext* ctx, bool bConst); |
StringVariable(ParserContext* ctx, bool bConst); |
226 |
}; |
}; |
231 |
String value; |
String value; |
232 |
|
|
233 |
ConstStringVariable(ParserContext* ctx, String value = ""); |
ConstStringVariable(ParserContext* ctx, String value = ""); |
234 |
void assign(Expression* expr); |
void assign(Expression* expr) OVERRIDE; |
235 |
String evalStr(); |
String evalStr() OVERRIDE; |
236 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
237 |
}; |
}; |
238 |
typedef Ref<ConstStringVariable,Node> ConstStringVariableRef; |
typedef Ref<ConstStringVariable,Node> ConstStringVariableRef; |
239 |
|
|
243 |
ExpressionRef rhs; |
ExpressionRef rhs; |
244 |
public: |
public: |
245 |
BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { } |
BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { } |
246 |
bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return lhs->isConstExpr() && rhs->isConstExpr(); } |
247 |
bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
248 |
}; |
}; |
249 |
typedef Ref<BinaryOp,Node> BinaryOpRef; |
typedef Ref<BinaryOp,Node> BinaryOpRef; |
250 |
|
|
251 |
class Add : virtual public BinaryOp, virtual public IntExpr { |
class Add : virtual public BinaryOp, virtual public IntExpr { |
252 |
public: |
public: |
253 |
Add(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Add(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
254 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
255 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
256 |
}; |
}; |
257 |
typedef Ref<Add,Node> AddRef; |
typedef Ref<Add,Node> AddRef; |
258 |
|
|
259 |
class Sub : virtual public BinaryOp, virtual public IntExpr { |
class Sub : virtual public BinaryOp, virtual public IntExpr { |
260 |
public: |
public: |
261 |
Sub(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Sub(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
262 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
263 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
264 |
}; |
}; |
265 |
typedef Ref<Sub,Node> SubRef; |
typedef Ref<Sub,Node> SubRef; |
266 |
|
|
267 |
class Mul : virtual public BinaryOp, virtual public IntExpr { |
class Mul : virtual public BinaryOp, virtual public IntExpr { |
268 |
public: |
public: |
269 |
Mul(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Mul(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
270 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
271 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
272 |
}; |
}; |
273 |
typedef Ref<Mul,Node> MulRef; |
typedef Ref<Mul,Node> MulRef; |
274 |
|
|
275 |
class Div : virtual public BinaryOp, virtual public IntExpr { |
class Div : virtual public BinaryOp, virtual public IntExpr { |
276 |
public: |
public: |
277 |
Div(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Div(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
278 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
279 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
280 |
}; |
}; |
281 |
typedef Ref<Div,Node> DivRef; |
typedef Ref<Div,Node> DivRef; |
282 |
|
|
283 |
class Mod : virtual public BinaryOp, virtual public IntExpr { |
class Mod : virtual public BinaryOp, virtual public IntExpr { |
284 |
public: |
public: |
285 |
Mod(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Mod(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
286 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
287 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
288 |
}; |
}; |
289 |
typedef Ref<Mod,Node> ModRef; |
typedef Ref<Mod,Node> ModRef; |
290 |
|
|
299 |
class NoOperation : public Statement { |
class NoOperation : public Statement { |
300 |
public: |
public: |
301 |
NoOperation() : Statement() {} |
NoOperation() : Statement() {} |
302 |
StmtType_t statementType() const { return STMT_NOOP; } |
StmtType_t statementType() const OVERRIDE { return STMT_NOOP; } |
303 |
void dump(int level = 0) {} |
void dump(int level = 0) OVERRIDE {} |
304 |
bool isPolyphonic() const { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
305 |
}; |
}; |
306 |
typedef Ref<NoOperation,Node> NoOperationRef; |
typedef Ref<NoOperation,Node> NoOperationRef; |
307 |
|
|
310 |
class LeafStatement : public Statement { |
class LeafStatement : public Statement { |
311 |
public: |
public: |
312 |
virtual StmtFlags_t exec() = 0; |
virtual StmtFlags_t exec() = 0; |
313 |
virtual StmtType_t statementType() const { return STMT_LEAF; } |
StmtType_t statementType() const OVERRIDE { return STMT_LEAF; } |
314 |
}; |
}; |
315 |
typedef Ref<LeafStatement,Node> LeafStatementRef; |
typedef Ref<LeafStatement,Node> LeafStatementRef; |
316 |
|
|
318 |
std::vector<StatementRef> args; |
std::vector<StatementRef> args; |
319 |
public: |
public: |
320 |
void add(StatementRef arg) { args.push_back(arg); } |
void add(StatementRef arg) { args.push_back(arg); } |
321 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
322 |
StmtType_t statementType() const { return STMT_LIST; } |
StmtType_t statementType() const OVERRIDE { return STMT_LIST; } |
323 |
virtual Statement* statement(uint i); |
virtual Statement* statement(uint i); |
324 |
bool isPolyphonic() const; |
bool isPolyphonic() const OVERRIDE; |
325 |
}; |
}; |
326 |
typedef Ref<Statements,Node> StatementsRef; |
typedef Ref<Statements,Node> StatementsRef; |
327 |
|
|
328 |
class BranchStatement : public Statement { |
class BranchStatement : public Statement { |
329 |
public: |
public: |
330 |
StmtType_t statementType() const { return STMT_BRANCH; } |
StmtType_t statementType() const OVERRIDE { return STMT_BRANCH; } |
331 |
virtual int evalBranch() = 0; |
virtual vmint evalBranch() = 0; |
332 |
virtual Statements* branch(uint i) const = 0; |
virtual Statements* branch(vmuint i) const = 0; |
333 |
}; |
}; |
334 |
|
|
335 |
class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr { |
class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr { |
343 |
bool isPolyphonic() const OVERRIDE { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
344 |
void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); } |
void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); } |
345 |
VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); } |
VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); } |
346 |
int evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
347 |
String evalStr() OVERRIDE; |
String evalStr() OVERRIDE; |
348 |
String evalCastToStr() OVERRIDE; |
String evalCastToStr() OVERRIDE; |
349 |
int arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); } |
vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); } |
350 |
int evalIntElement(uint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); } |
vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); } |
351 |
void assignIntElement(uint i, int value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); } |
void assignIntElement(vmuint i, vmint value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); } |
352 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
353 |
}; |
}; |
354 |
typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef; |
typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef; |
362 |
functionName(function), args(args), fn(fn) { } |
functionName(function), args(args), fn(fn) { } |
363 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
364 |
StmtFlags_t exec() OVERRIDE; |
StmtFlags_t exec() OVERRIDE; |
365 |
int evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
366 |
VMIntArrayExpr* asIntArray() const OVERRIDE; |
VMIntArrayExpr* asIntArray() const OVERRIDE; |
367 |
String evalStr() OVERRIDE; |
String evalStr() OVERRIDE; |
368 |
bool isConstExpr() const OVERRIDE { return false; } |
bool isConstExpr() const OVERRIDE { return false; } |
377 |
class NoFunctionCall : public FunctionCall { |
class NoFunctionCall : public FunctionCall { |
378 |
public: |
public: |
379 |
NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {} |
NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {} |
380 |
StmtType_t statementType() const { return STMT_NOOP; } |
StmtType_t statementType() const OVERRIDE { return STMT_NOOP; } |
381 |
}; |
}; |
382 |
typedef Ref<NoFunctionCall,Node> NoFunctionCallRef; |
typedef Ref<NoFunctionCall,Node> NoFunctionCallRef; |
383 |
|
|
385 |
StatementsRef statements; |
StatementsRef statements; |
386 |
bool usingPolyphonics; |
bool usingPolyphonics; |
387 |
public: |
public: |
388 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
389 |
StmtFlags_t exec(); |
StmtFlags_t exec(); |
390 |
EventHandler(StatementsRef statements); |
EventHandler(StatementsRef statements); |
391 |
Statement* statement(uint i) { return statements->statement(i); } |
Statement* statement(uint i) OVERRIDE { return statements->statement(i); } |
392 |
bool isPolyphonic() const { return usingPolyphonics; } |
bool isPolyphonic() const OVERRIDE { return usingPolyphonics; } |
393 |
}; |
}; |
394 |
typedef Ref<EventHandler,Node> EventHandlerRef; |
typedef Ref<EventHandler,Node> EventHandlerRef; |
395 |
|
|
396 |
class OnNote : public EventHandler { |
class OnNote : public EventHandler { |
397 |
public: |
public: |
398 |
OnNote(StatementsRef statements) : EventHandler(statements) {} |
OnNote(StatementsRef statements) : EventHandler(statements) {} |
399 |
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_NOTE; } |
VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; } |
400 |
String eventHandlerName() const { return "note"; } |
String eventHandlerName() const OVERRIDE { return "note"; } |
401 |
}; |
}; |
402 |
typedef Ref<OnNote,Node> OnNoteRef; |
typedef Ref<OnNote,Node> OnNoteRef; |
403 |
|
|
404 |
class OnInit : public EventHandler { |
class OnInit : public EventHandler { |
405 |
public: |
public: |
406 |
OnInit(StatementsRef statements) : EventHandler(statements) {} |
OnInit(StatementsRef statements) : EventHandler(statements) {} |
407 |
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_INIT; } |
VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; } |
408 |
String eventHandlerName() const { return "init"; } |
String eventHandlerName() const OVERRIDE { return "init"; } |
409 |
}; |
}; |
410 |
typedef Ref<OnInit,Node> OnInitRef; |
typedef Ref<OnInit,Node> OnInitRef; |
411 |
|
|
412 |
class OnRelease : public EventHandler { |
class OnRelease : public EventHandler { |
413 |
public: |
public: |
414 |
OnRelease(StatementsRef statements) : EventHandler(statements) {} |
OnRelease(StatementsRef statements) : EventHandler(statements) {} |
415 |
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_RELEASE; } |
VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; } |
416 |
String eventHandlerName() const { return "release"; } |
String eventHandlerName() const OVERRIDE { return "release"; } |
417 |
}; |
}; |
418 |
typedef Ref<OnRelease,Node> OnReleaseRef; |
typedef Ref<OnRelease,Node> OnReleaseRef; |
419 |
|
|
420 |
class OnController : public EventHandler { |
class OnController : public EventHandler { |
421 |
public: |
public: |
422 |
OnController(StatementsRef statements) : EventHandler(statements) {} |
OnController(StatementsRef statements) : EventHandler(statements) {} |
423 |
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_CONTROLLER; } |
VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; } |
424 |
String eventHandlerName() const { return "controller"; } |
String eventHandlerName() const OVERRIDE { return "controller"; } |
425 |
}; |
}; |
426 |
typedef Ref<OnController,Node> OnControllerRef; |
typedef Ref<OnController,Node> OnControllerRef; |
427 |
|
|
431 |
EventHandlers(); |
EventHandlers(); |
432 |
~EventHandlers(); |
~EventHandlers(); |
433 |
void add(EventHandlerRef arg); |
void add(EventHandlerRef arg); |
434 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
|
int evalInt() { return 0; } |
|
435 |
EventHandler* eventHandlerByName(const String& name) const; |
EventHandler* eventHandlerByName(const String& name) const; |
436 |
EventHandler* eventHandler(uint index) const; |
EventHandler* eventHandler(uint index) const; |
437 |
inline uint size() const { return (int) args.size(); } |
inline uint size() const { return (int) args.size(); } |
438 |
bool isPolyphonic() const; |
bool isPolyphonic() const OVERRIDE; |
439 |
}; |
}; |
440 |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
441 |
|
|
445 |
ExpressionRef value; |
ExpressionRef value; |
446 |
public: |
public: |
447 |
Assignment(VariableRef variable, ExpressionRef value); |
Assignment(VariableRef variable, ExpressionRef value); |
448 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
449 |
StmtFlags_t exec(); |
StmtFlags_t exec() OVERRIDE; |
450 |
bool isPolyphonic() const { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); } |
bool isPolyphonic() const OVERRIDE { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); } |
451 |
}; |
}; |
452 |
typedef Ref<Assignment,Node> AssignmentRef; |
typedef Ref<Assignment,Node> AssignmentRef; |
453 |
|
|
460 |
condition(condition), ifStatements(ifStatements), elseStatements(elseStatements) { } |
condition(condition), ifStatements(ifStatements), elseStatements(elseStatements) { } |
461 |
If(IntExprRef condition, StatementsRef statements) : |
If(IntExprRef condition, StatementsRef statements) : |
462 |
condition(condition), ifStatements(statements) { } |
condition(condition), ifStatements(statements) { } |
463 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
464 |
int evalBranch(); |
vmint evalBranch() OVERRIDE; |
465 |
Statements* branch(uint i) const; |
Statements* branch(vmuint i) const OVERRIDE; |
466 |
bool isPolyphonic() const; |
bool isPolyphonic() const OVERRIDE; |
467 |
}; |
}; |
468 |
typedef Ref<If,Node> IfRef; |
typedef Ref<If,Node> IfRef; |
469 |
|
|
480 |
CaseBranches branches; |
CaseBranches branches; |
481 |
public: |
public: |
482 |
SelectCase(IntExprRef select, const CaseBranches& branches) : select(select), branches(branches) { } |
SelectCase(IntExprRef select, const CaseBranches& branches) : select(select), branches(branches) { } |
483 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
484 |
int evalBranch(); |
vmint evalBranch() OVERRIDE; |
485 |
Statements* branch(uint i) const; |
Statements* branch(vmuint i) const OVERRIDE; |
486 |
//void addBranch(IntExprRef condition, StatementsRef statements); |
//void addBranch(IntExprRef condition, StatementsRef statements); |
487 |
//void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements); |
//void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements); |
488 |
//void addBranch(CaseBranchRef branch); |
//void addBranch(CaseBranchRef branch); |
489 |
//void addBranches(CaseBranchesRef branches); |
//void addBranches(CaseBranchesRef branches); |
490 |
bool isPolyphonic() const; |
bool isPolyphonic() const OVERRIDE; |
491 |
}; |
}; |
492 |
typedef Ref<SelectCase,Node> SelectCaseRef; |
typedef Ref<SelectCase,Node> SelectCaseRef; |
493 |
|
|
497 |
public: |
public: |
498 |
While(IntExprRef condition, StatementsRef statements) : |
While(IntExprRef condition, StatementsRef statements) : |
499 |
m_condition(condition), m_statements(statements) {} |
m_condition(condition), m_statements(statements) {} |
500 |
StmtType_t statementType() const { return STMT_LOOP; } |
StmtType_t statementType() const OVERRIDE { return STMT_LOOP; } |
501 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
502 |
bool evalLoopStartCondition(); |
bool evalLoopStartCondition(); |
503 |
Statements* statements() const; |
Statements* statements() const; |
504 |
bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); } |
505 |
}; |
}; |
506 |
|
|
507 |
class SyncBlock : public Statement { |
class SyncBlock : public Statement { |
508 |
StatementsRef m_statements; |
StatementsRef m_statements; |
509 |
public: |
public: |
510 |
SyncBlock(StatementsRef statements) : m_statements(statements) {} |
SyncBlock(StatementsRef statements) : m_statements(statements) {} |
511 |
StmtType_t statementType() const { return STMT_SYNC; } |
StmtType_t statementType() const OVERRIDE { return STMT_SYNC; } |
512 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
513 |
Statements* statements() const; |
Statements* statements() const; |
514 |
bool isPolyphonic() const { return m_statements->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return m_statements->isPolyphonic(); } |
515 |
}; |
}; |
516 |
typedef Ref<SyncBlock,Node> SyncBlockRef; |
typedef Ref<SyncBlock,Node> SyncBlockRef; |
517 |
|
|
519 |
IntExprRef expr; |
IntExprRef expr; |
520 |
public: |
public: |
521 |
Neg(IntExprRef expr) : expr(expr) { } |
Neg(IntExprRef expr) : expr(expr) { } |
522 |
int evalInt() { return (expr) ? -expr->evalInt() : 0; } |
vmint evalInt() OVERRIDE { return (expr) ? -expr->evalInt() : 0; } |
523 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
524 |
bool isConstExpr() const { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
525 |
bool isPolyphonic() const { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
526 |
}; |
}; |
527 |
typedef Ref<Neg,Node> NegRef; |
typedef Ref<Neg,Node> NegRef; |
528 |
|
|
531 |
ExpressionRef rhs; |
ExpressionRef rhs; |
532 |
public: |
public: |
533 |
ConcatString(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) {} |
ConcatString(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) {} |
534 |
String evalStr(); |
String evalStr() OVERRIDE; |
535 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
536 |
bool isConstExpr() const; |
bool isConstExpr() const OVERRIDE; |
537 |
bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
538 |
}; |
}; |
539 |
typedef Ref<ConcatString,Node> ConcatStringRef; |
typedef Ref<ConcatString,Node> ConcatStringRef; |
540 |
|
|
550 |
}; |
}; |
551 |
Relation(IntExprRef lhs, Type type, IntExprRef rhs) : |
Relation(IntExprRef lhs, Type type, IntExprRef rhs) : |
552 |
lhs(lhs), rhs(rhs), type(type) {} |
lhs(lhs), rhs(rhs), type(type) {} |
553 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
554 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
555 |
bool isConstExpr() const; |
bool isConstExpr() const OVERRIDE; |
556 |
bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
557 |
private: |
private: |
558 |
IntExprRef lhs; |
IntExprRef lhs; |
559 |
IntExprRef rhs; |
IntExprRef rhs; |
564 |
class Or : virtual public BinaryOp, virtual public IntExpr { |
class Or : virtual public BinaryOp, virtual public IntExpr { |
565 |
public: |
public: |
566 |
Or(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
Or(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
567 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
568 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
569 |
}; |
}; |
570 |
typedef Ref<Or,Node> OrRef; |
typedef Ref<Or,Node> OrRef; |
571 |
|
|
572 |
class BitwiseOr : virtual public BinaryOp, virtual public IntExpr { |
class BitwiseOr : virtual public BinaryOp, virtual public IntExpr { |
573 |
public: |
public: |
574 |
BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
575 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
576 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
577 |
}; |
}; |
578 |
typedef Ref<BitwiseOr,Node> BitwiseOrRef; |
typedef Ref<BitwiseOr,Node> BitwiseOrRef; |
579 |
|
|
580 |
class And : virtual public BinaryOp, virtual public IntExpr { |
class And : virtual public BinaryOp, virtual public IntExpr { |
581 |
public: |
public: |
582 |
And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
583 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
584 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
585 |
}; |
}; |
586 |
typedef Ref<And,Node> AndRef; |
typedef Ref<And,Node> AndRef; |
587 |
|
|
588 |
class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr { |
class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr { |
589 |
public: |
public: |
590 |
BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
591 |
int evalInt(); |
vmint evalInt() OVERRIDE; |
592 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
593 |
}; |
}; |
594 |
typedef Ref<BitwiseAnd,Node> BitwiseAndRef; |
typedef Ref<BitwiseAnd,Node> BitwiseAndRef; |
595 |
|
|
597 |
IntExprRef expr; |
IntExprRef expr; |
598 |
public: |
public: |
599 |
Not(IntExprRef expr) : expr(expr) {} |
Not(IntExprRef expr) : expr(expr) {} |
600 |
int evalInt() { return !expr->evalInt(); } |
vmint evalInt() OVERRIDE { return !expr->evalInt(); } |
601 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
602 |
bool isConstExpr() const { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
603 |
bool isPolyphonic() const { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
604 |
}; |
}; |
605 |
typedef Ref<Not,Node> NotRef; |
typedef Ref<Not,Node> NotRef; |
606 |
|
|
608 |
IntExprRef expr; |
IntExprRef expr; |
609 |
public: |
public: |
610 |
BitwiseNot(IntExprRef expr) : expr(expr) {} |
BitwiseNot(IntExprRef expr) : expr(expr) {} |
611 |
int evalInt() { return ~expr->evalInt(); } |
vmint evalInt() OVERRIDE { return ~expr->evalInt(); } |
612 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
613 |
bool isConstExpr() const { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
614 |
bool isPolyphonic() const { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
615 |
}; |
}; |
616 |
typedef Ref<BitwiseNot,Node> BitwiseNotRef; |
typedef Ref<BitwiseNot,Node> BitwiseNotRef; |
617 |
|
|
635 |
|
|
636 |
std::map<String,VariableRef> vartable; |
std::map<String,VariableRef> vartable; |
637 |
std::map<String,StatementsRef> userFnTable; |
std::map<String,StatementsRef> userFnTable; |
638 |
int globalIntVarCount; |
vmint globalIntVarCount; |
639 |
int globalStrVarCount; |
vmint globalStrVarCount; |
640 |
int polyphonicIntVarCount; |
vmint polyphonicIntVarCount; |
641 |
|
|
642 |
EventHandlersRef handlers; |
EventHandlersRef handlers; |
643 |
|
|
646 |
OnReleaseRef onRelease; |
OnReleaseRef onRelease; |
647 |
OnControllerRef onController; |
OnControllerRef onController; |
648 |
|
|
649 |
ArrayList<int>* globalIntMemory; |
ArrayList<vmint>* globalIntMemory; |
650 |
ArrayList<String>* globalStrMemory; |
ArrayList<String>* globalStrMemory; |
651 |
int requiredMaxStackSize; |
vmint requiredMaxStackSize; |
652 |
|
|
653 |
VMFunctionProvider* functionProvider; |
VMFunctionProvider* functionProvider; |
654 |
|
|
681 |
std::vector<CodeBlock> preprocessorComments() const OVERRIDE; |
std::vector<CodeBlock> preprocessorComments() const OVERRIDE; |
682 |
VMEventHandler* eventHandler(uint index) OVERRIDE; |
VMEventHandler* eventHandler(uint index) OVERRIDE; |
683 |
VMEventHandler* eventHandlerByName(const String& name) OVERRIDE; |
VMEventHandler* eventHandlerByName(const String& name) OVERRIDE; |
684 |
void registerBuiltInConstIntVariables(const std::map<String,int>& vars); |
void registerBuiltInConstIntVariables(const std::map<String,vmint>& vars); |
685 |
void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars); |
void registerBuiltInIntVariables(const std::map<String,VMIntPtr*>& vars); |
686 |
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
687 |
void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars); |
void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars); |
688 |
}; |
}; |
699 |
} |
} |
700 |
}; |
}; |
701 |
|
|
702 |
ArrayList<int> polyphonicIntMemory; |
ArrayList<vmint> polyphonicIntMemory; |
703 |
VMExecStatus_t status; |
VMExecStatus_t status; |
704 |
StmtFlags_t flags; |
StmtFlags_t flags; |
705 |
ArrayList<StackFrame> stack; |
ArrayList<StackFrame> stack; |
706 |
int stackFrame; |
int stackFrame; |
707 |
int suspendMicroseconds; |
vmint suspendMicroseconds; |
708 |
size_t instructionsCount; |
size_t instructionsCount; |
709 |
struct ExitRes { |
struct ExitRes { |
710 |
Expression* value; |
Expression* value; |
743 |
exitRes.value = NULL; |
exitRes.value = NULL; |
744 |
} |
} |
745 |
|
|
746 |
int suspensionTimeMicroseconds() const OVERRIDE { |
vmint suspensionTimeMicroseconds() const OVERRIDE { |
747 |
return suspendMicroseconds; |
return suspendMicroseconds; |
748 |
} |
} |
749 |
|
|
750 |
void resetPolyphonicData() OVERRIDE { |
void resetPolyphonicData() OVERRIDE { |
751 |
if (polyphonicIntMemory.empty()) return; |
if (polyphonicIntMemory.empty()) return; |
752 |
memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int)); |
memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint)); |
753 |
} |
} |
754 |
|
|
755 |
size_t instructionsPerformed() const OVERRIDE { |
size_t instructionsPerformed() const OVERRIDE { |