forked from bytecodealliance/wasmtime-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
externtype.go
84 lines (73 loc) · 2.1 KB
/
externtype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package wasmtime
// #include <wasm.h>
import "C"
import "runtime"
// ExternType means one of external types which classify imports and external values with their respective types.
type ExternType struct {
_ptr *C.wasm_externtype_t
_owner interface{}
}
// AsExternType is an interface for all types which can be ExternType.
type AsExternType interface {
AsExternType() *ExternType
}
func mkExternType(ptr *C.wasm_externtype_t, owner interface{}) *ExternType {
externtype := &ExternType{_ptr: ptr, _owner: owner}
if owner == nil {
runtime.SetFinalizer(externtype, func(externtype *ExternType) {
C.wasm_externtype_delete(externtype._ptr)
})
}
return externtype
}
func (ty *ExternType) ptr() *C.wasm_externtype_t {
ret := ty._ptr
maybeGC()
return ret
}
func (ty *ExternType) owner() interface{} {
if ty._owner != nil {
return ty._owner
}
return ty
}
// FuncType returns the underlying `FuncType` for this `ExternType` if it's a function
// type. Otherwise returns `nil`.
func (ty *ExternType) FuncType() *FuncType {
ptr := C.wasm_externtype_as_functype(ty.ptr())
if ptr == nil {
return nil
}
return mkFuncType(ptr, ty.owner())
}
// GlobalType returns the underlying `GlobalType` for this `ExternType` if it's a *global* type.
// Otherwise returns `nil`.
func (ty *ExternType) GlobalType() *GlobalType {
ptr := C.wasm_externtype_as_globaltype(ty.ptr())
if ptr == nil {
return nil
}
return mkGlobalType(ptr, ty.owner())
}
// TableType returns the underlying `TableType` for this `ExternType` if it's a *table* type.
// Otherwise returns `nil`.
func (ty *ExternType) TableType() *TableType {
ptr := C.wasm_externtype_as_tabletype(ty.ptr())
if ptr == nil {
return nil
}
return mkTableType(ptr, ty.owner())
}
// MemoryType returns the underlying `MemoryType` for this `ExternType` if it's a *memory* type.
// Otherwise returns `nil`.
func (ty *ExternType) MemoryType() *MemoryType {
ptr := C.wasm_externtype_as_memorytype(ty.ptr())
if ptr == nil {
return nil
}
return mkMemoryType(ptr, ty.owner())
}
// AsExternType returns this type itself
func (ty *ExternType) AsExternType() *ExternType {
return ty
}