I've been writing an interpreter for The Mouse Programming Language
. The code is structured around Pers example from the homework for day 3. My code can be found at https://github.com/dannas/rsc/blob/master/2018/mouse/main.c
I started out with a fixed value stack; then added a fixed call stack; then I needed a "control stack" for keeping track of the loop headers of nested loops. Hey, I might even throw in more stacks in case I decided to do abstract interpretation as suggested by Per and as is done in for instance Firefox Webassembly JIT-compiler.
My problem is that I'd like to have one pair of PUSH/POP functions that could operate on all three of these stacks. How would you go about having a fixed stack in C? Just use two variables per each stack and don't "overthink" it? Use a struct that contains the two variables making use of void-pointers? Something else?
I admit that this example is artificial, since having unbounded space for these three stacks is not a problem for this small toy interpreter: I could just use stretchy buffers for the stacks! But I'm wondering if there are more "tricks" similar to stretchy buffers for having succinct ADTs in C?
Thank you once again for the streams so far!