2022-08-07 09:44:11 -05:00
|
|
|
package object
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
type ObjectType string
|
|
|
|
|
|
|
|
const (
|
2022-08-11 00:04:44 -05:00
|
|
|
INTEGER_OBJECT = "INTEGER"
|
|
|
|
BOOLEAN_OBJECT = "BOOLEAN"
|
|
|
|
NULL_OBJECT = "NULL"
|
|
|
|
RETURN_VALUE_OBJECT = "RETURN_VALUE"
|
2022-08-07 09:44:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Object interface {
|
|
|
|
Type() ObjectType
|
|
|
|
Inspect() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Integer
|
|
|
|
type Integer struct {
|
|
|
|
Value int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Integer) Type() ObjectType {
|
|
|
|
return INTEGER_OBJECT
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Integer) Inspect() string {
|
|
|
|
return fmt.Sprintf("%d", i.Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Booleans
|
|
|
|
type Boolean struct {
|
|
|
|
Value bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Boolean) Type() ObjectType {
|
|
|
|
return BOOLEAN_OBJECT
|
|
|
|
}
|
|
|
|
|
2022-08-07 09:58:35 -05:00
|
|
|
func (b *Boolean) Inspect() string {
|
2022-08-07 09:44:11 -05:00
|
|
|
return fmt.Sprintf("%t", b.Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Null
|
|
|
|
type Null struct{}
|
|
|
|
|
|
|
|
func (n *Null) Type() ObjectType {
|
|
|
|
return NULL_OBJECT
|
|
|
|
}
|
|
|
|
|
2022-08-07 09:58:35 -05:00
|
|
|
func (n *Null) Inspect() string {
|
2022-08-07 09:44:11 -05:00
|
|
|
return "null"
|
|
|
|
}
|
2022-08-11 00:04:44 -05:00
|
|
|
|
|
|
|
// Return
|
|
|
|
type ReturnValue struct {
|
|
|
|
Value Object
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rv *ReturnValue) Type() ObjectType { return RETURN_VALUE_OBJECT }
|
|
|
|
func (rv *ReturnValue) Inspect() string { return rv.Value.Inspect() }
|