rename SB-SIMPLE-STREAMS utility function
[sbcl.git] / src / compiler / deftype.lisp
blob370852556b1ad7f65a10e9aa1bfa360d63a4f3ae
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
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))
14 (lambda (whole)
15 (if (cdr whole)
16 (sb!kernel::arg-count-error 'deftype (car whole) (cdr whole) nil 0 0)
17 expansion)))
19 (defun %deftype (name)
20 (setf (classoid-cell-pcl-class (find-classoid-cell name :create t)) nil))
22 (def!macro sb!xc:deftype (&whole form name lambda-list &body body)
23 #!+sb-doc
24 "Define a new type, with syntax like DEFMACRO."
25 (unless (symbolp name)
26 (bad-type name 'symbol "Type name is not a symbol:~% ~S"
27 form))
28 (multiple-value-bind (expander-form doc source-location-form)
29 (multiple-value-bind (forms decls doc) (parse-body body)
30 ;; FIXME: We could use CONSTANTP here to deal with slightly more
31 ;; complex deftypes using CONSTANT-TYPE-EXPANDER, but that XC:CONSTANTP
32 ;; is not availble early enough.
33 (if (and (not lambda-list) (not decls) (not (cdr forms))
34 (or (member (car forms) '(t nil))
35 (and (consp (car forms)) (eq 'quote (caar forms)))))
36 (values `(constant-type-expander ,(car forms)) doc '(sb!c:source-location))
37 (with-unique-names (whole)
38 (multiple-value-bind (macro-body local-decs doc)
39 (parse-defmacro lambda-list whole body name 'deftype :default-default ''*)
40 (values `(lambda (,whole)
41 ,@local-decs
42 ,macro-body)
43 doc
44 nil)))))
45 `(progn
46 (eval-when (:compile-toplevel :load-toplevel :execute)
47 (%compiler-deftype ',name
48 ',lambda-list
49 ,expander-form
50 ,doc
51 ,source-location-form))
52 (eval-when (:load-toplevel :execute)
53 (%deftype ',name))
54 ',name)))