2020-09-09 21:40:31 +01:00
|
|
|
/** Serene --- Yet an other Lisp
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-06-20 22:02:17 +01:00
|
|
|
extern crate inkwell;
|
2020-06-16 09:27:32 +01:00
|
|
|
|
2020-06-20 18:20:10 +01:00
|
|
|
use clap::{load_yaml, App};
|
2020-06-19 19:37:00 +01:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io;
|
|
|
|
use std::io::prelude::*;
|
2020-06-14 21:02:31 +01:00
|
|
|
use std::string::String;
|
2020-06-13 17:55:27 +01:00
|
|
|
|
|
|
|
pub mod ast;
|
2020-09-13 19:29:17 +01:00
|
|
|
pub mod builtins;
|
2020-06-20 22:02:17 +01:00
|
|
|
pub mod compiler;
|
2020-06-27 22:12:09 +01:00
|
|
|
pub mod namespace;
|
2020-06-16 09:27:32 +01:00
|
|
|
pub mod reader;
|
2020-07-06 14:18:29 +01:00
|
|
|
pub mod scope;
|
2020-06-20 22:02:17 +01:00
|
|
|
pub mod types;
|
2020-09-13 19:29:17 +01:00
|
|
|
pub mod values;
|
2020-06-13 17:55:27 +01:00
|
|
|
|
2020-06-19 19:37:00 +01:00
|
|
|
fn main() -> io::Result<()> {
|
2020-06-20 18:20:10 +01:00
|
|
|
let yaml = load_yaml!("cli.yml");
|
|
|
|
let args = App::from(yaml).get_matches();
|
2020-09-12 12:34:08 +01:00
|
|
|
|
|
|
|
// Create a compiler
|
2020-09-09 21:21:04 +01:00
|
|
|
let context = compiler::create_context();
|
2020-09-12 12:34:08 +01:00
|
|
|
let mut compiler = compiler::Compiler::new(&context);
|
|
|
|
|
2020-09-20 22:22:18 +01:00
|
|
|
compiler.create_ns("user".to_string(), None);
|
|
|
|
compiler.set_current_ns("user".to_string());
|
2020-06-14 21:02:31 +01:00
|
|
|
|
2020-06-20 18:20:10 +01:00
|
|
|
if let Some(input) = args.value_of("INPUT") {
|
|
|
|
let mut f = File::open(input)?;
|
2020-06-19 19:37:00 +01:00
|
|
|
|
2020-06-20 18:20:10 +01:00
|
|
|
let mut buf = String::new();
|
|
|
|
f.read_to_string(&mut buf)?;
|
|
|
|
match reader::read_string(&buf) {
|
2020-09-12 14:12:04 +01:00
|
|
|
Ok(v) => {
|
2020-09-14 21:46:52 +01:00
|
|
|
println!("AST: {:#?}", v);
|
2020-09-18 21:52:45 +01:00
|
|
|
|
2020-09-20 22:22:18 +01:00
|
|
|
let g = compiler::compile(&mut compiler, v);
|
2020-09-12 14:12:04 +01:00
|
|
|
println!("GEN: {:?}", g)
|
|
|
|
}
|
2020-06-20 18:20:10 +01:00
|
|
|
Err(e) => println!(">> error {:?}", e),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("Input file is missing.")
|
2020-06-19 19:37:00 +01:00
|
|
|
}
|
2020-09-12 14:12:04 +01:00
|
|
|
|
2020-06-19 19:37:00 +01:00
|
|
|
Ok(())
|
2020-06-05 22:23:14 +01:00
|
|
|
}
|