github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/wasm/global.go (about) 1 package wasm 2 3 import ( 4 "github.com/wasilibs/wazerox/api" 5 "github.com/wasilibs/wazerox/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 return g.g.Val 22 } 23 24 // String implements api.Global. 25 func (g constantGlobal) String() string { 26 return g.g.String() 27 } 28 29 // mutableGlobal extends constantGlobal to allow updates. 30 type mutableGlobal struct { 31 internalapi.WazeroOnlyType 32 g *GlobalInstance 33 } 34 35 // Type implements api.Global. 36 func (g mutableGlobal) Type() api.ValueType { 37 return g.g.Type.ValType 38 } 39 40 // Get implements api.Global. 41 func (g mutableGlobal) Get() uint64 { 42 return g.g.Val 43 } 44 45 // String implements api.Global. 46 func (g mutableGlobal) String() string { 47 return g.g.String() 48 } 49 50 // Set implements the same method as documented on api.MutableGlobal. 51 func (g mutableGlobal) Set(v uint64) { 52 g.g.Val = v 53 } 54 55 // compile-time check to ensure mutableGlobal is a api.Global. 56 var _ api.Global = mutableGlobal{}