Start refactoring.
This commit is contained in:
parent
af19c66589
commit
b83e6178b8
|
@ -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};
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
extern crate proc_macro;
|
||||
|
||||
mod codegen;
|
||||
mod model;
|
||||
mod parser;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
|
|
@ -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>,
|
||||
}
|
|
@ -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(|_| ())?;
|
||||
|
|
Loading…
Reference in New Issue