mirror of
https://github.com/fluencelabs/interface-types
synced 2024-12-04 15:20:20 +00:00
add deriving more traits for ast types
This commit is contained in:
parent
5e47fa6857
commit
dab853009f
21
src/ast.rs
21
src/ast.rs
@ -5,10 +5,13 @@ use crate::{
|
||||
interpreter::Instruction,
|
||||
types::{InterfaceType, RecordType},
|
||||
};
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::str;
|
||||
|
||||
/// Represents the kind of type.
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub enum TypeKind {
|
||||
/// A function type.
|
||||
Function,
|
||||
@ -18,7 +21,7 @@ pub enum TypeKind {
|
||||
}
|
||||
|
||||
/// Represents the function argument type.
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub struct FunctionArg {
|
||||
/// A function argument name.
|
||||
pub name: String,
|
||||
@ -28,7 +31,7 @@ pub struct FunctionArg {
|
||||
}
|
||||
|
||||
/// Represents a type.
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub enum Type {
|
||||
/// A function type, like:
|
||||
///
|
||||
@ -52,7 +55,7 @@ pub enum Type {
|
||||
}
|
||||
|
||||
/// Represents an imported function.
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug, Default, Clone, Hash)]
|
||||
pub struct Import<'input> {
|
||||
/// The function namespace.
|
||||
pub namespace: &'input str,
|
||||
@ -65,7 +68,7 @@ pub struct Import<'input> {
|
||||
}
|
||||
|
||||
/// Represents an exported function signature.
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug, Default, Clone, Hash)]
|
||||
pub struct Export<'input> {
|
||||
/// The export name.
|
||||
pub name: &'input str,
|
||||
@ -75,7 +78,7 @@ pub struct Export<'input> {
|
||||
}
|
||||
|
||||
/// Represents an adapter.
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub struct Adapter {
|
||||
/// The adapter function type.
|
||||
pub function_type: u32,
|
||||
@ -85,7 +88,7 @@ pub struct Adapter {
|
||||
}
|
||||
|
||||
/// Represents an implementation.
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug, Default, Clone, Hash, Serialize, Deserialize)]
|
||||
pub struct Implementation {
|
||||
/// The core function type.
|
||||
pub core_function_type: u32,
|
||||
@ -95,7 +98,7 @@ pub struct Implementation {
|
||||
}
|
||||
|
||||
/// Represents the kind of interface.
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub(crate) enum InterfaceKind {
|
||||
/// A type.
|
||||
Type,
|
||||
@ -115,7 +118,7 @@ pub(crate) enum InterfaceKind {
|
||||
|
||||
/// Represents a set of interfaces, i.e. it entirely describes a WIT
|
||||
/// definition.
|
||||
#[derive(PartialEq, Default, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug, Default, Clone, Hash)]
|
||||
pub struct Interfaces<'input> {
|
||||
/// All the types.
|
||||
pub types: Vec<Type>,
|
||||
|
@ -140,11 +140,7 @@ where
|
||||
result
|
||||
}
|
||||
InterfaceType::Array(ty) => {
|
||||
let data = transmute_many::<
|
||||
u32,
|
||||
AllOrNothingGuard,
|
||||
>(&data)
|
||||
.unwrap();
|
||||
let data = transmute_many::<u32, AllOrNothingGuard>(&data).unwrap();
|
||||
|
||||
if data.is_empty() {
|
||||
return Ok(vec![]);
|
||||
@ -186,11 +182,7 @@ where
|
||||
)
|
||||
})?;
|
||||
|
||||
let data = transmute_many::<
|
||||
u32,
|
||||
AllOrNothingGuard,
|
||||
>(&data)
|
||||
.unwrap();
|
||||
let data = transmute_many::<u32, AllOrNothingGuard>(&data).unwrap();
|
||||
|
||||
let mut result = Vec::with_capacity(data.len());
|
||||
|
||||
|
@ -26,11 +26,14 @@ pub(crate) use strings::*;
|
||||
pub(crate) use swap2::swap2;
|
||||
pub(self) use utils::*;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
pub(self) const ALLOCATE_FUNC_INDEX: u32 = 0;
|
||||
pub(self) const DEALLOCATE_FUNC_INDEX: u32 = 1;
|
||||
|
||||
/// Represents all the possible WIT instructions.
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub enum Instruction {
|
||||
/// The `arg.get` instruction.
|
||||
ArgumentGet {
|
||||
|
@ -39,8 +39,8 @@
|
||||
//! [instructions]: interpreter::Instruction
|
||||
|
||||
#![deny(
|
||||
// dead_code,
|
||||
intra_doc_link_resolution_failure,
|
||||
dead_code,
|
||||
broken_intra_doc_links,
|
||||
missing_docs,
|
||||
nonstandard_style,
|
||||
unreachable_patterns,
|
||||
|
Loading…
Reference in New Issue
Block a user