Start refactoring.

This commit is contained in:
Sergey Pepyakin 2019-01-25 10:45:39 +01:00
parent af19c66589
commit b83e6178b8
4 changed files with 41 additions and 41 deletions

View File

@ -1,4 +1,4 @@
use crate::model::{ExtDefinition, ExternalFunc};
use crate::parser::{ExtDefinition, ExternalFunc};
use proc_macro2::{Ident, Literal, Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens};

View File

@ -3,7 +3,6 @@
extern crate proc_macro;
mod codegen;
mod model;
mod parser;
use proc_macro::TokenStream;

View File

@ -1,38 +0,0 @@
pub enum ValueType {
I32,
I64,
F32,
F64,
}
pub struct Signature {
pub params: Vec<ValueType>,
pub return_ty: Option<ValueType>,
}
#[derive(Clone)]
pub struct Param {
/// A generated identifier used for temporary variables.
pub ident: syn::Ident,
}
pub struct ExternalFunc {
/// Assigned index of this function.
pub index: u32,
pub name: String,
// TODO: Rename args to params
pub args: Vec<Param>,
pub return_ty: Option<proc_macro2::Span>,
}
/// The core structure that contains the list of all functions
/// and the data required for implementing a trait.
pub struct ExtDefinition {
/// List of all external functions.
pub funcs: Vec<ExternalFunc>,
/// The generics required to implement a trait for this type.
pub generics: syn::Generics,
/// The type declaration to implement to implement a trait, most typically
/// represented by a structure.
pub ty: Box<syn::Type>,
}

View File

@ -1,7 +1,46 @@
use crate::model::{self, ExtDefinition, ExternalFunc, Param};
use syn::spanned::Spanned;
use syn::{FnArg, Ident, ImplItem, ImplItemMethod, ItemImpl, ReturnType};
pub enum ValueType {
I32,
I64,
F32,
F64,
}
pub struct Signature {
pub params: Vec<ValueType>,
pub return_ty: Option<ValueType>,
}
#[derive(Clone)]
pub struct Param {
/// A generated identifier used to name temporary variables
/// used for storing this parameter in generated code.
pub ident: syn::Ident,
}
pub struct ExternalFunc {
/// Assigned index of this function.
pub index: u32,
pub name: String,
// TODO: Rename args to params
pub args: Vec<Param>,
pub return_ty: Option<proc_macro2::Span>,
}
/// The core structure that contains the list of all functions
/// and the data required for implementing a trait.
pub struct ExtDefinition {
/// List of all external functions.
pub funcs: Vec<ExternalFunc>,
/// The generics required to implement a trait for this type.
pub generics: syn::Generics,
/// The type declaration to implement to implement a trait, most typically
/// represented by a structure.
pub ty: Box<syn::Type>,
}
/// Parse an incoming stream of tokens into externalities definition.
pub fn parse(input: proc_macro2::TokenStream) -> Result<ExtDefinition, ()> {
let item_impl = syn::parse2::<syn::ItemImpl>(input).map_err(|_| ())?;