Skip to content

Commit

Permalink
remove predefine call; update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Jun 26, 2024
1 parent 6c1bf35 commit 8e9c9a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 7 additions & 7 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -320,6 +321,7 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) {
default:
panic("should not happen")

Check warning on line 322 in gnovm/pkg/gnolang/preprocess.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/preprocess.go#L321-L322

Added lines #L321 - L322 were not covered by tests
}
return n, TRANS_CONTINUE

// ----------------------------------------
case TRANS_LEAVE:
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

0 comments on commit 8e9c9a1

Please sign in to comment.