diff options
Diffstat (limited to 'object/object.go')
| -rw-r--r-- | object/object.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/object/object.go b/object/object.go index 24de9be..9fe896e 100644 --- a/object/object.go +++ b/object/object.go @@ -18,6 +18,7 @@ const ( STRING_OBJ = "STRING" ERROR_OBJ = "ERROR" BUILTIN_OBJ = "BUILTIN" + ARRAY_OBJ = "ARRAY" ) type Object interface { @@ -59,6 +60,10 @@ type Builtin struct { Fn BuiltinFunction } +type Array struct { + Elements []Object +} + func (i *Integer) Type() ObjectType { return INTEGER_OBJ } @@ -122,3 +127,20 @@ func (s *String) Inspect() string { return s.Value } func (b *Builtin) Type() ObjectType { return BUILTIN_OBJ } func (b *Builtin) Inspect() string { return "builtin function" } + +func (ao *Array) Type() ObjectType { return ARRAY_OBJ } +func (ao *Array) Inspect() string { + var out bytes.Buffer + + elements := []string{} + + for _, el := range ao.Elements { + elements = append(elements, el.Inspect()) + } + + out.WriteString("[") + out.WriteString(strings.Join(elements, ", ")) + out.WriteString("]") + + return out.String() +} |
