structured-concept:
WebAssembly--programing-language (Wasm)

concept-created: {2018-03-18}

description of Wasm

description::
· WebAssembly-(Wasm) is a low-level, assembly-like programing-language understood by javascript-runtimes, browsers and Node.js.
· it is an intermediate language, between a-high|middle-level and a-machine programing-language.
[hmnSgm.2018-05-20]

name::
* cpt.filMcsLwasm.last.html,
* cpt.dirTchInf/filMcsLwasm.last.html,
* cpt.language.WebAssembly,
* cpt.programing-language.WebAssembly,
* cpt.Wasm,
* cpt.Wasm'(WebAssembly),
* cpt.Wasm-(WebAssembly),
* cpt.WebAssembly,
* cpt.WebAssembly-(Wasm),

archetype (input-doc) of Wasm

description::
· Wasm is an intermediate language between a-high|middle-level and a-machine languge.
· the-Wasm-archetype is a-high|middle-level-source-document of programing-languages such as C, C++, Rust, ..., which will-be-mapped to a-Wasm-binary-algorithm by a-compiler.
· also, the-Wasm-archetype could-be a human info-processing-document, which will-be-mapped to a-Wasm-text-algorithm by a-human.
[hmnSgm.2018-05-07]
===
Consider WebAssembly for performance-intensive use cases such as games, music streaming, video editing, and CAD applications.
[https://www.technologybreakingnews.com/2018/02/webassembly-tutorial-get-started-with-webassembly/]

name::
* cpt.Wasm'archetype,
* cpt.Wasm'input-document,

language compiled to Wasm

description::
· WebAssembly[a] is also a-compile-target, that is other languages like C, C++, Rust are-compiled to it[a].

name::
* cpt.Wasm'compile-target,
* cpt.Wasm'language-that-is-compiled-to-Wasm,

addressWpg::
* https://github.com/appcypher/awesome-wasm-langs,

algorithm (output-doc) of Wasm

description::
· Wasm-algorithm[a] is a-document, which is a-translation of a-Wasm-archetype in a-format that the-Wasm-virtual-machine executes.
· it[a] is written in 2 formats, a-text and a-binary.
· a-Wasm-algorithm is-not-understood directly by a-physical-machine.
· it[a] must-be-translated to machine-document.
[hmnSgm.2018-05-07]

name::
* cpt.Wasm'algorithm,
* cpt.Wasm'document,
* cpt.Wasm'output-document,
* cpt.Wasm-algo,
* cpt.Wasm-doc,

algo-machine of Wasm

description::
· the-machine[a] that understands a-Wasm-algorithm is not a real machine, it is a virtual machine, intermediate to the real machine that executes the-algorithm.
· it[a] is a-stack-machine, this means that all the-values an-operation needs are-inserted in a-stack before the-operation is-performed.

name::
* cpt.Wasm'computational-model,
* cpt.Wasm'intermediate-virtual-machine,
* cpt.Wasm'machine,
* cpt.Wasm'stack-machine,
* cpt.Wasm'virtual-machine,

addressWpg::
* {2017-04-25} Sven-Sauleau, Imagine the computer is a stack (using Forth), https://medium.com/@svensauleau/,

store of Wasm-machine

description::
· the-store contains the-state of a-Wasm-program.

name::
* cpt.Wasm'store-of-machine,
* cpt.Wasm-machine'store,

stack of Wasm-machine

description::
· instructions manipulate values on an-implicit-operand-stack, consuming (popping) argument-values and producing (pushing) result-values.
[https://webassembly.github.io/spec/core/_download/WebAssembly.pdf]

name::
* cpt.Wasm'implicit-operand-stack,
* cpt.Wasm'operand-stack,
* cpt.Wasm'stack,
* cpt.Wasm'value-stack,
* cpt.Wasm'virtual-stack,

algo-unit of Wasm

description::
· the-units of binary-algo are bits.
· the-units of text-algo are unicode-characters.
[hmnSgm.2018-03-28]

name::
* cpt.Wasm'unit-of-algo,

unit.TEXT

description::
· while source-text may-contain any Unicode-character in comments or string literals, the-rest of the-grammar is-formed exclusively from the-characters supported by the-7-bit-ASCII-subset-of-Unicode.
[https://webassembly.github.io/spec/core/text/lexical.html#characters {1-0.2018-03-22}]

name::
* cpt.Wasm'text-unit,
* cpt.Wasm-text-unit,
* cpt.Wasm-unit.text,

text-unit.CHARACTER

description::
· the-text-format assigns meaning to source-text, which consists of a sequence of characters.
· characters are-assumed to be-represented as valid Unicode (Section 2.4) code-points.
- source ::= char∗
- char ::= U+00 | … | U+D7FF | U+E000 | … | U+10FFFF
· note: while source-text may-contain any Unicode-character in comments or string-literals, the-rest of the-grammar is-formed exclusively from the-characters supported by the-7-bit-ASCII-subset-of-Unicode.
[https://webassembly.github.io/spec/core/text/lexical.html#characters {1-0.2018-03-28}]

name::
* cpt.Wasm'character-of-txt-algo,

text-unit.WHITE-SPACE

description::
· white-space is any sequence of literal-space-characters, formatting-characters, or comments.
· the allowed formatting-characters correspond to a subset of the-ASCII-format-effectors, namely, horizontal-tabulation-(U+09), line-feed-(U+0A), and carriage-return-(U+0D).
space ::= (‘ ’ | format | comment)∗
format ::= U+09 | U+0A | U+0D

· the only relevance of white-space is to separate tokens, it is-ignored otherwise.
[https://webassembly.github.io/spec/core/text/lexical.html#white-space]

name::
* cpt.Wasm'white-space,
* cpt.Wasm-text-unit.white-space,

text-unit.TOKEN

description::
· the character stream in the-source-text is-divided, from left to right, into a sequence of tokens, as defined by the following grammar.
- token ::= keyword | uN | sN | fN | string | id | ‘(’ | ‘)’ | reserved
- keyword ::= (‘a’ | … | ‘z’) idchar∗(if occurring as a literal terminal in the grammar)
- reserved ::= idchar+
· tokens are-formed from the input character stream according to the longest match rule.
· that is, the next token always consists of the longest possible sequence of characters that is recognized by the above lexical-grammar.
· tokens can-be-separated by white-space, but except for strings, they cannot themselves contain whitespace.
[https://webassembly.github.io/spec/core/text/lexical.html#tokens {1-0.2018-03-28}]

name::
* cpt.Wasm'token-of-text-algo,

text-unit.COMMENT

description::
· a-comment can either be a-line-comment, started with a double semicolon ‘;;’ and extending to the-end of the-line, or a-block-comment, enclosed in delimiters ‘(;’…‘;)’.
· block-comments can-be-nested.
[https://webassembly.github.io/spec/core/text/lexical.html#comments {1-0.2018-03-22}]

name::
* cpt.Wasm'comment,

example::
(global (;0;) (mut i32) (i32.const 100)) ;;mutable-variable
//(;0;) is a-block-comment denoting the-index of the-global
//;;mutable-variable is a-line-comment

unit.BINARY

description::
· bit is the-unit of a-binary-algo.

name::
* cpt.Wasm'binary-unit,
* cpt.Wasm-unit.binary,

algo-sem-unit of Wasm

name::
* cpt.Wasm'semantic-unit-of-algo,
* cpt.Wasm-sem-unit,

sem-unit.SPECIFIC

specific::
* text--sem-unit,
* binary--sem-unit,
===
* value,
* function,
* variable,
* table,
* memory,

sem-unit.TEXT

name::
* cpt.Wasm'text-sem-unit,
* cpt.Wasm-sem-unit.text,

text-sem-unit.STRING

description::
· strings denote sequences of bytes that can-represent both textual and binary data.
· they are-enclosed in quotation-marks and may-contain any character other than ASCII-control-characters, quotation-marks (‘"’), or backslash (‘∖’), except when expressed with an-escape-sequence.
[https://webassembly.github.io/spec/core/text/values.html#strings {1-0.2018-03-28}]

name::
* cpt.Wasm'string,
* cpt.Wasm-sem-unit.string,

sem-unit.BINARY

name::
* cpt.Wasm'binary-sem-unit,
* cpt.Wasm-sem-unit.binary,

sem-unit.VALUE

description::
'Machine Types
WebAssembly has only four basic value types t, all of which are available in common hardware.
These are integers and IEEE 754 floating point numbers, each in 32 and 64 bit width.
32 bit integers can be used as addresses in the linear memory (Section 2.2), and indexes into function tables (Section 2.4).
Most WebAssembly instructions simply execute operators on values of these basic data types.
The grammar in Figure 1 conveniently distinguishes several categories, such as unary and binary operators, tests and comparisons.
WebAssembly provides conversions between all four types, and the ability to reinterpret the bits of values across equally-sized types.
Like common hardware, WebAssembly has no distinction between signed and unsigned integer types.
Instead, when the signedness of values matters to an instruction, a sign extension suffix u or s selects either unsigned or 2's complement signed behavior.'
[https://github.com/WebAssembly/spec/blob/master/papers/pldi2017.pdf]

name::
* cpt.Wasm-sem-unit.value,
* cpt.Wasm-value,

value.SPECIFIC

name::
* cpt.Wasm-value.specific,

value.TYPE

name::
* cpt.Wasm'basic-data-type,
* cpt.Wasm'machine-type,
* cpt.Wasm'value-type,

specific::
* i32,
* i64,
* f32,
* f64,

value-type.BINARY

description::
· value-types are-encoded by a single byte.
- valtype ::= 0x7F ⇒ i32
  | 0x7E ⇒ i64
  | 0x7D ⇒ f32
  | 0x7C ⇒ f64
[https://webassembly.github.io/spec/core/binary/types.html#binary-valtype {1-0.2018-03-28}]

name::
* cpt.Wasm'value-type.binary,

value-type.TEXT

description::
· valtype ::= ‘i32’ ⇒ i32
  | ‘i64’ ⇒ i64
  | ‘f32’ ⇒ f32
  | ‘f64’ ⇒ f64
[https://webassembly.github.io/spec/core/text/types.html#value-types {1-0.2018-03-28}]

name::
* cpt.Wasm'value-type.text,

value-type.i32

description::
The types i32 and i64 classify 32 and 64 bit integers, respectively. Integers are not inherently signed or unsigned, their interpretation is determined by individual operations.
[https://webassembly.github.io/spec/core/syntax/types.html#value-types {1-0.2018-03-22}]

name::
* cpt.Wasm'i32-sem-unit,
* cpt.Wasm-sem-unit.i32,
* cpt.Wasm-value.i32,

value.i64

name::
* cpt.Wasm'i64-sem-unit,
* cpt.Wasm-sem-unit.i64,
* cpt.Wasm-value.i64,

value.f32

description::
The types f32 and f64 classify 32 and 64 bit floating-point data, respectively. They correspond to the respective binary floating-point representations, also known as single and double precision, as defined by the IEEE 754-2008 standard (Section 3.3).
[https://webassembly.github.io/spec/core/syntax/types.html#value-types {1-0.2018-03-22}]

name::
* cpt.Wasm'f32-sem-unit,
* cpt.Wasm-sem-unit.f32,
* cpt.Wasm-value.f32,

value.f64

name::
* cpt.Wasm'f64-sem-unit,
* cpt.Wasm-sem-unit.f64,
* cpt.Wasm-value.f64,

value.BYTE

name::
* cpt.Wasm'byte,
* cpt.Wasm-value.byte,

value.INTEGER

description::
· different classes of integers with different value ranges are distinguished by their bit-width-N and by whether they are unsigned or signed.
· the main integer types occurring in this specification are u32, u64, s32, s64, i8, i16, i32, i64. However, other sizes occur as auxiliary constructions, e.g., in the definition of floating-point numbers.
[https://webassembly.github.io/spec/core/syntax/values.html#integers {1-0.2018-03-22}]

name::
* cpt.Wasm'integer,
* cpt.Wasm'number.integer,
* cpt.Wasm-sem-unit.integer,

value.FLOATING-POINT

description::
·

name::
* cpt.Wasm'floating-point,
* cpt.Wasm'number.floating-point,
* cpt.Wasm-sem-unit.floating-point,

value.RESULT

description::
· result is a sequence of values which is the-output of executing instructions or blocks.
· in current version, at most one value is-allowed.
[https://webassembly.github.io/spec/core/syntax/types.html#result-types {1-0.2018-03-22}]

name::
* cpt.Wasm'result-type,
* cpt.Wasm-value.result,

sem-unit.FUNCTION

description::
· function is a-semantic-unit that denote a-process.
[hmnSgm.2018-05-17]

name::
* cpt.Wasm'function,
* cpt.Wasm-func,

parameter of function

name::
* cpt.Wasm'param-of-function,
* cpt.Wasm-function'param,

return-value of function

description::
· the-return-value of a-function is just the final value left on the-stack.
· the-WebAssembly validation-rules ensure the-stack matches exactly: if you declare a (result f32), then the-stack must contain exactly one f32 at the-end.
· If there is no result-type, the-stack must-be-empty.
[https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format]

name::
* cpt.Wasm'result-of-function,
* cpt.Wasm-function'result,

signature of function

description::
· function-types classify the-signature of functions, mapping a-vector of parameters to a-vector of results, written as follows.
- functype ::= [vec(valtype)] → [vec(valtype)]
· note: in the current version of WebAssembly, the-length of the-result-type-vector of a valid function-type may-be at most 1. This restriction may-be-removed in future versions.
[https://webassembly.github.io/spec/core/syntax/types.html#syntax-functype {1-0.2018-04-05}]
===
· function-type is a generic signature that maps a-vector of parmeters to a-vector of results[a] which[a] in the current version is at most 1.
[https://webassembly.github.io/spec/core/syntax/types.html#syntax-functype {1-0.2018-03-22}]

name::
* cpt.Wasm'type-of-function,
* cpt.Wasm-function'signature,
* cpt.Wasm-function'type,
* cpt.Wasm-function-type,

function-type.BINARY

description::
· function-types are-encoded by the-byte 0x60 followed by the respective vectors of parameter and result-types.
- functype ::= 0x60 t∗1:vec(valtype) t∗2:vec(valtype)⇒[t∗1]→[t∗2]
[https://webassembly.github.io/spec/core/binary/types.html#function-types {1-0.2018-03-28}]

name::
* cpt.Wasm-function-type.binary,

example::
;; (func (;0;) (param i32 i32) (result i32))
; type 0
60 ; function-type
02 ; num params
7f ; i32 type of first parameter
7f ; i32
01 ; num results
7f ; i32

function-type.TEXT

description::
- functype ::=‘(’ ‘func’ t∗1:vec(param) t∗2:vec(result) ‘)’ ⇒ [t∗1]→[t∗2]
- param ::= ‘(’ ‘param’ id? t:valtype ‘)’ ⇒ t
- result ::= ‘(’ ‘result’ t:valtype ‘)’ ⇒ t
[https://webassembly.github.io/spec/core/text/types.html#function-types {1-0.2018-03-28}]

name::
* cpt.Wasm-function-type.text,

example::
(type (;0;) (func (param i32 i32) (result i32)))
(func (;0;) (type 0) (param i32 i32) (result i32))

or
(func (param $p1 i32) (param $p2 i32) (result i32))
or
(func (export "f") (param $p1 i32) (param $p2 i32) (result i32))
or
(func (export "f") (param i32 i32) (result i32))

body of function

description::
· the-body-of-a-function is a-sequence of instructions that describe the-process of the-function:
(i32.mul
 (i32.add (i32.const 5) (get_local $x))
 (i32.const 2)
)

or in the following format:
i32.const 5
get_local $x
i32.add
i32.const 2
i32.mul

· in the-binary-format, the-order of instructions is always sequential.

name::
* cpt.Wasm-function'body,
* cpt.Wasm-function'code,

index-space of function

description::
· the-index-space for functions, tables, memories and globals includes respective imports declared in the same module.
· the-indices of these imports precede the-indices of other definitions in the same index-space.
[https://webassembly.github.io/spec/core/syntax/modules.html#indices {1-0.2018-03-22}]

name::
* cpt.Wasm-function'index-space,

calling of function

description::
· when a-function is-called, it starts with an empty stack which is gradually filled-up and emptied as the body’s instructions are-executed.
===
· Invocation may fail with an error if the arguments do not fit the function type.
[https://webassembly.github.io/spec/core/exec/modules.html#invocation]

name::
* cpt.Wasm-function'calling,
* cpt.Wasm-function'invocating,

function.START

description::
· modules can-define a-start-function that is automatically executed.
[https://webassembly.github.io/spec/core/intro/overview.html#concepts {1-0.2018-03-22}]
===
· the-start-component of a-module optionally declares the-function-index of a-start-function that is automatically invoked when the-module is-instantiated, after tables and memories have-been-initialized.
- start ::= {func funcidx}
[https://webassembly.github.io/spec/core/syntax/modules.html#start-function {1-0.2018-03-28}]

name::
* cpt.Wasm'start-function,
* cpt.Wasm-function.start,
* cpt.Wasm-start-function,

start-function.BINARY

description::
· the-start-section has the-id 8.
· it decodes into an optional start-function that represents the-start-component of a-module.
- startsec ::= st?:section8(start) ⇒st?
- start ::= x:funcidx ⇒ {func x}
[https://webassembly.github.io/spec/core/binary/modules.html#start-section {1-0.2018-03-28}]

name::
* cpt.Wasm-start-function.binary,

start-function.TEXT

description::
· a-start-function is-defined in terms of its index.
- startI ::= ‘(’ ‘start’ x:funcidxI ‘)’ ⇒ {func x}
· note: at most one start-function may-occur in a-module, which is-ensured by a suitable side condition on the-module-grammar.
[https://webassembly.github.io/spec/core/text/modules.html#start-function {1-0.2018-03-28}]

name::
* cpt.Wasm-start-function.text,

function.ADD

description::
· input: 2 i32 numbers.
· output: the-sum of input.

(func (export "f") (param $p1 i32) (param $p2 i32) (result i32)
 get_local $p1
 get_local $p2
 i32.add
)
//=== javascript code:
let f = oModule.instance.exports.f;
console.log(f(8,2)); //outputs 10

name::
* cpt.Wasm-function.add,

sem-unit.VARIABLE

description::
· a-variable is a-name-value pair.

name::
* cpt.Wasm'variable,
* cpt.Wasm-sem-unit.named-value,

variable.GLOBAL

name::
* cpt.Wasm'global-variable,
* cpt.Wasm-global,
* cpt.Wasm-variable.global,

declaration of global-variable

description::
· type | mutability | initialization
· text: (global (mut i32) (i32.const 100)) ;; mutable
· binary: 7F (;i32;) 01 (;mutable;) e400 (;i32 100;) 0b (;end;)

name::
* cpt.Wasm-global'declaration,
* cpt.Wasm-global'definition,
* cpt.Wasm-global'description,
* cpt.Wasm-global-variable'description,

whole-chain::
* global-section,

global-declaration.BINARY

description::
· Global types are encoded by their value type and a flag for their mutability.
- globaltype ::= t:valtype m:mut ⇒ m t
- mut ::= 0x00 ⇒ const
  | 0x01 ⇒ var
[https://webassembly.github.io/spec/core/binary/types.html#global-types {1-0.2018-03-28}]

name::
* cpt.Wasm-global-dfn.binary,

global-declaration.TEXT

description::
- globaltype ::= t:valtype ⇒ const t
  | ‘(’ ‘mut’ t:valtype ‘)’ ⇒ var t
[https://webassembly.github.io/spec/core/text/types.html#global-types {1-0.2018-03-28}]

name::
* cpt.Wasm-global-dfn.text,

example::
(global (;0;) (mut i32) (i32.const 100)) ;;mutable
(global (;1;) i32 (i32.const 200)) ;;immutable

index-space of global

description::
· the-global-index starts with any imported-globals and continues incrementing with any globals defined in the-global-section.
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm-global'index-space,
* cpt.Wasm-global-variable'index-space,

mutability of global

description::
· every global is mutable or immutable.
· in text-format it is-denoted with the-mut keyword.
· in binary-format this attribute takes 0 or 1 value.

name::
* cpt.Wasm-global'mutability,

variable.LOCAL

description::
· locals are the-variables of functions, parameters AND body variables.
===
· locals are like variables in many higher-level-programming-languages: we can-name them, store values to them and load values from them.
· locals are-named using function-local integer index.
· when defining a-function-body, we can-declare any number of locals for the function's code.
· parameters to a-function are also locals and the “name” index of locals start at 0 with the first function parameter and continue incrementing with each additional parameter and eventually with each listed local of the-function-body.
· locals are always initialized to zero (all their bits are 0.)
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm'local-variable,
* cpt.Wasm-local,
* cpt.Wasm-variable.local,

declaration of local

description::
· body-locals are-decleared in function's-body.
· text-format: (local i32 i32 i64)

name::
* cpt.Wasm-local.declaration,

index-space of local

description::
· the-index-space for locals is only accessible inside a-function and includes the-parameters and local-variables of that function, which precede the other locals.
[https://webassembly.github.io/spec/core/syntax/modules.html#indices {1-0.2018-03-22}]

name::
* cpt.Wasm-local'index-space,

sem-unit.TABLE

description::
A table is similar to a linear memory whose elements, instead of being bytes, are opaque values of a particular table element type.
This allows the table to contain values—like GC references, raw OS handles, or native pointers—that are accessed by WebAssembly code indirectly through an integer index.
This feature bridges the gap between low-level, untrusted linear memory and high-level opaque handles/references at the cost of a bounds-checked table indirection.
[https://webassembly.org/docs/semantics/#table]
===
· tables are basically resizable arrays of references that can-be-accessed by index from WebAssembly-code.
[https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format]
===
· tables are mechanisms for mapping opaque values which can-not-be-represented in nor directly accessed by WebAssembly, like for instance a-JavaScript-object or an-operating-system-file-handle.
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm'table,

addressWpg::
* https://webassembly.org/docs/semantics/#table,

declaration of table

description::
Field-Name | Type | Description
element_type | table element type | the element type of the table
resizable | resizable limits | table flags and sizes in units of elements
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#table-description]

name::
* cpt.Wasm-table'declaration,
* cpt.Wasm-table'description,

table-declaration.BINARY

description::
· Table types are encoded with their limits and a constant byte indicating their element type.
- tabletype ::= et:elemtype lim:limits ⇒ lim et
- elemtype ::= 0x70 ⇒ anyfunc
[https://webassembly.github.io/spec/core/binary/types.html#table-types {1-0.2018-03-28}]

name::
* cpt.Wasm-table-dfn.binary,

table-declaration.TEXT

description::
- tabletype ::=lim:limits et:elemtype ⇒ lim et
- elemtype ::= ‘anyfunc’ ⇒ anyfunc
Note: additional element-types may-be-introduced in future versions of WebAssembly.
[https://webassembly.github.io/spec/core/text/types.html#table-types {1-0.2018-03-28}]

name::
* cpt.Wasm-table-dfn.text,

index-space of table

description::
· the-index-space for functions, tables, memories and globals includes respective imports declared in the same module.
· the-indices of these imports precede the-indices of other definitions in the same index-space.
[https://webassembly.github.io/spec/core/syntax/modules.html#indices {1-0.2018-03-22}]

name::
* cpt.Wasm-table'index-space,

table.TXT

example::
// defines a-table with elements 2 funtions, and export it
(table (export "tbl") anyfunc (elem $f13 $f42))
===
// imports a-table with 2 elements and initializes the 2 elements.
(import "js" "tbl" (table 2 anyfunc))
(elem (i32.const 0) $f42 $f83)

sem-unit.MEMORY

description::
· a-memory is a-vector of raw uninterpreted bytes.
[https://webassembly.github.io/spec/core/syntax/modules.html#memories {1-0.2018-03-22}]

name::
* cpt.Wasm'memory,
* cpt.Wasm-memory,
* cpt.Wasm-sem-unit.memory,

usage::
· the-memory is-used to store strings and other data other than numbers.

declaration of memory

name::
* cpt.Wasm-memory'declaration,
* cpt.Wasm-memory'definition,

memory-declaration.BINARY

description::
· Memory types are encoded with their limits.
- memtype ::= lim:limits ⇒ lim
[https://webassembly.github.io/spec/core/binary/types.html#memory-types {1-0.2018-03-28}]

name::
* cpt.Wasm-memory.binary,

memory-declaration.TEXT

description::
- memtype ::= lim:limits ⇒ lim
[https://webassembly.github.io/spec/core/text/types.html#memory-types {1-0.2018-03-28}]

name::
* cpt.Wasm-memory.text,

example::
//declares a-memory and exports it as "mem"
//the ‘1’ indicates that the-memory requires at 1 page.
(memory (export "mem") 1)

page of memory

description::
· pages in WebAssembly are 64-KiB, and are the-units used in linear-memory size-declarations and size-operations.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#pages]

name::
* cpt.Wasm-memory'page,

index-space of memory

description::
· the-index-space for functions, tables, memories and globals includes respective imports declared in the same module.
· the-indices of these imports precede the-indices of other definitions in the same index-space.
[https://webassembly.github.io/spec/core/syntax/modules.html#indices {1-0.2018-03-22}]

name::
* cpt.Wasm-memory'index-space,

instruction of memory (link)

sem-unit.LIMIT

description::
· limit is the-size-range of resizeable storage associated with memory-types and table-types.
· limits ::= {min u32, max u32?}
· if no maximum is given, the respective storage can grow to any size.

name::
* cpt.Wasm'limit-type,
* cpt.Wasm-sem-unit.limit,

limit.BINARY

description::
· limits are-encoded with a preceding flag indicating whether a-maximum is present.
limits ::= 0x00 n:u32 ⇒ {min n,max ϵ}
  | 0x01 n:u32 m:u32 ⇒ {min n,max m}
[https://webassembly.github.io/spec/core/binary/types.html#limits {1-0.2018-03-28}]

name::
* cpt.Wasm-limit.binary,

limit.TEXT

description::
- limits ::= n:u32 ⇒{min n,max ϵ}
  | n:u32 m:u32 ⇒ {min n,max m}
[https://webassembly.github.io/spec/core/text/types.html#limits {1-0.2018-03-28}]

name::
* cpt.Wasm-limit.text,

sem-unit.EXTERNAL

description::
·

name::
* cpt.Wasm'external-type,
* cpt.Wasm-sem-unit.external,

sem-unit.NAMED

description::
· named-sem-unit is a-sem-unit with a-name.
· the-name is an-index in the-sequence of the-definitions of sem-units or a-symbolic-name in the-text-algo.
[hmnSgm.2018-03-28]

name::
* cpt.Wasm'named-sem-unit,
* cpt.Wasm-sem-unit.named,

index of named-sem-unit

description::
· definitions are-referenced with zero-based indices.
· each class of definition has its own index-space, as distinguished by the following classes.
- typeidx ::= u32
- funcidx ::= u32
- tableidx ::= u32
- memidx ::= u32
- globalidx ::= u32
- localidx ::= u32
- labelidx ::= u32
[https://webassembly.github.io/spec/core/syntax/modules.html#syntax-index {1-0.2018-03-22}]

name::
* cpt.Wasm'index-of-sem-unit,

identifier of named-sem-unit

description::
· indices can-be-given in both numeric and symbolic form.
· symbolic-identifiers that stand in-lieu-of indices start with ‘$’, followed by any sequence of printable-ASCII-characters that does-not-contain a-space, quotation-mark, comma, semicolon, or bracket.
- id ::= ‘$’ idchar+
- idchar ::= ‘0’ | … | ‘9’
  | ‘A’ | … | ‘Z’
  | ‘a’ | … | ‘z’
  | ‘!’ | ‘#’ | ‘$’ | ‘%’ | ‘&’ | ‘′’ | ‘∗’ | ‘+’ |
  | ‘−’ | ‘.’ | ‘/’
  | ‘:’ | ‘<’ | ‘=’ | ‘>’ | ‘?’ | ‘@’ | ‘∖’ | ‘ ^’ | ‘_’ | ‘`’ | ‘|’ | ‘~’

[https://webassembly.github.io/spec/core/text/values.html#text-idchar {1-0.2018-03-28}]

name::
* cpt.Wasm'identifier-of-sem-unit,

algo-sentence (instruction) of Wasm

description::
· a-WebAssembly-document consist of a-sequence of instructions.
· an-instruction consists of an-opcode followed by its immediate operands.

name::
* cpt.Wasm'command,
* cpt.Wasm'computation,
* cpt.Wasm'instruction,
* cpt.Wasm'sentence,
* cpt.Wasm-instruction,

opcode of instruction

description::
'WebAssembly is not a large language.
Its official specification defines 171 individual opcodes, but each of these can be viewed as different specialisations of the 28 abstract operations specified in the working group’s paper.
All WebAssembly behaviour is specified at the level of abstract operations, not concrete opcodes.'
[https://www.cl.cam.ac.uk/~caw77/papers/mechanising-and-verifying-the-webassembly-specification.pdf]

name::
* cpt.Wasm'opcode-of-instruction,
* cpt.Wasm-instruction'opcode,
* cpt.Wasm-instruction'operation,

mnemonic of opcode

name::
* cpt.Wasm-instruction'mnemonic,

opcode.SPECIFIC

specific::

  1. opcode.block: the beginning of a block construct, a sequence of instructions with a label at the end
  2. opcode.br: branch to a given label in an enclosing construct
  3. opcode.br_if: conditionally branch to a given label in an enclosing construct
  4. opcode.br_table: a jump table which jumps to a label in an enclosing construct
  5. opcode.call: call function directly
  6. opcode.call_indirect: call function indirectly
  7. opcode.current_memory: return the current memory size in units of pages.
  8. opcode.drop: a unary operator that discards the value of its operand.
  9. opcode.else: marks the else block of an if
  10. opcode.end: an instruction that marks the end of a block, loop, if, or function
  11. opcode.f32.abs: absolute value
  12. opcode.f32.add: addition
  13. opcode.f32.ceil: ceiling operator
  14. opcode.f32.const: produce the value of an f32 immediate
  15. opcode.f32.convert_s/i32: convert a signed 32-bit integer to a 32-bit float
  16. opcode.f32.convert_s/i64: convert a signed 64-bit integer to a 32-bit float
  17. opcode.f32.convert_u/i32: convert an unsigned 32-bit integer to a 32-bit float
  18. opcode.f32.convert_u/i64: convert an unsigned 64-bit integer to a 32-bit float
  19. opcode.f32.copysign: copysign
  20. opcode.f32.demote/f64: demote a 64-bit float to a 32-bit float
  21. opcode.f32.div: division
  22. opcode.f32.eq: compare ordered and equal
  23. opcode.f32.floor: floor operator
  24. opcode.f32.ge: compare ordered and greater than or equal
  25. opcode.f32.gt: compare ordered and greater than
  26. opcode.f32.le: compare ordered and less than or equal
  27. opcode.f32.load: load 4 bytes as f32
  28. opcode.f32.lt: compare ordered and less than
  29. opcode.f32.max: maximum (binary operator); if either operand is NaN, returns NaN
  30. opcode.f32.min: minimum (binary operator); if either operand is NaN, returns NaN
  31. opcode.f32.mul: multiplication
  32. opcode.f32.ne: compare unordered or unequal
  33. opcode.f32.nearest: round to nearest integer, ties to even
  34. opcode.f32.neg: negation
  35. opcode.f32.reinterpret/i32: reinterpret the bits of a 32-bit integer as a 32-bit float
  36. opcode.f32.sqrt: square root
  37. opcode.f32.store: (no conversion) store 4 bytes
  38. opcode.f32.sub: subtraction
  39. opcode.f32.trunc: round to nearest integer towards zero
  40. opcode.f64.abs: absolute value
  41. opcode.f64.add: addition
  42. opcode.f64.ceil: ceiling operator
  43. opcode.f64.const: produce the value of an f64 immediate
  44. opcode.f64.convert_s/i32: convert a signed 32-bit integer to a 64-bit float
  45. opcode.f64.convert_s/i64: convert a signed 64-bit integer to a 64-bit float
  46. opcode.f64.convert_u/i32: convert an unsigned 32-bit integer to a 64-bit float
  47. opcode.f64.convert_u/i64: convert an unsigned 64-bit integer to a 64-bit float
  48. opcode.f64.copysign: copysign
  49. opcode.f64.div: division
  50. opcode.f64.eq: compare ordered and equal
  51. opcode.f64.floor: floor operator
  52. opcode.f64.ge: compare ordered and greater than or equal
  53. opcode.f64.gt: compare ordered and greater than
  54. opcode.f64.le: compare ordered and less than or equal
  55. opcode.f64.load: load 8 bytes as f64
  56. opcode.f64.lt: compare ordered and less than
  57. opcode.f64.max: maximum (binary operator); if either operand is NaN, returns NaN
  58. opcode.f64.min: minimum (binary operator); if either operand is NaN, returns NaN
  59. opcode.f64.mul: multiplication
  60. opcode.f64.ne: compare unordered or unequal
  61. opcode.f64.nearest: round to nearest integer, ties to even
  62. opcode.f64.neg: negation
  63. opcode.f64.promote/f32: promote a 32-bit float to a 64-bit float
  64. opcode.f64.reinterpret/i64: reinterpret the bits of a 64-bit integer as a 64-bit float
  65. opcode.f64.sqrt: square root
  66. opcode.f64.store: (no conversion) store 8 bytes
  67. opcode.f64.sub: subtraction
  68. opcode.f64.trunc: round to nearest integer towards zero
  69. opcode.get_global: get the current value of a global variable
  70. opcode.get_local: read the current value of a local variable
  71. opcode.grow_memory: grow linear memory by a given unsigned delta of pages. Return the previous memory size in units of pages or -1 on failure.
  72. opcode.i32.add: sign-agnostic addition
  73. opcode.i32.and: sign-agnostic bitwise and
  74. opcode.i32.clz: sign-agnostic count leading zero bits (All zero bits are considered leading if the value is zero)
  75. opcode.i32.const: produce the value of an i32 immediate
  76. opcode.i32.ctz: sign-agnostic count trailing zero bits (All zero bits are considered trailing if the value is zero)
  77. opcode.i32.div_s: signed division (result is truncated toward zero)
  78. opcode.i32.div_u: unsigned division (result is floored)
  79. opcode.i32.eq: sign-agnostic compare equal
  80. opcode.i32.eqz: compare equal to zero (return 1 if operand is zero, 0 otherwise)
  81. opcode.i32.ge_s: signed greater than or equal
  82. opcode.i32.ge_u: unsigned greater than or equal
  83. opcode.i32.gt_s: signed greater than
  84. opcode.i32.gt_u: unsigned greater than
  85. opcode.i32.le_s: signed less than or equal
  86. opcode.i32.le_u: unsigned less than or equal
  87. opcode.i32.load8_s: load 1 byte and sign-extend i8 to i32
  88. opcode.i32.load8_u: load 1 byte and zero-extend i8 to i32
  89. opcode.i32.load16_s: load 2 bytes and sign-extend i16 to i32
  90. opcode.i32.load16_u: load 2 bytes and zero-extend i16 to i32
  91. opcode.i32.load: load 4 bytes as i32
  92. opcode.i32.lt_s: signed less than
  93. opcode.i32.lt_u: unsigned less than
  94. opcode.i32.mul: sign-agnostic multiplication (lower 32-bits)
  95. opcode.i32.ne: sign-agnostic compare unequal
  96. opcode.i32.or: sign-agnostic bitwise inclusive or
  97. opcode.i32.popcnt: sign-agnostic count number of one bits
  98. opcode.i32.reinterpret/f32: reinterpret the bits of a 32-bit float as a 32-bit integer
  99. opcode.i32.rem_s: signed remainder (result has the sign of the dividend)
  100. opcode.i32.rem_u: unsigned remainder
  101. opcode.i32.rotl: sign-agnostic rotate left
  102. opcode.i32.rotr: sign-agnostic rotate right
  103. opcode.i32.shl: sign-agnostic shift left
  104. opcode.i32.shr_s: sign-replicating (arithmetic) shift right
  105. opcode.i32.shr_u: zero-replicating (logical) shift right
  106. opcode.i32.store8: wrap i32 to i8 and store 1 byte
  107. opcode.i32.store16: wrap i32 to i16 and store 2 bytes
  108. opcode.i32.store: (no conversion) store 4 bytes
  109. opcode.i32.sub: sign-agnostic subtraction
  110. opcode.i32.trunc_s/f32: truncate a 32-bit float to a signed 32-bit integer
  111. opcode.i32.trunc_s/f64: truncate a 64-bit float to a signed 32-bit integer
  112. opcode.i32.trunc_u/f32: truncate a 32-bit float to an unsigned 32-bit integer
  113. opcode.i32.trunc_u/f64: truncate a 64-bit float to an unsigned 32-bit integer
  114. opcode.i32.wrap/i64: wrap a 64-bit integer to a 32-bit integer
  115. opcode.i32.xor: sign-agnostic bitwise exclusive or
  116. opcode.i64.const: produce the value of an i64 immediate
  117. opcode.i64.extend_s/i32: extend a signed 32-bit integer to a 64-bit integer
  118. opcode.i64.extend_u/i32: extend an unsigned 32-bit integer to a 64-bit integer
  119. opcode.i64.load8_s: load 1 byte and sign-extend i8 to i64
  120. opcode.i64.load8_u: load 1 byte and zero-extend i8 to i64
  121. opcode.i64.load16_s: load 2 bytes and sign-extend i16 to i64
  122. opcode.i64.load16_u: load 2 bytes and zero-extend i16 to i64
  123. opcode.i64.load32_s: load 4 bytes and sign-extend i32 to i64
  124. opcode.i64.load32_u: load 4 bytes and zero-extend i32 to i64
  125. opcode.i64.load: load 8 bytes as i64
  126. opcode.i64.reinterpret/f64: reinterpret the bits of a 64-bit float as a 64-bit integer
  127. opcode.i64.store8: wrap i64 to i8 and store 1 byte
  128. opcode.i64.store16: wrap i64 to i16 and store 2 bytes
  129. opcode.i64.store32: wrap i64 to i32 and store 4 bytes
  130. opcode.i64.store: (no conversion) store 8 bytes
  131. opcode.i64.trunc_s/f32: truncate a 32-bit float to a signed 64-bit integer
  132. opcode.i64.trunc_s/f64: truncate a 64-bit float to a signed 64-bit integer
  133. opcode.i64.trunc_u/f32: truncate a 32-bit float to an unsigned 64-bit integer
  134. opcode.i64.trunc_u/f64: truncate a 64-bit float to an unsigned 64-bit integer
  135. opcode.if: the beginning of an if construct with an implicit then block
  136. opcode.load:
  137. opcode.loop: a block with a label at the beginning which may be used to form loops
  138. opcode.nop: no operation, no effect
  139. opcode.return: return zero or more values from this function
  140. opcode.select: a ternary operator with two operands, which have the same type as each other, plus a boolean (i32) condition. select returns the first operand if the condition operand is non-zero, or the second otherwise.
  141. opcode.set_global: set the current value of a global variable
  142. opcode.set_local: set the current value of a local variable
  143. opcode.store:
  144. opcode.tee_local: like set_local, but also returns the set value
  145. opcode.unreachable: An instruction which always traps. It is intended to be used for example after calls to functions which are known by the producer not to return. This trap is intended to be impossible for user code to catch or handle, even in the future when it may be possible to handle some other kinds of traps or exceptions.

operand of instruction

name::
* cpt.Wasm'operand-of-sentence,
* cpt.Wasm-instruction'operand,

result of instruction

name::
* cpt.Wasm-instruction'result,

type of instruction

description::
· type-of-instruction is the-input (operands) and output (result) of an-instruction.
· it is-denoted as e.g.: [i32 i32]→[i32]
· you can-see them at: https://webassembly.github.io/spec/core/appendix/index-instructions.html,

name::
* cpt.Wasm'type-of-instruction,
* cpt.Wasm-instruction'type,

stack of instruction (link)

trap of instruction

description::
· under some conditions, certain instructions may-produce a-trap, which immediately aborts execution.
· traps cannot-be-handled by WebAssembly-code, but are-reported to the-outside-environment, where they typically can-be-caught.
[https://webassembly.github.io/spec/core/_download/WebAssembly.pdf {1-0.2018-03-22}]

name::
* cpt.Wasm'trap-of-instruction,
* cpt.Wasm-instruction'trap,

resource of instruction

name::
* cpt.Wasm-instruction'resource,

addressWpg::
* https://webassembly.org/docs/semantics/,
* https://webassembly.github.io/spec/core/syntax/instructions.html,
* https://webassembly.github.io/spec/core/appendix/index-instructions.html,
* {2018-04-07} Mauro-Bringolf, Learning the Webassembly type system, https://maurobringolf.ch/,

instruction.SPECIFIC

specific::
* additional-memory-related--instruction,
* basic-instruction,
* control-flow--instruction,
* conversion-instruction,
* floating-point-arithmetic--instruction,
* floating-point-comparison--instruction,
* integer-arithmetic--instruction,
* integer-comparison--instruction,
* load-and-store--instruction,
* signed-instruction,
* unsigned-instruction,
* B-branch--instruction-family,
* C-comparison--instruction-family,
* E-floating-point-bitwise--instruction-family,
* F-floating-point--instruction-family,
* G-generic-integer--instruction-family,
* L-call--instruction-family,
* M-linear-memory-access--instruction-family,
* Q-control-flow-barrier--instruction-family,
* R-remainder--instruction-family,
* S-signed-integer--instruction-family,
* T-shift--instruction-family,
* U-unsigned-integer--instruction-family,
* Z-linear-memory-size--instruction-family,

instruction.CONTROL-FLOW

name::
* cpt.Wasm'control-flow-instruction,
* cpt.Wasm-instruction.control-flow,

specific::
* block,
* br (unconditional-branch),
* br_if (conditional-brance),
* br_table (table-branch),
* loop,
* if,
* else,
* end,
* nop,
* return,
* unreachable,

control-instruction.STRUCTURED

description::
· the block, loop and if instructions are structured-instructions.
· they bracket nested sequences of instructions, called blocks, terminated with, or separated by, end or else pseudo-instructions.
· as the-grammar prescribes, they must-be-well-nested.
· a-structured-instruction can-produce a-value as described by the annotated result-type.
[https://webassembly.github.io/spec/core/syntax/instructions.html#control-instructions {1-0.2018-03-22}]

name::
* cpt.Wasm'structured-control-instruction,
* cpt.Wasm-instruction.structured-control,

addressWpg::
* {2018-04-22} Mauro-Bringolf, Structured control flow in WebAssembly by example, https://maurobringolf.ch/,

label of structured-control-instruction

description::
· each structured-control-instruction introduces an implicit label.
· labels are targets for branch-instructions that reference them with label indices.
· unlike with other index-spaces, indexing of labels is relative by nesting depth, that is, label 0 refers to the innermost structured-control-instruction enclosing the referring branch-instruction, while increasing indices refer to those farther out.
· consequently, labels can only be-referenced from within the associated structured-control-instruction.
· this also implies that branches can only be-directed outwards, “breaking” from the-block of the-control-construct they target.
· the exact effect depends on that control-construct.
· in case of block or if it is a forward jump, resuming execution after the matching end.
· in case of loop it is a backward jump to the-beginning of the-loop.
[https://webassembly.github.io/spec/core/syntax/instructions.html#control-instructions {1-0.2018-03-22}]

name::
* cpt.Wasm'label-of--structured-control-instruction,

instruction.block

description::
· block resulttype instr∗ end

name::
* cpt.Wasm'block-instruction,
* cpt.Wasm-instruction.0x02-block,
* cpt.Wasm-instruction.block-0x02,

instruction.br_if

name::
* cpt.Wasm'br_if-instruction,
* cpt.Wasm-instruction.0x0D-br_if,
* cpt.Wasm-instruction.br_if-0x0D,

example::
(func (export "f") (result i32)
 (local $v1 i32)
 (set_local $v1 (i32.const 1))
 loop
   ;; v1 + 1
   (i32.add (get_local $v1) (i32.const 1))
   ;; if v1 < 10, loop
   (br_if 0 (i32.lt_u (tee_local $v1) (i32.const 10)))
 end
 get_local $v1
)

instruction.else

description::
· marks the else block of an-if.

name::
* cpt.Wasm'else-instruction,
* cpt.Wasm-instruction.0x05-else,
* cpt.Wasm-instruction.else-0x05,

example::
(module
 (func (export "f") (param i32) (result i32)
   (if (result i32) (i32.lt_s (get_local 0) (i32.const 0))
     ;; if input < 0, then output 1
     (then (i32.const 1))
     ;; else output 2
     (else (i32.const 2))
   )
 )
)

or
(module
 (type (;0;) (func (param i32) (result i32)))
 (func (;0;) (type 0) (param i32) (result i32)
   get_local 0
   i32.const 0
   i32.lt_s
   if (result i32) ;; label = @1
     i32.const 1
   else
     i32.const 2
   end
 )
 (export "f" (func 0))
)

instruction.end

description::
· marks the end of a block, loop, if, or function.
· Blocks are composed of matched pairs of block … end instructions, loops with matched pairs of loop … end instructions, and ifs with either if … end or if … else … end sequences. For each of these constructs the instructions in the ellipsis are said to be enclosed in the construct.
[https://webassembly.org/docs/semantics/]

name::
* cpt.Wasm'end-instruction,
* cpt.Wasm-instruction.0x0B-end,
* cpt.Wasm-instruction.end-0x0B,

example::
(module
 (type (;0;) (func (param i32) (result i32)))
 (func (;0;) (type 0) (param i32) (result i32)
   get_local 0
   i32.const 0
   i32.lt_s
   if (result i32) ;; label = @1
     i32.const 1
   else
     i32.const 2
   end
 )
 (export "f" (func 0))
)

instruction.if

description::
· if resulttype instr∗ else instr∗ end

name::
* cpt.Wasm'if-instruction,
* cpt.Wasm-instruction.0x04-if,
* cpt.Wasm-instruction.if-0x04,

example::
(module
 (func (export "f") (param i32) (result i32)
   (if (result i32) (i32.lt_s (get_local 0) (i32.const 0))
     ;; if input < 0, then output 1
     (then (i32.const 1))
     ;; else output 2
     (else (i32.const 2))
   )
 )
)

or
(module
 (type (;0;) (func (param i32) (result i32)))
 (func (;0;) (type 0) (param i32) (result i32)
   get_local 0
   i32.const 0
   i32.lt_s
   if (result i32) ;; label = @1
     i32.const 1
   else
     i32.const 2
   end
 )
 (export "f" (func 0))
)

instruction.loop

description::
· loop resulttype instr∗ end

name::
* cpt.Wasm'loop-instruction,
* cpt.Wasm-instruction.0x03-loop,
* cpt.Wasm-instruction.loop-0x03,

example::
(func (export "f") (result i32)
 (local $v1 i32)
 (set_local $v1 (i32.const 1))
 loop
   ;; v1 + 1
   (i32.add (get_local $v1) (i32.const 1))
   ;; if v1 < 10, loop
   (br_if 0 (i32.lt_u (tee_local $v1) (i32.const 10)))
 end
 get_local $v1
)

or
(func (export "f") (result i32)
 (local $v1 i32)
 (set_local $v1 (i32.const 1))
 loop &L0
   get_local $v1
   i32.const 1
   i32.add
   tee_local $v1
   i32.const 10
   i32.lt_u
   br_if $L0
 end
 get_local $v1
)

instruction.nop

description::
· the-nop-instruction does nothing.

name::
* cpt.Wasm'nop-instruction,
* cpt.Wasm-instruction.0x01-nop,
* cpt.Wasm-instruction.nop-0x01,

instruction.return

description::
· return value from function.

name::
* cpt.Wasm'return-instruction,
* cpt.Wasm-instruction.0x0F-return,
* cpt.Wasm-instruction.return-0x0F,

example::
(func (export "f") (param $a i32) (param $b i32) (result i32)
 ;; if (a > b) return 1, return 2
 (if (i32.gt_s (get_local $a) (get_local $b))
   (return (i32.const 1))
 )
 (return (i32.const 2))
)

or using wasm2wat
(module
 (type (;0;) (func (param i32 i32) (result i32)))
 (func (;0;) (type 0) (param i32 i32) (result i32)
   get_local 0
   get_local 1
   i32.gt_s
   if ;; label = @1
     i32.const 1
     return
   end
   i32.const 2
   return
 )
 (export "f" (func 0))
)

instruction.unreachable

description::
· the-unreachable-instruction causes an unconditional trap.

name::
* cpt.Wasm'unreachable-instruction,
* cpt.Wasm-instruction.0x00-unreachable,
* cpt.Wasm-instruction.unreachable-0x00,

instruction.CONTROL-FLOW.NO

description::
· instructions manipulate values on an implicit operand-stack and fall into two main categories.
· simple-instructions perform basic operations on data.
· they pop arguments from the-operand-stack and push results back to it.
· control-instructions alter control-flow.
· control-flow is structured, meaning it is-expressed with well-nested constructs such as blocks, loops, and conditionals.
· branches can only target such constructs.
[https://webassembly.github.io/spec/core/_download/WebAssembly.pdf]

name::
* cpt.Wasm'control-flow.no-instruction,
* cpt.Wasm-instruction.control-flow.no,

instruction.call

description::
· the-call-instruction calls a single function, given its index or name.

name::
* cpt.Wasm'call-instruction,
* cpt.Wasm-instruction.0x10-call,
* cpt.Wasm-instruction.call-0x10,

example::
(func $f1 ...)
(func (export "f2") (result i32)
 call $f1
)

instruction.current_memory

description::
· the-current_memory instruction returns the current size of a-memory.

name::
* cpt.Wasm'current_memory,
* cpt.Wasm-instruction.current_memory,

instruction.drop

description::
· the-drop-operator simply throws away a single operand.
[https://webassembly.github.io/spec/core/syntax/instructions.html#parametric-instructions {1-0.2018-03-22}]
===
· binary-format: 0x1A

name::
* cpt.Wasm'drop-instruction,
* cpt.Wasm-instruction.0x1A-drop,
* cpt.Wasm-instruction.drop-0x1A,

instruction.get_global

name::
* cpt.Wasm'get_global,
* cpt.Wasm-instruction.0x23-get_global,
* cpt.Wasm-instruction.get_global-0x23,

instruction.get_local

description::
· pushes the-value of a-variable onto the-stack,

name::
* cpt.Wasm'get_local,
* cpt.Wasm-instruction.0x20-get_local,
* cpt.Wasm-instruction.get_local-0x20,

example::
(func (param $p1 i32) (param $p2 f32) (local $loc i32)
 get_local $p1 ;; pushes param1 on stack
)

===
(func (param i32) (param f32) (local i32)
 get_local 0 ;; pushes first parameter on stack
 get_local 1 ;; pushes second parameter on stack
 get_local 2 ;; pushes first local on stack
)

instruction.grow_memory

description::
· the-grow_memory-instruction grows memory by a given delta and returns the previous size, or −1 if enough memory cannot-be-allocated.
· operate in units of page size.
[https://webassembly.github.io/spec/core/syntax/instructions.html#memory-instructions {1-0.2018-03-22}]

name::
* cpt.Wasm'grow_memory,
* cpt.Wasm'memory.grow,
* cpt.Wasm-instruction.0x40-memory.grow,
* cpt.Wasm-instruction.memory.grow-0x40,

instruction.i32.add

description::
· i32.add pops two i32 values from the-stack, computes their sum (modulo 2^32) and pushes the resulting i32 value.

name::
* cpt.Wasm'i32.add-instruction,
* cpt.Wasm-instruction.0x6A-i32.add,
* cpt.Wasm-instruction.i32.add-0x6A,

example::
(func (export "f") (param $a i32) (result i32)
 (i32.add (get_local 0) (i32.const 10))
)

or
(func (export "f") (param $a i32) (result i32)
 get_local 0
 i32.const 10
 i32.add
)

instruction.i32.const

description::
· i32.const just defines a 32-bit integer and pushes it onto the-stack.

name::
* cpt.Wasm'i32.const-instruction,
* cpt.Wasm-instruction.0x41-i32.const,
* cpt.Wasm-instruction.i32.const-0x41,

example::
// returns 10
(func (export "f") (result i32)
 (i32.const 10)
)

or
(func (export "f") (result i32)
 i32.const 10
)

instruction.i32.mul

description::
· pop two values from the-stack, multiply them, and push the-result onto the-stack.

name::
* cpt.Wasm'i32.mul-instruction,
* cpt.Wasm-instruction.0x6C-i32.mul,
* cpt.Wasm-instruction.i32.mul-0x6C,

example::
//for input 6 and 5, outputs 30
(func (export "f") (param $a i32) (param $b i32) (result i32)
 (i32.mul (get_local 0) (get_local 1))
)

or
(func (export "f") (param $a i32) (param $b i32) (result i32)
 get_local 0
 get_local 1
 i32.mul
)

instruction.load

description::
· memory is-accessed with load and store instructions for the different value-types.
· they all take a-memory-immediate-memarg that contains an address-offset and an-alignment-hint (in base 2 logarithmic representation).
· integer loads and stores can optionally specify a storage size that is smaller than the bit width of the respective value-type.
· in the-case of loads, a-sign-extension-mode-sx-(u|s) is then required to select appropriate behavior.
· the-static-address offset is added to the-dynamic-address operand, yielding a 33-bit effective-address that is the zero-based index at which the-memory is-accessed.
· all values are read and written in little-endian-byte-order.
· a-trap results if any of the accessed memory bytes lies outside the address range implied by the memory's current size.
· note: future version of WebAssembly might-provide memory-instructions with 64-bit address ranges.
[https://webassembly.github.io/spec/core/syntax/instructions.html#memory-instructions {1-0.2018-03-22}]

name::
* cpt.Wasm'load-memory-instruction,
* cpt.Wasm-instruction.load-memory,

instruction.select

description::
· a-ternary-operator with two operands, which have the same type as each other, plus a-boolean (i32) condition.
· it returns the first operand if the-condition operand is non-zero, or the-second otherwise.
===
· the-select-operator selects one of its first two operands based on whether its third operand is zero or not.
[https://webassembly.github.io/spec/core/syntax/instructions.html#parametric-instructions {1-0.2018-03-22}]
===
· binary-format: 0x1B

name::
* cpt.Wasm'select-instruction,
* cpt.Wasm-instruction.0x1B-select,
* cpt.Wasm-instruction.select-0x1B,

example::
(func (export "f") (param $a i32) (param $b i32) (result i32)
 ;; return a > b ? a : b
 (select
   (get_local $a)
   (get_local $b)
   (i32.gt_s (get_local $a) (get_local $b))
 )
)

or
(func (export "f") (param $a i32) (param $b i32) (result i32)
 get_local 0
 get_local 1
 get_local 0
 get_local 1
 i32.gt_s
 select
)

instruction.set_global

name::
* cpt.Wasm'set_global,
* cpt.Wasm-instruction.0x24-set_global,
* cpt.Wasm-instruction.set_global-0x24,

instruction.set_local

description::
· set the-value of the-stack on a-local.

name::
* cpt.Wasm'set_local,
* cpt.Wasm-instruction.0x20-set_local,
* cpt.Wasm-instruction.set_local-0x20,

example::
(func (export "f") (param (;0;) i32) (result i32)
 (local (;1;) i32)
 i32.const 7
 set_local 1
 get_local 1 ;;no get_local, compile-error
)

instruction.store

name::
* cpt.Wasm'store-memory-instruction,
* cpt.Wasm-instruction.store-memory,

instruction.tee_local

description::
· set the-value of the-stack on a-local AND return it.

name::
* cpt.Wasm'tee_local,
* cpt.Wasm-instruction.0x22-tee_local,
* cpt.Wasm-instruction.tee_local-0x22,

example::
(func (export "f") (param (;0;) i32) (result i32)
 (local (;1;) i32)
 i32.const 7
 tee_local 1
)

instruction.BASIC

name::
* cpt.Wasm-instruction.basic,

specific::
* No-Op
* Drop
* Constant
* Get Local
* Set Local
* Tee Local
* Get Global
* Set Global
* Select
* Call
* Indirect Call,

instruction.NUMERIC

description::
·

name::
* cpt.Wasm-instruction.numeric,

specific::
* i32.clz (0x67),
* i32.ctz (0x68),
* i32.popcnt (0x69),
* i32.add (0x6a),
* i32.sub (0x6b),
* i32.mul (0x6c),
* i32.div_s (0x6d),
* i32.div_u (0x6e),
* i32.rem_s (0x6f),
* i32.rem_u (0x70),
* i32.and (0x71),
* i32.or (0x72),
* i32.xor (0x73),
* i32.shl (0x74),
* i32.shr_s (0x75),
* i32.shr_u (0x76),
* i32.rotl (0x77),
* i32.rotr (0x78),
* i64.clz (0x79),
* i64.ctz (0x7a),
* i64.popcnt (0x7b),
* i64.add (0x7c),
* i64.sub (0x7d),
* i64.mul (0x7e),
* i64.div_s (0x7f),
* i64.div_u (0x80),
* i64.rem_s (0x81),
* i64.rem_u (0x82),
* i64.and (0x83),
* i64.or (0x84),
* i64.xor (0x85),
* i64.shl (0x86),
* i64.shr_s (0x87),
* i64.shr_u (0x88),
* i64.rotl (0x89),
* i64.rotr (0x8a),
* f32.abs (0x8b),
* f32.neg (0x8c),
* f32.ceil (0x8d),
* f32.floor (0x8e),
* f32.trunc (0x8f),
* f32.nearest (0x90),
* f32.sqrt (0x91),
* f32.add (0x92),
* f32.sub (0x93),
* f32.mul (0x94),
* f32.div (0x95),
* f32.min (0x96),
* f32.max (0x97),
* f32.copysign (0x98),
* f64.abs (0x99),
* f64.neg (0x9a),
* f64.ceil (0x9b),
* f64.floor (0x9c),
* f64.trunc (0x9d),
* f64.nearest (0x9e),
* f64.sqrt (0x9f),
* f64.add (0xa0),
* f64.sub (0xa1),
* f64.mul (0xa2),
* f64.div (0xa3),
* f64.min (0xa4),
* f64.max (0xa5),
* f64.copysign (0xa6),

instruction.PARAMETRIC

description::
· instructions in this group can-operate on operands of any value-type.
[https://webassembly.github.io/spec/core/syntax/instructions.html#parametric-instructions {1-0.2018-03-22}]

name::
* cpt.Wasm-instruction.parametric,

specific::
* drop,
* select-instruction,

instruction.VARIABLE

description::
· variable-instructions are-concerned with the-access to local or global variables.
· these instructions get or set the-values of variables, respectively.
· the-tee_local-instruction is like set_local but also returns its argument.

name::
* cpt.Wasm'variable-instruction,
* cpt.Wasm-instruction.variable,

specific::
* get_global,
* get_local,
* set_global,
* set_local,
* tee_local,

instruction.MEMORY

description::
· instructions related to memory.

name::
* cpt.Wasm'memory-instruction,
* cpt.Wasm-instruction.memory,

memarg of memory-instruction

description::
· memarg ::= {offset u32, align u32}
[https://webassembly.github.io/spec/core/syntax/instructions.html#memory-instructions {1-0.2018-03-22}]

name::
* cpt.Wasm'memarg,
* cpt.Wasm-memory-instruction'memarg,

specific::
* current_memory,
* grow_memory,
* load,
* store,

instruction.EXPRESSION

description::
· expression is a sequence of instructions terminated by an-end-marker.
[https://webassembly.github.io/spec/core/syntax/instructions.html#expressions {1-0.2018-03-22}]

name::
* cpt.Wasm'expression-instruction,
* cpt.Wasm-instruction.expression,

expression.BINARY

description::
· expressions are-encoded by their instruction sequence terminated with an explicit 0x0B opcode for end.
- expr ::= (in:instr)∗ 0x0B ⇒ in∗ end
[https://webassembly.github.io/spec/core/binary/instructions.html#expressions {1-0.2018-03-28}]

name::
* cpt.Wasm-expression.binary,

expression.TEXT

description::
· expressions are-written as instruction sequences.
· no explicit ‘end’ keyword is-included, since they only occur in bracketed positions.
- expr ::= (in:instr)∗ ⇒ in∗ end
{https://webassembly.github.io/spec/core/text/instructions.html#expressions {1-0.2018-03-28}}

name::
* cpt.Wasm-expression.text,

instruction.TYPE

name::
* cpt.Wasm'type-signature,
* cpt.Wasm-instruction.type,

whole-chain::
* type-section,

example::
;;text-format
(type (;0;) (func (param i32 i32) (result i32)))
;;binary-format
; type 0
60 ; func
02 ; num params
7f ; i32
7f ; i32
01 ; num results
7f ; i32

instruction.EXPORT

description::
· the-exports-component of a-module defines a-set of exports that become accessible to the-host-environment once the-module has-been-instantiated.
- export ::= {name name,desc exportdesc}
- exportdesc ::= func funcidx
  | table tableidx
  | mem memidx
  | global globalidx

· each export is-labeled by a unique name.
· exportable definitions are functions, tables, memories, and globals, which are-referenced through a respective descriptor.
· note: in the current version of WebAssembly, only immutable globals may-be-exported.
[https://webassembly.github.io/spec/core/syntax/modules.html#exports {1-0.2018-03-28}]

name::
* cpt.Wasm'export-instruction,
* cpt.Wasm-export,
* cpt.Wasm-instruction.export,

whole-chain::
* export-section,

export.BINARY

description::
· the-export-section has the-id 7.
· it decodes into a-vector of exports that represent the-exports-component of a-module.
- exportsec ::= ex∗:section7 (vec(export)) ⇒ ex∗
- export ::= nm:name d:exportdesc ⇒ {name nm,desc d}
- exportdesc ::= 0x00 x:funcidx ⇒ func x
  | 0x01 x:tableidx ⇒ table x
  | 0x02 x:memidx ⇒ mem x
  | 0x03 x:globalidx ⇒ global x

name::
* cpt.Wasm-export.binary,

example::
02; string length
6632 ; 'f2' export name
00 ; export kind
01 ; export func index

or in text-format
(export "f2" (func 1)))

export.TEXT

description::
· the-syntax for exports mirrors their abstract-syntax directly.
- exportI ::= ‘(’ ‘export’ nm:name d:exportdescI ‘)’ ⇒ {name nm,desc d}
- exportdescI ::= ‘(’ ‘func’ x:funcidxI ‘)’ ⇒ func x
  | ‘(’ ‘table’ x:tableidxI ‘)’ ⇒ table x
  | ‘(’ ‘memory’ x:memidxI ‘)’ ⇒mem x
  | ‘(’ ‘global’ x:globalidxI ‘)’ ⇒ global x

· abbreviations: as an-abbreviation, exports may also be-specified inline with function, table, memory, or global definitions; see the respective sections.

name::
* cpt.Wasm-export.text,

example::
(func $fAdd … )
(export "fAdd" (func $fAdd))

or
(func (export "fAdd") ...)
===
//export global
(global (;1;) i32 (i32.const 20))
(export "CONSTA" (global 1))

instruction.IMPORT

name::
* cpt.Wasm'import-instruction,
* cpt.Wasm-import,
* cpt.Wasm-instruction.import,

whole-chain::
* import-section,

whole-chain::
* import-section,

import.TEXT

example::
//imports the-fImported javascript-function and name it fImp.
//wat file:
(func $fImp (import "oJs" "fImported") (param i32))
//html file:
var oImport = {oJs: {fImported: arg => console.log(arg)} };
WebAssembly.instantiateStreaming(fetch('simple.wasm'), oImport)

===
//the-above with import-sentence
//wat file:
(import "oJs" "fImported" (func $fImp (param i32)))

algo-section of Wasm

description::
· section is a-sequence of similar instructions.

name::
* cpt.Wasm'section,
* cpt.Wasm-section,

instruction of section (link)

WHOLE of section

whole-chain::
* module,

section.SPECIFIC

name::
* cpt.Wasm-section.specific,

specific::
* text-section,
* binary-section,
===
* code-section,
* custom-section,
* data-section,
* element-section,
* export-section,
* function-section,
* global-section,
* import-section,
* known-section,
* linear-memory--section,
* start-section,
* table-section,
* type-section,

section.TEXT

name::
* cpt.Wasm'text-section,
* cpt.Wasm-section.text,

section.BINARY

description::
· a-module consists of a-header and a sequence of sections.
· a-section consists of a varuint7 opcode followed by a byte-array payload.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#module-contents]

name::
* cpt.Wasm'binary-section,
* cpt.Wasm-binary-section,
* cpt.Wasm-section.binary,

opcode of binary-section

description::
· the-opcode is required to either indicate a-known-section, or be 0x00, indicating a-custom-section.

name::
* cpt.Wasm'opcode-of-section,
* cpt.Wasm-section'id,
* cpt.Wasm-section'opcode,

size of binary-section

description::
· each section consists of
- a one-byte section-id,
- the-u32-size of the-contents, in bytes,
- the actual contents, whose structure is depended on the section-id.
[https://webassembly.github.io/spec/core/binary/modules.html#sections {1-0.2018-03-22}]

name::
* cpt.Wasm-section'size,

content of binary-section

description::
· each section consists of
- a one-byte section-id,
- the-u32-size of the-contents, in bytes,
- the actual contents, whose structure is depended on the section-id.
[https://webassembly.github.io/spec/core/binary/modules.html#sections {1-0.2018-03-22}]

name::
* cpt.Wasm-section'content,
* cpt.Wasm-section'payload,

section.KNOWN

name::
* cpt.Wasm-known-section,
* cpt.Wasm-section.known,

specific::
There are several known sections:
01. type-section,
02. import-section,
03. function-section,
04. table-section,
05. linear-memory--section,
06. global-section,
07. export-section,
08. start-section,
09. element-section,
10. code-section,
11. data-section,

section.01-TYPE

description::
· for now, the-type-section contains function-types.
===
· opcode: 0x01.
· it consists of a-list of type-signatures, today of function-signatures.
· it includes signatures of imported-functions.
· the-position in this list, define the unique index of the-type inside the-module.
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm'types-component,
* cpt.Wasm-section.01-type,
* cpt.Wasm-section.type,
* cpt.Wasm-type-section,

example::
;;text-format
(type (;0;) (func (param i32 i32) (result i32)))
(type (;1;) (func (param i32) (result i32)))

;;or binary
; section "Type" (1)
01 ; section code
00 ; section size (guess)
02 ; num types
; type 0
60 ; func
02 ; num params
7f ; i32
7f ; i32
01 ; num results
7f ; i32
; type 1
60 ; func
01 ; num params
7f ; i32
01 ; num results
7f ; i32

type-section.TEXT

name::
* cpt.Wasm'section.type.text,
* cpt.Wasm'text-type-section,
* cpt.Wasm'type-section.text,
* cpt.Wasm-section.type.text,

example::
;;text-format
(type (;0;) (func (param i32 i32) (result i32)))
(type (;1;) (func (param i32) (result i32)))

type-section.BINARY

name::
* cpt.Wasm'binary-type-section,
* cpt.Wasm'section.type.binary,
* cpt.Wasm'type-section.binary,
* cpt.Wasm-section.type.binary,

example::
; section "Type" (1)
01 ; section code
00 ; section size (guess)
02 ; num types
; type 0
60 ; func
02 ; num params
7f ; i32
7f ; i32
01 ; num results
7f ; i32
; type 1
60 ; func
01 ; num params
7f ; i32
01 ; num results
7f ; i32

section.02-IMPORT

description::
· opcode: 0x02.
· it consists of an-array of imports.
· the-import-section declares any external dependencies by listing module name, field name and type for each function, value or data required:
("dumb-math", "quadruple", (func_type 1)) // func #0
("dumb-math", "pi", (global_type i64 immutable))

· it's up to the-host-system (e.g. web browser) to resolve these imports and this is how runtime-dynamic linking is made possible in Wasm, and is also the foreign-function interface for interacting with non-Wasm-functions.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#import-section]
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm'imports-component,
* cpt.Wasm-import-section,
* cpt.Wasm-section.02-import,
* cpt.Wasm-section.import,

example::
;; text-format
(import "oJs" "fImport1" (func (;0;) (type 0)))
(import "oJs" "fImport2" (func (;1;) (type 0)))

;; binary-format
; section "Import" (2)
02 ; section code
00 ; section size (guess)
02 ; num imports
; import header 0
03 ; string length
6f4a 73 ; oJs import module name
08 ; string length
6649 6d70 6f72 7431 ; fImport1 import field name
00 ; import kind
00 ; import signature index
; import header 1
03 ; string length
6f4a 73 ; oJs import module name
08 ; string length
6649 6d70 6f72 7432 ; fImport2 import field name
00 ; import kind
00 ; import signature index

import-section.TEXT

name::
* cpt.Wasm'import-section.text,
* cpt.Wasm'section.import.text,
* cpt.Wasm'text-import-section,
* cpt.Wasm-section.import.text,

example::
(import "oJs" "fImport1" (func (;0;) (type 0)))
(import "oJs" "fImport2" (func (;1;) (type 0)))

import-section.BINARY

name::
* cpt.Wasm'binary-import-section,
* cpt.Wasm'import-section.binary,
* cpt.Wasm'section.import.binary,
* cpt.Wasm-section.import.binary,

example::
; section "Import" (2)
02 ; section code
00 ; section size (guess)
02 ; num imports
; import header 0
03 ; string length
6f4a 73 ; oJs import module name
08 ; string length
6649 6d70 6f72 7431 ; fImport1 import field name
00 ; import kind
00 ; import signature index
; import header 1
03 ; string length
6f4a 73 ; oJs import module name
08 ; string length
6649 6d70 6f72 7432 ; fImport2 import field name
00 ; import kind
00 ; import signature index

section.03-FUNCTION

description::
· the-funcs-component of a-module defines a-vector of functions with the following structure:
· func ::= {type typeidx, locals vec(valtype), body expr}
· the-type of a-function declares its signature by reference to a-type defined in the-module.
· the-parameters of the-function are-referenced through 0-based local indices in the-function's-body.

· the-locals declare a-vector of mutable local-variables and their types.
· these variables are-referenced through local indices in the-function's-body.
· the-index of the first local is the smallest index not referencing a parameter.

· the-body is an instruction sequence that upon termination must-produce a-stack matching the-function-type's result-type.

· functions are-referenced through function indices, starting with the smallest index not referencing a-function-import.
[https://webassembly.github.io/spec/core/syntax/modules.html#syntax-func {1-0.2018-04-05}]
===
· opcode: 0x03.
· it consists of an-array of function-declarations.
· a-function-declaration consists of: an-index in the-type-section of the-signature-of-the-function.
· the-function-declarations directly correspond to elements in the-code-section array.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#function-section]

name::
* cpt.Wasm'funcs-component,
* cpt.Wasm-function-section,
* cpt.Wasm-section.03-function,
* cpt.Wasm-section.function,

whole-chain::
* module,

function-section.TEXT

description::
· the-text-function-section contains AND the-body[a] of functions, which[a] in the-binary-format is-included in the-binary-code-section.

name::
* cpt.Wasm'function-section.text,
* cpt.Wasm'section.function.text,
* cpt.Wasm'text-function-section,
* cpt.Wasm-section.function.text,

example::
(func $fAddTwo (param i32 i32) (result i32) get_local 0 get_local 1 i32.add)

function-section.BINARY

name::
* cpt.Wasm'function-section.binary,
* cpt.Wasm'section.function.binary,
* cpt.Wasm'binary-function-section,
* cpt.Wasm-section.function.binary,

example::
; section "Function" (3)
03 ; section code
00 ; section size (guess)
01 ; num functions
00 ; function 0 type-index

section.04-TABLE

description::
· opcode: 0x04.
· it consists of an-array of table-descriptions|definitions.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#table-section]

name::
* cpt.Wasm'table-section,
* cpt.Wasm-table-section,
* cpt.Wasm-section.04-table,
* cpt.Wasm-section.table,

table-section.TEXT

description::
· the-text-table-section includes and the-table initializations, which in the-binary-format is-included in the-element-section.

name::
* cpt.Wasm'table-section.text,
* cpt.Wasm'section.table.text,
* cpt.Wasm'text-table-section,
* cpt.Wasm-section.table.text,

example::
(table (export "tbl") anyfunc (elem $f42))

table-section.BINARY

name::
* cpt.Wasm'table-section.binary,
* cpt.Wasm'section.table.binary,
* cpt.Wasm'binary-table-section,
* cpt.Wasm-section.table.binary,

example::
; section "Table" (4)
0000013: 04 ; section code
0000014: 00 ; section size (guess)
0000015: 01 ; num tables
; table 0
0000016: 70 ; anyfunc
0000017: 01 ; limits: flags
0000018: 01 ; limits: initial
0000019: 01 ; limits: max
0000014: 05 ; FIXUP section size

section.05-LINEAR-MEMORY

description::
· opcode: 0x05.
· it consists of an-array of linear-memory-descriptions.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#linear-memory-section]
===
· the-memory-section defines the optional memory of the-module by defining its initial size and optionally how large it is-expected to expand.
· the-data-section can-be-used to initialize the-memory.
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm'mems-component,
* cpt.Wasm-memory-section,
* cpt.Wasm-section.05-linear-memory,
* cpt.Wasm-section.linear-memory,
* cpt.Wasm-section.memory,

memory-section.TEXT

name::
* cpt.Wasm'memory-section.text,
* cpt.Wasm'section.memory.text,
* cpt.Wasm'text-memory-section,
* cpt.Wasm-section.memory.text,

example::
(memory 1)
or
(memory (export "mem") 1)

memory-section.BINARY

name::
* cpt.Wasm'binary-memory-section,
* cpt.Wasm'memory-section.binary,
* cpt.Wasm'section.memory.binary,
* cpt.Wasm-section.memory.binary,

example::
; memory-section
05 ; section code
03 ; section size
01 ; num memories
00 ; limits: flags
01 ; limits: initial

section.06-GLOBAL

description::
· Opcode: 0x06.
· it consists of an-array of global-declarations.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#global-section]

name::
* cpt.Wasm'globals-component,
* cpt.Wasm-global-section,
* cpt.Wasm-section.06-global,
* cpt.Wasm-section.global,

example::
;; text-format
(global (;0;) (mut i32) (i32.const 100))
(global (;1;) i32 (i32.const 200))

;; binary-format
; section "Global" (6)
06 ; section code
00 ; section size (guess)
02 ; num globals
7f ; i32
01 ; global mutability
41 ; i32.const
e400 ; i32 literal
0b ; end
7f ; i32
00 ; global mutability
41 ; i32.const
c801 ; i32 literal
0b ; end

global-section.TEXT

name::
* cpt.Wasm'text-global-section,
* cpt.Wasm'global-section.text,
* cpt.Wasm'section.global.text,
* cpt.Wasm-section.global.text,

example::
(global (;0;) (mut i32) (i32.const 100))
(global (;1;) i32 (i32.const 200))

global-section.BINARY

name::
* cpt.Wasm'binary-global-section,
* cpt.Wasm'global-section.binary,
* cpt.Wasm'section.global.binary,
* cpt.Wasm-section.global.binary,

example::
; section "Global" (6)
06 ; section code
00 ; section size (guess)
02 ; num globals
7f ; i32
01 ; global mutability
41 ; i32.const
e400 ; i32 literal
0b ; end
7f ; i32
00 ; global mutability
41 ; i32.const
c801 ; i32 literal
0b ; end

section.07-EXPORT

description::
· opcode: 0x07.
· it consists of an-array of exports.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#export-section]
===
· the-export-section declares any parts of the-module that can-be-accessed by the-host-environment, not-including the special start-function, which we will get to in a just a few sentences.
("half" (func 1))
· the-above would-export function-1 as “half”.
· if we look at the-function-section above, we can-see that func #1’s type is func_type #1, so the-host-environment will see this as:
function half(arg0 :int64) :int64
· in addition to functions, modules can also export tables, memory-segments and global-variables to the-outside-world.
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm'exports-component,
* cpt.Wasm-export-section,
* cpt.Wasm-section.07-export,
* cpt.Wasm-section.export,

example::
;;text-format
(export "f" (func 0))
(export "f2" (func 1)))

;; binary-format
; section "Export" (7)
07 ; section code
00 ; section size (guess)
02 ; num exports
;; export f
01 ; string length
66 ; 'f' export name
00 ; export kind
00 ; export func index
;; export f2
02; string length
6632 ; 'f2' export name
00 ; export kind
01 ; export func index

export-section.TEXT

name::
* cpt.Wasm'text-export-section,
* cpt.Wasm'export-section.text,
* cpt.Wasm'section.export.text,
* cpt.Wasm-section.export.text,

example::
(export "f" (func 0))
(export "f2" (func 1)))

export-section.BINARY

name::
* cpt.Wasm'binary-export-section,
* cpt.Wasm'export-section.binary,
* cpt.Wasm'section.export.binary,
* cpt.Wasm-section.export.binary,

example::
; section "Export" (7)
07 ; section code
00 ; section size (guess)
02 ; num exports
;; export f
01 ; string length
66 ; 'f' export name
00 ; export kind
00 ; export func index
;; export f2
02; string length
6632 ; 'f2' export name
00 ; export kind
01 ; export func index

section.08-START

description::
· opcode: 0x08.
· it consists of a-varuint32-index into the-function-index-space. This is-used by Instance-Execution.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#start-section]
===
· the-start-section has the-id 8.
· it decodes into an optional start-function that represents the-start-component of a-module.
- startsec ::= st?:section8(start) ⇒st?
- start ::= x:funcidx ⇒ {func x}
[https://webassembly.github.io/spec/core/binary/modules.html#start-section {1-0.2018-03-28}]
===
· the-start-section designates a-function-index for a-function to be-called when the-module is loading and is the-mechanism that can-be-used to make a-module an-executable-program, or used to dynamically initialize globals or memory of a-module.
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm'start-component,
* cpt.Wasm-start-section,
* cpt.Wasm-section.08-start,
* cpt.Wasm-section.start,

example::
;; text-format
(func (;2;) (type 0) call 0)
(start 2)

;; binary-format
; section "Start" (8)
08 ; section code
00 ; section size (guess)
02 ; start func index

start-function of start-section (link)

start-section.TEXT

name::
* cpt.Wasm'text-start-section,
* cpt.Wasm'start-section.text,
* cpt.Wasm'section.start.text,
* cpt.Wasm-section.start.text,

example::
(start 2)

start-section.BINARY

name::
* cpt.Wasm'binary-start-section,
* cpt.Wasm'start-section.binary,
* cpt.Wasm'section.start.binary,
* cpt.Wasm-section.start.binary,

example::
; section "Start" (8)
08 ; section code
00 ; section size (guess)
02 ; start func index

section.09-ELEMENT

description::
· opcode: 0x09.
· it consists of an-array of table-initializers.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#element-section]
===
· the-element-section allows a-module to initialize the-contents of a-table imported from the-outside or defined in the-table-section.
[https://rsms.me/wasm-intro]
===
· the initial contents of a-table is-uninitialized.
· the-elem-component of a-module defines a-vector of element-segments that initialize a-subrange of a-table at a given offset from a static vector of elements.
- elem::={table tableidx,offset expr,init vec(funcidx)}
· the-offset is-given by a constant expression.
· note: in the current version of WebAssembly, at most one table is-allowed in a-module. Consequently, the only valid tableidx is 0.
[https://webassembly.github.io/spec/core/syntax/modules.html#syntax-elem {1-0.2018-03-28}]

name::
* cpt.Wasm'elem-component,
* cpt.Wasm-element-section,
* cpt.Wasm-section.09-element,
* cpt.Wasm-section.element,

element-section.TEXT

description::
· in text-Wasm, the-element-section is-included in the-table-section.

name::
* cpt.Wasm'text-element-section,
* cpt.Wasm'element-section.text,
* cpt.Wasm'section.element.text,
* cpt.Wasm-section.element.text,

example::
(table (export "tbl") anyfunc (elem $f42))

element-section.BINARY

name::
* cpt.Wasm'binary-element-section,
* cpt.Wasm'element-section.binary,
* cpt.Wasm'section.element.binary,
* cpt.Wasm-section.element.binary,

example::
; section "Elem" (9)
0000023: 09 ; section code
0000024: 00 ; section size (guess)
0000025: 01 ; num elem segments
; elem segment header 0
0000026: 00 ; table index
0000027: 41 ; i32.const
0000028: 00 ; i32 literal
0000029: 0b ; end
000002a: 01 ; num function indices
000002b: 00 ; function index
0000024: 07 ; FIXUP section size

section.10-CODE

description::
· opcode: 0x0a.
· it consists of an-array of function-bodies.
===
· the-code-section is probably the-bulk of most WebAssembly-modules as it defines all code for all functions in the-module.
· the-function-bodies are-defined in the same order as their respective function-indexes in the-function-section, not including imports of course.
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm-code-section,
* cpt.Wasm-section.10-code,
* cpt.Wasm-section.code,

code-section.TEXT

description::
· in text-Wasm, the-code-section (the-bodies of functions) is-included in the-function-section.

name::
* cpt.Wasm'text-code-section,
* cpt.Wasm'code-section.text,
* cpt.Wasm'section.code.text,
* cpt.Wasm-section.code.text,

code-section.BINARY

name::
* cpt.Wasm'binary-code-section,
* cpt.Wasm'code-section.binary,
* cpt.Wasm'section.code.binary,
* cpt.Wasm-section.code.binary,

example::
;; (func (result i32) (i32.const 59))
; section "Code" (10)
0a ; section code
06 ; section size (guess)
01 ; num functions
; function body 0
04 ; func body size (guess)
00 ; local decl count
41 ; i32.const
3b ; i32 literal
0b ; end

section.11-DATA

description::
· opcode: 0x0b.
· it consists of an-array of data-initializers.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#data-section]
===
· the initial contents of a-memory are zero bytes.
· the-data-component of a-module defines a-vector of data-segments that initialize a range of memory at a given offset with a static vector of bytes.
- data ::= {data memidx,offset expr,init vec(byte)}
· the-offset is-given by a constant expression.
· note: in the current version of WebAssembly, at most one memory is-allowed in a-module. Consequently, the only valid memidx is 0.
[https://webassembly.github.io/spec/core/syntax/modules.html#data-segments {1-0.2018-03-28}]

name::
* cpt.Wasm'data-component,
* cpt.Wasm-data-section,
* cpt.Wasm-section.11-data,
* cpt.Wasm-section.data,

data-section.TEXT

name::
* cpt.Wasm'text-data-section,
* cpt.Wasm'text-section.binary,
* cpt.Wasm'section.text.binary,
* cpt.Wasm-section.text.binary,

example::
(data (i32.const 0) "Hello World")

data-section.BINARY

name::
* cpt.Wasm'binary-data-section,
* cpt.Wasm'data-section.binary,
* cpt.Wasm'section.data.binary,
* cpt.Wasm-section.data.binary,

example::
; data-section
0B ; section code
11 ; section size
01 ; num data segments
00 ; memory index
41 ; i32.const
00 ; i32 value
0B ; end
0B ; data segment size
48 65 6C 6C 6F 20 57 6F 72 6C 64 ; Hello World

section.0-CUSTOM

description::
· opcode: 0x00.
· this appendix defines dedicated custom-sections for WebAssembly’s binary format.
· 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-name-section.
[https://webassembly.github.io/spec/core/appendix/custom.html#custom-sections {1-0.2018-03-28}]

name::
* cpt.Wasm-custom-section,
* cpt.Wasm-section.0-custom,
* cpt.Wasm-section.custom,

algo-module of Wasm

description::
· module is the outermost construction.
· a-module consists of a sequence of sections.
===
· WebAssembly-programs are-organized into modules, which are the-unit of deployment, loading, and compilation.
· a-module collects definitions for types, functions, tables, memories, and globals.
· in addition, it can-declare imports and exports and provide initialization logic in the-form of data and element segments or a-start-function.
- module ::= {
 types vec(functype),
 funcs vec(func),
 tables vec(table),
 mems vec(mem),
 globals vec(global),
 elem vec(elem),
 data vec(data),
 start start?,
 imports vec(import),
 exports vec(export)
}

· each of the-vectors – and thus the entire module – may-be empty.
[https://webassembly.github.io/spec/core/syntax/modules.html {1-0.2018-04-05}]

name::
* cpt.Wasm'module,
* cpt.Wasm-module,

section of module (link)

module.SPECIFIC

name::
* cpt.Wasm-module.specific,

specific::
* text-module,
* binary-module,

module.BINARY

description::
· a-binary-module consists of a-header followed by a sequence of binary-sections.

name::
* cpt.Wasm'binary-module,
* cpt.Wasm-binary-module,
* cpt.Wasm-module.binary,

header of binary-module

description::
· the-header is the first part of a-module.
· the-header consists of the-magic_cookie and the-version parts.

name::
* cpt.Wasm'header-of-module,
* cpt.Wasm-binary-module'header,

magic_cookie of header

description::
· magic_cookie is-required to be 0x6d736100 (the-string "asm") which identifies a-file as a-WebAssembly-module.
· its size is 4-bytes.

name::
* cpt.Wasm'magic_cookie-of-header,

version of header

description::
· version is a-32-bit-unsigned-integer which denotes the-WebAssembly-version.

name::
* cpt.Wasm'version-of-header,

module.TEXT

description::
· a-module consists of a sequence of text-sections.

name::
* cpt.Wasm'text-module,
* cpt.Wasm-module.text,
* cpt.Wasm-text-module,

algo.SPECIFIC

name::
* cpt.Wasm-algo.specific,

specific::
* text-algo,
* binary-algo,
===
* program,
* library,

algo.PROGRAM

description::
· a-Wasm-program is one or more modules working together.
[hmnSgm.2018-05-19]

name::
* cpt.program.Wasm,
* cpt.Wasm'program,
* cpt.Wasm-program,

program.SPECIFIC

specific::
* Wasm-binary-program,
* Wasm-text-program,
===
* examples that accompany the-MDN-WebAssembly-documentation: https://github.com/mdn/webassembly-examples
- demo: https://mdn.github.io/webassembly-examples/js-api-examples/,
* Hello World: https://github.com/tgsstdio/Hello-WebAssembly,

program.BINARY

description::
· Wasm-binary-program is a-Wasm-program written in binary-format.

name::
* cpt.Wasm'binary-program,
* cpt.Wasm-program.binary,

WHOLE of Wasm-program

whole-chain::
* browser-javascript-program,

program.TEXT

description::
· a-text-program is a-Wasm-program in text-format.
· it must-be-translated into binary-program to be-executed by the-runtime-environment.
[hmnSgm.2018-04-08]

name::
* cpt.Wasm'text-program,
* cpt.Wasm-program.text,
* cpt.Wasm-program.wat,

program.simple-demo

description::
· simple-demo-program.
· creates and exports a-Wasm-function that creates and outputs the-value 59.
· from javascript we execute that function.

name::
* cpt.Wasm-program.demo.simple,
* cpt.Wasm-program.simple-demo,

wat-file::
(module
 (func (export "f59") (result i32) (i32.const 59))
)

wasm-file::
// wat2wasm simple2.wat -o simple2.wasm
// a-sequence of bytes, in hex-format here.
00 61 73 6d ; WASM_BINARY_MAGIC
01 00 00 00 ; WASM_BINARY_VERSION
; section "Type" (1)
01 ; section code
05 ; section size
01 ; num types
60 ; func
00 ; num params
01 ; num results
7f ; i32
; section "Function" (3)
03 ; section code
02 ; section size (guess)
01 ; num functions
00 ; function 0 signature index
; section "Export" (7)
07 ; section code
07 ; section size (guess)
01 ; num exports
03 ; string length
66 35 39 ; f59 export name
00 ; export kind
00 ; export func index
; section "Code" (10)
0a ; section code
06 ; section size (guess)
01 ; num functions
; function body 0
04 ; func body size (guess)
00 ; local decl count
41 ; i32.const
3b ; i32 literal
0b ; end
; section "name"
00 ; section code
0a ; section size (guess)
04 ; string length
6e 61 6d 65 ; name custom section name
02 ; local name type
03 ; subsection size (guess)
01 ; num functions
00 ; function index
00 ; num locals

browser-file::
· we can-run the-program in a-browser-environment.
· we open this file in a-browser and hit F12 to see the-console.
<!doctype html>
<html>
<body>
 <script>
   WebAssembly.instantiateStreaming(fetch('simple2.wasm'))
   .then(oModule => console.log(oModule.instance.exports.f59()))
 </script>
</body>
</html>

Node.js-file::
//Node.js 8.11.1
· we ALSO can-run the-Wasm-program in a-Node.js-environment.
· we need this Node.js-program (simple2.js) and to run the-command: node simple2.js.
const { readFileSync } = require("fs");

const fRun = async () => {
 const oModule = await WebAssembly.compile(readFileSync("simple2.wasm"));
 const oModuleInst = await WebAssembly.instantiate(oModule);
 console.log(oModuleInst.exports.f59());
};

fRun();

[http://blog.scottlogic.com/2018/04/26/webassembly-by-hand.html]

demo::
· browser-demo.

program.table-demo

description::
· creates a-wasm-function that outputs 42.
· creates and exports a-table with element the previous function.
· then, from javascript get the-table, calls its element and also displays the-length of table's elements.

name::
* cpt.Wasm-program.demo.table,
* cpt.Wasm-program.table-demo,

wat-program::
(module
 (func $f42 (result i32) (i32.const 42))
 (table (export "tbl") anyfunc (elem $f42))
)

wasm-program::
0000000: 0061 736d ; WASM_BINARY_MAGIC
0000004: 0100 0000 ; WASM_BINARY_VERSION
; section "Type" (1)
0000008: 01 ; section code
0000009: 00 ; section size (guess)
000000a: 01 ; num types
; type 0
000000b: 60 ; func
000000c: 00 ; num params
000000d: 01 ; num results
000000e: 7f ; i32
0000009: 05 ; FIXUP section size
; section "Function" (3)
000000f: 03 ; section code
0000010: 00 ; section size (guess)
0000011: 01 ; num functions
0000012: 00 ; function 0 signature index
0000010: 02 ; FIXUP section size
; section "Table" (4)
0000013: 04 ; section code
0000014: 00 ; section size (guess)
0000015: 01 ; num tables
; table 0
0000016: 70 ; anyfunc
0000017: 01 ; limits: flags
0000018: 01 ; limits: initial
0000019: 01 ; limits: max
0000014: 05 ; FIXUP section size
; section "Export" (7)
000001a: 07 ; section code
000001b: 00 ; section size (guess)
000001c: 01 ; num exports
000001d: 03 ; string length
000001e: 7462 6c ; tbl export name
0000021: 01 ; export kind
0000022: 00 ; export table index
000001b: 07 ; FIXUP section size
; section "Elem" (9)
0000023: 09 ; section code
0000024: 00 ; section size (guess)
0000025: 01 ; num elem segments
; elem segment header 0
0000026: 00 ; table index
0000027: 41 ; i32.const
0000028: 00 ; i32 literal
0000029: 0b ; end
000002a: 01 ; num function indices
000002b: 00 ; function index
0000024: 07 ; FIXUP section size
; section "Code" (10)
000002c: 0a ; section code
000002d: 00 ; section size (guess)
000002e: 01 ; num functions
; function body 0
000002f: 00 ; func body size (guess)
0000030: 00 ; local decl count
0000031: 41 ; i32.const
0000032: 2a ; i32 literal
0000033: 0b ; end
000002f: 04 ; FIXUP func body size
000002d: 06 ; FIXUP section size
; section "name"
0000034: 00 ; section code
0000035: 00 ; section size (guess)
0000036: 04 ; string length
0000037: 6e61 6d65 ; name custom section name
000003b: 01 ; function name type
000003c: 00 ; subsection size (guess)
000003d: 01 ; num functions
000003e: 00 ; function index
000003f: 03 ; string length
0000040: 6634 32 ; f42 func name 0
000003c: 06 ; FIXUP subsection size
0000043: 02 ; local name type
0000044: 00 ; subsection size (guess)
0000045: 01 ; num functions
0000046: 00 ; function index
0000047: 00 ; num locals
0000044: 03 ; FIXUP subsection size
0000035: 12 ; FIXUP section size

html-program::
<html>
<body>
 <h1>table-demo</h1>
 <p>· hit F12 to see console's output.
 <script>
   WebAssembly.instantiateStreaming(fetch('table3.wasm'))
     var oTbl = oModule.instance.exports.tbl;
     console.log(oTbl.get(0)()); // 42
     console.log(oTbl.length); // 1
   })
 </script>
</body>
</html>

demo::
· link.

program.memory-demo

description::
· creates a-wasm-memory and export it.
· at offset 0, of memory puts the-string "Hello World".
· then, from javascript it gets the-memory, creates an-Uint8Array from its buffer, and String.fromCharCode() the-items of the-array.

name::
* cpt.Wasm-program.demo.memory,
* cpt.Wasm-program.memory-demo,

wat-program::
(module
 (memory (export "mem") 1)
 (data (i32.const 0) "Hello World")
)

wasm-program::
// a-sequence of bytes, here in hex
00 61 73 6D ; magic
01 00 00 00 ; version
; memory-section
05 ; section code
03 ; section size
01 ; num memories
00 ; limits: flags
01 ; limits: initial
; export-section
07 ; section code
07 ; section size
01 ; num exports
03 ; string length
6D 65 6D ; mem
02 ; export kind
00 ; export memory index
; data-section
0B ; section code
11 ; section size
01 ; num data segments
00 ; memory index
41 ; i32.const
00 ; i32 value
0B ; end
0B ; data segment size
48 65 6C 6C 6F 20 57 6F 72 6C 64 ; Hello World
; custom-section
00 ; section code
08 ; section size
04 ; string length
6E 61 6D 65 ; name
02 ; local name type
01 ; subsection size
00 ; num functions

html-program::
<html>
<body>
 <h1>Wasm-memory demo</h1>
 <p>· hit F12 to see console's output.
 <script>
   WebAssembly.instantiateStreaming(fetch('memory2.wasm'))
   .then(oModule => {
     function fUint8_to_string(aIn) {
       let s = "";
       for (let i = 0; i < 11; i++) {
         s += String.fromCharCode(aIn[i]);
       }
       return s;
     }
     let a = new Uint8Array(oModule.instance.exports.mem.buffer);
     console.log(fUint8_to_string(a));
   })
 </script>
</body>
</html>

demo::
· link.

program.simple

description::
· simple program from Mdn-examples.
· imports a-javascript-function that prints on console its argument.
· creates and exports a-Wasm-function that creates the value 42 and calls the imported function that prints 42 on console.

name::
* cpt.Wasm-program.simple,

wat-file::
(module
 (func $fImp (import "oJs" "fImported") (param i32))
 (func (export "fExported")
   i32.const 42
   call $fImp
 )
)

html-file::
<!doctype html>
<html>
<head>
 <meta charset="utf-8">
 <title>Wasm compile() test
</head>
<body>
 <script>
   var oImport = {
     oJs: {fImported: arg => console.log(arg)}
   };
   //case1: with compile()
   fetch('simple.wasm')
   .then(oResponse => oResponse.arrayBuffer())
   .then(bytes => WebAssembly.compile(bytes))
   .then(oModule => WebAssembly.instantiate(oModule, oImport))
   .then(oModuleInst => oModuleInst.exports.fExported());
   //case2: with compileStreaming()
   WebAssembly.compileStreaming(fetch('simple.wasm'))
   .then(oModule => WebAssembly.instantiate(oModule, oImport))
   .then(instance => instance.exports.fExported());
   //case3: with instantiate()
   fetch('simple.wasm')
   .then(oResponse => oResponse.arrayBuffer())
   .then(oArrayBuffer => WebAssembly.instantiate(oArrayBuffer, oImport))
   .then(oModule => oModule.instance.exports.fExported());
   //case4: with instantiateStreaming()
   WebAssembly.instantiateStreaming(fetch('simple.wasm'), oImport)
   .then(oModule => oModule.instance.exports.fExported());
   //case5: with XMLHttpRequest
   oXHR = new XMLHttpRequest();
   oXHR.open('GET', 'simple.wasm');
   oXHR.responseType = 'arraybuffer';
   oXHR.send();
   
   oXHR.onload = function() {
     WebAssembly.instantiate(oXHR.response, oImport))
     .then(oModule => oModule.instance.exports.fExported());
   }
 </script>
</body>
</html>

demo::
* compile-demo,
* compileStreaming-demo,
* instantiate-demo,
* instantiateStreaming-demo,

program.hello-world

description::
· example from spec's WebAssembly JavaScript Interface.
· imports 2 javascript-functions that print on console "hello," the-first and "world!" the-second.
· then, uses the first imported as start-function and exports the second imported.

name::
* cpt.Wasm-program.hello-world,

wat-program::
(module
 (import "oJs" "fImport1" (func $fImp1))
 (import "oJs" "fImport2" (func $fImp2))
 (func $fStart (call $fImp1))
 (start $fStart)
 (func (export "f") (call $fImp2))
)

wasm-program::
· we compile the-wat-program to wasm.
· one method is with an-online-compiler.

html-program::
<html>
<body>
 <h1>hello-world example</h1>
 <p>· example from spec's <a href="https://webassembly.github.io/spec/js-api/index.html">WebAssembly JavaScript Interface</a>
 <p>· hit F12 to see console's output.
 <script>
   var oImport = {oJs: {
     fImport1: () => console.log("hello,"),
     fImport2: () => console.log("world!")
   }};
   WebAssembly.instantiateStreaming(fetch('demo.wasm'), oImport)
   .then(oModule => oModule.instance.exports.f());
 </script>
</body>
</html>

demo::
· link.

program.FACTORIAL

description::
· computes the-factorial of a-number, !4=1*2*3*4=24.

name::
* cpt.factorial-Wasm-program,
* cpt.Wasm-program.factorial,

wat-file::
(module
 (func $factorial (export "f") (param i32) (result i32)
   (if (result i32) (i32.lt_s (get_local 0) (i32.const 1))
     ;; if input < 1, then output 1
     (then (i32.const 1))
     ;; else input * factorial(input-1)
     (else (i32.mul (get_local 0) (call $factorial (i32.sub (get_local 0) (i32.const 1)))))
   )
 )
)

wasm-file::
// wat2wasm factorial.wat -o factorial.wasm

Node.js-file::
//Node.js 8.11.1
//node factorial.js
const { readFileSync } = require("fs");

const fRun = async () => {
 const oModule = await WebAssembly.compile(readFileSync("factorial.wasm"));
 const oModuleInst = await WebAssembly.instantiate(oModule);
 console.log(oModuleInst.exports.f(4)); //24
};

fRun();

algo.LIBRARY

description::
with WebAssembly there’s no difference between a “program” and a “library” — there are only “modules”, each which can tie in and communicate with other modules, and each which can have a “main” function.
[https://rsms.me/wasm-intro]

name::
* cpt.Wasm'library,
* cpt.Wasm-library,

algo.TEXT

description::
· Wasm-text-algo is a-Wasm-algo written with the-Wasm-text-format using S-expressions.

name::
* cpt.Wasm-algo.text,
* cpt.Wasm-text-algo,

algo.BINARY

description::
· Wasm-binary-algo is a-Wasm-algo written with the-Wasm-binary-format.

name::
* cpt.Wasm'binary-algo,
* cpt.Wasm-algo.binary,
* cpt.Wasm-binary-algo,
* cpt.Wasm-bnr-algo,

bnr-algo'file of Wasm

description::
· the-extention of a-Wasm-binary-file is .wasm.

evaluation of Wasm

name::
* cpt.Wasm'evaluation,

relation-to-javascript of Wasm

name::
* cpt.Wasm'relation-to-javascript,

description::
An exciting aspect of WebAssembly is that it wasn’t made to be a substitute for JavaScript but to work alongside it.
At the same time, this combination can provide the performance of typed/compiled languages and the flexibility of JavaScript.
Using the WebAssembly API on JavaScript, you can load modules WASM on JS application and share functionalities between them.
[{2018-04-02} Willian-Martins, https://hackernoon.com/webassembly-the-journey-what-is-wasm-caf9871108aa]
===
WebAssembly is faster than JavaScript in many cases because:
* fetching WebAssembly takes less time because it is more compact than JavaScript, even when compressed.
* decoding WebAssembly takes less time than parsing JavaScript.
* compiling and optimizing takes less time because WebAssembly is closer to machine code than JavaScript and already has gone through optimization on the server side.
* reoptimizing doesn’t need to happen because WebAssembly has types and other information built in, so the JS engine doesn’t need to speculate when it optimizes the way it does with JavaScript.
* executing often takes less time because there are fewer compiler tricks and gotchas that the developer needs to know to write consistently performant code, plus WebAssembly’s set of instructions are more ideal for machines.
* garbage collection is not required since the memory is managed manually.
This is why, in many cases, WebAssembly will outperform JavaScript when doing the same task.
There are some cases where WebAssembly doesn’t perform as well as expected, and there are also some changes on the horizon that will make it faster.
[https://hacks.mozilla.org/2017/02/what-makes-webassembly-fast/]

specification of Wasm

description::
· to support the-embedding of WebAssembly into different environments, its specification is split into layers that are specified in separate documents.
· core-specification: defines the-semantics of WebAssembly-modules and its instruction-set, independent from a concrete embedding.
· API-specifications: define application-programming-interfaces enabling the-use of WebAssembly-modules in concrete embedding environments.
[https://webassembly.github.io/spec/]

name::
* cpt.Wasm'specification,
* cpt.Wasm-spec,

addressWpg::
* core-spec.html : https://webassembly.github.io/spec/core/,
* core-spec.pdf: https://webassembly.github.io/spec/core/_download/WebAssembly.pdf,
* JavaScript-API-spec: https://webassembly.github.io/spec/js-api/index.html,
* web-API-spec: https://webassembly.github.io/spec/web-api/index.html,
* WebAssembly-Reference-Manual: a human-readable document written in Markdown, an alternative to the official WebAssembly specification: https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md,
* Conrad-Watt, Mechanising and Verifying the WebAssembly Specification: https://www.cl.cam.ac.uk/~caw77/,
* Bringing the Web up to Speed with WebAssembly: https://github.com/WebAssembly/spec/blob/master/papers/pldi2017.pdf,

grammar of specification

name::
* cpt.Wasm'grammar,
* cpt.Wasm-grammar,
* cpt.Wasm-spec'grammar,

grammar.ABSTRACT

description::
· abstract-grammar is the generic grammar for both formats, binary and text.
[hmnSgm.2018-03-31]
===
· WebAssembly is a-programming-language that has multiple concrete representations (its binary-format and the-text-format).
· both map to a common structure.
· for conciseness, this structure is-described in the-form of an-abstract-syntax.
· all parts of this specification are-defined in terms of this abstract-syntax.
[https://webassembly.github.io/spec/core/syntax/conventions.html#conventions {1-0.2018-03-28}]

name::
* cpt.Wasm'abstract-grammar,
* cpt.Wasm-grammar.abstract,

addressWpg::
* https://webassembly.github.io/spec/core/syntax/conventions.html,

production of abstract-grammar

description::
· Terminal symbols (atoms) are written in sans-serif font: i32, end.
· Nonterminal symbols are written in italic font: valtype, instr.
· Productions are written sym ::= A1 | … | An.
· Some productions are augmented with side conditions in parentheses, “(if condition)”, that provide a shorthand for a combinatorial expansion of the production into many separate cases.
[https://webassembly.github.io/spec/core/syntax/conventions.html {1-0.2018-03-28}]

name::
* cpt.Wasm'production-of-abstract-syntax,
* cpt.Wasm-abstract-syntax'production,

sequence of abstract-grammar

description::
· An is a sequence of n≥0 iterations of A.
· A is a possibly empty sequence of iterations of A. (This is a shorthand for An used where n is not relevant.)
· A+ is a non-empty sequence of iterations of A. (This is a shorthand for An where n≥1.)
· A? is an optional occurrence of A. (This is a shorthand for An where n≤1.)
· ϵ denotes the empty sequence.
· |s| denotes the length of a sequence s.
· s[i] denotes the i-th element of a sequence s, starting from 0.
· s[i:n] denotes the sub-sequence s[i] … s[i+n−1] of a sequence s.
· swith[i]=A denotes the same sequence as s, except that the i-the element is replaced with A.
· swith[i:n]=An denotes the same sequence as s, except that the sub-sequence s[i:n] is replaced with An.
· concat(s∗) denotes the flat sequence formed by concatenating all sequences si in s∗.
[https://webassembly.github.io/spec/core/syntax/conventions.html {1-0.2018-03-28}]

name::
* cpt.Wasm'sequence-of-abstract-syntax,
* cpt.Wasm-abstract-syntax'sequence,

record of abstract-grammar

description::
·

name::
* cpt.Wasm'record-of-abstract-syntax,
* cpt.Wasm-abstract-syntax'record,

vector of abstract-grammar

description::
· vectors are bounded sequences of the-form An (or A), where the-A can either be values or complex constructions.
· a-vector can-have at most 232−1 elements.
- vec(A) ::= An (if n < 232)
[https://webassembly.github.io/spec/core/syntax/conventions.html#vectors {1-0.2018-03-28}]

name::
* cpt.Wasm'vector-of-abstract-grammar,
* cpt.Wasm-abstract-grammar'vector,

grammar.BINARY

description::
· the-binary-format for WebAssembly-modules is a dense linear encoding of their abstract-syntax. [ 1 ]
· the-format is-defined by an-attribute-grammar whose only terminal-symbols are bytes.
· a byte sequence is a-well-formed-encoding-of-a-module if and only if it is-generated by the-grammar.
· each production of this grammar has exactly one synthesized-attribute: the-abstract-syntax that the respective byte sequence encodes.
· thus, the-attribute-grammar implicitly defines a-decoding-function.
· except for a few exceptions, the-binary-grammar closely mirrors the-grammar-of-the-abstract-syntax.

· note: some phrases of abstract-syntax have multiple possible encodings in the-binary-format.
· for example, numbers may-be-encoded as if they had optional leading zeros.
· implementations of decoders must-support all possible alternatives; implementations of encoders can-pick any allowed encoding.

· the recommended extension for files containing WebAssembly-modules in binary-format is “.wasm” and the recommended Media-Type is “application/wasm”.

· [1] additional encoding layers – for example, introducing compression – may-be-defined on top of the basic representation defined here. However, such layers are outside the-scope of the current specification.
[https://webassembly.github.io/spec/core/binary/conventions.html]

name::
* cpt.Wasm'binary-grammar,
* cpt.Wasm-grammar.binary,

addressWpg::
* https://webassembly.github.io/spec/core/binary/conventions.html,

grammar.TEXT

description::
· like the-binary-format, the-text-format is defined by an-attribute-grammar.
· a-text-string is a well-formed description of a-module if and only if it is-generated by the-grammar.
[https://webassembly.github.io/spec/core/text/conventions.html {1-0.2018-03-28}]

name::
* cpt.Wasm'text-grammar,
* cpt.Wasm-grammar.text,
* cpt.Wasm-text-grammar,

addressWpg::
* https://webassembly.github.io/spec/core/text/conventions.html,
* https://github.com/WebAssembly/spec/tree/master/interpreter/#s-expression-syntax,

identifier-context of text-grammar

description::
· the-text-format allows to use symbolic-identifiers in place of indices.
· to resolve these identifiers into concrete indices, some grammar production are-indexed by an-identifier-context-I as a-synthesized-attribute that records the declared identifiers in each index-space.
· in addition, the-context records the-types defined in the-module, so that parameter indices can-be-computed for functions.

· it is convenient to define identifier-contexts as records I with abstract-syntax as follows:
- I ::= {types (id?)∗,
funcs (id?)∗,
tables (id?)∗,
mems (id?)∗,
globals (id?)∗,
locals (id?)∗,
labels (id?)∗,
typedefs functype∗ }

· for each index-space, such a-context contains the list of identifiers assigned to the defined indices.
· unnamed indices are-associated with empty (ϵ) entries in these lists.

· an-identifier-context is well-formed if no index-space contains duplicate identifiers.
[https://webassembly.github.io/spec/core/text/conventions.html#contexts {1-0.2018-03-28}]

name::
* cpt.Wasm-text-grammar'identifier-context,

WebAssembly-working-group

description::
'WebAssembly is an open standard developed by a W3C Community Group that includes representatives of all major browser vendors.'
[https://webassembly.github.io/spec/core/_download/WebAssembly.pdf]
===
'The mission of the WebAssembly Working Group is to standardize a size- and load-time-efficient format and execution environment, allowing compilation to the web with consistent behavior across a variety of implementations.'
[https://www.w3.org/wasm/]

name::
* cpt.Wasm'W3C-community-group,
* cpt.Wasm'working-group,
* cpt.WebAssembly-working-group,

addressWpg::
* https://www.w3.org/wasm/,
* https://www.w3.org/community/webassembly/,

tool of Wasm

name::
* cpt.Wasm'tool,
* cpt.Wasm-tool,

addressWpg::
* https://github.com/WebAssembly/design/blob/master/Tooling.md,

specific::
* runtime-environment,
* editor,
* compiler,

tool.COMPILER

name::
* cpt.Wasm'compiler,
* cpt.Wasm-compiler,

specific::
* https://wasdk.github.io/WasmFiddle/,
* http://mbebenita.github.io/WasmExplorer/,

compiler.to-wat

name::
* cpt.Wasm'to-wat-compiler,
* cpt.Wasm-compiler.to-wat,

specific::
* online C-to-wat: https://wasdk.github.io/WasmFiddle/,

compiler.to-wasm

name::
* cpt.Wasm'to-wasm-compiler,
* cpt.Wasm-compiler.to-wasm,

specific::
* online C-to-wasm: https://wasdk.github.io/WasmFiddle/,
* TypeScript-to-wasm: AssemblyScript https://github.com/AssemblyScript/assemblyscript,
* TypeScript-to-wasm: speedy.js https://github.com/MichaReiser/speedy.js,

compiler.wat-to-wasm

name::
* cpt.Wasm'wat-to-wasm,
* cpt.Wasm-compiler.wat-to-wasm,

specific::
* wat2wasm cli-tool (WABT),
* online: https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/wat2wasm/,

compiler.wasm-to-wat

name::
* cpt.Wasm'wasm-to-wat,
* cpt.Wasm-compiler.wasm-to-wat,

addressWpg::
* online: https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/wasm2wat/,
* wat2wasm: WABT cli tool (wat2wasm test.wat -o test.wasm).

compiler.wasm-to-machine

name::
* cpt.Wasm'wasm-to-machine,
* cpt.Wasm-compiler.wasm-to-machine,

specific::
* Wasm-runtime-environment,

tool.HEX-VIEWER

description::
· view a-wasm-file in hexadecimal-format.

name::
* cpt.Wasm-tool.hex-viewer,

addressWpg::
* online: http://tomeko.net/online_tools/file_to_hex.php?lang=en,

tool.WABT

description::
· WABT includes tools for development and/or use in tools meant to work with WebAssembly:
- it perfectly supports the format specification
- it can convert from/to the textual format
- it include an interpreter
· In short, it ensures a clean and easy access to the data in the WebAssembly format so that you can work with it.
[https://tomassetti.me/introduction-to-webassembly/]

name::
* cpt.WABT,
* cpt.Wasm'WABT, /wabit/
* cpt.Wasm'WebAssembly-Binary-Toolkit,
* cpt.Wasm-tool.WABT,

addressWpg::
* https://github.com/WebAssembly/wabt,
* on npm: https://www.npmjs.com/package/wabt,

tool::
* wat2wasm: translate from WebAssembly text format to the WebAssembly binary format
* wasm2wat: the inverse of wat2wasm, translate from the binary format back to the text format (also known as a .wat)
* wasm-objdump: print information about a wasm binary. Similiar to objdump.
* wasm-interp: decode and run a WebAssembly binary file using a stack-based interpreter
* wat-desugar: parse .wat text form as supported by the spec interpreter (s-expressions, flat syntax, or mixed) and print "canonical" flat format
* wasm2c: convert a WebAssembly binary file to a C source and header
[https://github.com/WebAssembly/wabt]

installing::
* clone: $ git clone --recursive https://github.com/WebAssembly/wabt
* build: instructions in https://github.com/WebAssembly/wabt.
* set directory of tools on path.

tool.Binaryen

description::
· Binaryen is an industrial-strength toolkit meant for usage in a compiler infrastructure:
- it can work with WebAssembly code or a control flow graph form meant for compilers
- it optimizes the code with many passes, both standard optimization and specific ones for WebAssembly
- it can compile from/to asm.js (a subset of JavaScript), Rust MIR (an intermediate language for Rust) and LLVM
· So, this toolkit is ready to be integrated in your production backend.
[https://tomassetti.me/introduction-to-webassembly/]

name::
* cpt.Binaryen,
* cpt.Wasm'Binaryen,
* cpt.Wasm-tool.Binaryen,

addressWpg::
* https://github.com/WebAssembly/binaryen,

tool.Emscripten-SDK

description::
· Emscripten is a toolchain for compiling to asm.js and WebAssembly, built using LLVM, that lets you run C and C++ on the web at near-native speed without plugins.
[http://kripken.github.io/emscripten-site/index.html]

name::
* cpt.Emscripten,
* cpt.Wasm'Emscripten,
* cpt.Wasm-tool.Emscripten,

addressWpg::
* http://kripken.github.io/emscripten-site/index.html,

tool.RUNTIME-ENVIRONMENT

description::
· the-runtime-environment[a] is the-software-system that provides the necessary libraries and executes a-Wasm-program.
· now, it[a] is a-browser and the-Node.js.
[hmnSgm.2018-04-08]
===
· a WebAssembly runtime-environment will typically provide APIs for interacting with the-outside-world, as-well-as mechanisms for loading and linking wasm-modules.
· this is the-embedding-environment.
[https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#embedding-environment]

name::
* cpt.Wasm'embedder,
* cpt.Wasm'embedding-environment,
* cpt.Wasm'host-environment,
* cpt.Wasm'outside-environment,
* cpt.Wasm'runtime-environment,

WebAssembly--javascript-object

description::
· The-WebAssembly-JavaScript-object acts as the-namespace for all WebAssembly-related functionality.
· unlike most other global-objects, WebAssembly is-not a-constructor (it is-not a-function-object).
· you can-compare it to Math, which is also a namespace object for mathematical constants and functions, or to Intl which is the namespace object for internationalization constructors and other language sensitive functions.
· the primary uses for the-WebAssembly-object are:
* loading WebAssembly-code, using the-WebAssembly.instantiate()-function.
* creating new memory and table instances via the-WebAssembly.Memory()/WebAssembly.Table()-constructors.
* providing facilities to handle errors that occur in WebAssembly via the-WebAssembly.CompileError()/WebAssembly.LinkError()/WebAssembly.RuntimeError()-constructors.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly]

name::
* cpt.Ljb-API'WebAssembly-object,
* cpt.Ljn-API'WebAssembly-object,
* cpt.Ljs-API'WebAssembly-object,
* cpt.Ljb-o.WebAssembly,
* cpt.Wasm'Api.javascript,
* cpt.Wasm'javascript-Api,
* cpt.Wasm'WebAssembly--javascript-object,
* cpt.Wasm-WebAssembly-object,
* cpt.WebAssembly--javascript-object,

member of WebAssembly-object

member::
> Object.getOwnPropertyNames(WebAssembly).sort().join(', ')
"CompileError, Instance, LinkError, Memory, Module, RuntimeError, Table, compile, compileStreaming, instantiate, instantiateStreaming, validate"
===
//Node.js 8.11.1
"CompileError, Instance, LinkError, Memory, Module, RuntimeError, Table, compile, instantiate, validate"

WebAssembly.instantiate-function

description::
· the-WebAssembly.instantiate()-function allows you to compile and instantiate WebAssembly-code.
· this function has two overloads:
* the primary overload takes the-WebAssembly-binary-code, in the-form of a-typed-array or ArrayBuffer, and performs both compilation and instantiation in one step. The returned Promise resolves to both a compiled WebAssembly.Module and its first WebAssembly.Instance.
* the secondary overload takes an already-compiled WebAssembly.Module and returns a-Promise that resolves to an Instance of that Module. This overload is useful if the-Module has already been-compiled or retrieved from cache.
· important: this method is-not the most efficient way of fetching and instantiating wasm-modules. If at all possible, you should-use the newer WebAssembly.instantiateStreaming() method instead, which fetches, compiles, and instantiates a-module all in one step, directly from the raw bytecode, so doesn't require conversation to an-ArrayBuffer.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate]

name::
* cpt.Wasm'WebAssembly.instantiate-function,
* cpt.WebAssembly.instantiate-function,

WebAssembly.instantiateSteaming-function

description::
· the-WebAssembly.instantiateStreaming()-function compiles and instantiates a-WebAssembly-module directly from a streamed underlying source.
· this is the most efficient, optimized way to load wasm-code.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming]

name::
* cpt.Wasm'WebAssembly.instantiateSteaming-function,
* cpt.WebAssembly.instantiateSteaming-function,

WebAssembly.compile-function

description::
· the-WebAssembly.compile()-function compiles a-WebAssembly.Module from WebAssembly-binary-code.
· this function is useful if it is necessary to compile a-module before it can-be-instantiated (otherwise, the-WebAssembly.instantiate()-function should-be-used).
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile]

name::
* cpt.Wasm'WebAssembly.compile-function,
* cpt.WebAssembly.compile-function,

WebAssembly.compileStreaming-function

description::
· the-WebAssembly.compileStreaming()-function compiles a-WebAssembly.Module directly from a streamed underlying source.
· this function is useful if it is necessary to compile a-module before it can-be-instantiated (otherwise, the-WebAssembly.instantiateStreaming()-function should-be-used).
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming]

name::
* cpt.Wasm'WebAssembly.compileStreaming-function,
* cpt.WebAssembly.compileStreaming-function,

WebAssembly.validate-function

description::
· the-WebAssembly.validate()-function validates a given typed-array of WebAssembly-binary-code, returning whether the-bytes form a valid wasm-module (true) or not (false).
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate]

name::
* cpt.Wasm'WebAssembly.validate-function,
* cpt.WebAssembly.validate-function,

example::
fetch('simple.wasm')
.then(oResponse => oResponse.arrayBuffer())
.then(function(oArrayBuffer) { var bValid = WebAssembly.validate(oArrayBuffer); console.log("The given bytes are " + (bValid ? "" : "not ") + "a valid wasm module");
});

[https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/validate.html]

WebAssembly.Module-function

description::
· a-WebAssembly.Module-object contains stateless WebAssembly-code that has already been-compiled by the-browser and can-be efficiently shared with Workers, cached in IndexedDB and instantiated multiple times.
· the-WebAssembly.Module()-constructor-function can-be-called to synchronously compile given WebAssembly-binary-code.
· however, the primary way to get a-Module is through an asynchronous compilation function like WebAssembly.compile() or by reading a-Module out of IndexedDB.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module]

name::
* cpt.Wasm'WebAssembly.Module-function,
* cpt.WebAssembly.Module-function,

member::
>Object.getOwnPropertyNames(WebAssembly.Module).sort()
(8) ["arguments", "caller", "customSections", "exports", "imports", "length", "name", "prototype"]

example Module.imports::
//display the-imports of the-simple-program
WebAssembly.compileStreaming(fetch('simple.wasm'))
.then(function(mod) {
 var aImports = WebAssembly.Module.imports(mod);
 console.log(aImports[0]);
});

demo.
[https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/imports.html]

example Module.exports::
//display the-exports of the-simple-program
WebAssembly.compileStreaming(fetch('simple.wasm'))
.then(function(mod) {
 var aExports = WebAssembly.Module.exports(mod);
 console.log(aExports[0]);
});

demo.

WebAssembly.Instance-function

description::
· a-WebAssembly.Instance-object is a stateful, executable instance of a-WebAssembly.Module.
· instance-objects contain all the Exported WebAssembly functions that allow calling into WebAssembly code from JavaScript.
· the-WebAssembly.Instance()-constructor-function can-be-called to synchronously instantiate a given WebAssembly.Module-object.
· however, the primary way to get an Instance is through the asynchronous WebAssembly.instantiateStreaming()-function.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance]

name::
* cpt.Wasm'WebAssembly.Instance-function,
* cpt.WebAssembly.Instance-function,

WebAssembly.Memory-function

description::
· the-WebAssembly.Memory()-constructor creates a new Memory-object which is a resizable ArrayBuffer that holds the raw bytes of memory accessed by a-WebAssembly-Instance.
· a-memory created by JavaScript or in WebAssembly-code will-be accessible and mutable from both JavaScript and WebAssembly.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory]

name::
* cpt.Wasm'WebAssembly.Memory-function,
* cpt.WebAssembly.Memory-function,

WebAssembly.Table-function

description::
· the-WebAssembly.Table()-constructor creates a new Table-object of the given size and element type.
· this is a-JavaScript wrapper object — an array-like structure representing a-WebAssembly-Table, which stores function-references.
· a-table created by JavaScript or in WebAssembly-code will-be accessible and mutable from both JavaScript and WebAssembly.
· note: tables can currently only store function-references, but this will likely be-expanded in the-future.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table]

name::
* cpt.Wasm'WebAssembly.Table-function,
* cpt.WebAssembly.Table-function,

WebAssembly.CompileError-function

description::
· the-WebAssembly.CompileError()-constructor creates a new WebAssembly-CompileError-object, which indicates an-error during WebAssembly decoding or validation.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError]

name::
* cpt.Wasm'WebAssembly.CompileError-function,
* cpt.WebAssembly.CompileError-function,

WebAssembly.LinkError-function

description::
· the-WebAssembly.LinkError()-constructor creates a new WebAssembly-LinkError-object, which indicates an-error during module-instantiation (besides traps from the-start-function).
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError]

name::
* cpt.Wasm'WebAssembly.LinkError-function,
* cpt.WebAssembly.LinkError-function,

WebAssembly.RuntimeError-function

description::
· the-WebAssembly.RuntimeError()-constructor creates a new WebAssembly-RuntimeError-object — the-type that is-thrown whenever WebAssembly specifies a-trap.
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError]

name::
* cpt.Wasm'WebAssembly.RuntimeError-function,
* cpt.WebAssembly.RuntimeError-function,

machine-document

description::
· machine-document is the-document that understands and executes a real|concrete machine.
[hmnSgm.2018-03-25]

name::
* cpt.Wasm'machine-document,

decoding a-Wasm-program

description::
'Decoding
WebAssembly modules are distributed in a binary format. Decoding processes that format and converts it into an internal representation of a module. In this specification, this representation is modelled by abstract syntax, but a real implementation could compile directly to machine code instead.'
[https://webassembly.github.io/spec/core/intro/overview.html#semantic-phases {1-0.2018-03-22}]

name::
* cpt.Wasm'decoding-of-binary-modules,

validating a-Wasm-program

description::
'Validation
A decoded module has to be valid. Validation checks a number of well-formedness conditions to guarantee that the module is meaningful and safe. In particular, it performs type checking of functions and the instruction sequences in their bodies, ensuring for example that the operand stack is used consistently.'
[https://webassembly.github.io/spec/core/intro/overview.html#semantic-phases {1-0.2018-03-22}]

name::
* cpt.Wasm'validating,

addressWpg::
* {2018-04-07} Mauro-Bringolf, Learning the Webassembly type system, https://maurobringolf.ch/,

executing a-Wasm-program

description::
'Finally, a valid module can be executed. Execution can be further divided into two phases: instantiation, invocation.'
[https://webassembly.github.io/spec/core/intro/overview.html#semantic-phases {1-0.2018-03-22}]

name::
* cpt.Wasm'executing,

instatiating a-Wasm-program

description::
Instantiation. A module instance is the dynamic representation of a module, complete with its own state and execution stack. Instantiation executes the module body itself, given definitions for all its imports. It initializes globals, memories and tables and invokes the module’s start function if defined. It returns the instances of the module’s exports.
[https://webassembly.github.io/spec/core/intro/overview.html#semantic-phases {1-0.2018-03-22}]

name::
* cpt.Wasm'instatiating,

invocating a-Wasm-program

description::
'Invocation. Once instantiated, further WebAssembly computations can be initiated by invoking an exported function on a module instance. Given the required arguments, that executes the respective function and returns its results.'
[https://webassembly.github.io/spec/core/intro/overview.html#semantic-phases {1-0.2018-03-22}]

name::
* cpt.Wasm'invocating,

resource of Wasm

Name::
* cpt.WebAssembly'resource,
* cpt.Wasm'resource,
* cpt.WasmAeResource,

addressWpg::
* webassembly.org,
* https://research.mozilla.org/webassembly/,
* WebAssembly-community-group,
* spec: https://webassembly.github.io/spec/core/_download/WebAssembly.pdf,
* https://github.com/mbasso/awesome-wasm,
* https://wasdk.github.io/WasmFiddle/,
* https://rsms.me/wasm-intro,
* https://hacks.mozilla.org/2017/07/creating-a-webassembly-module-instance-with-javascript/,
* https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md,

tutorial of Wasm

addressWpg::
* Clark.Lin, A cartoon intro to WebAssembly: https://hacks.mozilla.org/2017/02/,
* code-examples: https://github.com/reklatsmasters/webassembly-examples,

GENERIC of Wasm

Generic-chain::
* web-programing-language,
...
* entity,

Wasm.SPECIFIC

name::
* cpt.WebAssembly.specific,
* cpt.WasmAsSpecific,

specific::
* binary-format,
* text-format,
* Ethereum flavored WebAssembly (ewasm): https://github.com/ewasm,

Wasm.ABSTRACT-FORMAT

description::
· the-Wasm-specification represents a-Wasm-document AND in a generic format of the-two Wasm-formats, the-text and the-binary.
· this generic format it calls it 'abstract-format'.
[hmnSgm.2018-04-06]

name::
* cpt.Wasm'abstract-format,

grammar of abstract-format (link)

Wasm.TEXT-FORMAT

description::
· WebAssembly has an-S-expression-based textual representation, an intermediate form designed to be-exposed in text-editors, browser-developer-tools, etc.
[https://developer.mozilla.org/en-US/docs/WebAssembly/Text_format_to_wasm]

name::
* cpt.text-Wasm,
* cpt.Wasm.source-format,
* cpt.Wasm.textual-format,
* cpt.Wasm.text-format,

grammar of text-Wasm (link)

S-expression of text-Wasm

description::
· S-expressions are a very old and very simple textual-format for representing trees of nodes.
· each node in the-tree goes inside a-pair of parentheses — ( ... ).
· the first label inside the-parenthesis tells you what type of node it is, and after that there-is a space-separated list of either attributes or child-nodes.
[https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format]

name::
* cpt.S-expression.Wasm,
* cpt.Wasm'S-expression,

file of text-Wasm

description::
· the recommended file-extension for WebAssembly code in textual-format is .wat.

converting-to-binary-format of text-Wasm

name::
* cpt.Wasm'converting-text-to-binary-format,
* cpt.Wasm'translating-text-to-binary-format,

addressWpg::
* wat2wasm: https://cdn.rawgit.com/WebAssembly/wabt/aae5a4b7/demo/wat2wasm/,

resource of text-Wasm

addressWpg::
* https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format,

.wast-format

description::
The .wast format understood by some of the listed tools is a superset of the .wat format that is intended for writing test scripts. Besides the definition of modules such scripts can contain assertions and other commands as defined by a grammar extension. These extensions are not part of the official text format, which may only contain a single module.
[https://webassembly.org/docs/text-format/]

name::
* cpt.Wasm'wast-format,
* cpt.wast-format,

Wasm.BINARY-FORMAT

description::
· Wasm-binary-format is a-WebAssembly with bits as algo-units.

name::
* cpt.binary-Wasm,
* cpt.Wasm.binary-format,

grammar of binary-Wasm (link)

Wasm.EVOLUTING

name::
* cpt.Wasm.evoluting,

{time.2016-03-15}::
=== demonstration:
on 15-March-2016 was-demonstrated executing Unity's-Angry-Bots in Firefox, Chromium, Google Chrome, and Microsoft Edge.
[https://en.wikipedia.org/wiki/WebAssembly]

{time.2015-06-17}::
=== announcement:
It was first announced on 17-June-2015.
[https://en.wikipedia.org/wiki/WebAssembly]

meta-info

this page was-visited times since {2018-03-18}

page-path: synagonism.net / Mcs-worldview / dirTchInf / WebAssembly

SEARCH::
· this page uses 'locator-names', names that when you find them, you find the-LOCATION of the-concept they denote.
LOCAL-SEARCH:
· TYPE CTRL+F "cpt.words-of-concept's-name", to go to the-LOCATION of the-concept.
GLOBAL-SEARCH:
· clicking on the-green-TITLE of a-page you have access to the-global--locator-names of my-site.
· a-preview of the-description of a-global-name makes reading fast.

footer::
• author: Kaseluris.Nikos.1959
• email:
 imgMail
• twitter: @synagonism
• steemit: https://steemit.com/@synagonism
• github: https://github.com/synagonism/Mcsw/blob/master/dirTchInf/filMcsLwasm.last.html,

webpage-versions::
• version.last.dynamic: filMcsLwasm.last.html,
• version.0-1-0.2018-03-18.created: filMcsLwasm.0-1-0.2018-03-18.html,

support (link)