fix: pre-allocate slot zero in every compiled chunk to fix REPL local variable declarations

The compiler now always reserves slot zero for either the closure or method
receiver, eliminating a corner case where top-level REPL code lacked the
pre-allocated slot that function/method bodies expect. This ensures local
variables declared in REPL loops (e.g. `for (i in 1..2)`) get correct slot
indexes.

Additionally, inlines `wrenResetFiber` into `wrenNewFiber` and stores the
imported module's closure on the stack before invoking it, preventing a GC
from collecting the closure during import.
This commit is contained in:
Bob Nystrom
2018-04-27 15:20:49 +00:00
parent 7bb024eccc
commit 248e3a69f0
9 changed files with 66 additions and 73 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
{
var a0 = "value"
var a1 = a0
// Slot zero is always taken to hold the closure or receiver.
var a1 = "value"
var a2 = a1
var a3 = a2
var a4 = a3
@@ -1,10 +1,10 @@
// Can have more than 256 local variables in a local scope, as long as they
// Can have more than 255 local variables in a local scope, as long as they
// aren't all in scope at the same time.
{
{
var a0 = "value a"
var a1 = a0
// Slot zero is always taken to hold the closure or receiver.
var a1 = "value a"
var a2 = a1
var a3 = a2
var a4 = a3
@@ -263,8 +263,8 @@
}
{
var b0 = "value b"
var b1 = b0
// Slot zero is always taken to hold the closure or receiver.
var b1 = "value b"
var b2 = b1
var b3 = b2
var b4 = b3
+2 -2
View File
@@ -1,6 +1,6 @@
{
var a0 = "value"
var a1 = a0
// Slot zero is always taken to hold the closure or receiver.
var a1 = "value"
var a2 = a1
var a3 = a2
var a4 = a3
@@ -1,6 +1,6 @@
{
var a0 = "value"
var a1 = a0
// Slot zero is always taken to hold the closure or receiver.
var a1 = "value"
var a2 = a1
var a3 = a2
var a4 = a3