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 (declaim (inline %other-pointer-widetag
))
44 (defun %other-pointer-widetag
(x)
45 (sb!sys
:sap-ref-8
(int-sap (get-lisp-obj-address x
))
46 #.
(ecase sb
!c
:*backend-byte-order
*
48 (- sb
!vm
:other-pointer-lowtag
))
50 (- (1- sb
!vm
:n-word-bytes
) sb
!vm
:other-pointer-lowtag
)))))
52 ;;; Return a System-Area-Pointer pointing to the data for the vector
53 ;;; X, which must be simple.
55 ;;; FIXME: So it should be SIMPLE-VECTOR-SAP, right? (or UNHAIRY-VECTOR-SAP,
56 ;;; if the meaning is (SIMPLE-ARRAY * 1) instead of SIMPLE-VECTOR)
57 ;;; (or maybe SIMPLE-VECTOR-DATA-SAP or UNHAIRY-VECTOR-DATA-SAP?)
59 (declare (type (simple-unboxed-array (*)) x
))
62 ;;; Return a System-Area-Pointer pointing to the end of the binding stack.
63 (defun sb!c
::binding-stack-pointer-sap
()
64 (sb!c
::binding-stack-pointer-sap
))
66 ;;; Return a System-Area-Pointer pointing to the next free word of the
67 ;;; current dynamic space.
68 (defun sb!c
::dynamic-space-free-pointer
()
69 (sb!c
::dynamic-space-free-pointer
))
71 ;;; Return a System-Area-Pointer pointing to the end of the control stack.
72 (defun sb!c
::control-stack-pointer-sap
()
73 (sb!c
::control-stack-pointer-sap
))
75 ;;; Return the header typecode for FUNCTION. Can be set with SETF.
76 (defun fun-subtype (function)
77 (fun-subtype function
))
78 (defun (setf fun-subtype
) (type function
)
79 (setf (fun-subtype function
) type
))
81 ;;;; SIMPLE-FUN and accessors
83 (defun simple-fun-p (object)
84 (simple-fun-p object
))
86 (deftype simple-fun
()
87 '(satisfies simple-fun-p
))
89 (defun %simple-fun-doc
(simple-fun)
90 (declare (simple-fun simple-fun
))
91 (let ((info (%simple-fun-info simple-fun
)))
92 (cond ((typep info
'(or null string
))
94 ((simple-vector-p info
)
99 (bug "bogus INFO for ~S: ~S" simple-fun info
)))))
101 (defun (setf %simple-fun-doc
) (doc simple-fun
)
102 (declare (type (or null string
) doc
)
103 (simple-fun simple-fun
))
104 (let ((info (%simple-fun-info simple-fun
)))
105 (setf (%simple-fun-info simple-fun
)
106 (cond ((typep info
'(or null string
))
108 ((simple-vector-p info
)
114 (cons doc
(cdr info
))
117 (bug "bogus INFO for ~S: ~S" simple-fun info
))))))
119 (defun %simple-fun-xrefs
(simple-fun)
120 (declare (simple-fun simple-fun
))
121 (let ((info (%simple-fun-info simple-fun
)))
122 (cond ((typep info
'(or null string
))
124 ((simple-vector-p info
)
129 (bug "bogus INFO for ~S: ~S" simple-fun info
)))))
131 ;;; Extract the arglist from the function header FUNC.
132 (defun %simple-fun-arglist
(func)
133 (%simple-fun-arglist func
))
135 (defun (setf %simple-fun-arglist
) (new-value func
)
136 (setf (%simple-fun-arglist func
) new-value
))
138 ;;; Extract the name from the function header FUNC.
139 (defun %simple-fun-name
(func)
140 (%simple-fun-name func
))
142 (defun (setf %simple-fun-name
) (new-value func
)
143 (setf (%simple-fun-name func
) new-value
))
145 ;;; Extract the type from the function header FUNC.
146 (defun %simple-fun-type
(func)
147 (%simple-fun-type func
))
149 (defun %simple-fun-next
(simple-fun)
150 (%simple-fun-next simple-fun
))
152 ;; Given either a closure or a simple-fun, return the underlying simple-fun.
153 ;; FIXME: %SIMPLE-FUN-SELF is a somewhat poor name for this function.
154 ;; The x86[-64] code defines %CLOSURE-FUN as nothing more than %SIMPLE-FUN-SELF,
155 ;; and it's not clear whether that's because callers need the "simple" accessor
156 ;; to work on closures, versus reluctance to define a %CLOSURE/SIMPLE-FUN-FUN
157 ;; reader. %FUN-FUN works on all three function subtypes, but is nontrivial.
158 ;; Preferably at least one accessor should get a new name,
159 ;; so that %SIMPLE-FUN-SELF can mean what it says.
161 (defun %simple-fun-self
(simple-fun)
162 (%simple-fun-self simple-fun
))
164 ;;;; CLOSURE type and accessors
166 (defun closurep (object)
170 '(satisfies closurep
))
172 (defmacro do-closure-values
((value closure
) &body body
)
173 (with-unique-names (i nclosure
)
174 `(let ((,nclosure
,closure
))
175 (declare (closure ,nclosure
))
176 (dotimes (,i
(- (1+ (get-closure-length ,nclosure
)) sb
!vm
:closure-info-offset
))
177 (let ((,value
(%closure-index-ref
,nclosure
,i
)))
180 (defun %closure-values
(closure)
181 (declare (closure closure
))
183 (do-closure-values (elt closure
)
187 ;;; Extract the function from CLOSURE.
188 (defun %closure-fun
(closure)
189 (%closure-fun closure
))
191 ;;; Extract the INDEXth slot from CLOSURE.
192 (defun %closure-index-ref
(closure index
)
193 (%closure-index-ref closure index
))
195 ;;; Return the length of VECTOR. There is no reason to use this in
196 ;;; ordinary code, 'cause length (the vector foo)) is the same.
197 (defun sb!c
::vector-length
(vector)
198 (sb!c
::vector-length vector
))
200 ;;; Allocate a unboxed, simple vector with type code TYPE, length LENGTH, and
201 ;;; WORDS words long. Note: it is your responsibility to ensure that the
202 ;;; relation between LENGTH and WORDS is correct.
203 (defun allocate-vector (type length words
)
204 (allocate-vector type length words
))
206 ;;; Allocate an array header with type code TYPE and rank RANK.
207 (defun make-array-header (type rank
)
208 (make-array-header type rank
))
210 ;;; Return a SAP pointing to the instructions part of CODE-OBJ.
211 (defun code-instructions (code-obj)
212 (code-instructions code-obj
))
214 ;;; Extract the INDEXth element from the header of CODE-OBJ. Can be
216 (defun code-header-ref (code-obj index
)
217 (code-header-ref code-obj index
))
219 (defun code-header-set (code-obj index new
)
220 (code-header-set code-obj index new
))
222 (defun %vector-raw-bits
(object offset
)
223 (declare (type index offset
))
224 (%vector-raw-bits object offset
))
226 (defun %set-vector-raw-bits
(object offset value
)
227 (declare (type index offset
))
228 (declare (type word value
))
229 (setf (%vector-raw-bits object offset
) value
))
231 (defun make-single-float (x) (make-single-float x
))
232 (defun make-double-float (hi lo
) (make-double-float hi lo
))
234 (defun single-float-bits (x) (single-float-bits x
))
235 (defun double-float-high-bits (x) (double-float-high-bits x
))
236 (defun double-float-low-bits (x) (double-float-low-bits x
))