Commits

O01eg committed 8f27ead

GP: Optimize IF with TRUE branch equal to FALSE branch.

Comments (0)

Files changed (2)

   - Move functions to base GP folder.
   - Remove ADF from generated objects.
   - Optimize %0 as returning LIST.
+  - Optimize IF with TRUE branch equal to FALSE branch.
 
 Version 0.0.5 2012-09-05
  - Support for C++0x (GCC 4.5.3)
 				bool check_1st = true;
 				VM::Object t = obj.GetTail();
 				std::stack<VM::Object> stack;
+
+				/// \todo Rewrite to foreach.
 				while((! t.IsNIL()) && (t.GetType() == VM::LIST))
 				{
 					VM::Object opt(env);
 					stack.push(std::move(opt));
 
 					t = t.GetTail();
-				}
+				} //while((! t.IsNIL()) && (t.GetType() == VM::LIST))
 
 				t = VM::Object(env);
 				while(! stack.empty())
 				{
 					return GP::Optimize(VM::Object(head, t), prog, rules, mode);
 				}
+
+				if(! check_no_if) // get IF, t.GetTail() = ( TRUE-BRANCH FALSE-BRANCH )
+				{
+					if(t.GetTail().GetHead() == t.GetTail().GetTail().GetHead()) // if TRUE-BRACH equal to FALSE-BRANCH
+					{
+						return t.GetTail().GetHead();
+					}
+				}
+
 				return VM::Object(head, t);
 			}
 		}