I'm writing an implementation of a virtual machine in C#, and I need to implement the VM's stack, which can contain two types of entry - return entries or backtrack entries. What is the best way of implementing this?
I'm currently using a base type, as follows:
class StackEntry { }
class Return : StackEntry { uint pc; }
class Backtrack : StackEntry { uint pc; object backtrack; }
Stack<StackEntry> stack;
This works OK, but the resulting type testing and downcasting feels clumsy.
Is there a better way of handling this type of construction?