3eyedRaven
3eyedRaven

Reputation: 111

Will web assembly (wasm) have its own syntax?

I heard that W3 is working on the web's byte code, Will web assembly (wasm) have its own syntax like nasm and masm? for example typing stuff like,

 global _main
extern _MessageBoxA@16
extern _ExitProcess@4

section code use32 class=code
_main:
    push    dword 0      ; UINT uType = MB_OK
    push    dword title  ; LPCSTR lpCaption
    push    dword banner ; LPCSTR lpText
    push    dword 0      ; HWND hWnd = NULL
    call    _MessageBoxA@16

    push    dword 0      ; UINT uExitCode
    call    _ExitProcess@4

section data use32 class=data
    banner: db 'Hello, world!', 0
    title:  db 'Hello', 0

in nasm for windows

or will it only be created from being compiled from C/C++ and other languages?

Upvotes: 6

Views: 2635

Answers (2)

JF Bastien
JF Bastien

Reputation: 6843

The current working prototype for WebAssembly already has a syntax which is also emitted by the LLVM backend (the CHECK: parts of these tests), used by the WAVM backend. Also see ilwasm and WABT.

Is this the official, final textual syntax? No, but it may become official later (March 2017 update: this is likely to happen soon).

The current WebAssembly binary format is a stack machine which is a significant change from the original AST approach which WebAssembly took. s-expressions aren't inherently better suited to represent stack machines, but they're good enough, simple, and avoid endless bikeshed.


Original answer:

It has the important property for WebAssembly of being represented as s-expressions which inherently have an expression tree, which are a key part the AST's design. It also has structured control flow (an AST) instead of what most compiler IRs have (a CFG).

Are there any other prototype syntax? Yes! The wassembler which works closely with the V8 prototype has an entirely different syntax.

Why another syntax than s-expressions? A C-like syntax is more familiar to most developers! It's not as close to what the binary format would contain, but it's still pretty close and nicer to use.

Why is this so complicated? It's useful to read the text format description to understand. Work is still ongoing, and in the end the important part of WebAssembly is the binary format: it's what all tools will exchange, and what browsers will consume. Why even work on a text format, then? We're engineers, and it's easier for us to consume text. We're OK chancing it later, the main goal of the text format is for human understanding and we'll need more humans to figure out if the text we've created is understandable.

Upvotes: 14

Peter Awesome
Peter Awesome

Reputation: 59

The textual representation of WebAssembly (WASM) will look similar to asm.js. The official GitHUB FAQ covers your questions:

In fact, by dropping all the coercions required by asm.js validation, the WebAssembly text format should be much more natural to read and write than asm.js. Outside the browser, command-line and online tools that convert between text and binary will also be made readily available.

[...]

As WebAssembly evolves it will support more languages than C/C++, and we hope that other compilers will support it as well, even for the C/C++ language, for example GCC.

Upvotes: 0

Related Questions