From 71b70fe4b8bd305a41ee8b133b9652ab9ecbf974 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Sun, 22 Jan 2023 19:36:37 -0800 Subject: [PATCH] fix case for 0 arg function calls Signed-off-by: Ava Hahn --- Readme.org | 30 ++++++++++++++++-------------- src/bin/main.rs | 8 +------- src/config.rs | 2 ++ src/func.rs | 11 ++++++++++- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Readme.org b/Readme.org index 0b883ad..742bcc1 100644 --- a/Readme.org +++ b/Readme.org @@ -1,19 +1,21 @@ #+Title: Relish: Rusty Expressive LIsp SHell #+Author: Ava Hahn +Note: this document is best read within a dedicated ORG mode interpreter + * Purpose statement The purpose of Relish is to create a highly expressive POSIX shell using a lisp interpreter. * Goals -** Iterate on the ideas and designs that were tested with SHS +- Iterate on the ideas and designs that were tested with SHS https://gitlab.com/whom/shs -** Act as both a high level scripting language and as a system shell -** To be as portable as possible -** To provide code and framework that can be embedded in other applications needing a user facing interpreter -** To be well tested code -** No unsafe code without extreme consideration and rigorous containment +- Act as both a high level scripting language and as a system shell +- To be as portable as possible +- To provide code and framework that can be embedded in other applications needing a user facing interpreter +- To be well tested code +- No unsafe code without extreme consideration and rigorous containment -* Current Status +* Current Status / TODO list *** DONE Core interpreter stuffs **** DONE Lexing **** DONE Parsing @@ -73,7 +75,7 @@ Will need a concatenate function for func tables * Contact -** Matrix chat: #vomitorium:matrix.sunnypup.io +- Matrix chat: #vomitorium:matrix.sunnypup.io https://matrix.to/#/#vomitorium:matrix.sunnypup.io * How to use @@ -87,14 +89,14 @@ The configuration file is evaluated and run as a standalone script and may inclu Errors during configuration are non-terminal and will result in default values being returned. **** Important points to note -***** When the configuration file is run, it will be run with default configuration values. -***** The user/script interpreter will be run with a *re-instantiation* of the standard library, using the previously defined configuration variables. -***** Variables and functions defined during configuration will carry over to the user/script interpreter, allowing the user to load any number of custom functions and variables. +- When the configuration file is run, it will be run with default configuration values. +- The user/script interpreter will be run with a *re-instantiation* of the standard library, using the previously defined configuration variables. +- Variables and functions defined during configuration will carry over to the user/script interpreter, allowing the user to load any number of custom functions and variables. *** Configuration Values -**** CFG_RELISH_POSIX (default 0): when on, enables POSIX style job control. -**** CFG_RELISH_ENV (default 1): when on, interpreter's variable table and environment variable table are kept in sync. -**** CFG_RELISH_PROMPT (default (echo "λ ")): A *function* definition which is called in order to output the prompt for each loop of the REPL. +- CFG_RELISH_POSIX (default 0): when on, enables POSIX style job control. +- CFG_RELISH_ENV (default 1): when on, interpreter's variable table and environment variable table are kept in sync. +- CFG_RELISH_PROMPT (default (echo "λ ")): A *function* definition which is called in order to output the prompt for each loop of the REPL. Note: CFG_RELISH_PROMPT is only loaded once and will be ignored after initial configuration. ** Compilation diff --git a/src/bin/main.rs b/src/bin/main.rs index e9a0b04..9565a5a 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -18,7 +18,6 @@ use dirs::home_dir; use relish::ast::{ast_to_string, eval, func_call, lex, new_ast, Ctr, FTable, VTable}; use relish::aux::configure; -use relish::stdlib::get_stdlib; use rustyline::error::ReadlineError; use rustyline::Editor; use std::cell::RefCell; @@ -48,7 +47,7 @@ fn main() { let vt = Rc::new(RefCell::new(VTable::new())); let conf_file; - let mut ft; + let ft; match env::var("RELISH_CFG_FILE") { Ok(s) => { conf_file = s @@ -67,11 +66,6 @@ fn main() { }, } - match get_stdlib(vt.clone()) { - Ok(f) => ft = f, - Err(s) => println!("{}", s), - } - loop { let readline: Result; // Rust is pain diff --git a/src/config.rs b/src/config.rs index 21fb91a..24eb35a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,10 +23,12 @@ use crate::stl::get_stdlib; use crate::vars::{define, VTable}; use std::cell::RefCell; use std::fs; +use std::io::{self, Write}; use std::rc::Rc; fn prompt_default_callback(_: Ast, _: Rc>, _: Rc>) -> Ctr { print!("λ "); + io::stdout().flush().unwrap(); return Ctr::None; } diff --git a/src/func.rs b/src/func.rs index dd7310f..22e65ca 100644 --- a/src/func.rs +++ b/src/func.rs @@ -101,7 +101,16 @@ pub fn func_call( match &called_func.args { Args::Lazy(num) => { let called_arg_count = list_len(n_args.clone()) as i128; - if *num > -1 && (*num != called_arg_count) { + if *num == 0 { + if let Ctr::None = n_args.clone().borrow().car { + //pass + } else { + return Err(format!( + "expected 0 args in call to {}. Got one or more.", + called_func.name, + )); + } + } else if *num > -1 && (*num != called_arg_count) { return Err(format!( "expected {} args in call to {}. Got {}.", num, called_func.name, called_arg_count