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