2 ms·
Take for example i32.add you have to 1. Check the type at the top of the stack to make sure it's i32 and trap otherwise 2. Pop the top of the stack 3. Check
by charcircuit 3y ago
Take for example i32.add you have to
1. Check the type at the top of the stack to make sure it's i32 and trap otherwise
2. Pop the top of the stack
3. Check the top of the stack and make sure it's i32 and trap otherwise
4. Pop the top of the stack.
5. Add the two values together
6. Push the result to the top of the stack along with its type.
Compare this to ADD from RISC-V where you can just add the contents of 2 source registers and store it in a destination register. There is not a bunch of type book keeping or alignment that you have to worry about.
- klodolph 3y agoMost of this can be done statically. You do the bookkeeping once. There are various approaches—you can try to allocate registers, or you can emit code that loads/stores on the stack, or you can just run an interpreter and remove the safety checks from it. The stack isn’t dynamically typed, so it doesn’t make sense to trap.
- charcircuit 3y agoLooking into it further the type checking is supposed to be done in a dedicated validation step and other than validation using instructions with the wrong type of data seems to work.