diff --git a/document/Makefile b/document/Makefile
index 875efc72..629d5f51 100644
--- a/document/Makefile
+++ b/document/Makefile
@@ -1,4 +1,4 @@
-DIRS = core js-api web-api
+DIRS = core js-api web-api legacy/exceptions
FILES = index.html
BUILDDIR = _build
diff --git a/document/index.html b/document/index.html
index 37eed976..79a2a0cf 100644
--- a/document/index.html
+++ b/document/index.html
@@ -49,19 +49,32 @@
Embedder specifications
JavaScript Embedding : defines JavaScript classes and objects for accessing WebAssembly from within JavaScript, including methods for validation, compilation, instantiation, and classes for representing and manipulating imports and exports as JavaScript objects.
Web Embedding : defines extensions to the JavaScript API made available specifically in web browsers, in particular, an interface for streaming compilation and instantiation from origin-bound Response
types.
+Legacy Extensions
+
+Define extensions that are deprecated, but may still be in use.
+
+
+
+
Source for these documents is available
here .
diff --git a/document/legacy/exceptions/.gitignore b/document/legacy/exceptions/.gitignore
new file mode 100644
index 00000000..b932ec28
--- /dev/null
+++ b/document/legacy/exceptions/.gitignore
@@ -0,0 +1,3 @@
+_build
+_static
+document/*.pyc
diff --git a/document/legacy/exceptions/LICENSE b/document/legacy/exceptions/LICENSE
new file mode 100644
index 00000000..795b406e
--- /dev/null
+++ b/document/legacy/exceptions/LICENSE
@@ -0,0 +1,50 @@
+W3C SOFTWARE AND DOCUMENT NOTICE AND LICENSE
+
+This work is being provided by the copyright holders under the following
+license.
+
+
+LICENSE
+
+By obtaining and/or copying this work, you (the licensee) agree that you have
+read, understood, and will comply with the following terms and conditions.
+
+Permission to copy, modify, and distribute this work, with or without
+modification, for any purpose and without fee or royalty is hereby granted,
+provided that you include the following on ALL copies of the work or portions
+thereof, including modifications:
+
+* The full text of this NOTICE in a location viewable to users of the
+ redistributed or derivative work.
+
+* Any pre-existing intellectual property disclaimers, notices, or terms and
+ conditions. If none exist, the W3C Software and Document Short Notice
+ (https://www.w3.org/Consortium/Legal/copyright-software-short-notice) should
+ be included.
+
+* Notice of any changes or modifications, through a copyright statement on the
+ new code or document such as "This software or document includes material
+ copied from or derived from [title and URI of the W3C document]. Copyright © [YEAR] W3C® (MIT, ERCIM, Keio, Beihang)."
+
+
+DISCLAIMERS
+
+THIS WORK IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS
+OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF
+MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE
+SOFTWARE OR DOCUMENT WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
+TRADEMARKS OR OTHER RIGHTS.
+
+COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENT.
+
+The name and trademarks of copyright holders may NOT be used in advertising or
+publicity pertaining to the work without specific, written prior permission.
+Title to copyright in this work will at all times remain with copyright
+holders.
+
+
+NOTES
+
+This version:
+http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
diff --git a/document/legacy/exceptions/Makefile b/document/legacy/exceptions/Makefile
new file mode 100644
index 00000000..56b9560a
--- /dev/null
+++ b/document/legacy/exceptions/Makefile
@@ -0,0 +1,358 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER = a4
+BUILDDIR = _build
+STATICDIR = _static
+DOWNLOADDIR = _download
+NAME = WebAssembly
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: usage
+usage:
+ @echo "Please use \`make ' where is one of"
+ @echo " html to make standalone HTML files"
+ @echo " pdf to make standalone PDF file"
+ @echo " bikeshed to make a bikeshed wrapped single large HTML file"
+ @echo " diff to make a diff of the bikeshed HTML file with the latest TR"
+ @echo " WD-tar generate tar file for updating the Working Draft"
+ @echo " WD-echidna publish the Working Draft tar file via Echidna"
+ @echo " all to make all 3"
+ @echo " publish to make all and push to gh-pages"
+ @echo " help to see more options"
+
+.PHONY: help
+help:
+ @echo "Usage: \`make ' where is one of"
+ @echo " html to make standalone HTML files"
+ @echo " pdf to make standalone PDF file"
+ @echo " bikeshed to make a bikeshed wrapped single large HTML file"
+ @echo " all to make all 3"
+ @echo " publish to make all and push to gh-pages"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " applehelp to make an Apple Help Book"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " epub3 to make an epub3"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " texinfo to make Texinfo files"
+ @echo " info to make Texinfo files and run them through makeinfo"
+ @echo " gettext to make PO message catalogs"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " xml to make Docutils-native XML files"
+ @echo " pseudoxml to make pseudoxml-XML files for display purposes"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+ @echo " coverage to run coverage check of the documentation (if enabled)"
+ @echo " dummy to check syntax errors of document sources"
+
+.PHONY: deploy
+deploy:
+ (cd ../..; make dir-core deploy-core)
+
+.PHONY: publish
+publish: clean all deploy
+
+.PHONY: publish-main
+publish-main: clean main bikeshed-keep deploy
+
+.PHONY: all
+all: pdf html bikeshed
+
+.PHONY: main
+main: pdf html
+
+# Dirty hack to avoid rebuilding the Bikeshed version for every push.
+.PHONY: bikeshed-keep
+bikeshed-keep:
+ test -e $(BUILDDIR)/html/bikeshed || \
+ wget -r -nH --cut-dirs=2 -P $(BUILDDIR)/html --no-check-certificate \
+ https://webassembly.github.io/spec/core/bikeshed || \
+ echo Downloaded Bikeshed.
+
+
+GENERATED = appendix/index-instructions.rst
+.INTERMEDIATE: $(GENERATED)
+
+%.rst: %.py
+ (cd `dirname $@`; ./`basename $^`)
+
+.PHONY: pdf
+pdf: $(GENERATED) latexpdf
+ mkdir -p $(BUILDDIR)/html/$(DOWNLOADDIR)
+ ln -f $(BUILDDIR)/latex/$(NAME).pdf $(BUILDDIR)/html/$(DOWNLOADDIR)/$(NAME).pdf
+
+
+.PHONY: clean
+clean:
+ rm -rf $(BUILDDIR)
+ rm -rf $(STATICDIR)
+ rm -f $(GENERATED)
+
+.PHONY: html
+html: $(GENERATED)
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ for file in `ls $(BUILDDIR)/html/*.html`; \
+ do \
+ sed s:BASEDIR:.:g <$$file >$$file.out; \
+ mv -f $$file.out $$file; \
+ done
+ for file in `ls $(BUILDDIR)/html/*/*.html`; \
+ do \
+ sed s:BASEDIR:..:g <$$file >$$file.out; \
+ mv -f $$file.out $$file; \
+ done
+ @echo
+ @echo "Build finished. The HTML pages are in `pwd`/$(BUILDDIR)/html/."
+
+.PHONY: dirhtml
+dirhtml: $(GENERATED)
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+.PHONY: singlehtml
+singlehtml: $(GENERATED)
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+.PHONY: bikeshed
+bikeshed: $(GENERATED)
+ $(SPHINXBUILD) -b singlehtml -c util/bikeshed \
+ $(ALLSPHINXOPTS) $(BUILDDIR)/bikeshed_singlehtml
+ python3 util/bikeshed_fixup.py $(BUILDDIR)/bikeshed_singlehtml/index.html \
+ >$(BUILDDIR)/bikeshed_singlehtml/index_fixed.html
+ @echo ==== Showing contents of _build/bikeshed_singlehtml/index_fixed.html ====
+ @head -n10 _build/bikeshed_singlehtml/index_fixed.html
+ @echo ... skipping $$(expr `cat _build/bikeshed_singlehtml/index_fixed.html | wc -l` - 20) lines ...
+ @tail -n10 _build/bikeshed_singlehtml/index_fixed.html
+ @echo
+ @echo =========================================================================
+ mkdir -p $(BUILDDIR)/bikeshed_mathjax/
+ bikeshed spec index.bs $(BUILDDIR)/bikeshed_mathjax/index.html
+ mkdir -p $(BUILDDIR)/html/bikeshed/
+ (cd util/katex/ && yarn && yarn build && npm install --only=prod)
+ python3 util/mathjax2katex.py $(BUILDDIR)/bikeshed_mathjax/index.html \
+ >$(BUILDDIR)/html/bikeshed/index.html
+ mkdir -p $(BUILDDIR)/html/bikeshed/katex/dist/
+ cp -r util/katex/dist/* $(BUILDDIR)/html/bikeshed/katex/dist/
+ patch -p0 $(BUILDDIR)/html/bikeshed/katex/dist/katex.css \
+ < util/katex_fix.patch
+ cp $(BUILDDIR)/bikeshed_singlehtml/_static/pygments.css \
+ $(BUILDDIR)/html/bikeshed/
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/html/bikeshed/."
+
+.PHONY: WD-tar
+WD-tar: bikeshed
+ @echo "Building tar file..."
+ tar cvf \
+ $(BUILDDIR)/WD.tar \
+ --transform='s|$(BUILDDIR)/html/bikeshed/||' \
+ --transform='s|index.html|Overview.html|' \
+ $(BUILDDIR)/html/bikeshed/index.html \
+ $(BUILDDIR)/html/bikeshed/pygments.css \
+ $(BUILDDIR)/html/bikeshed/katex/dist/katex.css \
+ $(BUILDDIR)/html/bikeshed/katex/dist/fonts
+ @echo "Built $(BUILDDIR)/WD.tar."
+
+.PHONY: WD-echidna
+WD-echidna: WD-tar
+ @if [ -z $(W3C_USERNAME) ] || \
+ [ -z $(W3C_PASSWORD) ] || \
+ [ -z $(DECISION_URL) ] ; then \
+ echo "Must provide W3C_USERNAME, W3C_PASSWORD, and DECISION_URL environment variables"; \
+ exit 1; \
+ fi
+ curl 'https://labs.w3.org/echidna/api/request' \
+ --user '$(W3C_USERNAME):$(W3C_PASSWORD)' \
+ -F "tar=@$(BUILDDIR)/WD.tar" \
+ -F "decision=$(DECISION_URL)" | tee $(BUILDDIR)/WD-echidna-id.txt
+ @echo
+ @echo "Published working draft. Check its status at https://labs.w3.org/echidna/api/status?id=`cat $(BUILDDIR)/WD-echidna-id.txt`"
+
+.PHONY: diff
+diff: bikeshed
+ @echo "Downloading the old single-file html spec..."
+ curl `grep "^TR" index.bs | cut -d' ' -f2` -o $(BUILDDIR)/html/bikeshed/old.html
+ @echo "Done."
+ @echo "Diffing new against old (go get a coffee)..."
+ perl ../util/htmldiff.pl $(BUILDDIR)/html/bikeshed/old.html $(BUILDDIR)/html/bikeshed/index.html $(BUILDDIR)/html/bikeshed/diff.html
+ @echo "Done. The diff is at $(BUILDDIR)/html/bikeshed/diff.html"
+
+.PHONY: pickle
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+.PHONY: json
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+.PHONY: htmlhelp
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+.PHONY: qthelp
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/WebAssembly.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/WebAssembly.qhc"
+
+.PHONY: applehelp
+applehelp:
+ $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
+ @echo
+ @echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
+ @echo "N.B. You won't be able to view it unless you put it in" \
+ "~/Library/Documentation/Help or install it in your application" \
+ "bundle."
+
+.PHONY: devhelp
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/WebAssembly"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/WebAssembly"
+ @echo "# devhelp"
+
+.PHONY: epub
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+.PHONY: epub3
+epub3:
+ $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3
+ @echo
+ @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3."
+
+.PHONY: latex
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+.PHONY: latexpdf
+latexpdf: $(GENERATED)
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ $(MAKE) -C $(BUILDDIR)/latex LATEXMKOPTS=" $(BUILDDIR)/latex/LOG 2>&1 || cat $(BUILDDIR)/latex/LOG
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+.PHONY: latexpdfja
+latexpdfja:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through platex and dvipdfmx..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+.PHONY: text
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+.PHONY: man
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+.PHONY: texinfo
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+ @echo "Run \`make' in that directory to run these through makeinfo" \
+ "(use \`make info' here to do that automatically)."
+
+.PHONY: info
+info:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo "Running Texinfo files through makeinfo..."
+ make -C $(BUILDDIR)/texinfo info
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+.PHONY: gettext
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+.PHONY: changes
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+.PHONY: linkcheck
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+.PHONY: doctest
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
+
+.PHONY: coverage
+coverage:
+ $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
+ @echo "Testing of coverage in the sources finished, look at the " \
+ "results in $(BUILDDIR)/coverage/python.txt."
+
+.PHONY: xml
+xml:
+ $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
+ @echo
+ @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
+
+.PHONY: pseudoxml
+pseudoxml:
+ $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
+ @echo
+ @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
+
+.PHONY: dummy
+dummy:
+ $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
+ @echo
+ @echo "Build finished. Dummy builder generates no files."
diff --git a/document/legacy/exceptions/README.md b/document/legacy/exceptions/README.md
new file mode 100644
index 00000000..06d07523
--- /dev/null
+++ b/document/legacy/exceptions/README.md
@@ -0,0 +1,25 @@
+# WebAssembly Core Specification Addendum: Legacy Exception Handling
+
+This is the official WebAssembly "language" specification.
+
+It uses [Sphinx](http://www.sphinx-doc.org/). To install that:
+```
+pip install sphinx
+```
+To make HTML (result in `_build/html`):
+```
+make html
+```
+To make PDF (result in `_build/latex`, requires LaTeX):
+```
+make pdf
+```
+To make all:
+```
+make all
+```
+Finally, to make all and update webassembly.github.io/spec with it:
+```
+make publish
+```
+Please make sure to only use that once a change has approval.
diff --git a/document/legacy/exceptions/appendix/index-instructions.py b/document/legacy/exceptions/appendix/index-instructions.py
new file mode 100755
index 00000000..ea315469
--- /dev/null
+++ b/document/legacy/exceptions/appendix/index-instructions.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python3
+
+# This script generates the `index-instructions.rst` file. The table in that
+# file is particularly annoying to update by hand, since the Restructured Text
+# format requires the header and columns to line up properly. This is
+# especially tedious when merging changes from the upstream spec, or merging a
+# proposal back to the spec when it is standardized.
+
+import os
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+INDEX_INSTRUCTIONS_RST = os.path.join(SCRIPT_DIR, 'index-instructions.rst')
+
+HEADER = """\
+.. DO NOT EDIT: This file is auto-generated by the index-instructions.py script.
+
+.. _appendix:
+
+Appendix
+========
+
+.. index:: instruction
+.. _index-instr:
+
+Index of Instructions
+---------------------
+"""
+
+FOOTER = """\
+
+.. note::
+ Multi-byte opcodes are given with the shortest possible encoding in the table.
+ However, what is following the first byte is actually a :ref:`u32 ` with variable-length encoding
+ and consequently has multiple possible representations.\
+"""
+
+COLUMNS = [
+ 'Instruction',
+ 'Binary Opcode',
+ 'Type',
+ 'Validation',
+ 'Execution',
+]
+
+
+def MathWrap(s, default=''):
+ if s is None:
+ return default
+ else:
+ return f':math:`{s}`'
+
+
+def RefWrap(s, kind):
+ if s is None:
+ return ''
+ else:
+ return f':ref:`{kind} <{s}>`'
+
+
+def Instruction(name, opcode, type=None, validation=None, execution=None, operator=None, validation2=None, execution2=None):
+ if operator:
+ execution_str = ', '.join([RefWrap(execution, 'execution'),
+ RefWrap(operator, 'operator')])
+ elif execution2:
+ execution_str = ', '.join([RefWrap(execution, 'execution'),
+ RefWrap(execution, 'execution')])
+
+ else:
+ execution_str = RefWrap(execution, 'execution')
+
+ if validation2:
+ validation_str = ', '.join([RefWrap(validation, 'validation'),
+ RefWrap(validation2, 'validation')])
+ else:
+ validation_str = RefWrap(validation, 'validation')
+
+ return (
+ MathWrap(name, '(reserved)'),
+ MathWrap(opcode),
+ MathWrap(type),
+ validation_str,
+ execution_str
+ )
+
+
+INSTRUCTIONS = [
+ Instruction(r'\TRY~\X{bt}', r'\hex{06}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-try-catch', r'exec-try-catch', None, r'valid-try-delegate', r'exec-try-delegate'),
+ Instruction(r'\CATCH~x', r'\hex{07}', None, r'valid-try-catch', r'exec-try-catch'),
+ Instruction(r'\RETHROW~n', r'\hex{09}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-rethrow', r'exec-rethrow'),
+ Instruction(r'\DELEGATE~l', r'\hex{18}', None, r'valid-try-delegate', r'exec-try-delegate'),
+ Instruction(r'\CATCHALL', r'\hex{19}', None, r'valid-try-catch', r'exec-try-catch'),
+]
+
+
+def ColumnWidth(n):
+ return max([len(instr[n]) for instr in INSTRUCTIONS])
+
+COLUMN_WIDTHS = [ColumnWidth(i) for i in range(len(COLUMNS))]
+DIVIDER = ' '.join('=' * width for width in COLUMN_WIDTHS)
+
+def Row(columns):
+ return ' '.join(('{:%d}' % COLUMN_WIDTHS[i]).format(column)
+ for i, column in enumerate(columns))
+
+if __name__ == '__main__':
+ with open(INDEX_INSTRUCTIONS_RST, 'w') as f:
+ print(HEADER, file=f)
+ print(DIVIDER, file=f)
+ print(Row(COLUMNS), file=f)
+ print(DIVIDER, file=f)
+
+ for instr in INSTRUCTIONS:
+ print(Row(instr), file=f)
+
+ print(DIVIDER, file=f)
+ print(FOOTER, file=f)
diff --git a/document/legacy/exceptions/binary.rst b/document/legacy/exceptions/binary.rst
new file mode 100644
index 00000000..68ea09df
--- /dev/null
+++ b/document/legacy/exceptions/binary.rst
@@ -0,0 +1,31 @@
+.. _binary:
+
+Binary Format
+=============
+
+.. index:: instruction
+.. _binary-instr:
+
+Instructions
+------------
+
+.. _binary-instr-control:
+
+Control Instructions
+~~~~~~~~~~~~~~~~~~~~
+
+.. _binary-try:
+.. _binary-rethrow:
+
+.. math::
+ \begin{array}{llcllll}
+ \production{instruction} & \Binstr &::=& \dots \\ &&|&
+ \hex{06}~~\X{bt}{:}\Bblocktype~~(\X{in}_1{:}\Binstr)^\ast~~
+ (\hex{07}~~x{:}\Btagidx~~(\X{in}_2{:}\Binstr)^\ast)^\ast~~
+ (\hex{19}~~(\X{in}_3{:}\Binstr)^\ast)^?~~\hex{0B}
+ &\Rightarrow& \TRY~\X{bt}~\X{in}_1^\ast~(\CATCH~x~\X{in}_2^\ast)^\ast~
+ (\CATCHALL~\X{in}_3^\ast)^?\END \\ &&|&
+ \hex{06}~~\X{bt}{:}\Bblocktype~~(\X{in}{:}\Binstr)^\ast~~\hex{18}~~l{:}\Blabelidx
+ &\Rightarrow& \TRY~\X{bt}~\X{in}^\ast~\DELEGATE~l \\ &&|&
+ \hex{09}~~l{:}\Blabelidx &\Rightarrow& \RETHROW~l \\
+ \end{array}
diff --git a/document/legacy/exceptions/conf.py b/document/legacy/exceptions/conf.py
new file mode 100644
index 00000000..ebd159bd
--- /dev/null
+++ b/document/legacy/exceptions/conf.py
@@ -0,0 +1,498 @@
+# -*- coding: utf-8 -*-
+#
+# WebAssembly documentation build configuration file, created by
+# sphinx-quickstart on Mon Nov 21 11:32:49 2016.
+#
+# This file is execfile()d with the current directory set to its
+# containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+import os
+import sys
+from datetime import date
+
+pwd = os.path.abspath('.')
+sys.path.insert(0, pwd)
+
+# -- General configuration ------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#
+needs_sphinx = '2.3'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+ 'sphinx.ext.todo',
+ 'sphinx.ext.coverage',
+ 'sphinx.ext.mathjax',
+ 'sphinx.ext.ifconfig',
+ 'sphinx.ext.githubpages',
+ 'util.mathdef',
+ 'util.pseudo-lexer'
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix(es) of source filenames.
+# You can specify multiple suffix as a list of string:
+#
+source_suffix = ['.rst']
+
+# The encoding of source files.
+#
+# source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+name = 'WebAssembly'
+project = u'WebAssembly'
+title = u'WebAssembly Specification Addendum: Legacy Exception Handling'
+copyright = u'2023, WebAssembly Community Group'
+author = u'WebAssembly Community Group'
+editor = u'Andreas Rossberg (editor)'
+logo = 'static/webassembly.png'
+
+# The name of the GitHub repository this resides in
+repo = 'spec'
+
+# The draft version string (clear out for release cuts)
+draft = ' (Draft ' + date.today().strftime("%Y-%m-%d") + ')'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = u'0.1'
+# The full version, including alpha/beta/rc tags.
+release = version
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = 'en'
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#
+# today = ''
+#
+# Else, today_fmt is used as the format for a strftime call.
+#
+# today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This patterns also effect to html_static_path and html_extra_path
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+# The reST default role (used for this markup: `text`) to use for all
+# documents.
+#
+# default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#
+# add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#
+# add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#
+# show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+# modindex_common_prefix = []
+
+# If true, keep warnings as "system message" paragraphs in the built documents.
+# keep_warnings = False
+
+# If true, `todo` and `todoList` produce output, else they produce nothing.
+todo_include_todos = True
+
+
+# -- Options for HTML output ----------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'alabaster'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#
+html_theme_options = {
+ 'logo': logo,
+ 'logo_name': 'WebAssembly',
+ 'description': 'WebAssembly Specification',
+ 'fixed_sidebar': True,
+ 'sidebar_width': '260px',
+ 'sidebar_collapse': True,
+ 'show_powered_by': False,
+ 'extra_nav_links': {
+ 'Index': 'BASEDIR/genindex.html',
+ 'Download as PDF': 'BASEDIR/_download/' + name + '.pdf'
+ },
+}
+
+html_sidebars = {
+ '**': [
+ # 'about.html',
+ 'navigation.html',
+ # 'relations.html',
+ 'searchbox.html',
+ ]
+}
+
+
+# Add any paths that contain custom themes here, relative to this directory.
+# html_theme_path = []
+
+# The name for this set of Sphinx documents.
+# " v documentation" by default.
+#
+html_title = project + u' ' + release
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+#
+# html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#
+html_logo = logo
+
+# The name of an image file (relative to this directory) to use as a favicon of
+# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#
+# html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['static/custom.css']
+
+# Add any extra paths that contain custom files (such as robots.txt or
+# .htaccess) here, relative to this directory. These files are copied
+# directly to the root of the documentation.
+#
+# html_extra_path = []
+
+# If not None, a 'Last updated on:' timestamp is inserted at every page
+# bottom, using the given strftime format.
+# The empty string is equivalent to '%b %d, %Y'.
+#
+# html_last_updated_fmt = None
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#
+# html_use_smartypants = True
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#
+# html_additional_pages = {}
+
+# If false, no module index is generated.
+#
+html_domain_indices = False
+
+# If false, no index is generated.
+#
+html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#
+html_split_index = False
+
+# If true, the reST sources are included in the HTML build as _sources/name. The default is True.
+#
+html_copy_source = False
+
+# If true, links to the reST sources are added to the pages.
+#
+html_show_sourcelink = False
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#
+html_show_sphinx = False
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#
+html_show_copyright = True
+
+# If this is not None, a ‘Last updated on:’ timestamp is inserted at every
+# page bottom, using the given strftime() format.
+#
+html_last_updated_fmt = '%Y-%m-%d'
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#
+# html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#
+# html_file_suffix = None
+
+# Language to be used for generating the HTML full-text search index.
+# Sphinx supports the following languages:
+# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
+# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh'
+#
+# html_search_language = 'en'
+
+# A dictionary with options for the search language support, empty by default.
+# 'ja' uses this config value.
+# 'zh' user can custom change `jieba` dictionary path.
+#
+# html_search_options = {'type': 'default'}
+
+# The name of a javascript file (relative to the configuration directory) that
+# implements a search results scorer. If empty, the default will be used.
+#
+# html_search_scorer = 'scorer.js'
+
+# Output file base name for HTML help builder.
+#
+htmlhelp_basename = 'WebAssemblydoc'
+
+
+# -- Options for LaTeX output ---------------------------------------------
+
+latex_elements = {
+ # The paper size ('a4paper' or 'letterpaper').
+ 'papersize': 'a4paper',
+
+ # The font size ('10pt', '11pt' or '12pt').
+ 'pointsize': '10pt',
+
+ # Additional stuff for the LaTeX preamble.
+ # Don't type-set cross references with emphasis.
+ 'preamble': '\\renewcommand\\sphinxcrossref[1]{#1}\n',
+
+ # Latex figure (float) alignment
+ 'figure_align': 'htbp',
+
+ # Fancy chapters [Bjarne, Sonny, Lenny, Glenn, Conny, Rejne]
+ 'fncychap': '\\usepackage[Sonny]{fncychap}',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+# author, documentclass [howto, manual, or own class]).
+latex_documents = [
+ ( master_doc,
+ name + '.tex',
+ title,
+ author + '\\\\ \\hfill\\large ' + editor,
+ 'manual'
+ ),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#
+latex_logo = logo
+
+# For "manual" documents [part, chapter, or section].
+#
+latex_toplevel_sectioning = 'section'
+
+# If true, show page references after internal links.
+#
+latex_show_pagerefs = False
+
+# How to show URL addresses after external links [no, footnote, inline].
+#
+latex_show_urls = 'footnote'
+
+# Documents to append as an appendix to all manuals.
+#
+# latex_appendices = []
+
+# It false, will not define \strong, \code, \titleref, \crossref ... but only
+# \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added
+# packages.
+#
+# latex_keep_old_macro_names = True
+
+# If false, no module index is generated.
+#
+latex_domain_indices = False
+
+
+# -- Options for manual page output ---------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ ( master_doc,
+ name,
+ title,
+ [author],
+ 1
+ )
+]
+
+# If true, show URL addresses after external links.
+#
+# man_show_urls = False
+
+
+# -- Options for Texinfo output -------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+# dir menu entry, description, category)
+texinfo_documents = [
+ ( master_doc,
+ name,
+ title,
+ author,
+ name,
+ 'A portable low-level execution format.',
+ 'Virtual Machine'
+ ),
+]
+
+# Documents to append as an appendix to all manuals.
+#
+# texinfo_appendices = []
+
+# If false, no module index is generated.
+#
+texinfo_domain_indices = False
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#
+# texinfo_show_urls = 'footnote'
+
+# If true, do not generate a @detailmenu in the "Top" node's menu.
+#
+# texinfo_no_detailmenu = False
+
+
+# -- Options for Epub output ----------------------------------------------
+
+# Bibliographic Dublin Core info.
+epub_title = project
+epub_author = author
+epub_publisher = author
+epub_copyright = copyright
+
+# The basename for the epub file. It defaults to the project name.
+# epub_basename = project
+
+# The HTML theme for the epub output. Since the default themes are not
+# optimized for small screen space, using the same theme for HTML and epub
+# output is usually not wise. This defaults to 'epub', a theme designed to save
+# visual space.
+#
+# epub_theme = 'epub'
+
+# The language of the text. It defaults to the language option
+# or 'en' if the language is not set.
+#
+# epub_language = ''
+
+# The scheme of the identifier. Typical schemes are ISBN or URL.
+# epub_scheme = ''
+
+# The unique identifier of the text. This can be a ISBN number
+# or the project homepage.
+#
+# epub_identifier = ''
+
+# A unique identification for the text.
+#
+# epub_uid = ''
+
+# A tuple containing the cover image and cover page html template filenames.
+#
+# epub_cover = ()
+
+# A sequence of (type, uri, title) tuples for the guide element of content.opf.
+#
+# epub_guide = ()
+
+# HTML files that should be inserted before the pages created by sphinx.
+# The format is a list of tuples containing the path and title.
+#
+# epub_pre_files = []
+
+# HTML files that should be inserted after the pages created by sphinx.
+# The format is a list of tuples containing the path and title.
+#
+# epub_post_files = []
+
+# A list of files that should not be packed into the epub file.
+epub_exclude_files = ['search.html']
+
+# The depth of the table of contents in toc.ncx.
+#
+# epub_tocdepth = 3
+
+# Allow duplicate toc entries.
+#
+# epub_tocdup = True
+
+# Choose between 'default' and 'includehidden'.
+#
+# epub_tocscope = 'default'
+
+# Fix unsupported image types using the Pillow.
+#
+# epub_fix_images = False
+
+# Scale large images.
+#
+# epub_max_image_width = 0
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#
+# epub_show_urls = 'inline'
+
+# If false, no index is generated.
+#
+# epub_use_index = True
+
+# Macros
+rst_prolog = """
+.. |issuelink| replace:: https://github.com/webassembly/""" + repo + """/issues/
+.. |pagelink| replace:: https://webassembly.github.io/""" + repo + """/core/
+.. include:: /""" + pwd + """/util/macros.def
+"""
+
+# https://www.sphinx-doc.org/en/master/usage/extensions/math.html#confval-mathjax3_config
+# https://docs.mathjax.org/en/latest/web/configuration.html#configuration
+# https://docs.mathjax.org/en/latest/options/input/tex.html#tex-maxbuffer
+mathjax3_config = {
+ 'tex': { 'maxBuffer': 30*1024 },
+}
diff --git a/document/legacy/exceptions/exec.rst b/document/legacy/exceptions/exec.rst
new file mode 100644
index 00000000..a935eaca
--- /dev/null
+++ b/document/legacy/exceptions/exec.rst
@@ -0,0 +1,351 @@
+.. _exec:
+
+Execution
+=========
+
+.. _syntax-runtime:
+
+Runtime Structure
+-----------------
+
+.. _handler:
+.. _stack:
+
+Stack
+~~~~~
+
+.. _syntax-handler:
+
+Exception Handlers
+..................
+
+Legacy exception handlers are installed by |TRY| instructions.
+Instead of branch labels, their catch clauses have instruction blocks associated with them.
+Furthermore, a |DELEGATE| handler is associated with a label index to implicitly rewthrow to:
+
+.. math::
+ \begin{array}{llllll}
+ \production{catch} & \catch &::=& \dots \\ &&|&
+ \CATCH~\tagidx~\instr^\ast \\ &&|&
+ \CATCHALL~\tagidx~\instr^\ast \\ &&|&
+ \DELEGATE~\labelidx \\
+ \end{array}
+
+
+.. _syntax-caught:
+.. _syntax-instr-admin:
+
+Administrative Instructions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Administrative instructions are extended with the |CAUGHT| instruction that models exceptions caught by legacy exception handlers.
+
+.. math::
+ \begin{array}{llcl}
+ \production{administrative instruction} & \instr &::=& \dots \\ &&|&
+ \CAUGHT_n\{\exnaddr\}~\instr^\ast~\END \\
+ \end{array}
+
+
+.. _syntax-ctxt-block:
+
+Block Contexts
+..............
+
+Block contexts are extended to include |CAUGHT| instructions:
+
+.. math::
+ \begin{array}{llll}
+ \production{block contexts} & \XB^k &::=& \dots \\ &&|&
+ \CAUGHT_n~\{\exnaddr\}~\XB^k~\END \\
+ \end{array}
+
+
+.. _syntax-ctxt-throw:
+
+Throw Contexts
+..............
+
+Throw contexts are also extended to include |CAUGHT| instructions:
+
+.. math::
+ \begin{array}{llll}
+ \production{throw contexts} & \XT &::=& \dots \\ &&|&
+ \CAUGHT_n\{\exnaddr\}~\XT~\END \\
+ \end{array}
+
+
+.. _exec-instr:
+
+Instructions
+------------
+
+.. _exec-instr-control:
+
+Control Instructions
+~~~~~~~~~~~~~~~~~~~~
+
+.. _exec-try-catch:
+
+:math:`\TRY~\blocktype~\instr_1^\ast~(\CATCH~x~\instr_2^\ast)^\ast~(\CATCHALL~\instr_3^\ast)^?~\END`
+....................................................................................................
+
+1. Assert: due to :ref:`validation `, :math:`\expand_F(\blocktype)` is defined.
+
+2. Let :math:`[t_1^m] \to [t_2^n]` be the :ref:`function type ` :math:`\expand_F(\blocktype)`.
+
+3. Let :math:`L` be the label whose arity is :math:`n` and whose continuation is the end of the |TRY| instruction.
+
+4. Assert: due to :ref:`validation `, there are at least :math:`m` values on the top of the stack.
+
+5. Pop the values :math:`\val^m` from the stack.
+
+6. Let :math:`F` be the :ref:`current ` :ref:`frame `.
+
+7. For each catch clause :math:`(\CATCH~x_i~\instr_{2i}^\ast)` do:
+
+ a. Assert: due to :ref:`validation `, :math:`F.\AMODULE.\MITAGS[x_i]` exists.
+
+ b. Let :math:`a_i` be the tag address :math:`F.\AMODULE.\MITAGS[x_i]`.
+
+ c. Let :math:`\catch_i` be the catch clause :math:`(\CATCH~a_i~\instr_{2i}^\ast)`.
+
+8. If there is a catch-all clause :math:`(\CATCHALL~\instr_3^\ast)`, then:
+
+ a. Let :math:`\catch'^?` be the handler :math:`(\CATCHALL~\instr_3^\ast)`.
+
+9. Else:
+
+ a. Let :math:`\catch'^?` be empty.
+
+10. Let :math:`\catch^\ast` be the concatenation of :math:`\catch_i` and :math:`\catch'^?`.
+
+11. :ref:`Enter ` the block :math:`\val^m~\instr_1^\ast` with label :math:`L` and exception handler :math:`\HANDLER_n\{\catch^\ast\}^\ast`.
+
+.. math::
+ ~\\[-1ex]
+ \begin{array}{l}
+ F; \val^m~(\TRY~\X{bt}~\instr_1^\ast~(\CATCH~x~\instr_2^\ast)^\ast~(\CATCHALL~\instr_3^\ast)^?~\END
+ \quad \stepto \\
+ \qquad F; \LABEL_n\{\epsilon\}~(\HANDLER_n\{(\CATCH~a_x~\instr_2^\ast)^\ast~(\CATCHALL~\instr_3^\ast)^?\}~\val^m~\instr_1^\ast~\END)~\END \\
+ (\iff \expand_F(\X{bt}) = [t_1^m] \to [t_2^n] \land (F.\AMODULE.\MITAGS[x]=a_x)^\ast)
+ \end{array}
+
+
+.. _exec-try-delegate:
+
+:math:`\TRY~\blocktype~\instr^\ast~\DELEGATE~l`
+...............................................
+
+1. Assert: due to :ref:`validation `, :math:`\expand_F(\blocktype)` is defined.
+
+2. Let :math:`[t_1^m] \to [t_2^n]` be the :ref:`function type ` :math:`\expand_F(\blocktype)`.
+
+3. Let :math:`L` be the label whose arity is :math:`n` and whose continuation is the end of the |TRY| instruction.
+
+4. Let :math:`H` be the :ref:`exception handler ` :math:`l`, targeting the :math:`l`-th surrounding block.
+
+5. Assert: due to :ref:`validation `, there are at least :math:`m` values on the top of the stack.
+
+6. Pop the values :math:`\val^m` from the stack.
+
+7. :ref:`Enter ` the block :math:`\val^m~\instr^\ast` with label :math:`L` and exception handler `\HANDLER_n\{\DELEGATE~l\}`.
+
+.. math::
+ ~\\[-1ex]
+ \begin{array}{lcl}
+ F; \val^m~(\TRY~\X{bt}~\instr^\ast~\DELEGATE~l) &\stepto&
+ F; \LABEL_n\{\epsilon\}~(\HANDLER_n\{\DELEGATE~l\}~\val^m~\instr^\ast~\END)~\END \\
+ && (\iff \expand_F(\X{bt}) = [t_1^m] \to [t_2^n])
+ \end{array}
+
+
+.. _exec-throw_ref:
+
+:math:`\THROWREF`
+.................
+
+1. Let :math:`F` be the :ref:`current ` :ref:`frame `.
+
+2. Assert: due to :ref:`validation `, a :ref:`reference ` is on the top of the stack.
+
+3. Pop the reference :math:`\reff` from the stack.
+
+4. If :math:`\reff` is :math:`\REFNULL~\X{ht}`, then:
+
+ a. Trap.
+
+5. Assert: due to :ref:`validation `, :math:`\reff` is an :ref:`exception reference `.
+
+6. Let :math:`\REFEXNADDR~\X{ea}` be :math:`\reff`.
+
+7. Assert: due to :ref:`validation `, :math:`S.\SEXNS[\X{ea}]` exists.
+
+8. Let :math:`\X{exn}` be the :ref:`exception instance ` :math:`S.\SEXNS[\X{ea}]`.
+
+9. Let :math:`a` be the :ref:`tag address ` :math:`\X{exn}.\EITAG`.
+
+10. While the stack is not empty and the top of the stack is not an :ref:`exception handler `, do:
+
+ a. Pop the top element from the stack.
+
+11. Assert: the stack is now either empty, or there is an exception handler on the top of the stack.
+
+12. If the stack is empty, then:
+
+ a. Return the exception :math:`(\REFEXNADDR~a)` as a :ref:`result `.
+
+13. Assert: there is an :ref:`exception handler ` on the top of the stack.
+
+14. Pop the exception handler :math:`\HANDLER_n\{\catch^\ast\}` from the stack.
+
+15. If :math:`\catch^\ast` is empty, then:
+
+ a. Push the exception reference :math:`\REFEXNADDR~\X{ea}` back to the stack.
+
+ b. Execute the instruction |THROWREF| again.
+
+16. Else:
+
+ a. Let :math:`\catch_1` be the first :ref:`catch clause ` in :math:`\catch^\ast` and :math:`{\catch'}^\ast` the remaining clauses.
+
+ b. If :math:`\catch_1` is of the form :math:`\CATCH~x~l` and the :ref:`exception address ` :math:`a` equals :math:`F.\AMODULE.\MITAGS[x]`, then:
+
+ i. Push the values :math:`\X{exn}.\EIFIELDS` to the stack.
+
+ ii. Execute the instruction :math:`\BR~l`.
+
+ c. Else if :math:`\catch_1` is of the form :math:`\CATCHREF~x~l` and the :ref:`exception address ` :math:`a` equals :math:`F.\AMODULE.\MITAGS[x]`, then:
+
+ i. Push the values :math:`\X{exn}.\EIFIELDS` to the stack.
+
+ ii. Push the exception reference :math:`\REFEXNADDR~\X{ea}` to the stack.
+
+ iii. Execute the instruction :math:`\BR~l`.
+
+ d. Else if :math:`\catch_1` is of the form :math:`\CATCHALL~l`, then:
+
+ i. Execute the instruction :math:`\BR~l`.
+
+ e. Else if :math:`\catch_1` is of the form :math:`\CATCHALLREF~l`, then:
+
+ i. Push the exception reference :math:`\REFEXNADDR~\X{ea}` to the stack.
+
+ ii. Execute the instruction :math:`\BR~l`.
+
+ f. Else if :math:`\catch_1` is of the form :math:`\CATCH~x~\instr^\ast` and the :ref:`exception address ` :math:`a` equals :math:`F.\AMODULE.\MITAGS[x]`, then:
+
+ i. Push the caught exception :math:`\CAUGHT_n\{\X{ea}\}` to the stack.
+
+ ii. Push the values :math:`\X{exn}.\EIFIELDS` to the stack.
+
+ iii. :ref:`Enter ` the catch block :math:`\instr^\ast`.
+
+ g. Else if :math:`\catch_1` is of the form :math:`\CATCHALL~\instr^\ast`, then:
+
+ i. Push the caught exception :math:`\CAUGHT_n\{\X{ea}\}` to the stack.
+
+ ii. :ref:`Enter ` the catch block :math:`\instr^\ast`.
+
+ h. Else if :math:`\catch_1` is of the form :math:`\DELEGATE~l`, then:
+
+ i. Assert: due to :ref:`validation `, the stack contains at least :math:`l` labels.
+
+ ii. Repeat :math:`l` times:
+
+ * While the top of the stack is not a label, do:
+
+ - Pop the top element from the stack.
+
+ iii. Assert: due to :ref:`validation `, the top of the stack now is a label.
+
+ iv. Pop the label from the stack.
+
+ v. Push the exception reference :math:`\REFEXNADDR~\X{ea}` back to the stack.
+
+ vi. Execute the instruction :math:`\THROWREF` again.
+
+ i. Else:
+
+ 1. Push the modified handler :math:`\HANDLER_n\{{\catch'}^\ast\}` back to the stack.
+
+ 2. Push the exception reference :math:`\REFEXNADDR~\X{ea}` back to the stack.
+
+ 3. Execute the instruction :math:`\THROWREF` again.
+
+.. math::
+ ~\\[-1ex]
+ \begin{array}{rcl}
+ \dots \\
+ \HANDLER_n\{(\CATCH~x~\instr^\ast)~\catch^\ast\}~\XT[(\REFEXNADDR~a)~\THROWREF]~\END &\stepto&
+ \CAUGHT_n\{a\}~\X{exn}.\EIFIELDS~\instr^\ast~\END \\ &&
+ (\begin{array}[t]{@{}r@{~}l@{}}
+ \iff & \X{exn} = S.\SEXNS[a] \\
+ \land & \X{exn}.\EITAG = F.\AMODULE.\MITAGS[x]) \\
+ \end{array} \\
+ \HANDLER_n\{(\CATCHALL~\instr^\ast)~\catch^\ast\}~\XT[(\REFEXNADDR~a)~\THROWREF]~\END &\stepto&
+ \CAUGHT_n\{a\}~\instr^\ast~\END \\
+ \XB^l[\HANDLER_n\{(\DELEGATE~l)~\catch^\ast\}~\XT[(\REFEXNADDR~a)~\THROWREF]~\END] &\stepto&
+ (\REFEXNADDR~a)~\THROWREF \\
+ \end{array}
+
+
+.. _exec-rethrow:
+
+:math:`\RETHROW~l`
+..................
+
+1. Assert: due to :ref:`validation `, the stack contains at least :math:`l+1` labels.
+
+2. Let :math:`L` be the :math:`l`-th label appearing on the stack, starting from the top and counting from zero.
+
+3. Assert: due to :ref:`validation `, :math:`L` is a catch label, i.e., a label of the form :math:`(\LCATCH~[t^\ast])`, which is a label followed by a caught exception in an active catch clause.
+
+4. Let :math:`a` be the caught exception address.
+
+5. Push the value :math:`\REFEXNADDR~a` onto the stack.
+
+6. Execute the instruction |THROWREF|.
+
+.. math::
+ ~\\[-1ex]
+ \begin{array}{lclr@{\qquad}}
+ \CAUGHT_n\{a\}~\XB^l[\RETHROW~l]~\END &\stepto&
+ \CAUGHT_n\{a\}~\XB^l[(\REFEXNADDR~a)~\THROWREF]~\END \\
+ \end{array}
+
+
+.. _exec-caught-enter:
+
+Entering a catch block
+......................
+
+1. Jump to the start of the instruction sequence :math:`\instr^\ast`.
+
+
+.. _exec-caught-exit:
+
+Exiting a catch block
+.....................
+
+When the |END| of a catch block is reached without a jump, thrown exception, or trap, then the following steps are performed.
+
+1. Let :math:`\val^m` be the values on the top of the stack.
+
+2. Pop the values :math:`\val^m` from the stack.
+
+3. Assert: due to :ref:`validation `, a caught exception is now on the top of the stack.
+
+4. Pop the caught exception from the stack.
+
+5. Push :math:`\val^m` back to the stack.
+
+6. Jump to the position after the |END| of the administrative instruction associated with the caught exception.
+
+.. math::
+ \begin{array}{rcl}
+ \CAUGHT_n\{a\}~\val^m~\END &\stepto& \val^m
+ \end{array}
+
+.. note::
+ A caught exception can only be rethrown from the scope of the administrative instruction associated with it, i.e., from the scope of the |CATCH| or |CATCHALL| block of a legacy |TRY| instruction. Upon exit from that block, the caught exception is discarded.
diff --git a/document/legacy/exceptions/index.rst b/document/legacy/exceptions/index.rst
new file mode 100644
index 00000000..b6428fb7
--- /dev/null
+++ b/document/legacy/exceptions/index.rst
@@ -0,0 +1,22 @@
+WebAssembly Specification Addendum: Legacy Exception Handling
+=============================================================
+
+.. only:: html
+
+ | Release |release|
+
+ | Editor: Andreas Rossberg
+
+ | Latest Draft: |WasmDraft|
+ | Issue Tracker: |WasmIssues|
+
+.. toctree::
+ :maxdepth: 1
+
+ intro
+ syntax
+ valid
+ exec
+ binary
+ text
+ appendix/index-instructions
diff --git a/document/legacy/exceptions/intro.rst b/document/legacy/exceptions/intro.rst
new file mode 100644
index 00000000..b8d8c57c
--- /dev/null
+++ b/document/legacy/exceptions/intro.rst
@@ -0,0 +1,8 @@
+.. _intro:
+
+Introduction
+============
+
+This document describes an extension of the official WebAssembly standard
+developed by its `W3C Community Group `_ with additional instructions for exception handling.
+These instructions were never standardized and are deprecated, but they may still be available in some engines, especially in web browsers.
diff --git a/document/legacy/exceptions/static/custom.css b/document/legacy/exceptions/static/custom.css
new file mode 100644
index 00000000..33bb863d
--- /dev/null
+++ b/document/legacy/exceptions/static/custom.css
@@ -0,0 +1,78 @@
+a {
+ color: #004BAB;
+ text-decoration: none;
+}
+
+a.reference {
+ border-bottom: none;
+}
+
+a.reference:hover {
+ border-bottom: 1px dotted #004BAB;
+}
+
+body {
+ font-size: 15px;
+}
+
+div.document { width: 1000px; }
+div.bodywrapper { margin: 0 0 0 200px; }
+div.body { padding: 0 10px 0 10px; }
+div.footer { width: 1000px; }
+
+div.body h1 { font-size: 200%; }
+div.body h2 { font-size: 150%; }
+div.body h3 { font-size: 120%; }
+div.body h4 { font-size: 110%; }
+
+div.note {
+ border: 0px;
+ font-size: 90%;
+ background-color: #F6F8FF;
+}
+
+div.admonition {
+ padding: 10px;
+}
+
+div.admonition p.admonition-title {
+ margin: 0px 0px 0px 0px;
+ font-size: 100%;
+ font-weight: bold;
+}
+
+div.math {
+ background-color: #F0F0F0;
+ padding: 3px 0 3px 0;
+ overflow-x: auto;
+ overflow-y: hidden;
+}
+
+div.relations {
+ display: block;
+}
+
+div.sphinxsidebar {
+ z-index: 1;
+ background: #FFF;
+ margin-top: -30px;
+ font-size: 13px;
+ width: 200px;
+ height: 100%;
+}
+
+div.sphinxsidebarwrapper p.logo {
+ padding: 30px 40px 10px 0px;
+}
+
+div.sphinxsidebar h3 {
+ font-size: 0px;
+}
+
+div.sphinxsidebar a {
+ border-bottom: 0px;
+}
+
+div.sphinxsidebar a:hover {
+ border-bottom: 1px dotted;
+}
diff --git a/document/legacy/exceptions/static/webassembly.png b/document/legacy/exceptions/static/webassembly.png
new file mode 100644
index 00000000..f9edc610
Binary files /dev/null and b/document/legacy/exceptions/static/webassembly.png differ
diff --git a/document/legacy/exceptions/syntax.rst b/document/legacy/exceptions/syntax.rst
new file mode 100644
index 00000000..3dc50dfe
--- /dev/null
+++ b/document/legacy/exceptions/syntax.rst
@@ -0,0 +1,38 @@
+.. _syntax:
+
+Structure
+=========
+
+.. _syntax-instr:
+
+Instructions
+------------
+
+.. _syntax-try:
+.. _syntax-try-catch:
+.. _syntax-try-delegate:
+.. _syntax-rethrow:
+.. _syntax-instr-control:
+
+Control Instructions
+~~~~~~~~~~~~~~~~~~~~
+
+The set of recognised instructions is extended with the following:
+
+.. math::
+ \begin{array}{llcl}
+ \production{instruction} & \instr &::=&
+ \dots \\&&|&
+ \TRY~\blocktype~\instr^\ast~(\CATCH~\tagidx~\instr^\ast)^\ast~(\CATCHALL~\instr^\ast)^?~\END \\ &&|&
+ \TRY~\blocktype~\instr^\ast~\DELEGATE~\labelidx \\ &&|&
+ \RETHROW~\labelidx \\
+ \end{array}
+
+The instructions |TRY| and |RETHROW|, are concerned with exceptions.
+The |TRY| instruction installs an exception handler, and may either handle exceptions in the case of |CATCH| and |CATCHALL|,
+or rethrow them in an outer block in the case of |DELEGATE|.
+
+The |RETHROW| instruction is only allowed inside a |CATCH| or |CATCHALL| clause and allows rethrowing the caught exception by lexically referring to a the corresponding |TRY|.
+
+When |TRY|-|DELEGATE| handles an exception, it also behaves similar to a forward jump,
+effectively rethrowing the caught exception right before the matching |END|.
diff --git a/document/legacy/exceptions/text.rst b/document/legacy/exceptions/text.rst
new file mode 100644
index 00000000..0bf0a30d
--- /dev/null
+++ b/document/legacy/exceptions/text.rst
@@ -0,0 +1,37 @@
+.. _text:
+
+Text Format
+===========
+
+.. _text-instr:
+
+Instructions
+------------
+
+.. _text-blockinstr:
+.. _text-plaininstr:
+.. _text-instr-control:
+
+Control Instructions
+~~~~~~~~~~~~~~~~~~~~
+
+.. _text-try:
+
+The label identifier on a structured control instruction may optionally be repeated after the corresponding :math:`\T{end}`, :math:`\T{else}`, :math:`\T{catch}`, :math:`\T{catch\_all}`, and :math:`\T{delegate}`
+pseudo instructions, to indicate the matching delimiters.
+
+.. math::
+ \begin{array}{llclll}
+ \production{block instruction} & \Tblockinstr_I &::=& \dots \\ &&|&
+ \text{try}~~I'{:}\Tlabel_I~~\X{bt}{:}\Tblocktype~~(\X{in}_1{:}\Tinstr_{I'})^\ast~~
+ (\text{catch}~~\Tid_1^?~~x{:}\Ttagidx_I~~(\X{in}_2{:}\Tinstr_{I'})^\ast)^\ast~~
+ \\ &&&\qquad\qquad (\text{catch\_all}~~\Tid_1^?~~(\X{in}_3{:}\Tinstr_{I'})^\ast)^?~~\text{end}~~\Tid_2^?
+ \\ &&&\qquad \Rightarrow\quad \TRY~\X{bt}~\X{in}_1^\ast~(\CATCH~x~\X{in}_2^\ast)^\ast~(\CATCHALL~\X{in}_3^\ast)^?~\END
+ \\ &&&\qquad\qquad (\iff \Tid_1^? = \epsilon \vee \Tid_1^? = \Tlabel, \Tid_2^? = \epsilon \vee \Tid_2^? = \Tlabel) \\ &&|&
+ \text{try}~~I'{:}\Tlabel_I~~\X{bt}{:}\Tblocktype~~(\X{in}_1{:}\Tinstr_{I'})^\ast
+ ~~\text{delegate}~~l{:}\Tlabelidx_I~~\X{l}{:}\Tlabelidx_I
+ \\ &&&\qquad \Rightarrow\quad \TRY~\X{bt}~\X{in}_1^\ast~\DELEGATE~l
+ \qquad\quad~~ (\iff \Tid^? = \epsilon \vee \Tid^? = \Tlabel) \\
+ \production{plain instruction} & \Tplaininstr_I &::=& \dots \\ &&|&
+ \text{rethrow}~~l{:}\Tlabelidx_I \quad\Rightarrow\quad \RETHROW~l \\
+ \end{array}
diff --git a/document/legacy/exceptions/util/macros.def b/document/legacy/exceptions/util/macros.def
new file mode 100644
index 00000000..e1c28910
--- /dev/null
+++ b/document/legacy/exceptions/util/macros.def
@@ -0,0 +1,1342 @@
+.. LINK MACROS
+
+.. External Standards
+.. ------------------
+
+.. |WasmDraft| replace:: |pagelink|
+.. _WasmDraft: |pagelink|
+
+.. |WasmIssues| replace:: |issuelink|
+.. _WasmIssues: |issuelink|
+
+.. |IEEE754| replace:: IEEE 754
+.. _IEEE754: https://ieeexplore.ieee.org/document/8766229
+
+.. |Unicode| replace:: Unicode
+.. _Unicode: https://www.unicode.org/versions/latest/
+
+.. |ASCII| replace:: ASCII
+.. _ASCII: https://webstore.ansi.org/RecordDetail.aspx?sku=INCITS+4-1986%5bR2012%5d
+
+
+.. External Definitions
+.. --------------------
+
+.. |LittleEndian| replace:: little endian
+.. _LittleEndian: https://en.wikipedia.org/wiki/Endianness#Little-endian
+
+.. |LEB128| replace:: LEB128
+.. _LEB128: https://en.wikipedia.org/wiki/LEB128
+.. |UnsignedLEB128| replace:: unsigned LEB128
+.. _UnsignedLEB128: https://en.wikipedia.org/wiki/LEB128#Unsigned_LEB128
+.. |SignedLEB128| replace:: signed LEB128
+.. _SignedLEB128: https://en.wikipedia.org/wiki/LEB128#Signed_LEB128
+
+.. |SExpressions| replace:: S-expressions
+.. _SExpressions: https://en.wikipedia.org/wiki/S-expression
+
+.. |MediaType| replace:: Media Type
+.. _MediaType: https://www.iana.org/assignments/media-types/media-types.xhtml
+
+
+.. Literature
+.. ----------
+
+.. |PLDI2017| replace:: Bringing the Web up to Speed with WebAssembly
+.. _PLDI2017: https://dl.acm.org/citation.cfm?doid=3062341.3062363
+
+.. |CPP2018| replace:: Mechanising and Verifying the WebAssembly Specification
+.. _CPP2018: https://dl.acm.org/citation.cfm?id=3167082
+
+.. |FM2021| replace:: Two Mechanisations of WebAssembly 1.0
+.. _FM2021: https://link.springer.com/chapter/10.1007/978-3-030-90870-6_4
+
+.. |TAPL| replace:: Types and Programming Languages
+.. _TAPL: https://www.cis.upenn.edu/~bcpierce/tapl/
+
+
+
+.. MATH MACROS
+
+
+.. Generic Stuff
+.. -------------
+
+.. To comment out stuff
+
+.. |void#1| mathdef:: {}
+
+
+.. Type-setting of names
+.. X - (multi-letter) variables / non-terminals
+.. F - functions
+.. K - keywords / terminals
+.. B - binary grammar non-terminals
+.. T - textual grammar non-terminals
+
+.. |X| mathdef:: \mathit
+.. |F| mathdef:: \mathrm
+.. |K| mathdef:: \mathsf
+.. |B| mathdef:: \mathtt
+.. |T| mathdef:: \mathtt
+
+
+.. Notation
+
+.. |mod| mathdef:: \mathbin{\F{mod}}
+
+.. |iff| mathdef:: \mathrel{\mbox{if}}
+.. |otherwise| mathdef:: \mathrel{\mbox{otherwise}}
+.. |where| mathdef:: \mathrel{\mbox{where}}
+
+
+
+.. Grammar & Syntax Notation
+.. -------------------------
+
+.. Notation for grammars
+
+.. |production| mathdef:: \void
+
+
+.. Notation for Sequences & Records
+
+.. |slice| mathdef:: \xref{syntax/conventions}{notation-slice}{\mathrel{\mathbf{:}}}
+.. |with| mathdef:: \xref{syntax/conventions}{notation-replace}{\mathrel{\mbox{with}}}
+.. |concat| mathdef:: \xref{syntax/conventions}{notation-concat}{\F{concat}}
+.. |compose| mathdef:: \xref{syntax/conventions}{notation-compose}{\oplus}
+.. |bigcompose| mathdef:: \xref{syntax/conventions}{notation-compose}{\bigoplus}
+
+
+
+.. Abstract Syntax
+.. ---------------
+
+.. Auxiliary productions
+
+.. |vec| mathdef:: \xref{syntax/conventions}{syntax-vec}{\X{vec}}
+
+
+.. Values, terminals
+
+.. |hex#1| mathdef:: \mathtt{0x#1}
+.. |unicode#1| mathdef:: \mathrm{U{+}#1}
+
+.. |NAN| mathdef:: \xref{syntax/values}{syntax-float}{\K{nan}}
+
+
+.. Values, non-terminals
+
+.. |byte| mathdef:: \xref{syntax/values}{syntax-byte}{\X{byte}}
+
+.. |uX#1| mathdef:: {\X{u#1}}
+.. |sX#1| mathdef:: {\X{s#1}}
+.. |iX#1| mathdef:: {\X{i#1}}
+.. |fX#1| mathdef:: {\X{f#1}}
+.. |vX#1| mathdef:: {\X{v#1}}
+
+.. |uN| mathdef:: \xref{syntax/values}{syntax-int}{\X{u}N}
+.. |uM| mathdef:: \xref{syntax/values}{syntax-int}{\X{u}M}
+.. |u1| mathdef:: \xref{syntax/values}{syntax-int}{\X{u1}}
+.. |u8| mathdef:: \xref{syntax/values}{syntax-int}{\X{u8}}
+.. |u16| mathdef:: \xref{syntax/values}{syntax-int}{\X{u16}}
+.. |u32| mathdef:: \xref{syntax/values}{syntax-int}{\X{u32}}
+.. |u64| mathdef:: \xref{syntax/values}{syntax-int}{\X{u64}}
+
+.. |sN| mathdef:: \xref{syntax/values}{syntax-int}{\X{s}N}
+.. |s8| mathdef:: \xref{syntax/values}{syntax-int}{\X{s8}}
+.. |s16| mathdef:: \xref{syntax/values}{syntax-int}{\X{s16}}
+.. |s32| mathdef:: \xref{syntax/values}{syntax-int}{\X{s32}}
+.. |s64| mathdef:: \xref{syntax/values}{syntax-int}{\X{s64}}
+
+.. |iM| mathdef:: \xref{syntax/values}{syntax-int}{\X{i}M}
+.. |iN| mathdef:: \xref{syntax/values}{syntax-int}{\X{i}N}
+.. |i8| mathdef:: \xref{syntax/values}{syntax-int}{\X{i8}}
+.. |i16| mathdef:: \xref{syntax/values}{syntax-int}{\X{i16}}
+.. |i32| mathdef:: \xref{syntax/values}{syntax-int}{\X{i32}}
+.. |i64| mathdef:: \xref{syntax/values}{syntax-int}{\X{i64}}
+.. |i128| mathdef:: \xref{syntax/values}{syntax-int}{\X{i128}}
+
+.. |fN| mathdef:: \xref{syntax/values}{syntax-float}{\X{f}N}
+.. |fNmag| mathdef:: \xref{syntax/values}{syntax-float}{\X{f}\X{Nmag}}
+.. |f32| mathdef:: \xref{syntax/values}{syntax-float}{\X{f32}}
+.. |f64| mathdef:: \xref{syntax/values}{syntax-float}{\X{f64}}
+
+.. |name| mathdef:: \xref{syntax/values}{syntax-name}{\X{name}}
+.. |char| mathdef:: \xref{syntax/values}{syntax-name}{\X{char}}
+
+
+.. Values, meta functions
+
+.. |canon| mathdef:: \xref{syntax/values}{aux-canon}{\F{canon}}
+.. |significand| mathdef:: \xref{syntax/values}{aux-significand}{\F{signif}}
+.. |exponent| mathdef:: \xref{syntax/values}{aux-exponent}{\F{expon}}
+
+
+.. Types, terminals
+
+.. |to| mathdef:: \xref{syntax/types}{syntax-functype}{\rightarrow}
+.. |toF| mathdef:: \xref{syntax/types}{syntax-functype}{\rightarrow}
+
+.. |I8| mathdef:: \xref{exec/runtime}{syntax-storagetype}{\K{i8}}
+.. |I16| mathdef:: \xref{exec/runtime}{syntax-storagetype}{\K{i16}}
+.. |I32| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{i32}}
+.. |I64| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{i64}}
+.. |F32| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{f32}}
+.. |F64| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{f64}}
+.. |V128| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{v128}}
+.. |I8X16| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{i8x16}}
+.. |I16X8| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{i16x8}}
+.. |I32X4| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{i32x4}}
+.. |I64X2| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{i64x2}}
+.. |F32X4| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{f32x4}}
+.. |F64X2| mathdef:: \xref{syntax/types}{syntax-valtype}{\K{f64x2}}
+.. |I128| mathdef:: \K{i128}
+
+.. |FUNCREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{funcref}}
+.. |EXTERNREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{externref}}
+.. |EXNREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{exnref}}
+
+.. |MVAR| mathdef:: \xref{syntax/types}{syntax-mut}{\K{var}}
+.. |MCONST| mathdef:: \xref{syntax/types}{syntax-mut}{\K{const}}
+
+.. |LMIN| mathdef:: \xref{syntax/types}{syntax-limits}{\K{min}}
+.. |LMAX| mathdef:: \xref{syntax/types}{syntax-limits}{\K{max}}
+
+.. |ETFUNC| mathdef:: \xref{syntax/types}{syntax-externtype}{\K{func}}
+.. |ETTABLE| mathdef:: \xref{syntax/types}{syntax-externtype}{\K{table}}
+.. |ETMEM| mathdef:: \xref{syntax/types}{syntax-externtype}{\K{mem}}
+.. |ETGLOBAL| mathdef:: \xref{syntax/types}{syntax-externtype}{\K{global}}
+.. |ETTAG| mathdef:: \xref{syntax/types}{syntax-tagtype}{\K{tag}}
+
+
+.. Types, non-terminals
+
+.. |numtype| mathdef:: \xref{syntax/types}{syntax-numtype}{\X{numtype}}
+.. |vectype| mathdef:: \xref{syntax/types}{syntax-vectype}{\X{vectype}}
+.. |reftype| mathdef:: \xref{syntax/types}{syntax-reftype}{\X{reftype}}
+.. |valtype| mathdef:: \xref{syntax/types}{syntax-valtype}{\X{valtype}}
+.. |resulttype| mathdef:: \xref{syntax/types}{syntax-resulttype}{\X{resulttype}}
+.. |functype| mathdef:: \xref{syntax/types}{syntax-functype}{\X{functype}}
+.. |tagtype| mathdef:: \xref{syntax/types}{syntax-tagtype}{\X{tagtype}}
+
+.. |globaltype| mathdef:: \xref{syntax/types}{syntax-globaltype}{\X{globaltype}}
+.. |tabletype| mathdef:: \xref{syntax/types}{syntax-tabletype}{\X{tabletype}}
+.. |memtype| mathdef:: \xref{syntax/types}{syntax-memtype}{\X{memtype}}
+
+.. |limits| mathdef:: \xref{syntax/types}{syntax-limits}{\X{limits}}
+.. |mut| mathdef:: \xref{syntax/types}{syntax-mut}{\X{mut}}
+
+.. |externtype| mathdef:: \xref{syntax/types}{syntax-externtype}{\X{externtype}}
+
+.. |stacktype| mathdef:: \xref{syntax/types}{syntax-stacktype}{\X{stacktype}}
+.. |opdtype| mathdef:: \xref{syntax/types}{syntax-opdtype}{\X{opdtype}}
+
+
+.. Types, meta functions
+
+.. |etfuncs| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{funcs}}
+.. |ettables| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{tables}}
+.. |etmems| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{mems}}
+.. |etglobals| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{globals}}
+.. |ettags| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{tags}}
+
+
+.. Indices, non-terminals
+
+.. |typeidx| mathdef:: \xref{syntax/modules}{syntax-typeidx}{\X{typeidx}}
+.. |funcidx| mathdef:: \xref{syntax/modules}{syntax-funcidx}{\X{funcidx}}
+.. |tableidx| mathdef:: \xref{syntax/modules}{syntax-tableidx}{\X{tableidx}}
+.. |memidx| mathdef:: \xref{syntax/modules}{syntax-memidx}{\X{memidx}}
+.. |globalidx| mathdef:: \xref{syntax/modules}{syntax-globalidx}{\X{globalidx}}
+.. |elemidx| mathdef:: \xref{syntax/modules}{syntax-elemidx}{\X{elemidx}}
+.. |dataidx| mathdef:: \xref{syntax/modules}{syntax-dataidx}{\X{dataidx}}
+.. |localidx| mathdef:: \xref{syntax/modules}{syntax-localidx}{\X{localidx}}
+.. |labelidx| mathdef:: \xref{syntax/modules}{syntax-labelidx}{\X{labelidx}}
+.. |tagidx| mathdef:: \xref{syntax/modules}{syntax-tagidx}{\X{tagidx}}
+
+
+.. Indices, meta functions
+
+.. |freetypeidx| mathdef:: \xref{syntax/modules}{syntax-typeidx}{\F{typeidx}}
+.. |freefuncidx| mathdef:: \xref{syntax/modules}{syntax-funcidx}{\F{funcidx}}
+.. |freetableidx| mathdef:: \xref{syntax/modules}{syntax-tableidx}{\F{tableidx}}
+.. |freememidx| mathdef:: \xref{syntax/modules}{syntax-memidx}{\F{memidx}}
+.. |freeglobalidx| mathdef:: \xref{syntax/modules}{syntax-globalidx}{\F{globalidx}}
+.. |freeelemidx| mathdef:: \xref{syntax/modules}{syntax-elemidx}{\F{elemidx}}
+.. |freedataidx| mathdef:: \xref{syntax/modules}{syntax-dataidx}{\F{dataidx}}
+.. |freelocalidx| mathdef:: \xref{syntax/modules}{syntax-localidx}{\F{localidx}}
+.. |freelabelidx| mathdef:: \xref{syntax/modules}{syntax-labelidx}{\F{labelidx}}
+
+
+.. Modules, terminals
+
+.. |MTYPES| mathdef:: \xref{syntax/modules}{syntax-module}{\K{types}}
+.. |MFUNCS| mathdef:: \xref{syntax/modules}{syntax-module}{\K{funcs}}
+.. |MTABLES| mathdef:: \xref{syntax/modules}{syntax-module}{\K{tables}}
+.. |MMEMS| mathdef:: \xref{syntax/modules}{syntax-module}{\K{mems}}
+.. |MGLOBALS| mathdef:: \xref{syntax/modules}{syntax-module}{\K{globals}}
+.. |MTAGS| mathdef:: \xref{syntax/modules}{syntax-module}{\K{tags}}
+.. |MIMPORTS| mathdef:: \xref{syntax/modules}{syntax-module}{\K{imports}}
+.. |MEXPORTS| mathdef:: \xref{syntax/modules}{syntax-module}{\K{exports}}
+.. |MDATAS| mathdef:: \xref{syntax/modules}{syntax-module}{\K{datas}}
+.. |MELEMS| mathdef:: \xref{syntax/modules}{syntax-module}{\K{elems}}
+.. |MSTART| mathdef:: \xref{syntax/modules}{syntax-module}{\K{start}}
+
+.. |FTYPE| mathdef:: \xref{syntax/modules}{syntax-func}{\K{type}}
+.. |FLOCALS| mathdef:: \xref{syntax/modules}{syntax-func}{\K{locals}}
+.. |FBODY| mathdef:: \xref{syntax/modules}{syntax-func}{\K{body}}
+
+.. |TTYPE| mathdef:: \xref{syntax/modules}{syntax-table}{\K{type}}
+
+.. |MTYPE| mathdef:: \xref{syntax/modules}{syntax-mem}{\K{type}}
+
+.. |TAGTYPE| mathdef:: \xref{syntax/modules}{syntax-tag}{\K{type}}
+
+.. |GTYPE| mathdef:: \xref{syntax/modules}{syntax-global}{\K{type}}
+.. |GINIT| mathdef:: \xref{syntax/modules}{syntax-global}{\K{init}}
+
+.. |ETYPE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{type}}
+.. |EINIT| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{init}}
+.. |EMODE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{mode}}
+.. |EPASSIVE| mathdef:: \xref{syntax/modules}{syntax-elemmode}{\K{passive}}
+.. |EACTIVE| mathdef:: \xref{syntax/modules}{syntax-elemmode}{\K{active}}
+.. |EDECLARATIVE| mathdef:: \xref{syntax/modules}{syntax-elemmode}{\K{declarative}}
+.. |ETABLE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{table}}
+.. |EOFFSET| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{offset}}
+
+.. |DINIT| mathdef:: \xref{syntax/modules}{syntax-data}{\K{init}}
+.. |DMODE| mathdef:: \xref{syntax/modules}{syntax-data}{\K{mode}}
+.. |DPASSIVE| mathdef:: \xref{syntax/modules}{syntax-datamode}{\K{passive}}
+.. |DACTIVE| mathdef:: \xref{syntax/modules}{syntax-datamode}{\K{active}}
+.. |DMEM| mathdef:: \xref{syntax/modules}{syntax-data}{\K{memory}}
+.. |DOFFSET| mathdef:: \xref{syntax/modules}{syntax-data}{\K{offset}}
+
+.. |SFUNC| mathdef:: \xref{syntax/modules}{syntax-start}{\K{func}}
+
+.. |ENAME| mathdef:: \xref{syntax/modules}{syntax-export}{\K{name}}
+.. |EDESC| mathdef:: \xref{syntax/modules}{syntax-export}{\K{desc}}
+.. |EDFUNC| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{func}}
+.. |EDTABLE| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{table}}
+.. |EDMEM| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{mem}}
+.. |EDGLOBAL| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{global}}
+.. |EDTAG| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{tag}}
+
+.. |IMODULE| mathdef:: \xref{syntax/modules}{syntax-import}{\K{module}}
+.. |INAME| mathdef:: \xref{syntax/modules}{syntax-import}{\K{name}}
+.. |IDESC| mathdef:: \xref{syntax/modules}{syntax-import}{\K{desc}}
+.. |IDFUNC| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\K{func}}
+.. |IDTABLE| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\K{table}}
+.. |IDMEM| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\K{mem}}
+.. |IDTAG| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\K{tag}}
+.. |IDGLOBAL| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\K{global}}
+
+
+.. Modules, non-terminals
+
+.. |module| mathdef:: \xref{syntax/modules}{syntax-module}{\X{module}}
+.. |type| mathdef:: \xref{syntax/types}{syntax-functype}{\X{type}}
+.. |func| mathdef:: \xref{syntax/modules}{syntax-func}{\X{func}}
+.. |table| mathdef:: \xref{syntax/modules}{syntax-table}{\X{table}}
+.. |mem| mathdef:: \xref{syntax/modules}{syntax-mem}{\X{mem}}
+.. |tag| mathdef:: \xref{syntax/modules}{syntax-tag}{\X{tag}}
+.. |global| mathdef:: \xref{syntax/modules}{syntax-global}{\X{global}}
+.. |import| mathdef:: \xref{syntax/modules}{syntax-import}{\X{import}}
+.. |export| mathdef:: \xref{syntax/modules}{syntax-export}{\X{export}}
+.. |importdesc| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\X{importdesc}}
+.. |exportdesc| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\X{exportdesc}}
+.. |elem| mathdef:: \xref{syntax/modules}{syntax-elem}{\X{elem}}
+.. |elemmode| mathdef:: \xref{syntax/modules}{syntax-elemmode}{\X{elemmode}}
+.. |data| mathdef:: \xref{syntax/modules}{syntax-data}{\X{data}}
+.. |datamode| mathdef:: \xref{syntax/modules}{syntax-datamode}{\X{datamode}}
+.. |start| mathdef:: \xref{syntax/modules}{syntax-start}{\X{start}}
+
+
+.. Modules, meta functions
+
+.. |edfuncs| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\F{funcs}}
+.. |edtables| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\F{tables}}
+.. |edmems| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\F{mems}}
+.. |edtags| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\F{tags}}
+.. |edglobals| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\F{globals}}
+
+
+.. Instructions, terminals
+
+.. |OFFSET| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{offset}}
+.. |ALIGN| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{align}}
+
+.. |UNREACHABLE| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{unreachable}}
+.. |NOP| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{nop}}
+.. |BLOCK| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{block}}
+.. |LOOP| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{loop}}
+.. |IF| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{if}}
+.. |ELSE| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{else}}
+.. |END| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{end}}
+.. |BR| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{br}}
+.. |BRIF| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{br\_if}}
+.. |BRTABLE| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{br\_table}}
+.. |RETURN| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{return}}
+.. |CALL| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{call}}
+.. |CALLINDIRECT| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{call\_indirect}}
+.. |TRYTABLE| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{try\_table}}
+.. |TRY| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{try}}
+.. |CATCH| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{catch}}
+.. |CATCHREF| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{catch\_ref}}
+.. |CATCHALL| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{catch\_all}}
+.. |CATCHALLREF| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{catch\_all\_ref}}
+.. |DELEGATE| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{delegate}}
+.. |THROW| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{throw}}
+.. |THROWREF| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{throw\_ref}}
+.. |RETHROW| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{rethrow}}
+
+.. |DROP| mathdef:: \xref{syntax/instructions}{syntax-instr-parametric}{\K{drop}}
+.. |SELECT| mathdef:: \xref{syntax/instructions}{syntax-instr-parametric}{\K{select}}
+
+.. |LOCALGET| mathdef:: \xref{syntax/instructions}{syntax-instr-variable}{\K{local.get}}
+.. |LOCALSET| mathdef:: \xref{syntax/instructions}{syntax-instr-variable}{\K{local.set}}
+.. |LOCALTEE| mathdef:: \xref{syntax/instructions}{syntax-instr-variable}{\K{local.tee}}
+.. |GLOBALGET| mathdef:: \xref{syntax/instructions}{syntax-instr-variable}{\K{global.get}}
+.. |GLOBALSET| mathdef:: \xref{syntax/instructions}{syntax-instr-variable}{\K{global.set}}
+
+.. |TABLEGET| mathdef:: \xref{syntax/instructions}{syntax-instr-table}{\K{table.get}}
+.. |TABLESET| mathdef:: \xref{syntax/instructions}{syntax-instr-table}{\K{table.set}}
+.. |TABLESIZE| mathdef:: \xref{syntax/instructions}{syntax-instr-table}{\K{table.size}}
+.. |TABLEGROW| mathdef:: \xref{syntax/instructions}{syntax-instr-table}{\K{table.grow}}
+.. |TABLEFILL| mathdef:: \xref{syntax/instructions}{syntax-instr-table}{\K{table.fill}}
+.. |TABLECOPY| mathdef:: \xref{syntax/instructions}{syntax-instr-table}{\K{table.copy}}
+.. |TABLEINIT| mathdef:: \xref{syntax/instructions}{syntax-instr-table}{\K{table.init}}
+.. |ELEMDROP| mathdef:: \xref{syntax/instructions}{syntax-instr-table}{\K{elem.drop}}
+
+.. |LOAD| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{load}}
+.. |STORE| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{store}}
+.. |MEMORYSIZE| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{memory.size}}
+.. |MEMORYGROW| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{memory.grow}}
+.. |MEMORYFILL| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{memory.fill}}
+.. |MEMORYCOPY| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{memory.copy}}
+.. |MEMORYINIT| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{memory.init}}
+.. |DATADROP| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{data.drop}}
+
+.. |REFNULL| mathdef:: \xref{syntax/instructions}{syntax-instr-ref}{\K{ref{.}null}}
+.. |REFISNULL| mathdef:: \xref{syntax/instructions}{syntax-instr-ref}{\K{ref{.}is\_null}}
+.. |REFFUNC| mathdef:: \xref{syntax/instructions}{syntax-instr-ref}{\K{ref{.}func}}
+
+.. |CONST| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{const}}
+.. |EQZ| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{eqz}}
+.. |EQ| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{eq}}
+.. |NE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{ne}}
+.. |LT| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{lt}}
+.. |GT| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{gt}}
+.. |LE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{le}}
+.. |GE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{ge}}
+.. |CLZ| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{clz}}
+.. |CTZ| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{ctz}}
+.. |POPCNT| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{popcnt}}
+.. |ABS| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{abs}}
+.. |NEG| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{neg}}
+.. |CEIL| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{ceil}}
+.. |FLOOR| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{floor}}
+.. |TRUNC| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{trunc}}
+.. |NEAREST| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{nearest}}
+.. |SQRT| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{sqrt}}
+.. |ADD| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{add}}
+.. |SUB| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{sub}}
+.. |MUL| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{mul}}
+.. |DIV| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{div}}
+.. |REM| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{rem}}
+.. |FMIN| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{min}}
+.. |FMAX| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{max}}
+.. |AND| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{and}}
+.. |OR| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{or}}
+.. |XOR| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{xor}}
+.. |SHL| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{shl}}
+.. |SHR| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{shr}}
+.. |ROTL| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{rotl}}
+.. |ROTR| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{rotr}}
+.. |COPYSIGN| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{copysign}}
+
+.. |CONVERT| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{convert}}
+.. |EXTEND| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{extend}}
+.. |WRAP| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{wrap}}
+.. |PROMOTE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{promote}}
+.. |DEMOTE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{demote}}
+.. |REINTERPRET| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{reinterpret}}
+
+.. |VCONST| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{const}}
+.. |SHUFFLE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{shuffle}}
+.. |SWIZZLE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{swizzle}}
+.. |SPLAT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{splat}}
+.. |EXTRACTLANE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{extract\_lane}}
+.. |REPLACELANE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{replace\_lane}}
+.. |VNOT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{not}}
+.. |VAND| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{and}}
+.. |VANDNOT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{andnot}}
+.. |VOR| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{or}}
+.. |VXOR| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{xor}}
+.. |BITSELECT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{bitselect}}
+.. |VEQ| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{eq}}
+.. |VNE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{ne}}
+.. |VLT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{lt}}
+.. |VGT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{gt}}
+.. |VLE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{le}}
+.. |VGE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{ge}}
+.. |VABS| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{abs}}
+.. |VNEG| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{neg}}
+.. |VCEIL| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{ceil}}
+.. |VFLOOR| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{floor}}
+.. |VTRUNC| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{trunc}}
+.. |VNEAREST| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{nearest}}
+.. |VPOPCNT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{popcnt}}
+.. |ANYTRUE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{any\_true}}
+.. |ALLTRUE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{all\_true}}
+.. |BITMASK| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{bitmask}}
+.. |VSHL| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{shl}}
+.. |VSHR| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{shr}}
+.. |VSQRT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{sqrt}}
+.. |VADD| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{add}}
+.. |VSUB| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{sub}}
+.. |VMUL| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{mul}}
+.. |VDIV| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{div}}
+.. |VMIN| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{min}}
+.. |VMAX| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{max}}
+.. |VPMIN| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{pmin}}
+.. |VPMAX| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{pmax}}
+.. |NARROW| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{narrow}}
+.. |VEXTEND| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{extend}}
+.. |AVGR| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{avgr}}
+.. |DOT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{dot}}
+.. |EXTMUL| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{extmul}}
+.. |VCONVERT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{convert}}
+.. |Q15MULRSAT| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{q15mulr\_sat}}
+.. |EXTADDPAIRWISE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{extadd\_pairwise}}
+.. |VDEMOTE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{demote}}
+.. |VPROMOTE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{promote}}
+
+
+.. Instructions, non-terminals
+
+.. |unop| mathdef:: \xref{syntax/instructions}{syntax-unop}{\X{unop}}
+.. |binop| mathdef:: \xref{syntax/instructions}{syntax-binop}{\X{binop}}
+.. |testop| mathdef:: \xref{syntax/instructions}{syntax-testop}{\X{testop}}
+.. |relop| mathdef:: \xref{syntax/instructions}{syntax-relop}{\X{relop}}
+.. |cvtop| mathdef:: \xref{syntax/instructions}{syntax-cvtop}{\X{cvtop}}
+
+.. |iunop| mathdef:: \xref{syntax/instructions}{syntax-iunop}{\X{iunop}}
+.. |ibinop| mathdef:: \xref{syntax/instructions}{syntax-ibinop}{\X{ibinop}}
+.. |itestop| mathdef:: \xref{syntax/instructions}{syntax-itestop}{\X{itestop}}
+.. |irelop| mathdef:: \xref{syntax/instructions}{syntax-irelop}{\X{irelop}}
+
+.. |funop| mathdef:: \xref{syntax/instructions}{syntax-funop}{\X{funop}}
+.. |fbinop| mathdef:: \xref{syntax/instructions}{syntax-fbinop}{\X{fbinop}}
+.. |ftestop| mathdef:: \xref{syntax/instructions}{syntax-ftestop}{\X{ftestop}}
+.. |frelop| mathdef:: \xref{syntax/instructions}{syntax-frelop}{\X{frelop}}
+
+.. |ishape| mathdef:: \xref{syntax/instructions}{syntax-shape}{\X{ishape}}
+.. |fshape| mathdef:: \xref{syntax/instructions}{syntax-shape}{\X{fshape}}
+.. |shape| mathdef:: \xref{syntax/instructions}{syntax-shape}{\X{shape}}
+
+.. |vunop| mathdef:: \xref{syntax/instructions}{syntax-vunop}{\X{vunop}}
+.. |vbinop| mathdef:: \xref{syntax/instructions}{syntax-vbinop}{\X{vbinop}}
+.. |vrelop| mathdef:: \xref{syntax/instructions}{syntax-vrelop}{\X{vrelop}}
+.. |vternop| mathdef:: \xref{syntax/instructions}{syntax-vternop}{\X{vternop}}
+.. |vcvtop| mathdef:: \xref{syntax/instructions}{syntax-vcvtop}{\X{vcvtop}}
+.. |vextmul| mathdef:: \xref{syntax/instructions}{syntax-vextmul}{\X{vextmul}}
+
+.. |laneidx| mathdef:: \xref{syntax/instructions}{syntax-laneidx}{\X{laneidx}}
+.. |vvunop| mathdef:: \xref{syntax/instructions}{syntax-vvunop}{\X{vvunop}}
+.. |vvbinop| mathdef:: \xref{syntax/instructions}{syntax-vvbinop}{\X{vvbinop}}
+.. |vvternop| mathdef:: \xref{syntax/instructions}{syntax-vvternop}{\X{vvternop}}
+.. |vvtestop| mathdef:: \xref{syntax/instructions}{syntax-vvtestop}{\X{vvtestop}}
+.. |vishiftop| mathdef:: \xref{syntax/instructions}{syntax-vishiftop}{\X{vishiftop}}
+.. |viunop| mathdef:: \xref{syntax/instructions}{syntax-viunop}{\X{viunop}}
+.. |vibinop| mathdef:: \xref{syntax/instructions}{syntax-vibinop}{\X{vibinop}}
+.. |viminmaxop| mathdef:: \xref{syntax/instructions}{syntax-viminmaxop}{\X{viminmaxop}}
+.. |visatbinop| mathdef:: \xref{syntax/instructions}{syntax-visatbinop}{\X{visatbinop}}
+.. |vfunop| mathdef:: \xref{syntax/instructions}{syntax-vfunop}{\X{vfunop}}
+.. |vfbinop| mathdef:: \xref{syntax/instructions}{syntax-vfbinop}{\X{vfbinop}}
+.. |virelop| mathdef:: \xref{syntax/instructions}{syntax-virelop}{\X{virelop}}
+.. |vfrelop| mathdef:: \xref{syntax/instructions}{syntax-vfrelop}{\X{vfrelop}}
+.. |vitestop| mathdef:: \xref{syntax/instructions}{syntax-vitestop}{\X{vitestop}}
+.. |vtestop| mathdef:: \xref{syntax/instructions}{syntax-vtestop}{\X{vtestop}}
+
+.. |sx| mathdef:: \xref{syntax/instructions}{syntax-sx}{\X{sx}}
+.. |half| mathdef:: \xref{syntax/instructions}{syntax-half}{\X{half}}
+.. |memarg| mathdef:: \xref{syntax/instructions}{syntax-memarg}{\X{memarg}}
+
+.. |blocktype| mathdef:: \xref{syntax/instructions}{syntax-blocktype}{\X{blocktype}}
+
+.. |instr| mathdef:: \xref{syntax/instructions}{syntax-instr}{\X{instr}}
+.. |catch| mathdef:: \xref{syntax/instructions}{syntax-catch}{\X{catch}}
+.. |expr| mathdef:: \xref{syntax/instructions}{syntax-expr}{\X{expr}}
+
+
+
+.. Binary Format
+.. -------------
+
+.. Auxiliary productions
+
+.. |Bvec| mathdef:: \xref{binary/conventions}{binary-vec}{\B{vec}}
+
+
+.. Values, non-terminals
+
+.. |Bbyte| mathdef:: \xref{binary/values}{binary-byte}{\B{byte}}
+
+.. |BuX#1| mathdef:: {\B{u}#1}
+.. |BsX#1| mathdef:: {\B{s}#1}
+.. |BiX#1| mathdef:: {\B{i}#1}
+.. |BfX#1| mathdef:: {\B{f}#1}
+
+.. |BuN| mathdef:: \xref{binary/values}{binary-int}{\BuX{N}}
+.. |Bu1| mathdef:: \xref{binary/values}{binary-int}{\BuX{\B{1}}}
+.. |Bu8| mathdef:: \xref{binary/values}{binary-int}{\BuX{\B{8}}}
+.. |Bu16| mathdef:: \xref{binary/values}{binary-int}{\BuX{\B{16}}}
+.. |Bu32| mathdef:: \xref{binary/values}{binary-int}{\BuX{\B{32}}}
+.. |Bu64| mathdef:: \xref{binary/values}{binary-int}{\BuX{\B{64}}}
+
+.. |BsN| mathdef:: \xref{binary/values}{binary-int}{\BsX{N}}
+.. |Bs7| mathdef:: \xref{binary/values}{binary-int}{\BsX{\B{7}}}
+.. |Bs32| mathdef:: \xref{binary/values}{binary-int}{\BsX{\B{32}}}
+.. |Bs33| mathdef:: \xref{binary/values}{binary-int}{\BsX{\B{33}}}
+.. |Bs64| mathdef:: \xref{binary/values}{binary-int}{\BsX{\B{64}}}
+
+.. |BiN| mathdef:: \xref{binary/values}{binary-int}{\BiX{N}}
+.. |Bi32| mathdef:: \xref{binary/values}{binary-int}{\BiX{\B{32}}}
+.. |Bi64| mathdef:: \xref{binary/values}{binary-int}{\BiX{\B{64}}}
+
+.. |BfN| mathdef:: \xref{binary/values}{binary-float}{\BfX{N}}
+.. |Bf32| mathdef:: \xref{binary/values}{binary-float}{\BfX{\B{32}}}
+.. |Bf64| mathdef:: \xref{binary/values}{binary-float}{\BfX{\B{64}}}
+
+.. |Bname| mathdef:: \xref{binary/values}{binary-name}{\B{name}}
+
+
+.. Values, meta functions
+
+.. |utf8| mathdef:: \xref{binary/values}{binary-utf8}{\F{utf8}}
+
+
+.. Types, non-terminals
+
+.. |Bnumtype| mathdef:: \xref{binary/types}{binary-numtype}{\B{numtype}}
+.. |Bvectype| mathdef:: \xref{binary/types}{binary-vectype}{\B{vectype}}
+.. |Breftype| mathdef:: \xref{binary/types}{binary-reftype}{\B{reftype}}
+.. |Bvaltype| mathdef:: \xref{binary/types}{binary-valtype}{\B{valtype}}
+.. |Bresulttype| mathdef:: \xref{binary/types}{binary-resulttype}{\B{resulttype}}
+.. |Bfunctype| mathdef:: \xref{binary/types}{binary-functype}{\B{functype}}
+.. |Bglobaltype| mathdef:: \xref{binary/types}{binary-globaltype}{\B{globaltype}}
+.. |Btagtype| mathdef:: \xref{binary/types}{binary-tagtype}{\B{tagtype}}
+.. |Btabletype| mathdef:: \xref{binary/types}{binary-tabletype}{\B{tabletype}}
+.. |Bmemtype| mathdef:: \xref{binary/types}{binary-memtype}{\B{memtype}}
+.. |Blimits| mathdef:: \xref{binary/types}{binary-limits}{\B{limits}}
+.. |Bmut| mathdef:: \xref{binary/types}{binary-mut}{\B{mut}}
+
+
+.. Indices, non-terminals
+
+.. |Bidx| mathdef:: \xref{binary/modules}{binary-index}{\B{idx}}
+.. |Btypeidx| mathdef:: \xref{binary/modules}{binary-typeidx}{\B{typeidx}}
+.. |Bfuncidx| mathdef:: \xref{binary/modules}{binary-funcidx}{\B{funcidx}}
+.. |Btableidx| mathdef:: \xref{binary/modules}{binary-tableidx}{\B{tableidx}}
+.. |Bmemidx| mathdef:: \xref{binary/modules}{binary-memidx}{\B{memidx}}
+.. |Btagidx| mathdef:: \xref{binary/modules}{binary-tagidx}{\B{tagidx}}
+.. |Bglobalidx| mathdef:: \xref{binary/modules}{binary-globalidx}{\B{globalidx}}
+.. |Belemidx| mathdef:: \xref{binary/modules}{binary-elemidx}{\B{elemidx}}
+.. |Bdataidx| mathdef:: \xref{binary/modules}{binary-dataidx}{\B{dataidx}}
+.. |Blocalidx| mathdef:: \xref{binary/modules}{binary-localidx}{\B{localidx}}
+.. |Blabelidx| mathdef:: \xref{binary/modules}{binary-labelidx}{\B{labelidx}}
+
+
+.. Modules, non-terminals
+
+.. |Bmagic| mathdef:: \xref{binary/modules}{binary-magic}{\B{magic}}
+.. |Bversion| mathdef:: \xref{binary/modules}{binary-version}{\B{version}}
+.. |Bmodule| mathdef:: \xref{binary/modules}{binary-module}{\B{module}}
+
+.. |Bsection| mathdef:: \xref{binary/modules}{binary-section}{\B{section}}
+.. |Bcustomsec| mathdef:: \xref{binary/modules}{binary-customsec}{\B{customsec}}
+.. |Btypesec| mathdef:: \xref{binary/modules}{binary-typesec}{\B{typesec}}
+.. |Bfuncsec| mathdef:: \xref{binary/modules}{binary-funcsec}{\B{funcsec}}
+.. |Bcodesec| mathdef:: \xref{binary/modules}{binary-codesec}{\B{codesec}}
+.. |Btablesec| mathdef:: \xref{binary/modules}{binary-tablesec}{\B{tablesec}}
+.. |Bmemsec| mathdef:: \xref{binary/modules}{binary-memsec}{\B{memsec}}
+.. |Btagsec| mathdef:: \xref{binary/modules}{binary-tagsec}{\B{tagsec}}
+.. |Bglobalsec| mathdef:: \xref{binary/modules}{binary-globalsec}{\B{globalsec}}
+.. |Bimportsec| mathdef:: \xref{binary/modules}{binary-importsec}{\B{importsec}}
+.. |Bexportsec| mathdef:: \xref{binary/modules}{binary-exportsec}{\B{exportsec}}
+.. |Belemsec| mathdef:: \xref{binary/modules}{binary-elemsec}{\B{elemsec}}
+.. |Bdatasec| mathdef:: \xref{binary/modules}{binary-datasec}{\B{datasec}}
+.. |Bstartsec| mathdef:: \xref{binary/modules}{binary-startsec}{\B{startsec}}
+.. |Bdatacountsec| mathdef:: \xref{binary/modules}{binary-datacountsec}{\B{datacountsec}}
+
+.. |Bcustom| mathdef:: \xref{binary/modules}{binary-customsec}{\B{custom}}
+.. |Btype| mathdef:: \xref{binary/modules}{binary-typedef}{\B{type}}
+.. |Bfunc| mathdef:: \xref{binary/modules}{binary-func}{\B{func}}
+.. |Btable| mathdef:: \xref{binary/modules}{binary-table}{\B{table}}
+.. |Bmem| mathdef:: \xref{binary/modules}{binary-mem}{\B{mem}}
+.. |Btag| mathdef:: \xref{binary/modules}{binary-tag}{\B{tag}}
+.. |Bglobal| mathdef:: \xref{binary/modules}{binary-global}{\B{global}}
+.. |Bimport| mathdef:: \xref{binary/modules}{binary-import}{\B{import}}
+.. |Bexport| mathdef:: \xref{binary/modules}{binary-export}{\B{export}}
+.. |Bimportdesc| mathdef:: \xref{binary/modules}{binary-importdesc}{\B{importdesc}}
+.. |Bexportdesc| mathdef:: \xref{binary/modules}{binary-exportdesc}{\B{exportdesc}}
+.. |Belem| mathdef:: \xref{binary/modules}{binary-elem}{\B{elem}}
+.. |Belemkind| mathdef:: \xref{binary/modules}{binary-elemkind}{\B{elemkind}}
+.. |Bcode| mathdef:: \xref{binary/modules}{binary-code}{\B{code}}
+.. |Blocal| mathdef:: \xref{binary/modules}{binary-local}{\B{local}}
+.. |Blocals| mathdef:: \xref{binary/modules}{binary-local}{\B{locals}}
+.. |Bdata| mathdef:: \xref{binary/modules}{binary-data}{\B{data}}
+.. |Bstart| mathdef:: \xref{binary/modules}{binary-start}{\B{start}}
+
+
+.. Instructions, non-terminals
+
+.. |Bmemarg| mathdef:: \xref{binary/instructions}{binary-memarg}{\B{memarg}}
+.. |Bblocktype| mathdef:: \xref{binary/instructions}{binary-blocktype}{\B{blocktype}}
+
+.. |Binstr| mathdef:: \xref{binary/instructions}{binary-instr}{\B{instr}}
+.. |Bcatch| mathdef:: \xref{binary/instructions}{binary-catch}{\B{catch}}
+.. |Bexpr| mathdef:: \xref{binary/instructions}{binary-expr}{\B{expr}}
+
+.. |Blaneidx| mathdef:: \xref{binary/instructions}{binary-laneidx}{\B{laneidx}}
+
+
+.. Text Format
+.. -----------
+
+.. Auxiliary productions
+
+.. |Tvec| mathdef:: \xref{text/conventions}{text-vec}{\T{vec}}
+
+
+.. Lexical grammar, terminals
+
+.. |textl| mathdef:: \mbox{‘}
+.. |textr| mathdef:: \mbox{’}
+.. |text#1| mathdef:: \textl\mathtt{#1}\textr
+
+.. |Tcommentl| mathdef:: \text{{(}{;}}
+.. |Tcommentr| mathdef:: \text{{;}{)}}
+.. |Tcommentd| mathdef:: \text{{;}{;}}
+
+
+.. Lexical grammar, non-terminals
+
+.. |Tsource| mathdef:: \xref{text/lexical}{text-source}{\T{source}}
+.. |Tchar| mathdef:: \xref{text/lexical}{text-char}{\T{char}}
+.. |Tspace| mathdef:: \xref{text/lexical}{text-space}{\T{space}}
+.. |Tformat| mathdef:: \xref{text/lexical}{text-format}{\T{format}}
+
+.. |Ttoken| mathdef:: \xref{text/lexical}{text-token}{\T{token}}
+.. |Tkeyword| mathdef:: \xref{text/lexical}{text-keyword}{\T{keyword}}
+.. |Treserved| mathdef:: \xref{text/lexical}{text-reserved}{\T{reserved}}
+
+.. |Tcomment| mathdef:: \xref{text/lexical}{text-comment}{\T{comment}}
+.. |Tlinecomment| mathdef:: \xref{text/lexical}{text-comment}{\T{linecomment}}
+.. |Tblockcomment| mathdef:: \xref{text/lexical}{text-comment}{\T{blockcomment}}
+.. |Tlinechar| mathdef:: \xref{text/lexical}{text-comment}{\T{linechar}}
+.. |Tblockchar| mathdef:: \xref{text/lexical}{text-comment}{\T{blockchar}}
+
+
+.. Values, non-terminals
+
+.. |Tsign| mathdef:: \xref{text/values}{text-sign}{\T{sign}}
+.. |Tdigit| mathdef:: \xref{text/values}{text-digit}{\T{digit}}
+.. |Thexdigit| mathdef:: \xref{text/values}{text-hexdigit}{\T{hexdigit}}
+.. |Tnum| mathdef:: \xref{text/values}{text-num}{\T{num}}
+.. |Thexnum| mathdef:: \xref{text/values}{text-hexnum}{\T{hexnum}}
+.. |Tfrac| mathdef:: \xref{text/values}{text-frac}{\T{frac}}
+.. |Thexfrac| mathdef:: \xref{text/values}{text-hexfrac}{\T{hexfrac}}
+.. |Tfloat| mathdef:: \xref{text/values}{text-float}{\T{float}}
+.. |Thexfloat| mathdef:: \xref{text/values}{text-hexfloat}{\T{hexfloat}}
+
+.. |TuX#1| mathdef:: {\T{u}#1}
+.. |TsX#1| mathdef:: {\T{s}#1}
+.. |TiX#1| mathdef:: {\T{i}#1}
+.. |TfX#1| mathdef:: {\T{f}#1}
+
+.. |TuN| mathdef:: \xref{text/values}{text-int}{\TuX{N}}
+.. |Tu1| mathdef:: \xref{text/values}{text-int}{\TuX{\T{1}}}
+.. |Tu8| mathdef:: \xref{text/values}{text-int}{\TuX{\T{8}}}
+.. |Tu16| mathdef:: \xref{text/values}{text-int}{\TuX{\T{16}}}
+.. |Tu32| mathdef:: \xref{text/values}{text-int}{\TuX{\T{32}}}
+.. |Tu64| mathdef:: \xref{text/values}{text-int}{\TuX{\T{64}}}
+
+.. |TsN| mathdef:: \xref{text/values}{text-int}{\TsX{N}}
+.. |Ts32| mathdef:: \xref{text/values}{text-int}{\TsX{\T{32}}}
+.. |Ts64| mathdef:: \xref{text/values}{text-int}{\TsX{\T{64}}}
+
+.. |TiN| mathdef:: \xref{text/values}{text-int}{\TiX{N}}
+.. |Ti8| mathdef:: \xref{text/values}{text-int}{\TiX{\T{8}}}
+.. |Ti16| mathdef:: \xref{text/values}{text-int}{\TiX{\T{16}}}
+.. |Ti32| mathdef:: \xref{text/values}{text-int}{\TiX{\T{32}}}
+.. |Ti64| mathdef:: \xref{text/values}{text-int}{\TiX{\T{64}}}
+
+.. |TfN| mathdef:: \xref{text/values}{text-float}{\TfX{N}}
+.. |TfNmag| mathdef:: \xref{text/values}{text-float}{\TfX{N}\T{mag}}
+.. |Tf32| mathdef:: \xref{text/values}{text-float}{\TfX{\T{32}}}
+.. |Tf64| mathdef:: \xref{text/values}{text-float}{\TfX{\T{64}}}
+
+.. |Tstring| mathdef:: \xref{text/values}{text-string}{\T{string}}
+.. |Tstringelem| mathdef:: \xref{text/values}{text-string}{\T{stringelem}}
+.. |Tstringchar| mathdef:: \xref{text/values}{text-string}{\T{stringchar}}
+.. |Tname| mathdef:: \xref{text/values}{text-name}{\T{name}}
+
+.. |Tid| mathdef:: \xref{text/values}{text-id}{\T{id}}
+.. |Tidchar| mathdef:: \xref{text/values}{text-idchar}{\T{idchar}}
+
+
+.. Types, non-terminals
+
+.. |Tnumtype| mathdef:: \xref{text/types}{text-numtype}{\T{numtype}}
+.. |Tvectype| mathdef:: \xref{text/types}{text-vectype}{\T{vectype}}
+.. |Treftype| mathdef:: \xref{text/types}{text-reftype}{\T{reftype}}
+.. |Theaptype| mathdef:: \xref{text/types}{text-heaptype}{\T{heaptype}}
+.. |Tvaltype| mathdef:: \xref{text/types}{text-valtype}{\T{valtype}}
+.. |Tfunctype| mathdef:: \xref{text/types}{text-functype}{\T{functype}}
+
+.. |Tglobaltype| mathdef:: \xref{text/types}{text-globaltype}{\T{globaltype}}
+.. |Ttabletype| mathdef:: \xref{text/types}{text-tabletype}{\T{tabletype}}
+.. |Tmemtype| mathdef:: \xref{text/types}{text-memtype}{\T{memtype}}
+.. |Tlimits| mathdef:: \xref{text/types}{text-limits}{\T{limits}}
+
+.. |Tparam| mathdef:: \xref{text/types}{text-functype}{\T{param}}
+.. |Tresult| mathdef:: \xref{text/types}{text-functype}{\T{result}}
+
+
+.. Indices, non-terminals
+
+.. |Ttypeidx| mathdef:: \xref{text/modules}{text-typeidx}{\T{typeidx}}
+.. |Tfuncidx| mathdef:: \xref{text/modules}{text-funcidx}{\T{funcidx}}
+.. |Ttableidx| mathdef:: \xref{text/modules}{text-tableidx}{\T{tableidx}}
+.. |Tmemidx| mathdef:: \xref{text/modules}{text-memidx}{\T{memidx}}
+.. |Ttagidx| mathdef:: \xref{text/modules}{text-tagidx}{\T{tagidx}}
+.. |Tglobalidx| mathdef:: \xref{text/modules}{text-globalidx}{\T{globalidx}}
+.. |Telemidx| mathdef:: \xref{text/modules}{text-elemidx}{\T{elemidx}}
+.. |Tdataidx| mathdef:: \xref{text/modules}{text-dataidx}{\T{dataidx}}
+.. |Tlocalidx| mathdef:: \xref{text/modules}{text-localidx}{\T{localidx}}
+.. |Tlabelidx| mathdef:: \xref{text/modules}{text-labelidx}{\T{labelidx}}
+
+.. |Ttypebind| mathdef:: \xref{text/modules}{text-typebind}{\T{typebind}}
+.. |Tfuncbind| mathdef:: \xref{text/modules}{text-funcbind}{\T{funcbind}}
+.. |Ttablebind| mathdef:: \xref{text/modules}{text-tablebind}{\T{tablebind}}
+.. |Tmembind| mathdef:: \xref{text/modules}{text-membind}{\T{membind}}
+.. |Tglobalbind| mathdef:: \xref{text/modules}{text-globalbind}{\T{globalbind}}
+.. |Tlocalbind| mathdef:: \xref{text/modules}{text-localbind}{\T{localbind}}
+.. |Tlabelbind| mathdef:: \xref{text/modules}{text-labelbind}{\T{labelbind}}
+
+
+.. Modules, non-terminals
+
+.. |Tmodule| mathdef:: \xref{text/modules}{text-module}{\T{module}}
+.. |Tmodulebody| mathdef:: \xref{text/modules}{text-modulebody}{\T{modulebody}}
+.. |Tmodulefield| mathdef:: \xref{text/modules}{text-modulefield}{\T{modulefield}}
+.. |Ttype| mathdef:: \xref{text/modules}{text-typedef}{\T{type}}
+.. |Ttypeuse| mathdef:: \xref{text/modules}{text-typeuse}{\T{typeuse}}
+.. |Tfunc| mathdef:: \xref{text/modules}{text-func}{\T{func}}
+.. |Ttable| mathdef:: \xref{text/modules}{text-table}{\T{table}}
+.. |Tmem| mathdef:: \xref{text/modules}{text-mem}{\T{mem}}
+.. |Ttag| mathdef:: \xref{text/modules}{text-tag}{\T{tag}}
+.. |Tglobal| mathdef:: \xref{text/modules}{text-global}{\T{global}}
+.. |Timport| mathdef:: \xref{text/modules}{text-import}{\T{import}}
+.. |Texport| mathdef:: \xref{text/modules}{text-export}{\T{export}}
+.. |Timportdesc| mathdef:: \xref{text/modules}{text-importdesc}{\T{importdesc}}
+.. |Texportdesc| mathdef:: \xref{text/modules}{text-exportdesc}{\T{exportdesc}}
+.. |Telem| mathdef:: \xref{text/modules}{text-elem}{\T{elem}}
+.. |Telemlist| mathdef:: \xref{text/modules}{text-elemlist}{\T{elemlist}}
+.. |Telemexpr| mathdef:: \xref{text/modules}{text-elemexpr}{\T{elemexpr}}
+.. |Ttableuse| mathdef:: \xref{text/modules}{text-tableuse}{\T{tableuse}}
+.. |Tcode| mathdef:: \xref{text/modules}{text-code}{\T{code}}
+.. |Tlocal| mathdef:: \xref{text/modules}{text-local}{\T{local}}
+.. |Tlocals| mathdef:: \xref{text/modules}{text-local}{\T{locals}}
+.. |Tdata| mathdef:: \xref{text/modules}{text-data}{\T{data}}
+.. |Tdatastring| mathdef:: \xref{text/modules}{text-datastring}{\T{datastring}}
+.. |Tmemuse| mathdef:: \xref{text/modules}{text-memuse}{\T{memuse}}
+.. |Tstart| mathdef:: \xref{text/modules}{text-start}{\T{start}}
+
+
+.. Instructions, non-terminals
+
+.. |Tmemarg| mathdef:: \xref{text/instructions}{text-memarg}{\T{memarg}}
+.. |Talign| mathdef:: \xref{text/instructions}{text-memarg}{\T{align}}
+.. |Toffset| mathdef:: \xref{text/instructions}{text-memarg}{\T{offset}}
+
+.. |Tblocktype| mathdef:: \xref{text/instructions}{text-blocktype}{\T{blocktype}}
+
+.. |Tlabel| mathdef:: \xref{text/instructions}{text-label}{\T{label}}
+.. |Tinstr| mathdef:: \xref{text/instructions}{text-instr}{\T{instr}}
+.. |Tplaininstr| mathdef:: \xref{text/instructions}{text-plaininstr}{\T{plaininstr}}
+.. |Tblockinstr| mathdef:: \xref{text/instructions}{text-blockinstr}{\T{blockinstr}}
+.. |Tfoldedinstr| mathdef:: \xref{text/instructions}{text-foldedinstr}{\T{foldedinstr}}
+.. |Tcatch| mathdef:: \xref{text/instructions}{text-catch}{\T{catch}}
+.. |Texpr| mathdef:: \xref{text/instructions}{text-expr}{\T{expr}}
+
+
+
+.. Parsing
+.. -------
+
+.. Contexts
+
+.. |ITYPEDEFS| mathdef:: \xref{text/conventions}{text-context}{\K{typedefs}}
+.. |ITYPES| mathdef:: \xref{text/conventions}{text-context}{\K{types}}
+.. |IFUNCS| mathdef:: \xref{text/conventions}{text-context}{\K{funcs}}
+.. |ITABLES| mathdef:: \xref{text/conventions}{text-context}{\K{tables}}
+.. |IMEMS| mathdef:: \xref{text/conventions}{text-context}{\K{mems}}
+.. |ITAGS| mathdef:: \xref{text/conventions}{text-context}{\K{tags}}
+.. |IGLOBALS| mathdef:: \xref{text/conventions}{text-context}{\K{globals}}
+.. |IELEM| mathdef:: \xref{text/conventions}{text-context}{\K{elem}}
+.. |IDATA| mathdef:: \xref{text/conventions}{text-context}{\K{data}}
+.. |ILOCALS| mathdef:: \xref{text/conventions}{text-context}{\K{locals}}
+.. |ILABELS| mathdef:: \xref{text/conventions}{text-context}{\K{labels}}
+
+
+.. Meta Functions
+
+.. |idfresh| mathdef:: ~\xref{text/values}{text-id-fresh}{\mbox{fresh}}
+.. |idcwellformed| mathdef:: ~\xref{text/conventions}{text-context-wf}{\mbox{well-formed}}
+
+
+
+
+.. Validation
+.. ----------
+
+.. Notation
+
+.. |ok| mathdef:: \mathrel{\mbox{ok}}
+.. |const| mathdef:: \xref{valid/instructions}{valid-constant}{\mathrel{\mbox{const}}}
+
+.. Contexts, terminals
+
+.. |CTYPES| mathdef:: \xref{valid/conventions}{context}{\K{types}}
+.. |CFUNCS| mathdef:: \xref{valid/conventions}{context}{\K{funcs}}
+.. |CTABLES| mathdef:: \xref{valid/conventions}{context}{\K{tables}}
+.. |CMEMS| mathdef:: \xref{valid/conventions}{context}{\K{mems}}
+.. |CTAGS| mathdef:: \xref{valid/conventions}{context}{\K{tags}}
+.. |CGLOBALS| mathdef:: \xref{valid/conventions}{context}{\K{globals}}
+.. |CELEMS| mathdef:: \xref{valid/conventions}{context}{\K{elems}}
+.. |CDATAS| mathdef:: \xref{valid/conventions}{context}{\K{datas}}
+.. |CLOCALS| mathdef:: \xref{valid/conventions}{context}{\K{locals}}
+.. |CLABELS| mathdef:: \xref{valid/conventions}{context}{\K{labels}}
+.. |CRETURN| mathdef:: \xref{valid/conventions}{context}{\K{return}}
+.. |CREFS| mathdef:: \xref{valid/conventions}{context}{\K{refs}}
+.. |LCATCH| mathdef:: \xref{valid/conventions}{context}{\K{catch}}
+
+.. Contexts, non-terminals
+
+.. |labeltype| mathdef:: \xref{valid/conventions}{context}{\X{labeltype}}
+
+
+.. Judgments
+
+.. |vdashlimits| mathdef:: \xref{valid/types}{valid-limits}{\vdash}
+.. |vdashblocktype| mathdef:: \xref{valid/types}{valid-blocktype}{\vdash}
+.. |vdashfunctype| mathdef:: \xref{valid/types}{valid-functype}{\vdash}
+.. |vdashtabletype| mathdef:: \xref{valid/types}{valid-tabletype}{\vdash}
+.. |vdashmemtype| mathdef:: \xref{valid/types}{valid-memtype}{\vdash}
+.. |vdashtagtype| mathdef:: \xref{valid/types}{valid-tagtype}{\vdash}
+.. |vdashglobaltype| mathdef:: \xref{valid/types}{valid-globaltype}{\vdash}
+.. |vdashexterntype| mathdef:: \xref{valid/types}{valid-externtype}{\vdash}
+
+.. |vdashinstr| mathdef:: \xref{valid/instructions}{valid-instr}{\vdash}
+.. |vdashinstrseq| mathdef:: \xref{valid/instructions}{valid-instr-seq}{\vdash}
+.. |vdashcatch| mathdef:: \xref{valid/instructions}{valid-catch}{\vdash}
+.. |vdashexpr| mathdef:: \xref{valid/instructions}{valid-expr}{\vdash}
+.. |vdashexprconst| mathdef:: \xref{valid/instructions}{valid-constant}{\vdash}
+.. |vdashinstrconst| mathdef:: \xref{valid/instructions}{valid-constant}{\vdash}
+
+.. |vdashfunc| mathdef:: \xref{valid/modules}{valid-func}{\vdash}
+.. |vdashtable| mathdef:: \xref{valid/modules}{valid-table}{\vdash}
+.. |vdashmem| mathdef:: \xref{valid/modules}{valid-mem}{\vdash}
+.. |vdashtag| mathdef:: \xref{valid/modules}{valid-tag}{\vdash}
+.. |vdashglobal| mathdef:: \xref{valid/modules}{valid-global}{\vdash}
+.. |vdashelem| mathdef:: \xref{valid/modules}{valid-elem}{\vdash}
+.. |vdashelemmode| mathdef:: \xref{valid/modules}{valid-elemmode}{\vdash}
+.. |vdashdata| mathdef:: \xref{valid/modules}{valid-data}{\vdash}
+.. |vdashdatamode| mathdef:: \xref{valid/modules}{valid-datamode}{\vdash}
+.. |vdashstart| mathdef:: \xref{valid/modules}{valid-start}{\vdash}
+.. |vdashexport| mathdef:: \xref{valid/modules}{valid-export}{\vdash}
+.. |vdashexportdesc| mathdef:: \xref{valid/modules}{valid-exportdesc}{\vdash}
+.. |vdashimport| mathdef:: \xref{valid/modules}{valid-import}{\vdash}
+.. |vdashimportdesc| mathdef:: \xref{valid/modules}{valid-importdesc}{\vdash}
+.. |vdashmodule| mathdef:: \xref{valid/modules}{valid-module}{\vdash}
+
+.. |unpacked| mathdef:: \xref{valid/instructions}{aux-unpacked}{\F{unpacked}}
+.. |dim| mathdef:: \xref{valid/instructions}{aux-dim}{\F{dim}}
+
+
+.. Execution
+.. ---------
+
+.. Notation
+
+.. |stepto| mathdef:: \xref{exec/conventions}{formal-notation}{\hookrightarrow}
+.. |extendsto| mathdef:: \xref{appendix/properties}{extend}{\preceq}
+.. |matchesexterntype| mathdef:: \xref{exec/modules}{match-externtype}{\leq}
+.. |matcheslimits| mathdef:: \xref{exec/modules}{match-limits}{\leq}
+
+
+.. Allocation
+
+.. |allocfunc| mathdef:: \xref{exec/modules}{alloc-func}{\F{allocfunc}}
+.. |allochostfunc| mathdef:: \xref{exec/modules}{alloc-hostfunc}{\F{allochostfunc}}
+.. |alloctable| mathdef:: \xref{exec/modules}{alloc-table}{\F{alloctable}}
+.. |allocmem| mathdef:: \xref{exec/modules}{alloc-mem}{\F{allocmem}}
+.. |alloctag| mathdef:: \xref{exec/modules}{alloc-tag}{\F{alloctag}}
+.. |allocglobal| mathdef:: \xref{exec/modules}{alloc-global}{\F{allocglobal}}
+.. |allocelem| mathdef:: \xref{exec/modules}{alloc-elem}{\F{allocelem}}
+.. |allocdata| mathdef:: \xref{exec/modules}{alloc-data}{\F{allocdata}}
+.. |allocmodule| mathdef:: \xref{exec/modules}{alloc-module}{\F{allocmodule}}
+
+.. |growtable| mathdef:: \xref{exec/modules}{grow-table}{\F{growtable}}
+.. |growmem| mathdef:: \xref{exec/modules}{grow-mem}{\F{growmem}}
+
+
+.. Addresses, non-terminals
+
+.. |addr| mathdef:: \xref{exec/runtime}{syntax-addr}{\X{addr}}
+.. |funcaddr| mathdef:: \xref{exec/runtime}{syntax-funcaddr}{\X{funcaddr}}
+.. |tableaddr| mathdef:: \xref{exec/runtime}{syntax-tableaddr}{\X{tableaddr}}
+.. |memaddr| mathdef:: \xref{exec/runtime}{syntax-memaddr}{\X{memaddr}}
+.. |tagaddr| mathdef:: \xref{exec/runtime}{syntax-tagaddr}{\X{tagaddr}}
+.. |globaladdr| mathdef:: \xref{exec/runtime}{syntax-globaladdr}{\X{globaladdr}}
+.. |elemaddr| mathdef:: \xref{exec/runtime}{syntax-elemaddr}{\X{elemaddr}}
+.. |dataaddr| mathdef:: \xref{exec/runtime}{syntax-dataaddr}{\X{dataaddr}}
+.. |exnaddr| mathdef:: \xref{exec/runtime}{syntax-exnaddr}{\X{exnaddr}}
+.. |externaddr| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\X{externaddr}}
+
+.. Instances, terminals
+
+.. |FITYPE| mathdef:: \xref{exec/runtime}{syntax-funcinst}{\K{type}}
+.. |FIMODULE| mathdef:: \xref{exec/runtime}{syntax-funcinst}{\K{module}}
+.. |FICODE| mathdef:: \xref{exec/runtime}{syntax-funcinst}{\K{code}}
+.. |FIHOSTCODE| mathdef:: \xref{exec/runtime}{syntax-funcinst}{\K{hostcode}}
+
+.. |TITYPE| mathdef:: \xref{exec/runtime}{syntax-tableinst}{\K{type}}
+.. |TIELEM| mathdef:: \xref{exec/runtime}{syntax-tableinst}{\K{elem}}
+
+.. |MITYPE| mathdef:: \xref{exec/runtime}{syntax-meminst}{\K{type}}
+.. |MIDATA| mathdef:: \xref{exec/runtime}{syntax-meminst}{\K{data}}
+
+.. |TAGITYPE| mathdef:: \xref{exec/runtime}{syntax-taginst}{\K{type}}
+
+.. |GITYPE| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\K{type}}
+.. |GIVALUE| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\K{value}}
+
+.. |EITYPE| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\K{type}}
+.. |EIELEM| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\K{elem}}
+
+.. |DIDATA| mathdef:: \xref{exec/runtime}{syntax-datainst}{\K{data}}
+
+.. |EITAG| mathdef:: \xref{exec/runtime}{syntax-exninst}{\K{tag}}
+.. |EIFIELDS| mathdef:: \xref{exec/runtime}{syntax-exninst}{\K{fields}}
+
+.. |EINAME| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{name}}
+.. |EIVALUE| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{value}}
+
+.. |EVFUNC| mathdef:: \xref{exec/runtime}{syntax-externval}{\K{func}}
+.. |EVTABLE| mathdef:: \xref{exec/runtime}{syntax-externval}{\K{table}}
+.. |EVMEM| mathdef:: \xref{exec/runtime}{syntax-externval}{\K{mem}}
+.. |EVTAG| mathdef:: \xref{exec/runtime}{syntax-externval}{\K{tag}}
+.. |EVGLOBAL| mathdef:: \xref{exec/runtime}{syntax-externval}{\K{global}}
+
+.. |MITYPES| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{types}}
+.. |MIFUNCS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{funcaddrs}}
+.. |MITABLES| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{tableaddrs}}
+.. |MIMEMS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{memaddrs}}
+.. |MITAGS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{tagaddrs}}
+.. |MIGLOBALS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{globaladdrs}}
+.. |MIELEMS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{elemaddrs}}
+.. |MIDATAS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{dataaddrs}}
+.. |MIEXPORTS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{exports}}
+
+
+.. Instances, non-terminals
+
+.. |externval| mathdef:: \xref{exec/runtime}{syntax-externval}{\X{externval}}
+
+.. |moduleinst| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\X{moduleinst}}
+.. |funcinst| mathdef:: \xref{exec/runtime}{syntax-funcinst}{\X{funcinst}}
+.. |tableinst| mathdef:: \xref{exec/runtime}{syntax-tableinst}{\X{tableinst}}
+.. |meminst| mathdef:: \xref{exec/runtime}{syntax-meminst}{\X{meminst}}
+.. |taginst| mathdef:: \xref{exec/runtime}{syntax-taginst}{\X{taginst}}
+.. |globalinst| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\X{globalinst}}
+.. |eleminst| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\X{eleminst}}
+.. |datainst| mathdef:: \xref{exec/runtime}{syntax-datainst}{\X{datainst}}
+.. |exninst| mathdef:: \xref{exec/runtime}{syntax-exninst}{\X{exninst}}
+.. |exportinst| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\X{exportinst}}
+
+.. |hostfunc| mathdef:: \xref{exec/runtime}{syntax-hostfunc}{\X{hostfunc}}
+
+
+.. Instances, meta functions
+
+.. |evfuncs| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{funcs}}
+.. |evtables| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{tables}}
+.. |evmems| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{mems}}
+.. |evtags| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{tags}}
+.. |evglobals| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{globals}}
+
+
+.. Store, terminals
+
+.. |SFUNCS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{funcs}}
+.. |STABLES| mathdef:: \xref{exec/runtime}{syntax-store}{\K{tables}}
+.. |SMEMS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{mems}}
+.. |STAGS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{tags}}
+.. |SGLOBALS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{globals}}
+.. |SELEMS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{elems}}
+.. |SDATAS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{datas}}
+.. |SEXNS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{exns}}
+
+.. Store, non-terminals
+
+.. |store| mathdef:: \xref{exec/runtime}{syntax-store}{\X{store}}
+
+
+.. Stack, terminals
+
+.. |LABEL| mathdef:: \xref{exec/runtime}{syntax-label}{\K{label}}
+.. |FRAME| mathdef:: \xref{exec/runtime}{syntax-frame}{\K{frame}}
+
+.. |ALOCALS| mathdef:: \xref{exec/runtime}{syntax-frame}{\K{locals}}
+.. |AMODULE| mathdef:: \xref{exec/runtime}{syntax-frame}{\K{module}}
+
+
+.. Stack, non-terminals
+
+.. |label| mathdef:: \xref{exec/runtime}{syntax-label}{\X{label}}
+.. |frame| mathdef:: \xref{exec/runtime}{syntax-frame}{\X{frame}}
+.. |handler| mathdef:: \xref{exec/runtime}{syntax-handler}{\X{handler}}
+
+.. Stack, meta functions
+
+.. |expand| mathdef:: \xref{exec/runtime}{exec-expand}{\F{expand}}
+
+
+.. Administrative Instructions, terminals
+
+.. |REFFUNCADDR| mathdef:: \xref{exec/runtime}{syntax-ref}{\K{ref}}
+.. |REFEXNADDR| mathdef:: \xref{exec/runtime}{syntax-ref.exn-addr}{\K{ref{.}exn}}
+.. |REFEXTERNADDR| mathdef:: \xref{exec/runtime}{syntax-ref.extern-addr}{\K{ref{.}extern}}
+.. |TRAP| mathdef:: \xref{exec/runtime}{syntax-trap}{\K{trap}}
+.. |INVOKE| mathdef:: \xref{exec/runtime}{syntax-invoke}{\K{invoke}}
+.. |HANDLER| mathdef:: \xref{exec/runtime}{syntax-handler}{\K{handler}}
+.. |CAUGHT| mathdef:: \xref{exec/runtime}{syntax-caught}{\K{caught}}
+
+
+.. Values & Results, non-terminals
+
+.. |num| mathdef:: \xref{exec/runtime}{syntax-num}{\X{num}}
+.. |vecc| mathdef:: \xref{exec/runtime}{syntax-vec}{\X{vec}}
+.. |reff| mathdef:: \xref{exec/runtime}{syntax-ref}{\X{ref}}
+.. |val| mathdef:: \xref{exec/runtime}{syntax-val}{\X{val}}
+.. |result| mathdef:: \xref{exec/runtime}{syntax-result}{\X{result}}
+
+
+.. Values, meta-functions
+
+.. |default| mathdef:: \xref{exec/runtime}{default-val}{\F{default}}
+
+
+.. Administrative Instructions, non-terminals
+
+.. |XB| mathdef:: \xref{exec/runtime}{syntax-ctxt-block}{B}
+.. |XC| mathdef:: \xref{exec/runtime}{syntax-ctxt-block}{C}
+.. |XT| mathdef:: \xref{exec/runtime}{syntax-ctxt-throw}{T}
+
+
+.. Configurations, non-terminals
+
+.. |config| mathdef:: \xref{exec/runtime}{syntax-config}{\X{config}}
+.. |thread| mathdef:: \xref{exec/runtime}{syntax-thread}{\X{thread}}
+
+
+.. Numerics, operators
+
+.. |iadd| mathdef:: \xref{exec/numerics}{op-iadd}{\F{iadd}}
+.. |isub| mathdef:: \xref{exec/numerics}{op-isub}{\F{isub}}
+.. |imul| mathdef:: \xref{exec/numerics}{op-imul}{\F{imul}}
+.. |idivu| mathdef:: \xref{exec/numerics}{op-idiv_u}{\F{idiv\_u}}
+.. |idivs| mathdef:: \xref{exec/numerics}{op-idiv_s}{\F{idiv\_s}}
+.. |iremu| mathdef:: \xref{exec/numerics}{op-irem_u}{\F{irem\_u}}
+.. |irems| mathdef:: \xref{exec/numerics}{op-irem_s}{\F{irem\_s}}
+.. |inot| mathdef:: \xref{exec/numerics}{op-inot}{\F{inot}}
+.. |iand| mathdef:: \xref{exec/numerics}{op-iand}{\F{iand}}
+.. |iandnot| mathdef:: \xref{exec/numerics}{op-iandnot}{\F{iandnot}}
+.. |ior| mathdef:: \xref{exec/numerics}{op-ior}{\F{ior}}
+.. |ixor| mathdef:: \xref{exec/numerics}{op-ixor}{\F{ixor}}
+.. |ishl| mathdef:: \xref{exec/numerics}{op-ishl}{\F{ishl}}
+.. |ishru| mathdef:: \xref{exec/numerics}{op-ishr_u}{\F{ishr\_u}}
+.. |ishrs| mathdef:: \xref{exec/numerics}{op-ishr_s}{\F{ishr\_s}}
+.. |irotl| mathdef:: \xref{exec/numerics}{op-irotl}{\F{irotl}}
+.. |irotr| mathdef:: \xref{exec/numerics}{op-irotr}{\F{irotr}}
+.. |iclz| mathdef:: \xref{exec/numerics}{op-iclz}{\F{iclz}}
+.. |ictz| mathdef:: \xref{exec/numerics}{op-ictz}{\F{ictz}}
+.. |ipopcnt| mathdef:: \xref{exec/numerics}{op-ipopcnt}{\F{ipopcnt}}
+.. |ieqz| mathdef:: \xref{exec/numerics}{op-ieqz}{\F{ieqz}}
+.. |ieq| mathdef:: \xref{exec/numerics}{op-ieq}{\F{ieq}}
+.. |ine| mathdef:: \xref{exec/numerics}{op-ine}{\F{ine}}
+.. |iltu| mathdef:: \xref{exec/numerics}{op-ilt_u}{\F{ilt\_u}}
+.. |ilts| mathdef:: \xref{exec/numerics}{op-ilt_s}{\F{ilt\_s}}
+.. |igtu| mathdef:: \xref{exec/numerics}{op-igt_u}{\F{igt\_u}}
+.. |igts| mathdef:: \xref{exec/numerics}{op-igt_s}{\F{igt\_s}}
+.. |ileu| mathdef:: \xref{exec/numerics}{op-ile_u}{\F{ile\_u}}
+.. |iles| mathdef:: \xref{exec/numerics}{op-ile_s}{\F{ile\_s}}
+.. |igeu| mathdef:: \xref{exec/numerics}{op-ige_u}{\F{ige\_u}}
+.. |iges| mathdef:: \xref{exec/numerics}{op-ige_s}{\F{ige\_s}}
+.. |iextendMs| mathdef:: \xref{exec/numerics}{op-iextendn_s}{\F{iextend}M\F{\_s}}
+.. |ibitselect| mathdef:: \xref{exec/numerics}{op-ibitselect}{\F{ibitselect}}
+.. |iabs| mathdef:: \xref{exec/numerics}{op-iabs}{\F{iabs}}
+.. |ineg| mathdef:: \xref{exec/numerics}{op-ineg}{\F{ineg}}
+.. |iminu| mathdef:: \xref{exec/numerics}{op-imin_u}{\F{imin\_u}}
+.. |imins| mathdef:: \xref{exec/numerics}{op-imin_s}{\F{imin\_s}}
+.. |imaxu| mathdef:: \xref{exec/numerics}{op-imax_u}{\F{imax\_u}}
+.. |imaxs| mathdef:: \xref{exec/numerics}{op-imax_s}{\F{imax\_s}}
+.. |iaddsatu| mathdef:: \xref{exec/numerics}{op-iaddsat_u}{\F{iaddsat\_u}}
+.. |iaddsats| mathdef:: \xref{exec/numerics}{op-iaddsat_s}{\F{iaddsat\_s}}
+.. |isubsatu| mathdef:: \xref{exec/numerics}{op-isubsat_u}{\F{isubsat\_u}}
+.. |isubsats| mathdef:: \xref{exec/numerics}{op-isubsat_s}{\F{isubsat\_s}}
+.. |iavgru| mathdef:: \xref{exec/numerics}{op-iavgr_u}{\F{iavgr\_u}}
+.. |iq15mulrsats| mathdef:: \xref{exec/numerics}{op-iq15mulrsat_s}{\F{iq15mulrsat\_s}}
+
+.. |fadd| mathdef:: \xref{exec/numerics}{op-fadd}{\F{fadd}}
+.. |fsub| mathdef:: \xref{exec/numerics}{op-fsub}{\F{fsub}}
+.. |fmul| mathdef:: \xref{exec/numerics}{op-fmul}{\F{fmul}}
+.. |fdiv| mathdef:: \xref{exec/numerics}{op-fdiv}{\F{fdiv}}
+.. |fmin| mathdef:: \xref{exec/numerics}{op-fmin}{\F{fmin}}
+.. |fmax| mathdef:: \xref{exec/numerics}{op-fmax}{\F{fmax}}
+.. |fcopysign| mathdef:: \xref{exec/numerics}{op-fcopysign}{\F{fcopysign}}
+.. |fabs| mathdef:: \xref{exec/numerics}{op-fabs}{\F{fabs}}
+.. |fneg| mathdef:: \xref{exec/numerics}{op-fneg}{\F{fneg}}
+.. |fsqrt| mathdef:: \xref{exec/numerics}{op-fsqrt}{\F{fsqrt}}
+.. |fceil| mathdef:: \xref{exec/numerics}{op-fceil}{\F{fceil}}
+.. |ffloor| mathdef:: \xref{exec/numerics}{op-ffloor}{\F{ffloor}}
+.. |ftrunc| mathdef:: \xref{exec/numerics}{op-ftrunc}{\F{ftrunc}}
+.. |fnearest| mathdef:: \xref{exec/numerics}{op-fnearest}{\F{fnearest}}
+.. |feq| mathdef:: \xref{exec/numerics}{op-feq}{\F{feq}}
+.. |fne| mathdef:: \xref{exec/numerics}{op-fne}{\F{fne}}
+.. |flt| mathdef:: \xref{exec/numerics}{op-flt}{\F{flt}}
+.. |fgt| mathdef:: \xref{exec/numerics}{op-fgt}{\F{fgt}}
+.. |fle| mathdef:: \xref{exec/numerics}{op-fle}{\F{fle}}
+.. |fge| mathdef:: \xref{exec/numerics}{op-fge}{\F{fge}}
+.. |fpmin| mathdef:: \xref{exec/numerics}{op-fpmin}{\F{fpmin}}
+.. |fpmax| mathdef:: \xref{exec/numerics}{op-fpmax}{\F{fpmax}}
+
+.. |extend| mathdef:: \xref{exec/numerics}{op-extend_u}{\F{extend}}
+.. |extendu| mathdef:: \xref{exec/numerics}{op-extend_u}{\F{extend}^{\K{u}}}
+.. |extends| mathdef:: \xref{exec/numerics}{op-extend_s}{\F{extend}^{\K{s}}}
+.. |wrap| mathdef:: \xref{exec/numerics}{op-wrap}{\F{wrap}}
+.. |truncu| mathdef:: \xref{exec/numerics}{op-trunc_u}{\F{trunc}^{\K{u}}}
+.. |truncs| mathdef:: \xref{exec/numerics}{op-trunc_s}{\F{trunc}^{\K{s}}}
+.. |truncsatu| mathdef:: \xref{exec/numerics}{op-trunc_sat_u}{\F{trunc\_sat\_u}}
+.. |truncsats| mathdef:: \xref{exec/numerics}{op-trunc_sat_s}{\F{trunc\_sat\_s}}
+.. |promote| mathdef:: \xref{exec/numerics}{op-promote}{\F{promote}}
+.. |demote| mathdef:: \xref{exec/numerics}{op-demote}{\F{demote}}
+.. |convertu| mathdef:: \xref{exec/numerics}{op-convert_u}{\F{convert}^{\K{u}}}
+.. |converts| mathdef:: \xref{exec/numerics}{op-convert_s}{\F{convert}^{\K{s}}}
+.. |reinterpret| mathdef:: \xref{exec/numerics}{op-reinterpret}{\F{reinterpret}}
+.. |narrow| mathdef:: \xref{exec/numerics}{op-narrow_u}{\F{narrow}}
+.. |narrowu| mathdef:: \xref{exec/numerics}{op-narrow_u}{\F{narrow}^{\K{u}}}
+.. |narrows| mathdef:: \xref{exec/numerics}{op-narrow_s}{\F{narrow}^{\K{s}}}
+
+
+.. Numerics, meta functions
+
+.. |bits| mathdef:: \xref{exec/numerics}{aux-bits}{\F{bits}}
+.. |ibits| mathdef:: \xref{exec/numerics}{aux-ibits}{\F{ibits}}
+.. |fbits| mathdef:: \xref{exec/numerics}{aux-fbits}{\F{fbits}}
+.. |fsign| mathdef:: \xref{exec/numerics}{aux-fsign}{\F{fsign}}
+.. |fbias| mathdef:: \xref{exec/numerics}{aux-fbias}{\F{fbias}}
+.. |bytes| mathdef:: \xref{exec/numerics}{aux-bytes}{\F{bytes}}
+.. |littleendian| mathdef:: \xref{exec/numerics}{aux-littleendian}{\F{littleendian}}
+.. |signed| mathdef:: \xref{exec/numerics}{aux-signed}{\F{signed}}
+.. |bool| mathdef:: \xref{exec/numerics}{aux-bool}{\F{bool}}
+
+.. |ieee| mathdef:: \xref{exec/numerics}{aux-ieee}{\F{float}}
+.. |nans| mathdef:: \xref{exec/numerics}{aux-nans}{\F{nans}}
+.. |trunc| mathdef:: \xref{exec/numerics}{aux-trunc}{\F{trunc}}
+.. |satu| mathdef:: \xref{exec/numerics}{aux-sat_u}{\F{sat}^{\K{u}}}
+.. |sats| mathdef:: \xref{exec/numerics}{aux-sat_s}{\F{sat}^{\K{s}}}
+
+.. |lanes| mathdef:: \xref{exec/numerics}{aux-lanes}{\F{lanes}}
+
+
+.. Other meta functions
+
+.. |instantiate| mathdef:: \xref{exec/modules}{exec-instantiation}{\F{instantiate}}
+.. |invoke| mathdef:: \xref{exec/modules}{exec-invocation}{\F{invoke}}
+
+
+.. Judgements
+
+.. |vdashexternval| mathdef:: \xref{exec/modules}{valid-externval}{\vdash}
+
+.. |vdashlimitsmatch| mathdef:: \xref{exec/modules}{match-limits}{\vdash}
+.. |vdashexterntypematch| mathdef:: \xref{exec/modules}{match-externtype}{\vdash}
+
+
+.. Soundness
+.. ---------
+
+.. Judgements
+
+.. |vdashadmininstr| mathdef:: \xref{appendix/properties}{valid-instr-admin}{\vdash}
+
+.. |vdashval| mathdef:: \xref{appendix/properties}{valid-val}{\vdash}
+.. |vdashresult| mathdef:: \xref{appendix/properties}{valid-result}{\vdash}
+
+.. |vdashfuncinst| mathdef:: \xref{appendix/properties}{valid-funcinst}{\vdash}
+.. |vdashtableinst| mathdef:: \xref{appendix/properties}{valid-tableinst}{\vdash}
+.. |vdashmeminst| mathdef:: \xref{appendix/properties}{valid-meminst}{\vdash}
+.. |vdashtaginst| mathdef:: \xref{appendix/properties}{valid-taginst}{\vdash}
+.. |vdashglobalinst| mathdef:: \xref{appendix/properties}{valid-globalinst}{\vdash}
+.. |vdasheleminst| mathdef:: \xref{appendix/properties}{valid-eleminst}{\vdash}
+.. |vdashdatainst| mathdef:: \xref{appendix/properties}{valid-datainst}{\vdash}
+.. |vdashexninst| mathdef:: \xref{appendix/properties}{valid-exninst}{\vdash}
+.. |vdashexportinst| mathdef:: \xref{appendix/properties}{valid-exportinst}{\vdash}
+.. |vdashmoduleinst| mathdef:: \xref{appendix/properties}{valid-moduleinst}{\vdash}
+
+.. |vdashstore| mathdef:: \xref{appendix/properties}{valid-store}{\vdash}
+.. |vdashconfig| mathdef:: \xref{appendix/properties}{valid-config}{\vdash}
+.. |vdashthread| mathdef:: \xref{appendix/properties}{valid-thread}{\vdash}
+.. |vdashframe| mathdef:: \xref{appendix/properties}{valid-frame}{\vdash}
+
+.. |vdashfuncinstextends| mathdef:: \xref{appendix/properties}{extend-funcinst}{\vdash}
+.. |vdashtableinstextends| mathdef:: \xref{appendix/properties}{extend-tableinst}{\vdash}
+.. |vdashmeminstextends| mathdef:: \xref{appendix/properties}{extend-meminst}{\vdash}
+.. |vdashtaginstextends| mathdef:: \xref{appendix/properties}{extend-taginst}{\vdash}
+.. |vdashglobalinstextends| mathdef:: \xref{appendix/properties}{extend-globalinst}{\vdash}
+.. |vdasheleminstextends| mathdef:: \xref{appendix/properties}{extend-eleminst}{\vdash}
+.. |vdashdatainstextends| mathdef:: \xref{appendix/properties}{extend-datainst}{\vdash}
+.. |vdashexninstextends| mathdef:: \xref{appendix/properties}{extend-exninst}{\vdash}
+.. |vdashstoreextends| mathdef:: \xref{appendix/properties}{extend-store}{\vdash}
+
+
+.. Custom Sections
+.. ---------------
+
+.. Name section, non-terminals
+
+.. |Bnamesec| mathdef:: \xref{appendix/custom}{binary-namesubsection}{\B{namesec}}
+.. |Bnamedata| mathdef:: \xref{appendix/custom}{binary-namesubsection}{\B{namedata}}
+.. |Bnamesubsection| mathdef:: \xref{appendix/custom}{binary-namesubsection}{\B{namesubsection}}
+
+.. |Bnamemap| mathdef:: \xref{appendix/custom}{binary-namemap}{\B{namemap}}
+.. |Bnameassoc| mathdef:: \xref{appendix/custom}{binary-namemap}{\B{nameassoc}}
+.. |Bindirectnamemap| mathdef:: \xref{appendix/custom}{binary-indirectnamemap}{\B{indirectnamemap}}
+.. |Bindirectnameassoc| mathdef:: \xref{appendix/custom}{binary-indirectnamemap}{\B{indirectnameassoc}}
+
+.. |Bmodulenamesubsec| mathdef:: \xref{appendix/custom}{binary-modulenamesec}{\B{modulenamesubsec}}
+.. |Bfuncnamesubsec| mathdef:: \xref{appendix/custom}{binary-funcnamesec}{\B{funcnamesubsec}}
+.. |Blocalnamesubsec| mathdef:: \xref{appendix/custom}{binary-localnamesec}{\B{localnamesubsec}}
+.. |Btagnamesubsec| mathdef:: \xref{appendix/custom}{binary-tagnamesec}{\B{tagnamesubsec}}
+
+
+.. Embedding
+.. ---------
+
+.. |error| mathdef:: \xref{appendix/embedding}{embed-error}{\X{error}}
+.. |ERROR| mathdef:: \xref{appendix/embedding}{embed-error}{\K{error}}
diff --git a/document/legacy/exceptions/util/mathdef.py b/document/legacy/exceptions/util/mathdef.py
new file mode 100644
index 00000000..a10fc458
--- /dev/null
+++ b/document/legacy/exceptions/util/mathdef.py
@@ -0,0 +1,122 @@
+from sphinx.directives.patches import MathDirective
+from sphinx.util.texescape import tex_replace_map
+from sphinx.writers.html5 import HTML5Translator
+from sphinx.writers.latex import LaTeXTranslator
+from docutils import nodes
+from docutils.nodes import math
+from docutils.parsers.rst.directives.misc import Replace
+from six import text_type
+import re
+
+
+# Transform \xref in math nodes
+
+xref_re = re.compile('\\\\xref\{([^}]*)\}\{([^}]*)\}', re.M)
+
+def html_hyperlink(file, id):
+ return '\\href{../%s.html#%s}' % (file, id.replace('_', '-'))
+
+def html_transform_math_xref(node):
+ new_text = xref_re.sub(lambda m: html_hyperlink(m.group(1), m.group(2)), node.astext())
+ node.children[0] = nodes.Text(new_text)
+
+# Mirrors sphinx/writers/latex
+def latex_hyperlink(file, id):
+ id = text_type(id).translate(tex_replace_map).\
+ encode('ascii', 'backslashreplace').decode('ascii').\
+ replace('_', '-').replace('\\', '_')
+ return '\\hyperref[%s:%s]' % (file, id)
+
+def latex_transform_math_xref(node):
+ new_text = xref_re.sub(lambda m: latex_hyperlink(m.group(1), m.group(2)), node.astext())
+ node.children[0] = nodes.Text(new_text)
+
+# Expand mathdef names in math roles and directives
+
+def_re = re.compile('\\\\[A-Za-z][0-9A-Za-z]*', re.M)
+
+auxcounter = 0
+
+def lookup_mathdef(defs, name):
+ if name in defs:
+ [arity, s] = defs[name]
+ if arity > 0:
+ global auxcounter
+ auxcounter = auxcounter + 1
+ name = "\\mathdef%d" % auxcounter
+ s = "\\def%s#%d{%s}%s" % (name, arity, s, name)
+ return s
+ return name
+
+def replace_mathdefs(doc, s):
+ if not hasattr(doc, 'mathdefs'):
+ return s
+ return def_re.sub(lambda m: lookup_mathdef(doc.mathdefs, m.group(0)), s)
+
+def ext_math_role(role, raw, text, line, inliner, options = {}, content = []):
+ text = replace_mathdefs(inliner.document, raw.split('`')[1])
+ return [math(raw, text)], []
+
+class ExtMathDirective(MathDirective):
+ def run(self):
+ doc = self.state.document
+ for i, s in enumerate(self.content):
+ self.content[i] = replace_mathdefs(doc, s)
+ for i, s in enumerate(self.arguments):
+ self.arguments[i] = replace_mathdefs(doc, s)
+ return super().run()
+
+class MathdefDirective(Replace):
+ def run(self):
+ name = '\\' + self.state.parent.rawsource.split('|')[1]
+ name = name.split('#')
+ if len(name) > 1:
+ arity = int(name[1])
+ else:
+ arity = 0
+ name = name[0]
+ doc = self.state.document
+ if not hasattr(doc, 'mathdefs'):
+ doc.mathdefs = {}
+ # TODO: we don't ever hit the case where len(self.content) > 1
+ for i, s in enumerate(self.content):
+ self.content[i] = replace_mathdefs(doc, s)
+ doc.mathdefs[name] = [arity, ''.join(self.content)]
+ self.content[0] = ':math:`' + self.content[0]
+ self.content[-1] = self.content[-1] + '`'
+ return super().run()
+
+class WebAssemblyHTML5Translator(HTML5Translator):
+ """
+ Customize HTML5Translator.
+ Convert xref in math and math block nodes to hrefs.
+ """
+ def visit_math(self, node, math_env = ''):
+ html_transform_math_xref(node)
+ super().visit_math(node, math_env)
+
+ def visit_math_block(self, node, math_env = ''):
+ html_transform_math_xref(node)
+ super().visit_math_block(node, math_env)
+
+class WebAssemblyLaTeXTranslator(LaTeXTranslator):
+ """
+ Customize LaTeXTranslator.
+ Convert xref in math and math block nodes to hyperrefs.
+ """
+ def visit_math(self, node):
+ latex_transform_math_xref(node)
+ super().visit_math(node)
+
+ def visit_math_block(self, node):
+ latex_transform_math_xref(node)
+ super().visit_math_block(node)
+
+# Setup
+
+def setup(app):
+ app.set_translator('html', WebAssemblyHTML5Translator)
+ app.set_translator('latex', WebAssemblyLaTeXTranslator)
+ app.add_role('math', ext_math_role)
+ app.add_directive('math', ExtMathDirective, override = True)
+ app.add_directive('mathdef', MathdefDirective)
diff --git a/document/legacy/exceptions/util/pseudo-lexer.py b/document/legacy/exceptions/util/pseudo-lexer.py
new file mode 100644
index 00000000..fd3a251d
--- /dev/null
+++ b/document/legacy/exceptions/util/pseudo-lexer.py
@@ -0,0 +1,32 @@
+from pygments.lexer import RegexLexer
+from pygments.token import *
+from sphinx.highlighting import lexers
+
+class PseudoLexer(RegexLexer):
+ name = 'Pseudo'
+ aliases = ['pseudo']
+ filenames = ['*.pseudo']
+
+ tokens = {
+ 'root': [
+ (r"(?` must be :ref:`valid ` as some :ref:`function type ` :math:`[t_1^\ast] \to [t_2^\ast]`.
+
+* Let :math:`C'` be the same :ref:`context ` as :math:`C`, but with the :ref:`label type ` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
+
+* Under context :math:`C'`,
+ the instruction sequence :math:`\instr_1^\ast` must be :ref:`valid ` with type :math:`[t_1^\ast] \to [t_2^\ast]`.
+
+* Let :math:`C''` be the same :ref:`context ` as :math:`C`, but with the :ref:`label type ` :math:`\LCATCH~[t_2^\ast]` prepended to the |CLABELS| vector.
+
+* For every :math:`x_i` and :math:`\instr_{2i}^\ast` in :math:`(\CATCH~x~\instr_2^\ast)^\ast`:
+
+ * The tag :math:`C.\CTAGS[x_i]` must be defined in the context :math:`C`.
+
+ * Let :math:`[t_{3i}^\ast] \to [t_{4i}^\ast]` be the :ref:`tag type ` :math:`C.\CTAGS[x_i]`.
+
+ * The :ref:`result type ` :math:`[t_{4i}^\ast]` must be empty.
+
+ * Under context :math:`C''`,
+ the instruction sequence :math:`\instr_{2i}^\ast` must be :ref:`valid ` with type :math:`[t_{3i}^\ast] \to [t_2^\ast]`.
+
+* If :math:`(\CATCHALL~\instr_3^\ast)^?` is not empty, then:
+
+ * Under context :math:`C''`,
+ the instruction sequence :math:`\instr_3^\ast` must be :ref:`valid ` with type :math:`[] \to [t_2^\ast]`.
+
+* Then the compound instruction is valid with type :math:`[t_1^\ast] \to [t_2^\ast]`.
+
+.. math::
+ \frac{
+ \begin{array}{c}
+ C \vdashblocktype \blocktype : [t_1^\ast] \to [t_2^\ast]
+ \qquad
+ C,\CLABELS\,[t_2^\ast] \vdashinstrseq \instr_1^\ast : [t_1^\ast] \to [t_2^\ast] \\
+ (C.\CTAGS[x] = [t^\ast] \to [])^\ast \\
+ C,\CLABELS\,(\LCATCH~[t_2^\ast]) \vdashinstrseq \instr_2^\ast : [t^\ast] \to [t_2^\ast])^\ast \\
+ (C,\CLABELS\,(\LCATCH~[t_2^\ast]) \vdashinstrseq \instr_3^\ast : [] \to [t_2^\ast])^?
+ \end{array}
+ }{
+ C \vdashinstr \TRY~\blocktype~\instr_1^\ast~(\CATCH~x~\instr_2^\ast)^\ast~(\CATCHALL~\instr_3^\ast)^?~\END : [t_1^\ast] \to [t_2^\ast]
+ }
+
+
+.. note::
+ The :ref:`notation ` :math:`C,\CLABELS\,(\LCATCH^?~[t^\ast])` inserts the new label type at index :math:`0`, shifting all others.
+
+
+.. _valid-try-delegate:
+
+:math:`\TRY~\blocktype~\instr^\ast~\DELEGATE~l`
+...............................................
+
+* The label :math:`C.\CLABELS[l]` must be defined in the context.
+
+* The :ref:`block type ` must be :ref:`valid ` as some :ref:`function type ` :math:`[t_1^\ast] \to [t_2^\ast]`.
+
+* Let :math:`C'` be the same :ref:`context ` as :math:`C`, but with the :ref:`result type ` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
+
+* Under context :math:`C'`,
+ the instruction sequence :math:`\instr^\ast` must be :ref:`valid ` with type :math:`[t_1^\ast] \to [t_2^\ast]`.
+
+* Then the compound instruction is valid with type :math:`[t_1^\ast] \to [t_2^\ast]`.
+
+.. math::
+ \frac{
+ C \vdashblocktype \blocktype : [t_1^\ast] \to [t_2^\ast]
+ \qquad
+ C,\CLABELS\,[t_2^\ast] \vdashinstrseq \instr^\ast : [t_1^\ast]\to[t_2^\ast]
+ \qquad
+ C.\CLABELS[l] = [t_0^\ast]
+ }{
+ C \vdashinstrseq \TRY~\blocktype~\instr^\ast~\DELEGATE~l : [t_1^\ast]\to[t_2^\ast]
+ }
+
+.. note::
+ The :ref:`label index ` space in the :ref:`context ` :math:`C` contains the most recent label first, so that :math:`C.\CLABELS[l]` performs a relative lookup as expected.
+
+
+.. _valid-rethrow:
+
+:math:`\RETHROW~l`
+..................
+
+* The label :math:`C.\CLABELS[l]` must be defined in the context.
+
+* Let :math:`(\LCATCH^?~[t^\ast])` be the :ref:`label type ` :math:`C.\CLABELS[l]`.
+
+* The |LCATCH| must be present in the :ref:`label type ` :math:`C.\CLABELS[l]`.
+
+* Then the instruction is valid with type :math:`[t_1^\ast] \to [t_2^\ast]`, for any sequences of :ref:`value types ` :math:`t_1^\ast` and :math:`t_2^\ast`.
+
+
+.. math::
+ \frac{
+ C.\CLABELS[l] = \LCATCH~[t^\ast]
+ }{
+ C \vdashinstr \RETHROW~l : [t_1^\ast] \to [t_2^\ast]
+ }
+
+
+.. note::
+ The |RETHROW| instruction is stack-polymorphic.
diff --git a/test/legacy/exceptions/rethrow.wast b/test/legacy/exceptions/rethrow.wast
new file mode 100644
index 00000000..e41d94b2
--- /dev/null
+++ b/test/legacy/exceptions/rethrow.wast
@@ -0,0 +1,96 @@
+;; Test rethrow instruction.
+
+(module
+ (tag $e0)
+ (tag $e1)
+
+ (func (export "catch-rethrow-0")
+ (try
+ (do (throw $e0))
+ (catch $e0 (rethrow 0))
+ )
+ )
+
+ (func (export "catch-rethrow-1") (param i32) (result i32)
+ (try (result i32)
+ (do (throw $e0))
+ (catch $e0
+ (if (i32.eqz (local.get 0)) (then (rethrow 1))) (i32.const 23)
+ )
+ )
+ )
+
+ (func (export "catchall-rethrow-0")
+ (try
+ (do (throw $e0))
+ (catch_all (rethrow 0))
+ )
+ )
+
+ (func (export "catchall-rethrow-1") (param i32) (result i32)
+ (try (result i32)
+ (do (throw $e0))
+ (catch_all
+ (if (i32.eqz (local.get 0)) (then (rethrow 1))) (i32.const 23)
+ )
+ )
+ )
+
+ (func (export "rethrow-nested") (param i32) (result i32)
+ (try (result i32)
+ (do (throw $e1))
+ (catch $e1
+ (try (result i32)
+ (do (throw $e0))
+ (catch $e0
+ (if (i32.eq (local.get 0) (i32.const 0)) (then (rethrow 1)))
+ (if (i32.eq (local.get 0) (i32.const 1)) (then (rethrow 2)))
+ (i32.const 23)
+ )
+ )
+ )
+ )
+ )
+
+ (func (export "rethrow-recatch") (param i32) (result i32)
+ (try (result i32)
+ (do (throw $e0))
+ (catch $e0
+ (try (result i32)
+ (do (if (i32.eqz (local.get 0)) (then (rethrow 2))) (i32.const 42))
+ (catch $e0 (i32.const 23))
+ )
+ )
+ )
+ )
+
+ (func (export "rethrow-stack-polymorphism")
+ (try
+ (do (throw $e0))
+ (catch $e0 (i32.const 1) (rethrow 0))
+ )
+ )
+)
+
+(assert_exception (invoke "catch-rethrow-0"))
+
+(assert_exception (invoke "catch-rethrow-1" (i32.const 0)))
+(assert_return (invoke "catch-rethrow-1" (i32.const 1)) (i32.const 23))
+
+(assert_exception (invoke "catchall-rethrow-0"))
+
+(assert_exception (invoke "catchall-rethrow-1" (i32.const 0)))
+(assert_return (invoke "catchall-rethrow-1" (i32.const 1)) (i32.const 23))
+(assert_exception (invoke "rethrow-nested" (i32.const 0)))
+(assert_exception (invoke "rethrow-nested" (i32.const 1)))
+(assert_return (invoke "rethrow-nested" (i32.const 2)) (i32.const 23))
+
+(assert_return (invoke "rethrow-recatch" (i32.const 0)) (i32.const 23))
+(assert_return (invoke "rethrow-recatch" (i32.const 1)) (i32.const 42))
+
+(assert_exception (invoke "rethrow-stack-polymorphism"))
+
+(assert_invalid (module (func (rethrow 0))) "invalid rethrow label")
+(assert_invalid (module (func (block (rethrow 0)))) "invalid rethrow label")
+(assert_invalid (module (func (try (do (rethrow 0)) (delegate 0))))
+ "invalid rethrow label")
diff --git a/test/legacy/exceptions/throw.wast b/test/legacy/exceptions/throw.wast
new file mode 100644
index 00000000..d53b5b55
--- /dev/null
+++ b/test/legacy/exceptions/throw.wast
@@ -0,0 +1,51 @@
+;; Test throw instruction.
+
+(module
+ (tag $e0)
+ (tag $e-i32 (param i32))
+ (tag $e-f32 (param f32))
+ (tag $e-i64 (param i64))
+ (tag $e-f64 (param f64))
+ (tag $e-i32-i32 (param i32 i32))
+
+ (func $throw-if (export "throw-if") (param i32) (result i32)
+ (local.get 0)
+ (i32.const 0) (if (i32.ne) (then (throw $e0)))
+ (i32.const 0)
+ )
+
+ (func (export "throw-param-f32") (param f32) (local.get 0) (throw $e-f32))
+
+ (func (export "throw-param-i64") (param i64) (local.get 0) (throw $e-i64))
+
+ (func (export "throw-param-f64") (param f64) (local.get 0) (throw $e-f64))
+
+ (func $throw-1-2 (i32.const 1) (i32.const 2) (throw $e-i32-i32))
+ (func (export "test-throw-1-2")
+ (try
+ (do (call $throw-1-2))
+ (catch $e-i32-i32
+ (i32.const 2)
+ (if (i32.ne) (then (unreachable)))
+ (i32.const 1)
+ (if (i32.ne) (then (unreachable)))
+ )
+ )
+ )
+)
+
+(assert_return (invoke "throw-if" (i32.const 0)) (i32.const 0))
+(assert_exception (invoke "throw-if" (i32.const 10)))
+(assert_exception (invoke "throw-if" (i32.const -1)))
+
+(assert_exception (invoke "throw-param-f32" (f32.const 5.0)))
+(assert_exception (invoke "throw-param-i64" (i64.const 5)))
+(assert_exception (invoke "throw-param-f64" (f64.const 5.0)))
+
+(assert_return (invoke "test-throw-1-2"))
+
+(assert_invalid (module (func (throw 0))) "unknown tag 0")
+(assert_invalid (module (tag (param i32)) (func (throw 0)))
+ "type mismatch: instruction requires [i32] but stack has []")
+(assert_invalid (module (tag (param i32)) (func (i64.const 5) (throw 0)))
+ "type mismatch: instruction requires [i32] but stack has [i64]")
diff --git a/test/legacy/exceptions/try_catch.wast b/test/legacy/exceptions/try_catch.wast
new file mode 100644
index 00000000..2a0e9ff6
--- /dev/null
+++ b/test/legacy/exceptions/try_catch.wast
@@ -0,0 +1,265 @@
+;; Test try-catch blocks.
+
+(module
+ (tag $e0 (export "e0"))
+ (func (export "throw") (throw $e0))
+)
+
+(register "test")
+
+(module
+ (tag $imported-e0 (import "test" "e0"))
+ (func $imported-throw (import "test" "throw"))
+ (tag $e0)
+ (tag $e1)
+ (tag $e2)
+ (tag $e-i32 (param i32))
+ (tag $e-f32 (param f32))
+ (tag $e-i64 (param i64))
+ (tag $e-f64 (param f64))
+
+ (func $throw-if (param i32) (result i32)
+ (local.get 0)
+ (i32.const 0) (if (i32.ne) (then (throw $e0)))
+ (i32.const 0)
+ )
+
+ (func (export "empty-catch") (try (do) (catch $e0)))
+
+ (func (export "simple-throw-catch") (param i32) (result i32)
+ (try (result i32)
+ (do (local.get 0) (i32.eqz) (if (then (throw $e0)) (else)) (i32.const 42))
+ (catch $e0 (i32.const 23))
+ )
+ )
+
+ (func (export "unreachable-not-caught") (try (do (unreachable)) (catch_all)))
+
+ (func $div (param i32 i32) (result i32)
+ (local.get 0) (local.get 1) (i32.div_u)
+ )
+ (func (export "trap-in-callee") (param i32 i32) (result i32)
+ (try (result i32)
+ (do (local.get 0) (local.get 1) (call $div))
+ (catch_all (i32.const 11))
+ )
+ )
+
+ (func (export "catch-complex-1") (param i32) (result i32)
+ (try (result i32)
+ (do
+ (try (result i32)
+ (do
+ (local.get 0)
+ (i32.eqz)
+ (if
+ (then (throw $e0))
+ (else
+ (local.get 0)
+ (i32.const 1)
+ (i32.eq)
+ (if (then (throw $e1)) (else (throw $e2)))
+ )
+ )
+ (i32.const 2)
+ )
+ (catch $e0 (i32.const 3))
+ )
+ )
+ (catch $e1 (i32.const 4))
+ )
+ )
+
+ (func (export "catch-complex-2") (param i32) (result i32)
+ (try (result i32)
+ (do
+ (local.get 0)
+ (i32.eqz)
+ (if
+ (then (throw $e0))
+ (else
+ (local.get 0)
+ (i32.const 1)
+ (i32.eq)
+ (if (then (throw $e1)) (else (throw $e2)))
+ )
+ )
+ (i32.const 2)
+ )
+ (catch $e0 (i32.const 3))
+ (catch $e1 (i32.const 4))
+ )
+ )
+
+ (func (export "throw-catch-param-i32") (param i32) (result i32)
+ (try (result i32)
+ (do (local.get 0) (throw $e-i32) (i32.const 2))
+ (catch $e-i32 (return))
+ )
+ )
+
+ (func (export "throw-catch-param-f32") (param f32) (result f32)
+ (try (result f32)
+ (do (local.get 0) (throw $e-f32) (f32.const 0))
+ (catch $e-f32 (return))
+ )
+ )
+
+ (func (export "throw-catch-param-i64") (param i64) (result i64)
+ (try (result i64)
+ (do (local.get 0) (throw $e-i64) (i64.const 2))
+ (catch $e-i64 (return))
+ )
+ )
+
+ (func (export "throw-catch-param-f64") (param f64) (result f64)
+ (try (result f64)
+ (do (local.get 0) (throw $e-f64) (f64.const 0))
+ (catch $e-f64 (return))
+ )
+ )
+
+ (func $throw-param-i32 (param i32) (local.get 0) (throw $e-i32))
+ (func (export "catch-param-i32") (param i32) (result i32)
+ (try (result i32)
+ (do (i32.const 0) (local.get 0) (call $throw-param-i32))
+ (catch $e-i32)
+ )
+ )
+
+ (func (export "catch-imported") (result i32)
+ (try (result i32)
+ (do
+ (i32.const 1)
+ (call $imported-throw)
+ )
+ (catch $imported-e0 (i32.const 2))
+ )
+ )
+
+ (func (export "catchless-try") (param i32) (result i32)
+ (try (result i32)
+ (do
+ (try (result i32)
+ (do (local.get 0) (call $throw-if))
+ )
+ )
+ (catch $e0 (i32.const 1))
+ )
+ )
+
+ (func $throw-void (throw $e0))
+ (func (export "return-call-in-try-catch")
+ (try
+ (do
+ (return_call $throw-void)
+ )
+ (catch $e0)
+ )
+ )
+
+ (table funcref (elem $throw-void))
+ (func (export "return-call-indirect-in-try-catch")
+ (try
+ (do
+ (return_call_indirect (param) (i32.const 0))
+ )
+ (catch $e0)
+ )
+ )
+)
+
+(assert_return (invoke "empty-catch"))
+
+(assert_return (invoke "simple-throw-catch" (i32.const 0)) (i32.const 23))
+(assert_return (invoke "simple-throw-catch" (i32.const 1)) (i32.const 42))
+
+(assert_trap (invoke "unreachable-not-caught") "unreachable")
+
+(assert_return (invoke "trap-in-callee" (i32.const 7) (i32.const 2)) (i32.const 3))
+(assert_trap (invoke "trap-in-callee" (i32.const 1) (i32.const 0)) "integer divide by zero")
+
+(assert_return (invoke "catch-complex-1" (i32.const 0)) (i32.const 3))
+(assert_return (invoke "catch-complex-1" (i32.const 1)) (i32.const 4))
+(assert_exception (invoke "catch-complex-1" (i32.const 2)))
+
+(assert_return (invoke "catch-complex-2" (i32.const 0)) (i32.const 3))
+(assert_return (invoke "catch-complex-2" (i32.const 1)) (i32.const 4))
+(assert_exception (invoke "catch-complex-2" (i32.const 2)))
+
+(assert_return (invoke "throw-catch-param-i32" (i32.const 0)) (i32.const 0))
+(assert_return (invoke "throw-catch-param-i32" (i32.const 1)) (i32.const 1))
+(assert_return (invoke "throw-catch-param-i32" (i32.const 10)) (i32.const 10))
+
+(assert_return (invoke "throw-catch-param-f32" (f32.const 5.0)) (f32.const 5.0))
+(assert_return (invoke "throw-catch-param-f32" (f32.const 10.5)) (f32.const 10.5))
+
+(assert_return (invoke "throw-catch-param-i64" (i64.const 5)) (i64.const 5))
+(assert_return (invoke "throw-catch-param-i64" (i64.const 0)) (i64.const 0))
+(assert_return (invoke "throw-catch-param-i64" (i64.const -1)) (i64.const -1))
+
+(assert_return (invoke "throw-catch-param-f64" (f64.const 5.0)) (f64.const 5.0))
+(assert_return (invoke "throw-catch-param-f64" (f64.const 10.5)) (f64.const 10.5))
+
+(assert_return (invoke "catch-param-i32" (i32.const 5)) (i32.const 5))
+
+(assert_return (invoke "catch-imported") (i32.const 2))
+
+(assert_return (invoke "catchless-try" (i32.const 0)) (i32.const 0))
+(assert_return (invoke "catchless-try" (i32.const 1)) (i32.const 1))
+
+(assert_exception (invoke "return-call-in-try-catch"))
+(assert_exception (invoke "return-call-indirect-in-try-catch"))
+
+(module
+ (func $imported-throw (import "test" "throw"))
+ (tag $e0)
+
+ (func (export "imported-mismatch") (result i32)
+ (try (result i32)
+ (do
+ (try (result i32)
+ (do
+ (i32.const 1)
+ (call $imported-throw)
+ )
+ (catch $e0 (i32.const 2))
+ )
+ )
+ (catch_all (i32.const 3))
+ )
+ )
+)
+
+(assert_return (invoke "imported-mismatch") (i32.const 3))
+
+(assert_malformed
+ (module quote "(module (func (catch_all)))")
+ "unexpected token"
+)
+
+(assert_malformed
+ (module quote "(module (tag $e) (func (catch $e)))")
+ "unexpected token"
+)
+
+(assert_malformed
+ (module quote
+ "(module (func (try (do) (catch_all) (catch_all))))"
+ )
+ "unexpected token"
+)
+
+(assert_invalid (module (func (result i32) (try (result i32) (do))))
+ "type mismatch: instruction requires [i32] but stack has []")
+(assert_invalid (module (func (result i32) (try (result i32) (do (i64.const 42)))))
+ "type mismatch: instruction requires [i32] but stack has [i64]")
+(assert_invalid (module (tag) (func (try (do) (catch 0 (i32.const 42)))))
+ "type mismatch: block requires [] but stack has [i32]")
+(assert_invalid (module
+ (tag (param i64))
+ (func (result i32)
+ (try (result i32) (do (i32.const 42)) (catch 0))))
+ "type mismatch: instruction requires [i32] but stack has [i64]")
+(assert_invalid (module (func (try (do) (catch_all (i32.const 42)))))
+ "type mismatch: block requires [] but stack has [i32]")
diff --git a/test/legacy/exceptions/try_delegate.wast b/test/legacy/exceptions/try_delegate.wast
new file mode 100644
index 00000000..aae3a301
--- /dev/null
+++ b/test/legacy/exceptions/try_delegate.wast
@@ -0,0 +1,199 @@
+;; Test try-delegate blocks.
+
+(module
+ (tag $e0)
+ (tag $e1)
+
+ (func (export "delegate-no-throw") (result i32)
+ (try $t (result i32)
+ (do (try (result i32) (do (i32.const 1)) (delegate $t)))
+ (catch $e0 (i32.const 2))
+ )
+ )
+
+ (func $throw-if (param i32)
+ (local.get 0)
+ (if (then (throw $e0)) (else))
+ )
+
+ (func (export "delegate-throw") (param i32) (result i32)
+ (try $t (result i32)
+ (do
+ (try (result i32)
+ (do (local.get 0) (call $throw-if) (i32.const 1))
+ (delegate $t)
+ )
+ )
+ (catch $e0 (i32.const 2))
+ )
+ )
+
+ (func (export "delegate-skip") (result i32)
+ (try $t (result i32)
+ (do
+ (try (result i32)
+ (do
+ (try (result i32)
+ (do (throw $e0) (i32.const 1))
+ (delegate $t)
+ )
+ )
+ (catch $e0 (i32.const 2))
+ )
+ )
+ (catch $e0 (i32.const 3))
+ )
+ )
+
+ (func (export "delegate-to-block") (result i32)
+ (try (result i32)
+ (do (block (try (do (throw $e0)) (delegate 0)))
+ (i32.const 0))
+ (catch_all (i32.const 1)))
+ )
+
+ (func (export "delegate-to-catch") (result i32)
+ (try (result i32)
+ (do (try
+ (do (throw $e0))
+ (catch $e0
+ (try (do (rethrow 1)) (delegate 0))))
+ (i32.const 0))
+ (catch_all (i32.const 1)))
+ )
+
+ (func (export "delegate-to-caller-trivial")
+ (try
+ (do (throw $e0))
+ (delegate 0)))
+
+ (func (export "delegate-to-caller-skipping")
+ (try (do (try (do (throw $e0)) (delegate 1))) (catch_all))
+ )
+
+ (func $select-tag (param i32)
+ (block (block (block (local.get 0) (br_table 0 1 2)) (return)) (throw $e0))
+ (throw $e1)
+ )
+
+ (func (export "delegate-merge") (param i32 i32) (result i32)
+ (try $t (result i32)
+ (do
+ (local.get 0)
+ (call $select-tag)
+ (try
+ (result i32)
+ (do (local.get 1) (call $select-tag) (i32.const 1))
+ (delegate $t)
+ )
+ )
+ (catch $e0 (i32.const 2))
+ )
+ )
+
+ (func (export "delegate-throw-no-catch") (result i32)
+ (try (result i32)
+ (do (try (result i32) (do (throw $e0) (i32.const 1)) (delegate 0)))
+ (catch $e1 (i32.const 2))
+ )
+ )
+
+ (func (export "delegate-correct-targets") (result i32)
+ (try (result i32)
+ (do (try $l3
+ (do (try $l2
+ (do (try $l1
+ (do (try $l0
+ (do (try
+ (do (throw $e0))
+ (delegate $l1)))
+ (catch_all unreachable)))
+ (delegate $l3)))
+ (catch_all unreachable)))
+ (catch_all (try
+ (do (throw $e0))
+ (delegate $l3))))
+ unreachable)
+ (catch_all (i32.const 1))))
+
+ (func $throw-void (throw $e0))
+ (func (export "return-call-in-try-delegate")
+ (try $l
+ (do
+ (try
+ (do
+ (return_call $throw-void)
+ )
+ (delegate $l)
+ )
+ )
+ (catch $e0)
+ )
+ )
+
+ (table funcref (elem $throw-void))
+ (func (export "return-call-indirect-in-try-delegate")
+ (try $l
+ (do
+ (try
+ (do
+ (return_call_indirect (param) (i32.const 0))
+ )
+ (delegate $l)
+ )
+ )
+ (catch $e0)
+ )
+ )
+)
+
+(assert_return (invoke "delegate-no-throw") (i32.const 1))
+
+(assert_return (invoke "delegate-throw" (i32.const 0)) (i32.const 1))
+(assert_return (invoke "delegate-throw" (i32.const 1)) (i32.const 2))
+
+(assert_exception (invoke "delegate-throw-no-catch"))
+
+(assert_return (invoke "delegate-merge" (i32.const 1) (i32.const 0)) (i32.const 2))
+(assert_exception (invoke "delegate-merge" (i32.const 2) (i32.const 0)))
+(assert_return (invoke "delegate-merge" (i32.const 0) (i32.const 1)) (i32.const 2))
+(assert_exception (invoke "delegate-merge" (i32.const 0) (i32.const 2)))
+(assert_return (invoke "delegate-merge" (i32.const 0) (i32.const 0)) (i32.const 1))
+
+(assert_return (invoke "delegate-skip") (i32.const 3))
+
+(assert_return (invoke "delegate-to-block") (i32.const 1))
+(assert_return (invoke "delegate-to-catch") (i32.const 1))
+
+(assert_exception (invoke "delegate-to-caller-trivial"))
+(assert_exception (invoke "delegate-to-caller-skipping"))
+
+(assert_return (invoke "delegate-correct-targets") (i32.const 1))
+
+(assert_exception (invoke "return-call-in-try-delegate"))
+(assert_exception (invoke "return-call-indirect-in-try-delegate"))
+
+(assert_malformed
+ (module quote "(module (func (delegate 0)))")
+ "unexpected token"
+)
+
+(assert_malformed
+ (module quote "(module (tag $e) (func (try (do) (catch $e) (delegate 0))))")
+ "unexpected token"
+)
+
+(assert_malformed
+ (module quote "(module (func (try (do) (catch_all) (delegate 0))))")
+ "unexpected token"
+)
+
+(assert_malformed
+ (module quote "(module (func (try (do) (delegate) (delegate 0))))")
+ "unexpected token"
+)
+
+(assert_invalid
+ (module (func (try (do) (delegate 1))))
+ "unknown label"
+)
diff --git a/test/legacy/run.py b/test/legacy/run.py
new file mode 100755
index 00000000..f727aeef
--- /dev/null
+++ b/test/legacy/run.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python3
+
+from __future__ import print_function
+import argparse
+import os
+import os.path
+import unittest
+import subprocess
+import glob
+import sys
+
+
+ownDir = os.path.dirname(os.path.abspath(sys.argv[0]))
+inputDir = ownDir
+outputDir = os.path.join(inputDir, "_output")
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--wasm", metavar="", default=os.path.join(os.getcwd(), "wasm"))
+parser.add_argument("--js", metavar="")
+parser.add_argument("--generate-js-only", action='store_true')
+parser.add_argument("--out", metavar="", default=outputDir)
+parser.add_argument("file", nargs='*')
+arguments = parser.parse_args()
+sys.argv = sys.argv[:1]
+
+exceptions_test_files = glob.glob(os.path.join(inputDir, "exceptions", "*.wast"))
+
+wasmCommand = arguments.wasm
+jsCommand = arguments.js
+generateJsOnly = arguments.generate_js_only
+outputDir = arguments.out
+inputFiles = arguments.file if arguments.file else exceptions_test_files
+
+if not os.path.exists(wasmCommand):
+ sys.stderr.write("""\
+Error: The executable '%s' does not exist.
+Provide the correct path with the '--wasm' flag.
+
+""" % (wasmCommand))
+ parser.print_help()
+ sys.exit(1)
+
+
+class RunTests(unittest.TestCase):
+ def _runCommand(self, command, logPath, expectedExitCode = 0):
+ with open(logPath, 'w+') as out:
+ exitCode = subprocess.call(command, shell=True, stdout=out, stderr=subprocess.STDOUT)
+ self.assertEqual(expectedExitCode, exitCode, "failed with exit code %i (expected %i) for %s" % (exitCode, expectedExitCode, command))
+
+ def _auxFile(self, path):
+ if os.path.exists(path):
+ os.remove(path)
+ return path
+
+ def _compareFile(self, expectFile, actualFile):
+ if os.path.exists(expectFile):
+ with open(expectFile) as expect:
+ with open(actualFile) as actual:
+ expectText = expect.read()
+ actualText = actual.read()
+ self.assertEqual(expectText, actualText)
+
+ def _runTestFile(self, inputPath):
+ dir, inputFile = os.path.split(inputPath)
+ outputPath = os.path.join(outputDir, inputFile)
+
+ # Generate JS first, then return early if we are only generating JS.
+ jsPath = self._auxFile(outputPath.replace(".wast", ".js"))
+ logPath = self._auxFile(jsPath + ".log")
+ self._runCommand(('%s -d "%s" -o "%s"') % (wasmCommand, inputPath, jsPath), logPath)
+
+ if generateJsOnly:
+ return
+
+ # Run original file
+ expectedExitCode = 1 if ".fail." in inputFile else 0
+ logPath = self._auxFile(outputPath + ".log")
+ self._runCommand(('%s "%s"') % (wasmCommand, inputPath), logPath, expectedExitCode)
+
+ if expectedExitCode != 0:
+ return
+
+ # Convert to binary and run again
+ wasmPath = self._auxFile(outputPath + ".bin.wast")
+ logPath = self._auxFile(wasmPath + ".log")
+ self._runCommand(('%s -d "%s" -o "%s"') % (wasmCommand, inputPath, wasmPath), logPath)
+ self._runCommand(('%s "%s"') % (wasmCommand, wasmPath), logPath)
+
+ # Convert back to text and run again
+ wastPath = self._auxFile(wasmPath + ".wast")
+ logPath = self._auxFile(wastPath + ".log")
+ self._runCommand(('%s -d "%s" -o "%s"') % (wasmCommand, wasmPath, wastPath), logPath)
+ self._runCommand(('%s "%s"') % (wasmCommand, wastPath), logPath)
+
+ # Convert back to binary once more and compare
+ wasm2Path = self._auxFile(wastPath + ".bin.wast")
+ logPath = self._auxFile(wasm2Path + ".log")
+ self._runCommand(('%s -d "%s" -o "%s"') % (wasmCommand, wastPath, wasm2Path), logPath)
+ self._compareFile(wasmPath, wasm2Path)
+
+ # Convert back to text once more and compare
+ wast2Path = self._auxFile(wasm2Path + ".wast")
+ logPath = self._auxFile(wast2Path + ".log")
+ self._runCommand(('%s -d "%s" -o "%s"') % (wasmCommand, wasm2Path, wast2Path), logPath)
+ self._compareFile(wastPath, wast2Path)
+
+ if jsCommand != None:
+ self._runCommand(('%s "%s"') % (jsCommand, jsPath), logPath)
+
+
+if __name__ == "__main__":
+ if not os.path.exists(outputDir):
+ os.makedirs(outputDir)
+ for fileName in inputFiles:
+ testName = 'test ' + os.path.basename(fileName)
+ setattr(RunTests, testName, lambda self, file=fileName: self._runTestFile(file))
+ unittest.main()