Wasmtime
val.h File Reference
#include <stdalign.h>
#include <wasm.h>
#include <wasmtime/extern.h>

Go to the source code of this file.

Data Structures

union  wasmtime_valunion
 Container for different kinds of wasm values. More...
 
union  wasmtime_val_raw
 Container for possible wasm values. More...
 
union  wasmtime_val
 Container for different kinds of wasm values. More...
 

Macros

#define WASMTIME_I32   0
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is an i32.
 
#define WASMTIME_I64   1
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is an i64.
 
#define WASMTIME_F32   2
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is a f32.
 
#define WASMTIME_F64   3
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is a f64.
 
#define WASMTIME_V128   4
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is a v128.
 
#define WASMTIME_FUNCREF   5
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is a funcref.
 
#define WASMTIME_EXTERNREF   6
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is an externref.
 
#define WASMTIME_ANYREF   7
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is an anyref.
 

Typedefs

typedef struct wasmtime_anyref wasmtime_anyref_t
 Convenience alias for wasmtime_anyref.
 
typedef struct wasmtime_externref wasmtime_externref_t
 Convenience alias for wasmtime_externref.
 
typedef uint8_t wasmtime_valkind_t
 Discriminant stored in wasmtime_val::kind.
 
typedef uint8_t wasmtime_v128[16]
 A 128-bit value representing the WebAssembly v128 type. Bytes are stored in little-endian order.
 
typedef union wasmtime_valunion wasmtime_valunion_t
 Convenience alias for wasmtime_valunion.
 
typedef union wasmtime_val_raw wasmtime_val_raw_t
 Convenience alias for wasmtime_val_raw.
 
typedef struct wasmtime_val wasmtime_val_t
 Convenience alias for wasmtime_val_t.
 

Functions

wasmtime_anyref_twasmtime_anyref_clone (wasmtime_context_t *context, wasmtime_anyref_t *ref)
 Creates a shallow copy of the anyref argument, returning a separately owned pointer (depending on the configured collector this might increase a reference count or create a new GC root).
 
void wasmtime_anyref_delete (wasmtime_context_t *context, wasmtime_anyref_t *ref)
 Drops an owned pointer to ref, potentially deleting it if it's the last reference, or allowing it to be collected during the next GC.
 
wasmtime_anyref_twasmtime_anyref_from_raw (wasmtime_context_t *context, uint32_t raw)
 Converts a raw anyref value coming from wasmtime_val_raw_t into a wasmtime_anyref_t. More...
 
uint32_t wasmtime_anyref_to_raw (wasmtime_context_t *context, const wasmtime_anyref_t *ref)
 Converts a wasmtime_anyref_t to a raw value suitable for storing into a wasmtime_val_raw_t. More...
 
wasmtime_anyref_twasmtime_anyref_from_i31 (wasmtime_context_t *context, uint32_t i31val)
 Create a new i31ref value. More...
 
bool wasmtime_anyref_i31_get_u (wasmtime_context_t *context, wasmtime_anyref_t *anyref, uint32_t *dst)
 Get the anyref's underlying i31ref value, zero extended, if any. More...
 
bool wasmtime_anyref_i31_get_s (wasmtime_context_t *context, wasmtime_anyref_t *anyref, int32_t *dst)
 Get the anyref's underlying i31ref value, sign extended, if any. More...
 
wasmtime_externref_twasmtime_externref_new (wasmtime_context_t *context, void *data, void(*finalizer)(void *))
 Create a new externref value. More...
 
void * wasmtime_externref_data (wasmtime_context_t *context, wasmtime_externref_t *data)
 Get an externref's wrapped data. More...
 
wasmtime_externref_twasmtime_externref_clone (wasmtime_context_t *context, wasmtime_externref_t *ref)
 Creates a shallow copy of the externref argument, returning a separately owned pointer (depending on the configured collector this might increase a reference count or create a new GC root).
 
void wasmtime_externref_delete (wasmtime_context_t *context, wasmtime_externref_t *ref)
 Drops an owned pointer to ref, potentially deleting it if it's the last reference, or allowing it to be collected during the next GC.
 
wasmtime_externref_twasmtime_externref_from_raw (wasmtime_context_t *context, uint32_t raw)
 Converts a raw externref value coming from wasmtime_val_raw_t into a wasmtime_externref_t. More...
 
uint32_t wasmtime_externref_to_raw (wasmtime_context_t *context, const wasmtime_externref_t *ref)
 Converts a wasmtime_externref_t to a raw value suitable for storing into a wasmtime_val_raw_t. More...
 
void wasmtime_val_delete (wasmtime_context_t *context, wasmtime_val_t *val)
 Deletes an owned wasmtime_val_t. More...
 
void wasmtime_val_copy (wasmtime_context_t *context, wasmtime_val_t *dst, const wasmtime_val_t *src)
 Copies src into dst.
 

Detailed Description

APIs for interacting with WebAssembly values in Wasmtime.

Function Documentation

◆ wasmtime_anyref_from_i31()

wasmtime_anyref_t * wasmtime_anyref_from_i31 ( wasmtime_context_t context,
uint32_t  i31val 
)

Create a new i31ref value.

Creates a new i31ref value (which is a subtype of anyref) and returns a pointer to it.

If i31val does not fit in 31 bits, it is wrapped.

◆ wasmtime_anyref_from_raw()

wasmtime_anyref_t * wasmtime_anyref_from_raw ( wasmtime_context_t context,
uint32_t  raw 
)

Converts a raw anyref value coming from wasmtime_val_raw_t into a wasmtime_anyref_t.

Note that the returned wasmtime_anyref_t is an owned value that must be deleted via wasmtime_anyref_delete by the caller if it is non-null.

◆ wasmtime_anyref_i31_get_s()

bool wasmtime_anyref_i31_get_s ( wasmtime_context_t context,
wasmtime_anyref_t anyref,
int32_t *  dst 
)

Get the anyref's underlying i31ref value, sign extended, if any.

If the given anyref is an instance of i31ref, then its value is sign extended to 32 bits, written to dst, and true is returned.

If the given anyref is not an instance of i31ref, then false is returned and dst is left unmodified.

◆ wasmtime_anyref_i31_get_u()

bool wasmtime_anyref_i31_get_u ( wasmtime_context_t context,
wasmtime_anyref_t anyref,
uint32_t *  dst 
)

Get the anyref's underlying i31ref value, zero extended, if any.

If the given anyref is an instance of i31ref, then its value is zero extended to 32 bits, written to dst, and true is returned.

If the given anyref is not an instance of i31ref, then false is returned and dst is left unmodified.

◆ wasmtime_anyref_to_raw()

uint32_t wasmtime_anyref_to_raw ( wasmtime_context_t context,
const wasmtime_anyref_t ref 
)

Converts a wasmtime_anyref_t to a raw value suitable for storing into a wasmtime_val_raw_t.

Note that the returned underlying value is not tracked by Wasmtime's garbage collector until it enters WebAssembly. This means that a GC may release the context's reference to the raw value, making the raw value invalid within the context of the store. Do not perform a GC between calling this function and passing it to WebAssembly.

◆ wasmtime_externref_data()

void * wasmtime_externref_data ( wasmtime_context_t context,
wasmtime_externref_t data 
)

Get an externref's wrapped data.

Returns the original data passed to wasmtime_externref_new. It is required that data is not NULL.

◆ wasmtime_externref_from_raw()

wasmtime_externref_t * wasmtime_externref_from_raw ( wasmtime_context_t context,
uint32_t  raw 
)

Converts a raw externref value coming from wasmtime_val_raw_t into a wasmtime_externref_t.

Note that the returned wasmtime_externref_t is an owned value that must be deleted via wasmtime_externref_delete by the caller if it is non-null.

◆ wasmtime_externref_new()

wasmtime_externref_t * wasmtime_externref_new ( wasmtime_context_t context,
void *  data,
void(*)(void *)  finalizer 
)

Create a new externref value.

Creates a new externref value wrapping the provided data, returning the pointer to the externref.

Parameters
contextthe store context to allocate this externref within
datathe host-specific data to wrap
finalizeran optional finalizer for data

When the reference is reclaimed, the wrapped data is cleaned up with the provided finalizer.

The returned value must be deleted with wasmtime_externref_delete and may not be used after the context is destroyed.

◆ wasmtime_externref_to_raw()

uint32_t wasmtime_externref_to_raw ( wasmtime_context_t context,
const wasmtime_externref_t ref 
)

Converts a wasmtime_externref_t to a raw value suitable for storing into a wasmtime_val_raw_t.

Note that the returned underlying value is not tracked by Wasmtime's garbage collector until it enters WebAssembly. This means that a GC may release the context's reference to the raw value, making the raw value invalid within the context of the store. Do not perform a GC between calling this function and passing it to WebAssembly.

◆ wasmtime_val_delete()

void wasmtime_val_delete ( wasmtime_context_t context,
wasmtime_val_t val 
)

Deletes an owned wasmtime_val_t.

Note that this only deletes the contents, not the memory that val points to itself (which is owned by the caller).