1 ;;;; miscellaneous kernel-level definitions
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.
12 (in-package "SB!KERNEL")
14 ;;; Return the 24 bits of data in the header of object X, which must
15 ;;; be an other-pointer object.
16 (defun get-header-data (x)
19 ;;; Set the 24 bits of data in the header of object X (which must be
20 ;;; an other-pointer object) to VAL.
21 (defun set-header-data (x val
)
22 (set-header-data x val
))
24 ;;; Return the 24 bits of data in the header of object X, which must
25 ;;; be a fun-pointer object.
27 ;;; FIXME: Should this not be called GET-FUN-LENGTH instead? Or even better
28 ;;; yet, if GET-HEADER-DATA masked the lowtag instead of substracting it, we
29 ;;; could just use it instead -- or at least this could just be a function on
30 ;;; top of the same VOP.
31 (defun get-closure-length (x)
32 (get-closure-length x
))
40 ;;; WIDETAG-OF needs extra code to handle LIST and FUNCTION lowtags. When
41 ;;; we're only dealing with other pointers (eg. when dispatching on array
42 ;;; element type), this is going to be faster.
43 (defun %other-pointer-widetag
(x)
44 (%other-pointer-widetag x
))
46 ;;; Return a System-Area-Pointer pointing to the data for the vector
47 ;;; X, which must be simple.
49 ;;; FIXME: So it should be SIMPLE-VECTOR-SAP, right? (or UNHAIRY-VECTOR-SAP,
50 ;;; if the meaning is (SIMPLE-ARRAY * 1) instead of SIMPLE-VECTOR)
51 ;;; (or maybe SIMPLE-VECTOR-DATA-SAP or UNHAIRY-VECTOR-DATA-SAP?)
53 (declare (type (simple-unboxed-array (*)) x
))
56 ;;; Return a System-Area-Pointer pointing to the end of the binding stack.
57 (defun sb!c
::binding-stack-pointer-sap
()
58 (sb!c
::binding-stack-pointer-sap
))
60 ;;; Return a System-Area-Pointer pointing to the next free word of the
61 ;;; current dynamic space.
62 (defun sb!c
::dynamic-space-free-pointer
()
63 (sb!c
::dynamic-space-free-pointer
))
65 ;;; Return a System-Area-Pointer pointing to the end of the control stack.
66 (defun sb!c
::control-stack-pointer-sap
()
67 (sb!c
::control-stack-pointer-sap
))
70 (defun sb!c
:safe-fdefn-fun
(x) (sb!c
:safe-fdefn-fun x
))
72 ;;; Return the header typecode for FUNCTION. Can be set with SETF.
73 (defun fun-subtype (function)
74 (fun-subtype function
))
75 (defun (setf fun-subtype
) (type function
)
76 (setf (fun-subtype function
) type
))
78 ;;;; SIMPLE-FUN and accessors
80 (defun simple-fun-p (object)
81 (simple-fun-p object
))
83 (deftype simple-fun
()
84 '(satisfies simple-fun-p
))
86 (defun %simple-fun-doc
(simple-fun)
87 (declare (simple-fun simple-fun
))
88 (let ((info (%simple-fun-info simple-fun
)))
89 (cond ((typep info
'(or null string
))
91 ((simple-vector-p info
)
96 (bug "bogus INFO for ~S: ~S" simple-fun info
)))))
98 (defun (setf %simple-fun-doc
) (doc simple-fun
)
99 (declare (type (or null string
) doc
)
100 (simple-fun simple-fun
))
101 (let ((info (%simple-fun-info simple-fun
)))
102 (setf (%simple-fun-info simple-fun
)
103 (cond ((typep info
'(or null string
))
105 ((simple-vector-p info
)
111 (cons doc
(cdr info
))
114 (bug "bogus INFO for ~S: ~S" simple-fun info
))))))
116 (defun %simple-fun-xrefs
(simple-fun)
117 (declare (simple-fun simple-fun
))
118 (let ((info (%simple-fun-info simple-fun
)))
119 (cond ((typep info
'(or null string
))
121 ((simple-vector-p info
)
126 (bug "bogus INFO for ~S: ~S" simple-fun info
)))))
128 ;;; Extract the arglist from the function header FUNC.
129 (defun %simple-fun-arglist
(func)
130 (%simple-fun-arglist func
))
132 (defun (setf %simple-fun-arglist
) (new-value func
)
133 (setf (%simple-fun-arglist func
) new-value
))
135 ;;; Extract the name from the function header FUNC.
136 (defun %simple-fun-name
(func)
137 (%simple-fun-name func
))
139 (defun (setf %simple-fun-name
) (new-value func
)
140 (setf (%simple-fun-name func
) new-value
))
142 ;;; Extract the type from the function header FUNC.
143 (defun %simple-fun-type
(func)
144 (%simple-fun-type func
))
146 (defun %simple-fun-next
(simple-fun)
147 (%simple-fun-next simple-fun
))
149 ;; Given either a closure or a simple-fun, return the underlying simple-fun.
150 ;; FIXME: %SIMPLE-FUN-SELF is a somewhat poor name for this function.
151 ;; The x86[-64] code defines %CLOSURE-FUN as nothing more than %SIMPLE-FUN-SELF,
152 ;; and it's not clear whether that's because callers need the "simple" accessor
153 ;; to work on closures, versus reluctance to define a %CLOSURE/SIMPLE-FUN-FUN
154 ;; reader. %FUN-FUN works on all three function subtypes, but is nontrivial.
155 ;; Preferably at least one accessor should get a new name,
156 ;; so that %SIMPLE-FUN-SELF can mean what it says.
158 (defun %simple-fun-self
(simple-fun)
159 (%simple-fun-self simple-fun
))
161 ;;;; CLOSURE type and accessors
163 (defun closurep (object)
167 '(satisfies closurep
))
169 (defmacro do-closure-values
((value closure
) &body body
)
170 (with-unique-names (i nclosure
)
171 `(let ((,nclosure
,closure
))
172 (declare (closure ,nclosure
))
173 (dotimes (,i
(- (1+ (get-closure-length ,nclosure
)) sb
!vm
:closure-info-offset
))
174 (let ((,value
(%closure-index-ref
,nclosure
,i
)))
177 (defun %closure-values
(closure)
178 (declare (closure closure
))
180 (do-closure-values (elt closure
)
184 ;;; Extract the function from CLOSURE.
185 (defun %closure-fun
(closure)
186 (%closure-fun closure
))
188 ;;; Extract the INDEXth slot from CLOSURE.
189 (defun %closure-index-ref
(closure index
)
190 (%closure-index-ref closure index
))
192 ;;; Return the length of VECTOR. There is no reason to use this in
193 ;;; ordinary code, 'cause length (the vector foo)) is the same.
194 (defun sb!c
::vector-length
(vector)
195 (sb!c
::vector-length vector
))
197 ;;; Allocate a unboxed, simple vector with type code TYPE, length LENGTH, and
198 ;;; WORDS words long. Note: it is your responsibility to ensure that the
199 ;;; relation between LENGTH and WORDS is correct.
200 (defun allocate-vector (type length words
)
201 (allocate-vector type length words
))
203 ;;; Allocate an array header with type code TYPE and rank RANK.
204 (defun make-array-header (type rank
)
205 (make-array-header type rank
))
207 ;;; Return a SAP pointing to the instructions part of CODE-OBJ.
208 (defun code-instructions (code-obj)
209 (code-instructions code-obj
))
211 ;;; Extract the INDEXth element from the header of CODE-OBJ. Can be
213 (defun code-header-ref (code-obj index
)
214 (code-header-ref code-obj index
))
216 (defun code-header-set (code-obj index new
)
217 (code-header-set code-obj index new
))
219 (defun %vector-raw-bits
(object offset
)
220 (declare (type index offset
))
221 (%vector-raw-bits object offset
))
223 (defun %set-vector-raw-bits
(object offset value
)
224 (declare (type index offset
))
225 (declare (type word value
))
226 (setf (%vector-raw-bits object offset
) value
))
228 (defun make-single-float (x) (make-single-float x
))
229 (defun make-double-float (hi lo
) (make-double-float hi lo
))
231 (defun single-float-bits (x) (single-float-bits x
))
232 (defun double-float-high-bits (x) (double-float-high-bits x
))
233 (defun double-float-low-bits (x) (double-float-low-bits x
))
235 (defun value-cell-ref (x) (value-cell-ref x
))