diff options
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r-- | src/wasm/literal.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 9d659f753..650318be3 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -80,6 +80,12 @@ Literal::Literal(std::shared_ptr<GCData> gcData, HeapType type) (type.isBottom() && !gcData)); } +Literal::Literal(std::shared_ptr<ExnData> exnData) + : exnData(exnData), type(HeapType::exn, NonNullable) { + // The data must not be null. + assert(exnData); +} + Literal::Literal(std::string_view string) : gcData(nullptr), type(Type(HeapType::string, NonNullable)) { // TODO: we could in theory internalize strings @@ -133,6 +139,9 @@ Literal::Literal(const Literal& other) : type(other.type) { case HeapType::i31: i32 = other.i32; return; + case HeapType::exn: + new (&exnData) std::shared_ptr<ExnData>(other.exnData); + return; case HeapType::ext: WASM_UNREACHABLE("handled above with isData()"); case HeapType::none: @@ -147,7 +156,6 @@ Literal::Literal(const Literal& other) : type(other.type) { case HeapType::cont: case HeapType::struct_: case HeapType::array: - case HeapType::exn: WASM_UNREACHABLE("invalid type"); case HeapType::string: WASM_UNREACHABLE("TODO: string literals"); @@ -161,6 +169,8 @@ Literal::~Literal() { } if (isNull() || isData() || type.getHeapType().isMaybeShared(HeapType::ext)) { gcData.~shared_ptr(); + } else if (isExn()) { + exnData.~shared_ptr(); } } @@ -328,6 +338,12 @@ std::shared_ptr<GCData> Literal::getGCData() const { return gcData; } +std::shared_ptr<ExnData> Literal::getExnData() const { + assert(isExn()); + assert(exnData); + return exnData; +} + Literal Literal::castToF32() { assert(type == Type::i32); Literal ret(Type::f32); |