Files
monkey/builtins/exit.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

27 lines
419 B
Go

package builtins
import (
"monkey/object"
"monkey/typing"
)
// Exit ...
func Exit(args ...object.Object) object.Object {
if err := typing.Check(
"exit", args,
typing.RangeOfArgs(0, 1),
typing.WithTypes(object.INTEGER_OBJ),
); err != nil {
return newError(err.Error())
}
var status int
if len(args) == 1 {
status = int(args[0].(*object.Integer).Value)
}
object.ExitFunction(status)
return nil
}