Skip to content
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
11 changes: 8 additions & 3 deletions AstSemantics.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Abstract Syntax Tree Semantics

WebAssembly code is represented as an Abstract Syntax Tree (AST) where each node
represents an expression. Each function body consists of a list of expressions.
All expressions and operators are typed, with no implicit conversions or overloading rules.
This document describes WebAssembly semantics. The description here is written
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "typed stack machine"? if typed is important, why not "typed AST" as well?

in terms of an Abstract Syntax Tree (AST), however it is also possible to
understand WebAssembly semantics in terms of a stack machine. (In practice,
implementations need not build an actual AST or maintain an actual stack; they
need only behave [as if](https://en.wikipedia.org/wiki/As-if_rule) they did so.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw I don't think describing wasm as a 'stack machine' will help the reader because: the nodes are still expressions and need not represent one value on the stack; and there are some in-order operators that do not fit the 'stack machine' 'instruction' description well. Perhaps after some of the changes under discussion it will fit the 'stack machine' description better, such as removing the invalid/empty type, and defining multiple value calls to push multiple values on a values stack, but there are a lot of issues to consider.

This document explains the high-level design of the AST: its types, constructs, and
semantics. For full details consult [the formal Specification](https://github.com/WebAssembly/spec),
for file-level encoding details consult [Binary Encoding](BinaryEncoding.md),
and for the human-readable text representation consult [Text Format](TextFormat.md).

Each function body consists of a list of expressions. All expressions and
operators are typed, with no implicit conversions or overloading rules.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may well be more efficient for the encoding to take advantage of implicit conversions and/or to specialize the operators based on the argument types with the post-order encoding. I don't see the rationale for excluding these options.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is preexisting text that this PR is just moving, so I'd like to suggest raising this question in a new issue.

Verification of WebAssembly code requires only a single pass with constant-time
type checking and well-formedness checking.

Expand Down