36#include <initializer_list>
52#include <wasmtime/types.hh>
67typedef std::variant<Func, Global, Memory, Table>
Extern;
69template <
typename Params,
typename Results>
class TypedFunc;
89 std::optional<Extern>
get_export(std::string_view name);
95inline Store::Context::Context(
Caller &caller)
103template <
typename T>
struct WasmType {
static const bool valid =
false; };
108#define NATIVE_WASM_TYPE(native, valkind, field) \
109 template <> struct WasmType<native> { \
110 static const bool valid = true; \
111 static const ValKind kind = ValKind::valkind; \
112 static void store(Store::Context cx, wasmtime_val_raw_t *p, \
116 static native load(Store::Context cx, wasmtime_val_raw_t *p) { \
128#undef NATIVE_WASM_TYPE
132template <>
struct WasmType<std::optional<ExternRef>> {
133 static const bool valid =
true;
134 static const ValKind kind = ValKind::ExternRef;
136 const std::optional<ExternRef> &ref) {
143 static std::optional<ExternRef> load(Store::Context cx,
150 return ExternRef(val);
155template <>
struct WasmType<
V128> {
156 static const bool valid =
true;
157 static const ValKind kind = ValKind::V128;
168template <
typename T>
struct WasmTypeList {
169 static const bool valid = WasmType<T>::valid;
170 static const size_t size = 1;
171 static bool matches(ValType::ListRef types) {
172 return WasmTypeList<std::tuple<T>>::matches(types);
176 WasmType<T>::store(cx, storage, t);
179 return WasmType<T>::load(cx, storage);
181 static std::vector<ValType> types() {
return {WasmType<T>::kind}; }
185template <>
struct WasmTypeList<std::monostate> {
186 static const bool valid =
true;
187 static const size_t size = 0;
188 static bool matches(ValType::ListRef types) {
return types.size() == 0; }
190 const std::monostate &t) {}
192 return std::monostate();
194 static std::vector<ValType> types() {
return {}; }
198template <
typename... T>
struct WasmTypeList<std::tuple<T...>> {
199 static const bool valid = (WasmType<T>::valid && ...);
200 static const size_t size =
sizeof...(T);
201 static bool matches(ValType::ListRef types) {
202 if (types.size() != size) {
206 return ((WasmType<T>::kind == types.begin()[n++].kind()) && ...);
209 const std::tuple<T...> &t) {
212 [&](
const auto &...val) {
213 (WasmType<T>::store(cx, &storage[n++], val), ...);
219 return std::tuple<T...>{WasmType<T>::load(cx, &storage[n++])...};
221 static std::vector<ValType> types() {
return {WasmType<T>::kind...}; }
227template <
typename R>
struct WasmHostRet {
228 using Results = WasmTypeList<R>;
230 template <
typename F,
typename... A>
233 auto ret = f(args...);
234 Results::store(cx, raw, ret);
240template <>
struct WasmHostRet<void> {
241 using Results = WasmTypeList<std::tuple<>>;
243 template <
typename F,
typename... A>
253template <>
struct WasmHostRet<std::monostate> :
public WasmHostRet<void> {};
257template <
typename R>
struct WasmHostRet<Result<R, Trap>> {
258 using Results = WasmTypeList<R>;
260 template <
typename F,
typename... A>
263 Result<R, Trap> ret = f(args...);
267 Results::store(cx, raw, ret.ok());
272template <
typename F,
typename =
void>
struct WasmHostFunc;
276template <
typename R,
typename... A>
struct WasmHostFunc<R (*)(A...)> {
277 using Params = WasmTypeList<std::tuple<A...>>;
278 using Results =
typename WasmHostRet<R>::Results;
280 template <
typename F>
282 auto params = Params::load(cx, raw);
284 [&](
const auto &...val) {
285 return WasmHostRet<R>::invoke(f, cx, raw, val...);
292template <
typename R,
typename... A>
293struct WasmHostFunc<R (*)(Caller, A...)> :
public WasmHostFunc<R (*)(A...)> {
295 template <
typename F>
297 auto params = WasmTypeList<std::tuple<A...>>::load(cx, raw);
299 [&](
const auto &...val) {
300 return WasmHostRet<R>::invoke(f, cx, raw, cx, val...);
307template <
typename R,
typename C,
typename... A>
308struct WasmHostFunc<R (C::*)(A...)> :
public WasmHostFunc<R (*)(A...)> {};
311template <
typename R,
typename C,
typename... A>
312struct WasmHostFunc<R (C::*)(A...) const> :
public WasmHostFunc<R (*)(A...)> {};
316template <
typename R,
typename C,
typename... A>
317struct WasmHostFunc<R (C::*)(Caller, A...)>
318 :
public WasmHostFunc<R (*)(Caller, A...)> {};
322template <
typename R,
typename C,
typename... A>
323struct WasmHostFunc<R (C::*)(Caller, A...) const>
324 :
public WasmHostFunc<R (*)(Caller, A...)> {};
329struct WasmHostFunc<T, std::void_t<decltype(&T::operator())>>
330 :
public WasmHostFunc<decltype(&T::operator())> {};
334using namespace detail;
351 template <
typename Params,
typename Results>
friend class TypedFunc;
355 template <
typename F>
361 F *func =
reinterpret_cast<F *
>(env);
364 Span<Val> results_span(
reinterpret_cast<Val *
>(results),
367 (*func)(
Caller(caller), args_span, results_span);
369 return result.
err().ptr.release();
374 template <
typename F>
378 size_t nargs_and_results) {
379 using HostFunc = WasmHostFunc<F>;
381 F *func =
reinterpret_cast<F *
>(env);
382 auto trap = HostFunc::invoke(*func, cx, args_and_results);
384 return trap->ptr.release();
389 template <
typename F>
static void raw_finalize(
void *env) {
390 std::unique_ptr<F> ptr(
reinterpret_cast<F *
>(env));
428 template <
typename F,
430 std::is_invocable_r_v<Result<std::monostate, Trap>, F,
Caller,
435 std::make_unique<F>(f).release(), raw_finalize<F>, &func);
476 template <
typename F,
477 std::enable_if_t<WasmHostFunc<F>::Params::valid,
bool> =
true,
478 std::enable_if_t<WasmHostFunc<F>::Results::valid,
bool> =
true>
480 using HostFunc = WasmHostFunc<F>;
481 auto params = HostFunc::Params::types();
482 auto results = HostFunc::Results::types();
486 std::make_unique<F>(f).release(),
487 raw_finalize<F>, &func);
511 template <
typename I>
513 const I &end)
const {
514 std::vector<wasmtime_val_t> raw_params;
515 raw_params.reserve(end - begin);
516 for (
auto i = begin; i != end; i++) {
517 raw_params.push_back(i->val);
519 size_t nresults = this->type(cx)->results().size();
520 std::vector<wasmtime_val_t> raw_results(nresults);
525 raw_results.data(), raw_results.capacity(), &trap);
526 if (error !=
nullptr) {
529 if (trap !=
nullptr) {
533 std::vector<Val> results;
534 results.reserve(nresults);
535 for (
size_t i = 0; i < nresults; i++) {
536 results.push_back(raw_results[i]);
548 const std::vector<Val> ¶ms)
const {
549 return this->call(cx, params.begin(), params.end());
560 return this->call(cx, params.begin(), params.end());
585 template <
typename Params,
typename Results,
586 std::enable_if_t<WasmTypeList<Params>::valid,
bool> =
true,
587 std::enable_if_t<WasmTypeList<Results>::valid,
bool> =
true>
589 auto ty = this->type(cx);
590 if (!WasmTypeList<Params>::matches(ty->params()) ||
591 !WasmTypeList<Results>::matches(ty->results())) {
592 return Trap(
"static type for this function does not match actual type");
606template <
typename Params,
typename Results>
class TypedFunc {
624 WasmTypeList<Results>::size)>
629 WasmTypeList<Params>::store(cx, ptr, params);
632 cx.
raw_context(), &f.func, ptr, storage.size(), &trap);
633 if (error !=
nullptr) {
636 if (trap !=
nullptr) {
639 return WasmTypeList<Results>::load(cx, ptr);
646inline Val::Val(std::optional<Func> func) : val{} {
651 wasmtime_funcref_set_null(&val.
of.
funcref);
655inline Val::Val(
Func func) :
Val(std::optional(func)) {}
670template <>
struct detail::WasmType<std::optional<Func>> {
672 static const bool valid =
true;
674 static const ValKind kind = ValKind::FuncRef;
677 const std::optional<Func> func) {
728 if (error !=
nullptr) {
747 if (error !=
nullptr) {
750 return std::monostate();
787 if (error !=
nullptr) {
818 const Val &val)
const {
820 if (error !=
nullptr) {
823 return std::monostate();
835 const Val &init)
const {
838 if (error !=
nullptr) {
876 if (error !=
nullptr) {
910 if (error !=
nullptr) {
950 if (
const auto *func = std::get_if<Func>(&e)) {
953 }
else if (
const auto *global = std::get_if<Global>(&e)) {
956 }
else if (
const auto *table = std::get_if<Table>(&e)) {
959 }
else if (
const auto *memory = std::get_if<Memory>(&e)) {
988 const std::vector<Extern> &imports) {
989 std::vector<wasmtime_extern_t> raw_imports;
990 for (
const auto &item : imports) {
992 auto &last = raw_imports.back();
993 Instance::cvt(item, last);
998 raw_imports.size(), &instance, &trap);
999 if (error !=
nullptr) {
1002 if (trap !=
nullptr) {
1018 return std::nullopt;
1020 return Instance::cvt(e);
1035 char *name =
nullptr;
1039 return std::nullopt;
1041 std::string_view n(name, len);
1042 return std::pair(n, Instance::cvt(e));
1049 return Instance::cvt(item);
1051 return std::nullopt;
1066 std::unique_ptr<wasmtime_linker_t, deleter> ptr;
1082 std::string_view name,
const Extern &item) {
1084 Instance::cvt(item, raw);
1087 name.data(), name.size(), &raw);
1088 if (error !=
nullptr) {
1089 return Error(error);
1091 return std::monostate();
1100 if (error !=
nullptr) {
1101 return Error(error);
1103 return std::monostate();
1111 ptr.get(), cx.ptr, name.data(), name.size(), &instance.instance);
1112 if (error !=
nullptr) {
1113 return Error(error);
1115 return std::monostate();
1125 if (error !=
nullptr) {
1128 if (trap !=
nullptr) {
1139 name.size(), m.ptr.get());
1140 if (error !=
nullptr) {
1141 return Error(error);
1143 return std::monostate();
1148 [[nodiscard]] std::optional<Extern>
1152 name.data(), name.size(), &item)) {
1153 return Instance::cvt(item);
1155 return std::nullopt;
1160 template <
typename F,
1162 std::is_invocable_r_v<Result<std::monostate, Trap>, F,
Caller,
1166 std::string_view name,
const FuncType &ty,
1170 ptr.get(),
module.data(),
module.length(), name.data(), name.length(),
1171 ty.ptr.get(), Func::raw_callback<std::remove_reference_t<F>>, std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f)).release(),
1172 Func::raw_finalize<std::remove_reference_t<F>>);
1174 if (error !=
nullptr) {
1175 return Error(error);
1178 return std::monostate();
1183 template <
typename F,
1184 std::enable_if_t<WasmHostFunc<F>::Params::valid,
bool> =
true,
1185 std::enable_if_t<WasmHostFunc<F>::Results::valid,
bool> =
true>
1187 std::string_view name, F&& f) {
1188 using HostFunc = WasmHostFunc<F>;
1189 auto params = HostFunc::Params::types();
1190 auto results = HostFunc::Results::types();
1193 ptr.get(),
module.data(),
module.length(), name.data(), name.length(),
1194 ty.ptr.get(), Func::raw_callback_unchecked<std::remove_reference_t<F>>,
1195 std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f)).release(), Func::raw_finalize<std::remove_reference_t<F>>);
1197 if (error !=
nullptr) {
1198 return Error(error);
1201 return std::monostate();
1209 name.size(), &item);
1210 if (error !=
nullptr) {
1211 return Error(error);
Representation of a WebAssembly anyref value.
Definition: val.hh:82
Structure provided to host functions to lookup caller information or acquire a Store::Context.
Definition: wasmtime.hh:78
std::optional< Extern > get_export(std::string_view name)
Definition: wasmtime.hh:1046
Store::Context context()
Explicitly acquire a Store::Context from this Caller.
Definition: wasmtime.hh:92
Global compilation state in Wasmtime.
Definition: engine.hh:21
Errors coming from Wasmtime.
Definition: error.hh:24
Representation of a WebAssembly externref value.
Definition: val.hh:28
Type information for a WebAssembly function.
Definition: func.hh:15
static FuncType from_iters(P params, R results)
Creates a new function type from the given list of parameters and results.
Definition: func.hh:75
Representation of a WebAssembly function.
Definition: wasmtime.hh:347
TrapResult< std::vector< Val > > call(Store::Context cx, const I &begin, const I &end) const
Invoke a WebAssembly function.
Definition: wasmtime.hh:512
Func(wasmtime_func_t func)
Creates a new function from the raw underlying C API representation.
Definition: wasmtime.hh:395
FuncType type(Store::Context cx) const
Returns the type of this function.
Definition: wasmtime.hh:564
const wasmtime_func_t & raw_func() const
Returns the raw underlying C API function this is using.
Definition: wasmtime.hh:599
TrapResult< std::vector< Val > > call(Store::Context cx, const std::vector< Val > ¶ms) const
Helper function for call(Store::Context cx, const I &begin, const I &end)
Definition: wasmtime.hh:547
static Func wrap(Store::Context cx, F f)
Creates a new host function from the provided callback f, inferring the WebAssembly function type fro...
Definition: wasmtime.hh:479
TrapResult< std::vector< Val > > call(Store::Context cx, const std::initializer_list< Val > ¶ms) const
Helper function for call(Store::Context cx, const I &begin, const I &end)
Definition: wasmtime.hh:559
Func(Store::Context cx, const FuncType &ty, F f)
Creates a new host-defined function.
Definition: wasmtime.hh:433
Result< TypedFunc< Params, Results >, Trap > typed(Store::Context cx) const
Statically checks this function against the provided types.
Definition: wasmtime.hh:588
Type information about a WebAssembly global.
Definition: global.hh:15
A WebAssembly global.
Definition: wasmtime.hh:707
Global(wasmtime_global_t global)
Creates as global from the raw underlying C API representation.
Definition: wasmtime.hh:713
Result< std::monostate > set(Store::Context cx, const Val &val) const
Definition: wasmtime.hh:745
Val get(Store::Context cx) const
Returns the current value of this global.
Definition: wasmtime.hh:847
GlobalType type(Store::Context cx) const
Returns the type of this global.
Definition: wasmtime.hh:735
static Result< Global > create(Store::Context cx, const GlobalType &ty, const Val &init)
Create a new WebAssembly global.
Definition: wasmtime.hh:724
A WebAssembly instance.
Definition: wasmtime.hh:929
Instance(wasmtime_instance_t instance)
Creates a new instance from the raw underlying C API representation.
Definition: wasmtime.hh:969
std::optional< std::pair< std::string_view, Extern > > get(Store::Context cx, size_t idx)
Load an instance's export by index.
Definition: wasmtime.hh:1029
std::optional< Extern > get(Store::Context cx, std::string_view name)
Load an instance's export by name.
Definition: wasmtime.hh:1014
static TrapResult< Instance > create(Store::Context cx, const Module &m, const std::vector< Extern > &imports)
Instantiates the module m with the provided imports
Definition: wasmtime.hh:987
Helper class for linking modules together with name-based resolution.
Definition: wasmtime.hh:1061
Result< std::monostate > define(Store::Context cx, std::string_view module, std::string_view name, const Extern &item)
Defines the provided item into this linker with the given name.
Definition: wasmtime.hh:1081
Result< std::monostate > func_wrap(std::string_view module, std::string_view name, F &&f)
Definition: wasmtime.hh:1186
Linker(Engine &engine)
Creates a new linker which will instantiate in the given engine.
Definition: wasmtime.hh:1070
Result< std::monostate > func_new(std::string_view module, std::string_view name, const FuncType &ty, F &&f)
Definition: wasmtime.hh:1165
void allow_shadowing(bool allow)
Definition: wasmtime.hh:1076
Result< std::monostate > module(Store::Context cx, std::string_view name, const Module &m)
Definition: wasmtime.hh:1136
std::optional< Extern > get(Store::Context cx, std::string_view module, std::string_view name)
Definition: wasmtime.hh:1149
Result< Func > get_default(Store::Context cx, std::string_view name)
Definition: wasmtime.hh:1206
TrapResult< Instance > instantiate(Store::Context cx, const Module &m)
Definition: wasmtime.hh:1120
Result< std::monostate > define_instance(Store::Context cx, std::string_view name, Instance instance)
Definition: wasmtime.hh:1109
Result< std::monostate > define_wasi()
Definition: wasmtime.hh:1098
Type information about a WebAssembly linear memory.
Definition: memory.hh:18
A WebAssembly linear memory.
Definition: wasmtime.hh:864
Memory(wasmtime_memory_t memory)
Creates a new memory from the raw underlying C API representation.
Definition: wasmtime.hh:870
static Result< Memory > create(Store::Context cx, const MemoryType &ty)
Creates a new host-defined memory with the type specified.
Definition: wasmtime.hh:873
Span< uint8_t > data(Store::Context cx) const
Definition: wasmtime.hh:897
MemoryType type(Store::Context cx) const
Returns the type of this memory.
Definition: wasmtime.hh:883
uint64_t size(Store::Context cx) const
Returns the size, in WebAssembly pages, of this memory.
Definition: wasmtime.hh:888
Result< uint64_t > grow(Store::Context cx, uint64_t delta) const
Definition: wasmtime.hh:907
Representation of a compiled WebAssembly module.
Definition: module.hh:27
Fallible result type used for Wasmtime.
Definition: error.hh:83
E && err()
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:97
Span class used when c++20 is not available.
Definition: span.hh:45
An interior pointer into a Store.
Definition: store.hh:60
wasmtime_context_t * raw_context()
Returns the raw context pointer for the C API.
Definition: store.hh:153
Owner of all WebAssembly objects.
Definition: store.hh:33
Type information about a WebAssembly table.
Definition: table.hh:16
A WebAssembly table.
Definition: wasmtime.hh:766
Table(wasmtime_table_t table)
Creates a new table from the raw underlying C API representation.
Definition: wasmtime.hh:772
Result< std::monostate > set(Store::Context cx, uint64_t idx, const Val &val) const
Definition: wasmtime.hh:817
static Result< Table > create(Store::Context cx, const TableType &ty, const Val &init)
Creates a new host-defined table.
Definition: wasmtime.hh:783
Result< uint64_t > grow(Store::Context cx, uint64_t delta, const Val &init) const
Definition: wasmtime.hh:834
uint64_t size(Store::Context cx) const
Returns the size, in elements, that the table currently has.
Definition: wasmtime.hh:799
TableType type(Store::Context cx) const
Returns the type of this table.
Definition: wasmtime.hh:794
std::optional< Val > get(Store::Context cx, uint64_t idx) const
Definition: wasmtime.hh:806
Information about a WebAssembly trap.
Definition: trap.hh:113
A version of a WebAssembly Func where the type signature of the function is statically known.
Definition: wasmtime.hh:606
const Func & func() const
Returns the underlying un-typed Func for this function.
Definition: wasmtime.hh:643
TrapResult< Results > call(Store::Context cx, Params params) const
Calls this function with the provided parameters.
Definition: wasmtime.hh:622
Representation of a generic WebAssembly value.
Definition: val.hh:160
std::optional< Func > funcref() const
Definition: wasmtime.hh:659
#define WASMTIME_EXTERN_TABLE
Value of wasmtime_extern_kind_t meaning that wasmtime_extern_t is a table.
Definition: extern.h:89
#define WASMTIME_EXTERN_GLOBAL
Value of wasmtime_extern_kind_t meaning that wasmtime_extern_t is a global.
Definition: extern.h:86
#define WASMTIME_EXTERN_FUNC
Value of wasmtime_extern_kind_t meaning that wasmtime_extern_t is a function.
Definition: extern.h:83
#define WASMTIME_EXTERN_MEMORY
Value of wasmtime_extern_kind_t meaning that wasmtime_extern_t is a memory.
Definition: extern.h:92
void wasmtime_func_from_raw(wasmtime_context_t *context, void *raw, wasmtime_func_t *ret)
Converts a raw nonzero funcref value from wasmtime_val_raw_t into a wasmtime_func_t.
wasmtime_error_t * wasmtime_func_call(wasmtime_context_t *store, const wasmtime_func_t *func, const wasmtime_val_t *args, size_t nargs, wasmtime_val_t *results, size_t nresults, wasm_trap_t **trap)
Call a WebAssembly function.
void * wasmtime_func_to_raw(wasmtime_context_t *context, const wasmtime_func_t *func)
Converts a func which belongs to context into a usize parameter that is suitable for insertion into a...
wasmtime_error_t * wasmtime_func_call_unchecked(wasmtime_context_t *store, const wasmtime_func_t *func, wasmtime_val_raw_t *args_and_results, size_t args_and_results_len, wasm_trap_t **trap)
Call a WebAssembly function in an "unchecked" fashion.
void wasmtime_func_new(wasmtime_context_t *store, const wasm_functype_t *type, wasmtime_func_callback_t callback, void *env, void(*finalizer)(void *), wasmtime_func_t *ret)
Creates a new host-defined function.
wasmtime_context_t * wasmtime_caller_context(wasmtime_caller_t *caller)
Returns the store context of the caller object.
bool wasmtime_caller_export_get(wasmtime_caller_t *caller, const char *name, size_t name_len, wasmtime_extern_t *item)
Loads a wasmtime_extern_t from the caller's context.
void wasmtime_func_new_unchecked(wasmtime_context_t *store, const wasm_functype_t *type, wasmtime_func_unchecked_callback_t callback, void *env, void(*finalizer)(void *), wasmtime_func_t *ret)
Creates a new host function in the same manner of wasmtime_func_new, but the function-to-call has no ...
wasm_functype_t * wasmtime_func_type(const wasmtime_context_t *store, const wasmtime_func_t *func)
Returns the type of the function specified.
wasmtime_error_t * wasmtime_global_new(wasmtime_context_t *store, const wasm_globaltype_t *type, const wasmtime_val_t *val, wasmtime_global_t *ret)
Creates a new global value.
wasmtime_error_t * wasmtime_global_set(wasmtime_context_t *store, const wasmtime_global_t *global, const wasmtime_val_t *val)
Sets a global to a new value.
wasm_globaltype_t * wasmtime_global_type(const wasmtime_context_t *store, const wasmtime_global_t *global)
Returns the wasm type of the specified global.
void wasmtime_global_get(wasmtime_context_t *store, const wasmtime_global_t *global, wasmtime_val_t *out)
Get the value of the specified global.
bool wasmtime_instance_export_get(wasmtime_context_t *store, const wasmtime_instance_t *instance, const char *name, size_t name_len, wasmtime_extern_t *item)
Get an export by name from an instance.
bool wasmtime_instance_export_nth(wasmtime_context_t *store, const wasmtime_instance_t *instance, size_t index, char **name, size_t *name_len, wasmtime_extern_t *item)
Get an export by index from an instance.
wasmtime_error_t * wasmtime_instance_new(wasmtime_context_t *store, const wasmtime_module_t *module, const wasmtime_extern_t *imports, size_t nimports, wasmtime_instance_t *instance, wasm_trap_t **trap)
Instantiate a wasm module.
wasmtime_linker_t * wasmtime_linker_new(wasm_engine_t *engine)
Creates a new linker for the specified engine.
bool wasmtime_linker_get(const wasmtime_linker_t *linker, wasmtime_context_t *store, const char *module, size_t module_len, const char *name, size_t name_len, wasmtime_extern_t *item)
Loads an item by name from this linker.
wasmtime_error_t * wasmtime_linker_define_func_unchecked(wasmtime_linker_t *linker, const char *module, size_t module_len, const char *name, size_t name_len, const wasm_functype_t *ty, wasmtime_func_unchecked_callback_t cb, void *data, void(*finalizer)(void *))
Defines a new function in this linker.
wasmtime_error_t * wasmtime_linker_get_default(const wasmtime_linker_t *linker, wasmtime_context_t *store, const char *name, size_t name_len, wasmtime_func_t *func)
Acquires the "default export" of the named module in this linker.
wasmtime_error_t * wasmtime_linker_define_wasi(wasmtime_linker_t *linker)
Defines WASI functions in this linker.
wasmtime_error_t * wasmtime_linker_define(wasmtime_linker_t *linker, wasmtime_context_t *store, const char *module, size_t module_len, const char *name, size_t name_len, const wasmtime_extern_t *item)
Defines a new item in this linker.
void wasmtime_linker_allow_shadowing(wasmtime_linker_t *linker, bool allow_shadowing)
Configures whether this linker allows later definitions to shadow previous definitions.
wasmtime_error_t * wasmtime_linker_module(wasmtime_linker_t *linker, wasmtime_context_t *store, const char *name, size_t name_len, const wasmtime_module_t *module)
Defines automatic instantiations of a wasm_module_t in this linker.
wasmtime_error_t * wasmtime_linker_define_instance(wasmtime_linker_t *linker, wasmtime_context_t *store, const char *name, size_t name_len, const wasmtime_instance_t *instance)
Defines an instance under the specified name in this linker.
void wasmtime_linker_delete(wasmtime_linker_t *linker)
Deletes a linker.
wasmtime_error_t * wasmtime_linker_define_func(wasmtime_linker_t *linker, const char *module, size_t module_len, const char *name, size_t name_len, const wasm_functype_t *ty, wasmtime_func_callback_t cb, void *data, void(*finalizer)(void *))
Defines a new function in this linker.
wasmtime_error_t * wasmtime_linker_instantiate(const wasmtime_linker_t *linker, wasmtime_context_t *store, const wasmtime_module_t *module, wasmtime_instance_t *instance, wasm_trap_t **trap)
Instantiates a wasm_module_t with the items defined in this linker.
uint8_t * wasmtime_memory_data(const wasmtime_context_t *store, const wasmtime_memory_t *memory)
Returns the base pointer in memory where the linear memory starts.
wasmtime_error_t * wasmtime_memory_grow(wasmtime_context_t *store, const wasmtime_memory_t *memory, uint64_t delta, uint64_t *prev_size)
Attempts to grow the specified memory by delta pages.
wasmtime_error_t * wasmtime_memory_new(wasmtime_context_t *store, const wasm_memorytype_t *ty, wasmtime_memory_t *ret)
Creates a new WebAssembly linear memory.
size_t wasmtime_memory_data_size(const wasmtime_context_t *store, const wasmtime_memory_t *memory)
Returns the byte length of this linear memory.
uint64_t wasmtime_memory_size(const wasmtime_context_t *store, const wasmtime_memory_t *memory)
Returns the length, in WebAssembly pages, of this linear memory.
wasm_memorytype_t * wasmtime_memory_type(const wasmtime_context_t *store, const wasmtime_memory_t *memory)
Returns the type of the memory specified.
Opaque struct representing a wasm trap.
Structure used to represent either a Trap or an Error.
Definition: trap.hh:162
Container for different kinds of extern items.
Definition: extern.h:133
wasmtime_extern_union_t of
Container for the extern item's value.
Definition: extern.h:137
wasmtime_extern_kind_t kind
Discriminant of which field of of is valid.
Definition: extern.h:135
A host-defined un-forgeable reference to pass into WebAssembly.
Definition: val.h:174
Representation of a function in Wasmtime.
Definition: extern.h:25
uint64_t store_id
Definition: extern.h:31
Representation of a global in Wasmtime.
Definition: extern.h:71
Representation of a instance in Wasmtime.
Definition: instance.h:26
Object used to conveniently link together and instantiate wasm modules.
Representation of a memory in Wasmtime.
Definition: extern.h:57
Representation of a table in Wasmtime.
Definition: extern.h:43
Container for different kinds of wasm values.
Definition: val.h:441
wasmtime_valkind_t kind
Discriminant of which field of of is valid.
Definition: val.h:443
wasmtime_valunion_t of
Container for the extern item's value.
Definition: val.h:445
wasm_tabletype_t * wasmtime_table_type(const wasmtime_context_t *store, const wasmtime_table_t *table)
Returns the type of this table.
wasmtime_error_t * wasmtime_table_set(wasmtime_context_t *store, const wasmtime_table_t *table, uint64_t index, const wasmtime_val_t *value)
Sets a value in a table.
wasmtime_error_t * wasmtime_table_new(wasmtime_context_t *store, const wasm_tabletype_t *ty, const wasmtime_val_t *init, wasmtime_table_t *table)
Creates a new host-defined wasm table.
bool wasmtime_table_get(wasmtime_context_t *store, const wasmtime_table_t *table, uint64_t index, wasmtime_val_t *val)
Gets a value in a table.
wasmtime_error_t * wasmtime_table_grow(wasmtime_context_t *store, const wasmtime_table_t *table, uint64_t delta, const wasmtime_val_t *init, uint64_t *prev_size)
Grows a table.
uint64_t wasmtime_table_size(const wasmtime_context_t *store, const wasmtime_table_t *table)
Returns the size, in elements, of the specified table.
ValKind
Different kinds of types accepted by Wasmtime.
Definition: types/val.hh:16
@ V128
WebAssembly's v128 type from the simd proposal.
wasmtime_memory_t memory
Field used if wasmtime_extern_t::kind is WASMTIME_EXTERN_MEMORY.
Definition: extern.h:115
wasmtime_func_t func
Field used if wasmtime_extern_t::kind is WASMTIME_EXTERN_FUNC.
Definition: extern.h:109
wasmtime_global_t global
Field used if wasmtime_extern_t::kind is WASMTIME_EXTERN_GLOBAL.
Definition: extern.h:111
wasmtime_table_t table
Field used if wasmtime_extern_t::kind is WASMTIME_EXTERN_TABLE.
Definition: extern.h:113
Container for possible wasm values.
Definition: val.h:372
uint32_t externref
Definition: val.h:408
wasmtime_v128 v128
Definition: val.h:392
void * funcref
Definition: val.h:415
wasmtime_func_t funcref
Definition: val.h:336
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.
union wasmtime_val_raw wasmtime_val_raw_t
Convenience alias for wasmtime_val_raw.
uint8_t wasmtime_v128[16]
A 128-bit value representing the WebAssembly v128 type. Bytes are stored in little-endian order.
Definition: val.h:307
void wasmtime_externref_from_raw(wasmtime_context_t *context, uint32_t raw, wasmtime_externref_t *out)
Converts a raw externref value coming from wasmtime_val_raw_t into a wasmtime_externref_t.
#define WASMTIME_FUNCREF
Value of wasmtime_valkind_t meaning that wasmtime_val_t is a funcref.
Definition: val.h:297
#define NATIVE_WASM_TYPE(native, valkind, field)
Definition: wasmtime.hh:108
std::variant< Func, Global, Memory, Table > Extern
Representation of an external WebAssembly item.
Definition: wasmtime.hh:67