From 8e9c9a1ba1af27801a7bb909536a302b8428aad8 Mon Sep 17 00:00:00 2001 From: jaekwon Date: Tue, 25 Jun 2024 18:01:19 -0700 Subject: [PATCH] remove predefine call; update comments --- gnovm/pkg/gnolang/preprocess.go | 14 +++++++------- gnovm/pkg/gnolang/preprocess_test.go | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 1665bf10b5a..edef039d137 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -19,10 +19,16 @@ const ( // phase. func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { // First, initialize all file nodes and connect to package node. + // This will also reserve names on BlockNode.StaticBlock by + // calling StaticBlock.Predefine(). for _, fn := range fset.Files { SetNodeLocations(pn.PkgPath, string(fn.Name), fn) initStaticBlocks(store, pn, fn) } + // NOTE: The calls to .Predefine() above is more of a name reservation, + // and what comes later in PredefineFileset() below is a second type of + // pre-defining mixed with defining, where recursive types are defined + // first and then filled out later. // NOTE: much of what follows is duplicated for a single *FileNode // in the main Preprocess translation function. Keep synced. @@ -109,11 +115,6 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { // iterate over all nodes recursively. _ = Transcribe(bn, func(ns []Node, ftype TransField, index int, n Node, stage TransStage) (Node, TransCtrl) { - // if already preprocessed, skip it. - if n.GetAttribute(ATTR_PREPROCESSED) == true { - return n, TRANS_SKIP - } - defer func() { if r := recover(); r != nil { // before re-throwing the error, append location information to message. @@ -320,6 +321,7 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { default: panic("should not happen") } + return n, TRANS_CONTINUE // ---------------------------------------- case TRANS_LEAVE: @@ -3267,13 +3269,11 @@ func tryPredefine(store Store, last BlockNode, d Decl) (un Name) { return } } - last2 := skipFile(last) for i := 0; i < len(d.NameExprs); i++ { nx := &d.NameExprs[i] if nx.Name == blankIdentifier { nx.Path.Name = blankIdentifier } else { - last2.Predefine(d.Const, nx.Name) nx.Path = last.GetPathForName(store, nx.Name) } } diff --git a/gnovm/pkg/gnolang/preprocess_test.go b/gnovm/pkg/gnolang/preprocess_test.go index 49e6d53fd3d..73e1318b062 100644 --- a/gnovm/pkg/gnolang/preprocess_test.go +++ b/gnovm/pkg/gnolang/preprocess_test.go @@ -31,6 +31,7 @@ func main() { err := recover() assert.Contains(t, fmt.Sprint(err), "incompatible operands in binary expression") }() + initStaticBlocks(store, pn, n) Preprocess(store, pn, n) } @@ -56,5 +57,6 @@ func main() { err := recover() assert.Contains(t, fmt.Sprint(err), "incompatible operands in binary expression") }() + initStaticBlocks(store, pn, n) Preprocess(store, pn, n) }