diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/node-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/node-ini.lua | 319 |
1 files changed, 79 insertions, 240 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/node-ini.lua b/Master/texmf-dist/tex/context/base/mkiv/node-ini.lua index f910c7e012f..806ac5658d7 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/node-ini.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/node-ini.lua @@ -7,15 +7,13 @@ if not modules then modules = { } end modules ['node-ini'] = { } --[[ldx-- -<p>Most of the code that had accumulated here is now separated in -modules.</p> +<p>Most of the code that had accumulated here is now separated in modules.</p> --ldx]]-- --- this module is being reconstructed --- --- todo: datatype table per node type - --- todo: query names with new node.subtypes +-- I need to clean up this module as it's a bit of a mess now. The latest luatex +-- has most tables but we have a few more in luametatex. Also, some are different +-- between these engines. We started out with hardcoded tables, that then ended +-- up as comments and are now gone (as they differ per engine anyway). local next, type, tostring = next, type, tostring local gsub = string.gsub @@ -23,36 +21,34 @@ local concat, remove = table.concat, table.remove local sortedhash, sortedkeys, swapped = table.sortedhash, table.sortedkeys, table.swapped --[[ldx-- -<p>Access to nodes is what gives <l n='luatex'/> its power. Here we -implement a few helper functions. These functions are rather optimized.</p> +<p>Access to nodes is what gives <l n='luatex'/> its power. Here we implement a +few helper functions. These functions are rather optimized.</p> --ldx]]-- --[[ldx-- -<p>When manipulating node lists in <l n='context'/>, we will remove -nodes and insert new ones. While node access was implemented, we did -quite some experiments in order to find out if manipulating nodes -in <l n='lua'/> was feasible from the perspective of performance.</p> - -<p>First of all, we noticed that the bottleneck is more with excessive -callbacks (some gets called very often) and the conversion from and to -<l n='tex'/>'s datastructures. However, at the <l n='lua'/> end, we -found that inserting and deleting nodes in a table could become a -bottleneck.</p> - -<p>This resulted in two special situations in passing nodes back to -<l n='tex'/>: a table entry with value <type>false</type> is ignored, -and when instead of a table <type>true</type> is returned, the -original table is used.</p> - -<p>Insertion is handled (at least in <l n='context'/> as follows. When -we need to insert a node at a certain position, we change the node at -that position by a dummy node, tagged <type>inline</type> which itself -has_attribute the original node and one or more new nodes. Before we pass -back the list we collapse the list. Of course collapsing could be built -into the <l n='tex'/> engine, but this is a not so natural extension.</p> - -<p>When we collapse (something that we only do when really needed), we -also ignore the empty nodes. [This is obsolete!]</p> +<p>When manipulating node lists in <l n='context'/>, we will remove nodes and +insert new ones. While node access was implemented, we did quite some experiments +in order to find out if manipulating nodes in <l n='lua'/> was feasible from the +perspective of performance.</p> + +<p>First of all, we noticed that the bottleneck is more with excessive callbacks +(some gets called very often) and the conversion from and to <l n='tex'/>'s +datastructures. However, at the <l n='lua'/> end, we found that inserting and +deleting nodes in a table could become a bottleneck.</p> + +<p>This resulted in two special situations in passing nodes back to <l n='tex'/>: +a table entry with value <type>false</type> is ignored, and when instead of a +table <type>true</type> is returned, the original table is used.</p> + +<p>Insertion is handled (at least in <l n='context'/> as follows. When we need to +insert a node at a certain position, we change the node at that position by a +dummy node, tagged <type>inline</type> which itself has_attribute the original +node and one or more new nodes. Before we pass back the list we collapse the +list. Of course collapsing could be built into the <l n='tex'/> engine, but this +is a not so natural extension.</p> + +<p>When we collapse (something that we only do when really needed), we also +ignore the empty nodes. [This is obsolete!]</p> --ldx]]-- -- local gf = node.direct.getfield @@ -76,206 +72,25 @@ tex.magicconstants = { -- we use tex.constants for something else trueinch = 4736286, } --- local listcodes = allocate { --- [0] = "unknown", --- [1] = "line", --- [2] = "box", --- [3] = "indent", --- [4] = "alignment", -- row or column --- [5] = "cell", --- [6] = "equation", --- [7] = "equationnumber", --- } - -local listcodes = mark(getsubtypes("list")) - --- local rulecodes = allocate { --- [0] = "normal", --- [1] = "box", --- [2] = "image", --- [3] = "empty", --- [4] = "user", --- } - -local rulecodes = mark(getsubtypes("rule")) - -if not rulecodes[5] then - rulecodes[5] = "over" - rulecodes[6] = "under" - rulecodes[7] = "fraction" - rulecodes[8] = "radical" -end - --- local dircodes = mark(getsubtypes("dir")) - -dircodes = allocate { - [0] = "normal", - [1] = "cancel", -} - --- local glyphcodes = allocate { --- [ 1] = "character", --- [ 2] = "ligature", --- [ 4] = "ghost", --- [ 8] = "left", --- [16] = "right", --- } - -local glyphcodes = mark(getsubtypes("glyph")) - --- local disccodes = allocate { --- [0] = "discretionary", -- \discretionary --- [1] = "explicit", -- \- --- [2] = "automatic", -- following a - --- [3] = "regular", -- by hyphenator: simple --- [4] = "first", -- by hyphenator: hard first item --- [5] = "second", -- by hyphenator: hard second item --- } - -local disccodes = mark(getsubtypes("disc")) - --- local gluecodes = allocate { --- [ 0] = "userskip", --- [ 1] = "lineskip", --- [ 2] = "baselineskip", --- [ 3] = "parskip", --- [ 4] = "abovedisplayskip", --- [ 5] = "belowdisplayskip", --- [ 6] = "abovedisplayshortskip", --- [ 7] = "belowdisplayshortskip", --- [ 8] = "leftskip", --- [ 9] = "rightskip", --- [ 10] = "topskip", --- [ 11] = "splittopskip", --- [ 12] = "tabskip", --- [ 13] = "spaceskip", --- [ 14] = "xspaceskip", --- [ 15] = "parfillskip", --- [ 16] = "mathskip", -- experiment --- [ 17] = "thinmuskip", --- [ 18] = "medmuskip", --- [ 19] = "thickmuskip", --- [ 98] = "conditionalmathglue", --- [ 99] = "muskip", --- [100] = "leaders", --- [101] = "cleaders", --- [102] = "xleaders", --- [103] = "gleaders", --- } - -local gluecodes = mark(getsubtypes("glue")) - --- local leadercodes = allocate { --- [100] = "leaders", --- [101] = "cleaders", --- [102] = "xleaders", --- [103] = "gleaders", --- } - -local leadercodes = mark(getsubtypes("leader")) - --- local fillcodes = allocate { --- [0] = "stretch", --- [1] = "fi", --- [2] = "fil", --- [3] = "fill", --- [4] = "filll", --- } - -local fillcodes = mark(getsubtypes("fill")) - --- for now: - -local boundarycodes = allocate { - [0] = "cancel", - [1] = "user", - [2] = "protrusion", - [3] = "word", -} - --- local boundarycodes = mark(getsubtypes("boundary")) - --- local penaltycodes = allocate { -- unfortunately not used (yet) --- [ 0] = "userpenalty", --- } - -local penaltycodes = mark(getsubtypes("penalty")) - -table.setmetatableindex(penaltycodes,function(t,k) return "userpenalty" end) -- not used anyway - --- local kerncodes = allocate { --- [0] = "fontkern", --- [1] = "userkern", --- [2] = "accentkern", --- [3] = "italiccorrection", --- } - -local kerncodes = mark(getsubtypes("kern")) - --- local margincodes = allocate { --- [0] = "left", --- [1] = "right", --- } - -local margincodes = mark(getsubtypes("marginkern")) - --- local mathcodes = allocate { --- [0] = "beginmath", --- [1] = "endmath", --- } - -local mathcodes = mark(getsubtypes("math")) - --- local noadcodes = allocate { -- simple nodes --- [ 0] = "ord", --- [ 1] = "opdisplaylimits", --- [ 2] = "oplimits", --- [ 3] = "opnolimits", --- [ 4] = "bin", --- [ 5] = "rel", --- [ 6] = "open", --- [ 7] = "close", --- [ 8] = "punct", --- [ 9] = "inner", --- [10] = "under", --- [11] = "over", --- [12] = "vcenter", --- } - -local noadcodes = mark(getsubtypes("noad")) - --- local radicalcodes = allocate { --- [0] = "radical", --- [1] = "uradical", --- [2] = "uroot", --- [3] = "uunderdelimiter", --- [4] = "uoverdelimiter", --- [5] = "udelimiterunder", --- [6] = "udelimiterover", --- } - -local radicalcodes = mark(getsubtypes("radical")) - --- local accentcodes = allocate { --- [0] = "bothflexible", --- [1] = "fixedtop", --- [2] = "fixedbottom", --- [3] = "fixedboth", --- } - -local accentcodes = mark(getsubtypes("accent")) - --- local fencecodes = allocate { --- [0] = "unset", --- [1] = "left", --- [2] = "middle", --- [3] = "right", --- [4] = "no", --- } - -local fencecodes = mark(getsubtypes("fence")) - --- maybe we also need fractioncodes +local listcodes = mark(getsubtypes("list")) +local rulecodes = mark(getsubtypes("rule")) +local dircodes = mark(getsubtypes("dir")) +local glyphcodes = mark(getsubtypes("glyph")) +local disccodes = mark(getsubtypes("disc")) +local gluecodes = mark(getsubtypes("glue")) +local leadercodes = mark(getsubtypes("leader")) +local fillcodes = mark(getsubtypes("fill")) +local boundarycodes = mark(getsubtypes("boundary")) +local penaltycodes = mark(getsubtypes("penalty")) +local kerncodes = mark(getsubtypes("kern")) +local margincodes = mark(getsubtypes("marginkern")) +local mathcodes = mark(getsubtypes("math")) +local noadcodes = mark(getsubtypes("noad")) +local radicalcodes = mark(getsubtypes("radical")) +local accentcodes = mark(getsubtypes("accent")) +local fencecodes = mark(getsubtypes("fence")) +----- fractioncodes = mark(getsubtypes("fraction")) +local localparcodes = allocate { [0] = "new_graf", "local_box", "hmode_par", "penalty", "math" } -- only in luametatex now local function simplified(t) local r = { } @@ -356,6 +171,7 @@ margincodes = allocate(swapped(margincodes,margincodes)) disccodes = allocate(swapped(disccodes,disccodes)) accentcodes = allocate(swapped(accentcodes,accentcodes)) fencecodes = allocate(swapped(fencecodes,fencecodes)) +localparcodes = allocate(swapped(localparcodes,localparcodes)) rulecodes = allocate(swapped(rulecodes,rulecodes)) leadercodes = allocate(swapped(leadercodes,leadercodes)) usercodes = allocate(swapped(usercodes,usercodes)) @@ -364,7 +180,15 @@ dirvalues = allocate(swapped(dirvalues,dirvalues)) gluevalues = allocate(swapped(gluevalues,gluevalues)) literalvalues = allocate(swapped(literalvalues,literalvalues)) -if CONTEXTLMTXMODE > 1 then +if not gluecodes.indentskip then + gluecodes.indentskip = gluecodes.userskip + gluecodes.lefthangskip = gluecodes.userskip + gluecodes.righthangskip = gluecodes.userskip + gluecodes.correctionskip = gluecodes.userskip + gluecodes.intermathskip = gluecodes.userskip +end + +if CONTEXTLMTXMODE > 0 then whatcodes.literal = 0x1 whatcodes[0x1] = "literal" whatcodes.latelua = 0x2 whatcodes[0x2] = "latelua" whatcodes.userdefined = 0x3 whatcodes[0x3] = "userdefined" @@ -399,6 +223,7 @@ nodes.disccodes = disccodes nodes.accentcodes = accentcodes nodes.radicalcodes = radicalcodes nodes.fencecodes = fencecodes +nodes.localparcodes = localparcodes nodes.rulecodes = rulecodes nodes.leadercodes = leadercodes nodes.usercodes = usercodes @@ -420,12 +245,14 @@ nodes.subtypes = allocate { [nodecodes.glyph] = glyphcodes, [nodecodes.hlist] = listcodes, [nodecodes.kern] = kerncodes, + [nodecodes.localpar] = localparcodes, [nodecodes.marginkern] = margincodes, [nodecodes.math] = mathcodes, [nodecodes.noad] = noadcodes, [nodecodes.penalty] = penaltycodes, [nodecodes.radical] = radicalcodes, [nodecodes.rule] = rulecodes, + -- [nodecodes.user] = usercodes, [nodecodes.vlist] = listcodes, [nodecodes.whatsit] = whatcodes, } @@ -447,6 +274,8 @@ nodes.literalvalues = literalvalues -- more friendly glyphcodes.glyph = glyphcodes.character +localparcodes.vmode_par = localparcodes.new_graf + listcodes.row = listcodes.alignment listcodes.column = listcodes.alignment @@ -512,14 +341,24 @@ end trackers.register("system.showcodes", nodes.showcodes) -if not nodecodes.dir then - report_codes("use a newer version of luatex") - os.exit() -end - -- We don't need this sanitize-after-callback in ConTeXt and by disabling it we -- also have a way to check if LuaTeX itself does the right thing. if node.fix_node_lists then node.fix_node_lists(false) end + +-- We use the real node code numbers. + +if CONTEXTLMTXMODE > 0 then + + local texchardef = tex.chardef + + if texchardef then + for i=0,nodecodes.glyph do + texchardef(nodecodes[i] .. "nodecode",i) + end + tex.set("internalcodesmode",1) + end + +end |