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

support (u32, u32) as return value #116

Open
xlc opened this issue May 6, 2024 · 1 comment
Open

support (u32, u32) as return value #116

xlc opened this issue May 6, 2024 · 1 comment

Comments

@xlc
Copy link

xlc commented May 6, 2024

I got the guest program to compile with this

struct ReturnValue(u32, u32);
impl IntoHost for ReturnValue {
    type Regs = (u32, u32);
    type Destructor = ();

    #[inline(always)]
    fn into_host(value: Self) -> (Self::Regs, ()) {
        ((value.0, value.1), ())
    }
}

but I see no reason to not support (u32, u32) directly without the extra work

But from the host side, I am not very sure how to use call_typed with it

poc/executor/src/lib.rs:69:64
     |
69   |         let (res_ptr, res_len) = instance.call_typed::<(u32,), (u32, u32)>(&mut self.context, "main", (input_ptr,))?;
     |                                           ----------           ^^^^^^^^^^ the trait `polkavm::api::AbiTy` is not implemented for `(u32, u32)`, which is required by `(u32, u32): polkavm::api::FuncResult`
     |                                           |
     |                                           required by a bound introduced by this call
     |
     = help: the following other types implement trait `polkavm::api::AbiTy`:
               i32
               i64
               u32
               u64
     = note: required for `(u32, u32)` to implement `polkavm::api::FuncResult`
@koute
Copy link
Collaborator

koute commented May 6, 2024

You can call into the guest without call_typed.

https://docs.rs/polkavm/latest/src/polkavm/api.rs.html#2226-2252

Then you can extract the return values with get_reg(Reg::A0) and get_reg(Reg::A1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants