feat(interface-types) Change Instance::local_or_import(&self) to Instance::local_or_import(&mut self).

It allows the instance to create or update locals/imports when the
`local_or_import` function is called. It's not ideal, but fine enough
for a first step.
This commit is contained in:
Ivan Enderlin 2019-10-03 00:13:07 +02:00
parent 99c9fc44dc
commit 207d69fdbd
8 changed files with 13 additions and 15 deletions

2
Cargo.lock generated
View File

@ -1594,8 +1594,6 @@ name = "wasmer-interface-types"
version = "0.7.0"
dependencies = [
"nom 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.7.0",
"wasmer-runtime-core 0.7.0",
]
[[package]]

View File

@ -6,7 +6,7 @@ use crate::interpreter::wasm::{
executable_instruction!(
call(function_index: usize, instruction_name: String) -> _ {
move |runtime| -> _ {
let instance = runtime.wasm_instance;
let instance = &mut runtime.wasm_instance;
let index = FunctionIndex::new(function_index);
match instance.local_or_import(index) {

View File

@ -3,7 +3,7 @@ use crate::interpreter::wasm::values::InterfaceType;
executable_instruction!(
call_export(export_name: String, instruction_name: String) -> _ {
move |runtime| -> _ {
let instance = runtime.wasm_instance;
let instance = &mut runtime.wasm_instance;
match instance.export(&export_name) {
Some(export) => {

View File

@ -175,7 +175,7 @@ pub(crate) mod tests {
}
fn local_or_import<I: wasm::structures::TypedIndex + wasm::structures::LocalImportIndex>(
&self,
&mut self,
index: I,
) -> Option<&LocalImport> {
self.locals_or_imports.get(&index.index())

View File

@ -4,7 +4,7 @@ use std::convert::TryInto;
executable_instruction!(
write_utf8(allocator_name: String, instruction_name: String) -> _ {
move |runtime| -> _ {
let instance = runtime.wasm_instance;
let instance = &mut runtime.wasm_instance;
match instance.export(&allocator_name) {
Some(allocator) => {
@ -17,7 +17,7 @@ executable_instruction!(
))
}
match runtime.wasm_instance.memory(0) {
match instance.memory(0) {
Some(memory) => match runtime.stack.pop1() {
Some(string) => {
let memory_view = memory.view();

View File

@ -18,7 +18,7 @@ where
{
invocation_inputs: &'invocation [InterfaceValue],
stack: Stack<InterfaceValue>,
wasm_instance: &'instance Instance,
wasm_instance: &'instance mut Instance,
_phantom: PhantomData<(Export, LocalImport, Memory, MemoryView)>,
}
@ -58,7 +58,7 @@ where
pub fn run(
&self,
invocation_inputs: &[InterfaceValue],
wasm_instance: &Instance,
wasm_instance: &mut Instance,
) -> Result<Stack<InterfaceValue>, String> {
let mut runtime = Runtime {
invocation_inputs,

View File

@ -70,7 +70,7 @@ where
MV: MemoryView,
{
fn export(&self, export_name: &str) -> Option<&E>;
fn local_or_import<I: TypedIndex + LocalImportIndex>(&self, index: I) -> Option<&LI>;
fn local_or_import<I: TypedIndex + LocalImportIndex>(&mut self, index: I) -> Option<&LI>;
fn memory(&self, index: usize) -> Option<&M>;
}
@ -151,7 +151,7 @@ where
None
}
fn local_or_import<I: TypedIndex + LocalImportIndex>(&self, _index: I) -> Option<&LI> {
fn local_or_import<I: TypedIndex + LocalImportIndex>(&mut self, _index: I) -> Option<&LI> {
None
}
}

View File

@ -68,8 +68,8 @@ macro_rules! test_executable_instruction {
(&vec![$($instructions),*]).try_into().unwrap();
let invocation_inputs = vec![$($invocation_inputs),*];
let instance = $instance;
let run = interpreter.run(&invocation_inputs, &instance);
let mut instance = $instance;
let run = interpreter.run(&invocation_inputs, &mut instance);
assert!(run.is_ok());
@ -102,8 +102,8 @@ macro_rules! test_executable_instruction {
(&vec![$($instructions),*]).try_into().unwrap();
let invocation_inputs = vec![$($invocation_inputs),*];
let instance = $instance;
let run = interpreter.run(&invocation_inputs, &instance);
let mut instance = $instance;
let run = interpreter.run(&invocation_inputs, &mut instance);
assert!(run.is_err());