use super::types::Wec; use super::types::FuncType; use super::types::ValType; use super::types::TableType; use super::types::MemType; use super::types::GlobalType; use super::types::Byte; use super::types::Name; use super::types::U32; use super::instructions::Expr; #[derive(Debug, PartialEq)] pub struct Module { pub types: Wec, pub funcs: Wec, pub tables: Wec, pub mems: Wec, pub globals: Wec, pub elem: Wec, pub data: Wec, pub start: Option, pub imports: Wec, pub exports: Wec, } #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub struct TypeIdx(pub U32); impl Into for TypeIdx { fn into(self) -> usize { self.0 as usize } } impl From for TypeIdx { fn from(a: usize) -> Self { TypeIdx(a as u32) } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub struct FuncIdx(pub U32); impl Into for FuncIdx { fn into(self) -> usize { self.0 as usize } } impl From for FuncIdx { fn from(a: usize) -> Self { FuncIdx(a as u32) } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub struct TableIdx(pub U32); impl Into for TableIdx { fn into(self) -> usize { self.0 as usize } } impl From for TableIdx { fn from(a: usize) -> Self { TableIdx(a as u32) } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub struct MemIdx(pub U32); impl Into for MemIdx { fn into(self) -> usize { self.0 as usize } } impl From for MemIdx { fn from(a: usize) -> Self { MemIdx(a as u32) } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub struct GlobalIdx(pub U32); impl Into for GlobalIdx { fn into(self) -> usize { self.0 as usize } } impl From for GlobalIdx { fn from(a: usize) -> Self { GlobalIdx(a as u32) } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub struct LocalIdx(pub U32); impl Into for LocalIdx { fn into(self) -> usize { self.0 as usize } } impl From for LocalIdx { fn from(a: usize) -> Self { LocalIdx(a as u32) } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub struct LabelIdx(pub U32); impl Into for LabelIdx { fn into(self) -> usize { self.0 as usize } } impl From for LabelIdx { fn from(a: usize) -> Self { LabelIdx(a as u32) } } #[derive(Debug, PartialEq, Clone)] pub struct Func { pub type_: TypeIdx, pub locals: Wec, pub body: Expr, } #[derive(Debug, PartialEq)] pub struct Table { pub type_: TableType, } #[derive(Debug, PartialEq)] pub struct Mem { pub type_: MemType, } #[derive(Debug, PartialEq)] pub struct Global { pub type_: GlobalType, pub init: Expr, } #[derive(Debug, PartialEq)] pub struct Elem { pub table: TableIdx, pub offset: Expr, pub init: Wec, } #[derive(Debug, PartialEq)] pub struct Data { pub data: MemIdx, pub offset: Expr, pub init: Wec, } #[derive(Debug, PartialEq)] pub struct Start { pub func: FuncIdx, } #[derive(Debug, PartialEq)] pub struct Export { pub name: Name, pub desc: ExportDesc, } #[derive(Debug, PartialEq)] pub enum ExportDesc { Func(FuncIdx), Table(TableIdx), Mem(MemIdx), Global(GlobalIdx), } #[derive(Debug, PartialEq)] pub struct Import { pub module: Name, pub name: Name, pub desc: ImportDesc, } #[derive(Debug, PartialEq)] pub enum ImportDesc { Func(TypeIdx), Table(TableType), Mem(MemType), Global(GlobalType), }