summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/node-tsk.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-tsk.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/node-tsk.lua207
1 files changed, 141 insertions, 66 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-tsk.lua b/Master/texmf-dist/tex/context/base/node-tsk.lua
index 206b4a2668c..29a665ff031 100644
--- a/Master/texmf-dist/tex/context/base/node-tsk.lua
+++ b/Master/texmf-dist/tex/context/base/node-tsk.lua
@@ -6,88 +6,153 @@ if not modules then modules = { } end modules ['node-tsk'] = {
license = "see context related readme files"
}
--- this might move to task-*
+-- This might move to task-* and become less code as in sequencers
+-- we already have dirty flags as well. On the other hand, nodes are
+-- rather specialized and here we focus on node related tasks.
local trace_tasks = false trackers.register("tasks.creation", function(v) trace_tasks = v end)
-tasks = tasks or { }
-tasks.data = tasks.data or { }
+local report_tasks = logs.reporter("tasks")
-function tasks.new(name,list)
- local tasklist = sequencer.reset()
- tasks.data[name] = { list = tasklist, runner = false }
- for l=1,#list do
- sequencer.appendgroup(tasklist,list[l])
+local allocate = utilities.storage.allocate
+
+local nodes = nodes
+
+nodes.tasks = nodes.tasks or { }
+local tasks = nodes.tasks
+
+local tasksdata = { } -- no longer public
+
+local sequencers = utilities.sequencers
+
+local frozengroups = "no"
+
+function tasks.freeze(kind)
+ frozengroups = kind or "tolerant" -- todo: hook into jobname
+end
+
+function tasks.new(specification) -- was: name,arguments,list
+ local name = specification.name
+ local arguments = specification.arguments or 0
+ local sequence = specification.sequence
+ if name and sequence then
+ local tasklist = sequencers.reset()
+ tasksdata[name] = {
+ list = tasklist,
+ runner = false,
+ arguments = arguments,
+ -- sequence = sequence,
+ frozen = { },
+ }
+ for l=1,#sequence do
+ sequencers.appendgroup(tasklist,sequence[l])
+ end
+ end
+end
+
+local function valid(name)
+ local data = tasksdata[name]
+ if not data then
+ report_tasks("unknown task %s",name)
+ else
+ return data
+ end
+end
+
+local function validgroup(name,group,what)
+ local data = tasksdata[name]
+ if not data then
+ report_tasks("unknown task %s",name)
+ else
+ local frozen = data.frozen[group]
+ if frozen then
+ if frozengroup == "no" then
+ -- default
+ elseif frozengroup == "strict" then
+ report_tasks("warning: group %s of task %s is frozen, %s applied but not supported",group,name,what)
+ return
+ else -- if frozengroup == "tolerant" then
+ report_tasks("warning: group %s of task %s is frozen, %s ignored",group,name,what)
+ end
+ end
+ return data
+ end
+end
+
+function tasks.freezegroup(name,group)
+ local data = valid(name)
+ if data then
+ data.frozen[group] = true
end
end
function tasks.restart(name)
- local data = tasks.data[name]
+ local data = valid(name)
if data then
data.runner = false
end
end
function tasks.enableaction(name,action)
- local data = tasks.data[name]
+ local data = valid(name)
if data then
- sequencer.enableaction(data.list,action)
+ sequencers.enableaction(data.list,action)
data.runner = false
end
end
function tasks.disableaction(name,action)
- local data = tasks.data[name]
+ local data = valid(name)
if data then
- sequencer.disableaction(data.list,action)
+ sequencers.disableaction(data.list,action)
data.runner = false
end
end
function tasks.enablegroup(name,group)
- local data = tasks.data[name]
+ local data = validgroup(name,"enable group")
if data then
- sequencer.enablegroup(data.list,group)
+ sequencers.enablegroup(data.list,group)
data.runner = false
end
end
function tasks.disablegroup(name,group)
- local data = tasks.data[name]
+ local data = validgroup(name,"disable group")
if data then
- sequencer.disablegroup(data.list,group)
+ sequencers.disablegroup(data.list,group)
data.runner = false
end
end
function tasks.appendaction(name,group,action,where,kind)
- local data = tasks.data[name]
+ local data = validgroup(name,"append action")
if data then
- sequencer.appendaction(data.list,group,action,where,kind)
+ sequencers.appendaction(data.list,group,action,where,kind)
data.runner = false
end
end
function tasks.prependaction(name,group,action,where,kind)
- local data = tasks.data[name]
+ local data = validgroup(name,"prepend action")
if data then
- sequencer.prependaction(data.list,group,action,where,kind)
+ sequencers.prependaction(data.list,group,action,where,kind)
data.runner = false
end
end
function tasks.removeaction(name,group,action)
- local data = tasks.data[name]
+ local data = validgroup(name,"remove action")
if data then
- sequencer.removeaction(data.list,group,action)
+ sequencers.removeaction(data.list,group,action)
data.runner = false
end
end
function tasks.showactions(name,group,action,where,kind)
- local data = tasks.data[name]
+ local data = valid(name)
if data then
- logs.report("nodes","task %s, list:\n%s",name,sequencer.nodeprocessor(data.list))
+ report_tasks("task %s, list:\n%s",name,sequencers.nodeprocessor(data.list))
end
end
@@ -100,25 +165,26 @@ local created, total = 0, 0
statistics.register("node list callback tasks", function()
if total > 0 then
- return string.format("%s unique task lists, %s instances (re)created, %s calls",table.count(tasks.data),created,total)
+ return string.format("%s unique task lists, %s instances (re)created, %s calls",table.count(tasksdata),created,total)
else
return nil
end
end)
-local compile, nodeprocessor = sequencer.compile, sequencer.nodeprocessor
+local compile, nodeprocessor = sequencers.compile, sequencers.nodeprocessor
-function tasks.actions(name,n) -- we optimize for the number or arguments (no ...)
- local data = tasks.data[name]
+function tasks.actions(name) -- we optimize for the number or arguments (no ...)
+ local data = tasksdata[name]
if data then
+ local n = data.arguments or 0
if n == 0 then
return function(head)
- local runner = data.runner
total = total + 1 -- will go away
+ local runner = data.runner
if not runner then
created = created + 1
if trace_tasks then
- logs.report("nodes","creating task runner '%s'",name)
+ report_tasks("creating runner '%s'",name)
end
runner = compile(data.list,nodeprocessor,0)
data.runner = runner
@@ -132,7 +198,7 @@ function tasks.actions(name,n) -- we optimize for the number or arguments (no ..
if not runner then
created = created + 1
if trace_tasks then
- logs.report("nodes","creating task runner '%s' with 1 extra arguments",name)
+ report_tasks("creating runner '%s' with 1 extra arguments",name)
end
runner = compile(data.list,nodeprocessor,1)
data.runner = runner
@@ -146,7 +212,7 @@ function tasks.actions(name,n) -- we optimize for the number or arguments (no ..
if not runner then
created = created + 1
if trace_tasks then
- logs.report("nodes","creating task runner '%s' with 2 extra arguments",name)
+ report_tasks("creating runner '%s' with 2 extra arguments",name)
end
runner = compile(data.list,nodeprocessor,2)
data.runner = runner
@@ -160,7 +226,7 @@ function tasks.actions(name,n) -- we optimize for the number or arguments (no ..
if not runner then
created = created + 1
if trace_tasks then
- logs.report("nodes","creating task runner '%s' with 3 extra arguments",name)
+ report_tasks("creating runner '%s' with 3 extra arguments",name)
end
runner = compile(data.list,nodeprocessor,3)
data.runner = runner
@@ -174,7 +240,7 @@ function tasks.actions(name,n) -- we optimize for the number or arguments (no ..
if not runner then
created = created + 1
if trace_tasks then
- logs.report("nodes","creating task runner '%s' with 4 extra arguments",name)
+ report_tasks("creating runner '%s' with 4 extra arguments",name)
end
runner = compile(data.list,nodeprocessor,4)
data.runner = runner
@@ -188,7 +254,7 @@ function tasks.actions(name,n) -- we optimize for the number or arguments (no ..
if not runner then
created = created + 1
if trace_tasks then
- logs.report("nodes","creating task runner '%s' with 5 extra arguments",name)
+ report_tasks("creating runner '%s' with 5 extra arguments",name)
end
runner = compile(data.list,nodeprocessor,5)
data.runner = runner
@@ -202,7 +268,7 @@ function tasks.actions(name,n) -- we optimize for the number or arguments (no ..
if not runner then
created = created + 1
if trace_tasks then
- logs.report("nodes","creating task runner '%s' with n extra arguments",name)
+ report_tasks("creating runner '%s' with n extra arguments",name)
end
runner = compile(data.list,nodeprocessor,"n")
data.runner = runner
@@ -216,7 +282,7 @@ function tasks.actions(name,n) -- we optimize for the number or arguments (no ..
end
function tasks.table(name) --maybe move this to task-deb.lua
- local tsk = tasks.data[name]
+ local tsk = tasksdata[name]
local lst = tsk and tsk.list
local HL, NC, NR, bold, type = context.HL, context.NC, context.NR, context.bold, context.type
if lst then
@@ -242,9 +308,12 @@ function tasks.table(name) --maybe move this to task-deb.lua
end
end
-tasks.new (
- "processors",
- {
+-- this will move
+
+tasks.new {
+ name = "processors",
+ arguments = 4,
+ sequence = {
"before", -- for users
"normalizers",
"characters",
@@ -253,11 +322,12 @@ tasks.new (
"lists",
"after", -- for users
}
-)
+}
-tasks.new (
- "finalizers",
- {
+tasks.new {
+ name = "finalizers",
+ arguments = 1,
+ sequence = {
"before", -- for users
"normalizers",
-- "characters",
@@ -266,50 +336,55 @@ tasks.new (
"lists",
"after", -- for users
}
-)
+}
-tasks.new (
- "shipouts",
- {
+tasks.new {
+ name = "shipouts",
+ arguments = 0,
+ sequence = {
"before", -- for users
"normalizers",
"finishers",
"after", -- for users
}
-)
+}
-tasks.new (
- "mvlbuilders",
- {
+tasks.new {
+ name = "mvlbuilders",
+ arguments = 1,
+ sequence = {
"before", -- for users
"normalizers",
"after", -- for users
}
-)
+}
-tasks.new (
- "vboxbuilders",
- {
+tasks.new {
+ name = "vboxbuilders",
+ arguments = 5,
+ sequence = {
"before", -- for users
"normalizers",
"after", -- for users
}
-)
+}
---~ tasks.new (
---~ "parbuilders",
---~ {
+--~ tasks.new {
+--~ name = "parbuilders",
+--~ arguments = 1,
+--~ sequence = {
--~ "before", -- for users
--~ "lists",
--~ "after", -- for users
--~ }
---~ )
+--~ }
---~ tasks.new (
---~ "pagebuilders",
---~ {
+--~ tasks.new {
+--~ name = "pagebuilders",
+--~ arguments = 5,
+--~ sequence = {
--~ "before", -- for users
--~ "lists",
--~ "after", -- for users
--~ }
---~ )
+--~ }