summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/contexts.h3
-rw-r--r--src/parser/parsers.h36
2 files changed, 29 insertions, 10 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h
index bce051a93..7c1a07b53 100644
--- a/src/parser/contexts.h
+++ b/src/parser/contexts.h
@@ -907,6 +907,7 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
void addStructType(StructT) {}
void addArrayType(ArrayT) {}
void setOpen() {}
+ void setShared() {}
Result<> addSubtype(Index) { return Ok{}; }
void finishSubtype(Name name, Index pos) {
// TODO: type annotations
@@ -1077,6 +1078,8 @@ struct ParseTypeDefsCtx : TypeParserCtx<ParseTypeDefsCtx> {
void setOpen() { builder[index].setOpen(); }
+ void setShared() { builder[index].setShared(); }
+
Result<> addSubtype(Index super) {
if (super >= builder.size()) {
return in.err("supertype index out of bounds");
diff --git a/src/parser/parsers.h b/src/parser/parsers.h
index c4eaf5fc6..a3fe5e5eb 100644
--- a/src/parser/parsers.h
+++ b/src/parser/parsers.h
@@ -331,7 +331,8 @@ template<typename Ctx>
Result<typename Ctx::TypeUseT> typeuse(Ctx&, bool allowNames = true);
MaybeResult<ImportNames> inlineImport(Lexer&);
Result<std::vector<Name>> inlineExports(Lexer&);
-template<typename Ctx> Result<> strtype(Ctx&);
+template<typename Ctx> Result<> comptype(Ctx&);
+template<typename Ctx> Result<> sharecomptype(Ctx&);
template<typename Ctx> MaybeResult<typename Ctx::ModuleNameT> subtype(Ctx&);
template<typename Ctx> MaybeResult<> deftype(Ctx&);
template<typename Ctx> MaybeResult<typename Ctx::LocalsT> locals(Ctx&);
@@ -2709,11 +2710,11 @@ inline Result<std::vector<Name>> inlineExports(Lexer& in) {
return exports;
}
-// strtype ::= ft:functype => ft
-// | ct:conttype => ct
-// | st:structtype => st
-// | at:arraytype => at
-template<typename Ctx> Result<> strtype(Ctx& ctx) {
+// comptype ::= ft:functype => ft
+// | ct:conttype => ct
+// | st:structtype => st
+// | at:arraytype => at
+template<typename Ctx> Result<> comptype(Ctx& ctx) {
if (auto type = functype(ctx)) {
CHECK_ERR(type);
ctx.addFuncType(*type);
@@ -2737,8 +2738,23 @@ template<typename Ctx> Result<> strtype(Ctx& ctx) {
return ctx.in.err("expected type description");
}
-// subtype ::= '(' 'type' id? '(' 'sub' typeidx? strtype ')' ')'
-// | '(' 'type' id? strtype ')'
+// sharecomptype ::= '(' 'shared' t:comptype ')' => shared t
+// | t:comptype => unshared t
+template<typename Ctx> Result<> sharecomptype(Ctx& ctx) {
+ if (ctx.in.takeSExprStart("shared"sv)) {
+ ctx.setShared();
+ CHECK_ERR(comptype(ctx));
+ if (!ctx.in.takeRParen()) {
+ return ctx.in.err("expected end of shared comptype");
+ }
+ } else {
+ CHECK_ERR(comptype(ctx));
+ }
+ return Ok{};
+}
+
+// subtype ::= '(' 'type' id? '(' 'sub' typeidx? sharecomptype ')' ')'
+// | '(' 'type' id? sharecomptype ')'
template<typename Ctx> MaybeResult<> subtype(Ctx& ctx) {
auto pos = ctx.in.getPos();
@@ -2760,13 +2776,13 @@ template<typename Ctx> MaybeResult<> subtype(Ctx& ctx) {
CHECK_ERR(ctx.addSubtype(*super));
}
- CHECK_ERR(strtype(ctx));
+ CHECK_ERR(sharecomptype(ctx));
if (!ctx.in.takeRParen()) {
return ctx.in.err("expected end of subtype definition");
}
} else {
- CHECK_ERR(strtype(ctx));
+ CHECK_ERR(sharecomptype(ctx));
}
if (!ctx.in.takeRParen()) {