source: trunk/j/src/org/armedbear/lisp/deftype.lisp @ 9375

Last change on this file since 9375 was 9375, checked in by piso, 16 years ago

CHECK-DECLARATION-TYPE

File size: 2.1 KB
Line 
1;;; deftype.lisp
2;;;
3;;; Copyright (C) 2004-2005 Peter Graves
4;;; $Id: deftype.lisp,v 1.8 2005-06-14 00:53:33 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(in-package #:system)
21
22(defmacro deftype (name lambda-list &rest body)
23  (check-declaration-type name)
24  ;; Optional and keyword parameters default to * rather than NIL.
25  (when (or (memq '&optional lambda-list)
26            (memq '&key lambda-list))
27    (let ((new-lambda-list ())
28          (state nil))
29      (dolist (thing lambda-list)
30        (cond ((eq thing '&optional)
31               (setf state '&optional))
32              ((eq thing '&key)
33               (setf state '&key))
34              ((memq thing lambda-list-keywords)
35               (setf state nil))
36              ((eq state '&optional)
37               (when (symbolp thing)
38                 (setf thing (list thing ''*))))
39              ((eq state '&key)
40               (when (symbolp thing)
41                 (setf thing (list thing ''*)))))
42        (push thing new-lambda-list))
43      (setf lambda-list (nreverse new-lambda-list))))
44  `(progn
45     (setf (get ',name 'deftype-definition)
46           #'(lambda ,lambda-list (block ,name ,@body)))
47     ',name))
48
49(defun expand-deftype (type)
50  (let (tp i)
51    (loop
52      (if (consp type)
53          (setf tp (%car type) i (%cdr type))
54          (setf tp type
55                i nil))
56      (if (and (symbolp tp) (get tp 'deftype-definition))
57          (setf type (apply (get tp 'deftype-definition) i))
58          (return))))
59  type)
Note: See TracBrowser for help on using the repository browser.