-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from wasmerio/feature/type-safety
Add VarArgs newtype to simplify emscripten varargs.
- Loading branch information
Showing
4 changed files
with
34 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::webassembly::Instance; | ||
use std::mem; | ||
|
||
#[repr(transparent)] | ||
pub struct VarArgs { | ||
pointer: u32, // assuming 32bit wasm | ||
} | ||
|
||
impl VarArgs { | ||
pub fn get<T: Copy>(&mut self, instance: &mut Instance) -> T { | ||
let ptr = instance.memory_offset_addr(0, self.pointer as usize); | ||
self.pointer += mem::size_of::<T>() as u32; | ||
unsafe { (ptr as *const T).read() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters