|
|
@ -4,49 +4,78 @@ import (
|
|
|
|
"github.com/jordanorelli/hyperstone/bit"
|
|
|
|
"github.com/jordanorelli/hyperstone/bit"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var atom_types = map[string]typeFn{
|
|
|
|
var atom_types = []typeLiteral{
|
|
|
|
"bool": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
return bit.ReadBool(r), r.Err()
|
|
|
|
"bool",
|
|
|
|
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
|
|
|
|
return bit.ReadBool(r), r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"uint8": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
// TODO: bounds check here
|
|
|
|
"uint8",
|
|
|
|
return uint8(bit.ReadVarInt(r)), r.Err()
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
|
|
|
|
// TODO: bounds check here
|
|
|
|
|
|
|
|
return uint8(bit.ReadVarInt(r)), r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"uint16": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
// TODO: bounds check here
|
|
|
|
"uint16",
|
|
|
|
return uint16(bit.ReadVarInt(r)), r.Err()
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
|
|
|
|
// TODO: bounds check here
|
|
|
|
|
|
|
|
return uint16(bit.ReadVarInt(r)), r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"uint32": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
return bit.ReadVarInt32(r), r.Err()
|
|
|
|
"uint32",
|
|
|
|
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
|
|
|
|
return bit.ReadVarInt32(r), r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"uint64": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
return bit.ReadVarInt(r), r.Err()
|
|
|
|
"uint64",
|
|
|
|
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
|
|
|
|
return bit.ReadVarInt(r), r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"int8": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
// TODO: bounds check here
|
|
|
|
"int8",
|
|
|
|
return int8(bit.ReadZigZag32(r)), r.Err()
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
|
|
|
|
// TODO: bounds check here
|
|
|
|
|
|
|
|
return int8(bit.ReadZigZag32(r)), r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"int32": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
return bit.ReadZigZag32(r), r.Err()
|
|
|
|
"int32",
|
|
|
|
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
|
|
|
|
return bit.ReadZigZag32(r), r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"CUtlStringToken": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
return bit.ReadVarInt(r), r.Err()
|
|
|
|
"CUtlStringToken",
|
|
|
|
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
|
|
|
|
return bit.ReadVarInt(r), r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"Color": func(r bit.Reader) (value, error) {
|
|
|
|
{
|
|
|
|
u := bit.ReadVarInt(r)
|
|
|
|
"Color",
|
|
|
|
return color{
|
|
|
|
func(r bit.Reader) (value, error) {
|
|
|
|
r: uint8(u >> 6 & 0xff),
|
|
|
|
u := bit.ReadVarInt(r)
|
|
|
|
g: uint8(u >> 4 & 0xff),
|
|
|
|
return color{
|
|
|
|
b: uint8(u >> 2 & 0xff),
|
|
|
|
r: uint8(u >> 6 & 0xff),
|
|
|
|
a: uint8(u >> 0 & 0xff),
|
|
|
|
g: uint8(u >> 4 & 0xff),
|
|
|
|
}, r.Err()
|
|
|
|
b: uint8(u >> 2 & 0xff),
|
|
|
|
|
|
|
|
a: uint8(u >> 0 & 0xff),
|
|
|
|
|
|
|
|
}, r.Err()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func atomType(spec *typeSpec, env *Env) tÿpe {
|
|
|
|
func atomType(spec *typeSpec, env *Env) tÿpe {
|
|
|
|
if t, ok := atom_types[spec.typeName]; ok {
|
|
|
|
for _, t := range atom_types {
|
|
|
|
Debug.Printf(" atom type")
|
|
|
|
if t.typeName() == spec.typeName {
|
|
|
|
return t
|
|
|
|
Debug.Printf(" atom type: %s", t.typeName())
|
|
|
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|