@@ -44,6 +44,8 @@ template<typename Ctx> Result<typename Ctx::MemTypeT> memtype(Ctx&);
4444template <typename Ctx>
4545Result<typename Ctx::MemTypeT> memtypeContinued (Ctx&, Type indexType);
4646template <typename Ctx> Result<typename Ctx::TableTypeT> tabletype (Ctx&);
47+ template <typename Ctx>
48+ Result<typename Ctx::TableTypeT> tabletypeContinued (Ctx&, Type indexType);
4749template <typename Ctx> Result<typename Ctx::GlobalTypeT> globaltype (Ctx&);
4850template <typename Ctx> Result<uint32_t > tupleArity (Ctx&);
4951
@@ -815,16 +817,28 @@ Result<typename Ctx::MemTypeT> memtypeContinued(Ctx& ctx, Type indexType) {
815817 return ctx.makeMemType (indexType, *limits, shared);
816818}
817819
818- // tabletype ::= limits32 reftype
820+ // tabletype ::= ( limits32 | 'i32' limits32 | 'i64' limit64) reftype
819821template <typename Ctx> Result<typename Ctx::TableTypeT> tabletype (Ctx& ctx) {
820- auto limits = limits32 (ctx);
822+ Type indexType = Type::i32 ;
823+ if (ctx.in .takeKeyword (" i64" sv)) {
824+ indexType = Type::i64 ;
825+ } else {
826+ ctx.in .takeKeyword (" i32" sv);
827+ }
828+ return tabletypeContinued (ctx, indexType);
829+ }
830+
831+ template <typename Ctx>
832+ Result<typename Ctx::TableTypeT> tabletypeContinued (Ctx& ctx, Type indexType) {
833+ auto limits = indexType == Type::i32 ? limits32 (ctx) : limits64 (ctx);
821834 CHECK_ERR (limits);
822835 auto type = reftype (ctx);
823836 CHECK_ERR (type);
837+
824838 if (!type) {
825839 return ctx.in .err (" expected reftype" );
826840 }
827- return ctx.makeTableType (*limits, *type);
841+ return ctx.makeTableType (indexType, *limits, *type);
828842}
829843
830844// globaltype ::= t:valtype => const t
@@ -3049,8 +3063,8 @@ template<typename Ctx> MaybeResult<> func(Ctx& ctx) {
30493063}
30503064
30513065// table ::= '(' 'table' id? ('(' 'export' name ')')*
3052- // '(' 'import' mod:name nm:name ')'? tabletype ')'
3053- // | '(' 'table' id? ('(' 'export' name ')')*
3066+ // '(' 'import' mod:name nm:name ')'? index_type? tabletype ')'
3067+ // | '(' 'table' id? ('(' 'export' name ')')* index_type?
30543068// reftype '(' 'elem' (elemexpr* | funcidx*) ')' ')'
30553069template <typename Ctx> MaybeResult<> table (Ctx& ctx) {
30563070 auto pos = ctx.in .getPos ();
@@ -3069,6 +3083,13 @@ template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
30693083 auto import = inlineImport (ctx.in );
30703084 CHECK_ERR (import );
30713085
3086+ auto indexType = Type::i32 ;
3087+ if (ctx.in .takeKeyword (" i64" sv)) {
3088+ indexType = Type::i64 ;
3089+ } else {
3090+ ctx.in .takeKeyword (" i32" sv);
3091+ }
3092+
30723093 // Reftype if we have inline elements.
30733094 auto type = reftype (ctx);
30743095 CHECK_ERR (type);
@@ -3103,10 +3124,10 @@ template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
31033124 if (!ctx.in .takeRParen ()) {
31043125 return ctx.in .err (" expected end of inline elems" );
31053126 }
3106- ttype = ctx.makeTableType (ctx.getLimitsFromElems (list), *type);
3127+ ttype = ctx.makeTableType (indexType, ctx.getLimitsFromElems (list), *type);
31073128 elems = std::move (list);
31083129 } else {
3109- auto tabtype = tabletype (ctx);
3130+ auto tabtype = tabletypeContinued (ctx, indexType );
31103131 CHECK_ERR (tabtype);
31113132 ttype = *tabtype;
31123133 }
@@ -3124,10 +3145,10 @@ template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
31243145 return Ok{};
31253146}
31263147
3127- // mem ::= '(' 'memory' id? ('(' 'export' name ')')* index_type?
3128- // ('(' 'data' b:datastring ')' | memtype) ')'
3129- // | '(' 'memory' id? ('(' 'export' name ')')*
3130- // '(' 'import' mod:name nm:name ')' memtype ')'
3148+ // memory ::= '(' 'memory' id? ('(' 'export' name ')')* index_type?
3149+ // ('(' 'data' b:datastring ')' | memtype) ')'
3150+ // | '(' 'memory' id? ('(' 'export' name ')')*
3151+ // '(' 'import' mod:name nm:name ')' index_type? memtype ')'
31313152template <typename Ctx> MaybeResult<> memory (Ctx& ctx) {
31323153 auto pos = ctx.in .getPos ();
31333154 if (!ctx.in .takeSExprStart (" memory" sv)) {
0 commit comments