diff options
author | Thomas Lively <tlively@google.com> | 2024-01-26 10:33:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-26 10:33:40 -0800 |
commit | 5d297dca547fdca2d525f251a27d0a94fc2c2674 (patch) | |
tree | de2eaa163260754ec94265d50a45dcb5e9661d32 /src | |
parent | d23a63fce8635aa6e401d016a5d0bf23f6f030e8 (diff) | |
download | binaryen-5d297dca547fdca2d525f251a27d0a94fc2c2674.tar.gz binaryen-5d297dca547fdca2d525f251a27d0a94fc2c2674.tar.bz2 binaryen-5d297dca547fdca2d525f251a27d0a94fc2c2674.zip |
Update the text syntax for tuple types (#6246)
Instead of e.g. `(i32 i32)`, use `(tuple i32 i32)`. Having a keyword to
introduce the s-expression is more consistent with the rest of the language.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared-constants.h | 1 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 13 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 6 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 1 |
4 files changed, 12 insertions, 9 deletions
diff --git a/src/shared-constants.h b/src/shared-constants.h index 321ec3884..528d09df5 100644 --- a/src/shared-constants.h +++ b/src/shared-constants.h @@ -62,6 +62,7 @@ extern Name PRINT; extern Name EXIT; extern Name SHARED; extern Name TAG; +extern Name TUPLE; } // namespace wasm diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index cc8fe2273..af042bd55 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -1393,12 +1393,15 @@ Type SExpressionWasmBuilder::elementToType(Element& s) { } return Type(parseHeapType(*s[i]), nullable); } - // It's a tuple. - std::vector<Type> types; - for (size_t i = 0; i < s.size(); ++i) { - types.push_back(elementToType(*list[i])); + if (elementStartsWith(s, TUPLE)) { + // It's a tuple. + std::vector<Type> types; + for (size_t i = 1; i < s.size(); ++i) { + types.push_back(elementToType(*list[i])); + } + return Type(types); } - return Type(types); + throw SParseException(std::string("expected type, got list"), s); } Type SExpressionWasmBuilder::stringToLaneType(const char* str) { diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 97a8cba0e..f1ceca51a 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -1952,11 +1952,9 @@ std::ostream& TypePrinter::print(HeapType type) { } std::ostream& TypePrinter::print(const Tuple& tuple) { - os << '('; - auto sep = ""; + os << "(tuple"; for (Type type : tuple) { - os << sep; - sep = " "; + os << ' '; print(type); } return os << ')'; diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 06e9de148..4785b22ab 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -99,6 +99,7 @@ Name PRINT("print"); Name EXIT("exit"); Name SHARED("shared"); Name TAG("tag"); +Name TUPLE("tuple"); // Expressions |