arrays + builtins

This commit is contained in:
Chuck Smith
2024-01-22 12:47:16 -05:00
parent 6bb06370bb
commit 069b5ba8cf
10 changed files with 364 additions and 5 deletions

View File

@@ -18,6 +18,7 @@ const (
FUNCTION_OBJ = "FUNCTION"
STRING_OBJ = "STRING"
BUILTIN_OBJ = "BUILTIN"
ARRAY_OBJ = "ARRAY"
)
type Object interface {
@@ -133,3 +134,26 @@ func (b Builtin) Type() ObjectType {
func (b Builtin) Inspect() string {
return "builtin function"
}
type Array struct {
Elements []Object
}
func (ao Array) Type() ObjectType {
return ARRAY_OBJ
}
func (ao Array) Inspect() string {
var out bytes.Buffer
elements := []string{}
for _, e := range ao.Elements {
elements = append(elements, e.Inspect())
}
out.WriteString("[")
out.WriteString(strings.Join(elements, ", "))
out.WriteString("]")
return out.String()
}