This commit is contained in:
NikVolf
2017-03-31 17:31:33 +03:00
parent 5b93ee2236
commit f60b941cd4
6 changed files with 101 additions and 25 deletions

View File

@ -12,6 +12,7 @@ use super::{
ExportEntry,
Opcodes,
ValueType,
GlobalEntry,
};
use super::types::Type;
@ -27,6 +28,7 @@ pub enum Section {
Function(FunctionsSection),
Table(TableSection),
Memory(MemorySection),
Global(GlobalSection),
Export(ExportSection),
Start(u32),
Code(CodeSection),
@ -62,6 +64,9 @@ impl Deserialize for Section {
5 => {
Section::Memory(MemorySection::deserialize(reader)?)
},
6 => {
Section::Global(GlobalSection::deserialize(reader)?)
},
7 => {
Section::Export(ExportSection::deserialize(reader)?)
},
@ -188,6 +193,25 @@ impl Deserialize for MemorySection {
}
}
pub struct GlobalSection(Vec<GlobalEntry>);
impl GlobalSection {
pub fn entries(&self) -> &[GlobalEntry] {
&self.0
}
}
impl Deserialize for GlobalSection {
type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length)
let _section_length = VarUint32::deserialize(reader)?;
let entries: Vec<GlobalEntry> = CountedList::deserialize(reader)?.into_inner();
Ok(GlobalSection(entries))
}
}
pub struct ExportSection(Vec<ExportEntry>);
impl ExportSection {