1 |
/* |
/* |
2 |
* Copyright (c) 2014 - 2016 Christian Schoenebeck and Andreas Persson |
* Copyright (c) 2014 - 2019 Christian Schoenebeck and Andreas Persson |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
16 |
namespace LinuxSampler { |
namespace LinuxSampler { |
17 |
|
|
18 |
bool isNoOperation(StatementRef statement) { |
bool isNoOperation(StatementRef statement) { |
19 |
NoOperation* noOp = dynamic_cast<NoOperation*>(&*statement); |
return statement->statementType() == STMT_NOOP; |
|
return noOp; |
|
20 |
} |
} |
21 |
|
|
22 |
Node::Node() { |
Node::Node() { |
34 |
return ToString(evalInt()); |
return ToString(evalInt()); |
35 |
} |
} |
36 |
|
|
37 |
|
String IntArrayExpr::evalCastToStr() { |
38 |
|
String s = "{"; |
39 |
|
for (int i = 0; i < arraySize(); ++i) { |
40 |
|
int val = evalIntElement(i); |
41 |
|
if (i) s += ","; |
42 |
|
s += ToString(val); |
43 |
|
} |
44 |
|
s += "}"; |
45 |
|
return s; |
46 |
|
} |
47 |
|
|
48 |
int IntLiteral::evalInt() { |
int IntLiteral::evalInt() { |
49 |
return value; |
return value; |
50 |
} |
} |
323 |
return intExpr->evalInt(); |
return intExpr->evalInt(); |
324 |
} |
} |
325 |
|
|
326 |
|
VMIntArrayExpr* FunctionCall::asIntArray() const { |
327 |
|
VMFnResult* result = const_cast<FunctionCall*>(this)->execVMFn(); |
328 |
|
if (!result) return 0; |
329 |
|
VMIntArrayExpr* intArrExpr = dynamic_cast<VMIntArrayExpr*>(result->resultValue()); |
330 |
|
return intArrExpr; |
331 |
|
} |
332 |
|
|
333 |
String FunctionCall::evalStr() { |
String FunctionCall::evalStr() { |
334 |
VMFnResult* result = execVMFn(); |
VMFnResult* result = execVMFn(); |
335 |
if (!result) return ""; |
if (!result) return ""; |
376 |
|
|
377 |
void IntVariable::assign(Expression* expr) { |
void IntVariable::assign(Expression* expr) { |
378 |
IntExpr* intExpr = dynamic_cast<IntExpr*>(expr); |
IntExpr* intExpr = dynamic_cast<IntExpr*>(expr); |
379 |
if (intExpr) |
if (intExpr) { |
380 |
if (polyphonic) |
if (polyphonic) |
381 |
context->execContext->polyphonicIntMemory[memPos] = intExpr->evalInt(); |
context->execContext->polyphonicIntMemory[memPos] = intExpr->evalInt(); |
382 |
else |
else |
383 |
(*context->globalIntMemory)[memPos] = intExpr->evalInt(); |
(*context->globalIntMemory)[memPos] = intExpr->evalInt(); |
384 |
|
} |
385 |
} |
} |
386 |
|
|
387 |
int IntVariable::evalInt() { |
int IntVariable::evalInt() { |
462 |
memset(&values[0], 0, size * sizeof(int)); |
memset(&values[0], 0, size * sizeof(int)); |
463 |
} |
} |
464 |
|
|
465 |
IntArrayVariable::IntArrayVariable(ParserContext* ctx, int size, ArgsRef values) |
IntArrayVariable::IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst) |
466 |
: Variable(ctx, 0, false) |
: Variable(ctx, 0, _bConst) |
467 |
{ |
{ |
468 |
this->values.resize(size); |
this->values.resize(size); |
469 |
for (int i = 0; i < values->argsCount(); ++i) { |
for (int i = 0; i < values->argsCount(); ++i) { |
520 |
printf("Built-In Int Array Variable '%s'\n", name.c_str()); |
printf("Built-In Int Array Variable '%s'\n", name.c_str()); |
521 |
} |
} |
522 |
|
|
523 |
IntArrayElement::IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex) |
IntArrayElement::IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex) |
524 |
: IntVariable(NULL, false, false, 0), array(array), index(arrayIndex) |
: IntVariable(NULL, false, false, 0), array(array), index(arrayIndex) |
525 |
{ |
{ |
526 |
} |
} |
723 |
return m_condition->evalInt(); |
return m_condition->evalInt(); |
724 |
} |
} |
725 |
|
|
726 |
|
void SyncBlock::dump(int level) { |
727 |
|
printIndents(level); |
728 |
|
printf("sync {\n"); |
729 |
|
m_statements->dump(level+1); |
730 |
|
printIndents(level); |
731 |
|
printf("}\n"); |
732 |
|
} |
733 |
|
|
734 |
|
Statements* SyncBlock::statements() const { |
735 |
|
return (m_statements) ? const_cast<Statements*>( &*m_statements ) : NULL; |
736 |
|
} |
737 |
|
|
738 |
void Neg::dump(int level) { |
void Neg::dump(int level) { |
739 |
printIndents(level); |
printIndents(level); |
740 |
printf("Negative Expr\n"); |
printf("Negative Expr\n"); |
912 |
printf(")\n"); |
printf(")\n"); |
913 |
} |
} |
914 |
|
|
915 |
|
StatementsRef ParserContext::userFunctionByName(const String& name) { |
916 |
|
if (!userFnTable.count(name)) { |
917 |
|
return StatementsRef(); |
918 |
|
} |
919 |
|
return userFnTable.find(name)->second; |
920 |
|
} |
921 |
|
|
922 |
VariableRef ParserContext::variableByName(const String& name) { |
VariableRef ParserContext::variableByName(const String& name) { |
923 |
if (!vartable.count(name)) { |
if (!vartable.count(name)) { |
924 |
return VariableRef(); |
return VariableRef(); |
976 |
vIssues.push_back(w); |
vIssues.push_back(w); |
977 |
} |
} |
978 |
|
|
979 |
|
void ParserContext::addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn) { |
980 |
|
CodeBlock block; |
981 |
|
block.firstLine = firstLine; |
982 |
|
block.lastLine = lastLine; |
983 |
|
block.firstColumn = firstColumn; |
984 |
|
block.lastColumn = lastColumn; |
985 |
|
vPreprocessorComments.push_back(block); |
986 |
|
} |
987 |
|
|
988 |
bool ParserContext::setPreprocessorCondition(const char* name) { |
bool ParserContext::setPreprocessorCondition(const char* name) { |
989 |
if (builtinPreprocessorConditions.count(name)) return false; |
if (builtinPreprocessorConditions.count(name)) return false; |
990 |
if (userPreprocessorConditions.count(name)) return false; |
if (userPreprocessorConditions.count(name)) return false; |
1016 |
return vWarnings; |
return vWarnings; |
1017 |
} |
} |
1018 |
|
|
1019 |
|
std::vector<CodeBlock> ParserContext::preprocessorComments() const { |
1020 |
|
return vPreprocessorComments; |
1021 |
|
} |
1022 |
|
|
1023 |
VMEventHandler* ParserContext::eventHandler(uint index) { |
VMEventHandler* ParserContext::eventHandler(uint index) { |
1024 |
if (!handlers) return NULL; |
if (!handlers) return NULL; |
1025 |
return handlers->eventHandler(index); |
return handlers->eventHandler(index); |
1066 |
} |
} |
1067 |
} |
} |
1068 |
|
|
1069 |
|
ExecContext::ExecContext() : |
1070 |
|
status(VM_EXEC_NOT_RUNNING), flags(STMT_SUCCESS), stackFrame(-1), |
1071 |
|
suspendMicroseconds(0), instructionsCount(0) |
1072 |
|
{ |
1073 |
|
exitRes.value = NULL; |
1074 |
|
} |
1075 |
|
|
1076 |
|
void ExecContext::forkTo(VMExecContext* ectx) const { |
1077 |
|
ExecContext* child = dynamic_cast<ExecContext*>(ectx); |
1078 |
|
|
1079 |
|
child->polyphonicIntMemory.copyFlatFrom(polyphonicIntMemory); |
1080 |
|
child->status = VM_EXEC_SUSPENDED; |
1081 |
|
child->flags = STMT_SUCCESS; |
1082 |
|
child->stack.copyFlatFrom(stack); |
1083 |
|
child->stackFrame = stackFrame; |
1084 |
|
child->suspendMicroseconds = 0; |
1085 |
|
child->instructionsCount = 0; |
1086 |
|
} |
1087 |
|
|
1088 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |