diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-07-17 21:59:56 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-07-17 21:59:56 -0700 |
commit | 8780662836a33d08325682492fa76e68de3f5e13 (patch) | |
tree | db1d27cf086eff5be3ec6d8e87ee32ef372caedf | |
parent | b9439904e4c295ba060ed9572ef7d86502505f87 (diff) | |
download | txr-8780662836a33d08325682492fa76e68de3f5e13.tar.gz txr-8780662836a33d08325682492fa76e68de3f5e13.tar.bz2 txr-8780662836a33d08325682492fa76e68de3f5e13.zip |
compiler: constant fold gapply like gcall.
* stdlib/optimize.tl (basic-blocks do-peephole-block): Extend
constant-folding case to recognize gapply as well as gcall.
We just have to take care in how we apply apply arguments
to the actual function to get the value.
-rw-r--r-- | stdlib/optimize.tl | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl index 1d423f3c..29fe0a64 100644 --- a/stdlib/optimize.tl +++ b/stdlib/optimize.tl @@ -528,15 +528,18 @@ (cons (car insns) ren)) (t insns)))) ;; constant folding - (@(require ((gcall @tgt @idx . @(all @(or (d @dn) - @(with (t 0) dn nil)))) + (@(require ((@(as op @(or gapply gcall)) @tgt @idx + . @(all @(or (d @dn) + @(with (t 0) dn nil)))) . @rest) [%const-foldable% [bb.symvec idx]]) (let* ((co bb.compiler) (dvec co.(get-datavec)) (fun [bb.symvec idx]) (args (mapcar [iffi true dvec] dn)) - (val (apply fun args)) + (val (if (eq op 'gcall) + (apply fun args) + (apply fun (append [args 0..-1] [args -1])))) (dreg co.(get-dreg val))) ^((mov ,tgt ,dreg) ,*rest))) ;; apply to gapply |