mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Adding cases for host function closures
This commit is contained in:
parent
0fcdb13eae
commit
b7b844b16e
2 changed files with 22 additions and 0 deletions
12
runtime.c
12
runtime.c
|
@ -5086,6 +5086,14 @@ object apply(void *data, object cont, object func, object args)
|
|||
count = Cyc_length(data, args);
|
||||
// TODO: validate number of args provided:
|
||||
Cyc_check_num_args(data, "<procedure>", ((closure) func)->num_args, args); // TODO: could be more efficient, eg: cyc_length(args) is called twice.
|
||||
|
||||
// TODO:
|
||||
// if (((closure)func)->pc) {
|
||||
// ((gc_thread_data *)data)->pc = ((closure)func)->pc;
|
||||
// need to alloc array for args, and load it up...
|
||||
// ((gc_thread_data *)data)->args = ((closure)func)->pc;
|
||||
// ((closure)func)->fn(data, count);
|
||||
// }
|
||||
dispatch(data, obj_obj2int(count), ((closure) func)->fn, func, cont, args);
|
||||
break;
|
||||
|
||||
|
@ -5197,6 +5205,10 @@ void Cyc_start_trampoline(gc_thread_data * thd)
|
|||
|
||||
if (type_is_pair_prim(thd->gc_cont)) {
|
||||
Cyc_apply_from_buf(thd, thd->gc_num_args, thd->gc_cont, thd->gc_args);
|
||||
} else if (((closure) (thd->gc_cont))->pc) {
|
||||
thd->pc = ((closure) (thd->gc_cont))->pc;
|
||||
thd->args = thd->gc_args;
|
||||
(((closure) (thd->gc_cont))->fn)(thd, thd->gc_num_args);
|
||||
} else {
|
||||
do_dispatch(thd, thd->gc_num_args, ((closure) (thd->gc_cont))->fn,
|
||||
thd->gc_cont, thd->gc_args);
|
||||
|
|
|
@ -2806,6 +2806,11 @@
|
|||
#define closcall1(td, clo,a1) \
|
||||
if (type_is_pair_prim(clo)) { \
|
||||
Cyc_apply(td, 0, (closure)(a1), clo); \
|
||||
} else if((clo)->pc) { \
|
||||
object buf[1]; buf[0] = a1;\
|
||||
((gc_thread_data *)td)->args = &buf; \
|
||||
((gc_thread_data *)td)->pc = (clo)->pc; \
|
||||
((clo)->fn)(td, 1);\
|
||||
} else { \
|
||||
((clo)->fn)(td, 1, clo,a1);\
|
||||
}
|
||||
|
@ -2845,6 +2850,11 @@ if (type_is_pair_prim(clo)) { \
|
|||
#define closcall2(td, clo,a1,a2) \
|
||||
if (type_is_pair_prim(clo)) { \
|
||||
Cyc_apply(td, 1, (closure)(a1), clo,a2); \
|
||||
} else if((clo)->pc) { \
|
||||
object buf[2]; buf[0] = a1;buf[1] = a2; \
|
||||
((gc_thread_data *)td)->args = &buf; \
|
||||
((gc_thread_data *)td)->pc = (clo)->pc; \
|
||||
((clo)->fn)(td, 2);\
|
||||
} else { \
|
||||
((clo)->fn)(td, 2, clo,a1,a2);\
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue