Questions tagged [webassembly]
For questions about how programming languages target the WebAssembly virtual machine, or the WebAssembly text format itself
12 questions
14
votes
1
answer
3k
views
What is the rationale behind the WebAssembly `if` statements behaving like `block` when it comes to breaking (`br`), rather than being transparent?
So, WebAssembly has two types of blocks of code, block and loop. When you break with br or <...
0
votes
3
answers
334
views
How do compilers which output WebAssembly Text Format (or any other LISP-like language) make sure the assembly code is indented consistently?
So, I recently run into this bug in the compiler for my programming language that outputs WebAssembly Text Format. Here is what the output looked like:
I fixed it by changing in my compiler:
...
2
votes
1
answer
620
views
Why weren't the WebAssembly directives `load` and `store` made more future-proof by requiring an additional argument specifying which linear memory?
So, WebAssembly is planning to add the support for multiple linear memories (something like x86 sections). And some WebAssembly directives (such as data) are made ...
4
votes
1
answer
280
views
How is the `wasm2c` tool from the WebAssembly Binary Toolkit capable of converting WebAssembly code doing unaligned access into C?
My AEC-to-WebAssembly compiler often outputs WebAssembly code doing unaligned access, which is valid in WebAssembly (it's just not guaranteed to be as fast as aligned access, and, on ARM, it usually ...
5
votes
1
answer
394
views
How to compile Discriminated Union types to Webassembly?
Assume that I have a simple language with the types I32 and F32, but also composite types like Tuples. I want to add Discriminated Union types, but I find it difficult to generate the wasm code in a ...
0
votes
1
answer
438
views
How might I implement a `typeid` operator (returning the type of its argument as something, presumably as a string) in my compiler?
So, here is how strings work in my AEC-to-WebAssembly compiler. After the program is parsed, all strings except inline assembly ones are gathered in a C++ ...
2
votes
1
answer
341
views
Is `WebAssembly` (the object through which WebAssembly and JavaScript programs communicate) considered to be a host object or a native object?
In our front-end developer course at Algebra, we are being taught there are three different types of objects in JavaScript:
Native objects - those that are defined by JavaScript itself, such as ...
10
votes
2
answers
697
views
Idiomatic memory allocation and garbage collection in LLVM
I am working on a new backend for a programming language using LLVM IR. This language makes a distinction between basic values and pointers to nodes on the heap, and uses a copying collector for ...
6
votes
2
answers
658
views
How can I compile closures in WebAssembly?
Consider the following pseudocode:
...
7
votes
2
answers
469
views
Is it fine to target .wat instead of .wasm and use wat2wasm?
IIRC the WebAssembly text format (.wat) is not able to express everything .wasm can, such as binary (custom) sections. I'm not sure about the current state of WebAssembly text and binary formats now ...
5
votes
3
answers
807
views
What are some different approaches for inline assembly, and what are their pros and cons?
In my programming language that compiles to WebAssembly, I am using the following syntax for inline assembly:
...
13
votes
1
answer
696
views
How do I implement coroutines on WebAssembly?
I am building a compiler targeting WebAssembly for a language that makes heavy use of first-class coroutines. WASM doesn't have native coroutine support (yet), so I have to emulate it. Given the ...