github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/wasm/global.go (about)

     1  package wasm
     2  
     3  import (
     4  	"github.com/bananabytelabs/wazero/api"
     5  	"github.com/bananabytelabs/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.Val = v
    55  }