Skip to content

Commit

Permalink
interp: handle ref.null exn
Browse files Browse the repository at this point in the history
  • Loading branch information
SoniEx2 committed Oct 29, 2024
1 parent 22b8252 commit a7805b0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/binary-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ bool BinaryReader::IsConcreteType(Type type) {
case Type::ExternRef:
return options_.features.reference_types_enabled();

case Type::ExnRef:
return options_.features.exceptions_enabled();

case Type::Reference:
return options_.features.function_references_enabled();

Expand Down
8 changes: 8 additions & 0 deletions src/binary-writer-spec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ void BinaryWriterSpec::WriteConst(const Const& const_) {
break;
}

case Type::ExnRef: {
WriteString("exnref");
WriteSeparator();
WriteKey("value");
WriteRefBits(const_.ref_bits());
break;
}

case Type::V128: {
WriteString("v128");
WriteSeparator();
Expand Down
5 changes: 5 additions & 0 deletions src/interp/interp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ bool Store::HasValueType(Ref ref, ValueType type) const {
case ValueType::FuncRef:
return obj->kind() == ObjectKind::DefinedFunc ||
obj->kind() == ObjectKind::HostFunc;
case ValueType::ExnRef:
return obj->kind() == ObjectKind::Exception;
default:
return false;
}
Expand Down Expand Up @@ -2733,8 +2735,11 @@ std::string Thread::TraceSource::Pick(Index index, Instr instr) {
v.u32(2), v.u32(3));
}

// clang-format off
case ValueType::FuncRef: reftype = "funcref"; break;
case ValueType::ExternRef: reftype = "externref"; break;
case ValueType::ExnRef: reftype = "exnref"; break;
// clang-format on

default:
WABT_UNREACHABLE;
Expand Down
17 changes: 17 additions & 0 deletions src/tools/spectest-interp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ wabt::Result JSONParser::ParseType(Type* out_type) {
*out_type = Type::FuncRef;
} else if (type_str == "externref") {
*out_type = Type::ExternRef;
} else if (type_str == "exnref") {
*out_type = Type::ExnRef;
} else {
PrintError("unknown type: \"%s\"", type_str.c_str());
return wabt::Result::Error;
Expand Down Expand Up @@ -863,6 +865,16 @@ wabt::Result JSONParser::ParseConstValue(Type type,
}
break;

case Type::ExnRef:
if (value_str == "null") {
out_value->Set(Ref::Null);
} else {
// FIXME?
PrintError("NYI");
return wabt::Result::Error;
}
break;

default:
PrintError("unknown concrete type: \"%s\"", type.GetName().c_str());
return wabt::Result::Error;
Expand Down Expand Up @@ -1914,6 +1926,11 @@ wabt::Result CommandRunner::CheckAssertReturnResult(
ok = expected.value.value.Get<Ref>() == actual.value.Get<Ref>();
break;

case Type::ExnRef:
// FIXME is this correct?
ok = (actual.type == Type::ExnRef);
break;

default:
WABT_UNREACHABLE;
}
Expand Down
6 changes: 5 additions & 1 deletion src/wast-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ bool WastParser::PeekMatchExpr() {
}

bool WastParser::PeekMatchRefType() {
return options_->features.function_references_enabled() &&
return (options_->features.function_references_enabled() ||
options_->features.exceptions_enabled()) &&
PeekMatchLpar(TokenType::Ref);
}

Expand Down Expand Up @@ -934,6 +935,9 @@ Result WastParser::ParseValueType(Var* out_type) {
case Type::ExternRef:
is_enabled = options_->features.reference_types_enabled();
break;
case Type::ExnRef:
is_enabled = options_->features.exceptions_enabled();
break;
default:
is_enabled = true;
break;
Expand Down
6 changes: 6 additions & 0 deletions test/spec/exception-handling/ref_null.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-interp-spec
;;; STDIN_FILE: third_party/testsuite/proposals/exception-handling/ref_null.wast
;;; ARGS*: --enable-exceptions
(;; STDOUT ;;;
4/4 tests passed.
;;; STDOUT ;;)

0 comments on commit a7805b0

Please sign in to comment.