1 ;;;; some macros and constants that are object-format-specific or are
2 ;;;; used for defining the object format
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
15 ;;;; other miscellaneous stuff
17 ;;; This returns a form that returns a dual-word aligned number of bytes when
18 ;;; given a number of words.
20 ;;; FIXME: should be a function
21 ;;; FIXME: should be called PAD-DATA-BLOCK-SIZE
22 (defmacro pad-data-block (words)
23 `(logandc2 (+ (ash ,words word-shift) lowtag-mask) lowtag-mask))
25 ;;;; primitive object definition stuff
27 (defun remove-keywords (options keywords)
28 (cond ((null options) nil)
29 ((member (car options) keywords)
30 (remove-keywords (cddr options) keywords))
32 (list* (car options) (cadr options)
33 (remove-keywords (cddr options) keywords)))))
35 (def!struct (prim-object-slot
36 (:constructor make-slot (name docs rest-p offset length options))
37 (:make-load-form-fun just-dump-it-normally)
39 (name nil :type symbol)
40 (docs nil :type (or null simple-string))
41 (rest-p nil :type (member t nil))
42 (offset 0 :type fixnum)
43 (length 1 :type fixnum)
44 (options nil :type list))
46 (def!struct (primitive-object (:make-load-form-fun just-dump-it-normally))
47 (name nil :type symbol)
48 (header nil :type symbol)
49 (lowtag nil :type symbol)
50 (options nil :type list)
51 (slots nil :type list)
53 (variable-length nil :type (member t nil)))
55 (defvar *primitive-objects* nil)
57 (defun %define-primitive-object (primobj)
58 (let ((name (primitive-object-name primobj)))
59 (setf *primitive-objects*
61 (remove name *primitive-objects*
62 :key #'primitive-object-name :test #'eq)))
65 (defmacro define-primitive-object
66 ((name &key header lowtag alloc-trans (type t))
68 (collect ((slots) (exports) (constants) (forms) (inits))
69 (let ((offset (if header 1 0))
70 (variable-length nil))
71 (dolist (spec slot-specs)
73 (error "No more slots can follow a :rest-p slot."))
75 (slot-name &rest options
76 &key docs rest-p (length (if rest-p 0 1))
77 ((:type slot-type) t) init
78 (ref-known nil ref-known-p) ref-trans
79 (set-known nil set-known-p) set-trans
81 (if (atom spec) (list spec) spec)
82 (slots (make-slot slot-name docs rest-p offset length
83 (remove-keywords options
84 '(:docs :rest-p :length))))
85 (let ((offset-sym (symbolicate name "-" slot-name
86 (if rest-p "-OFFSET" "-SLOT"))))
87 (constants `(defconstant ,offset-sym ,offset
88 ,@(when docs (list docs))))
92 (forms `(defknown ,ref-trans (,type) ,slot-type ,ref-known)))
93 (forms `(def-reffer ,ref-trans ,offset ,lowtag)))
96 (forms `(defknown ,set-trans
97 ,(if (listp set-trans)
99 (list type slot-type))
102 (forms `(def-setter ,set-trans ,offset ,lowtag)))
104 (inits (cons init offset)))
106 (setf variable-length t))
107 (incf offset length)))
108 (unless variable-length
109 (let ((size (symbolicate name "-SIZE")))
110 (constants `(defconstant ,size ,offset
112 "Number of slots used by each ~S~
113 ~@[~* including the header~]."
117 (forms `(def-alloc ,alloc-trans ,offset ,variable-length ,header
120 (eval-when (:compile-toplevel :load-toplevel :execute)
121 (%define-primitive-object
122 ',(make-primitive-object :name name
127 :variable-length variable-length))
131 ;;;; stuff for defining reffers and setters
135 (defun %def-reffer (name offset lowtag)
136 (let ((info (function-info-or-lose name)))
137 (setf (function-info-ir2-convert info)
138 #'(lambda (node block)
139 (ir2-convert-reffer node block name offset lowtag))))
142 (defmacro def-reffer (name offset lowtag)
143 `(%def-reffer ',name ,offset ,lowtag))
145 (defun %def-setter (name offset lowtag)
146 (let ((info (function-info-or-lose name)))
147 (setf (function-info-ir2-convert info)
149 #'(lambda (node block)
150 (ir2-convert-setfer node block name offset lowtag))
151 #'(lambda (node block)
152 (ir2-convert-setter node block name offset lowtag)))))
155 (defmacro def-setter (name offset lowtag)
156 `(%def-setter ',name ,offset ,lowtag))
158 (defun %def-alloc (name words variable-length header lowtag inits)
159 (let ((info (function-info-or-lose name)))
160 (setf (function-info-ir2-convert info)
162 #'(lambda (node block)
163 (ir2-convert-variable-allocation node block name words header
165 #'(lambda (node block)
166 (ir2-convert-fixed-allocation node block name words header
170 (defmacro def-alloc (name words variable-length header lowtag inits)
171 `(%def-alloc ',name ,words ,variable-length ,header ,lowtag ,inits))
173 ;;;; some general constant definitions
175 ;;; FIXME: SC-NUMBER-LIMIT should probably be exported from SB!C
176 ;;; or SB!VM so that we don't need to do this extra IN-PACKAGE.
179 ;;; the maximum number of SCs in any implementation
180 (defconstant sc-number-limit 32)