diff options
Diffstat (limited to 'tex/context/base/mkiv')
-rw-r--r-- | tex/context/base/mkiv/cont-new.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/mkiv/context.lus | 58 | ||||
-rw-r--r-- | tex/context/base/mkiv/context.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/mkiv/context.mkxl | 4 | ||||
-rw-r--r-- | tex/context/base/mkiv/luat-cod.lmt | 278 | ||||
-rw-r--r-- | tex/context/base/mkiv/luat-cod.mkiv | 28 | ||||
-rw-r--r-- | tex/context/base/mkiv/luat-cod.mkxl | 45 | ||||
-rw-r--r-- | tex/context/base/mkiv/luat-fio.lmt | 47 | ||||
-rw-r--r-- | tex/context/base/mkiv/luat-fmt.lua | 172 | ||||
-rw-r--r-- | tex/context/base/mkiv/mult-low.lua | 2 | ||||
-rw-r--r-- | tex/context/base/mkiv/spac-par.mkxl | 10 | ||||
-rw-r--r-- | tex/context/base/mkiv/status-files.pdf | bin | 27976 -> 28017 bytes | |||
-rw-r--r-- | tex/context/base/mkiv/status-lua.pdf | bin | 255052 -> 255035 bytes | |||
-rw-r--r-- | tex/context/base/mkiv/syst-ini.mkxl | 27 | ||||
-rw-r--r-- | tex/context/base/mkiv/syst-lua.lmt | 2 | ||||
-rw-r--r-- | tex/context/base/mkiv/toks-aux.lmt | 108 | ||||
-rw-r--r-- | tex/context/base/mkiv/toks-aux.lua | 84 | ||||
-rw-r--r-- | tex/context/base/mkiv/trac-deb.lua | 50 |
18 files changed, 600 insertions, 319 deletions
diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 0af9acd4e..670de7fde 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.03 14:18} +\newcontextversion{2020.08.04 10:23} %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/context.lus b/tex/context/base/mkiv/context.lus index 960e96adf..29c9b8301 100644 --- a/tex/context/base/mkiv/context.lus +++ b/tex/context/base/mkiv/context.lus @@ -12,60 +12,4 @@ bypass kpse. When the format itself is used, another stub is used (with suffix lui). The current format builder is to a large part determined by the way luatex evolved and the process will probaby change.</p>]]-- -local method = 3 - -local stubfiles = { - - 'luat-cod.lua', - - -- Here follows a list of trac, luat and data files, but we don't - -- it this way any more so there is no need to keep this updated. - -} - --- This method will trigger the creation of a stub file with all neccessary --- libraries merged. This is how we originally did it. - -if method == 1 then - - return stubfiles - -end - --- This method will use this file as stub file so no merge is needed. - -if method == 2 then - - if resolvers then - -- we're loading this file in mtxrun - else - - local sourcepath = string.gsub(arg and arg[1] or "","/[^/]+$","") - local targetpath = "." - - if sourcepath == "" then sourcepath = targetpath end - - for i=1,#stubfiles do - local filename = sourcepath .. "/" .. stubfiles[i] - texio.write_nl("preloading " .. filename) - dofile(filename) - end - texio.write_nl("\n") - - end - - return "context.lus" - -end - --- Only a simple stub: - -if method == 3 then - - return "luat-cod.lua" - -end - --- The last resort. - -return stubfiles +return "luat-cod.lua" diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 6c5d16655..c5b760178 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.03 14:18} +\edef\contextversion{2020.08.04 10:23} %D Kind of special: diff --git a/tex/context/base/mkiv/context.mkxl b/tex/context/base/mkiv/context.mkxl index 256a19140..a70713337 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.03 14:18} +\edef\contextversion{2020.08.04 10:23} %D Kind of special: @@ -84,7 +84,7 @@ \loadmarkfile{syst-pln} \loadmarkfile{syst-mes} -\loadmarkfile{luat-cod} +\loadmkxlfile{luat-cod} \loadmarkfile{luat-bas} \loadmarkfile{luat-lib} \loadmarkfile{luat-soc} diff --git a/tex/context/base/mkiv/luat-cod.lmt b/tex/context/base/mkiv/luat-cod.lmt new file mode 100644 index 000000000..c7c868f42 --- /dev/null +++ b/tex/context/base/mkiv/luat-cod.lmt @@ -0,0 +1,278 @@ +if not modules then modules = { } end modules ['luat-cod'] = { + version = 1.001, + comment = "companion to luat-cod.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local type, loadfile, tonumber = type, loadfile, tonumber +local match, gsub, find, format, gmatch = string.match, string.gsub, string.find, string.format, string.gmatch + +local texconfig, lua = texconfig, lua + +-- maybe pick up from commandline: +-- +-- texconfig.interaction: 0=batchmode 1=nonstopmode 2=scrollmode 3=errornonstopmode 4=normal + +-- 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 + +-- registering bytecode chunks + +local bytedata = lua.bytedata or { } +local bytedone = lua.bytedone or { } + +---.bytecode = bytecode +lua.bytedata = bytedata +lua.bytedone = bytedone + +local setbytecode = lua.setbytecode +----- getbytecode = lua.getbytecode + +lua.firstbytecode = 501 +lua.lastbytecode = lua.lastbytecode or (lua.firstbytecode - 1) -- as we load ourselves again ... maybe return earlier + +function lua.registeredcodes() + return lua.lastbytecode - lua.firstbytecode + 1 +end + +-- no file.* and utilities.parsers.* functions yet + +local strip = false if arg then for i=-1,#arg do if arg[i] == "--c:strip" then strip = true break end end end + +function lua.registercode(filename,options) + local barename = gsub(filename,"%.[%a%d]+$","") + local basename = match(barename,"^.+[/\\](.-)$") or barename + if not bytedone[basename] then + local opts = { } + if type(options) == "string" and options ~= "" then + for s in gmatch(options,"([a-z]+)") do + opts[s] = true + end + end + if barename == filename then + filename = filename .. (opts.autosuffix and CONTEXTLMTXMODE > 0 and ".lmt" or ".lua") + end + local code = environment.luafilechunk(filename,false,opts.optimize) + if code then + bytedone[basename] = true + if environment.initex and not opts.initexonly then + local n = lua.lastbytecode + 1 + bytedata[n] = { name = barename, options = opts } + if strip or opts.strip then + setbytecode(n,code,true) + else + setbytecode(n,code) + end + lua.lastbytecode = n + end + elseif environment.initex then + texio.write_nl(format("\nerror loading file: %s (aborting)",filename)) + os.exit() + end + end +end + +local finalizers = { } + +function lua.registerfinalizer(f,comment) + comment = comment or "unknown" + if type(f) == "function" then + finalizers[#finalizers+1] = { action = f, comment = comment } + else + print(format("\nfatal error: invalid finalizer, action: %s\n",comment)) + os.exit() + end +end + +function lua.finalize(logger) + for i=1,#finalizers do + local finalizer = finalizers[i] + finalizer.action() + if logger then + logger("finalize action: %s",finalizer.comment) + end + end +end + +-- A first start with environments. This will be overloaded later. + +environment = environment or { } +local environment = environment + +-- no string.unquoted yet + +local sourcefile = gsub(arg and arg[1] or "","^\"(.*)\"$","%1") +local sourcepath = find(sourcefile,"/",1,true) and gsub(sourcefile,"/[^/]+$","") or "" +local targetpath = "." + +-- delayed (via metatable): +-- +-- environment.jobname = tex.jobname +-- environment.version = tostring(tex.toks.contextversiontoks) + +-- traditionally the revision has been a one character string and only +-- pdftex went beyond "9" but anyway we test for it + +if LUATEXENGINE == nil then + LUATEXENGINE = status.luatex_engine and string.lower(status.luatex_engine) + or (find(status.banner,"LuajitTeX",1,true) and "luajittex" or "luatex") +end + +if LUATEXVERSION == nil then + LUATEXVERSION = status.luatex_version/100 + + tonumber(status.luatex_revision)/10000 +end + +if CONTEXTLMTXMODE == nil then + CONTEXTLMTXMODE = LUATEXENGINE == "luametatex" and 1 or 0 +end + +if LUATEXFUNCTIONALITY == nil then + LUATEXFUNCTIONALITY = status.development_id or 6346 +end + +if LUATEXFORMATID == nil then + LUATEXFORMATID = status.format_id or 0 +end + +if JITSUPPORTED == nil then + JITSUPPORTED = LUATEXENGINE == "luajittex" or jit -- "or jit" can go +end + +if INITEXMODE == nil then + INITEXMODE = status.ini_version +end + +environment.luatexengine = LUATEXENGINE +environment.luatexversion = LUATEXVERSION +environment.luatexfunctionality = LUATEXFUNCTIONALITY +environment.jitsupported = JITSUPPORTED +environment.initex = INITEXMODE +environment.initexmode = INITEXMODE + +if not environment.luafilechunk then + + function environment.luafilechunk(filename) + local fullname = filename + if sourcepath ~= "" then + fullname = sourcepath .. "/" .. filename + end + local data = loadfile(fullname) + texio.write("term and log","<",data and "+ " or "- ",fullname,">") + if data then +-- package.loaded[gsub(filename,"%..-$"] = + data() + end + return data + end + +end + +if not environment.engineflags then -- raw flags + + local engineflags = { } + + for i=-10,#arg do + local a = arg[i] + if a then + local flag, content = match(a,"^%-%-([^=]+)=?(.-)$") + if flag then + engineflags[flag] = content or "" + end + end + end + + environment.engineflags = engineflags + +end + +-- We need a few premature callbacks in the format generator. We +-- also do this when the format is loaded as otherwise we get +-- a kpse error when disabled. This is an engine issue that will +-- be sorted out in due time. + +-- print("!!!!!!!!!!!!!!!!!!!!!!",lfs.isfile) os.exit() + +if not lfs.isfile then + + local attributes = lfs.attributes + + function lfs.isdir(name) + return attributes(name,"mode") == "directory" + end + + function lfs.isfile(name) + local a = attributes(name,"mode") + return a == "file" or a == "link" or nil + end + +end + +local isfile = lfs.isfile + +local function source_file(name) + local fullname = sourcepath .. "/" .. name + if isfile(fullname) then + return fullname + end + fullname = fullname .. ".tex" + if isfile(fullname) then + return fullname + end + if isfile(name) then + return name + end + name = name .. ".tex" + if isfile(name) then + return name + end + return nil +end + +local function target_file(name) + return targetpath .. "/" .. name +end + +local function find_log_file(name) + return target_file(name) +end + +local function find_data_file(name) + return source_file(name) +end + +local function open_data_file(name) + local fullname = source_file(name) + if fullname then + local f = io.open(fullname,'rb') + return { + reader = function() + return f:read("*line") + end + } + else + return false + end +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 ) diff --git a/tex/context/base/mkiv/luat-cod.mkiv b/tex/context/base/mkiv/luat-cod.mkiv index 823b918c3..e7d58e8ab 100644 --- a/tex/context/base/mkiv/luat-cod.mkiv +++ b/tex/context/base/mkiv/luat-cod.mkiv @@ -15,8 +15,8 @@ \unprotect -%D We cannot use the following due to the fact that existing usage -%D demanded duplicating hashes. +%D We cannot use the following due to the fact that existing usage demanded +%D duplicating hashes. %D %D \starttyping %D \def\expanded#1{\normalexpanded{\noexpand#1}} % ## mess @@ -24,10 +24,9 @@ \newif\ifproductionrun -%D Originally we compiled the \LUA\ files externally and loaded -%D then at runtime, but when the amount grew, we realized that -%D we needed away to store them in the format, which is what -%D bytecode arrays do. And so the following is obsolete: +%D Originally we compiled the \LUA\ files externally and loaded then at runtime, but +%D when the amount grew, we realized that we needed away to store them in the +%D format, which is what bytecode arrays do. And so the following is obsolete: %D %D \starttyping %D \setnewconstant\ctxluaembeddingmode \plusone @@ -36,16 +35,15 @@ %D 1 = runtime compilation and embedding %D \stoptyping %D -%D Allocation of \LUA\ engines has changed too. The original idea -%D was to have multiple \LUA\ instances and it worked that way for -%D several years. Hoewver in practice we used only one engine because -%D scripts need to share data anyway. So eventually \LUATEX\ got only -%D one instance. Because each call is reentrant there is not much -%D danger for crashes. +%D Allocation of \LUA\ engines has changed too. The original idea was to have +%D multiple \LUA\ instances and it worked that way for several years. Hoewver in +%D practice we used only one engine because scripts need to share data anyway. So +%D eventually \LUATEX\ got only one instance. Because each call is reentrant there +%D is not much danger for crashes. %D -%D Most code here has changed after version 0.60 as part of adaption to -%D new functionality. We no longer support the hooks for initializing -%D code as this can be done at the \LUA\ end. +%D Most code here has changed after version 0.60 as part of adaption to new +%D functionality. We no longer support the hooks for initializing code as this can +%D be done at the \LUA\ end. % we can drop the \zerocount as it's default diff --git a/tex/context/base/mkiv/luat-cod.mkxl b/tex/context/base/mkiv/luat-cod.mkxl new file mode 100644 index 000000000..3d3a5dd6b --- /dev/null +++ b/tex/context/base/mkiv/luat-cod.mkxl @@ -0,0 +1,45 @@ +%D \module +%D [ file=luat-cod, +%D version=2005.05.26, +%D title=\CONTEXT\ Lua Macros, +%D subtitle=Code, +%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 Macros / Code} + +\unprotect + +\newif\ifproductionrun + +\let\ctxdirectlua \directlua +\let\ctxlatelua \latelua +\def\ctxsprint #1{\directlua{tex.sprint(tex.ctxcatcodes,#1)}} % saves tokens +\def\ctxwrite #1{\directlua{tex.write(#1)}} % saves tokens +\def\ctxcommand #1{\directlua{commands.#1}} % saves tokens +\def\ctxdirectcommand#1{\directlua{commands.#1}} % saves tokens +\def\ctxlatecommand #1{\latelua {commands.#1}} % saves tokens +\def\ctxreport #1{\directlua{logs.writer[[#1]]}} + +%D Take your choice \unknown + +\let\ctxlua \ctxdirectlua +\let\luacode \ctxdirectlua +\let\lateluacode \ctxlatelua +\let\directluacode\ctxdirectlua + +%D Reporting the version of \LUA\ that we use is done as follows: + +\def\luaversion{\ctxwrite{LUAVERSION}} + +\def\registerctxluafile#1#2{\ctxlua{lua.registercode("#1","#2")}} +\def\ctxloadluafile #1{\ctxlua{lua.registercode("#1")}} + +\registerctxluafile{luat-cod.lmt}{autosuffix} + +\protect \endinput diff --git a/tex/context/base/mkiv/luat-fio.lmt b/tex/context/base/mkiv/luat-fio.lmt index 4ce981c48..c70ed54e4 100644 --- a/tex/context/base/mkiv/luat-fio.lmt +++ b/tex/context/base/mkiv/luat-fio.lmt @@ -26,7 +26,6 @@ if not resolvers.initialized() then if callback then local findbinfile = resolvers.findbinfile - local loadbinfile = resolvers.loadbinfile local findtexfile = resolvers.findtexfile local opentexfile = resolvers.opentexfile local register = callbacks.register @@ -44,23 +43,41 @@ if not resolvers.initialized() then return line end - local function find_data_file(name, index) - if index == 0 then - return "terminal" - else - return findbinfile(name,"tex") - end - end - - local function open_data_file(name, index) - if index == 0 and name == "terminal" then + -- local function find_data_file(name) + -- if not name or name == "" then + -- return "context terminal" + -- else + -- return findbinfile(name,"tex") + -- end + -- end + -- + -- local function open_data_file(name) + -- if not name or name == "" or name == "context terminal" then + -- return { + -- reader = terminal, + -- noflines = 1, + -- filename = name, + -- } + -- else + -- name = opentexfile(name) + -- return name ~= "" and name or false + -- end + -- end + + local function open_data_file(name) + if not name or name == "" then return { reader = terminal, noflines = 1, - filename = name, + filename = "context terminal" } else - return opentexfile(name) + local fullname = findbinfile(name,"tex") + if fullname then + return opentexfile(fullname) + else + return false + end end end @@ -68,10 +85,10 @@ if not resolvers.initialized() then return name end - register('find_data_file' , find_data_file, true) - register('open_data_file' , open_data_file, true) register('find_log_file' , find_any_file, true) register('find_format_file', find_any_file, true) + -- register('find_data_file' , find_data_file, true) + register('open_data_file' , open_data_file, true) end diff --git a/tex/context/base/mkiv/luat-fmt.lua b/tex/context/base/mkiv/luat-fmt.lua index 538556ed2..ab831fafc 100644 --- a/tex/context/base/mkiv/luat-fmt.lua +++ b/tex/context/base/mkiv/luat-fmt.lua @@ -6,6 +6,15 @@ if not modules then modules = { } end modules ['luat-fmt'] = { license = "see context related readme files" } +-- The original idea was to have a generic format builder and as a result the code +-- here (and some elsewhere) is bit more extensive that we really need for context. +-- For instance, in the real beginning we had runtime loading because we had no +-- bytecode registers yet. We also had multiple files as stubs and the context.lus +-- file specified these. More than a decade only the third method was used, just +-- loading luat-cod, so in the end we cpould get rid of the lus file. In due time +-- I'll strip the code here because something generic will never take of and we +-- moved on to luametatex anyway. + local format = string.format local concat = table.concat local quoted = string.quoted @@ -13,9 +22,6 @@ local luasuffixes = utilities.lua.suffixes local report_format = logs.reporter("resolvers","formats") --- this is a bit messy: we also handle flags in mtx-context so best we --- can combine this some day (all here) - local function primaryflags(arguments) local flags = { } if arguments.silent then @@ -71,16 +77,16 @@ local checkers = { } local runners = { - luatex = sandbox.registerrunner { - name = "make luatex format", - program = "luatex", + luametatex = sandbox.registerrunner { + name = "make luametatex format", + program = "luametatex", template = template, checkers = checkers, reporter = report_format, }, - luametatex = sandbox.registerrunner { - name = "make luametatex format", - program = "luametatex", + luatex = sandbox.registerrunner { + name = "make luatex format", + program = "luatex", template = template, checkers = checkers, reporter = report_format, @@ -94,6 +100,18 @@ local runners = { }, } +local stubfiles = { + luametatex = "luat-cod.lmt", + luatex = "luat-cod.lua", + luajittex = "luat-cod.lua", +} + +local suffixes = { + luametatex = "mkxl", + luatex = "mkiv", + luajittex = "mkiv", +} + local function validbinarypath() -- if environment.arguments.addbinarypath then if not environment.arguments.nobinarypath then @@ -107,81 +125,55 @@ local function validbinarypath() end end +local function fatalerror(startupdir,...) + report_format(...) + lfs.chdir(startupdir) +end + function environment.make_format(formatname) - -- first we set up the engine and normally that information is provided - -- by the engine ... when we move to luametatex we could decide to simplfy - -- all the following - local arguments = environment.arguments - local engine = environment.ownmain or "luatex" - local silent = arguments.silent - local errors = arguments.errors + local arguments = environment.arguments + local engine = environment.ownmain or "luatex" + local silent = arguments.silent + local errors = arguments.errors + local runner = runners[engine] + local startupdir = dir.current() + if not runner then + return fatalerror(startupdir,"the format %a cannot be generated, no runner available for engine %a",name,engine) + end -- now we locate the to be used source files ... there are some variants that we -- need to take care - local texsourcename = "" - local texsourcepath = "" - local fulltexsourcename = "" - if engine == "luametatex" then - texsourcename = file.addsuffix(formatname,"mkxl") - fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" - end - if fulltexsourcename == "" then - texsourcename = file.addsuffix(formatname,"mkiv") - fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" + local luasourcename = stubfiles[engine] + if not luasourcename then + return fatalerror(startupdir,"no lua stub file specified for %a",engine) end + local texsourcename = file.addsuffix(formatname,suffixes[engine]) + local fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" if fulltexsourcename == "" then - texsourcename = file.addsuffix(formatname,"tex") - fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" + return fatalerror(startupdir,"no tex source file with name %a (mkiv or tex)",formatname) end - if fulltexsourcename == "" then - report_format("no tex source file with name %a (mkiv or tex)",formatname) - return - end - report_format("using tex source file %a",fulltexsourcename) -- this is tricky: we normally have an expanded path but when we don't have one, -- the current path gets appended - fulltexsourcename = dir.expandname(fulltexsourcename) - texsourcepath = file.dirname(fulltexsourcename) - if not lfs.isfile(fulltexsourcename) then - report_format("no accessible tex source file with name %a",fulltexsourcename) - return + local fulltexsourcename = dir.expandname(fulltexsourcename) + local texsourcepath = file.dirname(fulltexsourcename) + if lfs.isfile(fulltexsourcename) then + report_format("using tex source file %a",fulltexsourcename) + else + return fatalerror(startupdir,"no accessible tex source file with name %a",fulltexsourcename) end -- we're getting there, that is: we have a file that specifies the context format; -- in addition to that file we need a stub for setting up lua as we start rather - -- minimalistic - local specificationname = "context.lus" - local specificationpath = "" - local fullspecificationname = resolvers.findfile(specificationname) or "" - if fullspecificationname == "" then - report_format("unable to locate specification file %a",specificationname) - return - end - report_format("using specification file %a",fullspecificationname) - -- let's expand the found name and so an extra check - fullspecificationname = dir.expandname(fullspecificationname) - specificationpath = file.dirname(fullspecificationname) - if texsourcepath ~= specificationpath then - report_format("tex source file and specification file are on different paths") - return - end - -- let's do an additional check here, if only because we then have a bit better - -- feedback on what goes wrong - if not lfs.isfile(fulltexsourcename) then - report_format("no accessible tex source file with name %a",fulltexsourcename) - return - end - if not lfs.isfile(fullspecificationname) then - report_format("no accessible specification file with name %a",fulltexsourcename) - return + -- minimalistic .. + local fullluasourcename = dir.expandname(file.join(texsourcepath,luasourcename) or "") + if lfs.isfile(fullluasourcename) then + report_format("using lua stub file %a",fullluasourcename) + else + return fatalerror(startupdir,"no accessible lua stub file with name %a",fulltexsourcename) end - -- we're still going strong - report_format("using tex source path %a",texsourcepath) -- we will change tot the format path because some local files will be created -- in the process and we don't want clutter local validformatpath = caches.getwritablepath("formats",engine) or "" - local startupdir = dir.current() if validformatpath == "" then - report_format("invalid format path, insufficient write access") - return + return fatalerror(startupdir,"invalid format path, insufficient write access") end -- in case we have a qualified path, we need to do this before we change -- because we can have half qualified paths (in lxc) @@ -189,53 +181,17 @@ function environment.make_format(formatname) report_format("changing to format path %a",validformatpath) lfs.chdir(validformatpath) if dir.current() ~= validformatpath then - report_format("unable to change to format path %a",validformatpath) - return - end - -- we're now ready for making the format which we do on the first found - -- writable path - local usedluastub = nil - local usedlualibs = dofile(fullspecificationname) - if type(usedlualibs) == "string" then - usedluastub = file.join(specificationpath,usedlualibs) - elseif type(usedlualibs) == "table" then - report_format("using stub specification %a",fullspecificationname) - local texbasename = file.basename(name) - local luastubname = file.addsuffix(texbasename,luasuffixes.lua) - local lucstubname = file.addsuffix(texbasename,luasuffixes.luc) - -- pack libraries in stub - report_format("creating initialization file %a",luastubname) - utilities.merger.selfcreate(usedlualibs,specificationpath,luastubname) - -- compile stub file (does not save that much as we don't use this stub at startup any more) - if utilities.lua.compile(luastubname,lucstubname) and lfs.isfile(lucstubname) then - report_format("using compiled initialization file %a",lucstubname) - usedluastub = lucstubname - else - report_format("using uncompiled initialization file %a",luastubname) - usedluastub = luastubname - end - else - report_format("invalid stub specification %a",fullspecificationname) - lfs.chdir(startupdir) - return - end - -- we're ready to go now but first we check if we actually do have a runner - -- for this engine ... we'd better have one - local runner = runners[engine] - if not runner then - report_format("the format %a cannot be generated, no runner available for engine %a",name,engine) - lfs.chdir(startupdir) - return + return fatalerror(startupdir,"unable to change to format path %a",validformatpath) end -- now we can generate the format, where we use a couple of flags, -- split into two categories local primaryflags = primaryflags(arguments) local secondaryflags = secondaryflags(arguments) - local specification = { + local specification = { binarypath = binarypath, primaryflags = primaryflags, secondaryflags = secondaryflags, - luafile = quoted(usedluastub), + luafile = quoted(fullluasourcename), texfile = quoted(fulltexsourcename), dump = os.platform == "unix" and "\\\\dump" or "\\dump", } @@ -255,7 +211,7 @@ function environment.make_format(formatname) end report_format("format path : %s",validformatpath) report_format("luatex engine : %s",engine) - report_format("lua startup file : %s",usedluastub) + report_format("lua startup file : %s",fullluasourcename) if primaryflags ~= "" then report_format("primary flags : %s",primaryflags) end diff --git a/tex/context/base/mkiv/mult-low.lua b/tex/context/base/mkiv/mult-low.lua index e656b987b..855084aaa 100644 --- a/tex/context/base/mkiv/mult-low.lua +++ b/tex/context/base/mkiv/mult-low.lua @@ -500,6 +500,6 @@ return { -- "unsupportedcs", -- - "openout", "closeout", "write", "openin", "closein", "read", "readline", + "openout", "closeout", "write", "openin", "closein", "read", "readline", "readfromterminal", } } diff --git a/tex/context/base/mkiv/spac-par.mkxl b/tex/context/base/mkiv/spac-par.mkxl index 574cfec12..60b35db13 100644 --- a/tex/context/base/mkiv/spac-par.mkxl +++ b/tex/context/base/mkiv/spac-par.mkxl @@ -163,7 +163,7 @@ {\ifcsname\??parwrapcount#3\endcsname \else \spac_paragraph_install_count{#3}% \fi - \csname\??parwrapcount #3\endcsname\plusone + \csname\??parwrapcount#3\endcsname\plusone #4\wrapuppar{#5}} \protected\def\spac_register_par_wrapper @@ -178,9 +178,11 @@ \csname\??eparwrap\the\currentgrouplevel\endcsname\emptytoks} \protected\def\unregisterparwrapper#1% - {\csname\??parwrapcount #1\endcsname\zerocount - \csname\??parwrapbefore#1\endcsname\emptytoks - \csname\??parwrapafter #1\endcsname\emptytoks} + {\csname\??parwrapcount#1\endcsname\zerocount + \ifcsname\??parwrapbefore#1\endcsname + \lastnamedcs\emptytoks + \csname\??parwrapafter#1\endcsname\emptytoks + \fi} \def\directparwrapper#1#2% {#1\wrapuppar{#2}} diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf Binary files differindex ec8fb1b27..b92bfef95 100644 --- a/tex/context/base/mkiv/status-files.pdf +++ b/tex/context/base/mkiv/status-files.pdf diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf Binary files differindex d1d552035..120965f03 100644 --- a/tex/context/base/mkiv/status-lua.pdf +++ b/tex/context/base/mkiv/status-lua.pdf diff --git a/tex/context/base/mkiv/syst-ini.mkxl b/tex/context/base/mkiv/syst-ini.mkxl index 048a0bb55..2fc4a0259 100644 --- a/tex/context/base/mkiv/syst-ini.mkxl +++ b/tex/context/base/mkiv/syst-ini.mkxl @@ -645,40 +645,35 @@ \protected\def\tracingall {\tracingonline \plusone \tracingcommands \plusthree - \tracingstats \plustwo - \tracingpages \plusone - \tracingoutput \plusone - \tracinglostchars \plustwo \tracingmacros \plustwo + \tracingoutput \plusone + \tracingpages \plusone \tracingparagraphs\plusone \tracingrestores \plusone - \showboxbreadth \maxdimen - \showboxdepth \maxdimen \tracinggroups \plusone \tracingifs \plusone - \tracingscantokens\plusone \tracingnesting \plustwo - \tracingassigns \plustwo} + \tracingassigns \plustwo + \tracingfonts + \showboxbreadth \maxdimen + \showboxdepth \maxdimen} \protected\def\loggingall {\tracingall \tracingonline \zerocount} \protected\def\tracingnone - {\tracingassigns \zerocount + {\showboxdepth \plusthree + \showboxbreadth \plusfive + \tracingassigns \zerocount \tracingnesting \zerocount - \tracingscantokens\zerocount \tracingifs \zerocount \tracinggroups \zerocount - \showboxdepth \plusthree - \showboxbreadth \plusfive \tracingrestores \zerocount \tracingparagraphs\zerocount - \tracingmacros \zerocount - \tracinglostchars \plusone - \tracingoutput \zerocount \tracingpages \zerocount - \tracingstats \zerocount + \tracingoutput \zerocount + \tracingmacros \zerocount \tracingcommands \zerocount \tracingonline \zerocount} diff --git a/tex/context/base/mkiv/syst-lua.lmt b/tex/context/base/mkiv/syst-lua.lmt index 68f0d1b75..29f91ae75 100644 --- a/tex/context/base/mkiv/syst-lua.lmt +++ b/tex/context/base/mkiv/syst-lua.lmt @@ -407,7 +407,7 @@ do end, } - callback.register("end_of_file", function(n) + callback.register("if_end_of_file", function(n) return not channels[n] end) diff --git a/tex/context/base/mkiv/toks-aux.lmt b/tex/context/base/mkiv/toks-aux.lmt new file mode 100644 index 000000000..d46a5872a --- /dev/null +++ b/tex/context/base/mkiv/toks-aux.lmt @@ -0,0 +1,108 @@ +if not modules then modules = { } end modules ['toks-aux'] = { + version = 1.001, + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +if CONTEXTLMTXMODE > 0 then + + local type, tostring = type, tostring + local max = math.max + local formatters, gsub = string.formatters, string.gsub + + interfaces.implement { + name = "showluatokens", + public = true, + protected = true, + actions = function() + local f0 = formatters["%s: %s"] + local nl = logs.newline + local wr = logs.writer + local t = token.peek_next() -- local t = token.scan_next() token.put_back(t) + local n = "" + local w = "" + local c = t.cmdname + if c == "left_brace" then + w = "given token list" + t = token.scan_toks(false) + elseif c == "register_toks" then + token.scan_next() + w = "token register" + n = t.csname or t.index + t = tex.gettoks(n,true) + elseif c == "internal_toks" then + token.scan_next() + w = "internal token variable" + n = t.csname or t.index + t = tex.gettoks(n,true) + else + if t.protected then + w = "protected control sequence" + else + w = "control sequence" + end + n = token.scan_csname() + t = token.get_meaning(n,true) + end + wr(f0(w,n)) + nl() + if type(t) == "table" then + local w1 = 4 + local w2 = 1 + local w3 = 3 + local w4 = 3 + for i=1,#t do + local ti = t[i] + w1 = max(w1,#tostring(ti.id)) + w2 = max(w2,#tostring(ti.command)) + w3 = max(w3,#tostring(ti.index)) + w4 = max(w4,#ti.cmdname) + end + local f1 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s %s"] + local f2 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s"] + local f3 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s %C"] + for i=1,#t do + local ti = t[i] + local cs = ti.csname + local id = ti.id + local ix = ti.index + local cd = ti.command + local cn = gsub(ti.cmdname,"_"," ") + if cs then + wr(f1(id,cd,ix,cn,cs)) + elseif cn == "letter" or cn == "other_char" then + wr(f3(id,cd,ix,cn,ix)) + else + wr(f2(id,cd,ix,cn)) + if cn == "end_match" then + wr("-------") + end + end + end + nl() + end + end + } + + -- for the moment here, will move to initex only (also see node-ini.lua) : + + if environment.initex then + + local texchardef = tex.chardef + local groupcodes = { } + + for k, v in next, tex.getgroupvalues() do + groupcodes[k] = gsub(v,"_","") + end + + groupcodes = utilities.storage.allocate(table.swapped(groupcodes,groupcodes)) + tex.groupcodes = groupcodes + + for i=0,#groupcodes do + texchardef(groupcodes[i] .. "groupcode",i) + end + + end + +end diff --git a/tex/context/base/mkiv/toks-aux.lua b/tex/context/base/mkiv/toks-aux.lua deleted file mode 100644 index cce29a32a..000000000 --- a/tex/context/base/mkiv/toks-aux.lua +++ /dev/null @@ -1,84 +0,0 @@ -if not modules then modules = { } end modules ['toks-aux'] = { - version = 1.001, - author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", - copyright = "PRAGMA ADE / ConTeXt Development Team", - license = "see context related readme files" -} - -local type, tostring = type, tostring -local max = math.max -local formatters, gsub = string.formatters, string.gsub - -interfaces.implement { - name = "showluatokens", - public = true, - protected = true, - actions = function() - local f0 = formatters["%s: %s"] - local nl = logs.newline - local wr = logs.writer - local t = token.peek_next() -- local t = token.scan_next() token.put_back(t) - local n = "" - local w = "" - local c = t.cmdname - if c == "left_brace" then - w = "given token list" - t = token.scan_toks(false) - elseif c == "register_toks" then - token.scan_next() - w = "token register" - n = t.csname or t.index - t = tex.gettoks(n,true) - elseif c == "internal_toks" then - token.scan_next() - w = "internal token variable" - n = t.csname or t.index - t = tex.gettoks(n,true) - else - if t.protected then - w = "protected control sequence" - else - w = "control sequence" - end - n = token.scan_csname() - t = token.get_meaning(n,true) - end - wr(f0(w,n)) - nl() - if type(t) == "table" then - local w1 = 4 - local w2 = 1 - local w3 = 3 - local w4 = 3 - for i=1,#t do - local ti = t[i] - w1 = max(w1,#tostring(ti.id)) - w2 = max(w2,#tostring(ti.command)) - w3 = max(w3,#tostring(ti.index)) - w4 = max(w4,#ti.cmdname) - end - local f1 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s %s"] - local f2 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s"] - local f3 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s %C"] - for i=1,#t do - local ti = t[i] - local cs = ti.csname - local id = ti.id - local ix = ti.index - local cd = ti.command - local cn = gsub(ti.cmdname,"_"," ") - if cs then - wr(f1(id,cd,ix,cn,cs)) - elseif cn == "letter" or cn == "other_char" then - wr(f3(id,cd,ix,cn,ix)) - else - wr(f2(id,cd,ix,cn)) - if cn == "end_match" then - wr("-------") - end - end - end - nl() - end - end -} diff --git a/tex/context/base/mkiv/trac-deb.lua b/tex/context/base/mkiv/trac-deb.lua index d24922042..cdf40fd59 100644 --- a/tex/context/base/mkiv/trac-deb.lua +++ b/tex/context/base/mkiv/trac-deb.lua @@ -361,20 +361,41 @@ 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('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) +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 -- this might move @@ -433,6 +454,7 @@ function lmx.overloaderror(v) end callback.register('show_error_hook', function() showerror() end) -- prevents arguments being passed callback.register('show_lua_error_hook', function() showerror() end) -- prevents arguments being passed + callback.register('show_tex_error_hook', function() showerror() end) -- prevents arguments being passed end directives.register("system.showerror", lmx.overloaderror) |