-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Disallow top-level lets and introduce const
declarations.
#278
Conversation
a2425f5
to
c4e1b45
Compare
const
declarations.const
declarations.
This looks fine and makes sense to me, but I have a question. I was thinking we could just parse them (only allowing literals, the same as your intuition) and then just pre-populate the data section and namespace with them. Then whenever they were referenced, they'd already have a data section entry and it would all fall into place. Is what I just described too naïve? |
I don't know -- how is that different to what I've done? My mental model of how it works still isn't 100%, I think. Everything pre-asm would have to stay, yeah? It needs to type-check and pass dead code analysis. And then in the asm-gen I'm just putting the values into registers and and the namespace. That sounds different to 'pre-populating the data section' but I don't quite understand the difference, or whether it would be any simpler/better..? |
Hrmm, what it does now is add each const to the namespace by using I see that each module type (script, predicate, etc.) has their own data section though, is that what you mean? Otherwise, to pre-populate the namespace you need to associate a register with a name, and to get a register you need to generate the load instruction... |
You don't need a register to reference a data section value, instead you get a data label. But I see what you mean, you then need to get that data label associated with the variable name somehow.... Ok, this makes sense. And it allows us to do more complicated constant expressions in the future. Feel free to resolve the conflicts and we can take this in. |
c4e1b45
to
2c0f4df
Compare
Just did a forced push to resolve merge conflicts. |
This turned out to be bigger than I thought it would. Closes #215.
For now
const
declarations can only be initialised with a literal. In the future we may want to allow any const expression.I had to touch a bunch of stuff, right from the type checker, the control flow analyser, and asm gen and I'm fairly confident it's right, but much of it was new to me so I might've missed something.
In particular I've added some code to the asm gen which adds ops for the constants and their initialisers before it converts
main
. This is becauseconst
can be a global, but unlike functions, enums or structs, they do need asm to be generated, and since globals aren't in functions they won't be instantiated whenmain
is.