From 14f31a518653357a025810eca36a5727b69be6ae Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 27 Apr 2018 02:19:09 -0700 Subject: [PATCH] Adding proc macro for codegen This should hopefully make the compiler pass thing I want to do possible --- Cargo.toml | 1 + TODO.md | 9 +++++++++ schala-codegen/Cargo.toml | 9 +++++++++ schala-codegen/src/lib.rs | 16 ++++++++++++++++ schala-lang/Cargo.toml | 1 + schala-lang/src/lib.rs | 4 ++++ 6 files changed, 40 insertions(+) create mode 100644 schala-codegen/Cargo.toml create mode 100644 schala-codegen/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index b02bc4f..302a881 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ authors = ["greg "] [dependencies] schala-repl = { path = "schala-repl" } +schala-codegen = { path = "schala-codegen" } maaru-lang = { path = "maaru" } rukka-lang = { path = "rukka" } robo-lang = { path = "robo" } diff --git a/TODO.md b/TODO.md index 8133315..bed20ee 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,15 @@ # TODO Items + +- sketch of an idea for the REPL: + -each compiler pass should be a (procedural?) macro like + compiler_pass!("parse", dataproducts: ["ast", "parse_tree"], { + match parsing::parse(INPUT) { + Ok( + PASS.add_artifact( + } + -should have an Idris-like `cast To From` function - REPL: diff --git a/schala-codegen/Cargo.toml b/schala-codegen/Cargo.toml new file mode 100644 index 0000000..28c33b8 --- /dev/null +++ b/schala-codegen/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "schala-codegen" +version = "0.1.0" +authors = ["greg "] + +[dependencies] + +[lib] +proc-macro = true diff --git a/schala-codegen/src/lib.rs b/schala-codegen/src/lib.rs new file mode 100644 index 0000000..9588701 --- /dev/null +++ b/schala-codegen/src/lib.rs @@ -0,0 +1,16 @@ +#![feature(proc_macro)] +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() +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/schala-lang/Cargo.toml b/schala-lang/Cargo.toml index 622a126..5ec98b6 100644 --- a/schala-lang/Cargo.toml +++ b/schala-lang/Cargo.toml @@ -10,3 +10,4 @@ maplit = "*" lazy_static = "0.2.8" schala-repl = { path = "../schala-repl" } +schala-codegen = { path = "../schala-codegen" } diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 12dfa1b..b948cd3 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -1,4 +1,5 @@ #![feature(slice_patterns, box_patterns, box_syntax)] +#![feature(proc_macro)] extern crate itertools; #[macro_use] extern crate lazy_static; @@ -6,6 +7,7 @@ extern crate lazy_static; extern crate maplit; extern crate schala_repl; +extern crate schala_codegen; use itertools::Itertools; use schala_repl::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, UnfinishedComputation, FinishedComputation}; @@ -47,6 +49,8 @@ impl ProgrammingLanguageInterface for Schala { } fn execute(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation { + schala_codegen::print_a_thing!(); + let mut evaluation = UnfinishedComputation::default(); //tokenzing