source: trunk/j/src/org/armedbear/lisp/do.lisp @ 11297

Last change on this file since 11297 was 11297, checked in by ehuelsmann, 13 years ago

Set Id keyword for expansion.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1;;; do.lisp
2;;;
3;;; Copyright (C) 2004-2006 Peter Graves <peter@armedbear.org>
4;;;
5;;; This program is free software; you can redistribute it and/or
6;;; modify it under the terms of the GNU General Public License
7;;; as published by the Free Software Foundation; either version 2
8;;; of the License, or (at your option) any later version.
9;;;
10;;; This program is distributed in the hope that it will be useful,
11;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13;;; GNU General Public License for more details.
14;;;
15;;; You should have received a copy of the GNU General Public License
16;;; along with this program; if not, write to the Free Software
17;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19;;; Adapted from CMUCL.
20
21(in-package "SYSTEM")
22
23(defun do-do-body (varlist endlist decls-and-code bind step name block)
24  (let* ((inits ())
25   (steps ())
26   (L1 (gensym))
27   (L2 (gensym)))
28    ;; Check for illegal old-style do.
29    (when (or (not (listp varlist)) (atom endlist))
30      (error "Ill-formed ~S -- possibly illegal old style DO?" name))
31    ;; Parse the varlist to get inits and steps.
32    (dolist (v varlist)
33      (cond ((symbolp v) (push v inits))
34      ((listp v)
35       (unless (symbolp (first v))
36         (error "~S step variable is not a symbol: ~S" name (first v)))
37       (case (length v)
38         (1 (push (first v) inits))
39         (2 (push v inits))
40         (3 (push (list (first v) (second v)) inits)
41      (setq steps (list* (third v) (first v) steps)))
42         (t (error "~S is an illegal form for a ~S varlist." v name))))
43      (t (error "~S is an illegal form for a ~S varlist." v name))))
44    ;; Construct the new form.
45    (multiple-value-bind (code decls) (parse-body decls-and-code nil)
46      `(block ,block
47         (,bind ,(nreverse inits)
48          ,@decls
49          (tagbody
50           (go ,L2)
51           ,L1
52           ,@code
53           (,step ,@(nreverse steps))
54           ,L2
55           (unless ,(car endlist) (go ,L1))
56           (return-from ,block (progn ,@(cdr endlist)))))))))
57
58(defmacro do (varlist endlist &rest body)
59  (do-do-body varlist endlist body 'let 'psetq 'do nil))
60
61(defmacro do* (varlist endlist &rest body)
62  (do-do-body varlist endlist body 'let* 'setq 'do* nil))
Note: See TracBrowser for help on using the repository browser.