Files
monkey/internal/builtins/divmod.go
Chuck Smith fc6ceee02c
Some checks failed
Build / build (push) Failing after 5m21s
Publish Image / publish (push) Failing after 32s
Test / build (push) Failing after 5m8s
restructure project
2024-03-28 16:20:09 -04:00

25 lines
585 B
Go

package builtins
import (
"monkey/internal/object"
"monkey/internal/typing"
)
// Divmod ...
func Divmod(args ...object.Object) object.Object {
if err := typing.Check(
"divmod", args,
typing.ExactArgs(2),
typing.WithTypes(object.INTEGER_OBJ, object.INTEGER_OBJ),
); err != nil {
return newError(err.Error())
}
a := args[0].(*object.Integer)
b := args[1].(*object.Integer)
elements := make([]object.Object, 2)
elements[0] = &object.Integer{Value: a.Value / b.Value}
elements[1] = &object.Integer{Value: a.Value % b.Value}
return &object.Array{Elements: elements}
}