Skip to content
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

Merged
merged 14 commits into from
Jul 21, 2024
Merged

Conversation

B-rando1
Copy link
Collaborator

@B-rando1 B-rando1 commented Jul 8, 2024

Main changes:

  • I renamed the existing ScopeSym and all its derivatives to VisibilitySym, because it has to do with public vs private class members. Hopefully this isn't too confusing...
  • I created a new ScopeSym that deals with global vs local variables.
  • I added Scope as a new parameter to var, staticVar, extVar, and const.

Notes:

  • Currently none of the renderers do anything with this, as they don't need to. Julia will need it, though.
  • To make our current code work with the changes, I had to give a scope to variables, constants, etc. Because I wanted to get the code working again as soon as possible, I set it to 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.
  • The order of the parameters for var, etc. could be up for debate. Currently the Scope 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.
    • I know there are several previous instances (e.g. objMethodCall) where we use a smart constructor to rearrange the order of parameters from a user-friendly ordering to an internal-friendly ordering. Would this be a good place to do that?

Contributes towards #3821

Copy link
Owner

@JacquesCarette JacquesCarette left a 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.

varDec $ var "a" int,
varDecDef (var "b" int) (litInt 5),
listDecDef (var "myOtherList" (listType double)) [litDouble 1.0,
varDec $ var "a" int local,
Copy link
Owner

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.

Copy link
Collaborator Author

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:

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.

Copy link
Owner

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.

B-rando1 added 4 commits July 8, 2024 14:44
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.
@B-rando1 B-rando1 force-pushed the GlobalLocalScope branch from fbfc58e to d8fd41e Compare July 8, 2024 20:52
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.
@B-rando1 B-rando1 marked this pull request as draft July 9, 2024 16:00
@B-rando1
Copy link
Collaborator Author

B-rando1 commented Jul 9, 2024

I think we should find a better solution to my comment before we go further with this work.

B-rando1 added 5 commits July 12, 2024 11:42
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.
@B-rando1 B-rando1 marked this pull request as ready for review July 15, 2024 13:51
B-rando1 added 3 commits July 17, 2024 16:11
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.
@JacquesCarette JacquesCarette merged commit ce525a2 into main Jul 21, 2024
5 checks passed
@JacquesCarette JacquesCarette deleted the GlobalLocalScope branch July 21, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants