/[cmucl]/src/code/macros.lisp
ViewVC logotype

Diff of /src/code/macros.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.107 by rtoy, Fri Oct 21 17:56:07 2005 UTC revision 1.108 by rtoy, Fri Nov 18 19:36:17 2005 UTC
# Line 1623  Line 1623 
1623    
1624  ;;;; Iteration macros:  ;;;; Iteration macros:
1625    
1626    ;;; Make sure we iterate the given number of times, independent of
1627    ;;; what the body might do to the index variable.  We do this by
1628    ;;; repeatedly binding the var in the body and also in the result
1629    ;;; form.  We also spuriously reference the var in case the body or
1630    ;;; result form don't reference the var either.  (Mostly modeled on
1631    ;;; the dolist macro below.)
1632  (defmacro dotimes ((var count &optional (result nil)) &body body)  (defmacro dotimes ((var count &optional (result nil)) &body body)
1633    (cond ((numberp count)    (let ((count-var (gensym "CTR-")))
1634           `(do ((,var 0 (1+ ,var)))      (multiple-value-bind (forms decls)
1635                ((>= ,var ,count) ,result)          (parse-body body nil nil)
1636              (declare (type (integer 0 ,count) ,var))        (cond ((numberp count)
1637              ,@body))               `(do ((,count-var 0 (1+ ,count-var)))
1638          (t (let ((v1 (gensym)))                    ((>= ,count-var ,count)
1639               `(do ((,var 0 (1+ ,var)) (,v1 ,count))                     (let ((,var ,count-var))
1640                    ((>= ,var ,v1) ,result)                       ,var
1641                  (declare (type unsigned-byte ,var))                       ,result))
1642                  ,@body)))))                  (declare (type (integer 0 ,count) ,count-var))
1643                    (let ((,var ,count-var))
1644                      ,@decls
1645                      ,var
1646                      (tagbody
1647                         ,@forms))))
1648                (t (let ((v1 (gensym)))
1649                     `(do ((,count-var 0 (1+ ,count-var))
1650                           (,v1 ,count))
1651                          ((>= ,count-var ,v1)
1652                           (let ((,var ,count-var))
1653                             ,var
1654                             ,result))
1655                        (declare (type unsigned-byte ,count-var))
1656                        (let ((,var ,count-var))
1657                          ,@decls
1658                          ,var
1659                          (tagbody
1660                             ,@forms)))))))))
1661    
1662    
1663  ;;; We repeatedly bind the var instead of setting it so that we never give the  ;;; We repeatedly bind the var instead of setting it so that we never give the

Legend:
Removed from v.1.107  
changed lines
  Added in v.1.108

  ViewVC Help
Powered by ViewVC 1.1.5