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

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

DEFTYPE.16: "The body of the DEFTYPE form (but not the lambda-list) is
implicitly enclosed in a block named NAME..."

File size: 1.9 KB
RevLine 
[4080]1;;; deftype.lisp
2;;;
[8640]3;;; Copyright (C) 2004-2005 Peter Graves
[9266]4;;; $Id: deftype.lisp,v 1.6 2005-05-27 11:43:06 piso Exp $
[4080]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
[8640]20(in-package #:system)
[4080]21
22(defmacro deftype (name lambda-list &rest body)
[6833]23  ;; Optional parameters default to * rather than NIL.
24  ;; FIXME Extend this code to handle keyword parameters too!
25  (when (memq '&optional lambda-list)
26    (let ((new-lambda-list ())
27          (optionalp nil))
28      (dolist (thing lambda-list)
29        (cond (optionalp
30               (when (symbolp thing)
31                 (setf thing (list thing ''*))))
32              ((eq thing '&optional)
33               (setf optionalp t))
34              ((memq thing lambda-list-keywords)
35               (setf optionalp nil)))
36        (push thing new-lambda-list))
37      (setf lambda-list (nreverse new-lambda-list))))
[4080]38  `(progn
[9266]39     (setf (get ',name 'deftype-definition)
40           #'(lambda ,lambda-list (block ,name ,@body)))
[4080]41     ',name))
[8640]42
43(defun expand-deftype (type)
44  (let (tp i)
45    (loop
46      (if (consp type)
[9242]47          (setf tp (%car type) i (%cdr type))
48          (setf tp type
49                i nil))
[8640]50      (if (and (symbolp tp) (get tp 'deftype-definition))
51          (setf type (apply (get tp 'deftype-definition) i))
52          (return))))
53  type)
Note: See TracBrowser for help on using the repository browser.