@@ -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;
0 commit comments