diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-12-18 06:09:42 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-12-18 06:09:42 -0800 |
commit | 9107ce48a93c737a9bbe645e37e8cc3b01a0903d (patch) | |
tree | 991d5bda433d4fe8add6db41db09653ee46660bf /eval.c | |
parent | d247d615332771f0ac18b3f81c7f8cab78ed6207 (diff) | |
download | txr-9107ce48a93c737a9bbe645e37e8cc3b01a0903d.tar.gz txr-9107ce48a93c737a9bbe645e37e8cc3b01a0903d.tar.bz2 txr-9107ce48a93c737a9bbe645e37e8cc3b01a0903d.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.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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; |