summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/luat-sto.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/luat-sto.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/luat-sto.lua118
1 files changed, 57 insertions, 61 deletions
diff --git a/Master/texmf-dist/tex/context/base/luat-sto.lua b/Master/texmf-dist/tex/context/base/luat-sto.lua
index 08da735db31..946ce375607 100644
--- a/Master/texmf-dist/tex/context/base/luat-sto.lua
+++ b/Master/texmf-dist/tex/context/base/luat-sto.lua
@@ -6,96 +6,86 @@ if not modules then modules = { } end modules ['luat-sto'] = {
license = "see context related readme files"
}
-local type, next = type, next
+local type, next, setmetatable, getmetatable = type, next, setmetatable, getmetatable
local gmatch, format, write_nl = string.gmatch, string.format, texio.write_nl
+local serialize, concat = table.serialize, table.concat
+local bytecode = lua.bytecode
+
+local report_storage = logs.reporter("system","storage")
storage = storage or { }
+local storage = storage
+
+local data = { }
+storage.data = data
+
+local evaluators = { }
+storage.evaluators = evaluators
+
storage.min = 0 -- 500
storage.max = storage.min - 1
storage.noftables = storage.noftables or 0
storage.nofmodules = storage.nofmodules or 0
-storage.data = { }
-storage.evaluators = { }
-local evaluators = storage.evaluators -- (evaluate,message,names)
-local data = storage.data
+storage.mark = utilities.storage.mark
+storage.allocate = utilities.storage.allocate
+storage.marked = utilities.storage.marked
function storage.register(...)
- data[#data+1] = { ... }
-end
-
--- evaluators .. messy .. to be redone
-
-function storage.evaluate(name)
- evaluators[#evaluators+1] = name
-end
-
-function storage.finalize() -- we can prepend the string with "evaluate:"
- for i=1,#evaluators do
- local t = evaluators[i]
- for i, v in next, t do
- local tv = type(v)
- if tv == "string" then
- t[i] = loadstring(v)()
- elseif tv == "table" then
- for _, vv in next, v do
- if type(vv) == "string" then
- t[i] = loadstring(vv)()
- end
- end
- elseif tv == "function" then
- t[i] = v()
- end
- end
+ local t = { ... }
+ local d = t[2]
+ if d then
+ storage.mark(d)
+ else
+ report_storage("fatal error: invalid storage '%s'",t[1])
+ os.exit()
end
+ data[#data+1] = t
+ return t
end
-function storage.dump()
+local function dump()
+ local max = storage.max
for i=1,#data do
local d = data[i]
- local message, original, target, evaluate = d[1], d[2] ,d[3] ,d[4]
- local name, initialize, finalize, code = nil, "", "", ""
+ local message, original, target = d[1], d[2] ,d[3]
+ local c, code, name = 0, { }, nil
for str in gmatch(target,"([^%.]+)") do
if name then
name = name .. "." .. str
else
name = str
end
- initialize = format("%s %s = %s or {} ", initialize, name, name)
- end
- if evaluate then
- finalize = "storage.evaluate(" .. name .. ")"
+ c = c + 1 ; code[c] = format("%s = %s or { }",name,name)
end
- storage.max = storage.max + 1
+ max = max + 1
if trace_storage then
- logs.report('storage','saving %s in slot %s',message,storage.max)
- code =
- initialize ..
- format("logs.report('storage','restoring %s from slot %s') ",message,storage.max) ..
- table.serialize(original,name) ..
- finalize
- else
- code = initialize .. table.serialize(original,name) .. finalize
+ report_storage('saving %s in slot %s',message,max)
+ c = c + 1 ; code[c] = format("report_storage('restoring %s from slot %s')",message,max)
end
- lua.bytecode[storage.max] = loadstring(code)
+ c = c + 1 ; code[c] = serialize(original,name)
+ bytecode[max] = loadstring(concat(code,"\n"))
collectgarbage("step")
end
+ storage.max = max
end
+lua.registerfinalizer(dump,"dump storage")
+
-- we also need to count at generation time (nicer for message)
-if lua.bytecode then -- from 0 upwards
- local i, b = storage.min, lua.bytecode
- while b[i] do
- storage.noftables = i
- b[i]()
- b[i] = nil
- i = i + 1
- end
-end
+--~ if lua.bytecode then -- from 0 upwards
+--~ local i, b = storage.min, lua.bytecode
+--~ while b[i] do
+--~ storage.noftables = i
+--~ b[i]()
+--~ b[i] = nil
+--~ i = i + 1
+--~ end
+--~ end
statistics.register("stored bytecode data", function()
- local modules = (storage.nofmodules > 0 and storage.nofmodules) or (status.luabytecodes - 500)
+ local modules = (storage.nofmodules > 0 and storage.nofmodules) or (status.luabytecodes - lua.firstbytecode - 1)
local dumps = (storage.noftables > 0 and storage.noftables) or storage.max-storage.min + 1
return format("%s modules, %s tables, %s chunks",modules,dumps,modules+dumps)
end)
@@ -104,9 +94,7 @@ if lua.bytedata then
storage.register("lua/bytedata",lua.bytedata,"lua.bytedata")
end
--- wrong place, kind of forward reference
-
-function statistics.report_storage(whereto)
+function statistics.reportstorage(whereto)
whereto = whereto or "term and log"
write_nl(whereto," ","stored tables:"," ")
for k,v in table.sortedhash(storage.data) do
@@ -133,3 +121,11 @@ storage.shared = storage.shared or { }
-- (non table) values.
storage.register("storage/shared", storage.shared, "storage.shared")
+
+local mark = storage.mark
+
+if string.patterns then mark(string.patterns) end
+if lpeg.patterns then mark(lpeg.patterns) end
+if os.env then mark(os.env) end
+if number.dimenfactors then mark(number.dimenfactors) end
+if libraries then for k,v in next, libraries do mark(v) end end