Rename Instance to InstanceHandle.
This commit is contained in:
@@ -7,7 +7,7 @@ use core::{fmt, mem, ptr, slice};
|
||||
use cranelift_codegen::ir;
|
||||
use std::string::String;
|
||||
use std::vec::Vec;
|
||||
use wasmtime_runtime::{wasmtime_call_trampoline, Export, Instance};
|
||||
use wasmtime_runtime::{wasmtime_call_trampoline, Export, InstanceHandle};
|
||||
|
||||
/// A runtime value.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
@@ -125,10 +125,10 @@ pub enum ActionError {
|
||||
Type(String),
|
||||
}
|
||||
|
||||
/// Invoke a function in an `Instance` identified by an export name.
|
||||
/// Invoke a function through an `InstanceHandle` identified by an export name.
|
||||
pub fn invoke(
|
||||
compiler: &mut Compiler,
|
||||
instance: &mut Instance,
|
||||
instance: &mut InstanceHandle,
|
||||
function_name: &str,
|
||||
args: &[RuntimeValue],
|
||||
) -> Result<ActionOutcome, ActionError> {
|
||||
@@ -220,7 +220,7 @@ pub fn invoke(
|
||||
|
||||
/// Returns a slice of the contents of allocated linear memory.
|
||||
pub fn inspect_memory<'instance>(
|
||||
instance: &'instance Instance,
|
||||
instance: &'instance InstanceHandle,
|
||||
memory_name: &str,
|
||||
start: usize,
|
||||
len: usize,
|
||||
@@ -251,8 +251,8 @@ pub fn inspect_memory<'instance>(
|
||||
})
|
||||
}
|
||||
|
||||
/// Read a global in this `Instance` identified by an export name.
|
||||
pub fn get(instance: &Instance, global_name: &str) -> Result<RuntimeValue, ActionError> {
|
||||
/// Read a global in the given instance identified by an export name.
|
||||
pub fn get(instance: &InstanceHandle, global_name: &str) -> Result<RuntimeValue, ActionError> {
|
||||
let (definition, global) = match unsafe { instance.lookup_immutable(global_name) } {
|
||||
Some(Export::Global {
|
||||
definition,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::action::{get, inspect_memory, invoke};
|
||||
use crate::{
|
||||
instantiate, ActionError, ActionOutcome, Compiler, Instance, Namespace, RuntimeValue,
|
||||
instantiate, ActionError, ActionOutcome, Compiler, InstanceHandle, Namespace, RuntimeValue,
|
||||
SetupError,
|
||||
};
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
@@ -86,7 +86,7 @@ impl Context {
|
||||
}
|
||||
}
|
||||
|
||||
fn instantiate(&mut self, data: &[u8]) -> Result<Instance, SetupError> {
|
||||
fn instantiate(&mut self, data: &[u8]) -> Result<InstanceHandle, SetupError> {
|
||||
self.validate(&data).map_err(SetupError::Validate)?;
|
||||
|
||||
instantiate(
|
||||
@@ -98,7 +98,10 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Return the instance associated with the given name.
|
||||
pub fn get_instance(&mut self, instance_name: &str) -> Result<&mut Instance, UnknownInstance> {
|
||||
pub fn get_instance(
|
||||
&mut self,
|
||||
instance_name: &str,
|
||||
) -> Result<&mut InstanceHandle, UnknownInstance> {
|
||||
self.namespace
|
||||
.get_instance(instance_name)
|
||||
.ok_or_else(|| UnknownInstance {
|
||||
@@ -111,21 +114,21 @@ impl Context {
|
||||
&mut self,
|
||||
instance_name: Option<String>,
|
||||
data: &[u8],
|
||||
) -> Result<Instance, ActionError> {
|
||||
) -> Result<InstanceHandle, ActionError> {
|
||||
let instance = self.instantiate(data).map_err(ActionError::Setup)?;
|
||||
self.optionally_name_instance(instance_name, instance.clone());
|
||||
Ok(instance)
|
||||
}
|
||||
|
||||
/// If `name` isn't None, register it for the given instance.
|
||||
pub fn optionally_name_instance(&mut self, name: Option<String>, instance: Instance) {
|
||||
pub fn optionally_name_instance(&mut self, name: Option<String>, instance: InstanceHandle) {
|
||||
if let Some(name) = name {
|
||||
self.namespace.name_instance(name, instance);
|
||||
}
|
||||
}
|
||||
|
||||
/// Register a name for the given instance.
|
||||
pub fn name_instance(&mut self, name: String, instance: Instance) {
|
||||
pub fn name_instance(&mut self, name: String, instance: InstanceHandle) {
|
||||
self.namespace.name_instance(name, instance);
|
||||
}
|
||||
|
||||
@@ -154,7 +157,7 @@ impl Context {
|
||||
/// Invoke an exported function from an instance.
|
||||
pub fn invoke(
|
||||
&mut self,
|
||||
instance: &mut Instance,
|
||||
instance: &mut InstanceHandle,
|
||||
field: &str,
|
||||
args: &[RuntimeValue],
|
||||
) -> Result<ActionOutcome, ActionError> {
|
||||
@@ -175,7 +178,11 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Get the value of an exported global variable from an instance.
|
||||
pub fn get(&mut self, instance: &Instance, field: &str) -> Result<ActionOutcome, ActionError> {
|
||||
pub fn get(
|
||||
&mut self,
|
||||
instance: &InstanceHandle,
|
||||
field: &str,
|
||||
) -> Result<ActionOutcome, ActionError> {
|
||||
get(instance, field).map(|value| ActionOutcome::Returned {
|
||||
values: vec![value],
|
||||
})
|
||||
@@ -184,7 +191,7 @@ impl Context {
|
||||
/// Get a slice of memory from an instance.
|
||||
pub fn inspect_memory<'instance>(
|
||||
&self,
|
||||
instance: &'instance Instance,
|
||||
instance: &'instance InstanceHandle,
|
||||
field_name: &str,
|
||||
start: usize,
|
||||
len: usize,
|
||||
|
||||
@@ -18,7 +18,7 @@ use wasmtime_environ::{
|
||||
CompileError, DataInitializer, DataInitializerLocation, Module, ModuleEnvironment,
|
||||
};
|
||||
use wasmtime_runtime::{
|
||||
Export, Imports, Instance, InstantiationError, VMFunctionBody, VMSharedSignatureIndex,
|
||||
Export, Imports, InstanceHandle, InstantiationError, VMFunctionBody, VMSharedSignatureIndex,
|
||||
};
|
||||
|
||||
/// An error condition while setting up a wasm instance, be it validation,
|
||||
@@ -160,12 +160,12 @@ impl CompiledModule {
|
||||
}
|
||||
}
|
||||
|
||||
/// Crate an `Instance` from this `CompiledModule`.
|
||||
/// Crate an `InstanceContents` from this `CompiledModule`.
|
||||
///
|
||||
/// Note that if only one instance of this module is needed, it may be more
|
||||
/// efficient to call the top-level `instantiate`, since that avoids copying
|
||||
/// the data initializers.
|
||||
pub fn instantiate(&mut self) -> Result<Instance, InstantiationError> {
|
||||
pub fn instantiate(&mut self) -> Result<InstanceHandle, InstantiationError> {
|
||||
let data_initializers = self
|
||||
.data_initializers
|
||||
.iter()
|
||||
@@ -174,7 +174,7 @@ impl CompiledModule {
|
||||
data: &*init.data,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
Instance::new(
|
||||
InstanceHandle::new(
|
||||
Rc::clone(&self.module),
|
||||
Rc::clone(&self.global_exports),
|
||||
self.finished_functions.clone(),
|
||||
@@ -205,7 +205,7 @@ impl OwnedDataInitializer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new `Instance` by compiling the wasm module in `data` and instatiating it.
|
||||
/// Create a new wasm instance by compiling the wasm module in `data` and instatiating it.
|
||||
///
|
||||
/// This is equivalent to createing a `CompiledModule` and calling `instantiate()` on it,
|
||||
/// but avoids creating an intermediate copy of the data initializers.
|
||||
@@ -214,10 +214,10 @@ pub fn instantiate(
|
||||
data: &[u8],
|
||||
resolver: &mut dyn Resolver,
|
||||
global_exports: Rc<RefCell<HashMap<String, Option<Export>>>>,
|
||||
) -> Result<Instance, SetupError> {
|
||||
) -> Result<InstanceHandle, SetupError> {
|
||||
let raw = RawCompiledModule::new(compiler, data, resolver)?;
|
||||
|
||||
Instance::new(
|
||||
InstanceHandle::new(
|
||||
Rc::new(raw.module),
|
||||
global_exports,
|
||||
raw.finished_functions,
|
||||
|
||||
@@ -36,8 +36,6 @@ use hashbrown::{hash_map, HashMap};
|
||||
#[cfg(feature = "std")]
|
||||
use std::collections::{hash_map, HashMap};
|
||||
|
||||
#[macro_use]
|
||||
extern crate cranelift_entity;
|
||||
#[macro_use]
|
||||
extern crate failure_derive;
|
||||
|
||||
@@ -60,9 +58,9 @@ pub use crate::namespace::Namespace;
|
||||
pub use crate::resolver::{NullResolver, Resolver};
|
||||
pub use crate::target_tunables::target_tunables;
|
||||
|
||||
// Re-export `Instance` so that users won't need to separately depend on
|
||||
// Re-export `InstanceHandle` so that users won't need to separately depend on
|
||||
// wasmtime-runtime in common cases.
|
||||
pub use wasmtime_runtime::{Instance, InstantiationError};
|
||||
pub use wasmtime_runtime::{InstanceHandle, InstantiationError};
|
||||
|
||||
/// Version number of this crate.
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
@@ -12,7 +12,7 @@ use wasmtime_environ::{
|
||||
};
|
||||
use wasmtime_runtime::libcalls;
|
||||
use wasmtime_runtime::{
|
||||
Export, Imports, Instance, LinkError, VMFunctionBody, VMFunctionImport, VMGlobalImport,
|
||||
Export, Imports, InstanceHandle, LinkError, VMFunctionBody, VMFunctionImport, VMGlobalImport,
|
||||
VMMemoryImport, VMTableImport,
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ pub fn link_module(
|
||||
signature, import_signature)
|
||||
));
|
||||
}
|
||||
dependencies.insert(Instance::from_vmctx(vmctx));
|
||||
dependencies.insert(InstanceHandle::from_vmctx(vmctx));
|
||||
function_imports.push(VMFunctionImport {
|
||||
body: address,
|
||||
vmctx,
|
||||
@@ -82,7 +82,7 @@ pub fn link_module(
|
||||
module_name, field,
|
||||
)));
|
||||
}
|
||||
dependencies.insert(Instance::from_vmctx(vmctx));
|
||||
dependencies.insert(InstanceHandle::from_vmctx(vmctx));
|
||||
table_imports.push(VMTableImport {
|
||||
from: definition,
|
||||
vmctx,
|
||||
@@ -136,7 +136,7 @@ pub fn link_module(
|
||||
}
|
||||
assert!(memory.offset_guard_size >= import_memory.offset_guard_size);
|
||||
|
||||
dependencies.insert(Instance::from_vmctx(vmctx));
|
||||
dependencies.insert(InstanceHandle::from_vmctx(vmctx));
|
||||
memory_imports.push(VMMemoryImport {
|
||||
from: definition,
|
||||
vmctx,
|
||||
@@ -180,7 +180,7 @@ pub fn link_module(
|
||||
module_name, field
|
||||
)));
|
||||
}
|
||||
dependencies.insert(Instance::from_vmctx(vmctx));
|
||||
dependencies.insert(InstanceHandle::from_vmctx(vmctx));
|
||||
global_imports.push(VMGlobalImport { from: definition });
|
||||
}
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use super::HashMap;
|
||||
use crate::resolver::Resolver;
|
||||
use std::string::String;
|
||||
use wasmtime_runtime::{Export, Instance};
|
||||
use wasmtime_runtime::{Export, InstanceHandle};
|
||||
|
||||
/// A namespace containing instances keyed by name.
|
||||
///
|
||||
@@ -13,7 +13,7 @@ use wasmtime_runtime::{Export, Instance};
|
||||
/// imports using defined exports.
|
||||
pub struct Namespace {
|
||||
/// Mapping from identifiers to indices in `self.instances`.
|
||||
names: HashMap<String, Instance>,
|
||||
names: HashMap<String, InstanceHandle>,
|
||||
}
|
||||
|
||||
impl Namespace {
|
||||
@@ -24,14 +24,14 @@ impl Namespace {
|
||||
}
|
||||
}
|
||||
|
||||
/// Install a new `Instance` in this `Namespace`, optionally with the
|
||||
/// given name, and return its index.
|
||||
pub fn name_instance(&mut self, name: String, instance: Instance) {
|
||||
/// Install a new `InstanceHandle` in this `Namespace`, optionally with the
|
||||
/// given name.
|
||||
pub fn name_instance(&mut self, name: String, instance: InstanceHandle) {
|
||||
self.names.insert(name, instance);
|
||||
}
|
||||
|
||||
/// Get the instance index registered with the given `instance_name`.
|
||||
pub fn get_instance(&mut self, name: &str) -> Option<&mut Instance> {
|
||||
/// Get the instance registered with the given `instance_name`.
|
||||
pub fn get_instance(&mut self, name: &str) -> Option<&mut InstanceHandle> {
|
||||
self.names.get_mut(name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user