mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 05:48:45 +00:00
Fixed lint again
This commit is contained in:
@@ -7,6 +7,7 @@ use js_sys::Uint8Array;
|
||||
/// A mutable Wasm-memory location.
|
||||
pub struct WasmCell<'a, T: ?Sized> {
|
||||
pub(crate) memory: Uint8Array,
|
||||
#[allow(dead_code)]
|
||||
phantom: &'a PhantomData<T>,
|
||||
}
|
||||
|
||||
|
||||
4
lib/js-api/src/externals/function.rs
vendored
4
lib/js-api/src/externals/function.rs
vendored
@@ -301,7 +301,7 @@ impl Function {
|
||||
let as_table = ft.unchecked_ref::<js_sys::WebAssembly::Table>();
|
||||
let func = as_table.get(address).unwrap();
|
||||
let binded_func = func.bind1(&JsValue::UNDEFINED, &JsValue::UNDEFINED);
|
||||
let ty = FunctionType::new(Args::wasm_types(), Rets::wasm_types());
|
||||
let ty = function.ty();
|
||||
Self {
|
||||
store: store.clone(),
|
||||
exported: VMFunction::new(binded_func, ty, None),
|
||||
@@ -347,7 +347,7 @@ impl Function {
|
||||
let ft = wasm_bindgen::function_table();
|
||||
let as_table = ft.unchecked_ref::<js_sys::WebAssembly::Table>();
|
||||
let func = as_table.get(address).unwrap();
|
||||
let ty = FunctionType::new(Args::wasm_types(), Rets::wasm_types());
|
||||
let ty = function.ty();
|
||||
let environment = Box::new(env);
|
||||
let binded_func = func.bind1(
|
||||
&JsValue::UNDEFINED,
|
||||
|
||||
@@ -60,198 +60,6 @@
|
||||
//!
|
||||
//! For more examples of using the `wasmer` API, check out the
|
||||
//! [wasmer examples][wasmer-examples].
|
||||
//!
|
||||
//! ---------
|
||||
//!
|
||||
//! # Table of Contents
|
||||
//!
|
||||
//! - [Wasm Primitives](#wasm-primitives)
|
||||
//! - [Externs](#externs)
|
||||
//! - [Functions](#functions)
|
||||
//! - [Memories](#memories)
|
||||
//! - [Globals](#globals)
|
||||
//! - [Tables](#tables)
|
||||
//! - [Project Layout](#project-layout)
|
||||
//! - [Engines](#engines)
|
||||
//! - [Compilers](#compilers)
|
||||
//! - [Features](#features)
|
||||
//!
|
||||
//!
|
||||
//! # Wasm Primitives
|
||||
//! In order to make use of the power of the `wasmer` API, it's important
|
||||
//! to understand the primitives around which the API is built.
|
||||
//!
|
||||
//! Wasm only deals with a small number of core data types, these data
|
||||
//! types can be found in the [`Value`] type.
|
||||
//!
|
||||
//! In addition to the core Wasm types, the core types of the API are
|
||||
//! referred to as "externs".
|
||||
//!
|
||||
//! ## Externs
|
||||
//! An [`Extern`] is a type that can be imported or exported from a Wasm
|
||||
//! module.
|
||||
//!
|
||||
//! To import an extern, simply give it a namespace and a name with the
|
||||
//! [`imports`] macro:
|
||||
//!
|
||||
//! ```
|
||||
//! # use wasmer::{imports, Function, Memory, MemoryType, Store, ImportObject};
|
||||
//! # fn imports_example(store: &Store) -> ImportObject {
|
||||
//! let memory = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
|
||||
//! imports! {
|
||||
//! "env" => {
|
||||
//! "my_function" => Function::new_native(store, || println!("Hello")),
|
||||
//! "memory" => memory,
|
||||
//! }
|
||||
//! }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! And to access an exported extern, see the [`Exports`] API, accessible
|
||||
//! from any instance via `instance.exports`:
|
||||
//!
|
||||
//! ```
|
||||
//! # use wasmer::{imports, Instance, Function, Memory, NativeFunc};
|
||||
//! # fn exports_example(instance: &Instance) -> anyhow::Result<()> {
|
||||
//! let memory = instance.exports.get_memory("memory")?;
|
||||
//! let memory: &Memory = instance.exports.get("some_other_memory")?;
|
||||
//! let add: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?;
|
||||
//! let result = add.call(5, 37)?;
|
||||
//! assert_eq!(result, 42);
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! These are the primary types that the `wasmer` API uses.
|
||||
//!
|
||||
//! ### Functions
|
||||
//! There are 2 types of functions in `wasmer`:
|
||||
//! 1. Wasm functions
|
||||
//! 2. Host functions
|
||||
//!
|
||||
//! A Wasm function is a function defined in a WebAssembly module that can
|
||||
//! only perform computation without side effects and call other functions.
|
||||
//!
|
||||
//! Wasm functions take 0 or more arguments and return 0 or more results.
|
||||
//! Wasm functions can only deal with the primitive types defined in
|
||||
//! [`Value`].
|
||||
//!
|
||||
//! A Host function is any function implemented on the host, in this case in
|
||||
//! Rust.
|
||||
//!
|
||||
//! Host functions can optionally be created with an environment that
|
||||
//! implements [`WasmerEnv`]. This environment is useful for maintaining
|
||||
//! host state (for example the filesystem in WASI).
|
||||
//!
|
||||
//! Thus WebAssembly modules by themselves cannot do anything but computation
|
||||
//! on the core types in [`Value`]. In order to make them more useful we
|
||||
//! give them access to the outside world with [`imports`].
|
||||
//!
|
||||
//! If you're looking for a sandboxed, POSIX-like environment to execute Wasm
|
||||
//! in, check out the [`wasmer-wasi`][wasmer-wasi] crate for our implementation of WASI,
|
||||
//! the WebAssembly System Interface.
|
||||
//!
|
||||
//! In the `wasmer` API we support functions which take their arguments and
|
||||
//! return their results dynamically, [`Function`], and functions which
|
||||
//! take their arguments and return their results statically, [`NativeFunc`].
|
||||
//!
|
||||
//! ### Memories
|
||||
//! Memories store data.
|
||||
//!
|
||||
//! In most Wasm programs, nearly all data will live in a [`Memory`].
|
||||
//!
|
||||
//! This data can be shared between the host and guest to allow for more
|
||||
//! interesting programs.
|
||||
//!
|
||||
//! ### Globals
|
||||
//! A [`Global`] is a type that may be either mutable or immutable, and
|
||||
//! contains one of the core Wasm types defined in [`Value`].
|
||||
//!
|
||||
//! ### Tables
|
||||
//! A [`Table`] is an indexed list of items.
|
||||
//!
|
||||
//!
|
||||
//! ## Project Layout
|
||||
//!
|
||||
//! The Wasmer project is divided into a number of crates, below is a dependency
|
||||
//! graph with transitive dependencies removed.
|
||||
//!
|
||||
//! <div>
|
||||
//! <img src="https://raw.githubusercontent.com/wasmerio/wasmer/master/docs/deps_dedup.svg" />
|
||||
//! </div>
|
||||
//!
|
||||
//! While this crate is the top level API, we also publish crates built
|
||||
//! on top of this API that you may be interested in using, including:
|
||||
//!
|
||||
//! - [wasmer-cache][] for caching compiled Wasm modules.
|
||||
//! - [wasmer-emscripten][] for running Wasm modules compiled to the
|
||||
//! Emscripten ABI.
|
||||
//! - [wasmer-wasi][] for running Wasm modules compiled to the WASI ABI.
|
||||
//!
|
||||
//! --------
|
||||
//!
|
||||
//! The Wasmer project has two major abstractions:
|
||||
//! 1. [Engines][wasmer-engine]
|
||||
//! 2. [Compilers][wasmer-compiler]
|
||||
//!
|
||||
//! These two abstractions have multiple options that can be enabled
|
||||
//! with features.
|
||||
//!
|
||||
//! ### Engines
|
||||
//!
|
||||
//! An engine is a system that uses a compiler to make a WebAssembly
|
||||
//! module executable.
|
||||
//!
|
||||
//! ### Compilers
|
||||
//!
|
||||
//! A compiler is a system that handles the details of making a Wasm
|
||||
//! module executable. For example, by generating native machine code
|
||||
//! for each Wasm function.
|
||||
//!
|
||||
//!
|
||||
//! ## Features
|
||||
//!
|
||||
//! This crate's features can be broken down into 2 kinds, features that
|
||||
//! enable new functionality and features that set defaults.
|
||||
//!
|
||||
//! The features that enable new functionality are:
|
||||
//! - `universal` - enable the Universal engine. (See [wasmer-universal][])
|
||||
//! - `native` - enable the native engine. (See [wasmer-native][])
|
||||
//! - `cranelift` - enable Wasmer's Cranelift compiler. (See [wasmer-cranelift][])
|
||||
//! - `llvm` - enable Wasmer's LLVM compiler. (See [wasmer-llvm][])
|
||||
//! - `singlepass` - enable Wasmer's Singlepass compiler. (See [wasmer-singlepass][])
|
||||
//! - `wat` - enable `wasmer` to parse the WebAssembly text format.
|
||||
//!
|
||||
//! The features that set defaults come in sets that are mutually exclusive.
|
||||
//!
|
||||
//! The first set is the default compiler set:
|
||||
//! - `default-cranelift` - set Wasmer's Cranelift compiler as the default.
|
||||
//! - `default-llvm` - set Wasmer's LLVM compiler as the default.
|
||||
//! - `default-singlepass` - set Wasmer's Singlepass compiler as the default.
|
||||
//!
|
||||
//! The next set is the default engine set:
|
||||
//! - `default-universal` - set the Universal engine as the default.
|
||||
//! - `default-native` - set the native engine as the default.
|
||||
//!
|
||||
//! --------
|
||||
//!
|
||||
//! By default the `wat`, `default-cranelift`, and `default-universal` features
|
||||
//! are enabled.
|
||||
//!
|
||||
//!
|
||||
//!
|
||||
//! [wasm]: https://webassembly.org/
|
||||
//! [wasmer-examples]: https://github.com/wasmerio/wasmer/tree/master/examples
|
||||
//! [wasmer-cache]: https://docs.rs/wasmer-cache/*/wasmer_cache/
|
||||
//! [wasmer-compiler]: https://docs.rs/wasmer-compiler/*/wasmer_compiler/
|
||||
//! [wasmer-cranelift]: https://docs.rs/wasmer-compiler-cranelift/*/wasmer_compiler_cranelift/
|
||||
//! [wasmer-emscripten]: https://docs.rs/wasmer-emscripten/*/wasmer_emscripten/
|
||||
//! [wasmer-engine]: https://docs.rs/wasmer-engine/*/wasmer_engine/
|
||||
//! [wasmer-universal]: https://docs.rs/wasmer-engine-universal/*/wasmer_engine_universal/
|
||||
//! [wasmer-native]: https://docs.rs/wasmer-engine-dylib/*/wasmer_engine_dylib/
|
||||
//! [wasmer-singlepass]: https://docs.rs/wasmer-compiler-singlepass/*/wasmer_compiler_singlepass/
|
||||
//! [wasmer-llvm]: https://docs.rs/wasmer-compiler-llvm/*/wasmer_compiler_llvm/
|
||||
//! [wasmer-wasi]: https://docs.rs/wasmer-wasi/*/wasmer_wasi/
|
||||
|
||||
#[cfg(all(feature = "std", feature = "core"))]
|
||||
compile_error!(
|
||||
|
||||
@@ -86,13 +86,6 @@ impl<T: Copy, Ty> WasmPtr<T, Ty> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn align_pointer(ptr: usize, align: usize) -> usize {
|
||||
// clears bits below aligment amount (assumes power of 2) to align pointer
|
||||
debug_assert!(align.count_ones() == 1);
|
||||
ptr & !(align - 1)
|
||||
}
|
||||
|
||||
/// Methods for `WasmPtr`s to data that can be dereferenced, namely to types
|
||||
/// that implement [`ValueType`], meaning that they're valid for all possible
|
||||
/// bit patterns.
|
||||
|
||||
Reference in New Issue
Block a user