circuit handles load commands better

Signed-off-by: Ava Hahn <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2023-03-27 14:34:07 -07:00
parent 921deb9e5e
commit ab14ba4b5e
Signed by: affine
GPG key ID: 3A4645B8CF806069
7 changed files with 43 additions and 14 deletions

View file

@ -320,7 +320,7 @@ It also contains considerably subpar implementations of Relish's internals that
*** Userlib *** Userlib
The *Userlib* was added as a script containing many valuable functions such as ~set~ and ~prepend~. 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 ** Easy patterns
This section contains examples of common composites of control flow that can be used to build more complex or effective applications 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. Variables and functions defined in an external script loaded by your interpreter will persist in the symbol table.
#+BEGIN_SRC lisp #+BEGIN_SRC lisp
(load "my-extra-library-functions.rls") (call "my-extra-library-functions.rls")
#+END_SRC #+END_SRC
** Compilation ** Compilation
@ -482,10 +482,9 @@ 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
- 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 - pipe control flow construct
- l and load functions for binaries, call for scripts
- load-to-string function
- ignore job control signals (if needed) - ignore job control signals (if needed)
- background processes - background processes
- be able to list all background processes with j function - 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?) - be able to bg and fg process (ctrl z?)
- changedir/cd - changedir/cd
- pwd - pwd
- call-with (let style fd redirection)
- Documentation! - Documentation!
- Do I need some linemode management stuff?
- Escape sequences in strings
- logging library - logging library
- make const all the error messages - make const all the error messages
- make presentation on relish - make presentation on relish
@ -514,12 +514,21 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
- help - help
- beyond lisp - beyond lisp
- POSIX - 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 - ergonomics of control flow as shell command
- circuit -> pipe - circuit -> pipe
- let -> call-with - let -> call-with
- putting it all together - putting it all together
- job control in shell - job control in shell
- shell scripts - shell scripts
- fancy prompts
- To infinity and beyond - To infinity and beyond
- NGINX modules - NGINX modules
- bootable? - bootable?
@ -527,11 +536,11 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
- store in repo after giving presentation - store in repo after giving presentation
** TODO alpha tasks ** 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 interpreter)
- Can pass args to relish scripts (via command line) - Can pass args to relish scripts (via command line)
- History length configurable - History length configurable
- Search delim configurable - Search delim configurable
- Escape sequences in strings
- Rename to Flesh - Rename to Flesh
- master branch -> main branch - master branch -> main branch
- Create a dedicated community channel on matrix.sunnypup.io - 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 - File operations
- read-to-string - read-to-string
- write-to-file - write-to-file
- file exists
- color control library - color control library
- emacs syntax highlighting and/or LSP implementation - emacs syntax highlighting and/or LSP implementation
- GNU Guix package - GNU Guix package

View file

@ -1,5 +1,5 @@
;; comment out to load USERLIB ;; comment out to load USERLIB
;; (load (concat HOME "/.relish/userlib.rls")) ;; (call (concat HOME "/.relish/userlib.rls"))
;; if you have userlib ;; if you have userlib
;; (set CFG_RELISH_POSIX "1") ;; (set CFG_RELISH_POSIX "1")

View file

@ -126,7 +126,7 @@ fn process(document: &String) -> Result<Box<Seg>, String> {
delim_stack.push(')'); delim_stack.push(')');
} }
// begin parsing a string // begin parsing a string
'"' | '\'' | '`' => { '"' | '\'' | '`' if !is_str => {
is_str = true; is_str = true;
delim_stack.push(c); delim_stack.push(c);
} }

View file

@ -586,9 +586,9 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
); );
syms.insert( syms.insert(
"load".to_string(), "call".to_string(),
Symbol { Symbol {
name: String::from("load"), name: String::from("call"),
args: Args::Strict(vec![Type::String]), args: Args::Strict(vec![Type::String]),
conditional_branches: false, conditional_branches: false,
docs: RUN_DOCSTRING.to_string(), docs: RUN_DOCSTRING.to_string(),

View file

@ -314,10 +314,14 @@ pub fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
Ctr::Seg(s) if expand_eval_res => { Ctr::Seg(s) if expand_eval_res => {
if let Ctr::Bool(b) = *s.car { if let Ctr::Bool(b) = *s.car {
return b; return b;
} else if let Ctr::Integer(i) = *s.car {
return i==0;
} else { } else {
error = "impossible condition in circuit form".to_string(); error = "impossible condition in circuit form".to_string();
} }
} },
Ctr::Integer(i) => return i == 0,
_ => error = format!("{cursor} form did not evaluate to a boolean"), _ => error = format!("{cursor} form did not evaluate to a boolean"),
}, },

View file

@ -211,7 +211,8 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>
} }
// 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 bg_ss = shell_state.clone();
let q_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<RefCell<ShellState>
}, },
); );
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<Ctr, String> {
load_callback(ast, symtable, &mut load_ss.borrow_mut())
})),
..Default::default()
},
);
syms.insert( syms.insert(
String::from("bg"), String::from("bg"),
Symbol { Symbol {

View file

@ -204,7 +204,7 @@ mod control_lib_tests {
#[test] #[test]
fn test_circuit_basic() { 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 test = "result";
let doc_tree = lex(&document.to_string()).unwrap(); let doc_tree = lex(&document.to_string()).unwrap();