summaryrefslogtreecommitdiff
path: root/src/parser/parsers.h
diff options
context:
space:
mode:
authorFrank Emrich <git@emrich.io>2023-10-25 00:16:12 +0100
committerGitHub <noreply@github.com>2023-10-24 16:16:12 -0700
commit02e5b160a1625ca8e2bf24bff9b4e06d012cf417 (patch)
tree0763490e387856d2cc62eb9a93d3a8d01996b3ec /src/parser/parsers.h
parentec8220f4aa556ce39145db13eddd84855b11f76c (diff)
downloadbinaryen-02e5b160a1625ca8e2bf24bff9b4e06d012cf417.tar.gz
binaryen-02e5b160a1625ca8e2bf24bff9b4e06d012cf417.tar.bz2
binaryen-02e5b160a1625ca8e2bf24bff9b4e06d012cf417.zip
Typed Continuations: Add cont type (#5998)
This PR is part of a series that adds basic support for the [typed continuations proposal](https://github.com/wasmfx/specfx). This PR adds continuation types, of the form `(cont $foo)` for some function type `$foo`. The only notable changes affecting existing code are the following: - This is the first `HeapType` which has another `HeapType` (rather than, say, a `Type`) as its immediate child. This required fixes to certain traversals that have a flag for being at the toplevel of a type. - Some shared logic for parsing `HeapType`s has been factored out.
Diffstat (limited to 'src/parser/parsers.h')
-rw-r--r--src/parser/parsers.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/parser/parsers.h b/src/parser/parsers.h
index 32f6709df..65fd98a24 100644
--- a/src/parser/parsers.h
+++ b/src/parser/parsers.h
@@ -391,6 +391,23 @@ MaybeResult<typename Ctx::SignatureT> functype(Ctx& ctx) {
return ctx.makeFuncType(parsedParams.getPtr(), parsedResults.getPtr());
}
+// conttype ::= '(' 'cont' x:typeidx ')' => cont x
+template<typename Ctx>
+MaybeResult<typename Ctx::ContinuationT> conttype(Ctx& ctx) {
+ if (!ctx.in.takeSExprStart("cont"sv)) {
+ return {};
+ }
+
+ auto x = typeidx(ctx);
+ CHECK_ERR(x);
+
+ if (!ctx.in.takeRParen()) {
+ return ctx.in.err("expected end of cont type");
+ }
+
+ return ctx.makeContType(*x);
+}
+
// storagetype ::= valtype | packedtype
// packedtype ::= i8 | i16
template<typename Ctx> Result<typename Ctx::FieldT> storagetype(Ctx& ctx) {
@@ -1650,6 +1667,7 @@ Result<std::vector<Name>> inlineExports(ParseInput& in) {
}
// strtype ::= ft:functype => ft
+// | ct:conttype => ct
// | st:structtype => st
// | at:arraytype => at
template<typename Ctx> Result<> strtype(Ctx& ctx) {
@@ -1658,6 +1676,11 @@ template<typename Ctx> Result<> strtype(Ctx& ctx) {
ctx.addFuncType(*type);
return Ok{};
}
+ if (auto type = conttype(ctx)) {
+ CHECK_ERR(type);
+ ctx.addContType(*type);
+ return Ok{};
+ }
if (auto type = structtype(ctx)) {
CHECK_ERR(type);
ctx.addStructType(*type);