From 24ff5f311f6c797681be1cff0fb2d0b75c0f848f Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Thu, 14 Jan 2021 14:37:27 +0000 Subject: Finish AutoChomp --- autochomp/src/main.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'autochomp/src/main.rs') 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::() .map_err(|e| Box::new(e) as Box) }) - .and_then(|ast| { - write!(io::stdout(), "{:?}", ast).map_err(|e| Box::new(e) as Box) + .and_then(|ast| ast.convert().map_err(|e| Box::new(e) as Box)) + .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) + }) + .and_then(|term| { + let mut context = Context::default(); + term.fold(&mut TypeInfer { + context: &mut context, + }) + .map_err(|e| Box::new(e) as Box) + }) + .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) }); if let Err(e) = res { -- cgit v1.2.3