Skip to content

Commit 592ce8f

Browse files
committed
Everything works now
1 parent 725c203 commit 592ce8f

File tree

2 files changed

+53
-54
lines changed

2 files changed

+53
-54
lines changed

src/optimizer/optimizerModuleConstantFold.cpp

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
4747
//math
4848

4949

50-
//binaryActions["+"] = [](OptimizerModuleBase::Node & node) -> void {
50+
//binaryActions["+"] = [](OptimizerModuleBase::Node & node) -> void { //#TODO array
5151
// if (node.children[0].value.index() == 1) { //string
5252
// auto leftArg = std::get<STRINGTYPE>(node.children[0].value);
5353
// auto rightArg = std::get<STRINGTYPE>(node.children[1].value);
@@ -66,46 +66,46 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
6666
//
6767
//};
6868

69-
//binaryActions["-"] = [](OptimizerModuleBase::Node & node) -> void {
70-
// if (node.children[0].value.index() == 4) { //array
71-
// //std::unordered_set<STRINGTYPE> vals;
72-
// //
73-
// //for (auto& i : node.children[1].children) { //#TODO number support
74-
// // if (i.value.index() != 1)
75-
// // return; //not string, don't optimize
76-
// // vals.emplace(std::get<STRINGTYPE>(i.value));
77-
// //}
78-
// //std::vector<OptimizerModuleBase::Node> newNodes;
79-
// //for (auto& it : node.children[0].children) {
80-
// // if (it.value.index() != 1)
81-
// // return; //not string, don't optimize
82-
// // auto & sval = std::get<STRINGTYPE>(it.value);
83-
// //
84-
// // auto found = vals.find(sval);
85-
// // if (found == vals.end())
86-
// // newNodes.emplace_back(std::move(it));
87-
// //}
88-
// //node.children[0].children = std::move(newNodes);
89-
// return;
90-
// } else {//float
91-
// float leftArg = std::get<float>(node.children[0].value);
92-
// float rightArg = std::get<float>(node.children[1].value);
93-
// node.value = leftArg - rightArg;
94-
// }
95-
// node.type = InstructionType::push;
96-
// node.children.clear();
97-
// node.constant = true;
98-
//};
69+
binaryActions["-"] = [](OptimizerModuleBase::Node & node) -> void {
70+
if (node.children[0].value.index() == 4) { //array
71+
//std::unordered_set<STRINGTYPE> vals;
72+
//
73+
//for (auto& i : node.children[1].children) { //#TODO number support
74+
// if (i.value.index() != 1)
75+
// return; //not string, don't optimize
76+
// vals.emplace(std::get<STRINGTYPE>(i.value));
77+
//}
78+
//std::vector<OptimizerModuleBase::Node> newNodes;
79+
//for (auto& it : node.children[0].children) {
80+
// if (it.value.index() != 1)
81+
// return; //not string, don't optimize
82+
// auto & sval = std::get<STRINGTYPE>(it.value);
83+
//
84+
// auto found = vals.find(sval);
85+
// if (found == vals.end())
86+
// newNodes.emplace_back(std::move(it));
87+
//}
88+
//node.children[0].children = std::move(newNodes);
89+
return;
90+
} else {//float
91+
float leftArg = std::get<float>(node.children[0].value);
92+
float rightArg = std::get<float>(node.children[1].value);
93+
node.value = leftArg - rightArg;
94+
}
95+
node.type = InstructionType::push;
96+
node.children.clear();
97+
node.constant = true;
98+
};
9999

100-
//binaryActions["/"] = [](OptimizerModuleBase::Node & node) -> void { //#TODO could be config with two strings?
101-
// float leftArg = std::get<float>(node.children[0].value);
102-
// float rightArg = std::get<float>(node.children[1].value);
103-
//
104-
// node.type = InstructionType::push;
105-
// node.children.clear();
106-
// node.constant = true;
107-
// node.value = leftArg / rightArg;
108-
//};
100+
binaryActions["/"] = [](OptimizerModuleBase::Node & node) -> void { //Can't be config as configFile is not const
101+
float leftArg = std::get<float>(node.children[0].value);
102+
float rightArg = std::get<float>(node.children[1].value);
103+
104+
node.type = InstructionType::push;
105+
node.children.clear();
106+
node.constant = true;
107+
node.value = leftArg / rightArg;
108+
};
109109
binaryActions["*"] = [](OptimizerModuleBase::Node & node) -> void {
110110
float leftArg = std::get<float>(node.children[0].value);
111111
float rightArg = std::get<float>(node.children[1].value);
@@ -149,19 +149,19 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
149149
}
150150

151151
void setupNulary() {
152-
//nularyActions["true"] = [](OptimizerModuleBase::Node & node) -> void {
153-
// node.type = InstructionType::push;
154-
// node.children.clear();
155-
// node.constant = true;
156-
// node.value = true;
157-
//};
158-
//
159-
//nularyActions["false"] = [](OptimizerModuleBase::Node & node) -> void {
160-
// node.type = InstructionType::push;
161-
// node.children.clear();
162-
// node.constant = true;
163-
// node.value = false;
164-
//};
152+
nularyActions["true"] = [](OptimizerModuleBase::Node & node) -> void {
153+
node.type = InstructionType::push;
154+
node.children.clear();
155+
node.constant = true;
156+
node.value = true;
157+
};
158+
159+
nularyActions["false"] = [](OptimizerModuleBase::Node & node) -> void {
160+
node.type = InstructionType::push;
161+
node.children.clear();
162+
node.constant = true;
163+
node.value = false;
164+
};
165165

166166
//nularyActions["nil"] = [](OptimizerModuleBase::Node & node) -> void {
167167
// node.type = InstructionType::push;

src/scriptCompiler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ CompiledCodeData ScriptCompiler::compileScript(std::filesystem::path file) {
9191
stuff.constants.emplace_back(std::move(preprocessedScript));
9292
stuff.codeIndex = stuff.constants.size();
9393
stuff.constants.emplace_back(std::move(mainCode));
94-
if (stuff.codeIndex == 220) __debugbreak();
9594

9695
//std::ofstream output2("P:\\outOpt.sqfa", std::ofstream::binary);
9796
//ScriptSerializer::compiledToHumanReadable(stuff, output2);

0 commit comments

Comments
 (0)