0.6.11.13:
[sbcl.git] / src / code / alien-type.lisp
1 ;;;; ALIEN-related type system stuff, done later
2 ;;;; than other type system stuff because it depends on the definition
3 ;;;; of the ALIEN-VALUE target structure type
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
13
14 (in-package "SB!KERNEL")
15
16 (/show0 "code/alien-type.lisp 16")
17
18 (!begin-collecting-cold-init-forms)
19
20 (defstruct (alien-type-type
21             (:include ctype
22                       (class-info (type-class-or-lose 'alien)))
23             (:constructor %make-alien-type-type (alien-type))
24             (:copier nil))
25   (alien-type nil :type alien-type))
26
27 (!define-type-class alien)
28
29 (!define-type-method (alien :unparse) (type)
30   `(alien ,(unparse-alien-type (alien-type-type-alien-type type))))
31
32 (!define-type-method (alien :simple-subtypep) (type1 type2)
33   (values (alien-subtype-p (alien-type-type-alien-type type1)
34                            (alien-type-type-alien-type type2))
35           t))
36
37 ;;; KLUDGE: This !DEFINE-SUPERCLASSES gets executed much later than the
38 ;;; others (toplevel form time instead of cold load init time) because
39 ;;; ALIEN-VALUE itself is a structure which isn't defined until fairly
40 ;;; late.
41 ;;;
42 ;;; FIXME: I'm somewhat tempted to just punt ALIEN from the type system.
43 ;;; It's sufficiently unlike the others that it's a bit of a pain, and
44 ;;; it doesn't seem to be put to any good use either in type inference or
45 ;;; in type declarations.
46 (!define-superclasses alien ((alien-value)) progn)
47
48 (!define-type-method (alien :simple-=) (type1 type2)
49   (let ((alien-type-1 (alien-type-type-alien-type type1))
50         (alien-type-2 (alien-type-type-alien-type type2)))
51     (values (or (eq alien-type-1 alien-type-2)
52                 (alien-type-= alien-type-1 alien-type-2))
53             t)))
54
55 (!def-type-translator alien (&optional (alien-type nil))
56   (typecase alien-type
57     (null
58      (make-alien-type-type))
59     (alien-type
60      (make-alien-type-type alien-type))
61     (t
62      (make-alien-type-type (parse-alien-type alien-type (make-null-lexenv))))))
63
64 (defun make-alien-type-type (&optional alien-type)
65   (if alien-type
66       (let ((lisp-rep-type (compute-lisp-rep-type alien-type)))
67         (if lisp-rep-type
68             (specifier-type lisp-rep-type)
69             (%make-alien-type-type alien-type)))
70       *universal-type*))
71
72 (!defun-from-collected-cold-init-forms !alien-type-cold-init)
73
74 (/show0 "code/alien-type.lisp end of file")