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
5 ;;;; This software is part of the SBCL system. See the README file for
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.
14 (in-package "SB!KERNEL")
16 (!begin-collecting-cold-init-forms)
18 (defstruct (alien-type-type
20 (class-info (type-class-or-lose 'alien)))
21 (:constructor %make-alien-type-type (alien-type)))
22 (alien-type nil :type alien-type))
24 (define-type-class alien)
26 (define-type-method (alien :unparse) (type)
27 `(alien ,(unparse-alien-type (alien-type-type-alien-type type))))
29 (define-type-method (alien :simple-subtypep) (type1 type2)
30 (values (alien-subtype-p (alien-type-type-alien-type type1)
31 (alien-type-type-alien-type type2))
34 ;;; KLUDGE: This DEFINE-SUPERCLASSES gets executed much later than the others
35 ;;; (toplevel form time instead of cold load init time) because ALIEN-VALUE
36 ;;; itself is a structure which isn't defined until fairly late.
38 ;;; FIXME: I'm somewhat tempted to just punt ALIEN from the type system.
39 ;;; It's sufficiently unlike the others that it's a bit of a pain, and
40 ;;; it doesn't seem to be put to any good use either in type inference or
41 ;;; in type declarations.
42 (define-superclasses alien ((alien-value)) progn)
44 (define-type-method (alien :simple-=) (type1 type2)
45 (let ((alien-type-1 (alien-type-type-alien-type type1))
46 (alien-type-2 (alien-type-type-alien-type type2)))
47 (values (or (eq alien-type-1 alien-type-2)
48 (alien-type-= alien-type-1 alien-type-2))
51 (def-type-translator alien (&optional (alien-type nil))
54 (make-alien-type-type))
56 (make-alien-type-type alien-type))
58 (make-alien-type-type (parse-alien-type alien-type (make-null-lexenv))))))
60 (defun make-alien-type-type (&optional alien-type)
62 (let ((lisp-rep-type (compute-lisp-rep-type alien-type)))
64 (specifier-type lisp-rep-type)
65 (%make-alien-type-type alien-type)))
68 (!defun-from-collected-cold-init-forms !alien-type-cold-init)