-
Notifications
You must be signed in to change notification settings - Fork 25
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
Started adding Global
vs Local
scope distinction
#3838
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one thing to change, otherwise this looks great.
code/drasil-code/test/HelloWorld.hs
Outdated
varDec $ var "a" int, | ||
varDecDef (var "b" int) (litInt 5), | ||
listDecDef (var "myOtherList" (listType double)) [litDouble 1.0, | ||
varDec $ var "a" int local, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would make more sense would be to introduce a new combinator locvar
that is a synonym for var ... local
and use that instead. Everywhere. It just 'clicked' with me when I was reviewing this part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I'll add that in.
While we're talking about smart constructors, do you think we should change the var
in the typeclass to var'
, and change the order of its parameters? As you guessed, the fix for the type error in the C++ renderer (as well as a few places in drasil-code
) would look nicer if we were to do that. This is the current fix, for reference:
Drasil/code/drasil-gool/lib/GOOL/Drasil/LanguageRenderer/CppRenderer.hs
Lines 275 to 278 in fbfc58e
var n t s = pair1 (\tp -> var n tp (pfst s)) (\tp -> var n tp (psnd s)) t | |
staticVar n t s = pair1 (\tp -> staticVar n tp (pfst s)) (\tp -> staticVar n tp (psnd s)) t | |
constant n t s = pair1 (\tp -> constant n tp (pfst s)) (\tp -> constant n tp (psnd s)) t | |
extVar l n t s = pair1 (\tp -> extVar l n tp (pfst s)) (\tp -> extVar l n tp (psnd s)) t |
If we changed the operand order, we could get rid of the lambdas and leave the functions partially applied, as they were before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, changing the order of parameters to make things smooth is worthwhile.
And many similar changes. Basically, there are almost no occurrences left of `scope` in either of `drasil-gool` or `drasil-code`.
`drasil-code` doesn't work with it yet, but one step at a time. Also, the C++ renderer has some weird type errors. I'll hopefully be able to fix it and amend this commit message, but if not, then you'll see this message :).
None of our current renderers do anything with it, and for now I made every variable `local`, since I'm not quite clear on how to do more than that yet. It works though, and I _think_ it's roughly in the right direction.
That was quite the merge conflict! It should all be working now though. I also created the `locvar` smart constructor for local variables. I'll have to put it to use tomorrow, though.
fbfc58e
to
d8fd41e
Compare
I changed the order of the parameters for `var`, `constant`, `extVar`, and `staticVar`. I then added and integrated some smart constructors to make using them simpler.
I think we should find a better solution to my comment before we go further with this work. |
I realized that `extVar`s are always `global` and `staticVar`s are always local, so they don't need that parameter.
This will represent the `main` function of a module, which is either global or local, depending on the language.
- I updated everything in `drasil-code/test` to use the proper scope. - I also started getting `drasil-code` to use the proper scope. It's slow going, but I fixed what I'm hoping was one of the trickier functions that needed a scope.
3b6f656
to
baf3f56
Compare
Similar to `locVar`, it makes it easier to create a variable in the 'main function' scope. I also renamed `locvar` to `locVar`, to be more consistent with `extVar` and `staticVar`.
I pushed it back to `mkVar` and `mkVal`. These get called by a ton of other things, but _hopefully_ I'm getting close to the end.
This one feels like a step backwards, as I created more `TODO`'s than I removed, but it's a necessary step.
Main changes:
ScopeSym
and all its derivatives toVisibilitySym
, because it has to do withpublic
vsprivate
class members. Hopefully this isn't too confusing...ScopeSym
that deals withglobal
vslocal
variables.Scope
as a new parameter tovar
,staticVar
,extVar
, andconst
.Notes:
local
in every instance. I might regret this later, but I just haven't thought through what we need to do to give the proper value in each case.var
, etc. could be up for debate. Currently theScope
is the last parameter for these. I think that makes sense, as it feels less important than the name or type of the variable. As @JacquesCarette's comment shows, however, putting it nearer the start of the list of parameters would make certain internal functions look simpler.Contributes towards #3821