source: branches/portable/woodequ.lisp@ 31

Last change on this file since 31 was 14, checked in by wws, 10 years ago

Eliminate warnings in persistent-clos.lisp.

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