diff --git a/src/main.rs b/src/main.rs index a7a2cc1..d782d69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,44 +31,37 @@ fn main() -> std::io::Result<()> { Ok(p) => p }; - println!("Parse successful!!"); - for decl in &program.0 { - println!("{decl:?}\n"); - } + println!("Parse successful! Building IR..."); - println!("Building IR..."); - match program.gen_ir() { - Ok(program) => { - println!( - "IR built successfully!\n{}", - program.iter() - .map(|decl| format!("\n\n{decl}\n\n")) - .collect::(), - ); - - match display_program(program) { - Ok(value) => - println!("Evaluated successfully! Got:\n{value}"), - Err(EvaluateError::UndefinedValue(v)) => - println!("Hit an error: {v} is undefined"), - Err(EvaluateError::EvaluatingZeroLengthExpr) => - println!("Hit an error: Tried to evaluate a series of zero instructions"), - Err(EvaluateError::ArgumentCountMismatch(op, real, ex)) => - println!("Problem while evaluating operation {op:?}: expected {ex} arguments, got {real}"), - Err(EvaluateError::FunctionArgumentCountMismatch(real, ex)) => - println!("Problem while evaluating a function: expected {ex} arguments, got {real}"), - Err(EvaluateError::TypeMismatch(a, b)) => - println!("Type mismatch between {a:?} and {b:?}!"), - Err(EvaluateError::NoMain) => - println!("Huh, there's no main method"), - Err(EvaluateError::MainHasArgs) => - println!("Your main method has args, but that's not allowed"), - Err(EvaluateError::IncompleteConditional) => - println!("Uh oh, a conditional somewhere isn't complete!"), - } + let program = match program.gen_ir() { + Ok(program) => program, + Err(e) => { + println!("Oh noes! {e:?}"); + exit(2); } - Err(e) => - println!("Oh noes! {e:?}"), + }; + + println!("IR built successfully! Evaluating..."); + + match display_program(program) { + Ok(value) => + println!("Evaluated successfully!\n\n{value}"), + Err(EvaluateError::UndefinedValue(v)) => + println!("Hit an error: {v} is undefined"), + Err(EvaluateError::EvaluatingZeroLengthExpr) => + println!("Hit an error: Tried to evaluate a series of zero instructions"), + Err(EvaluateError::ArgumentCountMismatch(op, real, ex)) => + println!("Problem while evaluating operation {op:?}: expected {ex} arguments, got {real}"), + Err(EvaluateError::FunctionArgumentCountMismatch(real, ex)) => + println!("Problem while evaluating a function: expected {ex} arguments, got {real}"), + Err(EvaluateError::TypeMismatch(a, b)) => + println!("Type mismatch between {a:?} and {b:?}!"), + Err(EvaluateError::NoMain) => + println!("Huh, there's no main method"), + Err(EvaluateError::MainHasArgs) => + println!("Your main method has args, but that's not allowed"), + Err(EvaluateError::IncompleteConditional) => + println!("Uh oh, a conditional somewhere isn't complete!"), } Ok(()) } diff --git a/src/parser/program.rs b/src/parser/program.rs index 9147761..22222d6 100644 --- a/src/parser/program.rs +++ b/src/parser/program.rs @@ -40,7 +40,6 @@ impl Program { .enumerate() .filter_map(|(i, decl)| decl.get_identifier(&Identifier::ROOT, i as u32)) .fold(BindingScope::builtins(), |scope, ident| scope.bind_single(ident)); - println!("DEBUG {root_scope:?}"); self.0.into_iter() .enumerate() .filter_map(|(i, decl)| decl.gen_ir(&root_scope, i as u32, Identifier::ROOT).transpose())