| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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 }
|