1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-01-18 03:22:02 +02:00

Switched from int to int64 (#188)

This commit is contained in:
Tim Voronov 2018-11-30 19:31:08 -05:00 committed by GitHub
parent 39e379f0f2
commit a219e776ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,12 +9,12 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/core"
)
type Int int
type Int int64
var ZeroInt = Int(0)
func NewInt(input int) Int {
return Int(input)
return Int(int64(input))
}
func ParseInt(input interface{}) (Int, error) {
@ -22,21 +22,19 @@ func ParseInt(input interface{}) (Int, error) {
return ZeroInt, nil
}
i, ok := input.(int)
if ok {
if i == 0 {
return ZeroInt, nil
}
return Int(i), nil
}
// try to cast
str, ok := input.(string)
if ok {
i, err := strconv.Atoi(str)
switch input.(type) {
case int:
return Int(input.(int)), nil
case int64:
return Int(input.(int64)), nil
case int32:
return Int(input.(int32)), nil
case int16:
return Int(input.(int16)), nil
case int8:
return Int(input.(int8)), nil
case string:
i, err := strconv.Atoi(input.(string))
if err == nil {
if i == 0 {
@ -45,9 +43,11 @@ func ParseInt(input interface{}) (Int, error) {
return Int(i), nil
}
}
return ZeroInt, core.Error(core.ErrInvalidType, "expected 'int'")
return ZeroInt, err
default:
return ZeroInt, core.Error(core.ErrInvalidType, "expected 'int'")
}
}
func ParseIntP(input interface{}) Int {
@ -61,7 +61,7 @@ func ParseIntP(input interface{}) Int {
}
func (t Int) MarshalJSON() ([]byte, error) {
return json.Marshal(int(t))
return json.Marshal(int64(t))
}
func (t Int) Type() core.Type {
@ -73,30 +73,28 @@ func (t Int) String() string {
}
func (t Int) Compare(other core.Value) int {
raw := int(t)
switch other.Type() {
case core.IntType:
i := other.Unwrap().(int)
i := other.(Int)
if raw == i {
if t == i {
return 0
}
if raw < i {
if t < i {
return -1
}
return +1
case core.FloatType:
f := other.Unwrap().(float64)
i := int(f)
f := other.(Float)
f2 := Float(t)
if raw == i {
if f2 == f {
return 0
}
if raw < i {
if f2 < f {
return -1
}