mirror of
https://github.com/fluencelabs/interface-types
synced 2025-04-24 23:32:13 +00:00
feat(interface-types) Rename ImportedFunction
to Import
.
So that we are consistent with `Export`.
This commit is contained in:
parent
a8da95b339
commit
11729b1d4c
@ -291,30 +291,30 @@ fn types<'input, E: ParseError<&'input [u8]>>(
|
||||
Ok((input, types))
|
||||
}
|
||||
|
||||
fn imported_functions<'input, E: ParseError<&'input [u8]>>(
|
||||
fn imports<'input, E: ParseError<&'input [u8]>>(
|
||||
input: &'input [u8],
|
||||
) -> IResult<&'input [u8], Vec<ImportedFunction>, E> {
|
||||
) -> IResult<&'input [u8], Vec<Import>, E> {
|
||||
let mut input = input;
|
||||
|
||||
consume!((input, number_of_imported_functions) = leb(input)?);
|
||||
consume!((input, number_of_imports) = leb(input)?);
|
||||
|
||||
let mut imported_functions = Vec::with_capacity(number_of_imported_functions as usize);
|
||||
let mut imports = Vec::with_capacity(number_of_imports as usize);
|
||||
|
||||
for _ in 0..number_of_imported_functions {
|
||||
consume!((input, imported_function_namespace) = string(input)?);
|
||||
consume!((input, imported_function_name) = string(input)?);
|
||||
consume!((input, imported_function_input_types) = list(input, ty)?);
|
||||
consume!((input, imported_function_output_types) = list(input, ty)?);
|
||||
for _ in 0..number_of_imports {
|
||||
consume!((input, import_namespace) = string(input)?);
|
||||
consume!((input, import_name) = string(input)?);
|
||||
consume!((input, import_input_types) = list(input, ty)?);
|
||||
consume!((input, import_output_types) = list(input, ty)?);
|
||||
|
||||
imported_functions.push(ImportedFunction {
|
||||
namespace: imported_function_namespace,
|
||||
name: imported_function_name,
|
||||
input_types: imported_function_input_types,
|
||||
output_types: imported_function_output_types,
|
||||
imports.push(Import {
|
||||
namespace: import_namespace,
|
||||
name: import_name,
|
||||
input_types: import_input_types,
|
||||
output_types: import_output_types,
|
||||
});
|
||||
}
|
||||
|
||||
Ok((input, imported_functions))
|
||||
Ok((input, imports))
|
||||
}
|
||||
|
||||
fn adapters<'input, E: ParseError<&'input [u8]>>(
|
||||
@ -406,7 +406,7 @@ pub fn parse<'input, E: ParseError<&'input [u8]>>(
|
||||
|
||||
consume!((input, exports) = exports(input)?);
|
||||
consume!((input, types) = types(input)?);
|
||||
consume!((input, imported_functions) = imported_functions(input)?);
|
||||
consume!((input, imports) = imports(input)?);
|
||||
consume!((input, adapters) = adapters(input)?);
|
||||
consume!((input, forwards) = forwards(input)?);
|
||||
|
||||
@ -415,7 +415,7 @@ pub fn parse<'input, E: ParseError<&'input [u8]>>(
|
||||
Interfaces {
|
||||
exports,
|
||||
types,
|
||||
imported_functions,
|
||||
imports,
|
||||
adapters,
|
||||
forwards,
|
||||
},
|
||||
@ -634,9 +634,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_imported_functions() {
|
||||
fn test_imports() {
|
||||
let input = &[
|
||||
0x02, // 2 imported functions
|
||||
0x02, // 2 imports
|
||||
0x01, // string of 1 byte
|
||||
0x61, // "a"
|
||||
0x01, // string of 1 byte
|
||||
@ -657,13 +657,13 @@ mod tests {
|
||||
let output = Ok((
|
||||
&[] as &[u8],
|
||||
vec![
|
||||
ImportedFunction {
|
||||
Import {
|
||||
namespace: "a",
|
||||
name: "b",
|
||||
input_types: vec![InterfaceType::I32],
|
||||
output_types: vec![InterfaceType::I64],
|
||||
},
|
||||
ImportedFunction {
|
||||
Import {
|
||||
namespace: "c",
|
||||
name: "d",
|
||||
input_types: vec![InterfaceType::I32],
|
||||
@ -672,7 +672,7 @@ mod tests {
|
||||
],
|
||||
));
|
||||
|
||||
assert_eq!(imported_functions::<()>(input), output);
|
||||
assert_eq!(imports::<()>(input), output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
ast::{Adapter, Export, Forward, ImportedFunction, InterfaceType, Interfaces, Type},
|
||||
ast::{Adapter, Export, Forward, Import, InterfaceType, Interfaces, Type},
|
||||
interpreter::Instruction,
|
||||
};
|
||||
|
||||
@ -120,14 +120,14 @@ impl<'input> From<&Type<'input>> for String {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'input> From<&ImportedFunction<'input>> for String {
|
||||
fn from(imported_function: &ImportedFunction) -> Self {
|
||||
impl<'input> From<&Import<'input>> for String {
|
||||
fn from(import: &Import) -> Self {
|
||||
format!(
|
||||
r#"(@interface func ${namespace}_{name} (import "{namespace}" "{name}"){inputs}{outputs})"#,
|
||||
namespace = imported_function.namespace,
|
||||
name = imported_function.name,
|
||||
inputs = input_types_to_param(&imported_function.input_types),
|
||||
outputs = output_types_to_result(&imported_function.output_types),
|
||||
namespace = import.namespace,
|
||||
name = import.name,
|
||||
inputs = input_types_to_param(&import.input_types),
|
||||
outputs = output_types_to_result(&import.output_types),
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -213,17 +213,17 @@ impl<'input> From<&Interfaces<'input>> for String {
|
||||
accumulator
|
||||
});
|
||||
|
||||
let imported_functions = interfaces.imported_functions.iter().fold(
|
||||
String::new(),
|
||||
|mut accumulator, imported_function| {
|
||||
let imports = interfaces
|
||||
.imports
|
||||
.iter()
|
||||
.fold(String::new(), |mut accumulator, import| {
|
||||
accumulator.push_str(&format!(
|
||||
"\n\n;; Interface, Imported function {}.{}\n",
|
||||
imported_function.namespace, imported_function.name
|
||||
"\n\n;; Interface, Import {}.{}\n",
|
||||
import.namespace, import.name
|
||||
));
|
||||
accumulator.push_str(&String::from(imported_function));
|
||||
accumulator.push_str(&String::from(import));
|
||||
accumulator
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
let adapters =
|
||||
interfaces
|
||||
@ -260,7 +260,7 @@ impl<'input> From<&Interfaces<'input>> for String {
|
||||
|
||||
output.push_str(&exports);
|
||||
output.push_str(&types);
|
||||
output.push_str(&imported_functions);
|
||||
output.push_str(&imports);
|
||||
output.push_str(&adapters);
|
||||
output.push_str(&forwards);
|
||||
|
||||
@ -389,30 +389,30 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_imported_functions() {
|
||||
fn test_imports() {
|
||||
let inputs: Vec<String> = vec![
|
||||
(&ImportedFunction {
|
||||
(&Import {
|
||||
namespace: "ns",
|
||||
name: "foo",
|
||||
input_types: vec![InterfaceType::Int, InterfaceType::String],
|
||||
output_types: vec![InterfaceType::String],
|
||||
})
|
||||
.into(),
|
||||
(&ImportedFunction {
|
||||
(&Import {
|
||||
namespace: "ns",
|
||||
name: "foo",
|
||||
input_types: vec![InterfaceType::String],
|
||||
output_types: vec![],
|
||||
})
|
||||
.into(),
|
||||
(&ImportedFunction {
|
||||
(&Import {
|
||||
namespace: "ns",
|
||||
name: "foo",
|
||||
input_types: vec![],
|
||||
output_types: vec![InterfaceType::String],
|
||||
})
|
||||
.into(),
|
||||
(&ImportedFunction {
|
||||
(&Import {
|
||||
namespace: "ns",
|
||||
name: "foo",
|
||||
input_types: vec![],
|
||||
@ -549,14 +549,14 @@ mod tests {
|
||||
},
|
||||
],
|
||||
types: vec![],
|
||||
imported_functions: vec![
|
||||
ImportedFunction {
|
||||
imports: vec![
|
||||
Import {
|
||||
namespace: "ns",
|
||||
name: "foo",
|
||||
input_types: vec![],
|
||||
output_types: vec![InterfaceType::I32],
|
||||
},
|
||||
ImportedFunction {
|
||||
Import {
|
||||
namespace: "ns",
|
||||
name: "bar",
|
||||
input_types: vec![],
|
||||
@ -590,11 +590,11 @@ mod tests {
|
||||
;; Interface, Export bar
|
||||
(@interface export "bar")
|
||||
|
||||
;; Interface, Imported function ns.foo
|
||||
;; Interface, Import ns.foo
|
||||
(@interface func $ns_foo (import "ns" "foo")
|
||||
(result i32))
|
||||
|
||||
;; Interface, Imported function ns.bar
|
||||
;; Interface, Import ns.bar
|
||||
(@interface func $ns_bar (import "ns" "bar"))
|
||||
|
||||
;; Interface, Adapter ns.foo
|
||||
|
Loading…
x
Reference in New Issue
Block a user