-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
49 additions
and
6 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
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 |
---|---|---|
|
@@ -29,3 +29,5 @@ pub mod value; | |
|
||
#[cfg(feature = "wasi")] | ||
pub mod wasi; | ||
|
||
pub mod wat; |
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,30 @@ | ||
use super::types::wasm_byte_vec_t; | ||
|
||
/// Parses in-memory bytes as either the WAT format, or a binary Wasm | ||
/// module. This is wasmer-specific. | ||
/// | ||
/// In case of failure, `wat2wasm` returns `NULL`. | ||
#[cfg(feature = "wat")] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn wat2wasm(wat: &wasm_byte_vec_t) -> Option<Box<wasm_byte_vec_t>> { | ||
let wat: &[u8] = wat.into_slice()?; | ||
|
||
let result = match wasmer::wat2wasm(wat) { | ||
Ok(result) => result, | ||
Err(error) => { | ||
crate::error::update_last_error(error); | ||
|
||
return None; | ||
} | ||
}; | ||
|
||
let mut result: Vec<u8> = result.into_owned(); | ||
result.shrink_to_fit(); | ||
|
||
let wasm = wasm_byte_vec_t { | ||
size: result.len(), | ||
data: result.as_mut_ptr(), | ||
}; | ||
|
||
Some(Box::new(wasm)) | ||
} |
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