From ab14ba4b5e9ed725b36858890481b09197edb99a Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Mon, 27 Mar 2023 14:34:07 -0700 Subject: [PATCH] circuit handles load commands better Signed-off-by: Ava Hahn --- Readme.org | 24 +++++++++++++++++------- snippets/basic_minimal_configuration.rls | 2 +- src/lex.rs | 2 +- src/stl.rs | 4 ++-- src/stl/control.rs | 6 +++++- src/stl/posix.rs | 17 ++++++++++++++++- tests/test_lib_control.rs | 2 +- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Readme.org b/Readme.org index 058de78..12c4511 100644 --- a/Readme.org +++ b/Readme.org @@ -320,7 +320,7 @@ It also contains considerably subpar implementations of Relish's internals that *** Userlib The *Userlib* was added as a script containing many valuable functions such as ~set~ and ~prepend~. -You can use it by loading it in your shell config (See file:snippets/basic_minimal_configuration.rls for more info). +You can use it by calling it in your shell config (See file:snippets/basic_minimal_configuration.rls for more info). ** Easy patterns This section contains examples of common composites of control flow that can be used to build more complex or effective applications @@ -407,7 +407,7 @@ Further configuration can be done by loading scripts that contain more functions Variables and functions defined in an external script loaded by your interpreter will persist in the symbol table. #+BEGIN_SRC lisp - (load "my-extra-library-functions.rls") + (call "my-extra-library-functions.rls") #+END_SRC ** Compilation @@ -482,10 +482,9 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt ** TODO Pre-alpha tasks - Shell module - - circuit casts int to bool automatically + - call-with (let style fd redirection) + - load-to-string function (userlib extension of call-with) - pipe control flow construct - - l and load functions for binaries, call for scripts - - load-to-string function - ignore job control signals (if needed) - background processes - be able to list all background processes with j function @@ -493,8 +492,9 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt - be able to bg and fg process (ctrl z?) - changedir/cd - pwd - - call-with (let style fd redirection) - Documentation! + - Do I need some linemode management stuff? +- Escape sequences in strings - logging library - make const all the error messages - make presentation on relish @@ -514,12 +514,21 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt - help - beyond lisp - POSIX + - how to make a shell + - process groups + - tcgetpgrp/tcsetpgrp + - linemode + - getting things off of the path + - calls to exec system call + - signal management + - job control (and process groups) - ergonomics of control flow as shell command - circuit -> pipe - let -> call-with - putting it all together - job control in shell - shell scripts + - fancy prompts - To infinity and beyond - NGINX modules - bootable? @@ -527,11 +536,11 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt - store in repo after giving presentation ** TODO alpha tasks +- Write next_has member function for &Seg and simplify stdlib and probably also eval/sym - Can pass args to relish scripts (via interpreter) - Can pass args to relish scripts (via command line) - History length configurable - Search delim configurable -- Escape sequences in strings - Rename to Flesh - master branch -> main branch - Create a dedicated community channel on matrix.sunnypup.io @@ -547,6 +556,7 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt - File operations - read-to-string - write-to-file + - file exists - color control library - emacs syntax highlighting and/or LSP implementation - GNU Guix package diff --git a/snippets/basic_minimal_configuration.rls b/snippets/basic_minimal_configuration.rls index 0837ed7..7a6fcbb 100644 --- a/snippets/basic_minimal_configuration.rls +++ b/snippets/basic_minimal_configuration.rls @@ -1,5 +1,5 @@ ;; comment out to load USERLIB -;; (load (concat HOME "/.relish/userlib.rls")) +;; (call (concat HOME "/.relish/userlib.rls")) ;; if you have userlib ;; (set CFG_RELISH_POSIX "1") diff --git a/src/lex.rs b/src/lex.rs index d75a2de..6a01804 100644 --- a/src/lex.rs +++ b/src/lex.rs @@ -126,7 +126,7 @@ fn process(document: &String) -> Result, String> { delim_stack.push(')'); } // begin parsing a string - '"' | '\'' | '`' => { + '"' | '\'' | '`' if !is_str => { is_str = true; delim_stack.push(c); } diff --git a/src/stl.rs b/src/stl.rs index 4e3743e..51091ef 100644 --- a/src/stl.rs +++ b/src/stl.rs @@ -586,9 +586,9 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> { ); syms.insert( - "load".to_string(), + "call".to_string(), Symbol { - name: String::from("load"), + name: String::from("call"), args: Args::Strict(vec![Type::String]), conditional_branches: false, docs: RUN_DOCSTRING.to_string(), diff --git a/src/stl/control.rs b/src/stl/control.rs index df0e510..620f6f1 100644 --- a/src/stl/control.rs +++ b/src/stl/control.rs @@ -314,10 +314,14 @@ pub fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result { Ctr::Seg(s) if expand_eval_res => { if let Ctr::Bool(b) = *s.car { return b; + } else if let Ctr::Integer(i) = *s.car { + return i==0; } else { error = "impossible condition in circuit form".to_string(); } - } + }, + + Ctr::Integer(i) => return i == 0, _ => error = format!("{cursor} form did not evaluate to a boolean"), }, diff --git a/src/stl/posix.rs b/src/stl/posix.rs index 7613a68..e7ac439 100644 --- a/src/stl/posix.rs +++ b/src/stl/posix.rs @@ -211,7 +211,8 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc } - // these clones are needed for callbacks which consume references + // these clones are needed for callbacks which move references + let load_ss = shell_state.clone(); let bg_ss = shell_state.clone(); let q_ss = shell_state.clone(); @@ -229,6 +230,20 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc }, ); + syms.insert( + String::from("load"), + Symbol { + name: String::from("load"), + args: Args::Infinite, + conditional_branches: true, + docs: String::from(LOAD_DOCSTRING), + value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result { + load_callback(ast, symtable, &mut load_ss.borrow_mut()) + })), + ..Default::default() + }, + ); + syms.insert( String::from("bg"), Symbol { diff --git a/tests/test_lib_control.rs b/tests/test_lib_control.rs index 71993c3..b583d5f 100644 --- a/tests/test_lib_control.rs +++ b/tests/test_lib_control.rs @@ -204,7 +204,7 @@ mod control_lib_tests { #[test] fn test_circuit_basic() { - let document = "(if (circuit true (and true true) true) (def result '' 'passed') ())"; + let document = "(if (circuit true (and true true) 0 true) (def result '' 'passed') ())"; let test = "result"; let doc_tree = lex(&document.to_string()).unwrap();