-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Used GenState
to store variable scope
#3899
Conversation
This will allow us to store the scope in the state instead of passing it around explicitly.
If I am correct and also didn't miss anything, the scope should now be accurate throughout `drasil-code`.
Yes
I don't fully understand this. The code should be able to look at the variable itself and query its scope, no? |
Hmm, I'm trying to think. I don't think we're currently keeping track of what scope is tied to a variable.
I'm not sure if I've completely thought through our options, so I might have to make another comment on #3821 tomorrow. Let me know if you have any thoughts here. |
We're planning to move it at this point.
And propogated the function calls down as far as I could without adding to the AST.
And integrated throughout GOOL
These changes only affect Julia. There are two places they take place: - When a global constant is declared, the `const` keyword is used. - When a global variable is assigned to, the `global` keyword is used to explicitly declare that it is a global variable. Notes: - Right now, the `global` keyword is added way too often. Unfortunately this won't be easy to fix, but we should fix it eventually. - Because Julia's implementation of `multiAssign` creates an empty variable, I had to add a hack to accomodate it.
After talking about it a lot, I decided to just go for the changes I thought we needed. Going off my comment in #3821, this implements option 2. It moves a lot of the weight of keeping track of scope from Just a few notes:
As I mentioned at the end of this comment, another benefit of doing this as an intermediate step is that it removes some work in the wrong direction that had unfortunately made it into |
There are a few macros that involve creating a temporary variable. Previously I just set them to be local, but now they use the scope of the input variable to set their own scope. This has a possibility of being `global` more often than it should, but it should be more accurate than it was.
As discussed in #3888, it is better to store the
scope
inGenState
than to pass it around all overdrasil-code
. I modifiedGenState
to hold that information. I also made sure that thecurrentScope
value is being modified wheneverdrasil-code
goes into a specific situation. Lastly, I usedcurrentScope
to give variables the proper scope when they are created.I have a few notes:
State
automatically revert its values back? E.g. if a generator function in theglobal
scope calls a generator function in thelocal
state, when the function terminates will it automatically set the state back toglobal
?currentScope
value. I based it on what I had in Finished tracing outscope
to its sources indrasil-code
#3888, which is at least a good baseline, though.GenState
, see that it's in a local state, and say the variable was created in a local scope. This is exactly the kind of behaviour we're trying to prevent, so I think we still need a bit more here.These last two points show the need for a better way of testing the scope of a variable in generated code. We should be able to do this once #3891 is merged, by temporarily modifying one of the renderers to display a variable's scope.