diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-11-27 05:54:28 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 19:24:28 +0530 |
commit | ca66978a5aadddf7895b49b44076c574e7e6a0b0 (patch) | |
tree | 65d93f524bc5fea23cef4e75b02de275833158e1 /ops/attrs.rs | |
parent | 9ffc6acdbb3326dde74c803332547b0ae33e483a (diff) |
feat(ops): fast calls for Wasm (#16776)
This PR introduces Wasm ops. These calls are optimized for entry from
Wasm land.
The `#[op(wasm)]` attribute is opt-in.
Last parameter `Option<&mut [u8]>` is the memory slice of the Wasm
module *when entered from a Fast API call*. Otherwise, the user is
expected to implement logic to obtain the memory if `None`
```rust
#[op(wasm)]
pub fn op_args_get(
offset: i32,
buffer_offset: i32,
memory: Option<&mut [u8]>,
) {
// ...
}
```
Diffstat (limited to 'ops/attrs.rs')
-rw-r--r-- | ops/attrs.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ops/attrs.rs b/ops/attrs.rs index 95374ef36..4d298d7ed 100644 --- a/ops/attrs.rs +++ b/ops/attrs.rs @@ -11,6 +11,7 @@ pub struct Attributes { pub is_v8: bool, pub must_be_fast: bool, pub deferred: bool, + pub is_wasm: bool, } impl Parse for Attributes { @@ -20,18 +21,22 @@ impl Parse for Attributes { let vars: Vec<_> = vars.iter().map(Ident::to_string).collect(); let vars: Vec<_> = vars.iter().map(String::as_str).collect(); for var in vars.iter() { - if !["unstable", "v8", "fast", "deferred"].contains(var) { + if !["unstable", "v8", "fast", "deferred", "wasm"].contains(var) { return Err(Error::new( input.span(), - "invalid attribute, expected one of: unstable, v8, fast, deferred", + "invalid attribute, expected one of: unstable, v8, fast, deferred, wasm", )); } } + + let is_wasm = vars.contains(&"wasm"); + Ok(Self { is_unstable: vars.contains(&"unstable"), is_v8: vars.contains(&"v8"), - must_be_fast: vars.contains(&"fast"), deferred: vars.contains(&"deferred"), + must_be_fast: is_wasm || vars.contains(&"fast"), + is_wasm, }) } } |