summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/mlib-ctx.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/mlib-ctx.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/mlib-ctx.lua87
1 files changed, 55 insertions, 32 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/mlib-ctx.lua b/Master/texmf-dist/tex/context/base/mkiv/mlib-ctx.lua
index 89f2fa0eeb1..c568b92a3f1 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/mlib-ctx.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/mlib-ctx.lua
@@ -11,29 +11,46 @@ local format, concat = string.format, table.concat
local settings_to_hash = utilities.parsers.settings_to_hash
local formatters = string.formatters
-local report_metapost = logs.reporter ("metapost")
-local status_metapost = logs.messenger("metapost")
+local report_metapost = logs.reporter("metapost")
-local starttiming = statistics.starttiming
-local stoptiming = statistics.stoptiming
+local starttiming = statistics.starttiming
+local stoptiming = statistics.stoptiming
-local trace_graphic = false
+local mplib = mplib
-trackers.register("metapost.graphics",
- function(v) trace_graphic = v end
-);
+metapost = metapost or { }
+local metapost = metapost
+local context = context
-local mplib = mplib
+local setters = tokens.setters
+local setmacro = setters.macro
+local implement = interfaces.implement
-metapost = metapost or { }
-local metapost = metapost
-local context = context
+local v_no = interfaces.variables.no
-local setters = tokens.setters
-local setmacro = setters.macro
-local implement = interfaces.implement
+metapost.defaultformat = "metafun"
+metapost.defaultinstance = "metafun"
+metapost.defaultmethod = "default"
-local v_no = interfaces.variables.no
+local function setmpsformat(specification)
+ local instance = specification.instance
+ local format = specification.format
+ local method = specification.method
+ if not instance or instance == "" then
+ instance = metapost.defaultinstance
+ specification.instance = instance
+ end
+ if not format or format == "" then
+ format = metapost.defaultformat
+ specification.format = format
+ end
+ if not method or method == "" then
+ method = metapost.defaultmethod
+ specification.method = method
+ end
+ specification.mpx = metapost.format(instance,format,method)
+ return specification
+end
local extensiondata = metapost.extensiondata or storage.allocate { }
metapost.extensiondata = extensiondata
@@ -79,6 +96,9 @@ implement {
arguments = "string"
}
+local report_metapost = logs.reporter ("metapost")
+local status_metapost = logs.messenger("metapost")
+
local patterns = {
"meta-imp-%s.mkiv",
"meta-imp-%s.tex",
@@ -172,9 +192,7 @@ implement {
-- or just move the scanners to pps
function metapost.graphic(specification)
- metapost.pushformat(specification)
- metapost.graphic_base_pass(specification)
- metapost.popformat()
+ metapost.graphic_base_pass(setmpsformat(specification))
end
function metapost.startgraphic(t)
@@ -190,6 +208,9 @@ function metapost.startgraphic(t)
if not t.method then
t.method = metapost.defaultmethod
end
+ if not t.definitions then
+ t.definitions = ""
+ end
t.data = { }
return t
end
@@ -197,10 +218,8 @@ end
function metapost.stopgraphic(t)
if t then
t.data = concat(t.data or { },"\n")
- if trace_graphic then
- report_metapost("\n"..t.data.."\n")
- end
metapost.graphic(t)
+ t.data = ""
end
end
@@ -246,7 +265,8 @@ implement {
}
function metapost.getclippath(specification) -- why not a special instance for this
- local mpx = metapost.pushformat(specification)
+ setmpsformat(specification)
+ local mpx = specification.mpx
local data = specification.data or ""
if mpx and data ~= "" then
starttiming(metapost)
@@ -265,10 +285,7 @@ function metapost.getclippath(specification) -- why not a special instance for t
result = metapost.filterclippath(result)
end
stoptiming(metapost)
- metapost.pushformat()
return result
- else
- metapost.pushformat()
end
end
@@ -320,17 +337,23 @@ implement {
}
}
-statistics.register("metapost", function()
+statistics.register("metapost processing time", function()
local n = metapost.n
if n and n > 0 then
+ local nofconverted = metapost.makempy.nofconverted
local elapsedtime = statistics.elapsedtime
- local elapsed = statistics.elapsed
- local instances,
- memory = metapost.getstatistics(true)
- return format("%s seconds, loading: %s, execution: %s, n: %s, average: %s, instances: %i, luacalls: %i, memory: %0.3f M",
+ local elapsed = statistics.elapsed
+ local instances, memory = metapost.getstatistics(true)
+ local str = format("%s seconds, loading: %s, execution: %s, n: %s, average: %s, instances: %i, memory: %0.3f M",
elapsedtime(metapost), elapsedtime(mplib), elapsedtime(metapost.exectime), n,
elapsedtime((elapsed(metapost) + elapsed(mplib) + elapsed(metapost.exectime)) / n),
- instances, metapost.nofscriptruns(),memory/(1024*1024))
+ instances, memory/(1024*1024))
+ if nofconverted > 0 then
+ return format("%s, external: %s (%s calls)",
+ str, elapsedtime(metapost.makempy), nofconverted)
+ else
+ return str
+ end
else
return nil
end