Optimize code generated for let*, let*-syntax, and letrec.
authorChris Hanson <org/chris-hanson/cph>
Sun, 15 Apr 2018 00:59:41 +0000 (17:59 -0700)
committerChris Hanson <org/chris-hanson/cph>
Sun, 15 Apr 2018 00:59:41 +0000 (17:59 -0700)
Thanks to Patric Jonsson for noticing this.

src/runtime/mit-macros.scm

index 2393cd4160638edca76c2d36d0430ff97d55a57b..a1c87cd7441159334a9625f53b77238977ee0f54 100644 (file)
@@ -142,10 +142,12 @@ USA.
         (expand-let* scons-let-syntax bindings body-forms))))))
 
 (define (expand-let* scons-let bindings body-forms)
-  (fold-right (lambda (binding expr)
-               (scons-let (list binding) expr))
-             (apply scons-let '() body-forms)
-             bindings))
+  (if (pair? bindings)
+      (fold-right (lambda (binding expr)
+                   (scons-let (list binding) expr))
+                 (apply scons-begin body-forms)
+                 bindings)
+      (apply scons-let '() body-forms)))
 
 (define $letrec
   (spar-transformer->runtime
@@ -160,9 +162,14 @@ USA.
           (scons-let (map (lambda (id)
                             (list id (unassigned-expression)))
                           ids)
-            (apply scons-let
-                   (map list temps vals)
-                   (map scons-set! ids temps))
+            (cond ((not (pair? ids))
+                   (default-object))
+                  ((not (pair? (cdr ids)))
+                   (scons-set! (car ids) (car vals)))
+                  (else
+                   (apply scons-let
+                          (map list temps vals)
+                          (map scons-set! ids temps))))
             (scons-call (apply scons-lambda '() body-forms)))))))))
 
 (define $letrec*