Get closures working!

In the process, I had to change the grammar. There is now a strong
separation between statements and expressions. The code was just wrong
before when it popped locals at the end of a block scope because there
could be temporaries on the stack if the block was in expression
position. This fixes that.

Still need to implement closing over `this`.
This commit is contained in:
Bob Nystrom
2013-12-04 07:43:50 -08:00
parent c14b115c02
commit 157944aa27
32 changed files with 1063 additions and 416 deletions
+6 -2
View File
@@ -1,9 +1,13 @@
// Create a local scope for the 'then' expression.
var a = "out"
if (true) var a = "in"
if (true) {
var a = "in"
}
io.write(a) // expect: out
// Create a local scope for the 'else' expression.
var b = "out"
if (false) "dummy" else var b = "in"
if (false) "dummy" else {
var b = "in"
}
io.write(b) // expect: out
+3 -3
View File
@@ -1,7 +1,7 @@
// Body has its own scope.
var a = "outer"
var i = 0
while ((i = i + 1) <= 1) var a = "inner"
while ((i = i + 1) <= 1) {
var a = "inner"
}
io.write(a) // expect: outer
// TODO(bob): What about condition?