tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit cf250c5d4241602a8c2d3e7aa9b6b5be2d49084a
parent 2ebdaf95fc3d13cf7934af105646c862da6e53ca
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Wed, 15 Jan 2020 14:35:16 -0800

If no arguments are given launch REPL

Diffstat:
doc/tisp.1 | 3+++
doc/tisp.1.md | 3+++
main.c | 13+++++++------
tsp | 4++--
4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/doc/tisp.1 b/doc/tisp.1 @@ -13,6 +13,9 @@ tisp [-hv] [-c COMMAND] [-] [FILE ...] Tisp is a tiny, terse, and transparent lisp library designed to be lightweight and easy to embedded in other programs. Simply drop the 'tisp.c' and 'tisp.h' files into your project in order to use the necessary functions for your program. An example command line interpreter is provided in 'main.c'. Tisp is a single value name language (lisp-1) which tries to be unambiguous and focus on simplicity. Much of the language is defined with Tisp itself leaving the C code as short as possible. .PP .SH OPTIONS +.PP +Read and evaluate all files in order given, if file name is '-' read from 'stdin'. If no files are supplied launch REPL. +.PP .TP \fB-c COMMAND\fP Read \fICOMMAND\fP as a line of Tisp code and print result diff --git a/doc/tisp.1.md b/doc/tisp.1.md @@ -12,6 +12,9 @@ code as short as possible. ## Options +Read and evaluate all files in order given, if file name is `-` read from +`stdin`. If no files are supplied launch REPL. + #### -c COMMAND Read *COMMAND* as a line of Tisp code and print result diff --git a/main.c b/main.c @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) { - int i; + int i = 1; Val v = NULL; Tsp st = tisp_env_init(64); @@ -29,18 +29,19 @@ main(int argc, char *argv[]) tisp_env_lib(st, libs_tsp); #endif - /* TODO reduce redunecy by setting argv[i][0] = '-' ? */ - if (argc == 1) - if ((v = tisp_eval_seq(st, st->global, tisp_parse_file(st, NULL)))) - tisp_print(stdout, v); + if (argc == 1) { + st->file = "(repl)"; + goto readstr; + } - for (i = 1; i < argc; i++, v = NULL) { + for (; i < argc; i++, v = NULL) { if (argv[i][0] == '-') { if (argv[i][1] == 'c') { /* run next argument as tisp command */ if (!(st->file = argv[++i])) { fputs("tisp: expected command after -c\n", stderr); exit(2); } +readstr: if ((v = tisp_read(st))) v = tisp_eval(st, st->global, v); } else if (argv[i][1] == 'v') { /* version and copyright info */ diff --git a/tsp b/tsp @@ -2,7 +2,7 @@ # if rlwrap is not installed, run without it command -v rlwrap >/dev/null 2>&1 || { - ./tisp $@ -c "(repl)" + ./tisp $@ exit 0 } -rlwrap -ncr -M ".tsp" -pWhite -q"\"" ./tisp $@ -c "(repl)" +rlwrap -ncr -M ".tsp" -pWhite -q"\"" ./tisp $@