diff --git a/.github/goreleaser.yaml b/.github/goreleaser.yaml index 95f7fdaab4c..186bac6f31a 100644 --- a/.github/goreleaser.yaml +++ b/.github/goreleaser.yaml @@ -67,6 +67,20 @@ builds: goarch: - amd64 - arm64 + - id: gnodev + dir: ./contribs/gnodev/cmd/gnodev + binary: gnodev + ldflags: + # using hardcoded ldflag + - -X github.com/gnolang/gno/gnovm/pkg/gnoenv._GNOROOT=/gnoroot + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 # Gno Contribs # NOTE: Contribs binary will be added in a single docker image below: gnocontribs - id: gnobro @@ -307,6 +321,48 @@ dockers: ids: - gnofaucet + # gnodev + - use: buildx + dockerfile: Dockerfile.release + goos: linux + goarch: amd64 + image_templates: + - "ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}-amd64" + - "ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}-amd64" + build_flag_templates: + - "--target=gnodev" + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}/gnodev" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + ids: + - gnodev + extra_files: + - examples + - gno.land/genesis/genesis_balances.txt + - gno.land/genesis/genesis_txs.jsonl + - use: buildx + dockerfile: Dockerfile.release + goos: linux + goarch: arm64 + image_templates: + - "ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}-arm64v8" + - "ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}-arm64v8" + build_flag_templates: + - "--target=gnodev" + - "--platform=linux/arm64/v8" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}/gnodev" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + ids: + - gnodev + extra_files: + - examples + - gno.land/genesis/genesis_balances.txt + - gno.land/genesis/genesis_txs.jsonl + # gnocontribs - use: buildx dockerfile: Dockerfile.release @@ -406,6 +462,16 @@ docker_manifests: - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-amd64 - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-arm64v8 + # gnodev + - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }} + image_templates: + - ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}-amd64 + - ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}-arm64v8 + - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }} + image_templates: + - ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}-amd64 + - ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}-arm64v8 + # gnocontribs - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }} image_templates: diff --git a/Dockerfile.release b/Dockerfile.release index c7bb1b582ed..69a508000aa 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -44,6 +44,18 @@ COPY ./gnofaucet /usr/bin/gnofaucet EXPOSE 5050 ENTRYPOINT [ "/usr/bin/gnofaucet" ] +# +## ghcr.io/gnolang/gno/gnodev +FROM base as gnodev + +COPY ./gnodev /usr/bin/gnodev +COPY ./examples /gnoroot/examples/ +COPY ./gno.land/genesis/genesis_balances.txt /gnoroot/gno.land/genesis/genesis_balances.txt +COPY ./gno.land/genesis/genesis_txs.jsonl /gnoroot/gno.land/genesis/genesis_txs.jsonl +# gnoweb exposed by default +EXPOSE 8888 +ENTRYPOINT [ "/usr/bin/gnodev" ] + # ## ghcr.io/gnolang/gno FROM base as gno diff --git a/examples/gno.land/r/leon/config/config.gno b/examples/gno.land/r/leon/config/config.gno index bb90a6c21d7..eaea52c951e 100644 --- a/examples/gno.land/r/leon/config/config.gno +++ b/examples/gno.land/r/leon/config/config.gno @@ -3,22 +3,18 @@ package config import ( "errors" "std" - "strconv" "strings" "time" "gno.land/p/demo/avl" - p "gno.land/p/demo/avl/pager" "gno.land/p/demo/ownable" - "gno.land/p/demo/ufmt" - "gno.land/p/moul/md" - "gno.land/p/moul/realmpath" + "gno.land/p/demo/seqid" ) var ( + cfgID seqid.ID configs = avl.NewTree() - pager = p.NewPager(configs, 10, false) - banner = "---\n[[Leon's Home page]](/r/leon/home) | [[GitHub: @leohhhn]](https://github.com/leohhhn)\n\n---" + absPath = strings.TrimPrefix(std.CurrentRealm().PkgPath(), std.GetChainDomain()) // SafeObjects @@ -29,6 +25,8 @@ var ( ) type Config struct { + id seqid.ID + name string lines string updated time.Time } @@ -38,81 +36,50 @@ func AddConfig(name, lines string) { panic(ErrUnauthorized) } - configs.Set(name, Config{ + id := cfgID.Next() + configs.Set(id.String(), Config{ + id: id, + name: name, lines: lines, updated: time.Now(), - }) // no overwrite check + }) } -func RemoveConfig(name string) { +func EditConfig(id string, name, lines string) { if !IsAuthorized(std.PrevRealm().Addr()) { panic(ErrUnauthorized) } - if _, ok := configs.Remove(name); !ok { - panic("no config with that name") + raw, ok := configs.Remove(id) + if !ok { + panic("no config with that id") } + + conf := raw.(Config) + // Overwrites data + conf.lines = lines + conf.name = name + conf.updated = time.Now() } -func UpdateBanner(newBanner string) { +func RemoveConfig(id string) { if !IsAuthorized(std.PrevRealm().Addr()) { panic(ErrUnauthorized) } - banner = newBanner -} - -func IsAuthorized(addr std.Address) bool { - return addr == OwnableMain.Owner() || addr == OwnableBackup.Owner() -} - -func Banner() string { - return banner -} - -func Render(path string) (out string) { - req := realmpath.Parse(path) - if req.Path == "" { - out += md.H1("Leon's config package") - - out += ufmt.Sprintf("Leon's main address: %s\n\n", OwnableMain.Owner().String()) - out += ufmt.Sprintf("Leon's backup address: %s\n\n", OwnableBackup.Owner().String()) - - out += md.H2("Leon's configs") - - if configs.Size() == 0 { - out += "No configs yet :c\n\n" - } - - page := pager.MustGetPageByPath(path) - for _, item := range page.Items { - out += ufmt.Sprintf("- [%s](%s:%s)\n\n", item.Key, absPath, item.Key) - } - - out += page.Picker() - out += "\n\n" - out += "Page " + strconv.Itoa(page.PageNumber) + " of " + strconv.Itoa(page.TotalPages) + "\n\n" - - out += Banner() - - return out + if _, ok := configs.Remove(id); !ok { + panic("no config with that id") } - - return renderConfPage(req.Path) } -func renderConfPage(confName string) (out string) { - raw, ok := configs.Get(confName) - if !ok { - out += md.H1("404") - out += "That config does not exist :/" - return out +func UpdateBanner(newBanner string) { + if !IsAuthorized(std.PrevRealm().Addr()) { + panic(ErrUnauthorized) } - conf := raw.(Config) - out += md.H1(confName) - out += ufmt.Sprintf("```\n%s\n```\n\n", conf.lines) - out += ufmt.Sprintf("_Last updated on %s_", conf.updated.Format("02 Jan, 2006")) + banner = newBanner +} - return out +func IsAuthorized(addr std.Address) bool { + return addr == OwnableMain.Owner() || addr == OwnableBackup.Owner() } diff --git a/examples/gno.land/r/leon/config/render.gno b/examples/gno.land/r/leon/config/render.gno new file mode 100644 index 00000000000..e32435b0d59 --- /dev/null +++ b/examples/gno.land/r/leon/config/render.gno @@ -0,0 +1,69 @@ +package config + +import ( + "strconv" + + p "gno.land/p/demo/avl/pager" + "gno.land/p/demo/ufmt" + "gno.land/p/moul/md" + "gno.land/p/moul/realmpath" + "gno.land/p/moul/txlink" +) + +var ( + banner = "---\n[[Leon's Home page]](/r/leon/home) | [[Leon's snippets]](/r/leon/config) | [[GitHub: @leohhhn]](https://github.com/leohhhn)\n\n---" + pager = p.NewPager(configs, 10, true) +) + +func Banner() string { + return banner +} + +func Render(path string) (out string) { + req := realmpath.Parse(path) + if req.Path == "" { + out += md.H1("Leon's configs & snippets") + + out += ufmt.Sprintf("Leon's main address: %s\n\n", OwnableMain.Owner().String()) + out += ufmt.Sprintf("Leon's backup address: %s\n\n", OwnableBackup.Owner().String()) + + out += md.H2("Snippets") + + if configs.Size() == 0 { + out += "No configs yet :c\n\n" + } else { + page := pager.MustGetPageByPath(path) + for _, item := range page.Items { + out += ufmt.Sprintf("- [%s](%s:%s)\n\n", item.Value.(Config).name, absPath, item.Key) + } + + out += page.Picker() + out += "\n\n" + out += "Page " + strconv.Itoa(page.PageNumber) + " of " + strconv.Itoa(page.TotalPages) + "\n\n" + } + + out += Banner() + + return out + } + + return renderConfPage(req.Path) +} + +func renderConfPage(id string) (out string) { + raw, ok := configs.Get(id) + if !ok { + out += md.H1("404") + out += "That config does not exist :/" + return out + } + + conf := raw.(Config) + out += md.H1(conf.name) + out += ufmt.Sprintf("```\n%s\n```\n\n", conf.lines) + out += ufmt.Sprintf("_Last updated on %s_\n\n", conf.updated.Format("02 Jan, 2006")) + out += md.HorizontalRule() + out += ufmt.Sprintf("[[EDIT]](%s) - [[DELETE]](%s)", txlink.Call("EditConfig", "id", conf.id.String()), txlink.Call("RemoveConfig", "id", conf.id.String())) + + return out +} diff --git a/gnovm/pkg/gnolang/gno_test.go b/gnovm/pkg/gnolang/gno_test.go index 5a8c6faf315..16ea1f4118d 100644 --- a/gnovm/pkg/gnolang/gno_test.go +++ b/gnovm/pkg/gnolang/gno_test.go @@ -64,7 +64,6 @@ func TestBuiltinIdentifiersShadowing(t *testing.T) { "println", "recover", "nil", - "bigint", "bool", "byte", "float32", @@ -247,7 +246,7 @@ func main() { }, { `package test - + func main() { const f = float64(1.0) println(int64(f)) diff --git a/gnovm/pkg/gnolang/gonative.go b/gnovm/pkg/gnolang/gonative.go index a777c1cef3e..0a2429fb1c6 100644 --- a/gnovm/pkg/gnolang/gonative.go +++ b/gnovm/pkg/gnolang/gonative.go @@ -769,9 +769,9 @@ func gno2GoType(t Type) reflect.Type { return reflect.TypeOf(float32(0)) case Float64Type: return reflect.TypeOf(float64(0)) - case BigintType, UntypedBigintType: + case UntypedBigintType: panic("not yet implemented") - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: panic("not yet implemented") default: panic("should not happen") @@ -887,9 +887,9 @@ func gno2GoTypeMatches(t Type, rt reflect.Type) (result bool) { return rt.Kind() == reflect.Float32 case Float64Type: return rt.Kind() == reflect.Float64 - case BigintType, UntypedBigintType: + case UntypedBigintType: panic("not yet implemented") - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: panic("not yet implemented") default: panic("should not happen") diff --git a/gnovm/pkg/gnolang/nodes.go b/gnovm/pkg/gnolang/nodes.go index 0e8f701dea8..b2e646cf697 100644 --- a/gnovm/pkg/gnolang/nodes.go +++ b/gnovm/pkg/gnolang/nodes.go @@ -2119,12 +2119,28 @@ func (x *PackageNode) SetBody(b Body) { // such as those for *DeclaredType methods or *StructType fields, // see tests/selector_test.go. type ValuePath struct { - Type VPType // see VPType* consts. + Type VPType // see VPType* consts. + // Warning: Use SetDepth() to set Depth. Depth uint8 // see doc for ValuePath. Index uint16 // index of value, field, or method. Name Name // name of value, field, or method. } +// Maximum depth of a ValuePath. +const MaxValuePathDepth = 127 + +func (vp ValuePath) validateDepth() { + if vp.Depth > MaxValuePathDepth { + panic(fmt.Sprintf("exceeded maximum %s depth (%d)", vp.Type, MaxValuePathDepth)) + } +} + +func (vp *ValuePath) SetDepth(d uint8) { + vp.Depth = d + + vp.validateDepth() +} + type VPType uint8 const ( @@ -2203,6 +2219,8 @@ func NewValuePathNative(n Name) ValuePath { } func (vp ValuePath) Validate() { + vp.validateDepth() + switch vp.Type { case VPUverse: if vp.Depth != 0 { diff --git a/gnovm/pkg/gnolang/op_binary.go b/gnovm/pkg/gnolang/op_binary.go index 42419ec5d54..ad41cb7d0ff 100644 --- a/gnovm/pkg/gnolang/op_binary.go +++ b/gnovm/pkg/gnolang/op_binary.go @@ -719,11 +719,11 @@ func addAssign(alloc *Allocator, lv, rv *TypedValue) { case Float64Type: // NOTE: gno doesn't fuse *+. lv.SetFloat64(softfloat.Fadd64(lv.GetFloat64(), rv.GetFloat64())) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Add(lb, rv.GetBigInt()) lv.V = BigintValue{V: lb} - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: lb := lv.GetBigDec() rb := rv.GetBigDec() sum := apd.New(0, 0) @@ -775,11 +775,11 @@ func subAssign(lv, rv *TypedValue) { case Float64Type: // NOTE: gno doesn't fuse *+. lv.SetFloat64(softfloat.Fsub64(lv.GetFloat64(), rv.GetFloat64())) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Sub(lb, rv.GetBigInt()) lv.V = BigintValue{V: lb} - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: lb := lv.GetBigDec() rb := rv.GetBigDec() diff := apd.New(0, 0) @@ -831,11 +831,11 @@ func mulAssign(lv, rv *TypedValue) { case Float64Type: // NOTE: gno doesn't fuse *+. lv.SetFloat64(softfloat.Fmul64(lv.GetFloat64(), rv.GetFloat64())) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Mul(lb, rv.GetBigInt()) lv.V = BigintValue{V: lb} - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: lb := lv.GetBigDec() rb := rv.GetBigDec() prod := apd.New(0, 0) @@ -929,14 +929,14 @@ func quoAssign(lv, rv *TypedValue) *Exception { if ok { lv.SetFloat64(softfloat.Fdiv64(lv.GetFloat64(), rv.GetFloat64())) } - case BigintType, UntypedBigintType: + case UntypedBigintType: if rv.GetBigInt().Sign() == 0 { return expt } lb := lv.GetBigInt() lb = big.NewInt(0).Quo(lb, rv.GetBigInt()) lv.V = BigintValue{V: lb} - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: if rv.GetBigDec().Cmp(apd.New(0, 0)) == 0 { return expt } @@ -1022,7 +1022,7 @@ func remAssign(lv, rv *TypedValue) *Exception { return expt } lv.SetUint64(lv.GetUint64() % rv.GetUint64()) - case BigintType, UntypedBigintType: + case UntypedBigintType: if rv.GetBigInt().Sign() == 0 { return expt } @@ -1067,7 +1067,7 @@ func bandAssign(lv, rv *TypedValue) { lv.SetUint32(lv.GetUint32() & rv.GetUint32()) case Uint64Type: lv.SetUint64(lv.GetUint64() & rv.GetUint64()) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).And(lb, rv.GetBigInt()) lv.V = BigintValue{V: lb} @@ -1106,7 +1106,7 @@ func bandnAssign(lv, rv *TypedValue) { lv.SetUint32(lv.GetUint32() &^ rv.GetUint32()) case Uint64Type: lv.SetUint64(lv.GetUint64() &^ rv.GetUint64()) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).AndNot(lb, rv.GetBigInt()) lv.V = BigintValue{V: lb} @@ -1145,7 +1145,7 @@ func borAssign(lv, rv *TypedValue) { lv.SetUint32(lv.GetUint32() | rv.GetUint32()) case Uint64Type: lv.SetUint64(lv.GetUint64() | rv.GetUint64()) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Or(lb, rv.GetBigInt()) lv.V = BigintValue{V: lb} @@ -1184,7 +1184,7 @@ func xorAssign(lv, rv *TypedValue) { lv.SetUint32(lv.GetUint32() ^ rv.GetUint32()) case Uint64Type: lv.SetUint64(lv.GetUint64() ^ rv.GetUint64()) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Xor(lb, rv.GetBigInt()) lv.V = BigintValue{V: lb} @@ -1308,7 +1308,7 @@ func shlAssign(m *Machine, lv, rv *TypedValue) { }) lv.SetUint64(lv.GetUint64() << rv.GetUint()) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Lsh(lb, uint(rv.GetUint())) lv.V = BigintValue{V: lb} @@ -1432,7 +1432,7 @@ func shrAssign(m *Machine, lv, rv *TypedValue) { }) lv.SetUint64(lv.GetUint64() >> rv.GetUint()) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Rsh(lb, uint(rv.GetUint())) lv.V = BigintValue{V: lb} diff --git a/gnovm/pkg/gnolang/op_inc_dec.go b/gnovm/pkg/gnolang/op_inc_dec.go index 708aae821ac..ee0e90a94a5 100644 --- a/gnovm/pkg/gnolang/op_inc_dec.go +++ b/gnovm/pkg/gnolang/op_inc_dec.go @@ -58,11 +58,11 @@ func (m *Machine) doOpInc() { lv.SetFloat32(softfloat.Fadd32(lv.GetFloat32(), softfloat.Fintto32(1))) case Float64Type: lv.SetFloat64(softfloat.Fadd64(lv.GetFloat64(), softfloat.Fintto64(1))) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Add(lb, big.NewInt(1)) lv.V = BigintValue{V: lb} - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: lb := lv.GetBigDec() sum := apd.New(0, 0) cond, err := apd.BaseContext.WithPrecision(0).Add(sum, lb, apd.New(1, 0)) @@ -128,11 +128,11 @@ func (m *Machine) doOpDec() { lv.SetFloat32(softfloat.Fsub32(lv.GetFloat32(), softfloat.Fintto32(1))) case Float64Type: lv.SetFloat64(softfloat.Fsub64(lv.GetFloat64(), softfloat.Fintto64(1))) - case BigintType, UntypedBigintType: + case UntypedBigintType: lb := lv.GetBigInt() lb = big.NewInt(0).Sub(lb, big.NewInt(1)) lv.V = BigintValue{V: lb} - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: lb := lv.GetBigDec() sum := apd.New(0, 0) cond, err := apd.BaseContext.WithPrecision(0).Sub(sum, lb, apd.New(1, 0)) diff --git a/gnovm/pkg/gnolang/op_types.go b/gnovm/pkg/gnolang/op_types.go index e3003066037..640ddc7d9a9 100644 --- a/gnovm/pkg/gnolang/op_types.go +++ b/gnovm/pkg/gnolang/op_types.go @@ -239,7 +239,7 @@ func (m *Machine) doOpStaticTypeOf() { dxt = xt case 1: dxt = baseOf(xt) - path.Depth = 0 + path.SetDepth(0) default: panic("should not happen") } @@ -247,16 +247,16 @@ func (m *Machine) doOpStaticTypeOf() { switch path.Depth { case 0: dxt = xt.Elem() - path.Depth = 0 + path.SetDepth(0) case 1: dxt = xt.Elem() - path.Depth = 0 + path.SetDepth(0) case 2: dxt = baseOf(xt.Elem()) - path.Depth = 0 + path.SetDepth(0) case 3: dxt = baseOf(xt.Elem()) - path.Depth = 0 + path.SetDepth(0) default: panic("should not happen") } @@ -265,19 +265,19 @@ func (m *Machine) doOpStaticTypeOf() { case 0: dxt = xt.Elem() path.Type = VPField - path.Depth = 0 + path.SetDepth(0) case 1: dxt = xt.Elem() path.Type = VPField - path.Depth = 0 + path.SetDepth(0) case 2: dxt = baseOf(xt.Elem()) path.Type = VPField - path.Depth = 0 + path.SetDepth(0) case 3: dxt = baseOf(xt.Elem()) path.Type = VPField - path.Depth = 0 + path.SetDepth(0) default: panic("should not happen") } diff --git a/gnovm/pkg/gnolang/op_unary.go b/gnovm/pkg/gnolang/op_unary.go index 469c80b8dac..fdf4324349c 100644 --- a/gnovm/pkg/gnolang/op_unary.go +++ b/gnovm/pkg/gnolang/op_unary.go @@ -50,10 +50,10 @@ func (m *Machine) doOpUneg() { xv.SetFloat32(softfloat.Fneg32(xv.GetFloat32())) case Float64Type: xv.SetFloat64(softfloat.Fneg64(xv.GetFloat64())) - case UntypedBigintType, BigintType: + case UntypedBigintType: bv := xv.V.(BigintValue) xv.V = BigintValue{V: new(big.Int).Neg(bv.V)} - case UntypedBigdecType, BigdecType: + case UntypedBigdecType: bv := xv.V.(BigdecValue) xv.V = BigdecValue{V: apd.New(0, 0).Neg(bv.V)} case nil: @@ -112,7 +112,7 @@ func (m *Machine) doOpUxor() { xv.SetUint32(^xv.GetUint32()) case Uint64Type: xv.SetUint64(^xv.GetUint64()) - case UntypedBigintType, BigintType: + case UntypedBigintType: // XXX can it even be implemented? panic("not yet implemented") default: diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 26e67e71fad..e30f02b1b87 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1402,6 +1402,19 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node { if !constConverted { convertConst(store, last, n, arg0, nil) } + + // check legal type for nil + if arg0.IsUndefined() { + switch ct.Kind() { // special case for nil conversion check. + case SliceKind, PointerKind, FuncKind, MapKind, InterfaceKind, ChanKind: + convertConst(store, last, n, arg0, ct) + default: + panic(fmt.Sprintf( + "cannot convert %v to %v", + arg0, ct.Kind())) + } + } + // evaluate the new expression. cx := evalConst(store, last, n) // Though cx may be undefined if ct is interface, @@ -2886,7 +2899,7 @@ func findLoopUses1(ctx BlockNode, bn BlockNode) { idx := addHeapCapture(dbn, fle, n.Name) // adjust NameExpr type. n.Type = NameExprTypeHeapUse - n.Path.Depth = uint8(depth) + n.Path.SetDepth(uint8(depth)) n.Path.Index = idx } else { if ftype == TRANS_REF_X { @@ -2982,7 +2995,7 @@ func addHeapCapture(dbn BlockNode, fle *FuncLitExpr, name Name) (idx uint16) { // add name to fle.HeapCaptures. vp := fle.GetPathForName(nil, name) - vp.Depth -= 1 // minus 1 for fle itself. + vp.SetDepth(vp.Depth - 1) // minus 1 for fle itself. ne := NameExpr{ Path: vp, Name: name, @@ -5066,7 +5079,8 @@ func fillNameExprPath(last BlockNode, nx *NameExpr, isDefineLHS bool) { break } } - path.Depth += uint8(i) + path.SetDepth(path.Depth + uint8(i)) + path.Validate() nx.Path = path return } diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 3a70d07381b..84625bd92c1 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -1028,7 +1028,7 @@ func InitStoreCaches(store Store) { StringType, UntypedStringType, IntType, Int8Type, Int16Type, Int32Type, Int64Type, UntypedRuneType, UintType, Uint8Type, Uint16Type, Uint32Type, Uint64Type, - BigintType, UntypedBigintType, + UntypedBigintType, gTypeType, gPackageType, blockType{}, diff --git a/gnovm/pkg/gnolang/types.go b/gnovm/pkg/gnolang/types.go index 8ac07162f10..259c3e0a5ae 100644 --- a/gnovm/pkg/gnolang/types.go +++ b/gnovm/pkg/gnolang/types.go @@ -108,9 +108,7 @@ const ( Float32Type Float64Type UntypedBigintType - BigintType UntypedBigdecType - BigdecType // UintptrType ) @@ -153,20 +151,16 @@ func (pt PrimitiveType) Specificity() int { return 0 case Float64Type: return 0 - case BigintType: - return 1 - case BigdecType: - return 2 case UntypedBigdecType: - return 3 + return 1 case UntypedStringType: - return 4 + return 2 case UntypedBigintType: - return 4 + return 2 case UntypedRuneType: - return 5 + return 3 case UntypedBoolType: - return 6 + return 4 default: panic(fmt.Sprintf("unexpected primitive type %v", pt)) } @@ -204,9 +198,9 @@ func (pt PrimitiveType) Kind() Kind { return Float32Kind case Float64Type: return Float64Kind - case BigintType, UntypedBigintType: + case UntypedBigintType: return BigintKind - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: return BigdecKind default: panic(fmt.Sprintf("unexpected primitive type %v", pt)) @@ -256,12 +250,8 @@ func (pt PrimitiveType) TypeID() TypeID { return typeid("float64") case UntypedBigintType: return typeid(" bigint") - case BigintType: - return typeid("bigint") case UntypedBigdecType: return typeid(" bigdec") - case BigdecType: - return typeid("bigdec") default: panic(fmt.Sprintf("unexpected primitive type %v", pt)) } @@ -309,12 +299,8 @@ func (pt PrimitiveType) String() string { return string("float64") case UntypedBigintType: return string(" bigint") - case BigintType: - return string("bigint") case UntypedBigdecType: return string(" bigdec") - case BigdecType: - return string("bigdec") default: panic(fmt.Sprintf("unexpected primitive type %d", pt)) } @@ -698,7 +684,7 @@ func (pt *PointerType) FindEmbeddedFieldType(callerPath string, n Name, m map[Ty case 1: // *DeclaredType > *StructType.Field has depth 1 (& type VPField). // *PointerType > *DeclaredType > *StructType.Field has depth 2. - trail[0].Depth = 2 + trail[0].SetDepth(2) /* // If trail[-1].Type == VPPtrMethod, set VPDerefPtrMethod. if len(trail) > 1 && trail[1].Type == VPPtrMethod { @@ -1602,7 +1588,7 @@ func (dt *DeclaredType) GetPathForName(n Name) ValuePath { } // Otherwise it is underlying. path := dt.Base.(ValuePather).GetPathForName(n) - path.Depth += 1 + path.SetDepth(path.Depth + 1) return path } @@ -1672,7 +1658,8 @@ func (dt *DeclaredType) FindEmbeddedFieldType(callerPath string, n Name, m map[T panic("should not happen") } } - trail[0].Depth += 1 + + trail[0].SetDepth(trail[0].Depth + 1) return trail, hasPtr, rcvr, ft, false default: panic("should not happen") @@ -2206,9 +2193,9 @@ func KindOf(t Type) Kind { return Float32Kind case Float64Type: return Float64Kind - case BigintType, UntypedBigintType: + case UntypedBigintType: return BigintKind - case BigdecType, UntypedBigdecType: + case UntypedBigdecType: return BigdecKind default: panic(fmt.Sprintf("unexpected primitive type %s", t.String())) @@ -2401,12 +2388,6 @@ func fillEmbeddedName(ft *FieldType) { ft.Name = Name("float32") case Float64Type: ft.Name = Name("float64") - case BigintType: - ft.Name = Name("bigint") - case BigdecType: - ft.Name = Name("bigdec") - default: - panic("should not happen") } case *NativeType: panic("native type cannot be embedded") diff --git a/gnovm/pkg/gnolang/uverse.go b/gnovm/pkg/gnolang/uverse.go index bfa4a6c65a7..55791ba4900 100644 --- a/gnovm/pkg/gnolang/uverse.go +++ b/gnovm/pkg/gnolang/uverse.go @@ -129,7 +129,6 @@ func makeUverseNode() { def("._", undefined) // special, path is zero. def("iota", undefined) // special def("nil", undefined) - def("bigint", asValue(BigintType)) def("bool", asValue(BoolType)) def("byte", asValue(Uint8Type)) def("float32", asValue(Float32Type)) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index ef537502bda..53919845de8 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -1130,8 +1130,6 @@ func (tv *TypedValue) PrimitiveBytes() (data []byte) { binary.LittleEndian.PutUint64( data, u64) return data - case BigintType: - return tv.V.(BigintValue).V.Bytes() default: panic(fmt.Sprintf( "unexpected primitive value type: %s", @@ -1667,7 +1665,7 @@ func (tv *TypedValue) GetPointerToFromTV(alloc *Allocator, store Store, path Val dtv = tv case 1: dtv = tv - path.Depth = 0 + path.SetDepth(0) default: panic("should not happen") } @@ -1679,15 +1677,15 @@ func (tv *TypedValue) GetPointerToFromTV(alloc *Allocator, store Store, path Val case 1: dtv = tv.V.(PointerValue).TV isPtr = true - path.Depth = 0 + path.SetDepth(0) case 2: dtv = tv.V.(PointerValue).TV isPtr = true - path.Depth = 0 + path.SetDepth(0) case 3: dtv = tv.V.(PointerValue).TV isPtr = true - path.Depth = 0 + path.SetDepth(0) default: panic("should not happen") } @@ -1701,7 +1699,7 @@ func (tv *TypedValue) GetPointerToFromTV(alloc *Allocator, store Store, path Val dtv = tv.V.(PointerValue).TV isPtr = true path.Type = VPField - path.Depth = 0 + path.SetDepth(0) case 2: if tv.V == nil { panic(&Exception{Value: typedString("nil pointer dereference")}) @@ -1709,12 +1707,12 @@ func (tv *TypedValue) GetPointerToFromTV(alloc *Allocator, store Store, path Val dtv = tv.V.(PointerValue).TV isPtr = true path.Type = VPField - path.Depth = 0 + path.SetDepth(0) case 3: dtv = tv.V.(PointerValue).TV isPtr = true path.Type = VPField - path.Depth = 0 + path.SetDepth(0) default: panic("should not happen") } diff --git a/gnovm/pkg/gnolang/values_conversions.go b/gnovm/pkg/gnolang/values_conversions.go index f6e39bd1912..920ed655ec9 100644 --- a/gnovm/pkg/gnolang/values_conversions.go +++ b/gnovm/pkg/gnolang/values_conversions.go @@ -75,6 +75,11 @@ func ConvertTo(alloc *Allocator, store Store, tv *TypedValue, t Type, isConst bo GNO_CASE: // special case for interface target if t.Kind() == InterfaceKind { + if tv.IsUndefined() && tv.T == nil { + if _, ok := t.(*NativeType); !ok { // no support for native now + tv.T = t + } + } return } // special case for undefined/nil source diff --git a/gnovm/pkg/gnolang/values_string.go b/gnovm/pkg/gnolang/values_string.go index fdf0c8f55de..b18bdb0dddc 100644 --- a/gnovm/pkg/gnolang/values_string.go +++ b/gnovm/pkg/gnolang/values_string.go @@ -343,9 +343,9 @@ func (tv *TypedValue) ProtectedSprint(seen *seenValues, considerDeclaredType boo return fmt.Sprintf("%v", math.Float32frombits(tv.GetFloat32())) case Float64Type: return fmt.Sprintf("%v", math.Float64frombits(tv.GetFloat64())) - case UntypedBigintType, BigintType: + case UntypedBigintType: return tv.V.(BigintValue).V.String() - case UntypedBigdecType, BigdecType: + case UntypedBigdecType: return tv.V.(BigdecValue).V.String() default: panic("should not happen") diff --git a/gnovm/tests/files/block1.gno b/gnovm/tests/files/block1.gno new file mode 100644 index 00000000000..6eb2403c163 --- /dev/null +++ b/gnovm/tests/files/block1.gno @@ -0,0 +1,669 @@ +// You can edit this code! +// Click here and start typing. +package main + +var v int = 1 + +func main() { + v++ + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +// Output: +// 3 +// 4 +// 5 +// 6 +// 7 +// 8 +// 9 +// 10 +// 11 +// 12 +// 13 +// 14 +// 15 +// 16 +// 17 +// 18 +// 19 +// 20 +// 21 +// 22 +// 23 +// 24 +// 25 +// 26 +// 27 +// 28 +// 29 +// 30 +// 31 +// 32 +// 33 +// 34 +// 35 +// 36 +// 37 +// 38 +// 39 +// 40 +// 41 +// 42 +// 43 +// 44 +// 45 +// 46 +// 47 +// 48 +// 49 +// 50 +// 51 +// 52 +// 53 +// 54 +// 55 +// 56 +// 57 +// 58 +// 59 +// 60 +// 61 +// 62 +// 63 +// 64 +// 65 +// 66 +// 67 +// 68 +// 69 +// 70 +// 71 +// 72 +// 73 +// 74 +// 75 +// 76 +// 77 +// 78 +// 79 +// 80 +// 81 +// 82 +// 83 +// 84 +// 85 +// 86 +// 87 +// 88 +// 89 +// 90 +// 91 +// 92 +// 93 +// 94 +// 95 +// 96 +// 97 +// 98 +// 99 +// 100 +// 101 +// 102 +// 103 +// 104 +// 105 +// 106 +// 107 +// 108 +// 109 +// 110 +// 111 +// 112 +// 113 +// 114 +// 115 +// 116 +// 117 +// 118 +// 119 +// 120 +// 121 +// 122 +// 123 +// 124 +// 125 +// 126 diff --git a/gnovm/tests/files/block2.gno b/gnovm/tests/files/block2.gno new file mode 100644 index 00000000000..6738c76bf40 --- /dev/null +++ b/gnovm/tests/files/block2.gno @@ -0,0 +1,550 @@ +// You can edit this code! +// Click here and start typing. +package main + +var v int = 1 + +func main() { + v++ + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + + if v >= 1 { + v++ + println(v) + if v >= 1 { + v++ + println(v) + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +// Error: +// main/files/block2.gno:419:129: exceeded maximum VPBlock depth (127) diff --git a/gnovm/tests/files/convert4.gno b/gnovm/tests/files/convert4.gno index e03e1d07ce3..03c7d454b82 100644 --- a/gnovm/tests/files/convert4.gno +++ b/gnovm/tests/files/convert4.gno @@ -5,4 +5,4 @@ func main() { } // Error: -// main/files/convert4.gno:4:10: cannot convert (undefined) to int +// main/files/convert4.gno:4:10: cannot convert (const (undefined)) to IntKind diff --git a/gnovm/tests/files/convert5.gno b/gnovm/tests/files/convert5.gno index e2e16c5eb83..1e785abdd7b 100644 --- a/gnovm/tests/files/convert5.gno +++ b/gnovm/tests/files/convert5.gno @@ -7,4 +7,4 @@ func main() { } // Error: -// main/files/convert5.gno:3:1: cannot convert (undefined) to int +// main/files/convert5.gno:3:1: cannot convert (const (undefined)) to IntKind diff --git a/gnovm/tests/files/types/cmp_iface_0_stdlibs.gno b/gnovm/tests/files/types/cmp_iface_0_stdlibs.gno new file mode 100644 index 00000000000..fb4ac682243 --- /dev/null +++ b/gnovm/tests/files/types/cmp_iface_0_stdlibs.gno @@ -0,0 +1,27 @@ +package main + +import ( + "errors" + "strconv" +) + +type Error int64 + +func (e Error) Error() string { + return "error: " + strconv.Itoa(int(e)) +} + +var errCmp = errors.New("XXXX") + +// special case: +// one is interface +func main() { + if Error(0) == errCmp { + println("what the firetruck?") + } else { + println("something else") + } +} + +// Output: +// something else diff --git a/gnovm/tests/files/types/cmp_iface_3_stdlibs.gno b/gnovm/tests/files/types/cmp_iface_3_stdlibs.gno new file mode 100644 index 00000000000..9c4cb0e5ea0 --- /dev/null +++ b/gnovm/tests/files/types/cmp_iface_3_stdlibs.gno @@ -0,0 +1,27 @@ +package main + +import ( + "errors" + "strconv" +) + +type Error int64 + +func (e Error) Error() string { + return "error: " + strconv.Itoa(int(e)) +} + +var errCmp = errors.New("XXXX") + +// special case: +// one is interface +func main() { + if Error(1) == errCmp { + println("what the firetruck?") + } else { + println("something else") + } +} + +// Output: +// something else diff --git a/gnovm/tests/files/types/cmp_iface_5_stdlibs.gno b/gnovm/tests/files/types/cmp_iface_5_stdlibs.gno new file mode 100644 index 00000000000..e706c74808e --- /dev/null +++ b/gnovm/tests/files/types/cmp_iface_5_stdlibs.gno @@ -0,0 +1,27 @@ +package main + +import ( + "errors" + "strconv" +) + +type Error int64 + +func (e Error) Error() string { + return "error: " + strconv.Itoa(int(e)) +} + +var errCmp = errors.New("XXXX") + +// special case: +// one is interface +func main() { + if errCmp == int64(1) { + println("what the firetruck?") + } else { + println("something else") + } +} + +// Error: +// main/files/types/cmp_iface_5_stdlibs.gno:19:5: int64 does not implement .uverse.error (missing method Error) diff --git a/gnovm/tests/files/types/typed_nil_a.gno b/gnovm/tests/files/types/typed_nil_a.gno new file mode 100644 index 00000000000..f212c677bab --- /dev/null +++ b/gnovm/tests/files/types/typed_nil_a.gno @@ -0,0 +1,18 @@ +package main + +import "fmt" + +type integer int + +func main() { + // illegal conversion + // should not work + if integer(nil) == nil { + fmt.Println("integer is nil") + } else { + fmt.Println("integer is not nil") + } +} + +// Error: +// main/files/types/typed_nil_a.gno:10:5: cannot convert (const (undefined)) to IntKind diff --git a/gnovm/tests/files/types/typed_nil_b.gno b/gnovm/tests/files/types/typed_nil_b.gno new file mode 100644 index 00000000000..fb1492dd02b --- /dev/null +++ b/gnovm/tests/files/types/typed_nil_b.gno @@ -0,0 +1,16 @@ +package main + +import "fmt" + +type integer *int + +func main() { + println(integer(nil)) + fmt.Println(integer(nil)) + fmt.Printf("%T\n", integer(nil)) +} + +// Output: +// (nil main.integer) +// +// *int diff --git a/gnovm/tests/files/types/typed_nil_c.gno b/gnovm/tests/files/types/typed_nil_c.gno new file mode 100644 index 00000000000..c8a556ea0c1 --- /dev/null +++ b/gnovm/tests/files/types/typed_nil_c.gno @@ -0,0 +1,12 @@ +package main + +import "fmt" + +func main() { + println(interface{}(nil) == (*int)(nil)) + fmt.Printf("%T\n", interface{}(nil)) +} + +// Output: +// false +// diff --git a/gnovm/tests/files/zpersist_valids.gno b/gnovm/tests/files/zpersist_valids.gno index 2709a243adf..790d4ea1551 100644 --- a/gnovm/tests/files/zpersist_valids.gno +++ b/gnovm/tests/files/zpersist_valids.gno @@ -8,7 +8,6 @@ type myStruct struct { var ( // Native types - abigint bigint = 16 abool bool = true abyte byte = 0x16 afloat32 float32 = 16.16 @@ -52,7 +51,6 @@ func main() { } func mutateVars(stringModifier string) { - abigint *= 2 abool = !abool abyte *= 2 afloat32 *= 2 @@ -82,7 +80,6 @@ func mutateVars(stringModifier string) { func printVars(phase string) { println(phase, // variables - abigint, abool, abyte, afloat32, @@ -108,7 +105,7 @@ func printVars(phase string) { } // Output: -// preinit 16 true 22 16.16 16.16 16 16 16 16 16 97 hello slice[("A" string)] A (struct{(16 int),("A" string)} gno.land/r/demo/tests_test.myStruct) 16 16 16 16 16 struct{(16 float32)} A -// postinit 32 false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B -// premain 32 false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B -// postmain 64 true 88 64.64 64.64 64 64 64 64 64 67 helloBC slice[("A" string),("B" string),("C" string)] A (struct{(64 int),("C" string)} gno.land/r/demo/tests_test.myStruct) 64 64 64 64 64 struct{("C" string)} C +// preinit true 22 16.16 16.16 16 16 16 16 16 97 hello slice[("A" string)] A (struct{(16 int),("A" string)} gno.land/r/demo/tests_test.myStruct) 16 16 16 16 16 struct{(16 float32)} A +// postinit false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B +// premain false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B +// postmain true 88 64.64 64.64 64 64 64 64 64 67 helloBC slice[("A" string),("B" string),("C" string)] A (struct{(64 int),("C" string)} gno.land/r/demo/tests_test.myStruct) 64 64 64 64 64 struct{("C" string)} C