|
34 | 34 | #include <minitscript/minitscript/MathMethods.h> |
35 | 35 | #include <minitscript/minitscript/NetworkMethods.h> |
36 | 36 | #include <minitscript/minitscript/ScriptMethods.h> |
| 37 | +#include <minitscript/minitscript/Setup.h> |
37 | 38 | #include <minitscript/minitscript/SetMethods.h> |
38 | 39 | #include <minitscript/minitscript/StringMethods.h> |
39 | 40 | #include <minitscript/minitscript/TimeMethods.h> |
@@ -89,6 +90,7 @@ using minitscript::minitscript::MapMethods; |
89 | 90 | using minitscript::minitscript::MathMethods; |
90 | 91 | using minitscript::minitscript::NetworkMethods; |
91 | 92 | using minitscript::minitscript::ScriptMethods; |
| 93 | +using minitscript::minitscript::Setup; |
92 | 94 | using minitscript::minitscript::SetMethods; |
93 | 95 | using minitscript::minitscript::StringMethods; |
94 | 96 | using minitscript::minitscript::TimeMethods; |
@@ -960,192 +962,6 @@ int MinitScript::getStackletScopeScriptIdx(int scriptIdx) { |
960 | 962 | return MinitScript::SCRIPTIDX_NONE; |
961 | 963 | } |
962 | 964 |
|
963 | | - |
964 | | -bool MinitScript::setupFunctionAndStackletScriptIndices(int scriptIdx) { |
965 | | - // |
966 | | - auto& script = scripts[scriptIdx]; |
967 | | - auto statementIdx = STATEMENTIDX_FIRST; |
968 | | - // |
969 | | - for (auto& syntaxTreeNode: script.syntaxTree) { |
970 | | - auto& statement = script.statements[statementIdx++]; |
971 | | - // |
972 | | - if (setupFunctionAndStackletScriptIndices(syntaxTreeNode, statement) == false) { |
973 | | - // |
974 | | - return false; |
975 | | - } |
976 | | - } |
977 | | - // |
978 | | - return true; |
979 | | - |
980 | | -} |
981 | | - |
982 | | -bool MinitScript::setupFunctionAndStackletScriptIndices(SyntaxTreeNode& syntaxTreeNode, const Statement& statement) { |
983 | | - switch (syntaxTreeNode.type) { |
984 | | - case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: |
985 | | - { |
986 | | - switch(syntaxTreeNode.value.getType()) { |
987 | | - case(MinitScript::TYPE_ARRAY): |
988 | | - case(MinitScript::TYPE_MAP): |
989 | | - { |
990 | | - if (setupFunctionAndStackletScriptIndices(syntaxTreeNode.value, statement, syntaxTreeNode.subLineIdx) == false) return false; |
991 | | - // |
992 | | - break; |
993 | | - } |
994 | | - case(MinitScript::TYPE_FUNCTION_ASSIGNMENT): |
995 | | - { |
996 | | - string function; |
997 | | - auto functionScriptIdx = SCRIPTIDX_NONE; |
998 | | - if (syntaxTreeNode.value.getFunctionValue(function, functionScriptIdx) == false || |
999 | | - (functionScriptIdx = getFunctionScriptIdx(function)) == SCRIPTIDX_NONE) { |
1000 | | - // |
1001 | | - _Console::printLine( |
1002 | | - getStatementInformation(statement, syntaxTreeNode.subLineIdx) + |
1003 | | - ": Function not found: " + |
1004 | | - syntaxTreeNode.value.getValueAsString() |
1005 | | - ); |
1006 | | - // |
1007 | | - parseErrors.push_back( |
1008 | | - getStatementInformation(statement, syntaxTreeNode.subLineIdx) + |
1009 | | - ": Function not found: " + |
1010 | | - syntaxTreeNode.value.getValueAsString() |
1011 | | - ); |
1012 | | - // |
1013 | | - return false; |
1014 | | - } |
1015 | | - // |
1016 | | - syntaxTreeNode.value.setFunctionAssignment(function, functionScriptIdx); |
1017 | | - // |
1018 | | - break; |
1019 | | - } |
1020 | | - case(MinitScript::TYPE_STACKLET_ASSIGNMENT): |
1021 | | - { |
1022 | | - string stacklet; |
1023 | | - auto stackletScriptIdx = SCRIPTIDX_NONE; |
1024 | | - if (syntaxTreeNode.value.getStackletValue(stacklet, stackletScriptIdx) == false || |
1025 | | - (stackletScriptIdx = getFunctionScriptIdx(stacklet)) == SCRIPTIDX_NONE) { |
1026 | | - // |
1027 | | - _Console::printLine( |
1028 | | - getStatementInformation(statement, syntaxTreeNode.subLineIdx) + |
1029 | | - ": Stacklet not found" + |
1030 | | - syntaxTreeNode.value.getValueAsString() |
1031 | | - ); |
1032 | | - // |
1033 | | - parseErrors.push_back( |
1034 | | - getStatementInformation(statement, syntaxTreeNode.subLineIdx) + |
1035 | | - ": Stacklet not found: " + |
1036 | | - syntaxTreeNode.value.getValueAsString() |
1037 | | - ); |
1038 | | - // |
1039 | | - return false; |
1040 | | - } |
1041 | | - // |
1042 | | - syntaxTreeNode.value.setStackletAssignment(stacklet, stackletScriptIdx); |
1043 | | - // |
1044 | | - break; |
1045 | | - } |
1046 | | - default: |
1047 | | - break; |
1048 | | - } |
1049 | | - // |
1050 | | - break; |
1051 | | - } |
1052 | | - case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: |
1053 | | - case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: |
1054 | | - { |
1055 | | - for (auto& argument: syntaxTreeNode.arguments) { |
1056 | | - if (setupFunctionAndStackletScriptIndices(argument, statement) == false) return false; |
1057 | | - } |
1058 | | - // |
1059 | | - break; |
1060 | | - } |
1061 | | - default: |
1062 | | - break; |
1063 | | - } |
1064 | | - // |
1065 | | - return true; |
1066 | | -} |
1067 | | - |
1068 | | -bool MinitScript::setupFunctionAndStackletScriptIndices(Variable& variable, const Statement& statement, int subLineIdx) { |
1069 | | - switch (variable.getType()) { |
1070 | | - case TYPE_ARRAY: |
1071 | | - { |
1072 | | - auto arrayPointer = variable.getArrayPointer(); |
1073 | | - if (arrayPointer == nullptr) break; |
1074 | | - for (auto arrayEntry: *arrayPointer) { |
1075 | | - if (setupFunctionAndStackletScriptIndices(*arrayEntry, statement, subLineIdx) == false) return false; |
1076 | | - } |
1077 | | - // |
1078 | | - break; |
1079 | | - } |
1080 | | - case TYPE_MAP: |
1081 | | - { |
1082 | | - // |
1083 | | - auto mapPointer = variable.getMapPointer(); |
1084 | | - if (mapPointer == nullptr) break; |
1085 | | - for (auto& [mapKey, mapValue]: *mapPointer) { |
1086 | | - if (setupFunctionAndStackletScriptIndices(*mapValue, statement, subLineIdx) == false) return false; |
1087 | | - } |
1088 | | - // |
1089 | | - break; |
1090 | | - } |
1091 | | - case TYPE_FUNCTION_ASSIGNMENT: |
1092 | | - { |
1093 | | - string function; |
1094 | | - auto functionScriptIdx = SCRIPTIDX_NONE; |
1095 | | - if (variable.getFunctionValue(function, functionScriptIdx) == false || |
1096 | | - (functionScriptIdx = getFunctionScriptIdx(function)) == SCRIPTIDX_NONE) { |
1097 | | - // |
1098 | | - _Console::printLine( |
1099 | | - getStatementInformation(statement, subLineIdx) + |
1100 | | - ": Function not found: " + |
1101 | | - variable.getValueAsString() |
1102 | | - ); |
1103 | | - // |
1104 | | - parseErrors.push_back( |
1105 | | - getStatementInformation(statement, subLineIdx) + |
1106 | | - ": Function not found: " + |
1107 | | - variable.getValueAsString() |
1108 | | - ); |
1109 | | - // |
1110 | | - return false; |
1111 | | - } |
1112 | | - // |
1113 | | - variable.setFunctionAssignment(function, functionScriptIdx); |
1114 | | - // |
1115 | | - break; |
1116 | | - } |
1117 | | - case TYPE_STACKLET_ASSIGNMENT: |
1118 | | - { |
1119 | | - string stacklet; |
1120 | | - auto stackletScriptIdx = SCRIPTIDX_NONE; |
1121 | | - if (variable.getStackletValue(stacklet, stackletScriptIdx) == false || |
1122 | | - (stackletScriptIdx = getFunctionScriptIdx(stacklet)) == SCRIPTIDX_NONE) { |
1123 | | - // |
1124 | | - _Console::printLine( |
1125 | | - getStatementInformation(statement, subLineIdx) + |
1126 | | - ": Stacklet not found" + |
1127 | | - variable.getValueAsString() |
1128 | | - ); |
1129 | | - // |
1130 | | - parseErrors.push_back( |
1131 | | - getStatementInformation(statement, subLineIdx) + |
1132 | | - ": Stacklet not found: " + |
1133 | | - variable.getValueAsString() |
1134 | | - ); |
1135 | | - // |
1136 | | - return false; |
1137 | | - } |
1138 | | - // |
1139 | | - variable.setStackletAssignment(stacklet, stackletScriptIdx); |
1140 | | - // |
1141 | | - break; |
1142 | | - } |
1143 | | - default: break; |
1144 | | - } |
1145 | | - // |
1146 | | - return true; |
1147 | | -} |
1148 | | - |
1149 | 965 | void MinitScript::emit(const string& condition) { |
1150 | 966 | // defer emit if a function/stacklet is still running |
1151 | 967 | if (isFunctionRunning() == true) { |
@@ -2578,7 +2394,7 @@ void MinitScript::parseScript(const string& pathName, const string& fileName, bo |
2578 | 2394 | // set up stacklet and function indices |
2579 | 2395 | for (auto scriptIdx = 0; scriptIdx < scripts.size(); scriptIdx++) { |
2580 | 2396 | // |
2581 | | - if (setupFunctionAndStackletScriptIndices(scriptIdx) == false) { |
| 2397 | + if (Setup::setupFunctionAndStackletScriptIndices(this, scriptIdx, parseErrors) == false) { |
2582 | 2398 | scriptValid = false; |
2583 | 2399 | return; |
2584 | 2400 | } |
|
0 commit comments