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

chore: improve tests and docs of persisted types #833

Merged
merged 11 commits into from
May 26, 2023
78 changes: 51 additions & 27 deletions gnovm/docs/go-gno-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,57 @@

Legend: full, partial, missing, TBD.

| keyword | status |
|-------------|--------|
| break | TBD |
| case | TBD |
| chan | TBD |
| const | TBD |
| continue | TBD |
| default | TBD |
| defer | TBD |
| else | TBD |
| fallthrough | TBD |
| for | TBD |
| func | TBD |
| go | TBD |
| goto | TBD |
| if | TBD |
| import | TBD |
| interface | TBD |
| map | TBD |
| package | TBD |
| range | TBD |
| return | TBD |
| select | TBD |
| struct | TBD |
| switch | TBD |
| type | TBD |
| var | TBD |
| keyword | support |
|-------------|------------------------|
| break | full |
| case | full |
| const | full |
| continue | full |
| default | full |
| defer | full |
| else | full |
| fallthrough | full |
| for | full |
| func | full |
| go | missing (after launch) |
| goto | full |
| if | full |
| import | full |
| interface | full |
| package | full |
| range | full |
| return | full |
| select | TBD |
moul marked this conversation as resolved.
Show resolved Hide resolved
| struct | full |
| switch | full |
| type | full |
| var | full |

## Native types

| type | usage | persistency | comment |
|-----------------------------------------------|------------------------|-------------------------------------------|-------------------------------------------|
| `bool` | full | full | |
| `byte` | full | full | |
| `float32`, `float64` | full | full | need review of determinism across systems |
| `int`, `int8`, `int16`, `int32`, `int64` | full | full | potential support of 128, 256 later |
| `uint`, `uint8`, `uint16`, `uint32`, `uint64` | full | full | potential support of 128, 256 later |
moul marked this conversation as resolved.
Show resolved Hide resolved
| `string` | full | full | |
| `rune` | full | full | |
| `interface{}` | full | full | |
| `[]T` (slices) | full | partial (depends on T) | |
moul marked this conversation as resolved.
Show resolved Hide resolved
| `map[T1]T2` | full | missing (in progress, will be for launch) | |
| `func (T1...) T2...` | full | full (to confirm) | |
moul marked this conversation as resolved.
Show resolved Hide resolved
| `*T` (pointers) | full | partial (depends on T) | |
moul marked this conversation as resolved.
Show resolved Hide resolved
| `chan T` (channels) | missing (after launch) | missing (after launch) | |

Additional native types:

| type | comment |
|----------|--------------------------------------------------------------------------------------------|
| `bigint` | Based on `math/big.Int` |
| `bigdec` | Based on https://github.com/cockroachdb/apd, (see https://github.com/gnolang/gno/pull/306) |


## Stdlibs

Expand Down
12 changes: 6 additions & 6 deletions gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ func UverseNode() *PackageNode {
def("._", undefined) // special, path is zero.
def("iota", undefined) // special
def("nil", undefined)
def("bigint", asValue(BigintType))
def("bool", asValue(BoolType))
def("string", asValue(StringType))
def("byte", asValue(Uint8Type))
def("float32", asValue(Float32Type))
def("float64", asValue(Float64Type))
def("int", asValue(IntType))
def("int8", asValue(Int8Type))
def("int16", asValue(Int16Type))
def("rune", asValue(Int32Type))
def("int32", asValue(Int32Type))
def("int64", asValue(Int64Type))
def("rune", asValue(Int32Type))
moul marked this conversation as resolved.
Show resolved Hide resolved
def("string", asValue(StringType))
def("uint", asValue(UintType))
def("byte", asValue(Uint8Type))
def("uint8", asValue(Uint8Type))
def("uint16", asValue(Uint16Type))
def("uint32", asValue(Uint32Type))
def("uint64", asValue(Uint64Type))
def("bigint", asValue(BigintType))
def("float32", asValue(Float32Type))
def("float64", asValue(Float64Type))
// NOTE on 'typeval': We can't call the type of a TypeValue a
// "type", even though we want to, because it conflicts with
// the pre-existing syntax for type-switching, `switch
Expand Down
94 changes: 94 additions & 0 deletions gnovm/tests/files/zpersist_valids.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// PKGPATH: gno.land/r/demo/tests_test
moul marked this conversation as resolved.
Show resolved Hide resolved
package tests_test

var (
// Native types
abigint bigint = 16
abool bool = true
abyte byte = 0x16
afloat32 float32 = 16.16
afloat64 float64 = 16.16
aint int = 16
aint8 int8 = 16
aint16 int16 = 16
aint32 int32 = 16
aint64 int64 = 16
arune rune = 'a'
astring string = "hello"
astringslice []string = []string{"a"}
auint uint = 16
auint8 uint8 = 16
auint16 uint16 = 16
auint32 uint32 = 16
auint64 uint64 = 16
ainterface interface{} = interface{}
afunc func() string = func() string { return "a" }

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

// Not supported:
// error
)

func init() {
printVars("preinit ")
aint *= 2
afloat64 *= 2
astring += "."
astringslice = append(astringslice, "b")
abool = false
arune = 'b'
afunc = func() string { return "b" }

// TODO:
// amap["b"] = "2"
printVars("postinit")
}

func main() {
printVars("premain ")
aint *= 2
afloat64 *= 2
astring += "."
astringslice = append(astringslice, "c")
abool = true
arune = 'c'
afunc = func() string { return "c" }

// TODO:
// amap["c"] = "3"
printVars("postmain")
}

func printVars(phase string) {
println(phase,
// variables
abigint,
abool,
abyte,
afloat32,
afloat64,
aint,
aint8,
aint16,
aint32,
aint64,
arune,
astring,
astringslice,
auint,
auint8,
auint16,
auint32,
auint64,
ainterface,
afunc(),
)
}

// Output:
// preinit 16 true 22 16.16 16.16 16 16 16 16 16 97 hello slice[("a" string)] 16 16 16 16 16 typeval{interface{} (0xc000370cd0)} a
// postinit 16 false 22 16.16 32.32 32 16 16 16 16 98 hello. slice[("a" string),("b" string)] 16 16 16 16 16 typeval{interface{} (0xc000370cd0)} b
// premain 16 false 22 16.16 32.32 32 16 16 16 16 98 hello. slice[ref(0e4830f6b0cb49c615cab8df855d8dd0f7ebc58c:4)] 16 16 16 16 16 typeval{interface{} (0xc00007e870)} b
// postmain 16 true 22 16.16 64.64 64 16 16 16 16 99 hello.. slice[("a" string),("b" string),("c" string)] 16 16 16 16 16 typeval{interface{} (0xc00007e870)} c