From 89f7bbac9616406b3990b8608c17c542f5fb476d Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Mon, 24 Aug 2020 20:03:53 +0200 Subject: 2020-08-24 19:49:00 --- tex/context/base/mkii/cont-new.mkii | 2 +- tex/context/base/mkii/context.mkii | 2 +- tex/context/base/mkii/mult-en.mkii | 1 + tex/context/base/mkii/mult-nl.mkii | 2 + tex/context/base/mkiv/back-ini.lua | 4 +- tex/context/base/mkiv/back-out.lmt | 4 +- tex/context/base/mkiv/blob-ini.lmt | 210 +++++++++ tex/context/base/mkiv/blob-ini.lua | 12 +- tex/context/base/mkiv/blob-ini.mkiv | 11 +- tex/context/base/mkiv/blob-ini.mkxl | 56 +++ tex/context/base/mkiv/cldf-lmt.lmt | 8 +- tex/context/base/mkiv/cont-new.mkiv | 2 +- tex/context/base/mkiv/cont-run.lua | 40 +- tex/context/base/mkiv/context.mkiv | 6 +- tex/context/base/mkiv/context.mkxl | 6 +- tex/context/base/mkiv/core-uti.lua | 82 ++-- tex/context/base/mkiv/file-job.lua | 6 +- tex/context/base/mkiv/file-mod.lua | 104 +++-- tex/context/base/mkiv/font-map.lua | 1 + tex/context/base/mkiv/l-lua.lua | 6 - tex/context/base/mkiv/lang-rep.lua | 24 +- tex/context/base/mkiv/luat-cnf.lua | 94 ++-- tex/context/base/mkiv/luat-cod.lmt | 49 +- tex/context/base/mkiv/luat-cod.lua | 26 +- tex/context/base/mkiv/luat-fmt.lua | 4 +- tex/context/base/mkiv/luat-lib.mkiv | 2 +- tex/context/base/mkiv/luat-run.lua | 8 +- tex/context/base/mkiv/luat-sto.lua | 9 +- tex/context/base/mkiv/mlib-ctx.lua | 5 +- tex/context/base/mkiv/mlib-mpf.lua | 18 +- tex/context/base/mkiv/mtx-context-timing.tex | 23 +- tex/context/base/mkiv/node-gcm.lmt | 5 + tex/context/base/mkiv/node-ini.mkiv | 2 +- tex/context/base/mkiv/node-ltp.lua | 2 +- tex/context/base/mkiv/node-nut.lua | 12 + tex/context/base/mkiv/node-snp.lmt | 61 +++ tex/context/base/mkiv/node-tra.lua | 14 +- tex/context/base/mkiv/page-run.lua | 36 +- tex/context/base/mkiv/page-run.mkiv | 6 - tex/context/base/mkiv/status-files.pdf | Bin 28129 -> 28127 bytes tex/context/base/mkiv/status-lua.pdf | Bin 255169 -> 255953 bytes tex/context/base/mkiv/strc-itm.mklx | 2 +- tex/context/base/mkiv/strc-itm.mkvi | 2 +- tex/context/base/mkiv/syst-ini.mkxl | 18 +- tex/context/base/mkiv/toks-ini.lua | 1 + tex/context/base/mkiv/toks-scn.lua | 3 +- tex/context/base/mkiv/trac-deb.lmt | 519 +++++++++++++++++++++ tex/context/base/mkiv/trac-deb.lua | 100 +--- tex/context/base/mkiv/trac-deb.mkiv | 2 +- tex/context/base/mkiv/trac-inf.lmt | 353 ++++++++++++++ tex/context/base/mkiv/trac-inf.lua | 39 +- tex/context/base/mkiv/trac-tim.lmt | 177 +++++++ tex/context/interface/mkii/keys-en.xml | 1 + tex/context/interface/mkii/keys-nl.xml | 2 + tex/context/modules/mkiv/m-timing.mkxl | 114 +++++ tex/context/modules/mkiv/s-fonts-variable.mkiv | 10 + tex/context/modules/mkiv/s-module-basic.mkiv | 45 +- tex/generic/context/luatex/luatex-fonts-merged.lua | 6 +- 58 files changed, 1932 insertions(+), 427 deletions(-) create mode 100644 tex/context/base/mkiv/blob-ini.lmt create mode 100644 tex/context/base/mkiv/blob-ini.mkxl create mode 100644 tex/context/base/mkiv/node-snp.lmt create mode 100644 tex/context/base/mkiv/trac-deb.lmt create mode 100644 tex/context/base/mkiv/trac-inf.lmt create mode 100644 tex/context/base/mkiv/trac-tim.lmt create mode 100644 tex/context/modules/mkiv/m-timing.mkxl (limited to 'tex') diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index 42229a6b2..71cceb7db 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2020.08.14 18:54} +\newcontextversion{2020.08.24 19:46} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii index 24ad82756..b38af7afc 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2020.08.14 18:54} +\edef\contextversion{2020.08.24 19:46} %D For those who want to use this: diff --git a/tex/context/base/mkii/mult-en.mkii b/tex/context/base/mkii/mult-en.mkii index 14d7555b2..20021c4ea 100644 --- a/tex/context/base/mkii/mult-en.mkii +++ b/tex/context/base/mkii/mult-en.mkii @@ -954,6 +954,7 @@ \setinterfaceconstant{limittext}{limittext} \setinterfaceconstant{line}{line} \setinterfaceconstant{linecorrection}{linecorrection} +\setinterfaceconstant{linedirection}{linedirection} \setinterfaceconstant{lines}{lines} \setinterfaceconstant{list}{list} \setinterfaceconstant{listtext}{listtext} diff --git a/tex/context/base/mkii/mult-nl.mkii b/tex/context/base/mkii/mult-nl.mkii index 0868762e9..287f47814 100644 --- a/tex/context/base/mkii/mult-nl.mkii +++ b/tex/context/base/mkii/mult-nl.mkii @@ -634,6 +634,7 @@ \setinterfaceconstant{afterkey}{natoets} \setinterfaceconstant{aftersection}{nasectie} \setinterfaceconstant{align}{uitlijnen} +\setinterfaceconstant{alignbottom}{alignbottom} \setinterfaceconstant{aligncharacter}{karakteruitlijnen} \setinterfaceconstant{alignmentcharacter}{uitlijnkarakter} \setinterfaceconstant{alignmentleftsample}{alignmentleftsample} @@ -953,6 +954,7 @@ \setinterfaceconstant{limittext}{limiettekst} \setinterfaceconstant{line}{regel} \setinterfaceconstant{linecorrection}{regelcorrectie} +\setinterfaceconstant{linedirection}{regelrichting} \setinterfaceconstant{lines}{regels} \setinterfaceconstant{list}{lijst} \setinterfaceconstant{listtext}{lijsttekst} diff --git a/tex/context/base/mkiv/back-ini.lua b/tex/context/base/mkiv/back-ini.lua index b0af61edc..ca6f6c1e5 100644 --- a/tex/context/base/mkiv/back-ini.lua +++ b/tex/context/base/mkiv/back-ini.lua @@ -207,6 +207,6 @@ implement { -- could also be codeinjections -function backends.noflatelua() - return status.late_callbacks or 0 +function backends.getcallbackstate() + return { count = status.late_callbacks or 0 } end diff --git a/tex/context/base/mkiv/back-out.lmt b/tex/context/base/mkiv/back-out.lmt index 832e93a14..968617ecc 100644 --- a/tex/context/base/mkiv/back-out.lmt +++ b/tex/context/base/mkiv/back-out.lmt @@ -204,8 +204,8 @@ function backends.latelua(current,pos_h,pos_v) -- todo: pass pos_h and pos_v (mo end end -function backends.noflatelua() - return noflatelua +function backends.getcallbackstate() + return { count = noflatelua } end function nodepool.originliteral(str) local t = copynode(literalnode) nodeproperties[t] = { data = str, mode = originliteral_code } return t end diff --git a/tex/context/base/mkiv/blob-ini.lmt b/tex/context/base/mkiv/blob-ini.lmt new file mode 100644 index 000000000..42a18fddd --- /dev/null +++ b/tex/context/base/mkiv/blob-ini.lmt @@ -0,0 +1,210 @@ +if not modules then modules = { } end modules ['blob-ini'] = { + version = 1.001, + comment = "companion to blob-ini.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- This module is just a playground. Occasionally we need to typeset at the lua and and +-- this is one method. In principle we can construct pages this way too which sometimes +-- makes sense in dumb cases. Actually, if one only needs this, one does not really need +-- tex, okay maybe the parbuilder but that one can be simplified as well then. + +-- set fonts, attributes +-- rest already done in packers etc +-- add local par whatsit (or wait till cleaned up) +-- collapse or new pars +-- interline spacing etc + +-- blob.char +-- blob.line +-- blob.paragraph +-- blob.page + +local type, tostring = type, tostring +local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns + +local report_blobs = logs.reporter("blobs") + +local flush_node_list = node.flush_list +local hpack_node_list = node.hpack +----- vpack_node_list = node.vpack +local write_node = node.write + +local typesetters = nodes.typesetters +local tonodes = typesetters.tonodes +local tohpack = typesetters.tohpack +local tovpack = typesetters.tovpack + +local implement = interfaces.implement + +-- provide copies here (nicer for manuals) + +blobs = blobs or { } +local blobs = blobs + +blobs.tonodes = tonodes +blobs.tohpack = tohpack +blobs.tovpack = tovpack + +-- end of helpers + +local newline = lpeg.patterns.newline +local space = lpeg.patterns.spacer +local newpar = (space^0*newline*space^0)^2 + +local ctxtextcapture = lpeg.Ct ( ( space^0 * ( newpar + lpeg.Cs(((space^1/" " + 1)-newpar)^1) ) )^0) + +function blobs.new() + return { + list = { }, + } +end + +function blobs.dispose(t) + local list = t.list + for i=1,#list do + local li = list[i] + local pack = li.pack + if pack then + flush_node_list(pack) + li.pack = nil + end + end +end + +function blobs.append(t,str) -- compare concat and link + local typ = type(str) + local dummy = nil + if typ == "number" then + str = tostring(str) + typ = "string" + end + if typ == "string" then + local pars = lpegmatch(ctxtextcapture,str) + local list = t.list + for p=1,#pars do + local head, tail = tonodes(pars[p],nil,nil) + list[#list+1] = { head = head, tail = tail } + end + end +end + +function blobs.pack(t,how) + local list = t.list + for i=1,#list do + local pack = list[i].pack + if pack then + flush_node_list(node.pack) + end + if how == "vertical" then + -- we need to prepend a local par node + -- list[i].pack = vpack_node_list(list[i].head,"exactly") + report_blobs("vpack not yet supported") + else + list[i].pack = hpack_node_list(list[i].head,"exactly") + end + end +end + +function blobs.write(t) + local list = t.list + for i=1,#list do + local li = list[i] + local pack = li.pack + if pack then + write_node(pack) + flush_node_list(pack) + li.pack = nil + end + end +end + +function blobs.dimensions(t) + local list = t.list + local first = list and list[1] + if first then + local pack = first.pack + return pack.width, pack.height, pack.depth + else + return 0, 0, 0 + end +end + +-- blob.char +-- blob.line: head, tail +-- blob.paragraph +-- blob.page + +-- local lineblob = { +-- type = "line", +-- head = false, +-- tail = false, +-- pack = false, +-- properties = { }, +-- end + +-- local parblob = { +-- type = "line", +-- head = false, +-- tail = false, +-- pack = false, +-- properties = { }, +-- end + +-- for the moment here: + +local function strwd(str) + local l = tohpack(str) + local w = l.width + flush_node_list(l) + return w +end + +local function strht(str) + local l = tohpack(str) + local h = l.height + flush_node_list(l) + return h +end + +local function strdp(str) + local l = tohpack(str) + local d = l.depth + flush_node_list(l) + return d +end + +local function strhd(str) + local l = tohpack(str) + local s = l.height + l.depth + flush_node_list(l) + return s +end + +blobs.strwd = strwd +blobs.strht = strht +blobs.strdp = strdp +blobs.strhd = strhd + +-- upgraded + +local dimension_code = tokens.values.dimension +local scan_hbox = tokens.scanners.hbox + +local function action(field,what) + local l = scan_hbox() + local d = l[field] + flush_node_list(l) + if what == "value" then + return dimension_code, d + else + context("%p",d) + end +end + +implement { name = "widthofstring", public = true, usage = "value", actions = function(w) return action("width", w) end } +implement { name = "heightofstring", public = true, usage = "value", actions = function(w) return action("height",w) end } +implement { name = "depthofstring", public = true, usage = "value", actions = function(w) return action("depth", w) end } +implement { name = "totalofstring", public = true, usage = "value", actions = function(w) return action("total", w) end } diff --git a/tex/context/base/mkiv/blob-ini.lua b/tex/context/base/mkiv/blob-ini.lua index f825b7aa3..0b35c3b65 100644 --- a/tex/context/base/mkiv/blob-ini.lua +++ b/tex/context/base/mkiv/blob-ini.lua @@ -188,7 +188,11 @@ blobs.strht = strht blobs.strdp = strdp blobs.strhd = strhd -implement { name = "strwd", arguments = "string", actions = { strwd, context } } -implement { name = "strht", arguments = "string", actions = { strht, context } } -implement { name = "strdp", arguments = "string", actions = { strdp, context } } -implement { name = "strhd", arguments = "string", actions = { strhd, context } } +-- upgraded + +local scan_hbox = tokens.scanners.hbox + +implement { name = "strwd", actions = function() local l = scan_hbox() context(l.width) flush_node_list(l) end } +implement { name = "strht", actions = function() local l = scan_hbox() context(l.height) flush_node_list(l) end } +implement { name = "strdp", actions = function() local l = scan_hbox() context(l.depth) flush_node_list(l) end } +implement { name = "strhd", actions = function() local l = scan_hbox() context(l.height + l.depth) flush_node_list(l) end } diff --git a/tex/context/base/mkiv/blob-ini.mkiv b/tex/context/base/mkiv/blob-ini.mkiv index 3cee3ff2f..dd33087f2 100644 --- a/tex/context/base/mkiv/blob-ini.mkiv +++ b/tex/context/base/mkiv/blob-ini.mkiv @@ -32,12 +32,13 @@ \def\dpofstring#1{\dimexpr\clf_strdp{#1}\scaledpoint\relax} \def\hdofstring#1{\dimexpr\clf_strhd{#1}\scaledpoint\relax} -\def\widthofstring {\the\wdofstring} -\def\heightofstring {\the\htofstring} -\def\depthofstring {\the\dpofstring} -\def\heightanddepthofstring{\the\hdofstring} +\def\widthofstring {\the\wdofstring} +\def\heightofstring {\the\htofstring} +\def\depthofstring {\the\dpofstring} +\def\totalofstring {\the\hdofstring} -\let\htdpofstring \hdofstring +\let\heightanddepthofstring\totalofstring +\let\htdpofstring \hdofstring \let\hd\htdp % if yes then move this diff --git a/tex/context/base/mkiv/blob-ini.mkxl b/tex/context/base/mkiv/blob-ini.mkxl new file mode 100644 index 000000000..126319b12 --- /dev/null +++ b/tex/context/base/mkiv/blob-ini.mkxl @@ -0,0 +1,56 @@ +%D \module +%D [ file=blob-ini, +%D version=2010.04.06, +%D title=\CONTEXT\ \LUA\ Typesetting, +%D subtitle=Initialization, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt Lua Typesetting / Initialization} + +%D This is a prelude to typesetting at the \LUA\ end. The code +%D is already quite old but will only get nice when we are further +%D down the road (close to version 1.00 of \LUATEX). Typesetting in +%D pure \LUA\ sometimes makes sense. + +\registerctxluafile{node-typ}{} % experimental +\registerctxluafile{blob-ini}{autosuffix} + +\unprotect + +% \widthofstring % defined in lua +% \heightofstring % defined in lua +% \depthofstring % defined in lua +% \heightanddepthofstring % defined in lua + +\def\wdofstring#1{\dimexpr\widthofstring {#1}\relax} % assured an dimen +\def\htofstring#1{\dimexpr\heightofstring{#1}\relax} % assured an dimen +\def\dpofstring#1{\dimexpr\depthofstring {#1}\relax} % assured an dimen +\def\hdofstring#1{\dimexpr\totalofstring {#1}\relax} % assured an dimen + +\let\heightanddepthofstring\totalofstring +\let\htdpofstring \hdofstring + +\let\hd\htdp % if yes then move this + +% This one takes anything that can be typeset + +\unexpanded\def\setwidthof#1\to#2{\edef#2{\widthofstring{#1}}} + +\protect \endinput + +% \starttext +% +% \startluacode +% local b = blobs.new() +% blobs.append(b,"Hello world.\n Here we are.\n\n And Again!") +% blobs.pack(b) +% blobs.write(b) +% \stopluacode +% +% \stoptext diff --git a/tex/context/base/mkiv/cldf-lmt.lmt b/tex/context/base/mkiv/cldf-lmt.lmt index 6a9353d2e..c60c75deb 100644 --- a/tex/context/base/mkiv/cldf-lmt.lmt +++ b/tex/context/base/mkiv/cldf-lmt.lmt @@ -934,10 +934,10 @@ interfaces.implement { local escape = function(s) return "\\" .. byte(s) end interfaces.implement { - name = "ctxluamatch", - public = true, - value = true, - actions = function() + name = "ctxluamatch", + public = true, + usage = "value", + actions = function() local command = context[scancsname()] local pattern = gsub(scanstring(),"\\.",escape) local input = gsub(scanstring(),"\\.",escape) diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 07f25fd35..2354e1a71 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -13,7 +13,7 @@ % \normalend % uncomment this to get the real base runtime -\newcontextversion{2020.08.14 18:54} +\newcontextversion{2020.08.24 19:46} %D This file is loaded at runtime, thereby providing an excellent place for hacks, %D patches, extensions and new features. There can be local overloads in cont-loc diff --git a/tex/context/base/mkiv/cont-run.lua b/tex/context/base/mkiv/cont-run.lua index c5f9014ff..3fef61672 100644 --- a/tex/context/base/mkiv/cont-run.lua +++ b/tex/context/base/mkiv/cont-run.lua @@ -207,37 +207,6 @@ local preparejob preparejob = function() -- tricky: we need a hook for this } end - -- -- todo: move from mtx-context to here: - -- - -- local timing = arguments.timing - -- if type(timing) == "string" then - -- context.usemodule { timing } - -- end - -- local nodates = arguments.nodates - -- if nodates then - -- context.enabledirectives { "backend.date=" .. (type(nodates) == "string" and nodates or "no") } - -- end - -- local trailerid = arguments.trailerid - -- if type(trailerid) == "string" then - -- context.enabledirectives { "backend.trailerid=" .. trailerid } - -- end - -- local profile = arguments.profile - -- if profile then - -- context.enabledirectives { "system.profile=" .. tonumber(profile) or 0 } - -- end - - -- -- already done in mtxrun / mtx-context, has to happen very early - -- - -- if arguments.silent then - -- directives.enable("logs.blocked",arguments.silent) - -- end - -- - -- -- already done in mtxrun / mtx-context, can as well happen here - -- - -- if arguments.errors then - -- directives.enable("logs.errors",arguments.errors) - -- end - preparejob = function() end job.prepare = preparejob @@ -248,6 +217,8 @@ job.prepare = preparejob local function processjob() + tokens.setters.macro("processjob","") -- make a + environment.initializefilenames() -- todo: check if we really need to pre-prep the filename local arguments = environment.arguments @@ -331,6 +302,13 @@ end implement { name = "processjob", + public = true, onlyonce = true, actions = processjob, } + +if CONTEXTLMTXMODE then + + texconfig.firstline = "\\processjob " -- experiment, yet undocumented + +end diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 6dd323348..79b0987ed 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -45,7 +45,7 @@ %D {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2020.08.14 18:54} +\edef\contextversion{2020.08.24 19:46} %D Kind of special: @@ -194,8 +194,6 @@ \loadmarkfile{trac-tex} \loadmarkfile{trac-deb} % will move up -%loadmarkfile{blob-ini} % not to be used, we only use a helper - \loadmarkfile{supp-box} \loadmarkfile{supp-ran} @@ -428,7 +426,7 @@ \loadmarkfile{spac-chr} % depends on fonts -\loadmarkfile{blob-ini} % not to be used, we only use a helper +\loadmarkfile{blob-ini} \loadmarkfile{trac-vis} \loadmarkfile{trac-jus} diff --git a/tex/context/base/mkiv/context.mkxl b/tex/context/base/mkiv/context.mkxl index 6b02b49c2..4a733dcdb 100644 --- a/tex/context/base/mkiv/context.mkxl +++ b/tex/context/base/mkiv/context.mkxl @@ -29,7 +29,7 @@ %D {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2020.08.14 18:54} +\edef\contextversion{2020.08.24 19:46} %D Kind of special: @@ -177,8 +177,6 @@ \loadmarkfile{trac-tex} \loadmarkfile{trac-deb} % will move up -%loadmarkfile{blob-ini} % not to be used, we only use a helper - \loadmkxlfile{supp-box} % LMTX \loadmarkfile{supp-ran} @@ -413,7 +411,7 @@ \loadmarkfile{spac-chr} % depends on fonts -\loadmarkfile{blob-ini} % not to be used, we only use a helper +\loadmkxlfile{blob-ini} \loadmarkfile{trac-vis} \loadmarkfile{trac-jus} diff --git a/tex/context/base/mkiv/core-uti.lua b/tex/context/base/mkiv/core-uti.lua index 50c7bc9dc..1debf347b 100644 --- a/tex/context/base/mkiv/core-uti.lua +++ b/tex/context/base/mkiv/core-uti.lua @@ -73,10 +73,9 @@ local enabled = true local initialized = false directives.register("job.save",function(v) enabled = v end) -----------.register("job.keep",function(v) kept = v end) -function job.disablesave() -- can be command - enabled = false +function job.disablesave() + enabled = false -- for instance called when an error end function job.initialize(loadname,savename) @@ -89,10 +88,7 @@ function job.initialize(loadname,savename) end job.load(loadname) -- has to come after structure is defined ! luatex.registerstopactions(function() - if enabled and not status.lasterrorstring or status.lasterrorstring == "" then - -- if kept then - -- job.keep(loadname) -- could move to mtx-context instead - -- end + if enabled then job.save(savename) end end) @@ -396,37 +392,53 @@ statistics.register("jobdata time",function() end end) --- statistics.register("callbacks", function() --- local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0 --- 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 --- return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total) --- end --- end) - -function statistics.callbacks() - local c_internal = status.callbacks or 0 - local c_file = status.indirect_callbacks or 0 - local c_direct = status.direct_callbacks or 0 - local c_late = backends.noflatelua() or 0 - local c_function = status.function_callbacks or 0 - local c_total = c_internal + c_file + c_direct + c_late + c_function - local n_pages = texgetcount('realpageno') - 1 - local c_average = n_pages > 0 and math.round(c_total/n_pages) or 0 - local s_result = format ( - c_average > 0 and "internal: %s, file: %s, direct: %s, late: %s, function %s, total: %s (%s per page)" - or "internal: %s, file: %s, direct: %s, late: %s, function %s, total: %s", - c_internal, c_file, c_direct, c_late, c_function, c_total, c_average - ) - statistics.callbacks = function() - return s_result +if CONTEXTLMTXMODE > 0 then + + function statistics.callbacks() + local backend = backends.getcallbackstate() + local frontend = status.getcallbackstate() + local pages = structures.pages.nofpages or 0 + local total = frontend.count + backend.count + local average = pages > 0 and math.round(total/pages) or 0 + local result = format ( + "file: %s, saved: %s, direct: %s, function: %s, value: %s, message: %s, bytecode: %s, late %s, total: %s (%s per page)", + frontend.file, frontend.saved, frontend.direct, frontend["function"], + frontend.value, frontend.message, frontend.bytecode, backend.count, + total, average + ) + statistics.callbacks = function() + return result + end + return result + end + + statistics.register("callbacks", statistics.callbacks) + +else + + function statistics.callbacks() + local c_internal = status.callbacks or 0 + local c_file = status.indirect_callbacks or 0 + local c_direct = status.direct_callbacks or 0 + local c_late = backends.getcallbackstate().count + local c_function = status.function_callbacks or 0 + local c_total = c_internal + c_file + c_direct + c_late + c_function + local n_pages = structures.pages.nofpages or 0 + local c_average = n_pages > 0 and math.round(c_total/n_pages) or 0 + local result = format ( + "internal: %s, file: %s, direct: %s, late: %s, function %s, total: %s (%s per page)", + c_internal, c_file, c_direct, c_late, c_function, c_total, c_average + ) + statistics.callbacks = function() + return result + end + return result end - return s_result + + statistics.register("callbacks", statistics.callbacks) + end -statistics.register("callbacks", statistics.callbacks) statistics.register("randomizer", function() if rmethod and rvalue then diff --git a/tex/context/base/mkiv/file-job.lua b/tex/context/base/mkiv/file-job.lua index 5641d3e15..1197bb1ac 100644 --- a/tex/context/base/mkiv/file-job.lua +++ b/tex/context/base/mkiv/file-job.lua @@ -968,7 +968,11 @@ function document.setcommandline() -- has to happen at the tex end in order to e -- to trick the files table which actually only has one entry in a tex job if arguments.timing then - context.usemodule("timing") + context.usemodule { "timing" } + end + + if arguments.usage then + directives.enable("system.usage") end if arguments.batchmode then diff --git a/tex/context/base/mkiv/file-mod.lua b/tex/context/base/mkiv/file-mod.lua index c10e557c7..d392887ec 100644 --- a/tex/context/base/mkiv/file-mod.lua +++ b/tex/context/base/mkiv/file-mod.lua @@ -111,64 +111,66 @@ local function usemodule(name,hasscheme) end function environment.usemodules(prefix,askedname,truename) - local truename = truename or environment.truefilename(askedname) - local hasprefix = prefix and prefix ~= "" - local hashname = ((hasprefix and prefix) or "*") .. "-" .. truename - local status = modstatus[hashname] or false -- yet unset - if status == 0 then - -- not found - elseif status == 1 then - status = status + 1 - else - if trace_modules then - report("locating, prefix %a, askedname %a, truename %a",prefix,askedname,truename) - end - local hasscheme = url.hasscheme(truename) - if hasscheme then - -- no prefix and suffix done - if usemodule(truename,true) then - status = 1 - else - status = 0 - end - elseif hasprefix then - if usemodule(prefix .. "-" .. truename) then - status = 1 - else - status = 0 - end + local truename = truename or environment.truefilename(askedname) or askedname + if truename and truename ~= "" then + local hasprefix = prefix and prefix ~= "" + local hashname = ((hasprefix and prefix) or "*") .. "-" .. truename + local status = modstatus[hashname] or false -- yet unset + if status == 0 then + -- not found + elseif status == 1 then + status = status + 1 else - for i=1,#prefixes do - -- todo: reconstruct name i.e. basename - local thename = prefixes[i] .. "-" .. truename - if usemodule(thename) then + if trace_modules then + report("locating, prefix %a, askedname %a, truename %a",prefix,askedname,truename) + end + local hasscheme = url.hasscheme(truename) + if hasscheme then + -- no prefix and suffix done + if usemodule(truename,true) then status = 1 - break + else + status = 0 + end + elseif hasprefix then + if usemodule(prefix .. "-" .. truename) then + status = 1 + else + status = 0 end - end - if status then - -- ok, don't change - elseif find(truename,"-",1,true) and usemodule(truename) then - -- assume a user namespace - report("using user prefixed file %a",truename) - status = 1 - elseif permit_unprefixed and usemodule(truename) then - report("using unprefixed file %a",truename) - status = 1 else - status = 0 + for i=1,#prefixes do + -- todo: reconstruct name i.e. basename + local thename = prefixes[i] .. "-" .. truename + if usemodule(thename) then + status = 1 + break + end + end + if status then + -- ok, don't change + elseif find(truename,"-",1,true) and usemodule(truename) then + -- assume a user namespace + report("using user prefixed file %a",truename) + status = 1 + elseif permit_unprefixed and usemodule(truename) then + report("using unprefixed file %a",truename) + status = 1 + else + status = 0 + end end end + if status == 0 then + missing = true + report("%a is not found",askedname) + elseif status == 1 then + report("%a is loaded",trace_modules and truename or askedname) + else + report("%a is already loaded",trace_modules and truename or askedname) + end + modstatus[hashname] = status end - if status == 0 then - missing = true - report("%a is not found",askedname) - elseif status == 1 then - report("%a is loaded",trace_modules and truename or askedname) - else - report("%a is already loaded",trace_modules and truename or askedname) - end - modstatus[hashname] = status end statistics.register("loaded tex modules", function() diff --git a/tex/context/base/mkiv/font-map.lua b/tex/context/base/mkiv/font-map.lua index 990a561f9..c983ea963 100644 --- a/tex/context/base/mkiv/font-map.lua +++ b/tex/context/base/mkiv/font-map.lua @@ -104,6 +104,7 @@ local hash = { } local conc = { } table.setmetatableindex(hash,function(t,k) + local v if k < 0xD7FF or (k > 0xDFFF and k <= 0xFFFF) then v = f_single(k) else diff --git a/tex/context/base/mkiv/l-lua.lua b/tex/context/base/mkiv/l-lua.lua index f411230d4..00989c5ce 100644 --- a/tex/context/base/mkiv/l-lua.lua +++ b/tex/context/base/mkiv/l-lua.lua @@ -195,12 +195,6 @@ function optionalrequire(...) end end --- nice for non ascii scripts (this might move): - -if lua then - lua.mask = load([[τεχ = 1]]) and "utf" or "ascii" -end - local flush = io.flush if flush then diff --git a/tex/context/base/mkiv/lang-rep.lua b/tex/context/base/mkiv/lang-rep.lua index d0f6f6d5f..a48215781 100644 --- a/tex/context/base/mkiv/lang-rep.lua +++ b/tex/context/base/mkiv/lang-rep.lua @@ -40,6 +40,10 @@ local trace_details = false trackers.register("languages.replacements.deta local report_replacement = logs.reporter("languages","replacements") local glyph_code = nodes.nodecodes.glyph +local glue_code = nodes.nodecodes.glue + +local spaceskip_code = nodes.gluecodes.spaceskip +local xspaceskip_code = nodes.gluecodes.xspaceskip local nuts = nodes.nuts @@ -47,6 +51,7 @@ local getnext = nuts.getnext local getprev = nuts.getprev local getattr = nuts.getattr local getid = nuts.getid +local getsubtype = nuts.getsubtype local getchar = nuts.getchar local isglyph = nuts.isglyph @@ -105,7 +110,7 @@ lists[v_reset].attribute = unsetvalue -- so we discard 0 local function add(root,word,replacement) local processor, replacement = splitprocessor(replacement,true) -- no check replacement = lpegmatch(stripper,replacement) or replacement - local list = utfsplit(word,true) + local list = utfsplit(word) -- ,true) local size = #list for i=1,size do local l = utfbyte(list[i]) @@ -169,9 +174,12 @@ local function hit(a,head) local lastfinal = false while current do local char, id = isglyph(current) - -- if not char and id == glue_code then - -- char = " " -- if needed we can also deal with spaces and special nbsp and such - -- end + if not char and id == glue_code then + local s = getsubtype(current) + if s == spaceskip_code or s == xspaceskip_code then + char = 32 -- if needed we can also deal with spaces and special nbsp and such + end + end if char then local newroot = root[char] if not newroot then @@ -288,9 +296,9 @@ function replacements.handler(head) i = i + 1 end flush_list(list) - elseif newlength == 0 then - -- nothing gets replaced - current = getnext(last) + -- elseif newlength == 0 then + -- -- nothing gets replaced + -- current = getnext(last) elseif oldlength == newlength then -- #old == #new if final.word == final.replacement then -- nothing to do but skip @@ -311,7 +319,7 @@ function replacements.handler(head) setchar(current,newcodes[i]) current = getnext(current) end - else -- #old > #new + else -- #old > #new or #new == 0 for i=1,oldlength-newlength do head, current = remove_node(head,current,true) end diff --git a/tex/context/base/mkiv/luat-cnf.lua b/tex/context/base/mkiv/luat-cnf.lua index c9ccc1b90..910ee5989 100644 --- a/tex/context/base/mkiv/luat-cnf.lua +++ b/tex/context/base/mkiv/luat-cnf.lua @@ -19,20 +19,70 @@ texconfig.shell_escape = 't' luatex = luatex or { } local luatex = luatex -texconfig.error_line = 250 -- 79 -- frozen / large values can crash -texconfig.expand_depth = 10000 -texconfig.half_error_line = 125 -- 50 -- frozen -texconfig.hash_extra = 100000 -texconfig.max_in_open = 1000 -- frozen -texconfig.max_print_line = 100000 -- frozen -texconfig.max_strings = 500000 -texconfig.nest_size = 1000 -texconfig.param_size = 25000 -texconfig.save_size = 100000 -texconfig.stack_size = 10000 -texconfig.function_size = 32768 -texconfig.properties_size = 10000 -texconfig.fix_mem_init = 750000 +texconfig.error_line = 250 +texconfig.expand_depth = 10000 +texconfig.half_error_line = 125 +texconfig.max_print_line = 100000 +texconfig.max_strings = 500000 +texconfig.hash_extra = 200000 +texconfig.function_size = 32768 +texconfig.properties_size = 10000 + +if CONTEXTLMTXMODE > 0 then + +texconfig.max_in_open = 2000 +texconfig.nest_size = 10000 +texconfig.param_size = 100000 +texconfig.save_size = 500000 +texconfig.stack_size = 100000 +texconfig.buffer_size = 10000000 +texconfig.token_size = 10000000 +texconfig.node_size = 20000000 + +else + +texconfig.max_in_open = 1000 +texconfig.nest_size = 1000 +texconfig.param_size = 25000 +texconfig.save_size = 100000 +texconfig.stack_size = 10000 +texconfig.buf_size = 10000000 +texconfig.fix_mem_init = 1000000 + +end + +local variablenames = CONTEXTLMTXMODE > 0 and { + error_line = false, + half_error_line = false, + max_print_line = false, + max_in_open = false, + expand_depth = true, + hash_extra = true, + nest_size = true, + max_strings = true, + param_size = true, + save_size = true, + stack_size = true, + function_size = true, + properties_size = true, + token_size = true, + node_size = true, +} or { + error_line = false, + half_error_line = false, + max_print_line = false, + max_in_open = false, + expand_depth = true, + hash_extra = true, + nest_size = true, + max_strings = true, + param_size = true, + save_size = true, + stack_size = true, + function_size = true, + properties_size = true, + fix_mem_init = true, +} local stub = [[ @@ -201,22 +251,6 @@ end) -- done, from now on input and callbacks are internal ]] -local variablenames = { - error_line = false, - half_error_line = false, - max_print_line = false, - max_in_open = false, - expand_depth = true, - hash_extra = true, - nest_size = true, - max_strings = true, - param_size = true, - save_size = true, - stack_size = true, - function_size = true, - properties_size = true, -} - local function makestub() name = name or (environment.jobname .. ".lui") report("creating stub file %a using directives:",name) diff --git a/tex/context/base/mkiv/luat-cod.lmt b/tex/context/base/mkiv/luat-cod.lmt index c7c868f42..802a89fc1 100644 --- a/tex/context/base/mkiv/luat-cod.lmt +++ b/tex/context/base/mkiv/luat-cod.lmt @@ -17,22 +17,27 @@ local texconfig, lua = texconfig, lua -- some basic housekeeping -texconfig.kpse_init = false -texconfig.shell_escape = 't' - -texconfig.error_line = 250 -- 79 -- frozen / large values can crash -texconfig.expand_depth = 10000 -texconfig.half_error_line = 125 -- 50 -- frozen -texconfig.max_in_open = 1000 -texconfig.max_print_line = 100000 -texconfig.max_strings = 500000 -texconfig.nest_size = 1000 -texconfig.param_size = 25000 -texconfig.save_size = 100000 -texconfig.stack_size = 10000 -texconfig.function_size = 32768 -texconfig.properties_size = 10000 -texconfig.fix_mem_init = 750000 +texconfig.kpse_init = false -- not needed in lmtx +texconfig.shell_escape = 't' -- not needed in lmtx + +texconfig.max_in_open = 2000 +texconfig.nest_size = 10000 +texconfig.param_size = 100000 +texconfig.save_size = 500000 +texconfig.stack_size = 100000 +texconfig.buffer_size = 10000000 +texconfig.token_size = 10000000 +texconfig.node_size = 20000000 + +texconfig.max_print_line = 100000 +texconfig.max_strings = 500000 +texconfig.hash_extra = 200000 + +texconfig.expand_depth = 10000 +texconfig.function_size = 32768 +texconfig.properties_size = 10000 +texconfig.error_line = 250 +texconfig.half_error_line = 125 -- registering bytecode chunks @@ -276,3 +281,15 @@ end callback.register('find_log_file', find_log_file) callback.register('find_data_file' , find_data_file ) callback.register('open_data_file' , open_data_file ) + +callback.register("trace_memory", function(what,success) + success = success and "succeeded" or "failed" + if logs then + logs.report("tex memory","bumping category %a %s, details: %s", + what,success,table.sequenced(status["get"..what.."state"]())) + elseif texio then + texio.write_nl(format("bumping tex %a memory %s", + what,success)) + end + -- os.exit() +end) diff --git a/tex/context/base/mkiv/luat-cod.lua b/tex/context/base/mkiv/luat-cod.lua index a2a261866..0b7521180 100644 --- a/tex/context/base/mkiv/luat-cod.lua +++ b/tex/context/base/mkiv/luat-cod.lua @@ -20,19 +20,19 @@ local texconfig, lua = texconfig, lua texconfig.kpse_init = false texconfig.shell_escape = 't' -texconfig.error_line = 250 -- 79 -- frozen / large values can crash -texconfig.expand_depth = 10000 -texconfig.half_error_line = 125 -- 50 -- frozen -texconfig.max_in_open = 1000 -texconfig.max_print_line = 100000 -texconfig.max_strings = 500000 -texconfig.nest_size = 1000 -texconfig.param_size = 25000 -texconfig.save_size = 100000 -texconfig.stack_size = 10000 -texconfig.function_size = 32768 -texconfig.properties_size = 10000 -texconfig.fix_mem_init = 750000 +texconfig.error_line = 250 +texconfig.expand_depth = 10000 +texconfig.half_error_line = 125 +texconfig.max_in_open = 1000 +texconfig.max_print_line = 100000 +texconfig.max_strings = 500000 +texconfig.nest_size = 1000 +texconfig.param_size = 25000 +texconfig.save_size = 100000 +texconfig.stack_size = 10000 +texconfig.function_size = 32768 +texconfig.properties_size = 10000 +texconfig.fix_mem_init = 1000000 -- registering bytecode chunks diff --git a/tex/context/base/mkiv/luat-fmt.lua b/tex/context/base/mkiv/luat-fmt.lua index ab831fafc..815ff10db 100644 --- a/tex/context/base/mkiv/luat-fmt.lua +++ b/tex/context/base/mkiv/luat-fmt.lua @@ -64,7 +64,7 @@ end -- The silent option is for Taco. It's a bit of a hack because we cannot yet mess -- with directives. In fact, I could probably clean up the maker a bit by now. -local template = [[--ini %primaryflags% --lua=%luafile% %texfile% %secondaryflags% %dump% %redirect%]] +local template = [[--ini %primaryflags% --lua=%luafile% %texfile% %secondaryflags% %redirect%]] local checkers = { primaryflags = "verbose", -- "flags" @@ -72,7 +72,6 @@ local checkers = { luafile = "readable", -- "cache" texfile = "readable", -- "cache" redirect = "string", - dump = "string", binarypath = "string", } @@ -193,7 +192,6 @@ function environment.make_format(formatname) secondaryflags = secondaryflags, luafile = quoted(fullluasourcename), texfile = quoted(fulltexsourcename), - dump = os.platform == "unix" and "\\\\dump" or "\\dump", } if silent then specification.redirect = "> temp.log" diff --git a/tex/context/base/mkiv/luat-lib.mkiv b/tex/context/base/mkiv/luat-lib.mkiv index 4d3fd1823..ac60374d0 100644 --- a/tex/context/base/mkiv/luat-lib.mkiv +++ b/tex/context/base/mkiv/luat-lib.mkiv @@ -25,7 +25,7 @@ \registerctxluafile{trac-set}{} \registerctxluafile{trac-log}{} -\registerctxluafile{trac-inf}{} +\registerctxluafile{trac-inf}{autosuffix} \registerctxluafile{util-lua}{} \registerctxluafile{util-deb}{} % could also be done in trac-deb.mkiv diff --git a/tex/context/base/mkiv/luat-run.lua b/tex/context/base/mkiv/luat-run.lua index 305948edb..beec93088 100644 --- a/tex/context/base/mkiv/luat-run.lua +++ b/tex/context/base/mkiv/luat-run.lua @@ -62,7 +62,9 @@ local function stop_run() if trace_tex_status then logs.newline() for k, v in table.sortedhash(status.list()) do - report_tex("%S=%S",k,v) + if type(v) ~= "table" then + report_tex("%S=%S",k,v) + end end end if quit then @@ -125,10 +127,10 @@ appendgroup(wrapupactions,"user") appendgroup(cleanupactions,"system") appendgroup(cleanupactions,"user") -local function wrapup_run() +local function wrapup_run(someerror) local runner = wrapupactions.runner if runner then - runner() + runner(someerror) -- we could use the error flag in lmtx end end diff --git a/tex/context/base/mkiv/luat-sto.lua b/tex/context/base/mkiv/luat-sto.lua index 620de9a15..17290848b 100644 --- a/tex/context/base/mkiv/luat-sto.lua +++ b/tex/context/base/mkiv/luat-sto.lua @@ -111,10 +111,11 @@ function lua.collectgarbage(threshold) end statistics.register("stored bytecode data", function() - local nofmodules = (storage.nofmodules > 0 and storage.nofmodules) or (status.luabytecodes - lua.firstbytecode - 1) - local nofdumps = (storage.noftables > 0 and storage.noftables ) or storage.max-storage.min + 1 - local tofmodules = storage.tofmodules or 0 - local tofdumps = storage.toftables or 0 + local nofbytecodes = CONTEXTLMTXMODE > 0 and status.luastate.bytecodes or status.lua_bytecodes + local nofmodules = (storage.nofmodules > 0 and storage.nofmodules) or (nofbytecodes - lua.firstbytecode - 1) + local nofdumps = (storage.noftables > 0 and storage.noftables ) or storage.max-storage.min + 1 + local tofmodules = storage.tofmodules or 0 + local tofdumps = storage.toftables or 0 if environment.initex then local luautilities = utilities.lua return format("%s modules, %s tables, %s chunks, %s chunks stripped (%s bytes)", diff --git a/tex/context/base/mkiv/mlib-ctx.lua b/tex/context/base/mkiv/mlib-ctx.lua index 0240c6a80..4e3d05654 100644 --- a/tex/context/base/mkiv/mlib-ctx.lua +++ b/tex/context/base/mkiv/mlib-ctx.lua @@ -335,12 +335,13 @@ statistics.register("metapost", function() if n and n > 0 then local elapsedtime = statistics.elapsedtime local elapsed = statistics.elapsed + local runs, stats = metapost.nofscriptruns() 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", + return format("%s seconds, loading: %s, execution: %s, n: %s, average: %s, instances: %i, luacalls: %s, 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, stats and stats or runs, memory/(1024*1024)) else return nil end diff --git a/tex/context/base/mkiv/mlib-mpf.lua b/tex/context/base/mkiv/mlib-mpf.lua index 83a585850..1e381b7c8 100644 --- a/tex/context/base/mkiv/mlib-mpf.lua +++ b/tex/context/base/mkiv/mlib-mpf.lua @@ -256,8 +256,22 @@ do return result end - function metapost.nofscriptruns() - return runs + if CONTEXTLMTXMODE > 0 then + + function metapost.nofscriptruns() + local c = mplib.getcallbackstate() + return c.count, string.format( + "%s (file: %s, text: %s, script: %s, log: %s)", + c.count, c.file, c.text, c.script, c.log + ) + end + + else + + function metapost.nofscriptruns() + return runs + end + end -- writers diff --git a/tex/context/base/mkiv/mtx-context-timing.tex b/tex/context/base/mkiv/mtx-context-timing.tex index c545c768f..db0d4c283 100644 --- a/tex/context/base/mkiv/mtx-context-timing.tex +++ b/tex/context/base/mkiv/mtx-context-timing.tex @@ -19,14 +19,27 @@ \enablemode[no-timing] \usemodule[timing] +\usemodule[article-basic] + \setuplayout - [topspace=1cm, - bottomspace=.5cm, - header=0pt, - width=middle, - height=middle, + [tight] + [footer=15pt, style=\tt] +\setuplayout + [tight] + +\setupbodyfont + [10pt] + +% \setuplayout +% [topspace=1cm, +% bottomspace=.5cm, +% header=0pt, +% width=middle, +% height=middle, +% style=\tt] + \setupfootertexts [\getdocumentfilename{1}-luatex-progress.lut \emdash\ \pagenumber] diff --git a/tex/context/base/mkiv/node-gcm.lmt b/tex/context/base/mkiv/node-gcm.lmt index 2b5b24369..8b09fb82b 100644 --- a/tex/context/base/mkiv/node-gcm.lmt +++ b/tex/context/base/mkiv/node-gcm.lmt @@ -15,6 +15,7 @@ local nuts = nodes.nuts local getnext = nuts.getnext local getsubtype = nuts.getsubtype local copy_node = nuts.copy +local flush_list = nuts.flush_list local count = nuts.count local isglyph = nuts.isglyph local getprop = nuts.getprop @@ -27,6 +28,7 @@ local report_error = logs.reporter("node-aux:error") local function set_components(base,list) local t = { } local n = 0 + local l = list while list do local char = isglyph(list) if char then @@ -35,6 +37,9 @@ local function set_components(base,list) end list = getnext(list) end + -- was forgotten: + flush_list(l) + -- setprop(base,"components",n > 0 and t or false) end diff --git a/tex/context/base/mkiv/node-ini.mkiv b/tex/context/base/mkiv/node-ini.mkiv index 231a8524e..2ecef4a54 100644 --- a/tex/context/base/mkiv/node-ini.mkiv +++ b/tex/context/base/mkiv/node-ini.mkiv @@ -30,7 +30,7 @@ \registerctxluafile{node-gcm}{autosuffix} \registerctxluafile{node-tst}{} \registerctxluafile{node-tra}{} % we might split it off (module) -\registerctxluafile{node-snp}{} +\registerctxluafile{node-snp}{autosuffix} \registerctxluafile{node-tsk}{} \registerctxluafile{node-tex}{} \registerctxluafile{node-dir}{} % experimental, not yet (and maybe never) used diff --git a/tex/context/base/mkiv/node-ltp.lua b/tex/context/base/mkiv/node-ltp.lua index 709ef2b95..87a19de34 100644 --- a/tex/context/base/mkiv/node-ltp.lua +++ b/tex/context/base/mkiv/node-ltp.lua @@ -2878,7 +2878,7 @@ do local function common_message(hlist,line,str) write_nl("") - if status.output_active then -- unset + if CONTEXTLMTXMODE > 0 and tex.getoutputactive() or status.output_active then write(str," has occurred while \\output is active") else write(str) diff --git a/tex/context/base/mkiv/node-nut.lua b/tex/context/base/mkiv/node-nut.lua index 5eed1b2b1..80335e933 100644 --- a/tex/context/base/mkiv/node-nut.lua +++ b/tex/context/base/mkiv/node-nut.lua @@ -296,6 +296,7 @@ nuts.getdepth = direct.getdepth nuts.setdepth = direct.setdepth nuts.getshift = direct.getshift nuts.setshift = direct.setshift +nuts.gettotal = direct.gettotal -- lmtx compatibility @@ -468,6 +469,17 @@ if not nuts.getpre then end +if not nuts.gettotal then + + local d_getheight = direct.getheight + local d_getdepth = direct.getdepth + + function nuts.gettotal(n) + return (d_getheight(n) or 0) + (d_getdepth(n) or 0) + end + +end + -- alias nuts.getsurround = nuts.getkern diff --git a/tex/context/base/mkiv/node-snp.lmt b/tex/context/base/mkiv/node-snp.lmt new file mode 100644 index 000000000..a8d467956 --- /dev/null +++ b/tex/context/base/mkiv/node-snp.lmt @@ -0,0 +1,61 @@ +if not modules then modules = { } end modules ['node-snp'] = { + version = 1.001, + comment = "companion to node-ini.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +if not nodes then + nodes = { } -- also loaded in mtx-timing +end + +local snapshots = { } +nodes.snapshots = snapshots + +local status = status + +local nodeusage = nodes.pool and nodes.pool.usage +local clock = os.gettimeofday or os.clock -- should go in environment +local lasttime = clock() +local samples = { } + +function snapshots.takesample(comment) + if nodeusage then + local c = clock() + samples[#samples+1] = { + nodes = nodeusage(), + texcallbacks = status.getcallbackstate(), + mpcallbacks = mplib.getcallbackstate(), + backendcallbacks = backends.getcallbackstate(), + luavariables = status.getluastate(), + texvariables = status.gettexstate(), + comment = comment, + variables = { + lasttime = c, + elapsed = c - lasttime, + }, + memories = { + pool = status.getpoolstate(), + hash = status.gethashstate(), + node = status.getnodestate(), + token = status.gettokenstate(), + buffer = status.getbufferstate(), + input = status.getinputstate(), + file = status.getfilestate(), + nest = status.getneststate(), + parameter = status.getparameterstate(), + save = status.getsavestate(), + expand = status.getexpandstate(), + }, + } + end +end + +function snapshots.getsamples() + return samples -- one return value ! +end + +function snapshots.resetsamples() + samples = { } +end diff --git a/tex/context/base/mkiv/node-tra.lua b/tex/context/base/mkiv/node-tra.lua index c7556aba6..d56e2adef 100644 --- a/tex/context/base/mkiv/node-tra.lua +++ b/tex/context/base/mkiv/node-tra.lua @@ -193,8 +193,18 @@ end nodes.tosequence = tosequence nuts .tosequence = tosequence -function nodes.report(t) - report_nodes("output %a, %s nodes",status.output_active,count_nodes(t)) +if CONTEXTLMTXMODE > 0 then + + function nodes.report(t) + report_nodes("output %a, %s nodes",tex.getoutputactive(),count_nodes(t)) + end + +else + + function nodes.report(t) + report_nodes("output %a, %s nodes",status.output_active,count_nodes(t)) + end + end function nodes.packlist(head) diff --git a/tex/context/base/mkiv/page-run.lua b/tex/context/base/mkiv/page-run.lua index cb8cf0311..7ad9c8d9f 100644 --- a/tex/context/base/mkiv/page-run.lua +++ b/tex/context/base/mkiv/page-run.lua @@ -186,38 +186,4 @@ function commands.showlayout(options) end -local report = logs.reporter("usage") - -function commands.showusage() - report("") - report("status after shipping out page %s",tex.getcount("realpageno")) - report("") - report(" filename : %s", status.filename) - report(" inputid : %s", status.inputid) - report(" linenumber : %s", status.linenumber) - report(" input pointer : %s", status.input_ptr) - report("") - report(" string pointer : %s of %s", status.str_ptr, status.max_strings + status.init_str_ptr) - report(" pool size : %s", status.pool_size) - report("") - report(" node memory usage : %s of %s", status.var_used, status.var_mem_max) - report(" token memory usage : %s of %s", status.dyn_used, status.fix_mem_max) - report("") - report(" cs count : %s of %s", status.cs_count, status.hash_size + status.hash_extra) - report("") - report(" stack size : %s of %s", status.max_in_stack, status.stack_size) - report(" nest size : %s of %s", status.max_nest_stack, status.nest_size) - report(" parameter size : %s of %s", status.max_param_stack, status.param_size) - report(" buffer size : %s of %s", status.max_buf_stack, status.buf_size) - report(" save size : %s of %s", status.max_save_stack, status.save_size) - report("") - report(" luabytecode bytes : %s in %s registers", status.luabytecode_bytes, status.luabytecodes) - report(" luastate bytes : %s of %s", status.luastate_bytes, status.luastate_bytes_max or "unknown") - report("") - report(" callbacks : %s", status.callbacks) - report(" indirect callbacks : %s", status.indirect_callbacks) - report(" saved callbacks : %s", status.saved_callbacks) - report(" direct callbacks : %s", status.direct_callbacks) - report(" function callbacks : %s", status.function_callbacks) - report("") -end +commands.showusage = statistics.showusage diff --git a/tex/context/base/mkiv/page-run.mkiv b/tex/context/base/mkiv/page-run.mkiv index d3efe1698..fc46d8236 100644 --- a/tex/context/base/mkiv/page-run.mkiv +++ b/tex/context/base/mkiv/page-run.mkiv @@ -215,10 +215,4 @@ \global\setbox#1\vpack{\noindent\backgroundline[layout:mix]{\box#1}}% \endgroup} -%D The next command shows some statistics (we might add more in due time): - -\unexpanded\gdef\showusage - {\gtoksapp\everyaftershipout{\ctxcommand{showusage()}}% - \glet\showusage\relax} - \protect \endinput diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf index 66d6cd7cf..415ffb8fe 100644 Binary files a/tex/context/base/mkiv/status-files.pdf and b/tex/context/base/mkiv/status-files.pdf differ diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf index 6001d8d6a..250ff88ff 100644 Binary files a/tex/context/base/mkiv/status-lua.pdf and b/tex/context/base/mkiv/status-lua.pdf differ diff --git a/tex/context/base/mkiv/strc-itm.mklx b/tex/context/base/mkiv/strc-itm.mklx index 8ce31c1a8..609bfac29 100644 --- a/tex/context/base/mkiv/strc-itm.mklx +++ b/tex/context/base/mkiv/strc-itm.mklx @@ -1561,7 +1561,7 @@ \m_strc_itemgroups_text_distance {.5\interwordspace\s!plus.5\emwidth}% {\interwordspace \s!plus \emwidth}% - {\emwidth \s!plus \interwordstretch\!!minus\interwordshrink}} + {\emwidth \s!plus \interwordstretch\s!minus\interwordshrink}} % \unexpanded\def\strc_itemgroups_default_command % {\EveryPar{\ignorespaces}% needed ? diff --git a/tex/context/base/mkiv/strc-itm.mkvi b/tex/context/base/mkiv/strc-itm.mkvi index ca47b73f7..ce1bcc6f5 100644 --- a/tex/context/base/mkiv/strc-itm.mkvi +++ b/tex/context/base/mkiv/strc-itm.mkvi @@ -1560,7 +1560,7 @@ \m_strc_itemgroups_text_distance {.5\interwordspace\s!plus.5\emwidth}% {\interwordspace \s!plus \emwidth}% - {\emwidth \s!plus \interwordstretch\!!minus\interwordshrink}} + {\emwidth \s!plus \interwordstretch\s!minus\interwordshrink}} % \unexpanded\def\strc_itemgroups_default_command % {\EveryPar{\ignorespaces}% needed ? diff --git a/tex/context/base/mkiv/syst-ini.mkxl b/tex/context/base/mkiv/syst-ini.mkxl index c8c16b773..9b516f3c5 100644 --- a/tex/context/base/mkiv/syst-ini.mkxl +++ b/tex/context/base/mkiv/syst-ini.mkxl @@ -203,19 +203,23 @@ % 255 : page % 256 - : user +% use \chardef instead for min and max +% +% will be blocked: \newfamily \newlanguage + \countdef \c_syst_min_allocated_register = 52 \c_syst_min_allocated_register = 256 % can change -\countdef \c_syst_max_allocated_register = 53 \c_syst_max_allocated_register = 32767 -\countdef \c_syst_min_allocated_read = 54 \c_syst_min_allocated_read = -1 -\countdef \c_syst_max_allocated_read = 55 \c_syst_max_allocated_read = 16 +\countdef \c_syst_max_allocated_register = 53 \c_syst_max_allocated_register = 65535 +\countdef \c_syst_min_allocated_read = 54 \c_syst_min_allocated_read = 0 +\countdef \c_syst_max_allocated_read = 55 \c_syst_max_allocated_read = 1023 \countdef \c_syst_min_allocated_language = 56 \c_syst_min_allocated_language = 0 -\countdef \c_syst_max_allocated_language = 57 \c_syst_max_allocated_language = 255 +\countdef \c_syst_max_allocated_language = 57 \c_syst_max_allocated_language = 8191 \countdef \c_syst_min_allocated_insert = 58 \c_syst_min_allocated_insert = 128 \countdef \c_syst_max_allocated_insert = 59 \c_syst_max_allocated_insert = 254 \countdef \c_syst_min_allocated_family = 60 \c_syst_min_allocated_family = 128 \countdef \c_syst_max_allocated_family = 61 \c_syst_max_allocated_family = 255 \countdef \c_syst_min_allocated_attribute = 62 \c_syst_min_allocated_attribute = 1024 % 0-1023 : private \countdef \c_syst_min_allocated_write = 63 \c_syst_min_allocated_write = 0 -\countdef \c_syst_max_allocated_write = 64 \c_syst_max_allocated_write = 127 +\countdef \c_syst_max_allocated_write = 64 \c_syst_max_allocated_write = 1023 \countdef \c_syst_last_allocated_count = 32 \c_syst_last_allocated_count = \c_syst_min_allocated_register \countdef \c_syst_last_allocated_dimen = 33 \c_syst_last_allocated_dimen = \c_syst_min_allocated_register @@ -1049,8 +1053,8 @@ %D For a while we will keep these useless numbers as for instance tikz checks for them: -\chardef\eTeXversion 2 -\def \eTeXrevision {2} +\frozen\chardef\eTeXversion 2 +\frozen\def \eTeXrevision {2} %D Experiment: diff --git a/tex/context/base/mkiv/toks-ini.lua b/tex/context/base/mkiv/toks-ini.lua index 834bc773d..3696364b9 100644 --- a/tex/context/base/mkiv/toks-ini.lua +++ b/tex/context/base/mkiv/toks-ini.lua @@ -158,6 +158,7 @@ if not scan_box then if s == "hbox" or s == "vbox" or s == "vtop" then put_next(create_token(s)) end + return scan_list() end token.scan_box = scan_box diff --git a/tex/context/base/mkiv/toks-scn.lua b/tex/context/base/mkiv/toks-scn.lua index abf39a319..ec5681cd7 100644 --- a/tex/context/base/mkiv/toks-scn.lua +++ b/tex/context/base/mkiv/toks-scn.lua @@ -184,7 +184,8 @@ local function scanbracketed() if s then return s else - report_scan("missing argument in line %i of %a", status.linenumber, status.filename) + local readstate = status.getreadstate() + report_scan("missing argument in line %i of %a", readstate.linenumber, readstate.filename) return "" end end diff --git a/tex/context/base/mkiv/trac-deb.lmt b/tex/context/base/mkiv/trac-deb.lmt new file mode 100644 index 000000000..42f6d183c --- /dev/null +++ b/tex/context/base/mkiv/trac-deb.lmt @@ -0,0 +1,519 @@ +if not modules then modules = { } end modules ['trac-deb'] = { + version = 1.001, + comment = "companion to trac-deb.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- This is an old mechanism, a result of some experiments in the early days of +-- luatex and mkiv, but still nice anyway. I will clean it up in lmtx. + +local status = status + +local tonumber, tostring, type = tonumber, tostring, type +local format, concat, match, find, gsub = string.format, table.concat, string.match, string.find, string.gsub +local lpegmatch = lpeg.match + +-- maybe tracers -> tracers.tex (and tracers.lua for current debugger) + +----- report_tex = logs.reporter("tex error") +----- report_lua = logs.reporter("lua error") +local report_nl = logs.newline +local report_str = logs.writer + +tracers = tracers or { } +local tracers = tracers + +-- this is old tracing stuff ... will go to its own module + +tracers.lists = { } +local lists = tracers.lists + +tracers.strings = { } +local strings = tracers.strings + +local texgetdimen = tex.getdimen +local texgettoks = tex.gettoks +local texgetcount = tex.getcount +local texgethelp = tex.gethelptext or function() end +local fatalerror = tex.fatalerror + +local implement = interfaces.implement + +-- this is used in lmx files but needs to be redone + +strings.undefined = "undefined" + +function tracers.dimen(name) + local d = texgetdimen(name) + return d and number.topoints(d) or strings.undefined +end + +function tracers.count(name) + return texgetcount(name) or strings.undefined +end + +function tracers.toks(name,limit) + local t = texgettoks(name) + return t and string.limit(t,tonumber(limit) or 40) or strings.undefined +end + +function tracers.primitive(name) + return tex[name] or strings.undefined +end + +lists.scratch = { + 0, 2, 4, 6, 8 +} + +lists.internals = { + 'p:hsize', 'p:parindent', 'p:leftskip','p:rightskip', + 'p:vsize', 'p:parskip', 'p:baselineskip', 'p:lineskip', 'p:topskip' +} + +lists.context = { + 'd:lineheight', + 'c:realpageno', 'c:userpageno', 'c:pageno', 'c:subpageno' +} + +local types = { + ['d'] = tracers.dimen, + ['c'] = tracers.count, + ['t'] = tracers.toks, + ['p'] = tracers.primitive +} + +local splitboth = lpeg.splitat(":") + +function tracers.type(csname) + local tag, name = lpegmatch(splitboth,csname) + return tag or "" +end + +function tracers.name(csname) + local tag, name = lpegmatch(splitboth,csname) + return name or csname +end + +function tracers.cs(csname) + local tag, name = lpegmatch(splitboth,csname) + if name and types[tag] then + return types[tag](name) + else + return tracers.primitive(csname) + end +end + +function tracers.knownlist(name) + local l = lists[name] + return l and #l > 0 +end + +-- till here + +do + + local ioflush = io.flush + local ioread = io.read + local writenl = texio.write_nl + local write = texio.write + + local runtoks = tex.runtoks + local terminaldata = false + local context = context + + interfaces.implement { + name = "fetchterminaldata", + actions = function() + context(terminaldata) + end, + } + + function texio.terminal() + writenl("\n" .. "entering interactive mode, use \\quit to abort reading" .."\n\n") + while true do + write(">") + ioflush() + terminaldata = ioread() + if terminaldata == "\\quit" then + terminaldata = false + break + else + runtoks("t_syst_terminal_data",nil,nil,true) -- obeymode + end + end + end + + interfaces.implement { + name = "readfromterminal", + public = true, + protected = true, + actions = texio.terminal, + } + +end + +local savedluaerror = nil +local usescitelexer = nil +local quitonerror = true + +local function errorreporter(luaerror) + local category = luaerror and "lua error" or "tex error" + local report = logs.reporter(category) + logs.enable(category) + return report +end + +function tracers.showlines(filename,linenumber,offset,luaerrorline) + local data = io.loaddata(filename) + if not data or data == "" then + local hash = url.hashed(filename) + if not hash.noscheme then + local ok, d, n = resolvers.loaders.byscheme(hash.scheme,filename) + if ok and n > 0 then + data = d + end + end + end + local scite = usescitelexer and require("util-sci") + if scite then + return utilities.scite.tohtml(data,"tex",linenumber or true,false) + else + local lines = data and string.splitlines(data) + if lines and #lines > 0 then + if luaerrorline and luaerrorline > 0 then + -- lua error: linenumber points to last line + local start = "\\startluacode" + local stop = "\\stopluacode" + local n = linenumber + for i=n,1,-1 do + local line = lines[i] + if not line then + break + elseif find(line,start) then + n = i + luaerrorline - 1 + if n <= linenumber then + linenumber = n + end + break + end + end + end + offset = tonumber(offset) or 10 + linenumber = tonumber(linenumber) or 10 + local start = math.max(linenumber - offset,1) + local stop = math.min(linenumber + offset,#lines) + if stop > #lines then + return "" + else + local result, fmt = { }, "%" .. #tostring(stop) .. "d %s %s" + for n=start,stop do + result[#result+1] = format(fmt,n,n == linenumber and ">>" or " ",lines[n]) + end + return concat(result,"\n") + end + else + return "" + end + end +end + +-- todo: last tex error has ! prepended +-- todo: some nested errors have two line numbers +-- todo: collect errorcontext in string (after code cleanup) +-- todo: have a separate status.lualinenumber +-- todo: \starttext bla \blank[foo] bla \stoptext + +local nop = function() end +local resetmessages = status.resetmessages or nop + +local function processerror(offset,errortype) + local readstate = status.readstate + local filename = readstate.filename + local linenumber = readstate.linenumber + local skiplinenumber = readstate.skiplinenumber + local errorstate = status.errorstate + local lastcontext = errorstate.errorcontext + local lasttexerror = errorstate.error or "?" + local lastluaerror = errorstate.luaerror or "?" -- lasttexerror + local luaerrorline = match(lastluaerror,[[lua%]?:.-(%d+)]]) or (lastluaerror and find(lastluaerror,"?:0:",1,true) and 0) + local lastmpserror = match(lasttexerror,[[^.-mp%serror:%s*(.*)$]]) + resetmessages() + lastluaerror = gsub(lastluaerror,"%[\\directlua%]","[ctxlua]") + tracers.printerror { + filename = filename, + linenumber = linenumber, + skiplinenumber = skiplinenumber, + offset = tonumber(offset) or 10, + lasttexerror = lasttexerror, + lastmpserror = lastmpserror, + lastluaerror = lastluaerror, -- can be the same as lasttexerror + luaerrorline = luaerrorline, + lastcontext = lastcontext, + lasttexhelp = tex.gethelptext and tex.gethelptext() or nil, + errortype = errortype, + } + if job and type(job.disablesave) == "function" then + job.disablesave() + end +end + +directives.register("system.quitonerror",function(v) + quitonerror = toboolean(v) +end) + +directives.register("system.usescitelexer",function(v) + usescitelexer = toboolean(v) +end) + +local busy = false + +function tracers.printerror(specification) + if not busy then + busy = true + local errorvalues = table.swapped(tex.geterrorvalues()) + local filename = specification.filename + local linenumber = specification.linenumber + local lasttexerror = specification.lasttexerror + local lastmpserror = specification.lastmpserror + local lastluaerror = specification.lastluaerror + local lastcontext = specification.lastcontext + local luaerrorline = specification.luaerrorline + local errortype = specification.errortype + local offset = specification.offset + local endoffile = specification.endoffile + local report = errorreporter(luaerrorline) + if errortype == errorvalues.eof then + report("runaway error: %s",lasttexerror or "-") + if not quitonerror and texio.terminal then + texio.terminal() -- not well tested + end + elseif errortype == errorvalues.condition then + linenumber = specification.skiplinenumber + if linenumber > 0 then + report("condition error on line %s in file %s: %s",linenumber,filename,lasttexerror) + report_nl() + report_str(tracers.showlines(filename,linenumber,offset,tonumber(luaerrorline))) + report_nl() + else + report("runaway condition error: %s",lasttexerror or "-") + end + quitonerror = true + elseif not filename then + report("fuzzy error:") + report(" tex: %s",lasttexerror or "-") + report(" lua: %s",lastluaerror or "-") + report(" mps: %s",lastmpserror or "-") + elseif type(filename) == "number" then + report("error on line %s of filehandle %s: %s ...",linenumber,lasttexerror) + else + report_nl() + if luaerrorline then + if linenumber == 0 or not filename or filename == "" then + print("\nfatal lua error:\n\n",lastluaerror,"\n") + luatex.abort() + return + else + report("lua error on line %s in file %s:\n\n%s",linenumber,filename,lastluaerror) + end + elseif lastmpserror then + report("mp error on line %s in file %s:\n\n%s",linenumber,filename,lastmpserror) + else + report("tex error on line %s in file %s: %s",linenumber,filename,lasttexerror) + if lastcontext then + report_nl() + report_str(lastcontext) + report_nl() + else + report_nl() + -- tex.show_context() + end + if lastluaerror and not match(lastluaerror,"^%s*[%?]*%s*$") then + print("\nlua error:\n\n",lastluaerror,"\n") + quitonerror = true + end + end + report_nl() + report_str(tracers.showlines(filename,linenumber,offset,tonumber(luaerrorline))) + report_nl() + end + local errname = file.addsuffix(tex.jobname .. "-error","log") + if quitonerror then + table.save(errname,specification) + local help = specification.lasttexhelp + if help and #help > 0 then + report_nl() + report_str(help) + report_nl() + report_nl() + end + luatex.abort() + end + busy = false + end +end + +luatex.wrapup(function() os.remove(file.addsuffix(tex.jobname .. "-error","log")) end) + +local function processwarning(offset) + local warningstate = status.warningstate + local lastwarning = warningstate.warning or "?" + local lastlocation = warningstate.warningtag or "?" + resetmessages() + tracers.printwarning { + lastwarning = lastwarning, + lastlocation = lastlocation, + } +end + +function tracers.printwarning(specification) + logs.report("luatex warning","%s: %s",specification.lastlocation,specification.lastwarning) +end + +directives.register("system.errorcontext", function(v) + local register = callback.register + if v then + register('show_error_message', nop) + register('show_warning_message', function() processwarning(v) end) + register('intercept_lua_error', function() processerror(v) end) + register('intercept_tex_error', function(mode,eof) processerror(v,eof) end) + else + register('show_error_message', nil) + register('show_warning_message', nil) + register('intercept_lua_error', nil) + register('intercept_tex_error', nil) + end +end) + +-- this might move + +lmx = lmx or { } + +lmx.htmfile = function(name) return environment.jobname .. "-status.html" end +lmx.lmxfile = function(name) return resolvers.findfile(name,'tex') end + +local function reportback(lmxname,default,variables) + if lmxname == false then + return variables + else + local name = lmx.show(type(lmxname) == "string" and lmxname or default,variables) + if name then + logs.report("context report","file: %s",name) + end + end +end + +function lmx.showdebuginfo(lmxname) + local variables = { + ['title'] = 'ConTeXt Debug Information', + ['color-background-one'] = lmx.get('color-background-green'), + ['color-background-two'] = lmx.get('color-background-blue'), + } + reportback(lmxname,"context-debug.lmx",variables) +end + +local function showerror(lmxname) + local readstate = status.readstate() + local filename = readstate.filename + local linenumber = tonumber(readstate.linenumber) or 0 + local errorcontext = "" + if not filename then + filename = status.iocodes and status.iocodes[readstate.iocode] or 'unknown' + errorcontext = 'error in filename' + else + errorcontext = tracers.showlines(filename,linenumber,offset) + end + local variables = { + ['title'] = 'ConTeXt Error Information', + ['errormessage'] = status.errorstatus.error or "?", + ['linenumber'] = linenumber, + ['color-background-one'] = lmx.get('color-background-yellow'), + ['color-background-two'] = lmx.get('color-background-purple'), + ['filename'] = filename, + ['errorcontext'] = errorcontext, + } + reportback(lmxname,"context-error.lmx",variables) + luatex.abort() +end + +lmx.showerror = showerror + +function lmx.overloaderror(v) + if v == "scite" then + usescitelexer = true + end + callback.register('show_error_message', function() showerror() end) + callback.register('intercept_lua_error', function() showerror() end) + callback.register('intercept_tex_error', function() showerror() end) +end + +directives.register("system.showerror", lmx.overloaderror) + +-- local debugger = utilities.debugger +-- +-- local function trace_calls(n) +-- debugger.enable() +-- luatex.registerstopactions(function() +-- debugger.disable() +-- debugger.savestats(tex.jobname .. "-luacalls.log",tonumber(n)) +-- end) +-- trace_calls = function() end +-- end +-- +-- directives.register("system.tracecalls", function(n) +-- trace_calls(n) +-- end) -- indirect is needed for nilling + +-- Obsolete ... not that usefull as normally one runs from an editor and +-- when run unattended it makes no sense either. + +-- local editor = [[scite "-open:%filename%" -goto:%linenumber%]] +-- +-- directives.register("system.editor",function(v) +-- editor = v +-- end) +-- +-- callback.register("call_edit",function(filename,linenumber) +-- if editor then +-- editor = gsub(editor,"%%s",filename) +-- editor = gsub(editor,"%%d",linenumber) +-- editor = gsub(editor,"%%filename%%",filename) +-- editor = gsub(editor,"%%linenumber%%",linenumber) +-- logs.report("system","starting editor: %s",editor) +-- os.execute(editor) +-- end +-- end) + +local implement = interfaces.implement + +implement { name = "showtrackers", actions = trackers.show } +implement { name = "enabletrackers", actions = trackers.enable, arguments = "string" } +implement { name = "disabletrackers", actions = trackers.disable, arguments = "string" } +implement { name = "resettrackers", actions = trackers.reset } + +implement { name = "showdirectives", actions = directives.show } +implement { name = "enabledirectives", actions = directives.enable, arguments = "string" } +implement { name = "disabledirectives", actions = directives.disable, arguments = "string" } + +implement { name = "showexperiments", actions = experiments.show } +implement { name = "enableexperiments", actions = experiments.enable, arguments = "string" } +implement { name = "disableexperiments", actions = experiments.disable, arguments = "string" } + +implement { name = "showdebuginfo", actions = lmx.showdebuginfo } +implement { name = "overloaderror", actions = lmx.overloaderror } +implement { name = "showlogcategories", actions = logs.show } + +local debugger = utilities.debugger + +directives.register("system.profile",function(n) + luatex.registerstopactions(function() + debugger.disable() + debugger.savestats("luatex-profile.log",tonumber(n) or 0) + report_nl() + logs.report("system","profiler stopped, log saved in %a","luatex-profile.log") + report_nl() + end) + logs.report("system","profiler started") + debugger.enable() +end) diff --git a/tex/context/base/mkiv/trac-deb.lua b/tex/context/base/mkiv/trac-deb.lua index cdf40fd59..4667b66ee 100644 --- a/tex/context/base/mkiv/trac-deb.lua +++ b/tex/context/base/mkiv/trac-deb.lua @@ -114,48 +114,6 @@ end -- for now here -if CONTEXTLMTXMODE > 0 then - - local ioflush = io.flush - local ioread = io.read - local writenl = texio.write_nl - local write = texio.write - - local runtoks = tex.runtoks - local terminaldata = false - local context = context - - interfaces.implement { - name = "fetchterminaldata", - actions = function() - context(terminaldata) - end, - } - - function texio.terminal() - writenl("\n" .. "entering interactive mode, use \\quit to abort reading" .."\n\n") - while true do - write(">") - ioflush() - terminaldata = ioread() - if terminaldata == "\\quit" then - terminaldata = false - break - else - runtoks("t_syst_terminal_data",nil,nil,true) -- obeymode - end - end - end - - interfaces.implement { - name = "readfromterminal", - public = true, - protected = true, - actions = texio.terminal, - } - -end - local savedluaerror = nil local usescitelexer = nil local quitonerror = true @@ -227,18 +185,12 @@ end -- todo: some nested errors have two line numbers -- todo: collect errorcontext in string (after code cleanup) -- todo: have a separate status.lualinenumber - -- todo: \starttext bla \blank[foo] bla \stoptext local nop = function() end local resetmessages = status.resetmessages or nop local function processerror(offset,eof) - -- print("[[ last tex error: " .. tostring(status.lasterrorstring or "") .. " ]]") - -- print("[[ last lua error: " .. tostring(status.lastluaerrorstring or "") .. " ]]") - -- print("[[ last warning : " .. tostring(status.lastwarningstring or "") .. " ]]") - -- print("[[ last location : " .. tostring(status.lastwarninglocation or "") .. " ]]") - -- print("[[ last context : " .. tostring(status.lasterrorcontext or "") .. " ]]") local filename = status.filename local linenumber = tonumber(status.linenumber) or 0 local lastcontext = status.lasterrorcontext @@ -260,6 +212,9 @@ local function processerror(offset,eof) lasttexhelp = tex.gethelptext and tex.gethelptext() or nil, endoffile = eof, } + if job and type(job.disablesave) == "function" then + job.disablesave() + end end directives.register("system.quitonerror",function(v) @@ -361,41 +316,20 @@ function tracers.printwarning(specification) logs.report("luatex warning","%s: %s",specification.lastlocation,specification.lastwarning) end -if CONTEXTLMTXMODE > 0 then - - directives.register("system.errorcontext", function(v) - local register = callback.register - if v then - register('show_error_message', nop) - register('show_warning_message', function() processwarning(v) end) - register('intercept_lua_error', function() processerror(v) end) - register('intercept_tex_error', function(mode,eof) processerror(v,eof) end) - else - register('show_error_message', nil) - register('show_warning_message', nil) - register('intercept_lua_error', nil) - register('intercept_tex_error', nil) - end - end) - -else - - directives.register("system.errorcontext", function(v) - local register = callback.register - if v then - register('show_error_message', nop) - register('show_warning_message',function() processwarning(v) end) - register('show_error_hook', function(eof) processerror(v,eof) end) - register('show_lua_error_hook', function() processerror(v) end) - else - register('show_error_message', nil) - register('show_error_hook', nil) - register('show_warning_message',nil) - register('show_lua_error_hook', nil) - end - end) - -end +directives.register("system.errorcontext", function(v) + local register = callback.register + if v then + register('show_error_message', nop) + register('show_warning_message',function() processwarning(v) end) + register('show_error_hook', function(eof) processerror(v,eof) end) + register('show_lua_error_hook', function() processerror(v) end) + else + register('show_error_message', nil) + register('show_error_hook', nil) + register('show_warning_message',nil) + register('show_lua_error_hook', nil) + end +end) -- this might move diff --git a/tex/context/base/mkiv/trac-deb.mkiv b/tex/context/base/mkiv/trac-deb.mkiv index fcf58f37f..994c357d0 100644 --- a/tex/context/base/mkiv/trac-deb.mkiv +++ b/tex/context/base/mkiv/trac-deb.mkiv @@ -16,7 +16,7 @@ \unprotect %registerctxluafile{trac-lmx}{} -\registerctxluafile{trac-deb}{} +\registerctxluafile{trac-deb}{autosuffix} \unexpanded\def\breakpoint {\showdebuginfo\wait} diff --git a/tex/context/base/mkiv/trac-inf.lmt b/tex/context/base/mkiv/trac-inf.lmt new file mode 100644 index 000000000..c7a4c3c34 --- /dev/null +++ b/tex/context/base/mkiv/trac-inf.lmt @@ -0,0 +1,353 @@ +if not modules then modules = { } end modules ['trac-inf'] = { + version = 1.001, + comment = "companion to trac-inf.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- As we want to protect the global tables, we no longer store the timing +-- in the tables themselves but in a hidden timers table so that we don't +-- get warnings about assignments. This is more efficient than using rawset +-- and rawget. + +local type, tonumber, select = type, tonumber, select +local format, lower, find = string.format, string.lower, string.find +local concat = table.concat +local clock = os.gettimeofday or os.clock -- should go in environment + +local setmetatableindex = table.setmetatableindex +local serialize = table.serialize +local formatters = string.formatters + +statistics = statistics or { } +local statistics = statistics + +statistics.enable = true +statistics.threshold = 0.01 + +local statusinfo, n, registered, timers = { }, 0, { }, { } + +setmetatableindex(timers,function(t,k) + local v = { timing = 0, loadtime = 0, offset = 0 } + t[k] = v + return v +end) + +local function hastiming(instance) + return instance and timers[instance] +end + +local function resettiming(instance) + timers[instance or "notimer"] = { timing = 0, loadtime = 0, offset = 0 } +end + +local ticks = clock +local seconds = function(n) return n or 0 end + +ticks = lua.getpreciseticks +seconds = lua.getpreciseseconds + +local function starttiming(instance,reset) + local timer = timers[instance or "notimer"] + local it = timer.timing + if reset then + it = 0 + timer.loadtime = 0 + end + if it == 0 then + timer.starttime = ticks() + if not timer.loadtime then + timer.loadtime = 0 + end + end + timer.timing = it + 1 +end + +local function stoptiming(instance) + local timer = timers[instance or "notimer"] + local it = timer.timing + if it > 1 then + timer.timing = it - 1 + else + local starttime = timer.starttime + if starttime and starttime > 0 then + local stoptime = ticks() + local loadtime = stoptime - starttime + timer.stoptime = stoptime + timer.loadtime = timer.loadtime + loadtime + timer.timing = 0 + timer.starttime = 0 + return loadtime + end + end + return 0 +end + +local function benchmarktimer(instance) + local timer = timers[instance or "notimer"] + local it = timer.timing + if it > 1 then + timer.timing = it - 1 + else + local starttime = timer.starttime + if starttime and starttime > 0 then + timer.offset = ticks() - starttime + else + timer.offset = 0 + end + end +end + +local function elapsed(instance) + if type(instance) == "number" then + return instance + else + local timer = timers[instance or "notimer"] + return timer and seconds(timer.loadtime - 2*(timer.offset or 0)) or 0 + end +end + +local function currenttime(instance) + if type(instance) == "number" then + return instance + else + local timer = timers[instance or "notimer"] + local it = timer.timing + if it > 1 then + -- whatever + else + local starttime = timer.starttime + if starttime and starttime > 0 then + return seconds(timer.loadtime + ticks() - starttime - 2*(timer.offset or 0)) + end + end + return 0 + end +end + +local function elapsedtime(instance) + return format("%0.3f",elapsed(instance)) +end + +local function elapsedindeed(instance) + return elapsed(instance) > statistics.threshold +end + +local function elapsedseconds(instance,rest) -- returns nil if 0 seconds + if elapsedindeed(instance) then + return format("%0.3f seconds %s", elapsed(instance),rest or "") + end +end + +statistics.hastiming = hastiming +statistics.resettiming = resettiming +statistics.starttiming = starttiming +statistics.stoptiming = stoptiming +statistics.currenttime = currenttime +statistics.elapsed = elapsed +statistics.elapsedtime = elapsedtime +statistics.elapsedindeed = elapsedindeed +statistics.elapsedseconds = elapsedseconds +statistics.benchmarktimer = benchmarktimer + +-- general function .. we might split this module + +function statistics.register(tag,fnc) + if statistics.enable and type(fnc) == "function" then + -- second load can overload: + local rt = registered[tag] or (#statusinfo + 1) + statusinfo[rt] = { tag, fnc } + registered[tag] = rt + if #tag > n then n = #tag end + end +end + +local report = logs.reporter("mkiv lua stats") + +function statistics.show() + if statistics.enable then + -- this code will move + local register = statistics.register + register("used platform", function() + return format("%s, type: %s, binary subtree: %s", + os.platform or "unknown",os.type or "unknown", environment.texos or "unknown") + end) + register("used engine", function() + return format("%s version: %s, functionality level: %s, format id: %s, compiler: %s", + LUATEXENGINE, LUATEXVERSION, LUATEXFUNCTIONALITY, LUATEXFORMATID, status.used_compiler) + end) + register("used hash slots", function() + local t = status.gethashstate() + local m = status.gettexstate() + return format("%s of %s with base %s, approximate memory usage: %i MB", + t.cnt, t.max, status.tex_hash_size, m.approximate // (1024 * 1024)) + end) + register("callbacks", statistics.callbacks) + -- so far + register("lua properties",function() + local hash = lua.gethashchars() + local mask = load([[τεχ = 1]]) and "utf" or "ascii" + return format("engine: %s %s, used memory: %s, hash chars: min(%i,40), symbol mask: %s (%s)", + "lua", LUAVERSION, statistics.memused(), hash, mask, mask == "utf" and "τεχ" or "tex") + end) + register("runtime",statistics.runtime) + logs.newline() -- initial newline + for i=1,#statusinfo do + local s = statusinfo[i] + local r = s[2]() + if r then + report("%s: %s",s[1],r) + end + end + -- logs.newline() -- final newline + statistics.enable = false + end +end + +function statistics.memused() -- no math.round yet -) + local round = math.round or math.floor + local luastate = status.getluastate() + return format("%s MB, ctx: %s MB, max: %s MB", + round(collectgarbage("count")/1000), + round(luastate.state_bytes/1000000), + luastate.state_bytes_max and round(luastate.state_bytes_max/1000000) or "unknown" + ) +end + +starttiming(statistics) + +function statistics.formatruntime(runtime) -- indirect so it can be overloaded and + return format("%s seconds", runtime) -- indeed that happens in cure-uti.lua +end + +function statistics.runtime() + stoptiming(statistics) + -- stoptiming(statistics) -- somehow we can start the timer twice, but where + local runtime = lua.getruntime and lua.getruntime() or elapsedtime(statistics) + return statistics.formatruntime(runtime) +end + +local report = logs.reporter("system") + +function statistics.timed(action,all) + starttiming("run") + action() + stoptiming("run") + local runtime = tonumber(elapsedtime("run")) + if all then + local alltime = tonumber(lua.getruntime and lua.getruntime() or elapsedtime(statistics)) + if alltime and alltime > 0 then + report("total runtime: %0.3f seconds of %0.3f seconds",runtime,alltime) + return + end + end + report("total runtime: %0.3f seconds",runtime) +end + +-- goodie + +function statistics.tracefunction(base,tag,...) + for i=1,select("#",...) do + local name = select(i,...) + local stat = { } + local func = base[name] + setmetatableindex(stat,function(t,k) t[k] = 0 return 0 end) + base[name] = function(n,k,v) stat[k] = stat[k] + 1 return func(n,k,v) end + statistics.register(formatters["%s.%s"](tag,name),function() return serialize(stat,"calls") end) + end +end + +-- now here + +status.iocodes = status.iocodes or { [0] = + "terminal input", + "lua input", + "scan token input", + "scan token eof input", + "tex macro", + "file input", +} + +local report = logs.reporter("usage") + +function statistics.showusage(when) + local s = status.list() + local c = status.getcallbackstate() -- status.callbacks + local m = mplib.getcallbackstate() + local b = backends.getcallbackstate() + -- + local pool = s.poolstate + local hash = s.hashstate + local node = s.nodestate + local token = s.tokenstate + local buffer = s.bufferstate + local input = s.inputstate + local file = s.filestate + local nest = s.neststate + local parameter = s.parameterstate + local save = s.savestate + local expand = s.expandstate + local tstatus = s.texstate + local lstatus = s.luastate + -- + report("") + if when == "finish" then + report("status after finishing run") + else + report("status after shipping out page %s",tex.getcount("realpageno")) + end + report("") + report(" current file name : %s", s.filename or "") + report(" current input type : %s", status.iocodes[s.iocode] or 'unknown') + report(" current line number : %s", s.linenumber) + report("") + report(" string memory : min: %s, max: %s, set: %s, mem: %s, top: %s, use: %s, cnt: %s", pool .min, pool .max, pool .set, pool .mem, pool .top, pool .use, pool.cnt) + report(" hash memory : min: %s, max: %s, set: %s, mem: %s, top: %s, use: %s, cnt: %s", hash .min, hash .max, hash .set, hash .mem, hash .top, hash .use, hash.cnt) + report(" node memory : min: %s, max: %s, set: %s, mem: %s, top: %s, use: %s, cnt: %s", node .min, node .max, node .set, node .mem, node .top, node .use, node.cnt) + report(" token memory : min: %s, max: %s, set: %s, mem: %s, top: %s, use: %s", token .min, token .max, token .set, token .mem, token .top, token.use) + report(" buffer size : min: %s, max: %s, set: %s, mem: %s, top: %s", buffer .min, buffer .max, buffer .set, buffer .mem, buffer .top) + report(" input stack : min: %s, max: %s, set: %s, mem: %s, top: %s", input .min, input .max, input .set, input .mem, input .top) + report(" input files : min: %s, max: %s, set: %s, mem: %s, top: %s", file .min, file .max, file .set, file .mem, file .top) + report(" nest stack : min: %s, max: %s, set: %s, mem: %s, top: %s", nest .min, nest .max, nest .set, nest .mem, nest .top) + report(" parameter stack : min: %s, max: %s, set: %s, mem: %s, top: %s", parameter.min, parameter.max, parameter.set, parameter.mem, parameter.top) + report(" save stack : min: %s, max: %s, set: %s, mem: %s, top: %s", save .min, save .max, save .set, save .mem, save .top) + report("") + report(" approximate memory : %s", tstatus.approximate) + report("") + report(" expansion depth : min: %s, max: %s, set: %s, top: %s", expand.min, expand.max, expand.set, expand.top) + report("") + report(" luabytecode bytes : %s in %s registers", lstatus.bytecode_bytes, lstatus.bytecodes) + report(" luastate bytes : %s of %s", lstatus.state_bytes, lstatus.state_bytes_max or "unknown") + report("") + report(" file callbacks : %s", c.file) + report(" saved callbacks : %s", c.saved) + report(" direct callbacks : %s", c.direct) + report(" function callbacks : %s", c["function"]) + report(" value callbacks : %s", c.value) + report(" message callbacks : %s", c.message) + report(" bytecode callbacks : %s", c.bytecode) + report("") + report(" total callbacks : %s", c.count) + report(" backend callbacks : %s", b.count) + report("") + report(" mp file callbacks : %s", m.file) + report(" mp text callbacks : %s", m.text) + report(" mp script callbacks : %s", m.script) + report(" mp log callbacks : %s", m.log) + report("") + report(" mp total callbacks : %s", m.count) + report("") +end + +local registered = false +local enabled = false + +directives.register("system.usage", function(v) + if v and not registered then + luatex.registerpageactions(function() if enabled then statistics.showusage("page") end end) + luatex.registerstopactions(function() if enabled then statistics.showusage("finish") end end) + registered = true + end + enabled = v +end) diff --git a/tex/context/base/mkiv/trac-inf.lua b/tex/context/base/mkiv/trac-inf.lua index daf478199..3db912be1 100644 --- a/tex/context/base/mkiv/trac-inf.lua +++ b/tex/context/base/mkiv/trac-inf.lua @@ -223,20 +223,10 @@ function statistics.show() return format("%s, type: %s, binary subtree: %s", os.platform or "unknown",os.type or "unknown", environment.texos or "unknown") end) - -- register("luatex banner", function() - -- return lower(status.banner) - -- end) - if LUATEXENGINE == "luametatex" then - register("used engine", function() - return format("%s version: %s, functionality level: %s, format id: %s, compiler: %s", - LUATEXENGINE, LUATEXVERSION, LUATEXFUNCTIONALITY, LUATEXFORMATID, status.used_compiler) - end) - else - register("used engine", function() - return format("%s version: %s, functionality level: %s, banner: %s", - LUATEXENGINE, LUATEXVERSION, LUATEXFUNCTIONALITY, lower(status.banner)) - end) - end + register("used engine", function() + return format("%s version: %s, functionality level: %s, banner: %s", + LUATEXENGINE, LUATEXVERSION, LUATEXFUNCTIONALITY, lower(status.banner)) + end) register("used hash slots", function() return format("%s of %s + %s", status.cs_count, status.hash_size,status.hash_extra) end) @@ -251,17 +241,11 @@ function statistics.show() end end -- so far - -- collectgarbage("collect") register("lua properties",function() - local hashchar = tonumber(status.luatex_hashchars) - local mask = lua.mask or "ascii" + local hash = 2^status.luatex_hashchars + local mask = load([[τεχ = 1]]) and "utf" or "ascii" return format("engine: %s %s, used memory: %s, hash chars: min(%i,40), symbol mask: %s (%s)", - jit and "luajit" or "lua", - LUAVERSION, - statistics.memused(), - hashchar and 2^hashchar or "unknown", - mask, - mask == "utf" and "τεχ" or "tex") + jit and "luajit" or "lua", LUAVERSION, statistics.memused(), hash, mask, mask == "utf" and "τεχ" or "tex") end) register("runtime",statistics.runtime) logs.newline() -- initial newline @@ -328,3 +312,12 @@ function statistics.tracefunction(base,tag,...) statistics.register(formatters["%s.%s"](tag,name),function() return serialize(stat,"calls") end) end end + +function status.getreadstate() + return { + filename = status.filename or "?", + linenumber = status.linenumber or 0, + iocode = status.inputid or 0, + } +end + diff --git a/tex/context/base/mkiv/trac-tim.lmt b/tex/context/base/mkiv/trac-tim.lmt new file mode 100644 index 000000000..ce61c7440 --- /dev/null +++ b/tex/context/base/mkiv/trac-tim.lmt @@ -0,0 +1,177 @@ +if not modules then modules = { } end modules ['trac-tim'] = { + version = 1.001, + comment = "companion to m-timing.tex", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local format, gsub = string.format, string.gsub +local concat, sort = table.concat, table.sort +local next, tonumber = next, tonumber + +moduledata = moduledata or { } +local progress = moduledata.progress or { } +moduledata.progress = progress + +local report_timing = logs.reporter("timing") + +if not nodes then nodes = { } end -- when loaded in mtxrun + +progress.defaultfilename = ((tex and tex.jobname) or "whatever") .. "-luatex-progress" + +-- storage + +function progress.store() + nodes.snapshots.takesample() +end + +function progress.save(name) + local filename = (name or progress.defaultfilename) .. ".lut" + report_timing("saving data in %a",filename) + table.save(filename,nodes.snapshots.getsamples()) + nodes.snapshots.resetsamples() +end + +-- conversion + +local processed = { } + +local function convert(name) + name = name ~= "" and name or progress.defaultfilename + if not processed[name] then + local pages = 0 + local names = { } + local top = { } + local bot = { } + local siz = { } + local paths = { } + local data = table.load(name .. ".lut") + if data then + pages = #data + if pages > 1 then + + local factor = 100 + + local function path(tag,subtag,tagname) + local tagname = tag .. ": " .. subtag + local b, t, s = nil, nil, { } + for k=1,#data do + local v = data[k][tag] + v = v and v[subtag] + if v then + if type(v) == "table" then + set[tagname] = tonumber(v.set) + v = tonumber(v.top) + else + v = tonumber(v) + end + if v then + if b then + if v > t then t = v end + if v < b then b = v end + else + t = v + b = v + end + else + v = 0 + end + else + v = 0 + end + s[k] = v + end + if not b then + -- safeguard against updates + b = 0 + t = 0 + end + top[tagname] = gsub(format("%.3f",t),"%.000$","") + bot[tagname] = gsub(format("%.3f",b),"%.000$","") + local delta = t - b + if delta == 0 then + delta = 1 + else + delta = factor/delta + end + for k=1,#s do + s[k] = format("(%.3f,%.3f)",k,(s[k]-b)*delta) + end + paths[tagname] = concat(s,"--") + return tagname + end + + local function collect(category) + if data[1][category] then + local keys = { } + for k=1,#data do + for k, v in next, data[k][category] do + keys[k] = true + end + end + for k=1,#data do + local m = data[k][category] + for k, v in next, keys do + if not m[k] then m[k] = 0 end + end + end + for k in next, keys do + names[#names+1] = path(category,k) + end + end + end + + collect("nodes") + collect("memories") + collect("variables") + collect("texvariables") + collect("luavariables") + collect("texcallbacks") + collect("mpcallbacks") + collect("backendcallbacks") + + pages = pages - 1 -- hm + end + end + + sort(names) + + processed[name] = { + names = names, + top = top, + bot = bot, + set = set, + pages = pages, + paths = paths, + } + end + return processed[name] +end + +progress.convert = convert + +function progress.set(name,tag) + return convert(name).set[tag] or 0 +end + +function progress.bot(name,tag) + return convert(name).bot[tag] or 0 +end + +function progress.top(name,tag) + return convert(name).top[tag] or 0 +end + +function progress.pages(name,tag) + return convert(name).pages or 0 +end + +function progress.path(name,tag) + return convert(name).paths[tag] or "origin" +end + +function progress.names(name) + return convert(name).names or { } +end + diff --git a/tex/context/interface/mkii/keys-en.xml b/tex/context/interface/mkii/keys-en.xml index f04b8848f..e39ab834f 100644 --- a/tex/context/interface/mkii/keys-en.xml +++ b/tex/context/interface/mkii/keys-en.xml @@ -960,6 +960,7 @@ + diff --git a/tex/context/interface/mkii/keys-nl.xml b/tex/context/interface/mkii/keys-nl.xml index ccec1c829..1590d4c6d 100644 --- a/tex/context/interface/mkii/keys-nl.xml +++ b/tex/context/interface/mkii/keys-nl.xml @@ -640,6 +640,7 @@ + @@ -959,6 +960,7 @@ + diff --git a/tex/context/modules/mkiv/m-timing.mkxl b/tex/context/modules/mkiv/m-timing.mkxl new file mode 100644 index 000000000..3c7667ff6 --- /dev/null +++ b/tex/context/modules/mkiv/m-timing.mkxl @@ -0,0 +1,114 @@ +%D \module +%D [ file=m-timing, +%D version=2007.12.23, +%D title=\CONTEXT\ Modules, +%D subtitle=Timing, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +%D Todo: adapt to latest metafun magic. + +\ifdefined\ShowNamedUsage \endinput \fi + +%D Written at the end of 2007, this module is dedicated to Taco. Reaching this +%D point in \LUATEX\ was a non trivial effort. By visualizing a bit what happens +%D when pages come out of \LUATEX, you may get an idea what is involved. It took +%D much time an dedication to reach this point in the development. Add to that +%D those daily Skype intense discussion, testing and debugging moments. Time flies +%D but progress is impressive. The motto of this module could be: what you see +%D is what you get. An there is much more to come \unknown. + +% \usemodule[timing] +% \setupcolors[state=start] +% \starttext +% \dorecurse{200}{\input tufte \par} \ShowUsage{} +% \stoptext + +\definecolor[usage:line] [darkred] +\definecolor[usage:time] [darkblue] +\definecolor[usage:frame][darkgray] + +\ctxloadluafile{trac-tim.lmt} + +\startluacode +local progress = moduledata.progress + +function progress.show(filename,names,other) + if not filename or filename == "" then + filename = progress.defaultfilename or "" + end + for n, name in pairs(progress.names(filename)) do + if string.find(name,names) and name ~= other and name ~= "variables: lasttime" then + context.ShowNamedUsage(filename,name or "",other or "") + end + end +end +\stopluacode + +\startnotmode[no-timing] + \appendtoks\ctxlua{moduledata.progress.store()}\to\everystarttext + \appendtoks\ctxlua{moduledata.progress.store()}\to\everyshipout + \ctxlua{luatex.registerstopactions(function() moduledata.progress.save() end)} +\stopnotmode + +\unexpanded\def\ShowNamedUsage#1#2#3% + {\setbox\scratchbox\vbox\bgroup + \startMPcode{doublefun} + begingroup ; save p, q, b, h, w ; + path p, q, b ; numeric h, w ; + p := \cldcontext{moduledata.progress.path("#1","#2")} ; + % p := p shifted -llcorner p ; + if bbwidth(p) > 0 : + h := 100 ; w := 2 * h ; + w := \the\textwidth-3pt ; % correct for pen + p := p xstretched w ; + b := boundingbox (llcorner p -- llcorner p shifted (w,h)) ; + pickup pencircle scaled 3pt ; linecap := butt ; + draw b withcolor \MPcolor{usage:frame} ; + draw p withcolor \MPcolor{usage:line} ; + if ("#3" <> "") and ("#3" <> "#2") : + q := \cldcontext{moduledata.progress.path("#1","#3")} ; + % q := q shifted -llcorner q ; + if bbwidth(q) > 1 : + q := q xstretched w ; + pickup pencircle scaled 1.5pt ; linecap := butt ; + draw q withcolor \MPcolor{usage:time} ; + fi ; + fi ; + fi ; + endgroup ; + \stopMPcode + \egroup + \scratchdimen\wd\scratchbox + \ifdim\scratchdimen>\zeropoint + \startlinecorrection[blank] + \box\scratchbox \endgraf + \hbox to \scratchdimen\bgroup + \tttf\strut\detokenize{#2}\hss + \scratchcounter=\cldcontext{moduledata.progress.set("#1","\detokenize{#2}")}\relax + \ifcase\scratchcounter\else + set:\the\scratchcounter, % + \fi + \scratchcounterone=\cldcontext{moduledata.progress.bot("#1","\detokenize{#2}")}\relax + \scratchcountertwo=\cldcontext{moduledata.progress.top("#1","\detokenize{#2}")}\relax + min:\the\scratchcounterone, % + max:\the\scratchcountertwo, % + inc:\the\numexpr\scratchcountertwo-\scratchcounterone\relax, % + pages:\cldcontext{moduledata.progress.pages("#1")}% + \egroup + \stoplinecorrection + \fi} + +\unexpanded\def\LoadUsage #1{\ctxlua{moduledata.progress.convert("#1")}} +\unexpanded\def\ShowUsage #1{\ctxlua{moduledata.progress.show("#1",".*", "variables: elapsed")}} +\unexpanded\def\ShowMemoryUsage #1{\ctxlua{moduledata.progress.show("#1","memory:.*","variables: elapsed")}} +\unexpanded\def\ShowNodeUsage #1{\ctxlua{moduledata.progress.show("#1","nodes:.*", "variables: elapsed")}} +\unexpanded\def\ShowFilteredUsage#1#2{\ctxlua{moduledata.progress.show("#1","#2", "variables: elapsed")}} +\unexpanded\def\ShowSimpleUsage #1#2{\ctxlua{moduledata.progress.show("#1","#2")}} + +\endinput diff --git a/tex/context/modules/mkiv/s-fonts-variable.mkiv b/tex/context/modules/mkiv/s-fonts-variable.mkiv index 5336f6024..7a9d82c5a 100644 --- a/tex/context/modules/mkiv/s-fonts-variable.mkiv +++ b/tex/context/modules/mkiv/s-fonts-variable.mkiv @@ -112,4 +112,14 @@ % \showfontvariations % [font=file:sitka.ttc] +% For Alan: + +% \usemodule[article-basic] +% \usemodule[fonts-variable] +% \starttext +% \showfontvariations[font=file:goldmansansitvf_wght.ttf] +% \showfontvariations[font=file:goldmansansvf_wght.ttf] +% \showfontvariations[font=file:goldmansanscdvf_wght.ttf] +% \stoptext + \stoptext diff --git a/tex/context/modules/mkiv/s-module-basic.mkiv b/tex/context/modules/mkiv/s-module-basic.mkiv index 74621b2a3..7024cd91a 100644 --- a/tex/context/modules/mkiv/s-module-basic.mkiv +++ b/tex/context/modules/mkiv/s-module-basic.mkiv @@ -25,8 +25,6 @@ %D him when you run into problems. Bugs in this style can be sent to %D Hans. -\showframe - \usemodule[abbreviations-words] \startmodule[modules-basics] @@ -45,20 +43,24 @@ \let\module\setupdocument -\definepalet [module:unknown] [localone=black,localtwo=white] +\definepalet [module:unknown] [locallocalone=darkyellow,localtwo=darkred,localthree=white,localfour=darkgray] -\definepalet [module:tex] [localone=blue,localtwo=green] -\definepalet [module:mkii] [localone=blue,localtwo=green] -\definepalet [module:mkiv] [localone=blue,localtwo=green] -\definepalet [module:mkvi] [localone=blue,localtwo=green] +\definepalet [module:tex] [localone=darkblue,localtwo=darkgreen,localthree=white,localfour=darkgray] +\definepalet [module:mkii] [localone=darkblue,localtwo=darkgreen,localthree=white,localfour=darkgray] +\definepalet [module:mkiv] [localone=darkblue,localtwo=darkgreen,localthree=white,localfour=darkgray] +\definepalet [module:mkvi] [localone=darkblue,localtwo=darkgreen,localthree=white,localfour=darkgray] +\definepalet [module:mkxl] [localone=darkblue,localtwo=darkgreen,localthree=white,localfour=darkgray] +\definepalet [module:mklx] [localone=darkblue,localtwo=darkgreen,localthree=white,localfour=darkgray] -\definepalet [module:lua] [localone=red,localtwo=green] -\definepalet [module:cld] [localone=red,localtwo=green] +\definepalet [module:lua] [localone=darkred,localtwo=darkgreen,localthree=white,localfour=darkgray] +\definepalet [module:lmt] [localone=darkred,localtwo=darkgreen,localthree=white,localfour=darkgray] +\definepalet [module:cld] [localone=darkred,localtwo=darkgreen,localthree=white,localfour=darkgray] -\definepalet [module:mp] [localone=red,localtwo=blue] -\definepalet [module:mpii] [localone=red,localtwo=blue] -\definepalet [module:mpiv] [localone=red,localtwo=blue] -\definepalet [module:metapost][localone=red,localtwo=blue] +\definepalet [module:mp] [localone=darkred,localtwo=darkblue,localthree=white,localfour=darkgray] +\definepalet [module:mpii] [localone=darkred,localtwo=darkblue,localthree=white,localfour=darkgray] +\definepalet [module:mpiv] [localone=darkred,localtwo=darkblue,localthree=white,localfour=darkgray] +\definepalet [module:mpxl] [localone=darkred,localtwo=darkblue,localthree=white,localfour=darkgray] +\definepalet [module:metapost][localone=darkred,localtwo=darkblue,localthree=white,localfour=darkgray] \setuppalet [module:unknown] @@ -67,12 +69,10 @@ StartPage ; - color local_white ; local_white := .8white ; - color local_one ; local_one := \MPcolor{localone} randomized (.6,.8) ; - color local_two ; local_two := \MPcolor{localtwo} randomized (.3,.4) ; - - color local_one ; local_one := .75[\MPcolor{localone},white] ; - color local_two ; local_two := .75[\MPcolor{localtwo},white] ; + color local_one ; local_one := .6 * \MPcolor{localone} ; + color local_two ; local_two := .6 * \MPcolor{localtwo} ; + color local_three ; local_three := \MPcolor{localthree} ; + color local_four ; local_four := \MPcolor{localfour} ; numeric width ; width := bbwidth Page ; numeric height ; height := bbheight Page ; @@ -84,12 +84,13 @@ ddy := 0 ; sx := 60u ; for i=1 upto (4 randomized 2) : sy := 7u randomized 3u ; - fill unitsquare xyscaled(sx,sy) shifted (0,ddy) withcolor local_two ; + fill unitsquare xyscaled(sx,sy) shifted (0,ddy) + withcolor local_two ; ddy := ddy + sy + 4u ; endfor ; ) ; p := p shifted (dx,dy) shifted - center p ; - fill boundingbox p enlarged 8u withcolor local_white ; + fill boundingbox p enlarged 8u withcolor local_four ; fill boundingbox p enlarged 4u withcolor local_one ; draw p ; enddef ; @@ -111,7 +112,7 @@ draw anchored.urt(textext("\bf\strut\documentvariable{subtitle}") ysized 1.5cm,urcorner Page shifted (-1cm,-10cm)) ; draw anchored.urt(textext("\bf\strut\documentvariable{author}") ysized 1.5cm,lrcorner Page shifted (-1cm, 5cm)) ; draw anchored.urt(textext("\bf\strut\currentdate") ysized 1.5cm,lrcorner Page shifted (-1cm, 3cm)) ; - ) withcolor .25white ; + ) withcolor local_three ; StopPage ; diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index f4b6fbb85..e33b426dc 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 2020-08-14 18:54 +-- merge date : 2020-08-24 19:46 do -- begin closure to overcome local limits and interference @@ -99,9 +99,6 @@ function optionalrequire(...) return result end end -if lua then - lua.mask=load([[τεχ = 1]]) and "utf" or "ascii" -end local flush=io.flush if flush then local execute=os.execute if execute then function os.execute(...) flush() return execute(...) end end @@ -10483,6 +10480,7 @@ end local hash={} local conc={} table.setmetatableindex(hash,function(t,k) + local v if k<0xD7FF or (k>0xDFFF and k<=0xFFFF) then v=f_single(k) else -- cgit v1.2.3