Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/17 11:23:05 (8 years ago)
Author:
pkimmesw
Message:

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CharExpressions.cs

    r14834 r14952  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
    22  using System;
    3 
    4   using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    5   using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    6   using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
     3  using Attributes;
     4  using Interpreter;
     5  using Persistence.Default.CompositeSerializers.Storable;
     6  using Stack;
    77
    88  [PushExpression(StackTypes.Char, "CHAR.ISWHITESPACE", StackTypes.Boolean)]
     9  [StorableClass]
    910  public class CharIsWhitespaceExpression : StatelessExpression {
    10     public override bool Eval(IInternalPushInterpreter interpreter) {
    11       if (interpreter.CharStack.IsEmpty) return false;
     11    public CharIsWhitespaceExpression() { }
     12    [StorableConstructor]
     13    public CharIsWhitespaceExpression(bool deserializing) : base(deserializing) { }
    1214
     15    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     16      return interpreter.CharStack.IsEmpty;
     17    }
     18
     19    public override void Eval(IInternalPushInterpreter interpreter) {
    1320      var c = interpreter.CharStack.Pop();
    1421      interpreter.BooleanStack.Push(char.IsWhiteSpace(c));
    15       return true;
    1622    }
    1723  }
    1824
    1925  [PushExpression(StackTypes.Char, "CHAR.ISLETTER", StackTypes.Boolean)]
     26  [StorableClass]
    2027  public class CharIsLetterExpression : StatelessExpression {
    21     public override bool Eval(IInternalPushInterpreter interpreter) {
    22       if (interpreter.CharStack.IsEmpty) return false;
     28    public CharIsLetterExpression() { }
     29    [StorableConstructor]
     30    public CharIsLetterExpression(bool deserializing) : base(deserializing) { }
    2331
     32    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     33      return interpreter.CharStack.IsEmpty;
     34    }
     35
     36    public override void Eval(IInternalPushInterpreter interpreter) {
    2437      var c = interpreter.CharStack.Pop();
    2538      interpreter.BooleanStack.Push(char.IsLetter(c));
    26       return true;
    2739    }
    2840  }
    2941
    3042  [PushExpression(StackTypes.Char, "CHAR.ISDIGIT", StackTypes.Boolean)]
     43  [StorableClass]
    3144  public class CharIsDigitExpression : StatelessExpression {
    32     public override bool Eval(IInternalPushInterpreter interpreter) {
    33       if (interpreter.CharStack.IsEmpty) return false;
     45    public CharIsDigitExpression() { }
     46    [StorableConstructor]
     47    public CharIsDigitExpression(bool deserializing) : base(deserializing) { }
    3448
     49    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     50      return interpreter.CharStack.IsEmpty;
     51    }
     52
     53    public override void Eval(IInternalPushInterpreter interpreter) {
    3554      var c = interpreter.CharStack.Pop();
    3655      interpreter.BooleanStack.Push(char.IsDigit(c));
    37       return true;
    3856    }
    3957  }
    4058
    4159  [PushExpression(StackTypes.Char, "CHAR.FROMINTEGER", StackTypes.Integer)]
     60  [StorableClass]
    4261  public class CharFromIntegerExpression : StatelessExpression {
    43     public override bool Eval(IInternalPushInterpreter interpreter) {
    44       if (interpreter.IntegerStack.IsEmpty) return false;
     62    public CharFromIntegerExpression() { }
     63    [StorableConstructor]
     64    public CharFromIntegerExpression(bool deserializing) : base(deserializing) { }
    4565
     66    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     67      return interpreter.IntegerStack.IsEmpty;
     68    }
     69
     70    public override void Eval(IInternalPushInterpreter interpreter) {
    4671      var value = (int)Math.Abs(interpreter.IntegerStack.Pop() % 128);
    4772      var c = Convert.ToChar(value);
    4873
    4974      interpreter.CharStack.Push(c);
    50       return true;
    5175    }
    5276  }
    5377
    5478  [PushExpression(StackTypes.Char, "CHAR.FROMFLOAT", StackTypes.Float)]
     79  [StorableClass]
    5580  public class CharFromFloatExpression : StatelessExpression {
    56     public override bool Eval(IInternalPushInterpreter interpreter) {
    57       if (interpreter.FloatStack.IsEmpty) return false;
     81    public CharFromFloatExpression() { }
     82    [StorableConstructor]
     83    public CharFromFloatExpression(bool deserializing) : base(deserializing) { }
    5884
     85    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     86      return interpreter.FloatStack.IsEmpty;
     87    }
     88
     89    public override void Eval(IInternalPushInterpreter interpreter) {
    5990      var value = (int)Math.Abs(interpreter.FloatStack.Pop() % 128);
    6091      var c = Convert.ToChar(value);
    6192
    6293      interpreter.CharStack.Push(c);
    63       return true;
    6494    }
    6595  }
    6696
    6797  [PushExpression(StackTypes.Char, "CHAR.ALLFROMSTRING", StackTypes.String)]
     98  [StorableClass]
    6899  public class CharAllFromStringExpression : StatelessExpression {
    69     public override bool Eval(IInternalPushInterpreter interpreter) {
    70       if (interpreter.StringStack.IsEmpty) return false;
     100    public CharAllFromStringExpression() { }
     101    [StorableConstructor]
     102    public CharAllFromStringExpression(bool deserializing) : base(deserializing) { }
    71103
     104    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     105      return interpreter.StringStack.IsEmpty;
     106    }
     107
     108    public override void Eval(IInternalPushInterpreter interpreter) {
    72109      var chars = interpreter.StringStack.Pop().ToCharArray();
    73110      interpreter.CharStack.Push(chars);
    74       return true;
    75111    }
    76112  }
Note: See TracChangeset for help on using the changeset viewer.