Simplify let-values to let if consumer binds only one variable
authorAndy Wingo <wingo@pobox.com>
Tue, 28 May 2013 15:20:29 +0000 (11:20 -0400)
committerAndy Wingo <wingo@pobox.com>
Mon, 10 Jun 2013 20:43:13 +0000 (22:43 +0200)
* module/language/tree-il/peval.scm (peval): let-values with a consumer
  that has only one argument is the same as let.

* test-suite/tests/peval.test ("partial evaluation"): Add test.

module/language/tree-il/peval.scm
test-suite/tests/peval.test

index c5a1c4e..d7d561d 100644 (file)
@@ -979,6 +979,10 @@ top-level bindings from ENV and return the resulting expression."
        ;; reconstruct the let-values, pevaling the consumer.
        (let ((producer (for-values producer)))
          (or (match consumer
+               (($ <lambda-case> src (req-name) #f #f #f () (req-sym) body #f)
+                (for-tail
+                 (make-let src (list req-name) (list req-sym) (list producer)
+                           body)))
                (($ <lambda-case> src req opt rest #f inits gensyms body #f)
                 (let* ((nmin (length req))
                        (nmax (and (not rest) (+ nmin (if opt (length opt) 0)))))
index ecc5dd1..f409e94 100644 (file)
       (call-with-prompt t
                         (lambda () (abort-to-prompt t 1 2 3))
                         (lambda (k x y z) (list x y z))))
-    (primcall list (const 1) (const 2) (const 3))))
+    (primcall list (const 1) (const 2) (const 3)))
+
+  (pass-if-peval
+      (call-with-values foo (lambda (x) (bar x)))
+    (let (x) (_) ((call (toplevel foo)))
+         (call (toplevel bar) (lexical x _)))))