Actually autogenerate the trait

This commit is contained in:
greg 2018-05-02 02:14:36 -07:00
parent 50236ac942
commit 51cdedb9cc
2 changed files with 34 additions and 1 deletions

View File

@ -13,14 +13,43 @@ pub fn print_a_thing(_input: TokenStream) -> TokenStream {
}
#[proc_macro_derive(ProgrammingLanguageInterface)]
#[proc_macro_derive(ProgrammingLanguageInterface, attributes(LanguageName, FileExtension, PipelineSteps))]
pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream {
let ast: DeriveInput = syn::parse(input).unwrap();
let name = &ast.ident;
let tokens = quote! {
impl ProgrammingLanguageInterface for #name {
fn get_language_name(&self) -> String {
"Schala".to_string()
}
fn get_source_file_suffix(&self) -> String {
format!("schala")
}
fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation {
let mut chain = pass_chain![self, options;
tokenizing_stage,
parsing_stage,
symbol_table_stage,
typechecking_stage,
eval_stage
];
chain(input)
}
fn get_stages(&self) -> Vec<String> {
vec![
format!("tokenizing_stage"),
format!("parsing_stage"), //TODO handle both types of this
format!("symbol_table_stage"),
format!("typechecking_stage"),
format!("eval_stage")
]
}
}
};
tokens.into()
}

View File

@ -8,6 +8,7 @@ extern crate maplit;
#[macro_use]
extern crate schala_repl;
#[macro_use]
extern crate schala_codegen;
use itertools::Itertools;
@ -26,6 +27,7 @@ mod eval;
use self::typechecking::{TypeContext};
#[derive(ProgrammingLanguageInterface)]
pub struct Schala {
state: eval::State<'static>,
type_context: TypeContext
@ -98,6 +100,7 @@ fn eval_stage(handle: &mut Schala, input: parsing::AST, _comp: Option<&mut Unfin
eval_output
}
/*
impl ProgrammingLanguageInterface for Schala {
fn get_language_name(&self) -> String {
"Schala".to_string()
@ -128,3 +131,4 @@ impl ProgrammingLanguageInterface for Schala {
]
}
}
*/