Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 707
3eyedRaven Avatar asked Sep 19 '15 09:09

3eyedRaven


People also ask

Is WebAssembly the same as assembly?

Be readable and debuggable — WebAssembly is a low-level assembly language, but it does have a human-readable text format (the specification for which is still being finalized) that allows code to be written, viewed, and debugged by hand.

Is Wasm an assembly language?

WebAssembly is a new type of code that can be run in modern web browsers — it is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages such as C/C++, C# and Rust with a compilation target so that they can run on the web.

Why WebAssembly is not popular?

WebAssembly can't render directly and has to rely on being called by and emitting Javascript to manipulate the DOM, but it still opens up some exciting options and introduces the potential to do things in the browser that we just can't do right now like 3D games, heavy image manipulation, cryptography, etc.

What is the primary goal of WebAssembly Wasm?

The main goal of WebAssembly is to enable high-performance applications on web pages, "but it does not make any Web-specific assumptions or provide Web-specific features, so it can be employed in other environments as well." It is an open standard and aims to support any language on any operating system, and in ...


1 Answers

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.

like image 103
JF Bastien Avatar answered Sep 28 '22 17:09

JF Bastien