diff --git a/src/ast.rs b/src/ast.rs index 42fc850..9429dd0 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -51,7 +51,7 @@ pub struct Import<'input> { pub name: &'input str, /// The type signature. - pub signature_type: u32, + pub function_type: u32, } /// Represents an exported function signature. diff --git a/src/decoders/binary.rs b/src/decoders/binary.rs index ce0f110..54dc1e1 100644 --- a/src/decoders/binary.rs +++ b/src/decoders/binary.rs @@ -304,12 +304,12 @@ fn imports<'input, E: ParseError<&'input [u8]>>( for _ in 0..number_of_imports { consume!((input, namespace) = string(input)?); consume!((input, name) = string(input)?); - consume!((input, signature_type) = uleb(input)?); + consume!((input, function_type) = uleb(input)?); imports.push(Import { namespace, name, - signature_type: signature_type as u32, + function_type: function_type as u32, }); } @@ -495,7 +495,7 @@ fn interfaces<'input, E: ParseError<&'input [u8]>>( /// imports: vec![Import { /// namespace: "ab", /// name: "c", -/// signature_type: 0, +/// function_type: 0, /// }], /// adapters: vec![Adapter { /// function_type: 0, @@ -890,12 +890,12 @@ mod tests { Import { namespace: "a", name: "b", - signature_type: 1, + function_type: 1, }, Import { namespace: "c", name: "d", - signature_type: 2, + function_type: 2, }, ], )); @@ -968,7 +968,7 @@ mod tests { imports: vec![Import { namespace: "ab", name: "c", - signature_type: 0, + function_type: 0, }], adapters: vec![Adapter { function_type: 0, diff --git a/src/decoders/wat.rs b/src/decoders/wat.rs index eb2f244..292a8f5 100644 --- a/src/decoders/wat.rs +++ b/src/decoders/wat.rs @@ -477,7 +477,7 @@ impl<'a> Parse<'a> for Import<'a> { let namespace = parser.parse()?; let name = parser.parse()?; - let signature_type = parser.parens(|parser| { + let function_type = parser.parens(|parser| { parser.parse::()?; parser.parens(|parser| { @@ -490,7 +490,7 @@ impl<'a> Parse<'a> for Import<'a> { Ok(Import { namespace, name, - signature_type, + function_type, }) } } @@ -616,7 +616,7 @@ impl<'a> Parse<'a> for Interfaces<'a> { /// imports: vec![Import { /// namespace: "ns", /// name: "foo", -/// signature_type: 0, +/// function_type: 0, /// }], /// adapters: vec![Adapter { /// function_type: 0, @@ -907,7 +907,7 @@ mod tests { let output = Interface::Import(Import { namespace: "ns", name: "foo", - signature_type: 0, + function_type: 0, }); assert_eq!(parser::parse::(&input).unwrap(), output); @@ -956,7 +956,7 @@ mod tests { imports: vec![Import { namespace: "ns", name: "foo", - signature_type: 0, + function_type: 0, }], adapters: vec![Adapter { function_type: 0, diff --git a/src/encoders/binary.rs b/src/encoders/binary.rs index dd2d072..77cd98a 100644 --- a/src/encoders/binary.rs +++ b/src/encoders/binary.rs @@ -190,7 +190,7 @@ where fn to_bytes(&self, writer: &mut W) -> io::Result<()> { self.namespace.to_bytes(writer)?; self.name.to_bytes(writer)?; - (self.signature_type as u64).to_bytes(writer)?; + (self.function_type as u64).to_bytes(writer)?; Ok(()) } @@ -556,7 +556,7 @@ mod tests { Import { namespace: "a", name: "b", - signature_type: 0, + function_type: 0, }, &[ 0x01, // string of length 1 @@ -594,7 +594,7 @@ mod tests { imports: vec![Import { namespace: "ab", name: "c", - signature_type: 0, + function_type: 0, }], adapters: vec![Adapter { function_type: 0, diff --git a/src/encoders/wat.rs b/src/encoders/wat.rs index 6d58e04..b4b1fe1 100644 --- a/src/encoders/wat.rs +++ b/src/encoders/wat.rs @@ -18,7 +18,7 @@ //! imports: vec![Import { //! namespace: "ns", //! name: "foo", -//! signature_type: 0, +//! function_type: 0, //! }], //! adapters: vec![Adapter { //! function_type: 0, @@ -207,7 +207,7 @@ impl<'input> ToString for &Import<'input> { r#"(@interface import "{namespace}" "{name}" (func (type {type})))"#, namespace = self.namespace, name = self.name, - type = self.signature_type, + type = self.function_type, ) } } @@ -571,7 +571,7 @@ mod tests { let input = (&Import { namespace: "ns", name: "foo", - signature_type: 0, + function_type: 0, }) .to_string(); let output = r#"(@interface import "ns" "foo" (func (type 0)))"#; @@ -602,7 +602,7 @@ mod tests { imports: vec![Import { namespace: "ns", name: "foo", - signature_type: 0, + function_type: 0, }], adapters: vec![Adapter { function_type: 0, diff --git a/src/interpreter/instructions/strings.rs b/src/interpreter/instructions/strings.rs index 854728f..cdbfe80 100644 --- a/src/interpreter/instructions/strings.rs +++ b/src/interpreter/instructions/strings.rs @@ -44,7 +44,7 @@ executable_instruction!( return Ok(()) } - if memory_view.len() <= pointer + length - 1 { + if memory_view.len() < pointer + length { return Err(InstructionError::new( instruction, InstructionErrorKind::MemoryOutOfBoundsAccess { @@ -54,7 +54,7 @@ executable_instruction!( )); } - let data: Vec = (&memory_view[pointer..=pointer + length - 1]) + let data: Vec = (&memory_view[pointer..pointer + length]) .iter() .map(Cell::get) .collect(); diff --git a/src/vec1.rs b/src/vec1.rs index 3e89293..4462beb 100644 --- a/src/vec1.rs +++ b/src/vec1.rs @@ -33,7 +33,7 @@ where /// Creates a new non-empty vector, based on an inner `Vec`. If /// the inner vector is empty, a `EmptyVec` error is returned. pub fn new(items: Vec) -> Result { - if items.len() == 0 { + if items.is_empty() { Err(EmptyVec) } else { Ok(Self(items)) diff --git a/tests/binary.rs b/tests/binary.rs index 81f8730..8198c04 100644 --- a/tests/binary.rs +++ b/tests/binary.rs @@ -23,7 +23,7 @@ fn test_binary_encoding_decoding_roundtrip() { imports: vec![Import { namespace: "a", name: "b", - signature_type: 0, + function_type: 0, }], adapters: vec![Adapter { function_type: 0,