Files
monkey/object/object.go
2024-01-19 17:50:02 -05:00

62 lines
906 B
Go

package object
import "fmt"
type ObjectType string
const (
INTEGER_OBJ = "INTEGER"
BOOLEAN_OBJ = "BOOLEAN"
NULL_OBJ = "NULL"
RETURN_VALUE_OBJ = "RETURN_VALUE"
)
type Object interface {
Type() ObjectType
Inspect() string
}
type Integer struct {
Value int64
}
func (i *Integer) Type() ObjectType {
return INTEGER_OBJ
}
func (i *Integer) Inspect() string {
return fmt.Sprintf("%d", i.Value)
}
type Boolean struct {
Value bool
}
func (b *Boolean) Type() ObjectType {
return BOOLEAN_OBJ
}
func (b *Boolean) Inspect() string {
return fmt.Sprintf("%t", b.Value)
}
type Null struct{}
func (n *Null) Type() ObjectType {
return NULL_OBJ
}
func (n *Null) Inspect() string {
return "null"
}
type ReturnValue struct {
Value Object
}
func (rv ReturnValue) Type() ObjectType {
return RETURN_VALUE_OBJ
}
func (rv ReturnValue) Inspect() string {
return rv.Value.Inspect()
}