object.go 711 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package object
  2. import "fmt"
  3. // ObjType type of object
  4. type ObjType string
  5. const (
  6. IntegerObj = "INTEGER"
  7. BooleanObj = "BOOLEAN"
  8. NullObj = "NULL"
  9. )
  10. // Object source code as an Object
  11. type Object interface {
  12. Type() ObjType
  13. Inspect() string
  14. }
  15. type Integer struct {
  16. Value int64
  17. }
  18. func (i *Integer) Type() ObjType { return IntegerObj }
  19. func (i *Integer) Inspect() string { return fmt.Sprintf("%d", i.Value) }
  20. type Boolean struct {
  21. Value bool
  22. }
  23. func (b *Boolean) Type() ObjType { return BooleanObj }
  24. func (b *Boolean) Inspect() string { return fmt.Sprintf("%t", b.Value) }
  25. type Null struct{}
  26. func (n *Null) Type() ObjType { return NullObj }
  27. func (n *Null) Inspect() string { return "null" }