@ 0a6d0b45c9b0e3f50876896c1c597c24311ceb7b | history
package ast
// Names for the builtins that have no source spelling as a symbol. The
// reader turns "()", "T" and "F" into values and handles "." itself, so none
// of these can collide with a user symbol.
const (
ListNode = "(...)"
Dot = "."
True = "T"
False = "F"
Empty = "()"
)
// builtinCodes is the table from DESIGN.md. A code is permanent once
// published: changing one would change the meaning of every .gov file
// already compiled, so new builtins only ever take a free code.
var builtinCodes = []struct {
code uint64
name string
}{
{1, ListNode},
{2, Dot},
{3, True},
{4, False},
{5, Empty},
{10, "quote"},
{11, "if"},
{12, "define"},
{13, "lambda"},
{14, "and"},
{15, "or"},
{20, "not"},
{21, "+"},
{22, "-"},
{23, "*"},
{24, "/"},
{25, "<"},
{26, ">"},
{27, "<="},
{28, ">="},
{29, "=="},
{30, "!="},
{31, "cons"},
{32, "car"},
{33, "cdr"},
{34, "strlen"},
{35, "strcat"},
{36, "str?"},
}
var (
codeByName = map[string]uint64{}
nameByCode = map[uint64]string{}
)
func init() {
for _, b := range builtinCodes {
codeByName[b.name] = b.code
nameByCode[b.code] = b.name
}
}
// IsBuiltin reports whether name is in namespace 0. A symbol with this name
// is always encoded as the builtin, which is why programs cannot rebind one.
func IsBuiltin(name string) bool {
_, ok := codeByName[name]
return ok
}