MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime-go / inferFuncType

Function inferFuncType

func.go:185–215  ·  view source on GitHub ↗
(val reflect.Value)

Source from the content-addressed store, hash-verified

183}
184
185func inferFuncType(val reflect.Value) *FuncType {
186 // Make sure the `interface{}` passed in was indeed a function
187 ty := val.Type()
188 if ty.Kind() != reflect.Func {
189 panic("callback provided must be a `func`")
190 }
191
192 // infer the parameter types, and `*Caller` type is special in the
193 // parameters so be sure to case on that as well.
194 params := make([]*ValType, 0, ty.NumIn())
195 var caller *Caller
196 for i := 0; i < ty.NumIn(); i++ {
197 paramTy := ty.In(i)
198 if paramTy != reflect.TypeOf(caller) {
199 params = append(params, typeToValType(paramTy))
200 }
201 }
202
203 // Then infer the result types, where a final `*Trap` result value is
204 // also special.
205 results := make([]*ValType, 0, ty.NumOut())
206 var trap *Trap
207 for i := 0; i < ty.NumOut(); i++ {
208 resultTy := ty.Out(i)
209 if i == ty.NumOut()-1 && resultTy == reflect.TypeOf(trap) {
210 continue
211 }
212 results = append(results, typeToValType(resultTy))
213 }
214 return NewFuncType(params, results)
215}
216
217func typeToValType(ty reflect.Type) *ValType {
218 var a int32

Callers 2

WrapFuncFunction · 0.85
FuncWrapMethod · 0.85

Calls 4

typeToValTypeFunction · 0.85
NewFuncTypeFunction · 0.85
TypeMethod · 0.45
KindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…