From 51cdedb9cc5f52e3ca067b26360eb8b2682a798f Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 2 May 2018 02:14:36 -0700 Subject: [PATCH] Actually autogenerate the trait --- schala-codegen/src/lib.rs | 31 ++++++++++++++++++++++++++++++- schala-lang/src/lib.rs | 4 ++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/schala-codegen/src/lib.rs b/schala-codegen/src/lib.rs index 856f196..89ecab8 100644 --- a/schala-codegen/src/lib.rs +++ b/schala-codegen/src/lib.rs @@ -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 { + 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() } diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 6a728bb..c5f0b1d 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -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 { ] } } +*/