Files
monkey/internal/builtins/assert.go
Charles Smith aebbe43999
Some checks failed
Build / build (push) Successful in 10m25s
Publish Image / publish (push) Failing after 39s
Test / build (push) Successful in 11m19s
Fix VM memory allocation optimizations by reducing what we allocate on the heap
2024-03-31 20:44:50 -04:00

27 lines
473 B
Go

package builtins
import (
"fmt"
"monkey/internal/object"
"monkey/internal/typing"
"os"
)
// Assert ...
func Assert(args ...object.Object) object.Object {
if err := typing.Check(
"assert", args,
typing.ExactArgs(2),
typing.WithTypes(object.BooleanType, object.StringType),
); err != nil {
return newError(err.Error())
}
if !args[0].(object.Boolean).Value {
fmt.Printf("Assertion Error: %s", args[1].(object.String).Value)
os.Exit(1)
}
return nil
}