I have written a small compiler for a simple stack machine. It can assemble and handle scope/functions through a number of virtual machine hacks only. That is I have it define scope and in scope variable definitions in the bytecode itself.
Can I get some pointers on how I should be handling scope.
The problems I face are mainly, how do I let it know when to and when not to overwrite a variable outside with a variable inside, and similar. The bytecode is mutable and I would prefer to change it.
Other problems include how to retain variables outside after returning. So that a variable still has its value. I can push it to stack, but I could have a lot of variables.
I think there is some compiler work done to check these things, but I can't think of what would need to be done to do it.