Skip to content

Commit

Permalink
Create file after compilation succeeds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlamonster committed Nov 26, 2023
1 parent 87b9cb9 commit bc1c5a3
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions compiler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#![allow(clippy::module_inception)]

extern crate core;

pub mod interpreter;
pub mod passes;
pub mod utils;

use crate::passes::parse::parse::parse_program;
use miette::{NamedSource, Report};
use miette::{IntoDiagnostic, NamedSource, Report};
use std::fs::File;
use std::path::Path;

pub fn compile(program: &str, filename: &str, output: &Path) -> miette::Result<()> {
let mut file = File::create(output).unwrap();

let add_source =
|error| Report::with_source_code(error, NamedSource::new(filename, program.to_string()));

Expand All @@ -32,7 +28,7 @@ pub fn compile(program: &str, filename: &str, output: &Path) -> miette::Result<(
.patch()
.conclude()
.emit()
.write(&mut file);
.write(&mut File::create(output).into_diagnostic()?);

Ok(())
}

0 comments on commit bc1c5a3

Please sign in to comment.