Refactoring

This commit is contained in:
Justin Ethier 2016-04-09 01:01:03 -04:00
parent a64ea52e18
commit e773acfafc

View file

@ -739,39 +739,50 @@ object memqp(void *data, object x, list l)
for (; !nullp(l); l = cdr(l)) if (eq(x,car(l))) return boolean_t; for (; !nullp(l); l = cdr(l)) if (eq(x,car(l))) return boolean_t;
return boolean_f;} return boolean_f;}
object get(x,i) object x,i; object get(object x, object i)
{register object plist; register object plistd; {
if (nullp(x)) return x; object plist, plistd;
if (type_of(x)!=symbol_tag) {printf("get: bad x=%ld\n",((closure)x)->tag); exit(0);} if (nullp(x)) return x;
plist = symbol_plist(x); if (type_of(x)!=symbol_tag) {printf("get: bad x=%ld\n",((closure)x)->tag); exit(0);}
for (; !nullp(plist); plist = cdr(plistd)) plist = symbol_plist(x);
{plistd = cdr(plist); for (; !nullp(plist); plist = cdr(plistd))
if (eq(car(plist),i)) return car(plistd);} {plistd = cdr(plist);
return nil;} if (eq(car(plist),i)) return car(plistd);}
return nil;
}
object equalp(x,y) object x,y; object equalp(object x, object y)
{for (; ; x = cdr(x), y = cdr(y)) {
{if (equal(x,y)) return boolean_t; for (; ; x = cdr(x), y = cdr(y)) {
if (equal(x,y)) return boolean_t;
if (is_value_type(x) || is_value_type(y) || if (is_value_type(x) || is_value_type(y) ||
nullp(x) || nullp(y) || nullp(x) || nullp(y) ||
type_of(x)!=cons_tag || type_of(y)!=cons_tag) return boolean_f; type_of(x)!=cons_tag || type_of(y)!=cons_tag) return boolean_f;
if (boolean_f == equalp(car(x),car(y))) return boolean_f;}} if (boolean_f == equalp(car(x),car(y))) return boolean_f;
}
}
list assq(void *data, object x, list l) list assq(void *data, object x, list l)
{if (nullp(l) || is_value_type(l) || type_of(l) != cons_tag) return boolean_f; {
for (; !nullp(l); l = cdr(l)) if (nullp(l) || is_value_type(l) || type_of(l) != cons_tag) return boolean_f;
{register list la = car(l); for (; !nullp(l); l = cdr(l)) {
Cyc_check_cons(data, la); list la = car(l);
if (eq(x,car(la))) return la;} Cyc_check_cons(data, la);
return boolean_f;} if (eq(x,car(la))) return la;
}
return boolean_f;
}
list assoc(void *data, object x, list l) list assoc(void *data, object x, list l)
{if (nullp(l) || is_value_type(l) || type_of(l) != cons_tag) return boolean_f; {
for (; !nullp(l); l = cdr(l)) if (nullp(l) || is_value_type(l) || type_of(l) != cons_tag) return boolean_f;
{register list la = car(l); for (; !nullp(l); l = cdr(l)){
Cyc_check_cons(data, la); list la = car(l);
if (boolean_f != equalp(x,car(la))) return la;} Cyc_check_cons(data, la);
return boolean_f;} if (boolean_f != equalp(x,car(la))) return la;
}
return boolean_f;
}
object Cyc_num_cmp_va_list(void *data, int argc, int (fn_op(void *, object, object)), object n, va_list ns) { object Cyc_num_cmp_va_list(void *data, int argc, int (fn_op(void *, object, object)), object n, va_list ns) {
int i; int i;
@ -2043,21 +2054,27 @@ object Cyc_io_peek_char(void *data, object cont, object port) {
return Cyc_EOF; return Cyc_EOF;
} }
/* This heap cons is used only for initialization. */ // Functions internal to the runtime that use malloc
list mcons(a,d) object a,d; list mcons(object a, object d)
{register cons_type *c = malloc(sizeof(cons_type)); {
c->hdr.mark = gc_color_red; cons_type *c = malloc(sizeof(cons_type));
c->hdr.grayed = 0; c->hdr.mark = gc_color_red;
c->tag = cons_tag; c->cons_car = a; c->cons_cdr = d; c->hdr.grayed = 0;
return c;} c->tag = cons_tag;
c->cons_car = a;
c->cons_cdr = d;
return c;
}
cvar_type *mcvar(object *var) { cvar_type *mcvar(object *var)
{
cvar_type *c = malloc(sizeof(cvar_type)); cvar_type *c = malloc(sizeof(cvar_type));
c->hdr.mark = gc_color_red; c->hdr.mark = gc_color_red;
c->hdr.grayed = 0; c->hdr.grayed = 0;
c->tag = cvar_tag; c->tag = cvar_tag;
c->pvar = var; c->pvar = var;
return c;} return c;
}
void _Cyc_91global_91vars(void *data, object cont, object args){ void _Cyc_91global_91vars(void *data, object cont, object args){
return_closcall1(data, cont, Cyc_global_variables); } return_closcall1(data, cont, Cyc_global_variables); }