From d0c3bd9ccbb5020f55fdbe456f598095f2071347 Mon Sep 17 00:00:00 2001 From: Bernd Jendrissek Date: Mon, 28 Jan 2008 01:24:38 +0000 Subject: [PATCH] lisp_car(): Utility function to simplify code. --- lisp/lisp.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lisp/lisp.c b/lisp/lisp.c index ac88552..da6d9cc 100644 --- a/lisp/lisp.c +++ b/lisp/lisp.c @@ -134,6 +134,11 @@ void pair_free(struct pair *p) free(p); } +union value_pointer lisp_car(union value_pointer v) +{ + return get_pair(v)->car; +} + struct binding *binding_new(struct environment *env, char const *name, union value_pointer value) @@ -323,7 +328,7 @@ void pretty_print(union value_pointer v) if (i.vp_pair != v.vp_pair) { printf(" "); } - pretty_print(get_pair(i)->car); + pretty_print(lisp_car(i)); } if (pointer_type(i) != 3) { printf(" . "); @@ -369,7 +374,7 @@ union value_pointer builtin_eval(struct environment *env, args.vp_pair = pair_new(); args.vp_pair->car = builtin_eval(env, subeval_arg); - if (get_pair(args.vp_pair->car)->car.vp_opaque == opaque_builtin_function) { + if (lisp_car(args.vp_pair->car).vp_opaque == opaque_builtin_function) { arglink = &args.vp_pair->cdr; for (list = get_pair(list->cdr); list != NULL; list = get_pair(list->cdr)) { @@ -433,7 +438,7 @@ union value_pointer builtin_car(struct environment *env, { union value_pointer retval; - retval = get_pair(rest->car)->car; + retval = lisp_car(rest->car); return retval; } @@ -455,7 +460,7 @@ union value_pointer builtin_cons(struct environment *env, retval.vp_pair = pair_new(); retval.vp_pair->car = rest->car; - retval.vp_pair->cdr = get_pair(rest->cdr)->car; + retval.vp_pair->cdr = lisp_car(rest->cdr); pointer_mark(&retval, 3); return retval; @@ -467,7 +472,7 @@ union value_pointer builtin_eq_p(struct environment *env, union value_pointer a, b; a = rest->car; - b = get_pair(rest->cdr)->car; + b = lisp_car(rest->cdr); if (pointer_type(a) != pointer_type(b)) { return constant_false; @@ -510,7 +515,7 @@ union value_pointer builtin_if(struct environment *env, pointer_mark(&retval, 3); condition = rest->car; - consequent = get_pair(rest->cdr)->car; + consequent = lisp_car(rest->cdr); alternate = get_pair(rest->cdr)->cdr; p = pair_new(); @@ -521,7 +526,7 @@ union value_pointer builtin_if(struct environment *env, condition.vp_charseq != constant_false.vp_charseq) { p->car = consequent; } else if (get_pair(alternate) != NULL) { - p->car = get_pair(alternate)->car; + p->car = lisp_car(alternate); } else { pair_free(p); return retval; -- 2.11.4.GIT