Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ltzmaxwell committed Oct 18, 2024
1 parent 607e163 commit e4c78b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
13 changes: 4 additions & 9 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,14 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) {
if nn == blankIdentifier {
continue
}
if !isLocallyDefined(last, nn) {
nx.Type = NameExprTypeDefine
last2.Predefine(n.Const, nn)
}
nx.Type = NameExprTypeDefine
last2.Predefine(n.Const, nn)
}
case *TypeDecl:
last2 := skipFile(last)
nx := &n.NameExpr
nn := nx.Name
if !isLocallyDefined(last2, nn) {
nx.Type = NameExprTypeDefine
last2.Predefine(false, n.Name)
}
nx.Type = NameExprTypeDefine
last2.Predefine(false, n.Name)
case *FuncDecl:
if n.IsMethod {
if n.Recv.Name == "" || n.Recv.Name == blankIdentifier {
Expand Down
3 changes: 1 addition & 2 deletions gnovm/tests/files/heap_alloc_forloop1b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import "fmt"

var s1 []*int
var a interface{} = 1

func forLoopRef() {
defer func() {
Expand All @@ -27,7 +26,7 @@ func main() {
// go 1.22 loop var is not supported for now.

// Preprocessed:
// file{ package main; import fmt fmt; var s1<!VPBlock(2,0)> []*((const-type int)); var a<!VPBlock(2,1)> interface { } = (const (1 int)); func forLoopRef() { defer func func(){ for i<VPBlock(1,0)>, e<VPBlock(1,1)> := range s1<VPBlock(5,0)> { fmt<VPBlock(4,0)>.Printf((const ("s1[%d] is: %d\n" string)), (const-type gonative{interface {}})(i<VPBlock(1,0)>), (const-type gonative{interface {}})(*(e<VPBlock(1,1)>))) } }(); for i<!~VPBlock(1,0)> := (const (0 int)); i<~VPBlock(1,0)> < (const (3 int)); i<~VPBlock(1,0)>++ { r<!VPBlock(1,1)> := i<~VPBlock(1,0)>; r<VPBlock(1,1)>, ok<!VPBlock(1,2)> := (const (0 int)), (const (true bool)); (const (println func(xs ...interface{})()))(ok<VPBlock(1,2)>, r<VPBlock(1,1)>); s1<VPBlock(4,0)> = (const (append func(x []*int,args ...*int)(res []*int)))(s1<VPBlock(4,0)>, &(i<~VPBlock(1,0)>)) } }; func main() { forLoopRef<VPBlock(3,2)>() } }
// file{ package main; import fmt fmt; var s1<!VPBlock(2,0)> []*((const-type int)); func forLoopRef() { defer func func(){ for i<VPBlock(1,0)>, e<VPBlock(1,1)> := range s1<VPBlock(5,0)> { fmt<VPBlock(4,0)>.Printf((const ("s1[%d] is: %d\n" string)), (const-type gonative{interface {}})(i<VPBlock(1,0)>), (const-type gonative{interface {}})(*(e<VPBlock(1,1)>))) } }(); for i<!~VPBlock(1,0)> := (const (0 int)); i<~VPBlock(1,0)> < (const (3 int)); i<~VPBlock(1,0)>++ { r<!VPBlock(1,1)> := i<~VPBlock(1,0)>; r<VPBlock(1,1)>, ok<!VPBlock(1,2)> := (const (0 int)), (const (true bool)); (const (println func(xs ...interface{})()))(ok<VPBlock(1,2)>, r<VPBlock(1,1)>); s1<VPBlock(4,0)> = (const (append func(x []*int,args ...*int)(res []*int)))(s1<VPBlock(4,0)>, &(i<~VPBlock(1,0)>)) } }; func main() { forLoopRef<VPBlock(3,1)>() } }

// Output:
// true 0
Expand Down

0 comments on commit e4c78b6

Please sign in to comment.