tisp

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

commit a21c3b663a6e2972a0522f3da2504705e9b99e64
parent d1a09ddb51f3be70521a6b9124b19e64c4792215
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat,  9 Jan 2021 02:29:18 -0800

Rename time to now and timeit to time

Make no argument builtins primitives not forms

Diffstat:
tib/os.c | 18+++++++++++-------
tisp.c | 4++--
2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/tib/os.c b/tib/os.c @@ -26,6 +26,8 @@ #include "../tisp.h" +/* TODO sys ls, mv, cp, rm, mkdir, exit */ + /* change to new directory */ static Val prim_cd(Tsp st, Hash env, Val args) @@ -43,7 +45,7 @@ prim_cd(Tsp st, Hash env, Val args) /* TODO rename to cwd ? */ /* return string of current working directory */ static Val -form_pwd(Tsp st, Hash env, Val args) +prim_pwd(Tsp st, Hash env, Val args) { tsp_arg_num(args, "pwd", 0); char cwd[PATH_MAX]; @@ -52,21 +54,23 @@ form_pwd(Tsp st, Hash env, Val args) return mk_str(st, cwd); } +/* TODO time formating */ /* return number of seconds since 1970 (unix time stamp) */ static Val -form_time(Tsp st, Hash env, Val args) +prim_now(Tsp st, Hash env, Val args) { - tsp_arg_num(args, "time", 0); + tsp_arg_num(args, "now", 0); return mk_int(time(NULL)); } +/* TODO time-avg: run timeit N times and take average */ /* return time taken to run command given */ static Val -form_timeit(Tsp st, Hash env, Val args) +form_time(Tsp st, Hash env, Val args) { Val v; clock_t t; - tsp_arg_num(args, "timeit", 1); + tsp_arg_num(args, "time", 1); t = clock(); if (!(v = tisp_eval(st, env, car(args)))) return NULL; @@ -78,7 +82,7 @@ void tib_env_os(Tsp st) { tsp_env_name_prim(cd!, cd); - tsp_env_form(pwd); + tsp_env_prim(pwd); + tsp_env_prim(now); tsp_env_form(time); - tsp_env_form(timeit); } diff --git a/tisp.c b/tisp.c @@ -829,7 +829,7 @@ form_quote(Tsp st, Hash env, Val args) /* TODO make Void variable like Nil, True, False or like Str, Int ? */ /* returns nothing */ static Val -form_Void(Tsp st, Hash env, Val args) +prim_Void(Tsp st, Hash env, Val args) { return st->none; } @@ -1121,7 +1121,7 @@ tisp_env_init(size_t cap) tsp_env_prim(cdr); tsp_env_prim(cons); tsp_env_form(quote); - tsp_env_form(Void); + tsp_env_prim(Void); tsp_env_prim(eval); tsp_env_name_prim(=, eq); tsp_env_form(cond);