using System.Collections.Generic;
namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
///
/// Pushes a boolean of whether the top vector is empty.
///
///
[StorableClass]
public abstract class VectorEmptyVectorExpression : StatelessExpression {
protected VectorEmptyVectorExpression() { }
[StorableConstructor]
protected VectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
protected bool IsNoop(IPushStack> vectorStack) {
return vectorStack.IsEmpty;
}
protected void Eval(IInternalPushInterpreter interpreter, IPushStack> vectorStack) {
var vector = vectorStack.Pop();
interpreter.BooleanStack.Push(vector.Count == 0);
}
}
[StorableClass]
[PushExpression(
StackTypes.IntegerVector,
"INTEGER[].EMPTYVECTOR",
"Pushes a BOOLEAN of whether the top INTEGER[] is empty.",
StackTypes.Boolean)]
public class IntegerVectorEmptyVectorExpression : VectorEmptyVectorExpression {
public IntegerVectorEmptyVectorExpression() { }
[StorableConstructor]
protected IntegerVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.IntegerVectorStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter, interpreter.IntegerVectorStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.FloatVector,
"FLOAT[].EMPTYVECTOR",
"Pushes a BOOLEAN of whether the top FLOAT[] is empty.",
StackTypes.Boolean)]
public class FloatVectorEmptyVectorExpression : VectorEmptyVectorExpression {
public FloatVectorEmptyVectorExpression() { }
[StorableConstructor]
protected FloatVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.FloatVectorStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter, interpreter.FloatVectorStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.BooleanVector,
"BOOLEAN[].EMPTYVECTOR",
"Pushes a BOOLEAN of whether the top BOOLEAN[] is empty.",
StackTypes.Boolean)]
public class BooleanVectorEmptyVectorExpression : VectorEmptyVectorExpression {
public BooleanVectorEmptyVectorExpression() { }
[StorableConstructor]
protected BooleanVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.BooleanVectorStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter, interpreter.BooleanVectorStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.StringVector,
"STRING[].EMPTYVECTOR",
"Pushes a BOOLEAN of whether the top STRING[] is empty.",
StackTypes.Boolean)]
public class StringVectorEmptyVectorExpression : VectorEmptyVectorExpression {
public StringVectorEmptyVectorExpression() { }
[StorableConstructor]
protected StringVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.StringVectorStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter, interpreter.StringVectorStack);
}
}
}