package object import "fmt" // ObjType type of object type ObjType string const ( IntegerObj = "INTEGER" BooleanObj = "BOOLEAN" NullObj = "NULL" ReturnValueObj = "RETURN_VALUE" ErrorObj = "ERROR" ) // Object source code as an Object type Object interface { Type() ObjType Inspect() string } type Integer struct { Value int64 } func (i *Integer) Type() ObjType { return IntegerObj } func (i *Integer) Inspect() string { return fmt.Sprintf("%d", i.Value) } type Boolean struct { Value bool } func (b *Boolean) Type() ObjType { return BooleanObj } func (b *Boolean) Inspect() string { return fmt.Sprintf("%t", b.Value) } type Null struct{} func (n *Null) Type() ObjType { return NullObj } func (n *Null) Inspect() string { return "null" } type ReturnValue struct { Value Object } func (rv *ReturnValue) Type() ObjType { return ReturnValueObj } func (rv *ReturnValue) Inspect() string { return rv.Value.Inspect() } type Error struct { Msg string } func (e *Error) Type() ObjType { return ErrorObj } func (e *Error) Inspect() string { return "ERROR: " + e.Msg }