You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TPL allows variables with the same name to be declared in different scopes. However, during bytecode generation, variables are resolved by performing a linear start-to-end lookup in the function's frame. This may not always be correct.
Example TPL:
fun main() -> int {
var a = 2
if (a < 10) {
var b = 8
if (a < b) {
var b = 5
if (a < b) {
var b = 1
if (a < b) {
return 100
}
}
}
}
return 2
}
One solution is to automatically uniq-ify all variable names internally, but we'll need to add extra metadata to the AST nodes. A simpler solution is to perform the linear search from inner-most scope to outer-most scope (as is done during semantic checks).
The text was updated successfully, but these errors were encountered:
Reminds me strongly of 312. We were taught that alpha-conversion is the one true way to do this, but I'll go look at what real compilers are doing for a bit.
I think this rightfully would call for something like de Bruijn indexes or Haskell's rapier, e.g. as described on [1]. But I can start by doing the dumb thing. I'm trying to figure out if there's a reason other people aren't doing the dumb thing.
TPL allows variables with the same name to be declared in different scopes. However, during bytecode generation, variables are resolved by performing a linear start-to-end lookup in the function's frame. This may not always be correct.
Example TPL:
One solution is to automatically uniq-ify all variable names internally, but we'll need to add extra metadata to the AST nodes. A simpler solution is to perform the linear search from inner-most scope to outer-most scope (as is done during semantic checks).
The text was updated successfully, but these errors were encountered: