|
|
|
|
|
by johnhenry
3035 days ago
|
|
I'm trying to learn more about this topic and I'm curious if anyone could clarify for me --
The reason Go would need a specific architecture for WebAssembly is because Go supports features, like garbage collection, that WebAssembly does not. Is that right? Close? An oversimplification. Way off? |
|
Say you have the code C=A+B in your program.
The generated assembly for a real machine looks something like this: (R* denote registers and A-C are memory addresses) load A->R1 load B->R2 add R1+R2->R3 store R3->C
WASM looks more like this: push A push B add pop C
This alone makes the approach to code generation and optimization quite different.
WASM does lack some features that you would find in real CPUs, most notably the ability for execution to jump to arbitrary memory locations. They had to work around this to maintain the behavior of goroutines. Functions also live in their own address spaces which necessitates a change to how the program counter works.