Give Listener a read-only view of globals (#1404)
* 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>
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
"github.com/tetratelabs/wazero/internal/internalapi"
|
||||
"github.com/tetratelabs/wazero/sys"
|
||||
)
|
||||
|
||||
@@ -223,19 +222,17 @@ func (m *ModuleInstance) ExportedGlobal(name string) api.Global {
|
||||
}
|
||||
g := m.Globals[exp.Index]
|
||||
if g.Type.Mutable {
|
||||
return &mutableGlobal{internalapi.WazeroOnlyType{}, g}
|
||||
}
|
||||
valType := g.Type.ValType
|
||||
switch valType {
|
||||
case ValueTypeI32:
|
||||
return globalI32(g.Val)
|
||||
case ValueTypeI64:
|
||||
return globalI64(g.Val)
|
||||
case ValueTypeF32:
|
||||
return globalF32(g.Val)
|
||||
case ValueTypeF64:
|
||||
return globalF64(g.Val)
|
||||
default:
|
||||
panic(fmt.Errorf("BUG: unknown value type %X", valType))
|
||||
return mutableGlobal{g: g}
|
||||
}
|
||||
return constantGlobal{g: g}
|
||||
}
|
||||
|
||||
// NumGlobal implements experimental.InternalModule.
|
||||
func (m *ModuleInstance) NumGlobal() int {
|
||||
return len(m.Globals)
|
||||
}
|
||||
|
||||
// Global implements experimental.InternalModule.
|
||||
func (m *ModuleInstance) Global(idx int) api.Global {
|
||||
return constantGlobal{g: m.Globals[idx]}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user