2021-11-07 22:04:57 -08:00
|
|
|
/* relish: versatile lisp shell
|
|
|
|
|
* Copyright (C) 2021 Aidan Hahn
|
|
|
|
|
*
|
|
|
|
|
* 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 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
use crate::vars::{VTable, define};
|
2021-12-31 11:00:13 -08:00
|
|
|
use crate::func::{FTable, Args, Function, Operation, InternalOperation, func_declare};
|
2021-11-07 22:04:57 -08:00
|
|
|
use crate::segment::{Ast, Ctr};
|
|
|
|
|
use crate::lex::lex;
|
|
|
|
|
use crate::eval::eval;
|
2021-11-08 00:59:14 -08:00
|
|
|
use crate::stl::get_stdlib;
|
2021-11-07 22:04:57 -08:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
use std::cell::RefCell;
|
|
|
|
|
use std::fs;
|
|
|
|
|
|
2021-12-31 11:00:13 -08:00
|
|
|
/*
|
|
|
|
|
fn get_prompt_default() -> InternalOperation {
|
|
|
|
|
|_: Ast, _: Rc<RefCell<VTable>>, _: Rc<RefCell<FTable>>| -> Ctr {
|
|
|
|
|
print!("λ ");
|
|
|
|
|
return Ctr::None;
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
2021-11-08 00:59:14 -08:00
|
|
|
pub fn configure(filename: String, vars: Rc<RefCell<VTable>>, mut funcs: Rc<RefCell<FTable>>) {
|
|
|
|
|
define(vars.clone(), String::from("CFG_RELISH_POSIX"), Rc::new(Ctr::String(String::from("0"))));
|
2021-11-07 22:04:57 -08:00
|
|
|
define(vars.clone(), String::from("CFG_RELISH_ENV"), Rc::new(Ctr::String(String::from("1"))));
|
2021-11-08 00:59:14 -08:00
|
|
|
|
|
|
|
|
match get_stdlib(vars.clone()) {
|
|
|
|
|
Ok(f) => funcs = f,
|
|
|
|
|
Err(s) => println!("{}", s)
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 11:00:13 -08:00
|
|
|
/*
|
2021-11-07 22:04:57 -08:00
|
|
|
func_declare(funcs.clone(), Rc::new(RefCell::new(Function{
|
|
|
|
|
name: String::from("CFG_RELISH_PROMPT"),
|
|
|
|
|
loose_syms: false,
|
|
|
|
|
eval_lazy: false,
|
|
|
|
|
args: Args::Lazy(0),
|
2021-12-31 11:00:13 -08:00
|
|
|
function: Operation::Internal(get_prompt_default())
|
|
|
|
|
})));*/
|
2021-11-07 22:04:57 -08:00
|
|
|
|
|
|
|
|
match fs::read_to_string(filename) {
|
|
|
|
|
Err(s) => {
|
|
|
|
|
eprintln!("Couldnt open configuration file: {}", s);
|
|
|
|
|
return
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Ok(raw_config) => {
|
|
|
|
|
match lex(raw_config) {
|
|
|
|
|
Err(s) => {
|
|
|
|
|
println!("Error in configuration: {}", s);
|
|
|
|
|
return
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Ok(config) => {
|
|
|
|
|
match eval(config, vars, funcs, false) {
|
|
|
|
|
Err(s) => {
|
|
|
|
|
println!("Error in applying configuration: {}", s);
|
|
|
|
|
return
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Ok(ctr) => {
|
|
|
|
|
match ctr {
|
|
|
|
|
Ctr:: String(s) => println!("{}", s),
|
|
|
|
|
_ => ()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|