summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/core-uti.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
committerTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
commitd7ccb42582f85acf30568913610ccf4d602023fb (patch)
tree7292e3545a420676878e7451b68892d360c62cb6 /Master/texmf-dist/tex/context/base/core-uti.lua
parent2d62a6fe9b80def59c392268022f1f9a2d6e358f (diff)
commit context 2011.05.18
git-svn-id: svn://tug.org/texlive/trunk@22719 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/core-uti.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/core-uti.lua224
1 files changed, 77 insertions, 147 deletions
diff --git a/Master/texmf-dist/tex/context/base/core-uti.lua b/Master/texmf-dist/tex/context/base/core-uti.lua
index 01fd8522b10..02411f13d99 100644
--- a/Master/texmf-dist/tex/context/base/core-uti.lua
+++ b/Master/texmf-dist/tex/context/base/core-uti.lua
@@ -17,14 +17,25 @@ utility file under different setups, we now load a table once. This
saves much runtime but at the cost of more memory usage.</p>
--ldx]]--
-local sort, concat, format, match = table.sort, table.concat, string.format, string.match
+local format, match = string.format, string.match
local next, type, tostring = next, type, tostring
-local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes
-if not jobs then jobs = { } end
-if not job then jobs['main'] = { } end job = jobs['main']
+local definetable = utilities.tables.definetable
+local accesstable = utilities.tables.accesstable
+local serialize = table.serialize
+local packers = utilities.packers
+local allocate = utilities.storage.allocate
+local mark = utilities.storage.mark
-jobs.version = 1.10
+local report_jobcontrol = logs.reporter("jobcontrol")
+
+job = job or { }
+local job = job
+
+job.version = 1.14
+
+-- some day we will implement loading of other jobs and then we need
+-- job.jobs
--[[ldx--
<p>Variables are saved using in the previously defined table and passed
@@ -38,151 +49,63 @@ function job.comment(str)
comment[#comment+1] = str
end
-job.comment(format("version: %1.2f",jobs.version))
+job.comment(format("version: %1.2f",job.version))
function job.initialize(loadname,savename)
- job.load(loadname)
- main.register_stop_actions(function()
+ job.load(loadname) -- has to come after structure is defined !
+ luatex.registerstopactions(function()
if not status.lasterrorstring or status.lasterrorstring == "" then
job.save(savename)
end
end)
end
-function job.register(...) -- collected, tobesaved, initializer, finalizer
- savelist[#savelist+1] = { ... }
+function job.register(collected, tobesaved, initializer, finalizer)
+ savelist[#savelist+1] = { collected, tobesaved, initializer, finalizer }
end
-- as an example we implement variables
-jobvariables = jobvariables or { }
-jobvariables.collected = jobvariables.collected or { }
-jobvariables.tobesaved = jobvariables.tobesaved or { }
-jobvariables.checksums = jobvariables.checksums or { }
-
-if not jobvariables.checksums.old then jobvariables.checksums.old = md5.HEX("old") end -- used in experiment
-if not jobvariables.checksums.new then jobvariables.checksums.new = md5.HEX("new") end -- used in experiment
-
-job.register('jobvariables.checksums', jobvariables.checksums)
-
-local function initializer()
- local r = jobvariables.collected.randomseed
- if not r then
- r = math.random()
- math.setrandomseedi(r,"initialize")
- else
- math.setrandomseedi(r,"previous run")
- end
- jobvariables.tobesaved.randomseed = r
- for cs, value in next, jobvariables.collected do
- texsprint(ctxcatcodes,format("\\xdef\\%s{%s}",cs,value))
- end
-end
-
-job.register('jobvariables.collected', jobvariables.tobesaved, initializer)
+local tobesaved, collected, checksums = allocate(), allocate(), allocate()
-function jobvariables.save(cs,value)
- jobvariables.tobesaved[cs] = value
-end
+local jobvariables = {
+ collected = collected,
+ tobesaved = tobesaved,
+ checksums = checksums,
+}
--- experiment (bugged: some loop in running)
+job.variables = jobvariables
--- for the moment here, very experimental stuff
+if not checksums.old then checksums.old = md5.HEX("old") end -- used in experiment
+if not checksums.new then checksums.new = md5.HEX("new") end -- used in experiment
-packer = packer or { }
-packer.version = 1.00
+job.register('job.variables.checksums', checksums)
-local function hashed(t)
- local s = { }
- for k, v in next, t do
- if type(v) == "table" then
- s[#s+1] = k.."={"..hashed(v).."}"
- else
- s[#s+1] = k.."="..tostring(v)
- end
- end
- sort(s)
- return concat(s,",")
-end
+local rmethod, rvalue
-local function pack(t,keys,hash,index)
- for k,v in next, t do
- if type(v) == "table" then
- pack(v,keys,hash,index)
- end
- if keys[k] and type(v) == "table" then
- local h = hashed(v)
- local i = hash[h]
- if not i then
- i = #index+1
- index[i] = v
- hash[h] = i
- end
- t[k] = i
- end
- end
-end
-
-local function unpack(t,keys,index)
- for k,v in next, t do
- if keys[k] and type(v) == "number" then
- local iv = index[v]
- if iv then
- v = iv
- t[k] = v
- end
- end
- if type(v) == "table" then
- unpack(v,keys,index)
- end
+local function initializer()
+ tobesaved = jobvariables.tobesaved
+ collected = jobvariables.collected
+ checksums = jobvariables.checksums
+ rvalue = collected.randomseed
+ if not rvalue then
+ rvalue = math.random()
+ math.setrandomseedi(rvalue,"initialize")
+ rmethod = "initialized"
+ else
+ math.setrandomseedi(rvalue,"previous run")
+ rmethod = "resumed"
end
-end
-
-function packer.new(keys,version)
- return {
- version = version or packer.version,
- keys = table.tohash(keys),
- hash = { },
- index = { },
- }
-end
-
-function packer.pack(t,p,shared)
- if shared then
- pack(t,p.keys,p.hash,p.index)
- elseif not t.packer then
- pack(t,p.keys,p.hash,p.index)
- if #p.index > 0 then
- t.packer = {
- version = p.version or packer.version,
- keys = p.keys,
- index = p.index,
- }
- end
- p.hash, p.index = { }, { }
+ tobesaved.randomseed = rvalue
+ for cs, value in next, collected do
+ context.setxvalue(cs,value)
end
end
-function packer.unpack(t,p,shared)
- if shared then
- if p then
- unpack(t,p.keys,p.index)
- end
- else
- local tp = t.packer
- if tp then
- if tp.version == (p and p.version or packer.version) then
- unpack(t,tp.keys,tp.index)
- else
- -- fatal error, wrong version
- end
- t.packer = nil
- end
- end
-end
+job.register('job.variables.collected', tobesaved, initializer)
-function packer.strip(p)
- p.hash = nil
+function jobvariables.save(cs,value)
+ tobesaved[cs] = value
end
local packlist = {
@@ -195,17 +118,17 @@ local packlist = {
"directives",
"specification",
"processors", -- might become key under directives or metadata
--- "references", -- we need to rename of them as only one packs (not structure.lists.references)
+-- "references", -- we need to rename of them as only one packs (not structures.lists.references)
}
-local jobpacker = packer.new(packlist,1.01)
+local jobpacker = packers.new(packlist,1.01)
job.pack = true
-job._save_, job._load_ = { }, { } -- registers timing
+local _save_, _load_ = { }, { } -- registers timing
function job.save(filename)
- statistics.starttiming(job._save_)
+ statistics.starttiming(_save_)
local f = io.open(filename,'w')
if f then
for c=1,#comment do
@@ -219,27 +142,27 @@ function job.save(filename)
finalizer()
end
if job.pack then
- packer.pack(data,jobpacker,true)
+ packers.pack(data,jobpacker,true)
end
- f:write(aux.definetable(target),"\n")
- f:write(table.serialize(data,target,true,true),"\n")
+ f:write(definetable(target),"\n")
+ f:write(serialize(data,target,true,true),"\n")
end
if job.pack then
- packer.strip(jobpacker)
- f:write(table.serialize(jobpacker,"job.packer",true,true),"\n")
+ packers.strip(jobpacker)
+ f:write(serialize(jobpacker,"job.packed",true,true),"\n")
end
f:close()
end
- statistics.stoptiming(job._save_)
+ statistics.stoptiming(_save_)
end
function job.load(filename)
- statistics.starttiming(job._load_)
+ statistics.starttiming(_load_)
local data = io.loaddata(filename)
if data and data ~= "" then
local version = tonumber(match(data,"^-- version: ([%d%.]+)"))
- if version ~= jobs.version then
- logs.report("job","version mismatch with jobfile: %s <> %s", version or "?", jobs.version)
+ if version ~= job.version then
+ report_jobcontrol("version mismatch with jobfile: %s <> %s", version or "?", job.version)
else
local data = loadstring(data)
if data then
@@ -248,26 +171,27 @@ function job.load(filename)
for l=1,#savelist do
local list = savelist[l]
local target, initializer = list[1], list[3]
- packer.unpack(aux.accesstable(target),job.packer,true)
+ local result = mark(accesstable(target))
+ packers.unpack(result,job.packed,true)
if type(initializer) == "function" then
- initializer(aux.accesstable(target))
+ initializer(result)
end
end
- job.packer = nil
+ job.packed = nil
end
end
- statistics.stoptiming(job._load_)
+ statistics.stoptiming(_load_)
end
-- eventually this will end up in strc-ini
statistics.register("startup time", function()
- return statistics.elapsedseconds(ctx,"including runtime option file processing")
+ return statistics.elapsedseconds(statistics,"including runtime option file processing")
end)
statistics.register("jobdata time",function()
- if statistics.elapsedindeed(job._save_) or statistics.elapsedindeed(job._load_) then
- return format("%s seconds saving, %s seconds loading", statistics.elapsedtime(job._save_), statistics.elapsedtime(job._load_))
+ if statistics.elapsedindeed(_save_) or statistics.elapsedindeed(_load_) then
+ return format("%s seconds saving, %s seconds loading", statistics.elapsedtime(_save_), statistics.elapsedtime(_load_))
end
end)
@@ -281,6 +205,12 @@ statistics.register("callbacks", function()
end
end)
+statistics.register("randomizer", function()
+ if rmethod and rvalue then
+ return format("%s with value %s",rmethod,rvalue)
+ end
+end)
+
function statistics.formatruntime(runtime)
local shipped = tex.count['nofshipouts']
local pages = tex.count['realpageno'] - 1