feat(interface-types) The “helper adapter” has been removed.

This commit is contained in:
Ivan Enderlin 2020-02-24 15:49:03 +01:00
parent ac68325cc9
commit 8538e3be33
5 changed files with 1 additions and 94 deletions

View File

@ -58,9 +58,6 @@ pub(crate) enum AdapterKind {
/// An adapter defined for an exported function of a WebAssembly instance.
Export,
/// A helper function.
HelperFunction,
}
/// Represents an exported function signature.
@ -176,21 +173,6 @@ pub enum Adapter<'input> {
/// The instructions of the adapter.
instructions: Vec<Instruction<'input>>,
},
/// An adapter for a helper function.
HelperFunction {
/// The helper name.
name: &'input str,
/// The helper input types.
input_types: Vec<InterfaceType>,
/// The helper output types.
output_types: Vec<InterfaceType>,
/// The instructions of the adapter.
instructions: Vec<Instruction<'input>>,
},
}
/// Represented a forwarded export.

View File

@ -40,7 +40,6 @@ impl TryFrom<u8> for AdapterKind {
Ok(match code {
0x0 => Self::Import,
0x1 => Self::Export,
0x2 => Self::HelperFunction,
_ => return Err("Unknown adapter kind code."),
})
}
@ -374,20 +373,6 @@ fn adapters<'input, E: ParseError<&'input [u8]>>(
instructions: adapter_instructions,
});
}
AdapterKind::HelperFunction => {
consume!((input, adapter_name) = string(input)?);
consume!((input, adapter_input_types) = list(input, ty)?);
consume!((input, adapter_output_types) = list(input, ty)?);
consume!((input, adapter_instructions) = list(input, instruction)?);
adapters.push(Adapter::HelperFunction {
name: adapter_name,
input_types: adapter_input_types,
output_types: adapter_output_types,
instructions: adapter_instructions,
});
}
}
}
@ -846,7 +831,7 @@ mod tests {
#[test]
fn test_adapters() {
let input = &[
0x03, // 3 adapters
0x02, // 3 adapters
0x00, // adapter kind: import
0x01, // string of 1 byte
0x61, // "a"
@ -867,15 +852,6 @@ mod tests {
0x0c, // I32
0x01, // list of 1 item
0x00, 0x01, // ArgumentGet { index: 1 }
0x02, // adapter kind: helper function
0x01, // string of 1 byte
0x64, // "d"
0x01, // list of 1 item
0x0c, // I32
0x01, // list of 1 item
0x0c, // I32
0x01, // list of 1 item
0x00, 0x01, // ArgumentGet { index: 1 }
];
let output = Ok((
&[] as &[u8],
@ -893,12 +869,6 @@ mod tests {
output_types: vec![InterfaceType::I32],
instructions: vec![Instruction::ArgumentGet { index: 1 }],
},
Adapter::HelperFunction {
name: "d",
input_types: vec![InterfaceType::I32],
output_types: vec![InterfaceType::I32],
instructions: vec![Instruction::ArgumentGet { index: 1 }],
},
],
));

View File

@ -426,8 +426,6 @@ impl<'a> Parse<'a> for Adapter<'a> {
output_types,
instructions,
},
_ => unimplemented!("Adapter of kind “helper” is not implemented yet."),
})
}
}

View File

@ -124,7 +124,6 @@ where
match self {
AdapterKind::Import => 0x00_u8.to_bytes(writer),
AdapterKind::Export => 0x01_u8.to_bytes(writer),
AdapterKind::HelperFunction => 0x02_u8.to_bytes(writer),
}
}
}
@ -214,19 +213,6 @@ where
output_types.to_bytes(writer)?;
instructions.to_bytes(writer)?;
}
Adapter::HelperFunction {
name,
input_types,
output_types,
instructions,
} => {
AdapterKind::HelperFunction.to_bytes(writer)?;
name.to_bytes(writer)?;
input_types.to_bytes(writer)?;
output_types.to_bytes(writer)?;
instructions.to_bytes(writer)?;
}
}
Ok(())
@ -468,7 +454,6 @@ mod tests {
fn test_adapter_kind() {
assert_to_bytes!(AdapterKind::Import, &[0x00]);
assert_to_bytes!(AdapterKind::Export, &[0x01]);
assert_to_bytes!(AdapterKind::HelperFunction, &[0x02]);
}
#[test]
@ -590,30 +575,6 @@ mod tests {
);
}
#[test]
fn test_adapter_helper_function() {
assert_to_bytes!(
Adapter::HelperFunction {
name: "a",
input_types: vec![InterfaceType::I32, InterfaceType::I64],
output_types: vec![InterfaceType::I32],
instructions: vec![Instruction::ArgumentGet { index: 1 }],
},
&[
0x02, // AdapterKind::HelperFunction
0x01, // string of length 1
0x61, // "a"
0x02, // list of 2 items
0x0c, // I32
0x0d, // I64
0x01, // list of 1 items
0x0c, // I32
0x01, // list of 1 item
0x00, 0x01, // ArgumentGet { index: 1 }
]
);
}
#[test]
fn test_forward() {
assert_to_bytes!(

View File

@ -279,8 +279,6 @@ impl<'input> ToString for &Adapter<'input> {
accumulator
}),
),
_ => todo!("To be implemented."),
}
}
}
@ -345,8 +343,6 @@ impl<'input> ToString for &Interfaces<'input> {
Adapter::Export { name, .. } => {
accumulator.push_str(&format!("\n\n;; Interface, Adapter {}\n", name))
}
_ => todo!("To be implemented."),
}
accumulator.push_str(&adapter.to_string());
accumulator