8f7824ed2fac58360ac166ee9dfcdc6b6a8215bb
[sbcl.git] / src / code / byte-types.lisp
1 ;;;; types which are needed to implement byte-compiled functions
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!C")
13
14 (file-comment
15   "$Header$")
16 \f
17 ;;;; types
18
19 (deftype stack-pointer ()
20   `(integer 0 ,(1- most-positive-fixnum)))
21
22 ;;; KLUDGE: bare numbers, no documentation, ick.. -- WHN 19990701
23 (eval-when (:compile-toplevel :load-toplevel :execute)
24   (defconstant max-pc (1- (ash 1 24))))
25
26 (deftype pc ()
27   `(integer 0 ,max-pc))
28
29 (deftype return-pc ()
30   `(integer ,(- max-pc) ,max-pc))
31 \f
32 ;;;; byte functions
33
34 ;;; This abstract class represents any type of byte-compiled function.
35 (defstruct (byte-function-or-closure
36             (:alternate-metaclass funcallable-instance
37                                   funcallable-structure-class
38                                   make-funcallable-structure-class)
39             (:type funcallable-structure)
40             (:constructor nil)
41             (:copier nil)))
42
43 ;;; a byte-compiled closure
44 (defstruct (byte-closure
45             (:include byte-function-or-closure)
46             (:constructor make-byte-closure (function data))
47             (:type funcallable-structure)
48             (:print-object
49              (lambda (x stream)
50                (print-unreadable-object (x stream :type t :identity t)
51                  (prin1 (byte-function-name (byte-closure-function x))
52                         stream)))))
53   ;; the byte function that we call
54   (function (required-argument) :type byte-function)
55   ;; the closure data vector
56   (data (required-argument) :type simple-vector))
57
58 ;;; any non-closure byte function (including the hidden function
59 ;;; object for a closure)
60 (defstruct (byte-function (:include byte-function-or-closure)
61                           (:type funcallable-structure)
62                           (:constructor nil))
63   ;; The component that this XEP is an entry point into. NIL until
64   ;; LOAD or MAKE-CORE-BYTE-COMPONENT fills it in. They count on this
65   ;; being the first slot.
66   (component nil :type (or null code-component))
67   ;; Debug name of this function.
68   (name nil))
69 (def!method print-object ((x byte-function) stream)
70   ;; FIXME: I think functions should probably print either as
71   ;; #<FUNCTION ..> or as #<COMPILED-FUNCTION ..>, since those are
72   ;; their user-visible types. (And this should be true for
73   ;; BYTE-CLOSURE objects too.)
74   (print-unreadable-object (x stream :identity t)
75     (format stream "byte function ~S" (byte-function-name x))))
76
77 ;;; fixed-argument byte function
78 (defstruct (simple-byte-function (:include byte-function)
79                                  (:type funcallable-structure))
80   ;; The number of arguments expected.
81   (num-args 0 :type (integer 0 #.call-arguments-limit))
82   ;; The start of the function.
83   (entry-point 0 :type index))
84
85 ;;; variable-arg-count byte function
86 (defstruct (hairy-byte-function (:include byte-function)
87                                 (:type funcallable-structure))
88   ;; The minimum and maximum number of args, ignoring &REST and &KEY.
89   (min-args 0 :type (integer 0 #.call-arguments-limit))
90   (max-args 0 :type (integer 0 #.call-arguments-limit))
91   ;; List of the entry points for min-args, min-args+1, ... max-args.
92   (entry-points nil :type list)
93   ;; The entry point to use when there are more than max-args. Only
94   ;; filled in where okay. In other words, only when &REST or &KEY is
95   ;; specified.
96   (more-args-entry-point nil :type (or null (unsigned-byte 24)))
97   ;; The number of ``more-arg'' args.
98   (num-more-args 0 :type (integer 0 #.call-arguments-limit))
99   ;; True if there is a rest-arg.
100   (rest-arg-p nil :type (member t nil))
101   ;; True if there are keywords. Note: keywords might still be NIL
102   ;; because having &KEY with no keywords is valid and should result
103   ;; in allow-other-keys processing. If :allow-others, then allow
104   ;; other keys.
105   (keywords-p nil :type (member t nil :allow-others))
106   ;; List of keyword arguments. Each element is a list of:
107   ;;   key, default, supplied-p.
108   (keywords nil :type list))
109
110 #!-sb-fluid (declaim (freeze-type byte-function-or-closure))