2018-11-23 05:13:01 +00:00
|
|
|
use std::mem;
|
2019-02-01 21:18:43 +00:00
|
|
|
use wasmer_runtime_core::{
|
|
|
|
types::{Type, WasmExternType},
|
2019-02-01 21:22:49 +00:00
|
|
|
vm::Ctx,
|
2019-02-01 21:18:43 +00:00
|
|
|
};
|
2018-11-23 05:13:01 +00:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
2019-02-01 21:18:43 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2018-11-23 05:13:01 +00:00
|
|
|
pub struct VarArgs {
|
2018-11-25 18:51:21 +00:00
|
|
|
pub pointer: u32, // assuming 32bit wasm
|
2018-11-23 05:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl VarArgs {
|
2019-01-24 21:04:12 +00: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 05:13:01 +00:00
|
|
|
self.pointer += mem::size_of::<T>() as u32;
|
|
|
|
unsafe { (ptr as *const T).read() }
|
|
|
|
}
|
2018-11-27 04:29:26 +00:00
|
|
|
}
|
2019-02-01 21:18:43 +00:00
|
|
|
|
|
|
|
unsafe impl WasmExternType for VarArgs {
|
|
|
|
const TYPE: Type = Type::I32;
|
2019-04-09 23:07:09 +00:00
|
|
|
|
|
|
|
fn to_bits(self) -> u64 {
|
|
|
|
self.pointer as u64
|
|
|
|
}
|
|
|
|
fn from_bits(n: u64) -> Self {
|
|
|
|
Self { pointer: n as u32 }
|
|
|
|
}
|
2019-02-01 21:22:49 +00:00
|
|
|
}
|