Uint8Kind;
)
-var ptrsize uint64
-var interfacesize uint64
+// Int is guaranteed large enough to store a size.
+var ptrsize int
+var interfacesize int
var MissingString = "$missing$" // syntactic name for undefined type names
var DotDotDotString = "..."
Name() string;
String() string;
SetString(string); // TODO: remove when no longer needed
- Size() uint64;
+ Size() int;
}
// Fields and methods common to all types
kind int;
str string;
name string;
- size uint64;
+ size int;
}
func (c *Common) Kind() int {
c.str = s
}
-func (c *Common) Size() uint64 {
+func (c *Common) Size() int {
return c.size
}
Common
}
-func NewBasicType(name string, kind int, size uint64) Type {
+func NewBasicType(name string, kind int, size int) Type {
return &BasicType{ Common{kind, name, name, size} }
}
export type ArrayType interface {
Open() bool;
- Len() uint64;
+ Len() int;
Elem() Type;
}
Common;
elem *StubType;
open bool; // otherwise fixed size
- len uint64;
+ len int;
}
-func NewArrayTypeStruct(name, typestring string, open bool, len uint64, elem *StubType) *ArrayTypeStruct {
+func NewArrayTypeStruct(name, typestring string, open bool, len int, elem *StubType) *ArrayTypeStruct {
return &ArrayTypeStruct{ Common{ArrayKind, typestring, name, 0}, elem, open, len}
}
-func (t *ArrayTypeStruct) Size() uint64 {
+func (t *ArrayTypeStruct) Size() int {
if t.open {
return ptrsize // open arrays are pointers to structures
}
return t.open
}
-func (t *ArrayTypeStruct) Len() uint64 {
+func (t *ArrayTypeStruct) Len() int {
// what about open array? TODO
return t.len
}
return &MapTypeStruct{ Common{MapKind, typestring, name, 0}, key, elem}
}
-func (t *MapTypeStruct) Size() uint64 {
+func (t *MapTypeStruct) Size() int {
panic("reflect.type: map.Size(): cannot happen");
return 0
}
return &ChanTypeStruct{ Common{ChanKind, typestring, name, 0}, elem, dir}
}
-func (t *ChanTypeStruct) Size() uint64 {
+func (t *ChanTypeStruct) Size() int {
panic("reflect.type: chan.Size(): cannot happen");
return 0
}
// -- Struct
export type StructType interface {
- Field(int) (name string, typ Type, tag string, offset uint64);
+ Field(int) (name string, typ Type, tag string, offset int);
Len() int;
}
name string;
typ *StubType;
tag string;
- size uint64;
- offset uint64;
+ size int;
+ offset int;
}
type StructTypeStruct struct {
}
// TODO: not portable; depends on 6g
-func (t *StructTypeStruct) Size() uint64 {
+func (t *StructTypeStruct) Size() int {
if t.size > 0 {
return t.size
}
- size := uint64(0);
+ size := 0;
for i := 0; i < len(t.field); i++ {
elemsize := t.field[i].typ.Get().Size();
// pad until at (elemsize mod 8) boundary
t.field[i].offset = size;
size += elemsize;
}
- size = (size + 7) & ((1<<64 - 1) & ^7);
+ structalignmask := 7; // TODO: knows that size fits in int32 (also can't use const here)
+ size = (size + structalignmask) & ^(structalignmask);
t.size = size;
return size;
}
-func (t *StructTypeStruct) Field(i int) (name string, typ Type, tag string, offset uint64) {
+func (t *StructTypeStruct) Field(i int) (name string, typ Type, tag string, offset int) {
if t.field[i].offset == 0 {
t.Size(); // will compute offsets
}
// -- Interface
export type InterfaceType interface {
- Field(int) (name string, typ Type, tag string, offset uint64);
+ Field(int) (name string, typ Type, tag string, offset int);
Len() int;
}
return &InterfaceTypeStruct{ Common{InterfaceKind, typestring, name, interfacesize}, field }
}
-func (t *InterfaceTypeStruct) Field(i int) (name string, typ Type, tag string, offset uint64) {
+func (t *InterfaceTypeStruct) Field(i int) (name string, typ Type, tag string, offset int) {
return t.field[i].name, t.field[i].typ.Get(), "", 0
}
return &FuncTypeStruct{ Common{FuncKind, typestring, name, 0}, in, out }
}
-func (t *FuncTypeStruct) Size() uint64 {
+func (t *FuncTypeStruct) Size() int {
panic("reflect.type: func.Size(): cannot happen");
return 0
}
func (p *Parser) Type(name string) *StubType
func (p *Parser) Array(name string, tokstart int) *StubType {
- size := uint64(0);
+ size := 0;
open := true;
if p.token != "]" {
if len(p.token) == 0 || !isdigit(p.token[0]) {
// write our own (trivial and simpleminded) atoi to avoid dependency
size = 0;
for i := 0; i < len(p.token); i++ {
- size = size * 10 + uint64(p.token[i]) - '0'
+ size = size * 10 + int(p.token[i]) - '0'
}
p.Next();
open = false;
export type Value interface {
Kind() int;
Type() Type;
- Unreflect() Empty;
+ Interface() Empty;
}
// Common fields and functionality for all values
return c.typ
}
-func (c *Common) Unreflect() Empty {
+func (c *Common) Interface() Empty {
return sys.unreflect(*AddrToPtrAddr(c.addr), c.typ.String());
}
Kind() int;
Type() Type;
Open() bool;
- Len() uint64;
- Elem(i uint64) Value;
+ Len() int;
+ Elem(i int) Value;
}
type OpenArrayValueStruct struct {
Common;
elemtype Type;
- elemsize uint64;
+ elemsize int;
}
/*
return true
}
-func (v *OpenArrayValueStruct) Len() uint64 {
- return uint64(*AddrToPtrInt32(v.addr+8));
+func (v *OpenArrayValueStruct) Len() int {
+ return int(*AddrToPtrInt32(v.addr+8));
}
-func (v *OpenArrayValueStruct) Elem(i uint64) Value {
+func (v *OpenArrayValueStruct) Elem(i int) Value {
base := *AddrToPtrAddr(v.addr);
- return NewValueAddr(v.elemtype, base + i * v.elemsize);
+ return NewValueAddr(v.elemtype, base + Addr(i * v.elemsize));
}
type FixedArrayValueStruct struct {
Common;
elemtype Type;
- elemsize uint64;
- len uint64;
+ elemsize int;
+ len int;
}
func (v *FixedArrayValueStruct) Open() bool {
return false
}
-func (v *FixedArrayValueStruct) Len() uint64 {
+func (v *FixedArrayValueStruct) Len() int {
return v.len
}
-func (v *FixedArrayValueStruct) Elem(i uint64) Value {
- return NewValueAddr(v.elemtype, v.addr + i * v.elemsize);
+func (v *FixedArrayValueStruct) Elem(i int) Value {
+ return NewValueAddr(v.elemtype, v.addr + Addr(i * v.elemsize));
return nil
}
v := &StructValueStruct{ Common{StructKind, typ, addr}, new([]Value, nfield) };
for i := 0; i < nfield; i++ {
name, ftype, str, offset := t.Field(i);
- v.field[i] = NewValueAddr(ftype, addr + offset);
+ v.field[i] = NewValueAddr(ftype, addr + Addr(offset));
}
v.typ = typ;
return v;