From 258ad8c4d8bb88af5e050c99f95cee4c0359ba89 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 23 Feb 2015 15:33:12 -0500 Subject: [PATCH] WIP - apply --- runtime.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/runtime.h b/runtime.h index 3c15db97..ed55615b 100644 --- a/runtime.h +++ b/runtime.h @@ -1076,8 +1076,17 @@ static object apply(object cont, object func, object args){ } break; case closure0_tag: - // TODO: get length of args, 2 below is just an example - return_funcall2((closure)func, cont, car(args)); + buf.integer_t = Cyc_length(args); + switch(buf.integer_t.value) { + case 0: return_funcall1((closure)func, cont); + case 1: return_funcall2((closure)func, cont, car(args)); + case 2: return_funcall3((closure)func, cont, car(args), cadr(args)); + // TODO: can see the pattern but this is not efficient. is there a better way? + default: + printf("Unhandled number of function arguments %d\n", buf.integer_t.value); + exit(1); + } + break; default: printf("Invalid object type %ld\n", type_of(func));