From e0a8f40f65b178556f6fcbed778923a36dca64e3 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Tue, 15 Jun 2021 00:07:55 -0400 Subject: Parsing and emitting nominal types (#3933) Adds a `--nominal` option to switch the type machinery from equirecursive to nominal. Implements binary and text parsing and emitting of nominal types using new type constructor opcodes and an `(extends $super)` text syntax extension. When not in nominal mode, these extensions will still be parsed but will not have any effect and will not be used when emitting. --- src/passes/Print.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 47db029ab..dbe4f2557 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2496,7 +2496,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor { } o << ')'; } - void handleHeapType(HeapType type) { + void handleHeapType(HeapType type, Module* module) { if (type.isSignature()) { handleSignature(type.getSignature()); } else if (type.isArray()) { @@ -2506,6 +2506,12 @@ struct PrintSExpression : public UnifiedExpressionVisitor { } else { o << type; } + HeapType super; + if (type.getSuperType(super)) { + o << " (extends "; + TypeNamePrinter(o, module).print(super); + o << ')'; + } } void visitExport(Export* curr) { o << '('; @@ -2889,7 +2895,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor { printMedium(o, "type") << ' '; TypeNamePrinter(o, curr).print(type); o << ' '; - handleHeapType(type); + handleHeapType(type, curr); o << ")" << maybeNewLine; } ModuleUtils::iterImportedMemories( -- cgit v1.2.3