polkavm icon indicating copy to clipboard operation
polkavm copied to clipboard

support (u32, u32) as return value

Open xlc opened this issue 1 year ago • 2 comments

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`

xlc avatar May 06 '24 09:05 xlc

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).

koute avatar May 06 '24 09:05 koute