/[svn]/linuxsampler/trunk/src/scriptvm/tree.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/tree.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2948 by schoenebeck, Fri Jul 15 15:29:04 2016 UTC revision 3293 by schoenebeck, Tue Jun 27 22:19:19 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014 - 2016 Christian Schoenebeck and Andreas Persson   * Copyright (c) 2014 - 2017 Christian Schoenebeck and Andreas Persson
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 35  String IntExpr::evalCastToStr() { Line 35  String IntExpr::evalCastToStr() {
35      return ToString(evalInt());      return ToString(evalInt());
36  }  }
37    
38    String IntArrayExpr::evalCastToStr() {
39        String s = "{";
40        for (int i = 0; i < arraySize(); ++i) {
41            int val = evalIntElement(i);
42            if (i) s += ",";
43            s += ToString(val);
44        }
45        s += "}";
46        return s;
47    }
48    
49  int IntLiteral::evalInt() {  int IntLiteral::evalInt() {
50      return value;      return value;
51  }  }
# Line 313  int FunctionCall::evalInt() { Line 324  int FunctionCall::evalInt() {
324      return intExpr->evalInt();      return intExpr->evalInt();
325  }  }
326    
327    VMIntArrayExpr* FunctionCall::asIntArray() const {
328        VMFnResult* result = const_cast<FunctionCall*>(this)->execVMFn();
329        if (!result) return 0;
330        VMIntArrayExpr* intArrExpr = dynamic_cast<VMIntArrayExpr*>(result->resultValue());
331        return intArrExpr;
332    }
333    
334  String FunctionCall::evalStr() {  String FunctionCall::evalStr() {
335      VMFnResult* result = execVMFn();      VMFnResult* result = execVMFn();
336      if (!result) return "";      if (!result) return "";
# Line 359  IntVariable::IntVariable(ParserContext* Line 377  IntVariable::IntVariable(ParserContext*
377    
378  void IntVariable::assign(Expression* expr) {  void IntVariable::assign(Expression* expr) {
379      IntExpr* intExpr = dynamic_cast<IntExpr*>(expr);      IntExpr* intExpr = dynamic_cast<IntExpr*>(expr);
380      if (intExpr)      if (intExpr) {
381          if (polyphonic)          if (polyphonic)
382              context->execContext->polyphonicIntMemory[memPos] = intExpr->evalInt();              context->execContext->polyphonicIntMemory[memPos] = intExpr->evalInt();
383          else          else
384              (*context->globalIntMemory)[memPos] = intExpr->evalInt();              (*context->globalIntMemory)[memPos] = intExpr->evalInt();
385        }
386  }  }
387    
388  int IntVariable::evalInt() {  int IntVariable::evalInt() {
# Line 444  IntArrayVariable::IntArrayVariable(Parse Line 463  IntArrayVariable::IntArrayVariable(Parse
463      memset(&values[0], 0, size * sizeof(int));      memset(&values[0], 0, size * sizeof(int));
464  }  }
465    
466  IntArrayVariable::IntArrayVariable(ParserContext* ctx, int size, ArgsRef values)  IntArrayVariable::IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst)
467      : Variable(ctx, 0, false)      : Variable(ctx, 0, _bConst)
468  {  {
469      this->values.resize(size);      this->values.resize(size);
470      for (int i = 0; i < values->argsCount(); ++i) {      for (int i = 0; i < values->argsCount(); ++i) {
# Line 502  void BuiltInIntArrayVariable::dump(int l Line 521  void BuiltInIntArrayVariable::dump(int l
521      printf("Built-In Int Array Variable '%s'\n", name.c_str());      printf("Built-In Int Array Variable '%s'\n", name.c_str());
522  }  }
523    
524  IntArrayElement::IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex)  IntArrayElement::IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex)
525      : IntVariable(NULL, false, false, 0), array(array), index(arrayIndex)      : IntVariable(NULL, false, false, 0), array(array), index(arrayIndex)
526  {      {    
527  }  }
# Line 705  bool While::evalLoopStartCondition() { Line 724  bool While::evalLoopStartCondition() {
724      return m_condition->evalInt();      return m_condition->evalInt();
725  }  }
726    
727    void SyncBlock::dump(int level) {
728        printIndents(level);
729        printf("sync {\n");
730        m_statements->dump(level+1);
731        printIndents(level);
732        printf("}\n");
733    }
734    
735    Statements* SyncBlock::statements() const {
736        return (m_statements) ? const_cast<Statements*>( &*m_statements ) : NULL;
737    }
738    
739  void Neg::dump(int level) {  void Neg::dump(int level) {
740      printIndents(level);      printIndents(level);
741      printf("Negative Expr\n");      printf("Negative Expr\n");
# Line 882  void BitwiseNot::dump(int level) { Line 913  void BitwiseNot::dump(int level) {
913      printf(")\n");      printf(")\n");
914  }  }
915    
916    StatementsRef ParserContext::userFunctionByName(const String& name) {
917        if (!userFnTable.count(name)) {
918            return StatementsRef();
919        }
920        return userFnTable.find(name)->second;
921    }
922    
923  VariableRef ParserContext::variableByName(const String& name) {  VariableRef ParserContext::variableByName(const String& name) {
924      if (!vartable.count(name)) {      if (!vartable.count(name)) {
925          return VariableRef();          return VariableRef();
# Line 939  void ParserContext::addWrn(int firstLine Line 977  void ParserContext::addWrn(int firstLine
977      vIssues.push_back(w);      vIssues.push_back(w);
978  }  }
979    
980    void ParserContext::addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn) {
981        CodeBlock block;
982        block.firstLine = firstLine;
983        block.lastLine = lastLine;
984        block.firstColumn = firstColumn;
985        block.lastColumn = lastColumn;
986        vPreprocessorComments.push_back(block);
987    }
988    
989  bool ParserContext::setPreprocessorCondition(const char* name) {  bool ParserContext::setPreprocessorCondition(const char* name) {
990      if (builtinPreprocessorConditions.count(name)) return false;      if (builtinPreprocessorConditions.count(name)) return false;
991      if (userPreprocessorConditions.count(name)) return false;      if (userPreprocessorConditions.count(name)) return false;
# Line 970  std::vector<ParserIssue> ParserContext:: Line 1017  std::vector<ParserIssue> ParserContext::
1017      return vWarnings;      return vWarnings;
1018  }  }
1019    
1020    std::vector<CodeBlock> ParserContext::preprocessorComments() const {
1021        return vPreprocessorComments;
1022    }
1023    
1024  VMEventHandler* ParserContext::eventHandler(uint index) {  VMEventHandler* ParserContext::eventHandler(uint index) {
1025      if (!handlers) return NULL;      if (!handlers) return NULL;
1026      return handlers->eventHandler(index);      return handlers->eventHandler(index);
# Line 1016  void ParserContext::registerBuiltInDynVa Line 1067  void ParserContext::registerBuiltInDynVa
1067      }      }
1068  }  }
1069    
1070    void ExecContext::forkTo(VMExecContext* ectx) const {
1071        ExecContext* child = dynamic_cast<ExecContext*>(ectx);
1072    
1073        child->polyphonicIntMemory.copyFlatFrom(polyphonicIntMemory);
1074        child->status = VM_EXEC_SUSPENDED;
1075        child->flags = STMT_SUCCESS;
1076        child->stack.copyFlatFrom(stack);
1077        child->stackFrame = stackFrame;
1078        child->suspendMicroseconds = 0;
1079        child->instructionsCount = 0;
1080    }
1081    
1082  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2948  
changed lines
  Added in v.3293

  ViewVC Help
Powered by ViewVC