summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/core-uti.lua
diff options
context:
space:
mode:
authorMojca Miklavec <mojca.miklavec@gmail.com>2014-05-05 20:29:55 +0000
committerMojca Miklavec <mojca.miklavec@gmail.com>2014-05-05 20:29:55 +0000
commitba9a57343987f1c2c72396e7c38f1fa30352c24c (patch)
tree66a8b12cdf67427ce96770fd0e9e581759aade1c /Master/texmf-dist/tex/context/base/core-uti.lua
parent15242121b8ddf7d4a041fb3998d295dd8232e1eb (diff)
ConTeXt 2014.04.28 23:24
git-svn-id: svn://tug.org/texlive/trunk@33856 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.lua113
1 files changed, 88 insertions, 25 deletions
diff --git a/Master/texmf-dist/tex/context/base/core-uti.lua b/Master/texmf-dist/tex/context/base/core-uti.lua
index 96ccdca4809..1903ad8236b 100644
--- a/Master/texmf-dist/tex/context/base/core-uti.lua
+++ b/Master/texmf-dist/tex/context/base/core-uti.lua
@@ -20,7 +20,6 @@ saves much runtime but at the cost of more memory usage.</p>
local format, match = string.format, string.match
local next, type, tostring = next, type, tostring
local concat = table.concat
-local texcount = tex.count
local definetable = utilities.tables.definetable
local accesstable = utilities.tables.accesstable
@@ -30,13 +29,15 @@ local packers = utilities.packers
local allocate = utilities.storage.allocate
local mark = utilities.storage.mark
+local texgetcount = tex.getcount
+
local report_passes = logs.reporter("job","passes")
job = job or { }
local job = job
-job.version = 1.22 -- make sure we don't have old lua 5.1 hash leftovers
-job.packversion = 1.02 -- make sure we don't have old lua 5.1 hash leftovers
+job.version = 1.25
+job.packversion = 1.02
-- some day we will implement loading of other jobs and then we need
-- job.jobs
@@ -50,7 +51,13 @@ directly access the variable using a <l n='lua'/> call.</p>
local savelist, comment = { }, { }
function job.comment(key,value)
- comment[key] = value
+ if type(key) == "table" then
+ for k, v in next, key do
+ comment[k] = v
+ end
+ else
+ comment[key] = value
+ end
end
job.comment("version",job.version)
@@ -72,8 +79,8 @@ function job.initialize(loadname,savename)
end)
end
-function job.register(collected, tobesaved, initializer, finalizer)
- savelist[#savelist+1] = { collected, tobesaved, initializer, finalizer }
+function job.register(collected, tobesaved, initializer, finalizer, serializer)
+ savelist[#savelist+1] = { collected, tobesaved, initializer, finalizer, serializer }
end
-- as an example we implement variables
@@ -86,19 +93,24 @@ local jobvariables = {
checksums = checksums,
}
+-- 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
+
job.variables = jobvariables
-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
+local function initializer()
+ checksums = jobvariables.checksums
+end
-job.register('job.variables.checksums', checksums)
+job.register('job.variables.checksums', 'job.variables.checksums', initializer)
local rmethod, rvalue
+local ctx_setxvalue = context.setxvalue
+
local function initializer()
tobesaved = jobvariables.tobesaved
collected = jobvariables.collected
- checksums = jobvariables.checksums
rvalue = collected.randomseed
if not rvalue then
rvalue = math.random()
@@ -110,7 +122,7 @@ local function initializer()
end
tobesaved.randomseed = rvalue
for cs, value in next, collected do
- context.setxvalue(cs,value)
+ ctx_setxvalue(cs,value)
end
end
@@ -120,6 +132,26 @@ function jobvariables.save(cs,value)
tobesaved[cs] = value
end
+function jobvariables.restore(cs)
+ return collected[cs] or tobesaved[cs]
+end
+
+-- checksums
+
+function jobvariables.getchecksum(tag)
+ return checksums[tag] -- no default
+end
+
+function jobvariables.makechecksum(data)
+ return data and md5.HEX(data) -- no default
+end
+
+function jobvariables.setchecksum(tag,checksum)
+ checksums[tag] = checksum
+end
+
+--
+
local packlist = {
"numbers",
"metadata",
@@ -138,7 +170,7 @@ local jobpacker = packers.new(packlist,job.packversion) -- jump number when chan
job.pack = true
-- job.pack = false
-directives.register("job.pack",function(v) pack = v end)
+directives.register("job.pack",function(v) job.pack = v end)
local _save_, _load_, _others_ = { }, { }, { } -- registers timing
@@ -147,12 +179,17 @@ function job.save(filename) -- we could return a table but it can get pretty lar
local f = io.open(filename,'w')
if f then
f:write("local utilitydata = { }\n\n")
- f:write(serialize(comment,"utilitydata.comment",true,true),"\n\n")
+ f:write(serialize(comment,"utilitydata.comment",true),"\n\n")
for l=1,#savelist do
- local list = savelist[l]
- local target = format("utilitydata.%s",list[1])
- local data = list[2]
- local finalizer = list[4]
+ -- f:write("do\n\n") -- no solution for the jit limitatione either
+ local list = savelist[l]
+ local target = format("utilitydata.%s",list[1])
+ local data = list[2]
+ local finalizer = list[4]
+ local serializer = list[5]
+ if type(data) == "string" then
+ data = utilities.tables.accesstable(data)
+ end
if type(finalizer) == "function" then
finalizer()
end
@@ -160,11 +197,18 @@ function job.save(filename) -- we could return a table but it can get pretty lar
packers.pack(data,jobpacker,true)
end
local definer, name = definetable(target,true,true) -- no first and no last
- f:write(definer,"\n\n",serialize(data,name,true,true),"\n\n")
+ if serializer then
+ f:write(definer,"\n\n",serializer(data,name,true),"\n\n")
+ else
+ f:write(definer,"\n\n",serialize(data,name,true),"\n\n")
+ end
+ -- f:write("end\n\n")
end
if job.pack then
packers.strip(jobpacker)
- f:write(serialize(jobpacker,"utilitydata.job.packed",true,true),"\n\n")
+ -- f:write("do\n\n")
+ f:write(serialize(jobpacker,"utilitydata.job.packed",true),"\n\n")
+ -- f:write("end\n\n")
end
f:write("return utilitydata")
f:close()
@@ -185,8 +229,9 @@ local function load(filename)
return data
end
else
- os.remove(filename) -- probably a bad file
- report_passes("removing stale job data file %a, restart job",filename)
+ os.remove(filename) -- probably a bad file (or luajit overflow as it cannot handle large tables well)
+ report_passes("removing stale job data file %a, restart job, message: %s%s",filename,tostring(data),
+ jit and " (try luatex instead of luajittex)" or "")
os.exit(true) -- trigger second run
end
end
@@ -262,7 +307,7 @@ end)
statistics.register("callbacks", function()
local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
- local pages = texcount['realpageno'] - 1
+ local pages = texgetcount('realpageno') - 1
if pages > 1 then
return format("direct: %s, indirect: %s, total: %s (%i per page)", total-indirect, indirect, total, total/pages)
else
@@ -276,19 +321,37 @@ statistics.register("randomizer", function()
end
end)
+-- a sort of joke (for ctx meeting)
+
+local kg_per_watt_per_second = 1 / 15000000
+local watts_per_core = 50
+local speedup_by_other_engine = 1.2
+local used_wood_factor = watts_per_core * kg_per_watt_per_second / speedup_by_other_engine
+local used_wood_factor = (50 / 15000000) / 1.2
+
function statistics.formatruntime(runtime)
if not environment.initex then -- else error when testing as not counters yet
- local shipped = texcount['nofshipouts']
- local pages = texcount['realpageno']
+ local shipped = texgetcount('nofshipouts')
+ local pages = texgetcount('realpageno')
if pages > shipped then
pages = shipped
end
if shipped > 0 or pages > 0 then
local persecond = shipped / runtime
if pages == 0 then pages = shipped end
- return format("%s seconds, %i processed pages, %i shipped pages, %.3f pages/second",runtime,pages,shipped,persecond)
+ -- if jit then
+ -- local saved = watts_per_core * runtime * kg_per_watt_per_second / speedup_by_other_engine
+ -- local saved = used_wood_factor * runtime
+ -- return format("%s seconds, %i processed pages, %i shipped pages, %.3f pages/second, %f mg tree saved by using luajittex",runtime,pages,shipped,persecond,saved*1000*1000)
+ -- else
+ return format("%s seconds, %i processed pages, %i shipped pages, %.3f pages/second",runtime,pages,shipped,persecond)
+ -- end
else
return format("%s seconds",runtime)
end
end
end
+
+
+commands.savevariable = job.variables.save
+commands.setjobcomment = job.comment