Skip to content

Remove references to post-order AST in BinaryEncoding.md #801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions BinaryEncoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See the [rationale document](Rationale.md#why-a-binary-encoding) for more detail

The encoding is split into three layers:

* **Layer 0** is a simple post-order encoding of the AST and related data structures.
* **Layer 0** is a simple binary encoding of the bytecode instructions and related data structures.
The encoding is dense and trivial to interact with, making it suitable for
scenarios like JIT, instrumentation tools, and debugging.
* **Layer 1** provides structural compression on top of layer 0, exploiting
Expand Down Expand Up @@ -85,22 +85,6 @@ Note that `get_global` in an initializer expression can only refer to immutable
imported globals and all uses of `init_expr` can only appear after the Imports
section.

# Definitions

### Post-order encoding
Refers to an approach for encoding syntax trees, where each node begins with an identifying binary
sequence, then followed recursively by any child nodes.

* Examples
* Given a simple AST node: `i32.add(left: AstNode, right: AstNode)`
* First recursively write the left and right child nodes.
* Then write the opcode for `i32.add` (uint8)

* Given a call AST node: `call(args: AstNode[], callee_index: varuint32)`
* First recursively write each argument node.
* Then write the (variable-length) integer `callee_index` (varuint32)
* Finally write the opcode of `Call` (uint8)

# Module structure

The following documents the current prototype format. This format is based on and supersedes the v8-native prototype format, originally in a [public design doc](https://docs.google.com/document/d/1-G11CnMA0My20KI9D7dBR6ZCPOBCRD0oCH6SHCPFGx0/edit?usp=sharing).
Expand Down Expand Up @@ -419,18 +403,15 @@ count may be greater or less than the actual number of locals.

# Function Bodies

Function bodies consist of a sequence of local variable declarations followed by a
dense post-order encoding of an [Abstract Syntax Tree](AstSemantics.md).
Each node in the abstract syntax tree corresponds to an operator, such as `i32.add` or `if` or `block`.
Operators are encoding by an opcode byte followed by immediate bytes (if any), followed by children
nodes (if any).
Function bodies consist of a sequence of local variable declarations followed by
[bytecode instructions](AstSemantics.md). Each function body must end with the `end` opcode.

| Field | Type | Description |
| ----- | ---- | ----------- |
| body_size | `varuint32` | size of function body to follow, in bytes |
| local_count | `varuint32` | number of local entries |
| locals | `local_entry*` | local variables |
| ast | `byte*` | post-order encoded AST |
| code | `byte*` | bytecode of the function |
| end | `byte` | `0x0f`, indicating the end of the body |

#### Local Entry
Expand Down