namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
using System.Collections.Generic;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions;
using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
///
/// Removes an indexed item from "deep" in the stack and pushes it on top of the stack.
/// The index is taken from the INTEGER stack, and the indexing is done after the index is removed.
///
/// Stacktype
[StorableClass]
public abstract class YankExpression : StatelessExpression {
protected YankExpression() { }
[StorableConstructor]
protected YankExpression(bool deserializing) : base(deserializing) { }
protected bool IsNoop(IPushStack stack, IPushStack integerStack) {
return (stack == integerStack && integerStack.Count < 3) ||
(stack != integerStack && (integerStack.IsEmpty || stack.Count < 2));
}
protected void Eval(IPushStack stack, IPushStack integerStack) {
var index = integerStack.Pop().AsInt(stack.Count);
stack.Yank(index);
}
}
[StorableClass]
[PushExpression(
StackTypes.Integer,
"INTEGER.YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.")]
public class IntegerYankExpression : YankExpression {
public IntegerYankExpression() { }
[StorableConstructor]
protected IntegerYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.IntegerStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.IntegerStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.Float,
"FLOAT.YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class FloatYankExpression : YankExpression {
public FloatYankExpression() { }
[StorableConstructor]
protected FloatYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.FloatStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.FloatStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.Boolean,
"BOOLEAN.YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class BooleanYankExpression : YankExpression {
public BooleanYankExpression() { }
[StorableConstructor]
protected BooleanYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.BooleanStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.BooleanStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.Name,
"NAME.YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class NameYankExpression : YankExpression {
public NameYankExpression() { }
[StorableConstructor]
protected NameYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.NameStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.NameStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.Exec,
"EXEC.YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer,
requiredBlockCount: 0)]
public class ExecYankExpression : YankExpression {
public ExecYankExpression() { }
[StorableConstructor]
protected ExecYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.ExecStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.ExecStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.Code,
"CODE.YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class CodeYankExpression : YankExpression {
public CodeYankExpression() { }
[StorableConstructor]
protected CodeYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.CodeStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.CodeStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.Char,
"CHAR.YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class CharYankExpression : YankExpression {
public CharYankExpression() { }
[StorableConstructor]
protected CharYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.CharStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.CharStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.String,
"STRING.YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class StringYankExpression : YankExpression {
public StringYankExpression() { }
[StorableConstructor]
protected StringYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.StringStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.StringStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.IntegerVector,
"INTEGER[].YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class IntegerVectorYankExpression : YankExpression> {
public IntegerVectorYankExpression() { }
[StorableConstructor]
protected IntegerVectorYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.IntegerVectorStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.FloatVector,
"FLOAT[].YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class FloatVectorYankExpression : YankExpression> {
public FloatVectorYankExpression() { }
[StorableConstructor]
protected FloatVectorYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.FloatVectorStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.FloatVectorStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.BooleanVector,
"BOOLEAN[].YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class BooleanVectorYankExpression : YankExpression> {
public BooleanVectorYankExpression() { }
[StorableConstructor]
protected BooleanVectorYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.BooleanVectorStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.BooleanVectorStack, interpreter.IntegerStack);
}
}
[StorableClass]
[PushExpression(
StackTypes.StringVector,
"STRING[].YANK",
"Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.",
StackTypes.Integer)]
public class StringVectorYankExpression : YankExpression> {
public StringVectorYankExpression() { }
[StorableConstructor]
protected StringVectorYankExpression(bool deserializing) : base(deserializing) { }
public override bool IsNoop(IInternalPushInterpreter interpreter) {
return IsNoop(interpreter.StringVectorStack, interpreter.IntegerStack);
}
public override void Eval(IInternalPushInterpreter interpreter) {
Eval(interpreter.StringVectorStack, interpreter.IntegerStack);
}
}
}