From b7b844b16e9c7d10820ddb508cbc73a63fec8f71 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 11 Oct 2018 18:25:25 -0400 Subject: [PATCH] Adding cases for host function closures --- runtime.c | 12 ++++++++++++ tests/experimental/fac-test.c | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/runtime.c b/runtime.c index 21bb846a..11bf45ea 100644 --- a/runtime.c +++ b/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, "", ((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); diff --git a/tests/experimental/fac-test.c b/tests/experimental/fac-test.c index f426e200..f1557d30 100644 --- a/tests/experimental/fac-test.c +++ b/tests/experimental/fac-test.c @@ -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);\ }