More tests
Some checks failed
Build / build (push) Failing after 1m26s
Test / build (push) Failing after 11m43s

This commit is contained in:
Chuck Smith
2024-03-18 19:46:54 -04:00
parent c59ce311b0
commit ca4eed10b8
16 changed files with 124 additions and 24 deletions

View File

@@ -9,6 +9,7 @@ import (
"unicode/utf8"
)
// Builtins ...
var Builtins = map[string]*Builtin{
"len": {Name: "len", Fn: Len},
"input": {Name: "input", Fn: Input},
@@ -21,6 +22,7 @@ var Builtins = map[string]*Builtin{
"exit": {Name: "exit", Fn: Exit},
}
// BuiltinsIndex ...
var BuiltinsIndex []*Builtin
func init() {
@@ -39,6 +41,7 @@ func newError(format string, a ...interface{}) *Error {
return &Error{Message: fmt.Sprintf(format, a...)}
}
// Len ...
func Len(args ...Object) Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
@@ -56,6 +59,7 @@ func Len(args ...Object) Object {
}
}
// Input ...
func Input(args ...Object) Object {
if len(args) > 0 {
obj, ok := args[0].(*String)
@@ -77,6 +81,7 @@ func Input(args ...Object) Object {
return &String{Value: string(line)}
}
// Print ...
func Print(args ...Object) Object {
for _, arg := range args {
fmt.Println(arg.Inspect())
@@ -85,6 +90,7 @@ func Print(args ...Object) Object {
return nil
}
// First ...
func First(args ...Object) Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
@@ -103,6 +109,7 @@ func First(args ...Object) Object {
return nil
}
// Last ...
func Last(args ...Object) Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
@@ -122,6 +129,7 @@ func Last(args ...Object) Object {
return nil
}
// Rest ...
func Rest(args ...Object) Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
@@ -143,6 +151,7 @@ func Rest(args ...Object) Object {
return nil
}
// Push ...
func Push(args ...Object) Object {
if len(args) != 2 {
return newError("wrong number of arguments. got=%d, want=2",
@@ -167,6 +176,7 @@ func Push(args ...Object) Object {
return &Array{Elements: newElements}
}
// Pop ...
func Pop(args ...Object) Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
@@ -190,6 +200,7 @@ func Pop(args ...Object) Object {
return element
}
// Exit ...
func Exit(args ...Object) Object {
if len(args) == 1 {
if args[0].Type() != INTEGER_OBJ {