42fe9431ee98719b863780e7bf84ec07a3f6bf08
[sbcl.git] / src / code / kernel.lisp
1 ;;;; miscellaneous kernel-level definitions
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!KERNEL")
13
14 (defun get-header-data (x)
15   #!+sb-doc
16   "Return the 24 bits of data in the header of object X, which must be an
17   other-pointer object."
18   (get-header-data x))
19
20 (defun set-header-data (x val)
21   #!+sb-doc
22   "Sets the 24 bits of data in the header of object X (which must be an
23   other-pointer object) to VAL."
24   (set-header-data x val))
25
26 (defun get-closure-length (x)
27   #!+sb-doc
28   "Returns the length of the closure X. This is one more than the number
29   of variables closed over."
30   (get-closure-length x))
31
32 (defun get-lowtag (x)
33   #!+sb-doc
34   "Returns the three-bit lowtag for the object X."
35   (get-lowtag x))
36
37 (defun get-type (x)
38   #!+sb-doc
39   "Returns the 8-bit header type for the object X."
40   (get-type x))
41
42 (defun vector-sap (x)
43   #!+sb-doc
44   "Return a System-Area-Pointer pointing to the data for the vector X, which
45   must be simple."
46   (declare (type (simple-unboxed-array (*)) x))
47   (vector-sap x))
48
49 (defun sb!c::binding-stack-pointer-sap ()
50   #!+sb-doc
51   "Return a System-Area-Pointer pointing to the end of the binding stack."
52   (sb!c::binding-stack-pointer-sap))
53
54 (defun sb!c::dynamic-space-free-pointer ()
55   #!+sb-doc
56   "Returns a System-Area-Pointer pointing to the next free work of the current
57   dynamic space."
58   (sb!c::dynamic-space-free-pointer))
59
60 (defun sb!c::control-stack-pointer-sap ()
61   #!+sb-doc
62   "Return a System-Area-Pointer pointing to the end of the control stack."
63   (sb!c::control-stack-pointer-sap))
64
65 (defun function-subtype (function)
66   #!+sb-doc
67   "Return the header typecode for FUNCTION. Can be set with SETF."
68   (function-subtype function))
69
70 (defun (setf function-subtype) (type function)
71   (setf (function-subtype function) type))
72
73 (defun %function-arglist (func)
74   #!+sb-doc
75   "Extracts the arglist from the function header FUNC."
76   (%function-arglist func))
77
78 (defun %function-name (func)
79   #!+sb-doc
80   "Extracts the name from the function header FUNC."
81   (%function-name func))
82
83 (defun %function-type (func)
84   #!+sb-doc
85   "Extracts the type from the function header FUNC."
86   (%function-type func))
87
88 (defun %closure-function (closure)
89   #!+sb-doc
90   "Extracts the function from CLOSURE."
91   (%closure-function closure))
92
93 (defun sb!c::vector-length (vector)
94   #!+sb-doc
95   "Return the length of VECTOR. There is no reason to use this, 'cause
96   (length (the vector foo)) is the same."
97   (sb!c::vector-length vector))
98
99 (defun %closure-index-ref (closure index)
100   #!+sb-doc
101   "Extract the INDEXth slot from CLOSURE."
102   (%closure-index-ref closure index))
103
104 (defun allocate-vector (type length words)
105   #!+sb-doc
106   "Allocate a unboxed, simple vector with type code TYPE, length LENGTH, and
107   WORDS words long. Note: it is your responsibility to ensure that the
108   relation between LENGTH and WORDS is correct."
109   (allocate-vector type length words))
110
111 (defun make-array-header (type rank)
112   #!+sb-doc
113   "Allocate an array header with type code TYPE and rank RANK."
114   (make-array-header type rank))
115
116 (defun code-instructions (code-obj)
117   #!+sb-doc
118   "Return a SAP pointing to the instructions part of CODE-OBJ."
119   (code-instructions code-obj))
120
121 (defun code-header-ref (code-obj index)
122   #!+sb-doc
123   "Extract the INDEXth element from the header of CODE-OBJ. Can be set with
124   setf."
125   (code-header-ref code-obj index))
126
127 (defun code-header-set (code-obj index new)
128   (code-header-set code-obj index new))
129
130 (defun %raw-bits (object offset)
131   (declare (type index offset))
132   (sb!kernel:%raw-bits object offset))
133
134 (defun %set-raw-bits (object offset value)
135   (declare (type index offset) (type (unsigned-byte #.sb!vm:word-bits) value))
136   (setf (sb!kernel:%raw-bits object offset) value))
137
138 (defun make-single-float (x) (make-single-float x))
139 (defun make-double-float (hi lo) (make-double-float hi lo))
140 #!+long-float
141 (defun make-long-float (exp hi #!+sparc mid lo)
142   (make-long-float exp hi #!+sparc mid lo))
143 (defun single-float-bits (x) (single-float-bits x))
144 (defun double-float-high-bits (x) (double-float-high-bits x))
145 (defun double-float-low-bits (x) (double-float-low-bits x))
146 #!+long-float
147 (defun long-float-exp-bits (x) (long-float-exp-bits x))
148 #!+long-float
149 (defun long-float-high-bits (x) (long-float-high-bits x))
150 #!+(and long-float sparc)
151 (defun long-float-mid-bits (x) (long-float-mid-bits x))
152 #!+long-float
153 (defun long-float-low-bits (x) (long-float-low-bits x))