diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-mig.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/node-mig.lua | 97 |
1 files changed, 62 insertions, 35 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-mig.lua b/Master/texmf-dist/tex/context/base/node-mig.lua index 9fc35a04820..41f95be4590 100644 --- a/Master/texmf-dist/tex/context/base/node-mig.lua +++ b/Master/texmf-dist/tex/context/base/node-mig.lua @@ -6,15 +6,32 @@ if not modules then modules = { } end modules ['node-mig'] = { license = "see context related readme files" } +-- todo: insert_after + local format = string.format -local attributes, nodes, node = attributes, nodes, node +local trace_migrations = false trackers.register("nodes.migrations", function(v) trace_migrations = v end) -local remove_nodes = nodes.remove +local report_nodes = logs.reporter("nodes","migrations") -local nodecodes = nodes.nodecodes +local attributes = attributes +local nodes = nodes local tasks = nodes.tasks +local nuts = nodes.nuts +local tonut = nuts.tonut + +local getnext = nuts.getnext +local getid = nuts.getid +local getlist = nuts.getlist +local getattr = nuts.getattr + +local setfield = nuts.setfield +local setattr = nuts.setattr + +local remove_node = nuts.remove + +local nodecodes = nodes.nodecodes local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist local insert_code = nodecodes.ins @@ -22,10 +39,6 @@ local mark_code = nodecodes.mark local a_migrated = attributes.private("migrated") -local trace_migrations = false trackers.register("nodes.migrations", function(v) trace_migrations = v end) - -local report_nodes = logs.reporter("nodes","migrations") - local migrate_inserts, migrate_marks, inserts_too local t_inserts, t_marks, t_sweeps = 0, 0, 0 @@ -33,32 +46,42 @@ local t_inserts, t_marks, t_sweeps = 0, 0, 0 local function locate(head,first,last,ni,nm) local current = head while current do - local id = current.id + local id = getid(current) if id == vlist_code or id == hlist_code then - current.list, first, last, ni, nm = locate(current.list,first,last,ni,nm) - current = current.next + local list = getlist(current) + if list then + list, first, last, ni, nm = locate(list,first,last,ni,nm) + setfield(current,"list",list) + end + current = getnext(current) elseif migrate_inserts and id == insert_code then local insert - head, current, insert = remove_nodes(head,current) - insert.next = nil + head, current, insert = remove_node(head,current) + setfield(insert,"next",nil) if first then - insert.prev, last.next = last, insert + setfield(insert,"prev",last) + setfield(last,"next",insert) else - insert.prev, first = nil, insert + setfield(insert,"prev",nil) + first = insert end - last, ni = insert, ni + 1 + last = insert + ni = ni + 1 elseif migrate_marks and id == mark_code then local mark - head, current, mark = remove_nodes(head,current) - mark.next = nil + head, current, mark = remove_node(head,current) + setfield(mark,"next",nil) if first then - mark.prev, last.next = last, mark + setfield(mark,"prev",last) + setfield(last,"next",mark) else - mark.prev, first = nil, mark + setfield(mark,"prev",nil) + first = mark end - last, nm = mark, nm + 1 + last = mark + nm = nm + 1 else - current= current.next + current = getnext(current) end end return head, first, last, ni, nm @@ -70,39 +93,43 @@ function nodes.handlers.migrate(head,where) if trace_migrations then report_nodes("migration sweep %a",where) end - local current = head + local current = tonut(head) while current do - local id = current.id + local id = getid(current) -- inserts_too is a temp hack, we should only do them when it concerns -- newly placed (flushed) inserts - if id == vlist_code or id == hlist_code or (inserts_too and id == insert_code) and not current[a_migrated] then - current[a_migrated] = 1 + if id == vlist_code or id == hlist_code or (inserts_too and id == insert_code) and not getattr(current,a_migrated) then + setattr(current,a_migrated,1) t_sweeps = t_sweeps + 1 - local h = current.list + local h = getlist(current) local first, last, ni, nm while h do - local id = h.id + local id = getid(h) if id == vlist_code or id == hlist_code then h, first, last, ni, nm = locate(h,first,last,0,0) end - h = h.next + h = getnext(h) end if first then - t_inserts, t_marks = t_inserts + ni, t_marks + nm + t_inserts = t_inserts + ni + t_marks = t_marks + nm if trace_migrations and (ni > 0 or nm > 0) then report_nodes("sweep %a, container %a, %s inserts and %s marks migrated outwards during %a", t_sweeps,nodecodes[id],ni,nm,where) end - -- inserts after head - local n = current.next + -- inserts after head, use insert_after + local n = getnext(current) if n then - last.next, n.prev = n, last + setfield(last,"next",n) + setfield(n,"prev",last) end - current.next, first.prev = first, current - done, current = true, last + setfield(current,"next",first) + setfield(first,"prev",current) + done = true + current = last end end - current = current.next + current = getnext(next) end return head, done end |