From 2c79984678b3b0060b91254a4d018f48ca1ded64 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 28 Apr 2018 00:08:16 -0700 Subject: [PATCH] Starting codegen work --- schala-codegen/src/lib.rs | 44 +++++++++++++++++++++++++++++++++++-- schala-lang/src/lib.rs | 7 +++++- schala-repl/src/language.rs | 4 ++++ schala-repl/src/lib.rs | 2 +- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/schala-codegen/src/lib.rs b/schala-codegen/src/lib.rs index 9588701..4f78247 100644 --- a/schala-codegen/src/lib.rs +++ b/schala-codegen/src/lib.rs @@ -3,8 +3,21 @@ extern crate proc_macro; use proc_macro::TokenStream; #[proc_macro] -pub fn print_a_thing(_input: TokenStream) -> TokenStream { - "println!(\"Invoked from a proc macro\");".parse().unwrap() +pub fn compiler_pass_sequence(input: TokenStream) -> TokenStream { + r#" + fn new_execute(&mut self, input: &str, _options: &EvalOptions) -> FinishedComputation { + let mut evaluation = UnfinishedComputation::default(); + evaluation.output(Err("this comes at ye from the macro".to_string())) + } + "#.parse().unwrap() +} + +/* #[compiler_pass(*/ +#[proc_macro_attribute] +pub fn compiler_pass(metadata: TokenStream, function: TokenStream) -> TokenStream { + //println!("FROM MACRO: {}", function); + println!("Compiler pass metadata: {}", metadata); + function } #[cfg(test)] @@ -14,3 +27,30 @@ mod tests { assert_eq!(2 + 2, 4); } } + + +/* in Rocket + * + + #[get("/")] + fn hi() -> &'static str { + "hello" + } + + GETS MAPPED TO: + + static hi_info = RouteInfo { + name: "hi", + method: Method::Get, + path: "/", + handler: hi_route, + } + + fn hi_route(req: &Request) -> Outcome { + let responder = hi(); + Outcome::from(req, responder); + } + + + + */ diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index b948cd3..bfdb6f5 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -9,6 +9,7 @@ extern crate maplit; extern crate schala_repl; extern crate schala_codegen; +use std::collections::HashMap; use itertools::Itertools; use schala_repl::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, UnfinishedComputation, FinishedComputation}; @@ -25,6 +26,7 @@ mod eval; use self::typechecking::{TypeContext}; +/* TODO eventually custom-derive ProgrammingLanguageInterface with compiler passes as options */ pub struct Schala { state: eval::State<'static>, type_context: TypeContext @@ -40,6 +42,9 @@ impl Schala { } impl ProgrammingLanguageInterface for Schala { + + schala_codegen::compiler_pass_sequence!("tok", "pars", "exec"); + fn get_language_name(&self) -> String { "Schala".to_string() } @@ -48,8 +53,8 @@ impl ProgrammingLanguageInterface for Schala { format!("schala") } + #[schala_codegen::compiler_pass = "yolo"] fn execute(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation { - schala_codegen::print_a_thing!(); let mut evaluation = UnfinishedComputation::default(); diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index c4d65e4..96ab800 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -163,6 +163,10 @@ pub trait ProgrammingLanguageInterface { } /* old */ + fn new_execute(&mut self, input: &str, _options: &EvalOptions) -> FinishedComputation { + FinishedComputation { artifacts: HashMap::new(), text_output: Err(format!("NOT DONE")) } + } + fn execute(&mut self, _input: &str, _eval_options: &EvalOptions) -> FinishedComputation { FinishedComputation { artifacts: HashMap::new(), text_output: Err(format!("REPL evaluation not implemented")) } } diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index fc03bf9..3c50d1f 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -210,7 +210,7 @@ impl Repl { fn input_handler(&mut self, input: &str) -> String { let ref mut language = self.languages[self.current_language_index]; - let interpreter_output = language.execute(input, &self.options); + let interpreter_output = language.new_execute(input, &self.options); interpreter_output.to_repl() }