global.go

 1package wasm
 2
 3import (
 4	"github.com/tetratelabs/wazero/api"
 5	"github.com/tetratelabs/wazero/internal/internalapi"
 6)
 7
 8// constantGlobal wraps GlobalInstance to implement api.Global.
 9type constantGlobal struct {
10	internalapi.WazeroOnlyType
11	g *GlobalInstance
12}
13
14// Type implements api.Global.
15func (g constantGlobal) Type() api.ValueType {
16	return g.g.Type.ValType
17}
18
19// Get implements api.Global.
20func (g constantGlobal) Get() uint64 {
21	ret, _ := g.g.Value()
22	return ret
23}
24
25// String implements api.Global.
26func (g constantGlobal) String() string {
27	return g.g.String()
28}
29
30// mutableGlobal extends constantGlobal to allow updates.
31type mutableGlobal struct {
32	internalapi.WazeroOnlyType
33	g *GlobalInstance
34}
35
36// Type implements api.Global.
37func (g mutableGlobal) Type() api.ValueType {
38	return g.g.Type.ValType
39}
40
41// Get implements api.Global.
42func (g mutableGlobal) Get() uint64 {
43	ret, _ := g.g.Value()
44	return ret
45}
46
47// String implements api.Global.
48func (g mutableGlobal) String() string {
49	return g.g.String()
50}
51
52// Set implements the same method as documented on api.MutableGlobal.
53func (g mutableGlobal) Set(v uint64) {
54	g.g.SetValue(v, 0)
55}