1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#![allow(unsafe_op_in_unsafe_fn)]
mod compiler;
mod errors;
mod lexer;
mod parser;
mod size;
mod unicode;
use std::ffi::OsString;
use std::thread;
use clap::Parser;
#[derive(Clone, Copy, Default)]
pub struct Flags {
pub debug_lexer: bool,
pub debug_parser: bool,
pub threads: usize,
pub error_style: errors::ErrorStyle,
}
#[derive(Parser)]
struct Args {
#[arg(short = 'l', long)]
debug_lexer: bool,
#[arg(short = 'p', long)]
debug_parser: bool,
#[arg(short = 's', long, default_value = "standard")]
error_style: errors::ErrorStyle,
#[arg(short = 't', long)]
threads: Option<usize>,
files: Vec<OsString>,
}
fn main() {
let args = Args::parse();
let threads = args.threads.unwrap_or_else(|| {
thread::available_parallelism().map_or_else(
|e| {
warn!(e, "failed to get thread count");
1
},
|x| x.get(),
)
});
if threads == 0 {
err!("thread count must be greater than 0");
}
let flags = Flags {
debug_lexer: args.debug_lexer,
debug_parser: args.debug_parser,
threads,
error_style: args.error_style,
};
let _ = errors::ERROR_STYLE.set(flags.error_style);
compiler::start(args.files, flags);
}
|