Add support for "nonlocal" (capitalized) names, and change how variable lookup works.

Inside a method, all local variable lookup stops at the method boundary. In other
words, methods, do not close over outer local variables.

If a name is not found inside a method and is lowercase, it's a method on this.
If it's capitalized, it's a global variable.
This commit is contained in:
Bob Nystrom
2015-01-13 21:36:42 -08:00
parent 9cb414d63b
commit a8e2ba233c
8 changed files with 124 additions and 61 deletions
@@ -1,12 +1,12 @@
var f = null
var F = null
class Foo {
method(param) {
f = new Fn {
F = new Fn {
IO.print(param)
}
}
}
(new Foo).method("param")
f.call // expect: param
F.call // expect: param
-6
View File
@@ -1,6 +0,0 @@
var global = "global"
// TODO: Forward reference to global declared after use.
new Fn {
IO.print(global) // expect: global
}.call
-15
View File
@@ -1,15 +0,0 @@
var global = "global"
// TODO: Forward reference to global declared after use.
class Foo {
method {
IO.print(global)
}
static classMethod {
IO.print(global)
}
}
(new Foo).method // expect: global
Foo.classMethod // expect: global