const Store = @import("./store.zig").Store; const FuncType = @import("./func.zig").FuncType; const MemoryType = @import("./memory.zig").MemoryType; // Re-exported for convenience (for now). pub const Func = @import("./func.zig").Func; pub const Memory = @import("./memory.zig").Memory; /// Representation of a table in Wasmtime. pub const Table = extern struct { store_id: u64, index: usize, }; /// Representation of a global in Wasmtime. pub const Global = extern struct { store_id: u64, index: usize, }; pub const ExternKind = enum(u8) { func = 0, global = 1, table = 2, memory = 3, }; /// Container for different kinds of extern items. /// /// Note that this structure may contain an owned value, namely `Module`, /// depending on the context in which this is used. APIs which consume an /// `Extern` do not take ownership, but APIs that return `Extern` require that /// `deinit` is called to deallocate the value. pub const Extern = extern struct { kind: ExternKind, of: extern union { func: Func, global: Global, table: Table, memory: Memory, }, pub fn deinit(self: *Extern) void { wasmtime_extern_delete(self); } pub fn getType(self: *const Extern, context: *const Store.Context) *ExternType { return wasmtime_extern_type(context, self); } pub fn fromFunc(func: Func) Extern { return .{ .kind = .func, .of = .{ .func = func } }; } pub fn asFunc(self: Extern) ?Func { return if (self.kind == .func) self.of.func else null; } pub fn fromMemory(memory: Memory) Extern { return .{ .kind = .memory, .of = .{ .memory = memory } }; } pub fn asMemory(self: Extern) ?Memory { return if (self.kind == .memory) self.of.memory else null; } extern "c" fn wasmtime_extern_delete(*Extern) void; extern "c" fn wasmtime_extern_type(*const Store.Context, *const Extern) *ExternType; }; // pub const ExternVec = Vec(*Extern, wasm_extern_vec_new_empty, wasm_extern_vec_new_uninitialized, wasm_extern_vec_new, wasm_extern_vec_copy, wasm_extern_vec_delete); // extern "c" fn wasm_extern_vec_new_empty(*anyopaque, usize) void; // extern "c" fn wasm_extern_vec_new_uninitialized(*anyopaque, usize) void; // extern "c" fn wasm_extern_vec_new(*anyopaque, usize, [*]const ?*Extern) void; // extern "c" fn wasm_extern_vec_copy(*anyopaque, *const anyopaque) void; // extern "c" fn wasm_extern_vec_delete(*anyopaque) void; pub const ExternType = opaque { pub fn copy(self: *const ExternType) *ExternType { return wasm_externtype_copy(self); } pub fn deinit(self: *ExternType) void { wasm_externtype_delete(self); } pub fn getKind(self: *const ExternType) ExternKind { return wasm_externtype_kind(self); } pub fn fromFuncType(func: *FuncType) *ExternType { return wasm_functype_as_externtype(func); } pub fn asFuncType(self: *ExternType) ?*FuncType { return wasm_externtype_as_functype(self); } pub fn fromMemoryType(func: *MemoryType) *ExternType { return wasm_memorytype_as_externtype(func); } pub fn asMemoryType(self: *ExternType) ?*MemoryType { return wasm_externtype_as_memorytype(self); } extern "c" fn wasm_externtype_copy(*const ExternType) *ExternType; extern "c" fn wasm_externtype_delete(*ExternType) void; extern "c" fn wasm_externtype_kind(*const ExternType) ExternKind; extern "c" fn wasm_functype_as_externtype(*FuncType) *ExternType; // extern "c" fn wasm_tabletype_as_externtype(*TableType) *ExternType; // extern "c" fn wasm_globaltype_as_externtype(*GlobalType) *ExternType; extern "c" fn wasm_memorytype_as_externtype(*MemoryType) *ExternType; extern "c" fn wasm_functype_as_externtype_const(*const FuncType) *const ExternType; // extern "c" fn wasm_tabletype_as_externtype_const(*const TableType) *const ExternType; // extern "c" fn wasm_globaltype_as_externtype_const(*const GlobalType) *const ExternType; extern "c" fn wasm_memorytype_as_externtype_const(*const MemoryType) *const ExternType; extern "c" fn wasm_externtype_as_functype(*ExternType) ?*FuncType; // extern "c" fn wasm_externtype_as_tabletype(*ExternType) ?*TableType; // extern "c" fn wasm_externtype_as_globaltype(*ExternType) ?*GlobalType; extern "c" fn wasm_externtype_as_memorytype(*ExternType) ?*MemoryType; extern "c" fn wasm_externtype_as_functype_const(*const ExternType) ?*const FuncType; // extern "c" fn wasm_externtype_as_tabletype_const(*const ExternType) ?*const TableType; // extern "c" fn wasm_externtype_as_globaltype_const(*const ExternType) ?*const GlobalType; extern "c" fn wasm_externtype_as_memorytype_const(*const ExternType) ?*const MemoryType; }; // pub const ExternTypeVec = Vec(*ExternType, wasm_externtype_vec_new_empty, wasm_externtype_vec_new_uninitialized, wasm_externtype_vec_new, wasm_externtype_vec_copy, wasm_externtype_vec_delete); // extern "c" fn wasm_externtype_vec_new_empty(*anyopaque, usize) void; // extern "c" fn wasm_externtype_vec_new_uninitialized(*anyopaque, usize) void; // extern "c" fn wasm_externtype_vec_new(*anyopaque, usize, [*]const ?*ExternType) void; // extern "c" fn wasm_externtype_vec_copy(*anyopaque, *const anyopaque) void; // extern "c" fn wasm_externtype_vec_delete(*anyopaque) void;