summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/node-ser.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-ser.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/node-ser.lua97
1 files changed, 50 insertions, 47 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-ser.lua b/Master/texmf-dist/tex/context/base/node-ser.lua
index e632e92da04..aa4615626e9 100644
--- a/Master/texmf-dist/tex/context/base/node-ser.lua
+++ b/Master/texmf-dist/tex/context/base/node-ser.lua
@@ -9,18 +9,21 @@ if not modules then modules = { } end modules ['node-ser'] = {
-- beware, some field names will change in a next releases
-- of luatex; this is pretty old code that needs an overhaul
-local type, format, concat = type, string.format, table.concat
+local type, format, concat, rep = type, string.format, table.concat, string.rep
-local ctxcatcodes = tex.ctxcatcodes
+local allocate = utilities.storage.allocate
-local hlist = node.id('hlist')
-local vlist = node.id('vlist')
+local nodes, node = nodes, node
local traverse = node.traverse
-local node_fields = node.fields
-local node_type = node.type
-local expand = table.tohash {
+local nodecodes = nodes.nodecodes
+local nodefields = nodes.fields
+
+local hlist_code = nodecodes.hlist
+local vlist_code = nodecodes.vlist
+
+local expand = allocate ( table.tohash {
"list", -- list_ptr & ins_ptr & adjust_ptr
"pre", --
"post", --
@@ -35,25 +38,25 @@ local expand = table.tohash {
"leader", -- leader_ptr
"action", -- action_ptr
"value", -- user_defined nodes with subtype 'a' en 'n'
-}
+} )
-- page_insert: "height", "last_ins_ptr", "best_ins_ptr"
-- split_insert: "height", "last_ins_ptr", "best_ins_ptr", "broken_ptr", "broken_ins"
-local ignore = table.tohash {
+local ignore = allocate ( table.tohash {
"page_insert",
"split_insert",
"ref_count",
-}
+} )
-local dimension = table.tohash {
+local dimension = allocate ( table.tohash {
"width", "height", "depth", "shift",
"stretch", "shrink",
"xoffset", "yoffset",
"surround",
"kern",
"box_left_width", "box_right_width"
-}
+} )
-- flat: don't use next, but indexes
-- verbose: also add type
@@ -66,7 +69,7 @@ nodes.ignorablefields = ignore
-- not ok yet:
function nodes.astable(n,sparse) -- not yet ok
- local f, t = node_fields(n.id,n.subtype), { }
+ local f, t = nodefields(n), { }
for i=1,#f do
local v = f[i]
local d = n[v]
@@ -84,7 +87,7 @@ function nodes.astable(n,sparse) -- not yet ok
end
end
end
- t.type = node_type(n.id)
+ t.type = nodecodes[n.id]
return t
end
@@ -93,11 +96,11 @@ end
local function totable(n,flat,verbose)
-- todo: no local function
local function to_table(n,flat,verbose)
- local f = node_fields(n.id,n.subtype)
+ local f = nodefields(n)
local tt = { }
for k=1,#f do
local v = f[k]
- local nv = n[v]
+ local nv = v and n[v]
if nv then
if ignore[v] then
-- skip
@@ -115,15 +118,16 @@ local function totable(n,flat,verbose)
end
end
if verbose then
- tt.type = node_type(tt.id)
+ tt.type = nodecodes[tt.id]
end
return tt
end
if n then
if flat then
- local t = { }
+ local t, tn = { }, 0
while n do
- t[#t+1] = to_table(n,flat,verbise)
+ tn = tn + 1
+ t[tn] = to_table(n,flat,verbose)
n = n.next
end
return t
@@ -147,6 +151,8 @@ end
-- not ok yet; this will become a module
+-- todo: adapt to nodecodes etc
+
local function serialize(root,name,handle,depth,m)
handle = handle or print
if depth then
@@ -170,7 +176,7 @@ local function serialize(root,name,handle,depth,m)
if root then
local fld
if root.id then
- fld = node_fields(root.id,root.subtype) -- we can cache these (todo)
+ fld = nodefields(root) -- we can cache these (todo)
else
fld = table.sortedkeys(root)
end
@@ -215,9 +221,10 @@ local function serialize(root,name,handle,depth,m)
end
function nodes.serialize(root,name)
- local t = { }
+ local t, n = { }, 0
local function flush(s)
- t[#t+1] = s
+ n = n + 1
+ t[n] = s
end
serialize(root, name, flush, nil, 0)
return concat(t,"\n")
@@ -227,50 +234,46 @@ function nodes.serializebox(n,flat,verbose,name)
return nodes.serialize(nodes.totable(tex.box[n],flat,verbose),name)
end
-function nodes.visualizebox(...)
- tex.print(ctxcatcodes,"\\starttyping")
- tex.print(nodes.serializebox(...))
- tex.print("\\stoptyping")
+-- keep:
+--
+-- function nodes.visualizebox(...)
+-- tex.print(ctxcatcodes,"\\starttyping")
+-- tex.print(nodes.serializebox(...))
+-- tex.print("\\stoptyping")
+-- end
+
+function nodes.visualizebox(...) -- to be checked .. will move to module anyway
+ context.starttyping()
+ context.pushcatcodes("verbatim")
+ context(nodes.serializebox(...))
+ context.stoptyping()
+ context.popcatcodes()
end
-function nodes.list(head,n) -- name might change to nodes.type
+function nodes.list(head,n) -- name might change to nodes.type -- to be checked .. will move to module anyway
if not n then
- tex.print(ctxcatcodes,"\\starttyping")
+ context.starttyping(true)
end
while head do
local id = head.id
- tex.print(string.rep(" ",n or 0) .. tostring(head) .. "\n")
- if id == hlist or id == vlist then
+ tex.write(rep(" ",n or 0) .. tostring(head) .. "\n")
+ if id == hlist_code or id == vlist_code then
nodes.list(head.list,(n or 0)+1)
end
head = head.next
end
if not n then
- tex.print("\\stoptyping")
+ context.stoptyping(true)
end
end
function nodes.print(head,n)
while head do
local id = head.id
- texio.write_nl(string.rep(" ",n or 0) .. tostring(head))
- if id == hlist or id == vlist then
+ texio.write_nl(rep(" ",n or 0) .. tostring(head))
+ if id == hlist_code or id == vlist_code then
nodes.print(head.list,(n or 0)+1)
end
head = head.next
end
end
-
-function nodes.check_for_leaks(sparse)
- local l = { }
- local q = node.usedlist()
- for p in traverse(q) do
- local s = table.serialize(nodes.astable(p,sparse),node_type(p.id))
- l[s] = (l[s] or 0) + 1
- end
- node.flush_list(q)
- for k, v in next, l do
- texio.write_nl(format("%s * %s", v, k))
- end
-end
-