seperated builtins
Some checks failed
Build / build (push) Successful in 10m0s
Test / build (push) Failing after 16m20s

This commit is contained in:
Chuck Smith
2024-03-20 17:01:45 -04:00
parent f735215c28
commit 43362475f9
13 changed files with 345 additions and 204 deletions

29
object/builtin_assert.go Normal file
View File

@@ -0,0 +1,29 @@
package object
import (
"fmt"
"os"
)
// Assert ...
func Assert(args ...Object) Object {
if len(args) != 2 {
return newError("wrong number of arguments. got=%d, want=2",
len(args))
}
if args[0].Type() != BOOLEAN_OBJ {
return newError("argument #1 to `assert` must be BOOLEAN, got %s",
args[0].Type())
}
if args[1].Type() != STRING_OBJ {
return newError("argument #2 to `assert` must be STRING, got %s",
args[0].Type())
}
if !args[0].(*Boolean).Value {
fmt.Printf("Assertion Error: %s", args[1].(*String).Value)
os.Exit(1)
}
return nil
}