/[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 3744 by schoenebeck, Sat Feb 15 11:50:02 2020 UTC revision 3836 by schoenebeck, Sat Nov 28 14:47:14 2020 UTC
# Line 501  StmtFlags_t Assignment::exec() { Line 501  StmtFlags_t Assignment::exec() {
501      return STMT_SUCCESS;      return STMT_SUCCESS;
502  }  }
503    
504  EventHandler::EventHandler(StatementsRef statements) {  Subroutine::Subroutine(StatementsRef statements) {
505      this->statements = statements;      this->statements = statements;
506    }
507    
508    void Subroutine::dump(int level) {
509        printIndents(level);
510        printf("Subroutine {\n");
511        statements->dump(level+1);
512        printIndents(level);
513        printf("}\n");
514    }
515    
516    UserFunction::UserFunction(StatementsRef statements)
517        : Subroutine(statements)
518    {
519    }
520    
521    EventHandler::EventHandler(StatementsRef statements)
522        : Subroutine(statements)
523    {
524      usingPolyphonics = statements->isPolyphonic();      usingPolyphonics = statements->isPolyphonic();
525  }  }
526    
527  void EventHandler::dump(int level) {  void EventHandler::dump(int level) {
528      printIndents(level);      printIndents(level);
529      printf("EventHandler {\n");      printf("EventHandler {\n");
530      statements->dump(level+1);      Subroutine::dump(level+1);
531      printIndents(level);      printIndents(level);
532      printf("}\n");      printf("}\n");
533  }  }
# Line 576  FunctionCall::FunctionCall(const char* f Line 594  FunctionCall::FunctionCall(const char* f
594      Unit(      Unit(
595          (fn) ? fn->returnUnitType(dynamic_cast<VMFnArgs*>(&*args)) : VM_NO_UNIT          (fn) ? fn->returnUnitType(dynamic_cast<VMFnArgs*>(&*args)) : VM_NO_UNIT
596      ),      ),
597      functionName(function), args(args), fn(fn), result(NULL)      functionName(function), args(args), fn(fn),
598        result( (fn) ? fn->allocResult(dynamic_cast<VMFnArgs*>(&*args)) : NULL )
599  {  {
600  }  }
601    
602    FunctionCall::~FunctionCall() {
603        if (result) {
604            delete result;
605            result = NULL;
606        }
607    }
608    
609  void FunctionCall::dump(int level) {  void FunctionCall::dump(int level) {
610      printIndents(level);      printIndents(level);
611      printf("FunctionCall '%s' args={\n", functionName.c_str());      printf("FunctionCall '%s' args={\n", functionName.c_str());
# Line 611  bool FunctionCall::isFinal() const { Line 637  bool FunctionCall::isFinal() const {
637    
638  VMFnResult* FunctionCall::execVMFn() {  VMFnResult* FunctionCall::execVMFn() {
639      if (!fn) return NULL;      if (!fn) return NULL;
640    
641        // tell function where it shall dump its return value to
642        VMFnResult* oldRes = fn->boundResult();
643        fn->bindResult(result);
644    
645      // assuming here that all argument checks (amount and types) have been made      // assuming here that all argument checks (amount and types) have been made
646      // at parse time, to avoid time intensive checks on each function call      // at parse time, to avoid time intensive checks on each function call
647      VMFnResult* res = fn->exec(dynamic_cast<VMFnArgs*>(&*args));      VMFnResult* res = fn->exec(dynamic_cast<VMFnArgs*>(&*args));
648    
649        // restore previous result binding of some potential toplevel or concurrent
650        // caller, i.e. if exactly same function is called more than one time,
651        // concurrently in a term by other FunctionCall objects, e.g.:
652        // ~c := ceil( ceil(~a) + ~b)
653        fn->bindResult(oldRes);
654    
655      if (!res) return res;      if (!res) return res;
656    
657      VMExpr* expr = res->resultValue();      VMExpr* expr = res->resultValue();
# Line 636  VMFnResult* FunctionCall::execVMFn() { Line 674  VMFnResult* FunctionCall::execVMFn() {
674  }  }
675    
676  StmtFlags_t FunctionCall::exec() {  StmtFlags_t FunctionCall::exec() {
677      result = execVMFn();      VMFnResult* result = execVMFn();
678      if (!result)      if (!result)
679          return StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);          return StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);
680      return result->resultFlags();      return result->resultFlags();
681  }  }
682    
683  vmint FunctionCall::evalInt() {  vmint FunctionCall::evalInt() {
684      result = execVMFn();      VMFnResult* result = execVMFn();
685      if (!result) return 0;      if (!result) return 0;
686      VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue());      VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue());
687      if (!intExpr) return 0;      if (!intExpr) return 0;
# Line 651  vmint FunctionCall::evalInt() { Line 689  vmint FunctionCall::evalInt() {
689  }  }
690    
691  vmfloat FunctionCall::evalReal() {  vmfloat FunctionCall::evalReal() {
692      result = execVMFn();      VMFnResult* result = execVMFn();
693      if (!result) return 0;      if (!result) return 0;
694      VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue());      VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue());
695      if (!realExpr) return 0;      if (!realExpr) return 0;
# Line 666  VMIntArrayExpr* FunctionCall::asIntArray Line 704  VMIntArrayExpr* FunctionCall::asIntArray
704      // calls to be evaluated at all. This issue should be addressed cleanly by      // calls to be evaluated at all. This issue should be addressed cleanly by
705      // adjusting the API appropriately.      // adjusting the API appropriately.
706      FunctionCall* rwSelf = const_cast<FunctionCall*>(this);      FunctionCall* rwSelf = const_cast<FunctionCall*>(this);
707      rwSelf->result = rwSelf->execVMFn();      VMFnResult* result = rwSelf->execVMFn();
708    
709      if (!result) return 0;      if (!result) return 0;
710      VMIntArrayExpr* intArrExpr = dynamic_cast<VMIntArrayExpr*>(result->resultValue());      VMIntArrayExpr* intArrExpr = dynamic_cast<VMIntArrayExpr*>(result->resultValue());
# Line 681  VMRealArrayExpr* FunctionCall::asRealArr Line 719  VMRealArrayExpr* FunctionCall::asRealArr
719      // calls to be evaluated at all. This issue should be addressed cleanly by      // calls to be evaluated at all. This issue should be addressed cleanly by
720      // adjusting the API appropriately.      // adjusting the API appropriately.
721      FunctionCall* rwSelf = const_cast<FunctionCall*>(this);      FunctionCall* rwSelf = const_cast<FunctionCall*>(this);
722      rwSelf->result = rwSelf->execVMFn();      VMFnResult* result = rwSelf->execVMFn();
723    
724      if (!result) return 0;      if (!result) return 0;
725      VMRealArrayExpr* realArrExpr = dynamic_cast<VMRealArrayExpr*>(result->resultValue());      VMRealArrayExpr* realArrExpr = dynamic_cast<VMRealArrayExpr*>(result->resultValue());
# Line 689  VMRealArrayExpr* FunctionCall::asRealArr Line 727  VMRealArrayExpr* FunctionCall::asRealArr
727  }  }
728    
729  String FunctionCall::evalStr() {  String FunctionCall::evalStr() {
730      result = execVMFn();      VMFnResult* result = execVMFn();
731      if (!result) return "";      if (!result) return "";
732      VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(result->resultValue());      VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(result->resultValue());
733      if (!strExpr) return "";      if (!strExpr) return "";
# Line 697  String FunctionCall::evalStr() { Line 735  String FunctionCall::evalStr() {
735  }  }
736    
737  String FunctionCall::evalCastToStr() {  String FunctionCall::evalCastToStr() {
738      result = execVMFn();      VMFnResult* result = execVMFn();
739      if (!result) return "";      if (!result) return "";
740      const ExprType_t resultType = result->resultValue()->exprType();      const ExprType_t resultType = result->resultValue()->exprType();
741      if (resultType == STRING_EXPR) {      if (resultType == STRING_EXPR) {
# Line 1026  IntArrayVariable::IntArrayVariable(Parse Line 1064  IntArrayVariable::IntArrayVariable(Parse
1064          if (expr) {          if (expr) {
1065              this->values[i] = expr->evalInt();              this->values[i] = expr->evalInt();
1066              this->unitFactors[i] = expr->unitFactor();              this->unitFactors[i] = expr->unitFactor();
1067            } else {
1068                this->values[i] = 0;
1069                this->unitFactors[i] = VM_NO_FACTOR;
1070          }          }
1071      }      }
1072        for (vmint i = values->argsCount(); i < size; ++i) {
1073            this->values[i] = 0;
1074            this->unitFactors[i] = VM_NO_FACTOR;
1075        }
1076  }  }
1077    
1078  IntArrayVariable::IntArrayVariable(ParserContext* ctx, bool bConst) :  IntArrayVariable::IntArrayVariable(ParserContext* ctx, bool bConst) :
# Line 1118  RealArrayVariable::RealArrayVariable(Par Line 1163  RealArrayVariable::RealArrayVariable(Par
1163          if (expr) {          if (expr) {
1164              this->values[i] = expr->evalReal();              this->values[i] = expr->evalReal();
1165              this->unitFactors[i] = expr->unitFactor();              this->unitFactors[i] = expr->unitFactor();
1166            } else {
1167                this->values[i] = (vmfloat) 0;
1168                this->unitFactors[i] = VM_NO_FACTOR;
1169          }          }
1170      }      }
1171        for (vmint i = values->argsCount(); i < size; ++i) {
1172            this->values[i] = (vmfloat) 0;
1173            this->unitFactors[i] = VM_NO_FACTOR;
1174        }
1175  }  }
1176    
1177  RealArrayVariable::RealArrayVariable(ParserContext* ctx, bool bConst) :  RealArrayVariable::RealArrayVariable(ParserContext* ctx, bool bConst) :
# Line 1784  void Final::dump(int level) { Line 1836  void Final::dump(int level) {
1836      printf(")\n");      printf(")\n");
1837  }  }
1838    
1839  StatementsRef ParserContext::userFunctionByName(const String& name) {  UserFunctionRef ParserContext::userFunctionByName(const String& name) {
1840      if (!userFnTable.count(name)) {      if (!userFnTable.count(name)) {
1841          return StatementsRef();          return UserFunctionRef();
1842      }      }
1843      return userFnTable.find(name)->second;      return userFnTable.find(name)->second;
1844  }  }
# Line 1830  ParserContext::~ParserContext() { Line 1882  ParserContext::~ParserContext() {
1882          delete globalRealMemory;          delete globalRealMemory;
1883          globalRealMemory = NULL;          globalRealMemory = NULL;
1884      }      }
1885        for (void* data : vAutoFreeAfterParse)
1886            free(data);
1887        vAutoFreeAfterParse.clear();
1888  }  }
1889    
1890  void ParserContext::addErr(int firstLine, int lastLine, int firstColumn,  void ParserContext::addErr(int firstLine, int lastLine, int firstColumn,
# Line 1899  bool ParserContext::isPreprocessorCondit Line 1954  bool ParserContext::isPreprocessorCondit
1954      return userPreprocessorConditions.count(name);      return userPreprocessorConditions.count(name);
1955  }  }
1956    
1957    void ParserContext::autoFreeAfterParse(void* data) {
1958        vAutoFreeAfterParse.push_back(data);
1959    }
1960    
1961  std::vector<ParserIssue> ParserContext::issues() const {  std::vector<ParserIssue> ParserContext::issues() const {
1962      return vIssues;      return vIssues;
1963  }  }

Legend:
Removed from v.3744  
changed lines
  Added in v.3836

  ViewVC Help
Powered by ViewVC