/[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 3582 by schoenebeck, Fri Aug 30 12:23:40 2019 UTC revision 3707 by schoenebeck, Wed Jan 8 21:21:58 2020 UTC
# Line 19  namespace LinuxSampler { Line 19  namespace LinuxSampler {
19  bool isNoOperation(StatementRef statement) {  bool isNoOperation(StatementRef statement) {
20      return statement->statementType() == STMT_NOOP;      return statement->statementType() == STMT_NOOP;
21  }  }
22    
23    String acceptedArgTypesStr(VMFunction* fn, vmint iArg) {
24        static const ExprType_t allTypes[] = {
25            INT_EXPR,
26            INT_ARR_EXPR,
27            REAL_EXPR,
28            REAL_ARR_EXPR,
29            STRING_EXPR,
30            STRING_ARR_EXPR,
31        };
32        const size_t nTypes = sizeof(allTypes) / sizeof(ExprType_t);
33    
34        std::vector<ExprType_t> supportedTypes;
35        for (int iType = 0; iType < nTypes; ++iType) {
36            const ExprType_t& type = allTypes[iType];
37            if (fn->acceptsArgType(iArg, type))
38                supportedTypes.push_back(type);
39        }
40        assert(!supportedTypes.empty());
41    
42        if (supportedTypes.size() == 1) {
43            return typeStr(*supportedTypes.begin());
44        } else {
45            String s = "either ";
46            for (size_t i = 0; i < supportedTypes.size(); ++i) {
47                const ExprType_t& type = supportedTypes[i];
48                if (i == 0) {
49                    s += typeStr(type);
50                } else if (i == supportedTypes.size() - 1) {
51                    s += " or " + typeStr(type);
52                } else {
53                    s += ", " + typeStr(type);
54                }
55            }
56            return s;
57        }
58    }
59            
60  Node::Node() {  Node::Node() {
61  }  }
# Line 151  vmint IntLiteral::evalInt() { Line 188  vmint IntLiteral::evalInt() {
188    
189  void IntLiteral::dump(int level) {  void IntLiteral::dump(int level) {
190      printIndents(level);      printIndents(level);
191      printf("IntLiteral %lld\n", value);      printf("IntLiteral %" PRId64 "\n", (int64_t)value);
192  }  }
193    
194  RealLiteral::RealLiteral(const RealLitDef& def) :  RealLiteral::RealLiteral(const RealLitDef& def) :
# Line 668  IntVariable::IntVariable(const VariableD Line 705  IntVariable::IntVariable(const VariableD
705          .ctx = decl.ctx,          .ctx = decl.ctx,
706          .isPolyphonic = decl.isPolyphonic,          .isPolyphonic = decl.isPolyphonic,
707          .isConst = decl.isConst,          .isConst = decl.isConst,
         .isFinal = decl.isFinal,  
708          .elements = decl.elements,          .elements = decl.elements,
709          .memPos = (          .memPos = (
710              (!decl.ctx) ? 0 :              (!decl.ctx) ? 0 :
# Line 682  IntVariable::IntVariable(const VariableD Line 718  IntVariable::IntVariable(const VariableD
718                      postfixInc(decl.ctx->polyphonicUnitFactorCount, decl.elements) :                      postfixInc(decl.ctx->polyphonicUnitFactorCount, decl.elements) :
719                      postfixInc(decl.ctx->globalUnitFactorCount, decl.elements)                      postfixInc(decl.ctx->globalUnitFactorCount, decl.elements)
720          ),          ),
721          .unitType = decl.unitType          .unitType = decl.unitType,
722            .isFinal = decl.isFinal,
723      }),      }),
724      Unit(decl.unitType)      Unit(decl.unitType)
725  {  {
# Line 724  RealVariable::RealVariable(const Variabl Line 761  RealVariable::RealVariable(const Variabl
761          .ctx = decl.ctx,          .ctx = decl.ctx,
762          .isPolyphonic = decl.isPolyphonic,          .isPolyphonic = decl.isPolyphonic,
763          .isConst = decl.isConst,          .isConst = decl.isConst,
         .isFinal = decl.isFinal,  
764          .elements = decl.elements,          .elements = decl.elements,
765          .memPos = (          .memPos = (
766              (!decl.ctx) ? 0 :              (!decl.ctx) ? 0 :
# Line 738  RealVariable::RealVariable(const Variabl Line 774  RealVariable::RealVariable(const Variabl
774                      postfixInc(decl.ctx->polyphonicUnitFactorCount, decl.elements) :                      postfixInc(decl.ctx->polyphonicUnitFactorCount, decl.elements) :
775                      postfixInc(decl.ctx->globalUnitFactorCount, decl.elements)                      postfixInc(decl.ctx->globalUnitFactorCount, decl.elements)
776          ),          ),
777          .unitType = decl.unitType          .unitType = decl.unitType,
778            .isFinal = decl.isFinal,
779      }),      }),
780      Unit(decl.unitType)      Unit(decl.unitType)
781  {  {
# Line 780  ConstIntVariable::ConstIntVariable(const Line 817  ConstIntVariable::ConstIntVariable(const
817          .ctx = def.ctx,          .ctx = def.ctx,
818          .isPolyphonic = false,          .isPolyphonic = false,
819          .isConst = true,          .isConst = true,
         .isFinal = def.isFinal,  
820          .elements = 1,          .elements = 1,
821          .memPos = def.memPos,          .memPos = def.memPos,
822          .unitFactorMemPos = def.unitFactorMemPos,          .unitFactorMemPos = def.unitFactorMemPos,
823          .unitType = def.unitType          .unitType = def.unitType,
824            .isFinal = def.isFinal,
825      }),      }),
826      Unit(def.unitType),      Unit(def.unitType),
827      value(def.value), unitPrefixFactor(def.unitFactor)      value(def.value), unitPrefixFactor(def.unitFactor)
# Line 808  vmint ConstIntVariable::evalInt() { Line 845  vmint ConstIntVariable::evalInt() {
845    
846  void ConstIntVariable::dump(int level) {  void ConstIntVariable::dump(int level) {
847      printIndents(level);      printIndents(level);
848      printf("ConstIntVariable val=%lld\n", value);      printf("ConstIntVariable val=%" PRId64 "\n", (int64_t)value);
849  }  }
850    
851  ConstRealVariable::ConstRealVariable(const RealVarDef& def) :  ConstRealVariable::ConstRealVariable(const RealVarDef& def) :
# Line 816  ConstRealVariable::ConstRealVariable(con Line 853  ConstRealVariable::ConstRealVariable(con
853          .ctx = def.ctx,          .ctx = def.ctx,
854          .isPolyphonic = false,          .isPolyphonic = false,
855          .isConst = true,          .isConst = true,
         .isFinal = def.isFinal,  
856          .elements = 1,          .elements = 1,
857          .memPos = def.memPos,          .memPos = def.memPos,
858          .unitFactorMemPos = def.unitFactorMemPos,          .unitFactorMemPos = def.unitFactorMemPos,
859          .unitType = def.unitType          .unitType = def.unitType,
860            .isFinal = def.isFinal,
861      }),      }),
862      Unit(def.unitType),      Unit(def.unitType),
863      value(def.value), unitPrefixFactor(def.unitFactor)      value(def.value), unitPrefixFactor(def.unitFactor)
# Line 845  BuiltInIntVariable::BuiltInIntVariable(c Line 882  BuiltInIntVariable::BuiltInIntVariable(c
882          .ctx = NULL,          .ctx = NULL,
883          .isPolyphonic = false,          .isPolyphonic = false,
884          .isConst = false, // may or may not be modifyable though!          .isConst = false, // may or may not be modifyable though!
         .isFinal = false,  
885          .elements = 0,          .elements = 0,
886          .memPos = 0,          .memPos = 0,
887          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
888          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
889            .isFinal = false,
890      }),      }),
891      Unit(VM_NO_UNIT),      Unit(VM_NO_UNIT),
892      name(name), ptr(ptr)      name(name), ptr(ptr)
# Line 876  PolyphonicIntVariable::PolyphonicIntVari Line 913  PolyphonicIntVariable::PolyphonicIntVari
913          .ctx = decl.ctx,          .ctx = decl.ctx,
914          .isPolyphonic = true,          .isPolyphonic = true,
915          .isConst = decl.isConst,          .isConst = decl.isConst,
         .isFinal = decl.isFinal,  
916          .elements = 1,          .elements = 1,
917          .memPos = 0,          .memPos = 0,
918          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
919          .unitType = decl.unitType          .unitType = decl.unitType,
920            .isFinal = decl.isFinal,
921      }),      }),
922      Unit(decl.unitType)      Unit(decl.unitType)
923  {  {
# Line 896  PolyphonicRealVariable::PolyphonicRealVa Line 933  PolyphonicRealVariable::PolyphonicRealVa
933          .ctx = decl.ctx,          .ctx = decl.ctx,
934          .isPolyphonic = true,          .isPolyphonic = true,
935          .isConst = decl.isConst,          .isConst = decl.isConst,
         .isFinal = decl.isFinal,  
936          .elements = 1,          .elements = 1,
937          .memPos = 0,          .memPos = 0,
938          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
939          .unitType = decl.unitType          .unitType = decl.unitType,
940            .isFinal = decl.isFinal,
941      }),      }),
942      Unit(decl.unitType)      Unit(decl.unitType)
943  {  {
# Line 916  IntArrayVariable::IntArrayVariable(Parse Line 953  IntArrayVariable::IntArrayVariable(Parse
953          .ctx = ctx,          .ctx = ctx,
954          .isPolyphonic = false,          .isPolyphonic = false,
955          .isConst = false,          .isConst = false,
         .isFinal = false,  
956          .elements = 0,          .elements = 0,
957          .memPos = 0,          .memPos = 0,
958          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
959          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
960            .isFinal = false,
961      })      })
962  {  {
963      values.resize(size);      values.resize(size);
# Line 937  IntArrayVariable::IntArrayVariable(Parse Line 974  IntArrayVariable::IntArrayVariable(Parse
974          .ctx = ctx,          .ctx = ctx,
975          .isPolyphonic = false,          .isPolyphonic = false,
976          .isConst = _bConst,          .isConst = _bConst,
         .isFinal = false,  
977          .elements = 0,          .elements = 0,
978          .memPos = 0,          .memPos = 0,
979          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
980          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
981            .isFinal = false,
982      })      })
983  {  {
984      this->values.resize(size);      this->values.resize(size);
# Line 960  IntArrayVariable::IntArrayVariable(Parse Line 997  IntArrayVariable::IntArrayVariable(Parse
997          .ctx = ctx,          .ctx = ctx,
998          .isPolyphonic = false,          .isPolyphonic = false,
999          .isConst = bConst,          .isConst = bConst,
         .isFinal = false,  
1000          .elements = 0,          .elements = 0,
1001          .memPos = 0,          .memPos = 0,
1002          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1003          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1004            .isFinal = false,
1005      })      })
1006  {  {
1007  }  }
# Line 997  void IntArrayVariable::dump(int level) { Line 1034  void IntArrayVariable::dump(int level) {
1034              printf("\n");              printf("\n");
1035              printIndents(level+1);              printIndents(level+1);
1036          }          }
1037          printf("%lld, ", values[i]);          printf("%" PRId64 ", ", (int64_t)values[i]);
1038      }      }
1039      printIndents(level);      printIndents(level);
1040      printf(")\n");      printf(")\n");
# Line 1008  RealArrayVariable::RealArrayVariable(Par Line 1045  RealArrayVariable::RealArrayVariable(Par
1045          .ctx = ctx,          .ctx = ctx,
1046          .isPolyphonic = false,          .isPolyphonic = false,
1047          .isConst = false,          .isConst = false,
         .isFinal = false,  
1048          .elements = 0,          .elements = 0,
1049          .memPos = 0,          .memPos = 0,
1050          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1051          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1052            .isFinal = false,
1053      })      })
1054  {  {
1055      values.resize(size);      values.resize(size);
# Line 1029  RealArrayVariable::RealArrayVariable(Par Line 1066  RealArrayVariable::RealArrayVariable(Par
1066          .ctx = ctx,          .ctx = ctx,
1067          .isPolyphonic = false,          .isPolyphonic = false,
1068          .isConst = _bConst,          .isConst = _bConst,
         .isFinal = false,  
1069          .elements = 0,          .elements = 0,
1070          .memPos = 0,          .memPos = 0,
1071          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1072          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1073            .isFinal = false,
1074      })      })
1075  {  {
1076      this->values.resize(size);      this->values.resize(size);
# Line 1052  RealArrayVariable::RealArrayVariable(Par Line 1089  RealArrayVariable::RealArrayVariable(Par
1089          .ctx = ctx,          .ctx = ctx,
1090          .isPolyphonic = false,          .isPolyphonic = false,
1091          .isConst = bConst,          .isConst = bConst,
         .isFinal = false,  
1092          .elements = 0,          .elements = 0,
1093          .memPos = 0,          .memPos = 0,
1094          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1095          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1096            .isFinal = false,
1097      })      })
1098  {  {
1099  }  }
# Line 1121  IntArrayElement::IntArrayElement(IntArra Line 1158  IntArrayElement::IntArrayElement(IntArra
1158          .ctx = NULL,          .ctx = NULL,
1159          .isPolyphonic = (array) ? array->isPolyphonic() : false,          .isPolyphonic = (array) ? array->isPolyphonic() : false,
1160          .isConst = (array) ? array->isConstExpr() : false,          .isConst = (array) ? array->isConstExpr() : false,
         .isFinal = false,  
1161          .elements = 0,          .elements = 0,
1162          .memPos = 0,          .memPos = 0,
1163          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1164          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1165            .isFinal = false,
1166      }),      }),
1167      Unit(VM_NO_UNIT),      Unit(VM_NO_UNIT),
1168      array(array), index(arrayIndex), currentIndex(-1)      array(array), index(arrayIndex), currentIndex(-1)
1169  {      {
1170  }  }
1171    
1172  void IntArrayElement::assign(Expression* expr) {  void IntArrayElement::assign(Expression* expr) {
# Line 1172  RealArrayElement::RealArrayElement(RealA Line 1209  RealArrayElement::RealArrayElement(RealA
1209          .ctx = NULL,          .ctx = NULL,
1210          .isPolyphonic = (array) ? array->isPolyphonic() : false,          .isPolyphonic = (array) ? array->isPolyphonic() : false,
1211          .isConst = (array) ? array->isConstExpr() : false,          .isConst = (array) ? array->isConstExpr() : false,
         .isFinal = false,  
1212          .elements = 0,          .elements = 0,
1213          .memPos = 0,          .memPos = 0,
1214          .unitFactorMemPos = 0,          .unitFactorMemPos = 0,
1215          .unitType = VM_NO_UNIT          .unitType = VM_NO_UNIT,
1216            .isFinal = false,
1217      }),      }),
1218      Unit(VM_NO_UNIT),      Unit(VM_NO_UNIT),
1219      array(array), index(arrayIndex), currentIndex(-1)      array(array), index(arrayIndex), currentIndex(-1)
# Line 1230  StringVariable::StringVariable(ParserCon Line 1267  StringVariable::StringVariable(ParserCon
1267  StringVariable::StringVariable(ParserContext* ctx, bool bConst) :  StringVariable::StringVariable(ParserContext* ctx, bool bConst) :
1268      Variable({      Variable({
1269          .ctx = ctx,          .ctx = ctx,
1270            .isConst = bConst,
1271          .memPos = 0,          .memPos = 0,
         .isConst = bConst  
1272      })      })
1273  {  {
1274  }  }
# Line 1248  String StringVariable::evalStr() { Line 1285  String StringVariable::evalStr() {
1285    
1286  void StringVariable::dump(int level) {  void StringVariable::dump(int level) {
1287      printIndents(level);      printIndents(level);
1288      printf("StringVariable memPos=%lld\n", memPos);      printf("StringVariable memPos=%" PRId64 "\n", (int64_t)memPos);
1289  }  }
1290    
1291  ConstStringVariable::ConstStringVariable(ParserContext* ctx, String _value)  ConstStringVariable::ConstStringVariable(ParserContext* ctx, String _value)
# Line 1318  void SelectCase::dump(int level) { Line 1355  void SelectCase::dump(int level) {
1355      printIndents(level);      printIndents(level);
1356      if (select)      if (select)
1357          if (select->isConstExpr())          if (select->isConstExpr())
1358              printf("Case select %lld\n", select->evalInt());              printf("Case select %" PRId64 "\n", (int64_t)select->evalInt());
1359          else          else
1360              printf("Case select [runtime expr]\n");              printf("Case select [runtime expr]\n");
1361      else      else
# Line 1328  void SelectCase::dump(int level) { Line 1365  void SelectCase::dump(int level) {
1365          CaseBranch& branch = branches[i];          CaseBranch& branch = branches[i];
1366          if (branch.from && branch.to)          if (branch.from && branch.to)
1367              if (branch.from->isConstExpr() && branch.to->isConstExpr())              if (branch.from->isConstExpr() && branch.to->isConstExpr())
1368                  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());
1369              else if (branch.from->isConstExpr() && !branch.to->isConstExpr())              else if (branch.from->isConstExpr() && !branch.to->isConstExpr())
1370                  printf("case %lld to [runtime expr]\n", branch.from->evalInt());                  printf("case %" PRId64 " to [runtime expr]\n", (int64_t)branch.from->evalInt());
1371              else if (!branch.from->isConstExpr() && branch.to->isConstExpr())              else if (!branch.from->isConstExpr() && branch.to->isConstExpr())
1372                  printf("case [runtime expr] to %lld\n", branch.to->evalInt());                  printf("case [runtime expr] to %" PRId64 "\n", (int64_t)branch.to->evalInt());
1373              else              else
1374                  printf("case [runtime expr] to [runtime expr]\n");                  printf("case [runtime expr] to [runtime expr]\n");
1375          else if (branch.from)          else if (branch.from)
1376              if (branch.from->isConstExpr())              if (branch.from->isConstExpr())
1377                  printf("case %lld\n", branch.from->evalInt());                  printf("case %" PRId64 "\n", (int64_t)branch.from->evalInt());
1378              else              else
1379                  printf("case [runtime expr]\n");                  printf("case [runtime expr]\n");
1380          else          else
# Line 1376  void While::dump(int level) { Line 1413  void While::dump(int level) {
1413      printIndents(level);      printIndents(level);
1414      if (m_condition)      if (m_condition)
1415          if (m_condition->isConstExpr())          if (m_condition->isConstExpr())
1416              printf("while (%lld) {\n", m_condition->evalInt());              printf("while (%" PRId64 ") {\n", (int64_t)m_condition->evalInt());
1417          else          else
1418              printf("while ([runtime expr]) {\n");              printf("while ([runtime expr]) {\n");
1419      else      else
# Line 1843  void ParserContext::registerBuiltInConst Line 1880  void ParserContext::registerBuiltInConst
1880              .value = it->second              .value = it->second
1881          });          });
1882          vartable[it->first] = ref;          vartable[it->first] = ref;
1883        }
1884    }
1885    
1886    void ParserContext::registerBuiltInConstRealVariables(const std::map<String,vmfloat>& vars) {
1887        for (std::map<String,vmfloat>::const_iterator it = vars.begin();
1888             it != vars.end(); ++it)
1889        {
1890            ConstRealVariableRef ref = new ConstRealVariable({
1891                .value = it->second
1892            });
1893            vartable[it->first] = ref;
1894      }      }
1895  }  }
1896    

Legend:
Removed from v.3582  
changed lines
  Added in v.3707

  ViewVC Help
Powered by ViewVC