diff --git a/.github/workflows/ci-spec.yml b/.github/workflows/ci-spec.yml index 33806f448a..04e47b40d5 100644 --- a/.github/workflows/ci-spec.yml +++ b/.github/workflows/ci-spec.yml @@ -30,8 +30,8 @@ jobs: uses: actions/setup-node@v3 with: node-version: 16 - # - name: Setup Bikeshed - # run: pip install bikeshed && bikeshed update + - name: Setup Bikeshed + run: pip install bikeshed && bikeshed update - name: Setup TexLive run: sudo apt-get update -y && sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended - name: Setup Sphinx @@ -40,8 +40,8 @@ jobs: run: cd spectec && opam exec make - name: Build main spec run: cd document/core && opam exec make main - # - name: Run Bikeshed - # run: cd document/core && opam exec make bikeshed + - name: Run Bikeshed + # run: cd document/core && opam exec make bikeshed - name: Upload artifact uses: actions/upload-artifact@v2 with: @@ -56,7 +56,7 @@ jobs: - name: Setup Bikeshed run: pip install bikeshed && bikeshed update - name: Run Bikeshed - run: bikeshed spec "document/js-api/index.bs" "document/js-api/index.html" + # run: bikeshed spec "document/js-api/index.bs" "document/js-api/index.html" - name: Upload artifact uses: actions/upload-artifact@v2 with: @@ -71,16 +71,70 @@ jobs: - name: Setup Bikeshed run: pip install bikeshed && bikeshed update - name: Run Bikeshed - run: bikeshed spec "document/web-api/index.bs" "document/web-api/index.html" + # run: bikeshed spec "document/web-api/index.bs" "document/web-api/index.html" - name: Upload artifact uses: actions/upload-artifact@v2 with: name: web-api-rendered path: document/web-api/index.html + build-code-metadata-spec: + runs-on: ubuntu-latest + needs: [build-core-spec] + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + submodules: "recursive" + - name: Setup TexLive + run: sudo apt-get update -y && sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended + - name: Setup Sphinx + run: pip install six && pip install sphinx==5.1.0 + - name: Build main spec + run: cd document/metadata/code && make main + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: code-metadata-rendered + path: document/metadata/code/_build/html + + build-legacy-exceptions-core-spec: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + submodules: "recursive" + - name: Setup TexLive + run: sudo apt-get update -y && sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended + - name: Setup Sphinx + run: pip install six && pip install sphinx==5.1.0 + - name: Build main spec + run: cd document/legacy/exceptions/core && make main + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: legacy-exceptions-core-rendered + path: document/legacy/exceptions/core/_build/html + + build-legacy-exceptions-js-api-spec: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v2 + - name: Setup Bikeshed + run: pip install bikeshed && bikeshed update + - name: Run Bikeshed + # run: bikeshed spec "document/legacy/exceptions/js-api/index.bs" "document/legacy/exceptions/js-api/index.html" + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: legacy-exceptions-js-api-rendered + path: document/legacy/exceptions/js-api/index.html + publish-spec: runs-on: ubuntu-latest - needs: [build-core-spec, build-js-api-spec, build-web-api-spec] + needs: [build-core-spec, build-js-api-spec, build-web-api-spec, build-code-metadata-spec, build-legacy-exceptions-core-spec, build-legacy-exceptions-js-api-spec] steps: - name: Checkout repo uses: actions/checkout@v2 @@ -101,6 +155,21 @@ jobs: with: name: web-api-rendered path: _output/web-api + - name: Download code metadata spec artifact + uses: actions/download-artifact@v2 + with: + name: code-metadata-rendered + path: _output/metadata/code + - name: Download legacy exceptions core spec artifact + uses: actions/download-artifact@v2 + with: + name: legacy-exceptions-core-rendered + path: _output/legacy/exceptions/core + - name: Download legacy exceptions JS API spec artifact + uses: actions/download-artifact@v2 + with: + name: legacy-exceptions-js-api-rendered + path: _output/legacy/exceptions/js-api - name: Publish to GitHub Pages if: github.ref == 'refs/heads/main' uses: peaceiris/actions-gh-pages@v3 diff --git a/README.md b/README.md index 641932c211..6617033a25 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,11 @@ Original `README` from upstream repository follows... # spec -This repository holds a prototypical reference implementation for WebAssembly, -which is currently serving as the official specification. Eventually, we expect -to produce a specification either written in human-readable prose or in a formal -specification language. +This repository holds the sources for the WebAssembly specification, +a reference implementation, and the official test suite. -It also holds the WebAssembly testsuite, which tests numerous aspects of -conformance to the spec. - -View the work-in-progress spec at [webassembly.github.io/spec](https://webassembly.github.io/spec/). - -At this time, the contents of this repository are under development and known -to be "incomplet and inkorrect". +A formatted version of the spec is available here: +[webassembly.github.io/spec](https://webassembly.github.io/spec/), Participation is welcome. Discussions about new features, significant semantic changes, or any specification change likely to generate substantial discussion diff --git a/deploy_key b/deploy_key deleted file mode 100644 index f4e5b00055..0000000000 --- a/deploy_key +++ /dev/null @@ -1,49 +0,0 @@ ------BEGIN OPENSSH PRIVATE KEY----- -b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn -NhAAAAAwEAAQAAAgEAn9FUrQzWcgEOHsDJ+f7L0g7xIYrdBb3K1dQqFWFidZcL8KYMMR0/ -CEYRXfSn3EcvpYnRoIjWfGQgqOpA90FMaAwqdoK72ByW7q2C4ymjX5xR8XFyG5YJVvjaMe -STXZlynQSOH9lXU5RooeEwRatgQizuwB/Bqahry/8FOfDhVlNO26IbEyJPd23qeyAd+42C -OTE5oWHEJ3TKSWSfwTAhfrIlIg+dWiSx/IUcLc+7Ms5EpQh3ebX49oaW00SWRDnyqoM95m -D+Uc3DuTFJyKdHlLouESdNrE9LeBms5N/bHSgedVyZ5fL9SHC6P1HmgDPFspmO6z1s15/a -5y5hf9zHVoj1ha54LSaPlE5/L5hpY6PCH7fepRXhw84VIQV74IsJow1XUbkmfKkjW3PeBq -CF5cTKF2LK65SraxEfNMLU0ThOH6B6yzePq7JF+05VGMh2G2Wkwy11pezeqW5tPU1M2qwS -RN8jAFKIwuC7B73drz8yMhF8MfTW4iGM4RqhQRCK22xmVtzwYFwRKUM++p2iOggGi42jnV -skv7/yQ6XcaEm+2Jx3C2zy/5OdLql9z8gmKsH4jpQUADmae8KBfJCqHZrtvhRTqH99E3th -pIKcpzY+n5uhNCyrY+hTfB44/EIntWkXDTLwVVRmmOyHSvEA7/Dz1vtA7gY9Nu25xY/SXS -sAAAc4dIF4rHSBeKwAAAAHc3NoLXJzYQAAAgEAn9FUrQzWcgEOHsDJ+f7L0g7xIYrdBb3K -1dQqFWFidZcL8KYMMR0/CEYRXfSn3EcvpYnRoIjWfGQgqOpA90FMaAwqdoK72ByW7q2C4y -mjX5xR8XFyG5YJVvjaMeSTXZlynQSOH9lXU5RooeEwRatgQizuwB/Bqahry/8FOfDhVlNO -26IbEyJPd23qeyAd+42COTE5oWHEJ3TKSWSfwTAhfrIlIg+dWiSx/IUcLc+7Ms5EpQh3eb -X49oaW00SWRDnyqoM95mD+Uc3DuTFJyKdHlLouESdNrE9LeBms5N/bHSgedVyZ5fL9SHC6 -P1HmgDPFspmO6z1s15/a5y5hf9zHVoj1ha54LSaPlE5/L5hpY6PCH7fepRXhw84VIQV74I -sJow1XUbkmfKkjW3PeBqCF5cTKF2LK65SraxEfNMLU0ThOH6B6yzePq7JF+05VGMh2G2Wk -wy11pezeqW5tPU1M2qwSRN8jAFKIwuC7B73drz8yMhF8MfTW4iGM4RqhQRCK22xmVtzwYF -wRKUM++p2iOggGi42jnVskv7/yQ6XcaEm+2Jx3C2zy/5OdLql9z8gmKsH4jpQUADmae8KB -fJCqHZrtvhRTqH99E3thpIKcpzY+n5uhNCyrY+hTfB44/EIntWkXDTLwVVRmmOyHSvEA7/ -Dz1vtA7gY9Nu25xY/SXSsAAAADAQABAAACAFMayDxgY5bOw6fsOlscSqKFkJAPpJUat0Hv -3J5XkJpzHAtcXRShD6jevqMr2Knr/nPHMdGXtmjirDUJ8xRfyTqFsQMFQmbDnxyn71ruyP -yrzdSOWHbN0zd9mgC9yn+ujnHl733SR923W51p+u8PibN/p/sRyGPPp5Zhmzcg8hwwn94H -8qpFeisxZe/2qICpeiEBXuVzcEvQKGx3vbb4r0IxoquOkRVR5ZfZI+kSj1aA+iMTPwV0Qe -z32bAshzMdKvnN2z9UCotBQ1imr6Z+jfNhyRi0ZmiGp0jhmQ0+9rK3rPb8Wy6+50RnEgJh -NUpPIauYvD/JJjMN9genD54skR61JnwRSmMUcuYFvcPKip1FYugYtZY/a9waqcSA73TcuZ -DQzihYs4fdr2aD3pH8QchYwo5vZFzPCVuXF387pYUmj8u3RLDhemSYjwuG/NWdVKnYnZ2B -EVOMi4YZ6Kms7rac8zzgFUonxDWLCigOPI0HPfrDKQ7P6NyiAKEEEfK6g2KvnDJaaCdfpb -70UTFG6YyN+1qa0NWVcU6iEGd/ziT7xPDT3WgJd4SAYkllycQkg5zdFz4T1SqABMrWqjK7 -1Xk//kZxboYZFwBoODiNd2dcLU1XOBhNvoAEajKQNyzAhET6eC02olwUwl7ZwdMxMH8C9H -/j4lAq+v6PYzFHN/uZAAABAQCExWknkwPAu+eDulQTW1T5kIhsD3Ffe+9yg1Ps83NPST9w -7dddykxOzZJ4j8WjpsvwCXuxyxPqt3UI3y2t4nC2aIWq5gPoIfDvtt5J8j6i4RwrI2AU3j -tKdPyLD4qKOCvuqThRCUz3GffU8QNknLYT1jGhO8p//nZq68SVIhtcL8CG1/mQQVApgvd+ -VrBIytptBk0wn4ufMY11CjRTLjASJzBsiT/VmUkQVBQDn6/yvCSxx7nYzMt0XcDqH1/KO7 -iqEN6HfkTNTKBXcRWIS+c7OvAixJTGXRCE2xcQindaHQ3HNK+6r1qAXp65XfsTJUw+FIdc -4OXiRdnAAanVy6tAAAABAQDKduhs+s+AKQWsuwkzWdnLQdMP+98vKBkMH7/dBA73xDd+hR -8sHOhoyxYoNoUhvYWcoip2Mqsn/+F5QLvKxaaccQOtfQpYEeB0koL3QEHUIBMwzgEW112T -ATa8KR6okRAUxn7tqswebAFPmdpGS1YkQAyAQQoPr2NQpPSWN0cKXQZUYLn5r6HSZ7isAm -K/6mrF+TqK80055A+duZggLIKyMAKDTdgtIu4D/wZIqZYcY8uiA2ZhGM3XEQutTjo4xemu -V2X+WSwXhrXiSAWqbCBxCRcCLKktweihb1nOkXIOspKr7Adj/ctmlqO875GHuwlrGaNfe2 -DFo67i4udsdrc9AAABAQDKE5rUxfN6K51jWdgiBVx1XVH0YenLGHECYcxg5AHkDTJUOl9F -SqiP4w128fFjHEO+GGltgkruQ94k+wINub/e7k1NYSpgj03BDs6swpRG7Y3uot1aBFAati -ITJF6p1rmjmBxtDhaVX9nA6GyOmzXO4Tb6niBHO5u7B3dqZI/iXHUmsZOsa1ijuE8YL5P7 -SzxbkiGGsWv5gfs8RcYuOmGhTx2LxOTNh3kovj4xQSoJVH3IikpodQAuXTdL5utuAzgVEL -Xpk1XVyVPkFGitmNqTr3D2gKnPnkQf8KYsRmzt4bPKDrKOBleqYbFSabyHUNJEaW7pmf8+ -fNbVF9dWMmyHAAAAAAEC ------END OPENSSH PRIVATE KEY----- diff --git a/deploy_key.pub b/deploy_key.pub deleted file mode 100644 index 313f1bd8e1..0000000000 --- a/deploy_key.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCf0VStDNZyAQ4ewMn5/svSDvEhit0FvcrV1CoVYWJ1lwvwpgwxHT8IRhFd9KfcRy+lidGgiNZ8ZCCo6kD3QUxoDCp2grvYHJburYLjKaNfnFHxcXIblglW+Nox5JNdmXKdBI4f2VdTlGih4TBFq2BCLO7AH8GpqGvL/wU58OFWU07bohsTIk93bep7IB37jYI5MTmhYcQndMpJZJ/BMCF+siUiD51aJLH8hRwtz7syzkSlCHd5tfj2hpbTRJZEOfKqgz3mYP5RzcO5MUnIp0eUui4RJ02sT0t4Gazk39sdKB51XJnl8v1IcLo/UeaAM8WymY7rPWzXn9rnLmF/3MdWiPWFrngtJo+UTn8vmGljo8Ift96lFeHDzhUhBXvgiwmjDVdRuSZ8qSNbc94GoIXlxMoXYsrrlKtrER80wtTROE4foHrLN4+rskX7TlUYyHYbZaTDLXWl7N6pbm09TUzarBJE3yMAUojC4LsHvd2vPzIyEXwx9NbiIYzhGqFBEIrbbGZW3PBgXBEpQz76naI6CAaLjaOdWyS/v/JDpdxoSb7YnHcLbPL/k50uqX3PyCYqwfiOlBQAOZp7woF8kKodmu2+FFOof30Te2GkgpynNj6fm6E0LKtj6FN8Hjj8Qie1aRcNMvBVVGaY7IdK8QDv8PPW+0DuBj027bnFj9JdKw== diff --git a/document/Makefile b/document/Makefile index 01a6d93423..77a79ee70f 100644 --- a/document/Makefile +++ b/document/Makefile @@ -1,4 +1,4 @@ -DIRS = js-api web-api core +DIRS = core js-api web-api metadata/code legacy/exceptions FILES = index.html BUILDDIR = _build TAR = tar diff --git a/document/core/appendix/algorithm.rst b/document/core/appendix/algorithm.rst index 97988bb381..b8dc8d6944 100644 --- a/document/core/appendix/algorithm.rst +++ b/document/core/appendix/algorithm.rst @@ -32,7 +32,7 @@ Value types are representable as sets of enumerations: type vec_type = V128 type heap_type = Any | Eq | I31 | Struct | Array | None | - Func | Nofunc | Extern | Noextern | Bot | + Func | Nofunc | Exn | Noexn | Extern | Noextern | Bot | Def(def : def_type) type ref_type = Ref(heap : heap_type, null : bool) type val_type = num_type | vec_type | ref_type | Bot @@ -445,6 +445,28 @@ Other instructions are checked in a similar manner. pop_val(Ref(Def(types[x]))) pop_val(unpack_field(st.fields[n])) + case (throw x) + pop_vals(tags[x].type.params) + unreachable() + + case (try_table t1*->t2* handler*) + pop_vals([t1*]) + foreach (handler in handler*) + error_if(ctrls.size() < handler.label) + push_ctrl(catch, [], label_types(ctrls[handler.label])) + switch (handler.clause) + case (catch x) + push_vals(tags[x].type.params) + case (catch_ref x) + push_vals(tags[x].type.params) + push_val(Exnref) + case (catch_all) + skip + case (catch_all_ref) + push_val(Exnref) + pop_ctrl() + push_ctrl(try_table, [t1*], [t2*]) + .. note:: It is an invariant under the current WebAssembly instruction set that an operand of :code:`Bot` type is never duplicated on the stack. This would change if the language were extended with stack instructions like :code:`dup`. diff --git a/document/core/appendix/changes.rst b/document/core/appendix/changes.rst index e60e6fd02d..cc8a445635 100644 --- a/document/core/appendix/changes.rst +++ b/document/core/appendix/changes.rst @@ -12,7 +12,7 @@ Release 2.0 .. index:: instruction, integer -Sign extension instructions +Sign Extension Instructions ........................... Added new numeric instructions for performing sign extension within integer representations. [#proposal-signext]_ @@ -22,7 +22,7 @@ Added new numeric instructions for performing sign extension within integer repr .. index:: instruction, trap, floating-point, integer -Non-trapping float-to-int conversions +Non-trapping Float-to-Int Conversions ..................................... Added new conversion instructions that avoid trapping when converting a floating-point number to an integer. [#proposal-cvtsat]_ @@ -32,7 +32,7 @@ Added new conversion instructions that avoid trapping when converting a floating .. index:: block, function, value type, result type -Multiple values +Multiple Values ............... Generalized the result type of blocks and functions to allow for multiple values; in addition, introduced the ability to have block parameters. [#proposal-multivalue]_ @@ -44,7 +44,7 @@ Generalized the result type of blocks and functions to allow for multiple values .. index:: value type, reference, reference type, instruction, element segment -Reference types +Reference Types ............... Added |FUNCREF| and |EXTERNREF| as new value types and respective instructions. [#proposal-reftype]_ @@ -60,7 +60,7 @@ Added |FUNCREF| and |EXTERNREF| as new value types and respective instructions. .. index:: reference, instruction, table, table type -Table instructions +Table Instructions .................. Added instructions to directly access and modify tables. [#proposal-reftype]_ @@ -72,7 +72,7 @@ Added instructions to directly access and modify tables. [#proposal-reftype]_ .. index:: table, instruction, table index, element segment, import, export -Multiple tables +Multiple Tables ............... Added the ability to use multiple tables per module. [#proposal-reftype]_ @@ -86,7 +86,7 @@ Added the ability to use multiple tables per module. [#proposal-reftype]_ .. index:: instruction, table, memory, data segment, element segment -Bulk memory and table instructions +Bulk Memory and Table Instructions .................................. Added instructions that modify ranges of memory or table entries. [#proposal-reftype]_ [#proposal-bulk]_ @@ -106,7 +106,7 @@ Added instructions that modify ranges of memory or table entries. [#proposal-ref .. index:: instructions, SIMD, value type, vector type -Vector instructions +Vector Instructions ................... Added vector type and instructions that manipulate multiple numeric values in parallel (also known as *SIMD*, single instruction multiple data) [#proposal-vectype]_ @@ -160,9 +160,9 @@ Added vector type and instructions that manipulate multiple numeric values in pa Release 3.0 ~~~~~~~~~~~ -.. index: instruction, expression, constant +.. index:: instruction, expression, constant -Extended constant expressions +Extended Constant Expressions ............................. Allowed basic numeric computations in constant expressions. [#proposal-extconst]_ @@ -173,9 +173,9 @@ Allowed basic numeric computations in constant expressions. [#proposal-extconst] The :ref:`garbage collection ` added further constant instructions. -.. index: instruction, function, call +.. index:: instruction, function, call -Tail calls +Tail Calls .......... Added instructions to perform tail calls. [#proposal-tailcall]_ @@ -183,9 +183,27 @@ Added instructions to perform tail calls. [#proposal-tailcall]_ * New :ref:`control instructions `: |RETURNCALL| and |RETURNCALLINDIRECT| -.. index: instruction, memory, memory index, data segment, import, export +.. index:: instruction, exception, reference type, tag type, tag, handler -Multiple memories +Exception Handling +.................. + +Added tag definitions, imports, and exports, and instructions to throw and catch exceptions [#proposal-exn]_ + +* Modules may :ref:`define `, :ref:`import `, and :ref:`export ` tags. + +* New :ref:`heap types `: |EXN|, |NOEXN| + +* New :ref:`reference type ` short-hands: |EXNREF|, |NULLEXNREF| + +* New :ref:`control instructions `: |THROW|, |THROWREF|, and |TRYTABLE|. + +* New :ref:`tag section ` in binary format. + + +.. index:: instruction, memory, memory index, data segment, import, export + +Multiple Memories ................. Added the ability to use multiple memories per module. [#proposal-multimem]_ @@ -199,7 +217,7 @@ Added the ability to use multiple memories per module. [#proposal-multimem]_ .. index:: reference, reference type, heap type, value type, local, local type, instruction, instruction type, table, function, function type, matching, subtyping -Typeful references +Typeful References .................. Added more precise types for references. [#proposal-typedref]_ @@ -224,7 +242,7 @@ Added more precise types for references. [#proposal-typedref]_ .. index:: reference, reference type, heap type, field type, storage type, structure type, array type, composite type, sub type, recursive type .. _extension-gc: -Garbage collection +Garbage Collection .................. Added managed reference types. [#proposal-gc]_ @@ -250,12 +268,32 @@ Added managed reference types. [#proposal-gc]_ * Extended set of :ref:`constant instructions ` with |REFI31|, |STRUCTNEW|, |STRUCTNEWDEFAULT|, |ARRAYNEW|, |ARRAYNEWDEFAULT|, |ARRAYNEWFIXED|, |ANYCONVERTEXTERN|, |EXTERNCONVERTANY| +.. index:: text format, annotation, custom section, identifier, module, type, function, local, structure field + +Custom Annotations +.................. + +Added generic syntax for custom annotations in the text format, +mirroring the role of custom sections in the binary format. [#proposal-annot]_ + +* :ref:`Annotations ` of the form :math:`\text{(@id~\dots)}` are allowed anywhere in the :ref:`text format ` + +* :ref:`Identifiers ` can be escaped as :math:`\text{@"\dots"}` with arbitrary :ref:`names ` + +* Defined :ref:`name annotations ` :math:`\text{(@name~"\dots")}` for :ref:`module names `, :ref:`type names `, :ref:`function names `, :ref:`local names `, and :ref:`field names ` + +* Defined :ref:`custom annotation ` :math:`\text{(@custom~"\dots")}` to represent arbitrary :ref:`custom sections ` in the text format + + .. [#proposal-extconst] https://github.com/WebAssembly/extended-const/blob/main/proposals/extended-const/ .. [#proposal-tailcall] https://github.com/WebAssembly/spec/tree/main/proposals/tail-call/ +.. [#proposal-exn] + https://github.com/WebAssembly/spec/tree/main/proposals/exception-handling/ + .. [#proposal-multimem] https://github.com/WebAssembly/multi-memory/blob/main/proposals/multi-memory/ @@ -264,3 +302,6 @@ Added managed reference types. [#proposal-gc]_ .. [#proposal-gc] https://github.com/WebAssembly/spec/tree/main/proposals/gc/ + +.. [#proposal-annot] + https://github.com/WebAssembly/annotations/tree/main/proposals/annotations/ diff --git a/document/core/appendix/custom.rst b/document/core/appendix/custom.rst index 106168ec0b..042a9fae44 100644 --- a/document/core/appendix/custom.rst +++ b/document/core/appendix/custom.rst @@ -45,7 +45,8 @@ Each subsection consists of a n{:}\Bname & (\iff n = \text{name}) \\ &&& \Bmodulenamesubsec^? \\ &&& \Bfuncnamesubsec^? \\ &&& - \Blocalnamesubsec^? \\ + \Blocalnamesubsec^? \\ &&& + \Btagnamesubsec^? \\ \production{name subsection} & \Bnamesubsection_N(\B{B}) &::=& N{:}\Bbyte~~\X{size}{:}\Bu32~~\B{B} & (\iff \X{size} = ||\B{B}||) \\ @@ -61,6 +62,7 @@ Id Subsection 2 :ref:`local names ` 4 :ref:`type names ` 10 :ref:`field names ` +11 :ref:`tag names ` == =========================================== Each subsection may occur at most once, and in order of increasing id. @@ -178,6 +180,22 @@ It consists of an :ref:`indirect name map ` assigning fi \end{array} +.. index:: tag, tag index +.. _binary-tagnamesec: + +Tag Names +......... + +The *tag name subsection* has the id 11. +It consists of a :ref:`name map ` assigning tag names to :ref:`tag indices `. + +.. math:: + \begin{array}{llclll} + \production{tag name subsection} & \Btagnamesubsec &::=& + \Bnamesubsection_1(\Bnamemap) \\ + \end{array} + + .. index:: ! name annotation, name, Unicode UTF-8 .. _text-nameannot: @@ -306,6 +324,22 @@ It may only be placed on a declaration that declares exactly one field. \end{array} +.. index:: tag +.. _text-tagnameannot: + +Tag Names +......... + +A *tag name annotation* must be placed on a :ref:`tag declaration ` or tag :ref:`import `, +directly after the :math:`\text{tag}` keyword, or if present, after the following tag :ref:`identifier `. + +.. math:: + \begin{array}{llclll} + \production{tag name annotation} & \Ttagnameannot &::=& + \Tnameannot \\ + \end{array} + + .. index:: ! custom annotation, custom section .. _text-customannot: diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index 969e2f1310..d643205f53 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -39,23 +39,34 @@ Interface operation that are predicates return Boolean values: .. _embed-error: -Errors -~~~~~~ +Exceptions and Errors +~~~~~~~~~~~~~~~~~~~~~ + +Invoking an exported function may throw or propagate exceptions, expressed by an auxiliary syntactic class: + +.. math:: + \begin{array}{llll} + \production{exception} & \exception &::=& \EXCEPTION~\exnaddr \\ + \end{array} -Failure of an interface operation is indicated by an auxiliary syntactic class: +The exception address :math:`exnaddr` identifies the exception thrown. + +Failure of an interface operation is also indicated by an auxiliary syntactic class: .. math:: \begin{array}{llll} \production{error} & \error &::=& \ERROR \\ \end{array} -In addition to the error conditions specified explicitly in this section, implementations may also return errors when specific :ref:`implementation limitations ` are reached. +In addition to the error conditions specified explicitly in this section, such as invalid arguments or :ref:`exceptions ` and :ref:`traps ` resulting from :ref:`execution `, implementations may also return errors when specific :ref:`implementation limitations ` are reached. .. note:: Errors are abstract and unspecific with this definition. Implementations can refine it to carry suitable classifications and diagnostic messages. + + Pre- and Post-Conditions ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -63,7 +74,7 @@ Some operations state *pre-conditions* about their arguments or *post-conditions It is the embedder's responsibility to meet the pre-conditions. If it does, the post conditions are guaranteed by the semantics. -In addition to pre- and post-conditions explicitly stated with each operation, the specification adopts the following conventions for :ref:`runtime objects ` (:math:`\store`, :math:`\moduleinst`, :math:`\externval`, :ref:`addresses `): +In addition to pre- and post-conditions explicitly stated with each operation, the specification adopts the following conventions for :ref:`runtime objects ` (:math:`\store`, :math:`\moduleinst`, :ref:`addresses `): * Every runtime object passed as a parameter must be :ref:`valid ` per an implicit pre-condition. @@ -89,7 +100,7 @@ Store .. math:: \begin{array}{lclll} - \F{store\_init}() &=& \{ \SFUNCS~\epsilon,~ \SMEMS~\epsilon,~ \STABLES~\epsilon,~ \SGLOBALS~\epsilon \} \\ + \F{store\_init}() &=& \{ \} \\ \end{array} @@ -153,10 +164,10 @@ Modules .. index:: instantiation, module instance .. _embed-module-instantiate: -:math:`\F{module\_instantiate}(\store, \module, \externval^\ast) : (\store, \moduleinst ~|~ \error)` -.................................................................................................... +:math:`\F{module\_instantiate}(\store, \module, \externaddr^\ast) : (\store, \moduleinst ~|~ \error)` +..................................................................................................... -1. Try :ref:`instantiating ` :math:`\module` in :math:`\store` with :ref:`external values ` :math:`\externval^\ast` as imports: +1. Try :ref:`instantiating ` :math:`\module` in :math:`\store` with :ref:`external addresses ` :math:`\externaddr^\ast` as imports: a. If it succeeds with a :ref:`module instance ` :math:`\moduleinst`, then let :math:`\X{result}` be :math:`\moduleinst`. @@ -167,7 +178,7 @@ Modules .. math:: \begin{array}{lclll} \F{module\_instantiate}(S, m, \X{ev}^\ast) &=& (S', F.\AMODULE) && (\iff \instantiate(S, m, \X{ev}^\ast) \stepto^\ast S'; F; \epsilon) \\ - \F{module\_instantiate}(S, m, \X{ev}^\ast) &=& (S', \ERROR) && (\iff \instantiate(S, m, \X{ev}^\ast) \stepto^\ast S'; F; \TRAP) \\ + \F{module\_instantiate}(S, m, \X{ev}^\ast) &=& (S', \ERROR) && (\otherwise, \iff \instantiate(S, m, \X{ev}^\ast) \stepto^\ast S'; F; \result) \\ \end{array} .. note:: @@ -216,7 +227,7 @@ Modules 4. For each :math:`\export_i` in :math:`\export^\ast` and corresponding :math:`\externtype'_i` in :math:`{\externtype'}^\ast`, do: - a. Let :math:`\X{result}_i` be the pair :math:`(\export_i.\ENAME, \externtype'_i)`. + a. Let :math:`\X{result}_i` be the pair :math:`(\export_i.\XNAME, \externtype'_i)`. 5. Return the concatenation of all :math:`\X{result}_i`, in index order. @@ -225,7 +236,7 @@ Modules .. math:: ~ \\ \begin{array}{lclll} - \F{module\_exports}(m) &=& (\X{ex}.\ENAME, \externtype')^\ast \\ + \F{module\_exports}(m) &=& (\X{ex}.\XNAME, \externtype')^\ast \\ && \qquad (\iff \X{ex}^\ast = m.\MEXPORTS \wedge {} \vdashmodule m : \externtype^\ast \rightarrow {\externtype'}^\ast) \\ \end{array} @@ -240,21 +251,21 @@ Module Instances .. _embed-instance-export: -:math:`\F{instance\_export}(\moduleinst, \name) : \externval ~|~ \error` -........................................................................ +:math:`\F{instance\_export}(\moduleinst, \name) : \externaddr ~|~ \error` +......................................................................... 1. Assert: due to :ref:`validity ` of the :ref:`module instance ` :math:`\moduleinst`, all its :ref:`export names ` are different. -2. If there exists an :math:`\exportinst_i` in :math:`\moduleinst.\MIEXPORTS` such that :ref:`name ` :math:`\exportinst_i.\EINAME` equals :math:`\name`, then: +2. If there exists an :math:`\exportinst_i` in :math:`\moduleinst.\MIEXPORTS` such that :ref:`name ` :math:`\exportinst_i.\XINAME` equals :math:`\name`, then: - a. Return the :ref:`external value ` :math:`\exportinst_i.\EIVALUE`. + a. Return the :ref:`external address ` :math:`\exportinst_i.\XIADDR`. 3. Else, return :math:`\ERROR`. .. math:: ~ \\ \begin{array}{lclll} - \F{instance\_export}(m, \name) &=& m.\MIEXPORTS[i].\EIVALUE && (\iff m.\MEXPORTS[i].\EINAME = \name) \\ + \F{instance\_export}(m, \name) &=& m.\MIEXPORTS[i].\XIADDR && (\iff m.\MEXPORTS[i].\XINAME = \name) \\ \F{instance\_export}(m, \name) &=& \ERROR && (\otherwise) \\ \end{array} @@ -307,14 +318,16 @@ Functions .. index:: invocation, value, result .. _embed-func-invoke: -:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \error)` -........................................................................................ +:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \exception ~|~ \error)` +...................................................................................................... 1. Try :ref:`invoking ` the function :math:`\funcaddr` in :math:`\store` with :ref:`values ` :math:`\val^\ast` as arguments: a. If it succeeds with :ref:`values ` :math:`{\val'}^\ast` as results, then let :math:`\X{result}` be :math:`{\val'}^\ast`. - b. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`. + b. Else if the outcome is an exception with a thrown :ref:`exception ` :math:`\REFEXNADDR~\exnaddr` as the result, then let :math:`\X{result}` be :math:`\EXCEPTION~\exnaddr` + + c. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`. 2. Return the new store paired with :math:`\X{result}`. @@ -322,6 +335,7 @@ Functions ~ \\ \begin{array}{lclll} \F{func\_invoke}(S, a, v^\ast) &=& (S', {v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; {v'}^\ast) \\ + \F{func\_invoke}(S, a, v^\ast) &=& (S', \EXCEPTION~a') && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; (\REFEXNADDR~a')~\THROWREF \\ \F{func\_invoke}(S, a, v^\ast) &=& (S', \ERROR) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \TRAP) \\ \end{array} @@ -553,6 +567,99 @@ Memories \end{array} +.. index:: tag, tag address, store, tag instance, tag type, function type +.. _embed-tag: + +Tags +~~~~ + +.. _embedd-tag-alloc: + +:math:`\F{tag\_alloc}(\store, \tagtype) : (\store, \tagaddr)` +............................................................. + +1. Pre-condition: :math:`tagtype` is :ref:`valid `. + +2. Let :math:`\tagaddr` be the result of :ref:`allocating a tag ` in :math:`\store` with :ref:`tag type ` :math:`\tagtype`. + +3. Return the new store paired with :math:`\tagaddr`. + +.. math:: + \begin{array}{lclll} + \F{tag\_alloc}(S, \X{tt}) &=& (S', \X{a}) && (\iff \alloctag(S, \X{tt}) = S', \X{a}) \\ + \end{array} + + +.. _embed-tag-type: + +:math:`\F{tag\_type}(\store, \tagaddr) : \tagtype` +.................................................. + +1. Return :math:`S.\STAGS[a].\HITYPE`. + +2. Post-condition: the returned :ref:`tag type ` is :ref:`valid `. + +.. math:: + \begin{array}{lclll} + \F{tag\_type}(S, a) &=& S.\STAGS[a].\HITYPE \\ + \end{array} + + +.. index:: exception, exception address, store, exception instance, exception type +.. _embed-exception: + +Exceptions +~~~~~~~~~~ + +.. _embed-exn-alloc: + +:math:`\F{exn\_alloc}(\store, \tagaddr, \val^\ast) : (\store, \exnaddr)` +........................................................................ + +1. Pre-condition: :math:`\tagaddr` is an allocated :ref:`tag address `. + +2. Let :math:`\exnaddr` be the result of :ref:`allocating an exception instance ` in :math:`\store` with :ref:`tag address ` :math:`\tagaddr` and initialization values :math:`\val^\ast`. + +3. Return the new store paired with :math:`\exnaddr`. + +.. math:: + \begin{array}{lcll} + \F{exn\_alloc}(S, \tagaddr, \val^\ast) &=& (S \compose \{\SEXNS~\exninst\}, |S.\SEXNS|) & + (\iff \exninst = \{\EITAG~\tagaddr, \EIFIELDS~\val^\ast\} \\ + \end{array} + + +.. _embed-exn-tag: + +:math:`\F{exn\_tag}(\store, \exnaddr) : \tagaddr` +................................................. + +1. Let :math:`\exninst` be the :ref:`exception instance ` :math:`\store.\SEXNS[\exnaddr]`. + +2. Return the :ref:`tag address ` :math:`\exninst.\EITAG`. + +.. math:: + \begin{array}{lcll} + \F{exn\_tag}(S, a) &=& \exninst.\EITAG & + (\iff \exninst = S.\SEXNS[a]) \\ + \end{array} + + +.. _embed-exn-read: + +:math:`\F{exn\_read}(\store, \exnaddr) : \val^\ast` +................................................... + +1. Let :math:`\exninst` be the :ref:`exception instance ` :math:`\store.\SEXNS[\exnaddr]`. + +2. Return the :ref:`values ` :math:`\exninst.\EIFIELDS`. + +.. math:: + \begin{array}{lcll} + \F{exn\_read}(S, a) &=& \exninst.\EIFIELDS & + (\iff \exninst = S.\SEXNS[a]) \\ + \end{array} + .. index:: global, global address, store, global instance, global type, value .. _embed-global: diff --git a/document/core/appendix/implementation.rst b/document/core/appendix/implementation.rst index 6de60fb587..15fe69357c 100644 --- a/document/core/appendix/implementation.rst +++ b/document/core/appendix/implementation.rst @@ -24,7 +24,7 @@ However, it is expected that all implementations have "reasonably" large limits Syntactic Limits ~~~~~~~~~~~~~~~~ -.. index:: abstract syntax, module, type, function, table, memory, global, element, data, import, export, parameter, result, local, structured control instruction, instruction, name, Unicode, character +.. index:: abstract syntax, module, type, function, table, memory, global, tag, element, data, import, export, parameter, result, local, structured control instruction, instruction, name, Unicode, character .. _impl-syntax: Structure @@ -37,6 +37,7 @@ An implementation may impose restrictions on the following dimensions of a modul * the number of :ref:`tables ` in a :ref:`module `, including imports * the number of :ref:`memories ` in a :ref:`module `, including imports * the number of :ref:`globals ` in a :ref:`module `, including imports +* the number of :ref:`tags ` in a :ref:`module `, including imports * the number of :ref:`element segments ` in a :ref:`module ` * the number of :ref:`data segments ` in a :ref:`module ` * the number of :ref:`imports ` to a :ref:`module ` @@ -131,8 +132,10 @@ Restrictions on the following dimensions may be imposed during :ref:`execution < * the number of allocated :ref:`table instances ` * the number of allocated :ref:`memory instances ` * the number of allocated :ref:`global instances ` +* the number of allocated :ref:`tag instances ` * the number of allocated :ref:`structure instances ` * the number of allocated :ref:`array instances ` +* the number of allocated :ref:`exception instances ` * the size of a :ref:`table instance ` * the size of a :ref:`memory instance ` * the size of an :ref:`array instance ` diff --git a/document/core/appendix/index-instructions.py b/document/core/appendix/index-instructions.py index 1b86ea3dd2..41c140da1d 100755 --- a/document/core/appendix/index-instructions.py +++ b/document/core/appendix/index-instructions.py @@ -52,17 +52,26 @@ def RefWrap(s, kind): return f':ref:`{kind} <{s}>`' -def Instruction(name, opcode, type=None, validation=None, execution=None, operator=None): +def Instruction(name, opcode, type=None, validation=None, execution=None, operator=None, validation2=None, execution2=None): if operator: execution_str = 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), - RefWrap(validation, 'validation'), + validation_str, execution_str ) @@ -76,9 +85,9 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat Instruction(r'\ELSE', r'\hex{05}'), Instruction(None, r'\hex{06}'), Instruction(None, r'\hex{07}'), - Instruction(None, r'\hex{08}'), + Instruction(r'\THROW~x', r'\hex{08}', r'[t_1^\ast~t_x^\ast] \to [t_2^\ast]', r'valid-throw', r'exec-throw'), Instruction(None, r'\hex{09}'), - Instruction(None, r'\hex{0A}'), + Instruction(r'\THROWREF', r'\hex{0A}', r'[t_1^\ast~\EXNREF] \to [t_2^\ast]', r'valid-throw_ref', r'exec-throw_ref'), Instruction(r'\END', r'\hex{0B}'), Instruction(r'\BR~l', r'\hex{0C}', r'[t_1^\ast~t^\ast] \to [t_2^\ast]', r'valid-br', r'exec-br'), Instruction(r'\BRIF~l', r'\hex{0D}', r'[t^\ast~\I32] \to [t^\ast]', r'valid-br_if', r'exec-br_if'), @@ -99,7 +108,7 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat Instruction(r'\SELECT~t', r'\hex{1C}', r'[t~t~\I32] \to [t]', r'valid-select', r'exec-select'), Instruction(None, r'\hex{1D}'), Instruction(None, r'\hex{1E}'), - Instruction(None, r'\hex{1F}'), + Instruction(r'\TRYTABLE~\X{bt}', r'\hex{1F}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-try_table', r'exec-try_table'), Instruction(r'\LOCALGET~x', r'\hex{20}', r'[] \to [t]', r'valid-local.get', r'exec-local.get'), Instruction(r'\LOCALSET~x', r'\hex{21}', r'[t] \to []', r'valid-local.set', r'exec-local.set'), Instruction(r'\LOCALTEE~x', r'\hex{22}', r'[t] \to [t]', r'valid-local.tee', r'exec-local.tee'), diff --git a/document/core/appendix/index-rules.rst b/document/core/appendix/index-rules.rst index 4edbc49527..5c523a2b94 100644 --- a/document/core/appendix/index-rules.rst +++ b/document/core/appendix/index-rules.rst @@ -34,6 +34,7 @@ Construct Judgement :ref:`Table type ` :math:`C \vdashtabletype \tabletype : \OKtabletype` :ref:`Memory type ` :math:`C \vdashmemtype \memtype : \OKmemtype` :ref:`Global type ` :math:`C \vdashglobaltype \globaltype : \OKglobaltype` +:ref:`Tag type ` :math:`C \vdashtagtype \tagtype : \OKtagtype` :ref:`External type ` :math:`C \vdashexterntype \externtype : \OKexterntype` :ref:`Type definitions ` :math:`C \vdashtypes \type^\ast : \OKtypes` =============================================== ================================================================================= @@ -45,8 +46,9 @@ Typing of Static Constructs =============================================== ================================================================================= Construct Judgement =============================================== ================================================================================= -:ref:`Instruction ` :math:`S;C \vdashinstr \instr : \functype` -:ref:`Instruction sequence ` :math:`S;C \vdashinstrs \instr^\ast : \functype` +:ref:`Instruction ` :math:`S;C \vdashinstr \instr : \instrtype` +:ref:`Instruction sequence ` :math:`S;C \vdashinstrs \instr^\ast : \instrtype` +:ref:`Catch clause ` :math:`C \vdashcatch \catch : \OKcatch` :ref:`Expression ` :math:`C \vdashexpr \expr : \resulttype` :ref:`Function ` :math:`C \vdashfunc \func : \functype` :ref:`Local ` :math:`C \vdashlocal \local : \localtype` @@ -54,6 +56,7 @@ Construct Judgement :ref:`Memory ` :math:`C \vdashmem \mem : \memtype` :ref:`Limits ` :math:`C \vdashlimits \limits : k` :ref:`Global ` :math:`C \vdashglobal \global : \globaltype` +:ref:`Tag ` :math:`C \vdashtag \tag : \tagtype` :ref:`Element segment ` :math:`C \vdashelem \elem : \reftype` :ref:`Element mode ` :math:`C \vdashelemmode \elemmode : \reftype` :ref:`Data segment ` :math:`C \vdashdata \data : \OKdata` @@ -79,11 +82,12 @@ Construct Judgement :ref:`Result ` :math:`S \vdashresult \result : \resulttype` :ref:`Packed value ` :math:`S \vdashpackval \packval : \packtype` :ref:`Field value ` :math:`S \vdashfieldval \fieldval : \storagetype` -:ref:`External value ` :math:`S \vdashexternval \externval : \externtype` +:ref:`External address ` :math:`S \vdashexternaddr \externaddr : \externtype` :ref:`Function instance ` :math:`S \vdashfuncinst \funcinst : \functype` :ref:`Table instance ` :math:`S \vdashtableinst \tableinst : \tabletype` :ref:`Memory instance ` :math:`S \vdashmeminst \meminst : \memtype` :ref:`Global instance ` :math:`S \vdashglobalinst \globalinst : \globaltype` +:ref:`Tag instance ` :math:`S \vdashtaginst \taginst : \tagtype` :ref:`Element instance ` :math:`S \vdasheleminst \eleminst : t` :ref:`Data instance ` :math:`S \vdashdatainst \datainst : \OKdatainst` :ref:`Structure instance ` :math:`S \vdashstructinst \structinst : \OKstructinst` @@ -132,6 +136,7 @@ Construct Judgement :ref:`Table type ` :math:`C \vdashtabletypematch \tabletype_1 \subtabletypematch \tabletype_2` :ref:`Memory type ` :math:`C \vdashmemtypematch \memtype_1 \submemtypematch \memtype_2` :ref:`Global type ` :math:`C \vdashglobaltypematch \globaltype_1 \subglobaltypematch \globaltype_2` +:ref:`Tag type ` :math:`C \vdashtagtypematch \tagtype_1 \subtagtypematch \tagtype_2` :ref:`External type ` :math:`C \vdashexterntypematch \externtype_1 \subexterntypematch \externtype_2` :ref:`Limits ` :math:`C \vdashlimitsmatch \limits_1 \sublimitsmatch \limits_2` =============================================== =================================================================================== @@ -147,6 +152,7 @@ Construct Judgement :ref:`Table instance ` :math:`\vdashtableinstextends \tableinst_1 \extendsto \tableinst_2` :ref:`Memory instance ` :math:`\vdashmeminstextends \meminst_1 \extendsto \meminst_2` :ref:`Global instance ` :math:`\vdashglobalinstextends \globalinst_1 \extendsto \globalinst_2` +:ref:`Tag instance ` :math:`\vdashtaginstextends \taginst_1 \extendsto \taginst_2` :ref:`Element instance ` :math:`\vdasheleminstextends \eleminst_1 \extendsto \eleminst_2` :ref:`Data instance ` :math:`\vdashdatainstextends \datainst_1 \extendsto \datainst_2` :ref:`Structure instance ` :math:`\vdashstructinstextends \structinst_1 \extendsto \structinst_2` diff --git a/document/core/appendix/index-types.rst b/document/core/appendix/index-types.rst index 9339bebdd0..6bd849c8ab 100644 --- a/document/core/appendix/index-types.rst +++ b/document/core/appendix/index-types.rst @@ -16,7 +16,8 @@ Category Constructor (reserved) :math:`\hex{7A}` .. :math:`\hex{79}` :ref:`Packed type ` |I8| :math:`\hex{78}` (-8 as |Bs7|) :ref:`Packed type ` |I16| :math:`\hex{77}` (-9 as |Bs7|) -(reserved) :math:`\hex{78}` .. :math:`\hex{74}` +(reserved) :math:`\hex{78}` .. :math:`\hex{75}` +:ref:`Heap type ` |NOEXN| :math:`\hex{74}` (-14 as |Bs7|) :ref:`Heap type ` |NOFUNC| :math:`\hex{73}` (-13 as |Bs7|) :ref:`Heap type ` |NOEXTERN| :math:`\hex{72}` (-14 as |Bs7|) :ref:`Heap type ` |NONE| :math:`\hex{71}` (-15 as |Bs7|) @@ -27,7 +28,8 @@ Category Constructor :ref:`Heap type ` |I31| :math:`\hex{6C}` (-20 as |Bs7|) :ref:`Heap type ` |STRUCT| :math:`\hex{6B}` (-21 as |Bs7|) :ref:`Heap type ` |ARRAY| :math:`\hex{6A}` (-22 as |Bs7|) -(reserved) :math:`\hex{69}` .. :math:`\hex{65}` +:ref:`Heap type ` |EXN| :math:`\hex{69}` (-23 as |Bs7|) +(reserved) :math:`\hex{68}` .. :math:`\hex{65}` :ref:`Reference type ` |REF| :math:`\hex{64}` (-28 as |Bs7|) :ref:`Reference type ` |REF| |NULL| :math:`\hex{63}` (-29 as |Bs7|) (reserved) :math:`\hex{62}` .. :math:`\hex{61}` @@ -43,4 +45,5 @@ Category Constructor :ref:`Table type ` :math:`\limits~\reftype` (none) :ref:`Memory type ` :math:`\limits` (none) :ref:`Global type ` :math:`\mut~\valtype` (none) +:ref:`Tag type ` :math:`\functype` (none) ======================================== ================================================== =============================================================== diff --git a/document/core/appendix/properties.rst b/document/core/appendix/properties.rst index f78541f5ca..6ec9c8c1e1 100644 --- a/document/core/appendix/properties.rst +++ b/document/core/appendix/properties.rst @@ -7,7 +7,7 @@ Type Soundness The :ref:`type system ` of WebAssembly is *sound*, implying both *type safety* and *memory safety* with respect to the WebAssembly semantics. For example: * All types declared and derived during validation are respected at run time; - e.g., every :ref:`local ` or :ref:`global ` variable will only contain type-correct values, every :ref:`instruction ` will only be applied to operands of the expected type, and every :ref:`function ` :ref:`invocation ` always evaluates to a result of the right type (if it does not :ref:`trap ` or diverge). + e.g., every :ref:`local ` or :ref:`global ` variable will only contain type-correct values, every :ref:`instruction ` will only be applied to operands of the expected type, and every :ref:`function ` :ref:`invocation ` always evaluates to a result of the right type (if it does not diverge, throw an exception, or :ref:`trap `). * No memory location will be read or written except those explicitly defined by the program, i.e., as a :ref:`local `, a :ref:`global `, an element in a :ref:`table `, or a location within a linear :ref:`memory `. @@ -219,7 +219,7 @@ In a :ref:`rolled-up ` :ref:`recursive type `, This rule is only invoked when checking :ref:`validity ` of :ref:`rolled-up ` :ref:`recursive types `. -.. index:: value, value type, result, result type, trap +.. index:: value, value type, result, result type, trap, exception, throw .. _valid-result: Results @@ -246,6 +246,23 @@ Results } +:ref:`Results ` :math:`(\REFEXNADDR~a)~\THROWREF` +................................................................ + +* The value :math:`\REFEXNADDR~a` must be :ref:`valid `. + +* Then the result is valid with :ref:`result type ` :math:`[t^\ast]`, for any :ref:`valid ` :ref:`closed ` :ref:`result types `. + +.. math:: + \frac{ + S \vdashval REFEXNADDR~a : REF~EXN + \qquad + \vdashresulttype [t^\ast] : \OKresulttype + }{ + S \vdashresult (\REFEXNADDR~a)~\THROWREF : [{t'}^\ast] + } + + :ref:`Results ` :math:`\TRAP` ............................................ @@ -267,14 +284,37 @@ Store Validity The following typing rules specify when a runtime :ref:`store ` :math:`S` is *valid*. A valid store must consist of -:ref:`function `, :ref:`table `, :ref:`memory `, :ref:`global `, and :ref:`module ` instances that are themselves valid, relative to :math:`S`. - -To that end, each kind of instance is classified by a respective :ref:`function `, :ref:`table `, :ref:`memory `, or :ref:`global ` type. +:ref:`function `, +:ref:`table `, +:ref:`memory `, +:ref:`global `, +:ref:`tag `, +:ref:`element `, +:ref:`data `, +:ref:`structure `, +:ref:`array `, +:ref:`exception `, +and +:ref:`module ` +instances that are themselves valid, relative to :math:`S`. + +To that end, each kind of instance is classified by a respective +:ref:`function `, +:ref:`table `, +:ref:`memory `, +:ref:`global `, +:ref:`tag `, +:ref:`element `, or +:ref:`data ` +type, or just ${:OK} in the case of +:ref:`structures `, +:ref:`arrays `, or +:ref:`exceptions `. Module instances are classified by *module contexts*, which are regular :ref:`contexts ` repurposed as module types describing the :ref:`index spaces ` defined by a module. -.. index:: store, function instance, table instance, memory instance, structure instance, array instance, global instance, function type, table type, memory type, global type, defined type, structure type, array type +.. index:: store, function instance, table instance, memory instance, structure instance, array instance, global instance, tag instance, function type, table type, memory type, global type, tag type, defined type, structure type, array type :ref:`Store ` :math:`S` ..................................... @@ -287,6 +327,8 @@ Module instances are classified by *module contexts*, which are regular :ref:`co * Each :ref:`global instance ` :math:`\globalinst_i` in :math:`S.\SGLOBALS` must be :ref:`valid ` with some :ref:`global type ` :math:`\globaltype_i`. +* Each :ref:`tag instance ` :math:`\taginst_i` in :math:`S.\STAGS` must be :ref:`valid ` with some :ref:`tag type ` :math:`\tagtype_i`. + * Each :ref:`element instance ` :math:`\eleminst_i` in :math:`S.\SELEMS` must be :ref:`valid ` with some :ref:`reference type ` :math:`\reftype_i`. * Each :ref:`data instance ` :math:`\datainst_i` in :math:`S.\SDATAS` must be :ref:`valid `. @@ -295,9 +337,13 @@ Module instances are classified by *module contexts*, which are regular :ref:`co * Each :ref:`array instance ` :math:`\arrayinst_i` in :math:`S.\SARRAYS` must be :ref:`valid `. -* No :ref:`reference ` to a bound :ref:`structure address ` must be reachable from itself through a path consisting only of indirections through immutable structure or array :ref:`fields `. +* Each :ref:`exception instance ` :math:`\exninst_i` in :math:`S.\SEXNS` must be :ref:`valid `. + +* No :ref:`reference ` to a bound :ref:`structure address ` must be reachable from itself through a path consisting only of indirections through immutable structure, or array :ref:`fields ` or fields of :ref:`exception instances `. -* No :ref:`reference ` to a bound :ref:`array address ` must be reachable from itself through a path consisting only of indirections through immutable structure or array :ref:`fields `. +* No :ref:`reference ` to a bound :ref:`array address ` must be reachable from itself through a path consisting only of indirections through immutable structure or array :ref:`fields ` or fields of :ref:`exception instances `. + +* No :ref:`reference ` to a bound :ref:`exception address ` must be reachable from itself through a path consisting only of indirections through immutable structure or array :ref:`fields ` or fields of :ref:`exception instances `. * Then the store is valid. @@ -313,6 +359,8 @@ Module instances are classified by *module contexts*, which are regular :ref:`co \qquad (S \vdashglobalinst \globalinst : \globaltype)^\ast \\ + (S \vdashtaginst \taginst : \tagtype)^\ast + \\ (S \vdasheleminst \eleminst : \reftype)^\ast \qquad (S \vdashdatainst \datainst : \OKdatainst)^\ast @@ -320,17 +368,21 @@ Module instances are classified by *module contexts*, which are regular :ref:`co (S \vdashstructinst \structinst : \OKstructinst)^\ast \qquad (S \vdasharrayinst \arrayinst : \OKarrayinst)^\ast + \qquad + (S \vdashexninst \exninst : \OKexninst)^\ast \\ S = \{ \begin{array}[t]{@{}l@{}} \SFUNCS~\funcinst^\ast, \SGLOBALS~\globalinst^\ast, \STABLES~\tableinst^\ast, - \SMEMS~\meminst^\ast, \\ + \SMEMS~\meminst^\ast, + \STAGS~\taginst^\ast, \\ \SELEMS~\eleminst^\ast, \SDATAS~\datainst^\ast, \SSTRUCTS~\structinst^\ast, - \SARRAYS~\arrayinst^\ast \} + \SARRAYS~\arrayinst^\ast, + \SEXNS~\exninst^\ast \} \end{array} \\ (S.\SSTRUCTS[a_{\F{s}}] = \structinst)^\ast @@ -340,6 +392,10 @@ Module instances are classified by *module contexts*, which are regular :ref:`co (S.\SARRAYS[a_{\F{a}}] = \arrayinst)^\ast \qquad ((\REFARRAYADDR~a_{\F{a}}) \not\gg^+_S (\REFARRAYADDR~a_{\F{a}}))^\ast + \\ + (S.\SEXNS[a_{\F{e}}] = \exninst)^\ast + \qquad + ((\REFEXNADDR~a_{\F{e}}) \not\gg^+_S (\REFEXNADDR~a_{\F{e}}))^\ast \end{array} }{ \vdashstore S : \OKstore @@ -347,7 +403,7 @@ Module instances are classified by *module contexts*, which are regular :ref:`co .. index:: reachability -where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the following *reachability* relation on :ref:`values `: +where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the following *immutable reachability* relation on :ref:`values `: .. math:: \begin{array}{@{}lcll@{}} @@ -355,6 +411,7 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow & \iff \expanddt(S.\SSTRUCTS[a].\SITYPE) = \TSTRUCT~\X{ft}_1^i~(\MCONST~\X{st})~\X{ft}_2^\ast \\ (\REFARRAYADDR~a) &\gg_S& S.\SARRAYS[a].\AIFIELDS[i] & \iff \expanddt(S.\SARRAYS[a].\AITYPE) = \TARRAY~(\MCONST~\X{st}) \\ + (\REFEXNADDR~a) &\gg_S& S.\SEXNS[a].\EIFIELDS[i] \\ (\REFEXTERN~\reff) &\gg_S& \reff \\ \end{array} @@ -532,6 +589,24 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow } +.. index:: tag type, tag instance +.. _valid-taginst: + +:ref:`Tag Instances ` :math:`\{ \HITYPE~\tagtype \}` +.................................................................... + +* The :ref:`tag type ` :math:`\tagtype` must be :ref:`valid ` under the empty :ref:`context `. + +* Then the tag instance is valid with :ref:`tag type ` :math:`\tagtype`. + +.. math:: + \frac{ + \vdashtagtype \tagtype : \OKtagtype + }{ + S \vdashtaginst \{ \HITYPE~\tagtype \} : \tagtype + } + + .. index:: element instance, reference .. _valid-eleminst: @@ -581,7 +656,7 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow :ref:`Structure Instances ` :math:`\{ \SITYPE~\deftype, \SIFIELDS~\fieldval^\ast \}` ....................................................................................................... -* The :ref:`defined type ` :math:`\deftype` must be :ref:`valid `. +* The :ref:`defined type ` :math:`\deftype` must be :ref:`valid ` under the empty :ref:`context `. * The :ref:`expansion ` of :math:`\deftype` must be a :ref:`structure type ` :math:`\TSTRUCT~\fieldtype^\ast`. @@ -613,7 +688,7 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow :ref:`Array Instances ` :math:`\{ \AITYPE~\deftype, \AIFIELDS~\fieldval^\ast \}` .................................................................................................. -* The :ref:`defined type ` :math:`\deftype` must be :ref:`valid `. +* The :ref:`defined type ` :math:`\deftype` must be :ref:`valid ` under the empty :ref:`context `. * The :ref:`expansion ` of :math:`\deftype` must be an :ref:`array type ` :math:`\TARRAY~\fieldtype`. @@ -663,21 +738,49 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow } -.. index:: external type, export instance, name, external value +.. index:: exception instance, tag, tag address +.. _valid-exninst: + +:ref:`Exception Instances ` :math:`\{ \EITAG~a, \EIFIELDS~\val^\ast \}` +....................................................................................... + +* The store entry :math:`S.\STAGS[a]` must exist. + +* Let :math:`[t^\ast] \toF [{t'}^\ast]` be the :ref:`tag type ` :math:`S.\STAGS[a].\HITYPE`. + +* The :ref:`result type ` :math:`[{t'}^\ast]` must be empty. + +* The sequence :math:`\val^ast` of :ref:`values ` must have the same length as the sequence :math:`t^\ast` of :ref:`value types `. + +* For each value :math:`\val_i` in :math:`\val^ast` and corresponding value type :math:`t_i` in :math:`t^\ast`, the value :math:`\val_i` must be valid with type :math:`t_i`. + +* Then the exception instance is valid. + +.. math:: + \frac{ + S.\STAGS[a] = \{\HITYPE = [t^\ast] \toF []\} + \qquad + (S \vdashval \val : t)^\ast + }{ + S \vdashexninst \{ \EITAG~a, \EIFIELDS~\val^\ast \} : \OKexninst + } + + +.. index:: external type, export instance, name, external address .. _valid-exportinst: -:ref:`Export Instances ` :math:`\{ \EINAME~\name, \EIVALUE~\externval \}` -....................................................................................................... +:ref:`Export Instances ` :math:`\{ \XINAME~\name, \XIADDR~\externaddr \}` +............................................................................................ -* The :ref:`external value ` :math:`\externval` must be :ref:`valid ` with some :ref:`external type ` :math:`\externtype`. +* The :ref:`external address ` :math:`\externaddr` must be :ref:`valid ` with some :ref:`external type ` :math:`\externtype`. * Then the export instance is valid. .. math:: \frac{ - S \vdashexternval \externval : \externtype + S \vdashexternaddr \externaddr : \externtype }{ - S \vdashexportinst \{ \EINAME~\name, \EIVALUE~\externval \} : \OKexportinst + S \vdashexportinst \{ \XINAME~\name, \XIADDR~\externaddr \} : \OKexportinst } @@ -689,13 +792,15 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow * Each :ref:`defined type ` :math:`\deftype_i` in :math:`\moduleinst.\MITYPES` must be :ref:`valid ` under the empty :ref:`context `. -* For each :ref:`function address ` :math:`\funcaddr_i` in :math:`\moduleinst.\MIFUNCS`, the :ref:`external value ` :math:`\EVFUNC~\funcaddr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\ETFUNC~\functype_i`. +* For each :ref:`function address ` :math:`\funcaddr_i` in :math:`\moduleinst.\MIFUNCS`, the :ref:`external address ` :math:`\XAFUNC~\funcaddr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\XTFUNC~\functype_i`. -* For each :ref:`table address ` :math:`\tableaddr_i` in :math:`\moduleinst.\MITABLES`, the :ref:`external value ` :math:`\EVTABLE~\tableaddr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\ETTABLE~\tabletype_i`. +* For each :ref:`table address ` :math:`\tableaddr_i` in :math:`\moduleinst.\MITABLES`, the :ref:`external address ` :math:`\XATABLE~\tableaddr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\XTTABLE~\tabletype_i`. -* For each :ref:`memory address ` :math:`\memaddr_i` in :math:`\moduleinst.\MIMEMS`, the :ref:`external value ` :math:`\EVMEM~\memaddr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\ETMEM~\memtype_i`. +* For each :ref:`memory address ` :math:`\memaddr_i` in :math:`\moduleinst.\MIMEMS`, the :ref:`external address ` :math:`\XAMEM~\memaddr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\XTMEM~\memtype_i`. -* For each :ref:`global address ` :math:`\globaladdr_i` in :math:`\moduleinst.\MIGLOBALS`, the :ref:`external value ` :math:`\EVGLOBAL~\globaladdr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\ETGLOBAL~\globaltype_i`. +* For each :ref:`global address ` :math:`\globaladdr_i` in :math:`\moduleinst.\MIGLOBALS`, the :ref:`external address ` :math:`\XAGLOBAL~\globaladdr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\XTGLOBAL~\globaltype_i`. + +* For each :ref:`tag address ` :math:`\tagaddr_i` in :math:`\moduleinst.\MITAGS`, the :ref:`external address ` :math:`\XATAG~\tagaddr_i` must be :ref:`valid ` with some :ref:`external type ` :math:`\XTTAG~\tagtype_i`. * For each :ref:`element address ` :math:`\elemaddr_i` in :math:`\moduleinst.\MIELEMS`, the :ref:`element instance ` :math:`S.\SELEMS[\elemaddr_i]` must be :ref:`valid ` with some :ref:`reference type ` :math:`\reftype_i`. @@ -703,7 +808,7 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow * Each :ref:`export instance ` :math:`\exportinst_i` in :math:`\moduleinst.\MIEXPORTS` must be :ref:`valid `. -* For each :ref:`export instance ` :math:`\exportinst_i` in :math:`\moduleinst.\MIEXPORTS`, the :ref:`name ` :math:`\exportinst_i.\EINAME` must be different from any other name occurring in :math:`\moduleinst.\MIEXPORTS`. +* For each :ref:`export instance ` :math:`\exportinst_i` in :math:`\moduleinst.\MIEXPORTS`, the :ref:`name ` :math:`\exportinst_i.\XINAME` must be different from any other name occurring in :math:`\moduleinst.\MIEXPORTS`. * Let :math:`\deftype^\ast` be the concatenation of all :math:`\deftype_i` in order. @@ -715,6 +820,8 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow * Let :math:`\globaltype^\ast` be the concatenation of all :math:`\globaltype_i` in order. +* Let :math:`\tagtype^\ast` be the concatenation of all :math:`\tagtype_i` in order. + * Let :math:`\reftype^\ast` be the concatenation of all :math:`\reftype_i` in order. * Let :math:`\X{ok}^\ast` be the concatenation of all :math:`\X{ok}_i` in order. @@ -724,7 +831,7 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow * Let :math:`x^\ast` be the sequence of :ref:`function indices ` from :math:`0` to :math:`m-1`. * Then the module instance is valid with :ref:`context ` - :math:`\{\CTYPES~\deftype^\ast,` :math:`\CFUNCS~\functype^\ast,` :math:`\CTABLES~\tabletype^\ast,` :math:`\CMEMS~\memtype^\ast,` :math:`\CGLOBALS~\globaltype^\ast,` :math:`\CELEMS~\reftype^\ast,` :math:`\CDATAS~\X{ok}^\ast,` :math:`\CREFS~x^\ast\}`. + :math:`\{\CTYPES~\deftype^\ast,` :math:`\CFUNCS~\functype^\ast,` :math:`\CTABLES~\tabletype^\ast,` :math:`\CMEMS~\memtype^\ast,` :math:`\CGLOBALS~\globaltype^\ast,` \CTAGS~\tagtype^\ast, :math:`\CELEMS~\reftype^\ast,` :math:`\CDATAS~\X{ok}^\ast,` :math:`\CREFS~x^\ast\}`. .. math:: ~\\[-1ex] @@ -732,13 +839,15 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow \begin{array}{@{}c@{}} (\vdashdeftype \deftype : \OKdeftype)^\ast \\ - (S \vdashexternval \EVFUNC~\funcaddr : \ETFUNC~\functype)^\ast + (S \vdashexternaddr \XAFUNC~\funcaddr : \XTFUNC~\functype)^\ast \qquad - (S \vdashexternval \EVTABLE~\tableaddr : \ETTABLE~\tabletype)^\ast + (S \vdashexternaddr \XATABLE~\tableaddr : \XTTABLE~\tabletype)^\ast \\ - (S \vdashexternval \EVMEM~\memaddr : \ETMEM~\memtype)^\ast + (S \vdashexternaddr \XAMEM~\memaddr : \XTMEM~\memtype)^\ast \qquad - (S \vdashexternval \EVGLOBAL~\globaladdr : \ETGLOBAL~\globaltype)^\ast + (S \vdashexternaddr \XAGLOBAL~\globaladdr : \XTGLOBAL~\globaltype)^\ast + \\ + (S \vdashexternaddr \XATAG~\tagaddr : \XTTAG~\tagtype)^\ast \\ (S \vdasheleminst S.\SELEMS[\elemaddr] : \reftype)^\ast \qquad @@ -746,7 +855,7 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow \\ (S \vdashexportinst \exportinst : \OKexportinst)^\ast \qquad - (\exportinst.\EINAME)^\ast ~\mbox{disjoint} + (\exportinst.\XINAME)^\ast ~\mbox{disjoint} \end{array} }{ S \vdashmoduleinst \{ @@ -756,6 +865,7 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow \MITABLES & \tableaddr^\ast, \\ \MIMEMS & \memaddr^\ast, \\ \MIGLOBALS & \globaladdr^\ast, \\ + \MITAGS & \tagaddr^\ast, \\ \MIELEMS & \elemaddr^\ast, \\ \MIDATAS & \dataaddr^\ast, \\ \MIEXPORTS & \exportinst^\ast ~\} : \{ @@ -765,6 +875,7 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow \CTABLES & \tabletype^\ast, \\ \CMEMS & \memtype^\ast, \\ \CGLOBALS & \globaltype^\ast, \\ + \CTAGS & \tagtype^\ast, \\ \CELEMS & \reftype^\ast, \\ \CDATAS & \X{ok}^\ast, \\ \CREFS & 0 \dots (|\funcaddr^\ast|-1) ~\} @@ -959,7 +1070,7 @@ To that end, all previous typing judgements :math:`C \vdash \X{prop}` are genera :math:`\INVOKE~\funcaddr` ......................... -* The :ref:`external function value ` :math:`\EVFUNC~\funcaddr` must be :ref:`valid ` with :ref:`external function type ` :math:`\ETFUNC \functype'`. +* The :ref:`external function address ` :math:`\XAFUNC~\funcaddr` must be :ref:`valid ` with :ref:`external function type ` :math:`\XTFUNC~\functype'`. * Let :math:`[t_1^\ast] \toF [t_2^\ast])` be the :ref:`function type ` :math:`\functype`. @@ -967,7 +1078,7 @@ To that end, all previous typing judgements :math:`C \vdash \X{prop}` are genera .. math:: \frac{ - S \vdashexternval \EVFUNC~\funcaddr : \ETFUNC~[t_1^\ast] \toF [t_2^\ast] + S \vdashexternaddr \XAFUNC~\funcaddr : \XTFUNC~[t_1^\ast] \toF [t_2^\ast] }{ S; C \vdashadmininstr \INVOKE~\funcaddr : [t_1^\ast] \to [t_2^\ast] } @@ -1000,7 +1111,7 @@ To that end, all previous typing judgements :math:`C \vdash \X{prop}` are genera .. index:: frame, instruction, result type :math:`\FRAME_n\{F\}~\instr^\ast~\END` -........................................... +...................................... * Under the :ref:`valid ` return type :math:`[t^n]`, the :ref:`thread ` :math:`F; \instr^\ast` must be :ref:`valid ` with :ref:`result type ` :math:`[t^n]`. @@ -1017,6 +1128,29 @@ To that end, all previous typing judgements :math:`C \vdash \X{prop}` are genera } +.. index:: handler, throw context + +:math:`\HANDLER_n\{\catch^\ast\}~\instr^\ast~\END` +.................................................. + +* For every :ref:`catch clause ` :math:`\catch_i` in :math:`\catch^\ast`, :math:`\catch_i` must be :ref:`valid `. + +* The instruction sequence :math:`\instr^\ast` must be :ref:`valid ` with some 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{ + \begin{array}{c} + (C \vdashcatch \catch : \OKcatch)^\ast + \qquad + S; C \vdashinstrs \instr^\ast : [t_1^\ast] \to [t_2^\ast] \\ + \end{array} + }{ + S; C \vdashadmininstr \HANDLER_n\{\catch^\ast\}~\instr^\ast~\END : [t_1^\ast] \to [t_2^\ast] + } + + .. index:: ! store extension, store .. _extend: @@ -1050,6 +1184,8 @@ a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S' * The length of :math:`S.\SGLOBALS` must not shrink. +* The length of :math:`S.\STAGS` must not shrink. + * The length of :math:`S.\SELEMS` must not shrink. * The length of :math:`S.\SDATAS` must not shrink. @@ -1058,6 +1194,8 @@ a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S' * The length of :math:`S.\SARRAYS` must not shrink. +* The length of :math:`S.\SEXNS` must not shrink. + * For each :ref:`function instance ` :math:`\funcinst_i` in the original :math:`S.\SFUNCS`, the new function instance must be an :ref:`extension ` of the old. * For each :ref:`table instance ` :math:`\tableinst_i` in the original :math:`S.\STABLES`, the new table instance must be an :ref:`extension ` of the old. @@ -1066,6 +1204,8 @@ a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S' * For each :ref:`global instance ` :math:`\globalinst_i` in the original :math:`S.\SGLOBALS`, the new global instance must be an :ref:`extension ` of the old. +* For each :ref:`tag instance ` :math:`\taginst_i` in the original :math:`S.\STAGS`, the new tag instance must be an :ref:`extension ` of the old. + * For each :ref:`element instance ` :math:`\eleminst_i` in the original :math:`S.\SELEMS`, the new element instance must be an :ref:`extension ` of the old. * For each :ref:`data instance ` :math:`\datainst_i` in the original :math:`S.\SDATAS`, the new data instance must be an :ref:`extension ` of the old. @@ -1074,6 +1214,8 @@ a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S' * For each :ref:`array instance ` :math:`\arrayinst_i` in the original :math:`S.\SARRAYS`, the new array instance must be an :ref:`extension ` of the old. +* For each :ref:`exception instance ` :math:`\exninst_i` in the original :math:`S.\SEXNS`, the new exception instance must be an :ref:`extension ` of the old. + .. math:: \frac{ \begin{array}{@{}ccc@{}} @@ -1089,6 +1231,9 @@ a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S' S_1.\SGLOBALS = \globalinst_1^\ast & S_2.\SGLOBALS = {\globalinst'_1}^\ast~\globalinst_2^\ast & (\vdashglobalinstextends \globalinst_1 \extendsto \globalinst'_1)^\ast \\ + S_1.\STAGS = \taginst_1^\ast & + S_2.\STAGS = {\taginst'_1}^\ast~\taginst_2^\ast & + (\vdashtaginstextends \taginst_1 \extendsto \taginst'_1)^\ast \\ S_1.\SELEMS = \eleminst_1^\ast & S_2.\SELEMS = {\eleminst'_1}^\ast~\eleminst_2^\ast & (\vdasheleminstextends \eleminst_1 \extendsto \eleminst'_1)^\ast \\ @@ -1101,6 +1246,9 @@ a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S' S_1.\SARRAYS = \arrayinst_1^\ast & S_2.\SARRAYS = {\arrayinst'_1}^\ast~\arrayinst_2^\ast & (\vdasharrayinstextends \arrayinst_1 \extendsto \arrayinst'_1)^\ast \\ + S_1.\SEXNS = \exninst_1^\ast & + S_2.\SEXNS = {\exninst'_1}^\ast~\exninst_2^\ast & + (\vdashexninstextends \exninst_1 \extendsto \exninst'_1)^\ast \\ \end{array} }{ \vdashstoreextends S_1 \extendsto S_2 @@ -1178,6 +1326,21 @@ a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S' } +.. index:: tag instance +.. _extend-taginst: + +:ref:`Tag Instance ` :math:`\taginst` +..................................................... + +* A tag instance must remain unchanged. + +.. math:: + \frac{ + }{ + \vdashtaginstextends \taginst \extendsto \taginst + } + + .. index:: element instance .. _extend-eleminst: @@ -1286,6 +1449,21 @@ a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S' } +.. index:: exception instance +.. _extend-exninst: + +:ref:`Exception Instance ` :math:`\exninst` +........................................................... + +* An exception instance must remain unchanged. + +.. math:: + \frac{ + }{ + \vdashexninstextends \exninst \extendsto \exninst + } + + .. index:: ! preservation, ! progress, soundness, configuration, thread, terminal configuration, instantiation, invocation, validity, module .. _soundness-statement: @@ -1317,7 +1495,7 @@ If a :ref:`configuration ` :math:`S;T` is :ref:`valid ` of :math:`S` (i.e., :math:`\vdashstoreextends S \extendsto S'`). -In other words, every thread in a valid configuration either runs forever, traps, or terminates with a result that has the expected type. +In other words, every thread in a valid configuration either runs forever, traps, throws an exception, or terminates with a result that has the expected type. Consequently, given a :ref:`valid store `, no computation defined by :ref:`instantiation ` or :ref:`invocation ` of a valid module can "crash" or otherwise (mis)behave in ways not covered by the :ref:`execution ` semantics given in this specification. diff --git a/document/core/binary/instructions.rst b/document/core/binary/instructions.rst index 89a4422811..347565d79e 100644 --- a/document/core/binary/instructions.rst +++ b/document/core/binary/instructions.rst @@ -13,7 +13,7 @@ The only exception are :ref:`structured control instructions ` have varying encodings. For structured instructions, the instruction sequences forming nested blocks are terminated with explicit opcodes for ${:END} and ${:ELSE}. +:ref:`Control instructions ` have varying encodings. For structured instructions, the instruction sequences forming nested blocks are delimited with explicit opcodes for ${:END} and ${:ELSE}. :ref:`Block types ` are encoded in special compressed form, by either the byte ${:0x40} indicating the empty type, as a single :ref:`value type `, or as a :ref:`type index ` encoded as a positive :ref:`signed integer `. @@ -41,8 +41,12 @@ Control Instructions .. _binary-return_call: .. _binary-return_call_ref: .. _binary-return_call_indirect: +.. _binary-throw: +.. _binary-throw_ref: +.. _binary-try_table: +.. _binary-catch: -$${grammar: Bblocktype Binstr/control} +$${grammar: Bblocktype Binstr/control Bcatch} .. note:: The ${:ELSE} opcode ${:0x05} in the encoding of an ${:IF} instruction can be omitted if the following instruction sequence is empty. @@ -100,7 +104,6 @@ Generic :ref:`reference instructions ` are represented by sing $${grammar: {Binstr/ref Binstr/struct Binstr/array Binstr/cast Binstr/extern Binstr/i31} Bcastop} $${syntax-ignore: castop} - .. index:: parametric instruction, value type, polymorphism pair: binary format; instruction .. _binary-instr-parametric: diff --git a/document/core/binary/modules.rst b/document/core/binary/modules.rst index 423c67c673..35631f729a 100644 --- a/document/core/binary/modules.rst +++ b/document/core/binary/modules.rst @@ -9,12 +9,13 @@ except that :ref:`function definitions ` are split into two section This separation enables *parallel* and *streaming* compilation of the functions in a module. -.. index:: index, type index, function index, table index, memory index, global index, element index, data index, local index, label index, field index +.. index:: index, type index, function index, table index, memory index, global index, tag index, element index, data index, local index, label index, field index pair: binary format; type index pair: binary format; function index pair: binary format; table index pair: binary format; memory index pair: binary format; global index + pair: binary format; tag index pair: binary format; element index pair: binary format; data index pair: binary format; local index @@ -25,6 +26,7 @@ except that :ref:`function definitions ` are split into two section .. _binary-tableidx: .. _binary-memidx: .. _binary-globalidx: +.. _binary-tagidx: .. _binary-elemidx: .. _binary-dataidx: .. _binary-localidx: @@ -39,7 +41,7 @@ Indices All basic :ref:`indices ` are encoded with their respective value. $${grammar: { - Btypeidx Bfuncidx Btableidx Bmemidx Bglobalidx Belemidx Bdataidx + Btypeidx Bfuncidx Btableidx Bmemidx Bglobalidx Btagidx Belemidx Bdataidx Blocalidx Blabelidx }} @@ -93,6 +95,7 @@ Id Section 10 :ref:`code section ` 11 :ref:`data section ` 12 :ref:`data count section ` +13 :ref:`tag section ` == =============================================== .. note:: @@ -132,7 +135,7 @@ It decodes into the list of :ref:`recursive types ` of a :ref:`m $${grammar: {Btypesec Btype}} -.. index:: ! import section, import, name, function type, table type, memory type, global type +.. index:: ! import section, import, name, function type, table type, memory type, global type, tag type pair: binary format; import pair: section; import .. _binary-import: @@ -157,7 +160,7 @@ Function Section ~~~~~~~~~~~~~~~~ The *function section* has the id 3. -It decodes into a list of :ref:`type indices ` that classify the :ref:`functions ` of a :ref:`module `. +It decodes into a list of :ref:`type indices ` that classify the :ref:`functions ` defined by a :ref:`module `. The bodies of the respective functions are encoded separately in the :ref:`code section `. $${grammar: {Bfuncsec}} @@ -173,7 +176,7 @@ Table Section ~~~~~~~~~~~~~ The *table section* has the id 4. -It decodes into the list of :ref:`tables ` of a :ref:`module `. +It decodes into the list of :ref:`tables ` defined by a :ref:`module `. $${grammar: {Btablesec Btable}} @@ -193,7 +196,7 @@ Memory Section ~~~~~~~~~~~~~~ The *memory section* has the id 5. -It decodes into the list of :ref:`memories ` of a :ref:`module `. +It decodes into the list of :ref:`memories ` defined by a :ref:`module `. $${grammar: {Bmemsec Bmem}} @@ -208,12 +211,12 @@ Global Section ~~~~~~~~~~~~~~ The *global section* has the id 6. -It decodes into the list of :ref:`globals ` of a :ref:`module `. +It decodes into the list of :ref:`globals ` defined by a :ref:`module `. $${grammar: {Bglobalsec Bglobal}} -.. index:: ! export section, export, name, index, function index, table index, memory index, global index +.. index:: ! export section, export, name, index, function index, table index, memory index, tag index, global index pair: binary format; export pair: section; export .. _binary-export: @@ -258,7 +261,7 @@ Element Section ~~~~~~~~~~~~~~~ The *element section* has the id 9. -It decodes into the list of :ref:`element segments ` of a :ref:`module `. +It decodes into the list of :ref:`element segments ` defined by a :ref:`module `. $${grammar: {Belemsec Belemkind Belem}} @@ -285,7 +288,7 @@ Code Section The *code section* has the id 10. It decodes into the list of *code* entries that are pairs of lists of :ref:`locals ` and :ref:`expressions `. -They represent the body of the :ref:`functions ` of a :ref:`module `. +They represent the body of the :ref:`functions ` defined by a :ref:`module `. The types of the respective functions are encoded separately in the :ref:`function section `. The encoding of each code entry consists of @@ -325,7 +328,7 @@ Data Section ~~~~~~~~~~~~ The *data section* has the id 11. -It decodes into the list of :ref:`data segments ` of a :ref:`module `. +It decodes into the list of :ref:`data segments ` defined by a :ref:`module `. $${grammar: {Bdatasec Bdata}} @@ -359,7 +362,22 @@ $${grammar: {Bdatacntsec Bdatacnt}} instead of deferring validation. -.. index:: module, section, type definition, function type, function, table, memory, global, element, data, start function, import, export, context, version +.. index:: ! tag section, tag, tag type, function type index, exception tag + pair: binary format; tag + pair: section; tag +.. _binary-tag: +.. _binary-tagsec: + +Tag Section +~~~~~~~~~~~ + +The *tag section* has the id 13. +It decodes into the list of :ref:`tags ` defined by a :ref:`module `. + +$${grammar: {Btagsec Btag}} + + +.. index:: module, section, type definition, function type, function, table, memory, tag, global, element, data, start function, import, export, context, version pair: binary format; module .. _binary-magic: .. _binary-version: diff --git a/document/core/binary/types.rst b/document/core/binary/types.rst index bf552bc0d5..6763885fae 100644 --- a/document/core/binary/types.rst +++ b/document/core/binary/types.rst @@ -182,6 +182,22 @@ Global Types $${grammar: Bglobaltype} +.. index:: tag type, function type, exception tag + pair: binary format; tag type +.. _binary-tagtype: + +Tag Types +~~~~~~~~~ + +:ref:`Tag types ` are encoded by a :ref:`type index ` denoting a :ref:`function type `. + +$${grammar: Btagtype} + +.. note:: + In future versions of WebAssembly, + the preceding zero byte may encode additional flags. + + .. index:: external type pair: binary format; external type .. _binary-externtype: diff --git a/document/core/exec/conventions.rst b/document/core/exec/conventions.rst index b3701610ac..88e9e0b346 100644 --- a/document/core/exec/conventions.rst +++ b/document/core/exec/conventions.rst @@ -49,7 +49,7 @@ The following conventions are adopted in stating these rules. * Execution can *enter* and *exit* :ref:`instruction sequences ` that form :ref:`blocks `. -* :ref:`Instruction sequences ` are implicitly executed in order, unless a trap or jump occurs. +* :ref:`Instruction sequences ` are implicitly executed in order, unless a trap, jump, or exception occurs. * In various places the rules contain *assertions* expressing crucial invariants about the program state. @@ -103,8 +103,8 @@ The order of reduction is determined by the details of the reduction rules. Usually, the left-most instruction that is not a constant will be the subject of the next reduction *step*. Reduction *terminates* when no more reduction rules are applicable. -:ref:`Soundness ` of the WebAssembly :ref:`type system ` guarantees that this is only the case when the original instruction sequence has either been reduced to a sequence of ${:CONST} instructions, which can be interpreted as the :ref:`values ` of the resulting operand stack, -or if a :ref:`trap ` occurred. +:ref:`Soundness ` of the WebAssembly :ref:`type system ` guarantees that this is only the case when the original instruction sequence has either been reduced to a sequence of :ref:`value ` instructions, which can be interpreted as the :ref:`values ` of the resulting operand stack, +or if an :ref:`exception ` or :ref:`trap ` occurred. .. note:: For example, the following instruction sequence, diff --git a/document/core/exec/instructions.rst b/document/core/exec/instructions.rst index 4153ac790c..c0cfb0767a 100644 --- a/document/core/exec/instructions.rst +++ b/document/core/exec/instructions.rst @@ -2554,7 +2554,146 @@ $${rule-prose: Step_pure/return_call_indirect} $${rule: {Step_pure/return_call_indirect}} -.. index:: instruction, instruction sequence, block +.. _exec-throw: + +$${rule-prose: exec/throw} + +.. todo:: check prose + +1. Let :math:`F` be the :ref:`current ` :ref:`frame `. + +2. Assert: due to :ref:`validation `, :math:`F.\AMODULE.\MITAGS[x]` exists. + +3. Let :math:`ta` be the :ref:`tag address ` :math:`F.\AMODULE.\MITAGS[x]`. + +4. Assert: due to :ref:`validation `, :math:`S.\STAGS[ta]` exists. + +5. Let :math:`\X{ti}` be the :ref:`tag instance ` :math:`S.\STAGS[ta]`. + +6. Let :math:`[t^n] \toF [{t'}^\ast]` be the :ref:`tag type ` :math:`\X{ti}.\HITYPE`. + +7. Assert: due to :ref:`validation `, there are at least :math:`n` values on the top of the stack. + +8. Pop the :math:`n` values :math:`\val^n` from the stack. + +9. Let :math:`\X{ea}` be the :ref:`exception address ` resulting from :ref:`allocating ` an exception instance with tag address :math:`ta` and initializer values :math:`\val^n`. + +10. Let :math:`\X{exn}` be :math:`S.\SEXNS[ea]` + +11. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack. + +12. Execute the instruction |THROWREF|. + +$${rule: Step/throw} + + +.. _exec-throw_ref: + +$${rule-prose: exec/throw_ref} + +.. todo:: check prose + +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:`tag 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:`tag 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: + + 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. + +$${rule: Step_read/throw_ref-*} + + +.. _exec-try_table: + +$${rule-prose: exec/try_table} + +.. todo:: check prose + +1. Assert: due to :ref:`validation `, :math:`\fblocktype_{S;F}(\blocktype)` is defined. + +2. Let :math:`[t_1^m] \to [t_2^n]` be the :ref:`instruction type ` :math:`\fblocktype_{S;F}(\blocktype)`. + +3. Assert: due to :ref:`validation `, there are at least :math:`m` values on the top of the stack. + +4. Pop the values :math:`\val^m` from the stack. + +5. Let :math:`L` be the label whose arity is :math:`n` and whose continuation is the end of the |TRYTABLE| instruction. + +6. :ref:`Enter ` the block :math:`\val^m~\instr_1^\ast` with label :math:`L` and exception handler :math:`\HANDLER_n\{\catch^\ast\}`. + +$${rule: Step_read/try_table} + + +.. index:: instruction, instruction sequence, block, exception, trap .. _exec-instrs: Blocks @@ -2583,7 +2722,7 @@ Entering :math:`\instr^\ast` with label :math:`L` Exiting :math:`\instr^\ast` with label :math:`L` ................................................ -When the end of a block is reached without a jump or trap aborting it, then the following steps are performed. +When the end of a block is reached without a jump, :ref:`exception `, or :ref:`trap ` aborting it, then the following steps are performed. 1. Pop all values :math:`\val^\ast` from the top of the stack. @@ -2598,10 +2737,60 @@ When the end of a block is reached without a jump or trap aborting it, then the $${rule: Step_pure/label-vals} .. note:: - This semantics also applies to the instruction sequence contained in a |LOOP| instruction. + This semantics also applies to the instruction sequence contained in a ${:LOOP} instruction. Therefore, execution of a loop falls off the end, unless a backwards branch is performed explicitly. +.. index:: exception, handler, throw context, tag, exception tag + +.. _exec-handler: + +Exception Handling +~~~~~~~~~~~~~~~~~~ + +The following auxiliary rules define the semantics of entering and exiting ${:TRY_TABLE} blocks. + +.. _exec-handler-enter: + +Entering :math:`\instr^\ast` with label :math:`L` and exception handler :math:`H` +................................................................................. + +1. Push :math:`L` to the stack. + +2. Push :math:`H` onto the stack. + +3. Jump to the start of the instruction sequence :math:`\instr^\ast`. + +.. note:: + No formal reduction rule is needed for entering an exception :ref:`handler ` + because it is an :ref:`administrative instruction ` + that the ${:TRY_TABLE} instruction reduces to directly. + + +.. _exec-handler-exit: + +Exiting an exception handler +............................ + +When the end of a ${:TRY_TABLE} block is reached without a jump, :ref:`exception `, or :ref:`trap `, then the following steps are performed. + +1. Let :math:`m` be the number of values on the top of the stack. + +2. Pop the values :math:`\val^m` from the stack. + +3. Assert: due to :ref:`validation `, a handler and a label are now on the top of the stack. + +4. Pop the label from the stack. + +5. Pop the handler :math:`H` from the stack. + +6. Push :math:`\val^m` back to the stack. + +7. Jump to the position after the |END| of the administrative instruction associated with the handler :math:`H`. + +$${rule: Step_pure/handler-vals} + + .. index:: ! call, function, function instance, label, frame Function Calls @@ -2650,7 +2839,7 @@ $${rule: {Step_read/call_ref-func}} Returning from a function ......................... -When the end of a function is reached without a jump (i.e., |RETURN|) or trap aborting it, then the following steps are performed. +When the end of a function is reached without a jump (including through |RETURN|), or an :ref:`exception ` or :ref:`trap ` aborting it, then the following steps are performed. 1. Let :math:`F` be the :ref:`current ` :ref:`frame `. @@ -2678,7 +2867,7 @@ Host Functions .............. Invoking a :ref:`host function ` has non-deterministic behavior. -It may either terminate with a :ref:`trap ` or return regularly. +It may either terminate with a :ref:`trap `, an :ref:`exception `, or return regularly. However, in the latter case, it must consume and produce the right number and types of WebAssembly :ref:`values ` on the stack, according to its :ref:`function type `. diff --git a/document/core/exec/modules.rst b/document/core/exec/modules.rst index a34f3a6276..daa361eb60 100644 --- a/document/core/exec/modules.rst +++ b/document/core/exec/modules.rst @@ -10,7 +10,19 @@ For modules, the execution semantics primarily defines :ref:`instantiation `, :ref:`tables `, :ref:`memories `, and :ref:`globals ` are *allocated* in a :ref:`store ` ${:s}, as defined by the following auxiliary functions. +New instances of +:ref:`functions `, +:ref:`tables `, +:ref:`memories `, +:ref:`globals `, +:ref:`tags `, +:ref:`element segments `, and +:ref:`data segments `, +as well as of dynamic data types like +:ref:`structures `, +:ref:`arrays `, or +:ref:`exceptions `, +are *allocated* in a :ref:`store ` ${:s}, as defined by the following auxiliary functions. .. index:: function, function instance, function address, module instance, function type @@ -80,6 +92,58 @@ $${definition: alloctable} $${definition: allocmem} +.. index:: tag, tag instance, tag address, tag type +.. _alloc-tag: + +:ref:`Tags ` +............................ + +1. Let :math:`\tagtype` be the :ref:`tag type ` to allocate. + +2. Let :math:`a` be the first free :ref:`tag address ` in :math:`S`. + +3. Let :math:`\taginst` be the :ref:`tag instance ` :math:`\{ \HITYPE~\tagtype \}`. + +4. Append :math:`\taginst` to the |STAGS| of :math:`S`. + +5. Return :math:`a`. + +.. math:: + \begin{array}{rlll} + \alloctag(S, \tagtype) &=& S', \tagaddr \\[1ex] + \mbox{where:} \hfill \\ + \tagaddr &=& |S.\STAGS| \\ + \taginst &=& \{\HITYPE~\tagtype\} \\ + S' &=& S \compose \{\STAGS~\taginst\} \\ + \end{array} + + +.. index:: exception, exception instance, exception address, tag address +.. _alloc-exception: + +:ref:`Exceptions ` +.................................. + +1. Let :math:`ta` be the :ref:`tag address ` associated with the exception to allocate and :math:`\EIFIELDS~\val^\ast` be the values to initialize the exception with. + +2. Let :math:`a` be the first free :ref:`exception address ` in :math:`S`. + +3. Let :math:`\exninst` be the :ref:`exception instance ` :math:`\{ \EITAG~ta, \EIFIELDS~\val^\ast \}`. + +4. Append :math:`\exninst` to the |SEXNS| of :math:`S`. + +5. Return :math:`a`. + +.. math:: + \begin{array}{rlll} + \allocexn(S, \tagaddr, \val^\ast) &=& S', \exnaddr \\[1ex] + \mbox{where:} \hfill \\ + \exnaddr &=& |S.\SEXNS| \\ + \exninst &=& \{ \EITAG~\tagaddr, \EIFIELDS~\val^\ast \} \\ + S' &=& S \compose \{\SEXNS~\exninst\} \\ + \end{array} + + .. index:: global, global instance, global address, global type, value type, mutability, value .. _alloc-global: @@ -189,7 +253,7 @@ Growing :ref:`memories ` $${definition: growmem} -.. index:: module, module instance, function instance, table instance, memory instance, global instance, export instance, function address, table address, memory address, global address, function index, table index, memory index, global index, type, function, table, memory, global, import, export, external value, external type, matching +.. index:: module, module instance, function instance, table instance, memory instance, tag instance, global instance, export instance, function address, table address, memory address, tag address, global address, function index, table index, memory index, tag index, global index, type, function, table, memory, tag, global, import, export, external address, external type, matching .. _alloc-module: :ref:`Modules ` @@ -197,11 +261,11 @@ $${definition: growmem} .. todo:: update prose for types -The allocation function for :ref:`modules ` requires a suitable list of :ref:`external values ` that are assumed to :ref:`match ` the :ref:`import ` list of the module, +The allocation function for :ref:`modules ` requires a suitable list of :ref:`external addresses ` that are assumed to :ref:`match ` the :ref:`import ` list of the module, a list of initialization :ref:`values ` for the module's :ref:`globals `, and list of :ref:`reference ` lists for the module's :ref:`element segments `. -1. Let :math:`\module` be the :ref:`module ` to allocate and :math:`\externval_{\F{im}}^\ast` the list of :ref:`external values ` providing the module's imports, :math:`\val_{\F{g}}^\ast` the initialization :ref:`values ` of the module's :ref:`globals `, :math:`\reff_{\F{t}}^\ast` the initializer :ref:`reference ` of the module's :ref:`tables `, and :math:`(\reff_{\F{e}}^\ast)^\ast` the :ref:`reference ` lists of the module's :ref:`element segments `. +1. Let :math:`\module` be the :ref:`module ` to allocate and :math:`\externaddr_{\F{im}}^\ast` the list of :ref:`external addresses ` providing the module's imports, :math:`\val_{\F{g}}^\ast` the initialization :ref:`values ` of the module's :ref:`globals `, :math:`\reff_{\F{t}}^\ast` the initializer :ref:`reference ` of the module's :ref:`tables `, and :math:`(\reff_{\F{e}}^\ast)^\ast` the :ref:`reference ` lists of the module's :ref:`element segments `. 2. For each :ref:`defined type ` :math:`\deftype'_i` in :math:`\module.\MTYPES`, do: @@ -229,56 +293,68 @@ and list of :ref:`reference ` lists for the module's :ref:`element s b. Let :math:`\globaladdr_i` be the :ref:`global address ` resulting from :ref:`allocating ` :math:`\globaltype_i` with initializer value :math:`\val_{\F{g}}^\ast[i]`. -7. For each :ref:`element segment ` :math:`\elem_i` in :math:`\module.\MELEMS`, do: +7. For each :ref:`tag ` :math:`\tag_i` in :math:`\module.\MTAGS`, do: + + a. Let :math:`\tagtype` be the :ref:`tag type ` :math:`\module.\MTYPES[\tag_i.\TAGTYPE]`. + + b. Let :math:`\tagaddr_i` be the :ref:`tag address ` resulting from :ref:`allocating ` :math:`\tagtype`. + +8. For each :ref:`element segment ` :math:`\elem_i` in :math:`\module.\MELEMS`, do: a. Let :math:`\reftype_i` be the element :ref:`reference type ` obtained by `instantiating ` :math:`\elem_i.\ETYPE` in :math:`\moduleinst` defined below. b. Let :math:`\elemaddr_i` be the :ref:`element address ` resulting from :ref:`allocating ` a :ref:`element instance ` of :ref:`reference type ` :math:`\reftype_i` with contents :math:`(\reff_{\F{e}}^\ast)^\ast[i]`. -8. For each :ref:`data segment ` :math:`\data_i` in :math:`\module.\MDATAS`, do: + +9. For each :ref:`data segment ` :math:`\data_i` in :math:`\module.\MDATAS`, do: a. Let :math:`\dataaddr_i` be the :ref:`data address ` resulting from :ref:`allocating ` a :ref:`data instance ` with contents :math:`\data_i.\DINIT`. -9. Let :math:`\deftype^\ast` be the concatenation of the :ref:`defined types ` :math:`\deftype_i` in index order. +10. Let :math:`\deftype^\ast` be the concatenation of the :ref:`defined types ` :math:`\deftype_i` in index order. + +11. Let :math:`\funcaddr^\ast` be the concatenation of the :ref:`function addresses ` :math:`\funcaddr_i` in index order. + +12. Let :math:`\tableaddr^\ast` be the concatenation of the :ref:`table addresses ` :math:`\tableaddr_i` in index order. -10. Let :math:`\funcaddr^\ast` be the concatenation of the :ref:`function addresses ` :math:`\funcaddr_i` in index order. +13. Let :math:`\memaddr^\ast` be the concatenation of the :ref:`memory addresses ` :math:`\memaddr_i` in index order. -11. Let :math:`\tableaddr^\ast` be the concatenation of the :ref:`table addresses ` :math:`\tableaddr_i` in index order. +14. Let :math:`\globaladdr^\ast` be the concatenation of the :ref:`global addresses ` :math:`\globaladdr_i` in index order. -12. Let :math:`\memaddr^\ast` be the concatenation of the :ref:`memory addresses ` :math:`\memaddr_i` in index order. +15. Let :math:`\tagaddr^\ast` be the concatenation of the :ref:`tag addresses ` :math:`\tagaddr_i` in index order. -13. Let :math:`\globaladdr^\ast` be the concatenation of the :ref:`global addresses ` :math:`\globaladdr_i` in index order. +16. Let :math:`\elemaddr^\ast` be the concatenation of the :ref:`element addresses ` :math:`\elemaddr_i` in index order. -14. Let :math:`\elemaddr^\ast` be the concatenation of the :ref:`element addresses ` :math:`\elemaddr_i` in index order. +17. Let :math:`\dataaddr^\ast` be the concatenation of the :ref:`data addresses ` :math:`\dataaddr_i` in index order. -15. Let :math:`\dataaddr^\ast` be the concatenation of the :ref:`data addresses ` :math:`\dataaddr_i` in index order. +18. Let :math:`\funcaddr_{\F{mod}}^\ast` be the list of :ref:`function addresses ` extracted from :math:`\externaddr_{\F{im}}^\ast`, concatenated with :math:`\funcaddr^\ast`. -16. Let :math:`\funcaddr_{\F{mod}}^\ast` be the list of :ref:`function addresses ` extracted from :math:`\externval_{\F{im}}^\ast`, concatenated with :math:`\funcaddr^\ast`. +19. Let :math:`\tableaddr_{\F{mod}}^\ast` be the list of :ref:`table addresses ` extracted from :math:`\externaddr_{\F{im}}^\ast`, concatenated with :math:`\tableaddr^\ast`. -17. Let :math:`\tableaddr_{\F{mod}}^\ast` be the list of :ref:`table addresses ` extracted from :math:`\externval_{\F{im}}^\ast`, concatenated with :math:`\tableaddr^\ast`. +20. Let :math:`\memaddr_{\F{mod}}^\ast` be the list of :ref:`memory addresses ` extracted from :math:`\externaddr_{\F{im}}^\ast`, concatenated with :math:`\memaddr^\ast`. -18. Let :math:`\memaddr_{\F{mod}}^\ast` be the list of :ref:`memory addresses ` extracted from :math:`\externval_{\F{im}}^\ast`, concatenated with :math:`\memaddr^\ast`. +21. Let :math:`\globaladdr_{\F{mod}}^\ast` be the list of :ref:`global addresses ` extracted from :math:`\externaddr_{\F{im}}^\ast`, concatenated with :math:`\globaladdr^\ast`. -19. Let :math:`\globaladdr_{\F{mod}}^\ast` be the list of :ref:`global addresses ` extracted from :math:`\externval_{\F{im}}^\ast`, concatenated with :math:`\globaladdr^\ast`. +22. Let :math:`\tagaddr_{\F{mod}}^\ast` be the list of :ref:`tag addresses ` extracted from :math:`\externaddr_{\F{im}}^\ast`, concatenated with :math:`\tagaddr^\ast`. -20. For each :ref:`export ` :math:`\export_i` in :math:`\module.\MEXPORTS`, do: +23. For each :ref:`export ` :math:`\export_i` in :math:`\module.\MEXPORTS`, do: - a. If :math:`\export_i` is a function export for :ref:`function index ` :math:`x`, then let :math:`\externval_i` be the :ref:`external value ` :math:`\EVFUNC~(\funcaddr_{\F{mod}}^\ast[x])`. + a. If :math:`\export_i` is a function export for :ref:`function index ` :math:`x`, then let :math:`\externaddr_i` be the :ref:`external address ` :math:`\XAFUNC~(\funcaddr_{\F{mod}}^\ast[x])`. - b. Else, if :math:`\export_i` is a table export for :ref:`table index ` :math:`x`, then let :math:`\externval_i` be the :ref:`external value ` :math:`\EVTABLE~(\tableaddr_{\F{mod}}^\ast[x])`. + b. Else, if :math:`\export_i` is a table export for :ref:`table index ` :math:`x`, then let :math:`\externaddr_i` be the :ref:`external address ` :math:`\XATABLE~(\tableaddr_{\F{mod}}^\ast[x])`. - c. Else, if :math:`\export_i` is a memory export for :ref:`memory index ` :math:`x`, then let :math:`\externval_i` be the :ref:`external value ` :math:`\EVMEM~(\memaddr_{\F{mod}}^\ast[x])`. + c. Else, if :math:`\export_i` is a memory export for :ref:`memory index ` :math:`x`, then let :math:`\externaddr_i` be the :ref:`external address ` :math:`\XAMEM~(\memaddr_{\F{mod}}^\ast[x])`. - d. Else, if :math:`\export_i` is a global export for :ref:`global index ` :math:`x`, then let :math:`\externval_i` be the :ref:`external value ` :math:`\EVGLOBAL~(\globaladdr_{\F{mod}}^\ast[x])`. + d. Else, if :math:`\export_i` is a global export for :ref:`global index ` :math:`x`, then let :math:`\externaddr_i` be the :ref:`external address ` :math:`\XAGLOBAL~(\globaladdr_{\F{mod}}^\ast[x])`. - e. Let :math:`\exportinst_i` be the :ref:`export instance ` :math:`\{\EINAME~(\export_i.\ENAME), \EIVALUE~\externval_i\}`. + e. Else, if :math:`\export_i` is a tag export for :ref:`tag index ` :math:`x`, then let :math:`\externaddr_i` be the :ref:`external address ` :math:`\XATAG~(\tagaddr_{\F{mod}}^\ast[x])`. -21. Let :math:`\exportinst^\ast` be the concatenation of the :ref:`export instances ` :math:`\exportinst_i` in index order. + f. Let :math:`\exportinst_i` be the :ref:`export instance ` :math:`\{\XINAME~(\export_i.\XNAME), \XIADDR~\externaddr_i\}`. -22. Let :math:`\moduleinst` be the :ref:`module instance ` :math:`\{\MITYPES~\deftype^\ast,` :math:`\MIFUNCS~\funcaddr_{\F{mod}}^\ast,` :math:`\MITABLES~\tableaddr_{\F{mod}}^\ast,` :math:`\MIMEMS~\memaddr_{\F{mod}}^\ast,` :math:`\MIGLOBALS~\globaladdr_{\F{mod}}^\ast,` :math:`\MIEXPORTS~\exportinst^\ast\}`. +24. Let :math:`\exportinst^\ast` be the concatenation of the :ref:`export instances ` :math:`\exportinst_i` in index order. -23. Return :math:`\moduleinst`. +25. Let :math:`\moduleinst` be the :ref:`module instance ` :math:`\{\MITYPES~\deftype^\ast,` :math:`\MIFUNCS~\funcaddr_{\F{mod}}^\ast,` :math:`\MITABLES~\tableaddr_{\F{mod}}^\ast,` :math:`\MIMEMS~\memaddr_{\F{mod}}^\ast,` :math:`\MIGLOBALS~\globaladdr_{\F{mod}}^\ast,` :math:`\MITAGS~\tagaddr_{\F{mod}}^\ast`, :math:`\MIEXPORTS~\exportinst^\ast\}`. +26. Return :math:`\moduleinst`. $${definition: allocmodule} @@ -305,18 +381,18 @@ $${definition: {allocexports allocexport}} -.. index:: ! instantiation, module, instance, store, trap +.. index:: ! instantiation, module, instance, store, trap, exception .. _exec-module: .. _exec-instantiation: Instantiation ~~~~~~~~~~~~~ -Given a :ref:`store ` ${:s}, a ${:module} is instantiated with a list of :ref:`external values ` ${:externval*} supplying the required imports as follows. +Given a :ref:`store ` ${:s}, a ${:module} is instantiated with a list of :ref:`external addresses ` ${:externaddr*} supplying the required imports as follows. Instantiation checks that the module is :ref:`valid ` and the provided imports :ref:`match ` the declared types, and may *fail* with an error otherwise. -Instantiation can also result in a :ref:`trap ` from initializing a table or memory from an active segment or from executing the start function. +Instantiation can also result in an :ref:`exception ` or :ref:`trap ` when initializing a :ref:`table ` or :ref:`memory ` from an :ref:`active segment ` or when executing the :ref:`start ` function. It is up to the :ref:`embedder ` to define how such conditions are reported. 1. If :math:`\module` is not :ref:`valid `, then: @@ -325,13 +401,13 @@ It is up to the :ref:`embedder ` to define how such conditions are rep 2. Assert: :math:`\module` is :ref:`valid ` with :ref:`external types ` :math:`\externtype_{\F{im}}^m` classifying its :ref:`imports `. -3. If the number :math:`m` of :ref:`imports ` is not equal to the number :math:`n` of provided :ref:`external values `, then: +3. If the number :math:`m` of :ref:`imports ` is not equal to the number :math:`n` of provided :ref:`external addresses `, then: a. Fail. -4. For each :ref:`external value ` :math:`\externval_i` in :math:`\externval^n` and :ref:`external type ` :math:`\externtype'_i` in :math:`\externtype_{\F{im}}^n`, do: +4. For each :ref:`external address ` :math:`\externaddr_i` in :math:`\externaddr^n` and :ref:`external type ` :math:`\externtype'_i` in :math:`\externtype_{\F{im}}^n`, do: - a. If :math:`\externval_i` is not :ref:`valid ` with an :ref:`external type ` :math:`\externtype_i` in store :math:`S`, then: + a. If :math:`\externaddr_i` is not :ref:`valid ` with an :ref:`external type ` :math:`\externtype_i` in store :math:`S`, then: i. Fail. @@ -347,7 +423,7 @@ It is up to the :ref:`embedder ` to define how such conditions are rep 7. Push the frame :math:`F` to the stack. -8. Let :math:`\val_{\F{g}}^\ast` be the list of :ref:`global ` initialization :ref:`values ` determined by :math:`\module` and :math:`\externval^n`. These may be calculated as follows. +8. Let :math:`\val_{\F{g}}^\ast` be the list of :ref:`global ` initialization :ref:`values ` determined by :math:`\module` and :math:`\externaddr^n`. These may be calculated as follows. a. For each :ref:`global ` :math:`\global_i` in :math:`\module.\MGLOBALS`, do: @@ -357,7 +433,7 @@ It is up to the :ref:`embedder ` to define how such conditions are rep c. Let :math:`\val_{\F{g}}^\ast` be the concatenation of :math:`\val_{\F{g}i}` in index order. -9. Let :math:`\reff_{\F{t}}^\ast` be the list of :ref:`table ` initialization :ref:`references ` determined by :math:`\module` and :math:`\externval^n`. These may be calculated as follows. +9. Let :math:`\reff_{\F{t}}^\ast` be the list of :ref:`table ` initialization :ref:`references ` determined by :math:`\module` and :math:`\externaddr^n`. These may be calculated as follows. a. For each :ref:`table ` :math:`\table_i` in :math:`\module.\MTABLES`, do: @@ -381,7 +457,7 @@ It is up to the :ref:`embedder ` to define how such conditions are rep c. Let :math:`(\reff_{\F{e}}^\ast)^\ast` be the concatenation of function element lists :math:`\reff^\ast_i` in order of index :math:`i`. -11. Let :math:`\moduleinst` be a new module instance :ref:`allocated ` from :math:`\module` in store :math:`S` with imports :math:`\externval^n`, global initializer values :math:`\val_{\F{g}}^\ast`, table initializer values :math:`\reff_{\F{t}}^\ast`, and element segment contents :math:`(\reff_{\F{e}}^\ast)^\ast`, and let :math:`S'` be the extended store produced by module allocation. +11. Let :math:`\moduleinst` be a new module instance :ref:`allocated ` from :math:`\module` in store :math:`S` with imports :math:`\externaddr^n`, global initializer values :math:`\val_{\F{g}}^\ast`, table initializer values :math:`\reff_{\F{t}}^\ast`, and element segment contents :math:`(\reff_{\F{e}}^\ast)^\ast`, and let :math:`S'` be the extended store produced by module allocation. 12. For each :ref:`element segment ` :math:`\elem_i` in :math:`\module.\MELEMS` whose :ref:`mode ` is of the form :math:`\EACTIVE~\{ \ETABLE~\tableidx_i, \EOFFSET~\X{einstr}^\ast_i~\END \}`, do: @@ -458,7 +534,7 @@ $${definition: runelem_ rundata_} :ref:`Evaluation ` of :ref:`constant expressions ` does not affect the store. -.. index:: ! invocation, module, module instance, function, export, function address, function instance, function type, value, stack, trap, store +.. index:: ! invocation, module, module instance, function, export, function address, function instance, function type, value, stack, trap, exception, store .. _exec-invocation: Invocation @@ -467,11 +543,11 @@ Invocation Once a :ref:`module ` has been :ref:`instantiated `, any exported function can be *invoked* externally via its :ref:`function address ` ${:funcaddr} in the :ref:`store ` ${:s} and an appropriate list ${:val*} of argument :ref:`values `. Invocation may *fail* with an error if the arguments do not fit the :ref:`function type `. -Invocation can also result in a :ref:`trap `. +Invocation can also result in an :ref:`exception ` or :ref:`trap `. It is up to the :ref:`embedder ` to define how such conditions are reported. .. note:: - If the :ref:`embedder ` API performs type checks itself, either statically or dynamically, before performing an invocation, then no failure other than traps can occur. + If the :ref:`embedder ` API performs type checks itself, either statically or dynamically, before performing an invocation, then no failure other than traps or exceptions can occur. The following steps are performed: diff --git a/document/core/exec/runtime.rst b/document/core/exec/runtime.rst index 08fbad90d5..ba97142c0d 100644 --- a/document/core/exec/runtime.rst +++ b/document/core/exec/runtime.rst @@ -16,6 +16,7 @@ Runtime Structure .. _syntax-ref.i31num: .. _syntax-ref.struct: .. _syntax-ref.array: +.. _syntax-ref.exn: .. _syntax-ref.host: .. _syntax-ref.extern: .. _syntax-val: @@ -36,6 +37,7 @@ They either are *scalar references*, containing a 31-bit :ref:`integer `, *array references*, pointing to a specific :ref:`array address `, *function references*, pointing to a specific :ref:`function address `, +*exception references*, pointing to a specific :ref:`exception address `, or *host references* pointing to an uninterpreted form of :ref:`host address ` defined by the :ref:`embedder `. Any of the aformentioned references can furthermore be wrapped up as an *external reference*. @@ -59,7 +61,7 @@ Convention * The meta variable ${ref: r} ranges over reference values where clear from context. -.. index:: ! result, value, trap +.. index:: ! result, value, trap, exception, exception address pair: abstract syntax; result .. _syntax-result: @@ -67,12 +69,12 @@ Results ~~~~~~~ A *result* is the outcome of a computation. -It is either a sequence of :ref:`values ` or a :ref:`trap `. +It is either a sequence of :ref:`values `, an :ref:`exception `, or a :ref:`trap `. $${syntax: result} -.. index:: ! store, type instance, function instance, table instance, memory instance, global instance, module, allocation, structure instance, array instance +.. index:: ! store, type instance, function instance, table instance, memory instance, global instance, tag instance, module, allocation, structure instance, array instance, exception instance pair: abstract syntax; store .. _syntax-store: .. _store: @@ -81,7 +83,19 @@ Store ~~~~~ The *store* represents all global state that can be manipulated by WebAssembly programs. -It consists of the runtime representation of all *instances* of :ref:`functions `, :ref:`tables `, :ref:`memories `, and :ref:`globals `, :ref:`element segments `, :ref:`data segments `, and :ref:`structures ` or :ref:`arrays ` that have been :ref:`allocated ` during the life time of the abstract machine. [#gc]_ +It consists of the runtime representation of all *instances* of +:ref:`functions `, +:ref:`tables `, +:ref:`memories `, +:ref:`globals `, +:ref:`tags `, +:ref:`element segments `, +:ref:`data segments `, +and +:ref:`structures `, +:ref:`arrays ` or +:ref:`exceptions ` +that have been :ref:`allocated ` during the life time of the abstract machine. [#gc]_ It is an invariant of the semantics that no element or data instance is :ref:`addressed ` from anywhere else but the owning module instances. @@ -90,7 +104,7 @@ Syntactically, the store is defined as a :ref:`record ` listing $${syntax: store} .. [#gc] - In practice, implementations may apply techniques like garbage collection to remove objects from the store that are no longer referenced. + In practice, implementations may apply techniques like garbage collection or reference counting to remove objects from the store that are no longer referenced. However, such techniques are not semantically observable, and hence outside the scope of this specification. @@ -101,32 +115,38 @@ Convention * The meta variable ${store: s} ranges over stores where clear from context. -.. index:: ! address, store, function instance, table instance, memory instance, global instance, element instance, data instance, structure instance, array instance, embedder, host +.. index:: ! address, store, function instance, table instance, memory instance, global instance, tag instance, element instance, data instance, structure instance, array instance, exception instance, embedder, host pair: abstract syntax; function address pair: abstract syntax; table address pair: abstract syntax; memory address pair: abstract syntax; global address + pair: abstract syntax; tag address pair: abstract syntax; element address pair: abstract syntax; data address pair: abstract syntax; structure address pair: abstract syntax; array address + pair: abstract syntax; exception address pair: abstract syntax; host address pair: function; address pair: table; address pair: memory; address pair: global; address + pair: tag; address pair: element; address pair: data; address pair: structure; address pair: array; address + pair: exception; address pair: host; address .. _syntax-funcaddr: .. _syntax-tableaddr: .. _syntax-memaddr: .. _syntax-globaladdr: +.. _syntax-tagaddr: .. _syntax-elemaddr: .. _syntax-dataaddr: .. _syntax-structaddr: +.. _syntax-exnaddr: .. _syntax-arrayaddr: .. _syntax-hostaddr: .. _syntax-addr: @@ -134,11 +154,22 @@ Convention Addresses ~~~~~~~~~ -:ref:`Function instances `, :ref:`table instances `, :ref:`memory instances `, and :ref:`global instances `, :ref:`element instances `, :ref:`data instances ` and :ref:`structure ` or :ref:`array instances ` in the :ref:`store ` are referenced with abstract *addresses*. +:ref:`Function instances `, +:ref:`table instances `, +:ref:`memory instances `, +:ref:`global instances `, +:ref:`tag instances `, +:ref:`element instances `, +:ref:`data instances ` +and +:ref:`structure `, +:ref:`array instances ` or +:ref:`exception instances ` +in the :ref:`store ` are referenced with abstract *addresses*. These are simply indices into the respective store component. In addition, an :ref:`embedder ` may supply an uninterpreted set of *host addresses*. -$${syntax: {addr funcaddr tableaddr memaddr globaladdr elemaddr dataaddr structaddr arrayaddr hostaddr}} +$${syntax: {addr funcaddr tableaddr memaddr globaladdr tagaddr elemaddr dataaddr structaddr arrayaddr hostaddr}} An :ref:`embedder ` may assign identity to :ref:`exported ` store objects corresponding to their addresses, even where this identity is not observable from within WebAssembly code itself @@ -159,6 +190,7 @@ even where this identity is not observable from within WebAssembly code itself .. _free-tableaddr: .. _free-memaddr: .. _free-globaladdr: +.. _free-tagaddr: .. _free-elemaddr: .. _free-dataaddr: .. _free-structaddr: @@ -173,8 +205,28 @@ Conventions * The notation ${:$addr(A)} denotes the set of addresses from address space ${:addr} occurring free in ${:A}. We sometimes reinterpret this set as the :ref:`list ` of its elements. +.. index:: ! external address, function address, table address, memory address, global address, tag address, store, function, table, memory, global, tag, instruction type + pair: abstract syntax; external address + pair: external; address +.. _syntax-externaddr: -.. index:: ! instance, function type, type instance, function instance, table instance, memory instance, global instance, element instance, data instance, export instance, table address, memory address, global address, element address, data address, index, name +External Addresses +~~~~~~~~~~~~~~~~~~ + +An *external address* is the runtime :ref:`address ` of an entity that can be imported or exported. +It is an :ref:`address ` denoting either a +:ref:`function instance `, +:ref:`global instances `, +:ref:`table instance `, +:ref:`memory instance `, or +:ref:`tag instances ` +in the shared :ref:`store `. + +$${syntax: externaddr} + + + +.. index:: ! instance, function type, type instance, function instance, table instance, memory instance, global instance, tag instance, element instance, data instance, export instance, table address, memory address, global address, tag address, element address, data address, index, name pair: abstract syntax; module instance pair: module; instance .. _syntax-moduleinst: @@ -189,7 +241,12 @@ and collects runtime representations of all entities that are imported, defined, $${syntax: moduleinst} Each component references runtime instances corresponding to respective declarations from the original module -- whether imported or defined -- in the order of their static :ref:`indices `. -:ref:`Function instances `, :ref:`table instances `, :ref:`memory instances `, and :ref:`global instances ` are referenced with an indirection through their respective :ref:`addresses ` in the :ref:`store `. +:ref:`Function instances `, +:ref:`table instances `, +:ref:`memory instances `, +:ref:`global instances `, and +:ref:`tag instances ` +are referenced with an indirection through their respective :ref:`addresses ` in the :ref:`store `. It is an invariant of the semantics that all :ref:`export instances ` in a given module instance have different :ref:`names `. @@ -278,6 +335,20 @@ The value of mutable globals can be mutated through :ref:`variable instructions It is an invariant of the semantics that the value has a type :ref:`matching ` the :ref:`value type ` of ${:globaltype}. +.. index:: ! tag instance, tag, exception tag, tag type + pair: abstract syntax; tag instance + pair: tag; instance +.. _syntax-taginst: + +Tag Instances +~~~~~~~~~~~~~ + +A *tag instance* is the runtime representation of a :ref:`tag ` definition. +It records the :ref:`defined type ` of the tag. + +$${syntax: taginst} + + .. index:: ! element instance, element segment, embedder, element expression pair: abstract syntax; element instance pair: element; instance @@ -306,7 +377,7 @@ It holds a list of :ref:`bytes `. $${syntax: datainst} -.. index:: ! export instance, export, name, external value +.. index:: ! export instance, export, name, external address pair: abstract syntax; export instance pair: export; instance .. _syntax-exportinst: @@ -315,32 +386,18 @@ Export Instances ~~~~~~~~~~~~~~~~ An *export instance* is the runtime representation of an :ref:`export `. -It defines the export's :ref:`name ` and the associated :ref:`external value `. +It defines the export's :ref:`name ` and the associated :ref:`external address `. $${syntax: exportinst} -.. index:: ! external value, function address, table address, memory address, global address, store, function, table, memory, global, instruction type - pair: abstract syntax; external value - pair: external; value -.. _syntax-externval: - -External Values -~~~~~~~~~~~~~~~ - -An *external value* is the runtime representation of an entity that can be imported or exported. -It is an :ref:`address ` denoting either a :ref:`function instance `, :ref:`table instance `, :ref:`memory instance `, or :ref:`global instances ` in the shared :ref:`store `. - -$${syntax: externval} - - Conventions ........... -The following auxiliary notation is defined for sequences of external values. +The following auxiliary notation is defined for sequences of external addresses. It filters out entries of a specific kind in an order-preserving fashion: -$${definition: funcsxv tablesxv memsxv globalsxv} +$${definition: funcsxa tablesxa memsxa globalsxa tagsxa} .. index:: ! structure instance, ! array instance, structure type, array type, defined type, ! field value, ! packed value @@ -381,21 +438,38 @@ Conventions $${definition: unpackfield_} -.. index:: ! stack, ! frame, ! label, instruction, store, activation, function, call, ! call frame, local, module instance +.. index:: ! exception instance, tag, tag address, value + pair: abstract syntax; exception instance + pair: exception; instance +.. _syntax-exninst: + +Exception Instances +~~~~~~~~~~~~~~~~~~~ + +An *exception instance* is the runtime representation of an :ref:`exception ` produced by a ${:THROW} instruction. +It holds the :ref:`address ` of the respective :ref:`tag ` and the argument :ref:`values `. + +$${syntax: exninst} + + +.. index:: ! stack, ! frame, ! label, ! handler, instruction, store, activation, function, call, ! call frame, local, exception, module instance pair: abstract syntax; frame pair: abstract syntax; label + pair: abstract syntax; handler .. _syntax-frame: .. _syntax-callframe: .. _syntax-label: +.. _syntax-handler: .. _frame: .. _label: +.. _handler: .. _stack: Stack ~~~~~ Besides the :ref:`store `, most :ref:`instructions ` interact with an implicit *stack*. -The stack contains three kinds of entries: +The stack contains the following kinds of entries: * *Values*: the *operands* of instructions. @@ -403,6 +477,8 @@ The stack contains three kinds of entries: * *Frames*: the *call frames* of active :ref:`function ` calls. +* *Handlers*: active exception handlers. + These entries can occur on the stack in any order during the execution of a program. Stack entries are described by abstract syntax as follows. @@ -449,6 +525,19 @@ $${syntax: {callframe frame}} Locals may be uninitialized, in which case they are empty. Locals are mutated by respective :ref:`variable instructions `. +Exception Handlers +.................. + +Exception handlers are installed by |TRYTABLE| instructions and record the corresponding list of :ref:`catch clauses `: + +.. math:: + \begin{array}{llllll} + \production{handler} & \handler &::=& + \HANDLER_n\{\catch^\ast\} + \end{array} + +The handlers on the stack are searched when an exception is :ref:`thrown `. + .. _aux-blocktype: @@ -459,12 +548,14 @@ Conventions * The meta variable ${:f} ranges over frame states where clear from context. +* The meta variable :math:`H` ranges over exception handlers where clear from context. + * The following auxiliary definition takes a :ref:`block type ` and looks up the :ref:`instruction type ` that it denotes in the current frame: $${definition: blocktype_} -.. index:: ! administrative instructions, function, function instance, function address, label, frame, instruction, trap, call, memory, memory instance, table, table instance, element, data, segment +.. index:: ! administrative instructions, function, function instance, function address, label, frame, instruction, trap, call, memory, memory instance, table, table instance, element, data, segment, tag, tag instance, tag address, exception, reftype, handler, caught, caught exception pair:: abstract syntax; administrative instruction .. _syntax-trap: .. _syntax-instr-admin: @@ -475,13 +566,13 @@ Administrative Instructions .. note:: This section is only relevant for the :ref:`formal notation `. -In order to express the reduction of :ref:`traps `, :ref:`calls `, and :ref:`control instructions `, the syntax of instructions is extended to include the following *administrative instructions*: +In order to express the reduction of :ref:`traps `, :ref:`calls `, :ref:`exception handling `, and :ref:`control instructions `, the syntax of instructions is extended to include the following *administrative instructions*: $${syntax: {instr/admin}} An :ref:`address reference ` represents an allocated :ref:`reference ` value of respective form :ref:`"on the stack" `. -The ${:LABEL} and ${:FRAME} instructions model :ref:`labels ` and :ref:`frames ` :ref:`"on the stack" `. +The ${:LABEL}, ${:FRAME}, and ${:HANDLER} instructions model :ref:`labels `, :ref:`frames `, and active :ref:`exception handlers `, respectively, :ref:`"on the stack" `. Moreover, the administrative syntax maintains the nesting structure of the original :ref:`structured control instruction ` or :ref:`function body ` and their :ref:`instruction sequences `. The ${:TRAP} instruction represents the occurrence of a trap. @@ -504,7 +595,7 @@ Traps are bubbled up through nested instruction sequences, ultimately reducing t Validation guarantees that ${:n} matches the number ${:|val*|} of resulting values at this point. -.. index:: ! configuration, !state, ! thread, store, frame, instruction, module instruction +.. index:: ! configuration, ! state, ! thread, store, frame, instruction, module instruction .. _syntax-state: .. _syntax-thread: .. _syntax-config: diff --git a/document/core/exec/values.rst b/document/core/exec/values.rst index cdf1a640db..97b35f01be 100644 --- a/document/core/exec/values.rst +++ b/document/core/exec/values.rst @@ -10,7 +10,7 @@ Values Value Typing ~~~~~~~~~~~~ -For the purpose of checking argument :ref:`values ` against the parameter types of exported :ref:`functions `, +For the purpose of checking argument :ref:`values ` against the parameter types of exported :ref:`functions `, values are classified by :ref:`value types `. The following auxiliary typing rules specify this typing relation relative to a :ref:`store ` :math:`S` in which possibly referenced addresses live. @@ -130,6 +130,23 @@ The following auxiliary typing rules specify this typing relation relative to a } +.. _valid-ref.exn: + +:ref:`Exception References ` :math:`\REFEXNADDR~a` +.............................................................. + +* The store entry :math:`S.\SEXNS[a]` must exist. + +* Then the value is valid with :ref:`reference type ` :math:`\EXNREF`. + +.. math:: + \frac{ + S.\SEXNS[a] = \exninst + }{ + S \vdashval \REFEXNADDR : \EXNREF + } + + :ref:`Function References ` :math:`\REFFUNCADDR~a` .............................................................. @@ -207,100 +224,91 @@ Subsumption } -.. index:: external value, external type, validation, import, store -.. _valid-externval: +.. index:: external address, external type, validation, import, store +.. _valid-externaddr: External Typing ~~~~~~~~~~~~~~~ -For the purpose of checking :ref:`external values ` against :ref:`imports `, +For the purpose of checking :ref:`external address ` against :ref:`imports `, such values are classified by :ref:`external types `. The following auxiliary typing rules specify this typing relation relative to a :ref:`store ` :math:`S` in which the referenced instances live. .. index:: function type, function address -.. _valid-externval-func: +.. _valid-externaddr-func: -:math:`\EVFUNC~a` +:math:`\XAFUNC~a` ................. * The store entry :math:`S.\SFUNCS[a]` must exist. -* Then :math:`\EVFUNC~a` is valid with :ref:`external type ` :math:`\ETFUNC~S.\SFUNCS[a].\FITYPE`. +* Then :math:`\XAFUNC~a` is valid with :ref:`external type ` :math:`\XTFUNC~S.\SFUNCS[a].\FITYPE`. -.. math:: - \frac{ - }{ - S \vdashexternval \EVFUNC~a : \ETFUNC~S.\SFUNCS[a].\FITYPE - } +$${rule: Externaddr_type/func} .. index:: table type, table address -.. _valid-externval-table: +.. _valid-externaddr-table: -:math:`\EVTABLE~a` +:math:`\XATABLE~a` .................. * The store entry :math:`S.\STABLES[a]` must exist. -* Then :math:`\EVTABLE~a` is valid with :ref:`external type ` :math:`\ETTABLE~S.\STABLES[a].\TITYPE`. +* Then :math:`\XATABLE~a` is valid with :ref:`external type ` :math:`\XTTABLE~S.\STABLES[a].\TITYPE`. -.. math:: - \frac{ - }{ - S \vdashexternval \EVTABLE~a : \ETTABLE~S.\STABLES[a].\TITYPE - } +$${rule: Externaddr_type/table} .. index:: memory type, memory address -.. _valid-externval-mem: +.. _valid-externaddr-mem: -:math:`\EVMEM~a` +:math:`\XAMEM~a` ................ * The store entry :math:`S.\SMEMS[a]` must exist. -* Then :math:`\EVMEM~a` is valid with :ref:`external type ` :math:`\ETMEM~S.\SMEMS[a].\MITYPE`. +* Then :math:`\XAMEM~a` is valid with :ref:`external type ` :math:`\XTMEM~S.\SMEMS[a].\MITYPE`. -.. math:: - \frac{ - }{ - S \vdashexternval \EVMEM~a : \ETMEM~S.\SMEMS[a].\MITYPE - } +$${rule: Externaddr_type/mem} .. index:: global type, global address, value type, mutability -.. _valid-externval-global: +.. _valid-externaddr-global: -:math:`\EVGLOBAL~a` +:math:`\XAGLOBAL~a` ................... * The store entry :math:`S.\SGLOBALS[a]` must exist. -* Then :math:`\EVGLOBAL~a` is valid with :ref:`external type ` :math:`\ETGLOBAL~S.\SGLOBALS[a].\GITYPE`. +* Then :math:`\XAGLOBAL~a` is valid with :ref:`external type ` :math:`\XTGLOBAL~S.\SGLOBALS[a].\GITYPE`. + +$${rule: Externaddr_type/global} + + +.. index:: tag type, tag address, exception tag, function type +.. _valid-externaddr-tag: + +:math:`\XATAG~a` +................ + +* The store entry :math:`S.\STAGS[a]` must exist. + +* Let :math:`\tagtype` be the function type :math:`S.\STAGS[a].\HITYPE`. + +* Then :math:`\XATAG~a` is valid with :ref:`external type ` :math:`\XTTAG~\tagtype`. + +$${rule: Externaddr_type/tag} -.. math:: - \frac{ - }{ - S \vdashexternval \EVGLOBAL~a : \ETGLOBAL~S.\SGLOBALS[a].\GITYPE - } Subsumption ........... -* The external value must be valid with some external type :math:`\X{et}`. +* The external address must be valid with some external type :math:`\X{et}`. * The external type :math:`\X{et}` :ref:`matches ` another :ref:`valid ` type :math:`\X{et'}`. -* Then the external value is valid with type :math:`\X{et'}`. +* Then the external address is valid with type :math:`\X{et'}`. -.. math:: - \frac{ - S \vdashexternval \externval : \X{et} - \qquad - \vdashexterntype \X{et'} : \OKexterntype - \qquad - \vdashexterntypematch \X{et} \subexterntypematch \X{et'} - }{ - S \vdashexternval \externval : \X{et'} - } +$${rule: Externaddr_type/sub} diff --git a/document/core/syntax/instructions.rst b/document/core/syntax/instructions.rst index 1a5beb9c29..7617d080bd 100644 --- a/document/core/syntax/instructions.rst +++ b/document/core/syntax/instructions.rst @@ -356,7 +356,7 @@ The ${:DATA.DROP} instruction prevents further use of a passive data segment. Th This restriction may be lifted in future versions. -.. index:: ! control instruction, ! structured control, ! label, ! block, ! block type, ! branch, ! unwinding, stack type, label index, function index, type index, list, trap, function, table, function type, value type, type index +.. index:: ! control instruction, ! structured control, ! exception, ! label, ! block, ! block type, ! branch, ! unwinding, stack type, label index, function index, type index, list, trap, function, table, tag, function type, value type, tag type, try block, type index pair: abstract syntax; instruction pair: abstract syntax; block type pair: block; type @@ -378,15 +378,20 @@ The ${:DATA.DROP} instruction prevents further use of a passive data segment. Th .. _syntax-call_indirect: .. _syntax-instrs: .. _syntax-instr-control: +.. _syntax-throw: +.. _syntax-throw_ref: +.. _syntax-try_table: +.. _syntax-catch: +.. _exception: Control Instructions ~~~~~~~~~~~~~~~~~~~~ Instructions in this group affect the flow of control. -$${syntax: blocktype {instr/block instr/br instr/call}} +$${syntax: blocktype {instr/block instr/br instr/call instr/exn} catch} -The ${:BLOCK}, ${:LOOP} and ${:IF} instructions are *structured* instructions. +The ${:BLOCK}, ${:LOOP}, ${:IF} and ${:TRY_TABLE} instructions are *structured* instructions. They bracket nested sequences of instructions, called *blocks*, terminated with, or separated by, ${:END} or ${:ELSE} pseudo-instructions. As the grammar prescribes, they must be well-nested. @@ -434,6 +439,10 @@ The ${:RETURN_CALL}, ${:RETURN_CALL_REF}, and ${:RETURN_CALL_INDIRECT} instructi That is, they first return from the current function before actually performing the respective call. It is guaranteed that no sequence of nested calls using only these instructions can cause resource exhaustion due to hitting an :ref:`implementation's limit ` on the number of active calls. +The instructions ${:THROW}, ${:THROW_REF}, and ${:TRY_TABLE} are concerned with *exceptions*. +The ${:THROW} and ${:THROW_REF} instructions raise and reraise an exception, respectively, and transfers control to the innermost enclosing exception handler that has a matching catch clause. +The ${:TRY_TABLE} instruction installs an exception *handler* that handles exceptions as specified by its catch clauses. + .. index:: ! expression, constant, global, offset, element, data, instruction pair: abstract syntax; expression diff --git a/document/core/syntax/modules.rst b/document/core/syntax/modules.rst index 68b3352122..abdd00b8cf 100644 --- a/document/core/syntax/modules.rst +++ b/document/core/syntax/modules.rst @@ -1,4 +1,4 @@ -.. index:: ! module, type definition, function type, function, table, memory, global, element, data, start function, import, export +.. index:: ! module, type definition, function type, tag type, function, table, memory, tag, global, element, data, start function, import, export pair: abstract syntax; module .. _syntax-module: @@ -7,21 +7,31 @@ Modules WebAssembly programs are organized into *modules*, which are the unit of deployment, loading, and compilation. -A module collects definitions for :ref:`types `, :ref:`functions `, :ref:`tables `, :ref:`memories `, and :ref:`globals `. -In addition, it can declare :ref:`imports ` and :ref:`exports ` -and provide initialization in the form of :ref:`data ` and :ref:`element ` segments, or a :ref:`start function `. +A module collects definitions for +:ref:`types `, +:ref:`functions `, +:ref:`tables `, +:ref:`memories `, +:ref:`tags `, and +:ref:`globals `. +In addition, it can declare +:ref:`imports ` and :ref:`exports ` +and provide initialization in the form of +:ref:`data ` and :ref:`element ` segments, +or a :ref:`start function `. $${syntax: module} Each of the lists --- and thus the entire module --- may be empty. -.. index:: ! index, ! index space, ! type index, ! function index, ! table index, ! memory index, ! global index, ! local index, ! label index, ! element index, ! data index, ! field index, function, global, table, memory, element, data, local, parameter, import, field +.. index:: ! index, ! index space, ! type index, ! function index, ! table index, ! memory index, ! global index, ! tag index, ! local index, ! label index, ! element index, ! data index, ! field index, function, global, table, memory, tag, element, data, local, parameter, import, field pair: abstract syntax; type index pair: abstract syntax; function index pair: abstract syntax; table index pair: abstract syntax; memory index pair: abstract syntax; global index + pair: abstract syntax; tag index pair: abstract syntax; element index pair: abstract syntax; data index pair: abstract syntax; local index @@ -32,6 +42,7 @@ Each of the lists --- and thus the entire module --- may be empty. pair: table; index pair: memory; index pair: global; index + pair: tag; index pair: element; index pair: data; index pair: local; index @@ -43,6 +54,7 @@ Each of the lists --- and thus the entire module --- may be empty. .. _syntax-tableidx: .. _syntax-memidx: .. _syntax-globalidx: +.. _syntax-tagidx: .. _syntax-elemidx: .. _syntax-dataidx: .. _syntax-localidx: @@ -56,9 +68,15 @@ Indices Definitions are referenced with zero-based *indices*. Each class of definition has its own *index space*, as distinguished by the following classes. -$${syntax: {typeidx funcidx globalidx tableidx memidx elemidx dataidx labelidx localidx fieldidx}} +$${syntax: {typeidx funcidx globalidx tableidx memidx tagidx elemidx dataidx labelidx localidx fieldidx}} -The index space for :ref:`functions `, :ref:`tables `, :ref:`memories ` and :ref:`globals ` includes respective :ref:`imports ` declared in the same module. +The index space for +:ref:`functions `, +:ref:`tables `, +:ref:`memories `, +:ref:`globals `, and +:ref:`tags ` +includes respective :ref:`imports ` declared in the same module. The indices of these imports precede the indices of other definitions in the same index space. Element indices reference :ref:`element segments ` and data indices reference :ref:`data segments `. @@ -82,6 +100,7 @@ Conventions .. _free-tableidx: .. _free-memidx: .. _free-globalidx: +.. _free-tagidx: .. _free-elemidx: .. _free-dataidx: .. _free-localidx: @@ -198,6 +217,23 @@ Globals are referenced through :ref:`global indices `, starting with the smallest index not referencing a global :ref:`import `. +.. index:: ! tag, type index, tag type + pair: abstract syntax; tag +.. _syntax-tag: + +Tags +~~~~ + +The ${:tag} section of a module defines a list of *tags*: + +$${syntax: tag} + +The :ref:`type index ` of a tag must refer to a :ref:`function type ` that declares its :ref:`tag type `. + +Tags are referenced through :ref:`tag indices `, +starting with the smallest index not referencing a tag :ref:`import `. + + .. index:: ! element, ! element mode, ! active, ! passive, ! declarative, element index, table, table index, expression, constant, function index, list pair: abstract syntax; element pair: abstract syntax; element mode @@ -264,13 +300,14 @@ $${syntax: start} The module and its exports are not accessible externally before this initialization has completed. -.. index:: ! export, name, index, external index, function index, table index, memory index, global index, function, table, memory, global, instantiation +.. index:: ! export, name, index, external index, function index, table index, memory index, global index, tag index, function, table, memory, global, tag, instantiation pair: abstract syntax; export pair: abstract syntax; external index single: function; export single: table; export single: memory; export single: global; export + single: tag; export .. _syntax-exportdesc: .. _syntax-export: .. _syntax-externidx: @@ -283,7 +320,12 @@ The ${:export} section of a module defines a set of *exports* that become access $${syntax: export externidx} Each export is labeled by a unique :ref:`name `. -Exportable definitions are :ref:`functions `, :ref:`tables `, :ref:`memories `, and :ref:`globals `, +Exportable definitions are +:ref:`functions `, +:ref:`tables `, +:ref:`memories `, +:ref:`globals `, and +:ref:`tags `, which are referenced through a respective index. @@ -292,15 +334,16 @@ Conventions The following auxiliary notation is defined for sequences of exports, filtering out indices of a specific kind in an order-preserving fashion: -$${definition: funcsxx tablesxx memsxx globalsxx} +$${definition: funcsxx tablesxx memsxx globalsxx tagsxx} -.. index:: ! import, name, function type, table type, memory type, global type, index, index space, type index, function index, table index, memory index, global index, function, table, memory, global, instantiation +.. index:: ! import, name, function type, table type, memory type, global type, tag type, index, index space, type index, function index, table index, memory index, global index, tag index, function, table, memory, tag, global, instantiation pair: abstract syntax; import single: function; import single: table; import single: memory; import single: global; import + single: tag; import .. _syntax-importdesc: .. _syntax-import: @@ -312,8 +355,13 @@ The ${:import} section of a module defines a set of *imports* that are required $${syntax: import} Each import is labeled by a two-level :ref:`name ` space, consisting of a *module name* and an *item name* for an entity within that module. -Importable definitions are :ref:`functions `, :ref:`tables `, :ref:`memories `, and :ref:`globals `. -Each import is specified by a descriptor with a respective type that a definition provided during instantiation is required to match. +Importable definitions are +:ref:`functions `, +:ref:`tables `, +:ref:`memories `, +:ref:`globals `, and +:ref:`tags `. +Each import is specified by a respective :ref:`external type ` that a definition provided during instantiation is required to match. Every import defines an index in the respective :ref:`index space `. In each index space, the indices of imports go before the first index of any definition contained in the module itself. diff --git a/document/core/syntax/types.rst b/document/core/syntax/types.rst index 4f149586ce..f3c0d7c6b7 100644 --- a/document/core/syntax/types.rst +++ b/document/core/syntax/types.rst @@ -103,6 +103,11 @@ The type ${:FUNC} denotes the common supertype of all :ref:`function types `, regardless of their concrete definition. This type has no values. +The type ${:EXN} denotes the common supertype of all :ref:`exception references `. +This type has no concrete subtypes. +Dually, the type ${:NOEXN} denotes the common subtype of all forms of exception references. +This type has no values. + The type ${:EXTERN} denotes the common supertype of all external references received through the :ref:`embedder `. This type has no concrete subtypes. Dually, the type ${:NOEXTERN} denotes the common subtype of all forms of external references. @@ -125,7 +130,7 @@ Their observable value range is limited to 31 bits. Engines need to perform some form of *pointer tagging* to achieve this, which is why one bit is reserved. - Although the types ${:NONE}, ${:NOFUNC}, and ${:NOEXTERN} are not inhabited by any values, + Although the types ${:NONE}, ${:NOFUNC}, ${:NOEXN}, and ${:NOEXTERN} are not inhabited by any values, they can be used to form the types of all null :ref:`references ` in their respective hierarchy. For example, ${:(REF NULL NOFUNC)} is the generic type of a null reference compatible with all function reference types. @@ -168,12 +173,16 @@ Conventions * The reference type ${:$FUNCREF} is an abbreviation for ${reftype: (REF NULL FUNC)}. +* The reference type ${:$EXNREF} is an abbreviation for ${reftype: (REF NULL EXN)}. + * The reference type ${:$EXTERNREF} is an abbreviation for ${reftype: (REF NULL EXTERN)}. * The reference type ${:$NULLREF} is an abbreviation for ${reftype: (REF NULL NONE)}. * The reference type ${:$NULLFUNCREF} is an abbreviation for ${reftype: (REF NULL NOFUNC)}. +* The reference type ${:$NULLEXNREF} is an abbreviation for ${reftype: (REF NULL NOEXN)}. + * The reference type ${:$NULLEXTERNREF} is an abbreviation for ${reftype: (REF NULL NOEXTERN)}. @@ -394,7 +403,31 @@ Since the contents of a data segment requires no further classification, they me $${syntax: datatype} -.. index:: ! external type, defined type, function type, table type, memory type, global type, import, external value +.. index:: ! tag, tag type, function type, exception tag + pair: abstract syntax; tag + pair: tag; exception tag + single: tag; type; exception +.. _syntax-tagtype: + +Tag Types +~~~~~~~~~ + +*Tag types* classify the signature of :ref:`tags ` with a function type. + +.. math:: + \begin{array}{llll} + \production{tag type} &\tagtype &::=& \functype \\ + \end{array} + +Currently tags are only used for categorizing exceptions. +The parameters of |functype| define the list of values associated with the exception thrown with this tag. +Furthermore, it is an invariant of the semantics that every |functype| in a :ref:`valid ` tag type for an exception has an empty result type. + +.. note:: + Future versions of WebAssembly may have additional uses for tags, and may allow non-empty result types in the function types of tags. + + +.. index:: ! external type, defined type, function type, table type, memory type, global type, tag type, import, external address pair: abstract syntax; external type pair: external; type .. _syntax-externtype: @@ -402,7 +435,7 @@ $${syntax: datatype} External Types ~~~~~~~~~~~~~~ -*External types* classify :ref:`imports ` and :ref:`external values ` with their respective types. +*External types* classify :ref:`imports ` and :ref:`external addresses ` with their respective types. $${syntax: externtype} @@ -413,4 +446,4 @@ Conventions The following auxiliary notation is defined for sequences of external types. It filters out entries of a specific kind in an order-preserving fashion: -$${definition: funcsxt tablesxt memsxt globalsxt} +$${definition: funcsxt tablesxt memsxt globalsxt tagsxt} diff --git a/document/core/text/conventions.rst b/document/core/text/conventions.rst index 2e8faf915b..4b288b0330 100644 --- a/document/core/text/conventions.rst +++ b/document/core/text/conventions.rst @@ -125,6 +125,7 @@ It is convenient to define identifier contexts as :ref:`records ` can bind an optional symbolic :ref:`label identifier `. -The same label identifier may optionally be repeated after the corresponding :math:`\T{end}` and :math:`\T{else}` pseudo instructions, to indicate the matching delimiters. +The same label identifier may optionally be repeated after the corresponding :math:`\T{end}` or :math:`\T{else}` keywords, to indicate the matching delimiters. Their :ref:`block type ` is given as a :ref:`type use `, analogous to the type of :ref:`functions `. However, the special case of a type use that is syntactically empty or consists of only a single :ref:`result ` is not regarded as an :ref:`abbreviation ` for an inline :ref:`function type `, but is parsed directly into an optional :ref:`value type `. @@ -88,7 +90,23 @@ However, the special case of a type use that is syntactically empty or consists \text{if}~~(v^?,I'){:}\Tlabel_I~~\X{bt}{:}\Tblocktype_I~~(\X{in}_1{:}\Tinstr_{I'})^\ast~~ \text{else}~~v_1^?{:}\Tid_1^?~~(\X{in}_2{:}\Tinstr_{I'})^\ast~~\text{end}~~v_2^?{:}\Tid_2^? \\ &&&\qquad \Rightarrow\quad \IF~\X{bt}~\X{in}_1^\ast~\ELSE~\X{in}_2^\ast~\END - \qquad (\iff v_1^? = \epsilon \vee v_1^? = v^?, v_2^? = \epsilon \vee v_2^? = v^?) \\ + \qquad (\iff v_1^? = \epsilon \vee v_1^? = v^?, v_2^? = \epsilon \vee v_2^? = v^?) \\ &&|& + \text{try\_table}~~I'{:}\Tlabel_I~~\X{bt}{:}\Tblocktype~~(c{:}\Tcatch_I)^\ast~~(\X{in}{:}\Tinstr_{I'})^\ast~~\text{end}~~\Tid^? + \\ &&&\qquad \Rightarrow\quad \TRYTABLE~\X{bt}~c^\ast~\X{in}^\ast~~\END + \qquad\qquad (\iff \Tid^? = \epsilon \vee \Tid^? = \Tlabel) \\ + \production{catch clause} & \Tcatch_I & + \begin{array}[t]{@{}c@{}} ::= \\ | \\ | \\ | \\ \end{array} + & + \begin{array}[t]{@{}lcll@{}} + \text{(}~\text{catch}~~x{:}\Ttagidx_I~~l{:}\Tlabelidx_I~\text{)} + &\Rightarrow& \CATCH~x~l \\ + \text{(}~\text{catch\_ref}~~x{:}\Ttagidx_I~~l{:}\Tlabelidx_I~\text{)} + &\Rightarrow& \CATCHREF~x~l \\ + \text{(}~\text{catch\_all}~~l{:}\Tlabelidx_I~\text{)} + &\Rightarrow& \CATCHALL~l \\ + \text{(}~\text{catch\_all\_ref}~~l{:}\Tlabelidx_I~\text{)} + &\Rightarrow& \CATCHALLREF~l \\ + \end{array} \\ \end{array} .. note:: @@ -110,6 +128,8 @@ However, the special case of a type use that is syntactically empty or consists .. _text-call_indirect: .. _text-return_call: .. _text-return_call_indirect: +.. _text-throw: +.. _text-throw_ref: All other control instruction are represented verbatim. @@ -134,7 +154,9 @@ All other control instruction are represented verbatim. \text{return\_call}~~x{:}\Tfuncidx_I &\Rightarrow& \RETURNCALL~x \\ &&|& \text{return\_call\_ref}~~x{:}\Ttypeidx &\Rightarrow& \RETURNCALLREF~x \\ &&|& \text{return\_call\_indirect}~~x{:}\Ttableidx~~y,I'{:}\Ttypeuse_I &\Rightarrow& \RETURNCALLINDIRECT~x~y - & (\iff I' = \{\ILOCALS~(\epsilon)^\ast\}) \\ + & (\iff I' = \{\ILOCALS~(\epsilon)^\ast\}) \\ &&|& + \text{throw}~~x{:}\Ttagidx_I &\Rightarrow& \THROW~x \\ &&|& + \text{throw\_ref} &\Rightarrow& \THROWREF \\ \end{array} .. note:: @@ -1059,9 +1081,14 @@ Such a folded instruction can appear anywhere a regular instruction can. \text{(}~\text{if}~~\Tlabel~~\Tblocktype~~\Tfoldedinstr^\ast &\hspace{-3ex} \text{(}~\text{then}~~\Tinstr_1^\ast~\text{)}~~(\text{(}~\text{else}~~\Tinstr_2^\ast~\text{)})^?~~\text{)} \quad\equiv \\ &\qquad - \Tfoldedinstr^\ast~~\text{if}~~\Tlabel~~\Tblocktype &\hspace{-1ex} \Tinstr_1^\ast~~\text{else}~~(\Tinstr_2^\ast)^?~\text{end} \\ + \Tfoldedinstr^\ast~~\text{if}~~\Tlabel + &\hspace{-12ex} \Tblocktype~~\Tinstr_1^\ast~~\text{else}~~(\Tinstr_2^\ast)^?~\text{end} \\ & + \text{(}~\text{try\_table}~~\Tlabel~~\Tblocktype~~\Tcatch^\ast~~\Tinstr^\ast~\text{)} + \quad\equiv \\ &\qquad + \text{try\_table}~~\Tlabel~~\Tblocktype~~\Tcatch^\ast~~\Tinstr^\ast~~\text{end} \\ \end{array} + .. note:: For example, the instruction sequence diff --git a/document/core/text/modules.rst b/document/core/text/modules.rst index ee4c756dfe..d7866b8be6 100644 --- a/document/core/text/modules.rst +++ b/document/core/text/modules.rst @@ -2,12 +2,13 @@ Modules ------- -.. index:: index, type index, function index, table index, memory index, global index, element index, data index, local index, label index +.. index:: index, type index, function index, table index, memory index, global index, tag index, element index, data index, local index, label index pair: text format; type index pair: text format; function index pair: text format; table index pair: text format; memory index pair: text format; global index + pair: text format; tag index pair: text format; element index pair: text format; data index pair: text format; local index @@ -16,9 +17,10 @@ Modules .. _text-funcidx: .. _text-tableidx: .. _text-memidx: +.. _text-globalidx: +.. _text-tagidx: .. _text-elemidx: .. _text-dataidx: -.. _text-globalidx: .. _text-localidx: .. _text-labelidx: .. _text-fieldidx: @@ -47,6 +49,9 @@ Such identifiers are looked up in the suitable space of the :ref:`identifier con \production{global index} & \Tglobalidx_I &::=& x{:}\Tu32 &\Rightarrow& x \\&&|& v{:}\Tid &\Rightarrow& x & (\iff I.\IGLOBALS[x] = v) \\ + \production{tag index} & \Ttagidx_I &::=& + x{:}\Tu32 &\Rightarrow& x \\&&|& + v{:}\Tid &\Rightarrow& x & (\iff I.\ITAGS[x] = v) \\ \production{element index} & \Telemidx_I &::=& x{:}\Tu32 &\Rightarrow& x \\&&|& v{:}\Tid &\Rightarrow& x & (\iff I.\IELEM[x] = v) \\ @@ -140,7 +145,7 @@ If no such index exists, then a new :ref:`recursive type ` of the Abbreviations are expanded in the order they appear, such that previously inserted type definitions are reused by consecutive expansions. -.. index:: import, name, function type, table type, memory type, global type +.. index:: import, name, function type, table type, memory type, global type, tag type pair: text format; import .. _text-importdesc: .. _text-import: @@ -148,7 +153,7 @@ Abbreviations are expanded in the order they appear, such that previously insert Imports ~~~~~~~ -The descriptors in imports can bind a symbolic function, table, memory, or global :ref:`identifier `. +The descriptors in imports can bind a symbolic function, table, memory, tag, or global :ref:`identifier `. .. math:: \begin{array}{llclll} @@ -163,14 +168,22 @@ The descriptors in imports can bind a symbolic function, table, memory, or globa \text{(}~\text{memory}~~\Tid^?~~\X{mt}{:}\Tmemtype_I~\text{)} &\Rightarrow& \IDMEM~~\X{mt} \\ &&|& \text{(}~\text{global}~~\Tid^?~~\X{gt}{:}\Tglobaltype_I~\text{)} - &\Rightarrow& \IDGLOBAL~\X{gt} \\ + &\Rightarrow& \IDGLOBAL~\X{gt} \\ &&|& + \text{(}~\text{tag}~~\Tid^?~~\X{tt}{:}\Ttag~\text{)} + &\Rightarrow& \IDTAG~\X{tt} \\ \end{array} Abbreviations ............. -As an abbreviation, imports may also be specified inline with :ref:`function `, :ref:`table `, :ref:`memory `, or :ref:`global ` definitions; see the respective sections. +As an abbreviation, imports may also be specified inline with +:ref:`function `, +:ref:`table `, +:ref:`memory `, +:ref:`global `, or +:ref:`tag ` +definitions; see the respective sections. @@ -438,7 +451,54 @@ Globals can be defined as :ref:`imports ` or :ref:`exports `. + +.. math:: + \begin{array}{llcl} + \production{tag} & \Ttag_I &::=& + \text{(}~\text{tag}~~\Tid^?~~x,I'{:}\Ttypeuse_I~\text{)} \\ &&& \qquad + \Rightarrow\quad \{ \TAGTYPE~x \} \\ + \end{array} + +.. index:: import, name + pair: text format; import +.. index:: export, name, index, tag index + pair: text format; export +.. index:: tag +.. _text-tag-abbrev: + +Abbreviations +............. + +Tags can be defined as :ref:`imports ` or :ref:`exports ` inline: + +.. math:: + \begin{array}{llclll} + \production{module field} & + \text{(}~\text{tag}~~\Tid^?~~\text{(}~\text{import}~~\Tname_1~~\Tname_2~\text{)}~~\Ttypeuse~\text{)} \quad\equiv \\ & \qquad + \text{(}~\text{import}~~\Tname_1~~\Tname_2~~\text{(}~\text{tag}~~\Tid^?~~\Ttypeuse~\text{)}~\text{)} + \\[1ex] & + \text{(}~\text{tag}~~\Tid^?~~\text{(}~\text{export}~~\Tname~\text{)}~~\dots~\text{)} \quad\equiv \\ & \qquad + \text{(}~\text{export}~~\Tname~~\text{(}~\text{tag}~~\Tid'~\text{)}~\text{)}~~ + \text{(}~\text{tag}~~\Tid'~~\dots~\text{)} + \\ & \qquad\qquad + (\iff \Tid^? \neq \epsilon \wedge \Tid' = \Tid^? \vee \Tid^? = \epsilon \wedge \Tid' \idfresh) \\ + \end{array} + +.. note:: + The latter abbreviation can be applied repeatedly, if ":math:`\dots`" contains additional export clauses. + Consequently, a memory declaration can contain any number of exports, possibly followed by an import. + + + +.. index:: export, name, index, function index, table index, memory index, global index, tag index pair: text format; export .. _text-exportdesc: .. _text-export: @@ -452,23 +512,31 @@ The syntax for exports mirrors their :ref:`abstract syntax ` dire \begin{array}{llclll} \production{export} & \Texport_I &::=& \text{(}~\text{export}~~\X{nm}{:}\Tname~~d{:}\Texportdesc_I~\text{)} - &\Rightarrow& \{ \ENAME~\X{nm}, \EDESC~d \} \\ + &\Rightarrow& \{ \XNAME~\X{nm}, \XDESC~d \} \\ \production{export description} & \Texportdesc_I &::=& \text{(}~\text{func}~~x{:}\Tfuncidx_I~\text{)} - &\Rightarrow& \EDFUNC~x \\ &&|& + &\Rightarrow& \XDFUNC~x \\ &&|& \text{(}~\text{table}~~x{:}\Ttableidx_I~\text{)} - &\Rightarrow& \EDTABLE~x \\ &&|& + &\Rightarrow& \XDTABLE~x \\ &&|& \text{(}~\text{memory}~~x{:}\Tmemidx_I~\text{)} - &\Rightarrow& \EDMEM~x \\ &&|& + &\Rightarrow& \XDMEM~x \\ &&|& \text{(}~\text{global}~~x{:}\Tglobalidx_I~\text{)} - &\Rightarrow& \EDGLOBAL~x \\ + &\Rightarrow& \XDGLOBAL~x \\&&|& + \text{(}~\text{tag}~~x{:}\Ttagidx_I~\text{)} + &\Rightarrow& \XDTAG~x \\ \end{array} Abbreviations ............. -As an abbreviation, exports may also be specified inline with :ref:`function `, :ref:`table `, :ref:`memory `, or :ref:`global ` definitions; see the respective sections. +As an abbreviation, exports may also be specified inline with +:ref:`function `, +:ref:`table `, +:ref:`memory `, +:ref:`global `, or +:ref:`tag ` +definitions; see the respective sections. .. index:: start function, function index @@ -623,7 +691,7 @@ Also, a memory use can be omitted, defaulting to :math:`\T{0}`. As another abbreviation, data segments may also be specified inline with :ref:`memory ` definitions; see the respective section. -.. index:: module, type definition, function type, function, table, memory, global, element, data, start function, import, export, identifier context, identifier, name section +.. index:: module, type definition, function type, function, table, memory, global, tag, element, data, start function, import, export, identifier context, identifier, name section pair: text format; module single: section; name .. _text-modulefield: @@ -659,10 +727,11 @@ The name serves a documentary role only. \X{ta}{:}\Ttable_I &\Rightarrow& \{\MTABLES~\X{ta}\} \\ |& \X{me}{:}\Tmem_I &\Rightarrow& \{\MMEMS~\X{me}\} \\ |& \X{gl}{:}\Tglobal_I &\Rightarrow& \{\MGLOBALS~\X{gl}\} \\ |& - \X{ex}{:}\Texport_I &\Rightarrow& \{\MEXPORTS~\X{ex}\} \\ |& - \X{st}{:}\Tstart_I &\Rightarrow& \{\MSTART~\X{st}\} \\ |& + \X{tg}{:}\Ttag_I &\Rightarrow& \{\MTAGS~\X{tg}\} \\ |& \X{el}{:}\Telem_I &\Rightarrow& \{\MELEMS~\X{el}\} \\ |& - \X{da}{:}\Tdata_I &\Rightarrow& \{\MDATAS~\X{da}\} \\ + \X{da}{:}\Tdata_I &\Rightarrow& \{\MDATAS~\X{da}\} \\ |& + \X{st}{:}\Tstart_I &\Rightarrow& \{\MSTART~\X{st}\} \\ |& + \X{ex}{:}\Texport_I &\Rightarrow& \{\MEXPORTS~\X{ex}\} \\ \end{array} \end{array} @@ -670,11 +739,16 @@ The following restrictions are imposed on the composition of :ref:`modules ` must occur before any regular definition of a :ref:`function `, :ref:`table `, :ref:`memory `, or :ref:`global `, + The second condition enforces that all :ref:`imports ` must occur before any regular definition of a + :ref:`function `, + :ref:`table `, + :ref:`memory `, + :ref:`global `, or + :ref:`tag `, thereby maintaining the ordering of the respective :ref:`index spaces `. The :ref:`well-formedness ` condition on :math:`I` in the grammar for |Tmodule| ensures that no namespace contains duplicate identifiers. @@ -695,6 +769,8 @@ The definition of the initial :ref:`identifier context ` :math:`I` \{\IMEMS~(v^?)\} \\ \F{idc}(\text{(}~\text{global}~v^?{:}\Tid^?~\dots~\text{)}) &=& \{\IGLOBALS~(v^?)\} \\ + \F{idc}(\text{(}~\text{tag}~v^?{:}\Tid^?~\dots~\text{)}) &=& + \{\ITAGS~(v^?)\} \\ \F{idc}(\text{(}~\text{elem}~v^?{:}\Tid^?~\dots~\text{)}) &=& \{\IELEM~(v^?)\} \\ \F{idc}(\text{(}~\text{data}~v^?{:}\Tid^?~\dots~\text{)}) &=& diff --git a/document/core/text/types.rst b/document/core/text/types.rst index a4c1f3d58b..09b8bb5069 100644 --- a/document/core/text/types.rst +++ b/document/core/text/types.rst @@ -56,6 +56,8 @@ Heap Types \text{func} &\Rightarrow& \FUNC \\ &&|& \text{nofunc} &\Rightarrow& \NOFUNC \\ &&|& \text{extern} &\Rightarrow& \EXTERN \\ &&|& + \text{noexn} &\Rightarrow& \NOEXN \\ &&|& + \text{exn} &\Rightarrow& \EXN \\ &&|& \text{noextern} &\Rightarrow& \NOEXTERN \\ \production{heap type} & \Theaptype_I &::=& t{:}\Tabsheaptype &\Rightarrow& y \\ &&|& @@ -95,6 +97,8 @@ There are shorthands for references to abstract heap types. \text{nullref} &\equiv& \text{(}~\text{ref}~~\text{null}~~\text{none}~\text{)} \\ \text{funcref} &\equiv& \text{(}~\text{ref}~~\text{null}~~\text{func}~\text{)} \\ \text{nullfuncref} &\equiv& \text{(}~\text{ref}~~\text{null}~~\text{nofunc}~\text{)} \\ + \text{exnref} &\equiv& \text{(}~\text{ref}~~\text{null}~~\text{exn}~\text{)} \\ + \text{nullexnref} &\equiv& \text{(}~\text{ref}~~\text{null}~~\text{noexn}~\text{)} \\ \text{externref} &\equiv& \text{(}~\text{ref}~~\text{null}~~\text{extern}~\text{)} \\ \text{nullexternref} &\equiv& \text{(}~\text{ref}~~\text{null}~~\text{noextern}~\text{)} \\ \end{array} diff --git a/document/core/util/macros.def b/document/core/util/macros.def index c3f6ffaf80..934bd53978 100644 --- a/document/core/util/macros.def +++ b/document/core/util/macros.def @@ -211,9 +211,11 @@ .. |STRUCTREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{structref}} .. |ARRAYREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{arrayref}} .. |FUNCREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{funcref}} +.. |EXNREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{exnref}} .. |EXTERNREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{externref}} .. |NULLREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{nullref}} .. |NULLFUNCREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{nullfuncref}} +.. |NULLEXNREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{nullexnref}} .. |NULLEXTERNREF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{nullexternref}} .. |REF| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{ref}} .. |NULL| mathdef:: \xref{syntax/types}{syntax-reftype}{\K{null}} @@ -224,9 +226,11 @@ .. |STRUCT| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{struct}} .. |ARRAY| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{array}} .. |FUNCT| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{func}} +.. |EXN| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{exn}} .. |EXTERN| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{extern}} .. |NONE| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{none}} .. |NOFUNC| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{nofunc}} +.. |NOEXN| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{noexn}} .. |NOEXTERN| mathdef:: \xref{syntax/types}{syntax-heaptype}{\K{noextern}} .. |I8X16| mathdef:: \xref{syntax/instructions}{syntax-shape}{\K{i{\scriptstyle8}x\scriptstyle16}} @@ -261,10 +265,11 @@ .. |LMAX| mathdef:: \xref{syntax/types}{syntax-limits}{\K{max}} .. |PAGE| mathdef:: \xref{syntax/types}{syntax-memtype}{\K{page}} -.. |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}} +.. |XTFUNC| mathdef:: \xref{syntax/types}{syntax-externtype}{\K{func}} +.. |XTTABLE| mathdef:: \xref{syntax/types}{syntax-externtype}{\K{table}} +.. |XTMEM| mathdef:: \xref{syntax/types}{syntax-externtype}{\K{mem}} +.. |XTGLOBAL| mathdef:: \xref{syntax/types}{syntax-externtype}{\K{global}} +.. |XTTAG| mathdef:: \xref{syntax/types}{syntax-tagtype}{\K{tag}} .. Types, non-terminals @@ -294,6 +299,7 @@ .. |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}} +.. |tagtype| mathdef:: \xref{syntax/types}{syntax-tagtype}{\X{tagtype}} .. |elemtype| mathdef:: \xref{syntax/types}{syntax-elemtype}{\X{elemtype}} .. |datatype| mathdef:: \xref{syntax/types}{syntax-datatype}{\X{datatype}} .. |externtype| mathdef:: \xref{syntax/types}{syntax-externtype}{\X{externtype}} @@ -325,6 +331,7 @@ .. |tablesxt| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{tables}} .. |memsxt| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{mems}} .. |globalsxt| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{globals}} +.. |tagsxt| mathdef:: \xref{syntax/types}{syntax-externtype}{\F{tags}} .. |assignsubst| mathdef:: \xref{valid/conventions}{notation-subst}{\mathrel{:=}} .. |lbracksubst| mathdef:: \xref{valid/conventions}{notation-subst}{{[}} @@ -339,6 +346,7 @@ .. |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}} +.. |tagidx| mathdef:: \xref{syntax/modules}{syntax-tagidx}{\X{tagidx}} .. |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}} @@ -370,6 +378,7 @@ .. |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}} @@ -396,6 +405,9 @@ .. |GTYPE| mathdef:: \xref{syntax/modules}{syntax-global}{\K{type}} .. |GINIT| mathdef:: \xref{syntax/modules}{syntax-global}{\K{init}} +.. |TAG| mathdef:: \xref{syntax/modules}{syntax-tag}{\K{tag}} +.. |TAGTYPE| mathdef:: \xref{syntax/modules}{syntax-tag}{\K{type}} + .. |ELEM| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{elem}} .. |ETYPE| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{type}} .. |EINIT| mathdef:: \xref{syntax/modules}{syntax-elem}{\K{init}} @@ -418,12 +430,13 @@ .. |SFUNC| mathdef:: \xref{syntax/modules}{syntax-start}{\K{func}} .. |EXPORT| mathdef:: \xref{syntax/modules}{syntax-export}{\K{export}} -.. |ENAME| mathdef:: \xref{syntax/modules}{syntax-export}{\K{name}} +.. |XNAME| mathdef:: \xref{syntax/modules}{syntax-export}{\K{name}} -.. |EXFUNC| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{func}} -.. |EXTABLE| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{table}} -.. |EXMEM| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{memory}} -.. |EXGLOBAL| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{global}} +.. |XXFUNC| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{func}} +.. |XXTABLE| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{table}} +.. |XXMEM| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{memory}} +.. |XXGLOBAL| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{global}} +.. |XXTAG| mathdef:: \xref{syntax/modules}{syntax-externidx}{\K{tag}} .. |IMPORT| mathdef:: \xref{syntax/modules}{syntax-import}{\K{import}} .. |IMODULE| mathdef:: \xref{syntax/modules}{syntax-import}{\K{module}} @@ -431,17 +444,19 @@ .. TODO remove below -.. |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}} +.. |XDESC| mathdef:: \xref{syntax/modules}{syntax-export}{\K{desc}} +.. |XDFUNC| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{func}} +.. |XDTABLE| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{table}} +.. |XDMEM| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{mem}} +.. |XDGLOBAL| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{global}} +.. |XDTAG| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\K{tag}} .. |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}} .. |IDGLOBAL| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\K{global}} +.. |IDTAG| mathdef:: \xref{syntax/modules}{syntax-importdesc}{\K{tag}} .. Modules, non-terminals @@ -453,6 +468,7 @@ .. |table| mathdef:: \xref{syntax/modules}{syntax-table}{\X{table}} .. |mem| mathdef:: \xref{syntax/modules}{syntax-mem}{\X{mem}} .. |global| mathdef:: \xref{syntax/modules}{syntax-global}{\X{global}} +.. |tag| mathdef:: \xref{syntax/modules}{syntax-tag}{\X{tag}} .. |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}} @@ -470,6 +486,7 @@ .. |tablesxx| mathdef:: \xref{syntax/modules}{syntax-externidx}{\F{tables}} .. |memsxx| mathdef:: \xref{syntax/modules}{syntax-externidx}{\F{mems}} .. |globalsxx| mathdef:: \xref{syntax/modules}{syntax-externidx}{\F{globals}} +.. |tagsxx| mathdef:: \xref{syntax/modules}{syntax-externidx}{\F{tags}} .. Instructions, terminals @@ -507,6 +524,14 @@ .. |RETURNCALLREF| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{return\_call\_ref}} .. |RETURNCALLINDIRECT| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{return\_call\_indirect}} +.. |THROW| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{throw}} +.. |THROWREF| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{throw\_ref}} +.. |TRYTABLE| mathdef:: \xref{syntax/instructions}{syntax-instr-control}{\K{try\_table}} +.. |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}} + .. |DROP| mathdef:: \xref{syntax/instructions}{syntax-instr-parametric}{\K{drop}} .. |SELECT| mathdef:: \xref{syntax/instructions}{syntax-instr-parametric}{\K{select}} @@ -751,6 +776,7 @@ .. |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}} @@ -825,6 +851,7 @@ .. |Bsubtype| mathdef:: \xref{binary/types}{binary-subtype}{\B{subtype}} .. |Brectype| mathdef:: \xref{binary/types}{binary-rectype}{\B{rectype}} .. |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}} @@ -840,6 +867,7 @@ .. |Btableidx| mathdef:: \xref{binary/modules}{binary-tableidx}{\B{tableidx}} .. |Bmemidx| mathdef:: \xref{binary/modules}{binary-memidx}{\B{memidx}} .. |Bglobalidx| mathdef:: \xref{binary/modules}{binary-globalidx}{\B{globalidx}} +.. |Btagidx| mathdef:: \xref{binary/modules}{binary-tagidx}{\B{tagidx}} .. |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}} @@ -863,6 +891,7 @@ .. |Btablesec| mathdef:: \xref{binary/modules}{binary-tablesec}{\B{tablesec}} .. |Bmemsec| mathdef:: \xref{binary/modules}{binary-memsec}{\B{memsec}} .. |Bglobalsec| mathdef:: \xref{binary/modules}{binary-globalsec}{\B{globalsec}} +.. |Btagsec| mathdef:: \xref{binary/modules}{binary-tagsec}{\B{tagsec}} .. |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}} @@ -876,6 +905,7 @@ .. |Btable| mathdef:: \xref{binary/modules}{binary-table}{\B{table}} .. |Bmem| mathdef:: \xref{binary/modules}{binary-mem}{\B{mem}} .. |Bglobal| mathdef:: \xref{binary/modules}{binary-global}{\B{global}} +.. |Btag| mathdef:: \xref{binary/modules}{binary-tag}{\B{tag}} .. |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}} @@ -897,6 +927,7 @@ .. |Bcastop| mathdef:: \xref{binary/instructions}{binary-castop}{\B{castop}} .. |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}} @@ -1029,6 +1060,7 @@ .. |Ttableidx| mathdef:: \xref{text/modules}{text-tableidx}{\T{tableidx}} .. |Tmemidx| mathdef:: \xref{text/modules}{text-memidx}{\T{memidx}} .. |Tglobalidx| mathdef:: \xref{text/modules}{text-globalidx}{\T{globalidx}} +.. |Ttagidx| mathdef:: \xref{text/modules}{text-tagidx}{\T{tagidx}} .. |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}} @@ -1046,6 +1078,7 @@ .. |Ttable| mathdef:: \xref{text/modules}{text-table}{\T{table}} .. |Tmem| mathdef:: \xref{text/modules}{text-mem}{\T{mem}} .. |Tglobal| mathdef:: \xref{text/modules}{text-global}{\T{global}} +.. |Ttag| mathdef:: \xref{text/modules}{text-tag}{\T{tag}} .. |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}} @@ -1075,6 +1108,7 @@ .. |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}} @@ -1091,6 +1125,7 @@ .. |ITABLES| mathdef:: \xref{text/conventions}{text-context}{\K{tables}} .. |IMEMS| mathdef:: \xref{text/conventions}{text-context}{\K{mems}} .. |IGLOBALS| mathdef:: \xref{text/conventions}{text-context}{\K{globals}} +.. |ITAGS| mathdef:: \xref{text/conventions}{text-context}{\K{tags}} .. |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}} @@ -1123,6 +1158,7 @@ .. |CTABLES| mathdef:: \xref{valid/conventions}{context}{\K{tables}} .. |CMEMS| mathdef:: \xref{valid/conventions}{context}{\K{mems}} .. |CGLOBALS| mathdef:: \xref{valid/conventions}{context}{\K{globals}} +.. |CTAGS| mathdef:: \xref{valid/conventions}{context}{\K{tags}} .. |CELEMS| mathdef:: \xref{valid/conventions}{context}{\K{elems}} .. |CDATAS| mathdef:: \xref{valid/conventions}{context}{\K{datas}} .. |CLOCALS| mathdef:: \xref{valid/conventions}{context}{\K{locals}} @@ -1156,6 +1192,7 @@ .. |vdashtabletype| mathdef:: \xref{valid/types}{valid-tabletype}{\vdash} .. |vdashmemtype| mathdef:: \xref{valid/types}{valid-memtype}{\vdash} .. |vdashglobaltype| mathdef:: \xref{valid/types}{valid-globaltype}{\vdash} +.. |vdashtagtype| mathdef:: \xref{valid/types}{valid-tagtype}{\vdash} .. |vdashexterntype| mathdef:: \xref{valid/types}{valid-externtype}{\vdash} .. |vdashdeftype| mathdef:: \xref{valid/types}{valid-deftype}{\vdash} @@ -1182,6 +1219,7 @@ .. |OKtabletype| mathdef:: \xref{valid/types}{valid-tabletype}{\K{ok}} .. |OKmemtype| mathdef:: \xref{valid/types}{valid-memtype}{\K{ok}} .. |OKglobaltype| mathdef:: \xref{valid/types}{valid-globaltype}{\K{ok}} +.. |OKtagtype| mathdef:: \xref{valid/types}{valid-tagtype}{\K{ok}} .. |OKexterntype| mathdef:: \xref{valid/types}{valid-externtype}{\K{ok}} .. |OKlimits| mathdef:: \xref{valid/types}{valid-limits}{\K{ok}} @@ -1205,6 +1243,7 @@ .. |vdashtabletypematch| mathdef:: \xref{valid/matching}{match-tabletype}{\vdash} .. |vdashmemtypematch| mathdef:: \xref{valid/matching}{match-memtype}{\vdash} .. |vdashglobaltypematch| mathdef:: \xref{valid/matching}{match-globaltype}{\vdash} +.. |vdashtagtypematch| mathdef:: \xref{valid/matching}{match-tagtype}{\vdash} .. |vdashexterntypematch| mathdef:: \xref{valid/matching}{match-externtype}{\vdash} .. |vdashlimitsmatch| mathdef:: \xref{valid/matching}{match-limits}{\vdash} @@ -1226,16 +1265,20 @@ .. |subtabletypematch| mathdef:: \xref{valid/matching}{match-tabletype}{\leq} .. |submemtypematch| mathdef:: \xref{valid/matching}{match-memtype}{\leq} .. |subglobaltypematch| mathdef:: \xref{valid/matching}{match-globaltype}{\leq} +.. |subtagtypematch| mathdef:: \xref{valid/matching}{match-tagtype}{\leq} .. |subexterntypematch| mathdef:: \xref{valid/matching}{match-externtype}{\leq} .. |sublimitsmatch| mathdef:: \xref{valid/matching}{match-limits}{\leq} .. |vdashinstr| mathdef:: \xref{valid/instructions}{valid-instr}{\vdash} .. |vdashinstrs| mathdef:: \xref{valid/instructions}{valid-instrs}{\vdash} +.. |vdashcatch| mathdef:: \xref{valid/instructions}{valid-catch}{\vdash} .. |vdashexpr| mathdef:: \xref{valid/instructions}{valid-expr}{\vdash} .. |vdashinstrconst| mathdef:: \xref{valid/instructions}{valid-const}{\vdash} .. |vdashexprconst| mathdef:: \xref{valid/instructions}{valid-const}{\vdash} .. |vdashexprokconst| mathdef:: \xref{valid/instructions}{valid-const}{\vdash} +.. |OKcatch| mathdef:: \xref{valid/instructions}{valid-catch}{\K{ok}} + .. |CONSTinstrconst| mathdef:: \xref{valid/instructions}{valid-const}{\K{const}} .. |CONSTexprconst| mathdef:: \xref{valid/instructions}{valid-const}{\K{const}} .. |CONSTexprokconst| mathdef:: \xref{valid/instructions}{valid-const}{\K{const}} @@ -1249,6 +1292,7 @@ .. |vdashtable| mathdef:: \xref{valid/modules}{valid-table}{\vdash} .. |vdashmem| mathdef:: \xref{valid/modules}{valid-mem}{\vdash} .. |vdashglobal| mathdef:: \xref{valid/modules}{valid-global}{\vdash} +.. |vdashtag| mathdef:: \xref{valid/modules}{valid-tag}{\vdash} .. |vdashglobals| mathdef:: \xref{valid/modules}{valid-globalseq}{\vdash} .. |vdashelem| mathdef:: \xref{valid/modules}{valid-elem}{\vdash} .. |vdashelemmode| mathdef:: \xref{valid/modules}{valid-elemmode}{\vdash} @@ -1292,11 +1336,14 @@ .. |alloctable| mathdef:: \xref{exec/modules}{alloc-table}{\F{alloctable}} .. |allocmem| mathdef:: \xref{exec/modules}{alloc-mem}{\F{allocmem}} .. |allocglobal| mathdef:: \xref{exec/modules}{alloc-global}{\F{allocglobal}} +.. |alloctag| mathdef:: \xref{exec/modules}{alloc-tag}{\F{alloctag}} .. |allocelem| mathdef:: \xref{exec/modules}{alloc-elem}{\F{allocelem}} .. |allocdata| mathdef:: \xref{exec/modules}{alloc-data}{\F{allocdata}} .. |allocexport| mathdef:: \xref{exec/modules}{alloc-export}{\F{allocexport}} .. |allocmodule| mathdef:: \xref{exec/modules}{alloc-module}{\F{allocmodule}} +.. |allocexn| mathdef:: \xref{exec/modules}{alloc-exception}{\F{allocexn}} + .. |evalglobal| mathdef:: \xref{exec/modules}{eval-globals}{\F{evalglobal}} .. |growtable| mathdef:: \xref{exec/modules}{grow-table}{\F{growtable}} @@ -1313,10 +1360,12 @@ .. |tableaddr| mathdef:: \xref{exec/runtime}{syntax-tableaddr}{\X{tableaddr}} .. |memaddr| mathdef:: \xref{exec/runtime}{syntax-memaddr}{\X{memaddr}} .. |globaladdr| mathdef:: \xref{exec/runtime}{syntax-globaladdr}{\X{globaladdr}} +.. |tagaddr| mathdef:: \xref{exec/runtime}{syntax-tagaddr}{\X{tagaddr}} .. |elemaddr| mathdef:: \xref{exec/runtime}{syntax-elemaddr}{\X{elemaddr}} .. |dataaddr| mathdef:: \xref{exec/runtime}{syntax-dataaddr}{\X{dataaddr}} .. |structaddr| mathdef:: \xref{exec/runtime}{syntax-structaddr}{\X{structaddr}} .. |arrayaddr| mathdef:: \xref{exec/runtime}{syntax-arrayaddr}{\X{arrayaddr}} +.. |exnaddr| mathdef:: \xref{exec/runtime}{syntax-exnaddr}{\X{exnaddr}} .. |hostaddr| mathdef:: \xref{exec/runtime}{syntax-hostaddr}{\X{hostaddr}} @@ -1326,6 +1375,7 @@ .. |freetableaddr| mathdef:: \xref{exec/runtime}{syntax-tableaddr}{\F{tableaddr}} .. |freememaddr| mathdef:: \xref{exec/runtime}{syntax-memaddr}{\F{memaddr}} .. |freeglobaladdr| mathdef:: \xref{exec/runtime}{syntax-globaladdr}{\F{globaladdr}} +.. |freetagaddr| mathdef:: \xref{exec/runtime}{syntax-globaladdr}{\F{tagaddr}} .. |freeelemaddr| mathdef:: \xref{exec/runtime}{syntax-elemaddr}{\F{elemaddr}} .. |freedataaddr| mathdef:: \xref{exec/runtime}{syntax-dataaddr}{\F{dataaddr}} @@ -1347,25 +1397,29 @@ .. |GITYPE| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\K{type}} .. |GIVALUE| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\K{value}} +.. |HITYPE| mathdef:: \xref{exec/runtime}{syntax-taginst}{\K{type}} + .. |EITYPE| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\K{type}} .. |EIREFS| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\K{elem}} .. |DITYPE| mathdef:: \xref{exec/runtime}{syntax-datainst}{\K{data}} .. |DIBYTES| mathdef:: \xref{exec/runtime}{syntax-datainst}{\K{bytes}} -.. |EINAME| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{name}} -.. |EIVALUE| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{value}} +.. |XINAME| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{name}} +.. |XIADDR| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{addr}} -.. |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}} -.. |EVGLOBAL| mathdef:: \xref{exec/runtime}{syntax-externval}{\K{global}} +.. |XAFUNC| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\K{func}} +.. |XATABLE| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\K{table}} +.. |XAMEM| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\K{mem}} +.. |XAGLOBAL| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\K{global}} +.. |XATAG| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\K{tag}} .. |MITYPES| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{types}} .. |MIFUNCS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{funcs}} .. |MITABLES| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{tables}} .. |MIMEMS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{mems}} .. |MIGLOBALS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{globals}} +.. |MITAGS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{tags}} .. |MIELEMS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{elems}} .. |MIDATAS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{datas}} .. |MIEXPORTS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{exports}} @@ -1376,6 +1430,9 @@ .. |AITYPE| mathdef:: \xref{exec/runtime}{syntax-arrayinst}{\K{type}} .. |AIFIELDS| mathdef:: \xref{exec/runtime}{syntax-arrayinst}{\K{fields}} +.. |EITAG| mathdef:: \xref{exec/runtime}{syntax-exninst}{\K{tag}} +.. |EIFIELDS| mathdef:: \xref{exec/runtime}{syntax-exninst}{\K{fields}} + .. |PACK| mathdef:: \xref{exec/runtime}{syntax-packval}{\K{pack}} .. |I8PACK| mathdef:: \xref{exec/runtime}{syntax-packval}{\K{i8.pack}} .. |I16PACK| mathdef:: \xref{exec/runtime}{syntax-packval}{\K{i16.pack}} @@ -1388,10 +1445,12 @@ .. |ZGLOBALS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{globals}} .. |ZTABLES| mathdef:: \xref{exec/runtime}{syntax-store}{\K{tables}} .. |ZMEMS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{mems}} +.. |ZTAGS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{tags}} .. |ZELEMS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{elems}} .. |ZDATAS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{datas}} .. |ZSTRUCTS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{structs}} .. |ZARRAYS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{arrays}} +.. |ZEXNS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{exns}} .. |ZLOCALS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{locals}} .. |ZGGLOBALS| mathdef:: \ZGLOBALS @@ -1415,7 +1474,7 @@ .. |packval| mathdef:: \xref{exec/runtime}{syntax-packval}{\X{packval}} .. |pack| mathdef:: \xref{exec/runtime}{syntax-pack}{\X{pack}} -.. |externval| mathdef:: \xref{exec/runtime}{syntax-externval}{\X{externval}} +.. |externaddr| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\X{externaddr}} .. |moduleinst| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\X{moduleinst}} .. |funccode| mathdef:: \xref{exec/runtime}{syntax-funcinst}{\X{code}} @@ -1423,21 +1482,24 @@ .. |tableinst| mathdef:: \xref{exec/runtime}{syntax-tableinst}{\X{tableinst}} .. |meminst| mathdef:: \xref{exec/runtime}{syntax-meminst}{\X{meminst}} .. |globalinst| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\X{globalinst}} +.. |taginst| mathdef:: \xref{exec/runtime}{syntax-taginst}{\X{taginst}} .. |eleminst| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\X{eleminst}} .. |datainst| mathdef:: \xref{exec/runtime}{syntax-datainst}{\X{datainst}} .. |structinst| mathdef:: \xref{exec/runtime}{syntax-structinst}{\X{structinst}} .. |arrayinst| mathdef:: \xref{exec/runtime}{syntax-arrayinst}{\X{arrayinst}} .. |exportinst| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\X{exportinst}} +.. |exninst| mathdef:: \xref{exec/runtime}{syntax-exninst}{\X{exninst}} .. |hostfunc| mathdef:: \xref{exec/runtime}{syntax-hostfunc}{\X{hostfunc}} .. Instances, meta functions -.. |funcsxv| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{funcs}} -.. |tablesxv| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{tables}} -.. |memsxv| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{mems}} -.. |globalsxv| mathdef:: \xref{exec/runtime}{syntax-externval}{\F{globals}} +.. |funcsxa| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\F{funcs}} +.. |tablesxa| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\F{tables}} +.. |memsxa| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\F{mems}} +.. |globalsxa| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\F{globals}} +.. |tagsxa| mathdef:: \xref{exec/runtime}{syntax-externaddr}{\F{tags}} .. Store, terminals @@ -1445,11 +1507,13 @@ .. |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}} .. |SSTRUCTS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{structs}} .. |SARRAYS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{arrays}} +.. |SEXNS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{exns}} .. Store, non-terminals @@ -1461,6 +1525,7 @@ .. |LABEL| mathdef:: \xref{exec/runtime}{syntax-label}{\K{label}} .. |FRAME| mathdef:: \xref{exec/runtime}{syntax-frame}{\K{frame}} +.. |HANDLER| mathdef:: \xref{exec/runtime}{syntax-handler}{\K{handler}} .. |ALOCALS| mathdef:: \xref{exec/runtime}{syntax-frame}{\K{locals}} .. |AMODULE| mathdef:: \xref{exec/runtime}{syntax-frame}{\K{module}} @@ -1469,6 +1534,7 @@ .. Stack, non-terminals .. |label| mathdef:: \xref{exec/runtime}{syntax-label}{\X{label}} +.. |handler| mathdef:: \xref{exec/runtime}{syntax-handler}{\X{handler}} .. |frame| mathdef:: \xref{exec/runtime}{syntax-frame}{\X{frame}} .. |callframe| mathdef:: \xref{exec/runtime}{syntax-callframe}{\X{callframe}} @@ -1484,6 +1550,7 @@ .. |REFFUNCADDR| mathdef:: \xref{exec/runtime}{syntax-ref}{\K{ref{.}func}} .. |REFSTRUCTADDR| mathdef:: \xref{exec/runtime}{syntax-ref}{\K{ref{.}struct}} .. |REFARRAYADDR| mathdef:: \xref{exec/runtime}{syntax-ref}{\K{ref{.}array}} +.. |REFEXNADDR| mathdef:: \xref{exec/runtime}{syntax-ref}{\K{ref{.}exn}} .. |REFHOSTADDR| mathdef:: \xref{exec/runtime}{syntax-ref}{\K{ref{.}host}} .. |REFEXTERN| mathdef:: \xref{exec/runtime}{syntax-ref}{\K{ref{.}extern}} .. |TRAP| mathdef:: \xref{exec/runtime}{syntax-trap}{\K{trap}} @@ -1661,7 +1728,7 @@ .. Judgements -.. |vdashexternval| mathdef:: \xref{exec/values}{valid-externval}{\vdash} +.. |vdashexternaddr| mathdef:: \xref{exec/values}{valid-externaddr}{\vdash} .. Soundness @@ -1680,16 +1747,20 @@ .. |vdashtableinst| mathdef:: \xref{appendix/properties}{valid-tableinst}{\vdash} .. |vdashmeminst| mathdef:: \xref{appendix/properties}{valid-meminst}{\vdash} .. |vdashglobalinst| mathdef:: \xref{appendix/properties}{valid-globalinst}{\vdash} +.. |vdashtaginst| mathdef:: \xref{appendix/properties}{valid-taginst}{\vdash} .. |vdasheleminst| mathdef:: \xref{appendix/properties}{valid-eleminst}{\vdash} .. |vdashdatainst| mathdef:: \xref{appendix/properties}{valid-datainst}{\vdash} .. |vdashstructinst| mathdef:: \xref{appendix/properties}{valid-structinst}{\vdash} .. |vdasharrayinst| mathdef:: \xref{appendix/properties}{valid-arrayinst}{\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} +.. |OKtaginst| mathdef:: \xref{appendix/properties}{valid-taginst}{\K{ok}} .. |OKdatainst| mathdef:: \xref{appendix/properties}{valid-datainst}{\K{ok}} .. |OKstructinst| mathdef:: \xref{appendix/properties}{valid-structinst}{\K{ok}} .. |OKarrayinst| mathdef:: \xref{appendix/properties}{valid-arrayinst}{\K{ok}} +.. |OKexninst| mathdef:: \xref{appendix/properties}{valid-exninst}{\K{ok}} .. |OKexportinst| mathdef:: \xref{appendix/properties}{valid-exportinst}{\K{ok}} .. |vdashcontext| mathdef:: \xref{appendix/properties}{valid-context}{\vdash} @@ -1704,10 +1775,12 @@ .. |vdashtableinstextends| mathdef:: \xref{appendix/properties}{extend-tableinst}{\vdash} .. |vdashmeminstextends| mathdef:: \xref{appendix/properties}{extend-meminst}{\vdash} .. |vdashglobalinstextends| mathdef:: \xref{appendix/properties}{extend-globalinst}{\vdash} +.. |vdashtaginstextends| mathdef:: \xref{appendix/properties}{extend-taginst}{\vdash} .. |vdasheleminstextends| mathdef:: \xref{appendix/properties}{extend-eleminst}{\vdash} .. |vdashdatainstextends| mathdef:: \xref{appendix/properties}{extend-datainst}{\vdash} .. |vdashstructinstextends| mathdef:: \xref{appendix/properties}{extend-structinst}{\vdash} .. |vdasharrayinstextends| mathdef:: \xref{appendix/properties}{extend-arrayinst}{\vdash} +.. |vdashexninstextends| mathdef:: \xref{appendix/properties}{extend-exninst}{\vdash} .. |vdashstoreextends| mathdef:: \xref{appendix/properties}{extend-store}{\vdash} @@ -1727,6 +1800,7 @@ .. |Bmodulenamesubsec| mathdef:: \xref{appendix/custom}{binary-modulenamesec}{\B{modulenamesubsec}} .. |Bfuncnamesubsec| mathdef:: \xref{appendix/custom}{binary-funcnamesec}{\B{funcnamesubsec}} +.. |Btagnamesubsec| mathdef:: \xref{appendix/custom}{binary-tagnamesec}{\B{tagnamesubsec}} .. |Blocalnamesubsec| mathdef:: \xref{appendix/custom}{binary-localnamesec}{\B{localnamesubsec}} .. |Btypenamesubsec| mathdef:: \xref{appendix/custom}{binary-typenamesec}{\B{typenamesubsec}} .. |Bfieldnamesubsec| mathdef:: \xref{appendix/custom}{binary-fieldnamesec}{\B{fieldnamesubsec}} @@ -1751,6 +1825,7 @@ .. |Tlocalnameannot| mathdef:: \xref{appendix/custom}{text-localnameannot}{\T{localnameannot}} .. |Ttypenameannot| mathdef:: \xref{appendix/custom}{text-typenameannot}{\T{typenameannot}} .. |Tfieldnameannot| mathdef:: \xref{appendix/custom}{text-fieldnameannot}{\T{fieldnameannot}} +.. |Ttagnameannot| mathdef:: \xref{appendix/custom}{text-tagnameannot}{\T{tagnameannot}} .. Embedding @@ -1762,3 +1837,5 @@ .. |error| mathdef:: \xref{appendix/embedding}{embed-error}{\X{error}} .. |ERROR| mathdef:: \xref{appendix/embedding}{embed-error}{\K{error}} +.. |exception| mathdef:: \xref{appendix/embedding}{embed-error}{\X{exception}} +.. |EXCEPTION| mathdef:: \xref{appendix/embedding}{embed-error}{\K{exception}} diff --git a/document/core/valid/conventions.rst b/document/core/valid/conventions.rst index 822ede5174..ebad23bb7b 100644 --- a/document/core/valid/conventions.rst +++ b/document/core/valid/conventions.rst @@ -1,4 +1,4 @@ -.. index:: ! validation, ! type system, function type, table type, memory type, globaltype, valtype, resulttype, index space, instantiation. module +.. index:: ! validation, ! type system, function type, table type, memory type, global type, tag type, value type, result type, index space, instantiation. module .. _type-system: Conventions @@ -199,7 +199,7 @@ $${syntax: {localtype init}} they do not occur in programs. -.. index:: ! context, local type, function type, table type, memory type, global type, value type, result type, index space, module, function, local type +.. index:: ! context, local type, function type, table type, memory type, global type, tag type, local type, value type, result type, index space, module, function, table, memory, global, tag .. _context: Contexts @@ -214,6 +214,7 @@ which collects relevant information about the surrounding :ref:`module ` declared in the current module, represented by their :ref:`table type `. * *Memories*: the list of :ref:`memories ` declared in the current module, represented by their :ref:`memory type `. * *Globals*: the list of :ref:`globals ` declared in the current module, represented by their :ref:`global type `. +* *Tags*: the list of tags declared in the current module, represented by their :ref:`tag type `. * *Element Segments*: the list of :ref:`element segments ` declared in the current module, represented by the elements' :ref:`reference type `. * *Data Segments*: the list of :ref:`data segments ` declared in the current module, each represented by an ${datatype: OK} entry. * *Locals*: the list of :ref:`locals ` declared in the current :ref:`function ` (including parameters), represented by their :ref:`local type `. diff --git a/document/core/valid/instructions.rst b/document/core/valid/instructions.rst index 721f7db5ab..37b810b20b 100644 --- a/document/core/valid/instructions.rst +++ b/document/core/valid/instructions.rst @@ -1368,7 +1368,7 @@ $${rule: Instr_ok/memory.init} $${rule: Instr_ok/data.drop} -.. index:: control instructions, structured control, label, block, branch, block type, label index, function index, type index, list, polymorphism, context +.. index:: control instructions, structured control, label, block, branch, block type, label index, result type, function index, type index, tag index, list, polymorphism, context pair: validation; instruction single: abstract syntax; instruction .. _valid-label: @@ -1395,6 +1395,7 @@ $${rule: Instr_ok/block} .. note:: The :ref:`notation ` ${context: {LABELS (t*)} ++ C} inserts the new label type at index ${:0}, shifting all others. + The same applies to all other block instructions. .. _valid-loop: @@ -1413,9 +1414,6 @@ $${rule: Instr_ok/block} $${rule: Instr_ok/loop} -.. note:: - The :ref:`notation ` ${context: {LABELS (t*)} ++ C} inserts the new label type at index ${:0}, shifting all others. - .. _valid-if: @@ -1436,8 +1434,86 @@ $${rule: Instr_ok/loop} $${rule: Instr_ok/if} -.. note:: - The :ref:`notation ` ${context: {LABELS (t*)} ++ C} inserts the new label type at index ${:0}, shifting all others. + + +.. _valid-try_table: + +:math:`\TRYTABLE~\blocktype~\catch^\ast~\instr^\ast~\END` +......................................................... + +* The :ref:`block type ` must be :ref:`valid ` as some :ref:`function type ` :math:`[t_1^\ast] \to [t_2^\ast]`. + +* For every :ref:`catch clause ` :math:`\catch_i` in :math:`\catch^\ast`, :math:`\catch_i` must be :ref:`valid `. + +* 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]`. + + +.. _valid-catch: + +:math:`\CATCH~x~l` +.................. + +* The tag :math:`C.\CTAGS[x]` must be defined in the context. + +* Let :math:`[t^\ast] \to [{t'}^\ast]` be the :ref:`tag type ` :math:`C.\CTAGS[x]`. + +* The :ref:`result type ` :math:`[{t'}^\ast]` must be empty. + +* The label :math:`C.\CLABELS[l]` must be defined in the context. + +* The :ref:`result type ` :math:`[t^\ast]` must :ref:`match ` :math:`C.\CLABELS[l]`. + +* Then the catch clause is valid. + +$${rule: Catch_ok/catch} + + +:math:`\CATCHREF~x~l` +..................... + +* The tag :math:`C.\CTAGS[x]` must be defined in the context. + +* Let :math:`[t^\ast] \to [{t'}^\ast]` be the :ref:`tag type ` :math:`C.\CTAGS[x]`. + +* The :ref:`result type ` :math:`[{t'}^\ast]` must be empty. + +* The label :math:`C.\CLABELS[l]` must be defined in the context. + +* The :ref:`result type ` :math:`[t^\ast (REF EXN)]` must :ref:`match ` :math:`C.\CLABELS[l]`. + +* Then the catch clause is valid. + +$${rule: Catch_ok/catch_ref} + + +:math:`\CATCHALL~l` +................... + +* The label :math:`C.\CLABELS[l]` must be defined in the context. + +* The :ref:`result type ` :math:`C.\CLABELS[l]` must be empty. + +* Then the catch clause is valid. + +$${rule: Catch_ok/catch_all} + + +:math:`\CATCHALLREF~l` +...................... + +* The label :math:`C.\CLABELS[l]` must be defined in the context. + +* The :ref:`result type ` :math:`[(REF EXN)]` must :ref:`match ` :math:`C.\CLABELS[l]`. + +* Then the catch clause is valid. + +$${rule: Catch_ok/catch_all_ref} + .. _valid-br: @@ -1454,7 +1530,8 @@ $${rule: Instr_ok/if} $${rule: Instr_ok/br} .. note:: - The :ref:`label index ` space in the :ref:`context ` ${:C} contains the most recent label first, so that ${:C.LABEL[l]} performs a relative lookup as expected. + The :ref:`label index ` space in the :ref:`context ` ${:C} contains the most recent label first, so that ${:C.LABELS[l]} performs a relative lookup as expected. + This applies to other branch instructions as well. The ${:BR} instruction is :ref:`stack-polymorphic `. @@ -1472,9 +1549,6 @@ $${rule: Instr_ok/br} $${rule: Instr_ok/br_if} -.. note:: - The :ref:`label index ` space in the :ref:`context ` ${:C} contains the most recent label first, so that ${:C.LABEL[l]} performs a relative lookup as expected. - .. _valid-br_table: @@ -1498,8 +1572,6 @@ $${rule: Instr_ok/br_if} $${rule: Instr_ok/br_table} .. note:: - The :ref:`label index ` space in the :ref:`context ` ${:C} contains the most recent label first, so that ${:C.LABEL[l]} performs a relative lookup as expected. - The ${:BR_TABLE} instruction is :ref:`stack-polymorphic `. Furthermore, the :ref:`result type ` ${:t*} is also chosen non-deterministically in this rule. @@ -1729,6 +1801,38 @@ $${rule: Instr_ok/return_call_indirect} The ${:RETURN_CALL_INDIRECT} instruction is :ref:`stack-polymorphic `. +.. _valid-throw: + +:math:`\THROW~x` +................ + +* The tag :math:`C.\CTAGS[x]` must be defined in the context. + +* Let :math:`[t^\ast] \to [{t'}^\ast]` be the :ref:`tag type ` :math:`C.\CTAGS[x]`. + +* The :ref:`result type ` :math:`[{t'}^\ast]` must be empty. + +* Then the instruction is valid with type :math:`[t_1^\ast t^\ast] \to [t_2^\ast]`, for any sequences of :ref:`value types ` :math:`t_1^\ast` and :math:`t_2^\ast`. + +$${rule: Instr_ok/throw} + +.. note:: + The ${:THROW} instruction is :ref:`stack-polymorphic `. + + +.. _valid-throw_ref: + +:math:`\THROWREF` +................. + +* The instruction is valid with type :math:`[t_1^\ast~\EXNREF] \to [t_2^\ast]`, for any sequences of :ref:`value types ` :math:`t_1^\ast` and :math:`t_2^\ast`. + +$${rule: Instr_ok/throw} + +.. note:: + The ${:THROW_REF} instruction is :ref:`stack-polymorphic `. + + .. index:: instruction, instruction sequence, local type .. _valid-instrs: diff --git a/document/core/valid/matching.rst b/document/core/valid/matching.rst index c9012be26c..0ed9aa2ae5 100644 --- a/document/core/valid/matching.rst +++ b/document/core/valid/matching.rst @@ -324,6 +324,19 @@ A :ref:`global type ` ${globaltype: (mut1 valtype_1)} matches $${rule: {Globaltype_sub/*}} +.. index:: tag type +.. _match-tagtype: + +Tag Types +~~~~~~~~~ + +A :ref:`tag type ` ${tagtype: deftype_1} matches ${tagtype: deftype_2} if and only if: + +* :ref:`Defined type ` :math:`\deftype_1` :ref:`matches ` :math:`\deftype_2` and vice versa. + +$${rule: {Tagtype_sub}} + + .. index:: external type, function type, table type, memory type, global type .. _match-externtype: @@ -368,3 +381,13 @@ An :ref:`external type ` ${externtype: GLOBAL globaltype_1} m * Global type :math:`\globaltype_1` :ref:`matches ` :math:`\globaltype_2`. $${rule: Externtype_sub/global} + + +Tags +.... + +An :ref:`external type ` ${externtype: TAG tagtype_1} matches ${externtype: TAG tagtype_2} if and only if: + +* Tag type :math:`\tagtype_1` :ref:`matches ` :math:`\tagtype_2`. + +$${rule: Externtype_sub/tag} diff --git a/document/core/valid/modules.rst b/document/core/valid/modules.rst index c14ec6e089..a0a479c040 100644 --- a/document/core/valid/modules.rst +++ b/document/core/valid/modules.rst @@ -212,6 +212,29 @@ $${rule: Global_ok} $${rule: {Globals_ok/*}} +.. index:: tag, tag type, function type, exception tag + pair: validation; tag + single: abstract syntax; tag +.. _valid-tag: + +Tags +~~~~ + +Tags :math:`\tag` are classified by their :ref:`tag type `, +each containing an index to a :ref:`function type ` with empty result. + +:math:`\{ \TAGTYPE~x \}` +........................ + +* The type :math:`C.\CTYPES[x]` must be defined in the context. + +* Let :math:`[t_1^\ast] \to [t_2^\ast]` be the :ref:`function type ` :math:`C.\CTYPES[x]`. + +* Then the tag definition is valid with :ref:`tag type ` :math:`[t_1^\ast]\to[t_2^\ast]`. + +$${rule: Tag_ok} + + .. index:: element, table, table index, expression, constant, function index pair: validation; element single: abstract syntax; element @@ -229,7 +252,7 @@ Element segments ${:elem} are classified by the :ref:`reference type ` :math:`t` must be :ref:`valid `. -* For each :math:`e_i` in :math:`e^\ast`, +* For each :math:`e_i` in :math:`e^\ast`: * The expression :math:`e_i` must be :ref:`valid ` with some :ref:`result type ` :math:`[t]`. @@ -345,7 +368,7 @@ Start function declarations ${:start} are not classified by any type. $${rule: Start_ok} -.. index:: export, name, index, function index, table index, memory index, global index +.. index:: export, name, index, function index, table index, memory index, global index, tag index pair: validation; export single: abstract syntax; export .. _valid-exportdesc: @@ -358,7 +381,7 @@ Exports Exports ${:export} are classified by their :ref:`external type `. -:math:`\{ \ENAME~\name, \EDESC~\exportdesc \}` +:math:`\{ \XNAME~\name, \XDESC~\exportdesc \}` .............................................. * The export description :math:`\exportdesc` must be valid with :ref:`external type ` :math:`\externtype`. @@ -368,50 +391,60 @@ Exports ${:export} are classified by their :ref:`external type ` :math:`C.\CFUNCS[x]`. -* Then the export description is valid with :ref:`external type ` :math:`\ETFUNC~\X{dt}`. +* Then the export description is valid with :ref:`external type ` :math:`\XTFUNC~\X{dt}`. $${rule: Externidx_ok/func} -:math:`\EDTABLE~x` +:math:`\XDTABLE~x` .................. * The table :math:`C.\CTABLES[x]` must be defined in the context. -* Then the export description is valid with :ref:`external type ` :math:`\ETTABLE~C.\CTABLES[x]`. +* Then the export description is valid with :ref:`external type ` :math:`\XTTABLE~C.\CTABLES[x]`. $${rule: Externidx_ok/table} -:math:`\EDMEM~x` +:math:`\XDMEM~x` ................ * The memory :math:`C.\CMEMS[x]` must be defined in the context. -* Then the export description is valid with :ref:`external type ` :math:`\ETMEM~C.\CMEMS[x]`. +* Then the export description is valid with :ref:`external type ` :math:`\XTMEM~C.\CMEMS[x]`. $${rule: Externidx_ok/mem} -:math:`\EDGLOBAL~x` +:math:`\XDGLOBAL~x` ................... * The global :math:`C.\CGLOBALS[x]` must be defined in the context. -* Then the export description is valid with :ref:`external type ` :math:`\ETGLOBAL~C.\CGLOBALS[x]`. +* Then the export description is valid with :ref:`external type ` :math:`\XTGLOBAL~C.\CGLOBALS[x]`. $${rule: Externidx_ok/global} -.. index:: import, name, function type, table type, memory type, global type +:math:`\XDTAG~x` +................ + +* The tag :math:`C.\CTAGS[x]` must be defined in the context. + +* Then the export description is valid with :ref:`external type ` :math:`\XTTAG~C.\CTAGS[x]`. + +$${rule: Externidx_ok/tag} + + +.. index:: import, name, function type, table type, memory type, global type, tag type pair: validation; import single: abstract syntax; import .. _valid-importdesc: @@ -433,7 +466,7 @@ Imports ${:import} are classified by :ref:`external types `. $${rule: Import_ok} -.. index:: module, type definition, function type, function, table, memory, global, element, data, start function, import, export, context +.. index:: module, type definition, function type, function, table, memory, global, tag, element, data, start function, import, export, context pair: validation; module single: abstract syntax; module .. _valid-module: @@ -472,6 +505,9 @@ The :ref:`external types ` classifying a module may contain f * :math:`C.\CGLOBALS` is :math:`\globalsxt(\X{it}^\ast)` concatenated with :math:`\X{gt}^\ast`, with the import's :ref:`external types ` :math:`\X{it}^\ast` and the internal :ref:`global types ` :math:`\X{gt}^\ast` as determined below, + * :math:`C.\CTAGS` is :math:`\tagsxt(\X{it}^\ast)` concatenated with :math:`\X{ht}^\ast`, + with the import's :ref:`external types ` :math:`\X{it}^\ast` and the internal :ref:`tag types ` :math:`\X{ht}^\ast` as determined below, + * :math:`C.\CELEMS` is :math:`{\X{rt}}^\ast` as determined below, * :math:`C.\CDATAS` is :math:`{\X{ok}}^\ast` as determined below, @@ -515,6 +551,9 @@ The :ref:`external types ` classifying a module may contain f * For each :math:`\func_i` in :math:`\module.\MFUNCS`, the definition :math:`\func_i` must be :ref:`valid ` with a :ref:`defined type ` :math:`\X{dt}_i`. + * For each :math:`\tag_i` in :math:`\module.\MTAGS`, + the definition :math:`\tag_i` must be :ref:`valid ` with a :ref:`tag type ` :math:`\X{ht}_i`. + * For each :math:`\elem_i` in :math:`\module.\MELEMS`, the segment :math:`\elem_i` must be :ref:`valid ` with :ref:`reference type ` :math:`\X{rt}_i`. @@ -536,6 +575,10 @@ The :ref:`external types ` classifying a module may contain f * Let :math:`\X{mt}^\ast` be the concatenation of the internal :ref:`memory types ` :math:`\X{mt}_i`, in index order. +* Let :math:`\X{gt}^\ast` be the concatenation of the internal :ref:`global types ` :math:`\X{gt}_i`, in index order. + +* Let :math:`\X{ht}^\ast` be the concatenation of the internal :ref:`tag types ` :math:`\X{ht}_i`, in index order. + * Let :math:`\X{rt}^\ast` be the concatenation of the :ref:`reference types ` :math:`\X{rt}_i`, in index order. * Let :math:`\X{ok}^\ast` be the concatenation of the :ref:`data types ` :math:`\X{ok}_i`, in index order. @@ -546,7 +589,7 @@ The :ref:`external types ` classifying a module may contain f * The length of :math:`C.\CMEMS` must not be larger than :math:`1`. -* All export names :math:`\export_i.\ENAME` must be different. +* All export names :math:`\export_i.\XNAME` must be different. * Then the module is valid with :ref:`external types ` :math:`\X{it}^\ast \to \X{et}^\ast`. @@ -563,6 +606,3 @@ $${rule: Module_ok} All types needed to construct ${:C} can easily be determined from a simple pre-pass over the module that does not perform any actual validation. Globals, however, are not recursive but evaluated sequentially, such that each :ref:`constant expressions ` only has access to imported or previously defined globals. - -.. note:: - The restriction on the number of memories may be lifted in future versions of WebAssembly. diff --git a/document/core/valid/types.rst b/document/core/valid/types.rst index 03f199b026..10bd77f0da 100644 --- a/document/core/valid/types.rst +++ b/document/core/valid/types.rst @@ -410,6 +410,26 @@ Memory Types $${rule: Memtype_ok} +.. index:: tag type, function type, exception tag + pair: validation; tag type + single: abstract syntax; tag type +.. _valid-tagtype: + +Tag Types +~~~~~~~~~ + +:math:`[t_1^n] \to [t_2^m]` +........................... + +* The :ref:`function type ` :math:`[t_1^n] \to [t_2^m]` must be :ref:`valid `. + +* The type sequence :math:`t_2^m` must be empty. + +* Then the tag type is valid. + +$${rule: Tagtype_ok} + + .. index:: global type, value type, mutability pair: validation; global type single: abstract syntax; global type @@ -436,7 +456,7 @@ $${rule: Globaltype_ok} External Types ~~~~~~~~~~~~~~ -:math:`\ETFUNC~\deftype` +:math:`\XTFUNC~\deftype` ........................ * The :ref:`defined type ` :math:`\deftype` must be :ref:`valid `. @@ -448,7 +468,7 @@ External Types $${rule: Externtype_ok/func} -:math:`\ETTABLE~\tabletype` +:math:`\XTTABLE~\tabletype` ........................... * The :ref:`table type ` :math:`\tabletype` must be :ref:`valid `. @@ -458,7 +478,7 @@ $${rule: Externtype_ok/func} $${rule: Externtype_ok/table} -:math:`\ETMEM~\memtype` +:math:`\XTMEM~\memtype` ....................... * The :ref:`memory type ` :math:`\memtype` must be :ref:`valid `. @@ -468,7 +488,17 @@ $${rule: Externtype_ok/table} $${rule: Externtype_ok/mem} -:math:`\ETGLOBAL~\globaltype` +:math:`\XTTAG~\tagtype` +....................... + +* The :ref:`tag type ` :math:`\tagtype` must be :ref:`valid `. + +* Then the external type is valid. + +$${rule: Externtype_ok/tag} + + +:math:`\XTGLOBAL~\globaltype` ............................. * The :ref:`global type ` :math:`\globaltype` must be :ref:`valid `. diff --git a/document/index.html b/document/index.html index 37eed9762e..f7661d8bec 100644 --- a/document/index.html +++ b/document/index.html @@ -49,21 +49,56 @@

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.

+

Metadata specifications

+ +

Define the format and semantics of extra information attached to a WebAssembly module

+ + + +

Legacy Extensions

+ +

Define extensions that are deprecated, but may still be in use.

+ +
    +
  • Legacy Exception Handling: defines additional instructions for exception handling that may still be available in some engines and tools, specifically web browsers.

    + +
  • +
+

- Source for these documents is available + Source for all documents is available here.

diff --git a/document/js-api/index.bs b/document/js-api/index.bs index bde4698862..dd790f819c 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -89,6 +89,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: ref.func text: ref.host text: ref.extern + text: ref.exn text: function index; url: syntax/modules.html#syntax-funcidx text: function instance; url: exec/runtime.html#function-instances text: store_init; url: appendix/embedding.html#embed-store-init @@ -127,11 +128,19 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: function address; url: exec/runtime.html#syntax-funcaddr text: memory address; url: exec/runtime.html#syntax-memaddr text: global address; url: exec/runtime.html#syntax-globaladdr + text: tag address; url: exec/runtime.html#syntax-tagaddr + text: tag type; url: syntax/types.html#syntax-tagtype text: struct address; url: exec/runtime.html#syntax-structaddr text: array address; url: exec/runtime.html#syntax-arrayaddr + text: exception address; url: exec/runtime.html#syntax-exnaddr text: host address; url: exec/runtime.html#syntax-hostaddr text: extern address; url: exec/runtime.html#syntax-externaddr text: page size; url: exec/runtime.html#page-size + text: tag_alloc; url: appendix/embedding.html#embed-tag-alloc + text: tag_type; url: appendix/embedding.html#embed-tag-type + text: exn_alloc; url: appendix/embedding.html#embed-exn-alloc + text: exn_tag; url: appendix/embedding.html#embed-exn-tag + text: exn_read; url: appendix/embedding.html#embed-exn-read url: syntax/types.html#syntax-numtype text: i32 text: i64 @@ -142,6 +151,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df url: syntax/types.html#syntax-reftype text: reftype text: funcref + text: exnref text: externref text: ref url: syntax/types.html#heap-types; for: heap-type @@ -157,7 +167,10 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: signif text: function element; url: exec/runtime.html#syntax-funcelem text: import component; url: syntax/modules.html#imports - text: external value; url: exec/runtime.html#syntax-externval + url: exec/runtime.html#syntax-externval + text: external value + for: external value + text: tag text: host function; url: exec/runtime.html#syntax-hostfunc text: the instantiation algorithm; url: exec/modules.html#instantiation text: module; url: syntax/modules.html#syntax-module @@ -169,6 +182,8 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: table text: mem text: global + for: externtype + text: tag text: global type; url: syntax/types.html#syntax-globaltype url: syntax/types.html#syntax-mut text: var @@ -177,14 +192,18 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: signed_31; url: exec/numerics.html#aux-signed text: signed_32; url: exec/numerics.html#aux-signed text: memory.grow; url: exec/instructions.html#exec-memory-grow + text: throw_ref; url: exec/instructions.html#exec-throw-ref text: current frame; url: exec/conventions.html#exec-notation-textual text: module; for: frame; url: exec/runtime.html#syntax-frame text: memaddrs; for: moduleinst; url: exec/runtime.html#syntax-moduleinst text: signed_64; url: exec/numerics.html#aux-signed text: sequence; url: syntax/conventions.html#grammar-notation + text: exception; for: tagtype/attribute; url: syntax/types.html#syntax-tagtype urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL type: dfn text: create a namespace object; url: create-a-namespace-object +urlPrefix: https://webassembly.github.io/js-types/js-api/; spec: WebAssembly JS API (JS Type Reflection) + type: abstract-op; text: FromValueType; url: abstract-opdef-fromvaluetype urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal type: dfn text: handled; url: sec-hostresizearraybuffer @@ -272,8 +291,11 @@ Each [=agent=] is associated with the following [=ordered map=]s: * The Exported Function cache, mapping [=function address=]es to [=Exported Function=] objects. * The Exported GC Object cache, mapping [=struct address=]es and [=array address=]es to [=Exported GC Object=] objects. * The Global object cache, mapping [=global address=]es to {{Global}} objects. + * The Tag object cache, mapping [=tag addresses=] to {{Tag}} objects. + * The Exception object cache, mapping [=exception address=]es to {{Exception}} objects. * The Host value cache, mapping [=host address=]es to values. +

The WebAssembly Namespace

@@ -292,6 +314,8 @@ namespace WebAssembly {
 
     Promise<Instance> instantiate(
         Module moduleObject, optional object importObject);
+
+    readonly attribute Tag JSTag;
 };
 
@@ -396,6 +420,12 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. Let |tableaddr| be |v|.\[[Table]]. 1. Let |externtable| be the [=external value=] [=external value|table=] |tableaddr|. 1. [=list/Append=] |externtable| to |imports|. + 1. If |externtype| is of the form [=externtype/tag=] |attribute| functype, + 1. Assert: |attribute| is [=tagtype/attribute/exception=]. + 1. If |v| does not [=implement=] {{Tag}}, throw a {{LinkError}} exception. + 1. Let |tagaddr| be |v|.\[[Address]]. + 1. Let |externtag| be the [=external value=] [=external value/tag=] |tagaddr|. + 1. [=list/Append=] |externtag| to |imports|. 1. Return |imports|. Note: This algorithm only verifies the right kind of JavaScript values are passed. @@ -429,6 +459,12 @@ The verification of WebAssembly type requirements is deferred to the 1. Let [=external value|table=] |tableaddr| be |externval|. 1. Let |table| be [=create a Table object|a new Table object=] created from |tableaddr|. 1. Let |value| be |table|. + 1. If |externtype| is of the form [=externtype/tag=] |attribute| functype, + 1. Assert: |attribute| is [=tagtype/attribute/exception=]. + 1. Assert: |externval| is of the form [=external value/tag=] |tagaddr|. + 1. Let [=external value/tag=] |tagaddr| be |externval|. + 1. Let |tag| be [=create a Tag object|a new Tag object=] created from |tagaddr|. + 1. Let |value| be |tag|. 1. Let |status| be [=!=] [$CreateDataProperty$](|exportsObject|, |name|, |value|). 1. Assert: |status| is true. @@ -506,6 +542,11 @@ The verification of WebAssembly type requirements is deferred to the Note: A follow-on streaming API is documented in the WebAssembly Web API. +The getter of the JSTag attribute of the {{WebAssembly}} Namespace, when invoked, performs the following steps: + 1. Let |JSTagAddr| be the result of [=get the JavaScript exception tag|getting the JavaScript exception tag=]. + 1. Let |JSTagObject| be the result of [=create a Tag object|creating a Tag object=] from |JSTagAddr|. + 1. Return |JSTagObject|. +

Modules

@@ -513,7 +554,8 @@ enum ImportExportKind {
   "function",
   "table",
   "memory",
-  "global"
+  "global",
+  "tag"
 };
 
 dictionary ModuleExportDescriptor {
@@ -543,6 +585,7 @@ interface Module {
     * "table" if |type| is of the form [=table=] tabletype
     * "memory" if |type| is of the form [=mem=] memtype
     * "global" if |type| is of the form [=global=] globaltype
+    * "tag" if |type| is of the form [=externtype/tag=] tag
 
 
 
@@ -848,7 +891,7 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address The Table(|descriptor|, |value|) constructor, when invoked, performs the following steps: 1. Let |elementType| be [=ToValueType=](|descriptor|["element"]). 1. If |elementType| is not a [=reftype=], - 1. [=Throw=] a {{TypeError}} exception. + 1. Throw a {{TypeError}} exception. 1. Let |initial| be |descriptor|["initial"]. 1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. @@ -895,6 +938,9 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address The get(|index|) method, when invoked, performs the following steps: 1. Let |tableaddr| be **this**.\[[Table]]. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let (limits, |elementType|) be [=table_type=](|store|, |tableaddr|). + 1. If |elementType| is [=exnref=], + 1. Throw a {{TypeError}} exception. 1. Let |result| be [=table_read=](|store|, |tableaddr|, |index|). 1. If |result| is [=error=], throw a {{RangeError}} exception. 1. Return [=ToJSValue=](|result|). @@ -903,7 +949,10 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address
The set(|index|, |value|) method, when invoked, performs the following steps: 1. Let |tableaddr| be **this**.\[[Table]]. - 1. Let (limits, |elementType|) be [=table_type=](|tableaddr|). + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let (limits, |elementType|) be [=table_type=](|store|, |tableaddr|). + 1. If |elementType| is [=exnref=], + 1. Throw a {{TypeError}} exception. 1. If |value| is missing, 1. Let |ref| be [=DefaultValue=](|elementType|). 1. If |ref| is [=error=], throw a {{TypeError}} exception. @@ -991,7 +1040,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each The Global(|descriptor|, |v|) constructor, when invoked, performs the following steps: 1. Let |mutable| be |descriptor|["mutable"]. 1. Let |valuetype| be [=ToValueType=](|descriptor|["value"]). - 1. If |valuetype| is [=v128=], + 1. If |valuetype| is [=v128=] or [=exnref=], 1. Throw a {{TypeError}} exception. 1. If |v| is missing, 1. Let |value| be [=DefaultValue=](|valuetype|). @@ -1010,7 +1059,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. Let |store| be the current agent's [=associated store=]. 1. Let |globaladdr| be |global|.\[[Global]]. 1. Let |globaltype| be [=global_type=](|store|, |globaladdr|). - 1. If |globaltype| is of the form mut [=v128=], throw a {{TypeError}}. + 1. If |globaltype| is of the form mut |valuetype| where |valuetype| is [=v128=] or [=exnref=], throw a {{TypeError}}. 1. Let |value| be [=global_read=](|store|, |globaladdr|). 1. Return [=ToJSValue=](|value|).
@@ -1023,7 +1072,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. Let |store| be the current agent's [=associated store=]. 1. Let |globaladdr| be **this**.\[[Global]]. 1. Let |mut| |valuetype| be [=global_type=](|store|, |globaladdr|). - 1. If |valuetype| is [=v128=], throw a {{TypeError}}. + 1. If |valuetype| is [=v128=] or [=exnref=], throw a {{TypeError}}. 1. If |mut| is [=const=], throw a {{TypeError}}. 1. Let |value| be [=ToWebAssemblyValue=](**the given value**, |valuetype|). 1. Let |store| be [=global_write=](|store|, |globaladdr|, |value|). @@ -1082,7 +1131,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [ 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let |functype| be [=func_type=](|store|, |funcaddr|). 1. Let [|parameters|] → [|results|] be |functype|. - 1. If |parameters| or |results| contain [=v128=], throw a {{TypeError}}. + 1. If |parameters| or |results| contain [=v128=] or [=exnref=], throw a {{TypeError}}. Note: the above error is thrown each time the \[[Call]] method is invoked. 1. Let |args| be « ». @@ -1095,6 +1144,15 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [ 1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. 1. If |ret| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by the WebAssembly error mapping. + 1. If |ret| is [=THROW=] [=ref.exn=] |exnaddr|, then + 1. Let |tagaddr| be [=exn_tag=](|store|, |exnaddr|). + 1. Let |payload| be [=exn_read=](|store|, |exnaddr|). + 1. Let |jsTagAddr| be the result of [=get the JavaScript exception tag |getting the JavaScript exception tag=]. + 1. If |tagaddr| is equal to |jsTagAddr|, + 1. Throw the result of [=retrieving an extern value=] from |payload|[0]. + 1. Otherwise, + 1. Let |exception| be [=create an Exception object|a new Exception=] created from |exnaddr|. + 1. Throw |exception|. 1. Let |outArity| be the [=list/size=] of |ret|. 1. If |outArity| is 0, return undefined. 1. Otherwise, if |outArity| is 1, return [=ToJSValue=](|ret|[0]). @@ -1113,7 +1171,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not To run a host function from the JavaScript object |func|, type |functype|, and [=list=] of [=WebAssembly values=] |arguments|, perform the following steps: 1. Let [|parameters|] → [|results|] be |functype|. - 1. If |parameters| or |results| contain [=v128=], throw a {{TypeError}}. + 1. If |parameters| or |results| contain [=v128=] or [=exnref=], throw a {{TypeError}}. 1. Let |jsArguments| be « ». 1. [=list/iterate|For each=] |arg| of |arguments|, 1. [=list/Append=] [=!=] [=ToJSValue=](|arg|) to |jsArguments|. @@ -1146,9 +1204,18 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. [=Clean up after running a callback=] with |stored settings|. 1. [=Clean up after running script=] with |relevant settings|. 1. Assert: |result|.\[[Type]] is throw or normal. - 1. If |result|.\[[Type]] is throw, then trigger a WebAssembly trap, and propagate |result|.\[[Value]] to the enclosing JavaScript. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. If |result|.\[[Type]] is throw, then: + 1. Let |v| be |result|.\[[Value]]. + 1. If |v| [=implements=] {{Exception}}, + 1. Let |address| be |v|.\[[Address]]. + 1. Otherwise, + 1. Let |type| be the result of [=get the JavaScript exception tag |getting the JavaScript exception tag=]. + 1. Let |payload| be [=!=] [=ToWebAssemblyValue=](|v|, [=externref=]). + 1. Let (|store|, |address|) be [=exn_alloc=](|store|, |type|, « |payload| »). + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. Execute the WebAssembly instructions ([=ref.exn=] |address|) ([=throw_ref=]). 1. Otherwise, return |result|.\[[Value]]. - 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. 1. Return |funcaddr|. @@ -1157,7 +1224,8 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
The algorithm ToJSValue(|w|) coerces a [=WebAssembly value=] to a JavaScript value by performing the following steps: -1. Assert: |w| is not of the form [=v128.const=] v128. +1. Assert: |w| is not of the form [=v128.const=] v128. +1. Assert: |w| is not of the form [=ref.exn=] exnaddr. 1. If |w| is of the form [=i64.const=] |u64|, 1. Let |i64| be [=signed_64=](|u64|). 1. Return [=ℤ=](|i64| interpreted as a mathematical value). @@ -1200,6 +1268,7 @@ For retrieving a host value from an [=host address=] |hostaddr|, perf The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript value to a [=WebAssembly value=] by performing the following steps: 1. Assert: |type| is not [=v128=]. +1. Assert: |type| is not [=exnref=]. 1. If |type| is [=i64=], 1. Let |i64| be [=?=] [$ToBigInt64$](|v|). 1. Let |u64| be the unsigned integer such that |i64| is [=signed_64=](|u64|). @@ -1260,6 +1329,68 @@ The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript va
+ +

Tags

+ +The tag_alloc(|store|, |parameters|) algorithm creates a new [=tag address=] for |parameters| in |store| and returns the updated store and the [=tag address=]. + +The tag_parameters(|store|, |tagAddress|) algorithm returns the [=list=] of types for |tagAddress| in |store|. + +

Tag types

+ +
+dictionary TagType {
+  required sequence<ValueType> parameters;
+};
+
+[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
+interface Tag {
+  constructor(TagType type);
+};
+
+ +A {{Tag}} value represents an exception tag. + +
+ +To initialize a Tag object |tag| from a [=tag address=] |tagAddress|, perform the following steps: + +1. Let |map| be the [=surrounding agent=]'s associated [=Tag object cache=]. +1. Assert: |map|[|tagAddress|] doesn't [=map/exist=]. +1. Set |tag|.\[[Address]] to |tagAddress|. +1. [=map/Set=] |map|[|tagAddress|] to |tag|. + +
+ +
+ +To create a Tag object from a [=tag address=] |tagAddress|, perform the following steps: + +1. Let |map| be the [=surrounding agent=]'s associated [=Tag object cache=]. +1. If |map|[|tagAddress|] [=map/exists=], + 1. Return |map|[|tagAddress|]. +1. Let |tag| be a [=new=] {{Tag}}. +1. [=initialize a Tag object|Initialize=] |tag| from |tagAddress|. +1. Return |tag|. + +
+ +
+ +The new Tag(|type|) constructor steps are: + +1. Let |parameters| be |type|["parameters"]. +1. Let |wasmParameters| be «». +1. [=list/iterate|For each=] |type| of |parameters|, + 1. [=list/Append=] [=ToValueType=](|type|) to |wasmParameters|. +1. Let |store| be the current agent's [=associated store=]. +1. Let (|store|, |tagAddress|) be [=tag_alloc=](|store|, |wasmParameters|). +1. Set the current agent's [=associated store=] to |store|. +1. [=initialize a Tag object|Initialize=] **this** from |tagAddress|. + +
+ +

Garbage Collected Objects

A WebAssembly struct or array is made available in JavaScript as an Exported GC Object. @@ -1363,6 +1494,139 @@ The internal methods of an [=Exported GC Object=] use the following implementati 1. Set |object|.\[[OwnPropertyKeys]] as specified in [=[[OwnPropertyKeys]] internal method of an Exported GC Object=]. 1. [=map/Set=] |map|[|objectaddr|] to |object|. 1. Return |object|. + + +

Exceptions

+ +
+dictionary ExceptionOptions {
+  boolean traceStack = false;
+};
+
+[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
+interface Exception {
+  constructor(Tag exceptionTag, sequence<any> payload, optional ExceptionOptions options = {});
+  any getArg([EnforceRange] unsigned long index);
+  boolean is(Tag exceptionTag);
+  readonly attribute (DOMString or undefined) stack;
+};
+
+ +An {{Exception}} value represents an exception. + +
+ +To initialize an Exception object |exn| from an [=Exception address=] |exnAddress|, perform the following steps: + +1. Let |map| be the [=surrounding agent=]'s associated [=Exception object cache=]. +1. Assert: |map|[|exnAddress|] doesn't [=map/exist=]. +1. Set |exn|.\[[Address]] to |exnAddress|. +1. [=map/Set=] |map|[|exnAddress|] to |exn|. +1. Let |store| be the [=surrounding agent=]'s [=associated store=]. +1. Let |tagaddr| be [=exn_tag=](|store|, |exnAddress|). +1. Let |payload| be [=exn_read=](|store|, |exnAddress|). +1. Set |exn|.\[[Type]] to |tagaddr|. +1. Set |exn|.\[[Payload]] to |payload|. +1. Set |exn|.\[[Stack]] to undefined. + +
+ +
+ +To create an Exception object from a [=exception address=] |exnAddress|, perform the following steps: + +1. Let |map| be the [=surrounding agent=]'s associated [=Exception object cache=]. +1. If |map|[|exnAddress|] [=map/exists=], + 1. Return |map|[|exnAddress|]. +1. Let |exn| be a [=new=] {{Exception}}. +1. [=initialize an Exception object|Initialize=] |exn| from |exnAddress|. +1. Return |exn|. + + +
+ +
+ +The new Exception(|exceptionTag|, |payload|, |options|) +constructor steps are: + +1. Let |JSTagAddr| be the result of [=get the JavaScript exception tag|getting the JavaScript exception tag=]. +1. If |exceptionTag|.\[[Address]] is equal to |JSTagAddr|, + 1. Throw a {{TypeError}}. +1. Let |store| be the [=surrounding agent=]'s [=associated store=]. +1. Let [|types|] → [] be [=tag_type=](|store|, |exceptionTag|.\[[Address]]). +1. If |types|'s [=list/size=] is not |payload|'s [=list/size=], + 1. Throw a {{TypeError}}. +1. Let |wasmPayload| be « ». +1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly, + 1. If |resultType| is [=v128=] or [=exnref=], + 1. Throw a {{TypeError}}. + 1. [=list/Append=] [=?=] [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|. +1. Let (|store|, |exceptionAddr|) be [=exn_alloc=](|store|, |exceptionTag|.\[[Address]], |wasmPayload|) +1. Set the [=surrounding agent=]'s [=associated store=] to |store|. +1. [=initialize an Exception object|Initialize=] **this** from |exceptionAddr|. +1. If |options|["traceStack"] is true, + 1. Set **this**.\[[Stack]] to either a {{DOMString}} representation of the current call stack or undefined. + + +
+ +
+ +The getArg(|index|) method steps are: + +1. Let |store| be the [=surrounding agent=]'s [=associated store=]. +1. Let |tagaddr| be [=exn_tag=](|store|, **this**.\[[Address]]). +1. Let |payload| be [=exn_read=](|store|, **this**.\[[Address]]). +1. Assert: |tagaddr| is equal to **this**.\[[Type]]. +1. If |index| ≥ |payload|'s [=list/size=], + 1. Throw a {{RangeError}}. +1. Let [|types|] → [] be [=tag_type=](|store|, |tagaddr|). +1. If |types|[|index|] is [=v128=] or [=exnref=], + 1. Throw a {{TypeError}}. +1. Return [=ToJSValue=](|payload|[|index|]). + +
+ +
+ +The is(|exceptionTag|) method steps are: + +1. If **this**.\[[Type]] is not equal to |exceptionTag|.\[[Address]], + 1. Return false. +1. Return true. + +
+ +
+ +The stack getter steps are: + +1. Return **this**.\[[Stack]]. + +
+ +

JavaScript exceptions

+ +The JavaScript exception tag is a [=tag address=] associated with +the surrounding agent. It is allocated in the agent's [=associated store=] on +first use and cached. It always has the [=tag type=] « [=externref=] » → « ». + + +
+ +To get the JavaScript exception tag, perform the following steps: + + 1. If the [=surrounding agent=]'s associated [=JavaScript exception tag=] has been initialized, + 1. return the [=surrounding agent=]'s associated [=JavaScript exception tag=] + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let (|store|, |tagAddress|) be [=tag_alloc=](|store|, « [=externref=] » → « »). + 1. Set the current agent's [=associated store=] to |store|. + 1. Set the current agent's associated [=JavaScript exception tag=] to |tagAddress|. + 1. return |tagAddress|. + +

Error Objects

@@ -1445,6 +1709,7 @@ In practice, an implementation may run out of resources for valid modules below
  • The maximum number of imports declared in a module is 100,000.
  • The maximum number of exports declared in a module is 100,000.
  • The maximum number of globals defined in a module is 1,000,000.
  • +
  • The maximum number of tags defined in a module is 1,000,000.
  • The maximum number of data segments defined in a module is 100,000.
  • The maximum number of tables, including declared or imported tables, is 100,000.
  • diff --git a/document/legacy/exceptions/.gitignore b/document/legacy/exceptions/.gitignore new file mode 100644 index 0000000000..b932ec283e --- /dev/null +++ b/document/legacy/exceptions/.gitignore @@ -0,0 +1,3 @@ +_build +_static +document/*.pyc diff --git a/document/legacy/exceptions/core/LICENSE b/document/legacy/exceptions/core/LICENSE new file mode 100644 index 0000000000..795b406e4e --- /dev/null +++ b/document/legacy/exceptions/core/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/core/Makefile b/document/legacy/exceptions/core/Makefile new file mode 100644 index 0000000000..eb2611acd2 --- /dev/null +++ b/document/legacy/exceptions/core/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-Legacy-Exceptions + +# 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/core/README.md b/document/legacy/exceptions/core/README.md new file mode 100644 index 0000000000..06d075235c --- /dev/null +++ b/document/legacy/exceptions/core/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/core/appendix/index-instructions.py b/document/legacy/exceptions/core/appendix/index-instructions.py new file mode 100755 index 0000000000..2c8d3407da --- /dev/null +++ b/document/legacy/exceptions/core/appendix/index-instructions.py @@ -0,0 +1,106 @@ +#!/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: +.. _index-instr: + +Index of Instructions +===================== +""" + +FOOTER = """\ +""" + +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/core/binary.rst b/document/legacy/exceptions/core/binary.rst new file mode 100644 index 0000000000..f5c95be2ff --- /dev/null +++ b/document/legacy/exceptions/core/binary.rst @@ -0,0 +1,32 @@ +.. _binary: + +Binary Format +============= + +.. _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/core/conf.py b/document/legacy/exceptions/core/conf.py new file mode 100644 index 0000000000..39b20491d6 --- /dev/null +++ b/document/legacy/exceptions/core/conf.py @@ -0,0 +1,500 @@ +# -*- 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-Legacy-Exceptions' +project = u'WebAssembly-Legacy-Exceptions' +title = u'WebAssembly Spec 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 = '' +# 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': { + '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 = u'WebAssembly Legacy Exceptions' + +# 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 = False + +# 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}', + + # Allow chapters to start on even pages + 'extraclassoptions': 'openany' +} + +# 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, + 'howto' + ), +] + +# 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/core/exec.rst b/document/legacy/exceptions/core/exec.rst new file mode 100644 index 0000000000..15d30b1b6b --- /dev/null +++ b/document/legacy/exceptions/core/exec.rst @@ -0,0 +1,350 @@ +.. _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 \\ \qquad + (\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/core/index.rst b/document/legacy/exceptions/core/index.rst new file mode 100644 index 0000000000..a83254bb59 --- /dev/null +++ b/document/legacy/exceptions/core/index.rst @@ -0,0 +1,19 @@ +WebAssembly Addendum: Legacy Exception Handling +=============================================== + +.. only:: html + + | Editor: Andreas Rossberg + + | Issue Tracker: |WasmIssues| + +.. toctree:: + :maxdepth: 1 + + intro + syntax + valid + exec + binary + text + appendix/index-instructions diff --git a/document/legacy/exceptions/core/intro.rst b/document/legacy/exceptions/core/intro.rst new file mode 100644 index 0000000000..b8d8c57c3b --- /dev/null +++ b/document/legacy/exceptions/core/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/core/static/custom.css b/document/legacy/exceptions/core/static/custom.css new file mode 100644 index 0000000000..33bb863d42 --- /dev/null +++ b/document/legacy/exceptions/core/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/core/static/webassembly.png b/document/legacy/exceptions/core/static/webassembly.png new file mode 100644 index 0000000000..f9edc61098 Binary files /dev/null and b/document/legacy/exceptions/core/static/webassembly.png differ diff --git a/document/legacy/exceptions/core/syntax.rst b/document/legacy/exceptions/core/syntax.rst new file mode 100644 index 0000000000..3dc50dfe69 --- /dev/null +++ b/document/legacy/exceptions/core/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/core/text.rst b/document/legacy/exceptions/core/text.rst new file mode 100644 index 0000000000..1968c1120d --- /dev/null +++ b/document/legacy/exceptions/core/text.rst @@ -0,0 +1,38 @@ +.. _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~~ \\&&& + (\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/core/util/macros.def b/document/legacy/exceptions/core/util/macros.def new file mode 100644 index 0000000000..e1c2891003 --- /dev/null +++ b/document/legacy/exceptions/core/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/core/util/mathdef.py b/document/legacy/exceptions/core/util/mathdef.py new file mode 100644 index 0000000000..a10fc458ff --- /dev/null +++ b/document/legacy/exceptions/core/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/core/util/pseudo-lexer.py b/document/legacy/exceptions/core/util/pseudo-lexer.py new file mode 100644 index 0000000000..fd3a251d5e --- /dev/null +++ b/document/legacy/exceptions/core/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/document/legacy/exceptions/js-api/Makefile b/document/legacy/exceptions/js-api/Makefile new file mode 100644 index 0000000000..84ba5d3abd --- /dev/null +++ b/document/legacy/exceptions/js-api/Makefile @@ -0,0 +1,44 @@ +BUILDDIR = _build +STATICDIR = _static +DOWNLOADDIR = _download +NAME = WebAssembly + +.PHONY: all +all: + mkdir -p $(BUILDDIR)/html + bikeshed spec index.bs $(BUILDDIR)/html/index.html + @echo "Build finished. The HTML pages are in `pwd`/$(BUILDDIR)/html." + +.PHONY: publish +publish: + (cd ..; make publish-js-api) + +.PHONY: clean +clean: + rm -rf $(BUILDDIR) + rm -rf $(STATICDIR) + +.PHONY: diff +diff: all + @echo "Downloading the old single-file html spec..." + curl `grep "^TR" index.bs | cut -d' ' -f2` -o $(BUILDDIR)/html/old.html + @echo "Done." + @echo "Diffing new against old..." + perl ../util/htmldiff.pl $(BUILDDIR)/html/old.html $(BUILDDIR)/html/index.html $(BUILDDIR)/html/diff.html + @echo "Done. The diff is at $(BUILDDIR)/html/diff.html" + +.PHONY: WD-tar +WD-tar: + bikeshed echidna --just-tar index.bs $(BUILDDIR)/html/index.html + mv test.tar $(BUILDDIR)/WD.tar + @echo "Built $(BUILDDIR)/WD.tar." + +.PHONY: WD-echidna +WD-echidna: + @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 + bikeshed echidna index.bs --u $(W3C_USERNAME) --p $(W3C_PASSWORD) --d $(DECISION_URL) diff --git a/document/legacy/exceptions/js-api/index.bs b/document/legacy/exceptions/js-api/index.bs new file mode 100644 index 0000000000..e7db140740 --- /dev/null +++ b/document/legacy/exceptions/js-api/index.bs @@ -0,0 +1,1450 @@ + + +
    +{
    +  "WEBASSEMBLY": {
    +    "href": "https://webassembly.github.io/spec/core/",
    +    "title": "WebAssembly Core Specification",
    +    "publisher": "W3C WebAssembly Community Group",
    +    "status": "Draft"
    +  }
    +}
    +
    + +
    +urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
    +    type: interface; for: ECMAScript
    +        text: ArrayBuffer; url: sec-arraybuffer-objects
    +    type: exception; for: ECMAScript
    +        text: Error; url: sec-error-objects
    +        text: NativeError; url: sec-nativeerror-constructors
    +        text: TypeError; url: sec-native-error-types-used-in-this-standard-typeerror
    +        text: RangeError; url: sec-native-error-types-used-in-this-standard-rangeerror
    +    type: dfn
    +        url: sec-returnifabrupt-shorthands
    +            text: !
    +            text: ?
    +        text: Type; url: sec-ecmascript-data-types-and-values
    +        text: current Realm; url: current-realm
    +        text: Built-in Function Objects; url: sec-built-in-function-objects
    +        text: NativeError Object Structure; url: sec-nativeerror-object-structure
    +        text: 𝔽; url: #𝔽
    +        text: ℤ; url: #ℤ
    +urlPrefix: https://webassembly.github.io/exception-handling/core/; spec: WebAssembly; type: dfn
    +    url: valid/modules.html#valid-module
    +        text: valid
    +        text: WebAssembly module validation
    +    text: module grammar; url: binary/modules.html#binary-module
    +    text: custom section; url: binary/modules.html#custom-section
    +    text: customsec; url: binary/modules.html#binary-customsec
    +    text: memory instance; url: exec/runtime.html#memory-instances
    +    text: table instance; url: exec/runtime.html#table-instances
    +    text: global instance; url: exec/runtime.html#global-instances
    +    text: trap; url: exec/runtime.html#syntax-trap
    +    url: exec/runtime.html#values
    +        text: WebAssembly value
    +        text: i64.const
    +        text: i32.const
    +        text: f32.const
    +        text: f64.const
    +        text: v128.const
    +        text: ref.null
    +        text: ref.func
    +        text: ref.extern
    +    text: function index; url: syntax/modules.html#syntax-funcidx
    +    text: function instance; url: exec/runtime.html#function-instances
    +    text: store_init; url: appendix/embedding.html#embed-store-init
    +    text: module_decode; url: appendix/embedding.html#embed-module-decode
    +    text: module_validate; url: appendix/embedding.html#embed-module-validate
    +    text: module_instantiate; url: appendix/embedding.html#embed-module-instantiate
    +    text: module_imports; url: appendix/embedding.html#embed-module-imports
    +    text: module_exports; url: appendix/embedding.html#embed-module-exports
    +    text: instance_export; url: appendix/embedding.html#embed-instance-export
    +    text: func_alloc; url: appendix/embedding.html#embed-func-alloc
    +    text: func_type; url: appendix/embedding.html#embed-func-type
    +    text: func_invoke; url: appendix/embedding.html#embed-func-invoke
    +    text: table_alloc; url: appendix/embedding.html#embed-table-alloc
    +    text: table_type; url: appendix/embedding.html#embed-table-type
    +    text: table_read; url: appendix/embedding.html#embed-table-read
    +    text: table_write; url: appendix/embedding.html#embed-table-write
    +    text: table_size; url: appendix/embedding.html#embed-table-size
    +    text: table_grow; url: appendix/embedding.html#embed-table-grow
    +    text: mem_alloc; url: appendix/embedding.html#embed-mem-alloc
    +    text: mem_type; url: appendix/embedding.html#embed-mem-type
    +    text: mem_read; url: appendix/embedding.html#embed-mem-read
    +    text: mem_write; url: appendix/embedding.html#embed-mem-write
    +    text: mem_size; url: appendix/embedding.html#embed-mem-size
    +    text: mem_grow; url: appendix/embedding.html#embed-mem-grow
    +    text: global_alloc; url: appendix/embedding.html#embed-global-alloc
    +    text: global_type; url: appendix/embedding.html#embed-global-type
    +    text: global_read; url: appendix/embedding.html#embed-global-read
    +    text: global_write; url: appendix/embedding.html#embed-global-write
    +    text: error; url: appendix/embedding.html#embed-error
    +    text: store; url: exec/runtime.html#syntax-store
    +    text: table type; url: syntax/types.html#syntax-tabletype
    +    text: table address; url: exec/runtime.html#syntax-tableaddr
    +    text: function address; url: exec/runtime.html#syntax-funcaddr
    +    text: memory address; url: exec/runtime.html#syntax-memaddr
    +    text: global address; url: exec/runtime.html#syntax-globaladdr
    +    text: extern address; url: exec/runtime.html#syntax-externaddr
    +    text: tag address; url: exec/runtime.html#syntax-tagaddr
    +    url: syntax/types.html#syntax-numtype
    +        text: i32
    +        text: i64
    +        text: f32
    +        text: f64
    +    url: syntax/types.html#vector-types
    +        text: v128
    +    url: syntax/types.html#syntax-reftype
    +        text: reftype
    +        text: funcref
    +        text: externref
    +    url: syntax/values.html#syntax-float
    +        text: +∞
    +        text: −∞
    +        text: nan
    +        text: canon
    +        text: signif
    +    text: function element; url: exec/runtime.html#syntax-funcelem
    +    text: import component; url: syntax/modules.html#imports
    +    url: exec/runtime.html#syntax-externval
    +        text: external value
    +        for: external value
    +            text: tag
    +    text: host function; url: exec/runtime.html#syntax-hostfunc
    +    text: the instantiation algorithm; url: exec/modules.html#instantiation
    +    text: module; url: syntax/modules.html#syntax-module
    +    text: imports; url: syntax/modules.html#syntax-module
    +    text: import; url: syntax/modules.html#syntax-import
    +    url: syntax/types.html#external-types
    +        text: external type
    +        text: func
    +        text: table
    +        text: mem
    +        text: global
    +        for: externtype
    +            text: tag
    +    text: global type; url: syntax/types.html#syntax-globaltype
    +    url: syntax/types.html#syntax-mut
    +        text: var
    +        text: const
    +    text: address; url: exec/runtime.html#addresses
    +    text: signed_32; url: exec/numerics.html#aux-signed
    +    text: memory.grow; url: exec/instructions.html#exec-memory-grow
    +    text: current frame; url: exec/conventions.html#exec-notation-textual
    +    text: module; for: frame; url: exec/runtime.html#syntax-frame
    +    text: memaddrs; for: moduleinst; url: exec/runtime.html#syntax-moduleinst
    +    text: signed_64; url: exec/numerics.html#aux-signed
    +    text: sequence; url: syntax/conventions.html#grammar-notation
    +    text: exception; for: tagtype/attribute; url: syntax/types.html#syntax-tagtype
    +urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL
    +    type: dfn
    +        text: create a namespace object; url: create-a-namespace-object
    +urlPrefix: https://webassembly.github.io/js-types/js-api/; spec: WebAssembly JS API (JS Type Reflection)
    +    type: abstract-op; text: FromValueType; url: abstract-opdef-fromvaluetype
    +
    + + + + + +This API provides a way to access WebAssembly [[WEBASSEMBLY]] through a bridge to explicitly construct modules from JavaScript [[ECMASCRIPT]]. + +

    Sample API Usage

    + +

    This section is non-normative.

    + +Given `demo.wat` (encoded to `demo.wasm`): + +```lisp +(module + (import "js" "import1" (func $i1)) + (import "js" "import2" (func $i2)) + (func $main (call $i1)) + (start $main) + (func (export "f") (call $i2)) +) +``` + +and the following JavaScript, run in a browser: + +```javascript +var importObj = {js: { + import1: () => console.log("hello,"), + import2: () => console.log("world!") +}}; +fetch('demo.wasm').then(response => + response.arrayBuffer() +).then(buffer => + WebAssembly.instantiate(buffer, importObj) +).then(({module, instance}) => + instance.exports.f() +); +``` + +

    Notation

    + +This specification depends on the Infra Standard. [[INFRA]] + +The WebAssembly [=sequence=] type is equivalent to the [=list=] type defined there; values of one +are treated as values of the other transparently. + +

    Internal storage

    + +

    Interaction of the WebAssembly Store with JavaScript

    + +Note: WebAssembly semantics are defined in terms of an abstract [=store=], representing the state of the WebAssembly abstract machine. WebAssembly operations take a store and return an updated store. + +Each [=agent=] has an associated store. When a new agent is created, its associated store is set to the result of [=store_init=](). + +Note: In this specification, no WebAssembly-related objects, memory or addresses can be shared among agents in an [=agent cluster=]. In a future version of WebAssembly, this may change. + +Elements of the WebAssembly store may be identified with JavaScript values. In particular, each WebAssembly [=memory instance=] with a corresponding {{Memory}} object is identified with a JavaScript [=Data Block=]; modifications to this Data Block are identified to updating the agent's store to a store which reflects those changes, and vice versa. + +

    WebAssembly JS Object Caches

    + +Note: There are several WebAssembly objects that may have a corresponding JavaScript object. The correspondence is stored in a per-agent mapping from WebAssembly [=address=]es to JavaScript objects. +This mapping is used to ensure that, for a given [=agent=], there exists at most one JavaScript object for a particular WebAssembly address. However, this property does not hold for shared objects. + +Each [=agent=] is associated with the following [=ordered map=]s: + * The Memory object cache, mapping [=memory address=]es to {{Memory}} objects. + * The Table object cache, mapping [=table address=]es to {{Table}} objects. + * The Exported Function cache, mapping [=function address=]es to [=Exported Function=] objects. + * The Global object cache, mapping [=global address=]es to {{Global}} objects. + * The Extern value cache, mapping [=extern address=]es to values. + * The Tag object cache, mapping [=tag addresses=] to {{Tag}} objects. + +

    The WebAssembly Namespace

    + +
    +dictionary WebAssemblyInstantiatedSource {
    +    required Module module;
    +    required Instance instance;
    +};
    +
    +[Exposed=*]
    +namespace WebAssembly {
    +    boolean validate(BufferSource bytes);
    +    Promise<Module> compile(BufferSource bytes);
    +
    +    Promise<WebAssemblyInstantiatedSource> instantiate(
    +        BufferSource bytes, optional object importObject);
    +
    +    Promise<Instance> instantiate(
    +        Module moduleObject, optional object importObject);
    +};
    +
    + + + +
    + To compile a WebAssembly module from source bytes |bytes|, perform the following steps: + 1. Let |module| be [=module_decode=](|bytes|). If |module| is [=error=], return [=error=]. + 1. If [=module_validate=](|module|) is [=error=], return [=error=]. + 1. Return |module|. +
    + +
    + The validate(|bytes|) method, when invoked, performs the following steps: + 1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bytes|. + 1. [=Compile a WebAssembly module|Compile=] |stableBytes| as a WebAssembly module and store the results as |module|. + 1. If |module| is [=error=], return false. + 1. Return true. +
    + +A {{Module}} object represents a single WebAssembly module. Each {{Module}} object has the following internal slots: + + * \[[Module]] : a WebAssembly [=/module=] + * \[[Bytes]] : the source bytes of \[[Module]]. + +
    + To construct a WebAssembly module object from a module |module| and source bytes |bytes|, perform the following steps: + + 1. Let |moduleObject| be a new {{Module}} object. + 1. Set |moduleObject|.\[[Module]] to |module|. + 1. Set |moduleObject|.\[[Bytes]] to |bytes|. + 1. Return |moduleObject|. +
    + +
    + To asynchronously compile a WebAssembly module from source bytes |bytes|, using optional [=task source=] |taskSource|, perform the following steps: + + 1. Let |promise| be [=a new promise=]. + 1. Run the following steps [=in parallel=]: + 1. [=compile a WebAssembly module|Compile the WebAssembly module=] |bytes| and store the result as |module|. + 1. [=Queue a task=] to perform the following steps. If |taskSource| was provided, queue the task on that task source. + 1. If |module| is [=error=], reject |promise| with a {{CompileError}} exception. + 1. Otherwise, + 1. [=Construct a WebAssembly module object=] from |module| and |bytes|, and let |moduleObject| be the result. + 1. [=Resolve=] |promise| with |moduleObject|. + 1. Return |promise|. +
    + +
    + The compile(|bytes|) method, when invoked, performs the following steps: + 1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bytes|. + 1. [=Asynchronously compile a WebAssembly module=] from |stableBytes| and return the result. +
    + +
    + To read the imports from a WebAssembly module |module| from imports object |importObject|, perform the following steps: + 1. If |module|.[=imports=] [=list/is empty|is not empty=], and |importObject| is undefined, throw a {{TypeError}} exception. + 1. Let |imports| be « ». + 1. [=list/iterate|For each=] (|moduleName|, |componentName|, |externtype|) of [=module_imports=](|module|), + 1. Let |o| be [=?=] [$Get$](|importObject|, |moduleName|). + 1. If [=Type=](|o|) is not Object, throw a {{TypeError}} exception. + 1. Let |v| be [=?=] [$Get$](|o|, |componentName|). + 1. If |externtype| is of the form [=func=] |functype|, + 1. If [$IsCallable$](|v|) is false, throw a {{LinkError}} exception. + 1. If |v| has a \[[FunctionAddress]] internal slot, and therefore is an [=Exported Function=], + 1. Let |funcaddr| be the value of |v|'s \[[FunctionAddress]] internal slot. + 1. Otherwise, + 1. [=Create a host function=] from |v| and |functype|, and let |funcaddr| be the result. + 1. Let |index| be the number of external functions in |imports|. This value |index| is known as the index of the host function |funcaddr|. + 1. Let |externfunc| be the [=external value=] [=external value|func=] |funcaddr|. + 1. [=list/Append=] |externfunc| to |imports|. + 1. If |externtype| is of the form [=global=] mut |valtype|, + 1. If [=Type=](|v|) is Number or BigInt, + 1. If |valtype| is [=i64=] and [=Type=](|v|) is Number, + 1. Throw a {{LinkError}} exception. + 1. If |valtype| is not [=i64=] and [=Type=](|v|) is BigInt, + 1. Throw a {{LinkError}} exception. + 1. If |valtype| is [=v128=], + 1. Throw a {{LinkError}} exception. + 1. Let |value| be [=ToWebAssemblyValue=](|v|, |valtype|). + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let (|store|, |globaladdr|) be [=global_alloc=](|store|, [=const=] |valtype|, |value|). + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. Otherwise, if |v| [=implements=] {{Global}}, + 1. Let |globaladdr| be |v|.\[[Global]]. + 1. Otherwise, + 1. Throw a {{LinkError}} exception. + 1. Let |externglobal| be [=external value|global=] |globaladdr|. + 1. [=list/Append=] |externglobal| to |imports|. + 1. If |externtype| is of the form [=mem=] memtype, + 1. If |v| does not [=implement=] {{Memory}}, throw a {{LinkError}} exception. + 1. Let |externmem| be the [=external value=] [=external value|mem=] |v|.\[[Memory]]. + 1. [=list/Append=] |externmem| to |imports|. + 1. If |externtype| is of the form [=table=] tabletype, + 1. If |v| does not [=implement=] {{Table}}, throw a {{LinkError}} exception. + 1. Let |tableaddr| be |v|.\[[Table]]. + 1. Let |externtable| be the [=external value=] [=external value|table=] |tableaddr|. + 1. [=list/Append=] |externtable| to |imports|. + 1. If |externtype| is of the form [=externtype/tag=] |attribute| functype, + 1. Assert: |attribute| is [=tagtype/attribute/exception=]. + 1. If |v| does not [=implement=] {{Tag}}, throw a {{LinkError}} exception. + 1. Let |tagaddr| be |v|.\[[Address]]. + 1. Let |externtag| be the [=external value=] [=external value/tag=] |tagaddr|. + 1. [=list/Append=] |externtag| to |imports|. + 1. Return |imports|. + +Note: This algorithm only verifies the right kind of JavaScript values are passed. +The verification of WebAssembly type requirements is deferred to the +"[=instantiate the core of a WebAssembly module=]" algorithm. +
    + +
    + To create an exports object from a WebAssembly module |module| and instance |instance|, perform the following steps: + 1. Let |exportsObject| be [=!=] [$OrdinaryObjectCreate$](null). + 1. [=list/iterate|For each=] (|name|, |externtype|) of [=module_exports=](|module|), + 1. Let |externval| be [=instance_export=](|instance|, |name|). + 1. Assert: |externval| is not [=error=]. + 1. If |externtype| is of the form [=func=] functype, + 1. Assert: |externval| is of the form [=external value|func=] |funcaddr|. + 1. Let [=external value|func=] |funcaddr| be |externval|. + 1. Let |func| be the result of creating [=a new Exported Function=] from |funcaddr|. + 1. Let |value| be |func|. + 1. If |externtype| is of the form [=global=] mut globaltype, + 1. Assert: |externval| is of the form [=external value|global=] |globaladdr|. + 1. Let [=external value|global=] |globaladdr| be |externval|. + 1. Let |global| be [=create a global object|a new Global object=] created from |globaladdr|. + 1. Let |value| be |global|. + 1. If |externtype| is of the form [=mem=] memtype, + 1. Assert: |externval| is of the form [=external value|mem=] |memaddr|. + 1. Let [=external value|mem=] |memaddr| be |externval|. + 1. Let |memory| be [=create a memory object|a new Memory object=] created from |memaddr|. + 1. Let |value| be |memory|. + 1. If |externtype| is of the form [=table=] tabletype, + 1. Assert: |externval| is of the form [=external value|table=] |tableaddr|. + 1. Let [=external value|table=] |tableaddr| be |externval|. + 1. Let |table| be [=create a Table object|a new Table object=] created from |tableaddr|. + 1. Let |value| be |table|. + 1. If |externtype| is of the form [=externtype/tag=] |attribute| functype, + 1. Assert: |attribute| is [=tagtype/attribute/exception=]. + 1. Assert: |externval| is of the form [=external value/tag=] |tagaddr|. + 1. Let [=external value/tag=] |tagaddr| be |externval|. + 1. Let |tag| be [=create a Tag object|a new Tag object=] created from |tagaddr|. + 1. Let |value| be |tag|. + 1. Let |status| be [=!=] [$CreateDataProperty$](|exportsObject|, |name|, |value|). + 1. Assert: |status| is true. + + Note: the validity and uniqueness checks performed during [=WebAssembly module validation=] ensure that each property name is valid and no properties are defined twice. + 1. Perform [=!=] [$SetIntegrityLevel$](|exportsObject|, `"frozen"`). + 1. Return |exportsObject|. +
    + +
    + To initialize an instance object |instanceObject| from a WebAssembly module |module| and instance |instance|, perform the following steps: + + 1. [=Create an exports object=] from |module| and |instance| and let |exportsObject| be the result. + 1. Set |instanceObject|.\[[Instance]] to |instance|. + 1. Set |instanceObject|.\[[Exports]] to |exportsObject|. +
    + +
    + To instantiate the core of a WebAssembly module from a module |module| and imports |imports|, perform the following steps: + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |result| be [=module_instantiate=](|store|, |module|, |imports|). + 1. If |result| is [=error=], throw an appropriate exception type: + * A {{LinkError}} exception for most cases which occur during linking. + * If the error came when running the start function, throw a {{RuntimeError}} for most errors which occur from WebAssembly, or the error object propagated from inner ECMAScript code. + * Another error type if appropriate, for example an out-of-memory exception, as documented in the WebAssembly error mapping. + 1. Let (|store|, |instance|) be |result|. + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. Return |instance|. +
    + +
    + To asynchronously instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: + 1. Let |promise| be [=a new promise=]. + 1. Let |module| be |moduleObject|.\[[Module]]. + 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. + If this operation throws an exception, catch it, [=reject=] |promise| with the exception, and return |promise|. + 1. Run the following steps [=in parallel=]: + 1. [=Queue a task=] to perform the following steps: + Note: Implementation-specific work may be performed here. + 1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result. + If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps. + 1. Let |instanceObject| be a [=/new=] {{Instance}}. + 1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|. + If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps. + 1. [=Resolve=] |promise| with |instanceObject|. + 1. Return |promise|. +
    + +
    + To synchronously instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: + 1. Let |module| be |moduleObject|.\[[Module]]. + 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. + 1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result. + 1. Let |instanceObject| be a [=/new=] {{Instance}}. + 1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|. + 1. Return |instanceObject|. +
    + +
    + To instantiate a promise of a module |promiseOfModule| with imports |importObject|, perform the following steps: + + 1. Let |promise| be [=a new promise=]. + 1. [=Upon fulfillment=] of |promiseOfModule| with value |module|: + 1. [=asynchronously instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, and let |innerPromise| be the result. + 1. [=Upon fulfillment=] of |innerPromise| with value |instance|. + 1. Let |result| be the {{WebAssemblyInstantiatedSource}} value «[ "{{WebAssemblyInstantiatedSource/module}}" → |module|, "{{WebAssemblyInstantiatedSource/instance}}" → |instance| ]». + 1. [=Resolve=] |promise| with |result|. + 1. [=Upon rejection=] of |innerPromise| with reason |reason|: + 1. [=Reject=] |promise| with |reason|. + 1. [=Upon rejection=] of |promiseOfModule| with reason |reason|: + 1. [=Reject=] |promise| with |reason|. + 1. Return |promise|. +
    + +
    + The instantiate(|bytes|, |importObject|) method, when invoked, performs the following steps: + 1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bytes|. + 1. [=Asynchronously compile a WebAssembly module=] from |stableBytes| and let |promiseOfModule| be the result. + 1. [=Instantiate a promise of a module|Instantiate=] |promiseOfModule| with imports |importObject| and return the result. +
    + +
    + The instantiate(|moduleObject|, |importObject|) method, when invoked, performs the following steps: + 1. [=asynchronously instantiate a WebAssembly module|Asynchronously instantiate the WebAssembly module=] |moduleObject| importing |importObject|, and return the result. +
    + +Note: A follow-on streaming API is documented in the WebAssembly Web API. + +

    Modules

    + +
    +enum ImportExportKind {
    +  "function",
    +  "table",
    +  "memory",
    +  "global",
    +  "tag"
    +};
    +
    +dictionary ModuleExportDescriptor {
    +  required USVString name;
    +  required ImportExportKind kind;
    +  // Note: Other fields such as signature may be added in the future.
    +};
    +
    +dictionary ModuleImportDescriptor {
    +  required USVString module;
    +  required USVString name;
    +  required ImportExportKind kind;
    +};
    +
    +[LegacyNamespace=WebAssembly, Exposed=*]
    +interface Module {
    +  constructor(BufferSource bytes);
    +  static sequence<ModuleExportDescriptor> exports(Module moduleObject);
    +  static sequence<ModuleImportDescriptor> imports(Module moduleObject);
    +  static sequence<ArrayBuffer> customSections(Module moduleObject, DOMString sectionName);
    +};
    +
    + +
    + The string value of the extern type |type| is + * "function" if |type| is of the form [=func=] functype + * "table" if |type| is of the form [=table=] tabletype + * "memory" if |type| is of the form [=mem=] memtype + * "global" if |type| is of the form [=global=] globaltype + * "tag" if |type| is of the form [=externtype/tag=] tag +
    + +
    + The exports(|moduleObject|) method, when invoked, performs the following steps: + 1. Let |module| be |moduleObject|.\[[Module]]. + 1. Let |exports| be « ». + 1. [=list/iterate|For each=] (|name|, |type|) of [=module_exports=](|module|), + 1. Let |kind| be the [=string value of the extern type=] |type|. + 1. Let |obj| be «[ "{{ModuleExportDescriptor/name}}" → |name|, "{{ModuleExportDescriptor/kind}}" → |kind| ]». + 1. [=list/Append=] |obj| to |exports|. + 1. Return |exports|. +
    + +
    + The imports(|moduleObject|) method, when invoked, performs the following steps: + 1. Let |module| be |moduleObject|.\[[Module]]. + 1. Let |imports| be « ». + 1. [=list/iterate|For each=] (|moduleName|, |name|, |type|) of [=module_imports=](|module|), + 1. Let |kind| be the [=string value of the extern type=] |type|. + 1. Let |obj| be «[ "{{ModuleImportDescriptor/module}}" → |moduleName|, "{{ModuleImportDescriptor/name}}" → |name|, "{{ModuleImportDescriptor/kind}}" → |kind| ]». + 1. [=list/Append=] |obj| to |imports|. + 1. Return |imports|. +
    + +
    + The customSections(|moduleObject|, |sectionName|) method, when invoked, performs the following steps: + 1. Let |bytes| be |moduleObject|.\[[Bytes]]. + 1. Let |customSections| be « ». + 1. [=list/iterate|For each=] [=custom section=] |customSection| of |bytes|, interpreted according to the [=module grammar=], + 1. Let |name| be the name of |customSection|, [=UTF-8 decode without BOM or fail|decoded as UTF-8=]. + 1. Assert: |name| is not failure (|moduleObject|.\[[Module]] is [=valid=]). + 1. If |name| equals |sectionName| as string values, + 1. [=list/Append=] a new {{ArrayBuffer}} containing a copy of the bytes in |bytes| for the range matched by this [=customsec=] production to |customSections|. + 1. Return |customSections|. +
    + +
    + The Module(|bytes|) constructor, when invoked, performs the following steps: + + 1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bytes|. + 1. [=Compile a WebAssembly module|Compile the WebAssembly module=] |stableBytes| and store the result as |module|. + 1. If |module| is [=error=], throw a {{CompileError}} exception. + 1. Set **this**.\[[Module]] to |module|. + 1. Set **this**.\[[Bytes]] to |stableBytes|. + +Note: Some implementations enforce a size limitation on |bytes|. Use of this API is discouraged, in favor of asynchronous APIs. +
    + +

    Instances

    + +
    +[LegacyNamespace=WebAssembly, Exposed=*]
    +interface Instance {
    +  constructor(Module module, optional object importObject);
    +  readonly attribute object exports;
    +};
    +
    + +
    + The Instance(|module|, |importObject|) constructor, when invoked, runs the following steps: + 1. Let |module| be |module|.\[[Module]]. + 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. + 1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result. + 1. [=initialize an instance object|Initialize=] **this** from |module| and |instance|. + +Note: The use of this synchronous API is discouraged, as some implementations sometimes do long-running compilation work when instantiating. +
    + +
    + The getter of the exports attribute of {{Instance}} returns **this**.\[[Exports]]. +
    + +

    Memories

    + +
    +dictionary MemoryDescriptor {
    +  required [EnforceRange] unsigned long initial;
    +  [EnforceRange] unsigned long maximum;
    +};
    +
    +[LegacyNamespace=WebAssembly, Exposed=*]
    +interface Memory {
    +  constructor(MemoryDescriptor descriptor);
    +  unsigned long grow([EnforceRange] unsigned long delta);
    +  readonly attribute ArrayBuffer buffer;
    +};
    +
    + +A {{Memory}} object represents a single [=memory instance=] +which can be simultaneously referenced by multiple {{Instance}} objects. Each +{{Memory}} object has the following internal slots: + + * \[[Memory]] : a [=memory address=] + * \[[BufferObject]] : an {{ArrayBuffer}} whose [=Data Block=] is [=identified with=] the above memory address + +
    + To create a memory buffer from a [=memory address=] |memaddr|, perform the following steps: + + 1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|. + 1. Let |buffer| be a new {{ArrayBuffer}} whose \[[ArrayBufferData]] is |block| and \[[ArrayBufferByteLength]] is set to the length of |block|. + 1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory". + 1. Return |buffer|. +
    + +
    + To initialize a memory object |memory| from a [=memory address=] |memaddr|, perform the following steps: + 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. + 1. Assert: |map|[|memaddr|] doesn't [=map/exist=]. + 1. Let |buffer| be the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|. + 1. Set |memory|.\[[Memory]] to |memaddr|. + 1. Set |memory|.\[[BufferObject]] to |buffer|. + 1. [=map/Set=] |map|[|memaddr|] to |memory|. +
    + +
    + To create a memory object from a [=memory address=] |memaddr|, perform the following steps: + + 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. + 1. If |map|[|memaddr|] [=map/exists=], + 1. Return |map|[|memaddr|]. + 1. Let |memory| be a [=/new=] {{Memory}}. + 1. [=initialize a memory object|Initialize=] |memory| from |memaddr|. + 1. Return |memory|. +
    + +
    + The Memory(|descriptor|) constructor, when invoked, performs the following steps: + 1. Let |initial| be |descriptor|["initial"]. + 1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. + 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. + 1. Let |memtype| be { min |initial|, max |maximum| }. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let (|store|, |memaddr|) be [=mem_alloc=](|store|, |memtype|). If allocation fails, throw a {{RangeError}} exception. + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. [=initialize a memory object|Initialize=] **this** from |memaddr|. +
    + +
    + To reset the Memory buffer of |memaddr|, perform the following steps: + + 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. + 1. Assert: |map|[|memaddr|] [=map/exists=]. + 1. Let |memory| be |map|[|memaddr|]. + 1. Perform [=!=] [$DetachArrayBuffer$](|memory|.\[[BufferObject]], "WebAssembly.Memory"). + 1. Let |buffer| be the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|. + 1. Set |memory|.\[[BufferObject]] to |buffer|. +
    + +
    + The grow(|delta|) method, when invoked, performs the following steps: + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |memaddr| be **this**.\[[Memory]]. + 1. Let |ret| be the [=mem_size=](|store|, |memaddr|). + 1. Let |store| be [=mem_grow=](|store|, |memaddr|, |delta|). + 1. If |store| is [=error=], throw a {{RangeError}} exception. + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. [=Reset the memory buffer=] of |memaddr|. + 1. Return |ret|. +
    + +Immediately after a WebAssembly [=memory.grow=] instruction executes, perform the following steps: + +
    + 1. If the top of the stack is not [=i32.const=] (−1), + 1. Let |frame| be the [=current frame=]. + 1. Assert: due to validation, |frame|.[=frame/module=].[=moduleinst/memaddrs=][0] exists. + 1. Let |memaddr| be the memory address |frame|.[=frame/module=].[=moduleinst/memaddrs=][0]. + 1. [=Reset the memory buffer=] of |memaddr|. +
    + +
    + The getter of the buffer attribute of {{Memory}} returns **this**.\[[BufferObject]]. +
    + +

    Tables

    + +
    +enum TableKind {
    +  "externref",
    +  "anyfunc",
    +  // Note: More values may be added in future iterations,
    +  // e.g., typed function references, typed GC references
    +};
    +
    +dictionary TableDescriptor {
    +  required TableKind element;
    +  required [EnforceRange] unsigned long initial;
    +  [EnforceRange] unsigned long maximum;
    +};
    +
    +[LegacyNamespace=WebAssembly, Exposed=*]
    +interface Table {
    +  constructor(TableDescriptor descriptor, optional any value);
    +  unsigned long grow([EnforceRange] unsigned long delta, optional any value);
    +  any get([EnforceRange] unsigned long index);
    +  undefined set([EnforceRange] unsigned long index, optional any value);
    +  readonly attribute unsigned long length;
    +};
    +
    + +A {{Table}} object represents a single [=table instance=] which can be simultaneously referenced by +multiple {{Instance}} objects. +Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address=]. + +
    + To initialize a table object |table| from a [=table address=] |tableaddr|, perform the following steps: + 1. Let |map| be the [=surrounding agent=]'s associated [=Table object cache=]. + 1. Assert: |map|[|tableaddr|] doesn't [=map/exist=]. + 1. Set |table|.\[[Table]] to |tableaddr|. + 1. [=map/Set=] |map|[|tableaddr|] to |table|. +
    + +
    + To create a table object from a [=table address=] |tableaddr|, perform the following steps: + 1. Let |map| be the [=surrounding agent=]'s associated [=Table object cache=]. + 1. If |map|[|tableaddr|] [=map/exists=], + 1. Return |map|[|tableaddr|]. + 1. Let |table| be a [=/new=] {{Table}}. + 1. [=initialize a table object|Initialize=] |table| from |tableaddr|. + 1. Return |table|. +
    + +
    + The Table(|descriptor|, |value|) constructor, when invoked, performs the following steps: + 1. Let |elementType| be [=ToValueType=](|descriptor|["element"]). + 1. If |elementType| is not a [=reftype=], + 1. [=Throw=] a {{TypeError}} exception. + 1. Let |initial| be |descriptor|["initial"]. + 1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. + 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. + 1. If |value| is missing, + 1. Let |ref| be [=DefaultValue=](|elementType|). + 1. Otherwise, + 1. Let |ref| be [=?=] [=ToWebAssemblyValue=](|value|, |elementType|). + 1. Let |type| be the [=table type=] {[=table type|min=] |initial|, [=table type|max=] |maximum|} |elementType|. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. [=initialize a table object|Initialize=] **this** from |tableaddr|. +
    + +
    + The grow(|delta|, |value|) method, when invoked, performs the following steps: + 1. Let |tableaddr| be **this**.\[[Table]]. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |initialSize| be [=table_size=](|store|, |tableaddr|). + 1. Let (limits, |elementType|) be [=table_type=](|tableaddr|). + 1. If |value| is missing, + 1. Let |ref| be [=DefaultValue=](|elementType|). + 1. Otherwise, + 1. Let |ref| be [=?=] [=ToWebAssemblyValue=](|value|, |elementType|). + 1. Let |result| be [=table_grow=](|store|, |tableaddr|, |delta|, |ref|). + 1. If |result| is [=error=], throw a {{RangeError}} exception. + + Note: The above exception can happen due to either insufficient memory or an invalid size parameter. + + 1. Set the [=surrounding agent=]'s [=associated store=] to |result|. + 1. Return |initialSize|. +
    + +
    + The getter of the length attribute of {{Table}}, when invoked, performs the following steps: + 1. Let |tableaddr| be **this**.\[[Table]]. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Return [=table_size=](|store|, |tableaddr|). +
    + +
    + The get(|index|) method, when invoked, performs the following steps: + 1. Let |tableaddr| be **this**.\[[Table]]. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |result| be [=table_read=](|store|, |tableaddr|, |index|). + 1. If |result| is [=error=], throw a {{RangeError}} exception. + 1. Return [=ToJSValue=](|result|). +
    + +
    + The set(|index|, |value|) method, when invoked, performs the following steps: + 1. Let |tableaddr| be **this**.\[[Table]]. + 1. Let (limits, |elementType|) be [=table_type=](|tableaddr|). + 1. If |value| is missing, + 1. Let |ref| be [=DefaultValue=](|elementType|). + 1. Otherwise, + 1. Let |ref| be [=?=] [=ToWebAssemblyValue=](|value|, |elementType|). + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |store| be [=table_write=](|store|, |tableaddr|, |index|, |ref|). + 1. If |store| is [=error=], throw a {{RangeError}} exception. + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. +
    + +

    Globals

    + +
    +enum ValueType {
    +  "i32",
    +  "i64",
    +  "f32",
    +  "f64",
    +  "v128",
    +  "externref",
    +  "anyfunc",
    +};
    +
    + +Note: this type may be extended with additional cases in future versions of WebAssembly. + +
    +dictionary GlobalDescriptor {
    +  required ValueType value;
    +  boolean mutable = false;
    +};
    +
    +[LegacyNamespace=WebAssembly, Exposed=*]
    +interface Global {
    +  constructor(GlobalDescriptor descriptor, optional any v);
    +  any valueOf();
    +  attribute any value;
    +};
    +
    + +A {{Global}} object represents a single [=global instance=] +which can be simultaneously referenced by multiple {{Instance}} objects. Each +{{Global}} object has one internal slot: + + * \[[Global]] : a [=global address=] + +
    + To initialize a global object |global| from a [=global address=] |globaladdr|, perform the following steps: + 1. Let |map| be the [=surrounding agent=]'s associated [=Global object cache=]. + 1. Assert: |map|[|globaladdr|] doesn't [=map/exist=]. + 1. Set |global|.\[[Global]] to |globaladdr|. + 1. [=map/Set=] |map|[|globaladdr|] to |global|. +
    + +
    + To create a global object from a [=global address=] |globaladdr|, perform the following steps: + 1. Let |map| be the current [=agent=]'s associated [=Global object cache=]. + 1. If |map|[|globaladdr|] [=map/exists=], + 1. Return |map|[|globaladdr|]. + 1. Let |global| be a [=/new=] {{Global}}. + 1. [=initialize a global object|Initialize=] |global| from |globaladdr|. + 1. Return |global|. +
    + +
    + The algorithm ToValueType(|s|) performs the following steps: + 1. If |s| equals "i32", return [=i32=]. + 1. If |s| equals "i64", return [=i64=]. + 1. If |s| equals "f32", return [=f32=]. + 1. If |s| equals "f64", return [=f64=]. + 1. If |s| equals "v128", return [=v128=]. + 1. If |s| equals "anyfunc", return [=funcref=]. + 1. If |s| equals "externref", return [=externref=]. + 1. Assert: This step is not reached. +
    + +
    + The algorithm DefaultValue(|valuetype|) performs the following steps: + 1. If |valuetype| equals [=i32=], return [=i32.const=] 0. + 1. If |valuetype| equals [=i64=], return [=i64.const=] 0. + 1. If |valuetype| equals [=f32=], return [=f32.const=] 0. + 1. If |valuetype| equals [=f64=], return [=f64.const=] 0. + 1. If |valuetype| equals [=funcref=], return [=ref.null=] [=funcref=]. + 1. If |valuetype| equals [=externref=], return [=ToWebAssemblyValue=](undefined, |valuetype|). + 1. Assert: This step is not reached. +
    + +
    + The Global(|descriptor|, |v|) constructor, when invoked, performs the following steps: + 1. Let |mutable| be |descriptor|["mutable"]. + 1. Let |valuetype| be [=ToValueType=](|descriptor|["value"]). + 1. If |valuetype| is [=v128=], + 1. Throw a {{TypeError}} exception. + 1. If |v| is missing, + 1. Let |value| be [=DefaultValue=](|valuetype|). + 1. Otherwise, + 1. Let |value| be [=ToWebAssemblyValue=](|v|, |valuetype|). + 1. If |mutable| is true, let |globaltype| be [=var=] |valuetype|; otherwise, let |globaltype| be [=const=] |valuetype|. + 1. Let |store| be the current agent's [=associated store=]. + 1. Let (|store|, |globaladdr|) be [=global_alloc=](|store|, |globaltype|, |value|). + 1. Set the current agent's [=associated store=] to |store|. + 1. [=initialize a global object|Initialize=] **this** from |globaladdr|. +
    + +
    + The algorithm GetGlobalValue({{Global}} |global|) performs the following steps: + 1. Let |store| be the current agent's [=associated store=]. + 1. Let |globaladdr| be |global|.\[[Global]]. + 1. Let |globaltype| be [=global_type=](|store|, |globaladdr|). + 1. If |globaltype| is of the form mut [=v128=], throw a {{TypeError}}. + 1. Let |value| be [=global_read=](|store|, |globaladdr|). + 1. Return [=ToJSValue=](|value|). +
    + +
    + The getter of the value attribute of {{Global}}, when invoked, performs the following steps: + 1. Return [=GetGlobalValue=](**this**). + + The setter of the value attribute of {{Global}}, when invoked, performs the following steps: + 1. Let |store| be the current agent's [=associated store=]. + 1. Let |globaladdr| be **this**.\[[Global]]. + 1. Let |mut| |valuetype| be [=global_type=](|store|, |globaladdr|). + 1. If |valuetype| is [=v128=], throw a {{TypeError}}. + 1. If |mut| is [=const=], throw a {{TypeError}}. + 1. Let |value| be [=ToWebAssemblyValue=](**the given value**, |valuetype|). + 1. Let |store| be [=global_write=](|store|, |globaladdr|, |value|). + 1. If |store| is [=error=], throw a {{RangeError}} exception. + 1. Set the current agent's [=associated store=] to |store|. +
    + +
    + The valueOf() method, when invoked, performs the following steps: + 1. Return [=GetGlobalValue=](**this**). +
    + +

    Exported Functions

    + +A WebAssembly function is made available in JavaScript as an Exported Function. +Exported Functions are [=Built-in Function Objects=] which are not constructors, and which have a \[[FunctionAddress]] internal slot. +This slot holds a [=function address=] relative to the [=surrounding agent=]'s [=associated store=]. + +
    + The name of the WebAssembly function |funcaddr| is found by performing the following steps: + + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |funcinst| be |store|.funcs[|funcaddr|]. + 1. If |funcinst| is of the form {type functype, hostcode |hostfunc|}, + 1. Assert: |hostfunc| is a JavaScript object and [$IsCallable$](|hostfunc|) is true. + 1. Let |index| be the [=index of the host function=] |funcaddr|. + 1. Otherwise, + 1. Let |moduleinst| be |funcinst|.module. + 1. Assert: |funcaddr| is contained in |moduleinst|.funcaddrs. + 1. Let |index| be the index of |moduleinst|.funcaddrs where |funcaddr| is found. + 1. Return [=!=] [$ToString$](|index|). +
    + +
    + To create a new Exported Function from a WebAssembly [=function address=] |funcaddr|, perform the following steps: + + 1. Let |map| be the [=surrounding agent=]'s associated [=Exported Function cache=]. + 1. If |map|[|funcaddr|] [=map/exists=], + 1. Return |map|[|funcaddr|]. + 1. Let |steps| be "[=call an Exported Function|call the Exported Function=] |funcaddr| with arguments." + 1. Let |realm| be the [=current Realm=]. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |functype| be [=func_type=](|store|, |funcaddr|). + 1. Let [|paramTypes|] → [resultTypes] be |functype|. + 1. Let |arity| be |paramTypes|'s [=list/size=]. + 1. Let |name| be the [=name of the WebAssembly function=] |funcaddr|. + 1. Let |function| be [=!=] [$CreateBuiltinFunction$](|steps|, |arity|, |name|, « \[[FunctionAddress]] », |realm|). + 1. Set |function|.\[[FunctionAddress]] to |funcaddr|. + 1. [=map/Set=] |map|[|funcaddr|] to |function|. + 1. Return |function|. +
    + +
    + To call an Exported Function with [=function address=] |funcaddr| and a [=list=] of JavaScript arguments |argValues|, perform the following steps: + + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |functype| be [=func_type=](|store|, |funcaddr|). + 1. Let [|parameters|] → [|results|] be |functype|. + 1. If |parameters| or |results| contain [=v128=], throw a {{TypeError}}. + + Note: the above error is thrown each time the \[[Call]] method is invoked. + 1. Let |args| be « ». + 1. Let |i| be 0. + 1. [=list/iterate|For each=] |t| of |parameters|, + 1. If |argValues|'s [=list/size=] > |i|, let |arg| be |argValues|[|i|]. + 1. Otherwise, let |arg| be undefined. + 1. [=list/Append=] [=ToWebAssemblyValue=](|arg|, |t|) to |args|. + 1. Set |i| to |i| + 1. + 1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|). + 1. Note: The expectation is that [=func_invoke=] will be updated to return (|store|, val* | [=error=] | (exception |exntag| |payload| |opaqueData|)). + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. If |ret| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by the WebAssembly error mapping. + 1. If |ret| is exception |exntag| |payload| |opaqueData|, then + 1. If |opaqueData| is not [=ref.null=] [=externref=], + 1. Let « [=ref.extern=] |externaddr| » be |opaqueData|. + 1. Throw the result of [=retrieving an extern value=] from |externaddr|. + 1. Let |exception| be [=create an Exception object|a new Exception=] for |exntag| and |payload|. + 1. Throw |exception|. + 1. Let |outArity| be the [=list/size=] of |ret|. + 1. If |outArity| is 0, return undefined. + 1. Otherwise, if |outArity| is 1, return [=ToJSValue=](|ret|[0]). + 1. Otherwise, + 1. Let |values| be « ». + 1. [=list/iterate|For each=] |r| of |ret|, + 1. [=list/Append=] [=ToJSValue=](|r|) to |values|. + 1. Return [$CreateArrayFromList$](|values|). +
    + +Note: [=call an Exported Function|Calling an Exported Function=] executes in the \[[Realm]] of the callee Exported Function, as per the definition of [=built-in function objects=]. + +Note: Exported Functions do not have a \[[Construct]] method and thus it is not possible to call one with the `new` operator. + +
    + To run a host function from the JavaScript object |func|, type |functype|, and [=list=] of [=WebAssembly values=] |arguments|, perform the following steps: + + 1. Let [|parameters|] → [|results|] be |functype|. + 1. If |parameters| or |results| contain [=v128=], throw a {{TypeError}}. + 1. Let |jsArguments| be « ». + 1. [=list/iterate|For each=] |arg| of |arguments|, + 1. [=list/Append=] [=!=] [=ToJSValue=](|arg|) to |jsArguments|. + 1. Let |ret| be [=?=] [$Call$](|func|, undefined, |jsArguments|). + 1. Let |resultsSize| be |results|'s [=list/size=]. + 1. If |resultsSize| is 0, return « ». + 1. Otherwise, if |resultsSize| is 1, return « [=?=] [=ToWebAssemblyValue=](|ret|, |results|[0]) ». + 1. Otherwise, + 1. Let |method| be [=?=] [$GetMethod$](|ret|, {{@@iterator}}). + 1. If |method| is undefined, [=throw=] a {{TypeError}}. + 1. Let |values| be [=?=] [$IterableToList$](|ret|, |method|). + 1. Let |wasmValues| be a new, empty [=list=]. + 1. If |values|'s [=list/size=] is not |resultsSize|, throw a {{TypeError}} exception. + 1. For each |value| and |resultType| in |values| and |results|, paired linearly, + 1. [=list/Append=] [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmValues|. + 1. Return |wasmValues|. +
    + +
    + To create a host function from the JavaScript object |func| and type |functype|, perform the following steps: + + 1. Assert: [$IsCallable$](|func|). + 1. Let |stored settings| be the incumbent settings object. + 1. Let |hostfunc| be a [=host function=] which performs the following steps when called with arguments |arguments|: + 1. Let |realm| be |func|'s [=associated Realm=]. + 1. Let |relevant settings| be |realm|'s [=realm/settings object=]. + 1. [=Prepare to run script=] with |relevant settings|. + 1. [=Prepare to run a callback=] with |stored settings|. + 1. Let |result| be the result of [=run a host function|running a host function=] from |func|, |functype|, and |arguments|. + 1. [=Clean up after running a callback=] with |stored settings|. + 1. [=Clean up after running script=] with |relevant settings|. + 1. Assert: |result|.\[[Type]] is throw or normal. + 1. If |result|.\[[Type]] is throw, then: + 1. Let |v| be |result|.\[[Value]]. + 1. If |v| [=implements=] {{Exception}}, + 1. Let |type| be |v|.\[[Type]]. + 1. Let |payload| be |v|.\[[Payload]]. + 1. Otherwise, + 1. Let |type| be the [=JavaScript exception tag=]. + 1. Let |payload| be « ». + 1. Let |opaqueData| be [=ToWebAssemblyValue=](|v|, [=externref=]) + 1. [=WebAssembly/Throw=] with |type|, |payload| and |opaqueData|. + 1. Otherwise, return |result|.\[[Value]]. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|). + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. Return |funcaddr|. +
    + +
    +The algorithm ToJSValue(|w|) coerces a [=WebAssembly value=] to a JavaScript value by performing the following steps: + +1. Assert: |w| is not of the form [=v128.const=] v128. +1. If |w| is of the form [=i64.const=] |i64|, + 1. Let |v| be [=signed_64=](|i64|). + 1. Return [=ℤ=](|v| interpreted as a mathematical value). +1. If |w| is of the form [=i32.const=] |i32|, return [=𝔽=]([=signed_32=](|i32| interpreted as a mathematical value)). +1. If |w| is of the form [=f32.const=] |f32|, + 1. If |f32| is [=+∞=] or [=−∞=], return **+∞**𝔽 or **-∞**𝔽, respectively. + 1. If |f32| is [=nan=], return **NaN**. + 1. Return [=𝔽=](|f32| interpreted as a mathematical value). +1. If |w| is of the form [=f64.const=] |f64|, + 1. If |f64| is [=+∞=] or [=−∞=], return **+∞**𝔽 or **-∞**𝔽, respectively. + 1. If |f64| is [=nan=], return **NaN**. + 1. Return [=𝔽=](|f64| interpreted as a mathematical value). +1. If |w| is of the form [=ref.null=] t, return null. +1. If |w| is of the form [=ref.func=] |funcaddr|, return the result of creating [=a new Exported Function=] from |funcaddr|. +1. If |w| is of the form [=ref.extern=] |externaddr|, return the result of [=retrieving an extern value=] from |externaddr|. + +Note: Number values which are equal to NaN may have various observable NaN payloads; see [$NumericToRawBytes$] for details. +
    + +
    + +For retrieving an extern value from an [=extern address=] |externaddr|, perform the following steps: + +1. Let |map| be the [=surrounding agent=]'s associated [=extern value cache=]. +1. Assert: |map|[|externaddr|] [=map/exists=]. +1. Return |map|[|externaddr|]. + +
    + +
    +The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript value to a [=WebAssembly value=] by performing the following steps: + +1. Assert: |type| is not [=v128=]. +1. If |type| is [=i64=], + 1. Let |i64| be [=?=] [$ToBigInt64$](|v|). + 1. Return [=i64.const=] |i64|. +1. If |type| is [=i32=], + 1. Let |i32| be [=?=] [$ToInt32$](|v|). + 1. Return [=i32.const=] |i32|. +1. If |type| is [=f32=], + 1. Let |number| be [=?=] [$ToNumber$](|v|). + 1. If |number| is **NaN**, + 1. Let |n| be an implementation-defined integer such that [=canon=]32 ≤ |n| < 2[=signif=](32). + 1. Let |f32| be [=nan=](n). + 1. Otherwise, + 1. Let |f32| be |number| rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode. [[IEEE-754]] + 1. Return [=f32.const=] |f32|. +1. If |type| is [=f64=], + 1. Let |number| be [=?=] [$ToNumber$](|v|). + 1. If |number| is **NaN**, + 1. Let |n| be an implementation-defined integer such that [=canon=]64 ≤ |n| < 2[=signif=](64). + 1. Let |f64| be [=nan=](n). + 1. Otherwise, + 1. Let |f64| be |number|. + 1. Return [=f64.const=] |f64|. +1. If |type| is [=funcref=], + 1. If |v| is null, + 1. Return [=ref.null=] [=funcref=]. + 1. If |v| is an [=Exported Function=], + 1. Let |funcaddr| be the value of |v|'s \[[FunctionAddress]] internal slot. + 1. Return [=ref.func=] |funcaddr|. + 1. Throw a {{TypeError}}. +1. If |type| is [=externref=], + 1. If |v| is null, + 1. Return [=ref.null=] [=externref=]. + 1. Let |map| be the [=surrounding agent=]'s associated [=extern value cache=]. + 1. If a [=extern address=] |externaddr| exists such that |map|[|externaddr|] is the same as |v|, + 1. Return [=ref.extern=] |externaddr|. + 1. Let [=extern address=] |externaddr| be the smallest address such that |map|[|externaddr|] [=map/exists=] is false. + 1. [=map/Set=] |map|[|externaddr|] to |v|. + 1. Return [=ref.extern=] |externaddr|. +1. Assert: This step is not reached. + +
    + +

    Tags

    + +The tag_alloc(|store|, |parameters|) algorithm creates a new [=tag address=] for |parameters| in |store| and returns the updated store and the [=tag address=]. + +The tag_parameters(|store|, |tagAddress|) algorithm returns the [=list=] of types for |tagAddress| in |store|. + +

    Exception types

    + +
    +dictionary TagType {
    +  required sequence<ValueType> parameters;
    +};
    +
    +[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
    +interface Tag {
    +  constructor(TagType type);
    +  TagType type();
    +};
    +
    + +A {{Tag}} value represents a type of exception. + +
    + +To initialize a Tag object |tag| from a [=tag address=] |tagAddress|, perform the following steps: + +1. Let |map| be the [=surrounding agent=]'s associated [=Tag object cache=]. +1. Assert: |map|[|tagAddress|] doesn't [=map/exist=]. +1. Set |tag|.\[[Address]] to |tagAddress|. +1. [=map/Set=] |map|[|tagAddress|] to |tag|. + +
    + +
    + +To create a Tag object from a [=tag address=] |tagAddress|, perform the following steps: + +1. Let |map| be the [=surrounding agent=]'s associated [=Tag object cache=]. +1. If |map|[|tagAddress|] [=map/exists=], + 1. Return |map|[|tagAddress|]. +1. Let |tag| be a [=new=] {{Tag}}. +1. [=initialize a Tag object|Initialize=] |tag| from |tagAddress|. +1. Return |tag|. + +
    + +
    + +The new Tag(|type|) constructor steps are: + +1. Let |parameters| be |type|["parameters"]. +1. Let |wasmParameters| be «». +1. [=list/iterate|For each=] |type| of |parameters|, + 1. [=list/Append=] [=ToValueType=](|type|) to |wasmParameters|. +1. Let |store| be the current agent's [=associated store=]. +1. Let (|store|, |tagAddress|) be [=tag_alloc=](|store|, |wasmParameters|). +1. Set the current agent's [=associated store=] to |store|. +1. [=initialize a Tag object|Initialize=] **this** from |tagAddress|. + +
    + +
    + +The type() method steps are: + +1. Let |store| be the [=surrounding agent=]'s [=associated store=]. +1. Let |parameters| be [=tag_parameters=](|store|, **this**.\[[Address]]). +1. Let |idlParameters| be «». +1. [=list/iterate|For each=] |type| of |parameters|, + 1. [=list/Append=] [$FromValueType$](|type|) to |idlParameters|. +1. Return «[ "{{TagType/parameters}}" → |idlParameters| ]». + +Advisement: This method is only expected to be implemented or shipped when both this proposal and the Type Reflection proposal are implemented or shipped (respectively). + +
    + +

    Runtime exceptions

    + +
    +dictionary ExceptionOptions {
    +  boolean traceStack = false;
    +};
    +
    +[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
    +interface Exception {
    +  constructor(Tag exceptionTag, sequence<any> payload, optional ExceptionOptions options = {});
    +  any getArg(Tag exceptionTag, [EnforceRange] unsigned long index);
    +  boolean is(Tag exceptionTag);
    +  readonly attribute (DOMString or undefined) stack;
    +};
    +
    + +An {{Exception}} value represents an exception. + +
    + +To create an Exception object from a [=tag address=] |tagAddress| and a [=list=] of +WebAssembly values |payload|, perform the following steps: + +1. Let |store| be the [=surrounding agent=]'s [=associated store=]. +1. Let |types| be [=tag_parameters=](|store|, |tagAddress|). +1. Assert: |types|'s [=list/size=] is |payload|'s [=list/size=]. +1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly, + 1. Assert: |value|'s type matches |resultType|. +1. Let |exception| be a [=new=] {{Exception}}. +1. Set |exception|.\[[Type]] to |tagAddress|. +1. Set |exception|.\[[Payload]] to |payload|. +1. Set |exception|.\[[Stack]] to undefined. +1. Return |exception|. + +
    + +
    + +The new Exception(|exceptionTag|, |payload|, |options|) +constructor steps are: + +1. Let |store| be the [=surrounding agent=]'s [=associated store=]. +1. Let |types| be [=tag_parameters=](|store|, |exceptionTag|.\[[Address]]). +1. If |types|'s [=list/size=] is not |payload|'s [=list/size=], + 1. Throw a {{TypeError}}. +1. Let |wasmPayload| be « ». +1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly, + 1. [=list/Append=] ? [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|. +1. Set **this**.\[[Type]] to |exceptionTag|.\[[Address]]. +1. Set **this**.\[[Payload]] to |wasmPayload|. +1. If |options|["traceStack"] is true, + 1. Set **this**.\[[Stack]] to either a {{DOMString}} representation of the current call stack or undefined. +1. Otherwise, + 1. Set **this**.\[[Stack]] to undefined. + +
    + +
    + +The getArg(|exceptionTag|, |index|) method steps are: + +1. If **this**.\[[Type]] is not equal to |exceptionTag|.\[[Address]], + 1. Throw a {{TypeError}}. +1. Let |payload| be **this**.\[[Payload]]. +1. If |index| ≥ |payload|'s [=list/size=], + 1. Throw a {{RangeError}}. +1. Return [=ToJSValue=](|payload|[|index|]). + +
    + +
    + +The is(|exceptionTag|) method steps are: + +1. If **this**.\[[Type]] is not equal to |exceptionTag|.\[[Address]], + 1. Return false. +1. Return true. + +
    + +
    + +The stack getter steps are: + +1. Return **this**.\[[Stack]]. + +
    + +

    JavaScript exceptions

    + +The JavaScript exception tag is a [=tag address=] reserved by this +specification to distinguish exceptions originating from JavaScript. + +For any [=associated store=] |store|, the result of +[=tag_parameters=](|store|, [=JavaScript exception tag=]) must be « ». + +
    + +To throw with a [=tag address=] |type|, a matching [=list=] of WebAssembly values |payload|, and an [=externref=] |opaqueData|, perform the following steps: + +1. Unwind the stack until reaching the *catching try block* given |type|. +1. Invoke the catch block with |payload| and |opaqueData|. + +Note: This algorithm is expected to be moved into the core specification. + +
    + +

    Error Objects

    + +WebAssembly defines the following Error classes: CompileError, LinkError, and RuntimeError. + +
    +When the [=namespace object=] for the {{WebAssembly}} namespace is [=create a namespace object|created=], the following steps must be run: + +1. Let |namespaceObject| be the [=namespace object=]. +1. [=list/iterate|For each=] |error| of « "CompileError", "LinkError", "RuntimeError" », + 1. Let |constructor| be a new object, implementing the [=NativeError Object Structure=], with NativeError set to |error|. + 1. [=!=] [$CreateMethodProperty$](|namespaceObject|, |error|, |constructor|). + +
    + +Note: This defines {{CompileError}}, {{LinkError}}, and {{RuntimeError}} classes on the {{WebAssembly}} namespace, which are produced by the APIs defined in this specification. +They expose the same interface as native JavaScript errors like {{TypeError}} and {{RangeError}}. + +Note: It is not currently possible to define this behavior using Web IDL. + + +

    Error Condition Mappings to JavaScript

    + +Running WebAssembly programs encounter certain events which halt execution of the WebAssembly code. +WebAssembly code (currently) +has no way to catch these conditions and thus an exception will necessarily +propagate to the enclosing non-WebAssembly caller (whether it is a browser, +JavaScript or another runtime system) where it is handled like a normal JavaScript exception. + +If WebAssembly calls JavaScript via import and the JavaScript throws an +exception, the exception is propagated through the WebAssembly activation to the +enclosing caller. + +Because JavaScript exceptions can be handled, and JavaScript can continue to +call WebAssembly exports after a trap has been handled, traps do not, in +general, prevent future execution. + +

    Stack Overflow

    + +Whenever a stack overflow occurs in +WebAssembly code, the same class of exception is thrown as for a stack overflow in +JavaScript. The particular exception here is implementation-defined in both cases. + +Note: ECMAScript doesn't specify any sort of behavior on stack overflow; implementations have been observed to throw {{RangeError}}, InternalError or Error. Any is valid here. + +

    Out of Memory

    + +Whenever validation, compilation or instantiation run out of memory, the +same class of exception is thrown as for out of memory conditions in JavaScript. +The particular exception here is implementation-defined in both cases. + +Note: ECMAScript doesn't specify any sort of behavior on out-of-memory conditions; implementations have been observed to throw OOMError and to crash. Either is valid here. + +
    + A failed allocation of a large table or memory may either result in + - a {{RangeError}}, as specified in the {{Memory}} {{Memory/grow()}} and {{Table}} {{Table/grow()}} operations + - returning -1 as the [=memory.grow=] instruction + - UA-specific OOM behavior as described in this section. + In a future revision, we may reconsider more reliable and recoverable errors for allocations of large amounts of memory. + + See [Issue 879](https://github.com/WebAssembly/spec/issues/879) for further discussion. +
    + +

    Implementation-defined Limits

    + +The WebAssembly core specification allows an implementation to define limits on the syntactic structure of the module. +While each embedding of WebAssembly may choose to define its own limits, for predictability the standard WebAssembly JavaScript Interface described in this document defines the following exact limits. +An implementation must reject a module that exceeds one of the following limits with a {{CompileError}}: +In practice, an implementation may run out of resources for valid modules below these limits. + +
      +
    • The maximum size of a module is 1,073,741,824 bytes (1 GiB).
    • +
    • The maximum number of types defined in the types section is 1,000,000.
    • +
    • The maximum number of functions defined in a module is 1,000,000.
    • +
    • The maximum number of imports declared in a module is 100,000.
    • +
    • The maximum number of exports declared in a module is 100,000.
    • +
    • The maximum number of globals defined in a module is 1,000,000.
    • +
    • The maximum number of tags defined in a module is 1,000,000.
    • +
    • The maximum number of data segments defined in a module is 100,000.
    • + +
    • The maximum number of tables, including declared or imported tables, is 100,000.
    • +
    • The maximum size of a table is 10,000,000.
    • +
    • The maximum number of table entries in any table initialization is 10,000,000.
    • +
    • The maximum number of memories, including declared or imported memories, is 1.
    • + +
    • The maximum number of parameters to any function or block is 1,000.
    • +
    • The maximum number of return values for any function or block is 1,000.
    • +
    • The maximum size of a function body, including locals declarations, is 7,654,321 bytes.
    • +
    • The maximum number of locals declared in a function, including implicitly declared as parameters, is 50,000.
    • +
    + +An implementation must throw a {{RuntimeError}} if one of the following limits is exceeded during runtime: +In practice, an implementation may run out of resources for valid modules below these limits. + +
      +
    • The maximum size of a table is 10,000,000.
    • +
    • The maximum number of pages of a memory is 65,536.
    • +
    + +

    Security and Privacy Considerations

    + +

    This section is non-normative.

    + +This document defines a host environment for WebAssembly. It enables a WebAssembly instance to [=import=] JavaScript objects and functions from an [=read the imports|import object=], but otherwise provides no access to the embedding environment. Thus a WebAssembly instance is bound to the same constraints as JavaScript. diff --git a/document/metadata/code/.gitignore b/document/metadata/code/.gitignore new file mode 100644 index 0000000000..b932ec283e --- /dev/null +++ b/document/metadata/code/.gitignore @@ -0,0 +1,3 @@ +_build +_static +document/*.pyc diff --git a/document/metadata/code/LICENSE b/document/metadata/code/LICENSE new file mode 100644 index 0000000000..795b406e4e --- /dev/null +++ b/document/metadata/code/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/metadata/code/Makefile b/document/metadata/code/Makefile new file mode 100644 index 0000000000..e8b975c727 --- /dev/null +++ b/document/metadata/code/Makefile @@ -0,0 +1,361 @@ +# 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-Metadata-Code + +# 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 deploy + +.PHONY: all +all: pdf html + +.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. + + +%.rst: %.py + (cd `dirname $@`; ./`basename $^`) + +.PHONY: pdf +pdf: 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) + +.PHONY: html +html: + $(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: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +.PHONY: singlehtml +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +.PHONY: bikeshed +bikeshed: + $(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-core-aux +latex-core-aux: + (cd ../../core; make BUILDDIR=$(BUILDDIR) latexpdf) + mkdir -p $(BUILDDIR)/latex + cp ../../core/$(BUILDDIR)/latex/WebAssembly.aux $(BUILDDIR)/latex/ + +.PHONY: latex +latex: latex-core-aux + $(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: latex-core-aux + $(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: latex-core-aux + $(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/metadata/code/README.md b/document/metadata/code/README.md new file mode 100644 index 0000000000..d5fe68ce8d --- /dev/null +++ b/document/metadata/code/README.md @@ -0,0 +1,25 @@ +# WebAssembly Code Metadata Specification + +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/metadata/code/binary.rst b/document/metadata/code/binary.rst new file mode 100644 index 0000000000..1b17265513 --- /dev/null +++ b/document/metadata/code/binary.rst @@ -0,0 +1,69 @@ +.. _binary: + +Binary Format +============= + +.. _binary-codemetadata: + +Code Metadata +------------- + +A Code Metadata item is a piece of information logically attached to an instruction. + +An item is associated with a format, which defines the item's payload. + +All code metadata items of a format named *T* are grouped under a custom section +named *'metadata.code.T'*. +The following parametrized grammar rules define the generic structure of a code metadata +section of format *T*. + +.. math:: + \begin{array}{llcll} + \production{code metadata section} & \Bcodemetadatasec(\B{T}) &::=& + \Bsection_0(\Bcodemetadata(\B{T})) \\ + \production{code metadata} & \Bcodemetadata(\B{T}) &::=& + n{:}\Bname & (\iff n = \text{metadata.code.T}) \\ &&& + \Bvec(\Bcodemetadatafunc(\B{T})) \\ + \production{code metadata function} & \Bcodemetadatafunc(\B{T}) &::=& + x{:}\Bfuncidx~\Bvec(\Bcodemetadataitem(\B{T})) \\ + \production{code metadata item} & \Bcodemetadataitem(\B{T}) &::=& + \X{off}{:}\Bu32 ~~ \X{size}{:}\Bu32 & (\iff \X{size} = ||\B{T}||) \\ &&& + \X{data}{:}\B{T} \\ + \end{array} +.. index:: ! code metadata section + +Where :math:`\X{off}` is the byte offset of the attached instruction, relative to the beginning of the |Bfunc| declaration, and :math:`\X{data}` is a further payload, whose content depends on the format :math:`T`. + +|Bcodemetadatafunc| entries must appear in order of increasing :math:`x`, and duplicate id values are not allowed. |Bcodemetadata| entries must appear in order of increasing :math:`\X{off}`, and duplicate offset values are not allowed. + +.. _binary-branchhints: + +Branch Hints +~~~~~~~~~~~~ + +A Branch Hint is a code metadata item with format *branch_hint*. + +It can only be attached to |BRIF| and |IF| instructions. + +Its payload indicates whether the branch is likely or unlikely to be taken. + +All branch hints for a module are contained in a single code metadata section +with name *'metadata.code.branch_hint'*. + +.. math:: + \begin{array}{llcll} + \production{branch hint section} & \Bbranchhintsec &::=& + \Bcodemetadatasec(\Bbranchhint) \\ + \production{branch hint} & \Bbranchhint &::=& + \Bunlikely \\ &&|& + \Blikely \\ + \production{unlikely} & \Bunlikely &::=& + \hex{00} \\ + \production{likely} & \Blikely &::=& + \hex{01} \\ + \end{array} +.. index:: ! branch hint section + +A value of |Blikely| means that the branch is likely to be taken, while a +value of |Bunlikely| means the opposite. A branch with no hints is considered +equally likely to be taken or not. diff --git a/document/metadata/code/conf.py b/document/metadata/code/conf.py new file mode 100644 index 0000000000..bff6550b48 --- /dev/null +++ b/document/metadata/code/conf.py @@ -0,0 +1,505 @@ +# -*- 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 + +core_dir = os.path.abspath('../../core') +sys.path.insert(0, core_dir) +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-Metadata-Code' +project = u'WebAssembly-Metadata-Code' +title = u'WebAssembly Code Metadata Specification' +copyright = u'2024, WebAssembly Community Group' +author = u'WebAssembly Community Group' +editor = u'Yuri Iozzelli (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 = '' +# 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': { + '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 = u'WebAssembly Custom Sections' + +# 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 = False + +# 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\\externaldocument[Core-]{WebAssembly}[https://webassembly.github.io//'+repo+'/core/_download/WebAssembly.pdf]\n', + + # Latex figure (float) alignment + 'figure_align': 'htbp', + + # Fancy chapters [Bjarne, Sonny, Lenny, Glenn, Conny, Rejne] + 'fncychap': '\\usepackage[Sonny]{fncychap}', + + # Allow chapters to start on even pages + 'extraclassoptions': 'openany', + + 'extrapackages': '\\usepackage{xr-hyper}', +} + +# 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, + 'howto' + ), +] + +# 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:: /""" + core_dir + """/util/macros.def +.. 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/metadata/code/index.rst b/document/metadata/code/index.rst new file mode 100644 index 0000000000..7485244829 --- /dev/null +++ b/document/metadata/code/index.rst @@ -0,0 +1,15 @@ +WebAssembly Code Metadata +========================= + +.. only:: html + + | Editor: Yuri Iozzelli + + | Issue Tracker: |WasmIssues| + +.. toctree:: + :maxdepth: 1 + + intro + binary + text diff --git a/document/metadata/code/intro.rst b/document/metadata/code/intro.rst new file mode 100644 index 0000000000..59503b413e --- /dev/null +++ b/document/metadata/code/intro.rst @@ -0,0 +1,18 @@ +.. _intro: + +Introduction +============ + +This document defines a generic mechanism for attaching arbitrary metadata to WebAssembly instructions. +Additionally, it defines specific metadata formats using this mechanism. + +Such metadata does not contribute to, or otherwise affect, the WebAssembly semantics, and may be ignored by an implementation. + +However, it can provides useful information that implementations can make use of to improve user experience or take compilation hints. + +Dependencies +~~~~~~~~~~~~ + +This document is based on the WebAssembly core specification (|WasmDraft|), and makes use of +terms and definitions described there. These uses always link to the corresponding definition +in the core specification. diff --git a/document/metadata/code/static/custom.css b/document/metadata/code/static/custom.css new file mode 100644 index 0000000000..33bb863d42 --- /dev/null +++ b/document/metadata/code/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/metadata/code/static/webassembly.png b/document/metadata/code/static/webassembly.png new file mode 100644 index 0000000000..f9edc61098 Binary files /dev/null and b/document/metadata/code/static/webassembly.png differ diff --git a/document/metadata/code/text.rst b/document/metadata/code/text.rst new file mode 100644 index 0000000000..c5ff1fbd04 --- /dev/null +++ b/document/metadata/code/text.rst @@ -0,0 +1,24 @@ +.. _text: + +Text Format +=========== + +.. _text-codemetadata: + +Code Metadata +------------- + +Code Metadata items appear in the text format as custom annotations, and are considered +attached to the first instruction that follows them. + + +.. math:: + \begin{array}{llclll} + \production{code metadata annotation} & \Tcodemetadataannot(\B{T}) &::=& + \text{(@metadata.code.T}~\X{data}{:}\B{T}~\text{)} \\ + \end{array} +.. index:: ! code metadata annotation + +Where `T` is the format name of the item, and `data` is a byte string containing the same +payload as in the binary format. + diff --git a/document/metadata/code/util/macros.def b/document/metadata/code/util/macros.def new file mode 100644 index 0000000000..fbdd841402 --- /dev/null +++ b/document/metadata/code/util/macros.def @@ -0,0 +1,44 @@ +.. LINK MACROS + +.. External Standards +.. ------------------ + +.. External Definitions +.. -------------------- + + +.. MATH MACROS + +.. Abstract Syntax +.. --------------- + +.. Values, non-terminals + + +.. Binary Format +.. ------------- + +.. Code Metadata, non-terminals + +.. |Bcodemetadatasec| mathdef:: \xref{binary}{binary-codemetadata}{\B{codemetadatasec}} +.. |Bcodemetadata| mathdef:: \xref{binary}{binary-codemetadata}{\B{codemetadata}} +.. |Bcodemetadatafunc| mathdef:: \xref{binary}{binary-codemetadata}{\B{codemetadatafunc}} +.. |Bcodemetadataitem| mathdef:: \xref{binary}{binary-codemetadata}{\B{codemetadataitem}} + +.. Branch Hints, non-terminals + +.. |Bbranchhintsec| mathdef:: \xref{binary}{binary-branchhints}{\B{branchhintsec}} +.. |Bbranchhint| mathdef:: \xref{binary}{binary-branchhints}{\B{branchhint}} +.. |Bunlikely| mathdef:: \xref{binary}{binary-branchhints}{\B{unlikely}} +.. |Blikely| mathdef:: \xref{binary}{binary-branchhints}{\B{likely}} + + +.. Text Format +.. ----------- + + \production{code metadata annotation} & \Tcodemetadataannot(\B{T}) &::=& + +.. Branch Hints, non-terminals + +.. |Tcodemetadataannot| mathdef:: \xref{text}{text-codemetadata}{\T{codemetadataannot}} + diff --git a/document/metadata/code/util/mathdef.py b/document/metadata/code/util/mathdef.py new file mode 100644 index 0000000000..57a6cf043d --- /dev/null +++ b/document/metadata/code/util/mathdef.py @@ -0,0 +1,128 @@ +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): + if "/" in file: + return '\\href{../../core/%s.html#%s}' % (file, id.replace('_', '-')) + else: + 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('\\', '_') + if "/" in file: + return '\\hyperref[Core-%s:%s]' % (file, id) + else: + 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/web-api/index.bs b/document/web-api/index.bs index 5bd1dac2c6..efc6a66635 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -1,5 +1,5 @@ @@ -67,6 +73,7 @@ urlPrefix: https://webassembly.github.io/spec/js-api/; spec: WASMJS text: Exported Function; url: #exported-function url:https://html.spec.whatwg.org/#cors-same-origin;text:CORS-same-origin;type:dfn;spec:HTML url:https://fetch.spec.whatwg.org/#concept-body-consume-body;text:consume body;type:dfn;spec:FETCH +url:https://w3c.github.io/webappsec-secure-contexts/#environment-settings-object-contextually-secure; text:contextually secure; type: dfn; spec: SECURECONTEXTS