forked from gluon-lang/gluon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
85 lines (74 loc) · 2.16 KB
/
main.rs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#[macro_use]
extern crate log;
#[cfg(feature = "env_logger")]
extern crate env_logger;
extern crate clap;
#[macro_use]
extern crate quick_error;
#[macro_use]
extern crate lazy_static;
extern crate gluon_base as base;
extern crate gluon;
extern crate gluon_check as check;
extern crate gluon_parser as parser;
#[macro_use]
extern crate gluon_vm as vm;
#[cfg(not(test))]
use std::error::Error as StdError;
#[cfg(not(test))]
use gluon::{new_vm, Compiler};
#[cfg(not(test))]
use clap::{Arg, App};
mod repl;
#[cfg(not(test))]
fn run_files<'s, I>(files: I) -> Result<(), Box<StdError + Send + Sync>>
where I: Iterator<Item = &'s str>
{
let vm = new_vm();
let mut compiler = Compiler::new();
for file in files {
try!(compiler.load_file(&vm, file));
}
Ok(())
}
#[cfg(all(not(test), feature = "env_logger"))]
fn init_env_logger() {
::env_logger::init().unwrap();
}
#[cfg(all(not(test), not(feature = "env_logger")))]
fn init_env_logger() {}
#[cfg(not(test))]
fn main() {
// Need the extra stack size when compiling the program using the msvc compiler
::std::thread::Builder::new()
.stack_size(2 * 1024 * 1024)
.spawn(|| {
init_env_logger();
let matches = App::new("gluon")
.about("Executes gluon programs")
.arg(Arg::with_name("INPUT")
.multiple(true)
.help("Executes each file as a gluon program"))
.arg(Arg::with_name("REPL")
.short("i")
.long("interactive")
.help("Starts the repl")
.takes_value(false))
.get_matches();
if matches.is_present("REPL") {
if let Err(err) = repl::run() {
println!("{}", err);
}
} else if let Some(args) = matches.values_of("INPUT") {
match run_files(args) {
Ok(()) => (),
Err(msg) => println!("{}", msg),
}
} else {
println!("{}", matches.usage());
}
})
.unwrap()
.join()
.unwrap();
}