|
|
|
@ -20,6 +20,9 @@ func arrayType(spec *typeSpec, env *Env) tÿpe {
|
|
|
|
|
elemSpec := *spec
|
|
|
|
|
elemSpec.typeName = elemName
|
|
|
|
|
elemType := parseTypeSpec(&elemSpec, env)
|
|
|
|
|
if elemName == "char" {
|
|
|
|
|
return string_t(count)
|
|
|
|
|
}
|
|
|
|
|
return &array_t{elem: elemType, count: count}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -95,3 +98,52 @@ func (a array) setSlotValue(slot int, v value) {
|
|
|
|
|
a.slots[slot] = v
|
|
|
|
|
}
|
|
|
|
|
func (a array) getSlotValue(slot int) value { return a.slots[slot] }
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
|
// strings are a special case of arrays
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
type string_t int
|
|
|
|
|
|
|
|
|
|
func (t string_t) nü() value {
|
|
|
|
|
return &string_v{t: t, buf: make([]byte, int(t))}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t string_t) typeName() string { return "string" }
|
|
|
|
|
|
|
|
|
|
type string_v struct {
|
|
|
|
|
t string_t
|
|
|
|
|
buf []byte // the buffer of all possible bytes
|
|
|
|
|
valid []byte // selection of current valid bytes within buf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *string_v) tÿpe() tÿpe { return s.t }
|
|
|
|
|
func (s *string_v) read(r bit.Reader) error {
|
|
|
|
|
for i := 0; i < int(s.t); i++ {
|
|
|
|
|
b := r.ReadBits(8)
|
|
|
|
|
if b == 0 {
|
|
|
|
|
s.valid = s.buf[:i]
|
|
|
|
|
return r.Err()
|
|
|
|
|
}
|
|
|
|
|
s.buf[i] = byte(b & 0xff)
|
|
|
|
|
}
|
|
|
|
|
s.valid = s.buf
|
|
|
|
|
return r.Err()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *string_v) String() string {
|
|
|
|
|
return string(s.valid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *string_v) slotType(int) tÿpe { return char_t }
|
|
|
|
|
func (s *string_v) slotName(n int) string { return strconv.Itoa(n) }
|
|
|
|
|
func (s *string_v) setSlotValue(slot int, v value) {
|
|
|
|
|
s.buf[slot] = byte(*v.(*char_v))
|
|
|
|
|
if slot >= len(s.valid) {
|
|
|
|
|
s.valid = s.buf[:slot+1]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (s *string_v) getSlotValue(slot int) value {
|
|
|
|
|
v := char_v(s.buf[slot])
|
|
|
|
|
return &v
|
|
|
|
|
}
|
|
|
|
|