/[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 3585 by schoenebeck, Fri Aug 30 17:51:24 2019 UTC revision 3804 by schoenebeck, Thu Aug 6 12:15:02 2020 UTC
# Line 13  Line 13 
13  #include "../common/global_private.h"  #include "../common/global_private.h"
14  #include "../common/RTMath.h"  #include "../common/RTMath.h"
15  #include <assert.h>  #include <assert.h>
16    #include "CoreVMFunctions.h" // for VMIntResult, VMRealResult
17    
18  namespace LinuxSampler {  namespace LinuxSampler {
19            
# Line 122  static String _unitFactorToShortStr(vmfl Line 123  static String _unitFactorToShortStr(vmfl
123      }      }
124  }  }
125    
126  static String _unitToStr(Unit* unit) {  static String _unitToStr(VMUnit* unit) {
127      const StdUnit_t type = unit->unitType();      const StdUnit_t type = unit->unitType();
128      String sType;      String sType;
129      switch (type) {      switch (type) {
# Line 188  vmint IntLiteral::evalInt() { Line 189  vmint IntLiteral::evalInt() {
189    
190  void IntLiteral::dump(int level) {  void IntLiteral::dump(int level) {
191      printIndents(level);      printIndents(level);
192      printf("IntLiteral %lld\n", value);      printf("IntLiteral %" PRId64 "\n", (int64_t)value);
193  }  }
194    
195  RealLiteral::RealLiteral(const RealLitDef& def) :  RealLiteral::RealLiteral(const RealLitDef& def) :
# Line 500  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 575  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 610  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      return 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;
656    
657        VMExpr* expr = res->resultValue();
658        if (!expr) return res;
659    
660        // For performance reasons we always only let 'FunctionCall' assign the unit
661        // type to the function's result expression, never by the function
662        // implementation itself, nor by other classes, because a FunctionCall
663        // object solely knows the unit type in O(1).
664        ExprType_t type = expr->exprType();
665        if (type == INT_EXPR) {
666            VMIntResult* intRes = dynamic_cast<VMIntResult*>(res);
667            intRes->unitBaseType = unitType();
668        } else if (type == REAL_EXPR) {
669            VMRealResult* realRes = dynamic_cast<VMRealResult*>(res);
670            realRes->unitBaseType = unitType();
671        }
672    
673        return res;
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 631  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 639  vmfloat FunctionCall::evalReal() { Line 697  vmfloat FunctionCall::evalReal() {
697  }  }
698    
699  VMIntArrayExpr* FunctionCall::asIntArray() const {  VMIntArrayExpr* FunctionCall::asIntArray() const {
700        //FIXME: asIntArray() not intended for evaluation semantics (for both
701        // performance reasons with arrays, but also to prevent undesired value
702        // mutation by implied (hidden) evaluation, as actually done here. We must
703        // force function evaluation here though, because we need it for function
704        // calls to be evaluated at all. This issue should be addressed cleanly by
705        // adjusting the API appropriately.
706        FunctionCall* rwSelf = const_cast<FunctionCall*>(this);
707        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());
711      return intArrExpr;      return intArrExpr;
712  }  }
713    
714  VMRealArrayExpr* FunctionCall::asRealArray() const {  VMRealArrayExpr* FunctionCall::asRealArray() const {
715        //FIXME: asRealArray() not intended for evaluation semantics (for both
716        // performance reasons with arrays, but also to prevent undesired value
717        // mutation by implied (hidden) evaluation, as actually done here. We must
718        // force function evaluation here though, because we need it for function
719        // calls to be evaluated at all. This issue should be addressed cleanly by
720        // adjusting the API appropriately.
721        FunctionCall* rwSelf = const_cast<FunctionCall*>(this);
722        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());
726      return realArrExpr;      return realArrExpr;
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 659  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 667  String FunctionCall::evalCastToStr() { Line 743  String FunctionCall::evalCastToStr() {
743          return strExpr ? strExpr->evalStr() : "";          return strExpr ? strExpr->evalStr() : "";
744      } else if (resultType == REAL_EXPR) {      } else if (resultType == REAL_EXPR) {
745          VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue());          VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue());
746          return realExpr ? ToString(realExpr->evalReal()) : "";          return realExpr ? ToString(realExpr->evalReal()) + _unitToStr(realExpr) : "";
747      } else {      } else {
748          VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue());          VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue());
749          return intExpr ? ToString(intExpr->evalInt()) : "";          return intExpr ? ToString(intExpr->evalInt()) + _unitToStr(intExpr) : "";
750      }      }
751  }  }
752    
# Line 705  IntVariable::IntVariable(const VariableD Line 781  IntVariable::IntVariable(const VariableD
781          .ctx = decl.ctx,          .ctx = decl.ctx,
782          .isPolyphonic = decl.isPolyphonic,          .isPolyphonic = decl.isPolyphonic,
783          .isConst = decl.isConst,          .isConst = decl.isConst,
         .isFinal = decl.isFinal,  
784          .elements = decl.elements,          .elements = decl.elements,
785          .memPos = (          .memPos = (
786              (!decl.ctx) ? 0 :              (!decl.ctx) ? 0 :
# Line 719  IntVariable::IntVariable(const VariableD Line 794  IntVariable::IntVariable(const VariableD
794                      postfixInc(decl.ctx->polyphonicUnitFactorCount, decl.elements) :                      postfixInc(decl.ctx->polyphonicUnitFactorCount, decl.elements) :
795                      postfixInc(decl.ctx->globalUnitFactorCount, decl.elements)                      postfixInc(decl.ctx->globalUnitFactorCount, decl.elements)
796          ),          ),
797          .unitType = decl.unitType          .unitType = decl.unitType,
798            .isFinal = decl.isFinal,
799      }),      }),
800      Unit(decl.unitType)      Unit(decl.unitType)
801  {  {
# Line 761  RealVariable::RealVariable(const Variabl Line 837  RealVariable::RealVariable(const Variabl
837          .ctx = decl.ctx,          .ctx = decl.ctx,
838          .isPolyphonic = decl.isPolyphonic,          .isPolyphonic = decl.isPolyphonic,
839          .isConst = decl.isConst,          .isConst = decl.isConst,
         .isFinal = decl.isFinal,  
840          .elements = decl.elements,          .elements = decl.elements,
841          .memPos = (          .memPos = (
842              (!decl.ctx) ? 0 :              (!decl.ctx) ? 0 :
# Line 775  RealVariable::RealVariable(const Variabl Line 850  RealVariable::RealVariable(const Variabl
850                      postfixInc(decl.ctx->polyphonicUnitFactorCount, decl.elements) :                      postfixInc(decl.ctx->polyphonicUnitFactorCount, decl.elements) :
851                      postfixInc(decl.ctx->globalUnitFactorCount, decl.elements)                      postfixInc(decl.ctx->globalUnitFactorCount, decl.elements)
852          ),          ),
853          .unitType = decl.unitType          .unitType = decl.unitType,
854            .isFinal = decl.isFinal,
855      }),      }),
856      Unit(decl.unitType)      Unit(decl.unitType)
857  {  {
# Line 817  ConstIntVariable::ConstIntVariable(const Line 893  ConstIntVariable::ConstIntVariable(const
893          .ctx = def.ctx,          .ctx = def.ctx,
894          .isPolyphonic = false,          .isPolyphonic = false,
895          .isConst = true,          .isConst = true,
         .isFinal = def.isFinal,  
896          .elements = 1,          .elements = 1,
897          .memPos = def.memPos,          .memPos = def.memPos,
898          .unitFactorMemPos = def.unitFactorMemPos,          .unitFactorMemPos = def.unitFactorMemPos,
899          .unitType = def.unitType          .unitType = def.unitType,
900            .isFinal = def.isFinal,
901      }),      }),
902      Unit(def.unitType),      Unit(def.unitType),
903      value(def.value), unitPrefixFactor(def.unitFactor)      value(def.value), unitPrefixFactor(def.unitFactor)
# Line 845  vmint ConstIntVariable::evalInt() { Line 921  vmint ConstIntVariable::evalInt() {
921    
922  void ConstIntVariable::dump(int level) {  void ConstIntVariable::dump(int level) {
923      printIndents(level);      printIndents(level);
924      printf("ConstIntVariable val=%lld\n", value);      printf("ConstIntVariable val=%" PRId64 "\n", (int64_t)value);
925  }  }
926    
927  ConstRealVariable::ConstRealVariable(const RealVarDef& def) :  ConstRealVariable::ConstRealVariable(const RealVarDef& def) :
# Line 853  ConstRealVariable::ConstRealVariable(con Line 929  ConstRealVariable::ConstRealVariable(con
929          .ctx = def.ctx,          .ctx = def.ctx,
930          .isPolyphonic = false,          .isPolyphonic = false,
931          .isConst = true,          .isConst = true,
         .isFinal = def.isFinal,  
932          .elements = 1,          .elements = 1,
933          .memPos = def.memPos,          .memPos = def.memPos,
934          .unitFactorMemPos = def.unitFactorMemPos,          .unitFactorMemPos = def.unitFactorMemPos,
935          .unitType = def.unitType          .unitType = def.unitType,
936            .isFinal = def.isFinal,
937      }),      }),
938      Unit(def.unitType),      Unit(def.unitType),
939      value(def.value), unitPrefixFactor(def.unitFactor)      value(def.value), unitPrefixFactor(def.unitFactor)
# Line 882  BuiltInIntVariable::BuiltInIntVariable(c Line 958  BuiltInIntVariable::BuiltInIntVariable(c
958          .ctx = NULL,          .ctx = NULL,
959          .isPolyphonic = false,          .isPolyphonic = false,
960          .isConst = false, // may or may not be modifyable though!          .isConst = false, // may or may not be modifyable though!
         .isFinal = false,  
961          .elements = 0,          .elements = 0,
962          .memPos = 0,          .memPos = 0,
963          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
964          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
965            .isFinal = false,
966      }),      }),
967      Unit(VM_NO_UNIT),      Unit(VM_NO_UNIT),
968      name(name), ptr(ptr)      name(name), ptr(ptr)
# Line 913  PolyphonicIntVariable::PolyphonicIntVari Line 989  PolyphonicIntVariable::PolyphonicIntVari
989          .ctx = decl.ctx,          .ctx = decl.ctx,
990          .isPolyphonic = true,          .isPolyphonic = true,
991          .isConst = decl.isConst,          .isConst = decl.isConst,
         .isFinal = decl.isFinal,  
992          .elements = 1,          .elements = 1,
993          .memPos = 0,          .memPos = 0,
994          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
995          .unitType = decl.unitType          .unitType = decl.unitType,
996            .isFinal = decl.isFinal,
997      }),      }),
998      Unit(decl.unitType)      Unit(decl.unitType)
999  {  {
# Line 933  PolyphonicRealVariable::PolyphonicRealVa Line 1009  PolyphonicRealVariable::PolyphonicRealVa
1009          .ctx = decl.ctx,          .ctx = decl.ctx,
1010          .isPolyphonic = true,          .isPolyphonic = true,
1011          .isConst = decl.isConst,          .isConst = decl.isConst,
         .isFinal = decl.isFinal,  
1012          .elements = 1,          .elements = 1,
1013          .memPos = 0,          .memPos = 0,
1014          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1015          .unitType = decl.unitType          .unitType = decl.unitType,
1016            .isFinal = decl.isFinal,
1017      }),      }),
1018      Unit(decl.unitType)      Unit(decl.unitType)
1019  {  {
# Line 953  IntArrayVariable::IntArrayVariable(Parse Line 1029  IntArrayVariable::IntArrayVariable(Parse
1029          .ctx = ctx,          .ctx = ctx,
1030          .isPolyphonic = false,          .isPolyphonic = false,
1031          .isConst = false,          .isConst = false,
         .isFinal = false,  
1032          .elements = 0,          .elements = 0,
1033          .memPos = 0,          .memPos = 0,
1034          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1035          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1036            .isFinal = false,
1037      })      })
1038  {  {
1039      values.resize(size);      values.resize(size);
# Line 974  IntArrayVariable::IntArrayVariable(Parse Line 1050  IntArrayVariable::IntArrayVariable(Parse
1050          .ctx = ctx,          .ctx = ctx,
1051          .isPolyphonic = false,          .isPolyphonic = false,
1052          .isConst = _bConst,          .isConst = _bConst,
         .isFinal = false,  
1053          .elements = 0,          .elements = 0,
1054          .memPos = 0,          .memPos = 0,
1055          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1056          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1057            .isFinal = false,
1058      })      })
1059  {  {
1060      this->values.resize(size);      this->values.resize(size);
# Line 988  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 997  IntArrayVariable::IntArrayVariable(Parse Line 1080  IntArrayVariable::IntArrayVariable(Parse
1080          .ctx = ctx,          .ctx = ctx,
1081          .isPolyphonic = false,          .isPolyphonic = false,
1082          .isConst = bConst,          .isConst = bConst,
         .isFinal = false,  
1083          .elements = 0,          .elements = 0,
1084          .memPos = 0,          .memPos = 0,
1085          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1086          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1087            .isFinal = false,
1088      })      })
1089  {  {
1090  }  }
# Line 1034  void IntArrayVariable::dump(int level) { Line 1117  void IntArrayVariable::dump(int level) {
1117              printf("\n");              printf("\n");
1118              printIndents(level+1);              printIndents(level+1);
1119          }          }
1120          printf("%lld, ", values[i]);          printf("%" PRId64 ", ", (int64_t)values[i]);
1121      }      }
1122      printIndents(level);      printIndents(level);
1123      printf(")\n");      printf(")\n");
# Line 1045  RealArrayVariable::RealArrayVariable(Par Line 1128  RealArrayVariable::RealArrayVariable(Par
1128          .ctx = ctx,          .ctx = ctx,
1129          .isPolyphonic = false,          .isPolyphonic = false,
1130          .isConst = false,          .isConst = false,
         .isFinal = false,  
1131          .elements = 0,          .elements = 0,
1132          .memPos = 0,          .memPos = 0,
1133          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1134          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1135            .isFinal = false,
1136      })      })
1137  {  {
1138      values.resize(size);      values.resize(size);
# Line 1066  RealArrayVariable::RealArrayVariable(Par Line 1149  RealArrayVariable::RealArrayVariable(Par
1149          .ctx = ctx,          .ctx = ctx,
1150          .isPolyphonic = false,          .isPolyphonic = false,
1151          .isConst = _bConst,          .isConst = _bConst,
         .isFinal = false,  
1152          .elements = 0,          .elements = 0,
1153          .memPos = 0,          .memPos = 0,
1154          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1155          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1156            .isFinal = false,
1157      })      })
1158  {  {
1159      this->values.resize(size);      this->values.resize(size);
# Line 1080  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 1089  RealArrayVariable::RealArrayVariable(Par Line 1179  RealArrayVariable::RealArrayVariable(Par
1179          .ctx = ctx,          .ctx = ctx,
1180          .isPolyphonic = false,          .isPolyphonic = false,
1181          .isConst = bConst,          .isConst = bConst,
         .isFinal = false,  
1182          .elements = 0,          .elements = 0,
1183          .memPos = 0,          .memPos = 0,
1184          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1185          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1186            .isFinal = false,
1187      })      })
1188  {  {
1189  }  }
# Line 1158  IntArrayElement::IntArrayElement(IntArra Line 1248  IntArrayElement::IntArrayElement(IntArra
1248          .ctx = NULL,          .ctx = NULL,
1249          .isPolyphonic = (array) ? array->isPolyphonic() : false,          .isPolyphonic = (array) ? array->isPolyphonic() : false,
1250          .isConst = (array) ? array->isConstExpr() : false,          .isConst = (array) ? array->isConstExpr() : false,
         .isFinal = false,  
1251          .elements = 0,          .elements = 0,
1252          .memPos = 0,          .memPos = 0,
1253          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1254          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1255            .isFinal = false,
1256      }),      }),
1257      Unit(VM_NO_UNIT),      Unit(VM_NO_UNIT),
1258      array(array), index(arrayIndex), currentIndex(-1)      array(array), index(arrayIndex), currentIndex(-1)
1259  {      {
1260  }  }
1261    
1262  void IntArrayElement::assign(Expression* expr) {  void IntArrayElement::assign(Expression* expr) {
# Line 1209  RealArrayElement::RealArrayElement(RealA Line 1299  RealArrayElement::RealArrayElement(RealA
1299          .ctx = NULL,          .ctx = NULL,
1300          .isPolyphonic = (array) ? array->isPolyphonic() : false,          .isPolyphonic = (array) ? array->isPolyphonic() : false,
1301          .isConst = (array) ? array->isConstExpr() : false,          .isConst = (array) ? array->isConstExpr() : false,
         .isFinal = false,  
1302          .elements = 0,          .elements = 0,
1303          .memPos = 0,          .memPos = 0,
1304          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1305          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1306            .isFinal = false,
1307      }),      }),
1308      Unit(VM_NO_UNIT),      Unit(VM_NO_UNIT),
1309      array(array), index(arrayIndex), currentIndex(-1)      array(array), index(arrayIndex), currentIndex(-1)
# Line 1267  StringVariable::StringVariable(ParserCon Line 1357  StringVariable::StringVariable(ParserCon
1357  StringVariable::StringVariable(ParserContext* ctx, bool bConst) :  StringVariable::StringVariable(ParserContext* ctx, bool bConst) :
1358      Variable({      Variable({
1359          .ctx = ctx,          .ctx = ctx,
1360            .isConst = bConst,
1361          .memPos = 0,          .memPos = 0,
         .isConst = bConst  
1362      })      })
1363  {  {
1364  }  }
# Line 1285  String StringVariable::evalStr() { Line 1375  String StringVariable::evalStr() {
1375    
1376  void StringVariable::dump(int level) {  void StringVariable::dump(int level) {
1377      printIndents(level);      printIndents(level);
1378      printf("StringVariable memPos=%lld\n", memPos);      printf("StringVariable memPos=%" PRId64 "\n", (int64_t)memPos);
1379  }  }
1380    
1381  ConstStringVariable::ConstStringVariable(ParserContext* ctx, String _value)  ConstStringVariable::ConstStringVariable(ParserContext* ctx, String _value)
# Line 1355  void SelectCase::dump(int level) { Line 1445  void SelectCase::dump(int level) {
1445      printIndents(level);      printIndents(level);
1446      if (select)      if (select)
1447          if (select->isConstExpr())          if (select->isConstExpr())
1448              printf("Case select %lld\n", select->evalInt());              printf("Case select %" PRId64 "\n", (int64_t)select->evalInt());
1449          else          else
1450              printf("Case select [runtime expr]\n");              printf("Case select [runtime expr]\n");
1451      else      else
# Line 1365  void SelectCase::dump(int level) { Line 1455  void SelectCase::dump(int level) {
1455          CaseBranch& branch = branches[i];          CaseBranch& branch = branches[i];
1456          if (branch.from && branch.to)          if (branch.from && branch.to)
1457              if (branch.from->isConstExpr() && branch.to->isConstExpr())              if (branch.from->isConstExpr() && branch.to->isConstExpr())
1458                  printf("case %lld to %lld\n", branch.from->evalInt(), branch.to->evalInt());                  printf("case %" PRId64 " to %" PRId64 "\n", (int64_t)branch.from->evalInt(), (int64_t)branch.to->evalInt());
1459              else if (branch.from->isConstExpr() && !branch.to->isConstExpr())              else if (branch.from->isConstExpr() && !branch.to->isConstExpr())
1460                  printf("case %lld to [runtime expr]\n", branch.from->evalInt());                  printf("case %" PRId64 " to [runtime expr]\n", (int64_t)branch.from->evalInt());
1461              else if (!branch.from->isConstExpr() && branch.to->isConstExpr())              else if (!branch.from->isConstExpr() && branch.to->isConstExpr())
1462                  printf("case [runtime expr] to %lld\n", branch.to->evalInt());                  printf("case [runtime expr] to %" PRId64 "\n", (int64_t)branch.to->evalInt());
1463              else              else
1464                  printf("case [runtime expr] to [runtime expr]\n");                  printf("case [runtime expr] to [runtime expr]\n");
1465          else if (branch.from)          else if (branch.from)
1466              if (branch.from->isConstExpr())              if (branch.from->isConstExpr())
1467                  printf("case %lld\n", branch.from->evalInt());                  printf("case %" PRId64 "\n", (int64_t)branch.from->evalInt());
1468              else              else
1469                  printf("case [runtime expr]\n");                  printf("case [runtime expr]\n");
1470          else          else
# Line 1413  void While::dump(int level) { Line 1503  void While::dump(int level) {
1503      printIndents(level);      printIndents(level);
1504      if (m_condition)      if (m_condition)
1505          if (m_condition->isConstExpr())          if (m_condition->isConstExpr())
1506              printf("while (%lld) {\n", m_condition->evalInt());              printf("while (%" PRId64 ") {\n", (int64_t)m_condition->evalInt());
1507          else          else
1508              printf("while ([runtime expr]) {\n");              printf("while ([runtime expr]) {\n");
1509      else      else
# Line 1746  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 1794  ParserContext::~ParserContext() { Line 1884  ParserContext::~ParserContext() {
1884      }      }
1885  }  }
1886    
1887  void ParserContext::addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt) {  void ParserContext::addErr(int firstLine, int lastLine, int firstColumn,
1888                               int lastColumn, int firstByte, int lengthBytes,
1889                               const char* txt)
1890    {
1891      ParserIssue e;      ParserIssue e;
1892      e.type = PARSER_ERROR;      e.type = PARSER_ERROR;
1893      e.txt = txt;      e.txt = txt;
# Line 1802  void ParserContext::addErr(int firstLine Line 1895  void ParserContext::addErr(int firstLine
1895      e.lastLine = lastLine;      e.lastLine = lastLine;
1896      e.firstColumn = firstColumn;      e.firstColumn = firstColumn;
1897      e.lastColumn = lastColumn;      e.lastColumn = lastColumn;
1898        e.firstByte = firstByte;
1899        e.lengthBytes = lengthBytes;
1900      vErrors.push_back(e);      vErrors.push_back(e);
1901      vIssues.push_back(e);      vIssues.push_back(e);
1902  }  }
1903    
1904  void ParserContext::addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt) {  void ParserContext::addWrn(int firstLine, int lastLine, int firstColumn,
1905                               int lastColumn, int firstByte, int lengthBytes,
1906                               const char* txt)
1907    {
1908      ParserIssue w;      ParserIssue w;
1909      w.type = PARSER_WARNING;      w.type = PARSER_WARNING;
1910      w.txt = txt;      w.txt = txt;
# Line 1814  void ParserContext::addWrn(int firstLine Line 1912  void ParserContext::addWrn(int firstLine
1912      w.lastLine = lastLine;      w.lastLine = lastLine;
1913      w.firstColumn = firstColumn;      w.firstColumn = firstColumn;
1914      w.lastColumn = lastColumn;      w.lastColumn = lastColumn;
1915        w.firstByte = firstByte;
1916        w.lengthBytes = lengthBytes;
1917      vWarnings.push_back(w);      vWarnings.push_back(w);
1918      vIssues.push_back(w);      vIssues.push_back(w);
1919  }  }
1920    
1921  void ParserContext::addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn) {  void ParserContext::addPreprocessorComment(int firstLine, int lastLine,
1922                                               int firstColumn, int lastColumn,
1923                                               int firstByte, int lengthBytes)
1924    {
1925      CodeBlock block;      CodeBlock block;
1926      block.firstLine = firstLine;      block.firstLine = firstLine;
1927      block.lastLine = lastLine;      block.lastLine = lastLine;
1928      block.firstColumn = firstColumn;      block.firstColumn = firstColumn;
1929      block.lastColumn = lastColumn;      block.lastColumn = lastColumn;
1930        block.firstByte = firstByte;
1931        block.lengthBytes = lengthBytes;
1932      vPreprocessorComments.push_back(block);      vPreprocessorComments.push_back(block);
1933  }  }
1934    
# Line 1880  void ParserContext::registerBuiltInConst Line 1985  void ParserContext::registerBuiltInConst
1985              .value = it->second              .value = it->second
1986          });          });
1987          vartable[it->first] = ref;          vartable[it->first] = ref;
1988        }
1989    }
1990    
1991    void ParserContext::registerBuiltInConstRealVariables(const std::map<String,vmfloat>& vars) {
1992        for (std::map<String,vmfloat>::const_iterator it = vars.begin();
1993             it != vars.end(); ++it)
1994        {
1995            ConstRealVariableRef ref = new ConstRealVariable({
1996                .value = it->second
1997            });
1998            vartable[it->first] = ref;
1999      }      }
2000  }  }
2001    

Legend:
Removed from v.3585  
changed lines
  Added in v.3804

  ViewVC Help
Powered by ViewVC