Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gnovm): load map from state #932

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gnovm/docs/go-gno-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ Legend: full, partial, missing, TBD.
| `rune` | full | full |
| `interface{}` | full | full |
| `[]T` (slices) | full | full* |
| `map[T1]T2` | full | missing (in progress, will be for launch) |
| `map[T1]T2` | full | full* |
| `func (T1...) T2...` | full | full (needs more tests) |
| `*T` (pointers) | full | full* |
| `chan T` (channels) | missing (after launch) | missing (after launch) |

**\*:** depends on `T`
**\*:** depends on `T`/`T1`/`T2`

Additional native types:

Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ func fillTypesOfValue(store Store, val Value) Value {
fillTypesTV(store, &cv.Receiver)
return cv
case *MapValue:
cv.MakeMap(cv.List.Size) // TODO move out.
cv.vmap = make(map[MapKey]*MapListItem, cv.List.Size)
for cur := cv.List.Head; cur != nil; cur = cur.Next {
fillTypesTV(store, &cur.Key)
fillTypesTV(store, &cur.Value)
Expand Down
5 changes: 4 additions & 1 deletion gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"unsafe"

"github.com/cockroachdb/apd"

"github.com/gnolang/gno/tm2/pkg/crypto"
)

Expand Down Expand Up @@ -661,7 +662,9 @@ func (ml *MapList) UnmarshalAmino(mlimg MapListImage) error {
ml.Head = item
}
item.Prev = ml.Tail
ml.Tail.Next = item
if ml.Tail != nil {
ml.Tail.Next = item
}
ml.Tail = item
ml.Size++
}
Expand Down
18 changes: 0 additions & 18 deletions gnovm/tests/challenges/persist_map.gno

This file was deleted.

22 changes: 22 additions & 0 deletions gnovm/tests/files/persist_map.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// PKGPATH: gno.land/r/demo/tests_test
package tests_test

var amap map[string]string = map[string]string{"a": "1"}

func init() {
println("preinit", amap)
amap["b"] = "2"
println("postinit", amap)
}

func main() {
println("premain", amap)
amap["c"] = "3"
println("postmain", amap)
}

// Output:
// preinit map{("a" string):("1" string)}
// postinit map{("a" string):("1" string),("b" string):("2" string)}
// premain map{("a" string):("1" string),("b" string):("2" string)}
// postmain map{("a" string):("1" string),("b" string):("2" string),("c" string):("3" string)}