1 ;;;; types which are needed to implement byte-compiled functions
3 ;;;; This software is part of the SBCL system. See the README file for
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.
16 (deftype stack-pointer ()
17 `(integer 0 ,(1- most-positive-fixnum)))
19 ;;; KLUDGE: bare numbers, no documentation, ick.. -- WHN 19990701
20 (defconstant max-pc (1- (ash 1 24)))
26 `(integer ,(- max-pc) ,max-pc))
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)
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)
46 (print-unreadable-object (x stream :type t :identity t)
47 (prin1 (byte-function-name (byte-closure-function x))
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))
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)
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.
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))))
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))
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
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
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))
106 #!-sb-fluid (declaim (freeze-type byte-function-or-closure))