fix docs, and init stdlib when configuring

This commit is contained in:
Aidan Hahn 2021-11-08 00:59:14 -08:00
parent 1b1ac3cd2b
commit 827458b06f
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 16 additions and 7 deletions

View file

@ -15,7 +15,7 @@ The following are important variables that will determine the runtime behavior o
| Variable | Default Value | Explanation | | Variable | Default Value | Explanation |
|-|-|-| |-|-|-|
| CFG_RELISH_POSIX | 1 | When on, enables POSIX style job control. [more information.](shell.md) | | CFG_RELISH_POSIX | 0 | When on, enables POSIX style job control. [more information.](shell.md) |
| CFG_RELISH_ENV | 1 | When on, variables defined will be synchronized with environment variables. | | CFG_RELISH_ENV | 1 | When on, variables defined will be synchronized with environment variables. |
| CFG_RELISH_PROMPT | (echo "λ ") | *note: this is a function not a variable*. This function will be called to output the prompt each time the REPL loops. | | CFG_RELISH_PROMPT | (echo "λ ") | *note: this is a function not a variable*. This function will be called to output the prompt each time the REPL loops. |

View file

@ -17,7 +17,7 @@ Relish is a language meant to iterate on the ideas and designs that were tested
- TESTS TESTS TESTS - TESTS TESTS TESTS
## Configuration ## Configuration
[See docs here](CONFIGURATION.md) [See docs here](CONFIGURING.md)
## Compilation ## Compilation
`$ cargo build` `$ cargo build`

View file

@ -28,14 +28,16 @@ use relish::stdlib::{get_stdlib};
fn main() { fn main() {
let mut rl = Editor::<()>::new(); let mut rl = Editor::<()>::new();
const HIST_FILE: &str = ".relish_hist"; const HIST_FILE: &str = "/.relish_hist";
const CONFIG_FILE_DEFAULT: &str = ".relishrc"; const CONFIG_FILE_DEFAULT: &str = "/.relishrc";
let mut hist: String = "".to_owned(); let mut hist: String = "".to_owned();
let mut cfg: String = "".to_owned();
if let Some(home) = home_dir() { if let Some(home) = home_dir() {
if let Some(h) = home.to_str() { if let Some(h) = home.to_str() {
hist = h.to_owned() + HIST_FILE; hist = h.to_owned() + HIST_FILE;
cfg = h.to_owned() + CONFIG_FILE_DEFAULT;
} }
} }
@ -50,7 +52,7 @@ fn main() {
match env::var("RELISH_CFG_FILE") { match env::var("RELISH_CFG_FILE") {
Ok(s) => configure(s, vt.clone(), ft.clone()), Ok(s) => configure(s, vt.clone(), ft.clone()),
Err(_) => configure(String::from(CONFIG_FILE_DEFAULT), vt.clone(), ft.clone()) Err(_) => configure(cfg, vt.clone(), ft.clone())
} }
match get_stdlib(vt.clone()) { match get_stdlib(vt.clone()) {

View file

@ -20,13 +20,20 @@ use crate::func::{FTable, Args, Function, Operation, func_declare};
use crate::segment::{Ast, Ctr}; use crate::segment::{Ast, Ctr};
use crate::lex::lex; use crate::lex::lex;
use crate::eval::eval; use crate::eval::eval;
use crate::stl::get_stdlib;
use std::rc::Rc; use std::rc::Rc;
use std::cell::RefCell; use std::cell::RefCell;
use std::fs; use std::fs;
pub fn configure(filename: String, vars: Rc<RefCell<VTable>>, funcs: Rc<RefCell<FTable>>) { 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("1")))); define(vars.clone(), String::from("CFG_RELISH_POSIX"), Rc::new(Ctr::String(String::from("0"))));
define(vars.clone(), String::from("CFG_RELISH_ENV"), Rc::new(Ctr::String(String::from("1")))); define(vars.clone(), String::from("CFG_RELISH_ENV"), Rc::new(Ctr::String(String::from("1"))));
match get_stdlib(vars.clone()) {
Ok(f) => funcs = f,
Err(s) => println!("{}", s)
}
func_declare(funcs.clone(), Rc::new(RefCell::new(Function{ func_declare(funcs.clone(), Rc::new(RefCell::new(Function{
name: String::from("CFG_RELISH_PROMPT"), name: String::from("CFG_RELISH_PROMPT"),
loose_syms: false, loose_syms: false,