Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set parameter type to i64 in imported functions #95

Open
s2x opened this issue Nov 19, 2019 · 3 comments
Open

How to set parameter type to i64 in imported functions #95

s2x opened this issue Nov 19, 2019 · 3 comments
Assignees
Labels
❓ question Further information is requested

Comments

@s2x
Copy link

s2x commented Nov 19, 2019

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 s2x added the ❓ question Further information is requested label Nov 19, 2019
@Hywan
Copy link
Contributor

Hywan commented Nov 20, 2019

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 Hywan self-assigned this Nov 20, 2019
@s2x
Copy link
Author

s2x commented Nov 22, 2019

Yes, it would be great.

@Hywan
Copy link
Contributor

Hywan commented Apr 27, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants