| Copyright | (c) 2026 Tushar Adhatrao |
|---|---|
| License | MIT |
| Stability | stable |
| Safe Haskell | None |
| Language | GHC2021 |
WasmEdge.Global
Description
Provides contexts for WebAssembly global variables:
GlobalType— describes the value type and mutability of a globalGlobalInstance— a runtime global variable instance
Synopsis
- data GlobalType
- createGlobalType :: ValType -> Mutability -> IO GlobalType
- deleteGlobalType :: GlobalType -> IO ()
- withGlobalType :: ValType -> Mutability -> (GlobalType -> IO a) -> IO a
- getGlobalTypeValType :: GlobalType -> IO ValType
- getGlobalTypeMutability :: GlobalType -> IO Mutability
- data GlobalInstance
- createGlobal :: GlobalType -> WasmVal -> IO GlobalInstance
- deleteGlobal :: GlobalInstance -> IO ()
- withGlobal :: GlobalType -> WasmVal -> (GlobalInstance -> IO a) -> IO a
- getGlobalType :: GlobalInstance -> IO GlobalType
- getGlobalValue :: GlobalInstance -> IO WasmVal
- setGlobalValue :: GlobalInstance -> WasmVal -> IO (WasmResult ())
- unsafeGlobalPtr :: GlobalInstance -> IO (Ptr GlobalInstanceTag)
- borrowGlobal :: Ptr GlobalInstanceTag -> IO GlobalInstance
- unsafeGlobalTypePtr :: GlobalType -> IO (Ptr GlobalTypeTag)
- borrowGlobalType :: Ptr GlobalTypeTag -> IO GlobalType
- disarmGlobal :: GlobalInstance -> IO ()
Global type
data GlobalType #
A WebAssembly global type context, describing its type and mutability.
createGlobalType :: ValType -> Mutability -> IO GlobalType #
Create a GlobalType with the specified ValType and Mutability.
deleteGlobalType :: GlobalType -> IO () #
Delete a GlobalType context.
withGlobalType :: ValType -> Mutability -> (GlobalType -> IO a) -> IO a #
Scoped GlobalType context.
getGlobalTypeValType :: GlobalType -> IO ValType #
Retrieve the ValType of a GlobalType.
getGlobalTypeMutability :: GlobalType -> IO Mutability #
Retrieve the Mutability of a GlobalType.
Global instance
data GlobalInstance #
A runtime WebAssembly global variable instance.
createGlobal :: GlobalType -> WasmVal -> IO GlobalInstance #
Create a GlobalInstance with the given type and initial value.
deleteGlobal :: GlobalInstance -> IO () #
Delete a GlobalInstance.
withGlobal :: GlobalType -> WasmVal -> (GlobalInstance -> IO a) -> IO a #
Scoped GlobalInstance.
getGlobalType :: GlobalInstance -> IO GlobalType #
Get the GlobalType of a GlobalInstance.
Note: the returned GlobalType borrows the type context from the instance.
getGlobalValue :: GlobalInstance -> IO WasmVal #
Get the current value of a global variable.
setGlobalValue :: GlobalInstance -> WasmVal -> IO (WasmResult ()) #
Set a new value for a mutable global variable.
Fails with a WasmEdgeError if the global is immutable or type mismatches.
Internal / borrowed pointers
unsafeGlobalPtr :: GlobalInstance -> IO (Ptr GlobalInstanceTag) #
Extract the raw pointer of a GlobalInstance.
borrowGlobal :: Ptr GlobalInstanceTag -> IO GlobalInstance #
Create a borrowed GlobalInstance from a raw pointer (does not finalize).
unsafeGlobalTypePtr :: GlobalType -> IO (Ptr GlobalTypeTag) #
Extract the raw pointer of a GlobalType.
borrowGlobalType :: Ptr GlobalTypeTag -> IO GlobalType #
Create a borrowed GlobalType from a raw pointer (does not finalize).
disarmGlobal :: GlobalInstance -> IO () #
Disarm finalizer when ownership is transferred to a module instance.