compiler: implement shadowing of global variables
Before introducing slots it was hard to change global variables preserving changes across multiple function calls. This commit implements such possibility. Closes #638.
This commit is contained in:
parent
0cb6dc47e4
commit
e21015233b
2 changed files with 24 additions and 0 deletions
21
pkg/compiler/global_test.go
Normal file
21
pkg/compiler/global_test.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package compiler_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChangeGlobal(t *testing.T) {
|
||||
src := `package foo
|
||||
var a int
|
||||
func Main() int {
|
||||
setLocal()
|
||||
set42()
|
||||
setLocal()
|
||||
return a
|
||||
}
|
||||
func set42() { a = 42 }
|
||||
func setLocal() { a := 10; _ = a }`
|
||||
|
||||
eval(t, src, big.NewInt(42))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue