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 (let ((internal-type (sb!vm
::%%simple-fun-type func
)))
145 ;; For backward-compatibility we expand SFUNCTION -> FUNCTION.
146 (if (and (listp internal-type
) (eq (car internal-type
) 'sfunction
))
147 (sb!ext
:typexpand-1 internal-type
)
150 (defun %simple-fun-next
(simple-fun)
151 (%simple-fun-next simple-fun
))
153 ;; Given either a closure or a simple-fun, return the underlying simple-fun.
154 ;; FIXME: %SIMPLE-FUN-SELF is a somewhat poor name for this function.
155 ;; The x86[-64] code defines %CLOSURE-FUN as nothing more than %SIMPLE-FUN-SELF,
156 ;; and it's not clear whether that's because callers need the "simple" accessor
157 ;; to work on closures, versus reluctance to define a %CLOSURE/SIMPLE-FUN-FUN
158 ;; reader. %FUN-FUN works on all three function subtypes, but is nontrivial.
159 ;; Preferably at least one accessor should get a new name,
160 ;; so that %SIMPLE-FUN-SELF can mean what it says.
162 (defun %simple-fun-self
(simple-fun)
163 (%simple-fun-self simple-fun
))
165 ;;;; CLOSURE type and accessors
167 (defun closurep (object)
171 '(satisfies closurep
))
173 (defmacro do-closure-values
((value closure
) &body body
)
174 (with-unique-names (i nclosure
)
175 `(let ((,nclosure
,closure
))
176 (declare (closure ,nclosure
))
177 (dotimes (,i
(- (1+ (get-closure-length ,nclosure
)) sb
!vm
:closure-info-offset
))
178 (let ((,value
(%closure-index-ref
,nclosure
,i
)))
181 (defun %closure-values
(closure)
182 (declare (closure closure
))
184 (do-closure-values (elt closure
)
188 ;;; Extract the function from CLOSURE.
189 (defun %closure-fun
(closure)
190 (%closure-fun closure
))
192 ;;; Extract the INDEXth slot from CLOSURE.
193 (defun %closure-index-ref
(closure index
)
194 (%closure-index-ref closure index
))
196 ;;; Return the length of VECTOR. There is no reason to use this in
197 ;;; ordinary code, 'cause length (the vector foo)) is the same.
198 (defun sb!c
::vector-length
(vector)
199 (sb!c
::vector-length vector
))
201 ;;; Allocate a unboxed, simple vector with type code TYPE, length LENGTH, and
202 ;;; WORDS words long. Note: it is your responsibility to ensure that the
203 ;;; relation between LENGTH and WORDS is correct.
204 (defun allocate-vector (type length words
)
205 (allocate-vector type length words
))
207 ;;; Allocate an array header with type code TYPE and rank RANK.
208 (defun make-array-header (type rank
)
209 (make-array-header type rank
))
211 ;;; Return a SAP pointing to the instructions part of CODE-OBJ.
212 (defun code-instructions (code-obj)
213 (code-instructions code-obj
))
215 ;;; Extract the INDEXth element from the header of CODE-OBJ. Can be
217 (defun code-header-ref (code-obj index
)
218 (code-header-ref code-obj index
))
220 (defun code-header-set (code-obj index new
)
221 (code-header-set code-obj index new
))
223 (defun %vector-raw-bits
(object offset
)
224 (declare (type index offset
))
225 (%vector-raw-bits object offset
))
227 (defun %set-vector-raw-bits
(object offset value
)
228 (declare (type index offset
))
229 (declare (type word value
))
230 (setf (%vector-raw-bits object offset
) value
))
232 (defun make-single-float (x) (make-single-float x
))
233 (defun make-double-float (hi lo
) (make-double-float hi lo
))
235 (defun single-float-bits (x) (single-float-bits x
))
236 (defun double-float-high-bits (x) (double-float-high-bits x
))
237 (defun double-float-low-bits (x) (double-float-low-bits x
))
239 (defun value-cell-ref (x) (value-cell-ref x
))
241 ;;; A unique GC id. This is supplied for code that needs to detect
242 ;;; whether a GC has happened since some earlier point in time. For
245 ;;; (let ((epoch *gc-epoch*))
247 ;;; (unless (eql epoch *gc-epoch)
250 ;;; This isn't just a fixnum counter since then we'd have theoretical
251 ;;; problems when exactly 2^29 GCs happen between epoch
252 ;;; comparisons. Unlikely, but the cost of using a cons instead is too
253 ;;; small to measure. -- JES, 2007-09-30
254 (declaim (type cons
*gc-epoch
*))
255 (!defglobal
*gc-epoch
* '(nil . nil
))