diff --git a/gnovm/pkg/gnolang/alloc.go b/gnovm/pkg/gnolang/alloc.go index fbed712dc59..1fce05d9dcb 100644 --- a/gnovm/pkg/gnolang/alloc.go +++ b/gnovm/pkg/gnolang/alloc.go @@ -26,7 +26,6 @@ const ( _allocMapValue = 144 _allocBoundMethodValue = 176 _allocBlock = 464 - _allocNativeValue = 48 _allocTypeValue = 16 _allocTypedValue = 40 _allocBigint = 200 // XXX @@ -54,7 +53,6 @@ const ( allocBoundMethod = _allocBase + _allocPointer + _allocBoundMethodValue allocBlock = _allocBase + _allocPointer + _allocBlock allocBlockItem = _allocTypedValue - allocNative = _allocBase + _allocPointer + _allocNativeValue allocType = _allocBase + _allocPointer + _allocType // allocDataByte = 1 // allocPackge = 1 @@ -159,11 +157,6 @@ func (alloc *Allocator) AllocateBlockItems(items int64) { alloc.Allocate(allocBlockItem * items) } -// NOTE: does not allocate for the underlying value. -func (alloc *Allocator) AllocateNative() { - alloc.Allocate(allocNative) -} - /* NOTE: Not used, account for with AllocatePointer. func (alloc *Allocator) AllocateDataByte() { alloc.Allocate(allocDataByte) diff --git a/gnovm/pkg/gnolang/gonative.go b/gnovm/pkg/gnolang/gonative.go index 9ea1846da56..9e661c5ab24 100644 --- a/gnovm/pkg/gnolang/gonative.go +++ b/gnovm/pkg/gnolang/gonative.go @@ -4,45 +4,24 @@ import ( "fmt" "math" "reflect" - "unsafe" "github.com/gnolang/gno/gnovm/pkg/gnolang/internal/softfloat" ) -// GoNative, *NativeType, and *NativeValue are experimental and subject to -// change. These functions were originally created for bootstrapping Gno's -// (file) tests from the Yaegi project (which imported complex standard -// libraries). Then later they became used for native bindings in autogenerated -// code (see stdlibs/generated.go). +// This file contains functions to convert values and types from Go to Gno, and +// vice versa. It supports a small subset of types, which are used in native +// functions, linked using misc/genstd. // -// Due to the limitations of Go reflection and due to the complexity of -// converting complex recursive data structures, neither Go2Gno* nor Gno2Go* -// will ever be complete for the general case. -// -// NOTE This means that new native bindings must conform to these limitations, -// namely use these for message-passing objects (read-only copies), rather than -// relying on much intelligence, such as those offered by go2GnoValueUpdate(). -// -// TODO list and document the limitations. -// -// * Go 1.15 reflect has a bug in creating new types with methods -- namely, -// it cannot, and so you cannot create types through reflection that obey any -// interface but the empty interface. -// * ... +// Much of this code is eventually meant to be converted into code generation +// performed by misc/genstd. // ---------------------------------------- // Go to Gno conversion -// See go2GnoValue(); this is lazy. -func go2GnoType(rt reflect.Type) Type { - return go2GnoBaseType(rt) -} - -// like go2GnoType() but ignores name declaration. // for native type unary/binary expression conversion. // also used for untyped gno -> native conversion intermediary. // XXX support unary conversions as we did for binary. -func go2GnoBaseType(rt reflect.Type) Type { +func go2GnoType(rt reflect.Type) Type { switch rk := rt.Kind(); rk { case reflect.Bool: return BoolType @@ -87,292 +66,25 @@ func go2GnoBaseType(rt reflect.Type) Type { return &PointerType{ Elt: go2GnoType(rt.Elem()), // recursive } - case reflect.UnsafePointer: - panic("not yet implemented") default: panic(fmt.Sprintf( "unexpected type %v", rt)) } } -// Implements Store. -// See go2GnoValue2(). Like go2GnoType() but also converts any -// top-level complex types (or pointers to them). The result gets -// memoized in *NativeType.GnoType() for type inference in the -// preprocessor, as well as in the cacheNativeTypes lookup map to -// support recursive translations. -// The namedness of the native type gets converted to an -// appropriate gno *DeclaredType with native methods -// converted via go2GnoFuncType(). -func (ds *defaultStore) Go2GnoType(rt reflect.Type) (t Type) { - if gnot, ok := ds.cacheNativeTypes[rt]; ok { - return gnot - } - defer func() { - if r := recover(); r != nil { - panic(r) // do not run the below logic upon panic. - } - // regardless of rt kind, if rt.PkgPath() is set, - // wrap t with declared type. - pkgPath := rt.PkgPath() - if pkgPath != "" { - // mappings have been removed, so this should never happen. - gokey := pkgPath + "." + rt.Name() - panic(fmt.Sprintf("native type does not exist for %s", gokey)) - } - // memoize t to cache. - if debug { - if gnot, ok := ds.cacheNativeTypes[rt]; ok { - if gnot.TypeID() != baseOf(t).TypeID() { - panic("should not happen") - } - } - } - ds.cacheNativeTypes[rt] = t // may overwrite - }() - switch rk := rt.Kind(); rk { - case reflect.Bool: - return BoolType - case reflect.String: - return StringType - case reflect.Int: - return IntType - case reflect.Int8: - return Int8Type - case reflect.Int16: - return Int16Type - case reflect.Int32: - return Int32Type - case reflect.Int64: - return Int64Type - case reflect.Uint: - return UintType - case reflect.Uint8: - return Uint8Type - case reflect.Uint16: - return Uint16Type - case reflect.Uint32: - return Uint32Type - case reflect.Uint64: - return Uint64Type - case reflect.Float32: - return Float32Type - case reflect.Float64: - return Float64Type - case reflect.Array: - // predefine gno type - at := &ArrayType{} - ds.cacheNativeTypes[rt] = at - // define gno type - at.Len = rt.Len() - at.Elt = go2GnoType(rt.Elem()) - at.Vrd = false - return at - case reflect.Slice: - return &SliceType{ - Elt: go2GnoType(rt.Elem()), - Vrd: false, - } - case reflect.Chan: - // predefine gno type - ct := &ChanType{} - ds.cacheNativeTypes[rt] = ct - // define gno type - chdir := toChanDir(rt.ChanDir()) - ct.Dir = chdir - ct.Elt = go2GnoType(rt.Elem()) - return ct - case reflect.Func: - return ds.go2GnoFuncType(rt) - case reflect.Interface: - // predefine gno type - it := &InterfaceType{} - ds.cacheNativeTypes[rt] = it - // define gno type - nm := rt.NumMethod() - fs := make([]FieldType, nm) - for i := 0; i < nm; i++ { - mthd := rt.Method(i) - fs[i] = FieldType{ - Name: Name(mthd.Name), - Type: ds.Go2GnoType(mthd.Type), // recursive - } - } - it.PkgPath = rt.PkgPath() - it.Methods = fs - return it - case reflect.Map: - // predefine gno type - mt := &MapType{} - ds.cacheNativeTypes[rt] = mt - // define gno type - mt.Key = go2GnoType(rt.Key()) - mt.Value = go2GnoType(rt.Elem()) - return mt - case reflect.Ptr: - return &PointerType{ - Elt: ds.Go2GnoType(rt.Elem()), // recursive - } - case reflect.Struct: - // predefine gno type - st := &StructType{} - ds.cacheNativeTypes[rt] = st - // define gno type - nf := rt.NumField() - fs := make([]FieldType, nf) - for i := 0; i < nf; i++ { - sf := rt.Field(i) - fs[i] = FieldType{ - Name: Name(sf.Name), - Type: go2GnoType(sf.Type), - } - } - st.PkgPath = rt.PkgPath() - st.Fields = fs - return st - case reflect.UnsafePointer: - panic("not yet implemented") - default: - panic("not yet implemented") - } -} - -// Converts native go function type to gno *FuncType, -// for the preprocessor to infer types of arguments. -// The argument and return types are shallowly converted -// to gno types, (to preserve the original native types). -func (ds *defaultStore) go2GnoFuncType(rt reflect.Type) *FuncType { - // predefine func type - ft := &FuncType{} - ds.cacheNativeTypes[rt] = ft - // define func type - hasVargs := rt.IsVariadic() - ins := make([]FieldType, rt.NumIn()) - for i := 0; i < len(ins); i++ { - it := go2GnoType(rt.In(i)) - if hasVargs && i == len(ins)-1 { - it = &SliceType{ - Elt: it.Elem(), - Vrd: true, - } - } - ins[i] = FieldType{ - Name: "", // XXX dontcare? - Type: it, - } - } - outs := make([]FieldType, rt.NumOut()) - for i := 0; i < len(outs); i++ { - ot := go2GnoType(rt.Out(i)) - outs[i] = FieldType{ - Name: "", // XXX dontcare? - Type: ot, - } - } - ft.Params = ins - ft.Results = outs - return ft -} - // NOTE: used by vm module. Recursively converts. -func Go2GnoValue(alloc *Allocator, store Store, rv reflect.Value) (tv TypedValue) { - return go2GnoValue2(alloc, store, rv, true) -} - -// NOTE: used by imports_test.go TestSetOriginCaller. -// See also gno2GoValue(). -func Gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { - return gno2GoValue(tv, rv) -} - -// Default run-time representation of go-native values. It is -// "lazy" in the sense that unnamed complex types like arrays and -// slices aren't translated to Gno canonical types except as -// *NativeType/*NativeValues, primarily for speed. To force -// translation to Gno canonical types for unnamed complex types, -// call go2GnoValue2(), which is used by the implementation of -// ConvertTo(). -// Unlike go2GnoValue2(), rv may be invalid. -func go2GnoValue(alloc *Allocator, rv reflect.Value) (tv TypedValue) { - if !rv.IsValid() { - return - } - if rv.Kind() == reflect.Interface { - if rv.IsNil() { - return TypedValue{} - } else { - rv = rv.Elem() - } - } - if rv.Type().PkgPath() != "" { - panic("should not happen") - } - tv.T = alloc.NewType(go2GnoType(rv.Type())) - switch rk := rv.Kind(); rk { - case reflect.Bool: - tv.SetBool(rv.Bool()) - case reflect.String: - tv.V = alloc.NewString(rv.String()) - case reflect.Int: - tv.SetInt(rv.Int()) - case reflect.Int8: - tv.SetInt8(int8(rv.Int())) - case reflect.Int16: - tv.SetInt16(int16(rv.Int())) - case reflect.Int32: - tv.SetInt32(int32(rv.Int())) - case reflect.Int64: - tv.SetInt64(rv.Int()) - case reflect.Uint: - tv.SetUint(rv.Uint()) - case reflect.Uint8: - tv.SetUint8(uint8(rv.Uint())) - case reflect.Uint16: - tv.SetUint16(uint16(rv.Uint())) - case reflect.Uint32: - tv.SetUint32(uint32(rv.Uint())) - case reflect.Uint64: - tv.SetUint64(rv.Uint()) - case reflect.Float32: - tv.SetFloat32(softfloat.F64to32(math.Float64bits(rv.Float()))) - case reflect.Float64: - tv.SetFloat64(math.Float64bits(rv.Float())) - case reflect.Array: - panic("not yet implemented") - case reflect.Slice: - panic("not yet implemented") - case reflect.Chan: - panic("not yet implemented") - case reflect.Func: - panic("not yet implemented") - case reflect.Interface: - panic("should not happen") - case reflect.Map: - panic("not yet implemented") - case reflect.Ptr: - panic("not yet implemented") - case reflect.Struct: - panic("not yet implemented") - case reflect.UnsafePointer: - panic("not yet implemented") - default: - panic("not yet implemented") - } - return -} - // If recursive is false, this function is like go2GnoValue() but less lazy // (but still not recursive/eager). When recursive is false, it is for // converting Go types to Gno types upon an explicit conversion (via // ConvertTo). Panics on unexported/private fields. Some types that cannot be // converted remain native. Unlike go2GnoValue(), rv must be valid. -func go2GnoValue2(alloc *Allocator, store Store, rv reflect.Value, recursive bool) (tv TypedValue) { +func Go2GnoValue(alloc *Allocator, store Store, rv reflect.Value) (tv TypedValue) { if debug { if !rv.IsValid() { panic("go2GnoValue2() requires valid rv") } } - tv.T = store.Go2GnoType(rv.Type()) + tv.T = go2GnoType(rv.Type()) switch rk := rv.Kind(); rk { case reflect.Bool: tv.SetBool(rv.Bool()) @@ -413,11 +125,7 @@ func go2GnoValue2(alloc *Allocator, store Store, rv reflect.Value, recursive boo av := alloc.NewListArray(rvl) list := av.List for i := 0; i < rvl; i++ { - if recursive { - list[i] = go2GnoValue2(alloc, store, rv.Index(i), true) - } else { - list[i] = go2GnoValue(alloc, rv.Index(i)) - } + list[i] = Go2GnoValue(alloc, store, rv.Index(i)) } tv.V = av } @@ -426,38 +134,12 @@ func go2GnoValue2(alloc *Allocator, store Store, rv reflect.Value, recursive boo rvc := rv.Cap() list := make([]TypedValue, rvl, rvc) for i := 0; i < rvl; i++ { - if recursive { - list[i] = go2GnoValue2(alloc, store, rv.Index(i), true) - } else { - list[i] = go2GnoValue(alloc, rv.Index(i)) - } + list[i] = Go2GnoValue(alloc, store, rv.Index(i)) } tv.V = alloc.NewSliceFromList(list) - case reflect.Chan: - panic("not yet implemented") - case reflect.Func: - panic("not yet implemented") - case reflect.Interface: - panic("not yet implemented") - case reflect.Map: - panic("not yet implemented") case reflect.Ptr: - val := go2GnoValue2(alloc, store, rv.Elem(), recursive) + val := Go2GnoValue(alloc, store, rv.Elem()) tv.V = PointerValue{TV: &val} // heap alloc - case reflect.Struct: - nf := rv.NumField() - fs := alloc.NewStructFields(nf) - for i := 0; i < nf; i++ { - frv := rv.Field(i) - if recursive { - fs[i] = go2GnoValue2(alloc, store, frv, true) - } else { - fs[i] = go2GnoValue(alloc, frv) - } - } - tv.V = alloc.NewStruct(fs) - case reflect.UnsafePointer: - panic("not yet implemented") default: panic("not yet implemented") } @@ -525,54 +207,6 @@ func gno2GoType(t Type) reflect.Type { case *SliceType: et := gno2GoType(ct.Elem()) return reflect.SliceOf(et) - case *StructType: - gfs := make([]reflect.StructField, len(ct.Fields)) - for i, field := range ct.Fields { - gft := gno2GoType(field.Type) - fn := string(field.Name) - pkgPath := "" - if !isUpper(fn) { - pkgPath = ct.PkgPath - } - gfs[i] = reflect.StructField{ - Name: fn, - PkgPath: pkgPath, - Type: gft, - Tag: reflect.StructTag(field.Tag), - Anonymous: field.Name == "", - // Offset: dontcare - // Index: dontcare - } - } - return reflect.StructOf(gfs) - case *MapType: - kt := gno2GoType(ct.Key) - vt := gno2GoType(ct.Value) - return reflect.MapOf(kt, vt) - case *FuncType: - panic("not yet supported") - case *InterfaceType: - if ct.IsEmptyInterface() { - // XXX move out - rt := reflect.TypeOf((*interface{})(nil)).Elem() - return rt - } else { - // NOTE: can this be implemented in go1.15? i think not. - panic("gno2go conversion of type not yet supported: " + ct.String()) - } - case *TypeType: - panic("should not happen") - case *DeclaredType: - // NOTE: Go1.15 has issues with generating types and values using - // reflect to declare types with methods. When Go has fixed these - // issues, we can revisit. For now, all Gno objects passed to Go - // lose their names or "namedness", e.g. cannot satisfy anything - // but empty interfaces, and have no methods. - - // We switch on baseOf(t). - panic("should not happen") - case *PackageType: - panic("should not happen") default: panic(fmt.Sprintf("unexpected type %v with base %v", t, baseOf(t))) } @@ -587,7 +221,7 @@ func gno2GoType(t Type) reflect.Type { // loading (e.g. from native function bindings for SDKParams) because it // doesn't really make sense in the general case, and there is a FillValue() // function available for eager fetching of ref values. -func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { +func Gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { if tv.IsUndefined() { if debug { if !rv.IsValid() { @@ -620,6 +254,9 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { ret = rv rt = rv.Type() } + + // Only need to support the types supported by native bindings: + // see misc/genstd/mapping.go switch ct := bt.(type) { case PrimitiveType: switch ct { @@ -664,7 +301,7 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { // do nothing } else { rve := reflect.New(rv.Type().Elem()).Elem() - rv2 := gno2GoValue(tv.V.(PointerValue).TV, rve) + rv2 := Gno2GoValue(tv.V.(PointerValue).TV, rve) rv.Set(rv2.Addr()) } case *ArrayType: @@ -683,7 +320,7 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { if etv.IsUndefined() { continue } - gno2GoValue(etv, rv.Index(i)) + Gno2GoValue(etv, rv.Index(i)) } } else { for i := 0; i < ct.Len; i++ { @@ -711,62 +348,13 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { if etv.IsUndefined() { continue } - gno2GoValue(etv, rv.Index(i)) + Gno2GoValue(etv, rv.Index(i)) } } else { data := make([]byte, svl, svc) copy(data[:svc], svb.Data[svo:svo+svc]) rv.Set(reflect.ValueOf(data)) } - case *StructType: - // If uninitialized struct, return zero value. - if tv.V == nil { - return - } - // General case. - sv := tv.V.(*StructValue) - for i := range ct.Fields { - ftv := &(sv.Fields[i]) - if ftv.IsUndefined() { - continue - } - fv := rv.Field(i) - if !fv.CanSet() { - // Normally private fields can not bet set via reflect. Override this limitation. - fv = reflect.NewAt(fv.Type(), unsafe.Pointer(fv.UnsafeAddr())).Elem() - } - gno2GoValue(ftv, fv) - } - case *MapType: - // If uninitialized map, return zero value. - if tv.V == nil { - return - } - // General case. - mv := tv.V.(*MapValue) - mt := rt - rv.Set(reflect.MakeMapWithSize(mt, mv.List.Size)) - head := mv.List.Head - vrt := mt.Elem() - for head != nil { - ktv, vtv := &head.Key, &head.Value - krv := gno2GoValue(ktv, reflect.Value{}) - if vtv.IsUndefined() { - vrv := reflect.New(vrt).Elem() - rv.SetMapIndex(krv, vrv) - } else { - vrv := gno2GoValue(vtv, reflect.Value{}) - rv.SetMapIndex(krv, vrv) - } - head = head.Next - } - case *DeclaredType: - // See corresponding note on gno2GoType(). - panic("should not happen") // we switch on baseOf(). - case *FuncType: - // TODO: if tv.V.(*NativeValue), just return. - // TODO: otherwise, set rv to wrapper. - panic("gno2Go not supported for gno functions yet") default: panic(fmt.Sprintf( "unexpected type %s", @@ -774,19 +362,3 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { } return } - -// ---------------------------------------- -// misc - -func toChanDir(dir reflect.ChanDir) ChanDir { - switch dir { - case reflect.RecvDir: - return RECV - case reflect.SendDir: - return SEND - case reflect.BothDir: - return BOTH - default: - panic("should not happn") - } -} diff --git a/gnovm/pkg/gnolang/nodes.go b/gnovm/pkg/gnolang/nodes.go index c97874cb7ee..1f22f485ac3 100644 --- a/gnovm/pkg/gnolang/nodes.go +++ b/gnovm/pkg/gnolang/nodes.go @@ -1545,9 +1545,7 @@ func (x *PackageNode) PrepareNewValues(pv *PackageValue) []TypedValue { } } -// DefineNativeFunc defines a native function. This is not the -// same as DefineGoNativeValue, which DOES NOT give access to -// the running machine. +// DefineNativeFunc defines a native function. func (x *PackageNode) DefineNative(n Name, ps, rs FieldTypeExprs, native func(*Machine)) { if debug { debug.Printf("*PackageNode.DefineNative(%s,...)\n", n) diff --git a/gnovm/pkg/gnolang/op_call.go b/gnovm/pkg/gnolang/op_call.go index dd79b31d315..58155309cc6 100644 --- a/gnovm/pkg/gnolang/op_call.go +++ b/gnovm/pkg/gnolang/op_call.go @@ -370,11 +370,8 @@ func (m *Machine) doOpDefer() { // Pop func ftv := m.PopValue() // Push defer. - // NOTE: we let type be FuncValue and value NativeValue, - // because native funcs can't be converted to gno anyways. switch cv := ftv.V.(type) { case *FuncValue: - // TODO what if value is NativeValue? cfr.PushDefer(Defer{ Func: cv, Args: args, diff --git a/gnovm/pkg/gnolang/package.go b/gnovm/pkg/gnolang/package.go index 55a503fc305..5d80b40451e 100644 --- a/gnovm/pkg/gnolang/package.go +++ b/gnovm/pkg/gnolang/package.go @@ -28,7 +28,6 @@ var Package = amino.RegisterPackage(amino.NewPackage( &BoundMethodValue{}, TypeValue{}, &PackageValue{}, - // &NativeValue{}, &Block{}, RefValue{}, &HeapItemValue{}, diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 22ddb3cc763..09a3c352b59 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2003,9 +2003,6 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node { // General case: a, b = x, y. for i, lx := range n.Lhs { lt := evalStaticTypeOf(store, last, lx) - //if nt, ok := lt.(*NativeType); ok && nt.Kind() == FuncKind { - // panic(fmt.Sprintf("cannot assign to %s (neither addressable nor a map index expression)", lx)) - //} // if lt is interface, nothing will happen checkOrConvertType(store, last, n, &n.Rhs[i], lt, true) diff --git a/gnovm/pkg/gnolang/store.go b/gnovm/pkg/gnolang/store.go index 1ddc97ed0d0..084572968fb 100644 --- a/gnovm/pkg/gnolang/store.go +++ b/gnovm/pkg/gnolang/store.go @@ -2,7 +2,6 @@ package gnolang import ( "fmt" - "reflect" "slices" "strconv" "strings" @@ -54,7 +53,6 @@ type Store interface { SetBlockNode(BlockNode) // UNSTABLE - Go2GnoType(rt reflect.Type) Type GetAllocator() *Allocator NumMemPackages() int64 // Upon restart, all packages will be re-preprocessed; This @@ -65,8 +63,8 @@ type Store interface { GetMemFile(path string, name string) *gnovm.MemFile IterMemPackage() <-chan *gnovm.MemPackage ClearObjectCache() // run before processing a message - SetNativeResolver(NativeResolver) // for "new" natives XXX - GetNative(pkgPath string, name Name) func(m *Machine) // for "new" natives XXX + SetNativeResolver(NativeResolver) // for native functions + GetNative(pkgPath string, name Name) func(m *Machine) // for native functions SetLogStoreOps(enabled bool) SprintStoreOps() string LogSwitchRealm(rlmpath string) // to mark change of realm boundaries @@ -137,9 +135,8 @@ type defaultStore struct { alloc *Allocator // for accounting for cached items // store configuration; cannot be modified in a transaction - pkgGetter PackageGetter // non-realm packages - cacheNativeTypes map[reflect.Type]Type // reflect doc: reflect.Type are comparable - nativeResolver NativeResolver // for injecting natives + pkgGetter PackageGetter // non-realm packages + nativeResolver NativeResolver // for injecting natives // transient opslog []StoreOp // for debugging and testing. @@ -162,10 +159,9 @@ func NewStore(alloc *Allocator, baseStore, iavlStore store.Store) *defaultStore cacheNodes: txlog.GoMap[Location, BlockNode](map[Location]BlockNode{}), // store configuration - pkgGetter: nil, - cacheNativeTypes: make(map[reflect.Type]Type), - nativeResolver: nil, - gasConfig: DefaultGasConfig(), + pkgGetter: nil, + nativeResolver: nil, + gasConfig: DefaultGasConfig(), } InitStoreCaches(ds) return ds @@ -191,9 +187,8 @@ func (ds *defaultStore) BeginTransaction(baseStore, iavlStore store.Store, gasMe alloc: ds.alloc.Fork().Reset(), // store configuration - pkgGetter: ds.pkgGetter, - cacheNativeTypes: ds.cacheNativeTypes, - nativeResolver: ds.nativeResolver, + pkgGetter: ds.pkgGetter, + nativeResolver: ds.nativeResolver, // gas meter gasMeter: gasMeter, diff --git a/gnovm/pkg/gnolang/string_methods.go b/gnovm/pkg/gnolang/string_methods.go index d94d2a4162c..a70e3d77445 100644 --- a/gnovm/pkg/gnolang/string_methods.go +++ b/gnovm/pkg/gnolang/string_methods.go @@ -271,56 +271,55 @@ func _() { _ = x[TRANS_MAPTYPE_KEY-32] _ = x[TRANS_MAPTYPE_VALUE-33] _ = x[TRANS_STRUCTTYPE_FIELD-34] - _ = x[TRANS_MAYBENATIVETYPE_TYPE-35] - _ = x[TRANS_ASSIGN_LHS-36] - _ = x[TRANS_ASSIGN_RHS-37] - _ = x[TRANS_BLOCK_BODY-38] - _ = x[TRANS_DECL_BODY-39] - _ = x[TRANS_DEFER_CALL-40] - _ = x[TRANS_EXPR_X-41] - _ = x[TRANS_FOR_INIT-42] - _ = x[TRANS_FOR_COND-43] - _ = x[TRANS_FOR_POST-44] - _ = x[TRANS_FOR_BODY-45] - _ = x[TRANS_GO_CALL-46] - _ = x[TRANS_IF_INIT-47] - _ = x[TRANS_IF_COND-48] - _ = x[TRANS_IF_BODY-49] - _ = x[TRANS_IF_ELSE-50] - _ = x[TRANS_IF_CASE_BODY-51] - _ = x[TRANS_INCDEC_X-52] - _ = x[TRANS_RANGE_X-53] - _ = x[TRANS_RANGE_KEY-54] - _ = x[TRANS_RANGE_VALUE-55] - _ = x[TRANS_RANGE_BODY-56] - _ = x[TRANS_RETURN_RESULT-57] - _ = x[TRANS_PANIC_EXCEPTION-58] - _ = x[TRANS_SELECT_CASE-59] - _ = x[TRANS_SELECTCASE_COMM-60] - _ = x[TRANS_SELECTCASE_BODY-61] - _ = x[TRANS_SEND_CHAN-62] - _ = x[TRANS_SEND_VALUE-63] - _ = x[TRANS_SWITCH_INIT-64] - _ = x[TRANS_SWITCH_X-65] - _ = x[TRANS_SWITCH_CASE-66] - _ = x[TRANS_SWITCHCASE_CASE-67] - _ = x[TRANS_SWITCHCASE_BODY-68] - _ = x[TRANS_FUNC_RECV-69] - _ = x[TRANS_FUNC_TYPE-70] - _ = x[TRANS_FUNC_BODY-71] - _ = x[TRANS_IMPORT_PATH-72] - _ = x[TRANS_CONST_TYPE-73] - _ = x[TRANS_CONST_VALUE-74] - _ = x[TRANS_VAR_NAME-75] - _ = x[TRANS_VAR_TYPE-76] - _ = x[TRANS_VAR_VALUE-77] - _ = x[TRANS_TYPE_TYPE-78] - _ = x[TRANS_FILE_BODY-79] + _ = x[TRANS_ASSIGN_LHS-35] + _ = x[TRANS_ASSIGN_RHS-36] + _ = x[TRANS_BLOCK_BODY-37] + _ = x[TRANS_DECL_BODY-38] + _ = x[TRANS_DEFER_CALL-39] + _ = x[TRANS_EXPR_X-40] + _ = x[TRANS_FOR_INIT-41] + _ = x[TRANS_FOR_COND-42] + _ = x[TRANS_FOR_POST-43] + _ = x[TRANS_FOR_BODY-44] + _ = x[TRANS_GO_CALL-45] + _ = x[TRANS_IF_INIT-46] + _ = x[TRANS_IF_COND-47] + _ = x[TRANS_IF_BODY-48] + _ = x[TRANS_IF_ELSE-49] + _ = x[TRANS_IF_CASE_BODY-50] + _ = x[TRANS_INCDEC_X-51] + _ = x[TRANS_RANGE_X-52] + _ = x[TRANS_RANGE_KEY-53] + _ = x[TRANS_RANGE_VALUE-54] + _ = x[TRANS_RANGE_BODY-55] + _ = x[TRANS_RETURN_RESULT-56] + _ = x[TRANS_PANIC_EXCEPTION-57] + _ = x[TRANS_SELECT_CASE-58] + _ = x[TRANS_SELECTCASE_COMM-59] + _ = x[TRANS_SELECTCASE_BODY-60] + _ = x[TRANS_SEND_CHAN-61] + _ = x[TRANS_SEND_VALUE-62] + _ = x[TRANS_SWITCH_INIT-63] + _ = x[TRANS_SWITCH_X-64] + _ = x[TRANS_SWITCH_CASE-65] + _ = x[TRANS_SWITCHCASE_CASE-66] + _ = x[TRANS_SWITCHCASE_BODY-67] + _ = x[TRANS_FUNC_RECV-68] + _ = x[TRANS_FUNC_TYPE-69] + _ = x[TRANS_FUNC_BODY-70] + _ = x[TRANS_IMPORT_PATH-71] + _ = x[TRANS_CONST_TYPE-72] + _ = x[TRANS_CONST_VALUE-73] + _ = x[TRANS_VAR_NAME-74] + _ = x[TRANS_VAR_TYPE-75] + _ = x[TRANS_VAR_VALUE-76] + _ = x[TRANS_TYPE_TYPE-77] + _ = x[TRANS_FILE_BODY-78] } -const _TransField_name = "TRANS_ROOTTRANS_BINARY_LEFTTRANS_BINARY_RIGHTTRANS_CALL_FUNCTRANS_CALL_ARGTRANS_INDEX_XTRANS_INDEX_INDEXTRANS_SELECTOR_XTRANS_SLICE_XTRANS_SLICE_LOWTRANS_SLICE_HIGHTRANS_SLICE_MAXTRANS_STAR_XTRANS_REF_XTRANS_TYPEASSERT_XTRANS_TYPEASSERT_TYPETRANS_UNARY_XTRANS_COMPOSITE_TYPETRANS_COMPOSITE_KEYTRANS_COMPOSITE_VALUETRANS_FUNCLIT_TYPETRANS_FUNCLIT_HEAP_CAPTURETRANS_FUNCLIT_BODYTRANS_FIELDTYPE_TYPETRANS_FIELDTYPE_TAGTRANS_ARRAYTYPE_LENTRANS_ARRAYTYPE_ELTTRANS_SLICETYPE_ELTTRANS_INTERFACETYPE_METHODTRANS_CHANTYPE_VALUETRANS_FUNCTYPE_PARAMTRANS_FUNCTYPE_RESULTTRANS_MAPTYPE_KEYTRANS_MAPTYPE_VALUETRANS_STRUCTTYPE_FIELDTRANS_MAYBENATIVETYPE_TYPETRANS_ASSIGN_LHSTRANS_ASSIGN_RHSTRANS_BLOCK_BODYTRANS_DECL_BODYTRANS_DEFER_CALLTRANS_EXPR_XTRANS_FOR_INITTRANS_FOR_CONDTRANS_FOR_POSTTRANS_FOR_BODYTRANS_GO_CALLTRANS_IF_INITTRANS_IF_CONDTRANS_IF_BODYTRANS_IF_ELSETRANS_IF_CASE_BODYTRANS_INCDEC_XTRANS_RANGE_XTRANS_RANGE_KEYTRANS_RANGE_VALUETRANS_RANGE_BODYTRANS_RETURN_RESULTTRANS_PANIC_EXCEPTIONTRANS_SELECT_CASETRANS_SELECTCASE_COMMTRANS_SELECTCASE_BODYTRANS_SEND_CHANTRANS_SEND_VALUETRANS_SWITCH_INITTRANS_SWITCH_XTRANS_SWITCH_CASETRANS_SWITCHCASE_CASETRANS_SWITCHCASE_BODYTRANS_FUNC_RECVTRANS_FUNC_TYPETRANS_FUNC_BODYTRANS_IMPORT_PATHTRANS_CONST_TYPETRANS_CONST_VALUETRANS_VAR_NAMETRANS_VAR_TYPETRANS_VAR_VALUETRANS_TYPE_TYPETRANS_FILE_BODY" +const _TransField_name = "TRANS_ROOTTRANS_BINARY_LEFTTRANS_BINARY_RIGHTTRANS_CALL_FUNCTRANS_CALL_ARGTRANS_INDEX_XTRANS_INDEX_INDEXTRANS_SELECTOR_XTRANS_SLICE_XTRANS_SLICE_LOWTRANS_SLICE_HIGHTRANS_SLICE_MAXTRANS_STAR_XTRANS_REF_XTRANS_TYPEASSERT_XTRANS_TYPEASSERT_TYPETRANS_UNARY_XTRANS_COMPOSITE_TYPETRANS_COMPOSITE_KEYTRANS_COMPOSITE_VALUETRANS_FUNCLIT_TYPETRANS_FUNCLIT_HEAP_CAPTURETRANS_FUNCLIT_BODYTRANS_FIELDTYPE_TYPETRANS_FIELDTYPE_TAGTRANS_ARRAYTYPE_LENTRANS_ARRAYTYPE_ELTTRANS_SLICETYPE_ELTTRANS_INTERFACETYPE_METHODTRANS_CHANTYPE_VALUETRANS_FUNCTYPE_PARAMTRANS_FUNCTYPE_RESULTTRANS_MAPTYPE_KEYTRANS_MAPTYPE_VALUETRANS_STRUCTTYPE_FIELDTRANS_ASSIGN_LHSTRANS_ASSIGN_RHSTRANS_BLOCK_BODYTRANS_DECL_BODYTRANS_DEFER_CALLTRANS_EXPR_XTRANS_FOR_INITTRANS_FOR_CONDTRANS_FOR_POSTTRANS_FOR_BODYTRANS_GO_CALLTRANS_IF_INITTRANS_IF_CONDTRANS_IF_BODYTRANS_IF_ELSETRANS_IF_CASE_BODYTRANS_INCDEC_XTRANS_RANGE_XTRANS_RANGE_KEYTRANS_RANGE_VALUETRANS_RANGE_BODYTRANS_RETURN_RESULTTRANS_PANIC_EXCEPTIONTRANS_SELECT_CASETRANS_SELECTCASE_COMMTRANS_SELECTCASE_BODYTRANS_SEND_CHANTRANS_SEND_VALUETRANS_SWITCH_INITTRANS_SWITCH_XTRANS_SWITCH_CASETRANS_SWITCHCASE_CASETRANS_SWITCHCASE_BODYTRANS_FUNC_RECVTRANS_FUNC_TYPETRANS_FUNC_BODYTRANS_IMPORT_PATHTRANS_CONST_TYPETRANS_CONST_VALUETRANS_VAR_NAMETRANS_VAR_TYPETRANS_VAR_VALUETRANS_TYPE_TYPETRANS_FILE_BODY" -var _TransField_index = [...]uint16{0, 10, 27, 45, 60, 74, 87, 104, 120, 133, 148, 164, 179, 191, 202, 220, 241, 254, 274, 293, 314, 332, 358, 376, 396, 415, 434, 453, 472, 498, 518, 538, 559, 576, 595, 617, 643, 659, 675, 691, 706, 722, 734, 748, 762, 776, 790, 803, 816, 829, 842, 855, 873, 887, 900, 915, 932, 948, 967, 988, 1005, 1026, 1047, 1062, 1078, 1095, 1109, 1126, 1147, 1168, 1183, 1198, 1213, 1230, 1246, 1263, 1277, 1291, 1306, 1321, 1336} +var _TransField_index = [...]uint16{0, 10, 27, 45, 60, 74, 87, 104, 120, 133, 148, 164, 179, 191, 202, 220, 241, 254, 274, 293, 314, 332, 358, 376, 396, 415, 434, 453, 472, 498, 518, 538, 559, 576, 595, 617, 633, 649, 665, 680, 696, 708, 722, 736, 750, 764, 777, 790, 803, 816, 829, 847, 861, 874, 889, 906, 922, 941, 962, 979, 1000, 1021, 1036, 1052, 1069, 1083, 1100, 1121, 1142, 1157, 1172, 1187, 1204, 1220, 1237, 1251, 1265, 1280, 1295, 1310} func (i TransField) String() string { if i >= TransField(len(_TransField_index)-1) { diff --git a/gnovm/pkg/gnolang/transcribe.go b/gnovm/pkg/gnolang/transcribe.go index b2dfabe905e..d14013b34de 100644 --- a/gnovm/pkg/gnolang/transcribe.go +++ b/gnovm/pkg/gnolang/transcribe.go @@ -60,7 +60,6 @@ const ( TRANS_MAPTYPE_KEY TRANS_MAPTYPE_VALUE TRANS_STRUCTTYPE_FIELD - TRANS_MAYBENATIVETYPE_TYPE TRANS_ASSIGN_LHS TRANS_ASSIGN_RHS TRANS_BLOCK_BODY