aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authoralandonovan <adonovan@google.com>2019-04-03 16:43:05 -0400
committerGitHub <noreply@github.com>2019-04-03 16:43:05 -0400
commit754257e2330d5bfdefb6457ab834ababe2ee7114 (patch)
tree30564ab7d4c151538257543ca8586fd3e48febe3 /internal
parent40b4ab64fdb1cb06df3f70b1b06076de0a40bb2f (diff)
downloadstarlark-go-754257e2330d5bfdefb6457ab834ababe2ee7114.tar.gz
resolve: load statements now create local bindings (#178)
Previously, load statements created global bindings. As an often-unwanted consequence, names loaded by one module would leak into its module dictionary and be visible to others. This change to the resolver makes load define file-local variables using a similar approach to Go: a new lexical block (the file block) between function/comprehension blocks and the globals. The set of names in the file block and the globals must be disjoint. This incompatible change is guarded by the LoadBindsGlobally flag, which is false by default. Users who want the old behavior may set it to true, but they should prepare for it to go away entirely. After that point, the old behavior may be simulated thus: - load("...", "x") + load("...", _x="x"); x = _x # re-export Observe that no run-time or API changes are required.
Diffstat (limited to 'internal')
-rw-r--r--internal/compile/compile.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/internal/compile/compile.go b/internal/compile/compile.go
index 4160096..b8f4618 100644
--- a/internal/compile/compile.go
+++ b/internal/compile/compile.go
@@ -41,7 +41,7 @@ import (
const debug = false // TODO(adonovan): use a bitmap of options; and regexp to match files
// Increment this to force recompilation of saved bytecode files.
-const Version = 8
+const Version = 9
type Opcode uint8
@@ -1146,7 +1146,7 @@ func (fcomp *fcomp) stmt(stmt syntax.Stmt) {
fcomp.setPos(stmt.Load)
fcomp.emit1(LOAD, uint32(len(stmt.From)))
for i := range stmt.To {
- fcomp.emit1(SETGLOBAL, uint32(stmt.To[len(stmt.To)-1-i].Binding.Index))
+ fcomp.set(stmt.To[len(stmt.To)-1-i])
}
default: