mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 09:17:35 +02:00
Cleanup
This commit is contained in:
parent
63e476839f
commit
4f65fdb6e2
1 changed files with 7 additions and 34 deletions
41
runtime.c
41
runtime.c
|
@ -3248,12 +3248,14 @@ void apply_va(void *data, object cont, int argc, object func, ...)
|
||||||
apply(data, cont, func, tmp);
|
apply(data, cont, func, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define stack_append(lis, value) { \
|
// Prepend value to the given list
|
||||||
|
#define stack_prepend(lis, value) { \
|
||||||
pair_type *tmp2 = alloca(sizeof(pair_type)); \
|
pair_type *tmp2 = alloca(sizeof(pair_type)); \
|
||||||
set_pair(tmp2, value, lis); \
|
set_pair(tmp2, value, lis); \
|
||||||
lis = tmp2; \
|
lis = tmp2; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepend each element of src to dest list
|
||||||
#define stack_list_prepend(src, dest) { \
|
#define stack_list_prepend(src, dest) { \
|
||||||
while (src) { \
|
while (src) { \
|
||||||
pair_type *tmp2 = alloca(sizeof(pair_type)); \
|
pair_type *tmp2 = alloca(sizeof(pair_type)); \
|
||||||
|
@ -3269,8 +3271,6 @@ void dispatch_apply_va(void *data, int argc, object clo, object cont, object fun
|
||||||
int i;
|
int i;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
argc = argc - 1; // Required for "dispatch" function
|
argc = argc - 1; // Required for "dispatch" function
|
||||||
// TODO: pack all this up in a macro, and use it for apply_va also
|
|
||||||
// TODO: validate last arg is a list
|
|
||||||
va_start(ap, func);
|
va_start(ap, func);
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
// Fast path, nothing to append
|
// Fast path, nothing to append
|
||||||
|
@ -3281,46 +3281,19 @@ void dispatch_apply_va(void *data, int argc, object clo, object cont, object fun
|
||||||
tmp = va_arg(ap, object);
|
tmp = va_arg(ap, object);
|
||||||
if (tmp == NULL){
|
if (tmp == NULL){
|
||||||
continue;
|
continue;
|
||||||
} else if (is_object_type(tmp)) {
|
} else if (is_object_type(tmp) && type_of(tmp) == pair_tag) {
|
||||||
if (type_of(tmp) == pair_tag) {
|
l = tmp;
|
||||||
l = tmp;
|
stack_list_prepend(l, lis);
|
||||||
stack_list_prepend(l, lis);
|
|
||||||
//while (l) {
|
|
||||||
// pair_type *tmp2 = alloca(sizeof(pair_type));
|
|
||||||
// set_pair(tmp2, car(l), lis);
|
|
||||||
// lis = tmp2;
|
|
||||||
// l = cdr(l);
|
|
||||||
//}
|
|
||||||
} else {
|
|
||||||
stack_append(lis, tmp);
|
|
||||||
//pair_type *tmp2 = alloca(sizeof(pair_type));
|
|
||||||
//set_pair(tmp2, tmp, lis);
|
|
||||||
//lis = tmp2;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
stack_append(lis, tmp);
|
stack_prepend(lis, tmp);
|
||||||
//pair_type *tmp2 = alloca(sizeof(pair_type));
|
|
||||||
//set_pair(tmp2, tmp, lis);
|
|
||||||
//lis = tmp2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Reverse lis
|
// Reverse lis
|
||||||
l = lis;
|
l = lis;
|
||||||
lis = NULL;
|
lis = NULL;
|
||||||
stack_list_prepend(l, lis);
|
stack_list_prepend(l, lis);
|
||||||
//while (l) {
|
|
||||||
// pair_type *tmp2 = alloca(sizeof(pair_type));
|
|
||||||
// set_pair(tmp2, car(l), lis);
|
|
||||||
// lis = tmp2;
|
|
||||||
// l = cdr(l);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
//fprintf(stdout, "DEBUG applying argc %d, func ", argc);
|
|
||||||
//Cyc_display(func, stdout);
|
|
||||||
//fprintf(stdout, " to values ");
|
|
||||||
//Cyc_display(lis, stdout);
|
|
||||||
//fprintf(stdout, "\n");
|
|
||||||
apply(data, cont, func, lis);
|
apply(data, cont, func, lis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue