33#include < intrin.h>
44#include < sstream>
55#include < unordered_set>
6+ #include < iostream>
67
78constexpr auto NularPushConstNularCommand (std::string_view name) {
89 return [name](OptimizerModuleBase::Node& node) -> void {
@@ -15,7 +16,7 @@ constexpr auto NularPushConstNularCommand(std::string_view name) {
1516 };
1617}
1718
18-
19+ # define ONLY_PUSH_BINARY if (node.children[ 0 ].type != InstructionType::push || node.children[ 1 ].type != InstructionType::push) return
1920
2021class OptimizerConstantFoldActionMap : public Singleton <OptimizerConstantFoldActionMap> {
2122public:
@@ -62,6 +63,7 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
6263
6364
6465 // binaryActions["+"] = [](OptimizerModuleBase::Node & node) -> void { //#TODO array
66+ // ONLY_PUSH_BINARY;
6567 // if (node.children[0].value.index() == 1) { //string
6668 // auto leftArg = std::get<STRINGTYPE>(node.children[0].value);
6769 // auto rightArg = std::get<STRINGTYPE>(node.children[1].value);
@@ -81,9 +83,11 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
8183 // };
8284
8385 binaryActions[" -" ] = [](OptimizerModuleBase::Node & node) -> void {
86+ ONLY_PUSH_BINARY ;
8487
8588 auto type = getConstantType (node.children [0 ].value );
8689
90+ // #TODO fix array, this is safe if both are const, see params need to convert arrays to constants and merge
8791 if (type == ConstantType::array) { // array
8892 // std::unordered_set<STRINGTYPE> vals;
8993 //
@@ -109,12 +113,19 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
109113 float rightArg = std::get<float >(node.children [1 ].value );
110114 node.value = leftArg - rightArg;
111115 }
116+ else
117+ {
118+ std::cout << " Something is very wrong, tried to optimize operator '-' but argument type is neither array nor number?! Breaking into debugger now." << std::endl;
119+ __debugbreak ();
120+
121+ }
112122 node.type = InstructionType::push;
113123 node.children .clear ();
114124 node.constant = true ;
115125 };
116126
117127 binaryActions[" /" ] = [](OptimizerModuleBase::Node & node) -> void {
128+ ONLY_PUSH_BINARY ;
118129 auto type = getConstantType (node.children [0 ].value );
119130 if (type != ConstantType::scalar)
120131 return ;
@@ -128,6 +139,7 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
128139 node.value = leftArg / rightArg;
129140 };
130141 binaryActions[" *" ] = [](OptimizerModuleBase::Node & node) -> void {
142+ ONLY_PUSH_BINARY ;
131143 auto type = getConstantType (node.children [0 ].value );
132144 if (type != ConstantType::scalar)
133145 return ;
@@ -142,6 +154,7 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
142154 };
143155
144156 binaryActions[" mod" ] = [](OptimizerModuleBase::Node & node) -> void {
157+ ONLY_PUSH_BINARY ;
145158 auto type = getConstantType (node.children [0 ].value );
146159 if (type != ConstantType::scalar)
147160 return ;
0 commit comments