/
object.go
46 lines (33 loc) · 886 Bytes
/
object.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 (*Integer) Type() ObjectType { return INTEGER_OBJ }
func (i *Integer) Inspect() string { return fmt.Sprintf("%d", i.Value) }
type Boolean struct {
Value bool
}
func (*Boolean) Type() ObjectType { return BOOLEAN_OBJ }
func (b *Boolean) Inspect() string { return fmt.Sprintf("%t", b.Value) }
type Null struct{}
func (*Null) Type() ObjectType { return NULL_OBJ }
func (*Null) Inspect() string { return "null" }
type Return struct {
Value Object
}
func (*Return) Type() ObjectType { return RETURN_VALUE_OBJ }
func (r *Return) Inspect() string {
return fmt.Sprintf("return %s", r.Value.Inspect())
}