commit a0d8998dc51db0ccb3dc251639b1c799eaf3c398
parent bcb6d965aa4260f852e10921db1e989722a0f90e
Author: Ed van Bruggen <edvb@uw.edu>
Date: Tue, 29 Oct 2019 17:32:54 -0700
Define do in tisp, not as primitive
Return list with each element to be evaluated in tisp_parse_file instead
of returning do list
Diffstat:
4 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/Makefile b/Makefile
@@ -24,7 +24,7 @@ options:
libs.tsp.h: $(TSP)
@echo xxd $@
- @echo "char libs_tsp[] = { 0x28, 0x64, 0x6f, 0x20," > $@
+ @echo "char libs_tsp[] = { 0x28, " > $@
@cat $(TSP) | xxd -i - >> $@
@echo ", 0x29, 0x00};" >> $@
diff --git a/main.c b/main.c
@@ -30,7 +30,7 @@ main(int argc, char *argv[])
#endif
if (argc == 1)
- tisp_print(stdout, tisp_eval(env, tisp_parse_file(env, NULL)));
+ tisp_print(stdout, tisp_eval_list(env, tisp_parse_file(env, NULL)));
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
@@ -47,10 +47,10 @@ main(int argc, char *argv[])
fputs("usage: tisp [-hv] [FILE ...]\n", stderr);
exit(argv[i][1] == 'h' ? 0 : 1);
} else { /* single hypen read from stdin */
- tisp_print(stdout, tisp_eval(env, tisp_parse_file(env, NULL)));
+ tisp_print(stdout, tisp_eval_list(env, tisp_parse_file(env, NULL)));
}
} else { /* otherwise read as file */
- tisp_print(stdout, tisp_eval(env, tisp_parse_file(env, argv[i])));
+ tisp_print(stdout, tisp_eval_list(env, tisp_parse_file(env, argv[i])));
}
}
diff --git a/tibs/lib.tsp b/tibs/lib.tsp
@@ -94,6 +94,7 @@
(cons (car lst) (apply list* (cdr lst)))
(car lst)))
+(define (do . body) (last body))
(define (do0 . body) (car body))
(define (length lst)
diff --git a/tisp.c b/tisp.c
@@ -640,7 +640,7 @@ Val
tisp_parse_file(Env env, char *fname)
{
struct Str str = { NULL };
- Val ret = mk_pair(mk_sym(env, "do"), env->nil);
+ Val ret = mk_pair(NULL, env->nil);
Val v, last = ret;
char *file;
if (!(file = tisp_read_file(fname)))
@@ -648,7 +648,7 @@ tisp_parse_file(Env env, char *fname)
for (str.d = file; *str.d && (v = tisp_read(env, &str)); last = cdr(last))
cdr(last) = mk_pair(v, env->nil);
free(file);
- return ret;
+ return cdr(ret);
}
/* eval */
@@ -844,16 +844,6 @@ prim_void(Env env, Val args)
return env->none;
}
-/* evaluate all functions given, returning the value of the last one */
-static Val
-prim_do(Env env, Val args)
-{
- Val v;
- if (!(v = tisp_eval_list(env, args)))
- return NULL;
- return nilp(v) ? env->none : list_last(v);
-}
-
/* evaluate argument given */
static Val
prim_eval(Env env, Val args)
@@ -995,7 +985,7 @@ prim_load(Env env, Val args)
strcat(name, v->v.s);
strcat(name, ".tsp");
if (access(name, R_OK) != -1) {
- tisp_eval(env, tisp_parse_file(env, name));
+ tisp_eval_list(env, tisp_parse_file(env, name));
free(name);
return env->none;
}
@@ -1085,7 +1075,6 @@ tisp_env_init(size_t cap)
tsp_env_fn(cons);
tsp_env_fn(quote);
tsp_env_fn(void);
- tsp_env_fn(do);
tsp_env_fn(eval);
tsp_env_name_fn(=, eq);
tsp_env_fn(cond);
@@ -1113,7 +1102,8 @@ tisp_env_lib(Env env, char* lib)
struct Str s;
if (!(s.d = strndup(lib, strlen(lib))))
return;
- tisp_eval(env, tisp_read(env, &s));
+ /* TODO check if tisp_read is NULL */
+ tisp_eval_list(env, tisp_read(env, &s));
}
void