namespaces

This commit is contained in:
NikVolf
2017-04-03 13:58:49 +03:00
parent 8a48edb6c6
commit a5fdfa57cf
5 changed files with 25 additions and 20 deletions

View File

@ -1,7 +1,7 @@
extern crate parity_wasm;
use std::env;
use parity_wasm::Section;
use parity_wasm::elements::Section;
fn main() {
let args = env::args().collect::<Vec<_>>();

View File

@ -1,6 +1,16 @@
use std::io;
use super::{Deserialize, Error, ValueType, VarUint32, CountedList, Opcodes};
/// Function signature (type reference)
pub struct Func(u32);
impl Func {
pub fn new(type_ref: u32) -> Self { Func(type_ref) }
pub fn type_ref(&self) -> u32 {
self.0
}
}
pub struct Local {
count: u32,

View File

@ -19,7 +19,7 @@ pub use self::global_entry::GlobalEntry;
pub use self::primitives::{VarUint32, VarUint7, VarUint1, VarInt7, Uint32, Uint64, VarUint64, CountedList};
pub use self::types::{ValueType, BlockType};
pub use self::ops::{Opcode, Opcodes, InitExpr};
pub use self::func::{FuncBody, Local};
pub use self::func::{Func, FuncBody, Local};
pub use self::segment::{ElementSegment, DataSegment};
pub trait Deserialize : Sized {
@ -27,6 +27,11 @@ pub trait Deserialize : Sized {
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error>;
}
pub trait Serialize {
type Error;
fn serialize<W: io::Write>(&self, writer: &mut W) -> Result<(), Self::Error>;
}
#[derive(Debug)]
pub enum Error {
UnexpectedEof,

View File

@ -11,6 +11,7 @@ use super::{
TableType,
ExportEntry,
GlobalEntry,
Func,
FuncBody,
ElementSegment,
DataSegment,
@ -132,19 +133,10 @@ impl Deserialize for ImportSection {
}
}
/// Function signature (type reference)
pub struct Function(pub u32);
impl Function {
pub fn type_ref(&self) -> u32 {
self.0
}
}
pub struct FunctionsSection(Vec<Function>);
pub struct FunctionsSection(Vec<Func>);
impl FunctionsSection {
pub fn entries(&self) -> &[Function] {
pub fn entries(&self) -> &[Func] {
&self.0
}
}
@ -155,13 +147,13 @@ impl Deserialize for FunctionsSection {
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 funcs: Vec<Function> = CountedList::<VarUint32>::deserialize(reader)?
let funcs: Vec<Func> = CountedList::<VarUint32>::deserialize(reader)?
.into_inner()
.into_iter()
.map(|f| Function(f.into()))
.map(|f| Func::new(f.into()))
.collect();
Ok(FunctionsSection(funcs))
}
}
}
pub struct TableSection(Vec<TableType>);

View File

@ -1,11 +1,9 @@
extern crate byteorder;
mod elements;
pub mod elements;
pub use elements::{
Section,
Module,
Error as DeserializeError,
Error as SerializationError,
deserialize_buffer,
deserialize_file
};