feat(interface-types) Move TryFrom from the ast to the binary module.

This commit is contained in:
Ivan Enderlin 2019-09-13 14:50:17 +02:00
parent b38418fcc3
commit 086c3bdb4c
2 changed files with 34 additions and 34 deletions

View File

@ -1,4 +1,4 @@
use std::{convert::TryFrom, str};
use std::str;
#[derive(PartialEq, Debug)]
pub enum InterfaceType {
@ -15,26 +15,6 @@ pub enum InterfaceType {
AnyRef,
}
impl TryFrom<u64> for InterfaceType {
type Error = &'static str;
fn try_from(code: u64) -> Result<Self, Self::Error> {
Ok(match code {
0x7fff => Self::Int,
0x7ffe => Self::Float,
0x7ffd => Self::Any,
0x7ffc => Self::String,
0x7ffb => Self::Seq,
0x7f => Self::I32,
0x7e => Self::I64,
0x7d => Self::F32,
0x7c => Self::F64,
0x6f => Self::AnyRef,
_ => return Err("Unknown interface type code."),
})
}
}
#[derive(PartialEq, Debug)]
pub(crate) enum AdapterKind {
Import,
@ -42,19 +22,6 @@ pub(crate) enum AdapterKind {
HelperFunction,
}
impl TryFrom<u8> for AdapterKind {
type Error = &'static str;
fn try_from(code: u8) -> Result<Self, Self::Error> {
Ok(match code {
0x0 => Self::Import,
0x1 => Self::Export,
0x2 => Self::HelperFunction,
_ => return Err("Unknown adapter kind code."),
})
}
}
#[derive(PartialEq, Debug)]
pub enum Instruction<'input> {
ArgumentGet(u64),

View File

@ -5,6 +5,39 @@ use nom::{
};
use std::{convert::TryFrom, str};
impl TryFrom<u64> for InterfaceType {
type Error = &'static str;
fn try_from(code: u64) -> Result<Self, Self::Error> {
Ok(match code {
0x7fff => Self::Int,
0x7ffe => Self::Float,
0x7ffd => Self::Any,
0x7ffc => Self::String,
0x7ffb => Self::Seq,
0x7f => Self::I32,
0x7e => Self::I64,
0x7d => Self::F32,
0x7c => Self::F64,
0x6f => Self::AnyRef,
_ => return Err("Unknown interface type code."),
})
}
}
impl TryFrom<u8> for AdapterKind {
type Error = &'static str;
fn try_from(code: u8) -> Result<Self, Self::Error> {
Ok(match code {
0x0 => Self::Import,
0x1 => Self::Export,
0x2 => Self::HelperFunction,
_ => return Err("Unknown adapter kind code."),
})
}
}
fn byte<'input, E: ParseError<&'input [u8]>>(input: &'input [u8]) -> IResult<&'input [u8], u8, E> {
if input.is_empty() {
return Err(Err::Error(make_error(input, ErrorKind::Eof)));