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 (declaim (inline simple-fun-p))
84 (defun simple-fun-p (object)
85 (= sb!vm:simple-fun-header-widetag (widetag-of object)))
87 (deftype simple-fun ()
88 '(satisfies simple-fun-p))
90 (defun %simple-fun-doc (simple-fun)
91 (declare (simple-fun simple-fun))
92 (let ((info (%simple-fun-info simple-fun)))
93 (cond ((typep info '(or null string))
95 ((simple-vector-p info)
100 (bug "bogus INFO for ~S: ~S" simple-fun info)))))
102 (defun (setf %simple-fun-doc) (doc simple-fun)
103 (declare (type (or null string) doc)
104 (simple-fun simple-fun))
105 (let ((info (%simple-fun-info simple-fun)))
106 (setf (%simple-fun-info simple-fun)
107 (cond ((typep info '(or null string))
109 ((simple-vector-p info)
115 (cons doc (cdr info))
118 (bug "bogus INFO for ~S: ~S" simple-fun info))))))
120 (defun %simple-fun-xrefs (simple-fun)
121 (declare (simple-fun simple-fun))
122 (let ((info (%simple-fun-info simple-fun)))
123 (cond ((typep info '(or null string))
125 ((simple-vector-p info)
130 (bug "bogus INFO for ~S: ~S" simple-fun info)))))
132 ;;; Extract the arglist from the function header FUNC.
133 (defun %simple-fun-arglist (func)
134 (%simple-fun-arglist func))
136 (defun (setf %simple-fun-arglist) (new-value func)
137 (setf (%simple-fun-arglist func) new-value))
139 ;;; Extract the name from the function header FUNC.
140 (defun %simple-fun-name (func)
141 (%simple-fun-name func))
143 (defun (setf %simple-fun-name) (new-value func)
144 (setf (%simple-fun-name func) new-value))
146 ;;; Extract the type from the function header FUNC.
147 (defun %simple-fun-type (func)
148 (%simple-fun-type func))
150 (defun %simple-fun-next (simple-fun)
151 (%simple-fun-next simple-fun))
153 (defun %simple-fun-self (simple-fun)
154 (%simple-fun-self simple-fun))
156 ;;;; CLOSURE type and accessors
158 (declaim (inline closurep))
159 (defun closurep (object)
160 (= sb!vm:closure-header-widetag (widetag-of object)))
163 '(satisfies closurep))
165 (defmacro do-closure-values ((value closure) &body body)
166 (with-unique-names (i nclosure)
167 `(let ((,nclosure ,closure))
168 (declare (closure ,nclosure))
169 (dotimes (,i (- (1+ (get-closure-length ,nclosure)) sb!vm:closure-info-offset))
170 (let ((,value (%closure-index-ref ,nclosure ,i)))
173 (defun %closure-values (closure)
174 (declare (closure closure))
176 (do-closure-values (elt closure)
180 ;;; Extract the function from CLOSURE.
181 (defun %closure-fun (closure)
182 (%closure-fun closure))
184 ;;; Extract the INDEXth slot from CLOSURE.
185 (defun %closure-index-ref (closure index)
186 (%closure-index-ref closure index))
188 ;;; Return the length of VECTOR. There is no reason to use this in
189 ;;; ordinary code, 'cause length (the vector foo)) is the same.
190 (defun sb!c::vector-length (vector)
191 (sb!c::vector-length vector))
193 ;;; Allocate a unboxed, simple vector with type code TYPE, length LENGTH, and
194 ;;; WORDS words long. Note: it is your responsibility to ensure that the
195 ;;; relation between LENGTH and WORDS is correct.
196 (defun allocate-vector (type length words)
197 (allocate-vector type length words))
199 ;;; Allocate an array header with type code TYPE and rank RANK.
200 (defun make-array-header (type rank)
201 (make-array-header type rank))
203 ;;; Return a SAP pointing to the instructions part of CODE-OBJ.
204 (defun code-instructions (code-obj)
205 (code-instructions code-obj))
207 ;;; Extract the INDEXth element from the header of CODE-OBJ. Can be
209 (defun code-header-ref (code-obj index)
210 (code-header-ref code-obj index))
212 (defun code-header-set (code-obj index new)
213 (code-header-set code-obj index new))
215 (defun %vector-raw-bits (object offset)
216 (declare (type index offset))
217 (sb!kernel:%vector-raw-bits object offset))
219 (defun %set-vector-raw-bits (object offset value)
220 (declare (type index offset))
221 (declare (type sb!vm:word value))
222 (setf (sb!kernel:%vector-raw-bits object offset) value))
224 (defun make-single-float (x) (make-single-float x))
225 (defun make-double-float (hi lo) (make-double-float hi lo))
227 (defun single-float-bits (x) (single-float-bits x))
228 (defun double-float-high-bits (x) (double-float-high-bits x))
229 (defun double-float-low-bits (x) (double-float-low-bits x))