diff --git a/Cargo.lock b/Cargo.lock index 66a4e1e..588e4e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,14 +154,15 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" name = "hc" version = "0.1.0" dependencies = [ - "ariadne", - "chumsky", "clap", "codegen", "diagnostic", "hir", "lexer", "parser", + "serde", + "serde_derive", + "toml", ] [[package]] @@ -286,6 +287,23 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "serde" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" + +[[package]] +name = "serde_derive" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "strsim" version = "0.10.0" @@ -327,6 +345,15 @@ dependencies = [ "crunchy", ] +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + [[package]] name = "unicode-xid" version = "0.2.2" diff --git a/README.md b/README.md index 69b4e00..f59c2cd 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,21 @@ Programming language that compiles to C++! Note: Everything in this project can be changed at anytime! (I'm still finding out what work best for lots of thing) if you have an idea, feel free to create an issues about it, or even create a PR! (I'd be very happy) # Prerequistie -- `clang++`(preferred) or any C++ compiler +- `clang++`(preferred, default) or any C++ compiler - Rust (if you're going to build from source) +# (Compiler) Configuration +You can also configurate Hades compiler (currently you can only change the C++ compiler). Make a new file called `hades.toml` in the current working directory and the compiler will look for it! if there isn't one then it will use the default configuration: +```toml +[compiler] +compiler = "clang++" +``` + # TODO +> This is only contains important TODOs, smaller TODOs isn't listed here and instead scattered around among sources code. +- More compiler configuration (e.x. complier options) - Optimization (IR) -- Error reporting (probably with Ariadne crate) -- Standard library -- Runtime stuff +- Standard library & Runtime stuff # License Hades is licensed under both [MIT license](https://github.com/azur1s/hades/blob/master/LICENSE-MIT) and [Apache License](https://github.com/azur1s/hades/blob/master/LICENSE-APACHE) diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml index 5c9ea72..2e84fca 100644 --- a/crates/main/Cargo.toml +++ b/crates/main/Cargo.toml @@ -5,11 +5,21 @@ version = "0.1.0" edition = "2021" [dependencies] +# Argument handling clap = { version = "3.0.14", features = ["derive"] } + +# Configuration +toml = "0.5" +serde = "1.0.136" +serde_derive = "1.0.136" + +# Parsing lexer = { path = "../lexer" } parser = { path = "../parser" } + +# Diagnostics diagnostic = { path = "../diagnostic" } + +# Codegen hir = { path = "../hir" } -codegen = { path = "../codegen" } -chumsky = "0.8.0" -ariadne = "0.1.5" \ No newline at end of file +codegen = { path = "../codegen" } \ No newline at end of file diff --git a/crates/main/src/config.rs b/crates/main/src/config.rs new file mode 100644 index 0000000..4407414 --- /dev/null +++ b/crates/main/src/config.rs @@ -0,0 +1,25 @@ +use serde_derive::Deserialize; +use toml::{from_str, de::Error}; + +#[derive(Deserialize)] +pub struct Config { + pub compiler: CompilerOptions, +} + +#[derive(Deserialize)] +pub struct CompilerOptions { + pub compiler: String, +} + +pub fn default_config() -> Config { + Config { + compiler: CompilerOptions { + compiler: "clang++".to_string(), + }, + } +} + +pub fn parse_config(toml_content: &str) -> Result { + let config: Config = from_str(toml_content)?; + Ok(config) +} \ No newline at end of file diff --git a/crates/main/src/main.rs b/crates/main/src/main.rs index 6360f01..a9e9085 100644 --- a/crates/main/src/main.rs +++ b/crates/main/src/main.rs @@ -1,4 +1,4 @@ -use std::{fs, io::Write}; +use std::{fs, io::Write, process::Command}; use clap::Parser as ArgParser; @@ -11,10 +11,31 @@ use codegen::cpp; pub mod args; use args::{Args, Options}; +pub mod config; + pub mod util; use crate::util::log; fn main() { + let config_file = fs::read_to_string("./hades.toml"); + let config: config::Config; + match config_file { + Ok(content) => { + let parsed = config::parse_config(&content); + match parsed { + Ok(c) => config = c, + Err(e) => { + log(2, format!("{}", e)); + config = config::default_config(); + } + } + } + Err(e) => { + log(1, format!("Error reading config file: {}, using default config", e)); + config = config::default_config(); + } + } + let args = Args::parse(); match args.options { Options::Compile { @@ -81,11 +102,15 @@ fn main() { let duration = start.elapsed().as_millis(); logif!(0, format!("Compilation took {}ms", duration)); - logif!(0, format!("Wrote output to `{}`. All done.", output_path.display())); + logif!(0, format!("Wrote output to `{}`", output_path.display())); + + let compiler = &config.compiler.compiler; + Command::new(compiler) + .arg(&output_path) + .spawn() + .expect("Failed to run compiler"); }, - None => { - unreachable!(); - } + None => { unreachable!(); } } } } diff --git a/hades.toml b/hades.toml new file mode 100644 index 0000000..bf19bbb --- /dev/null +++ b/hades.toml @@ -0,0 +1,2 @@ +[compiler] +compiler = "clang++" \ No newline at end of file