squash commits

This commit is contained in:
NikVolf 2017-06-03 18:20:20 +03:00
parent 2e16c335e1
commit af16f6dfc9
2 changed files with 42 additions and 12 deletions

View File

@ -167,7 +167,7 @@ impl<F> Invoke<u32> for SignaturesBuilder<F> {
impl<F> SignaturesBuilder<F> where F: Invoke<elements::FunctionsSection> { impl<F> SignaturesBuilder<F> where F: Invoke<elements::FunctionsSection> {
pub fn build(self) -> F::Result { pub fn build(self) -> F::Result {
let mut result = elements::FunctionsSection::new(); let mut result = elements::FunctionsSection::default();
for f in self.section.into_iter() { for f in self.section.into_iter() {
if let Signature::TypeReference(type_ref) = f { if let Signature::TypeReference(type_ref) = f {
result.entries_mut().push(elements::Func::new(type_ref)); result.entries_mut().push(elements::Func::new(type_ref));

View File

@ -183,6 +183,11 @@ impl Serialize for Section {
pub struct TypeSection(Vec<Type>); pub struct TypeSection(Vec<Type>);
impl TypeSection { impl TypeSection {
/// New type section with provided types
pub fn with_types(types: Vec<Type>) -> Self {
TypeSection(types)
}
/// List of type declarations /// List of type declarations
pub fn types(&self) -> &[Type] { pub fn types(&self) -> &[Type] {
&self.0 &self.0
@ -226,6 +231,11 @@ impl Serialize for TypeSection {
pub struct ImportSection(Vec<ImportEntry>); pub struct ImportSection(Vec<ImportEntry>);
impl ImportSection { impl ImportSection {
/// New import section with provided types
pub fn with_entries(entries: Vec<ImportEntry>) -> Self {
ImportSection(entries)
}
/// List of import entries. /// List of import entries.
pub fn entries(&self) -> &[ImportEntry] { pub fn entries(&self) -> &[ImportEntry] {
&self.0 &self.0
@ -269,9 +279,9 @@ impl Serialize for ImportSection {
pub struct FunctionsSection(Vec<Func>); pub struct FunctionsSection(Vec<Func>);
impl FunctionsSection { impl FunctionsSection {
/// New functions section /// New function signatures section with provided entries
pub fn new() -> FunctionsSection { pub fn with_entries(entries: Vec<Func>) -> Self {
FunctionsSection(Vec::new()) FunctionsSection(entries)
} }
/// List of all functions in the section, mutable /// List of all functions in the section, mutable
@ -326,6 +336,11 @@ impl TableSection {
&self.0 &self.0
} }
/// New table section with provided table entries
pub fn with_entries(entries: Vec<TableType>) -> Self {
TableSection(entries)
}
/// Mutable table entries. /// Mutable table entries.
pub fn entries_mut(&mut self) -> &mut Vec<TableType> { pub fn entries_mut(&mut self) -> &mut Vec<TableType> {
&mut self.0 &mut self.0
@ -369,6 +384,11 @@ impl MemorySection {
&self.0 &self.0
} }
/// New memory section with memory types
pub fn with_entries(entries: Vec<MemoryType>) -> Self {
MemorySection(entries)
}
/// Mutable list of all memory entries in the section /// Mutable list of all memory entries in the section
pub fn entries_mut(&mut self) -> &mut Vec<MemoryType> { pub fn entries_mut(&mut self) -> &mut Vec<MemoryType> {
&mut self.0 &mut self.0
@ -412,6 +432,11 @@ impl GlobalSection {
&self.0 &self.0
} }
/// New global section from list of global entries
pub fn with_entries(entries: Vec<GlobalEntry>) -> Self {
GlobalSection(entries)
}
/// List of all global entries in the section (mutable) /// List of all global entries in the section (mutable)
pub fn entries_mut(&mut self) -> &mut Vec<GlobalEntry> { pub fn entries_mut(&mut self) -> &mut Vec<GlobalEntry> {
&mut self.0 &mut self.0
@ -455,6 +480,11 @@ impl ExportSection {
&self.0 &self.0
} }
/// New export section from list of export entries
pub fn with_entries(entries: Vec<ExportEntry>) -> Self {
ExportSection(entries)
}
/// List of all export entries in the section (mutable) /// List of all export entries in the section (mutable)
pub fn entries_mut(&mut self) -> &mut Vec<ExportEntry> { pub fn entries_mut(&mut self) -> &mut Vec<ExportEntry> {
&mut self.0 &mut self.0
@ -493,8 +523,8 @@ impl Serialize for ExportSection {
pub struct CodeSection(Vec<FuncBody>); pub struct CodeSection(Vec<FuncBody>);
impl CodeSection { impl CodeSection {
/// New code section /// New code section with specified function bodies
pub fn new(bodies: Vec<FuncBody>) -> Self { pub fn with_bodies(bodies: Vec<FuncBody>) -> Self {
CodeSection(bodies) CodeSection(bodies)
} }
@ -542,7 +572,7 @@ pub struct ElementSection(Vec<ElementSegment>);
impl ElementSection { impl ElementSection {
/// New elements section /// New elements section
pub fn new(entries: Vec<ElementSegment>) -> Self { pub fn with_entries(entries: Vec<ElementSegment>) -> Self {
ElementSection(entries) ElementSection(entries)
} }
@ -590,8 +620,8 @@ pub struct DataSection(Vec<DataSegment>);
impl DataSection { impl DataSection {
/// New data section /// New data section
pub fn new(segments: Vec<DataSegment>) -> Self { pub fn with_entries(entries: Vec<DataSegment>) -> Self {
DataSection(segments) DataSection(entries)
} }
/// List of all data entries in the section /// List of all data entries in the section
@ -868,7 +898,7 @@ mod tests {
#[test] #[test]
fn data_section_ser() { fn data_section_ser() {
let data_section = DataSection::new( let data_section = DataSection::with_entries(
vec![DataSegment::new(0u32, InitExpr::empty(), vec![0u8; 16])] vec![DataSegment::new(0u32, InitExpr::empty(), vec![0u8; 16])]
); );
@ -902,7 +932,7 @@ mod tests {
#[test] #[test]
fn element_section_ser() { fn element_section_ser() {
let element_section = ElementSection::new( let element_section = ElementSection::with_entries(
vec![ElementSegment::new(0u32, InitExpr::empty(), vec![0u32; 4])] vec![ElementSegment::new(0u32, InitExpr::empty(), vec![0u32; 4])]
); );
@ -922,7 +952,7 @@ mod tests {
fn code_section_ser() { fn code_section_ser() {
use super::super::Opcode::*; use super::super::Opcode::*;
let code_section = CodeSection::new( let code_section = CodeSection::with_bodies(
vec![ vec![
FuncBody::new( FuncBody::new(
vec![Local::new(1, ValueType::I32)], vec![Local::new(1, ValueType::I32)],