From 1f2a5640a631d3303e58a649ca0117acd890c242 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 24 Feb 2020 15:49:03 +0100 Subject: [PATCH] =?UTF-8?q?feat(interface-types)=20The=20=E2=80=9Chelper?= =?UTF-8?q?=20adapter=E2=80=9D=20has=20been=20removed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast.rs | 18 ------------------ src/decoders/binary.rs | 32 +------------------------------- src/decoders/wat.rs | 2 -- src/encoders/binary.rs | 39 --------------------------------------- src/encoders/wat.rs | 4 ---- 5 files changed, 1 insertion(+), 94 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 1c80484..7319e2b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -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>, }, - - /// An adapter for a helper function. - HelperFunction { - /// The helper name. - name: &'input str, - - /// The helper input types. - input_types: Vec, - - /// The helper output types. - output_types: Vec, - - /// The instructions of the adapter. - instructions: Vec>, - }, } /// Represented a forwarded export. diff --git a/src/decoders/binary.rs b/src/decoders/binary.rs index ffff812..151ff81 100644 --- a/src/decoders/binary.rs +++ b/src/decoders/binary.rs @@ -40,7 +40,6 @@ impl TryFrom 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 }], - }, ], )); diff --git a/src/decoders/wat.rs b/src/decoders/wat.rs index e6b5215..4506e18 100644 --- a/src/decoders/wat.rs +++ b/src/decoders/wat.rs @@ -426,8 +426,6 @@ impl<'a> Parse<'a> for Adapter<'a> { output_types, instructions, }, - - _ => unimplemented!("Adapter of kind “helper” is not implemented yet."), }) } } diff --git a/src/encoders/binary.rs b/src/encoders/binary.rs index 47cd12d..d862329 100644 --- a/src/encoders/binary.rs +++ b/src/encoders/binary.rs @@ -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!( diff --git a/src/encoders/wat.rs b/src/encoders/wat.rs index 3748829..ab888fd 100644 --- a/src/encoders/wat.rs +++ b/src/encoders/wat.rs @@ -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