From 7edeb4274841192ac574849e6c8c53f53fb47590 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 18 Dec 2017 06:09:42 -0800 Subject: expander: do constant folding of a..b range exprs. * eval.c (do_expand): In the function call case, check for the operator being the rcons function. If it is called with exactly two arguments and they are constantp in the given environment, then evaluate them and replace with a range literal object. Rationale: ranges often appear in constant form like [array 1..:] and whatnot. --- eval.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/eval.c b/eval.c index b4b2d7de..b321d692 100644 --- a/eval.c +++ b/eval.c @@ -4430,6 +4430,15 @@ again: sym, nao); } + if (insym_ex == rcons_s && + proper_list_p(args_ex) && length(args_ex) == two && + constantp(car(args_ex), menv) && + constantp(cadr(args_ex), menv)) + { + return rlcp(rcons(eval(car(args_ex), menv, form), + eval(cadr(args_ex), menv, form)), form); + } + if (insym_ex == insym && args_ex == args) { if (form_ex == form) return form; -- cgit v1.2.3