implement load-to-string, revert odd Cargo.toml mistake

This commit is contained in:
Ava Apples Affine 2023-03-30 20:47:22 -07:00
parent dcbc855783
commit d11545bc31
Signed by: affine
GPG key ID: 3A4645B8CF806069
3 changed files with 69 additions and 39 deletions

View file

@ -1,36 +1,12 @@
Readme.org:65:Function calls are executed as soon as the tree is evaluated. See the following example: [package]
Readme.org:324:You can use it by calling it in your shell config (See file:snippets/basic_minimal_configuration.rls for more info). name = "relish"
Readme.org:382:See file:snippets/basic_minimal_configuration.rls for an example of a basic minimal configuration file. version = "0.1.0"
snippets/userlib.rls:13:;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the authors = ["Ava <ava@sunnypup.io>"]
snippets/userlib.rls:45: See the userlib tests for an easy to follow example of this.' edition = "2018"
snippets/userlib-tests.rls:13:;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/eval_draft2.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [dependencies]
snippets/legacy/initial_rough_spaghetti_implementation/eval.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the dirs = "3.0"
snippets/legacy/initial_rough_spaghetti_implementation/bin/main.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nu-ansi-term = "0.47.0"
snippets/legacy/initial_rough_spaghetti_implementation/func.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the reedline = "0.17.0"
snippets/legacy/initial_rough_spaghetti_implementation/segment.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nix = "0.26.2"
snippets/legacy/initial_rough_spaghetti_implementation/control.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ctrlc = { version = "3.0", features = ["termination"] }
snippets/legacy/initial_rough_spaghetti_implementation/stl.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/initial_rough_spaghetti_implementation/str.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/initial_rough_spaghetti_implementation/config.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/initial_rough_spaghetti_implementation/lib.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/initial_rough_spaghetti_implementation/lex.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/initial_rough_spaghetti_implementation/append.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/initial_rough_spaghetti_implementation/vars.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/seperate_tables/func.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snippets/legacy/seperate_tables/vars.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/eval.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/bin/main.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/run.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/segment.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/sym.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/stl.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/stl/posix.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/stl/decl.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/stl/strings.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/stl/control.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/stl/math.rs:10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/stl/boolean.rs:10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/stl/append.rs:10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/lib.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
src/lex.rs:11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

View file

@ -483,8 +483,6 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
** TODO Pre-alpha tasks ** TODO Pre-alpha tasks
- Shell module - Shell module
- call-with (let style fd redirection)
- load-to-string function (userlib extension of call-with)
- pipe control flow construct - pipe control flow construct
- ignore job control signals (if needed) - ignore job control signals (if needed)
- background processes - background processes
@ -495,7 +493,7 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
- pwd - pwd
- Documentation! - Documentation!
- Do I need some linemode management stuff? - Do I need some linemode management stuff?
- Fake load in pre-posix shell outputs "shell not yet configured!" - Function stubs for all posix functions go into minimal shell (posix stub functions)
- Escape sequences in strings - Escape sequences in strings
- logging library - logging library
- make const all the error messages - make const all the error messages

View file

@ -165,6 +165,48 @@ fn load_callback(ast: &Seg, syms: &mut SymTable, state: &mut ShellState) -> Resu
} }
} }
const LOAD_TO_STRING_DOCSTRING: &str = "Calls a binary off disk with given arguments.
Arguments may be of any type except lambda. If a symbol is not defined it will be passed as a string.
first argument (command name) will be found on path (or an error returned).
examples:
(l ping google.com)
(let ((ping-count 4))
(l ping -c ping-count google.com))
(l emacs -nw (concat HOME '/.relishrc'))
Unlike with the normal load function, the load to string function collects stdout output and returns it as a string.
";
fn load_to_string_callback(ast: &Seg, syms: &mut SymTable, state: &mut ShellState) -> Result<Ctr, String> {
if ast.is_empty() {
Err("need at least one argument".to_string())
} else {
let mut args = VecDeque::from(args_from_ast(ast, syms));
if args.is_empty() {
Err("empty command".to_string())
} else {
if let Some(filepath) = run::find_on_path(args.pop_front().unwrap()) {
let res = Command::new(filepath).args(args).output();
if let Ok(output) = res {
if let Some(code) = output.status.code() {
state.last_exit_code = code;
}
if let Ok(string) = String::from_utf8(output.stdout) {
Ok(Ctr::String(string))
} else {
Err(format!("could'nt marshall utf-8 command output into a string"))
}
} else {
Err(format!("{}", res.err().unwrap()))
}
} else {
Err("file not found".to_string())
}
}
}
}
// TODO: rework this callback to reduce spaghett // TODO: rework this callback to reduce spaghett
const LOAD_WITH_DOCSTRING: &str = ""; const LOAD_WITH_DOCSTRING: &str = "";
fn load_with_callback(ast: &Seg, syms: &mut SymTable, state: &mut ShellState) -> Result<Ctr, String> { fn load_with_callback(ast: &Seg, syms: &mut SymTable, state: &mut ShellState) -> Result<Ctr, String> {
@ -346,6 +388,7 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>
let bg_ss = shell_state.clone(); let bg_ss = shell_state.clone();
let q_ss = shell_state.clone(); let q_ss = shell_state.clone();
let lw_ss = shell_state.clone(); let lw_ss = shell_state.clone();
let lts_ss = shell_state.clone();
syms.insert( syms.insert(
String::from("l"), String::from("l"),
@ -417,6 +460,19 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>
}, },
); );
syms.insert(
String::from("load-to-string"),
Symbol {
name: String::from("load-to-string"),
args: Args::Infinite,
conditional_branches: true,
docs: String::from(LOAD_TO_STRING_DOCSTRING),
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
load_to_string_callback(ast, symtable, &mut lts_ss.clone().borrow_mut())
})),
..Default::default()
},
);
if let Err(e) = ctrlc::set_handler(move || println!("POSIX layer caught SIG-something")) { if let Err(e) = ctrlc::set_handler(move || println!("POSIX layer caught SIG-something")) {
eprintln!("WARNING: couldn't set sig handler: {}", e); eprintln!("WARNING: couldn't set sig handler: {}", e);