From 5c05a46da92cadf28e13f134bec61419113b973a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 17 Jul 2023 21:59:56 -0700 Subject: 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. --- stdlib/optimize.tl | 9 ++++++--- 1 file 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 -- cgit v1.2.3