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

feat(gnovm)!: remove bigint type #3641

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestBuiltinIdentifiersShadowing(t *testing.T) {
"println",
"recover",
"nil",
"bigint",
"bool",
"byte",
"float32",
Expand Down Expand Up @@ -247,7 +246,7 @@ func main() {
},
{
`package test
func main() {
const f = float64(1.0)
println(int64(f))
Expand Down
8 changes: 4 additions & 4 deletions gnovm/pkg/gnolang/gonative.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,9 @@
return reflect.TypeOf(float32(0))
case Float64Type:
return reflect.TypeOf(float64(0))
case BigintType, UntypedBigintType:
case UntypedBigintType:

Check warning on line 772 in gnovm/pkg/gnolang/gonative.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/gonative.go#L772

Added line #L772 was not covered by tests
panic("not yet implemented")
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:

Check warning on line 774 in gnovm/pkg/gnolang/gonative.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/gonative.go#L774

Added line #L774 was not covered by tests
panic("not yet implemented")
default:
panic("should not happen")
Expand Down Expand Up @@ -887,9 +887,9 @@
return rt.Kind() == reflect.Float32
case Float64Type:
return rt.Kind() == reflect.Float64
case BigintType, UntypedBigintType:
case UntypedBigintType:

Check warning on line 890 in gnovm/pkg/gnolang/gonative.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/gonative.go#L890

Added line #L890 was not covered by tests
panic("not yet implemented")
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:

Check warning on line 892 in gnovm/pkg/gnolang/gonative.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/gonative.go#L892

Added line #L892 was not covered by tests
panic("not yet implemented")
default:
panic("should not happen")
Expand Down
30 changes: 15 additions & 15 deletions gnovm/pkg/gnolang/op_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,11 @@
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)
Expand Down Expand Up @@ -775,11 +775,11 @@
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)
Expand Down Expand Up @@ -831,11 +831,11 @@
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)
Expand Down Expand Up @@ -929,14 +929,14 @@
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
}
Expand Down Expand Up @@ -1022,7 +1022,7 @@
return expt
}
lv.SetUint64(lv.GetUint64() % rv.GetUint64())
case BigintType, UntypedBigintType:
case UntypedBigintType:

Check warning on line 1025 in gnovm/pkg/gnolang/op_binary.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_binary.go#L1025

Added line #L1025 was not covered by tests
if rv.GetBigInt().Sign() == 0 {
return expt
}
Expand Down Expand Up @@ -1067,7 +1067,7 @@
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}
Expand Down Expand Up @@ -1106,7 +1106,7 @@
lv.SetUint32(lv.GetUint32() &^ rv.GetUint32())
case Uint64Type:
lv.SetUint64(lv.GetUint64() &^ rv.GetUint64())
case BigintType, UntypedBigintType:
case UntypedBigintType:

Check warning on line 1109 in gnovm/pkg/gnolang/op_binary.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_binary.go#L1109

Added line #L1109 was not covered by tests
lb := lv.GetBigInt()
lb = big.NewInt(0).AndNot(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
Expand Down Expand Up @@ -1145,7 +1145,7 @@
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}
Expand Down Expand Up @@ -1184,7 +1184,7 @@
lv.SetUint32(lv.GetUint32() ^ rv.GetUint32())
case Uint64Type:
lv.SetUint64(lv.GetUint64() ^ rv.GetUint64())
case BigintType, UntypedBigintType:
case UntypedBigintType:

Check warning on line 1187 in gnovm/pkg/gnolang/op_binary.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_binary.go#L1187

Added line #L1187 was not covered by tests
lb := lv.GetBigInt()
lb = big.NewInt(0).Xor(lb, rv.GetBigInt())
lv.V = BigintValue{V: lb}
Expand Down Expand Up @@ -1308,7 +1308,7 @@
})

lv.SetUint64(lv.GetUint64() << rv.GetUint())
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Lsh(lb, rv.GetUint())
lv.V = BigintValue{V: lb}
Expand Down Expand Up @@ -1432,7 +1432,7 @@
})

lv.SetUint64(lv.GetUint64() >> rv.GetUint())
case BigintType, UntypedBigintType:
case UntypedBigintType:
lb := lv.GetBigInt()
lb = big.NewInt(0).Rsh(lb, rv.GetUint())
lv.V = BigintValue{V: lb}
Expand Down
8 changes: 4 additions & 4 deletions gnovm/pkg/gnolang/op_inc_dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
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:

Check warning on line 61 in gnovm/pkg/gnolang/op_inc_dec.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_inc_dec.go#L61

Added line #L61 was not covered by tests
lb := lv.GetBigInt()
lb = big.NewInt(0).Add(lb, big.NewInt(1))
lv.V = BigintValue{V: lb}
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:

Check warning on line 65 in gnovm/pkg/gnolang/op_inc_dec.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_inc_dec.go#L65

Added line #L65 was not covered by tests
lb := lv.GetBigDec()
sum := apd.New(0, 0)
cond, err := apd.BaseContext.WithPrecision(0).Add(sum, lb, apd.New(1, 0))
Expand Down Expand Up @@ -128,11 +128,11 @@
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:

Check warning on line 131 in gnovm/pkg/gnolang/op_inc_dec.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_inc_dec.go#L131

Added line #L131 was not covered by tests
lb := lv.GetBigInt()
lb = big.NewInt(0).Sub(lb, big.NewInt(1))
lv.V = BigintValue{V: lb}
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:

Check warning on line 135 in gnovm/pkg/gnolang/op_inc_dec.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_inc_dec.go#L135

Added line #L135 was not covered by tests
lb := lv.GetBigDec()
sum := apd.New(0, 0)
cond, err := apd.BaseContext.WithPrecision(0).Sub(sum, lb, apd.New(1, 0))
Expand Down
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/op_unary.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
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:
Expand Down Expand Up @@ -112,7 +112,7 @@
xv.SetUint32(^xv.GetUint32())
case Uint64Type:
xv.SetUint64(^xv.GetUint64())
case UntypedBigintType, BigintType:
case UntypedBigintType:

Check warning on line 115 in gnovm/pkg/gnolang/op_unary.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/op_unary.go#L115

Added line #L115 was not covered by tests
// XXX can it even be implemented?
panic("not yet implemented")
default:
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
38 changes: 9 additions & 29 deletions gnovm/pkg/gnolang/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@
Float32Type
Float64Type
UntypedBigintType
BigintType
UntypedBigdecType
BigdecType
// UintptrType
)

Expand Down Expand Up @@ -153,20 +151,16 @@
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))
}
Expand Down Expand Up @@ -204,9 +198,9 @@
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))
Expand Down Expand Up @@ -256,12 +250,8 @@
return typeid("float64")
case UntypedBigintType:
return typeid("<untyped> bigint")
case BigintType:
return typeid("bigint")
case UntypedBigdecType:
return typeid("<untyped> bigdec")
case BigdecType:
return typeid("bigdec")
default:
panic(fmt.Sprintf("unexpected primitive type %v", pt))
}
Expand Down Expand Up @@ -309,12 +299,8 @@
return string("float64")
case UntypedBigintType:
return string("<untyped> bigint")
case BigintType:
return string("bigint")
case UntypedBigdecType:
return string("<untyped> bigdec")
case BigdecType:
return string("bigdec")
default:
panic(fmt.Sprintf("unexpected primitive type %d", pt))
}
Expand Down Expand Up @@ -2199,9 +2185,9 @@
return Float32Kind
case Float64Type:
return Float64Kind
case BigintType, UntypedBigintType:
case UntypedBigintType:

Check warning on line 2188 in gnovm/pkg/gnolang/types.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/types.go#L2188

Added line #L2188 was not covered by tests
return BigintKind
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:

Check warning on line 2190 in gnovm/pkg/gnolang/types.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/types.go#L2190

Added line #L2190 was not covered by tests
return BigdecKind
default:
panic(fmt.Sprintf("unexpected primitive type %s", t.String()))
Expand Down Expand Up @@ -2394,12 +2380,6 @@
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")
Expand Down
1 change: 0 additions & 1 deletion gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/values_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 4 additions & 7 deletions gnovm/tests/files/zpersist_valids.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type myStruct struct {

var (
// Native types
abigint bigint = 16
abool bool = true
abyte byte = 0x16
afloat32 float32 = 16.16
Expand Down Expand Up @@ -52,7 +51,6 @@ func main() {
}

func mutateVars(stringModifier string) {
abigint *= 2
abool = !abool
abyte *= 2
afloat32 *= 2
Expand Down Expand Up @@ -82,7 +80,6 @@ func mutateVars(stringModifier string) {
func printVars(phase string) {
println(phase,
// variables
abigint,
abool,
abyte,
afloat32,
Expand All @@ -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
Loading