From 02e5b160a1625ca8e2bf24bff9b4e06d012cf417 Mon Sep 17 00:00:00 2001 From: Frank Emrich Date: Wed, 25 Oct 2023 00:16:12 +0100 Subject: 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. --- src/parser/parsers.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/parser/parsers.h') 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 functype(Ctx& ctx) { return ctx.makeFuncType(parsedParams.getPtr(), parsedResults.getPtr()); } +// conttype ::= '(' 'cont' x:typeidx ')' => cont x +template +MaybeResult 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 Result storagetype(Ctx& ctx) { @@ -1650,6 +1667,7 @@ Result> inlineExports(ParseInput& in) { } // strtype ::= ft:functype => ft +// | ct:conttype => ct // | st:structtype => st // | at:arraytype => at template Result<> strtype(Ctx& ctx) { @@ -1658,6 +1676,11 @@ template 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); -- cgit v1.2.3