tisp

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

commit a00cb216917ca87ca3b7ba668fde6e6efb06bea7
parent 62afda910c4dc11f6849b106aad1d9e4b94bb115
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Wed,  5 Jan 2022 21:39:39 -0800

Make Void variable not procedure

Diffstat:
Mtest.c | 40++++++++++++++++++++--------------------
Mtib/doc.tsp | 6+++---
Mtib/io.tsp | 2+-
Mtisp.c | 12++----------
4 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/test.c b/test.c @@ -60,12 +60,12 @@ char *tests[][2] = { { "Nil", "Nil" }, { "comments", NULL }, - { "; commment", "(Void)" }, - { "; (+ 1 1)", "(Void)" }, + { "; commment", "Void" }, + { "; (+ 1 1)", "Void" }, { "(+ 1 ; more comments\n1)", "2" }, { "whitespace", NULL }, - { "\t \n \n\n\t\n \t\n", "(Void)" }, + { "\t \n \n\n\t\n \t\n", "Void" }, { "\t \t(+ \t\t5 \n \n5 \n\t)", "10" }, { "quote", NULL }, @@ -101,13 +101,13 @@ char *tests[][2] = { { "(cdr (cons 1 (cons 2 3)))", "(2 . 3)" }, { "(cdr (cdr (cons 1 (cons 2 3))))", "3" }, - { "void", NULL }, - { "(Void)", "(Void)" }, + { "void", NULL }, + { "Void", "Void" }, { "do", NULL }, { "(do (+ 1 2) (+ 2 2))", "4" }, { "(do (+ -4 8) (- 1 2) (* 80 0) (+ 39 -3))", "36" }, - { "(do (mod 80 2) (/ 4 2) (Void))", "(Void)" }, + { "(do (mod 80 2) (/ 4 2) Void)", "Void" }, { "eval", NULL }, { "(eval ''hey)", "hey" }, @@ -118,14 +118,14 @@ char *tests[][2] = { { "(do (def bar '(/ 25 5)) (eval bar))", "5" }, { "cond", NULL }, - { "(cond)", "(Void)" }, + { "(cond)", "Void" }, { "(cond (True 1))", "1" }, { "(cond ((= 1 1) 1) ((= 1 2) 2) (True 3))", "1" }, { "(cond ((= 1 2) 1) ((= 1 2) 2) (else (+ 1 2)))", "3" }, { "(cond ((= 1 2) 1) ((= 1 1) 2) (else 3))", "2" }, - { "(cond ((= 1 2) 1) ((= 1 3) 2))", "(Void)" }, + { "(cond ((= 1 2) 1) ((= 1 3) 2))", "Void" }, { "(cond ((= 1 2) 1) (\"foo\" 2) (else 3))", "2" }, - { "(cond (() (+ 1 2)))", "(Void)" }, + { "(cond (() (+ 1 2)))", "Void" }, { "get", NULL }, { "(get \"hello\" 'len)", "5" }, @@ -191,24 +191,24 @@ char *tests[][2] = { { "(/= 'greg 'greg 'greg 'greg)", "Nil" }, { "def", NULL }, - { "(def foo 4)", "(Void)" }, + { "(def foo 4)", "Void" }, { "foo", "4" }, - { "(def bar foo)", "(Void)" }, + { "(def bar foo)", "Void" }, { "bar", "4" }, { "(set! foo 5)", "5" }, { "foo", "5" }, { "(set! foo (+ foo bar))", "9" }, { "foo", "9" }, - { "(def add +)", "(Void)" }, + { "(def add +)", "Void" }, { "(add foo bar)", "13" }, - { "(def (one x) (add x 1))", "(Void)" }, + { "(def (one x) (add x 1))", "Void" }, { "(one foo)", "10" }, { "(def (more x)" " (def term 3)" - " (+ x term))", "(Void)" }, + " (+ x term))", "Void" }, { "(more 8)", "11" }, { "(def (add2 x)" - " (+ x 1) (+ x 2))", "(Void)" }, + " (+ x 1) (+ x 2))", "Void" }, { "(add2 2)", "4" }, { "(set! add2 2)", "2" }, { "add2", "2" }, @@ -234,15 +234,15 @@ char *tests[][2] = { { "(if (integer? 3) True ())", "True" }, { "(if (ratio? car) (cons 1 2) (car '(1 2)))", "1" }, { "(when True 'foo)", "foo" }, - { "(when () 'b ar)", "(Void)" }, + { "(when () 'b ar)", "Void" }, { "(when (= 1 1) 4)", "4" }, - { "(unless True 'foo)", "(Void)" }, + { "(unless True 'foo)", "Void" }, { "(unless () 'bar)", "bar" }, - { "(unless 3 4)", "(Void)" }, + { "(unless 3 4)", "Void" }, { "(unless (< 5 4) 7)", "7" }, { "(switch 5 (3 'yes) (5 'no))", "no" }, { "(switch (+ 1 2) ((mod 8 5) 'yes) (err 'no))", "yes" }, - { "(switch 2 (3 'yes) (5 'no))", "(Void)" }, + { "(switch 2 (3 'yes) (5 'no))", "Void" }, { "(switch \"foo\" (e \"bar\") (\"foo\" 'zar) ('baz 3))", "zar" }, /* TODO other syms as well */ @@ -409,7 +409,7 @@ char *tests[][2] = { { "(swap (list 1/2 1/4 1/9 1/16))", "(1/4 1/2 1/9 1/16)" }, { "stack!", NULL }, - { "(def s '(1 2 3 4 5))", "(Void)" }, + { "(def s '(1 2 3 4 5))", "Void" }, { "(peek s)", "1" }, { "(pop! s)", "1" }, { "s", "(2 3 4 5)" }, diff --git a/tib/doc.tsp b/tib/doc.tsp @@ -14,7 +14,7 @@ " Can be shortened with the ' prefix" " Also see quote, unquote, and unquote-splice") (Void - "(Void)" + "Void" "Return nothing" "Used to insert a void type in a list or force a function not to return anything") (eval @@ -64,7 +64,7 @@ (def (docstr-add! . docstrs) "Add given docstrs to the global doc string registry" (set! docstr-reg (apply @(append docstr-reg it) docstrs)) - (Void)) + Void) (def (doc proc) "Get documentation of procedure" @@ -82,4 +82,4 @@ (println docstr) (lookup proc))) (lookup proc)) - (Void)) + Void) diff --git a/tib/io.tsp b/tib/io.tsp @@ -25,6 +25,6 @@ ((pair? it) (print "'" it)) (else (print it))) str) - (Void)) + Void) (def (displayln . str) (apply display str) (newline)) (def (println . str) (apply print str) (newline)) diff --git a/tisp.c b/tisp.c @@ -737,7 +737,7 @@ tisp_print(FILE *f, Val v) { switch (v->t) { case TSP_NONE: - fputs("(Void)", f); + fputs("Void", f); break; case TSP_NIL: fputs("Nil", f); @@ -826,14 +826,6 @@ form_quote(Tsp st, Hash env, Val args) return car(args); } -/* TODO make Void variable like Nil, True, False or like Str, Int ? */ -/* returns nothing */ -static Val -prim_Void(Tsp st, Hash env, Val args) -{ - return st->none; -} - /* evaluate argument given */ static Val prim_eval(Tsp st, Hash env, Val args) @@ -1115,13 +1107,13 @@ tisp_env_init(size_t cap) st->global = hash_new(cap, NULL); tisp_env_add(st, "True", st->t); tisp_env_add(st, "Nil", st->nil); + tisp_env_add(st, "Void", st->none); tisp_env_add(st, "bt", st->nil); tisp_env_add(st, "version", mk_str(st, "0.0.0")); tsp_env_prim(car); tsp_env_prim(cdr); tsp_env_prim(cons); tsp_env_form(quote); - tsp_env_prim(Void); tsp_env_prim(eval); tsp_env_name_prim(=, eq); tsp_env_form(cond);