forked from TrueCloudLab/neoneo-go
Merge pull request #3147 from fyfyrchik/fix-big-uint64
compiler: Fix emitting big uint64 constants
This commit is contained in:
commit
b78bea17c0
2 changed files with 13 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"math"
|
"math"
|
||||||
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -208,9 +209,12 @@ func (c *codegen) emitLoadConst(t types.TypeAndValue) {
|
||||||
case types.Int, types.UntypedInt, types.Uint,
|
case types.Int, types.UntypedInt, types.Uint,
|
||||||
types.Int8, types.Uint8,
|
types.Int8, types.Uint8,
|
||||||
types.Int16, types.Uint16,
|
types.Int16, types.Uint16,
|
||||||
types.Int32, types.Uint32, types.Int64, types.Uint64:
|
types.Int32, types.Uint32, types.Int64:
|
||||||
val, _ := constant.Int64Val(t.Value)
|
val, _ := constant.Int64Val(t.Value)
|
||||||
emit.Int(c.prog.BinWriter, val)
|
emit.Int(c.prog.BinWriter, val)
|
||||||
|
case types.Uint64:
|
||||||
|
val, _ := constant.Int64Val(t.Value)
|
||||||
|
emit.BigInt(c.prog.BinWriter, new(big.Int).SetUint64(uint64(val)))
|
||||||
case types.String, types.UntypedString:
|
case types.String, types.UntypedString:
|
||||||
val := constant.StringVal(t.Value)
|
val := constant.StringVal(t.Value)
|
||||||
emit.String(c.prog.BinWriter, val)
|
emit.String(c.prog.BinWriter, val)
|
||||||
|
|
|
@ -18,6 +18,14 @@ var numericTestCases = []testCase{
|
||||||
`,
|
`,
|
||||||
big.NewInt(6),
|
big.NewInt(6),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"shift uint64",
|
||||||
|
`package foo
|
||||||
|
func Main() uint64 {
|
||||||
|
return 1 << 63
|
||||||
|
}`,
|
||||||
|
new(big.Int).SetUint64(1 << 63),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumericExprs(t *testing.T) {
|
func TestNumericExprs(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue