Global generation

This commit is contained in:
2026-01-18 03:11:17 -08:00
parent 94d5749d31
commit c0b18cda5a
16 changed files with 571 additions and 57 deletions

View File

@ -16,6 +16,14 @@ intptr_t list_length(LispVal *list) {
return length;
}
bool list_length_eq(LispVal *list, intptr_t size) {
assert(LISTP(list));
while (size-- && CONSP(list)) {
list = XCDR(list);
}
return size == 0;
}
DEFUN(cons, "cons", (LispVal * car, LispVal *cdr), "(car cdr)",
"Construct a new cons object from CAR and CDR.") {
return CONS(car, cdr);
@ -25,3 +33,21 @@ DEFUN(length, "length", (LispVal * list), "(list)", "") {
// TODO type check
return MAKE_FIXNUM(list_length(list));
}
DEFUN(length_eq, "length=", (LispVal * list, LispVal *length), "(list length)",
"Return non-nil if LIST's length is LENGTH.") {
// TODO type check
return list_length_eq(list, XFIXNUM(length)) ? Qt : Qnil;
}
DEFUN(nreverse, "nreverse", (LispVal * list), "(list)", "") {
// TODO type checking
LispVal *rev = Qnil;
while (!NILP(list)) {
LispVal *next = XCDR(list);
RPLACD(list, rev);
rev = list;
list = next;
}
return rev;
}