提交 36381d5a 编写于 作者: 3 3dgen

修正接口查询

上级 40385e8c
......@@ -85,10 +85,15 @@ func (t *Interface) emitGenFromInterface(x *aInterface) (insts []wat.Inst) {
insts = append(insts, x.Extract("d").EmitPush()...) //data
insts = append(insts, x.Extract("itab").EmitPush()...)
insts = append(insts, wat.NewInstLoad(wat.I32{}, 0, 4))
insts = append(insts, wat.NewInstConst(wat.I32{}, strconv.Itoa(t.Hash())))
insts = append(insts, wat.NewInstConst(wat.I32{}, "0"))
insts = append(insts, wat.NewInstCall("$wa.runtime.getItab")) //itab
ifs := wat.NewInstIf(nil, nil, nil)
ifs.Ret = append(ifs.Ret, wat.U32{})
ifs.True = append(ifs.True, x.Extract("itab").EmitPush()...)
ifs.True = append(ifs.True, wat.NewInstLoad(wat.I32{}, 0, 4))
ifs.True = append(ifs.True, wat.NewInstConst(wat.I32{}, strconv.Itoa(t.Hash())))
ifs.True = append(ifs.True, wat.NewInstConst(wat.I32{}, "0"))
ifs.True = append(ifs.True, wat.NewInstCall("$wa.runtime.getItab")) //itab
ifs.False = append(ifs.False, wat.NewInstConst(wat.I32{}, "0"))
insts = append(insts, ifs)
insts = append(insts, x.Extract("eq").EmitPush()...) //eq
......@@ -154,31 +159,14 @@ func (v *aInterface) emitGetData(destType ValueType, commaOk bool) (insts []wat.
}
func (v *aInterface) emitQueryInterface(destType ValueType, commaOk bool) (insts []wat.Inst) {
insts = append(insts, v.Extract("d").EmitPush()...) //data, todo: nil check
insts = append(insts, v.Extract("d").EmitPush()...)
insts = append(insts, v.Extract("itab").EmitPush()...)
insts = append(insts, wat.NewInstLoad(wat.I32{}, 0, 4))
insts = append(insts, v.Extract("eq").EmitPush()...)
insts = append(insts, wat.NewInstConst(wat.I32{}, strconv.Itoa(destType.Hash())))
if commaOk {
insts = append(insts, wat.NewInstConst(wat.I32{}, "1"))
} else {
insts = append(insts, wat.NewInstConst(wat.I32{}, "0"))
}
insts = append(insts, wat.NewInstCall("$wa.runtime.getItab")) //itab
insts = append(insts, wat.NewInstCall("$wa.runtime.DupI32"))
ifs := wat.NewInstIf(nil, nil, nil)
insts = append(insts, ifs)
if commaOk {
ifs.Ret = []wat.ValueType{wat.I32{}, wat.I32{}}
ifs.True = append(ifs.True, v.Extract("eq").EmitPush()...) //eq
ifs.True = append(ifs.True, wat.NewInstConst(wat.I32{}, "1")) //ok:true
ifs.False = append(ifs.False, v.Extract("eq").EmitPush()...) //eq
ifs.False = append(ifs.False, wat.NewInstConst(wat.I32{}, "0")) //ok:false
insts = append(insts, wat.NewInstCall("$wa.runtime.queryIface_CommaOk"))
} else {
ifs.False = append(ifs.False, wat.NewInstUnreachable())
insts = append(insts, v.Extract("eq").EmitPush()...) //eq
insts = append(insts, wat.NewInstCall("$wa.runtime.queryIface"))
}
return
......
(func $$wa.runtime.queryIface (param $d.b i32) (param $d.d i32) (param $itab i32) (param $eq i32) (param $ihash i32)
(result i32 i32 i32 i32)
(local $t i32)
local.get $itab
if (result i32 i32 i32 i32)
local.get $itab
i32.load offset=0 align=4
local.get $ihash
i32.const 0
call $$wa.runtime.getItab
local.set $t
local.get $t
if (result i32 i32 i32 i32)
local.get $d.b
local.get $d.d
local.get $t
local.get $eq
else
local.get $d.b
call $$Release
i32.const 0
i32.const 0
i32.const 0
i32.const 0
unreachable
end
else
local.get $d.b
call $$Release
i32.const 0
i32.const 0
i32.const 0
i32.const 0
unreachable
end
)
(func $$wa.runtime.queryIface_CommaOk (param $d.b i32) (param $d.d i32) (param $itab i32) (param $eq i32) (param $ihash i32)
(result i32 i32 i32 i32 i32)
(local $t i32)
local.get $itab
if (result i32 i32 i32 i32 i32)
local.get $itab
i32.load offset=0 align=4
local.get $ihash
i32.const 1
call $$wa.runtime.getItab
local.set $t
local.get $t
if (result i32 i32 i32 i32 i32)
local.get $d.b
local.get $d.d
local.get $t
local.get $eq
i32.const 1
else
local.get $d.b
call $$Release
i32.const 0
i32.const 0
i32.const 0
i32.const 0
i32.const 0
end
else
local.get $d.b
call $$Release
i32.const 0
i32.const 0
i32.const 0
i32.const 0
i32.const 0
end
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册