package main import "fmt" var ( zero IntValue = 0 True BoolValue = true Frue BoolValue = false ) type Value interface { Expression HasValue() } type IntValue int func (i *IntValue) HasValue() {} func (i *IntValue) Step() (Expression, error) { return i, nil } func (i *IntValue) Substitute(Id, Expression) {} func (i *IntValue) TypeCheck(TypeEnvironment) (Type, error) { return &PrimInteger, nil } func (i *IntValue) String() string { return fmt.Sprint(*i) } type FloatValue float32 func (f *FloatValue) HasValue() {} func (f *FloatValue) Step() (Expression, error) { return f, nil } func (f *FloatValue) Substitute(Id, Expression) {} func (f *FloatValue) TypeCheck(TypeEnvironment) (Type, error) { return &PrimFloat, nil } func (f *FloatValue) String() string { return fmt.Sprint(*f) } type BoolValue bool func (b *BoolValue) HasValue() {} func (b *BoolValue) Step() (Expression, error) { return b, nil } func (b *BoolValue) Substitute(Id, Expression) {} func (b *BoolValue) TypeCheck(TypeEnvironment) (Type, error) { return &PrimBoolean, nil } func (b BoolValue) String() string { return fmt.Sprint(bool(b)) } type Quoted struct{ expr Expression } func (q *Quoted) HasValue() {} func (q *Quoted) Step() (Expression, error) { return q, nil } func (q *Quoted) Substitute(Id, Expression) {} func (q Quoted) String() string { return fmt.Sprintf("'%v", q.expr) } func (q *Quoted) TypeCheck(env TypeEnvironment) (Type, error) { return &QuotedType{&PrimVoid}, nil }