Debian Codegraph @

texk/web2c/alephdir/eo16bit.ch

raw
1 % This is an \Aleph change file; it brings \eTeX register numbers
2 % from 32767 ($2^{15}-1$) to 65535 ($2^{16}-1), to bring it on line
3 % with \Omega
4 % Noticeably, since Omega has 16-bit quarterwords, it is possible
5 % to do so without changing much.
6 % Notice that we do this for marks register: everything else is
7 % brought to level with Omega in eomem.ch
8 %----------------------------------------
9 @x Section 53a onwards l.4600
10 @ @<Initialize variables for \eTeX\ ext...@>=
11 max_reg_num:=32767;
12 max_reg_help_line:="A register number must be between 0 and 32767.";
13 @y
14 @ @<Initialize variables for \eTeX\ ext...@>=
15 max_reg_num:=65535;
16 max_reg_help_line:="A register number must be between 0 and 65535.";
17 @z
18 %----------------------------------------
19 @x l.4607
20 @ There are seven almost identical doubly linked trees, one for the
21 sparse array of the up to 32512 additional registers of each kind and
22 one for the sparse array of the up to 32767 additional mark classes.
23 The root of each such tree, if it exists, is an index node containing 16
24 pointers to subtrees for 4096 consecutive array elements. Similar index
25 nodes are the starting points for all nonempty subtrees for 4096, 256,
26 and 16 consecutive array elements. These four levels of index nodes are
27 followed by a fifth level with nodes for the individual array elements.
28
29 Each index node is nine words long. The pointers to the 16 possible
30 subtrees or are kept in the |info| and |link| fields of the last eight
31 words. (It would be both elegant and efficient to declare them as
32 array, unfortunately \PASCAL\ doesn't allow this.)
33
34 The fields in the first word of each index node and in the nodes for the
35 array elements are closely related. The |link| field points to the next
36 lower index node and the |sa_index| field contains four bits (one
37 hexadecimal digit) of the register number or mark class. For the lowest
38 index node the |link| field is |null| and the |sa_index| field indicates
39 the type of quantity (|int_avl|, |dimen_val|, |glue_val|, |mu_val|,
40 |box_val|, |tok_val|, or |mark_val|). The |sa_used| field in the index
41 nodes counts how many of the 16 pointers are non-null.
42 @y
43 @ There is one doubly linked tree, to handle the sparse array of the up
44 to 65535 additional mark classes.
45 The root of the tree, if it exists, is an index node containing 16
46 pointers to subtrees for 4096 consecutive array elements. Similar index
47 nodes are the starting points for all nonempty subtrees for 4096, 256,
48 and 16 consecutive array elements. These four levels of index nodes are
49 followed by a fifth level with nodes for the individual array elements.
50
51 Each index node is nine words long. The pointers to the 16 possible
52 subtrees are kept in the |info| and |link| fields of the last eight
53 words. (It would be both elegant and efficient to declare them as
54 array, unfortunately \PASCAL\ doesn't allow this.)
55
56 The fields in the first word of each index node and in the nodes for the
57 array elements are closely related. The |link| field points to the next
58 lower index node and the |sa_index| field contains eight bits (two
59 hexadecimal digits) of the mark class. For the lowest
60 index node the |link| field is |null| and the |sa_index| field indicates
61 the type of quantity (which is always |mark_val|). The |sa_used| field in the
62 index nodes counts how many of the 16 pointers are non-null.
63 @z
64 %----------------------------------------
65 @x l.4630
66 The |sa_index| field in the nodes for array elements contains the four
67 bits plus 16 times the type. Therefore such a node represents a count
68 or dimen register if and only if |sa_index<dimen_val_limit|; it
69 represents a skip or muskip register if and only if
70 |dimen_val_limit<=sa_index<mu_val_limit|; it represents a box register
71 if and only if |mu_val_limit<=sa_index<box_val_limit|; it represents a
72 token list register if and only if
73 |box_val_limit<=sa_index<tok_val_limit|; finally it represents a mark
74 class if and only if |tok_val_limit<=sa_index|.
75
76 The |new_index| procedure creates an index node (returned in |cur_ptr|)
77 having given contents of the |sa_index| and |link| fields.
78
79 @d box_val==4 {the additional box registers}
80 @d mark_val=6 {the additional mark classes}
81 @#
82 @d dimen_val_limit=@"20 {$2^4\cdot(|dimen_val|+1)$}
83 @d mu_val_limit=@"40 {$2^4\cdot(|mu_val|+1)$}
84 @d box_val_limit=@"50 {$2^4\cdot(|box_val|+1)$}
85 @d tok_val_limit=@"60 {$2^4\cdot(|tok_val|+1)$}
86 @y
87 The |sa_index| field in the nodes for array elements contains the eight
88 bits plus 256 times the type. The type field is actually ignored,
89 since we only use this hoop-jumpings for marks registers (the code
90 will probably get a rewrite to get in line with the rest of the
91 (e-)Omega stuf, anyway, so \dots)
92
93 The |new_index| procedure creates an index node (returned in |cur_ptr|)
94 having given contents of the |sa_index| and |link| fields.
95
96 @d box_val==7 {the additional box registers}
97 @d mark_val=8 {the additional mark classes}
98 @z
99 %----------------------------------------
100 @x
101 @ The roots of the seven trees for the additional registers and mark
102 classes are kept in the |sa_root| array. The first six locations must
103 be dumped and undumped; the last one is also known as |sa_mark|.
104
105 @d sa_mark==sa_root[mark_val] {root for mark classes}
106
107 @<Glob...@>=
108 @!sa_root:array[int_val..mark_val] of pointer; {roots of sparse arrays}
109 @!cur_ptr:pointer; {value returned by |new_index| and |find_sa_element|}
110 @!sa_null:memory_word; {two |null| pointers}
111
112 @ @<Set init...@>=
113 sa_mark:=null; sa_null.hh.lh:=null; sa_null.hh.rh:=null;
114
115 @ @<Initialize table...@>=
116 for i:=int_val to tok_val do sa_root[i]:=null;
117 @y
118 @ The root of the tree for the additional mark classes is kept
119 in |sa_mark|.
120
121 @<Glob...@>=
122 @!sa_mark:pointer; {pointer to sparse array of marks}
123 @!cur_ptr:pointer; {value returned by |new_index| and |find_sa_element|}
124 @!sa_null:memory_word; {two |null| pointers}
125
126 @ @<Set init...@>=
127 sa_mark:=null; sa_null.hh.lh:=null; sa_null.hh.rh:=null;
128 @z
129 %----------------------------------------
130 @x l.4681
131 @ Given a type |t| and a sixteen-bit number |n|, the |find_sa_element|
132 procedure returns (in |cur_ptr|) a pointer to the node for the
133 corresponding array element, or |null| when no such element exists. The
134 third parameter |w| is set |true| if the element must exist, e.g.,
135 because it is about to be modified. The procedure has two main
136 branches: one follows the existing tree structure, the other (only used
137 when |w| is |true|) creates the missing nodes.
138
139 We use macros to extract the four-bit pieces from a sixteen-bit register
140 number or mark class and to fetch or store one of the 16 pointers from
141 an index node.
142
143 @d if_cur_ptr_is_null_then_return_or_goto(#)== {some tree element is missing}
144 begin if cur_ptr=null then
145 if w then goto #@+else return;
146 end
147 @#
148 @d hex_dig1(#)==# div 4096 {the fourth lowest hexadecimal digit}
149 @d hex_dig2(#)==(# div 256) mod 16 {the third lowest hexadecimal digit}
150 @d hex_dig3(#)==(# div 16) mod 16 {the second lowest hexadecimal digit}
151 @d hex_dig4(#)==# mod 16 {the lowest hexadecimal digit}
152 @#
153 @d get_sa_ptr==if odd(i) then cur_ptr:=link(q+(i div 2)+1)
154 else cur_ptr:=info(q+(i div 2)+1)
155 {set |cur_ptr| to the pointer indexed by |i| from index node |q|}
156 @d put_sa_ptr(#)==if odd(i) then link(q+(i div 2)+1):=#
157 else info(q+(i div 2)+1):=#
158 {store the pointer indexed by |i| in index node |q|}
159 @d add_sa_ptr==begin put_sa_ptr(cur_ptr); incr(sa_used(q));
160 end {add |cur_ptr| as the pointer indexed by |i| in index node |q|}
161 @d delete_sa_ptr==begin put_sa_ptr(null); decr(sa_used(q));
162 end {delete the pointer indexed by |i| in index node |q|}
163
164 @<Declare \eTeX\ procedures for ex...@>=
165 procedure find_sa_element(@!t:small_number;@!n:halfword;@!w:boolean);
166 {sets |cur_val| to sparse array element location or |null|}
167 label not_found,not_found1,not_found2,not_found3,not_found4,exit;
168 var q:pointer; {for list manipulations}
169 @!i:small_number; {a four bit index}
170 begin cur_ptr:=sa_root[t];
171 if_cur_ptr_is_null_then_return_or_goto(not_found);@/
172 q:=cur_ptr; i:=hex_dig1(n); get_sa_ptr;
173 if_cur_ptr_is_null_then_return_or_goto(not_found1);@/
174 q:=cur_ptr; i:=hex_dig2(n); get_sa_ptr;
175 if_cur_ptr_is_null_then_return_or_goto(not_found2);@/
176 q:=cur_ptr; i:=hex_dig3(n); get_sa_ptr;
177 if_cur_ptr_is_null_then_return_or_goto(not_found3);@/
178 q:=cur_ptr; i:=hex_dig4(n); get_sa_ptr;
179 if (cur_ptr=null)and w then goto not_found4;
180 return;
181 not_found: new_index(t,null); {create first level index node}
182 sa_root[t]:=cur_ptr; q:=cur_ptr; i:=hex_dig1(n);
183 not_found1: new_index(i,q); {create second level index node}
184 add_sa_ptr; q:=cur_ptr; i:=hex_dig2(n);
185 not_found2: new_index(i,q); {create third level index node}
186 add_sa_ptr; q:=cur_ptr; i:=hex_dig3(n);
187 not_found3: new_index(i,q); {create fourth level index node}
188 add_sa_ptr; q:=cur_ptr; i:=hex_dig4(n);
189 not_found4: @<Create a new array element of type |t| with index |i|@>;
190 link(cur_ptr):=q; add_sa_ptr;
191 exit:end;
192
193 @ The array elements for registers are subject to grouping and have an
194 |sa_lev| field (quite analogous to |eq_level|) instead of |sa_used|.
195 Since saved values as well as shorthand definitions (created by e.g.,
196 \.{\\countdef}) refer to the location of the respective array element,
197 we need a reference count that is kept in the |sa_ref| field. An array
198 element can be deleted (together with all references to it) when its
199 |sa_ref| value is |null| and its value is the default value.
200 @^reference counts@>
201
202 Skip, muskip, box, and token registers use two word nodes, their values
203 are stored in the |sa_ptr| field.
204 Count and dimen registers use three word nodes, their
205 values are stored in the |sa_int| resp.\ |sa_dim| field in the third
206 word; the |sa_ptr| field is used under the name |sa_num| to store
207 the register number. Mark classes use four word nodes. The last three
208 words contain the five types of current marks
209
210 @d sa_lev==sa_used {grouping level for the current value}
211 @d pointer_node_size=2 {size of an element with a pointer value}
212 @d sa_type(#)==(sa_index(#) div 16) {type part of combined type/index}
213 @d sa_ref(#)==info(#+1) {reference count of a sparse array element}
214 @d sa_ptr(#)==link(#+1) {a pointer value}
215 @#
216 @d word_node_size=3 {size of an element with a word value}
217 @d sa_num==sa_ptr {the register number}
218 @d sa_int(#)==mem[#+2].int {an integer}
219 @d sa_dim(#)==mem[#+2].sc {a dimension (a somewhat esotheric distinction)}
220 @#
221 @d mark_class_node_size=4 {size of an element for a mark class}
222 @#
223 @d fetch_box(#)== {fetch |box(cur_val)|}
224 if cur_val<256 then #:=box(cur_val)
225 else begin find_sa_element(box_val,cur_val,false);
226 if cur_ptr=null then #:=null@+else #:=sa_ptr(cur_ptr);
227 end
228
229 @<Create a new array element...@>=
230 if t=mark_val then {a mark class}
231 begin cur_ptr:=get_node(mark_class_node_size);
232 mem[cur_ptr+1]:=sa_null; mem[cur_ptr+2]:=sa_null; mem[cur_ptr+3]:=sa_null;
233 end
234 else begin if t<=dimen_val then {a count or dimen register}
235 begin cur_ptr:=get_node(word_node_size); sa_int(cur_ptr):=0;
236 sa_num(cur_ptr):=n;
237 end
238 else begin cur_ptr:=get_node(pointer_node_size);
239 if t<=mu_val then {a skip or muskip register}
240 begin sa_ptr(cur_ptr):=zero_glue; add_glue_ref(zero_glue);
241 end
242 else sa_ptr(cur_ptr):=null; {a box or token list register}
243 end;
244 sa_ref(cur_ptr):=null; {all registers have a reference count}
245 end;
246 sa_index(cur_ptr):=16*t+i; sa_lev(cur_ptr):=level_one
247
248 @ The |delete_sa_ref| procedure is called when a pointer to an array
249 element representing a register is being removed; this means that the
250 reference count should be decreased by one. If the reduced reference
251 count is |null| and the register has been (globally) assigned its
252 default value the array element should disappear, possibly together with
253 some index nodes. This procedure will never be used for mark class
254 nodes.
255 @^reference counts@>
256
257 @d add_sa_ref(#)==incr(sa_ref(#)) {increase reference count}
258 @#
259 @d change_box(#)== {change |box(cur_val)|, the |eq_level| stays the same}
260 if cur_val<256 then set_equiv(box_base+cur_val,#)@+else set_sa_box(#)
261 @#
262
263 { FIXME: needs debugging (sparse arrays) }
264 @d set_sa_box(#)==begin find_sa_element(box_val,cur_val,false);
265 if cur_ptr<>0 then
266 begin
267 set_equiv(sa_ptr(cur_ptr),#);
268 add_sa_ref(cur_ptr);
269 delete_sa_ref(cur_ptr);
270 end;
271 end
272
273 @<Declare \eTeX\ procedures for tr...@>=
274 procedure delete_sa_ref(@!q:pointer); {reduce reference count}
275 label exit;
276 var p:pointer; {for list manipulations}
277 @!i:small_number; {a four bit index}
278 @!s:small_number; {size of a node}
279 begin decr(sa_ref(q));
280 if sa_ref(q)<>null then return;
281 if sa_index(q)<dimen_val_limit then
282 if sa_int(q)=0 then s:=word_node_size
283 else return
284 else begin if sa_index(q)<mu_val_limit then
285 if sa_ptr(q)=zero_glue then delete_glue_ref(zero_glue)
286 else return
287 else if sa_ptr(q)<>null then return;
288 s:=pointer_node_size;
289 end;
290 repeat i:=hex_dig4(sa_index(q)); p:=q; q:=link(p); free_node(p,s);
291 if q=null then {the whole tree has been freed}
292 begin sa_root[i]:=null; return;
293 end;
294 delete_sa_ptr; s:=index_node_size; {node |q| is an index node}
295 until sa_used(q)>0;
296 exit:end;
297
298 @ The |print_sa_num| procedure prints the register number corresponding
299 to an array element.
300
301 @<Basic print...@>=
302 procedure print_sa_num(@!q:pointer); {print register number}
303 var @!n:halfword; {the register number}
304 begin if sa_index(q)<dimen_val_limit then n:=sa_num(q) {the easy case}
305 else begin n:=hex_dig4(sa_index(q)); q:=link(q); n:=n+16*sa_index(q);
306 q:=link(q); n:=n+256*(sa_index(q)+16*sa_index(link(q)));
307 end;
308 print_int(n);
309 end;
310
311 @ Here is a procedure that displays the contents of an array element
312 symbolically. It is used under similar circumstances as is
313 |restore_trace| (together with |show_eqtb|) for the quantities kept in
314 the |eqtb| array.
315
316 @<Declare \eTeX\ procedures for tr...@>=
317 @!stat procedure show_sa(@!p:pointer;@!s:str_number);
318 var t:small_number; {the type of element}
319 begin begin_diagnostic; print_char("{"); print(s); print_char(" ");
320 if p=null then print_char("?") {this can't happen}
321 else begin t:=sa_type(p);
322 if t<box_val then print_cmd_chr(register,p)
323 else if t=box_val then
324 begin print_esc("box"); print_sa_num(p);
325 end
326 else if t=tok_val then print_cmd_chr(toks_register,p)
327 else print_char("?"); {this can't happen either}
328 print_char("=");
329 if t=int_val then print_int(sa_int(p))
330 else if t=dimen_val then
331 begin print_scaled(sa_dim(p)); print("pt");
332 end
333 else begin p:=sa_ptr(p);
334 if t=glue_val then print_spec(p,"pt")
335 else if t=mu_val then print_spec(p,"mu")
336 else if t=box_val then
337 if p=null then print("void")
338 else begin depth_threshold:=0; breadth_max:=1; show_node_list(p);
339 end
340 else if t=tok_val then
341 begin if p<>null then show_token_list(link(p),null,32);
342 end
343 else print_char("?"); {this can't happen either}
344 end;
345 end;
346 print_char("}"); end_diagnostic(false);
347 end;
348 tats
349 @y
350 @ Given a type |t| (which is always |mark_val|) and a sixteen-bit number |n|,
351 the |find_sa_element| procedure returns (in |cur_ptr|) a pointer to the node
352 for the corresponding array element, or |null| when no such element exists.
353 The third parameter |w| is set |true| if the element must exist, e.g., because
354 it is about to be modified. The procedure has two main branches: one follows
355 the existing tree structure, the other (only used when |w| is |true|) creates
356 the missing nodes.
357
358 We use macros to extract the four-bit pieces from a sixteen-bit register
359 number or mark class and to fetch or store one of the 16 pointers from
360 an index node.
361
362 @d if_cur_ptr_is_null_then_return_or_goto(#)== {some tree element is missing}
363 begin if cur_ptr=null then
364 if w then goto #@+else return;
365 end
366 @#
367 {FIXME: needs debugging}
368 @d hex_dig1(#)==# div 4096 {the fourth lowest hexadecimal digit}
369 @d hex_dig2(#)==(# div 256) mod 16 {the third lowest hexadecimal digit}
370 @d hex_dig3(#)==(# div 16) mod 16 {the second lowest hexadecimal digit}
371 @d hex_dig4(#)==# mod 16 {the lowest hexadecimal digit}
372 @#
373 @d get_sa_ptr==if odd(i) then cur_ptr:=link(q+(i div 2)+1)
374 else cur_ptr:=info(q+(i div 2)+1)
375 {set |cur_ptr| to the pointer indexed by |i| from index node |q|}
376 @d put_sa_ptr(#)==if odd(i) then link(q+(i div 2)+1):=#
377 else info(q+(i div 2)+1):=#
378 {store the pointer indexed by |i| in index node |q|}
379 @d add_sa_ptr==begin put_sa_ptr(cur_ptr); incr(sa_used(q));
380 end {add |cur_ptr| as the pointer indexed by |i| in index node |q|}
381 @d delete_sa_ptr==begin put_sa_ptr(null); decr(sa_used(q));
382 end {delete the pointer indexed by |i| in index node |q|}
383
384 @<Declare \eTeX\ procedures for ex...@>=
385 procedure find_sa_element(@!t:small_number;@!n:halfword;@!w:boolean);
386 {sets |cur_val| to sparse array element location or |null|}
387 label not_found,not_found1,not_found2,not_found3,not_found4,exit;
388 var q:pointer; {for list manipulations}
389 @!i:small_number; {a four bit index}
390 begin
391 begin if t<>mark_val then begin
392 cur_ptr:=null;
393 return;
394 end; end;
395 cur_ptr:=sa_mark;
396 if_cur_ptr_is_null_then_return_or_goto(not_found);@/
397 q:=cur_ptr; i:=hex_dig1(n); get_sa_ptr;
398 if_cur_ptr_is_null_then_return_or_goto(not_found1);@/
399 q:=cur_ptr; i:=hex_dig2(n); get_sa_ptr;
400 if_cur_ptr_is_null_then_return_or_goto(not_found2);@/
401 q:=cur_ptr; i:=hex_dig3(n); get_sa_ptr;
402 if_cur_ptr_is_null_then_return_or_goto(not_found3);@/
403 q:=cur_ptr; i:=hex_dig4(n); get_sa_ptr;
404 if (cur_ptr=null)and w then goto not_found4;
405 return;
406 not_found: new_index(t,null); {create first level index node}
407 sa_mark:=cur_ptr; q:=cur_ptr; i:=hex_dig1(n);
408 not_found1: new_index(i,q); {create second level index node}
409 add_sa_ptr; q:=cur_ptr; i:=hex_dig2(n);
410 not_found2: new_index(i,q); {create third level index node}
411 add_sa_ptr; q:=cur_ptr; i:=hex_dig3(n);
412 not_found3: new_index(i,q); {create fourth level index node}
413 add_sa_ptr; q:=cur_ptr; i:=hex_dig4(n);
414 not_found4: @<Create a new array element of type |t| with index |i|@>;
415 link(cur_ptr):=q; add_sa_ptr;
416 exit:end;
417
418 @ FIXME OBSOLETE The array elements for registers are subject to grouping and have an
419 |sa_lev| field (quite analogous to |eq_level|) instead of |sa_used|.
420 Since saved values as well as shorthand definitions (created by e.g.,
421 \.{\\countdef}) refer to the location of the respective array element,
422 we need a reference count that is kept in the |sa_ref| field. An array
423 element can be deleted (together with all references to it) when its
424 |sa_ref| value is |null| and its value is the default value.
425 @^reference counts@>
426
427 Skip, muskip, box, and token registers use two word nodes, their values
428 are stored in the |sa_ptr| field.
429 Count and dimen registers use three word nodes, their
430 values are stored in the |sa_int| resp.\ |sa_dim| field in the third
431 word; the |sa_ptr| field is used under the name |sa_num| to store
432 the register number.
433
434 @ Mark classes use four word nodes. The last three
435 words contain the five types of current marks
436
437 @d sa_lev==sa_used {grouping level for the current value}
438 @d pointer_node_size=2 {size of an element with a pointer value}
439 @d sa_type(#)==(sa_index(#) div 256) {type part of combined type/index}
440 @d sa_ref(#)==info(#+1) {reference count of a sparse array element}
441 @d sa_ptr(#)==link(#+1) {a pointer value}
442 @#
443 {FIXME: will be removed}
444 @d word_node_size=3 {size of an element with a word value}
445 @d sa_num==sa_ptr {the register number}
446 @d sa_int(#)==mem[#+2].int {an integer}
447 @d sa_dim(#)==mem[#+2].sc {a dimension (a somewhat esotheric distinction)}
448 @#
449 @d mark_class_node_size=4 {size of an element for a mark class}
450 @#
451 {FIXME: will be removed}
452 @d fetch_box(#)== {fetch |box(cur_val)|}
453 if cur_val<number_regs then #:=box(cur_val)
454 else begin find_sa_element(box_val,cur_val,false);
455 if cur_ptr=null then #:=null@+else #:=sa_ptr(cur_ptr);
456 end
457
458 @<Create a new array element...@>=
459 if t=mark_val then {a mark class}
460 begin cur_ptr:=get_node(mark_class_node_size);
461 mem[cur_ptr+1]:=sa_null; mem[cur_ptr+2]:=sa_null; mem[cur_ptr+3]:=sa_null;
462 end;
463 {
464 |else begin if t<=dimen_val then| {a count or dimen register}
465 | begin cur_ptr:=get_node(word_node_size); sa_int(cur_ptr):=0;|
466 | sa_num(cur_ptr):=n;|
467 | end|
468 | else begin cur_ptr:=get_node(pointer_node_size);|
469 | if t<=mu_val then| {a skip or muskip register}
470 | begin sa_ptr(cur_ptr):=zero_glue; add_glue_ref(zero_glue);|
471 | end|
472 | else sa_ptr(cur_ptr):=null; |{a box or token list register}
473 | end;|
474 | sa_ref(cur_ptr):=null;| {all registers have a reference count}
475 | end;|
476 }
477 sa_index(cur_ptr):=256*t+i; sa_lev(cur_ptr):=level_one
478
479 @ The |delete_sa_ref| procedure is called when a pointer to an array
480 element representing a register is being removed; this means that the
481 reference count should be decreased by one. If the reduced reference
482 count is |null| and the register has been (globally) assigned its
483 default value the array element should disappear, possibly together with
484 some index nodes. This procedure will never be used for mark class
485 nodes.
486 @^reference counts@>
487
488 @d add_sa_ref(#)==incr(sa_ref(#)) {increase reference count}
489 @#
490 @d change_box(#)== {change |box(cur_val)|, the |eq_level| stays the same}
491 set_equiv(box_base+cur_val,#)
492 @#
493
494 {FIXME: will be removed}
495 @d set_sa_box(#)==begin find_sa_element(box_val,cur_val,false);
496 if cur_ptr<>0 then
497 begin
498 set_equiv(sa_ptr(cur_ptr),#);
499 add_sa_ref(cur_ptr);
500 delete_sa_ref(cur_ptr);
501 end;
502 end
503
504 @<Declare \eTeX\ procedures for tr...@>=
505 procedure delete_sa_ref(@!q:pointer); {reduce reference count}
506 label exit;
507 var p:pointer; {for list manipulations}
508 @!i:small_number; {a four bit index}
509 @!s:small_number; {size of a node}
510 begin decr(sa_ref(q));
511 if sa_ref(q)<>null then return;
512 if false then {was |if sa_index(q)<dimen_val_limit then|}
513 if sa_int(q)=0 then s:=word_node_size
514 else return
515 else begin if false then {was |sa_index(q)<mu_val_limit then|}
516 if sa_ptr(q)=zero_glue then delete_glue_ref(zero_glue)
517 else return
518 else if sa_ptr(q)<>null then return;
519 s:=pointer_node_size;
520 end;
521 repeat i:=hex_dig4(sa_index(q)); p:=q; q:=link(p); free_node(p,s);
522 if q=null then {the whole tree has been freed}
523 begin
524 sa_mark:=null {was |sa_root[i]:=null|}; return;
525 end;
526 delete_sa_ptr; s:=index_node_size; {node |q| is an index node}
527 until sa_used(q)>0;
528 exit:end;
529
530 @ The |print_sa_num| procedure prints the register number corresponding
531 to an array element.
532
533 @<Basic print...@>=
534 procedure print_sa_num(@!q:pointer); {print register number}
535 var @!n:halfword; {the register number}
536 begin if false {was |sa_index(q)<dimen_val_limit|} then n:=sa_num(q) {the easy case}
537 else begin n:=hex_dig4(sa_index(q)); q:=link(q); n:=n+16*sa_index(q);
538 q:=link(q); n:=n+256*(sa_index(q)+16*sa_index(link(q)));
539 end;
540 print_int(n);
541 end;
542
543 @ Here is a procedure that displays the contents of an array element
544 symbolically. It is used under similar circumstances as is
545 |restore_trace| (together with |show_eqtb|) for the quantities kept in
546 the |eqtb| array.
547
548 @<Declare \eTeX\ procedures for tr...@>=
549 @!stat procedure show_sa(@!p:pointer;@!s:str_number);
550 {|var t:small_number;|} {the type of element}
551 begin begin_diagnostic; print_char("{"); print(s); print_char(" ");
552 {
553 |if p=null then print_char("?")| {this can't happen}
554 |else begin t:=sa_type(p);|
555 | if t<box_val then print_cmd_chr(register,p)|
556 | else if t=box_val then|
557 | begin print_esc("box"); print_sa_num(p);|
558 | end|
559 | else if t=tok_val then print_cmd_chr(toks_register,p)|
560 | else print_char("?");| {this can't happen either}
561 | print_char("=");|
562 | if t=int_val then print_int(sa_int(p))|
563 | else if t=dimen_val then|
564 | begin print_scaled(sa_dim(p)); print("pt");|
565 | end|
566 | else begin p:=sa_ptr(p);|
567 | if t=glue_val then print_spec(p,"pt")|
568 | else if t=mu_val then print_spec(p,"mu")|
569 | else if t=box_val then|
570 | if p=null then print("void")|
571 | else begin depth_threshold:=0; breadth_max:=1; show_node_list(p);|
572 | end|
573 | else if t=tok_val then|
574 | begin if p<>null then show_token_list(link(p),null,32);|
575 | end|
576 | else print_char("?");| {this can't happen either}
577 | end;|
578 | end;|
579 }
580 print_char("}"); end_diagnostic(false);
581 end;
582 tats
583 @z
584 %----------------------------------------
585 % TODO: l.5029+: will the simply be removed?
586 % (i.e.: cases which cannot happen (anymore)?)
587 %----------------------------------------
588 @x
589 procedure sa_save(@!p:pointer); {saves value of |p|}
590 var q:pointer; {the new save node}
591 @!i:quarterword; {index field of node}
592 begin if cur_level<>sa_level then
593 begin check_full_save_stack; save_type(save_ptr):=restore_sa;
594 save_level(save_ptr):=sa_level; save_index(save_ptr):=sa_chain;
595 incr(save_ptr); sa_chain:=null; sa_level:=cur_level;
596 end;
597 i:=sa_index(p);
598 if i<dimen_val_limit then
599 begin if sa_int(p)=0 then
600 begin q:=get_node(pointer_node_size); i:=tok_val_limit;
601 end
602 else begin q:=get_node(word_node_size); sa_int(q):=sa_int(p);
603 end;
604 sa_ptr(q):=null;
605 end
606 else begin q:=get_node(pointer_node_size); sa_ptr(q):=sa_ptr(p);
607 end;
608 sa_loc(q):=p; sa_index(q):=i; sa_lev(q):=sa_lev(p);
609 link(q):=sa_chain; sa_chain:=q; add_sa_ref(p);
610 end;
611
612 @ @<Declare \eTeX\ procedures for tr...@>=
613 procedure sa_destroy(@!p:pointer); {destroy value of |p|}
614 begin if sa_index(p)<mu_val_limit then delete_glue_ref(sa_ptr(p))
615 else if sa_ptr(p)<>null then
616 if sa_index(p)<box_val_limit then flush_node_list(sa_ptr(p))
617 else delete_token_ref(sa_ptr(p));
618 end;
619 @y
620 procedure sa_save(@!p:pointer); {saves value of |p|}
621 var q:pointer; {the new save node}
622 @!i:quarterword; {index field of node}
623 begin if cur_level<>sa_level then
624 begin check_full_save_stack; save_type(save_ptr):=restore_sa;
625 save_level(save_ptr):=sa_level; save_index(save_ptr):=sa_chain;
626 incr(save_ptr); sa_chain:=null; sa_level:=cur_level;
627 end;
628 i:=sa_index(p);
629 if false {was |i<dimen_val_limit|} then
630 begin if sa_int(p)=0 then
631 begin q:=get_node(pointer_node_size); i:=i {was |i:=tok_val_limit|};
632 end
633 else begin q:=get_node(word_node_size); sa_int(q):=sa_int(p);
634 end;
635 sa_ptr(q):=null;
636 end
637 else begin q:=get_node(pointer_node_size); sa_ptr(q):=sa_ptr(p);
638 end;
639 sa_loc(q):=p; sa_index(q):=i; sa_lev(q):=sa_lev(p);
640 link(q):=sa_chain; sa_chain:=q; add_sa_ref(p);
641 end;
642
643 @ @<Declare \eTeX\ procedures for tr...@>=
644 procedure sa_destroy(@!p:pointer); {destroy value of |p|}
645 begin if false {was |sa_index(p)<mu_val_limit|} then delete_glue_ref(sa_ptr(p))
646 else if sa_ptr(p)<>null then
647 if false {was |sa_index(p)<box_val_limit|} then flush_node_list(sa_ptr(p))
648 else delete_token_ref(sa_ptr(p));
649 end;
650 @z
651 %----------------------------------------
652 @x
653 procedure sa_restore;
654 var p:pointer; {sparse array element}
655 begin repeat p:=sa_loc(sa_chain);
656 if sa_lev(p)=level_one then
657 begin if sa_index(p)>=dimen_val_limit then sa_destroy(sa_chain);
658 @!stat if tracing_restores>0 then show_sa(p,"retaining");@+tats@;@/
659 end
660 else begin if sa_index(p)<dimen_val_limit then
661 if sa_index(sa_chain)<dimen_val_limit then sa_int(p):=sa_int(sa_chain)
662 else sa_int(p):=0
663 else begin sa_destroy(p); sa_ptr(p):=sa_ptr(sa_chain);
664 end;
665 sa_lev(p):=sa_lev(sa_chain);
666 @!stat if tracing_restores>0 then show_sa(p,"restoring");@+tats@;@/
667 end;
668 delete_sa_ref(p);
669 p:=sa_chain; sa_chain:=link(p);
670 if sa_index(p)<dimen_val_limit then free_node(p,word_node_size)
671 else free_node(p,pointer_node_size);
672 until sa_chain=null;
673 end;
674 @y
675 procedure sa_restore;
676 var p:pointer; {sparse array element}
677 begin repeat p:=sa_loc(sa_chain);
678 if sa_lev(p)=level_one then
679 begin {|if sa_index(p)>=dimen_val_limit then|} sa_destroy(sa_chain);
680 @!stat if tracing_restores>0 then show_sa(p,"retaining");@+tats@;@/
681 end
682 else begin if false {was |sa_index(p)<dimen_val_limit|} then
683 if false {was |sa_index(sa_chain)<dimen_val_limit|} then sa_int(p):=sa_int(sa_chain)
684 else sa_int(p):=0
685 else begin sa_destroy(p); sa_ptr(p):=sa_ptr(sa_chain);
686 end;
687 sa_lev(p):=sa_lev(sa_chain);
688 @!stat if tracing_restores>0 then show_sa(p,"restoring");@+tats@;@/
689 end;
690 delete_sa_ref(p);
691 p:=sa_chain; sa_chain:=link(p);
692 if false {was |sa_index(p)<dimen_val_limit|} then free_node(p,word_node_size)
693 else free_node(p,pointer_node_size);
694 until sa_chain=null;
695 end;
696 @z