feat: support i32, i64, f32, f64 param/return types for Host functions #125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves implementation of host function calls by removing the limitation of only having I64 params/return types. Now Host Functions can have params/return types of any of the supported types: I32, I64, F32, F64
Example index.d.ts
2. Call Flow
When JavaScript calls a host function:
floatInputs
(from host.ts)floatInputs
calls__invokeHostFunc(index, ...bit_patterns)
(from globals.rs)__invokeHostFunc(index, ...bit_patterns)
uses__get_function_arg_type
(from shim layer) to know the expected type of each parameter, converts them to i64 numbers and then calls__invokeHostFunc
(from the shim layer)__invokeHostFunc
calls__conv_floatInputs
(from shim layer)__conv_floatInputs
re-interprets the arguments to the expected types, and does an indirect call tofloatInputs
(imported from the host)__conv_floatInputs
(from shim layer) takes the return value, re-interprets it asi64
__invokeHostFunc
(from shim layer) returns the return value back to__invokeHostFunc
(from globals.rs)__invokeHostFunc
(from globals.rs) then uses__get_function_return_type
to convert the returned i64 value back to the correct rquickjs type and returns it tofloatInputs
(from host.ts)3. Type System
Generated functions include:
4. Generated Host Imports