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

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

Support keyword parameters.

File size: 2.1 KB
Line 
1;;; deftype.lisp
2;;;
3;;; Copyright (C) 2004-2005 Peter Graves
4;;; $Id: deftype.lisp,v 1.7 2005-05-27 12:18:28 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  ;; Optional and keyword parameters default to * rather than NIL.
24  (when (or (memq '&optional lambda-list)
25            (memq '&key lambda-list))
26    (let ((new-lambda-list ())
27          (state nil))
28      (dolist (thing lambda-list)
29        (cond ((eq thing '&optional)
30               (setf state '&optional))
31              ((eq thing '&key)
32               (setf state '&key))
33              ((memq thing lambda-list-keywords)
34               (setf state nil))
35              ((eq state '&optional)
36               (when (symbolp thing)
37                 (setf thing (list thing ''*))))
38              ((eq state '&key)
39               (when (symbolp thing)
40                 (setf thing (list thing ''*)))))
41        (push thing new-lambda-list))
42      (setf lambda-list (nreverse new-lambda-list))))
43  `(progn
44     (setf (get ',name 'deftype-definition)
45           #'(lambda ,lambda-list (block ,name ,@body)))
46     ',name))
47
48(defun expand-deftype (type)
49  (let (tp i)
50    (loop
51      (if (consp type)
52          (setf tp (%car type) i (%cdr type))
53          (setf tp type
54                i nil))
55      (if (and (symbolp tp) (get tp 'deftype-definition))
56          (setf type (apply (get tp 'deftype-definition) i))
57          (return))))
58  type)
Note: See TracBrowser for help on using the repository browser.