From b734d1aef23257c29db2f48da172e955a5db53b2 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 20 Apr 2016 03:57:30 -0400 Subject: [PATCH] Refactoring --- include/cyclone/types.h | 13 +++++++------ runtime.c | 26 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 7271d262..53eb7a8b 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -201,9 +201,8 @@ typedef enum { STAGE_CLEAR_OR_MARKING #define stack_overflow(x,y) ((x) > (y)) #endif -#define eq(x,y) (x == y) -#define type_of(x) (((list) x)->tag) -#define forward(x) (((list) x)->cons_car) +#define type_of(obj) (((pair_type *) obj)->tag) +#define forward(obj) (((pair_type *) obj)->cons_car) /** Define value types. * Depending on the underlying architecture, compiler, etc these types @@ -326,11 +325,13 @@ typedef bytevector_type *bytevector; /* Pair (cons) type */ -typedef struct {gc_header_type hdr; tag_type tag; object cons_car,cons_cdr;} cons_type; +typedef struct {gc_header_type hdr; tag_type tag; object cons_car; object cons_cdr;} cons_type; typedef cons_type *list; +typedef cons_type pair_type; +typedef pair_type *pair; -#define car(x) (((list) x)->cons_car) -#define cdr(x) (((list) x)->cons_cdr) +#define car(x) (((pair_type *) x)->cons_car) +#define cdr(x) (((pair_type *) x)->cons_cdr) #define caar(x) (car(car(x))) #define cadr(x) (car(cdr(x))) #define cdar(x) (cdr(car(x))) diff --git a/runtime.c b/runtime.c index 8a0f0ac9..6259dc52 100644 --- a/runtime.c +++ b/runtime.c @@ -732,15 +732,25 @@ object Cyc_write_char(void *data, object c, object port) } // TODO: should not be a predicate, may end up moving these to Scheme code -object memberp(void *data, object x, list l) -{Cyc_check_cons_or_null(data, l); - for (; l != NULL; l = cdr(l)) if (boolean_f != equalp(x,car(l))) return boolean_t; - return boolean_f;} +object memberp(void *data, object x, list l) +{ + Cyc_check_cons_or_null(data, l); + for (; l != NULL; l = cdr(l)) { + if (boolean_f != equalp(x,car(l))) + return boolean_t; + } + return boolean_f; +} -object memqp(void *data, object x, list l) -{Cyc_check_cons_or_null(data, l); - for (; l != NULL; l = cdr(l)) if ((x == car(l))) return boolean_t; - return boolean_f;} +object memqp(void *data, object x, list l) +{ + Cyc_check_cons_or_null(data, l); + for (; l != NULL; l = cdr(l)){ + if ((x == car(l))) + return boolean_t; + } + return boolean_f; +} object equalp(object x, object y) {