提交 f1c62d54 编写于 作者: 3 3dgen

优化结构体操作,支持非0值常量结构体

上级 cccd46c0
......@@ -24,6 +24,7 @@ type iStruct interface {
type Field struct {
name string
typ ValueType
const_val Value
_start int
}
......@@ -33,6 +34,9 @@ func (i Field) Type() ValueType { return i.typ }
func (i Field) Equal(u Field) bool { return i.name == u.name && i.typ.Equal(u.typ) }
func makeAlign(i, a int) int {
if a == 1 || a == 0 {
return i
}
return (i + a - 1) / a * a
}
......@@ -168,9 +172,9 @@ func (t Struct) emitLoadFromAddr(addr Value, offset int) (insts []wat.Inst) {
}
func (t Struct) findFieldByName(field_name string) *Field {
for _, m := range t.Members {
if m.Name() == field_name {
return &m
for i := range t.Members {
if t.Members[i].Name() == field_name {
return &t.Members[i]
}
}
return nil
......@@ -190,9 +194,13 @@ func newValueStruct(name string, kind ValueKind, typ ValueType) *aStruct {
func (v *aStruct) genSubValue(m Field) Value {
if v.Kind() != ValueKindConst {
return newValue(v.Name()+"."+m.Name(), v.Kind(), m.Type())
} else {
if m.const_val != nil {
return m.const_val
} else {
return newValue(v.Name(), v.Kind(), m.Type())
}
}
}
func (v *aStruct) raw() []wat.Value {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册