Full Code of WebAssembly/reference-types for AI

master c7a3558bb5cb cached
321 files
4.9 MB
1.3M tokens
370 symbols
1 requests
Download .txt
Showing preview only (5,178K chars total). Download the full file or copy to clipboard to get everything.
Repository: WebAssembly/reference-types
Branch: master
Commit: c7a3558bb5cb
Files: 321
Total size: 4.9 MB

Directory structure:
gitextract_qmxq1s8y/

├── .gitattributes
├── .gitignore
├── .gitmodules
├── .travis.yml
├── Contributing.md
├── LICENSE
├── README.md
├── deploy_key.enc
├── document/
│   ├── Makefile
│   ├── README.md
│   ├── core/
│   │   ├── .gitignore
│   │   ├── LICENSE
│   │   ├── Makefile
│   │   ├── README.md
│   │   ├── appendix/
│   │   │   ├── algorithm.rst
│   │   │   ├── custom.rst
│   │   │   ├── embedding.rst
│   │   │   ├── gen-index-instructions.py
│   │   │   ├── implementation.rst
│   │   │   ├── index-instructions.rst
│   │   │   ├── index-rules.rst
│   │   │   ├── index-types.rst
│   │   │   ├── index.rst
│   │   │   └── properties.rst
│   │   ├── binary/
│   │   │   ├── conventions.rst
│   │   │   ├── index.rst
│   │   │   ├── instructions.rst
│   │   │   ├── modules.rst
│   │   │   ├── types.rst
│   │   │   └── values.rst
│   │   ├── conf.py
│   │   ├── exec/
│   │   │   ├── conventions.rst
│   │   │   ├── index.rst
│   │   │   ├── instructions.rst
│   │   │   ├── modules.rst
│   │   │   ├── numerics.rst
│   │   │   └── runtime.rst
│   │   ├── index.bs
│   │   ├── index.rst
│   │   ├── intro/
│   │   │   ├── index.rst
│   │   │   ├── introduction.rst
│   │   │   └── overview.rst
│   │   ├── make.bat
│   │   ├── static/
│   │   │   └── custom.css
│   │   ├── syntax/
│   │   │   ├── conventions.rst
│   │   │   ├── index.rst
│   │   │   ├── instructions.rst
│   │   │   ├── modules.rst
│   │   │   ├── types.rst
│   │   │   └── values.rst
│   │   ├── text/
│   │   │   ├── conventions.rst
│   │   │   ├── index.rst
│   │   │   ├── instructions.rst
│   │   │   ├── lexical.rst
│   │   │   ├── modules.rst
│   │   │   ├── types.rst
│   │   │   └── values.rst
│   │   ├── util/
│   │   │   ├── README.htmldiff.pl
│   │   │   ├── bikeshed/
│   │   │   │   └── conf.py
│   │   │   ├── bikeshed_fixup.py
│   │   │   ├── katex_fix.patch
│   │   │   ├── macros.def
│   │   │   ├── mathdef.py
│   │   │   ├── mathdefbs.py
│   │   │   ├── mathjax2katex.py
│   │   │   └── pseudo-lexer.py
│   │   └── valid/
│   │       ├── conventions.rst
│   │       ├── index.rst
│   │       ├── instructions.rst
│   │       ├── modules.rst
│   │       └── types.rst
│   ├── deploy.sh
│   ├── index.html
│   ├── js-api/
│   │   ├── Makefile
│   │   └── index.bs
│   ├── travis-deploy.sh
│   ├── util/
│   │   └── htmldiff.pl
│   └── web-api/
│       ├── Makefile
│       └── index.bs
├── interpreter/
│   ├── .gitignore
│   ├── .merlin
│   ├── LICENSE
│   ├── Makefile
│   ├── README.md
│   ├── binary/
│   │   ├── decode.ml
│   │   ├── decode.mli
│   │   ├── encode.ml
│   │   ├── encode.mli
│   │   ├── utf8.ml
│   │   └── utf8.mli
│   ├── exec/
│   │   ├── eval.ml
│   │   ├── eval.mli
│   │   ├── eval_numeric.ml
│   │   ├── eval_numeric.mli
│   │   ├── f32.ml
│   │   ├── f32_convert.ml
│   │   ├── f32_convert.mli
│   │   ├── f64.ml
│   │   ├── f64_convert.ml
│   │   ├── f64_convert.mli
│   │   ├── float.ml
│   │   ├── i32.ml
│   │   ├── i32_convert.ml
│   │   ├── i32_convert.mli
│   │   ├── i64.ml
│   │   ├── i64_convert.ml
│   │   ├── i64_convert.mli
│   │   ├── int.ml
│   │   └── numeric_error.ml
│   ├── host/
│   │   ├── env.ml
│   │   └── spectest.ml
│   ├── main/
│   │   ├── flags.ml
│   │   └── main.ml
│   ├── meta/
│   │   ├── findlib/
│   │   │   └── META
│   │   ├── jslib/
│   │   │   ├── bsconfig.json
│   │   │   ├── build.sh
│   │   │   └── wasm.ml
│   │   └── travis/
│   │       ├── build-test.sh
│   │       └── install-ocaml.sh
│   ├── runtime/
│   │   ├── func.ml
│   │   ├── func.mli
│   │   ├── global.ml
│   │   ├── global.mli
│   │   ├── instance.ml
│   │   ├── memory.ml
│   │   ├── memory.mli
│   │   ├── table.ml
│   │   └── table.mli
│   ├── script/
│   │   ├── import.ml
│   │   ├── import.mli
│   │   ├── js.ml
│   │   ├── js.mli
│   │   ├── run.ml
│   │   ├── run.mli
│   │   └── script.ml
│   ├── syntax/
│   │   ├── ast.ml
│   │   ├── free.ml
│   │   ├── free.mli
│   │   ├── operators.ml
│   │   ├── types.ml
│   │   └── values.ml
│   ├── text/
│   │   ├── arrange.ml
│   │   ├── arrange.mli
│   │   ├── lexer.mli
│   │   ├── lexer.mll
│   │   ├── parse.ml
│   │   ├── parse.mli
│   │   ├── parser.mly
│   │   ├── print.ml
│   │   └── print.mli
│   ├── util/
│   │   ├── error.ml
│   │   ├── error.mli
│   │   ├── lib.ml
│   │   ├── lib.mli
│   │   ├── sexpr.ml
│   │   ├── sexpr.mli
│   │   ├── source.ml
│   │   └── source.mli
│   ├── valid/
│   │   ├── valid.ml
│   │   └── valid.mli
│   └── winmake.bat
├── papers/
│   ├── LICENSE
│   └── README.md
├── proposals/
│   ├── README.md
│   ├── bulk-memory-operations/
│   │   └── Overview.md
│   ├── multi-value/
│   │   └── Overview.md
│   ├── nontrapping-float-to-int-conversion/
│   │   └── Overview.md
│   ├── reference-types/
│   │   └── Overview.md
│   └── sign-extension-ops/
│       └── Overview.md
├── test/
│   ├── LICENSE
│   ├── README.md
│   ├── Todo.md
│   ├── build.py
│   ├── core/
│   │   ├── .gitignore
│   │   ├── README.md
│   │   ├── address.wast
│   │   ├── align.wast
│   │   ├── binary-leb128.wast
│   │   ├── binary.wast
│   │   ├── block.wast
│   │   ├── br.wast
│   │   ├── br_if.wast
│   │   ├── br_table.wast
│   │   ├── bulk.wast
│   │   ├── call.wast
│   │   ├── call_indirect.wast
│   │   ├── comments.wast
│   │   ├── const.wast
│   │   ├── conversions.wast
│   │   ├── custom.wast
│   │   ├── data.wast
│   │   ├── elem.wast
│   │   ├── endianness.wast
│   │   ├── exports.wast
│   │   ├── f32.wast
│   │   ├── f32_bitwise.wast
│   │   ├── f32_cmp.wast
│   │   ├── f64.wast
│   │   ├── f64_bitwise.wast
│   │   ├── f64_cmp.wast
│   │   ├── fac.wast
│   │   ├── float_exprs.wast
│   │   ├── float_literals.wast
│   │   ├── float_memory.wast
│   │   ├── float_misc.wast
│   │   ├── forward.wast
│   │   ├── func.wast
│   │   ├── func_ptrs.wast
│   │   ├── global.wast
│   │   ├── i32.wast
│   │   ├── i64.wast
│   │   ├── if.wast
│   │   ├── imports.wast
│   │   ├── inline-module.wast
│   │   ├── int_exprs.wast
│   │   ├── int_literals.wast
│   │   ├── labels.wast
│   │   ├── left-to-right.wast
│   │   ├── linking.wast
│   │   ├── load.wast
│   │   ├── local_get.wast
│   │   ├── local_set.wast
│   │   ├── local_tee.wast
│   │   ├── loop.wast
│   │   ├── memory.wast
│   │   ├── memory_copy.wast
│   │   ├── memory_fill.wast
│   │   ├── memory_grow.wast
│   │   ├── memory_init.wast
│   │   ├── memory_redundancy.wast
│   │   ├── memory_size.wast
│   │   ├── memory_trap.wast
│   │   ├── names.wast
│   │   ├── nop.wast
│   │   ├── ref_func.wast
│   │   ├── ref_is_null.wast
│   │   ├── ref_null.wast
│   │   ├── return.wast
│   │   ├── run.py
│   │   ├── select.wast
│   │   ├── skip-stack-guard-page.wast
│   │   ├── stack.wast
│   │   ├── start.wast
│   │   ├── store.wast
│   │   ├── switch.wast
│   │   ├── table-sub.wast
│   │   ├── table.wast
│   │   ├── table_copy.wast
│   │   ├── table_fill.wast
│   │   ├── table_get.wast
│   │   ├── table_grow.wast
│   │   ├── table_init.wast
│   │   ├── table_set.wast
│   │   ├── table_size.wast
│   │   ├── token.wast
│   │   ├── traps.wast
│   │   ├── type.wast
│   │   ├── unreachable.wast
│   │   ├── unreached-invalid.wast
│   │   ├── unwind.wast
│   │   ├── utf8-custom-section-id.wast
│   │   ├── utf8-import-field.wast
│   │   ├── utf8-import-module.wast
│   │   └── utf8-invalid-encoding.wast
│   ├── harness/
│   │   ├── async_index.js
│   │   ├── sync_index.js
│   │   ├── testharness.css
│   │   ├── testharness.js
│   │   └── testharnessreport.js
│   ├── js-api/
│   │   ├── LICENSE.md
│   │   ├── README.md
│   │   ├── assertions.js
│   │   ├── bad-imports.js
│   │   ├── constructor/
│   │   │   ├── compile.any.js
│   │   │   ├── instantiate-bad-imports.any.js
│   │   │   ├── instantiate.any.js
│   │   │   ├── multi-value.any.js
│   │   │   └── validate.any.js
│   │   ├── error-interfaces-no-symbol-tostringtag.js
│   │   ├── global/
│   │   │   ├── constructor.any.js
│   │   │   ├── toString.any.js
│   │   │   ├── value-get-set.any.js
│   │   │   └── valueOf.any.js
│   │   ├── instance/
│   │   │   ├── constructor-bad-imports.any.js
│   │   │   ├── constructor-caching.any.js
│   │   │   ├── constructor.any.js
│   │   │   ├── exports.any.js
│   │   │   └── toString.any.js
│   │   ├── instanceTestFactory.js
│   │   ├── interface.any.js
│   │   ├── limits.any.js
│   │   ├── memory/
│   │   │   ├── assertions.js
│   │   │   ├── buffer.any.js
│   │   │   ├── constructor.any.js
│   │   │   ├── grow.any.js
│   │   │   └── toString.any.js
│   │   ├── module/
│   │   │   ├── constructor.any.js
│   │   │   ├── customSections.any.js
│   │   │   ├── exports.any.js
│   │   │   ├── imports.any.js
│   │   │   └── toString.any.js
│   │   ├── prototypes.any.js
│   │   ├── table/
│   │   │   ├── assertions.js
│   │   │   ├── constructor.any.js
│   │   │   ├── get-set.any.js
│   │   │   ├── grow.any.js
│   │   │   ├── length.any.js
│   │   │   └── toString.any.js
│   │   └── wasm-module-builder.js
│   ├── meta/
│   │   ├── Makefile
│   │   ├── README.md
│   │   ├── common.js
│   │   ├── generate_memory_copy.js
│   │   ├── generate_memory_fill.js
│   │   ├── generate_memory_init.js
│   │   ├── generate_table_copy.js
│   │   ├── generate_table_init.js
│   │   └── noderun.sh
│   └── sync-js-api.py
├── w3c.json
└── wasm-specs.bib

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitattributes
================================================
*.rst linguist-documentation=false
document/* linguist-documentation=false
document/*.rst linguist-documentation=false
document/*/*.rst linguist-documentation=false
test/harness/wast.js linguist-vendored
test/harness/testharness* linguist-vendored



================================================
FILE: .gitignore
================================================
**/*~
**/*.tmproj
**/*.pyc
**/_build
**/_output


================================================
FILE: .gitmodules
================================================
[submodule "document/core/util/katex"]
	path = document/core/util/katex
	url = https://github.com/KaTeX/KaTeX.git


================================================
FILE: .travis.yml
================================================
language: python
python:
  - "3.7"
dist: bionic

addons:
  apt:
    sources:
      - sourceline: 'ppa:avsm/ppa'
      - sourceline: 'deb https://dl.yarnpkg.com/debian/ stable main'
        key_url: 'https://dl.yarnpkg.com/debian/pubkey.gpg'
    update: true
    packages:
      - opam
      - texlive-full
      - yarn

install:
  - opam init --auto-setup --compiler=4.07.1
  - eval $(opam env)
  - opam --version
  - ocaml --version
  - opam install --yes ocamlbuild.0.14.0
  - pip install Sphinx==2.4.4
  - git clone https://github.com/tabatkins/bikeshed.git
  - pip install --editable $PWD/bikeshed
  - bikeshed update

script:
  - ./interpreter/meta/travis/build-test.sh
  - bash ./document/travis-deploy.sh

os: linux

env:
  global:
    - ENCRYPTION_LABEL: "5d9ec396f41d"
    - COMMIT_AUTHOR_EMAIL: "noreply@webassembly.org"


================================================
FILE: Contributing.md
================================================
# Contributing to WebAssembly

Interested in participating? Please follow
[the same contributing guidelines as the design repository][].

  [the same contributing guidelines as the design repository]: https://github.com/WebAssembly/design/blob/master/Contributing.md

Also, please be sure to read [the README.md](README.md) for this repository.


================================================
FILE: LICENSE
================================================
Please see the LICENSE file in each top-level directory for the terms applicable to that directory and its relative sub-directories.

The relevant directories and licenses are:

document/    - W3C Software and Document Notice and License
interpreter/ - Apache License 2.0
test/        - Apache License 2.0
papers/      - Creative Commons Attribution 4.0 International License


================================================
FILE: README.md
================================================
[![Build Status](https://travis-ci.org/WebAssembly/reference-types.svg?branch=master)](https://travis-ci.org/WebAssembly/reference-types)

# Reference Types Proposal for WebAssembly

This repository is a clone of [github.com/WebAssembly/spec/](https://github.com/WebAssembly/spec/).
It is meant for discussion, prototype specification and implementation of a proposal to add support for basic reference types to WebAssembly.

* See the [overview](proposals/reference-types/Overview.md) for a summary of the proposal.

* See the [modified spec](https://webassembly.github.io/reference-types/core/) for details.

The repository is now based on the [bulk operations proposal](proposals/bulk-memory-operations/Overview.md) and includes all respective changes.

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.

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".

Participation is welcome. Discussions about new features, significant semantic
changes, or any specification change likely to generate substantial discussion
should take place in
[the WebAssembly design repository](https://github.com/WebAssembly/design)
first, so that this spec repository can remain focused. And please follow the
[guidelines for contributing](Contributing.md).

# citing

For citing WebAssembly in LaTeX, use [this bibtex file](wasm-specs.bib).


================================================
FILE: document/Makefile
================================================
DIRS     = core js-api web-api
FILES    = index.html
BUILDDIR = _build

# Global targets.

.PHONY: all
all: $(BUILDDIR) root $(DIRS)

$(BUILDDIR):
	mkdir -p $@

.PHONY: deploy
deploy:
	GIT_DEPLOY_DIR=$(BUILDDIR) bash deploy.sh

.PHONY: publish
publish: all deploy

.PHONY: clean
clean: $(DIRS:%=clean-%)
	rm -rf $(BUILDDIR)

.PHONY: diff
diff: $(DIRS:%=diff-%)


# Directory-specific targets.

.PHONY: root
root: $(BUILDDIR)
	touch $(BUILDDIR)/.nojekyll
	cp -f $(FILES) $(BUILDDIR)/

.PHONY: $(DIRS)
$(DIRS): %: $(BUILDDIR) $(DIRS:%=build-%) $(DIRS:%=dir-%)

.PHONY: $(DIRS:%=build-%)
$(DIRS:%=build-%): build-%:
	(cd $(@:build-%=%); make BUILDDIR=$(BUILDDIR) all)

.PHONY: $(DIRS:%=dir-%)
$(DIRS:%=dir-%): dir-%:
	mkdir -p $(BUILDDIR)/$(@:dir-%=%)
	rm -rf $(BUILDDIR)/$(@:dir-%=%)/*
	cp -R $(@:dir-%=%)/$(BUILDDIR)/html/* $(BUILDDIR)/$(@:dir-%=%)/

.PHONY: $(DIRS:%=deploy-%)
$(DIRS:%=deploy-%): deploy-%:
	GIT_DEPLOY_DIR=$(BUILDDIR) GIT_DEPLOY_SUBDIR=$(@:deploy-%=%) bash deploy.sh

.PHONY: $(DIRS:%=publish-%)
$(DIRS:%=publish-%): publish-%: % deploy-%

.PHONY: $(DIRS:%=clean-%)
$(DIRS:%=clean-%): clean-%:
	(cd $(@:clean-%=%); make BUILDDIR=$(BUILDDIR) clean)
	rm -rf $(BUILDDIR)/$(@:clean-%=%)

.PHONY: $(DIRS:%=diff-%)
$(DIRS:%=diff-%): diff-%:
	(cd $(@:diff-%=%); make BUILDDIR=$(BUILDDIR) diff)


# Help.

.PHONY: help
help:
	@echo "Please use \`make <target>' where <target> is one of"
	@echo "  all             to build all documents"
	@echo "  publish         to make all and push to gh-pages"
	@echo "  <dir>           to build a specific subdirectory"
	@echo "  publish-<dir>   to build and push a specific subdirectory"

.PHONY: usage
usage: help


================================================
FILE: document/README.md
================================================
# WebAssembly Specifications

This directory contains the source code for the WebAssembly spec documents, as served from the [webassembly.github.io/spec](https://webassembly.github.io/spec) pages.
It uses [Sphinx](http://www.sphinx-doc.org/) and [Bikeshed](https://github.com/tabatkins/bikeshed).

To install Sphinx:
```
pip install sphinx
```

To install Bikeshed, see the instructions [here](https://tabatkins.github.io/bikeshed/#installing).


To build everything locally (result appears in `_build/`):
```
make all
```

To build everything and update [webassembly.github.io/spec](https://webassembly.github.io/spec) with it:
```
make publish
```
Please make sure to only use that once a change has approval.

## Step by step guide to building the spec

### Prerequisites

You will need `python3.7`, and `pip`. `pip` should come with Python, if not follow [these installation instructions for `pip`](https://pip.pypa.io/en/stable/installing/), or check your system package manager for `pip3`.

> Important: you will need the version of pip that works with `python3.7`.


Use something like [`pipenv`](https://pipenv.pypa.io/) to keep your system installation of Python clean.

```
pip install pipenv
pipenv --python 3.7
pipenv shell
```

Install Python dependencies:

```
pip install Sphinx==2.4.4
```

### Checking out the repository

Make sure this repository was cloned with `--recursive`:

```
git clone --recursive https://github.com/WebAssembly/spec
```

If you have already cloned but without `--recursive`, you can delete and re-clone, or `cd` into `spec` and run:

```
git submodule update --init --recursive
```

The rest of these instructions assume you are in the directory where is README is:

```
cd spec/document
```

### Building the multi-page HTML document

You can now build the [multi-page html document](https://webassembly.github.io/spec/core/):

```
make -C core html
```

### Building the single-page HTML document

To build the [single-page W3C version](https://webassembly.github.io/spec/core/bikeshed/), there are more dependencies to install. First, get [Bikeshed](https://github.com/tabatkins/bikeshed):

```
# cd back to root of git directory
git clone https://github.com/tabatkins/bikeshed.git
pip install --editable bikeshed
bikeshed update
```

You will also need `npm` and `yarn` for all the LaTeX goodness. `npm` might already be available on your system, you can also use something like [`nvm`](https://github.com/nvm-sh/nvm) to prevent messing with system packages:

```
npm install -g yarn
cd document
make -C core bikeshed
```

### Building the PDF

To build the [PDF](https://webassembly.github.io/spec/core/_download/WebAssembly.pdf), you will need `texlive-full`, install it using your system package manager:

```
apt install texlive-full
make -C core pdf
```

### Building the JavaScript Embedding API

To build the [JavaScript Embedding API](https://webassembly.github.io/spec/js-api/index.html), you will need `bikeshed` as describe in the section [Building the single-page HTML document](#building-the-single-page-html-document):

```
make -C js-api
```

### Building the Web Embedding API

To build the [Web Embedding API](https://webassembly.github.io/spec/web-api/index.html), you will need `bikeshed` as describe in the section [Building the single-page HTML document](#building-the-single-page-html-document):

```
make -C web-api
```


================================================
FILE: document/core/.gitignore
================================================
_build
_static
document/*.pyc


================================================
FILE: document/core/LICENSE
================================================
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


================================================
FILE: document/core/Makefile
================================================
# Makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS    =
SPHINXBUILD   = sphinx-build
PAPER         = a4
BUILDDIR      = _build
STATICDIR     = _static
DOWNLOADDIR   = _download
NAME          = WebAssembly

# Internal variables.
PAPEROPT_a4     = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

.PHONY: usage
usage:
	@echo "Please use \`make <target>' where <target> 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 <target>' where <target> 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.


.PHONY: index
index:
	(cd appendix; ./gen-index-instructions.py)

.PHONY: pdf
pdf:	index 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: index
	$(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
	python util/bikeshed_fixup.py $(BUILDDIR)/bikeshed_singlehtml/index.html \
		>$(BUILDDIR)/bikeshed_singlehtml/index_fixed.html
	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)
	python 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:
	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
	@echo "Running LaTeX files through pdflatex..."
	$(MAKE) -C $(BUILDDIR)/latex LATEXMKOPTS=" </dev/null" all-pdf >$(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."


================================================
FILE: document/core/README.md
================================================
# WebAssembly Core 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.


================================================
FILE: document/core/appendix/algorithm.rst
================================================
.. index:: validation, algorithm, instruction, module, binary format, opcode
.. _algo-valid:

Validation Algorithm
--------------------

The specification of WebAssembly :ref:`validation <valid>` is purely *declarative*.
It describes the constraints that must be met by a :ref:`module <valid-module>` or :ref:`instruction <valid-instr>` sequence to be valid.

This section sketches the skeleton of a sound and complete *algorithm* for effectively validating code, i.e., sequences of :ref:`instructions <syntax-instr>`.
(Other aspects of validation are straightforward to implement.)

In fact, the algorithm is expressed over the flat sequence of opcodes as occurring in the :ref:`binary format <binary>`, and performs only a single pass over it.
Consequently, it can be integrated directly into a decoder.

The algorithm is expressed in typed pseudo code whose semantics is intended to be self-explanatory.


.. index:: value type, stack, label, frame, instruction

Data Structures
~~~~~~~~~~~~~~~

Types are representable as an enumeration.

.. code-block:: pseudo

   type val_type = I32 | I64 | F32 | F64 | Funcref | Externref

   func is_num(t : val_type | Unknown) : bool =
     return t = I32 || t = I64 || t = F32 || t = F64 || t = Unknown

   func is_ref(t : val_type | Unknown) : bool =
     return t = Funcref || t = Externref || t = Unknown

The algorithm uses two separate stacks: the *value stack* and the *control stack*.
The former tracks the :ref:`types <syntax-valtype>` of operand values on the :ref:`stack <stack>`,
the latter surrounding :ref:`structured control instructions <syntax-instr-control>` and their associated :ref:`blocks <syntax-instr-control>`.

.. code-block:: pseudo

   type val_stack = stack(val_type | Unknown)

   type ctrl_stack = stack(ctrl_frame)
   type ctrl_frame = {
     opcode : opcode
     start_types : list(val_type)
     end_types : list(val_type)
     height : nat
     unreachable : bool
   }

For each value, the value stack records its :ref:`value type <syntax-valtype>`, or :code:`Unknown` when the type is not known.

For each entered block, the control stack records a *control frame* with the originating opcode, the types on the top of the operand stack at the start and end of the block (used to check its result as well as branches), the height of the operand stack at the start of the block (used to check that operands do not underflow the current block), and a flag recording whether the remainder of the block is unreachable (used to handle :ref:`stack-polymorphic <polymorphism>` typing after branches).

For the purpose of presenting the algorithm, the operand and control stacks are simply maintained as global variables:

.. code-block:: pseudo

   var vals : val_stack
   var ctrls : ctrl_stack

However, these variables are not manipulated directly by the main checking function, but through a set of auxiliary functions:

.. code-block:: pseudo

   func push_val(type : val_type | Unknown) =
     vals.push(type)

   func pop_val() : val_type | Unknown =
     if (vals.size() = ctrls[0].height && ctrls[0].unreachable) return Unknown
     error_if(vals.size() = ctrls[0].height)
     return vals.pop()

   func pop_val(expect : val_type | Unknown) : val_type | Unknown =
     let actual = pop_val()
     if (actual = Unknown) return expect
     if (expect = Unknown) return actual
     error_if(actual =/= expect)
     return actual

   func push_vals(types : list(val_type)) = foreach (t in types) push_val(t)
   func pop_vals(types : list(val_type)) : list(val_type) =
     var popped := []
     foreach (t in reverse(types)) popped.append(pop_val(t))
     return popped

Pushing an operand value simply pushes the respective type to the value stack.

Popping an operand value checks that the value stack does not underflow the current block and then removes one type.
But first, a special case is handled where the block contains no known values, but has been marked as unreachable.
That can occur after an unconditional branch, when the stack is typed :ref:`polymorphically <polymorphism>`.
In that case, an unknown type is returned.

A second function for popping an operand value takes an expected type, which the actual operand type is checked against.
The types may differ in case one of them is Unknown.
The function returns the actual type popped from the stack.

Finally, there are accumulative functions for pushing or popping multiple operand types.

.. note::
   The notation :code:`stack[i]` is meant to index the stack from the top,
   so that, e.g., :code:`ctrls[0]` accesses the element pushed last.


The control stack is likewise manipulated through auxiliary functions:

.. code-block:: pseudo

   func push_ctrl(opcode : opcode, in : list(val_type), out : list(val_type)) =
     let frame = ctrl_frame(opcode, in, out, vals.size(), false)
     ctrls.push(frame)
     push_vals(in)

   func pop_ctrl() : ctrl_frame =
     error_if(ctrls.is_empty())
     let frame = ctrls[0]
     pop_vals(frame.end_types)
     error_if(vals.size() =/= frame.height)
     ctrls.pop()
     return frame

   func label_types(frame : ctrl_frame) : list(val_types) =
     return (if frame.opcode == loop then frame.start_types else frame.end_types)

   func unreachable() =
     vals.resize(ctrls[0].height)
     ctrls[0].unreachable := true

Pushing a control frame takes the types of the label and result values.
It allocates a new frame record recording them along with the current height of the operand stack and marks the block as reachable.

Popping a frame first checks that the control stack is not empty.
It then verifies that the operand stack contains the right types of values expected at the end of the exited block and pops them off the operand stack.
Afterwards, it checks that the stack has shrunk back to its initial height.

The type of the :ref:`label <syntax-label>` associated with a control frame is either that of the stack at the start or the end of the frame, determined by the opcode that it originates from.

Finally, the current frame can be marked as unreachable.
In that case, all existing operand types are purged from the value stack, in order to allow for the :ref:`stack-polymorphism <polymorphism>` logic in :code:`pop_val` to take effect.

.. note::
   Even with the unreachable flag set, consecutive operands are still pushed to and popped from the operand stack.
   That is necessary to detect invalid :ref:`examples <polymorphism>` like :math:`(\UNREACHABLE~(\I32.\CONST)~\I64.\ADD)`.
   However, a polymorphic stack cannot underflow, but instead generates :code:`Unknown` types as needed.


.. index:: opcode

Validation of Opcode Sequences
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following function shows the validation of a number of representative instructions that manipulate the stack.
Other instructions are checked in a similar manner.

.. note::
   Various instructions not shown here will additionally require the presence of a validation :ref:`context <context>` for checking uses of :ref:`indices <syntax-index>`.
   That is an easy addition and therefore omitted from this presentation.

.. code-block:: pseudo

   func validate(opcode) =
     switch (opcode)
       case (i32.add)
         pop_val(I32)
         pop_val(I32)
         push_val(I32)

       case (drop)
         pop_val()

       case (select)
         pop_val(I32)
         let t1 = pop_val()
         let t2 = pop_val()
         error_if(not (is_num(t1) && is_num(t2)))
         error_if(t1 =/= t2 && t1 =/= Unknown && t2 =/= Unknown)
         push_val(if (t1 = Unknown) t2 else t1)

       case (select t)
         pop_val(I32)
         pop_val(t)
         pop_val(t)
         push_val(t)

       case (unreachable)
         unreachable()

       case (block t1*->t2*)
         pop_vals([t1*])
         push_ctrl(block, [t1*], [t2*])

       case (loop t1*->t2*)
         pop_vals([t1*])
         push_ctrl(loop, [t1*], [t2*])

       case (if t1*->t2*)
         pop_val(I32)
         pop_vals([t1*])
         push_ctrl(if, [t1*], [t2*])

       case (end)
         let frame = pop_ctrl()
         push_vals(frame.end_types)

       case (else)
         let frame = pop_ctrl()
         error_if(frame.opcode =/= if)
         push_ctrl(else, frame.start_types, frame.end_types)

       case (br n)
         error_if(ctrls.size() < n)
         pop_vals(label_types(ctrls[n]))
         unreachable()

       case (br_if n)
         error_if(ctrls.size() < n)
         pop_val(I32)
         pop_vals(label_types(ctrls[n]))
         push_vals(label_types(ctrls[n]))

       case (br_table n* m)
         pop_val(I32)
         error_if(ctrls.size() < m)
         let arity = label_types(ctrls[m]).size()
         foreach (n in n*)
           error_if(ctrls.size() < n)
           error_if(label_types(ctrls[n]).size() =/= arity)
           push_vals(pop_vals(label_types(ctrls[n])))
         pop_vals(label_types(ctrls[m]))
         unreachable()


.. note::
   It is an invariant under the current WebAssembly instruction set that an operand of :code:`Unknown` type is never duplicated on the stack.
   This would change if the language were extended with stack instructions like :code:`dup`.
   Under such an extension, the above algorithm would need to be refined by replacing the :code:`Unknown` type with proper *type variables* to ensure that all uses are consistent.


================================================
FILE: document/core/appendix/custom.rst
================================================
.. index:: custom section, section, binary format

Custom Sections
---------------

This appendix defines dedicated :ref:`custom sections <binary-customsec>` for WebAssembly's :ref:`binary format <binary>`.
Such sections do not contribute to, or otherwise affect, the WebAssembly semantics, and like any custom section they may be ignored by an implementation.
However, they provide useful meta data that implementations can make use of to improve user experience or take compilation hints.

Currently, only one dedicated custom section is defined, the :ref:`name section<binary-namesec>`.


.. index:: ! name section, name, Unicode UTF-8
.. _binary-namesec:

Name Section
~~~~~~~~~~~~

The *name section* is a :ref:`custom section <binary-customsec>` whose name string is itself :math:`\text{name}`.
The name section should appear only once in a module, and only after the :ref:`data section <binary-datasec>`.

The purpose of this section is to attach printable names to definitions in a module, which e.g. can be used by a debugger or when parts of the module are to be rendered in :ref:`text form <text>`.

.. note::
   All :ref:`names <binary-name>` are represented in |Unicode|_ encoded in UTF-8.
   Names need not be unique.


.. _binary-namesubsection:

Subsections
...........

The :ref:`data <binary-customsec>` of a name section consists of a sequence of *subsections*.
Each subsection consists of a

* a one-byte subsection *id*,
* the |U32| *size* of the contents, in bytes,
* the actual *contents*, whose structure is depended on the subsection id.

.. math::
   \begin{array}{llcll}
   \production{name section} & \Bnamesec &::=&
     \Bsection_0(\Bnamedata) \\
   \production{name data} & \Bnamedata &::=&
     n{:}\Bname & (\iff n = \text{name}) \\ &&&
     \Bmodulenamesubsec^? \\ &&&
     \Bfuncnamesubsec^? \\ &&&
     \Blocalnamesubsec^? \\
   \production{name subsection} & \Bnamesubsection_N(\B{B}) &::=&
     N{:}\Bbyte~~\X{size}{:}\Bu32~~\B{B}
       & (\iff \X{size} = ||\B{B}||) \\
   \end{array}

The following subsection ids are used:

==  ===========================================
Id  Subsection                                 
==  ===========================================
 0  :ref:`module name <binary-modulenamesec>`
 1  :ref:`function names <binary-funcnamesec>`    
 2  :ref:`local names <binary-localnamesec>`
==  ===========================================

Each subsection may occur at most once, and in order of increasing id.


.. index:: ! name map, index, index space
.. _binary-indirectnamemap:
.. _binary-namemap:

Name Maps
.........

A *name map* assigns :ref:`names <syntax-name>` to :ref:`indices <syntax-index>` in a given :ref:`index space <syntax-index>`.
It consists of a :ref:`vector <binary-vec>` of index/name pairs in order of increasing index value.
Each index must be unique, but the assigned names need not be.

.. math::
   \begin{array}{llclll}
   \production{name map} & \Bnamemap &::=&
     \Bvec(\Bnameassoc) \\
   \production{name association} & \Bnameassoc &::=&
     \Bidx~\Bname \\
   \end{array}

An *indirect name map* assigns :ref:`names <syntax-name>` to a two-dimensional :ref:`index space <syntax-index>`, where secondary indices are *grouped* by primary indices.
It consists of a vector of primary index/name map pairs in order of increasing index value, where each name map in turn maps secondary indices to names.
Each primary index must be unique, and likewise each secondary index per individual name map.

.. math::
   \begin{array}{llclll}
   \production{indirect name map} & \Bindirectnamemap &::=&
     \Bvec(\Bindirectnameassoc) \\
   \production{indirect name association} & \Bindirectnameassoc &::=&
     \Bidx~\Bnamemap \\
   \end{array}


.. index:: module
.. _binary-modulenamesec:

Module Names
............

The *module name subsection* has the id 0.
It simply consists of a single :ref:`name <binary-name>` that is assigned to the module itself.

.. math::
   \begin{array}{llclll}
   \production{module name subsection} & \Bmodulenamesubsec &::=&
     \Bnamesubsection_0(\Bname) \\
   \end{array}


.. index:: function, function index
.. _binary-funcnamesec:

Function Names
..............

The *function name subsection* has the id 1.
It consists of a :ref:`name map <binary-namemap>` assigning function names to :ref:`function indices <syntax-funcidx>`.

.. math::
   \begin{array}{llclll}
   \production{function name subsection} & \Bfuncnamesubsec &::=&
     \Bnamesubsection_1(\Bnamemap) \\
   \end{array}


.. index:: function, local, function index, local index
.. _binary-localnamesec:

Local Names
...........

The *local name subsection* has the id 2.
It consists of an :ref:`indirect name map <binary-indirectnamemap>` assigning local names to :ref:`local indices <syntax-localidx>` grouped by :ref:`function indices <syntax-funcidx>`.

.. math::
   \begin{array}{llclll}
   \production{local name subsection} & \Blocalnamesubsec &::=&
     \Bnamesubsection_2(\Bindirectnamemap) \\
   \end{array}


================================================
FILE: document/core/appendix/embedding.rst
================================================
.. index:: ! embedding, embedder, implementation, host
.. _embed:

Embedding
---------

A WebAssembly implementation will typically be *embedded* into a *host* environment.
An *embedder* implements the connection between such a host environment and the WebAssembly semantics as defined in the main body of this specification.
An embedder is expected to interact with the semantics in well-defined ways.

This section defines a suitable interface to the WebAssembly semantics in the form of entry points through which an embedder can access it.
The interface is intended to be complete, in the sense that an embedder does not need to reference other functional parts of the WebAssembly specification directly.

.. note::
   On the other hand, an embedder does not need to provide the host environment with access to all functionality defined in this interface.
   For example, an implementation may not support :ref:`parsing <embed-module-parse>` of the :ref:`text format <text>`.

Types
~~~~~

In the description of the embedder interface, syntactic classes from the :ref:`abstract syntax <syntax>` and the :ref:`runtime's abstract machine <syntax-runtime>` are used as names for variables that range over the possible objects from that class.
Hence, these syntactic classes can also be interpreted as types.

For numeric parameters, notation like :math:`n:\u32` is used to specify a symbolic name in addition to the respective value range.


.. _embed-error:

Errors
~~~~~~

Failure of an interface operation is 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 <impl>` 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
~~~~~~~~~~~~~~~~~~~~~~~~

Some operations state *pre-conditions* about their arguments or *post-conditions* about their results.
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 <syntax-runtime>` (:math:`store`, :math:`\moduleinst`, :math:`\externval`, :ref:`addresses <syntax-addr>`):

* Every runtime object passed as a parameter must be :ref:`valid <valid-store>` per an implicit pre-condition.

* Every runtime object returned as a result is :ref:`valid <valid-store>` per an implicit post-condition.

.. note::
   As long as an embedder treats runtime objects as abstract and only creates and manipulates them through the interface defined here, all implicit pre-conditions are automatically met.



.. index:: allocation, store
.. _embed-store:

Store
~~~~~

.. _embed-store-init:

:math:`\F{store\_init}() : \store`
..................................

1. Return the empty :ref:`store <syntax-store>`.

.. math::
   \begin{array}{lclll}
   \F{store\_init}() &=& \{ \SFUNCS~\epsilon,~ \SMEMS~\epsilon,~ \STABLES~\epsilon,~ \SGLOBALS~\epsilon \} \\
   \end{array}



.. index:: module
.. _embed-module:

Modules
~~~~~~~

.. index:: binary format
.. _embed-module-decode:

:math:`\F{module\_decode}(\byte^\ast) : \module ~|~ \error`
...........................................................

1. If there exists a derivation for the :ref:`byte <syntax-byte>` sequence :math:`\byte^\ast` as a :math:`\Bmodule` according to the :ref:`binary grammar for modules <binary-module>`, yielding a :ref:`module <syntax-module>` :math:`m`, then return :math:`m`.

2. Else, return :math:`\ERROR`.

.. math::
   \begin{array}{lclll}
   \F{module\_decode}(b^\ast) &=& m && (\iff \Bmodule \stackrel\ast\Longrightarrow m{:}b^\ast) \\
   \F{module\_decode}(b^\ast) &=& \ERROR && (\otherwise) \\
   \end{array}


.. index:: text format
.. _embed-module-parse:

:math:`\F{module\_parse}(\char^\ast) : \module ~|~ \error`
..........................................................

1. If there exists a derivation for the :ref:`source <text-source>` :math:`\char^\ast` as a :math:`\Tmodule` according to the :ref:`text grammar for modules <text-module>`, yielding a :ref:`module <syntax-module>` :math:`m`, then return :math:`m`.

2. Else, return :math:`\ERROR`.

.. math::
   \begin{array}{lclll}
   \F{module\_parse}(c^\ast) &=& m && (\iff \Tmodule \stackrel\ast\Longrightarrow m{:}c^\ast) \\
   \F{module\_parse}(c^\ast) &=& \ERROR && (\otherwise) \\
   \end{array}


.. index:: validation
.. _embed-module-validate:

:math:`\F{module\_validate}(\module) : \error^?`
................................................

1. If :math:`\module` is :ref:`valid <valid-module>`, then return nothing.

2. Else, return :math:`\ERROR`.

.. math::
   \begin{array}{lclll}
   \F{module\_validate}(m) &=& \epsilon && (\iff {} \vdashmodule m : \externtype^\ast \to {\externtype'}^\ast) \\
   \F{module\_validate}(m) &=& \ERROR && (\otherwise) \\
   \end{array}


.. index:: instantiation, module instance
.. _embed-module-instantiate:

:math:`\F{module\_instantiate}(\store, \module, \externval^\ast) : (\store, \moduleinst ~|~ \error)`
....................................................................................................

1. Try :ref:`instantiating <exec-instantiation>` :math:`\module` in :math:`\store` with :ref:`external values <syntax-externval>` :math:`\externval^\ast` as imports:

  a. If it succeeds with a :ref:`module instance <syntax-moduleinst>` :math:`\moduleinst`, then let :math:`\X{result}` be :math:`\moduleinst`.

  b. Else, let :math:`\X{result}` be :math:`\ERROR`.

2. Return the new store paired with :math:`\X{result}`.

.. 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) \\
   \end{array}

.. note::
   The store may be modified even in case of an error.


.. index:: import
.. _embed-module-imports:

:math:`\F{module\_imports}(\module) : (\name, \name, \externtype)^\ast`
.......................................................................

1. Pre-condition: :math:`\module` is :ref:`valid <valid-module>` with external import types :math:`\externtype^\ast` and external export types :math:`{\externtype'}^\ast`.

2. Let :math:`\import^\ast` be the :ref:`imports <syntax-import>` :math:`\module.\MIMPORTS`.

3. Assert: the length of :math:`\import^\ast` equals the length of :math:`\externtype^\ast`.

4. For each :math:`\import_i` in :math:`\import^\ast` and corresponding :math:`\externtype_i` in :math:`\externtype^\ast`, do:

  a. Let :math:`\X{result}_i` be the triple :math:`(\import_i.\IMODULE, \import_i.\INAME, \externtype_i)`.

5. Return the concatenation of all :math:`\X{result}_i`, in index order.

6. Post-condition: each :math:`\externtype_i` is :ref:`valid <valid-externtype>`.

.. math::
   ~ \\
   \begin{array}{lclll}
   \F{module\_imports}(m) &=& (\X{im}.\IMODULE, \X{im}.\INAME, \externtype)^\ast \\
     && \qquad (\iff \X{im}^\ast = m.\MIMPORTS \wedge {} \vdashmodule m : \externtype^\ast \to {\externtype'}^\ast) \\
   \end{array}


.. index:: export
.. _embed-module-exports:

:math:`\F{module\_exports}(\module) : (\name, \externtype)^\ast`
................................................................

1. Pre-condition: :math:`\module` is :ref:`valid <valid-module>` with external import types :math:`\externtype^\ast` and external export types :math:`{\externtype'}^\ast`.

2. Let :math:`\export^\ast` be the :ref:`exports <syntax-export>` :math:`\module.\MEXPORTS`.

3. Assert: the length of :math:`\export^\ast` equals the length of :math:`{\externtype'}^\ast`.

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)`.

5. Return the concatenation of all :math:`\X{result}_i`, in index order.

6. Post-condition: each :math:`\externtype'_i` is :ref:`valid <valid-externtype>`.

.. math::
   ~ \\
   \begin{array}{lclll}
   \F{module\_exports}(m) &=& (\X{ex}.\ENAME, \externtype')^\ast \\
     && \qquad (\iff \X{ex}^\ast = m.\MEXPORTS \wedge {} \vdashmodule m : \externtype^\ast \to {\externtype'}^\ast) \\
   \end{array}


.. index:: module, module instance
.. _embed-instance:

Module Instances
~~~~~~~~~~~~~~~~

.. index:: export, export instance

.. _embed-instance-export:

:math:`\F{instance\_export}(\moduleinst, \name) : \externval ~|~ \error`
........................................................................

1. Assert: due to :ref:`validity <valid-moduleinst>` of the :ref:`module instance <syntax-moduleinst>` :math:`\moduleinst`, all its :ref:`export names <syntax-exportinst>` are different.

2. If there exists an :math:`\exportinst_i` in :math:`\moduleinst.\MIEXPORTS` such that :ref:`name <syntax-name>` :math:`\exportinst_i.\EINAME` equals :math:`\name`, then:

   a. Return the :ref:`external value <syntax-externval>` :math:`\exportinst_i.\EIVALUE`.

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) &=& \ERROR && (\otherwise) \\
   \end{array}


.. index:: function, host function, function address, function instance, function type, store
.. _embed-func:

Functions
~~~~~~~~~

.. _embed-func-alloc:

:math:`\F{func\_alloc}(\store, \functype, \hostfunc) : (\store, \funcaddr)`
...........................................................................

1. Pre-condition: :math:`\functype` is :math:`valid <valid-functype>`.

2. Let :math:`\funcaddr` be the result of :ref:`allocating a host function <alloc-func>` in :math:`\store` with :ref:`function type <syntax-functype>` :math:`\functype` and host function code :math:`\hostfunc`.

3. Return the new store paired with :math:`\funcaddr`.

.. math::
   \begin{array}{lclll}
   \F{func\_alloc}(S, \X{ft}, \X{code}) &=& (S', \X{a}) && (\iff \allochostfunc(S, \X{ft}, \X{code}) = S', \X{a}) \\
   \end{array}

.. note::
   This operation assumes that :math:`\hostfunc` satisfies the :ref:`pre- and post-conditions <exec-invoke-host>` required for a function instance with type :math:`\functype`.

   Regular (non-host) function instances can only be created indirectly through :ref:`module instantiation <embed-module-instantiate>`.


.. _embed-func-type:

:math:`\F{func\_type}(\store, \funcaddr) : \functype`
.....................................................

1. Return :math:`S.\SFUNCS[a].\FITYPE`.

2. Post-condition: the returned :ref:`function type <syntax-functype>` is :ref:`valid <valid-functype>`.

.. math::
   \begin{array}{lclll}
   \F{func\_type}(S, a) &=& S.\SFUNCS[a].\FITYPE \\
   \end{array}


.. index:: invocation, value, result
.. _embed-func-invoke:

:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \error)`
........................................................................................

1. Try :ref:`invoking <exec-invocation>` the function :math:`\funcaddr` in :math:`\store` with :ref:`values <syntax-val>` :math:`\val^\ast` as arguments:

  a. If it succeeds with :ref:`values <syntax-val>` :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`.

2. Return the new store paired with :math:`\X{result}`.

.. math::
   ~ \\
   \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', \ERROR) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \TRAP) \\
   \end{array}

.. note::
   The store may be modified even in case of an error.


.. index:: table, table address, store, table instance, table type, element, function address
.. _embed-table:

Tables
~~~~~~

.. _embed-table-alloc:

:math:`\F{table\_alloc}(\store, \tabletype) : (\store, \tableaddr, \reff)`
..........................................................................

1. Pre-condition: :math:`\tabletype` is :math:`valid <valid-tabletype>`.

2. Let :math:`\tableaddr` be the result of :ref:`allocating a table <alloc-table>` in :math:`\store` with :ref:`table type <syntax-tabletype>` :math:`\tabletype` and initialization value :math:`\reff`.

3. Return the new store paired with :math:`\tableaddr`.

.. math::
   \begin{array}{lclll}
   \F{table\_alloc}(S, \X{tt}, r) &=& (S', \X{a}) && (\iff \alloctable(S, \X{tt}, r) = S', \X{a}) \\
   \end{array}


.. _embed-table-type:

:math:`\F{table\_type}(\store, \tableaddr) : \tabletype`
........................................................

1. Return :math:`S.\STABLES[a].\TITYPE`.

2. Post-condition: the returned :ref:`table type <syntax-tabletype>` is :math:`valid <valid-tabletype>`.

.. math::
   \begin{array}{lclll}
   \F{table\_type}(S, a) &=& S.\STABLES[a].\TITYPE \\
   \end{array}


.. _embed-table-read:

:math:`\F{table\_read}(\store, \tableaddr, i:\u32) : \reff ~|~ \error`
......................................................................

1. Let :math:`\X{ti}` be the :ref:`table instance <syntax-tableinst>` :math:`\store.\STABLES[\tableaddr]`.

2. If :math:`i` is larger than or equal to the length of :math:`\X{ti}.\TIELEM`, then return :math:`\ERROR`.

3. Else, return the :ref:`reference value <syntax-ref>` :math:`\X{ti}.\TIELEM[i]`.

.. math::
   \begin{array}{lclll}
   \F{table\_read}(S, a, i) &=& r && (\iff S.\STABLES[a].\TIELEM[i] = r) \\
   \F{table\_read}(S, a, i) &=& \ERROR && (\otherwise) \\
   \end{array}


.. _embed-table-write:

:math:`\F{table\_write}(\store, \tableaddr, i:\u32, \reff) : \store ~|~ \error`
...............................................................................

1. Let :math:`\X{ti}` be the :ref:`table instance <syntax-tableinst>` :math:`\store.\STABLES[\tableaddr]`.

2. If :math:`i` is larger than or equal to the length of :math:`\X{ti}.\TIELEM`, then return :math:`\ERROR`.

3. Replace :math:`\X{ti}.\TIELEM[i]` with the :ref:`reference value <syntax-ref>` :math:`\reff`.

4. Return the updated store.

.. math::
   \begin{array}{lclll}
   \F{table\_write}(S, a, i, r) &=& S' && (\iff S' = S \with \STABLES[a].\TIELEM[i] = r) \\
   \F{table\_write}(S, a, i, r) &=& \ERROR && (\otherwise) \\
   \end{array}


.. _embed-table-size:

:math:`\F{table\_size}(\store, \tableaddr) : \u32`
..................................................

1. Return the length of :math:`\store.\STABLES[\tableaddr].\TIELEM`.

.. math::
   ~ \\
   \begin{array}{lclll}
   \F{table\_size}(S, a) &=& n &&
     (\iff |S.\STABLES[a].\TIELEM| = n) \\
   \end{array}



.. _embed-table-grow:

:math:`\F{table\_grow}(\store, \tableaddr, n:\u32, \reff) : \store ~|~ \error`
..............................................................................

1. Try :ref:`growing <grow-table>` the :ref:`table instance <syntax-tableinst>` :math:`\store.\STABLES[\tableaddr]` by :math:`n` elements with initialization value :math:`\reff`:

   a. If it succeeds, return the updated store.

   b. Else, return :math:`\ERROR`.

.. math::
   ~ \\
   \begin{array}{lclll}
   \F{table\_grow}(S, a, n, r) &=& S' &&
     (\iff S' = S \with \STABLES[a] = \growtable(S.\STABLES[a], n, r)) \\
   \F{table\_grow}(S, a, n, r) &=& \ERROR && (\otherwise) \\
   \end{array}


.. index:: memory, memory address, store, memory instance, memory type, byte
.. _embed-mem:

Memories
~~~~~~~~

.. _embed-mem-alloc:

:math:`\F{mem\_alloc}(\store, \memtype) : (\store, \memaddr)`
................................................................

1. Pre-condition: :math:`\memtype` is :math:`valid <valid-memtype>`.

2. Let :math:`\memaddr` be the result of :ref:`allocating a memory <alloc-mem>` in :math:`\store` with :ref:`memory type <syntax-memtype>` :math:`\memtype`.

3. Return the new store paired with :math:`\memaddr`.

.. math::
   \begin{array}{lclll}
   \F{mem\_alloc}(S, \X{mt}) &=& (S', \X{a}) && (\iff \allocmem(S, \X{mt}) = S', \X{a}) \\
   \end{array}


.. _embed-mem-type:

:math:`\F{mem\_type}(\store, \memaddr) : \memtype`
..................................................

1. Return :math:`S.\SMEMS[a].\MITYPE`.

2. Post-condition: the returned :ref:`memory type <syntax-memtype>` is :math:`valid <valid-memtype>`.

.. math::
   \begin{array}{lclll}
   \F{mem\_type}(S, a) &=& S.\SMEMS[a].\MITYPE \\
   \end{array}


.. _embed-mem-read:

:math:`\F{mem\_read}(\store, \memaddr, i:\u32) : \byte ~|~ \error`
..................................................................

1. Let :math:`\X{mi}` be the :ref:`memory instance <syntax-meminst>` :math:`\store.\SMEMS[\memaddr]`.

2. If :math:`i` is larger than or equal to the length of :math:`\X{mi}.\MIDATA`, then return :math:`\ERROR`.

3. Else, return the  :ref:`byte <syntax-byte>` :math:`\X{mi}.\MIDATA[i]`.

.. math::
   \begin{array}{lclll}
   \F{mem\_read}(S, a, i) &=& b && (\iff S.\SMEMS[a].\MIDATA[i] = b) \\
   \F{mem\_read}(S, a, i) &=& \ERROR && (\otherwise) \\
   \end{array}


.. _embed-mem-write:

:math:`\F{mem\_write}(\store, \memaddr, i:\u32, \byte) : \store ~|~ \error`
...........................................................................

1. Let :math:`\X{mi}` be the :ref:`memory instance <syntax-meminst>` :math:`\store.\SMEMS[\memaddr]`.

2. If :math:`\u32` is larger than or equal to the length of :math:`\X{mi}.\MIDATA`, then return :math:`\ERROR`.

3. Replace :math:`\X{mi}.\MIDATA[i]` with :math:`\byte`.

4. Return the updated store.

.. math::
   \begin{array}{lclll}
   \F{mem\_write}(S, a, i, b) &=& S' && (\iff S' = S \with \SMEMS[a].\MIDATA[i] = b) \\
   \F{mem\_write}(S, a, i, b) &=& \ERROR && (\otherwise) \\
   \end{array}


.. _embed-mem-size:

:math:`\F{mem\_size}(\store, \memaddr) : \u32`
..............................................

1. Return the length of :math:`\store.\SMEMS[\memaddr].\MIDATA` divided by the :ref:`page size <page-size>`.

.. math::
   ~ \\
   \begin{array}{lclll}
   \F{mem\_size}(S, a) &=& n &&
     (\iff |S.\SMEMS[a].\MIDATA| = n \cdot 64\,\F{Ki}) \\
   \end{array}



.. _embed-mem-grow:

:math:`\F{mem\_grow}(\store, \memaddr, n:\u32) : \store ~|~ \error`
...................................................................

1. Try :ref:`growing <grow-mem>` the :ref:`memory instance <syntax-meminst>` :math:`\store.\SMEMS[\memaddr]` by :math:`n` :ref:`pages <page-size>`:

   a. If it succeeds, return the updated store.

   b. Else, return :math:`\ERROR`.

.. math::
   ~ \\
   \begin{array}{lclll}
   \F{mem\_grow}(S, a, n) &=& S' &&
     (\iff S' = S \with \SMEMS[a] = \growmem(S.\SMEMS[a], n)) \\
   \F{mem\_grow}(S, a, n) &=& \ERROR && (\otherwise) \\
   \end{array}



.. index:: global, global address, store, global instance, global type, value
.. _embed-global:

Globals
~~~~~~~

.. _embed-global-alloc:

:math:`\F{global\_alloc}(\store, \globaltype, \val) : (\store, \globaladdr)`
............................................................................

1. Pre-condition: :math:`\globaltype` is :math:`valid <valid-globaltype>`.

2. Let :math:`\globaladdr` be the result of :ref:`allocating a global <alloc-global>` in :math:`\store` with :ref:`global type <syntax-globaltype>` :math:`\globaltype` and initialization value :math:`\val`.

3. Return the new store paired with :math:`\globaladdr`.

.. math::
   \begin{array}{lclll}
   \F{global\_alloc}(S, \X{gt}, v) &=& (S', \X{a}) && (\iff \allocglobal(S, \X{gt}, v) = S', \X{a}) \\
   \end{array}


.. _embed-global-type:

:math:`\F{global\_type}(\store, \globaladdr) : \globaltype`
...........................................................

1. Return :math:`S.\SGLOBALS[a].\GITYPE`.

2. Post-condition: the returned :ref:`global type <syntax-globaltype>` is :math:`valid <valid-globaltype>`.

.. math::
   \begin{array}{lclll}
   \F{global\_type}(S, a) &=& S.\SGLOBALS[a].\GITYPE \\
   \end{array}


.. _embed-global-read:

:math:`\F{global\_read}(\store, \globaladdr) : \val`
....................................................

1. Let :math:`\X{gi}` be the :ref:`global instance <syntax-globalinst>` :math:`\store.\SGLOBALS[\globaladdr]`.

2. Return the :ref:`value <syntax-val>` :math:`\X{gi}.\GIVALUE`.

.. math::
   \begin{array}{lclll}
   \F{global\_read}(S, a) &=& v && (\iff S.\SGLOBALS[a].\GIVALUE = v) \\
   \end{array}


.. _embed-global-write:

:math:`\F{global\_write}(\store, \globaladdr, \val) : \store ~|~ \error`
........................................................................

1. Let :math:`\X{gi}` be the :ref:`global instance <syntax-globalinst>` :math:`\store.\SGLOBALS[\globaladdr]`.

2. Let :math:`\mut~t` be the structure of the :ref:`global type <syntax-globaltype>` :math:`\X{gi}.\GITYPE`.

3. If :math:`\mut` is not :math:`\MVAR`, then return :math:`\ERROR`.

4. Replace :math:`\X{gi}.\GIVALUE` with the :ref:`value <syntax-val>` :math:`\val`.

5. Return the updated store.

.. math::
   ~ \\
   \begin{array}{lclll}
   \F{global\_write}(S, a, v) &=& S' && (\iff S.\SGLOBALS[a].\GITYPE = \MVAR~t \wedge S' = S \with \SGLOBALS[a].\GIVALUE = v) \\
   \F{global\_write}(S, a, v) &=& \ERROR && (\otherwise) \\
   \end{array}


================================================
FILE: document/core/appendix/gen-index-instructions.py
================================================
#!/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 gen-index-instructions.py script.

.. index:: instruction
.. _index-instr:

Index of Instructions
---------------------
"""

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):
    if operator:
        execution_str = ', '.join([RefWrap(execution, 'execution'),
                                   RefWrap(operator, 'operator')])
    else:
        execution_str = RefWrap(execution, 'execution')

    return (
        MathWrap(name, '(reserved)'),
        MathWrap(opcode),
        MathWrap(type),
        RefWrap(validation, 'validation'),
        execution_str
    )


INSTRUCTIONS = [
    Instruction(r'\UNREACHABLE', r'\hex{00}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-unreachable', r'exec-unreachable'),
    Instruction(r'\NOP', r'\hex{01}', r'[] \to []', r'valid-nop', r'exec-nop'),
    Instruction(r'\BLOCK~\X{bt}', r'\hex{02}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-block', r'exec-block'),
    Instruction(r'\LOOP~\X{bt}', r'\hex{03}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-loop', r'exec-loop'),
    Instruction(r'\IF~\X{bt}', r'\hex{04}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-if', r'exec-if'),
    Instruction(r'\ELSE', r'\hex{05}'),
    Instruction(None, r'\hex{06}'),
    Instruction(None, r'\hex{07}'),
    Instruction(None, r'\hex{08}'),
    Instruction(None, r'\hex{09}'),
    Instruction(None, r'\hex{0A}'),
    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'),
    Instruction(r'\BRTABLE~l^\ast~l', r'\hex{0E}', r'[t_1^\ast~t^\ast~\I32] \to [t_2^\ast]', r'valid-br_table', r'exec-br_table'),
    Instruction(r'\RETURN', r'\hex{0F}', r'[t_1^\ast~t^\ast] \to [t_2^\ast]', r'valid-return', r'exec-return'),
    Instruction(r'\CALL~x', r'\hex{10}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-call', r'exec-call'),
    Instruction(r'\CALLINDIRECT~x~y', r'\hex{11}', r'[t_1^\ast~\I32] \to [t_2^\ast]', r'valid-call_indirect', r'exec-call_indirect'),
    Instruction(None, r'\hex{12}'),
    Instruction(None, r'\hex{13}'),
    Instruction(None, r'\hex{14}'),
    Instruction(None, r'\hex{15}'),
    Instruction(None, r'\hex{16}'),
    Instruction(None, r'\hex{17}'),
    Instruction(None, r'\hex{18}'),
    Instruction(None, r'\hex{19}'),
    Instruction(r'\DROP', r'\hex{1A}', r'[t] \to []', r'valid-drop', r'exec-drop'),
    Instruction(r'\SELECT', r'\hex{1B}', r'[t~t~\I32] \to [t]', r'valid-select', r'exec-select'),
    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'\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'),
    Instruction(r'\GLOBALGET~x', r'\hex{23}', r'[] \to [t]', r'valid-global.get', r'exec-global.get'),
    Instruction(r'\GLOBALSET~x', r'\hex{24}', r'[t] \to []', r'valid-global.set', r'exec-global.set'),
    Instruction(r'\TABLEGET~x', r'\hex{25}', r'[\I32] \to [t]', r'valid-table.get', r'exec-table.get'),
    Instruction(r'\TABLESET~x', r'\hex{26}', r'[\I32~t] \to []', r'valid-table.set', r'exec-table.set'),
    Instruction(None, r'\hex{27}'),
    Instruction(r'\I32.\LOAD~\memarg', r'\hex{28}', r'[\I32] \to [\I32]', r'valid-load', r'exec-load'),
    Instruction(r'\I64.\LOAD~\memarg', r'\hex{29}', r'[\I32] \to [\I64]', r'valid-load', r'exec-load'),
    Instruction(r'\F32.\LOAD~\memarg', r'\hex{2A}', r'[\I32] \to [\F32]', r'valid-load', r'exec-load'),
    Instruction(r'\F64.\LOAD~\memarg', r'\hex{2B}', r'[\I32] \to [\F64]', r'valid-load', r'exec-load'),
    Instruction(r'\I32.\LOAD\K{8\_s}~\memarg', r'\hex{2C}', r'[\I32] \to [\I32]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I32.\LOAD\K{8\_u}~\memarg', r'\hex{2D}', r'[\I32] \to [\I32]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I32.\LOAD\K{16\_s}~\memarg', r'\hex{2E}', r'[\I32] \to [\I32]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I32.\LOAD\K{16\_u}~\memarg', r'\hex{2F}', r'[\I32] \to [\I32]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I64.\LOAD\K{8\_s}~\memarg', r'\hex{30}', r'[\I32] \to [\I64]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I64.\LOAD\K{8\_u}~\memarg', r'\hex{31}', r'[\I32] \to [\I64]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I64.\LOAD\K{16\_s}~\memarg', r'\hex{32}', r'[\I32] \to [\I64]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I64.\LOAD\K{16\_u}~\memarg', r'\hex{33}', r'[\I32] \to [\I64]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I64.\LOAD\K{32\_s}~\memarg', r'\hex{34}', r'[\I32] \to [\I64]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I64.\LOAD\K{32\_u}~\memarg', r'\hex{35}', r'[\I32] \to [\I64]', r'valid-loadn', r'exec-loadn'),
    Instruction(r'\I32.\STORE~\memarg', r'\hex{36}', r'[\I32~\I32] \to []', r'valid-store', r'exec-store'),
    Instruction(r'\I64.\STORE~\memarg', r'\hex{37}', r'[\I32~\I64] \to []', r'valid-store', r'exec-store'),
    Instruction(r'\F32.\STORE~\memarg', r'\hex{38}', r'[\I32~\F32] \to []', r'valid-store', r'exec-store'),
    Instruction(r'\F64.\STORE~\memarg', r'\hex{39}', r'[\I32~\F64] \to []', r'valid-store', r'exec-store'),
    Instruction(r'\I32.\STORE\K{8}~\memarg', r'\hex{3A}', r'[\I32~\I32] \to []', r'valid-storen', r'exec-storen'),
    Instruction(r'\I32.\STORE\K{16}~\memarg', r'\hex{3B}', r'[\I32~\I32] \to []', r'valid-storen', r'exec-storen'),
    Instruction(r'\I64.\STORE\K{8}~\memarg', r'\hex{3C}', r'[\I32~\I64] \to []', r'valid-storen', r'exec-storen'),
    Instruction(r'\I64.\STORE\K{16}~\memarg', r'\hex{3D}', r'[\I32~\I64] \to []', r'valid-storen', r'exec-storen'),
    Instruction(r'\I64.\STORE\K{32}~\memarg', r'\hex{3E}', r'[\I32~\I64] \to []', r'valid-storen', r'exec-storen'),
    Instruction(r'\MEMORYSIZE', r'\hex{3F}', r'[] \to [\I32]', r'valid-memory.size', r'exec-memory.size'),
    Instruction(r'\MEMORYGROW', r'\hex{40}', r'[\I32] \to [\I32]', r'valid-memory.grow', r'exec-memory.grow'),
    Instruction(r'\I32.\CONST~\i32', r'\hex{41}', r'[] \to [\I32]', r'valid-const', r'exec-const'),
    Instruction(r'\I64.\CONST~\i64', r'\hex{42}', r'[] \to [\I64]', r'valid-const', r'exec-const'),
    Instruction(r'\F32.\CONST~\f32', r'\hex{43}', r'[] \to [\F32]', r'valid-const', r'exec-const'),
    Instruction(r'\F64.\CONST~\f64', r'\hex{44}', r'[] \to [\F64]', r'valid-const', r'exec-const'),
    Instruction(r'\I32.\EQZ', r'\hex{45}', r'[\I32] \to [\I32]', r'valid-testop', r'exec-testop', r'op-ieqz'),
    Instruction(r'\I32.\EQ', r'\hex{46}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ieq'),
    Instruction(r'\I32.\NE', r'\hex{47}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ine'),
    Instruction(r'\I32.\LT\K{\_s}', r'\hex{48}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ilt_s'),
    Instruction(r'\I32.\LT\K{\_u}', r'\hex{49}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ilt_u'),
    Instruction(r'\I32.\GT\K{\_s}', r'\hex{4A}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-igt_s'),
    Instruction(r'\I32.\GT\K{\_u}', r'\hex{4B}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-igt_u'),
    Instruction(r'\I32.\LE\K{\_s}', r'\hex{4C}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ile_s'),
    Instruction(r'\I32.\LE\K{\_u}', r'\hex{4D}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ile_u'),
    Instruction(r'\I32.\GE\K{\_s}', r'\hex{4E}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ige_s'),
    Instruction(r'\I32.\GE\K{\_u}', r'\hex{4F}', r'[\I32~\I32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ige_u'),
    Instruction(r'\I64.\EQZ', r'\hex{50}', r'[\I64] \to [\I32]', r'valid-testop', r'exec-testop', r'op-ieqz'),
    Instruction(r'\I64.\EQ', r'\hex{51}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ieq'),
    Instruction(r'\I64.\NE', r'\hex{52}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ine'),
    Instruction(r'\I64.\LT\K{\_s}', r'\hex{53}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ilt_s'),
    Instruction(r'\I64.\LT\K{\_u}', r'\hex{54}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ilt_u'),
    Instruction(r'\I64.\GT\K{\_s}', r'\hex{55}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-igt_s'),
    Instruction(r'\I64.\GT\K{\_u}', r'\hex{56}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-igt_u'),
    Instruction(r'\I64.\LE\K{\_s}', r'\hex{57}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ile_s'),
    Instruction(r'\I64.\LE\K{\_u}', r'\hex{58}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ile_u'),
    Instruction(r'\I64.\GE\K{\_s}', r'\hex{59}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ige_s'),
    Instruction(r'\I64.\GE\K{\_u}', r'\hex{5A}', r'[\I64~\I64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-ige_u'),
    Instruction(r'\F32.\EQ', r'\hex{5B}', r'[\F32~\F32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-feq'),
    Instruction(r'\F32.\NE', r'\hex{5C}', r'[\F32~\F32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-fne'),
    Instruction(r'\F32.\LT', r'\hex{5D}', r'[\F32~\F32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-flt'),
    Instruction(r'\F32.\GT', r'\hex{5E}', r'[\F32~\F32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-fgt'),
    Instruction(r'\F32.\LE', r'\hex{5F}', r'[\F32~\F32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-fle'),
    Instruction(r'\F32.\GE', r'\hex{60}', r'[\F32~\F32] \to [\I32]', r'valid-relop', r'exec-relop', r'op-fge'),
    Instruction(r'\F64.\EQ', r'\hex{61}', r'[\F64~\F64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-feq'),
    Instruction(r'\F64.\NE', r'\hex{62}', r'[\F64~\F64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-fne'),
    Instruction(r'\F64.\LT', r'\hex{63}', r'[\F64~\F64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-flt'),
    Instruction(r'\F64.\GT', r'\hex{64}', r'[\F64~\F64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-fgt'),
    Instruction(r'\F64.\LE', r'\hex{65}', r'[\F64~\F64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-fle'),
    Instruction(r'\F64.\GE', r'\hex{66}', r'[\F64~\F64] \to [\I32]', r'valid-relop', r'exec-relop', r'op-fge'),
    Instruction(r'\I32.\CLZ', r'\hex{67}', r'[\I32] \to [\I32]', r'valid-unop', r'exec-unop', r'op-iclz'),
    Instruction(r'\I32.\CTZ', r'\hex{68}', r'[\I32] \to [\I32]', r'valid-unop', r'exec-unop', r'op-ictz'),
    Instruction(r'\I32.\POPCNT', r'\hex{69}', r'[\I32] \to [\I32]', r'valid-unop', r'exec-unop', r'op-ipopcnt'),
    Instruction(r'\I32.\ADD', r'\hex{6A}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-iadd'),
    Instruction(r'\I32.\SUB', r'\hex{6B}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-isub'),
    Instruction(r'\I32.\MUL', r'\hex{6C}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-imul'),
    Instruction(r'\I32.\DIV\K{\_s}', r'\hex{6D}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-idiv_s'),
    Instruction(r'\I32.\DIV\K{\_u}', r'\hex{6E}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-idiv_u'),
    Instruction(r'\I32.\REM\K{\_s}', r'\hex{6F}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-irem_s'),
    Instruction(r'\I32.\REM\K{\_u}', r'\hex{70}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-irem_u'),
    Instruction(r'\I32.\AND', r'\hex{71}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-iand'),
    Instruction(r'\I32.\OR', r'\hex{72}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-ior'),
    Instruction(r'\I32.\XOR', r'\hex{73}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-ixor'),
    Instruction(r'\I32.\SHL', r'\hex{74}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-ishl'),
    Instruction(r'\I32.\SHR\K{\_s}', r'\hex{75}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-ishr_s'),
    Instruction(r'\I32.\SHR\K{\_u}', r'\hex{76}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-ishr_u'),
    Instruction(r'\I32.\ROTL', r'\hex{77}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-irotl'),
    Instruction(r'\I32.\ROTR', r'\hex{78}', r'[\I32~\I32] \to [\I32]', r'valid-binop', r'exec-binop', r'op-irotr'),
    Instruction(r'\I64.\CLZ', r'\hex{79}', r'[\I64] \to [\I64]', r'valid-unop', r'exec-unop', r'op-iclz'),
    Instruction(r'\I64.\CTZ', r'\hex{7A}', r'[\I64] \to [\I64]', r'valid-unop', r'exec-unop', r'op-ictz'),
    Instruction(r'\I64.\POPCNT', r'\hex{7B}', r'[\I64] \to [\I64]', r'valid-unop', r'exec-unop', r'op-ipopcnt'),
    Instruction(r'\I64.\ADD', r'\hex{7C}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-iadd'),
    Instruction(r'\I64.\SUB', r'\hex{7D}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-isub'),
    Instruction(r'\I64.\MUL', r'\hex{7E}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-imul'),
    Instruction(r'\I64.\DIV\K{\_s}', r'\hex{7F}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-idiv_s'),
    Instruction(r'\I64.\DIV\K{\_u}', r'\hex{80}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-idiv_u'),
    Instruction(r'\I64.\REM\K{\_s}', r'\hex{81}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-irem_s'),
    Instruction(r'\I64.\REM\K{\_u}', r'\hex{82}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-irem_u'),
    Instruction(r'\I64.\AND', r'\hex{83}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-iand'),
    Instruction(r'\I64.\OR', r'\hex{84}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-ior'),
    Instruction(r'\I64.\XOR', r'\hex{85}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-ixor'),
    Instruction(r'\I64.\SHL', r'\hex{86}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-ishl'),
    Instruction(r'\I64.\SHR\K{\_s}', r'\hex{87}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-ishr_s'),
    Instruction(r'\I64.\SHR\K{\_u}', r'\hex{88}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-ishr_u'),
    Instruction(r'\I64.\ROTL', r'\hex{89}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-irotl'),
    Instruction(r'\I64.\ROTR', r'\hex{8A}', r'[\I64~\I64] \to [\I64]', r'valid-binop', r'exec-binop', r'op-irotr'),
    Instruction(r'\F32.\ABS', r'\hex{8B}', r'[\F32] \to [\F32]', r'valid-unop', r'exec-unop', r'op-fabs'),
    Instruction(r'\F32.\NEG', r'\hex{8C}', r'[\F32] \to [\F32]', r'valid-unop', r'exec-unop', r'op-fneg'),
    Instruction(r'\F32.\CEIL', r'\hex{8D}', r'[\F32] \to [\F32]', r'valid-unop', r'exec-unop', r'op-fceil'),
    Instruction(r'\F32.\FLOOR', r'\hex{8E}', r'[\F32] \to [\F32]', r'valid-unop', r'exec-unop', r'op-ffloor'),
    Instruction(r'\F32.\TRUNC', r'\hex{8F}', r'[\F32] \to [\F32]', r'valid-unop', r'exec-unop', r'op-ftrunc'),
    Instruction(r'\F32.\NEAREST', r'\hex{90}', r'[\F32] \to [\F32]', r'valid-unop', r'exec-unop', r'op-fnearest'),
    Instruction(r'\F32.\SQRT', r'\hex{91}', r'[\F32] \to [\F32]', r'valid-unop', r'exec-unop', r'op-fsqrt'),
    Instruction(r'\F32.\ADD', r'\hex{92}', r'[\F32~\F32] \to [\F32]', r'valid-binop', r'exec-binop', r'op-fadd'),
    Instruction(r'\F32.\SUB', r'\hex{93}', r'[\F32~\F32] \to [\F32]', r'valid-binop', r'exec-binop', r'op-fsub'),
    Instruction(r'\F32.\MUL', r'\hex{94}', r'[\F32~\F32] \to [\F32]', r'valid-binop', r'exec-binop', r'op-fmul'),
    Instruction(r'\F32.\DIV', r'\hex{95}', r'[\F32~\F32] \to [\F32]', r'valid-binop', r'exec-binop', r'op-fdiv'),
    Instruction(r'\F32.\FMIN', r'\hex{96}', r'[\F32~\F32] \to [\F32]', r'valid-binop', r'exec-binop', r'op-fmin'),
    Instruction(r'\F32.\FMAX', r'\hex{97}', r'[\F32~\F32] \to [\F32]', r'valid-binop', r'exec-binop', r'op-fmax'),
    Instruction(r'\F32.\COPYSIGN', r'\hex{98}', r'[\F32~\F32] \to [\F32]', r'valid-binop', r'exec-binop', r'op-fcopysign'),
    Instruction(r'\F64.\ABS', r'\hex{99}', r'[\F64] \to [\F64]', r'valid-unop', r'exec-unop', r'op-fabs'),
    Instruction(r'\F64.\NEG', r'\hex{9A}', r'[\F64] \to [\F64]', r'valid-unop', r'exec-unop', r'op-fneg'),
    Instruction(r'\F64.\CEIL', r'\hex{9B}', r'[\F64] \to [\F64]', r'valid-unop', r'exec-unop', r'op-fceil'),
    Instruction(r'\F64.\FLOOR', r'\hex{9C}', r'[\F64] \to [\F64]', r'valid-unop', r'exec-unop', r'op-ffloor'),
    Instruction(r'\F64.\TRUNC', r'\hex{9D}', r'[\F64] \to [\F64]', r'valid-unop', r'exec-unop', r'op-ftrunc'),
    Instruction(r'\F64.\NEAREST', r'\hex{9E}', r'[\F64] \to [\F64]', r'valid-unop', r'exec-unop', r'op-fnearest'),
    Instruction(r'\F64.\SQRT', r'\hex{9F}', r'[\F64] \to [\F64]', r'valid-unop', r'exec-unop', r'op-fsqrt'),
    Instruction(r'\F64.\ADD', r'\hex{A0}', r'[\F64~\F64] \to [\F64]', r'valid-binop', r'exec-binop', r'op-fadd'),
    Instruction(r'\F64.\SUB', r'\hex{A1}', r'[\F64~\F64] \to [\F64]', r'valid-binop', r'exec-binop', r'op-fsub'),
    Instruction(r'\F64.\MUL', r'\hex{A2}', r'[\F64~\F64] \to [\F64]', r'valid-binop', r'exec-binop', r'op-fmul'),
    Instruction(r'\F64.\DIV', r'\hex{A3}', r'[\F64~\F64] \to [\F64]', r'valid-binop', r'exec-binop', r'op-fdiv'),
    Instruction(r'\F64.\FMIN', r'\hex{A4}', r'[\F64~\F64] \to [\F64]', r'valid-binop', r'exec-binop', r'op-fmin'),
    Instruction(r'\F64.\FMAX', r'\hex{A5}', r'[\F64~\F64] \to [\F64]', r'valid-binop', r'exec-binop', r'op-fmax'),
    Instruction(r'\F64.\COPYSIGN', r'\hex{A6}', r'[\F64~\F64] \to [\F64]', r'valid-binop', r'exec-binop', r'op-fcopysign'),
    Instruction(r'\I32.\WRAP\K{\_}\I64', r'\hex{A7}', r'[\I64] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-wrap'),
    Instruction(r'\I32.\TRUNC\K{\_}\F32\K{\_s}', r'\hex{A8}', r'[\F32] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_s'),
    Instruction(r'\I32.\TRUNC\K{\_}\F32\K{\_u}', r'\hex{A9}', r'[\F32] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_u'),
    Instruction(r'\I32.\TRUNC\K{\_}\F64\K{\_s}', r'\hex{AA}', r'[\F64] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_s'),
    Instruction(r'\I32.\TRUNC\K{\_}\F64\K{\_u}', r'\hex{AB}', r'[\F64] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_u'),
    Instruction(r'\I64.\EXTEND\K{\_}\I32\K{\_s}', r'\hex{AC}', r'[\I32] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-extend_s'),
    Instruction(r'\I64.\EXTEND\K{\_}\I32\K{\_u}', r'\hex{AD}', r'[\I32] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-extend_u'),
    Instruction(r'\I64.\TRUNC\K{\_}\F32\K{\_s}', r'\hex{AE}', r'[\F32] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_s'),
    Instruction(r'\I64.\TRUNC\K{\_}\F32\K{\_u}', r'\hex{AF}', r'[\F32] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_u'),
    Instruction(r'\I64.\TRUNC\K{\_}\F64\K{\_s}', r'\hex{B0}', r'[\F64] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_s'),
    Instruction(r'\I64.\TRUNC\K{\_}\F64\K{\_u}', r'\hex{B1}', r'[\F64] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_u'),
    Instruction(r'\F32.\CONVERT\K{\_}\I32\K{\_s}', r'\hex{B2}', r'[\I32] \to [\F32]', r'valid-cvtop', r'exec-cvtop', r'op-convert_s'),
    Instruction(r'\F32.\CONVERT\K{\_}\I32\K{\_u}', r'\hex{B3}', r'[\I32] \to [\F32]', r'valid-cvtop', r'exec-cvtop', r'op-convert_u'),
    Instruction(r'\F32.\CONVERT\K{\_}\I64\K{\_s}', r'\hex{B4}', r'[\I64] \to [\F32]', r'valid-cvtop', r'exec-cvtop', r'op-convert_s'),
    Instruction(r'\F32.\CONVERT\K{\_}\I64\K{\_u}', r'\hex{B5}', r'[\I64] \to [\F32]', r'valid-cvtop', r'exec-cvtop', r'op-convert_u'),
    Instruction(r'\F32.\DEMOTE\K{\_}\F64', r'\hex{B6}', r'[\F64] \to [\F32]', r'valid-cvtop', r'exec-cvtop', r'op-demote'),
    Instruction(r'\F64.\CONVERT\K{\_}\I32\K{\_s}', r'\hex{B7}', r'[\I32] \to [\F64]', r'valid-cvtop', r'exec-cvtop', r'op-convert_s'),
    Instruction(r'\F64.\CONVERT\K{\_}\I32\K{\_u}', r'\hex{B8}', r'[\I32] \to [\F64]', r'valid-cvtop', r'exec-cvtop', r'op-convert_u'),
    Instruction(r'\F64.\CONVERT\K{\_}\I64\K{\_s}', r'\hex{B9}', r'[\I64] \to [\F64]', r'valid-cvtop', r'exec-cvtop', r'op-convert_s'),
    Instruction(r'\F64.\CONVERT\K{\_}\I64\K{\_u}', r'\hex{BA}', r'[\I64] \to [\F64]', r'valid-cvtop', r'exec-cvtop', r'op-convert_u'),
    Instruction(r'\F64.\PROMOTE\K{\_}\F32', r'\hex{BB}', r'[\F32] \to [\F64]', r'valid-cvtop', r'exec-cvtop', r'op-promote'),
    Instruction(r'\I32.\REINTERPRET\K{\_}\F32', r'\hex{BC}', r'[\F32] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-reinterpret'),
    Instruction(r'\I64.\REINTERPRET\K{\_}\F64', r'\hex{BD}', r'[\F64] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-reinterpret'),
    Instruction(r'\F32.\REINTERPRET\K{\_}\I32', r'\hex{BE}', r'[\I32] \to [\F32]', r'valid-cvtop', r'exec-cvtop', r'op-reinterpret'),
    Instruction(r'\F64.\REINTERPRET\K{\_}\I64', r'\hex{BF}', r'[\I64] \to [\F64]', r'valid-cvtop', r'exec-cvtop', r'op-reinterpret'),
    Instruction(r'\I32.\EXTEND\K{8\_s}', r'\hex{C0}', r'[\I32] \to [\I32]', r'valid-unop', r'exec-unop', r'op-iextendn_s'),
    Instruction(r'\I32.\EXTEND\K{16\_s}', r'\hex{C1}', r'[\I32] \to [\I32]', r'valid-unop', r'exec-unop', r'op-iextendn_s'),
    Instruction(r'\I64.\EXTEND\K{8\_s}', r'\hex{C2}', r'[\I64] \to [\I64]', r'valid-unop', r'exec-unop', r'op-iextendn_s'),
    Instruction(r'\I64.\EXTEND\K{16\_s}', r'\hex{C3}', r'[\I64] \to [\I64]', r'valid-unop', r'exec-unop', r'op-iextendn_s'),
    Instruction(r'\I64.\EXTEND\K{32\_s}', r'\hex{C4}', r'[\I64] \to [\I64]', r'valid-unop', r'exec-unop', r'op-iextendn_s'),
    Instruction(None, r'\hex{C5}'),
    Instruction(None, r'\hex{C6}'),
    Instruction(None, r'\hex{C7}'),
    Instruction(None, r'\hex{C8}'),
    Instruction(None, r'\hex{C9}'),
    Instruction(None, r'\hex{CA}'),
    Instruction(None, r'\hex{CB}'),
    Instruction(None, r'\hex{CC}'),
    Instruction(None, r'\hex{CD}'),
    Instruction(None, r'\hex{CE}'),
    Instruction(None, r'\hex{CF}'),
    Instruction(r'\REFNULL~t', r'\hex{D0}', r'[] \to [t]', r'valid-ref.null', r'exec-ref.null'),
    Instruction(r'\REFISNULL', r'\hex{D1}', r'[t] \to [\I32]', r'valid-ref.is_null', r'exec-ref.is_null'),
    Instruction(r'\REFFUNC~x', r'\hex{D2}', r'[] \to [\FUNCREF]', r'valid-ref.func', r'exec-ref.func'),
    Instruction(None, r'\hex{D3}'),
    Instruction(None, r'\hex{D4}'),
    Instruction(None, r'\hex{D5}'),
    Instruction(None, r'\hex{D6}'),
    Instruction(None, r'\hex{D7}'),
    Instruction(None, r'\hex{D8}'),
    Instruction(None, r'\hex{D9}'),
    Instruction(None, r'\hex{DA}'),
    Instruction(None, r'\hex{DB}'),
    Instruction(None, r'\hex{DC}'),
    Instruction(None, r'\hex{DD}'),
    Instruction(None, r'\hex{DE}'),
    Instruction(None, r'\hex{DF}'),
    Instruction(None, r'\hex{E0}'),
    Instruction(None, r'\hex{E1}'),
    Instruction(None, r'\hex{E2}'),
    Instruction(None, r'\hex{E3}'),
    Instruction(None, r'\hex{E4}'),
    Instruction(None, r'\hex{E5}'),
    Instruction(None, r'\hex{E6}'),
    Instruction(None, r'\hex{E7}'),
    Instruction(None, r'\hex{E8}'),
    Instruction(None, r'\hex{E9}'),
    Instruction(None, r'\hex{EA}'),
    Instruction(None, r'\hex{EB}'),
    Instruction(None, r'\hex{EC}'),
    Instruction(None, r'\hex{ED}'),
    Instruction(None, r'\hex{EE}'),
    Instruction(None, r'\hex{EF}'),
    Instruction(None, r'\hex{F0}'),
    Instruction(None, r'\hex{F1}'),
    Instruction(None, r'\hex{F2}'),
    Instruction(None, r'\hex{F3}'),
    Instruction(None, r'\hex{F4}'),
    Instruction(None, r'\hex{F5}'),
    Instruction(None, r'\hex{F6}'),
    Instruction(None, r'\hex{F7}'),
    Instruction(None, r'\hex{F8}'),
    Instruction(None, r'\hex{F9}'),
    Instruction(None, r'\hex{FA}'),
    Instruction(None, r'\hex{FB}'),
    Instruction(r'\I32.\TRUNC\K{\_sat\_}\F32\K{\_s}', r'\hex{FC}~\hex{00}', r'[\F32] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_s'),
    Instruction(r'\I32.\TRUNC\K{\_sat\_}\F32\K{\_u}', r'\hex{FC}~\hex{01}', r'[\F32] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_u'),
    Instruction(r'\I32.\TRUNC\K{\_sat\_}\F64\K{\_s}', r'\hex{FC}~\hex{02}', r'[\F64] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_s'),
    Instruction(r'\I32.\TRUNC\K{\_sat\_}\F64\K{\_u}', r'\hex{FC}~\hex{03}', r'[\F64] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_u'),
    Instruction(r'\I64.\TRUNC\K{\_sat\_}\F32\K{\_s}', r'\hex{FC}~\hex{04}', r'[\F32] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_s'),
    Instruction(r'\I64.\TRUNC\K{\_sat\_}\F32\K{\_u}', r'\hex{FC}~\hex{05}', r'[\F32] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_u'),
    Instruction(r'\I64.\TRUNC\K{\_sat\_}\F64\K{\_s}', r'\hex{FC}~\hex{06}', r'[\F64] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_s'),
    Instruction(r'\I64.\TRUNC\K{\_sat\_}\F64\K{\_u}', r'\hex{FC}~\hex{07}', r'[\F64] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_u'),
    Instruction(r'\MEMORYINIT', r'\hex{FC}~\hex{08}', r'[\I32~\I32~\I32] \to []', r'valid-memory.init', r'exec-memory.init'),
    Instruction(r'\DATADROP', r'\hex{FC}~\hex{09}', r'[] \to []', r'valid-data.drop', r'exec-data.drop'),
    Instruction(r'\MEMORYCOPY', r'\hex{FC}~\hex{0A}', r'[\I32~\I32~\I32] \to []', r'valid-memory.copy', r'exec-memory.copy'),
    Instruction(r'\MEMORYFILL', r'\hex{FC}~\hex{0B}', r'[\I32~\I32~\I32] \to []', r'valid-memory.fill', r'exec-memory.fill'),
    Instruction(r'\TABLEINIT', r'\hex{FC}~\hex{0C}', r'[\I32~\I32~\I32] \to []', r'valid-table.init', r'exec-table.init'),
    Instruction(r'\ELEMDROP', r'\hex{FC}~\hex{0D}', r'[] \to []', r'valid-elem.drop', r'exec-elem.drop'),
    Instruction(r'\TABLECOPY', r'\hex{FC}~\hex{0E}', r'[\I32~\I32~\I32] \to []', r'valid-table.copy', r'exec-table.copy'),
    Instruction(r'\TABLEGROW', r'\hex{FC}~\hex{0F}', r'[t~\I32] \to []', r'valid-table.grow', r'exec-table.grow'),
    Instruction(r'\TABLESIZE', r'\hex{FC}~\hex{10}', r'[] \to []', r'valid-table.size', r'exec-table.size'),
    Instruction(r'\TABLEFILL', r'\hex{FC}~\hex{11}', r'[\I32~t~\I32] \to []', r'valid-table.fill', r'exec-table.fill'),
]

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)


================================================
FILE: document/core/appendix/implementation.rst
================================================
.. index:: ! implementation limitations, implementation
.. _impl:

Implementation Limitations
--------------------------

Implementations typically impose additional restrictions on a number of aspects of a WebAssembly module or execution.
These may stem from:

* physical resource limits,
* constraints imposed by the embedder or its environment,
* limitations of selected implementation strategies.

This section lists allowed limitations.
Where restrictions take the form of numeric limits, no minimum requirements are given,
nor are the limits assumed to be concrete, fixed numbers.
However, it is expected that all implementations have "reasonably" large limits  to enable common applications.

.. note::
   A conforming implementation is not allowed to leave out individual *features*.
   However, designated subsets of WebAssembly may be specified in the future.


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
.. _impl-syntax:

Structure
.........

An implementation may impose restrictions on the following dimensions of a module:

* the number of :ref:`types <syntax-type>` in a :ref:`module <syntax-module>`
* the number of :ref:`functions <syntax-func>` in a :ref:`module <syntax-module>`, including imports
* the number of :ref:`tables <syntax-table>` in a :ref:`module <syntax-module>`, including imports
* the number of :ref:`memories <syntax-mem>` in a :ref:`module <syntax-module>`, including imports
* the number of :ref:`globals <syntax-global>` in a :ref:`module <syntax-module>`, including imports
* the number of :ref:`element segments <syntax-elem>` in a :ref:`module <syntax-module>`
* the number of :ref:`data segments <syntax-data>` in a :ref:`module <syntax-module>`
* the number of :ref:`imports <syntax-import>` to a :ref:`module <syntax-module>`
* the number of :ref:`exports <syntax-export>` from a :ref:`module <syntax-module>`
* the number of parameters in a :ref:`function type <syntax-functype>`
* the number of results in a :ref:`function type <syntax-functype>`
* the number of parameters in a :ref:`block type <syntax-blocktype>`
* the number of results in a :ref:`block type <syntax-blocktype>`
* the number of :ref:`locals <syntax-local>` in a :ref:`function <syntax-func>`
* the size of a :ref:`function <syntax-func>` body
* the size of a :ref:`structured control instruction <syntax-instr-control>`
* the number of :ref:`structured control instructions <syntax-instr-control>` in a :ref:`function <syntax-func>`
* the nesting depth of :ref:`structured control instructions <syntax-instr-control>`
* the number of :ref:`label indices <syntax-labelidx>` in a |brtable| instruction
* the length of an :ref:`element segment <syntax-elem>`
* the length of a :ref:`data segment <syntax-data>`
* the length of a :ref:`name <syntax-name>`
* the range of :ref:`characters <syntax-char>` in a :ref:`name <syntax-name>`

If the limits of an implementation are exceeded for a given module,
then the implementation may reject the :ref:`validation <valid>`, compilation, or :ref:`instantiation <exec-instantiation>` of that module with an embedder-specific error.

.. note::
   The last item allows :ref:`embedders <embedder>` that operate in limited environments without support for
   |Unicode|_ to limit the
   names of :ref:`imports <syntax-import>` and :ref:`exports <syntax-export>`
   to common subsets like |ASCII|_.


.. index:: binary format, module, section, function, code
.. _impl-binary:

Binary Format
.............

For a module given in :ref:`binary format <binary>`, additional limitations may be imposed on the following dimensions:

* the size of a :ref:`module <binary-module>`
* the size of any :ref:`section <binary-section>`
* the size of an individual function's :ref:`code <binary-code>`
* the number of :ref:`sections <binary-section>`


.. index:: text format, source text, token, identifier, character, unicode
.. _impl-text:

Text Format
...........

For a module given in :ref:`text format <text>`, additional limitations may be imposed on the following dimensions:

* the size of the :ref:`source text <source>`
* the size of any syntactic element
* the size of an individual :ref:`token <text-token>`
* the nesting depth of :ref:`folded instructions <text-foldedinstr>`
* the length of symbolic :ref:`identifiers <text-id>`
* the range of literal :ref:`characters <text-char>` allowed in the :ref:`source text <source>`


.. index:: validation, function
.. _impl-valid:

Validation
~~~~~~~~~~

An implementation may defer :ref:`validation <valid>` of individual :ref:`functions <syntax-func>` until they are first :ref:`invoked <exec-invoke>`.

If a function turns out to be invalid, then the invocation, and every consecutive call to the same function, results in a :ref:`trap <trap>`.

.. note::
   This is to allow implementations to use interpretation or just-in-time compilation for functions.
   The function must still be fully validated before execution of its body begins.


.. index:: execution, module instance, function instance, table instance, memory instance, global instance, allocation, frame, label, value
.. _impl-exec:

Execution
~~~~~~~~~

Restrictions on the following dimensions may be imposed during :ref:`execution <exec>` of a WebAssembly program:

* the number of allocated :ref:`module instances <syntax-moduleinst>`
* the number of allocated :ref:`function instances <syntax-funcinst>`
* the number of allocated :ref:`table instances <syntax-tableinst>`
* the number of allocated :ref:`memory instances <syntax-meminst>`
* the number of allocated :ref:`global instances <syntax-globalinst>`
* the size of a :ref:`table instance <syntax-tableinst>`
* the size of a :ref:`memory instance <syntax-meminst>`
* the number of :ref:`frames <syntax-frame>` on the :ref:`stack <stack>`
* the number of :ref:`labels <syntax-label>` on the :ref:`stack <stack>`
* the number of :ref:`values <syntax-val>` on the :ref:`stack <stack>`

If the runtime limits of an implementation are exceeded during execution of a computation,
then it may terminate that computation and report an embedder-specific error to the invoking code.

Some of the above limits may already be verified during instantiation, in which case an implementation may report exceedance in the same manner as for :ref:`syntactic limits <impl-syntax>`.

.. note::
   Concrete limits are usually not fixed but may be dependent on specifics, interdependent, vary over time, or depend on other implementation- or embedder-specific situations or events.


================================================
FILE: document/core/appendix/index-instructions.rst
================================================
.. DO NOT EDIT: This file is auto-generated by the gen-index-instructions.py script.

.. index:: instruction
.. _index-instr:

Index of Instructions
---------------------

=========================================  =========================  =============================================  =======================================  ===============================================================
Instruction                                Binary Opcode              Type                                           Validation                               Execution                                                      
=========================================  =========================  =============================================  =======================================  ===============================================================
:math:`\UNREACHABLE`                       :math:`\hex{00}`           :math:`[t_1^\ast] \to [t_2^\ast]`              :ref:`validation <valid-unreachable>`    :ref:`execution <exec-unreachable>`                            
:math:`\NOP`                               :math:`\hex{01}`           :math:`[] \to []`                              :ref:`validation <valid-nop>`            :ref:`execution <exec-nop>`                                    
:math:`\BLOCK~\X{bt}`                      :math:`\hex{02}`           :math:`[t_1^\ast] \to [t_2^\ast]`              :ref:`validation <valid-block>`          :ref:`execution <exec-block>`                                  
:math:`\LOOP~\X{bt}`                       :math:`\hex{03}`           :math:`[t_1^\ast] \to [t_2^\ast]`              :ref:`validation <valid-loop>`           :ref:`execution <exec-loop>`                                   
:math:`\IF~\X{bt}`                         :math:`\hex{04}`           :math:`[t_1^\ast] \to [t_2^\ast]`              :ref:`validation <valid-if>`             :ref:`execution <exec-if>`                                     
:math:`\ELSE`                              :math:`\hex{05}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{06}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{07}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{08}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{09}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{0A}`                                                                                                                                                                  
:math:`\END`                               :math:`\hex{0B}`                                                                                                                                                                  
:math:`\BR~l`                              :math:`\hex{0C}`           :math:`[t_1^\ast~t^\ast] \to [t_2^\ast]`       :ref:`validation <valid-br>`             :ref:`execution <exec-br>`                                     
:math:`\BRIF~l`                            :math:`\hex{0D}`           :math:`[t^\ast~\I32] \to [t^\ast]`             :ref:`validation <valid-br_if>`          :ref:`execution <exec-br_if>`                                  
:math:`\BRTABLE~l^\ast~l`                  :math:`\hex{0E}`           :math:`[t_1^\ast~t^\ast~\I32] \to [t_2^\ast]`  :ref:`validation <valid-br_table>`       :ref:`execution <exec-br_table>`                               
:math:`\RETURN`                            :math:`\hex{0F}`           :math:`[t_1^\ast~t^\ast] \to [t_2^\ast]`       :ref:`validation <valid-return>`         :ref:`execution <exec-return>`                                 
:math:`\CALL~x`                            :math:`\hex{10}`           :math:`[t_1^\ast] \to [t_2^\ast]`              :ref:`validation <valid-call>`           :ref:`execution <exec-call>`                                   
:math:`\CALLINDIRECT~x~y`                  :math:`\hex{11}`           :math:`[t_1^\ast~\I32] \to [t_2^\ast]`         :ref:`validation <valid-call_indirect>`  :ref:`execution <exec-call_indirect>`                          
(reserved)                                 :math:`\hex{12}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{13}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{14}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{15}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{16}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{17}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{18}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{19}`                                                                                                                                                                  
:math:`\DROP`                              :math:`\hex{1A}`           :math:`[t] \to []`                             :ref:`validation <valid-drop>`           :ref:`execution <exec-drop>`                                   
:math:`\SELECT`                            :math:`\hex{1B}`           :math:`[t~t~\I32] \to [t]`                     :ref:`validation <valid-select>`         :ref:`execution <exec-select>`                                 
:math:`\SELECT~t`                          :math:`\hex{1C}`           :math:`[t~t~\I32] \to [t]`                     :ref:`validation <valid-select>`         :ref:`execution <exec-select>`                                 
(reserved)                                 :math:`\hex{1D}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{1E}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{1F}`                                                                                                                                                                  
:math:`\LOCALGET~x`                        :math:`\hex{20}`           :math:`[] \to [t]`                             :ref:`validation <valid-local.get>`      :ref:`execution <exec-local.get>`                              
:math:`\LOCALSET~x`                        :math:`\hex{21}`           :math:`[t] \to []`                             :ref:`validation <valid-local.set>`      :ref:`execution <exec-local.set>`                              
:math:`\LOCALTEE~x`                        :math:`\hex{22}`           :math:`[t] \to [t]`                            :ref:`validation <valid-local.tee>`      :ref:`execution <exec-local.tee>`                              
:math:`\GLOBALGET~x`                       :math:`\hex{23}`           :math:`[] \to [t]`                             :ref:`validation <valid-global.get>`     :ref:`execution <exec-global.get>`                             
:math:`\GLOBALSET~x`                       :math:`\hex{24}`           :math:`[t] \to []`                             :ref:`validation <valid-global.set>`     :ref:`execution <exec-global.set>`                             
:math:`\TABLEGET~x`                        :math:`\hex{25}`           :math:`[\I32] \to [t]`                         :ref:`validation <valid-table.get>`      :ref:`execution <exec-table.get>`                              
:math:`\TABLESET~x`                        :math:`\hex{26}`           :math:`[\I32~t] \to []`                        :ref:`validation <valid-table.set>`      :ref:`execution <exec-table.set>`                              
(reserved)                                 :math:`\hex{27}`                                                                                                                                                                  
:math:`\I32.\LOAD~\memarg`                 :math:`\hex{28}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-load>`           :ref:`execution <exec-load>`                                   
:math:`\I64.\LOAD~\memarg`                 :math:`\hex{29}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-load>`           :ref:`execution <exec-load>`                                   
:math:`\F32.\LOAD~\memarg`                 :math:`\hex{2A}`           :math:`[\I32] \to [\F32]`                      :ref:`validation <valid-load>`           :ref:`execution <exec-load>`                                   
:math:`\F64.\LOAD~\memarg`                 :math:`\hex{2B}`           :math:`[\I32] \to [\F64]`                      :ref:`validation <valid-load>`           :ref:`execution <exec-load>`                                   
:math:`\I32.\LOAD\K{8\_s}~\memarg`         :math:`\hex{2C}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I32.\LOAD\K{8\_u}~\memarg`         :math:`\hex{2D}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I32.\LOAD\K{16\_s}~\memarg`        :math:`\hex{2E}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I32.\LOAD\K{16\_u}~\memarg`        :math:`\hex{2F}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I64.\LOAD\K{8\_s}~\memarg`         :math:`\hex{30}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I64.\LOAD\K{8\_u}~\memarg`         :math:`\hex{31}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I64.\LOAD\K{16\_s}~\memarg`        :math:`\hex{32}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I64.\LOAD\K{16\_u}~\memarg`        :math:`\hex{33}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I64.\LOAD\K{32\_s}~\memarg`        :math:`\hex{34}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I64.\LOAD\K{32\_u}~\memarg`        :math:`\hex{35}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-loadn>`          :ref:`execution <exec-loadn>`                                  
:math:`\I32.\STORE~\memarg`                :math:`\hex{36}`           :math:`[\I32~\I32] \to []`                     :ref:`validation <valid-store>`          :ref:`execution <exec-store>`                                  
:math:`\I64.\STORE~\memarg`                :math:`\hex{37}`           :math:`[\I32~\I64] \to []`                     :ref:`validation <valid-store>`          :ref:`execution <exec-store>`                                  
:math:`\F32.\STORE~\memarg`                :math:`\hex{38}`           :math:`[\I32~\F32] \to []`                     :ref:`validation <valid-store>`          :ref:`execution <exec-store>`                                  
:math:`\F64.\STORE~\memarg`                :math:`\hex{39}`           :math:`[\I32~\F64] \to []`                     :ref:`validation <valid-store>`          :ref:`execution <exec-store>`                                  
:math:`\I32.\STORE\K{8}~\memarg`           :math:`\hex{3A}`           :math:`[\I32~\I32] \to []`                     :ref:`validation <valid-storen>`         :ref:`execution <exec-storen>`                                 
:math:`\I32.\STORE\K{16}~\memarg`          :math:`\hex{3B}`           :math:`[\I32~\I32] \to []`                     :ref:`validation <valid-storen>`         :ref:`execution <exec-storen>`                                 
:math:`\I64.\STORE\K{8}~\memarg`           :math:`\hex{3C}`           :math:`[\I32~\I64] \to []`                     :ref:`validation <valid-storen>`         :ref:`execution <exec-storen>`                                 
:math:`\I64.\STORE\K{16}~\memarg`          :math:`\hex{3D}`           :math:`[\I32~\I64] \to []`                     :ref:`validation <valid-storen>`         :ref:`execution <exec-storen>`                                 
:math:`\I64.\STORE\K{32}~\memarg`          :math:`\hex{3E}`           :math:`[\I32~\I64] \to []`                     :ref:`validation <valid-storen>`         :ref:`execution <exec-storen>`                                 
:math:`\MEMORYSIZE`                        :math:`\hex{3F}`           :math:`[] \to [\I32]`                          :ref:`validation <valid-memory.size>`    :ref:`execution <exec-memory.size>`                            
:math:`\MEMORYGROW`                        :math:`\hex{40}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-memory.grow>`    :ref:`execution <exec-memory.grow>`                            
:math:`\I32.\CONST~\i32`                   :math:`\hex{41}`           :math:`[] \to [\I32]`                          :ref:`validation <valid-const>`          :ref:`execution <exec-const>`                                  
:math:`\I64.\CONST~\i64`                   :math:`\hex{42}`           :math:`[] \to [\I64]`                          :ref:`validation <valid-const>`          :ref:`execution <exec-const>`                                  
:math:`\F32.\CONST~\f32`                   :math:`\hex{43}`           :math:`[] \to [\F32]`                          :ref:`validation <valid-const>`          :ref:`execution <exec-const>`                                  
:math:`\F64.\CONST~\f64`                   :math:`\hex{44}`           :math:`[] \to [\F64]`                          :ref:`validation <valid-const>`          :ref:`execution <exec-const>`                                  
:math:`\I32.\EQZ`                          :math:`\hex{45}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-testop>`         :ref:`execution <exec-testop>`, :ref:`operator <op-ieqz>`      
:math:`\I32.\EQ`                           :math:`\hex{46}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ieq>`        
:math:`\I32.\NE`                           :math:`\hex{47}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ine>`        
:math:`\I32.\LT\K{\_s}`                    :math:`\hex{48}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ilt_s>`      
:math:`\I32.\LT\K{\_u}`                    :math:`\hex{49}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ilt_u>`      
:math:`\I32.\GT\K{\_s}`                    :math:`\hex{4A}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-igt_s>`      
:math:`\I32.\GT\K{\_u}`                    :math:`\hex{4B}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-igt_u>`      
:math:`\I32.\LE\K{\_s}`                    :math:`\hex{4C}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ile_s>`      
:math:`\I32.\LE\K{\_u}`                    :math:`\hex{4D}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ile_u>`      
:math:`\I32.\GE\K{\_s}`                    :math:`\hex{4E}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ige_s>`      
:math:`\I32.\GE\K{\_u}`                    :math:`\hex{4F}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ige_u>`      
:math:`\I64.\EQZ`                          :math:`\hex{50}`           :math:`[\I64] \to [\I32]`                      :ref:`validation <valid-testop>`         :ref:`execution <exec-testop>`, :ref:`operator <op-ieqz>`      
:math:`\I64.\EQ`                           :math:`\hex{51}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ieq>`        
:math:`\I64.\NE`                           :math:`\hex{52}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ine>`        
:math:`\I64.\LT\K{\_s}`                    :math:`\hex{53}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ilt_s>`      
:math:`\I64.\LT\K{\_u}`                    :math:`\hex{54}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ilt_u>`      
:math:`\I64.\GT\K{\_s}`                    :math:`\hex{55}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-igt_s>`      
:math:`\I64.\GT\K{\_u}`                    :math:`\hex{56}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-igt_u>`      
:math:`\I64.\LE\K{\_s}`                    :math:`\hex{57}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ile_s>`      
:math:`\I64.\LE\K{\_u}`                    :math:`\hex{58}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ile_u>`      
:math:`\I64.\GE\K{\_s}`                    :math:`\hex{59}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ige_s>`      
:math:`\I64.\GE\K{\_u}`                    :math:`\hex{5A}`           :math:`[\I64~\I64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-ige_u>`      
:math:`\F32.\EQ`                           :math:`\hex{5B}`           :math:`[\F32~\F32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-feq>`        
:math:`\F32.\NE`                           :math:`\hex{5C}`           :math:`[\F32~\F32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-fne>`        
:math:`\F32.\LT`                           :math:`\hex{5D}`           :math:`[\F32~\F32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-flt>`        
:math:`\F32.\GT`                           :math:`\hex{5E}`           :math:`[\F32~\F32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-fgt>`        
:math:`\F32.\LE`                           :math:`\hex{5F}`           :math:`[\F32~\F32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-fle>`        
:math:`\F32.\GE`                           :math:`\hex{60}`           :math:`[\F32~\F32] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-fge>`        
:math:`\F64.\EQ`                           :math:`\hex{61}`           :math:`[\F64~\F64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-feq>`        
:math:`\F64.\NE`                           :math:`\hex{62}`           :math:`[\F64~\F64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-fne>`        
:math:`\F64.\LT`                           :math:`\hex{63}`           :math:`[\F64~\F64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-flt>`        
:math:`\F64.\GT`                           :math:`\hex{64}`           :math:`[\F64~\F64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-fgt>`        
:math:`\F64.\LE`                           :math:`\hex{65}`           :math:`[\F64~\F64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-fle>`        
:math:`\F64.\GE`                           :math:`\hex{66}`           :math:`[\F64~\F64] \to [\I32]`                 :ref:`validation <valid-relop>`          :ref:`execution <exec-relop>`, :ref:`operator <op-fge>`        
:math:`\I32.\CLZ`                          :math:`\hex{67}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-iclz>`        
:math:`\I32.\CTZ`                          :math:`\hex{68}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-ictz>`        
:math:`\I32.\POPCNT`                       :math:`\hex{69}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-ipopcnt>`     
:math:`\I32.\ADD`                          :math:`\hex{6A}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-iadd>`       
:math:`\I32.\SUB`                          :math:`\hex{6B}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-isub>`       
:math:`\I32.\MUL`                          :math:`\hex{6C}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-imul>`       
:math:`\I32.\DIV\K{\_s}`                   :math:`\hex{6D}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-idiv_s>`     
:math:`\I32.\DIV\K{\_u}`                   :math:`\hex{6E}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-idiv_u>`     
:math:`\I32.\REM\K{\_s}`                   :math:`\hex{6F}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-irem_s>`     
:math:`\I32.\REM\K{\_u}`                   :math:`\hex{70}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-irem_u>`     
:math:`\I32.\AND`                          :math:`\hex{71}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-iand>`       
:math:`\I32.\OR`                           :math:`\hex{72}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ior>`        
:math:`\I32.\XOR`                          :math:`\hex{73}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ixor>`       
:math:`\I32.\SHL`                          :math:`\hex{74}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ishl>`       
:math:`\I32.\SHR\K{\_s}`                   :math:`\hex{75}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ishr_s>`     
:math:`\I32.\SHR\K{\_u}`                   :math:`\hex{76}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ishr_u>`     
:math:`\I32.\ROTL`                         :math:`\hex{77}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-irotl>`      
:math:`\I32.\ROTR`                         :math:`\hex{78}`           :math:`[\I32~\I32] \to [\I32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-irotr>`      
:math:`\I64.\CLZ`                          :math:`\hex{79}`           :math:`[\I64] \to [\I64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-iclz>`        
:math:`\I64.\CTZ`                          :math:`\hex{7A}`           :math:`[\I64] \to [\I64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-ictz>`        
:math:`\I64.\POPCNT`                       :math:`\hex{7B}`           :math:`[\I64] \to [\I64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-ipopcnt>`     
:math:`\I64.\ADD`                          :math:`\hex{7C}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-iadd>`       
:math:`\I64.\SUB`                          :math:`\hex{7D}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-isub>`       
:math:`\I64.\MUL`                          :math:`\hex{7E}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-imul>`       
:math:`\I64.\DIV\K{\_s}`                   :math:`\hex{7F}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-idiv_s>`     
:math:`\I64.\DIV\K{\_u}`                   :math:`\hex{80}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-idiv_u>`     
:math:`\I64.\REM\K{\_s}`                   :math:`\hex{81}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-irem_s>`     
:math:`\I64.\REM\K{\_u}`                   :math:`\hex{82}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-irem_u>`     
:math:`\I64.\AND`                          :math:`\hex{83}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-iand>`       
:math:`\I64.\OR`                           :math:`\hex{84}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ior>`        
:math:`\I64.\XOR`                          :math:`\hex{85}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ixor>`       
:math:`\I64.\SHL`                          :math:`\hex{86}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ishl>`       
:math:`\I64.\SHR\K{\_s}`                   :math:`\hex{87}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ishr_s>`     
:math:`\I64.\SHR\K{\_u}`                   :math:`\hex{88}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-ishr_u>`     
:math:`\I64.\ROTL`                         :math:`\hex{89}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-irotl>`      
:math:`\I64.\ROTR`                         :math:`\hex{8A}`           :math:`[\I64~\I64] \to [\I64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-irotr>`      
:math:`\F32.\ABS`                          :math:`\hex{8B}`           :math:`[\F32] \to [\F32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fabs>`        
:math:`\F32.\NEG`                          :math:`\hex{8C}`           :math:`[\F32] \to [\F32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fneg>`        
:math:`\F32.\CEIL`                         :math:`\hex{8D}`           :math:`[\F32] \to [\F32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fceil>`       
:math:`\F32.\FLOOR`                        :math:`\hex{8E}`           :math:`[\F32] \to [\F32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-ffloor>`      
:math:`\F32.\TRUNC`                        :math:`\hex{8F}`           :math:`[\F32] \to [\F32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-ftrunc>`      
:math:`\F32.\NEAREST`                      :math:`\hex{90}`           :math:`[\F32] \to [\F32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fnearest>`    
:math:`\F32.\SQRT`                         :math:`\hex{91}`           :math:`[\F32] \to [\F32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fsqrt>`       
:math:`\F32.\ADD`                          :math:`\hex{92}`           :math:`[\F32~\F32] \to [\F32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fadd>`       
:math:`\F32.\SUB`                          :math:`\hex{93}`           :math:`[\F32~\F32] \to [\F32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fsub>`       
:math:`\F32.\MUL`                          :math:`\hex{94}`           :math:`[\F32~\F32] \to [\F32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fmul>`       
:math:`\F32.\DIV`                          :math:`\hex{95}`           :math:`[\F32~\F32] \to [\F32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fdiv>`       
:math:`\F32.\FMIN`                         :math:`\hex{96}`           :math:`[\F32~\F32] \to [\F32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fmin>`       
:math:`\F32.\FMAX`                         :math:`\hex{97}`           :math:`[\F32~\F32] \to [\F32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fmax>`       
:math:`\F32.\COPYSIGN`                     :math:`\hex{98}`           :math:`[\F32~\F32] \to [\F32]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fcopysign>`  
:math:`\F64.\ABS`                          :math:`\hex{99}`           :math:`[\F64] \to [\F64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fabs>`        
:math:`\F64.\NEG`                          :math:`\hex{9A}`           :math:`[\F64] \to [\F64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fneg>`        
:math:`\F64.\CEIL`                         :math:`\hex{9B}`           :math:`[\F64] \to [\F64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fceil>`       
:math:`\F64.\FLOOR`                        :math:`\hex{9C}`           :math:`[\F64] \to [\F64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-ffloor>`      
:math:`\F64.\TRUNC`                        :math:`\hex{9D}`           :math:`[\F64] \to [\F64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-ftrunc>`      
:math:`\F64.\NEAREST`                      :math:`\hex{9E}`           :math:`[\F64] \to [\F64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fnearest>`    
:math:`\F64.\SQRT`                         :math:`\hex{9F}`           :math:`[\F64] \to [\F64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-fsqrt>`       
:math:`\F64.\ADD`                          :math:`\hex{A0}`           :math:`[\F64~\F64] \to [\F64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fadd>`       
:math:`\F64.\SUB`                          :math:`\hex{A1}`           :math:`[\F64~\F64] \to [\F64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fsub>`       
:math:`\F64.\MUL`                          :math:`\hex{A2}`           :math:`[\F64~\F64] \to [\F64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fmul>`       
:math:`\F64.\DIV`                          :math:`\hex{A3}`           :math:`[\F64~\F64] \to [\F64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fdiv>`       
:math:`\F64.\FMIN`                         :math:`\hex{A4}`           :math:`[\F64~\F64] \to [\F64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fmin>`       
:math:`\F64.\FMAX`                         :math:`\hex{A5}`           :math:`[\F64~\F64] \to [\F64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fmax>`       
:math:`\F64.\COPYSIGN`                     :math:`\hex{A6}`           :math:`[\F64~\F64] \to [\F64]`                 :ref:`validation <valid-binop>`          :ref:`execution <exec-binop>`, :ref:`operator <op-fcopysign>`  
:math:`\I32.\WRAP\K{\_}\I64`               :math:`\hex{A7}`           :math:`[\I64] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-wrap>`       
:math:`\I32.\TRUNC\K{\_}\F32\K{\_s}`       :math:`\hex{A8}`           :math:`[\F32] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_s>`    
:math:`\I32.\TRUNC\K{\_}\F32\K{\_u}`       :math:`\hex{A9}`           :math:`[\F32] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_u>`    
:math:`\I32.\TRUNC\K{\_}\F64\K{\_s}`       :math:`\hex{AA}`           :math:`[\F64] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_s>`    
:math:`\I32.\TRUNC\K{\_}\F64\K{\_u}`       :math:`\hex{AB}`           :math:`[\F64] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_u>`    
:math:`\I64.\EXTEND\K{\_}\I32\K{\_s}`      :math:`\hex{AC}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-extend_s>`   
:math:`\I64.\EXTEND\K{\_}\I32\K{\_u}`      :math:`\hex{AD}`           :math:`[\I32] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-extend_u>`   
:math:`\I64.\TRUNC\K{\_}\F32\K{\_s}`       :math:`\hex{AE}`           :math:`[\F32] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_s>`    
:math:`\I64.\TRUNC\K{\_}\F32\K{\_u}`       :math:`\hex{AF}`           :math:`[\F32] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_u>`    
:math:`\I64.\TRUNC\K{\_}\F64\K{\_s}`       :math:`\hex{B0}`           :math:`[\F64] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_s>`    
:math:`\I64.\TRUNC\K{\_}\F64\K{\_u}`       :math:`\hex{B1}`           :math:`[\F64] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_u>`    
:math:`\F32.\CONVERT\K{\_}\I32\K{\_s}`     :math:`\hex{B2}`           :math:`[\I32] \to [\F32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-convert_s>`  
:math:`\F32.\CONVERT\K{\_}\I32\K{\_u}`     :math:`\hex{B3}`           :math:`[\I32] \to [\F32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-convert_u>`  
:math:`\F32.\CONVERT\K{\_}\I64\K{\_s}`     :math:`\hex{B4}`           :math:`[\I64] \to [\F32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-convert_s>`  
:math:`\F32.\CONVERT\K{\_}\I64\K{\_u}`     :math:`\hex{B5}`           :math:`[\I64] \to [\F32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-convert_u>`  
:math:`\F32.\DEMOTE\K{\_}\F64`             :math:`\hex{B6}`           :math:`[\F64] \to [\F32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-demote>`     
:math:`\F64.\CONVERT\K{\_}\I32\K{\_s}`     :math:`\hex{B7}`           :math:`[\I32] \to [\F64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-convert_s>`  
:math:`\F64.\CONVERT\K{\_}\I32\K{\_u}`     :math:`\hex{B8}`           :math:`[\I32] \to [\F64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-convert_u>`  
:math:`\F64.\CONVERT\K{\_}\I64\K{\_s}`     :math:`\hex{B9}`           :math:`[\I64] \to [\F64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-convert_s>`  
:math:`\F64.\CONVERT\K{\_}\I64\K{\_u}`     :math:`\hex{BA}`           :math:`[\I64] \to [\F64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-convert_u>`  
:math:`\F64.\PROMOTE\K{\_}\F32`            :math:`\hex{BB}`           :math:`[\F32] \to [\F64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-promote>`    
:math:`\I32.\REINTERPRET\K{\_}\F32`        :math:`\hex{BC}`           :math:`[\F32] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\I64.\REINTERPRET\K{\_}\F64`        :math:`\hex{BD}`           :math:`[\F64] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\F32.\REINTERPRET\K{\_}\I32`        :math:`\hex{BE}`           :math:`[\I32] \to [\F32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\F64.\REINTERPRET\K{\_}\I64`        :math:`\hex{BF}`           :math:`[\I64] \to [\F64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\I32.\EXTEND\K{8\_s}`               :math:`\hex{C0}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`  
:math:`\I32.\EXTEND\K{16\_s}`              :math:`\hex{C1}`           :math:`[\I32] \to [\I32]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`  
:math:`\I64.\EXTEND\K{8\_s}`               :math:`\hex{C2}`           :math:`[\I64] \to [\I64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`  
:math:`\I64.\EXTEND\K{16\_s}`              :math:`\hex{C3}`           :math:`[\I64] \to [\I64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`  
:math:`\I64.\EXTEND\K{32\_s}`              :math:`\hex{C4}`           :math:`[\I64] \to [\I64]`                      :ref:`validation <valid-unop>`           :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`  
(reserved)                                 :math:`\hex{C5}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{C6}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{C7}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{C8}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{C9}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{CA}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{CB}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{CC}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{CD}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{CE}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{CF}`                                                                                                                                                                  
:math:`\REFNULL~t`                         :math:`\hex{D0}`           :math:`[] \to [t]`                             :ref:`validation <valid-ref.null>`       :ref:`execution <exec-ref.null>`                               
:math:`\REFISNULL`                         :math:`\hex{D1}`           :math:`[t] \to [\I32]`                         :ref:`validation <valid-ref.is_null>`    :ref:`execution <exec-ref.is_null>`                            
:math:`\REFFUNC~x`                         :math:`\hex{D2}`           :math:`[] \to [\FUNCREF]`                      :ref:`validation <valid-ref.func>`       :ref:`execution <exec-ref.func>`                               
(reserved)                                 :math:`\hex{D3}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{D4}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{D5}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{D6}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{D7}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{D8}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{D9}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{DA}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{DB}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{DC}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{DD}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{DE}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{DF}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E0}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E1}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E2}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E3}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E4}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E5}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E6}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E7}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E8}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{E9}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{EA}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{EB}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{EC}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{ED}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{EE}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{EF}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F0}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F1}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F2}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F3}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F4}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F5}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F6}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F7}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F8}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{F9}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{FA}`                                                                                                                                                                  
(reserved)                                 :math:`\hex{FB}`                                                                                                                                                                  
:math:`\I32.\TRUNC\K{\_sat\_}\F32\K{\_s}`  :math:`\hex{FC}~\hex{00}`  :math:`[\F32] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_s>`
:math:`\I32.\TRUNC\K{\_sat\_}\F32\K{\_u}`  :math:`\hex{FC}~\hex{01}`  :math:`[\F32] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_u>`
:math:`\I32.\TRUNC\K{\_sat\_}\F64\K{\_s}`  :math:`\hex{FC}~\hex{02}`  :math:`[\F64] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_s>`
:math:`\I32.\TRUNC\K{\_sat\_}\F64\K{\_u}`  :math:`\hex{FC}~\hex{03}`  :math:`[\F64] \to [\I32]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_u>`
:math:`\I64.\TRUNC\K{\_sat\_}\F32\K{\_s}`  :math:`\hex{FC}~\hex{04}`  :math:`[\F32] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_s>`
:math:`\I64.\TRUNC\K{\_sat\_}\F32\K{\_u}`  :math:`\hex{FC}~\hex{05}`  :math:`[\F32] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_u>`
:math:`\I64.\TRUNC\K{\_sat\_}\F64\K{\_s}`  :math:`\hex{FC}~\hex{06}`  :math:`[\F64] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_s>`
:math:`\I64.\TRUNC\K{\_sat\_}\F64\K{\_u}`  :math:`\hex{FC}~\hex{07}`  :math:`[\F64] \to [\I64]`                      :ref:`validation <valid-cvtop>`          :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_u>`
:math:`\MEMORYINIT`                        :math:`\hex{FC}~\hex{08}`  :math:`[\I32~\I32~\I32] \to []`                :ref:`validation <valid-memory.init>`    :ref:`execution <exec-memory.init>`                            
:math:`\DATADROP`                          :math:`\hex{FC}~\hex{09}`  :math:`[] \to []`                              :ref:`validation <valid-data.drop>`      :ref:`execution <exec-data.drop>`                              
:math:`\MEMORYCOPY`                        :math:`\hex{FC}~\hex{0A}`  :math:`[\I32~\I32~\I32] \to []`                :ref:`validation <valid-memory.copy>`    :ref:`execution <exec-memory.copy>`                            
:math:`\MEMORYFILL`                        :math:`\hex{FC}~\hex{0B}`  :math:`[\I32~\I32~\I32] \to []`                :ref:`validation <valid-memory.fill>`    :ref:`execution <exec-memory.fill>`                            
:math:`\TABLEINIT`                         :math:`\hex{FC}~\hex{0C}`  :math:`[\I32~\I32~\I32] \to []`                :ref:`validation <valid-table.init>`     :ref:`execution <exec-table.init>`                             
:math:`\ELEMDROP`                          :math:`\hex{FC}~\hex{0D}`  :math:`[] \to []`                              :ref:`validation <valid-elem.drop>`      :ref:`execution <exec-elem.drop>`                              
:math:`\TABLECOPY`                         :math:`\hex{FC}~\hex{0E}`  :math:`[\I32~\I32~\I32] \to []`                :ref:`validation <valid-table.copy>`     :ref:`execution <exec-table.copy>`                             
:math:`\TABLEGROW`                         :math:`\hex{FC}~\hex{0F}`  :math:`[t~\I32] \to []`                        :ref:`validation <valid-table.grow>`     :ref:`execution <exec-table.grow>`                             
:math:`\TABLESIZE`                         :math:`\hex{FC}~\hex{10}`  :math:`[] \to []`                              :ref:`validation <valid-table.size>`     :ref:`execution <exec-table.size>`                             
:math:`\TABLEFILL`                         :math:`\hex{FC}~\hex{11}`  :math:`[\I32~t~\I32] \to []`                   :ref:`validation <valid-table.fill>`     :ref:`execution <exec-table.fill>`                             
=========================================  =========================  =============================================  =======================================  ===============================================================


================================================
FILE: document/core/appendix/index-rules.rst
================================================
.. _index-rules:

Index of Semantic Rules
-----------------------


.. index:: validation
.. _index-valid:

Typing of Static Constructs
~~~~~~~~~~~~~~~~~~~~~~~~~~~

===============================================  ===============================================================================
Construct                                        Judgement
===============================================  ===============================================================================
:ref:`Limits <valid-limits>`                     :math:`\vdashlimits \limits : k`
:ref:`Function type <valid-functype>`            :math:`\vdashfunctype \functype \ok`
:ref:`Block type <valid-blocktype>`              :math:`\vdashblocktype \blocktype \ok`
:ref:`Table type <valid-tabletype>`              :math:`\vdashtabletype \tabletype \ok`
:ref:`Memory type <valid-memtype>`               :math:`\vdashmemtype \memtype \ok`
:ref:`Global type <valid-globaltype>`            :math:`\vdashglobaltype \globaltype \ok`
:ref:`External type <valid-externtype>`          :math:`\vdashexterntype \externtype \ok`
:ref:`Instruction <valid-instr>`                 :math:`S;C \vdashinstr \instr : \stacktype`
:ref:`Instruction sequence <valid-instr-seq>`    :math:`S;C \vdashinstrseq \instr^\ast : \stacktype`
:ref:`Expression <valid-expr>`                   :math:`C \vdashexpr \expr : \resulttype`
:ref:`Function <valid-func>`                     :math:`C \vdashfunc \func : \functype`
:ref:`Table <valid-table>`                       :math:`C \vdashtable \table : \tabletype`
:ref:`Memory <valid-mem>`                        :math:`C \vdashmem \mem : \memtype`
:ref:`Global <valid-global>`                     :math:`C \vdashglobal \global : \globaltype`
:ref:`Element segment <valid-elem>`              :math:`C \vdashelem \elem : \reftype`
:ref:`Element mode <valid-elemmode>`             :math:`C \vdashelemmode \elemmode : \reftype`
:ref:`Data segment <valid-data>`                 :math:`C \vdashdata \data \ok`
:ref:`Data mode <valid-datamode>`                :math:`C \vdashdatamode \datamode \ok`
:ref:`Start function <valid-start>`              :math:`C \vdashstart \start \ok`
:ref:`Export <valid-export>`                     :math:`C \vdashexport \export : \externtype`
:ref:`Export description <valid-exportdesc>`     :math:`C \vdashexportdesc \exportdesc : \externtype`
:ref:`Import <valid-import>`                     :math:`C \vdashimport \import : \externtype`
:ref:`Import description <valid-importdesc>`     :math:`C \vdashimportdesc \importdesc : \externtype`
:ref:`Module <valid-module>`                     :math:`\vdashmodule \module : \externtype^\ast \to \externtype^\ast`
===============================================  ===============================================================================


.. index:: runtime

Typing of Runtime Constructs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

===============================================  ===============================================================================
Construct                                        Judgement
===============================================  ===============================================================================
:ref:`Value <valid-val>`                         :math:`S \vdashval \val : \valtype`
:ref:`Result <valid-result>`                     :math:`S \vdashresult \result : \resulttype`
:ref:`External value <valid-externval>`          :math:`S \vdashexternval \externval : \externtype`
:ref:`Function instance <valid-funcinst>`        :math:`S \vdashfuncinst \funcinst : \functype`
:ref:`Table instance <valid-tableinst>`          :math:`S \vdashtableinst \tableinst : \tabletype`
:ref:`Memory instance <valid-meminst>`           :math:`S \vdashmeminst \meminst : \memtype`
:ref:`Global instance <valid-globalinst>`        :math:`S \vdashglobalinst \globalinst : \globaltype`
:ref:`Element instance <valid-eleminst>`         :math:`S \vdasheleminst \eleminst \ok`
:ref:`Data instance <valid-datainst>`            :math:`S \vdashdatainst \datainst \ok`
:ref:`Export instance <valid-exportinst>`        :math:`S \vdashexportinst \exportinst \ok`
:ref:`Module instance <valid-moduleinst>`        :math:`S \vdashmoduleinst \moduleinst : C`
:ref:`Store <valid-store>`                       :math:`\vdashstore \store \ok`
:ref:`Configuration <valid-config>`              :math:`\vdashconfig \config \ok`
:ref:`Thread <valid-thread>`                     :math:`S;\resulttype^? \vdashthread \thread : \resulttype`
:ref:`Frame <valid-frame>`                       :math:`S \vdashframe \frame : C`
===============================================  ===============================================================================


Constantness
~~~~~~~~~~~~

===============================================  ===============================================================================
Construct                                        Judgement
===============================================  ===============================================================================
:ref:`Constant expression <valid-constant>`      :math:`C \vdashexprconst \expr \const`
:ref:`Constant instruction <valid-constant>`     :math:`C \vdashinstrconst \instr \const`
===============================================  ===============================================================================


Matching
~~~~~~~~

===============================================  ===============================================================================
Construct                                        Judgement
===============================================  ===============================================================================
:ref:`External type <match-externtype>`          :math:`\vdashexterntypematch \externtype_1 \matchesexterntype \externtype_2`
:ref:`Limits <match-limits>`                     :math:`\vdashlimitsmatch \limits_1 \matcheslimits \limits_2`
===============================================  ===============================================================================


Store Extension
~~~~~~~~~~~~~~~

===============================================  ===============================================================================
Construct                                        Judgement
===============================================  ===============================================================================
:ref:`Function instance <extend-funcinst>`       :math:`\vdashfuncinstextends \funcinst_1 \extendsto \funcinst_2`
:ref:`Table instance <extend-tableinst>`         :math:`\vdashtableinstextends \tableinst_1 \extendsto \tableinst_2`
:ref:`Memory instance <extend-meminst>`          :math:`\vdashmeminstextends \meminst_1 \extendsto \meminst_2`
:ref:`Global instance <extend-globalinst>`       :math:`\vdashglobalinstextends \globalinst_1 \extendsto \globalinst_2`
:ref:`Element instance <extend-eleminst>`         :math:`\vdasheleminstextends \eleminst_1 \extendsto \eleminst_2`
:ref:`Data instance <extend-datainst>`           :math:`\vdashdatainstextends \datainst_1 \extendsto \datainst_2`
:ref:`Store <extend-store>`                      :math:`\vdashstoreextends \store_1 \extendsto \store_2`
===============================================  ===============================================================================


Execution
~~~~~~~~~

===============================================  ===============================================================================
Construct                                        Judgement
===============================================  ===============================================================================
:ref:`Instruction <exec-instr>`                  :math:`S;F;\instr^\ast \stepto S';F';{\instr'}^\ast`
:ref:`Expression <exec-expr>`                    :math:`S;F;\expr \stepto  S';F';\expr'`
===============================================  ===============================================================================


================================================
FILE: document/core/appendix/index-types.rst
================================================
.. index:: type
.. _index-type:

Index of Types
--------------

========================================  ===========================================  ===============================================================================
Category                                  Constructor                                         Binary Opcode
========================================  ===========================================  ===============================================================================
:ref:`Type index <syntax-typeidx>`        :math:`x`                                    (positive number as |Bs32| or |Bu32|)
:ref:`Number type <syntax-numtype>`       |I32|                                        :math:`\hex{7F}` (-1 as |Bs7|)
:ref:`Number type <syntax-numtype>`       |I64|                                        :math:`\hex{7E}` (-2 as |Bs7|)
:ref:`Number type <syntax-numtype>`       |F32|                                        :math:`\hex{7D}` (-3 as |Bs7|)
:ref:`Number type <syntax-numtype>`       |F64|                                        :math:`\hex{7C}` (-4 as |Bs7|)
(reserved)                                                                             :math:`\hex{7B}` .. :math:`\hex{71}`
:ref:`Reference type <syntax-reftype>`    |FUNCREF|                                    :math:`\hex{70}` (-16 as |Bs7|)
:ref:`Reference type <syntax-reftype>`    |EXTERNREF|                                  :math:`\hex{6F}` (-17 as |Bs7|)
(reserved)                                                                             :math:`\hex{6E}` .. :math:`\hex{61}`
:ref:`Function type <syntax-functype>`    :math:`[\valtype^\ast] \to [\valtype^\ast]`  :math:`\hex{60}` (-32 as |Bs7|)
(reserved)                                                                             :math:`\hex{5F}` .. :math:`\hex{41}`
:ref:`Result type <syntax-resulttype>`    :math:`[\epsilon]`                           :math:`\hex{40}` (-64 as |Bs7|)
:ref:`Table type <syntax-tabletype>`      :math:`\limits~\reftype`                     (none)
:ref:`Memory type <syntax-memtype>`       :math:`\limits`                              (none)
:ref:`Global type <syntax-globaltype>`    :math:`\mut~\valtype`                        (none)
========================================  ===========================================  ===============================================================================


================================================
FILE: document/core/appendix/index.rst
================================================
.. _appendix:

Appendix
========

.. toctree::
   :maxdepth: 2

   embedding
   implementation
   algorithm
   custom
   properties

.. only:: singlehtml

   .. toctree::

      index-types
      index-instructions
      index-rules



================================================
FILE: document/core/appendix/properties.rst
================================================
.. index:: ! soundness, type system
.. _soundness:

Soundness
---------

The :ref:`type system <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 <syntax-local>` or :ref:`global <syntax-global>` variable will only contain type-correct values, every :ref:`instruction <syntax-instr>` will only be applied to operands of the expected type, and every :ref:`function <syntax-func>` :ref:`invocation <exec-invocation>` always evaluates to a result of the right type (if it does not :ref:`trap <trap>` or diverge).

* No memory location will be read or written except those explicitly defined by the program, i.e., as a :ref:`local <syntax-local>`, a :ref:`global <syntax-global>`, an element in a :ref:`table <syntax-table>`, or a location within a linear :ref:`memory <syntax-mem>`.

* There is no undefined behavior,
  i.e., the :ref:`execution rules <exec>` cover all possible cases that can occur in a :ref:`valid <valid>` program, and the rules are mutually consistent.

Soundness also is instrumental in ensuring additional properties, most notably, *encapsulation* of function and module scopes: no :ref:`locals <syntax-local>` can be accessed outside their own function and no :ref:`module <syntax-module>` components can be accessed outside their own module unless they are explicitly :ref:`exported <syntax-export>` or :ref:`imported <syntax-import>`.

The typing rules defining WebAssembly :ref:`validation <valid>` only cover the *static* components of a WebAssembly program.
In order to state and prove soundness precisely, the typing rules must be extended to the *dynamic* components of the abstract :ref:`runtime <syntax-runtime>`, that is, the :ref:`store <syntax-store>`, :ref:`configurations <syntax-config>`, and :ref:`administrative instructions <syntax-instr-admin>`. [#cite-pldi2017]_


.. index:: value, value type, result, result type, trap
.. _valid-result:

Results
~~~~~~~

:ref:`Results <syntax-result>` can be classified by :ref:`result types <syntax-resulttype>` as follows.

:ref:`Results <syntax-result>` :math:`\val^\ast`
................................................

* For each :ref:`value <syntax-val>` :math:`\val_i` in :math:`\val^\ast`:

  * The value :math:`\val_i` is :ref:`valid <valid-val>` with some :ref:`value type <syntax-valtype>` :math:`t_i`.

* Let :math:`t^\ast` be the concatenation of all :math:`t_i`.

* Then the result is valid with :ref:`result type <syntax-resulttype>` :math:`[t^\ast]`.

.. math::
   \frac{
     (S \vdashval \val : t)^\ast
   }{
     S \vdashresult \val^\ast : [t^\ast]
   }


:ref:`Results <syntax-result>` :math:`\TRAP`
............................................

* The result is valid with :ref:`result type <syntax-resulttype>` :math:`[t^\ast]`, for any sequence :math:`t^\ast` of :ref:`value types <syntax-valtype>`.

.. math::
   \frac{
   }{
     S \vdashresult \TRAP : [t^\ast]
   }


.. _module-context:
.. _valid-store:

Store Validity
~~~~~~~~~~~~~~

The following typing rules specify when a runtime :ref:`store <syntax-store>` :math:`S` is *valid*.
A valid store must consist of
:ref:`function <syntax-funcinst>`, :ref:`table <syntax-tableinst>`, :ref:`memory <syntax-meminst>`, :ref:`global <syntax-globalinst>`, and :ref:`module <syntax-moduleinst>` instances that are themselves valid, relative to :math:`S`.

To that end, each kind of instance is classified by a respective :ref:`function <syntax-functype>`, :ref:`table <syntax-tabletype>`, :ref:`memory <syntax-memtype>`, or :ref:`global <syntax-globaltype>` type.
Module instances are classified by *module contexts*, which are regular :ref:`contexts <context>` repurposed as module types describing the :ref:`index spaces <syntax-index>` defined by a module.



.. index:: store, function instance, table instance, memory instance, global instance, function type, table type, memory type, global type

:ref:`Store <syntax-store>` :math:`S`
.....................................

* Each :ref:`function instance <syntax-funcinst>` :math:`\funcinst_i` in :math:`S.\SFUNCS` must be :ref:`valid <valid-funcinst>` with some :ref:`function type <syntax-functype>` :math:`\functype_i`.

* Each :ref:`table instance <syntax-tableinst>` :math:`\tableinst_i` in :math:`S.\STABLES` must be :ref:`valid <valid-tableinst>` with some :ref:`table type <syntax-tabletype>` :math:`\tabletype_i`.

* Each :ref:`memory instance <syntax-meminst>` :math:`\meminst_i` in :math:`S.\SMEMS` must be :ref:`valid <valid-meminst>` with some :ref:`memory type <syntax-memtype>` :math:`\memtype_i`.

* Each :ref:`global instance <syntax-globalinst>` :math:`\globalinst_i` in :math:`S.\SGLOBALS` must be :ref:`valid <valid-globalinst>` with some  :ref:`global type <syntax-globaltype>` :math:`\globaltype_i`.

* Each :ref:`element instance <syntax-eleminst>` :math:`\eleminst_i` in :math:`S.\SELEMS` must be :ref:`valid <valid-eleminst>`.

* Each :ref:`data instance <syntax-datainst>` :math:`\datainst_i` in :math:`S.\SDATAS` must be :ref:`valid <valid-datainst>`.

* Then the store is valid.

.. math::
   ~\\[-1ex]
   \frac{
     \begin{array}{@{}c@{}}
     (S \vdashfuncinst \funcinst : \functype)^\ast
     \qquad
     (S \vdashtableinst \tableinst : \tabletype)^\ast
     \\
     (S \vdashmeminst \meminst : \memtype)^\ast
     \qquad
     (S \vdashglobalinst \globalinst : \globaltype)^\ast
     \\
     (S \vdasheleminst \eleminst \ok)^\ast
     \qquad
     (S \vdashdatainst \datainst \ok)^\ast
     \\
     S = \{
       \SFUNCS~\funcinst^\ast,
       \STABLES~\tableinst^\ast,
       \SMEMS~\meminst^\ast,
       \SGLOBALS~\globalinst^\ast,
       \SELEMS~\eleminst^\ast,
       \SDATAS~\datainst^\ast \}
     \end{array}
   }{
     \vdashstore S \ok
   }


.. index:: function type, function instance
.. _valid-funcinst:

:ref:`Function Instances <syntax-funcinst>` :math:`\{\FITYPE~\functype, \FIMODULE~\moduleinst, \FICODE~\func\}`
.......................................................................................................................

* The :ref:`function type <syntax-functype>` :math:`\functype` must be :ref:`valid <valid-functype>`.

* The :ref:`module instance <syntax-moduleinst>` :math:`\moduleinst` must be :ref:`valid <valid-moduleinst>` with some :ref:`context <context>` :math:`C`.

* Under :ref:`context <context>` :math:`C`, the :ref:`function <syntax-func>` :math:`\func` must be :ref:`valid <valid-func>` with :ref:`function type <syntax-functype>` :math:`\functype`.

* Then the function instance is valid with :ref:`function type <syntax-functype>` :math:`\functype`.

.. math::
   \frac{
     \vdashfunctype \functype \ok
     \qquad
     S \vdashmoduleinst \moduleinst : C
     \qquad
     C \vdashfunc \func : \functype
   }{
     S \vdashfuncinst \{\FITYPE~\functype, \FIMODULE~\moduleinst, \FICODE~\func\} : \functype
   }


.. index:: function type, function instance, host function
.. _valid-hostfuncinst:

:ref:`Host Function Instances <syntax-funcinst>` :math:`\{\FITYPE~\functype, \FIHOSTCODE~\X{hf}\}`
..................................................................................................

* The :ref:`function type <syntax-functype>` :math:`\functype` must be :ref:`valid <valid-functype>`.

* Let :math:`[t_1^\ast] \to [t_2^\ast]` be the :ref:`function type <syntax-functype>` :math:`\functype`.

* For every :ref:`valid <valid-store>` :ref:`store <syntax-store>` :math:`S_1` :ref:`extending <extend-store>` :math:`S` and every sequence :math:`\val^\ast` of :ref:`values <syntax-val>` whose :ref:`types <valid-val>` coincide with :math:`t_1^\ast`:

  * :ref:`Executing <exec-invoke-host>` :math:`\X{hf}` in store :math:`S_1` with arguments :math:`\val^\ast` has a non-empty set of possible outcomes.

  * For every element :math:`R` of this set:

    * Either :math:`R` must be :math:`\bot` (i.e., divergence).

    * Or :math:`R` consists of a :ref:`valid <valid-store>` :ref:`store <syntax-store>` :math:`S_2` :ref:`extending <extend-store>` :math:`S_1` and a :ref:`result <syntax-result>` :math:`\result` whose :ref:`type <valid-result>` coincides with :math:`[t_2^\ast]`.

* Then the function instance is valid with :ref:`function type <syntax-functype>` :math:`\functype`.

.. math::
   \frac{
     \begin{array}[b]{@{}l@{}}
     \vdashfunctype [t_1^\ast] \to [t_2^\ast] \ok \\
     \end{array}
     \quad
     \begin{array}[b]{@{}l@{}}
     \forall S_1, \val^\ast,~
       {\vdashstore S_1 \ok} \wedge
       {\vdashstoreextends S \extendsto S_1} \wedge
       {S_1 \vdashresult \val^\ast : [t_1^\ast]}
       \Longrightarrow {} \\ \qquad
       \X{hf}(S_1; \val^\ast) \supset \emptyset \wedge {} \\ \qquad
     \forall R \in \X{hf}(S_1; \val^\ast),~
       R = \bot \vee {} \\ \qquad\qquad
       \exists S_2, \result,~
       {\vdashstore S_2 \ok} \wedge
       {\vdashstoreextends S_1 \extendsto S_2} \wedge
       {S_2 \vdashresult \result : [t_2^\ast]} \wedge
       R = (S_2; \result)
     \end{array}
   }{
     S \vdashfuncinst \{\FITYPE~[t_1^\ast] \to [t_2^\ast], \FIHOSTCODE~\X{hf}\} : [t_1^\ast] \to [t_2^\ast]
   }

.. note::
   This rule states that, if appropriate pre-conditions about store and arguments are satisfied, then executing the host function must satisfy appropriate post-conditions about store and results.
   The post-conditions match the ones in the :ref:`execution rule <exec-invoke-host>` for invoking host functions.

   Any store under which the function is invoked is assumed to be an extension of the current store.
   That way, the function itself is able to make sufficient assumptions about future stores.


.. index:: table type, table instance, limits, function address
.. _valid-tableinst:

:ref:`Table Instances <syntax-tableinst>` :math:`\{ \TITYPE~(\limits~t), \TIELEM~\reff^\ast \}`
...............................................................................................

* The :ref:`table type <syntax-tabletype>` :math:`\limits~t` must be :ref:`valid <valid-tabletype>`.

* The length of :math:`\reff^\ast` must equal :math:`\limits.\LMIN`.

* For each :ref:`reference <syntax-ref>` :math:`\reff_i` in the table's elements :math:`\reff^n`:

  * The :ref:`reference <syntax-ref>` :math:`\reff_i` must be :ref:`valid <valid-ref>` with :ref:`reference type <syntax-reftype>` :math:`t`.

* Then the table instance is valid with :ref:`table type <syntax-tabletype>` :math:`\limits~t`.

.. math::
   \frac{
     \vdashtabletype \limits~t \ok
     \qquad
     n = \limits.\LMIN
     \qquad
     (S \vdash \reff : t)^n
   }{
     S \vdashtableinst \{ \TITYPE~(\limits~t), \TIELEM~\reff^n \} : \limits~t
   }


.. index:: memory type, memory instance, limits, byte
.. _valid-meminst:

:ref:`Memory Instances <syntax-meminst>` :math:`\{ \MITYPE~\limits, \MIDATA~b^\ast \}`
......................................................................................

* The :ref:`memory type <syntax-memtype>` :math:`\{\LMIN~n, \LMAX~m^?\}` must be :ref:`valid <valid-memtype>`.

* The length of :math:`b^\ast` must equal :math:`\limits.\LMIN` multiplied by the :ref:`page size <page-size>` :math:`64\,\F{Ki}`.

* Then the memory instance is valid with :ref:`memory type <syntax-memtype>` :math:`\limits`.

.. math::
   \frac{
     \vdashmemtype \limits \ok
     \qquad
     n = \limits.\LMIN \cdot 64\,\F{Ki}
   }{
     S \vdashmeminst \{ \MITYPE~\limits, \MIDATA~b^n \} : \limits
   }


.. index:: global type, global instance, value, mutability
.. _valid-globalinst:

:ref:`Global Instances <syntax-globalinst>` :math:`\{ \GITYPE~(\mut~t), \GIVALUE~\val \}`
.........................................................................................

* The :ref:`global type <syntax-globaltype>` :math:`\mut~t` must be :ref:`valid <valid-globaltype>`.

* The :ref:`value <syntax-val>` :math:`\val` must be :ref:`valid <valid-val>` with :ref:`value type <syntax-valtype>` :math:`t`.

* Then the global instance is valid with :ref:`global type <syntax-globaltype>` :math:`\mut~t`.

.. math::
   \frac{
     \vdashglobaltype \mut~t \ok
     \qquad
     S \vdashval \val : t
   }{
     S \vdashglobalinst \{ \GITYPE~(\mut~t), \GIVALUE~\val \} : \mut~t
   }


.. index:: element instance, reference
.. _valid-eleminst:

:ref:`Element Instances <syntax-eleminst>` :math:`\{ \EIELEM~\X{fa}^\ast \}`
............................................................................

* For each :ref:`reference <syntax-ref>` :math:`\reff_i` in the elements :math:`\reff^n`:

  * The :ref:`reference <syntax-ref>` :math:`\reff_i` must be :ref:`valid <valid-ref>` with :ref:`reference type <syntax-reftype>` :math:`t`.

* Then the table instance is valid.

.. math::
   \frac{
     (S \vdash \reff : t)^\ast
   }{
     S \vdasheleminst \{ \EITYPE~t, \EIELEM~\reff^\ast \} \ok
   }


.. index:: data instance, byte
.. _valid-datainst:

:ref:`Data Instances <syntax-eleminst>` :math:`\{ \DIDATA~b^\ast \}`
....................................................................

* The data instance is valid.

.. math::
   \frac{
   }{
     S \vdashdatainst \{ \DIDATA~b^\ast \} \ok
   }


.. index:: external type, export instance, name, external value
.. _valid-exportinst:

:ref:`Export Instances <syntax-exportinst>` :math:`\{ \EINAME~\name, \EIVALUE~\externval \}`
.......................................................................................................

* The :ref:`external value <syntax-externval>` :math:`\externval` must be :ref:`valid <valid-externval>` with some :ref:`external type <syntax-externtype>` :math:`\externtype`.

* Then the export instance is valid.

.. math::
   \frac{
     S \vdashexternval \externval : \externtype
   }{
     S \vdashexportinst \{ \EINAME~\name, \EIVALUE~\externval \} \ok
   }


.. index:: module instance, context
.. _valid-moduleinst:

:ref:`Module Instances <syntax-moduleinst>` :math:`\moduleinst`
...............................................................

* Each :ref:`function type <syntax-functype>` :math:`\functype_i` in :math:`\moduleinst.\MITYPES` must be :ref:`valid <valid-functype>`.

* For each :ref:`function address <syntax-funcaddr>` :math:`\funcaddr_i` in :math:`\moduleinst.\MIFUNCS`, the :ref:`external value <syntax-externval>` :math:`\EVFUNC~\funcaddr_i` must be :ref:`valid <valid-externval-func>` with some :ref:`external type <syntax-externtype>` :math:`\ETFUNC~\functype'_i`.

* For each :ref:`table address <syntax-tableaddr>` :math:`\tableaddr_i` in :math:`\moduleinst.\MITABLES`, the :ref:`external value <syntax-externval>` :math:`\EVTABLE~\tableaddr_i` must be :ref:`valid <valid-externval-table>` with some :ref:`external type <syntax-externtype>` :math:`\ETTABLE~\tabletype_i`.

* For each :ref:`memory address <syntax-memaddr>` :math:`\memaddr_i` in :math:`\moduleinst.\MIMEMS`, the :ref:`external value <syntax-externval>` :math:`\EVMEM~\memaddr_i` must be :ref:`valid <valid-externval-mem>` with some :ref:`external type <syntax-externtype>` :math:`\ETMEM~\memtype_i`.

* For each :ref:`global address <syntax-globaladdr>` :math:`\globaladdr_i` in :math:`\moduleinst.\MIGLOBALS`, the :ref:`external value <syntax-externval>` :math:`\EVGLOBAL~\globaladdr_i` must be :ref:`valid <valid-externval-global>` with some :ref:`external type <syntax-externtype>` :math:`\ETGLOBAL~\globaltype_i`.

* For each :ref:`element address <syntax-elemaddr>` :math:`\elemaddr_i` in :math:`\moduleinst.\MIELEMS`, the :ref:`element instance <syntax-eleminst>` :math:`S.\SELEMS[\elemaddr_i]` must be :ref:`valid <valid-eleminst>`.

* For each :ref:`data address <syntax-dataaddr>` :math:`\dataaddr_i` in :math:`\moduleinst.\MIDATAS`, the :ref:`data instance <syntax-datainst>` :math:`S.\SDATAS[\dataaddr_i]` must be :ref:`valid <valid-datainst>`.

* Each :ref:`export instance <syntax-exportinst>` :math:`\exportinst_i` in :math:`\moduleinst.\MIEXPORTS` must be :ref:`valid <valid-exportinst>`.

* For each :ref:`export instance <syntax-exportinst>` :math:`\exportinst_i` in :math:`\moduleinst.\MIEXPORTS`, the :ref:`name <syntax-name>` :math:`\exportinst_i.\EINAME` must be different from any other name occurring in :math:`\moduleinst.\MIEXPORTS`.

* Let :math:`{\functype'}^\ast` be the concatenation of all :math:`\functype'_i` in order.

* Let :math:`\tabletype^\ast` be the concatenation of all :math:`\tabletype_i` in order.

* Let :math:`\memtype^\ast` be the concatenation of all :math:`\memtype_i` in order.

* Let :math:`\globaltype^\ast` be the concatenation of all :math:`\globaltype_i` in order.

* Then the module instance is valid with :ref:`context <context>` :math:`\{\CTYPES~\functype^\ast, \CFUNCS~{\functype'}^\ast, \CTABLES~\tabletype^\ast, \CMEMS~\memtype^\ast, \CGLOBALS~\globaltype^\ast\}`.

.. math::
   ~\\[-1ex]
   \frac{
     \begin{array}{@{}c@{}}
     (\vdashfunctype \functype \ok)^\ast
     \\
     (S \vdashexternval \EVFUNC~\funcaddr : \ETFUNC~\functype')^\ast
     \qquad
     (S \vdashexternval \EVTABLE~\tableaddr : \ETTABLE~\tabletype)^\ast
     \\
     (S \vdashexternval \EVMEM~\memaddr : \ETMEM~\memtype)^\ast
     \qquad
     (S \vdashexternval \EVGLOBAL~\globaladdr : \ETGLOBAL~\globaltype)^\ast
     \\
     (S \vdasheleminst S.\SELEMS[\elemaddr] \ok)^\ast
     \qquad
     (S \vdashdatainst S.\SDATAS[\dataaddr] \ok)^\ast
     \\
     (S \vdashexportinst \exportinst \ok)^\ast
     \qquad
     (\exportinst.\EINAME)^\ast ~\mbox{disjoint}
     \end{array}
   }{
     S \vdashmoduleinst \{
       \begin{array}[t]{@{}l@{~}l@{}}
       \MITYPES & \functype^\ast, \\
       \MIFUNCS & \funcaddr^\ast, \\
       \MITABLES & \tableaddr^\ast, \\
       \MIMEMS & \memaddr^\ast, \\
       \MIGLOBALS & \globaladdr^\ast, \\
       \MIELEMS & \elemaddr^\ast, \\
       \MIDATAS & \dataaddr^\ast, \\
       \MIEXPORTS & \exportinst^\ast ~\} : \{
         \begin{array}[t]{@{}l@{~}l@{}}
         \CTYPES & \functype^\ast, \\
         \CFUNCS & {\functype'}^\ast, \\
         \CTABLES & \tabletype^\ast, \\
         \CMEMS & \memtype^\ast, \\
         \CGLOBALS & \globaltype^\ast ~\}
         \end{array}
       \end{array}
   }


.. index:: configuration, administrative instruction, store, frame
.. _frame-context:
.. _valid-config:

Configuration Validity
~~~~~~~~~~~~~~~~~~~~~~

To relate the WebAssembly :ref:`type system <valid>` to its :ref:`execution semantics <exec>`, the :ref:`typing rules for instructions <valid-instr>` must be extended to :ref:`configurations <syntax-config>` :math:`S;T`,
which relates the :ref:`store <syntax-store>` to execution :ref:`threads <syntax-thread>`.

Configurations and threads are classified by their :ref:`result type <syntax-resulttype>`.
In addition to the store :math:`S`, threads are typed under a *return type* :math:`\resulttype^?`, which controls whether and with which type a |return| instruction is allowed.
This type is absent (:math:`\epsilon`) except for instruction sequences inside an administrative |FRAME| instruction.

Finally, :ref:`frames <syntax-frame>` are classified with *frame contexts*, which extend the :ref:`module contexts <module-context>` of a frame's associated :ref:`module instance <syntax-moduleinst>` with the :ref:`locals <syntax-local>` that the frame contains.


.. index:: result type, thread

:ref:`Configurations <syntax-config>` :math:`S;T`
.................................................

* The :ref:`store <syntax-store>` :math:`S` must be :ref:`valid <valid-store>`.

* Under no allowed return type,
  the :ref:`thread <syntax-thread>` :math:`T` must be :ref:`valid <valid-thread>` with some :ref:`result type <syntax-resulttype>` :math:`[t^\ast]`.

* Then the configuration is valid with the :ref:`result type <syntax-resulttype>` :math:`[t^\ast]`.

.. math::
   \frac{
     \vdashstore S \ok
     \qquad
     S; \epsilon \vdashthread T : [t^\ast]
   }{
     \vdashconfig S; T : [t^\ast]
   }


.. index:: thread, frame, instruction, result type, context
.. _valid-thread:

:ref:`Threads <syntax-thread>` :math:`F;\instr^\ast`
....................................................

* Let :math:`\resulttype^?` be the current allowed return type.

* The :ref:`frame <syntax-frame>` :math:`F` must be :ref:`valid <valid-frame>` with a :ref:`context <context>` :math:`C`.

* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with |CRETURN| set to :math:`\resulttype^?`.

* Under context :math:`C'`,
  the instruction sequence :math:`\instr^\ast` must be :ref:`valid <valid-instr-seq>` with some type :math:`[] \to [t^\ast]`.

* Then the thread is valid with the :ref:`result type <syntax-resulttype>` :math:`[t^\ast]`.

.. math::
   \frac{
     S \vdashframe F : C
     \qquad
     S; C,\CRETURN~\resulttype^? \vdashinstrseq \instr^\ast : [] \to [t^\ast]
   }{
     S; \resulttype^? \vdashthread F; \instr^\ast : [t^\ast]
   }


.. index:: frame, local, module instance, value, value type, context
.. _valid-frame:

:ref:`Frames <syntax-frame>` :math:`\{\ALOCALS~\val^\ast, \AMODULE~\moduleinst\}`
.................................................................................

* The :ref:`module instance <syntax-moduleinst>` :math:`\moduleinst` must be :ref:`valid <valid-moduleinst>` with some :ref:`module context <module-context>` :math:`C`.

* Each :ref:`value <syntax-val>` :math:`\val_i` in :math:`\val^\ast` must be :ref:`valid <valid-val>` with some :ref:`value type <syntax-valtype>` :math:`t_i`.

* Let :math:`t^\ast` the concatenation of all :math:`t_i` in order.

* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`value types <syntax-valtype>` :math:`t^\ast` prepended to the |CLOCALS| vector.

* Then the frame is valid with :ref:`frame context <frame-context>` :math:`C'`.

.. math::
   \frac{
     S \vdashmoduleinst \moduleinst : C
     \qquad
     (S \vdashval \val : t)^\ast
   }{
     S \vdashframe \{\ALOCALS~\val^\ast, \AMODULE~\moduleinst\} : (C, \CLOCALS~t^\ast)
   }


.. index:: administrative instruction, value type, context, store
.. _valid-instr-admin:

Administrative Instructions
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Typing rules for :ref:`administrative instructions <syntax-instr-admin>` are specified as follows.
In addition to the :ref:`context <context>` :math:`C`, typing of these instructions is defined under a given :ref:`store <syntax-store>` :math:`S`.
To that end, all previous typing judgements :math:`C \vdash \X{prop}` are generalized to include the store, as in :math:`S; C \vdash \X{prop}`, by implicitly adding :math:`S` to all rules -- :math:`S` is never modified by the pre-existing rules, but it is accessed in the extra rules for :ref:`administrative instructions <valid-instr-admin>` given below.


.. index:: trap

:math:`\TRAP`
.............

* The instruction is valid with type :math:`[t_1^\ast] \to [t_2^\ast]`, for any sequences of :ref:`value types <syntax-valtype>` :math:`t_1^\ast` and :math:`t_2^\ast`.

.. math::
   \frac{
   }{
     S; C \vdashadmininstr \TRAP : [t_1^\ast] \to [t_2^\ast]
   }


.. index:: extern address

:math:`\REFEXTERNADDR~\externaddr`
..................................

* The instruction is valid with type :math:`[] \to [\EXTERNREF]`.

.. math::
   \frac{
   }{
     S; C \vdashadmininstr \REFEXTERNADDR~\externaddr : [] \to [\EXTERNREF]
   }


.. index:: function address, extern value, extern type, function type

:math:`\REFFUNCADDR~\funcaddr`
..............................

* The :ref:`external function value <syntax-externval>` :math:`\EVFUNC~\funcaddr` must be :ref:`valid <valid-externval-func>` with :ref:`external function type <syntax-externtype>` :math:`\ETFUNC \functype`.

* Then the instruction is valid with type :math:`[] \to [\FUNCREF]`.

.. math::
   \frac{
     S \vdashexternval \EVFUNC~\funcaddr : \ETFUNC~\functype
   }{
     S; C \vdashadmininstr \REFFUNCADDR~\funcaddr : [] \to [\FUNCREF]
   }


.. index:: function address, extern value, extern type, function type

:math:`\INVOKE~\funcaddr`
.........................

* The :ref:`external function value <syntax-externval>` :math:`\EVFUNC~\funcaddr` must be :ref:`valid <valid-externval-func>` with :ref:`external function type <syntax-externtype>` :math:`\ETFUNC ([t_1^\ast] \to [t_2^\ast])`.

* Then the instruction is valid with type :math:`[t_1^\ast] \to [t_2^\ast]`.

.. math::
   \frac{
     S \vdashexternval \EVFUNC~\funcaddr : \ETFUNC~[t_1^\ast] \to [t_2^\ast]
   }{
     S; C \vdashadmininstr \INVOKE~\funcaddr : [t_1^\ast] \to [t_2^\ast]
   }


.. index:: label, instruction, result type

:math:`\LABEL_n\{\instr_0^\ast\}~\instr^\ast~\END`
..................................................

* The instruction sequence :math:`\instr_0^\ast` must be :ref:`valid <valid-instr-seq>` with some type :math:`[t_1^n] \to [t_2^*]`.

* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`result type <syntax-resulttype>` :math:`[t_1^n]` prepended to the |CLABELS| vector.

* Under context :math:`C'`,
  the instruction sequence :math:`\instr^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[] \to [t_2^*]`.

* Then the compound instruction is valid with type :math:`[] \to [t_2^*]`.

.. math::
   \frac{
     S; C \vdashinstrseq \instr_0^\ast : [t_1^n] \to [t_2^*]
     \qquad
     S; C,\CLABELS\,[t_1^n] \vdashinstrseq \instr^\ast : [] \to [t_2^*]
   }{
     S; C \vdashadmininstr \LABEL_n\{\instr_0^\ast\}~\instr^\ast~\END : [] \to [t_2^*]
   }


.. index:: frame, instruction, result type

:math:`\FRAME_n\{F\}~\instr^\ast~\END`
...........................................

* Under the return type :math:`[t^n]`,
  the :ref:`thread <syntax-frame>` :math:`F; \instr^\ast` must be :ref:`valid <valid-frame>` with :ref:`result type <syntax-resulttype>` :math:`[t^n]`.

* Then the compound instruction is valid with type :math:`[] \to [t^n]`.

.. math::
   \frac{
     S; [t^n] \vdashinstrseq F; \instr^\ast : [t^n]
   }{
     S; C \vdashadmininstr \FRAME_n\{F\}~\instr^\ast~\END : [] \to [t^n]
   }


.. index:: ! store extension, store
.. _extend:

Store Extension
~~~~~~~~~~~~~~~

Programs can mutate the :ref:`store <syntax-store>` and its contained instances.
Any such modification must respect certain invariants, such as not removing allocated instances or changing immutable definitions.
While these invariants are inherent to the execution semantics of WebAssembly :ref:`instructions <exec-instr>` and :ref:`modules <exec-instantiation>`,
:ref:`host functions <syntax-hostfunc>` do not automatically adhere to them. Consequently, the required invariants must be stated as explicit constraints on the :ref:`invocation <exec-invoke-host>` of host functions.
Soundness only holds when the :ref:`embedder <embedder>` ensures these constraints.

The necessary constraints are codified by the notion of store *extension*:
a store state :math:`S'` extends state :math:`S`, written :math:`S \extendsto S'`, when the following rules hold.

.. note::
   Extension does not imply that the new store is valid, which is defined separately :ref:`above <valid-store>`.


.. index:: store, function instance, table instance, memory instance, global instance
.. _extend-store:

:ref:`Store <syntax-store>` :math:`S`
.....................................

* The length of :math:`S.\SFUNCS` must not shrink.

* The length of :math:`S.\STABLES` must not shrink.

* The length of :math:`S.\SMEMS` must not shrink.

* The length of :math:`S.\SGLOBALS` must not shrink.

* The length of :math:`S.\SELEMS` must not shrink.

* The length of :math:`S.\SDATAS` must not shrink.

* For each :ref:`function instance <syntax-funcinst>` :math:`\funcinst_i` in the original :math:`S.\SFUNCS`, the new function instance must be an :ref:`extension <extend-funcinst>` of the old.

* For each :ref:`table instance <syntax-tableinst>` :math:`\tableinst_i` in the original :math:`S.\STABLES`, the new table instance must be an :ref:`extension <extend-tableinst>` of the old.

* For each :ref:`memory instance <syntax-meminst>` :math:`\meminst_i` in the original :math:`S.\SMEMS`, the new memory instance must be an :ref:`extension <extend-meminst>` of the old.

* For each :ref:`global instance <syntax-globalinst>` :math:`\globalinst_i` in the original :math:`S.\SGLOBALS`, the new global instance must be an :ref:`extension <extend-globalinst>` of the old.

* For each :ref:`element instance <syntax-eleminst>` :math:`\eleminst_i` in the original :math:`S.\SELEMS`, the new global instance must be an :ref:`extension <extend-eleminst>` of the old.

* For each :ref:`data instance <syntax-datainst>` :math:`\datainst_i` in the original :math:`S.\SDATAS`, the new global instance must be an :ref:`extension <extend-datainst>` of the old.

.. math::
   \frac{
     \begin{array}{@{}ccc@{}}
     S_1.\SFUNCS = \funcinst_1^\ast &
     S_2.\SFUNCS = {\funcinst'_1}^\ast~\funcinst_2^\ast &
     (\vdashfuncinstextends \funcinst_1 \extendsto \funcinst'_1)^\ast \\
     S_1.\STABLES = \tableinst_1^\ast &
     S_2.\STABLES = {\tableinst'_1}^\ast~\tableinst_2^\ast &
     (\vdashtableinstextends \tableinst_1 \extendsto \tableinst'_1)^\ast \\
     S_1.\SMEMS = \meminst_1^\ast &
     S_2.\SMEMS = {\meminst'_1}^\ast~\meminst_2^\ast &
     (\vdashmeminstextends \meminst_1 \extendsto \meminst'_1)^\ast \\
     S_1.\SGLOBALS = \globalinst_1^\ast &
     S_2.\SGLOBALS = {\globalinst'_1}^\ast~\globalinst_2^\ast &
     (\vdashglobalinstextends \globalinst_1 \extendsto \globalinst'_1)^\ast \\
     S_1.\SELEMS = \eleminst_1^\ast &
     S_2.\SELEMS = {\eleminst'_1}^\ast~\eleminst_2^\ast &
     (\vdasheleminstextends \eleminst_1 \extendsto \eleminst'_1)^\ast \\
     S_1.\SDATAS = \datainst_1^\ast &
     S_2.\SDATAS = {\datainst'_1}^\ast~\datainst_2^\ast &
     (\vdashdatainstextends \datainst_1 \extendsto \datainst'_1)^\ast \\
     \end{array}
   }{
     \vdashstoreextends S_1 \extendsto S_2
   }


.. index:: function instance
.. _extend-funcinst:

:ref:`Function Instance <syntax-funcinst>` :math:`\funcinst`
............................................................

* A function instance must remain unchanged.

.. math::
   \frac{
   }{
     \vdashfuncinstextends \funcinst \extendsto \funcinst
   }


.. index:: table instance
.. _extend-tableinst:

:ref:`Table Instance <syntax-tableinst>` :math:`\tableinst`
...........................................................

* The :ref:`table type <syntax-tabletype>` :math:`\tableinst.\TITYPE` must remain unchanged.

* The length of :math:`\tableinst.\TIELEM` must not shrink.

.. math::
   \frac{
     n_1 \leq n_2
   }{
     \vdashtableinstextends \{\TITYPE~\X{tt}, \TIELEM~(\X{fa}_1^?)^{n_1}\} \extendsto \{\TITYPE~\X{tt}, \TIELEM~(\X{fa}_2^?)^{n_2}\}
   }


.. index:: memory instance
.. _extend-meminst:

:ref:`Memory Instance <syntax-meminst>` :math:`\meminst`
........................................................

* The :ref:`memory type <syntax-memtype>` :math:`\meminst.\MITYPE` must remain unchanged.

* The length of :math:`\meminst.\MIDATA` must not shrink.

.. math::
   \frac{
     n_1 \leq n_2
   }{
     \vdashmeminstextends \{\MITYPE~\X{mt}, \MIDATA~b_1^{n_1}\} \extendsto \{\MITYPE~\X{mt}, \MIDATA~b_2^{n_2}\}
   }


.. index:: global instance, value, mutability
.. 
Download .txt
gitextract_qmxq1s8y/

├── .gitattributes
├── .gitignore
├── .gitmodules
├── .travis.yml
├── Contributing.md
├── LICENSE
├── README.md
├── deploy_key.enc
├── document/
│   ├── Makefile
│   ├── README.md
│   ├── core/
│   │   ├── .gitignore
│   │   ├── LICENSE
│   │   ├── Makefile
│   │   ├── README.md
│   │   ├── appendix/
│   │   │   ├── algorithm.rst
│   │   │   ├── custom.rst
│   │   │   ├── embedding.rst
│   │   │   ├── gen-index-instructions.py
│   │   │   ├── implementation.rst
│   │   │   ├── index-instructions.rst
│   │   │   ├── index-rules.rst
│   │   │   ├── index-types.rst
│   │   │   ├── index.rst
│   │   │   └── properties.rst
│   │   ├── binary/
│   │   │   ├── conventions.rst
│   │   │   ├── index.rst
│   │   │   ├── instructions.rst
│   │   │   ├── modules.rst
│   │   │   ├── types.rst
│   │   │   └── values.rst
│   │   ├── conf.py
│   │   ├── exec/
│   │   │   ├── conventions.rst
│   │   │   ├── index.rst
│   │   │   ├── instructions.rst
│   │   │   ├── modules.rst
│   │   │   ├── numerics.rst
│   │   │   └── runtime.rst
│   │   ├── index.bs
│   │   ├── index.rst
│   │   ├── intro/
│   │   │   ├── index.rst
│   │   │   ├── introduction.rst
│   │   │   └── overview.rst
│   │   ├── make.bat
│   │   ├── static/
│   │   │   └── custom.css
│   │   ├── syntax/
│   │   │   ├── conventions.rst
│   │   │   ├── index.rst
│   │   │   ├── instructions.rst
│   │   │   ├── modules.rst
│   │   │   ├── types.rst
│   │   │   └── values.rst
│   │   ├── text/
│   │   │   ├── conventions.rst
│   │   │   ├── index.rst
│   │   │   ├── instructions.rst
│   │   │   ├── lexical.rst
│   │   │   ├── modules.rst
│   │   │   ├── types.rst
│   │   │   └── values.rst
│   │   ├── util/
│   │   │   ├── README.htmldiff.pl
│   │   │   ├── bikeshed/
│   │   │   │   └── conf.py
│   │   │   ├── bikeshed_fixup.py
│   │   │   ├── katex_fix.patch
│   │   │   ├── macros.def
│   │   │   ├── mathdef.py
│   │   │   ├── mathdefbs.py
│   │   │   ├── mathjax2katex.py
│   │   │   └── pseudo-lexer.py
│   │   └── valid/
│   │       ├── conventions.rst
│   │       ├── index.rst
│   │       ├── instructions.rst
│   │       ├── modules.rst
│   │       └── types.rst
│   ├── deploy.sh
│   ├── index.html
│   ├── js-api/
│   │   ├── Makefile
│   │   └── index.bs
│   ├── travis-deploy.sh
│   ├── util/
│   │   └── htmldiff.pl
│   └── web-api/
│       ├── Makefile
│       └── index.bs
├── interpreter/
│   ├── .gitignore
│   ├── .merlin
│   ├── LICENSE
│   ├── Makefile
│   ├── README.md
│   ├── binary/
│   │   ├── decode.ml
│   │   ├── decode.mli
│   │   ├── encode.ml
│   │   ├── encode.mli
│   │   ├── utf8.ml
│   │   └── utf8.mli
│   ├── exec/
│   │   ├── eval.ml
│   │   ├── eval.mli
│   │   ├── eval_numeric.ml
│   │   ├── eval_numeric.mli
│   │   ├── f32.ml
│   │   ├── f32_convert.ml
│   │   ├── f32_convert.mli
│   │   ├── f64.ml
│   │   ├── f64_convert.ml
│   │   ├── f64_convert.mli
│   │   ├── float.ml
│   │   ├── i32.ml
│   │   ├── i32_convert.ml
│   │   ├── i32_convert.mli
│   │   ├── i64.ml
│   │   ├── i64_convert.ml
│   │   ├── i64_convert.mli
│   │   ├── int.ml
│   │   └── numeric_error.ml
│   ├── host/
│   │   ├── env.ml
│   │   └── spectest.ml
│   ├── main/
│   │   ├── flags.ml
│   │   └── main.ml
│   ├── meta/
│   │   ├── findlib/
│   │   │   └── META
│   │   ├── jslib/
│   │   │   ├── bsconfig.json
│   │   │   ├── build.sh
│   │   │   └── wasm.ml
│   │   └── travis/
│   │       ├── build-test.sh
│   │       └── install-ocaml.sh
│   ├── runtime/
│   │   ├── func.ml
│   │   ├── func.mli
│   │   ├── global.ml
│   │   ├── global.mli
│   │   ├── instance.ml
│   │   ├── memory.ml
│   │   ├── memory.mli
│   │   ├── table.ml
│   │   └── table.mli
│   ├── script/
│   │   ├── import.ml
│   │   ├── import.mli
│   │   ├── js.ml
│   │   ├── js.mli
│   │   ├── run.ml
│   │   ├── run.mli
│   │   └── script.ml
│   ├── syntax/
│   │   ├── ast.ml
│   │   ├── free.ml
│   │   ├── free.mli
│   │   ├── operators.ml
│   │   ├── types.ml
│   │   └── values.ml
│   ├── text/
│   │   ├── arrange.ml
│   │   ├── arrange.mli
│   │   ├── lexer.mli
│   │   ├── lexer.mll
│   │   ├── parse.ml
│   │   ├── parse.mli
│   │   ├── parser.mly
│   │   ├── print.ml
│   │   └── print.mli
│   ├── util/
│   │   ├── error.ml
│   │   ├── error.mli
│   │   ├── lib.ml
│   │   ├── lib.mli
│   │   ├── sexpr.ml
│   │   ├── sexpr.mli
│   │   ├── source.ml
│   │   └── source.mli
│   ├── valid/
│   │   ├── valid.ml
│   │   └── valid.mli
│   └── winmake.bat
├── papers/
│   ├── LICENSE
│   └── README.md
├── proposals/
│   ├── README.md
│   ├── bulk-memory-operations/
│   │   └── Overview.md
│   ├── multi-value/
│   │   └── Overview.md
│   ├── nontrapping-float-to-int-conversion/
│   │   └── Overview.md
│   ├── reference-types/
│   │   └── Overview.md
│   └── sign-extension-ops/
│       └── Overview.md
├── test/
│   ├── LICENSE
│   ├── README.md
│   ├── Todo.md
│   ├── build.py
│   ├── core/
│   │   ├── .gitignore
│   │   ├── README.md
│   │   ├── address.wast
│   │   ├── align.wast
│   │   ├── binary-leb128.wast
│   │   ├── binary.wast
│   │   ├── block.wast
│   │   ├── br.wast
│   │   ├── br_if.wast
│   │   ├── br_table.wast
│   │   ├── bulk.wast
│   │   ├── call.wast
│   │   ├── call_indirect.wast
│   │   ├── comments.wast
│   │   ├── const.wast
│   │   ├── conversions.wast
│   │   ├── custom.wast
│   │   ├── data.wast
│   │   ├── elem.wast
│   │   ├── endianness.wast
│   │   ├── exports.wast
│   │   ├── f32.wast
│   │   ├── f32_bitwise.wast
│   │   ├── f32_cmp.wast
│   │   ├── f64.wast
│   │   ├── f64_bitwise.wast
│   │   ├── f64_cmp.wast
│   │   ├── fac.wast
│   │   ├── float_exprs.wast
│   │   ├── float_literals.wast
│   │   ├── float_memory.wast
│   │   ├── float_misc.wast
│   │   ├── forward.wast
│   │   ├── func.wast
│   │   ├── func_ptrs.wast
│   │   ├── global.wast
│   │   ├── i32.wast
│   │   ├── i64.wast
│   │   ├── if.wast
│   │   ├── imports.wast
│   │   ├── inline-module.wast
│   │   ├── int_exprs.wast
│   │   ├── int_literals.wast
│   │   ├── labels.wast
│   │   ├── left-to-right.wast
│   │   ├── linking.wast
│   │   ├── load.wast
│   │   ├── local_get.wast
│   │   ├── local_set.wast
│   │   ├── local_tee.wast
│   │   ├── loop.wast
│   │   ├── memory.wast
│   │   ├── memory_copy.wast
│   │   ├── memory_fill.wast
│   │   ├── memory_grow.wast
│   │   ├── memory_init.wast
│   │   ├── memory_redundancy.wast
│   │   ├── memory_size.wast
│   │   ├── memory_trap.wast
│   │   ├── names.wast
│   │   ├── nop.wast
│   │   ├── ref_func.wast
│   │   ├── ref_is_null.wast
│   │   ├── ref_null.wast
│   │   ├── return.wast
│   │   ├── run.py
│   │   ├── select.wast
│   │   ├── skip-stack-guard-page.wast
│   │   ├── stack.wast
│   │   ├── start.wast
│   │   ├── store.wast
│   │   ├── switch.wast
│   │   ├── table-sub.wast
│   │   ├── table.wast
│   │   ├── table_copy.wast
│   │   ├── table_fill.wast
│   │   ├── table_get.wast
│   │   ├── table_grow.wast
│   │   ├── table_init.wast
│   │   ├── table_set.wast
│   │   ├── table_size.wast
│   │   ├── token.wast
│   │   ├── traps.wast
│   │   ├── type.wast
│   │   ├── unreachable.wast
│   │   ├── unreached-invalid.wast
│   │   ├── unwind.wast
│   │   ├── utf8-custom-section-id.wast
│   │   ├── utf8-import-field.wast
│   │   ├── utf8-import-module.wast
│   │   └── utf8-invalid-encoding.wast
│   ├── harness/
│   │   ├── async_index.js
│   │   ├── sync_index.js
│   │   ├── testharness.css
│   │   ├── testharness.js
│   │   └── testharnessreport.js
│   ├── js-api/
│   │   ├── LICENSE.md
│   │   ├── README.md
│   │   ├── assertions.js
│   │   ├── bad-imports.js
│   │   ├── constructor/
│   │   │   ├── compile.any.js
│   │   │   ├── instantiate-bad-imports.any.js
│   │   │   ├── instantiate.any.js
│   │   │   ├── multi-value.any.js
│   │   │   └── validate.any.js
│   │   ├── error-interfaces-no-symbol-tostringtag.js
│   │   ├── global/
│   │   │   ├── constructor.any.js
│   │   │   ├── toString.any.js
│   │   │   ├── value-get-set.any.js
│   │   │   └── valueOf.any.js
│   │   ├── instance/
│   │   │   ├── constructor-bad-imports.any.js
│   │   │   ├── constructor-caching.any.js
│   │   │   ├── constructor.any.js
│   │   │   ├── exports.any.js
│   │   │   └── toString.any.js
│   │   ├── instanceTestFactory.js
│   │   ├── interface.any.js
│   │   ├── limits.any.js
│   │   ├── memory/
│   │   │   ├── assertions.js
│   │   │   ├── buffer.any.js
│   │   │   ├── constructor.any.js
│   │   │   ├── grow.any.js
│   │   │   └── toString.any.js
│   │   ├── module/
│   │   │   ├── constructor.any.js
│   │   │   ├── customSections.any.js
│   │   │   ├── exports.any.js
│   │   │   ├── imports.any.js
│   │   │   └── toString.any.js
│   │   ├── prototypes.any.js
│   │   ├── table/
│   │   │   ├── assertions.js
│   │   │   ├── constructor.any.js
│   │   │   ├── get-set.any.js
│   │   │   ├── grow.any.js
│   │   │   ├── length.any.js
│   │   │   └── toString.any.js
│   │   └── wasm-module-builder.js
│   ├── meta/
│   │   ├── Makefile
│   │   ├── README.md
│   │   ├── common.js
│   │   ├── generate_memory_copy.js
│   │   ├── generate_memory_fill.js
│   │   ├── generate_memory_init.js
│   │   ├── generate_table_copy.js
│   │   ├── generate_table_init.js
│   │   └── noderun.sh
│   └── sync-js-api.py
├── w3c.json
└── wasm-specs.bib
Download .txt
SYMBOL INDEX (370 symbols across 40 files)

FILE: document/core/appendix/gen-index-instructions.py
  function MathWrap (line 33) | def MathWrap(s, default=''):
  function RefWrap (line 40) | def RefWrap(s, kind):
  function Instruction (line 47) | def Instruction(name, opcode, type=None, validation=None, execution=None...
  function ColumnWidth (line 336) | def ColumnWidth(n):
  function Row (line 342) | def Row(columns):

FILE: document/core/util/bikeshed_fixup.py
  function Main (line 11) | def Main():

FILE: document/core/util/mathdef.py
  function html_hyperlink (line 16) | def html_hyperlink(file, id):
  function html_transform_math_xref (line 19) | def html_transform_math_xref(node):
  function latex_hyperlink (line 24) | def latex_hyperlink(file, id):
  function latex_transform_math_xref (line 30) | def latex_transform_math_xref(node):
  function lookup_mathdef (line 40) | def lookup_mathdef(defs, name):
  function replace_mathdefs (line 51) | def replace_mathdefs(doc, s):
  function ext_math_role (line 56) | def ext_math_role(role, raw, text, line, inliner, options = {}, content ...
  class ExtMathDirective (line 60) | class ExtMathDirective(MathDirective):
    method run (line 61) | def run(self):
  class MathdefDirective (line 69) | class MathdefDirective(Replace):
    method run (line 70) | def run(self):
  class WebAssemblyHTML5Translator (line 89) | class WebAssemblyHTML5Translator(HTML5Translator):
    method visit_math (line 94) | def visit_math(self, node, math_env = ''):
    method visit_math_block (line 98) | def visit_math_block(self, node, math_env  = ''):
  class WebAssemblyLaTeXTranslator (line 102) | class WebAssemblyLaTeXTranslator(LaTeXTranslator):
    method visit_math (line 107) | def visit_math(self, node):
    method visit_math_block (line 111) | def visit_math_block(self, node):
  function setup (line 117) | def setup(app):

FILE: document/core/util/mathdefbs.py
  function html_hyperlink (line 20) | def html_hyperlink(file, id):
  function html_transform_math_xref (line 23) | def html_transform_math_xref(node):
  function lookup_mathdef (line 33) | def lookup_mathdef(defs, name):
  function replace_mathdefs (line 44) | def replace_mathdefs(doc, s):
  function ext_math_role (line 49) | def ext_math_role(role, raw, text, line, inliner, options = {}, content ...
  class ExtMathDirective (line 53) | class ExtMathDirective(MathDirective):
    method run (line 54) | def run(self):
  class MathdefDirective (line 62) | class MathdefDirective(Replace):
    method run (line 63) | def run(self):
  class WebAssemblyHTML5Translator (line 81) | class WebAssemblyHTML5Translator(HTML5Translator):
    method visit_math (line 86) | def visit_math(self, node, math_env = ''):
    method visit_math_block (line 90) | def visit_math_block(self, node, math_env  = ''):
  function setup (line 96) | def setup(app):

FILE: document/core/util/mathjax2katex.py
  function FindMatching (line 18) | def FindMatching(data, prefix):
  function HasBalancedTags (line 36) | def HasBalancedTags(s):
  function ReplaceMath (line 61) | def ReplaceMath(cache, data):
  function Main (line 132) | def Main():

FILE: document/core/util/pseudo-lexer.py
  class PseudoLexer (line 5) | class PseudoLexer(RegexLexer):
  function setup (line 31) | def setup(app):

FILE: test/build.py
  function run (line 22) | def run(*cmd):
  function call (line 27) | def call(*cmd):
  function ensure_remove_dir (line 34) | def ensure_remove_dir(path):
  function ensure_empty_dir (line 38) | def ensure_empty_dir(path):
  function compile_wasm_interpreter (line 42) | def compile_wasm_interpreter():
  function ensure_wasm_executable (line 50) | def ensure_wasm_executable(path_to_wasm):
  function convert_one_wast_file (line 60) | def convert_one_wast_file(inputs):
  function convert_wast_to_js (line 65) | def convert_wast_to_js(out_js_dir):
  function copy_harness_files (line 90) | def copy_harness_files(out_js_dir, include_harness):
  function build_js (line 100) | def build_js(out_js_dir):
  function wrap_single_test (line 127) | def wrap_single_test(js_file):
  function build_html_js (line 138) | def build_html_js(out_dir):
  function build_html_from_js (line 147) | def build_html_from_js(tests, html_dir, use_sync):
  function build_html (line 161) | def build_html(html_dir, js_dir, use_sync):
  function build_front_page (line 175) | def build_front_page(out_dir, js_dir, use_sync):
  function process_args (line 197) | def process_args():

FILE: test/core/run.py
  class RunTests (line 40) | class RunTests(unittest.TestCase):
    method _runCommand (line 41) | def _runCommand(self, command, logPath, expectedExitCode = 0):
    method _auxFile (line 46) | def _auxFile(self, path):
    method _compareFile (line 51) | def _compareFile(self, expectFile, actualFile):
    method _runTestFile (line 59) | def _runTestFile(self, inputPath):

FILE: test/harness/async_index.js
  function uniqueTest (line 26) | function uniqueTest(func, desc) {
  function assertThrows (line 33) | function assertThrows(func, err) {
  constant EXPECT_INVALID (line 51) | const EXPECT_INVALID = false;
  function externref (line 57) | function externref(s) {
  function is_externref (line 61) | function is_externref(x) {
  function is_funcref (line 64) | function is_funcref(x) {
  function eq_externref (line 67) | function eq_externref(x, y) {
  function eq_funcref (line 70) | function eq_funcref(x, y) {
  function reinitializeRegistry (line 84) | function reinitializeRegistry() {
  function binary (line 128) | function binary(bytes) {
  function module (line 140) | function module(bytes, valid = true) {
  function assert_invalid (line 171) | function assert_invalid(bytes) {
  function instance (line 177) | function instance(bytes, imports, valid = true) {
  function exports (line 207) | function exports(instance) {
  function call (line 213) | function call(instance, name, args) {
  function run (line 219) | function run(action) {
  function assert_trap (line 240) | function assert_trap(action) {
  function assert_return (line 263) | function assert_return(action, ...expected) {
  function assert_exhaustion (line 321) | function assert_exhaustion(action) {
  function assert_unlinkable (line 344) | function assert_unlinkable(bytes) {
  function assert_uninstantiable (line 367) | function assert_uninstantiable(bytes) {
  function register (line 390) | function register(name, instance) {
  function get (line 410) | function get(instance, name) {

FILE: test/harness/sync_index.js
  function assertThrows (line 29) | function assertThrows(func, err) {
  function _assert (line 45) | function _assert(x) {
  function Result (line 52) | function Result(type, maybeValue) {
  function ValueResult (line 60) | function ValueResult(val) { return new Result(Result.VALUE, val); }
  function ErrorResult (line 61) | function ErrorResult(err) { return new Result(Result.ERROR, err); }
  constant EXPECT_INVALID (line 65) | const EXPECT_INVALID = false;
  function externref (line 71) | function externref(s) {
  function is_externref (line 75) | function is_externref(x) {
  function is_funcref (line 78) | function is_funcref(x) {
  function eq_externref (line 81) | function eq_externref(x, y) {
  function eq_funcref (line 84) | function eq_funcref(x, y) {
  function reinitializeRegistry (line 94) | function reinitializeRegistry() {
  function binary (line 128) | function binary(bytes) {
  function module (line 140) | function module(bytes, valid = true) {
  function uniqueTest (line 175) | function uniqueTest(func, desc) {
  function assert_invalid (line 179) | function assert_invalid(bytes) {
  function instance (line 192) | function instance(bytes, imports = registry, valid = true) {
  function register (line 219) | function register(name, instance) {
  function call (line 228) | function call(instance, name, args) {
  function get (line 245) | function get(instance, name) {
  function exports (line 255) | function exports(instance) {
  function run (line 264) | function run(action) {
  function assert_unlinkable (line 275) | function assert_unlinkable(bytes) {
  function assert_uninstantiable (line 289) | function assert_uninstantiable(bytes) {
  function assert_trap (line 303) | function assert_trap(action) {
  function assert_exhaustion (line 320) | function assert_exhaustion(action) {
  function assert_return (line 334) | function assert_return(action, ...expected) {
  function assert_return_nan (line 376) | function assert_return_nan(action) {

FILE: test/harness/testharness.js
  function WindowTestEnvironment (line 62) | function WindowTestEnvironment() {
  function WorkerTestEnvironment (line 273) | function WorkerTestEnvironment() {
  function DedicatedWorkerTestEnvironment (line 361) | function DedicatedWorkerTestEnvironment() {
  function SharedWorkerTestEnvironment (line 384) | function SharedWorkerTestEnvironment() {
  function ServiceWorkerTestEnvironment (line 410) | function ServiceWorkerTestEnvironment() {
  function create_test_environment (line 458) | function create_test_environment() {
  function is_shared_worker (line 484) | function is_shared_worker(worker) {
  function is_service_worker (line 488) | function is_service_worker(worker) {
  function test (line 496) | function test(func, name, properties)
  function async_test (line 507) | function async_test(func, name, properties)
  function promise_test (line 523) | function promise_test(func, name, properties) {
  function promise_rejects (line 550) | function promise_rejects(test, expected, promise, description) {
  function EventWatcher (line 561) | function EventWatcher(test, watchedNode, eventTypes)
  function setup (line 624) | function setup(func_or_properties, maybe_properties)
  function done (line 640) | function done() {
  function generate_tests (line 650) | function generate_tests(func, args, properties) {
  function on_event (line 663) | function on_event(object, event, callback)
  function step_timeout (line 668) | function step_timeout(f, t) {
  function truncate (line 690) | function truncate(s, len)
  function is_node (line 701) | function is_node(object)
  function format_value (line 771) | function format_value(val, seen)
  function assert_true (line 853) | function assert_true(actual, description)
  function assert_false (line 860) | function assert_false(actual, description)
  function same_value (line 867) | function same_value(x, y) {
  function assert_equals (line 879) | function assert_equals(actual, expected, description)
  function assert_not_equals (line 897) | function assert_not_equals(actual, expected, description)
  function assert_in_array (line 909) | function assert_in_array(actual, expected, description)
  function assert_object_equals (line 917) | function assert_object_equals(actual, expected, description)
  function assert_array_equals (line 950) | function assert_array_equals(actual, expected, description)
  function assert_approx_equals (line 971) | function assert_approx_equals(actual, expected, epsilon, description)
  function assert_less_than (line 988) | function assert_less_than(actual, expected, description)
  function assert_greater_than (line 1005) | function assert_greater_than(actual, expected, description)
  function assert_between_exclusive (line 1022) | function assert_between_exclusive(actual, lower, upper, description)
  function assert_less_than_equal (line 1040) | function assert_less_than_equal(actual, expected, description)
  function assert_greater_than_equal (line 1057) | function assert_greater_than_equal(actual, expected, description)
  function assert_between_inclusive (line 1074) | function assert_between_inclusive(actual, lower, upper, description)
  function assert_regexp_match (line 1092) | function assert_regexp_match(actual, expected, description) {
  function assert_class_string (line 1103) | function assert_class_string(object, class_string, description) {
  function _assert_own_property (line 1110) | function _assert_own_property(name) {
  function assert_not_exists (line 1121) | function assert_not_exists(object, property_name, description)
  function _assert_inherits (line 1129) | function _assert_inherits(name) {
  function assert_readonly (line 1154) | function assert_readonly(object, property_name, description)
  function assert_throws (line 1171) | function assert_throws(code, func, description)
  function assert_unreached (line 1292) | function assert_unreached(description) {
  function assert_any (line 1298) | function assert_any(assert_func, actual, expected_array)
  function Test (line 1319) | function Test(name, properties)
  function RemoteTest (line 1534) | function RemoteTest(clone) {
  function RemoteWorker (line 1579) | function RemoteWorker(worker) {
  function TestsStatus (line 1682) | function TestsStatus()
  function Tests (line 1711) | function Tests()
  function fetch_tests_from_worker (line 1939) | function fetch_tests_from_worker(port) {
  function timeout (line 1944) | function timeout() {
  function add_start_callback (line 1951) | function add_start_callback(callback) {
  function add_test_state_callback (line 1955) | function add_test_state_callback(callback) {
  function add_result_callback (line 1959) | function add_result_callback(callback) {
  function add_completion_callback (line 1963) | function add_completion_callback(callback) {
  function remove (line 1972) | function remove(array, item) {
  function remove_start_callback (line 1979) | function remove_start_callback(callback) {
  function remove_test_state_callback (line 1983) | function remove_test_state_callback(callback) {
  function remove_result_callback (line 1987) | function remove_result_callback(callback) {
  function remove_completion_callback (line 1991) | function remove_completion_callback(callback) {
  function Output (line 1999) | function Output() {
  function status_class (line 2135) | function status_class(status)
  function escape_html (line 2211) | function escape_html(s)
  function has_assertions (line 2219) | function has_assertions()
  function get_assertion (line 2229) | function get_assertion(test)
  function is_single_node (line 2306) | function is_single_node(template)
  function substitute (line 2311) | function substitute(template, substitutions)
  function substitute_single (line 2331) | function substitute_single(template, substitutions)
  function make_dom_single (line 2391) | function make_dom_single(template, doc)
  function make_dom (line 2421) | function make_dom(template, substitutions, output_document)
  function render (line 2432) | function render(template, substitutions, output_document)
  function assert (line 2440) | function assert(expected_true, function_name, description, error, substi...
  function AssertionError (line 2452) | function AssertionError(message)
  function make_message (line 2506) | function make_message(function_name, description, error, substitutions)
  function filter (line 2520) | function filter(array, callable, thisObj) {
  function map (line 2533) | function map(array, callable, thisObj)
  function extend (line 2545) | function extend(array, items)
  function forEach (line 2550) | function forEach(array, callback, thisObj)
  function merge (line 2559) | function merge(a,b)
  function expose (line 2572) | function expose(object, name)
  function is_same_origin (line 2585) | function is_same_origin(w) {
  function get_script_url (line 2595) | function get_script_url()
  function get_harness_url (line 2621) | function get_harness_url()
  function supports_post_message (line 2629) | function supports_post_message(w)

FILE: test/js-api/assertions.js
  function assert_function_name (line 1) | function assert_function_name(fn, name, description) {
  function assert_function_length (line 10) | function assert_function_length(fn, length, description) {
  function assert_exported_function (line 19) | function assert_exported_function(fn, { name, length }, description) {
  function assert_Instance (line 27) | function assert_Instance(instance, expected_exports) {
  function assert_WebAssemblyInstantiatedSource (line 76) | function assert_WebAssemblyInstantiatedSource(actual, expected_exports={...

FILE: test/js-api/bad-imports.js
  function test_bad_imports (line 13) | function test_bad_imports(t) {

FILE: test/js-api/constructor/compile.any.js
  function assert_Module (line 4) | function assert_Module(module) {

FILE: test/js-api/constructor/instantiate.any.js
  method module (line 85) | get module() {
  method module (line 116) | get module() {

FILE: test/js-api/constructor/multi-value.any.js
  method fn (line 76) | fn(f32, i32) {

FILE: test/js-api/global/constructor.any.js
  function assert_Global (line 4) | function assert_Global(actual, expected) {
  method value (line 34) | get value() {
  method mutable (line 44) | get mutable() {
  method valueOf (line 49) | valueOf() {
  method toString (line 110) | toString() { return "5" }
  method valueOf (line 111) | valueOf() { return "8" }
  method toString (line 112) | toString() { return 6 }
  method valueOf (line 113) | valueOf() { return 9 }
  method toString (line 135) | toString() { return "5" }
  method valueOf (line 136) | valueOf() { return "8" }
  method toString (line 137) | toString() { return 6n }
  method valueOf (line 138) | valueOf() { return 9n }
  method toString (line 151) | toString() { return 5 }
  method valueOf (line 152) | valueOf() { return 8 }

FILE: test/js-api/instance/constructor-caching.any.js
  function getExports (line 4) | function getExports() {

FILE: test/js-api/instanceTestFactory.js
  method module (line 50) | get module() {
  method module2 (line 67) | get module2() {
  method "module2" (line 115) | get "module2"() {
  method valueOf (line 321) | valueOf() { return 6; }
  method valueOf (line 405) | valueOf() { return 6n; }

FILE: test/js-api/interface.any.js
  function test_operations (line 4) | function test_operations(object, object_name, operations) {
  function test_attributes (line 25) | function test_attributes(object, object_name, attributes) {

FILE: test/js-api/limits.any.js
  function testLimit (line 28) | function testLimit(name, min, limit, gen) {
  function testDynamicLimit (line 180) | function testDynamicLimit(name, instantiationResult, imports, gen) {

FILE: test/js-api/memory/assertions.js
  function assert_ArrayBuffer (line 1) | function assert_ArrayBuffer(actual, { size=0, shared=false, detached=fal...
  function assert_Memory (line 30) | function assert_Memory(memory, { size=0, shared=false }) {

FILE: test/js-api/memory/constructor.any.js
  method has (line 71) | has(o, x) {
  method get (line 74) | get(o, x) {
  method maximum (line 85) | get maximum() {
  method initial (line 95) | get initial() {

FILE: test/js-api/memory/grow.any.js
  method valueOf (line 51) | valueOf() { return 0 }
  method valueOf (line 56) | valueOf() { return 2 }
  method valueOf (line 139) | valueOf() { return 0x100000000; }

FILE: test/js-api/module/customSections.any.js
  function assert_ArrayBuffer (line 4) | function assert_ArrayBuffer(buffer, expected) {
  function assert_sections (line 10) | function assert_sections(sections, expected) {

FILE: test/js-api/module/exports.any.js
  function assert_ModuleExportDescriptor (line 9) | function assert_ModuleExportDescriptor(export_, expected) {
  function assert_exports (line 26) | function assert_exports(exports, expected) {

FILE: test/js-api/module/imports.any.js
  function assert_ModuleImportDescriptor (line 4) | function assert_ModuleImportDescriptor(import_, expected) {
  function assert_imports (line 27) | function assert_imports(imports, expected) {

FILE: test/js-api/prototypes.any.js
  class _Module (line 11) | class _Module extends WebAssembly.Module {}
  class _Instance (line 18) | class _Instance extends WebAssembly.Instance {}
  class _Memory (line 25) | class _Memory extends WebAssembly.Memory {}
  class _Table (line 32) | class _Table extends WebAssembly.Table {}
  class _Global (line 39) | class _Global extends WebAssembly.Global {}

FILE: test/js-api/table/assertions.js
  function assert_equal_to_array (line 1) | function assert_equal_to_array(table, expected, message) {

FILE: test/js-api/table/constructor.any.js
  function assert_Table (line 4) | function assert_Table(actual, expected) {
  method has (line 107) | has(o, x) {
  method get (line 110) | get(o, x) {
  method toString (line 129) | toString() { return "anyfunc"; }
  method maximum (line 140) | get maximum() {
  method initial (line 150) | get initial() {
  method element (line 160) | get element() {

FILE: test/js-api/table/get-set.any.js
  method valueOf (line 187) | valueOf() { return 0x100000000; }
  method valueOf (line 209) | valueOf() {

FILE: test/js-api/table/grow.any.js
  function nulls (line 4) | function nulls(n) {
  method valueOf (line 77) | valueOf() { return 0x100000000; }

FILE: test/js-api/wasm-module-builder.js
  function bytes (line 15) | function bytes(...input) {
  function makeSig (line 164) | function makeSig(params, results) {
  function makeSig_v_x (line 168) | function makeSig_v_x(x) {
  function makeSig_v_xx (line 172) | function makeSig_v_xx(x) {
  function makeSig_r_v (line 176) | function makeSig_r_v(r) {
  function makeSig_r_x (line 180) | function makeSig_r_x(r, x) {
  function makeSig_r_xx (line 184) | function makeSig_r_xx(r, x) {
  class Binary (line 473) | class Binary {
    method constructor (line 474) | constructor() {
    method ensure_space (line 479) | ensure_space(needed) {
    method trunc_buffer (line 488) | trunc_buffer() {
    method reset (line 492) | reset() {
    method emit_u8 (line 496) | emit_u8(val) {
    method emit_u16 (line 501) | emit_u16(val) {
    method emit_u32 (line 507) | emit_u32(val) {
    method emit_leb_u (line 515) | emit_leb_u(val, max_len) {
    method emit_u32v (line 529) | emit_u32v(val) {
    method emit_u64v (line 533) | emit_u64v(val) {
    method emit_bytes (line 537) | emit_bytes(data) {
    method emit_string (line 543) | emit_string(string) {
    method emit_header (line 560) | emit_header() {
    method emit_section (line 566) | emit_section(section_code, content_generator) {
  class WasmFunctionBuilder (line 580) | class WasmFunctionBuilder {
    method constructor (line 581) | constructor(module, name, type_index) {
    method numLocalNames (line 590) | numLocalNames() {
    method exportAs (line 598) | exportAs(name) {
    method exportFunc (line 603) | exportFunc() {
    method addBody (line 608) | addBody(body) {
    method addBodyWithEnd (line 619) | addBodyWithEnd(body) {
    method getNumLocals (line 624) | getNumLocals() {
    method addLocals (line 634) | addLocals(locals, names) {
    method end (line 644) | end() {
  class WasmGlobalBuilder (line 649) | class WasmGlobalBuilder {
    method constructor (line 650) | constructor(module, type, mutable) {
    method exportAs (line 657) | exportAs(name) {
  class WasmTableBuilder (line 664) | class WasmTableBuilder {
    method constructor (line 665) | constructor(module, type, initial_size, max_size) {
    method exportAs (line 673) | exportAs(name) {
  class WasmModuleBuilder (line 680) | class WasmModuleBuilder {
    method constructor (line 681) | constructor() {
    method addStart (line 699) | addStart(start_index) {
    method addMemory (line 704) | addMemory(min, max, exp, shared) {
    method addExplicitSection (line 709) | addExplicitSection(bytes) {
    method stringToBytes (line 714) | stringToBytes(name) {
    method createCustomSection (line 720) | createCustomSection(name, bytes) {
    method addCustomSection (line 730) | addCustomSection(name, bytes) {
    method addType (line 734) | addType(type) {
    method addGlobal (line 741) | addGlobal(local_type, mutable) {
    method addTable (line 748) | addTable(type, initial_size, max_size = undefined) {
    method addException (line 759) | addException(type) {
    method addFunction (line 766) | addFunction(name, type) {
    method addImport (line 774) | addImport(module, name, type) {
    method addImportedGlobal (line 784) | addImportedGlobal(module, name, type, mutable = false) {
    method addImportedMemory (line 794) | addImportedMemory(module, name, initial = 0, maximum, shared) {
    method addImportedTable (line 801) | addImportedTable(module, name, initial, maximum, type) {
    method addImportedException (line 811) | addImportedException(module, name, type) {
    method addExport (line 821) | addExport(name, index) {
    method addExportOfKind (line 826) | addExportOfKind(name, kind, index) {
    method addDataSegment (line 831) | addDataSegment(addr, data, is_global = false) {
    method addPassiveDataSegment (line 837) | addPassiveDataSegment(data) {
    method exportMemoryAs (line 842) | exportMemoryAs(name) {
    method addElementSegment (line 846) | addElementSegment(table, base, is_global, array) {
    method addPassiveElementSegment (line 852) | addPassiveElementSegment(array, is_import = false) {
    method appendToTable (line 857) | appendToTable(array) {
    method setTableBounds (line 876) | setTableBounds(min, max = undefined) {
    method setName (line 884) | setName(name) {
    method toBuffer (line 889) | toBuffer(debug = false) {
    method toArray (line 1278) | toArray(debug = false) {
    method instantiate (line 1282) | instantiate(ffi) {
    method asyncInstantiate (line 1288) | asyncInstantiate(ffi) {
    method toModule (line 1293) | toModule(debug = false) {
  function wasmSignedLeb (line 1298) | function wasmSignedLeb(val, max_len = 5) {
  function wasmI32Const (line 1314) | function wasmI32Const(val) {
  function wasmF32Const (line 1318) | function wasmF32Const(f) {
  function wasmF64Const (line 1326) | function wasmF64Const(f) {

FILE: test/meta/common.js
  constant PAGESIZE (line 1) | const PAGESIZE = 65536;
  function print_origin (line 3) | function print_origin(origin) {
  function checkRangeCode (line 10) | function checkRangeCode() {
  function checkRange (line 25) | function checkRange(from, to, expected) {

FILE: test/meta/generate_memory_copy.js
  function mem_test (line 8) | function mem_test(instruction, expected_result_vector) {
  function initializers (line 80) | function initializers(count, startingAt) {
  function mem_copy (line 87) | function mem_copy(min, max, shared, srcOffs, targetOffs, len) {

FILE: test/meta/generate_memory_fill.js
  constant PREAMBLE (line 6) | let PREAMBLE =
  function mem_fill (line 131) | function mem_fill(min, max, shared, backup, write=backup*2) {

FILE: test/meta/generate_memory_init.js
  function mem_test (line 8) | function mem_test(instruction, expected_result_vector) {
  constant PREAMBLE (line 58) | let PREAMBLE =
  function mem_init (line 251) | function mem_init(min, max, shared, backup, write) {

FILE: test/meta/generate_table_copy.js
  function emit_a (line 8) | function emit_a() {
  function emit_b (line 29) | function emit_b(insn, t0, t1) {
  function tab_test (line 71) | function tab_test(args, t0, t1, dest_table, expected_t0, expected_t1) {
  function do_test (line 157) | function do_test(insn1, insn2, errText)
  function tab_test2 (line 191) | function tab_test2(insn1, insn2, errKind, errText) {
  function tab_test_nofail (line 195) | function tab_test_nofail(insn1, insn2) {
  function tbl_copy (line 277) | function tbl_copy(min, max, srcOffs, targetOffs, len) {

FILE: test/meta/generate_table_init.js
  function emit_a (line 8) | function emit_a() {
  function emit_b (line 29) | function emit_b(insn, table) {
  function tab_test (line 65) | function tab_test(instruction, table, expected_result_vector) {
  function do_test (line 153) | function do_test(insn1, insn2, table, errText)
  function tab_test1 (line 186) | function tab_test1(insn1, table, errText) {
  function tab_test2 (line 190) | function tab_test2(insn1, insn2, errText) {
  function tbl_init (line 303) | function tbl_init(min, max, backup, write, segoffs=0) {

FILE: test/sync-js-api.py
  function copy_from_local (line 17) | def copy_from_local(local_dir, out):
  function copy_from_upstream (line 22) | def copy_from_upstream(upstream, out):
  function main (line 41) | def main(upstream):
Condensed preview — 321 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (5,395K chars).
[
  {
    "path": ".gitattributes",
    "chars": 249,
    "preview": "*.rst linguist-documentation=false\ndocument/* linguist-documentation=false\ndocument/*.rst linguist-documentation=false\nd"
  },
  {
    "path": ".gitignore",
    "chars": 48,
    "preview": "**/*~\n**/*.tmproj\n**/*.pyc\n**/_build\n**/_output\n"
  },
  {
    "path": ".gitmodules",
    "chars": 114,
    "preview": "[submodule \"document/core/util/katex\"]\n\tpath = document/core/util/katex\n\turl = https://github.com/KaTeX/KaTeX.git\n"
  },
  {
    "path": ".travis.yml",
    "chars": 831,
    "preview": "language: python\npython:\n  - \"3.7\"\ndist: bionic\n\naddons:\n  apt:\n    sources:\n      - sourceline: 'ppa:avsm/ppa'\n      - "
  },
  {
    "path": "Contributing.md",
    "chars": 345,
    "preview": "# Contributing to WebAssembly\n\nInterested in participating? Please follow\n[the same contributing guidelines as the desig"
  },
  {
    "path": "LICENSE",
    "chars": 376,
    "preview": "Please see the LICENSE file in each top-level directory for the terms applicable to that directory and its relative sub-"
  },
  {
    "path": "README.md",
    "chars": 1860,
    "preview": "[![Build Status](https://travis-ci.org/WebAssembly/reference-types.svg?branch=master)](https://travis-ci.org/WebAssembly"
  },
  {
    "path": "document/Makefile",
    "chars": 1662,
    "preview": "DIRS     = core js-api web-api\nFILES    = index.html\nBUILDDIR = _build\n\n# Global targets.\n\n.PHONY: all\nall: $(BUILDDIR) "
  },
  {
    "path": "document/README.md",
    "chars": 3390,
    "preview": "# WebAssembly Specifications\n\nThis directory contains the source code for the WebAssembly spec documents, as served from"
  },
  {
    "path": "document/core/.gitignore",
    "chars": 30,
    "preview": "_build\n_static\ndocument/*.pyc\n"
  },
  {
    "path": "document/core/LICENSE",
    "chars": 2012,
    "preview": "W3C SOFTWARE AND DOCUMENT NOTICE AND LICENSE\n\nThis work is being provided by the copyright holders under the following\nl"
  },
  {
    "path": "document/core/Makefile",
    "chars": 12021,
    "preview": "# Makefile for Sphinx documentation\n#\n\n# You can set these variables from the command line.\nSPHINXOPTS    =\nSPHINXBUILD "
  },
  {
    "path": "document/core/README.md",
    "chars": 496,
    "preview": "# WebAssembly Core Specification\n\nThis is the official WebAssembly \"language\" specification.\n\nIt uses [Sphinx](http://ww"
  },
  {
    "path": "document/core/appendix/algorithm.rst",
    "chars": 9359,
    "preview": ".. index:: validation, algorithm, instruction, module, binary format, opcode\n.. _algo-valid:\n\nValidation Algorithm\n-----"
  },
  {
    "path": "document/core/appendix/custom.rst",
    "chars": 5006,
    "preview": ".. index:: custom section, section, binary format\n\nCustom Sections\n---------------\n\nThis appendix defines dedicated :ref"
  },
  {
    "path": "document/core/appendix/embedding.rst",
    "chars": 21592,
    "preview": ".. index:: ! embedding, embedder, implementation, host\n.. _embed:\n\nEmbedding\n---------\n\nA WebAssembly implementation wil"
  },
  {
    "path": "document/core/appendix/gen-index-instructions.py",
    "chars": 28042,
    "preview": "#!/usr/bin/env python3\n\n# This script generates the `index-instructions.rst` file. The table in that\n# file is particula"
  },
  {
    "path": "document/core/appendix/implementation.rst",
    "chars": 6682,
    "preview": ".. index:: ! implementation limitations, implementation\n.. _impl:\n\nImplementation Limitations\n--------------------------"
  },
  {
    "path": "document/core/appendix/index-instructions.rst",
    "chars": 61000,
    "preview": ".. DO NOT EDIT: This file is auto-generated by the gen-index-instructions.py script.\n\n.. index:: instruction\n.. _index-i"
  },
  {
    "path": "document/core/appendix/index-rules.rst",
    "chars": 8004,
    "preview": ".. _index-rules:\n\nIndex of Semantic Rules\n-----------------------\n\n\n.. index:: validation\n.. _index-valid:\n\nTyping of St"
  },
  {
    "path": "document/core/appendix/index-types.rst",
    "chars": 2400,
    "preview": ".. index:: type\n.. _index-type:\n\nIndex of Types\n--------------\n\n========================================  =============="
  },
  {
    "path": "document/core/appendix/index.rst",
    "chars": 234,
    "preview": ".. _appendix:\n\nAppendix\n========\n\n.. toctree::\n   :maxdepth: 2\n\n   embedding\n   implementation\n   algorithm\n   custom\n  "
  },
  {
    "path": "document/core/appendix/properties.rst",
    "chars": 35823,
    "preview": ".. index:: ! soundness, type system\n.. _soundness:\n\nSoundness\n---------\n\nThe :ref:`type system <type-system>` of WebAsse"
  },
  {
    "path": "document/core/binary/conventions.rst",
    "chars": 5592,
    "preview": ".. index:: ! binary format, module, byte, file extension, abstract syntax\n\nConventions\n-----------\n\nThe binary format fo"
  },
  {
    "path": "document/core/binary/index.rst",
    "chars": 133,
    "preview": ".. _binary:\n\nBinary Format\n=============\n\n.. toctree::\n   :maxdepth: 2\n\n   conventions\n   values\n   types\n   instruction"
  },
  {
    "path": "document/core/binary/instructions.rst",
    "chars": 20686,
    "preview": ".. index:: instruction, ! opcode\n.. _binary-instr:\n\nInstructions\n------------\n\n:ref:`Instructions <syntax-instr>` are en"
  },
  {
    "path": "document/core/binary/modules.rst",
    "chars": 21729,
    "preview": "Modules\n-------\n\nThe binary encoding of modules is organized into *sections*.\nMost sections correspond to one component "
  },
  {
    "path": "document/core/binary/types.rst",
    "chars": 5001,
    "preview": ".. index:: type\n   pair: binary format; type\n.. _binary-type:\n\nTypes\n-----\n\n.. note::\n   In future versions of WebAssemb"
  },
  {
    "path": "document/core/binary/values.rst",
    "chars": 5339,
    "preview": ".. index:: value\n   pair: binary format; value\n.. _binary-value:\n\nValues\n------\n\n\n.. index:: byte\n   pair: binary format"
  },
  {
    "path": "document/core/conf.py",
    "chars": 13155,
    "preview": "# -*- coding: utf-8 -*-\n#\n# WebAssembly documentation build configuration file, created by\n# sphinx-quickstart on Mon No"
  },
  {
    "path": "document/core/exec/conventions.rst",
    "chars": 6940,
    "preview": ".. index:: ! execution, stack, store\n\nConventions\n-----------\n\nWebAssembly code is *executed* when :ref:`instantiating <"
  },
  {
    "path": "document/core/exec/index.rst",
    "chars": 127,
    "preview": ".. _exec:\n\nExecution\n=========\n\n.. toctree::\n   :maxdepth: 2\n\n   conventions\n   runtime\n   numerics\n   instructions\n   m"
  },
  {
    "path": "document/core/exec/instructions.rst",
    "chars": 68718,
    "preview": ".. index:: instruction, function type, store, validation\n.. _exec-instr:\n\nInstructions\n------------\n\nWebAssembly computa"
  },
  {
    "path": "document/core/exec/modules.rst",
    "chars": 37097,
    "preview": "Modules\n-------\n\nFor modules, the execution semantics primarily defines :ref:`instantiation <exec-instantiation>`, which"
  },
  {
    "path": "document/core/exec/numerics.rst",
    "chars": 48873,
    "preview": ".. index:: value, integer, floating-point, bit width, determinism, NaN\n.. _exec-op-partial:\n.. _exec-numeric:\n\nNumerics\n"
  },
  {
    "path": "document/core/exec/runtime.rst",
    "chars": 27693,
    "preview": ".. index:: ! runtime\n.. _syntax-runtime:\n\nRuntime Structure\n-----------------\n\n:ref:`Store <store>`, :ref:`stack <stack>"
  },
  {
    "path": "document/core/index.bs",
    "chars": 851,
    "preview": "<pre class='metadata'>\nTitle: WebAssembly Core Specification\nShortname: wasm-core\nGroup: wasm\nStatus: ED\nLevel: 1\nTR: ht"
  },
  {
    "path": "document/core/index.rst",
    "chars": 615,
    "preview": "WebAssembly Specification\n=========================\n\n.. only:: html\n\n   | Release |release| + bulk instructions + refere"
  },
  {
    "path": "document/core/intro/index.rst",
    "chars": 97,
    "preview": ".. _intro:\n\nIntroduction\n============\n\n.. toctree::\n   :maxdepth: 2\n\n   introduction\n   overview\n"
  },
  {
    "path": "document/core/intro/introduction.rst",
    "chars": 6183,
    "preview": "Introduction\n------------\n\nWebAssembly (abbreviated Wasm [#wasm]_) is a *safe, portable, low-level code format*\ndesigned"
  },
  {
    "path": "document/core/intro/overview.rst",
    "chars": 6398,
    "preview": "Overview\n--------\n\n.. index:: concepts, value, instruction, trap, function, table, memory, linear memory, module, ! embe"
  },
  {
    "path": "document/core/make.bat",
    "chars": 8670,
    "preview": "@ECHO OFF\r\n\r\nREM Command file for Sphinx documentation\r\n\r\nif \"%SPHINXBUILD%\" == \"\" (\r\n\tset SPHINXBUILD=sphinx-build\r\n)\r\n"
  },
  {
    "path": "document/core/static/custom.css",
    "chars": 1057,
    "preview": "a {\n  color: #004BAB;\n  text-decoration: none;\n}\n\na.reference {\n  border-bottom: none;\n}\n\na.reference:hover {\n  border-b"
  },
  {
    "path": "document/core/syntax/conventions.rst",
    "chars": 5616,
    "preview": ".. index:: ! abstract syntax\n\nConventions\n-----------\n\nWebAssembly is a programming language that has multiple concrete "
  },
  {
    "path": "document/core/syntax/index.rst",
    "chars": 125,
    "preview": ".. _syntax:\n\nStructure\n=========\n\n.. toctree::\n   :maxdepth: 2\n\n   conventions\n   values\n   types\n   instructions\n   mod"
  },
  {
    "path": "document/core/syntax/instructions.rst",
    "chars": 18537,
    "preview": ".. index:: ! instruction, code, stack machine, operand, operand stack\n   pair: abstract syntax; instruction\n.. _syntax-i"
  },
  {
    "path": "document/core/syntax/modules.rst",
    "chars": 17681,
    "preview": ".. index:: ! module, type definition, function type, function, table, memory, global, element, data, start function, imp"
  },
  {
    "path": "document/core/syntax/types.rst",
    "chars": 7519,
    "preview": ".. index:: ! type, validation, instantiation, execution\n   pair: abstract syntax; type\n.. _syntax-type:\n\nTypes\n-----\n\nVa"
  },
  {
    "path": "document/core/syntax/values.rst",
    "chars": 6398,
    "preview": ".. index:: ! value\n   pair: abstract syntax; value\n.. _syntax-value:\n\nValues\n------\n\nWebAssembly programs operate on pri"
  },
  {
    "path": "document/core/text/conventions.rst",
    "chars": 7686,
    "preview": ".. index:: ! text format, Unicode, UTF-8, S-expression, identifier, file extension, abstract syntax\n\nConventions\n-------"
  },
  {
    "path": "document/core/text/index.rst",
    "chars": 138,
    "preview": ".. _text:\n\nText Format\n===========\n\n.. toctree::\n   :maxdepth: 2\n\n   conventions\n   lexical\n   values\n   types\n   instru"
  },
  {
    "path": "document/core/text/instructions.rst",
    "chars": 26754,
    "preview": ".. index:: instruction\n.. _text-instr:\n\nInstructions\n------------\n\nInstructions are syntactically distinguished into *pl"
  },
  {
    "path": "document/core/text/lexical.rst",
    "chars": 5153,
    "preview": ".. index:: lexical format\n.. _text-lexical:\n\nLexical Format\n--------------\n\n\n.. index:: ! character, Unicode, ASCII, cha"
  },
  {
    "path": "document/core/text/modules.rst",
    "chars": 27651,
    "preview": "Modules\n-------\n\n\n.. index:: index, type index, function index, table index, memory index, global index, element index, "
  },
  {
    "path": "document/core/text/types.rst",
    "chars": 3690,
    "preview": ".. index:: type\n   pair: text format; type\n.. _text-type:\n\nTypes\n-----\n\n.. index:: number type\n   pair: text format; num"
  },
  {
    "path": "document/core/text/values.rst",
    "chars": 9603,
    "preview": ".. index:: value\n   pair: text format; value\n.. _text-value:\n\nValues\n------\n\nThe grammar productions in this section def"
  },
  {
    "path": "document/core/util/README.htmldiff.pl",
    "chars": 97,
    "preview": "This file is a copy of the HTML diff script found here:\nhttps://dev.w3.org/cvsweb/2009/htmldiff/\n"
  },
  {
    "path": "document/core/util/bikeshed/conf.py",
    "chars": 12586,
    "preview": "# -*- coding: utf-8 -*-\n#\n# WebAssembly documentation build configuration file, created by\n# sphinx-quickstart on Mon No"
  },
  {
    "path": "document/core/util/bikeshed_fixup.py",
    "chars": 1575,
    "preview": "#! /usr/bin/env python3\n# -*- coding: latin-1 -*-\n\nimport os\nimport sys\n\n\nSCRIPT_DIR = os.path.dirname(os.path.realpath("
  },
  {
    "path": "document/core/util/katex_fix.patch",
    "chars": 869,
    "preview": "123c123,126\n<   font: normal 1.21em KaTeX_Main, Times New Roman, serif;\n---\n>   /* font: normal 1.21em KaTeX_Main, Times"
  },
  {
    "path": "document/core/util/macros.def",
    "chars": 54703,
    "preview": ".. LINK MACROS\n\n.. External Standards\n.. ------------------\n\n.. |WasmDraft| replace:: https://webassembly.github.io/refe"
  },
  {
    "path": "document/core/util/mathdef.py",
    "chars": 3862,
    "preview": "from sphinx.ext.mathbase import math\nfrom sphinx.ext.mathbase import MathDirective\nfrom sphinx.util.texescape import tex"
  },
  {
    "path": "document/core/util/mathdefbs.py",
    "chars": 3155,
    "preview": "# Version of mathdef.py for bikeshed build.\n# Tweaked to generate single page links.\n# TODO(bradnelson): Figure out a wa"
  },
  {
    "path": "document/core/util/mathjax2katex.py",
    "chars": 8395,
    "preview": "#! /usr/bin/env python3\n# -*- coding: latin-1 -*-\n\nimport queue\nimport os\nimport re\nimport shelve\nimport subprocess\nimpo"
  },
  {
    "path": "document/core/util/pseudo-lexer.py",
    "chars": 981,
    "preview": "from pygments.lexer import RegexLexer\nfrom pygments.token import *\nfrom sphinx.highlighting import lexers\n\nclass PseudoL"
  },
  {
    "path": "document/core/valid/conventions.rst",
    "chars": 9569,
    "preview": ".. index:: ! validation, ! type system, function type, table type, memory type, globaltype, valtype, resulttype, index s"
  },
  {
    "path": "document/core/valid/index.rst",
    "chars": 116,
    "preview": ".. _valid:\n\nValidation\n==========\n\n.. toctree::\n   :maxdepth: 2\n\n   conventions\n   types\n   instructions\n   modules\n"
  },
  {
    "path": "document/core/valid/instructions.rst",
    "chars": 31513,
    "preview": ".. index:: instruction, function type, context, value, operand stack, ! polymorphism, ! bottom type\n.. _valid-instr:\n.. "
  },
  {
    "path": "document/core/valid/modules.rst",
    "chars": 20998,
    "preview": "Modules\n-------\n\n:ref:`Modules <syntax-module>` are valid when all the components they contain are valid.\nFurthermore, m"
  },
  {
    "path": "document/core/valid/types.rst",
    "chars": 7875,
    "preview": "Types\n-----\n\nMost :ref:`types <syntax-type>` are universally valid.\nHowever, restrictions apply to :ref:`limits <syntax-"
  },
  {
    "path": "document/deploy.sh",
    "chars": 7013,
    "preview": "#!/usr/bin/env bash\n\n# Adapted from+ https://github.com/X1011/git-directory-deploy/\n\nset -o errexit #abort if any comman"
  },
  {
    "path": "document/index.html",
    "chars": 3148,
    "preview": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""
  },
  {
    "path": "document/js-api/Makefile",
    "chars": 1239,
    "preview": "BUILDDIR      = _build\nSTATICDIR     = _static\nDOWNLOADDIR   = _download\nNAME          = WebAssembly\n\n.PHONY: all\nall:\n\t"
  },
  {
    "path": "document/js-api/index.bs",
    "chars": 63162,
    "preview": "<pre class='metadata'>\nTitle: WebAssembly JavaScript Interface\nShortname: wasm-js-api\nGroup: wasm\nStatus: ED\nLevel: 1\nTR"
  },
  {
    "path": "document/travis-deploy.sh",
    "chars": 2474,
    "preview": "#!/bin/bash\n\n# Adapted from https://github.com/heycam/webidl/blob/master/deploy.sh\n\nset -e # Exit with nonzero exit code"
  },
  {
    "path": "document/util/htmldiff.pl",
    "chars": 15547,
    "preview": "#!/usr/bin/perl\n#\n# htmldiff - present a diff marked version of two html documents\n#\n# Copyright (c) 1998-2006 MACS, Inc"
  },
  {
    "path": "document/web-api/Makefile",
    "chars": 1240,
    "preview": "BUILDDIR      = _build\nSTATICDIR     = _static\nDOWNLOADDIR   = _download\nNAME          = WebAssembly\n\n.PHONY: all\nall:\n\t"
  },
  {
    "path": "document/web-api/index.bs",
    "chars": 15125,
    "preview": "<pre class='metadata'>\nTitle: WebAssembly Web API\nShortname: wasm-web-api\nGroup: wasm\nStatus: ED\nLevel: 1\nTR: https://ww"
  },
  {
    "path": "interpreter/.gitignore",
    "chars": 86,
    "preview": "*.cmo\n*.cmx\n*.native\n*.byte\n*.opt\n*.unopt\n*.js\n*.zip\n*.mlpack\n_build\nwasm\nwasm.debug\n\n"
  },
  {
    "path": "interpreter/.merlin",
    "chars": 92,
    "preview": "S binary\nS exec\nS host\nS main\nS runtime\nS script\nS syntax\nS text\nS util\nS valid\n\nB _build/*\n"
  },
  {
    "path": "interpreter/LICENSE",
    "chars": 11358,
    "preview": "                                 Apache License\n                           Version 2.0, January 2004\n                   "
  },
  {
    "path": "interpreter/Makefile",
    "chars": 4269,
    "preview": "# This Makefile uses ocamlbuild but does not rely on ocamlfind or the Opam\n# package manager to build. However, Opam pac"
  },
  {
    "path": "interpreter/README.md",
    "chars": 25878,
    "preview": "# WebAssembly Reference Interpreter\n\nThis repository implements a interpreter for WebAssembly. It is written for clarity"
  },
  {
    "path": "interpreter/binary/decode.ml",
    "chars": 20410,
    "preview": "(* Decoding stream *)\n\ntype stream =\n{\n  name : string;\n  bytes : string;\n  pos : int ref;\n}\n\nexception EOS\n\nlet stream "
  },
  {
    "path": "interpreter/binary/decode.mli",
    "chars": 188,
    "preview": "exception Code of Source.region * string\n\nval decode : string -> string -> Ast.module_ (* raises Code *)\n\nval decode_cus"
  },
  {
    "path": "interpreter/binary/encode.ml",
    "chars": 19148,
    "preview": "(* Version *)\n\nlet version = 1l\n\n\n(* Errors *)\n\nmodule Code = Error.Make ()\nexception Code = Code.Error\n\n\n(* Encoding st"
  },
  {
    "path": "interpreter/binary/encode.mli",
    "chars": 146,
    "preview": "exception Code of Source.region * string\n\nval version : int32\nval encode : Ast.module_ -> string\nval encode_custom : Ast"
  },
  {
    "path": "interpreter/binary/utf8.ml",
    "chars": 1308,
    "preview": "exception Utf8\n\nlet con n = 0x80 lor (n land 0x3f)\n\nlet rec encode ns = Lib.String.implode (List.map Char.chr (encode' n"
  },
  {
    "path": "interpreter/binary/utf8.mli",
    "chars": 116,
    "preview": "exception Utf8\n\nval decode : string -> int list (* raises Utf8 *)\nval encode : int list -> string (* raises Utf8 *)\n"
  },
  {
    "path": "interpreter/exec/eval.ml",
    "chars": 23479,
    "preview": "open Values\nopen Types\nopen Instance\nopen Ast\nopen Source\n\n\n(* Errors *)\n\nmodule Link = Error.Make ()\nmodule Trap = Erro"
  },
  {
    "path": "interpreter/exec/eval.mli",
    "chars": 345,
    "preview": "open Values\nopen Instance\n\nexception Link of Source.region * string\nexception Trap of Source.region * string\nexception C"
  },
  {
    "path": "interpreter/exec/eval_numeric.ml",
    "chars": 6618,
    "preview": "open Types\nopen Values\n\n\n(* Injection & projection *)\n\nexception TypeError of int * num * num_type\n\nmodule type NumType "
  },
  {
    "path": "interpreter/exec/eval_numeric.mli",
    "chars": 285,
    "preview": "open Values\n\nexception TypeError of int * num * Types.num_type\n\nval eval_unop : Ast.unop -> num -> num\nval eval_binop : "
  },
  {
    "path": "interpreter/exec/f32.ml",
    "chars": 413,
    "preview": "(*\n * OCaml lacks 32-bit floats, however we can emulate all the basic operations\n * using 64-bit floats, as described in"
  },
  {
    "path": "interpreter/exec/f32_convert.ml",
    "chars": 1719,
    "preview": "(* WebAssembly-compatible type conversions to f32 implementation *)\n\nlet demote_f64 x =\n  let xf = F64.to_float x in\n  i"
  },
  {
    "path": "interpreter/exec/f32_convert.mli",
    "chars": 278,
    "preview": "(* WebAssembly-compatible type conversions to f32 implementation *)\n\nval demote_f64 : F64.t -> F32.t\nval convert_i32_s :"
  },
  {
    "path": "interpreter/exec/f64.ml",
    "chars": 245,
    "preview": "include Float.Make\n  (struct\n    include Int64\n    let mantissa = 52\n    let pos_nan = 0x7ff8_0000_0000_0000L\n    let ne"
  },
  {
    "path": "interpreter/exec/f64_convert.ml",
    "chars": 1453,
    "preview": "(* WebAssembly-compatible type conversions to f64 implementation *)\n\nlet promote_f32 x =\n  let xf = F32.to_float x in\n  "
  },
  {
    "path": "interpreter/exec/f64_convert.mli",
    "chars": 279,
    "preview": "(* WebAssembly-compatible type conversions to f64 implementation *)\n\nval promote_f32 : F32.t -> F64.t\nval convert_i32_s "
  },
  {
    "path": "interpreter/exec/float.ml",
    "chars": 12024,
    "preview": "module type RepType =\nsig\n  type t\n\n  val mantissa : int\n\n  val zero : t\n  val min_int : t\n  val max_int : t\n\n  val pos_"
  },
  {
    "path": "interpreter/exec/i32.ml",
    "chars": 168,
    "preview": "(* WebAssembly-compatible i32 implementation *)\n\ninclude Int.Make\n  (struct\n    include Int32\n    let bitwidth = 32\n    "
  },
  {
    "path": "interpreter/exec/i32_convert.ml",
    "chars": 2268,
    "preview": "(* WebAssembly-compatible type conversions to i32 implementation *)\n\nlet wrap_i64 x = Int64.to_int32 x\n\nlet trunc_f32_s "
  },
  {
    "path": "interpreter/exec/i32_convert.mli",
    "chars": 416,
    "preview": "(* WebAssembly-compatible type conversions to i32 implementation *)\n\nval wrap_i64 : I64.t -> I32.t\nval trunc_f32_s : F32"
  },
  {
    "path": "interpreter/exec/i64.ml",
    "chars": 168,
    "preview": "(* WebAssembly-compatible i64 implementation *)\n\ninclude Int.Make\n  (struct\n    include Int64\n    let bitwidth = 64\n    "
  },
  {
    "path": "interpreter/exec/i64_convert.ml",
    "chars": 2739,
    "preview": "(* WebAssembly-compatible type conversions to i64 implementation *)\n\nlet extend_i32_s x = Int64.of_int32 x\n\nlet extend_i"
  },
  {
    "path": "interpreter/exec/i64_convert.mli",
    "chars": 454,
    "preview": "(* WebAssembly-compatible type conversions to i64 implementation *)\n\nval extend_i32_s : I32.t -> I64.t\nval extend_i32_u "
  },
  {
    "path": "interpreter/exec/int.ml",
    "chars": 8596,
    "preview": "module type RepType =\nsig\n  type t\n\n  val zero : t\n  val one : t\n  val minus_one : t\n  val max_int : t\n  val min_int : t"
  },
  {
    "path": "interpreter/exec/numeric_error.ml",
    "chars": 93,
    "preview": "exception IntegerOverflow\nexception IntegerDivideByZero\nexception InvalidConversionToInteger\n"
  },
  {
    "path": "interpreter/host/env.ml",
    "chars": 1088,
    "preview": "(*\n * Emulation of (a subset of) the `env` module currently used by Binaryen,\n * so that we can run modules generated by"
  },
  {
    "path": "interpreter/host/spectest.ml",
    "chars": 1988,
    "preview": "(*\n * Simple collection of functions useful for writing test cases.\n *)\n\nopen Types\nopen Values\nopen Instance\n\n\nlet glob"
  },
  {
    "path": "interpreter/main/flags.ml",
    "chars": 164,
    "preview": "let interactive = ref false\nlet trace = ref false\nlet unchecked = ref false\nlet print_sig = ref false\nlet dry = ref fals"
  },
  {
    "path": "interpreter/main/main.ml",
    "chars": 1796,
    "preview": "let name = \"wasm\"\nlet version = \"1.0\"\n\nlet configure () =\n  Import.register (Utf8.decode \"spectest\") Spectest.lookup;\n  "
  },
  {
    "path": "interpreter/meta/findlib/META",
    "chars": 157,
    "preview": "description = \"A library for writing/reading/running WebAssembly binaries\"\nrequires = \"bigarray,str\"\narchive(byte) = \"wa"
  },
  {
    "path": "interpreter/meta/jslib/bsconfig.json",
    "chars": 61,
    "preview": "{\n  \"name\": \"wasm\",\n  \"sources\": [\n    {\"dir\": \"src\"},\n  ]\n}\n"
  },
  {
    "path": "interpreter/meta/jslib/build.sh",
    "chars": 2123,
    "preview": "link () {\necho \"// DO NOT EDIT. Generated from WebAssembly spec interpreter\"\necho \"\nlet WebAssemblyText = (function() {\n"
  },
  {
    "path": "interpreter/meta/jslib/wasm.ml",
    "chars": 261,
    "preview": "let encode s =\n  let def = Parse.string_to_module s in\n  match def.Source.it with\n  | Script.Textual m -> Encode.encode "
  },
  {
    "path": "interpreter/meta/travis/build-test.sh",
    "chars": 148,
    "preview": "#!/bin/bash\n\nset -e\nset -x\n\n# Move to a location relative to the script so it runs\n# from anywhere.\ncd $(dirname ${BASH_"
  },
  {
    "path": "interpreter/meta/travis/install-ocaml.sh",
    "chars": 1151,
    "preview": "#!/bin/bash\n\nset -e\n\ndownload_from_gh_archive() {\n  local project=$1;\n  local version=$2;\n  local sha=$3;\n\n  curl https:"
  },
  {
    "path": "interpreter/runtime/func.ml",
    "chars": 330,
    "preview": "open Types\nopen Values\n\ntype 'inst t = 'inst func\nand 'inst func =\n  | AstFunc of func_type * 'inst * Ast.func\n  | HostF"
  },
  {
    "path": "interpreter/runtime/func.mli",
    "chars": 333,
    "preview": "open Types\nopen Values\n\ntype 'inst t = 'inst func\nand 'inst func =\n  | AstFunc of func_type * 'inst * Ast.func\n  | HostF"
  },
  {
    "path": "interpreter/runtime/global.ml",
    "chars": 466,
    "preview": "open Types\nopen Values\n\ntype global = {ty : global_type; mutable content : value}\ntype t = global\n\nexception Type\nexcept"
  },
  {
    "path": "interpreter/runtime/global.mli",
    "chars": 283,
    "preview": "open Types\nopen Values\n\ntype global\ntype t = global\n\nexception Type\nexception NotMutable\n\nval alloc : global_type -> val"
  },
  {
    "path": "interpreter/runtime/instance.ml",
    "chars": 1503,
    "preview": "open Types\n\ntype module_inst =\n{\n  types : func_type list;\n  funcs : func_inst list;\n  tables : table_inst list;\n  memor"
  },
  {
    "path": "interpreter/runtime/memory.ml",
    "chars": 3797,
    "preview": "open Bigarray\nopen Lib.Bigarray\nopen Types\nopen Values\n\ntype size = int32  (* number of pages *)\ntype address = int64\nty"
  },
  {
    "path": "interpreter/runtime/memory.mli",
    "chars": 1207,
    "preview": "open Types\nopen Values\n\ntype memory\ntype t = memory\n\ntype size = int32  (* number of pages *)\ntype address = int64\ntype "
  },
  {
    "path": "interpreter/runtime/table.ml",
    "chars": 1595,
    "preview": "open Types\nopen Values\n\ntype size = int32\ntype index = int32\ntype count = int32\n\ntype table = {mutable ty : table_type; "
  },
  {
    "path": "interpreter/runtime/table.mli",
    "chars": 620,
    "preview": "open Types\nopen Values\n\ntype table\ntype t = table\n\ntype size = int32\ntype index = int32\ntype count = int32\n\nexception Ty"
  },
  {
    "path": "interpreter/script/import.ml",
    "chars": 704,
    "preview": "open Source\nopen Ast\n\nmodule Unknown = Error.Make ()\nexception Unknown = Unknown.Error  (* indicates unknown import name"
  },
  {
    "path": "interpreter/script/import.mli",
    "chars": 229,
    "preview": "exception Unknown of Source.region * string\n\nval link : Ast.module_ -> Instance.extern list (* raises Unknown *)\n\nval re"
  },
  {
    "path": "interpreter/script/js.ml",
    "chars": 16895,
    "preview": "open Types\nopen Ast\nopen Script\nopen Source\n\n\n(* Harness *)\n\nlet harness =\n{|\n'use strict';\n\nlet externrefs = {};\nlet ex"
  },
  {
    "path": "interpreter/script/js.mli",
    "chars": 40,
    "preview": "val of_script : Script.script -> string\n"
  },
  {
    "path": "interpreter/script/run.ml",
    "chars": 16602,
    "preview": "open Script\nopen Source\n\n\n(* Errors & Tracing *)\n\nmodule Script = Error.Make ()\nmodule Abort = Error.Make ()\nmodule Asse"
  },
  {
    "path": "interpreter/script/run.mli",
    "chars": 244,
    "preview": "exception Abort of Source.region * string\nexception Assert of Source.region * string\nexception IO of Source.region * str"
  },
  {
    "path": "interpreter/script/script.ml",
    "chars": 1756,
    "preview": "type var = string Source.phrase\n\ntype Values.ref_ += ExternRef of int32\ntype literal = Values.value Source.phrase\n\ntype "
  },
  {
    "path": "interpreter/syntax/ast.ml",
    "chars": 8354,
    "preview": "(*\n * Throughout the implementation we use consistent naming conventions for\n * syntactic elements, associated with the "
  },
  {
    "path": "interpreter/syntax/free.ml",
    "chars": 4107,
    "preview": "open Source\nopen Ast\n\nmodule Set = Set.Make(Int32)\n\ntype t =\n{\n  types : Set.t;\n  globals : Set.t;\n  tables : Set.t;\n  m"
  },
  {
    "path": "interpreter/syntax/free.mli",
    "chars": 706,
    "preview": "module Set : Set.S with type elt = int32\n\ntype t =\n{\n  types : Set.t;\n  globals : Set.t;\n  tables : Set.t;\n  memories : "
  },
  {
    "path": "interpreter/syntax/operators.ml",
    "chars": 9043,
    "preview": "open Source\nopen Types\nopen Values\nopen Ast\n\n\nlet i32_const n = Const (I32 n.it @@ n.at)\nlet i64_const n = Const (I64 n."
  },
  {
    "path": "interpreter/syntax/types.ml",
    "chars": 3832,
    "preview": "(* Types *)\n\ntype num_type = I32Type | I64Type | F32Type | F64Type\ntype ref_type = FuncRefType | ExternRefType\ntype valu"
  },
  {
    "path": "interpreter/syntax/values.ml",
    "chars": 1628,
    "preview": "open Types\n\n\n(* Values and operators *)\n\ntype ('i32, 'i64, 'f32, 'f64) op =\n  I32 of 'i32 | I64 of 'i64 | F32 of 'f32 | "
  },
  {
    "path": "interpreter/text/arrange.ml",
    "chars": 15076,
    "preview": "open Source\nopen Ast\nopen Script\nopen Values\nopen Types\nopen Sexpr\n\n\n(* Generic formatting *)\n\nlet nat n = I32.to_string"
  },
  {
    "path": "interpreter/text/arrange.mli",
    "chars": 172,
    "preview": "open Sexpr\n\nval instr : Ast.instr -> sexpr\nval func : Ast.func -> sexpr\nval module_ : Ast.module_ -> sexpr\nval script : "
  },
  {
    "path": "interpreter/text/lexer.mli",
    "chars": 118,
    "preview": "val convert_pos : Lexing.position -> Source.pos\n\nval token : Lexing.lexbuf -> Parser.token  (* raises Source.Error *)\n"
  },
  {
    "path": "interpreter/text/lexer.mll",
    "chars": 13631,
    "preview": "{\nopen Parser\nopen Operators\n\nlet convert_pos pos =\n  { Source.file = pos.Lexing.pos_fname;\n    Source.line = pos.Lexing"
  },
  {
    "path": "interpreter/text/parse.ml",
    "chars": 982,
    "preview": "type 'a start =\n  | Module : (Script.var option * Script.definition) start\n  | Script : Script.script start\n  | Script1 "
  },
  {
    "path": "interpreter/text/parse.mli",
    "chars": 400,
    "preview": "type 'a start =\n  | Module : (Script.var option * Script.definition) start\n  | Script : Script.script start\n  | Script1 "
  },
  {
    "path": "interpreter/text/parser.mly",
    "chars": 35814,
    "preview": "%{\nopen Source\nopen Types\nopen Ast\nopen Operators\nopen Script\n\n\n(* Error handling *)\n\nlet error at msg = raise (Script.S"
  },
  {
    "path": "interpreter/text/print.ml",
    "chars": 280,
    "preview": "let instr oc width e = Sexpr.output oc width (Arrange.instr e)\nlet func oc width f = Sexpr.output oc width (Arrange.func"
  },
  {
    "path": "interpreter/text/print.mli",
    "chars": 239,
    "preview": "val instr : out_channel -> int -> Ast.instr -> unit\nval func : out_channel -> int -> Ast.func -> unit\nval module_ : out_"
  },
  {
    "path": "interpreter/util/error.ml",
    "chars": 196,
    "preview": "module Make () =\nstruct\n  exception Error of Source.region * string\n\n  let warn at m = prerr_endline (Source.string_of_r"
  },
  {
    "path": "interpreter/util/error.mli",
    "chars": 180,
    "preview": "module Make () :\nsig\n  exception Error of Source.region * string\n\n  val warn : Source.region -> string -> unit\n  val err"
  },
  {
    "path": "interpreter/util/lib.ml",
    "chars": 4903,
    "preview": "type void\n\nmodule Fun =\nstruct\n  let id x = x\n  let curry f x y = f (x, y)\n  let uncurry f (x, y) = f x y\n\n  let rec rep"
  },
  {
    "path": "interpreter/util/lib.mli",
    "chars": 2323,
    "preview": "(* Things that should be in the OCaml library... *)\n\ntype void\n\nmodule Fun :\nsig\n  val id : 'a -> 'a\n  val curry : ('a *"
  },
  {
    "path": "interpreter/util/sexpr.ml",
    "chars": 1008,
    "preview": "type sexpr = Atom of string | Node of string * sexpr list\n\ntype rope = Leaf of string | Concat of rope list\nlet (^+) s r"
  },
  {
    "path": "interpreter/util/sexpr.mli",
    "chars": 180,
    "preview": "type sexpr = Atom of string | Node of string * sexpr list\n\nval output : out_channel -> int -> sexpr -> unit\nval print : "
  },
  {
    "path": "interpreter/util/source.ml",
    "chars": 627,
    "preview": "type pos = {file : string; line : int; column : int}\ntype region = {left : pos; right : pos}\ntype 'a phrase = {at : regi"
  },
  {
    "path": "interpreter/util/source.mli",
    "chars": 322,
    "preview": "type pos = {file : string; line : int; column : int}\ntype region = {left : pos; right : pos}\ntype 'a phrase = {at : regi"
  },
  {
    "path": "interpreter/valid/valid.ml",
    "chars": 18375,
    "preview": "open Ast\nopen Source\nopen Types\n\n\n(* Errors *)\n\nmodule Invalid = Error.Make ()\nexception Invalid = Invalid.Error\n\nlet er"
  },
  {
    "path": "interpreter/valid/valid.mli",
    "chars": 105,
    "preview": "exception Invalid of Source.region * string\n\nval check_module : Ast.module_ -> unit (* raises Invalid *)\n"
  },
  {
    "path": "interpreter/winmake.bat",
    "chars": 13201,
    "preview": "rem Auto-generated from Makefile!\nset NAME=wasm\nif '%1' neq '' set NAME=%1\nocamlc.opt -c -w +a-3-4-27-42-44-45 -warn-err"
  },
  {
    "path": "papers/LICENSE",
    "chars": 251,
    "preview": "This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, "
  },
  {
    "path": "papers/README.md",
    "chars": 671,
    "preview": "* [Bringing the Web up to Speed with WebAssembly](pldi2017.pdf)\n\n  Andreas Haas, Andreas Rossberg, Derek Schuff, Ben Tit"
  },
  {
    "path": "proposals/README.md",
    "chars": 108,
    "preview": "# Proposals\n\nThis directory contains overviews for post-MVP proposals that are included in this repository.\n"
  },
  {
    "path": "proposals/bulk-memory-operations/Overview.md",
    "chars": 19823,
    "preview": "# Bulk Memory Operations and Conditional Segment Initialization\n\n## Motivation for Bulk Memory Operations\n\nSome people h"
  },
  {
    "path": "proposals/multi-value/Overview.md",
    "chars": 5589,
    "preview": "# Multi-value Extension\n\n## Introduction\n\n### Background\n\n* Currently, functions and instructions consume multiple opera"
  },
  {
    "path": "proposals/nontrapping-float-to-int-conversion/Overview.md",
    "chars": 3638,
    "preview": "# Non-trapping Float-to-int Conversions\n\n## Introduction\n\n### Motivation\n\nThe primary motivations are:\n\n - LLVM’s float-"
  },
  {
    "path": "proposals/reference-types/Overview.md",
    "chars": 11256,
    "preview": "# Reference Types for WebAssembly\n\nTODO: more text, motivation, explanation\n\n## Introduction\n\nMotivation:\n\n* Easier and "
  },
  {
    "path": "proposals/sign-extension-ops/Overview.md",
    "chars": 2142,
    "preview": "# Sign-extension operators proposal for WebAssembly\n\nThis page describes a proposal for the post-MVP\n[sign-extension ope"
  },
  {
    "path": "test/LICENSE",
    "chars": 11358,
    "preview": "                                 Apache License\n                           Version 2.0, January 2004\n                   "
  },
  {
    "path": "test/README.md",
    "chars": 1540,
    "preview": "This directory contains the WebAssembly test suite. It is split into three\ndirectories:\n\n* [`core/`](core/), tests for t"
  },
  {
    "path": "test/Todo.md",
    "chars": 1561,
    "preview": "This is a rough list of \"tests to write\". Everything here should either be\nspecified in [Semantics.md](https://github.co"
  },
  {
    "path": "test/build.py",
    "chars": 8406,
    "preview": "#!/usr/bin/env python3\n\nimport argparse\nimport sys\nimport os\nimport glob\nimport subprocess\nimport shutil\nimport multipro"
  },
  {
    "path": "test/core/.gitignore",
    "chars": 6,
    "preview": "output"
  },
  {
    "path": "test/core/README.md",
    "chars": 934,
    "preview": "This directory contains tests for the core WebAssembly semantics, as described in [Semantics.md](https://github.com/WebA"
  },
  {
    "path": "test/core/address.wast",
    "chars": 29863,
    "preview": ";; Load i32 data with different offset/align arguments\n\n(module\n  (memory 1)\n  (data (i32.const 0) \"abcdefghijklmnopqrst"
  },
  {
    "path": "test/core/align.wast",
    "chars": 28771,
    "preview": ";; Test alignment annotation rules\n\n(module (memory 0) (func (drop (i32.load8_s align=1 (i32.const 0)))))\n(module (memor"
  },
  {
    "path": "test/core/binary-leb128.wast",
    "chars": 39268,
    "preview": ";; Unsigned LEB128 can have non-minimal length\n(module binary\n  \"\\00asm\" \"\\01\\00\\00\\00\"\n  \"\\05\\04\\01\"                   "
  },
  {
    "path": "test/core/binary.wast",
    "chars": 61541,
    "preview": "(module binary \"\\00asm\\01\\00\\00\\00\")\n(module binary \"\\00asm\" \"\\01\\00\\00\\00\")\n(module $M1 binary \"\\00asm\\01\\00\\00\\00\")\n(m"
  },
  {
    "path": "test/core/block.wast",
    "chars": 40123,
    "preview": ";; Test `block` operator\n\n(module\n  ;; Auxiliary definition\n  (memory 1)\n\n  (func $dummy)\n\n  (func (export \"empty\")\n    "
  },
  {
    "path": "test/core/br.wast",
    "chars": 18368,
    "preview": ";; Test `br` operator\n\n(module\n  ;; Auxiliary definition\n  (func $dummy)\n\n  (func (export \"type-i32\") (block (drop (i32."
  },
  {
    "path": "test/core/br_if.wast",
    "chars": 20620,
    "preview": ";; Test `br_if` operator\n\n(module\n  (func $dummy)\n\n  (func (export \"type-i32\")\n    (block (drop (i32.ctz (br_if 0 (i32.c"
  },
  {
    "path": "test/core/br_table.wast",
    "chars": 84968,
    "preview": ";; Test `br_table` operator\n\n(module\n  ;; Auxiliary definition\n  (func $dummy)\n\n  (func (export \"type-i32\")\n    (block ("
  },
  {
    "path": "test/core/bulk.wast",
    "chars": 13179,
    "preview": ";; segment syntax\n(module\n  (memory 1)\n  (data \"foo\"))\n\n(module\n  (table 3 funcref)\n  (elem funcref (ref.func 0) (ref.nu"
  },
  {
    "path": "test/core/call.wast",
    "chars": 17686,
    "preview": ";; Test `call` operator\n\n(module\n  ;; Auxiliary definitions\n  (func $const-i32 (result i32) (i32.const 0x132))\n  (func $"
  },
  {
    "path": "test/core/call_indirect.wast",
    "chars": 32788,
    "preview": ";; Test `call_indirect` operator\n\n(module\n  ;; Auxiliary definitions\n  (type $proc (func))\n  (type $out-i32 (func (resul"
  },
  {
    "path": "test/core/const.wast",
    "chars": 57803,
    "preview": ";; Test t.const instructions\n\n;; Syntax error\n\n(module (func (i32.const 0_123_456_789) drop))\n(module (func (i32.const 0"
  },
  {
    "path": "test/core/conversions.wast",
    "chars": 59178,
    "preview": "(module\n  (func (export \"i64.extend_i32_s\") (param $x i32) (result i64) (i64.extend_i32_s (local.get $x)))\n  (func (expo"
  },
  {
    "path": "test/core/custom.wast",
    "chars": 3690,
    "preview": "(module binary\n  \"\\00asm\" \"\\01\\00\\00\\00\"\n  \"\\00\\24\\10\" \"a custom section\" \"this is the payload\"\n  \"\\00\\20\\10\" \"a custom "
  },
  {
    "path": "test/core/data.wast",
    "chars": 10256,
    "preview": ";; Test the data section\n\n;; Syntax\n\n(module\n  (memory $m 1)\n  (data (i32.const 0))\n  (data (i32.const 1) \"a\" \"\" \"bcd\")\n"
  },
  {
    "path": "test/core/elem.wast",
    "chars": 11954,
    "preview": ";; Test the element section\n\n;; Syntax\n(module\n  (table $t 10 funcref)\n  (func $f)\n  (func $g)\n\n  ;; Passive\n  (elem fun"
  },
  {
    "path": "test/core/endianness.wast",
    "chars": 10083,
    "preview": "(module\n  (memory 1)\n\n  ;; Stores an i16 value in little-endian-format\n  (func $i16_store_little (param $address i32) (p"
  },
  {
    "path": "test/core/exports.wast",
    "chars": 7410,
    "preview": ";; Functions\n\n(module (func) (export \"a\" (func 0)))\n(module (func) (export \"a\" (func 0)) (export \"b\" (func 0)))\n(module "
  },
  {
    "path": "test/core/f32.wast",
    "chars": 243424,
    "preview": ";; Test all the f32 operators on major boundary values and all special\n;; values (except comparison and bitwise operator"
  },
  {
    "path": "test/core/f32_bitwise.wast",
    "chars": 35420,
    "preview": ";; Test all the f32 bitwise operators on major boundary values and all special\n;; values.\n\n(module\n  (func (export \"abs\""
  },
  {
    "path": "test/core/f32_cmp.wast",
    "chars": 210146,
    "preview": ";; Test all the f32 comparison operators on major boundary values and all\n;; special values.\n\n(module\n  (func (export \"e"
  },
  {
    "path": "test/core/f64.wast",
    "chars": 267017,
    "preview": ";; Test all the f64 operators on major boundary values and all special\n;; values (except comparison and bitwise operator"
  },
  {
    "path": "test/core/f64_bitwise.wast",
    "chars": 39016,
    "preview": ";; Test all the f64 bitwise operators on major boundary values and all special\n;; values.\n\n(module\n  (func (export \"abs\""
  },
  {
    "path": "test/core/f64_cmp.wast",
    "chars": 228386,
    "preview": ";; Test all the f64 comparison operators on major boundary values and all\n;; special values.\n\n(module\n  (func (export \"e"
  },
  {
    "path": "test/core/fac.wast",
    "chars": 3217,
    "preview": "(module\n  ;; Recursive factorial\n  (func (export \"fac-rec\") (param i64) (result i64)\n    (if (result i64) (i64.eq (local"
  },
  {
    "path": "test/core/float_exprs.wast",
    "chars": 162572,
    "preview": ";; Test interesting floating-point \"expressions\". These tests contain code\n;; patterns which tempt common value-changing"
  }
]

// ... and 121 more files (download for full content)

About this extraction

This page contains the full source code of the WebAssembly/reference-types GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 321 files (4.9 MB), approximately 1.3M tokens, and a symbol index with 370 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!