* experimental: give listener r/o view of globals Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * experimental: add global support to interpreter Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * exp: replace globals proxy with module interface Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * exp: trim down experimental.InternalModule Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * Replace globals view slice with constantGlobal Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * Fix tests after merge Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * Address PR feedback Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * Rename methods of experimental.Module Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * Run make check Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> * Add WazeroOnlyType to constantGlobal Signed-off-by: Thomas Pelletier <thomas@pelletier.codes> --------- Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package wasm
|
|
|
|
import (
|
|
"github.com/tetratelabs/wazero/api"
|
|
"github.com/tetratelabs/wazero/internal/internalapi"
|
|
)
|
|
|
|
// constantGlobal wraps GlobalInstance to implement api.Global.
|
|
type constantGlobal struct {
|
|
internalapi.WazeroOnlyType
|
|
g *GlobalInstance
|
|
}
|
|
|
|
// Type implements api.Global.
|
|
func (g constantGlobal) Type() api.ValueType {
|
|
return g.g.Type.ValType
|
|
}
|
|
|
|
// Get implements api.Global.
|
|
func (g constantGlobal) Get() uint64 {
|
|
return g.g.Val
|
|
}
|
|
|
|
// String implements api.Global.
|
|
func (g constantGlobal) String() string {
|
|
return g.g.String()
|
|
}
|
|
|
|
// mutableGlobal extends constantGlobal to allow updates.
|
|
type mutableGlobal struct {
|
|
internalapi.WazeroOnlyType
|
|
g *GlobalInstance
|
|
}
|
|
|
|
// Type implements api.Global.
|
|
func (g mutableGlobal) Type() api.ValueType {
|
|
return g.g.Type.ValType
|
|
}
|
|
|
|
// Get implements api.Global.
|
|
func (g mutableGlobal) Get() uint64 {
|
|
return g.g.Val
|
|
}
|
|
|
|
// String implements api.Global.
|
|
func (g mutableGlobal) String() string {
|
|
return g.g.String()
|
|
}
|
|
|
|
// Set implements the same method as documented on api.MutableGlobal.
|
|
func (g mutableGlobal) Set(v uint64) {
|
|
g.g.Val = v
|
|
}
|
|
|
|
// compile-time check to ensure mutableGlobal is a api.Global.
|
|
var _ api.Global = mutableGlobal{}
|