1
0
Fork 0

Finalize error handling

This commit is contained in:
Vili Sinervä 2025-02-26 23:30:04 +02:00
parent 3e4d3fad7d
commit e67eeaaa81
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
5 changed files with 165 additions and 95 deletions

View file

@ -26,7 +26,7 @@ mod variable;
pub fn compile(code: &str) -> Result<String, Box<dyn Error>> {
let tokens = tokenize(code)?;
let mut ast = parse(&tokens)?;
type_check(&mut ast, &mut SymTab::new_type_table());
type_check(&mut ast, &mut SymTab::new_type_table())?;
let ir = generate_ir(&ast);
let assembly = generate_assembly(&ir);
@ -38,10 +38,7 @@ pub fn start_compiler() {
for line in lines.map_while(Result::ok) {
match compile(&line) {
Ok(_) => println!("\nCompilation OK :)\n"),
Err(e) => println!(
"{}",
format!("{{\"error\": {}}}", json::stringify(format!("{e}")))
),
Err(e) => println!("\n{e}\n"),
}
}
}