rearrange builtins
Some checks failed
Build / build (push) Successful in 10m31s
Test / build (push) Failing after 39m25s

This commit is contained in:
Chuck Smith
2024-03-24 14:00:22 -04:00
parent 387bb80094
commit b4ba660704
47 changed files with 652 additions and 515 deletions

53
builtins/builtins.go Normal file
View File

@@ -0,0 +1,53 @@
package builtins
import (
"fmt"
"monkey/object"
"sort"
)
// Builtins ...
var Builtins = map[string]*object.Builtin{
"len": {Name: "len", Fn: Len},
"input": {Name: "input", Fn: Input},
"print": {Name: "print", Fn: Print},
"first": {Name: "first", Fn: First},
"last": {Name: "last", Fn: Last},
"rest": {Name: "rest", Fn: Rest},
"push": {Name: "push", Fn: Push},
"pop": {Name: "pop", Fn: Pop},
"exit": {Name: "exit", Fn: Exit},
"assert": {Name: "assert", Fn: Assert},
"bool": {Name: "bool", Fn: Bool},
"int": {Name: "int", Fn: Int},
"str": {Name: "str", Fn: Str},
"type": {Name: "type", Fn: TypeOf},
"args": {Name: "args", Fn: Args},
"lower": {Name: "lower", Fn: Lower},
"upper": {Name: "upper", Fn: Upper},
"join": {Name: "join", Fn: Join},
"split": {Name: "split", Fn: Split},
"find": {Name: "find", Fn: Find},
"read": {Name: "read", Fn: Read},
"write": {Name: "write", Fn: Write},
"ffi": {Name: "ffi", Fn: FFI},
}
// BuiltinsIndex ...
var BuiltinsIndex []*object.Builtin
func init() {
var keys []string
for k := range Builtins {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
BuiltinsIndex = append(BuiltinsIndex, Builtins[k])
}
}
func newError(format string, a ...interface{}) *object.Error {
return &object.Error{Message: fmt.Sprintf(format, a...)}
}