Code for BEGIN now generates simpler code for sequences fo `simple'
authorStephen Adams <edu/mit/csail/zurich/adams>
Sat, 6 May 1995 18:25:35 +0000 (18:25 +0000)
committerStephen Adams <edu/mit/csail/zurich/adams>
Sat, 6 May 1995 18:25:35 +0000 (18:25 +0000)
expressions.

v8/src/compiler/midend/cpsconv.scm

index bec483ae0ecfea4bdc8af6760114e652c6f21208..a4eaedba7540b90a81376b5350cb3e12623f02df 100644 (file)
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: cpsconv.scm,v 1.11 1995/05/05 12:57:26 adams Exp $
+$Id: cpsconv.scm,v 1.12 1995/05/06 18:25:35 adams Exp $
 
 Copyright (c) 1994-1995 Massachusetts Institute of Technology
 
@@ -297,19 +297,27 @@ MIT in each case. |#
       (internal-error "Empty begin")
       (let walk ((next    (car actions))
                 (actions (cdr actions)))
-       (if (null? actions)
-           (cpsconv/expr cont next)
-           (let ((next-name (cpsconv/new-name 'NEXT))
-                 (ignore (cpsconv/new-ignored-continuation)))
-             `(LET ((,next-name
-                     (LAMBDA (,ignore)
-                       ,(walk (car actions)
-                              (cdr actions)))))
-                ,(cpsconv/expr
-                  (cpsconv/begin-continuation
-                   next-name
-                   (cpsconv/dbg-continuation/make 'BEGIN form next))
-                  next)))))))
+       (cond ((null? actions)
+              (cpsconv/expr cont next))
+             ((form/simple? next)
+              ;; This clause is completely optional but makes for a smaller
+              ;; program that needs less simplification.
+              (let ((next* (cpsconv/simple/copy next))
+                    (rest  (walk (car actions) (cdr actions))))
+                (if (BEGIN/? rest)
+                    `(BEGIN ,next* ,@(begin/exprs rest))
+                    `(BEGIN ,next* ,rest))))
+             (else
+              (let ((next-name (cpsconv/new-name 'NEXT)))
+                `(LET ((,next-name
+                        (LAMBDA (,(cpsconv/new-ignored-continuation))
+                          ,(walk (car actions)
+                                 (cdr actions)))))
+                   ,(cpsconv/expr
+                     (cpsconv/begin-continuation
+                      next-name
+                      (cpsconv/dbg-continuation/make 'BEGIN form next))
+                     next))))))))
 
 (define-cps-converter IF (cont pred conseq alt)
   (define (general)