Skip to content

Commit

Permalink
Moving over to a generic stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanecelis committed Oct 20, 2017
1 parent 7305938 commit a601788
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 213 deletions.
35 changes: 35 additions & 0 deletions Psh/Instructions.cs
Expand Up @@ -363,6 +363,41 @@ public override void Execute(Interpreter inI)
}
}

[System.Serializable]
internal class BinaryInstruction<T> : Instruction
{
private const long serialVersionUID = 1L;

private Func<T,T,T> func;
public BinaryInstruction(Func<T,T,T> func) {
this.func = func;
}

//
//
// Binary integer instructions
//
// internal abstract T BinaryOperator(T inA, T inB);

public override void Execute(Interpreter inI)
{
GenericStack<T> stack = inI.GetStack<T>();
if (stack.Size() > 1)
{
T a;
T b;
a = stack.Pop();
b = stack.Pop();
stack.Push(func(b, a));
}
}

public static implicit operator BinaryInstruction<T>(Func<T,T,T> f) {
return new BinaryInstruction<T>(f);
}
}


[System.Serializable]
internal class IntegerAdd : BinaryIntegerInstruction
{
Expand Down

0 comments on commit a601788

Please sign in to comment.