unoidl2

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/unoidl2.git/
Log | Files | Refs

commit 8f879a25878c593360b648124ca61e223b35a55c
parent b3147f2eeea78f979417c945bc2f645ad3cdf936
Author: Tomas Hlavaty <tom@logand.com>
Date:   Thu, 15 Mar 2012 23:44:10 +0100

set and con introduced

Diffstat:
Munoidl2.c | 15+++++++++------
Munoidl2.h | 2++
2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/unoidl2.c b/unoidl2.c @@ -57,11 +57,14 @@ Any xalloc() { Any NIL; Any T; +Any set(Any x, Any v) {return x->u.c.car = v;} +Any con(Any x, Any v) {return x->u.c.cdr = v;} + Any cons(Any car, Any cdr) { Any x = xalloc(); x->tag = CONS; - x->u.c.car = car; - x->u.c.cdr = cdr; + set(x, car); + con(x, cdr); return x; } @@ -76,7 +79,7 @@ Any intern1(char *x) { Any k = chara(*x); Any r = find(k, cdr(p), equal, caar); if(NIL == r) - p->u.c.cdr = cons(r = list1(cons(k, p)), cdr(p)); + con(p, cons(r = list1(cons(k, p)), cdr(p))); p = r; } return p; @@ -133,7 +136,7 @@ Any nconc2(Any a, Any b) { return b; Any x, d; for(x = a, d = cdr(x); NIL != d; x = d, d = cdr(x)); - x->u.c.cdr = b; + con(x, b); return a; } @@ -249,8 +252,8 @@ void init() { heap = calloc(HSIZE, sizeof(struct any)); NIL = xalloc(); NIL->tag = CONS; - NIL->u.c.car = NIL; - NIL->u.c.cdr = NIL; + set(NIL, NIL); + con(NIL, NIL); for(int i = 0; i < NCHARA; i++) { Any x = mkinum(i); x->tag = CHARA; diff --git a/unoidl2.h b/unoidl2.h @@ -25,6 +25,8 @@ typedef enum yytokentype Kind; typedef Any (*Fn1)(Any a); typedef Any (*Fn2)(Any a, Any b); +Any set(Any x, Any v); +Any con(Any x, Any v); Any cons(Any car, Any cdr); Any mk(Kind kind, char *token); Any mkinum(int n);