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