use std::{fs::File, io::Read, collections::LinkedList, process::exit}; use logos::Logos; use parser::{program::Program, Parsable, WrappedLexer}; mod token; mod parser; mod ir; fn main() -> std::io::Result<()> { let mut input_file = File::open("sample-initial.amo")?; let mut input = String::with_capacity(4096); input_file.read_to_string(&mut input)?; let lexer = token::Token::lexer(&input); let mut wrapped_lexer = WrappedLexer::new(lexer); let program = match Program::parse(&mut wrapped_lexer) { Err(e) => { let location = e.location; eprintln!("Parse error at {location:?}!"); eprintln!("Expected one of:"); for token in e.expected { eprintln!(" - {token:?}"); } exit(1); } Ok(p) => p }; println!("Parse successful!!"); for decl in &program.0 { println!("{decl:?}\n"); } println!("Building IR..."); match program.gen_ir() { Ok(program) => println!( "IR built successfully!\n{}", program.into_iter() .map(|decl| format!("\n\n{decl}")) .collect::(), ), Err(e) => println!("Oh noes! {e:?}"), } Ok(()) } pub fn cons(mut v: Vec, e: T) -> Vec { v.push(e); v } pub fn cons_ll(mut v: LinkedList, e: T) -> LinkedList { v.push_back(e); v } pub fn join(mut a: LinkedList, mut b: LinkedList) -> LinkedList { a.append(&mut b); a } pub fn join_vec(mut a: Vec, mut b: Vec) -> Vec { a.append(&mut b); a }