From e51f0d6dc38bb8cc8d1355fafe89f4ad315be7c0 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 25 Mar 2014 20:54:57 +0900 Subject: [PATCH] add arity-fixed apply functions --- include/picrin.h | 6 ++++++ src/vm.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/picrin.h b/include/picrin.h index 3617b788..5aa7454f 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -158,6 +158,12 @@ pic_value pic_load(pic_state *, const char *); pic_value pic_apply(pic_state *, struct pic_proc *, pic_value); pic_value pic_apply_argv(pic_state *, struct pic_proc *, size_t, ...); +pic_value pic_apply0(pic_state *, struct pic_proc *); +pic_value pic_apply1(pic_state *, struct pic_proc *, pic_value); +pic_value pic_apply2(pic_state *, struct pic_proc *, pic_value, pic_value); +pic_value pic_apply3(pic_state *, struct pic_proc *, pic_value, pic_value, pic_value); +pic_value pic_apply4(pic_state *, struct pic_proc *, pic_value, pic_value, pic_value, pic_value); +pic_value pic_apply5(pic_state *, struct pic_proc *, pic_value, pic_value, pic_value, pic_value, pic_value); pic_value pic_apply_trampoline(pic_state *, struct pic_proc *, pic_value); pic_value pic_eval(pic_state *, pic_value); struct pic_proc *pic_compile(pic_state *, pic_value); diff --git a/src/vm.c b/src/vm.c index 5625da6f..d85a7f58 100644 --- a/src/vm.c +++ b/src/vm.c @@ -448,6 +448,42 @@ vm_tear_off(pic_state *pic) env->regs = env->storage; } +pic_value +pic_apply0(pic_state *pic, struct pic_proc *proc) +{ + return pic_apply(pic, proc, pic_nil_value()); +} + +pic_value +pic_apply1(pic_state *pic, struct pic_proc *proc, pic_value arg1) +{ + return pic_apply(pic, proc, pic_list1(pic, arg1)); +} + +pic_value +pic_apply2(pic_state *pic, struct pic_proc *proc, pic_value arg1, pic_value arg2) +{ + return pic_apply(pic, proc, pic_list2(pic, arg1, arg2)); +} + +pic_value +pic_apply3(pic_state *pic, struct pic_proc *proc, pic_value arg1, pic_value arg2, pic_value arg3) +{ + return pic_apply(pic, proc, pic_list3(pic, arg1, arg2, arg3)); +} + +pic_value +pic_apply4(pic_state *pic, struct pic_proc *proc, pic_value arg1, pic_value arg2, pic_value arg3, pic_value arg4) +{ + return pic_apply(pic, proc, pic_list4(pic, arg1, arg2, arg3, arg4)); +} + +pic_value +pic_apply5(pic_state *pic, struct pic_proc *proc, pic_value arg1, pic_value arg2, pic_value arg3, pic_value arg4, pic_value arg5) +{ + return pic_apply(pic, proc, pic_list5(pic, arg1, arg2, arg3, arg4, arg5)); +} + pic_value pic_apply_argv(pic_state *pic, struct pic_proc *proc, size_t argc, ...) {