Starting codegen work

This commit is contained in:
greg 2018-04-28 00:08:16 -07:00
parent 82cfd3f03d
commit 2c79984678
4 changed files with 53 additions and 4 deletions

View File

@ -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(<name of 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);
}
*/

View File

@ -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();

View File

@ -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")) }
}

View File

@ -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()
}