1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
10 (in-package "SB!IMPL")
12 (defun constant-type-expander (expansion)
13 (declare (optimize safety))
16 (sb!kernel::arg-count-error 'deftype (car whole) (cdr whole) nil 0 0)
19 (def!macro sb!xc:deftype (name lambda-list &body body)
21 "Define a new type, with syntax like DEFMACRO."
22 (unless (symbolp name)
23 (error "type name not a symbol: ~S" name))
24 (multiple-value-bind (expander-form doc source-location-form)
25 (multiple-value-bind (forms decls doc) (parse-body body)
26 ;; FIXME: We could use CONSTANTP here to deal with slightly more
27 ;; complex deftypes using CONSTANT-TYPE-EXPANDER, but that XC:CONSTANTP
28 ;; is not availble early enough.
29 (if (and (not lambda-list) (not decls) (not (cdr forms))
30 (or (member (car forms) '(t nil))
31 (eq 'quote (caar forms))))
32 (values `(constant-type-expander ,@forms) doc '(sb!c:source-location))
33 (with-unique-names (whole)
34 (multiple-value-bind (macro-body local-decs doc)
35 (parse-defmacro lambda-list whole body name 'deftype :default-default ''*)
36 (values `(lambda (,whole)
41 `(eval-when (:compile-toplevel :load-toplevel :execute)
42 (%compiler-deftype ',name
46 ,source-location-form))))