Document the wasmtime::Instance APIs (#814)
* Document the `wasmtime::Instance` APIs This documents oddities like the import list and export list and how to match them all up. Addtionally this largely just expands all the docs related to `Instance` to get filled out. This also moves the `set_signal_handler` functions into platform-specific modules in order to follow Rust idioms about how to expose platform-specific information. Additionally the methods are marked `unsafe` because I figure anything having to do with signal handling is `unsafe` inherently. I don't actually know what these functions do, so they're currently still undocumented. * Fix build of python bindings * Fix some rebase conflicts
This commit is contained in:
@@ -94,7 +94,7 @@ impl WastContext {
|
||||
.get(import.module())
|
||||
.ok_or_else(|| anyhow!("no module named `{}`", import.module()))?;
|
||||
let export = instance
|
||||
.find_export_by_name(import.name())
|
||||
.get_export(import.name())
|
||||
.ok_or_else(|| anyhow!("unknown import `{}::{}`", import.name(), import.module()))?
|
||||
.clone();
|
||||
imports.push(export);
|
||||
@@ -165,13 +165,10 @@ impl WastContext {
|
||||
args: &[Val],
|
||||
) -> Result<Outcome> {
|
||||
let instance = self.get_instance(instance_name.as_ref().map(|x| &**x))?;
|
||||
let export = instance
|
||||
.find_export_by_name(field)
|
||||
.ok_or_else(|| anyhow!("no global named `{}`", field))?;
|
||||
let func = match export {
|
||||
Extern::Func(f) => f,
|
||||
_ => bail!("export of `{}` wasn't a global", field),
|
||||
};
|
||||
let func = instance
|
||||
.get_export(field)
|
||||
.and_then(|e| e.func())
|
||||
.ok_or_else(|| anyhow!("no function named `{}`", field))?;
|
||||
Ok(match func.call(args) {
|
||||
Ok(result) => Outcome::Ok(result.into()),
|
||||
Err(e) => Outcome::Trap(e),
|
||||
@@ -181,13 +178,10 @@ impl WastContext {
|
||||
/// Get the value of an exported global from an instance.
|
||||
fn get(&mut self, instance_name: Option<&str>, field: &str) -> Result<Outcome> {
|
||||
let instance = self.get_instance(instance_name.as_ref().map(|x| &**x))?;
|
||||
let export = instance
|
||||
.find_export_by_name(field)
|
||||
let global = instance
|
||||
.get_export(field)
|
||||
.and_then(|e| e.global())
|
||||
.ok_or_else(|| anyhow!("no global named `{}`", field))?;
|
||||
let global = match export {
|
||||
Extern::Global(g) => g,
|
||||
_ => bail!("export of `{}` wasn't a global", field),
|
||||
};
|
||||
Ok(Outcome::Ok(vec![global.get()]))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user