Giter VIP home page Giter VIP logo

wasm-reference-manual's Introduction

WebAssembly Reference Manual

This project contains a human-readable WebAssembly reference manual document written in Markdown. It is intended as an alternative to the official WebAssembly specification, which is organized around a particular approach to language specification, rather than on explanation. If you want to know how the WebAssembly runtime works, are writing a compiler, or want to try writing WebAssembly by hand (in text format), this manual is a good starting point.

Contribution

This is not the official WebAssembly specification, and as a result, will not be updated by the W3C working group as the specification evolves. For that reason, contributions are most welcome.

This work is public domain, and distributed under the CC0 1.0 Universal licence.

Current issues

Github-flavored Markdown is almost just powerful enough for this use case; the main things it lacks are automatic tables of contents and convenient term definitions, however the advantages in simplicity and convenient workflows partly make up for that.

Known deficiencies are marked with TODO comments. Corrections and contributions are welcome!

wasm-reference-manual's People

Contributors

colineberhardt avatar conr2d avatar jiboo avatar laughinghan avatar mulling avatar neutiyoo avatar ospencer avatar qwerty2501 avatar sunfishcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wasm-reference-manual's Issues

Are the type types right?

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

Linear memory import : initial size meaning ?

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.

Small inaccuracy about the `body_size` field in the Code section

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!

How was this manual constructed?

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.