Changeset 15334 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs
- Timestamp:
- 08/21/17 11:33:53 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP
- Property svn:ignore
-
old new 1 1 *.user 2 packages 3 TestResults
-
- Property svn:ignore
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs
r15189 r15334 122 122 public override bool IsNoop(IInternalPushInterpreter interpreter) { 123 123 return interpreter.StringStack.Count < 2 || 124 interpreter.StringStack.Top.Length + interpreter.StringStack[1].Length > =interpreter.Configuration.MaxStringLength;124 interpreter.StringStack.Top.Length + interpreter.StringStack[1].Length > interpreter.Configuration.MaxStringLength; 125 125 } 126 126 … … 148 148 return interpreter.StringStack.IsEmpty || 149 149 interpreter.CharStack.IsEmpty || 150 interpreter.StringStack.Top.Length + 1 > =interpreter.Configuration.MaxStringLength;150 interpreter.StringStack.Top.Length + 1 > interpreter.Configuration.MaxStringLength; 151 151 } 152 152 … … 618 618 619 619 public override void Eval(IInternalPushInterpreter interpreter) { 620 var result = GetResultString(interpreter); 621 622 // Should be checked in isNoop but would require to calculate result twice which is an expensive operation 623 if (result.Length > interpreter.Configuration.MaxStringLength) 624 return; 625 626 interpreter.StringStack.Remove(2); 627 interpreter.StringStack.Top = result; 628 } 629 630 private static string GetResultString(IInternalPushInterpreter interpreter) { 620 631 var third = interpreter.StringStack[2]; 621 632 var second = interpreter.StringStack[1]; 622 633 var first = interpreter.StringStack[0]; 623 interpreter.StringStack.Remove(2); 624 625 interpreter.StringStack.Top = third.Length == 0 || second.Length == 0 634 635 var result = third.Length == 0 || second.Length == 0 626 636 ? third 627 637 : third.Replace(second, first); 638 639 return result; 628 640 } 629 641 } … … 647 659 648 660 public override void Eval(IInternalPushInterpreter interpreter) { 661 var result = GetResultString(interpreter); 662 663 // Should be checked in isNoop but would require to calculate result twice which is an expensive operation 664 if (result.Length > interpreter.Configuration.MaxStringLength) 665 return; 666 667 interpreter.StringStack.Remove(2); 668 interpreter.StringStack.Top = result; 669 } 670 671 private static string GetResultString(IInternalPushInterpreter interpreter) { 649 672 var third = interpreter.StringStack[2]; 650 673 var second = interpreter.StringStack[1]; 651 674 var first = interpreter.StringStack[0]; 652 interpreter.StringStack.Remove(2); 653 654 interpreter.StringStack.Top = third.Length == 0 || second.Length == 0 675 676 var result = third.Length == 0 || second.Length == 0 655 677 ? third 656 678 : ReplaceFirst(third, second, first); 679 return result; 657 680 } 658 681 … … 802 825 "STRING.ITERATE", 803 826 "Iterates over the top STRING using the CODE on the EXEC stack.", 804 StackTypes.Exec | StackTypes.Char, execIn: 1)]827 StackTypes.Exec | StackTypes.Char, requiredBlockCount: 1)] 805 828 public class StringIterateExpression : StatelessExpression { 806 829 public StringIterateExpression() { }
Note: See TracChangeset
for help on using the changeset viewer.