further improvements
Some checks failed
Build / build (push) Successful in 10m40s
Publish Image / publish (push) Failing after 34s
Test / build (push) Has been cancelled

This commit is contained in:
2024-04-01 17:02:44 -04:00
parent aebbe43999
commit f9e6e164b0
26 changed files with 168 additions and 138 deletions

View File

@@ -27,17 +27,21 @@ func (i Integer) String() string {
}
func (i Integer) Add(other Object) (Object, error) {
if !AssertTypes(other, IntegerType) {
switch obj := other.(type) {
case Integer:
return Integer{i.Value + obj.Value}, nil
default:
return nil, NewBinaryOpError(i, other, "+")
}
return Integer{i.Value + other.(Integer).Value}, nil
}
func (i Integer) Sub(other Object) (Object, error) {
if !AssertTypes(other, IntegerType) {
switch obj := other.(type) {
case Integer:
return Integer{i.Value - obj.Value}, nil
default:
return nil, NewBinaryOpError(i, other, "-")
}
return Integer{i.Value - other.(Integer).Value}, nil
}
func (i Integer) Mul(other Object) (Object, error) {
@@ -115,15 +119,16 @@ func (i Integer) Negate() Object {
}
func (i Integer) Compare(other Object) int {
if obj, ok := other.(Integer); ok {
switch {
case i.Value < obj.Value:
switch obj := other.(type) {
case Integer:
if i.Value < obj.Value {
return -1
case i.Value > obj.Value:
return 1
default:
return 0
}
if i.Value > obj.Value {
return 1
}
return 0
default:
return -1
}
return -1
}