tisp

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

commit ff95a1d47af0763dbe7dd13bd26f89b7099227a8
parent 4706a62a7aaf9f91fe0f92a8e01505ebfb4d566f
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Fri, 14 Jun 2019 17:12:24 -0700

Split read into parse

Read only returns string from stdin, parse interprets a string as tisp
syntax and returns its value

Diffstat:
main.c | 1+
tibs/io.c | 20+++++++++++++++-----
tibs/repl.tsp | 2+-
3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c @@ -39,6 +39,7 @@ main(int argc, char *argv[]) tisp_print(stdout, tisp_eval(env, tisp_parse_file(env, NULL))); else tisp_print(stdout, tisp_eval(env, tisp_parse_file(env, argv[i]))); + puts(""); /* tisp_env_free(env); */ diff --git a/tibs/io.c b/tibs/io.c @@ -43,15 +43,24 @@ static Val prim_read(Env env, Val args) { char *file; + if (!(file = tisp_read_file(NULL))) + return env->nil; + return mk_str(env, file); +} + +static Val +prim_parse(Env env, Val args) +{ Val v; struct Str str = { NULL }; - if (!(file = tisp_read_file(NULL))) { - putchar('\n'); + tsp_arg_num(args, "parse", 1); + if (!(v = tisp_eval(env, car(args)))) + return NULL; + if (nilp(v)) return mk_pair(mk_sym(env, "quit"), env->nil); - } - str.d = file; + tsp_arg_type(v, "parse", STRING); + str.d = v->v.s; v = tisp_read(env, &str); - free(file); return v; } @@ -60,4 +69,5 @@ tib_env_io(Env env) { tsp_env_fn(print); tsp_env_fn(read); + tsp_env_fn(parse); } diff --git a/tibs/repl.tsp b/tibs/repl.tsp @@ -1,6 +1,6 @@ (define (repl) (print "> ") - (let ((expr (read))) + (let ((expr (parse (read)))) (unless (and (pair? expr) (= (car expr) 'quit)) (let ((ans (eval expr))) (unless (void? ans)