| 125 | // ── Type section ────────────────────────────────────────────────────────────── |
| 126 | |
| 127 | void ParseContext::parse_typesection() { |
| 128 | tok_.expect(TokenType::LParen); |
| 129 | tok_.expect_keyword("type"); |
| 130 | // optional Id |
| 131 | if (tok_.peek().type == TokenType::Id) { |
| 132 | std::string id = tok_.consume().text; |
| 133 | if (type_map_.contains(id)) |
| 134 | throw Exception::Parse("duplicated type id '" + id + "'", tok_.location()); |
| 135 | type_map_[id] = types_.size(); |
| 136 | } |
| 137 | types_.emplace_back(parse_functype()); |
| 138 | tok_.expect(TokenType::RParen); |
| 139 | } |
| 140 | |
| 141 | // ── Valtype / FuncType / type sub-parsers ───────────────────────────────────── |
| 142 | |