-
-
Notifications
You must be signed in to change notification settings - Fork 4
Exception
Exceptions can be represented and handled in the ABI via smart pointers. We do not need extensions to the WASM MVP in order for this to work:
Every function call in the ABI can be made to be followed by a check whether the return value contains an Exception(pointer). If so, pass it on to the caller by returning immediately, unless the function contains a catch block. This is possible because all functions adhere to our universal smart pointer scheme.
So throw "no such file"
is compiled to return 0xE0123456
where 0x0123456 is the position of the error object in linear memory. In the caller we find the wasm code
call $some_func
i32.and 0xF0000000
if i32.eq 0xE0000000 ;; error
if has catch
goto error handling
else
pop
return
end
end
else
pop ;; forget our i32.and calculation
end
These extra 20ish bytes per function call are forgivable, especially if the compiler is smart about whether the callee throws or not and whether there is a catch block.