Wasmtime
tag.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_TYPES_TAG_HH
6#define WASMTIME_TYPES_TAG_HH
7
8#include <memory>
9#include <wasmtime/engine.hh>
10#include <wasmtime/tag.h>
12
13namespace wasmtime {
14
21class TagType {
22 struct deleter {
23 void operator()(wasmtime_tagtype_t *p) const { wasmtime_tagtype_delete(p); }
24 };
25
26 std::unique_ptr<wasmtime_tagtype_t, deleter> ptr;
27
28public:
31 class Ref {
32 friend class TagType;
33 const wasmtime_tagtype_t *ptr;
34
35 public:
37 Ref(const wasmtime_tagtype_t *ptr) : ptr(ptr) {}
39 Ref(const TagType &ty) : Ref(ty.ptr.get()) {}
40
46 }
47 };
48
49private:
50 Ref ref;
51 TagType(wasmtime_tagtype_t *ptr) : ptr(ptr), ref(ptr) {}
52
53public:
55 TagType(Engine &engine, FuncType &functype)
56 : ptr(wasmtime_tagtype_new(engine.capi(), functype.ptr.get())),
57 ref(ptr.get()) {}
58
60 TagType(Ref other) : TagType(wasmtime_tagtype_copy(other.ptr)) {}
62 TagType(const TagType &other)
63 : TagType(wasmtime_tagtype_copy(other.ptr.get())) {}
65 TagType &operator=(const TagType &other) {
66 ptr.reset(wasmtime_tagtype_copy(other.ptr.get()));
67 ref = ptr.get();
68 return *this;
69 }
70 ~TagType() = default;
72 TagType(TagType &&other) = default;
74 TagType &operator=(TagType &&other) = default;
75
78 Ref *operator->() { return &ref; }
81 Ref *operator*() { return &ref; }
82};
83
84}; // namespace wasmtime
85
86#endif // WASMTIME_TYPES_TAG_HH
Global compilation state in Wasmtime.
Definition: engine.hh:22
Type information for a WebAssembly function.
Definition: types/func.hh:15
Definition: tag.hh:31
Ref(const wasmtime_tagtype_t *ptr)
Creates a reference from the raw underlying C API representation.
Definition: tag.hh:37
Ref(const TagType &ty)
Creates a reference to the provided TagType.
Definition: tag.hh:39
FuncType functype() const
Definition: tag.hh:44
Type information for a WebAssembly exception tag.
Definition: tag.hh:21
TagType & operator=(TagType &&other)=default
Moves the tag type resources from another type to this one.
TagType(Engine &engine, FuncType &functype)
Creates a new tag type from the given function type and engine.
Definition: tag.hh:55
TagType & operator=(const TagType &other)
Copies another tag type into this one.
Definition: tag.hh:65
Ref * operator*()
Returns the underlying Ref, a non-owning reference pointing to this instance.
Definition: tag.hh:81
TagType(TagType &&other)=default
Moves the tag type resources from another type to this one.
TagType(const TagType &other)
Copies another tag type into this one.
Definition: tag.hh:62
TagType(Ref other)
Copies a reference into a uniquely owned tag type.
Definition: tag.hh:60
Ref * operator->()
Returns the underlying Ref, a non-owning reference pointing to this instance.
Definition: tag.hh:78
Wasmtime APIs for WebAssembly exception tag types.
WASM_API_EXTERN wasm_functype_t * wasmtime_tagtype_functype(const wasmtime_tagtype_t *)
Returns the function type describing this tag's exception payload.
WASM_API_EXTERN wasmtime_tagtype_t * wasmtime_tagtype_new(wasm_engine_t *engine, const wasm_functype_t *functype)
Creates a new tag type from the given function type.
WASM_API_EXTERN void wasmtime_tagtype_delete(wasmtime_tagtype_t *)
Deletes a wasmtime_tagtype_t.
struct wasmtime_tagtype_t wasmtime_tagtype_t
Opaque type representing a WebAssembly exception tag type.
Definition: tag.h:29
WASM_API_EXTERN wasmtime_tagtype_t * wasmtime_tagtype_copy(const wasmtime_tagtype_t *)
Returns a copy of the given wasmtime_tagtype_t (caller owns the result).