From 9c89d1c658a11a40c4a97bd88a9321382c26fda5 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 15 Jun 2019 12:21:08 -0400 Subject: [PATCH] Inline yield when called with no arguments. It was already inline when called with one argument. --- src/core/cfuns.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/cfuns.c b/src/core/cfuns.c index c9573ee0..a86a0257 100644 --- a/src/core/cfuns.c +++ b/src/core/cfuns.c @@ -35,6 +35,10 @@ static int fixarity1(JanetFopts opts, JanetSlot *args) { (void) opts; return janet_v_count(args) == 1; } +static int maxarity1(JanetFopts opts, JanetSlot *args) { + (void) opts; + return janet_v_count(args) <= 1; +} static int minarity2(JanetFopts opts, JanetSlot *args) { (void) opts; return janet_v_count(args) >= 2; @@ -115,7 +119,11 @@ static JanetSlot do_length(JanetFopts opts, JanetSlot *args) { return genericSS(opts, JOP_LENGTH, args[0]); } static JanetSlot do_yield(JanetFopts opts, JanetSlot *args) { - return genericSSI(opts, JOP_SIGNAL, args[0], 3); + if (janet_v_count(args) == 0) { + return genericSSI(opts, JOP_SIGNAL, janetc_cslot(janet_wrap_nil()), 3); + } else { + return genericSSI(opts, JOP_SIGNAL, args[0], 3); + } } static JanetSlot do_resume(JanetFopts opts, JanetSlot *args) { return opreduce(opts, args, JOP_RESUME, janet_wrap_nil()); @@ -262,7 +270,7 @@ static const JanetFunOptimizer optimizers[] = { {fixarity0, do_debug}, {fixarity1, do_error}, {minarity2, do_apply}, - {fixarity1, do_yield}, + {maxarity1, do_yield}, {fixarity2, do_resume}, {fixarity2, do_get}, {fixarity3, do_put},