mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
compiler options
This commit is contained in:
parent
682178bec9
commit
63701f743b
31
Cargo.lock
generated
31
Cargo.lock
generated
|
@ -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"
|
||||
|
|
15
README.md
15
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)
|
||||
|
|
|
@ -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"
|
||||
codegen = { path = "../codegen" }
|
25
crates/main/src/config.rs
Normal file
25
crates/main/src/config.rs
Normal file
|
@ -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<Config, Error> {
|
||||
let config: Config = from_str(toml_content)?;
|
||||
Ok(config)
|
||||
}
|
|
@ -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!(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
hades.toml
Normal file
2
hades.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
[compiler]
|
||||
compiler = "clang++"
|
Loading…
Reference in a new issue