wasmer-php icon indicating copy to clipboard operation
wasmer-php copied to clipboard

How to set parameter type to i64 in imported functions

Open s2x opened this issue 6 years ago • 3 comments

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?

s2x avatar Nov 19 '19 07:11 s2x

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?

Hywan avatar Nov 20 '19 14:11 Hywan

Yes, it would be great.

s2x avatar Nov 22 '19 08:11 s2x

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.

Hywan avatar Apr 27 '20 07:04 Hywan