33 lines
503 B
Go
33 lines
503 B
Go
package runtime
|
|
|
|
//go:generate stringer -type LoxType -trimprefix LoxType
|
|
type LoxType int
|
|
|
|
const (
|
|
LoxTypeString LoxType = iota
|
|
LoxTypeNumber
|
|
LoxTypeBoolean
|
|
LoxTypeNil
|
|
LoxTypeUndefined
|
|
)
|
|
|
|
type LoxValue struct {
|
|
raw any
|
|
}
|
|
|
|
func (v *LoxValue) Type() LoxType {
|
|
switch v.raw.(type) {
|
|
case string:
|
|
return LoxTypeString
|
|
case float64, float32:
|
|
return LoxTypeNumber
|
|
case bool:
|
|
return LoxTypeBoolean
|
|
default:
|
|
return LoxTypeUndefined
|
|
}
|
|
}
|
|
|
|
func Value(v any) *LoxValue {
|
|
return &LoxValue{v}
|
|
}
|