rearrange builtins
This commit is contained in:
53
builtins/builtins.go
Normal file
53
builtins/builtins.go
Normal 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...)}
|
||||
}
|
||||
Reference in New Issue
Block a user