summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/literal.cpp18
-rw-r--r--src/wasm/wasm-interpreter.cpp3
-rw-r--r--src/wasm/wasm-type.cpp2
3 files changed, 21 insertions, 2 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);
diff --git a/src/wasm/wasm-interpreter.cpp b/src/wasm/wasm-interpreter.cpp
index b49eeef4b..cd6c232b5 100644
--- a/src/wasm/wasm-interpreter.cpp
+++ b/src/wasm/wasm-interpreter.cpp
@@ -20,7 +20,8 @@ void Indenter::print() {
#endif // WASM_INTERPRETER_DEBUG
std::ostream& operator<<(std::ostream& o, const WasmException& exn) {
- return o << exn.tag << " " << exn.values;
+ auto exnData = exn.exn.getExnData();
+ return o << exnData->tag << " " << exnData->payload;
}
} // namespace wasm
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index 84ae51521..1730f1b85 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -814,6 +814,8 @@ bool Type::isStruct() const { return isRef() && getHeapType().isStruct(); }
bool Type::isArray() const { return isRef() && getHeapType().isArray(); }
+bool Type::isExn() const { return isRef() && getHeapType().isExn(); }
+
bool Type::isString() const { return isRef() && getHeapType().isString(); }
bool Type::isDefaultable() const {