source: branches/lispworks/woodequ.lisp@ 38

Last change on this file since 38 was 36, checked in by Gail Zacharias, 9 years ago

Update to current eRef version

  • Property svn:eol-style set to native
File size: 16.1 KB
Line 
1;;;-*- Mode: Lisp; Package: WOOD -*-
2
3;;;;;;;;;;;;;;;;;;;;;;;;;;
4;;
5;; woodequ.lisp
6;; Data representation constants
7;; Largely copied from "ccl:library;lispequ.lisp"
8;;
9;; Portions Copyright © 2006 Clozure Associates
10;; Copyright © 1996 Digitool, Inc.
11;; Copyright © 1992-1995 Apple Computer, Inc.
12;; All rights reserved.
13;; Permission is given to use, copy, and modify this software provided
14;; that Digitool is given credit in all derivative works.
15;; This software is provided "as is". Digitool makes no warranty or
16;; representation, either express or implied, with respect to this software,
17;; its quality, accuracy, merchantability, or fitness for a particular
18;; purpose.
19;;
20
21;;;;;;;;;;;;;;;;;;;;;;;;;;
22;;
23;; Modification History
24;;
25;; 02/01/06 gz LispWorks port
26;; -------------- 0.96
27;; -------------- 0.95
28;; 05/09/96 bill use addr+ in dc-%arrayh-xxx
29;; -------------- 0.94 = MCL-PPC 3.9
30;; 03/21/96 bill add $v_xstr
31;; -------------- 0.93
32;; -------------- 0.9
33;; 01/18/95 bill $btree.max-key-size
34;; -------------- 0.8
35;; 03/27/93 bill $forwarding-pointer-header
36;; -------------- 0.6
37;; 08/27/92 bill $v_load-function
38;; 08/24/92 bill $btree-type_string-equal-bit, $btree-type_string-equal
39;; (these are not yet supported by the btree code)
40;; -------------- 0.5
41;; 06/23/92 bill persistent-clos equates, btree type bits
42;; -------------- 0.1
43;;
44
45
46(in-package :wood)
47
48; low 3 bits of an address are the tag.
49
50(defmacro pointer-tag (pointer)
51 `(the fixnum (logand ,pointer 7)))
52
53(defmacro pointer-tagp (pointer tag)
54 `(eql (pointer-tag ,pointer) ,tag))
55
56(defmacro pointer-address (pointer)
57 `(logand ,pointer -8))
58
59#+ccl (progn
60(defconstant $t_fixnum 0)
61(defconstant $t_vector 1)
62(defconstant $t_symbol 2)
63(defconstant $t_dfloat 3)
64(defconstant $t_cons 4)
65(defconstant $t_sfloat 5)
66(defconstant $t_lfun 6)
67(defconstant $t_imm 7)
68
69(defconstant $dfloat_size 8)
70
71(defmacro tag-vector (&key fixnum vector symbol dfloat cons sfloat lfun imm)
72 (vector fixnum vector symbol dfloat cons sfloat lfun imm))
73
74) ;#+ccl
75
76#+LispWorks (progn
77(defconstant $t_pos_fixnum 0)
78(defconstant $t_vector 1)
79(defconstant $t_symbol 2)
80(defconstant $t_dfloat 3)
81(defconstant $t_cons 4)
82(defconstant $t_neg_fixnum 5)
83(defconstant $t_char 6)
84(defconstant $t_imm 7)
85
86(defconstant $undefined-imm 0)
87
88(defmacro tag-vector (&key pos-fixnum vector symbol dfloat cons neg-fixnum char imm)
89 (vector pos-fixnum vector symbol dfloat cons neg-fixnum char imm))
90
91) ;#+LispWorks
92
93
94; Non-cons cells have a header long-word for the garbage collector.
95(defconstant $vector-header #x1ff)
96(defconstant $symbol-header #x8ff)
97; Need to find a value that can't be the first word of a float
98(defconstant $forwarding-pointer-header #xfff)
99
100; Vectors are a longword of block header, 1 byte of subtype, 3 bytes of length (in bytes)
101; then the contents.
102;
103; -------------------
104; | 00 | 00 | 01 | FF |
105; |-------------------|
106; | ST | Length |
107; |-------------------|
108; | Contents |
109; | . |
110; | . |
111; | . |
112; -------------------
113
114; Array subtypes. Multiply by two to get the MCL subtype
115;(defconstant $v_packed_sstr 0) ; used in image loader/dumper
116(defconstant $v_bignum 1)
117(defconstant $v_macptr 2)
118(defconstant $v_badptr 3)
119(defconstant $v_nlfunv 4) ; Lisp FUNction vector
120;subtype 5 unused
121(defconstant $v_min_arr 6)
122(defconstant $v_xstr 6) ;16-bit character vector
123(defconstant $v_ubytev 7) ;unsigned byte vector
124(defconstant $v_uwordv 8) ;unsigned word vector
125(defconstant $v_floatv 9) ;float vector
126(defconstant $v_slongv 10) ;Signed long vector
127(defconstant $v_ulongv 11) ;Unsigned long vector
128(defconstant $v_bitv 12) ;Bit vector
129(defconstant $v_sbytev 13) ;Signed byte vector
130(defconstant $v_swordv 14) ;Signed word vector
131(defconstant $v_sstr 15) ;simple string
132(defconstant $v_genv 16) ;simple general vector
133(defconstant $v_arrayh 17) ;complex array header
134(defconstant $v_struct 18) ;structure
135(defconstant $v_mark 19) ;buffer mark
136(defconstant $v_pkg 20)
137;subtype 21 unused
138(defconstant $v_istruct 22)
139(defconstant $v_ratio 23)
140(defconstant $v_complex 24)
141(defconstant $v_instance 25) ;clos instance
142; subtypes 26, 27, 28 unused in ccl
143#+LispWorks (defconstant $v_garrayh 26)
144#+LispWorks (defconstant $v_iarrayh 27)
145(defconstant $v_weakh 29)
146(defconstant $v_poolfreelist 30)
147(defconstant $v_nhash 31)
148
149; Types that exist only in the database
150(defconstant $v_area 32) ; area descriptor
151(defconstant $v_segment 33) ; area segment
152(defconstant $v_random-bits 34) ; used for vectors of random bits, e.g. resources
153(defconstant $v_dbheader 35) ; database header
154(defconstant $v_segment-headers 36) ; Segment headers page.
155(defconstant $v_btree 37) ; a BTREE
156(defconstant $v_btree-node 38) ; one node of a BTREE's tree.
157(defconstant $v_class 39) ; class
158(defconstant $v_load-function 40) ; result of P-MAKE-LOAD-FUNCTION-OBJECT
159(defconstant $v_pload-barrier 41) ; result of P-MAKE-PLOAD-BARRIER
160
161(defconstant $v_link (- $t_vector))
162(defconstant $V_SUBTYPE 3)
163(defconstant $V_DATA 7)
164(defconstant $V_LOG 3)
165(defconstant $vector-header-size 8)
166
167(defconstant $vnodebit 5) ; set for arrays containing pointers
168(defconstant $vnode (ash 1 $vnodebit))
169
170; NIL is tagged as a cons with and address of 0
171(defconstant $pheap-nil $t_cons)
172
173(defmacro vtype-vector (&key unused
174 (bignum unused) (badptr unused) (nlfunv unused)
175 (xstr unused) (ubytev unused) (uwordv unused)
176 (floatv unused) (slongv unused) (ulongv unused)
177 (bitv unused) (sbytev unused) (swordv unused)
178 (sstr unused) (genv unused) (arrayh unused)
179 (struct unused) (pkg unused) (istruct unused)
180 (ratio unused) (complex unused) (instance unused)
181 (weakh unused) (poolfreelist unused) (nhash unused)
182 ;; Simple-arrays other than special vectors above
183 (garrayh unused) (iarrayh unused)
184 ;; internal subtypes
185 area segment random-bits dbheader segment-headers
186 btree btree-node class load-function pload-barrier)
187 (vector unused ; 0 - unused
188 bignum ; 1 - $v_bignum
189 unused ; 2 - $v_macptr - not supported
190 badptr ; 3 - $v_badptr
191 nlfunv ; 4 - $v_nlfunv
192 unused ; 5 - unused
193 xstr ; 6 - $v_xstr - extended string
194 ubytev ; 7 - $v_ubytev - unsigned byte vector
195 uwordv ; 8 - $v_uwordv - unsigned word vector
196 floatv ; 9 - $v_floatv - float vector
197 slongv ; 10 - $v_slongv - Signed long vector
198 ulongv ; 11 - $v_ulongv - Unsigned long vector
199 bitv ; 12 - $v_bitv - Bit vector (handled specially)
200 sbytev ; 13 - $v_sbytev - Signed byte vector
201 swordv ; 14 - $v_swordv - Signed word vector
202 sstr ; 15 - $v_sstr - simple string
203 genv ; 16 - $v_genv - simple general vector
204 arrayh ; 17 - $v_arrayh - complex array header
205 struct ; 18 - $v_struct - structure
206 unused ; 19 - $v_mark - buffer mark unimplemented
207 pkg ; 20 - $v_pkg
208 unused ; 21 - unused
209 istruct ; 22 - $v_istruct - type in first element
210 ratio ; 23 - $v_ratio
211 complex ; 24 - $v_complex
212 instance ; 25 - $v_instance - clos instance
213 garrayh ; 26 - $v_garrayh - simple general array header
214 iarrayh ; 27 - $v_iarrayh - simple immediate array header
215 unused ; 28 - unused
216 weakh ; 29 - $v_weakh - weak list header
217 poolfreelist ; 30 - $v_poolfreelist - free pool header
218 nhash ; 31 - $v_nhash
219 ; WOOD specific subtypes
220 area ; 32 - $v_area - area descriptor
221 segment ; 33 - $v_segment - area segment
222 random-bits ; 34 - $v_random-bits - vectors of random bits, e.g. resources
223 dbheader ; 35 - $v_dbheader - database header
224 segment-headers ; 36 - $v_segment-headers - specially allocated
225 btree ; 37 - $v_btree
226 btree-node ; 38 - $v_btree-node - specially allocated
227 class ; 39 - $v_class
228 load-function ; 40 - $v_load-function
229 pload-barrier ;41 - $v_pload-barrier
230 ))
231
232(defmacro def-indices (&body indices)
233 (let ((index 0)
234 res)
235 (dolist (spec indices)
236 (labels ((f (spec)
237 (etypecase spec
238 (symbol (push `(defconstant ,spec ,index) res))
239 (list (dolist (sub-spec spec)
240 (f sub-spec))))))
241 (declare (dynamic-extent #'f))
242 (f spec)
243 (incf index)))
244 `(progn ,@(nreverse res))))
245
246; Symbols are not regular vectors.
247(defconstant $sym_header -2) ; $symbol-header
248(defconstant $sym_pname 2)
249(defconstant $sym_package 6)
250(defconstant $sym_values 10) ; place for (value function . plist)
251(defconstant $symbol-size 16)
252
253; Packages do not support inheritance.
254; maybe they should.
255(def-indices
256 $pkg.names
257 $pkg.btree
258 $pkg-length)
259
260; Weak lists. Subtype $v_weakh
261(def-indices
262 $population.gclink
263 $population.type
264 $population.data
265 $population-size)
266
267;;;;;;;;;;;;;;;;;;;;;;;;;;
268;;
269;; A PHEAP file starts with a single vector containing
270;; the root objects and the file-wide information.
271;;
272(defconstant $block-overhead 8) ; commit-lsn + segment-ptr
273(defconstant $block-commit-lsn 0)
274(defconstant $block-segment-ptr 4)
275
276(defconstant $root-vector (+ $block-overhead $t_vector))
277
278(def-indices
279 $pheap.version ; version number
280 $pheap.free-page ; free pointer in pages
281 $pheap.root ; root object
282 $pheap.default-consing-area ; a pointer to an area descriptor
283 $pheap.class-hash ; class hash table
284 $pheap.page-size ; size of a page in bytes
285 $pheap.btree-free-list ; head of linked list of btree nodes
286 $pheap.package-btree ; string->package table
287 $pheap.page-write-count ; pages written since open
288 $pheap-free9
289 $pheap-free10
290 $pheap-free11
291 $pheap-free12
292 $pheap-free13
293 $pheap-free14
294 $pheap-free15
295 $pheap-header-size
296 )
297
298; A segment headers page header. Subtype is $v_segment-headers
299; The header in the first page of headers for an area
300; contains the $area.xxx information as well.
301(def-indices
302 $segment-headers.area ; my area
303 $segment-headers.link ; next segment headers page
304 $area.flags ; fixnum
305 $area.segment-size ; default size for segments
306 $area.last-headers ; last segment headers page
307 $area.free-count ; number of headers left in $area.last-headers
308 $area.free-ptr ; cons pointing at current header
309 $area-descriptor-size
310 )
311
312(defconstant $segment-headers-size $area.flags)
313
314; A segment header page entry
315; Pointers to these are typed as conses
316(defconstant $segment-header_free -4) ; pointer to free space. Tagged as a cons
317(defconstant $segment-header_freebytes 0) ; number of bytes left
318(defconstant $segment-header_free-link 4) ; header entry with free space
319(defconstant $segment-header_segment 8) ; beginning of the segment
320(defconstant $segment-header-entry-bytes (* 4 4)) ; must be a multiple of 8
321
322; The header of a segment. Subtype is $v_segment
323; This vector contains all other types of objects
324(def-indices
325 $segment.area ; my area
326 $segment.header ; my header entry
327 $segment-header-size
328 )
329
330; Complex array headers
331; Copied from lispequ.
332(def-indices
333 $arh.fixnum
334 $arh.offs
335 $arh.vect
336 #+LispWorks $arh.etype
337 ($arh.vlen $arh.dims)
338 $arh.fill)
339
340;byte offsets in arh.fixnum slot.
341(defconstant $arh_rank4 0) ;4*rank
342(defconstant $arh_type 2) ;vector subtype
343(defconstant $arh_bits 3) ;Flags
344
345(defconstant $arh_one_dim 4) ;arh.rank4 value of one-dim arrays
346
347;Bits in $arh_bits.
348(defconstant $arh_adjp_bit 7) ;adjustable-p
349(defconstant $arh_fill_bit 6) ;fill-pointer-p
350(defconstant $arh_disp_bit 5) ;displaced to another array header -p
351(defconstant $arh_simple_bit 4) ;not adjustable, no fill-pointer and
352 ; not user-visibly displaced -p
353
354(defmacro dc-%arrayh-bits (disk-cache pointer)
355 (setq disk-cache (require-type disk-cache 'symbol))
356 `(the fixnum
357 (read-8-bits ,disk-cache
358 (addr+ ,disk-cache
359 ,pointer
360 (+ $v_data (* 4 $arh.fixnum) $arh_bits)))))
361
362(defmacro dc-%arrayh-type (disk-cache pointer)
363 (setq disk-cache (require-type disk-cache 'symbol))
364 `(the fixnum
365 (read-8-bits ,disk-cache
366 (addr+ ,disk-cache
367 ,pointer
368 (+ $v_data (* 4 $arh.fixnum) $arh_type)))))
369
370(defmacro dc-%arrayh-rank4 (disk-cache pointer)
371 (setq disk-cache (require-type disk-cache 'symbol))
372 `(the fixnum
373 (read-unsigned-word
374 ,disk-cache
375 (addr+ ,disk-cache
376 ,pointer
377 (+ $v_data (* 4 $arh.fixnum) $arh_rank4)))))
378
379(defmacro arh.fixnum_type-bytespec ()
380 (byte 8 5))
381
382(defmacro arh.fixnum_type (fixnum)
383 `(ldb (arh.fixnum_type-bytespec) ,fixnum))
384
385;;;;;;;;;;;;;;;;;;;;;;;;;;
386;;;
387;;; btree vector - subtype $v_btree
388;;;
389(def-indices
390 $btree.root ; the root node
391 $btree.count ; number of leaf entries
392 $btree.depth ; 0 means only the root exists
393 $btree.nodes ; total number of nodes
394 $btree.first-leaf ; first leaf node. A constant
395 $btree.type ; type bits
396 $btree.max-key-size ; maximum size of a key
397 $btree-size ; length of a $v_btree vector
398 )
399
400;; Btree type bits
401(defconstant $btree-type_eqhash-bit 0) ; EQ hash table
402(defconstant $btree-type_weak-bit 1) ; weak hash table
403(defconstant $btree-type_weak-value-bit 2) ; weak on value, not key
404(defconstant $btree-type_string-equal-bit 3) ; use string-equal, not string=
405
406; Btree type values
407(defconstant $btree-type_normal 0) ; normal string->value btree
408(defconstant $btree-type_string-equal (ash 1 $btree-type_string-equal-bit))
409(defconstant $btree-type_eqhash (ash 1 $btree-type_eqhash-bit))
410(defconstant $btree-type_eqhash-weak-key
411 (+ $btree-type_eqhash (ash 1 $btree-type_weak-bit)))
412(defconstant $btree-type_eqhash-weak-value
413 (+ $btree-type_eqhash-weak-key (ash 1 $btree-type_weak-value-bit)))
414
415;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
416;;;
417;;; Persistent CLOS equates
418;;;
419
420; subtype $v_instance
421(def-indices
422 $instance.wrapper ; class wrapper
423 $instance.slots ; slots vector
424 $instance-size)
425
426; A wrapper is a regular general vector
427(def-indices
428 $wrapper.class
429 $wrapper.slots ; vector of slot names
430 $wrapper-size)
431
432; subtype $v_class
433(def-indices
434 $class.name
435 $class.own-wrapper
436 $class-size)
437
438;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
439;;;
440;;; $v_load-function subtype
441;;;
442(def-indices
443 $load-function.load-list ; load-function.args
444 $load-function.init-list ; init-function.args
445 $load-function-size)
446
447;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
448;;;
449;;; $v_pload-barrier subtype
450;;;
451
452(def-indices
453 $pload-barrier.object
454 $pload-barrier-size)
455
456
457(provide :woodequ)
458;;; 1 3/10/94 bill 1.8d247
459;;; 2 7/26/94 Derek 1.9d027
460;;; 2 2/18/95 RŽti 1.10d019
461;;; 3 3/23/95 bill 1.11d010
Note: See TracBrowser for help on using the repository browser.