|
This post was updated on .
I know how local vars are auto-initialized to 0, since we covered that in our VM_code-to-assembly translation.
How are static variables for a class auto-initialized to 0 before they can be referenced by Main.main (our entry-point)?
One option would be for my compiler to find Main.main and insert those initializations of all classes into the beginning of that, which seems messy.
Another option would be for static variables to be initialized to 0 upon first reference (if referenced before assignment): Cause from where I see it, static variables only exist on our symbol table until we either reference or assign to them. That means the VM has no idea how many static variables we have during runtime, until from within a function, it sees something like `pop static 2`(first assignment to 3rd static variable) or it first sees `push static 2`(reference before assignment which auto initialization is supposed to prevent).
Or is undefined behavior possible? Or does an error get thrown somewhere instead?
Should my VM-to-assembly translator have included assembly instructions to clear all static segments to 0?
Also, is there such thing as a virtual machine here that does anything besides translate our assembly-macros into assembly? Well it also shows on screen what is happening. I guess I could ask myself, "what is any machine?". Stretching my brain here...
I'm trying to put the pieces together and see how this comes full circle... get the big picture
|