From 9107ce48a93c737a9bbe645e37e8cc3b01a0903d 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(+) (limited to 'eval.c') 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