Skip to content

Commit

Permalink
fix(gnovm): load map from state (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Jun 27, 2023
1 parent abf7792 commit d684985
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
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)}

0 comments on commit d684985

Please sign in to comment.