diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkxl/node-met.lmt')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkxl/node-met.lmt | 229 |
1 files changed, 67 insertions, 162 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkxl/node-met.lmt b/Master/texmf-dist/tex/context/base/mkxl/node-met.lmt index a3f02d7093a..81d5b556134 100644 --- a/Master/texmf-dist/tex/context/base/mkxl/node-met.lmt +++ b/Master/texmf-dist/tex/context/base/mkxl/node-met.lmt @@ -10,7 +10,7 @@ if not modules then modules = { } end modules ['node-MET'] = { -- the regular code is proven stable. No support otherwise. -- luatex: todo: copylist should return h, t --- todo: see if using insert_before and insert_after makes sense here +-- todo: see if using insertbefore and insertafter makes sense here -- This file is a side effect of the \LUATEX\ speed optimization project of Luigi -- Scarso and me. As \CONTEXT\ spends over half its time in \LUA, we though that @@ -65,84 +65,66 @@ end -- We start with some helpers and provide all relevant basic functions in the -- node namespace as well. -nodes = nodes or { } -local nodes = nodes - -local nodecodes = nodes.nodecodes - -nodes.tostring = node.tostring or tostring -nodes.copy = node.copy -nodes.copy_node = node.copy -nodes.copy_list = node.copy_list -nodes.delete = node.delete -nodes.dimensions = node.dimensions -nodes.rangedimensions = node.rangedimensions -nodes.end_of_math = node.end_of_math -nodes.flush = node.flush_node -nodes.flush_node = node.flush_node -nodes.flush_list = node.flush_list -nodes.free = node.free -nodes.insert_after = node.insert_after -nodes.insert_before = node.insert_before -nodes.hpack = node.hpack -nodes.new = node.new -nodes.tail = node.tail -nodes.traverse = node.traverse -nodes.traverse_id = node.traverse_id -nodes.traverse_char = node.traverse_char -nodes.traverse_glyph = node.traverse_glyph -nodes.traverse_list = node.traverse_list -nodes.slide = node.slide -nodes.vpack = node.vpack -nodes.fields = node.fields -nodes.is_node = node.is_node -nodes.setglue = node.setglue -nodes.uses_font = node.uses_font - -nodes.first_glyph = node.first_glyph -nodes.has_glyph = node.has_glyph or node.first_glyph - -nodes.current_attributes = node.current_attributes or node.current_attr -nodes.has_field = node.has_field -nodes.last_node = node.last_node -nodes.usedlist = node.usedlist -nodes.protrusion_skippable = node.protrusion_skippable -nodes.check_discretionaries = node.check_discretionaries -nodes.write = node.write -nodes.flatten_discretionaries = node.flatten_discretionaries - -nodes.count = node.count -nodes.length = node.length - -nodes.has_attribute = node.has_attribute -nodes.set_attribute = node.set_attribute -nodes.find_attribute = node.find_attribute -nodes.unset_attribute = node.unset_attribute - -nodes.protect_glyph = node.protect_glyph -nodes.protect_glyphs = node.protect_glyphs -nodes.unprotect_glyph = node.unprotect_glyph -nodes.unprotect_glyphs = node.unprotect_glyphs -nodes.kerning = node.kerning -nodes.ligaturing = node.ligaturing -nodes.hyphenating = node.hyphenating -nodes.mlist_to_hlist = node.mlist_to_hlist - -nodes.effective_glue = node.effective_glue -nodes.getglue = node.getglue -nodes.setglue = node.setglue -nodes.is_zero_glue = node.is_zero_glue - -nodes.tonode = function(n) return n end -nodes.tonut = function(n) return n end +nodes = nodes or { } +local nodes = nodes + +local nodecodes = nodes.nodecodes + +nodes.copy = node.copy +nodes.copylist = node.copylist +nodes.copy_node = node.copy +nodes.currentattributes = node.currentattributes +nodes.remove = node.remove +nodes.fields = node.fields +nodes.flush = node.flushnode +nodes.flushlist = node.flushlist +nodes.flushnode = node.flushnode +nodes.getattribute = node.getattribute +nodes.hasattribute = node.hasattribute +nodes.hasfield = node.hasfield +nodes.insertafter = node.insertafter +nodes.insertbefore = node.insertbefore +-----.appendafter = node.appendafter +-----.prependbefore = node.prependbefore +nodes.isnode = node.isnode +nodes.isdirect = node.isdirect +nodes.isnut = node.isdirect +nodes.new = node.new +nodes.setattribute = node.setattribute +nodes.tail = node.tail +nodes.tostring = node.tostring or tostring +nodes.traverse = node.traverse +nodes.traverseid = node.traverseid +nodes.unsetattribute = node.unsetattribute +nodes.write = node.write +nodes.usedlist = node.usedlist + +nodes.getpropertiestable = node.get_properties_table +nodes.getproperty = node.getproperty +nodes.setproperty = node.setproperty + +-----.show = node.show +nodes.serialized = node.serialized + +-- nodes.usedlist +-- nodes.inuse +-- nodes.instock +-- nodes.type +-- nodes.types +-- nodes.subtypes +-- nodes.values +-- nodes.id + +-- nodes.tonode = function(n) return n end +-- nodes.tonut = function(n) return n end -- These are never used in \CONTEXT, only as a gimmick in node operators -- so we keep them around. -- --- Fro nwo I keep them in \LMTX\ but they will go away! +-- Fot now I keep them in \LMTX\ but they will go away! local n_getfield = node.getfield -local n_getattr = node.get_attribute +local n_getattr = node.getattribute local n_setfield = node.setfield local n_setattr = n_setfield @@ -151,7 +133,7 @@ nodes.getfield = n_getfield nodes.setfield = n_setfield nodes.getattr = n_getattr nodes.setattr = n_setattr -nodes.takeattr = nodes.unset_attribute +nodes.takeattr = nodes.unsetattribute local function n_getid (n) return n_getfield(n,"id") end local function n_getsubtype(n) return n_getfield(n,"subtype") end @@ -215,12 +197,12 @@ nodes.setlink = n_setlink nodes.getbox = node.getbox or tex.getbox nodes.setbox = node.setbox or tex.setbox -local n_flush_node = nodes.flush +local n_flushnode = nodes.flushnode local n_copy_node = nodes.copy -local n_copy_list = nodes.copy_list +local n_copy_list = nodes.copylist local n_find_tail = nodes.tail -local n_insert_after = nodes.insert_after -local n_insert_before = nodes.insert_before +local n_insertafter = nodes.insertafter +local n_insertbefore = nodes.insertbefore local n_slide = nodes.slide local n_remove_node = node.remove -- not yet nodes.remove @@ -231,7 +213,7 @@ local function remove(head,current,free_too) if not t then -- forget about it elseif free_too then - n_flush_node(t) + n_flushnode(t) t = nil else n_setboth(t) @@ -268,10 +250,10 @@ function nodes.replace(head,current,new) -- no head returned if false if head == current then head = new end - n_flush_node(current) + n_flushnode(current) return head, new else - n_flush_node(current) + n_flushnode(current) return new end end @@ -280,14 +262,14 @@ end function nodes.append(head,current,...) for i=1,select("#",...) do - head, current = n_insert_after(head,current,(select(i,...))) + head, current = n_insertafter(head,current,(select(i,...))) end return head, current end function nodes.prepend(head,current,...) for i=1,select("#",...) do - head, current = n_insert_before(head,current,(select(i,...))) + head, current = n_insertbefore(head,current,(select(i,...))) end return head, current end @@ -324,10 +306,6 @@ function nodes.concat(list) -- consider tail instead of slide return head, tail end -function nodes.reference(n) - return n and tonut(n) or "<none>" -end - -- Here starts an experiment with metatables. Of course this only works with nodes -- wrapped in userdata with a metatable. -- @@ -436,7 +414,7 @@ metatable.__sub = function(first,second) local tail = n_find_tail(first) for i=1,second do local prev = n_getprev(tail) - n_flush_node(tail) -- can become flushlist/flushnode + n_flushnode(tail) -- can become flushlist/flushnode if prev then tail = prev else @@ -471,7 +449,7 @@ metatable.__add = function(first,second) local head = second for i=1,first do local second = n_getnext(head) - n_flush_node(head) -- can become flushlist/flushnode + n_flushnode(head) -- can become flushlist/flushnode if second then head = second else @@ -558,76 +536,3 @@ metatable.__unm = function(head) n_setnext(last) return first end - --- see node-nut.lua for more info on going nuts - --- if not gonuts then --- --- local nuts = { } --- nodes.nuts = nuts --- --- local function dummy(f) return f end --- --- nodes.vianuts = dummy --- nodes.vianodes = dummy --- --- for k, v in next, nodes do --- if type(v) == "function" then --- nuts[k] = v --- end --- end --- --- end - --- also handy - -local tonode = nodes.tonode -local whatsit_code = nodecodes.whatsit -local getfields = node.fields -local sort = table.sort -local whatsitkeys = { } -local keys = { whatsit = whatsitkeys } -local messyhack = table.tohash { -- temporary solution - nodecodes.attributelist, - nodecodes.attribute, - nodecodes.action, -- hm -} - -setmetatableindex(keys,function(t,k) - local v = (k == "attributelist" or k == nodecodes.attributelist) and { } or getfields(k) - if messyhack[k] then - for i=1,#v do - if v[i] == "subtype" then - remove(v,i) - break - end - end - end - if v[ 0] then v[#v+1] = "next" v[ 0] = nil end - if v[-1] then v[#v+1] = "prev" v[-1] = nil end - sort(v) - t[k] = v - return v -end) - -setmetatableindex(whatsitkeys,function(t,k) - local v = getfields(whatsit_code,k) - if v[ 0] then v[#v+1] = "next" v[ 0] = nil end - if v[-1] then v[#v+1] = "prev" v[-1] = nil end - sort(v) - t[k] = v - return v -end) - -local function nodefields(n) - n = tonode(n) - local id = n.id - if id == whatsit_code then - return whatsitkeys[n.subtype] - else - return keys[id] - end -end - -nodes.keys = keys -- [id][subtype] -nodes.fields = nodefields -- (n) |