sunfishcode / wasm-reference-manual Goto Github PK
View Code? Open in Web Editor NEWWebAssembly Reference Manual
Home Page: https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md
License: Apache License 2.0
WebAssembly Reference Manual
Home Page: https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md
License: Apache License 2.0
First of all, thanks for this amazing resource!
While working on a toy webassembly parser, I noticed an inconsistency with the official spec in your description of the Code section (#code-section
). You state that body_size
describes "the size of body
in bytes", while in fact it describes the size of locals
plus the size of body
, in bytes. This is stated in the formal specification:
The encoding of each code entry consists of
- the u32 size of the function code in bytes,
- the actual function code, which in turn consists of
- the declaration of locals,
- the function body as an expression.
I wasn't sure how you'd want to have this formulated in your document, so I opted to write this issue instead of directly making a PR.
Just wanted to post a heads-up; thanks again for the effort to write this up in an accessible manner!
Web
Assembly
Reference
Manual
This is an extremely useful resource. I'm just wondering, how it was constructed, and how definitive it is considered to be?
I believe that the following is the definitive WebAssembly specification:
https://webassembly.github.io/spec/
Although while it describes the language, it does that without reference to syntax.
What did you use as the source reference for constructing this guide?
(and if i can help resolve some TODOs I certainly will)
Hi,
The docs for data sections seems to be out dated - there's a whole 'data mode' scheme for 'active' and 'passive' data, see:
https://webassembly.github.io/spec/core/binary/modules.html#data-section
The elements section also has a similar setup I believe.
Also missing is docs for section type '12' which I think just contains size of data section.
Table-of-contents-crx[1] is a-Chrome-extension that facilitates the-reading of the-document.
[1] https://chrome.google.com/webstore/detail/table-of-contents-crx/eeknhipceeelbgdbcmchicoaoalfdnhi
Hi,
Are the type type encodings right?
I've just had wasm-objdump complain about using '0xff' to represent a result type of 'int32' in the 'type' section. I got this value from here:
https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#type-encoding-type
I checked the 'official docs' and it has this table instead:
https://www.w3.org/TR/wasm-core-2/binary/types.html#number-types
Going by these docs, I tried using '0x7f' for int32 and it does at prevent wasm-objdump complaining about the result type, although I haven't confirmed my program even actually works yet so it still could be my fault!
Anyway, I've generally found your docs to be clearest wasm docs around by far, keep up the great work.
Bye,
Mark
In the this section of this great document, it is written that:
A linear-memory import's minimum length is required to be at most the imported linear memory's minimum length.
Which is perfectly correct according to this section of the WebAssembly official documentation. The initial size of the memory declared in the module must but at least the initial size of the imported memory.
But this raises a question: what if the initial size of the memory declared in the module is less than the initial size of the imported memory?
The following module does compile with wat2wasm:
(module
(memory (import "imports" "memory") 1)
(func (export "fillMemory")
(local $count i32)
(local $index i32)
(set_local $count (i32.const 32768)) ;; 2 pages of 32 bits words
(set_local $index (i32.const 0))
(block
(loop
(i32.store (get_local $index) (i32.const 0x01010101))
(set_local $index (i32.add (get_local $index) (i32.const 4)))
(set_local $count (i32.sub (get_local $count) (i32.const 1)))
(br_if 1 (i32.eqz (get_local $count)))
br 0
)
)
)
)
It may be run with this program:
var nbPages = 2;
var importObject = {
imports: {
memory: new WebAssembly.Memory ({ initial: nbPages })
}
};
var wasmInstance = new WebAssembly.Instance (wasmModule, importObject);
wasmInstance.exports.fillMemory ();
var i, total = 0, bytes;
bytes = new Uint8Array (importObject.imports.memory.buffer);
for (var i = 0; i < nbPages * 65536; i++)
total += bytes[i];
console.log (`Read ${total} bytes`);
The result printed in the console is "Read 131072 bytes". This means that the code in the module is able to write 2 pages of 32 bits integers in the imported memory, although the initial value is said to be 1 in the module. It would be nice if the WASM Reference Manual explain why.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.