2018-11-23 00:13:01 -05:00
|
|
|
use std::mem;
|
2019-04-22 11:42:52 -07:00
|
|
|
use wasmer_runtime_core::{types::WasmExternType, vm::Ctx};
|
2018-11-23 00:13:01 -05:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
2019-02-01 13:18:43 -08:00
|
|
|
#[derive(Copy, Clone)]
|
2018-11-23 00:13:01 -05:00
|
|
|
pub struct VarArgs {
|
2018-11-25 13:51:21 -05:00
|
|
|
pub pointer: u32, // assuming 32bit wasm
|
2018-11-23 00:13:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl VarArgs {
|
2019-01-24 13:04:12 -08:00
|
|
|
pub fn get<T: Sized>(&mut self, ctx: &mut Ctx) -> T {
|
|
|
|
let ptr = emscripten_memory_pointer!(ctx.memory(0), self.pointer);
|
2018-11-23 00:13:01 -05:00
|
|
|
self.pointer += mem::size_of::<T>() as u32;
|
|
|
|
unsafe { (ptr as *const T).read() }
|
|
|
|
}
|
2018-11-26 20:29:26 -08:00
|
|
|
}
|
2019-02-01 13:18:43 -08:00
|
|
|
|
|
|
|
unsafe impl WasmExternType for VarArgs {
|
2019-04-22 11:42:52 -07:00
|
|
|
type Native = i32;
|
2019-04-09 16:07:09 -07:00
|
|
|
|
2019-04-22 11:42:52 -07:00
|
|
|
fn to_native(self) -> Self::Native {
|
|
|
|
self.pointer as _
|
2019-04-09 16:07:09 -07:00
|
|
|
}
|
2019-04-22 11:42:52 -07:00
|
|
|
fn from_native(n: Self::Native) -> Self {
|
2019-04-09 16:07:09 -07:00
|
|
|
Self { pointer: n as u32 }
|
|
|
|
}
|
2019-02-01 13:22:49 -08:00
|
|
|
}
|