-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implementing nested scopes #1
Comments
Halfway through the language reference manual there's mention of the following:
|
For the MVP, here's a simple implementation with just a hash map: #2 |
Hello, also trying to implement nested scoping for my own compiler and looking at this issue has been helpful. Thank you. If I make any progress I can update here, if it is still active. |
Awesome! I've not come back to developing Vampa but I'd like to do it at some point. Updates on your progress here would be great, if you have the time. Also, could you link to your current progress? Just out of curiosity. |
Might be helpful: https://craftinginterpreters.com/local-variables.html |
Hello! I actually implemented nested scoping for my compiler project. I used an extra hidden struct argument in the form of an llvm struct that contains any variables the inner function needs from the outer scopres. Essentially you have nested structs of the form: |
I'm having trouble wrapping my head around how one can represent an AST that's inherently built to represent nested structures (scopes and control flow) into the mostly flat LLVM IR.
This is Christophe's suggestions from an email conversation (which we decided to bring onto GitHub) that should serve as an introduction in this topic:
At the moment, Vampa's variable references are unimplemented and variable declarations essentially just print out the most basic LLVM IR wherever the builder is currently positioned:
vampa/src/libvamc_llvm/src/variable_declaration.rs
Lines 28 to 34 in 78691f0
This means declared variables aren't actually accessible from anywhere. The LLVM tutorial language Kaleidoscope simply includes a hash map that stores variables by name, and this hash map is later on used to access the values those variables point to.
Although Vampa is a toy programming language and a learning project right now, I plan to implement nested scopes. A global hash map storing variables and nested scopes aren't concepts that go so well together, so...
The purpose of this issue is to discuss how one would go about implementing scopes in Vampa to achieve nested scopes. Two things are necessary:
LexicalScope
but I'm not sure if this is the right construct.LexicalScope
'sgetParent
method looks promising.If anyone knowledgeable on this topic happens to stumble upon this, I would gladly welcome some help or being pointed to a good resource.
Useful links:
The text was updated successfully, but these errors were encountered: