mirror of
https://github.com/fluencelabs/interface-types
synced 2025-04-24 23:32:13 +00:00
chore(interface-types) Re-order match arms.
This commit is contained in:
parent
07055522a1
commit
77546784cf
@ -107,6 +107,65 @@ where
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
Instruction::Call { function_index: index } => {
|
||||
let index = index.to_owned();
|
||||
let instruction_name: String = instruction.into();
|
||||
|
||||
Box::new(move |runtime: &mut Runtime<Instance, Export, LocalImport, Memory>| -> Result<(), _> {
|
||||
let instance = runtime.wasm_instance;
|
||||
let function_index = FunctionIndex::new(index);
|
||||
|
||||
match instance.local_or_import(function_index) {
|
||||
Some(local_or_import) => {
|
||||
let inputs_cardinality = local_or_import.inputs_cardinality();
|
||||
|
||||
match runtime.stack.pop(inputs_cardinality) {
|
||||
Some(inputs) => {
|
||||
let input_types = inputs
|
||||
.iter()
|
||||
.map(|input| input.into())
|
||||
.collect::<Vec<InterfaceType>>();
|
||||
|
||||
if input_types != local_or_import.inputs() {
|
||||
return Err(format!(
|
||||
"`{}` cannot call the local or imported function `{}` because the value types on the stack mismatch the function signature (expects {:?}).",
|
||||
instruction_name,
|
||||
index,
|
||||
local_or_import.inputs(),
|
||||
))
|
||||
}
|
||||
|
||||
match local_or_import.call(&inputs) {
|
||||
Ok(outputs) => {
|
||||
for output in outputs.iter() {
|
||||
runtime.stack.push(output.clone());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(format!(
|
||||
"`{}` failed when calling the local or imported function `{}`.",
|
||||
instruction_name,
|
||||
index
|
||||
))
|
||||
}
|
||||
}
|
||||
None => Err(format!(
|
||||
"`{}` cannot call the local or imported function `{}` because there is no enough data on the stack for the arguments (needs {}).",
|
||||
instruction_name,
|
||||
index,
|
||||
inputs_cardinality,
|
||||
))
|
||||
}
|
||||
}
|
||||
None => Err(format!(
|
||||
"`{}` cannot call the local or imported function `{}` because it doesn't exist.",
|
||||
instruction_name,
|
||||
index,
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
Instruction::CallExport { export_name } => {
|
||||
let export_name = (*export_name).to_owned();
|
||||
let instruction_name: String = instruction.into();
|
||||
@ -215,65 +274,6 @@ where
|
||||
}
|
||||
})
|
||||
}
|
||||
Instruction::Call { function_index: index } => {
|
||||
let index = index.to_owned();
|
||||
let instruction_name: String = instruction.into();
|
||||
|
||||
Box::new(move |runtime: &mut Runtime<Instance, Export, LocalImport, Memory>| -> Result<(), _> {
|
||||
let instance = runtime.wasm_instance;
|
||||
let function_index = FunctionIndex::new(index);
|
||||
|
||||
match instance.local_or_import(function_index) {
|
||||
Some(local_or_import) => {
|
||||
let inputs_cardinality = local_or_import.inputs_cardinality();
|
||||
|
||||
match runtime.stack.pop(inputs_cardinality) {
|
||||
Some(inputs) => {
|
||||
let input_types = inputs
|
||||
.iter()
|
||||
.map(|input| input.into())
|
||||
.collect::<Vec<InterfaceType>>();
|
||||
|
||||
if input_types != local_or_import.inputs() {
|
||||
return Err(format!(
|
||||
"`{}` cannot call the local or imported function `{}` because the value types on the stack mismatch the function signature (expects {:?}).",
|
||||
instruction_name,
|
||||
index,
|
||||
local_or_import.inputs(),
|
||||
))
|
||||
}
|
||||
|
||||
match local_or_import.call(&inputs) {
|
||||
Ok(outputs) => {
|
||||
for output in outputs.iter() {
|
||||
runtime.stack.push(output.clone());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(format!(
|
||||
"`{}` failed when calling the local or imported function `{}`.",
|
||||
instruction_name,
|
||||
index
|
||||
))
|
||||
}
|
||||
}
|
||||
None => Err(format!(
|
||||
"`{}` cannot call the local or imported function `{}` because there is no enough data on the stack for the arguments (needs {}).",
|
||||
instruction_name,
|
||||
index,
|
||||
inputs_cardinality,
|
||||
))
|
||||
}
|
||||
}
|
||||
None => Err(format!(
|
||||
"`{}` cannot call the local or imported function `{}` because it doesn't exist.",
|
||||
instruction_name,
|
||||
index,
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user