summaryrefslogtreecommitdiff
path: root/autochomp/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'autochomp/src/main.rs')
-rw-r--r--autochomp/src/main.rs36
1 files changed, 34 insertions, 2 deletions
diff --git a/autochomp/src/main.rs b/autochomp/src/main.rs
index 493204d..ec50a92 100644
--- a/autochomp/src/main.rs
+++ b/autochomp/src/main.rs
@@ -5,6 +5,18 @@ use std::{
};
use chewed::{IterWrapper, Parser};
+use chomp::{
+ chomp::{
+ ast::substitute::InlineCalls,
+ typed::{
+ context::Context,
+ lower::{Backend, GenerateCode},
+ TypeInfer,
+ },
+ visit::Visitable,
+ },
+ lower::RustBackend,
+};
mod nibble;
@@ -18,8 +30,28 @@ fn main() {
.parse::<nibble::Ast>()
.map_err(|e| Box::new(e) as Box<dyn Error>)
})
- .and_then(|ast| {
- write!(io::stdout(), "{:?}", ast).map_err(|e| Box::new(e) as Box<dyn Error>)
+ .and_then(|ast| ast.convert().map_err(|e| Box::new(e) as Box<dyn Error>))
+ .and_then(|(funs, goal)| {
+ funs.into_iter()
+ .try_rfold(goal, |goal, function| {
+ goal.fold(&mut InlineCalls { function })
+ })
+ .map_err(|e| Box::new(e) as Box<dyn Error>)
+ })
+ .and_then(|term| {
+ let mut context = Context::default();
+ term.fold(&mut TypeInfer {
+ context: &mut context,
+ })
+ .map_err(|e| Box::new(e) as Box<dyn Error>)
+ })
+ .map(|typed| {
+ let mut backend = RustBackend::default();
+ let id = typed.gen(&mut backend);
+ backend.emit_code(None, None, id)
+ })
+ .and_then(|code| {
+ write!(io::stdout(), "{:#}", code).map_err(|e| Box::new(e) as Box<dyn Error>)
});
if let Err(e) = res {