tisp

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

commit 27a8d7135bbcb8d7cdff4f11ec5e3e8124a46cd5
parent cc5bc24160a8d536fa190209852032d5fbdaef15
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat, 26 Jan 2019 22:00:32 -0800

Add begin, eval, and type primitives

Diffstat:
tisp.c | 33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)

diff --git a/tisp.c b/tisp.c @@ -700,6 +700,26 @@ prim_void(Env env, Val args) } static Val +prim_begin(Env env, Val args) +{ + Val v; + if (!(v = tisp_eval_list(env, args))) + return NULL; + if (nilp(v)) + return env->none; + return list_last(v); +} + +static Val +prim_eval(Env env, Val args) +{ + Val v; + if (!(v = tisp_eval(env, car(args)))) + return NULL; + return tisp_eval(env, v); +} + +static Val prim_eq(Env env, Val args) { Val v; @@ -726,6 +746,16 @@ prim_cond(Env env, Val args) } static Val +prim_type(Env env, Val args) +{ + Val v; + tsp_arg_num(args, "type", 1); + if (!(v = tisp_eval(env, car(args)))) + return NULL; + return mk_str(env, type_str(v->t)); +} + +static Val prim_lambda(Env env, Val args) { if (list_len(args) < 2) @@ -815,8 +845,11 @@ tisp_env_init(size_t cap) hash_add(e->h, "cons", mk_prim(prim_cons)); hash_add(e->h, "quote", mk_prim(prim_quote)); hash_add(e->h, "void", mk_prim(prim_void)); + hash_add(e->h, "begin", mk_prim(prim_begin)); + hash_add(e->h, "eval", mk_prim(prim_eval)); hash_add(e->h, "=", mk_prim(prim_eq)); hash_add(e->h, "cond", mk_prim(prim_cond)); + hash_add(e->h, "type", mk_prim(prim_type)); hash_add(e->h, "lambda", mk_prim(prim_lambda)); hash_add(e->h, "define", mk_prim(prim_define)); hash_add(e->h, "load", mk_prim(prim_load));