I'm building a little scripting language in C#, and last night I hit an interesting problem:
I need to add GOTO. Yes, really. This is for game logic scripting, so when the player walks back and forth between two rooms I can either call goToRoomA<->goToRoomB and grow a ridiculous stack, or I can build some ungainly chaining monstrosity, or I can just GOTO and blow away the stack.
So how do I implement this?
Right now my interpreter is using the stack in C# to represent context. For example, if it hits a curly brace then it calls a function named block(), and until that function returns it's in that code block. This is a very neat solution, but doesn't obviously allow complete stack obliteration.
Do I:
A) Implement my own stack representation instead, with maybe a bit ol switch for the contexts and the interpreter code that runs within them.
B) Manually manage falling out of scope everywhere
...