]> Witch of Git - ivy/blob - src/main.rs
Add an extensible framework for adding built-ins
[ivy] / src / main.rs
1 use std::io::{self, Read};
2 use ivy::{parse, BUILTINS, ast::Ast, trans::{self, translate}};
3
4 fn main() -> io::Result<()> {
5 let stdin = std::io::stdin();
6 let mut text = String::new();
7 stdin.lock().read_to_string(&mut text)?;
8 let sexp = match parse(&text) {
9 Ok(item) => item,
10 Err(err) => {
11 println!("{:?}", err);
12 std::process::exit(1);
13 }
14 };
15 let (ast, mut builtins) = match Ast::parse(BUILTINS, &sexp) {
16 Ok(ast) => ast,
17 Err(err) => {
18 println!("{}", err);
19 std::process::exit(1);
20 }
21 };
22 let code = match translate(&ast) {
23 Ok(code) => code,
24 Err(err) => {
25 println!("{}", err);
26 std::process::exit(1);
27 }
28 };
29 builtins.retain(|_, v| code.globals.contains(&v.global_number().unwrap()));
30 let stdout = std::io::stdout();
31 trans::x64::write_compile(&builtins, &mut stdout.lock(), &code)?;
32 Ok(())
33 }