node-res.lua /size: 18 Kb    last modification: 2021-10-28 13:50
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
node-res
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to node-ini.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
type
,
next
=
type
,
next
10
local
gmatch
,
format
=
string
.
gmatch
,
string
.
format
11 12
--[[ldx-- 13<p>The next function is not that much needed but in <l n='context'/> we use 14for debugging <l n='luatex'/> node management.</p> 15--ldx]]
--
16 17
local
nodes
,
node
=
nodes
,
node
18 19
local
report_nodes
=
logs
.
reporter
(
"
nodes
"
,
"
housekeeping
"
)
20 21
nodes
.
pool
=
nodes
.
pool
or
{
}
22
local
nodepool
=
nodes
.
pool
23 24
local
whatsitcodes
=
nodes
.
whatsitcodes
25
local
gluecodes
=
nodes
.
gluecodes
26
local
kerncodes
=
nodes
.
kerncodes
27
local
rulecodes
=
nodes
.
rulecodes
28
local
nodecodes
=
nodes
.
nodecodes
29
local
boundarycodes
=
nodes
.
boundarycodes
30
local
usercodes
=
nodes
.
usercodes
31 32
local
nodeproperties
=
nodes
.
properties
.
data
33 34
local
glyph_code
=
nodecodes
.
glyph
35
local
rule_code
=
nodecodes
.
rule
36
local
kern_code
=
nodecodes
.
kern
37
local
glue_code
=
nodecodes
.
glue
38
local
gluespec_code
=
nodecodes
.
gluespec
39
local
whatsit_code
=
nodecodes
.
whatsit
40 41
local
currentfont
=
font
.
current
42
local
texgetcount
=
tex
.
getcount
43 44
local
allocate
=
utilities
.
storage
.
allocate
45 46
local
reserved
=
{
}
47
local
nofreserved
=
0
48
local
userids
=
allocate
(
)
49
local
lastid
=
0
50 51
setmetatable
(
userids
,
{
52
__index
=
function
(
t
,
k
)
53
if
type
(
k
)
=
=
"
string
"
then
54
lastid
=
lastid
+
1
55
rawset
(
userids
,
lastid
,
k
)
56
rawset
(
userids
,
k
,
lastid
)
57
return
lastid
58
else
59
rawset
(
userids
,
k
,
k
)
60
return
k
61
end
62
end
,
63
__call
=
function
(
t
,
k
)
64
return
t
[
k
]
65
end
66
}
)
67 68
-- nuts overload
69 70
local
nuts
=
nodes
.
nuts
71
local
nutpool
=
{
}
72
nuts
.
pool
=
nutpool
73 74
local
tonut
=
nuts
.
tonut
75
local
tonode
=
nuts
.
tonode
76 77
local
getbox
=
nuts
.
getbox
78
local
getid
=
nuts
.
getid
79
local
getlist
=
nuts
.
getlist
80
local
getglue
=
nuts
.
getglue
81 82
local
setfield
=
nuts
.
setfield
83
local
setchar
=
nuts
.
setchar
84
local
setlist
=
nuts
.
setlist
85
local
setwhd
=
nuts
.
setwhd
86
local
setglue
=
nuts
.
setglue
87
local
setdisc
=
nuts
.
setdisc
88
local
setfont
=
nuts
.
setfont
89
local
setkern
=
nuts
.
setkern
90
local
setpenalty
=
nuts
.
setpenalty
91
local
setdir
=
nuts
.
setdir
92
local
setdirection
=
nuts
.
setdirection
93
local
setshift
=
nuts
.
setshift
94
local
setwidth
=
nuts
.
setwidth
95
local
setsubtype
=
nuts
.
setsubtype
96
local
setleader
=
nuts
.
setleader
97 98
local
setdata
=
nuts
.
setdata
99
local
setruledata
=
nuts
.
setruledata
100
local
setvalue
=
nuts
.
setvalue
101 102
local
copy_nut
=
nuts
.
copy
103
local
new_nut
=
nuts
.
new
104
local
flush_nut
=
nuts
.
flush
105 106
-- at some point we could have a dual set (the overhead of tonut is not much larger than
107
-- metatable associations at the lua/c end esp if we also take assignments into account
108 109
-- table.setmetatableindex(nodepool,function(t,k,v)
110
-- -- report_nodes("defining nodepool[%s] instance",k)
111
-- local f = nutpool[k]
112
-- local v = function(...)
113
-- return tonode(f(...))
114
-- end
115
-- t[k] = v
116
-- return v
117
-- end)
118
--
119
-- -- we delay one step because that permits us a forward reference
120
-- -- e.g. in pdfsetmatrix
121 122
table
.
setmetatableindex
(
nodepool
,
function
(
t
,
k
,
v
)
123
-- report_nodes("defining nodepool[%s] instance",k)
124
local
v
=
function
(
...
)
125
local
f
=
nutpool
[
k
]
126
local
v
=
function
(
...
)
127
return
tonode
(
f
(
...
)
)
128
end
129
t
[
k
]
=
v
130
return
v
(
...
)
131
end
132
t
[
k
]
=
v
133
return
v
134
end
)
135 136
local
function
register_nut
(
n
)
137
nofreserved
=
nofreserved
+
1
138
reserved
[
nofreserved
]
=
n
139
return
n
140
end
141 142
local
function
register_node
(
n
)
143
nofreserved
=
nofreserved
+
1
144
if
type
(
n
)
=
=
"
number
"
then
-- isnut(n)
145
reserved
[
nofreserved
]
=
n
146
else
147
reserved
[
nofreserved
]
=
tonut
(
n
)
148
end
149
return
n
150
end
151 152
nodepool
.
userids
=
userids
153
nodepool
.
register
=
register_node
154 155
nutpool
.
userids
=
userids
156
nutpool
.
register
=
register_node
-- could be register_nut
157 158
-- so far
159 160
local
disc
=
register_nut
(
new_nut
(
nodecodes
.
disc
)
)
161
local
kern
=
register_nut
(
new_nut
(
kern_code
,
kerncodes
.
userkern
)
)
162
local
fontkern
=
register_nut
(
new_nut
(
kern_code
,
kerncodes
.
fontkern
)
)
163
local
italickern
=
register_nut
(
new_nut
(
kern_code
,
kerncodes
.
italiccorrection
)
)
164
local
penalty
=
register_nut
(
new_nut
(
nodecodes
.
penalty
)
)
165
local
glue
=
register_nut
(
new_nut
(
glue_code
)
)
166
local
gluespec
=
register_nut
(
new_nut
(
gluespec_code
)
)
167
local
glyph
=
register_nut
(
new_nut
(
glyph_code
,
0
)
)
168 169
local
textdir
=
register_nut
(
new_nut
(
nodecodes
.
dir
)
)
170 171
local
latelua
=
register_nut
(
new_nut
(
whatsit_code
,
whatsitcodes
.
latelua
)
)
172
local
savepos
=
register_nut
(
new_nut
(
whatsit_code
,
whatsitcodes
.
savepos
)
)
173 174
local
user_node
=
new_nut
(
whatsit_code
,
whatsitcodes
.
userdefined
)
175 176
setfield
(
user_node
,
"
type
"
,
usercodes
.
number
)
177 178
local
left_margin_kern
=
register_nut
(
new_nut
(
nodecodes
.
marginkern
,
0
)
)
179
local
right_margin_kern
=
register_nut
(
new_nut
(
nodecodes
.
marginkern
,
1
)
)
180 181
local
lineskip
=
register_nut
(
new_nut
(
glue_code
,
gluecodes
.
lineskip
)
)
182
local
baselineskip
=
register_nut
(
new_nut
(
glue_code
,
gluecodes
.
baselineskip
)
)
183
local
leftskip
=
register_nut
(
new_nut
(
glue_code
,
gluecodes
.
leftskip
)
)
184
local
rightskip
=
register_nut
(
new_nut
(
glue_code
,
gluecodes
.
rightskip
)
)
185
local
lefthangskip
=
register_nut
(
new_nut
(
glue_code
,
gluecodes
.
lefthangskip
)
)
186
local
righthangskip
=
register_nut
(
new_nut
(
glue_code
,
gluecodes
.
righthangskip
)
)
187
local
indentskip
=
register_nut
(
new_nut
(
glue_code
,
gluecodes
.
indentskip
)
)
188
local
correctionskip
=
register_nut
(
new_nut
(
glue_code
,
gluecodes
.
correctionskip
)
)
189 190
local
temp
=
register_nut
(
new_nut
(
nodecodes
.
temp
,
0
)
)
191 192
local
noad
=
register_nut
(
new_nut
(
nodecodes
.
noad
)
)
193
local
delimiter
=
register_nut
(
new_nut
(
nodecodes
.
delimiter
)
)
194
local
fence
=
register_nut
(
new_nut
(
nodecodes
.
fence
)
)
195
local
submlist
=
register_nut
(
new_nut
(
nodecodes
.
submlist
)
)
196
local
accent
=
register_nut
(
new_nut
(
nodecodes
.
accent
)
)
197
local
radical
=
register_nut
(
new_nut
(
nodecodes
.
radical
)
)
198
local
fraction
=
register_nut
(
new_nut
(
nodecodes
.
fraction
)
)
199
local
subbox
=
register_nut
(
new_nut
(
nodecodes
.
subbox
)
)
200
local
mathchar
=
register_nut
(
new_nut
(
nodecodes
.
mathchar
)
)
201
local
mathtextchar
=
register_nut
(
new_nut
(
nodecodes
.
mathtextchar
)
)
202
local
choice
=
register_nut
(
new_nut
(
nodecodes
.
choice
)
)
203 204
local
boundary
=
register_nut
(
new_nut
(
nodecodes
.
boundary
,
boundarycodes
.
user
)
)
205
local
wordboundary
=
register_nut
(
new_nut
(
nodecodes
.
boundary
,
boundarycodes
.
word
)
)
206 207
local
cleader
=
register_nut
(
copy_nut
(
glue
)
)
setsubtype
(
cleader
,
gluecodes
.
cleaders
)
setglue
(
cleader
,
0
,
65536
,
0
,
2
,
0
)
208 209
-- the dir field needs to be set otherwise crash:
210 211
local
lefttoright_code
=
nodes
.
dirvalues
.
lefttoright
212 213
local
rule
=
register_nut
(
new_nut
(
rule_code
)
)
setdirection
(
rule
,
lefttoright_code
)
214
local
emptyrule
=
register_nut
(
new_nut
(
rule_code
,
rulecodes
.
empty
)
)
setdirection
(
rule
,
lefttoright_code
)
215
local
userrule
=
register_nut
(
new_nut
(
rule_code
,
rulecodes
.
user
)
)
setdirection
(
rule
,
lefttoright_code
)
216
local
outlinerule
=
register_nut
(
new_nut
(
rule_code
,
rulecodes
.
outline
)
)
setdirection
(
rule
,
lefttoright_code
)
217
local
hlist
=
register_nut
(
new_nut
(
nodecodes
.
hlist
)
)
setdirection
(
hlist
,
lefttoright_code
)
218
local
vlist
=
register_nut
(
new_nut
(
nodecodes
.
vlist
)
)
setdirection
(
vlist
,
lefttoright_code
)
219 220
function
nutpool
.
glyph
(
fnt
,
chr
)
221
local
n
=
copy_nut
(
glyph
)
222
if
fnt
then
223
setfont
(
n
,
fnt
=
=
true
and
currentfont
(
)
or
fnt
,
chr
)
224
elseif
chr
then
225
setchar
(
n
,
chr
)
226
end
227
return
n
228
end
229 230
function
nutpool
.
penalty
(
p
)
231
local
n
=
copy_nut
(
penalty
)
232
if
p
and
p
~
=
0
then
233
setpenalty
(
n
,
p
)
234
end
235
return
n
236
end
237 238
function
nutpool
.
kern
(
k
)
239
local
n
=
copy_nut
(
kern
)
240
if
k
and
k
~
=
0
then
241
setkern
(
n
,
k
)
242
end
243
return
n
244
end
245 246
function
nutpool
.
boundary
(
v
)
247
local
n
=
copy_nut
(
boundary
)
248
if
v
and
v
~
=
0
then
249
setvalue
(
n
,
v
)
250
end
251
return
n
252
end
253 254
function
nutpool
.
wordboundary
(
v
)
255
local
n
=
copy_nut
(
wordboundary
)
256
if
v
and
v
~
=
0
then
257
setvalue
(
n
,
v
)
258
end
259
return
n
260
end
261 262
function
nutpool
.
fontkern
(
k
)
263
local
n
=
copy_nut
(
fontkern
)
264
if
k
and
k
~
=
0
then
265
setkern
(
n
,
k
)
266
end
267
return
n
268
end
269 270
function
nutpool
.
italickern
(
k
)
271
local
n
=
copy_nut
(
italickern
)
272
if
k
and
k
~
=
0
then
273
setkern
(
n
,
k
)
274
end
275
return
n
276
end
277 278
function
nutpool
.
gluespec
(
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
279
local
n
=
copy_nut
(
gluespec
)
280
if
width
or
stretch
or
shrink
or
stretch_order
or
shrink_order
then
281
setglue
(
n
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
282
end
283
return
n
284
end
285 286
local
function
someskip
(
skip
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
287
-- maybe setglue
288
local
n
=
copy_nut
(
skip
)
289
if
width
or
stretch
or
shrink
or
stretch_order
or
shrink_order
then
290
setglue
(
n
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
291
end
292
return
n
293
end
294 295
function
nutpool
.
stretch
(
a
,
b
)
296
-- width stretch shrink stretch_order shrink_order
297
local
n
=
copy_nut
(
glue
)
298
if
not
b
then
299
a
,
b
=
1
,
a
or
1
300
end
301
setglue
(
n
,
0
,
a
,
0
,
b
,
0
)
302
return
n
303
end
304 305
function
nutpool
.
shrink
(
a
,
b
)
306
local
n
=
copy_nut
(
glue
)
307
if
not
b
then
308
a
,
b
=
1
,
a
or
1
309
end
310
setglue
(
n
,
0
,
0
,
a
,
0
,
0
,
b
)
311
return
n
312
end
313 314
function
nutpool
.
glue
(
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
315
return
someskip
(
glue
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
316
end
317 318
function
nutpool
.
negatedglue
(
glue
)
319
local
n
=
copy_nut
(
glue
)
320
local
width
,
stretch
,
shrink
=
getglue
(
n
)
321
setglue
(
n
,
-
width
,
-
stretch
,
-
shrink
)
322
return
n
323
end
324 325
function
nutpool
.
leftskip
(
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
326
return
someskip
(
leftskip
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
327
end
328 329
function
nutpool
.
rightskip
(
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
330
return
someskip
(
rightskip
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
331
end
332 333
function
nutpool
.
lefthangskip
(
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
334
return
someskip
(
lefthangskip
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
335
end
336 337
function
nutpool
.
righthangskip
(
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
338
return
someskip
(
righthangskip
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
339
end
340 341
function
nutpool
.
indentskip
(
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
342
return
someskip
(
indentskip
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
343
end
344 345
function
nutpool
.
lineskip
(
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
346
return
someskip
(
lineskip
,
width
,
stretch
,
shrink
,
stretch_order
,
shrink_order
)
347
end
348 349
function
nutpool
.
baselineskip
(
width
,
stretch
,
shrink
)
350
return
someskip
(
baselineskip
,
width
,
stretch
,
shrink
)
351
end
352 353
function
nutpool
.
disc
(
pre
,
post
,
replace
)
354
local
d
=
copy_nut
(
disc
)
355
if
pre
or
post
or
replace
then
356
setdisc
(
d
,
pre
,
post
,
replace
)
357
end
358
return
d
359
end
360 361
function
nutpool
.
direction
(
dir
,
swap
)
362
local
t
=
copy_nut
(
textdir
)
363
if
not
dir
then
364
-- just a l2r start node
365
elseif
swap
then
366
setdirection
(
t
,
dir
,
true
)
367
else
368
setdirection
(
t
,
dir
,
false
)
369
end
370
return
t
371
end
372 373
function
nutpool
.
rule
(
width
,
height
,
depth
)
-- w/h/d == nil will let them adapt
374
local
n
=
copy_nut
(
rule
)
375
if
width
or
height
or
depth
then
376
setwhd
(
n
,
width
,
height
,
depth
)
377
end
378
return
n
379
end
380 381
function
nutpool
.
emptyrule
(
width
,
height
,
depth
)
-- w/h/d == nil will let them adapt
382
local
n
=
copy_nut
(
emptyrule
)
383
if
width
or
height
or
depth
then
384
setwhd
(
n
,
width
,
height
,
depth
)
385
end
386
return
n
387
end
388 389
function
nutpool
.
userrule
(
width
,
height
,
depth
)
-- w/h/d == nil will let them adapt
390
local
n
=
copy_nut
(
userrule
)
391
if
width
or
height
or
depth
then
392
setwhd
(
n
,
width
,
height
,
depth
)
393
end
394
return
n
395
end
396 397
function
nutpool
.
outlinerule
(
width
,
height
,
depth
,
line
)
-- w/h/d == nil will let them adapt
398
local
n
=
copy_nut
(
outlinerule
)
399
if
width
or
height
or
depth
then
400
setwhd
(
n
,
width
,
height
,
depth
)
401
end
402
if
line
then
403
setruledata
(
n
,
line
)
404
end
405
return
n
406
end
407 408
function
nutpool
.
leader
(
width
,
list
)
409
local
n
=
copy_nut
(
cleader
)
410
if
width
then
411
setwidth
(
n
,
width
)
412
end
413
if
list
then
414
setleader
(
n
,
list
)
415
end
416
return
n
417
end
418 419
function
nutpool
.
savepos
(
)
420
return
copy_nut
(
savepos
)
421
end
422 423
function
nutpool
.
latelua
(
code
)
424
local
n
=
copy_nut
(
latelua
)
425
if
type
(
code
)
=
=
"
table
"
then
426
local
action
=
code
.
action
427
local
specification
=
code
.
specification
or
code
428
code
=
function
(
)
action
(
specification
)
end
429
end
430
setdata
(
n
,
code
)
431
return
n
432
end
433 434
function
nutpool
.
leftmarginkern
(
glyph
,
width
)
435
local
n
=
copy_nut
(
left_margin_kern
)
436
if
not
glyph
then
437
report_nodes
(
"
invalid pointer to left margin glyph node
"
)
438
elseif
getid
(
glyph
)
~
=
glyph_code
then
439
report_nodes
(
"
invalid node type %a for %s margin glyph node
"
,
nodecodes
[
glyph
]
,
"
left
"
)
440
else
441
setfield
(
n
,
"
glyph
"
,
glyph
)
442
end
443
if
width
and
width
~
=
0
then
444
setwidth
(
n
,
width
)
445
end
446
return
n
447
end
448 449
function
nutpool
.
rightmarginkern
(
glyph
,
width
)
450
local
n
=
copy_nut
(
right_margin_kern
)
451
if
not
glyph
then
452
report_nodes
(
"
invalid pointer to right margin glyph node
"
)
453
elseif
getid
(
glyph
)
~
=
glyph_code
then
454
report_nodes
(
"
invalid node type %a for %s margin glyph node
"
,
nodecodes
[
p
]
,
"
right
"
)
455
else
456
setfield
(
n
,
"
glyph
"
,
glyph
)
457
end
458
if
width
and
width
~
=
0
then
459
setwidth
(
n
,
width
)
460
end
461
return
n
462
end
463 464
function
nutpool
.
temp
(
)
465
return
copy_nut
(
temp
)
466
end
467 468
function
nutpool
.
noad
(
)
return
copy_nut
(
noad
)
end
469
function
nutpool
.
delimiter
(
)
return
copy_nut
(
delimiter
)
end
nutpool
.
delim
=
nutpool
.
delimiter
470
function
nutpool
.
fence
(
)
return
copy_nut
(
fence
)
end
471
function
nutpool
.
submlist
(
)
return
copy_nut
(
submlist
)
end
472
function
nutpool
.
noad
(
)
return
copy_nut
(
noad
)
end
473
function
nutpool
.
fence
(
)
return
copy_nut
(
fence
)
end
474
function
nutpool
.
accent
(
)
return
copy_nut
(
accent
)
end
475
function
nutpool
.
radical
(
)
return
copy_nut
(
radical
)
end
476
function
nutpool
.
fraction
(
)
return
copy_nut
(
fraction
)
end
477
function
nutpool
.
subbox
(
)
return
copy_nut
(
subbox
)
end
478
function
nutpool
.
mathchar
(
)
return
copy_nut
(
mathchar
)
end
479
function
nutpool
.
mathtextchar
(
)
return
copy_nut
(
mathtextchar
)
end
480
function
nutpool
.
choice
(
)
return
copy_nut
(
choice
)
end
481 482
local
function
new_hlist
(
list
,
width
,
height
,
depth
,
shift
)
483
local
n
=
copy_nut
(
hlist
)
484
if
list
then
485
setlist
(
n
,
list
)
486
end
487
if
width
or
height
or
depth
then
488
setwhd
(
n
,
width
,
height
,
depth
)
489
end
490
if
shift
and
shift
~
=
0
then
491
setshift
(
n
,
shift
)
492
end
493
return
n
494
end
495 496
local
function
new_vlist
(
list
,
width
,
height
,
depth
,
shift
)
497
local
n
=
copy_nut
(
vlist
)
498
if
list
then
499
setlist
(
n
,
list
)
500
end
501
if
width
or
height
or
depth
then
502
setwhd
(
n
,
width
,
height
,
depth
)
503
end
504
if
shift
and
shift
~
=
0
then
505
setshift
(
n
,
shift
)
506
end
507
return
n
508
end
509 510
nutpool
.
hlist
=
new_hlist
511
nutpool
.
vlist
=
new_vlist
512 513
function
nodepool
.
hlist
(
list
,
width
,
height
,
depth
,
shift
)
514
return
tonode
(
new_hlist
(
list
and
tonut
(
list
)
,
width
,
height
,
depth
,
shift
)
)
515
end
516 517
function
nodepool
.
vlist
(
list
,
width
,
height
,
depth
,
shift
)
518
return
tonode
(
new_vlist
(
list
and
tonut
(
list
)
,
width
,
height
,
depth
,
shift
)
)
519
end
520 521
function
nutpool
.
usernode
(
id
,
data
)
522
local
n
=
copy_nut
(
user_node
)
523
nodeproperties
[
n
]
=
{
524
id
=
id
,
525
data
=
data
,
526
}
527
return
n
528
end
529 530
-- housekeeping
531 532
local
function
cleanup
(
nofboxes
)
-- todo
533
local
tracers
=
nodes
.
tracers
534
if
tracers
and
tracers
.
steppers
then
-- to be resolved
535
tracers
.
steppers
.
reset
(
)
-- todo: make a registration subsystem
536
end
537
local
nl
=
0
538
local
nr
=
nofreserved
539
for
i
=
1
,
nofreserved
do
540
local
ri
=
reserved
[
i
]
541
flush_nut
(
reserved
[
i
]
)
542
end
543
if
nofboxes
then
544
for
i
=
0
,
nofboxes
do
545
local
l
=
getbox
(
i
)
546
if
l
then
547
flush_nut
(
l
)
-- also list ?
548
nl
=
nl
+
1
549
end
550
end
551
end
552
reserved
=
{
}
553
nofreserved
=
0
554
return
nr
,
nl
,
nofboxes
-- can be nil
555
end
556 557
local
function
usage
(
)
558
local
t
=
{
}
559
for
n
,
tag
in
gmatch
(
status
.
node_mem_usage
,
"
(%d+) ([a-z_]+)
"
)
do
560
t
[
tag
]
=
tonumber
(
n
)
or
0
561
end
562
return
t
563
end
564 565
local
stock
=
{
}
566 567
nutpool
.
cleanup
=
cleanup
568
nodepool
.
cleanup
=
cleanup
569 570
nutpool
.
usage
=
usage
571
nodepool
.
usage
=
usage
572 573
nutpool
.
stock
=
stock
574
nodepool
.
stock
=
stock
575 576
-- end
577 578
statistics
.
register
(
"
cleaned up reserved nodes
"
,
function
(
)
579
return
format
(
"
%s nodes, %s lists of %s
"
,
cleanup
(
texgetcount
(
"
c_syst_last_allocated_box
"
)
)
)
580
end
)
-- \topofboxstack
581 582
statistics
.
register
(
"
node memory usage
"
,
function
(
)
-- comes after cleanup !
583
local
used
=
usage
(
)
584
if
next
(
used
)
then
585
local
t
,
n
=
{
}
,
0
586
for
k
,
v
in
table
.
sortedhash
(
used
)
do
587
n
=
n
+
1
;
t
[
n
]
=
format
(
"
%s %s
"
,
v
,
k
)
588
end
589
return
table
.
concat
(
t
,
"
,
"
)
590
end
591
end
)
592 593
lua
.
registerinitexfinalizer
(
cleanup
,
"
cleanup reserved nodes
"
)
594 595
-- experiment
596 597
do
598 599
local
glyph
=
tonode
(
glyph
)
600
local
traverseid
=
nodes
.
traverseid
601 602
local
traversers
=
table
.
setmetatableindex
(
function
(
t
,
k
)
603
local
v
=
traverseid
(
type
(
k
)
=
=
"
number
"
and
k
or
nodecodes
[
k
]
,
glyph
)
604
t
[
k
]
=
v
605
return
v
606
end
)
607 608
traversers
.
node
=
nodes
.
traverse
(
glyph
)
609
traversers
.
char
=
nodes
.
traversechar
(
glyph
)
610
if
nodes
.
traverseglyph
then
traversers
.
glyph
=
nodes
.
traverseglyph
(
glyph
)
end
611
if
nodes
.
traverselist
then
traversers
.
list
=
nodes
.
traverselist
(
glyph
)
end
612 613
nodes
.
traversers
=
traversers
614 615
end
616 617
do
618 619
local
glyph
=
glyph
620
local
traverseid
=
nuts
.
traverseid
621 622
local
traversers
=
table
.
setmetatableindex
(
function
(
t
,
k
)
623
local
v
=
traverseid
(
type
(
k
)
=
=
"
number
"
and
k
or
nodecodes
[
k
]
,
glyph
)
624
t
[
k
]
=
v
625
return
v
626
end
)
627 628
traversers
.
node
=
nuts
.
traverse
(
glyph
)
629
traversers
.
char
=
nuts
.
traversechar
(
glyph
)
630
if
nuts
.
traverseglyph
then
traversers
.
glyph
=
nuts
.
traverseglyph
(
glyph
)
end
631
if
nuts
.
traverselist
then
traversers
.
list
=
nuts
.
traverselist
(
glyph
)
end
632
if
nuts
.
traversecontent
then
traversers
.
content
=
nuts
.
traversecontent
(
glyph
)
end
633 634
nuts
.
traversers
=
traversers
635 636
end
637