Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1624: Add Value::I32/Value::I64 converters from unsigned ints r=MarkMcCaskey a=webmaster128 # Description Allow conversion of Rust `u32`/`u64` to Wasm `i32`/`i64` (which is something different than Rust's `i32`/`i64`. At https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md you see how i32/i64 are used to store both signed and unsigned values and are intepreted based in the operation. All our imports and exports ```rust // imports extern "C" { fn db_read(key: u32) -> u32; fn db_write(key: u32, value: u32); fn db_remove(key: u32); // … } // exports /// allocate reserves the given number of bytes in wasm memory and returns a pointer /// to a Region defining this data. This space is managed by the calling process /// and should be accompanied by a corresponding deallocate #[no_mangle] extern "C" fn allocate(size: usize) -> u32 { alloc(size) as u32 } /// deallocate expects a pointer to a Region created with allocate. /// It will free both the Region and the memory referenced by the Region. #[no_mangle] extern "C" fn deallocate(pointer: u32) { // auto-drop Region on function end let _ = unsafe { consume_region(pointer as *mut Region) }; } // ... ``` compile from Rust `u32` to Wasm `i32`. I hope this is the right approach work with those flexible Wasm types. Let me know what you think. # Review - [ ] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Simon Warta <[email protected]>
- Loading branch information