Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657package types
// Struct is a structure in memory whose regions are addressable with named fields.type Struct struct { File any Package string UniqueName string name string Fields []*Field}
// NewStruct creates a new struct.func NewStruct(file any, pkg string, name string) *Struct { return &Struct{ File: file, Package: pkg, UniqueName: pkg + "." + name, name: name, }}
// AddField adds a new field to the end of the struct.func (s *Struct) AddField(field *Field) { s.Fields = append(s.Fields, field)}
// FieldByName returns the field with the given name if it exists.func (s *Struct) FieldByName(name string) *Field { for _, field := range s.Fields { if field.Name == name { return field } }
return nil}
// IsArray returns true if the struct is an array.func (s *Struct) IsArray() bool { return len(s.Fields) > 0 && s.Fields[0].Name == "0"}
// Name returns the name of the struct.func (s *Struct) Name() string { return s.name}
// Size returns the total size in bytes.func (s *Struct) Size() int { sum := 0
for _, field := range s.Fields { sum += field.Type.Size() }
return sum}