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 ;;; Extract the arglist from the function header FUNC.
91 (defun %simple-fun-arglist (func)
92 (%simple-fun-arglist func))
94 (defun (setf %simple-fun-arglist) (new-value func)
95 (setf (%simple-fun-arglist func) new-value))
97 ;;; Extract the name from the function header FUNC.
98 (defun %simple-fun-name (func)
99 (%simple-fun-name func))
101 ;;; Extract the type from the function header FUNC.
102 (defun %simple-fun-type (func)
103 (%simple-fun-type func))
105 (defun %simple-fun-next (simple-fun)
106 (%simple-fun-next simple-fun))
108 (defun %simple-fun-self (simple-fun)
109 (%simple-fun-self simple-fun))
111 ;;;; CLOSURE type and accessors
113 (declaim (inline closurep))
114 (defun closurep (object)
115 (= sb!vm:closure-header-widetag (widetag-of object)))
118 '(satisfies closurep))
120 (defmacro do-closure-values ((value closure) &body body)
121 (with-unique-names (i nclosure)
122 `(let ((,nclosure ,closure))
123 (declare (closure ,nclosure))
124 (dotimes (,i (- (1+ (get-closure-length ,nclosure)) sb!vm:closure-info-offset))
125 (let ((,value (%closure-index-ref ,nclosure ,i)))
128 (defun %closure-values (closure)
129 (declare (closure closure))
131 (do-closure-values (elt closure)
135 ;;; Extract the function from CLOSURE.
136 (defun %closure-fun (closure)
137 (%closure-fun closure))
139 ;;; Extract the INDEXth slot from CLOSURE.
140 (defun %closure-index-ref (closure index)
141 (%closure-index-ref closure index))
143 ;;; Return the length of VECTOR. There is no reason to use this in
144 ;;; ordinary code, 'cause length (the vector foo)) is the same.
145 (defun sb!c::vector-length (vector)
146 (sb!c::vector-length vector))
148 ;;; Allocate a unboxed, simple vector with type code TYPE, length LENGTH, and
149 ;;; WORDS words long. Note: it is your responsibility to ensure that the
150 ;;; relation between LENGTH and WORDS is correct.
151 (defun allocate-vector (type length words)
152 (allocate-vector type length words))
154 ;;; Allocate an array header with type code TYPE and rank RANK.
155 (defun make-array-header (type rank)
156 (make-array-header type rank))
158 ;;; Return a SAP pointing to the instructions part of CODE-OBJ.
159 (defun code-instructions (code-obj)
160 (code-instructions code-obj))
162 ;;; Extract the INDEXth element from the header of CODE-OBJ. Can be
164 (defun code-header-ref (code-obj index)
165 (code-header-ref code-obj index))
167 (defun code-header-set (code-obj index new)
168 (code-header-set code-obj index new))
170 (defun %vector-raw-bits (object offset)
171 (declare (type index offset))
172 (sb!kernel:%vector-raw-bits object offset))
174 (defun %set-vector-raw-bits (object offset value)
175 (declare (type index offset))
176 (declare (type sb!vm:word value))
177 (setf (sb!kernel:%vector-raw-bits object offset) value))
179 (defun make-single-float (x) (make-single-float x))
180 (defun make-double-float (hi lo) (make-double-float hi lo))
182 (defun single-float-bits (x) (single-float-bits x))
183 (defun double-float-high-bits (x) (double-float-high-bits x))
184 (defun double-float-low-bits (x) (double-float-low-bits x))