summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-12-18 06:09:42 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-12-18 06:09:42 -0800
commit7edeb4274841192ac574849e6c8c53f53fb47590 (patch)
tree991d5bda433d4fe8add6db41db09653ee46660bf
parentbd52099d270fce8bd6d4da9e337f3c694439a109 (diff)
downloadtxr-7edeb4274841192ac574849e6c8c53f53fb47590.tar.gz
txr-7edeb4274841192ac574849e6c8c53f53fb47590.tar.bz2
txr-7edeb4274841192ac574849e6c8c53f53fb47590.zip
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.
-rw-r--r--eval.c9
1 files changed, 9 insertions, 0 deletions
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;