@@ -3130,6 +3130,7 @@ Legal values for OFFSET are -4, -8, -12, ..."
3130
3130
(write-string " ," out))
3131
3131
(terpri out)))
3132
3132
(write-line " };" out)))
3133
+ (format out " #include <stddef.h>~% " ) ; for NULL
3133
3134
(write-tags " static " " -LOWTAG" sb-vm :lowtag-limit 0 )
3134
3135
; ; this -2 shift depends on every OTHER-IMMEDIATE-?-LOWTAG
3135
3136
; ; ending with the same 2 bits. (#b10)
@@ -3170,40 +3171,46 @@ Legal values for OFFSET are -4, -8, -12, ..."
3170
3171
(slots (sb-vm :primitive-object-slots obj))
3171
3172
(lowtag (or (symbol-value (sb-vm :primitive-object-lowtag obj)) 0 )))
3172
3173
; ; writing primitive object layouts
3173
- (format t " #ifndef __ASSEMBLER__~ 2 % " )
3174
- (when (eq name ' sb-vm::thread)
3175
- (format t " #define THREAD_HEADER_SLOTS ~d~% " sb-vm ::thread-header-slots)
3176
- (dolist (x sb-vm ::*thread-header-slot-names* )
3177
- (let ((s (package-symbolicate " SB-VM" " THREAD-" x " -SLOT" )))
3178
- (format t " #define ~a ~d~% "
3179
- (c-name (string s)) (symbol-value s))))
3180
- (terpri ))
3181
- (format t " struct ~A {~% " c-name)
3182
- (when (sb-vm :primitive-object-widetag obj)
3183
- (format t " lispobj header;~% " ))
3184
- (dolist (slot slots)
3185
- (format t " ~A ~A ~@[ [1]~] ;~% "
3186
- (getf (sb-vm :slot-options slot) :c-type " lispobj" )
3187
- (c-name (string-downcase (sb-vm :slot-name slot)))
3188
- (sb-vm :slot-rest-p slot)))
3189
- (format t " };~% " )
3190
- (when (member name ' (cons vector symbol fdefn))
3191
- (write-cast-operator name c-name lowtag))
3192
- (format t " ~% #else /* __ASSEMBLER__ */~ 2 % " )
3193
- (format t " /* These offsets are SLOT-OFFSET * N-WORD-BYTES - LOWTAG~% " )
3194
- (format t " * so they work directly on tagged addresses. */~ 2 % " )
3195
- (dolist (slot slots)
3196
- (format t " #define ~A _~A _OFFSET ~D~% "
3197
- (c-symbol-name name)
3198
- (c-symbol-name (sb-vm :slot-name slot))
3199
- (- (* (sb-vm :slot-offset slot) sb-vm :n-word-bytes) lowtag)))
3200
- (format t " #define ~A _SIZE ~d~% "
3201
- (string-upcase c-name) (sb-vm :primitive-object-length obj)))
3202
- (format t " ~% #endif /* __ASSEMBLER__ */~ 2 % " ))
3174
+ (flet ((output-c ()
3175
+ (when (eq name ' sb-vm::thread)
3176
+ (format t " #define THREAD_HEADER_SLOTS ~d~% " sb-vm ::thread-header-slots)
3177
+ (dolist (x sb-vm ::*thread-header-slot-names* )
3178
+ (let ((s (package-symbolicate " SB-VM" " THREAD-" x " -SLOT" )))
3179
+ (format t " #define ~a ~d~% "
3180
+ (c-name (string s)) (symbol-value s))))
3181
+ (terpri ))
3182
+ (format t " struct ~A {~% " c-name)
3183
+ (when (sb-vm :primitive-object-widetag obj)
3184
+ (format t " lispobj header;~% " ))
3185
+ (dolist (slot slots)
3186
+ (format t " ~A ~A ~@[ [1]~] ;~% "
3187
+ (getf (sb-vm :slot-options slot) :c-type " lispobj" )
3188
+ (c-name (string-downcase (sb-vm :slot-name slot)))
3189
+ (sb-vm :slot-rest-p slot)))
3190
+ (format t " };~% " )
3191
+ (when (member name ' (cons vector symbol fdefn))
3192
+ (write-cast-operator name c-name lowtag)))
3193
+ (output-asm ()
3194
+ (format t " /* These offsets are SLOT-OFFSET * N-WORD-BYTES - LOWTAG~% " )
3195
+ (format t " * so they work directly on tagged addresses. */~ 2 % " )
3196
+ (dolist (slot slots)
3197
+ (format t " #define ~A _~A _OFFSET ~D~% "
3198
+ (c-symbol-name name)
3199
+ (c-symbol-name (sb-vm :slot-name slot))
3200
+ (- (* (sb-vm :slot-offset slot) sb-vm :n-word-bytes) lowtag)))
3201
+ (format t " #define ~A _SIZE ~d~% "
3202
+ (string-upcase c-name) (sb-vm :primitive-object-length obj))))
3203
+ (format t " #ifdef __ASSEMBLER__~ 2 % " )
3204
+ (output-asm)
3205
+ (format t " ~% #else /* __ASSEMBLER__ */~ 2 % " )
3206
+ (format t " #include \" lispobj.h\" ~% " )
3207
+ (output-c)
3208
+ (format t " ~% #endif /* __ASSEMBLER__ */~% " ))))
3203
3209
3204
3210
(defun write-structure-object (dd *standard-output* &optional structname)
3205
3211
(flet ((cstring (designator) (c-name (string-downcase designator))))
3206
3212
(format t " #ifndef __ASSEMBLER__~ 2 % " )
3213
+ (format t " #include \" lispobj.h\" ~% " )
3207
3214
(format t " struct ~A {~% " (or structname (cstring (dd-name dd))))
3208
3215
(format t " lispobj header; // = word_0_~% " )
3209
3216
; ; "self layout" slots are named '_layout' instead of 'layout' so that
@@ -3846,19 +3853,40 @@ III. initially undefined function references (alphabetically):
3846
3853
(ensure-directories-exist filename)
3847
3854
(with-open-file (stream filename :direction :output :if-exists :supersede )
3848
3855
(write-makefile-features stream )))
3849
-
3850
- (macrolet ((out-to (name &body body) ; write boilerplate and inclusion guard
3851
- (let ((headerp (if (and (stringp name) (position #\. name)) nil " .h" )))
3852
- ` (with-open-file (stream (format nil " ~A /~A ~@[ ~A ~] "
3853
- c-header-dir-name , name , headerp)
3854
- :direction :output :if-exists :supersede )
3855
- (write-boilerplate stream )
3856
- , (when headerp
3857
- ` (format stream
3858
- " #ifndef SBCL_GENESIS_~A~% #define SBCL_GENESIS_~:*~A~% "
3859
- (c-name (string-upcase , name))))
3860
- ,@ body
3861
- , (when headerp ` (format stream " #endif~% " ))))))
3856
+ (write-c-headers c-header-dir-name))))
3857
+
3858
+ (defun write-c-headers (c-header-dir-name)
3859
+ (macrolet ((out-to (name &body body) ; write boilerplate and inclusion guard
3860
+ ` (actually-out-to , name (lambda (stream ) ,@ body))))
3861
+ (flet ((actually-out-to (name lambda )
3862
+ ; ; A file gets a '.inc' extension, not '.h' for either or both
3863
+ ; ; of two reasons:
3864
+ ; ; - if it isn't self-contained, meaning that in order to #include it,
3865
+ ; ; the consumer of it has to know something about which other headers
3866
+ ; ; need to be #included first.
3867
+ ; ; - it is not intended to be directly consumed because any use would
3868
+ ; ; typically need to wrap each slot in some small calculation
3869
+ ; ; such as native_pointer(), but we don't want to embed the wrapper
3870
+ ; ; accessors into the autogenerated header. So there would instead be
3871
+ ; ; a "src/runtime/foo.h" which includes "src/runtime/genesis/foo.inc"
3872
+ ; ; 'thread.h' and 'gc-tables.h' violate the naming convention
3873
+ ; ; by being non-self-contained.
3874
+ (let* ((extension
3875
+ (cond ((and (stringp name) (position #\. name)) nil )
3876
+ (t " .h" )))
3877
+ (inclusion-guardp
3878
+ (string= extension " .h" )))
3879
+ (with-open-file (stream (format nil " ~A /~A ~@[ ~A ~] "
3880
+ c-header-dir-name name extension)
3881
+ :direction :output :if-exists :supersede )
3882
+ (write-boilerplate stream )
3883
+ (when inclusion-guardp
3884
+ (format stream
3885
+ " #ifndef SBCL_GENESIS_~A~% #define SBCL_GENESIS_~:*~A~% "
3886
+ (c-name (string-upcase name))))
3887
+ (funcall lambda stream )
3888
+ (when inclusion-guardp
3889
+ (format stream " #endif~% " ))))))
3862
3890
(out-to " config" (write-config-h stream ))
3863
3891
(out-to " constants" (write-constants-h stream ))
3864
3892
(out-to " regnames" (write-regnames-h stream ))
@@ -3888,7 +3916,7 @@ III. initially undefined function references (alphabetically):
3888
3916
(write-boilerplate stream ) ; no inclusion guard, it's not a ".h" file
3889
3917
(write-thread-init stream ))
3890
3918
(out-to " static-symbols" (write-static-symbols stream ))
3891
- (out-to " sc-offset" (write-sc+offset-coding stream ))))))
3919
+ (out-to " sc-offset" (write-sc+offset-coding stream )))))
3892
3920
3893
3921
; ;; Invert the action of HOST-CONSTANT-TO-CORE. If STRICTP is given as NIL,
3894
3922
; ;; then we can produce a host object even if it is not a faithful rendition.
0 commit comments