+388 -106, this is getting messy.
I dropped the idea last night of trying to have codegen retrace the steps of the scope pass. Instead any given invocation of a variable will be tied to a specific token index, & any given token index has only one interpretation of whether it is local/global/nonlocal. Key of the concept is all in the getScope/nameScope functions, the rest is all trace logic & block scoping. Moved subfunction compilation to occur within scoping phase, tho that's commented until I get around to it. Getting busy with a work project so that'll hamper this project
getScope's designed to have any upvar also mark the variable as being upvar'd by the between functions. This is because 'function f1(x) function f2() return function f3() return x end end return f2 end' needs g = f1(5) h = f1(8) to be able to pass the upvar ref to f3 on any arbitrary call to g or h
As an aside it turns out Functiondef was a totally useless rule to have so I killed it. I'd like to clean up the grammar code a bit, stuff like Namelist doesn't need to propagate to the AST