How to set parameter type to i64 in imported functions
Hi,
i try to implement missing function where expected signature is:
expected signature: [I32, I64, I32, I32] -> [I32]
my code:
$imports = [
'wasi_unstable' => [
'fd_seek' => function(int $file, int $offset, int $whence, int $newoffset): int {
return 0;
},
]
]
$instance = new Wasm\Instance(__DIR__ . '/demo.wasm', $imports);
when i try to run i get this error:
Incorrect import signature, namespace: wasi_unstable, name: fd_seek, expected signature: [I32, I64, I32, I32] -> [I32], found signature: [I32, I32, I32, I32] -> [I32]
How to set parameter type to i64 in imported functions?
Hi!
It's not yet possible, see:
https://github.com/wasmerio/php-ext-wasm/blob/6147c9837626277b07331f4f3eca53f2bf756dbe/src/wasm.cc#L880-L882
Because PHP has no way to represent an i32 or an i64, I decided to fallback to i32 everytime.
The hack I've in my head is to create a new “type” in PHP, like wasm\i32 and wasm\i64 (2 “value objects”), and use them instead of int. Is it something you would use?
Yes, it would be great.
I'm likely to adopt a new strategy. We will use the PHP int type hint, and cast to i32 or i64 according to the Wasm signature in the module.