Files
monkey/object/int.go
Chuck Smith 6d234099d1
Some checks failed
Build / build (push) Successful in 11m16s
Test / build (push) Failing after 17m0s
type checking and error handling for builtins improved.
2024-03-25 16:18:08 -04:00

42 lines
609 B
Go

package object
import "fmt"
type Integer struct {
Value int64
}
func (i *Integer) Bool() bool {
return i.Value != 0
}
func (i *Integer) Type() ObjectType {
return INTEGER_OBJ
}
func (i *Integer) Inspect() string {
return fmt.Sprintf("%d", i.Value)
}
func (i *Integer) Clone() Object {
return &Integer{Value: i.Value}
}
func (i *Integer) String() string {
return i.Inspect()
}
func (i *Integer) Compare(other Object) int {
if obj, ok := other.(*Integer); ok {
switch {
case i.Value < obj.Value:
return -1
case i.Value > obj.Value:
return 1
default:
return 0
}
}
return -1
}