summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/node-met.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-03-26 13:38:18 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-03-26 13:38:18 +0100
commit788487819ccf38a8478cc2afd88e0c0b088d0ec1 (patch)
tree215addbe3b9e293c2958227e7fc8923880b2e71f /tex/context/base/mkiv/node-met.lua
parentadfe72d5a0c9d7bdc1bd7bc8faabb4d05e21d70a (diff)
downloadcontext-788487819ccf38a8478cc2afd88e0c0b088d0ec1.tar.gz
2016-03-26 13:07:00
Diffstat (limited to 'tex/context/base/mkiv/node-met.lua')
-rw-r--r--tex/context/base/mkiv/node-met.lua161
1 files changed, 87 insertions, 74 deletions
diff --git a/tex/context/base/mkiv/node-met.lua b/tex/context/base/mkiv/node-met.lua
index 5c6e18bd3..a5ad15c80 100644
--- a/tex/context/base/mkiv/node-met.lua
+++ b/tex/context/base/mkiv/node-met.lua
@@ -127,32 +127,70 @@ nodes.tonut = function(n) return n end
local getfield = node.getfield
local setfield = node.setfield
-local getattr = node.get_attribute or node.has_attribute or getfield
+local getattr = node.get_attribute
local setattr = setfield
-local getnext = node.getnext or function(n) return getfield(n,"next") end
-local getprev = node.getprev or function(n) return getfield(n,"prev") end
-local getid = node.getid or function(n) return getfield(n,"id") end
-local getchar = node.getchar or function(n) return getfield(n,"char") end
-local getfont = node.getfont or function(n) return getfield(n,"font") end
-local getsubtype = node.getsubtype or function(n) return getfield(n,"subtype") end
-local getlist = node.getlist or function(n) return getfield(n,"list") end
-local getleader = node.getleader or function(n) return getfield(n,"leader") end
-
-nodes.getfield = getfield
-nodes.getattr = getattr
-
-nodes.setfield = setfield
-nodes.setattr = setattr
-
-nodes.getnext = getnext
-nodes.getprev = getprev
-nodes.getid = getid
-nodes.getchar = getchar
-nodes.getfont = getfont
-nodes.getsubtype = getsubtype
-nodes.getlist = getlist
-nodes.getleader = getleader
+local n_getid = node.getid
+local n_getlist = node.getlist
+local n_getnext = node.getnext
+local n_getprev = node.getprev
+local n_getchar = node.getchar
+local n_getfont = node.getfont
+local n_getsubtype = node.getsubtype
+local n_setfield = node.setfield
+local n_getfield = node.getfield
+local n_setattr = node.setattr
+local n_getattr = node.getattr
+local n_getdisc = node.getdisc
+local n_getleader = node.getleader
+
+local n_setnext = node.setnext or
+ function(c,next)
+ setfield(c,"next",n)
+ end
+local n_setprev = node.setprev or
+ function(c,prev)
+ setfield(c,"prev",p)
+ end
+local n_setlink = node.setlink or
+ function(c1,c2)
+ if c1 then setfield(c1,"next",c2) end
+ if c2 then setfield(c2,"prev",c1) end
+ end
+local n_setboth = node.setboth or
+ function(c,p,n)
+ setfield(c,"prev",p)
+ setfield(c,"next",n)
+ end
+
+node.setnext = n_setnext
+node.setprev = n_setprev
+node.setlink = n_setlink
+node.setboth = n_setboth
+
+nodes.getfield = n_getfield
+nodes.setfield = n_setfield
+nodes.getattr = n_getattr
+nodes.setattr = n_setattr
+
+nodes.getnext = n_getnext
+nodes.getprev = n_getprev
+nodes.getid = n_getid
+nodes.getchar = n_getchar
+nodes.getfont = n_getfont
+nodes.getsubtype = n_getsubtype
+nodes.getlist = n_getlist
+nodes.getleader = n_getleader
+nodes.getdisc = n_getdisc
+-----.getpre = node.getpre or function(n) local h, _, _, t = n_getdisc(n,true) return h, t end
+-----.getpost = node.getpost or function(n) local _, h, _, _, t = n_getdisc(n,true) return h, t end
+-----.getreplace = node.getreplace or function(n) local _, _, h, _, _, t = n_getdisc(n,true) return h, t end
+
+nodes.is_char = node.is_char
+nodes.ischar = node.is_char
+
+nodes.is_glyph = node.is_glyph
+nodes.isglyph = node.is_glyph
nodes.getbox = node.getbox or tex.getbox
nodes.setbox = node.setbox or tex.setbox
@@ -160,12 +198,6 @@ nodes.getskip = node.getskip or tex.get
local n_new_node = nodes.new
local n_free_node = nodes.free
-local n_setfield = nodes.setfield
-local n_getfield = nodes.getfield
-local n_getnext = nodes.getnext
-local n_getprev = nodes.getprev
-local n_getid = nodes.getid
-local n_getlist = nodes.getlist
local n_copy_node = nodes.copy
local n_copy_list = nodes.copy_list
local n_find_tail = nodes.tail
@@ -184,8 +216,7 @@ local function remove(head,current,free_too)
n_free_node(t)
t = nil
else
- n_setfield(t,"next",nil)
- n_setfield(t,"prev",nil)
+ n_setboth(t)
end
return head, current, t
end
@@ -210,12 +241,10 @@ function nodes.replace(head,current,new) -- no head returned if false
local prev = n_getprev(current)
local next = n_getnext(current)
if next then
- n_setfield(new,"next",next)
- n_setfield(next,"prev",new)
+ n_setlink(new,next)
end
if prev then
- n_setfield(new,"prev",prev)
- n_setfield(prev,"next",new)
+ n_setlink(prev,new)
end
if head then
if head == current then
@@ -270,8 +299,7 @@ function nodes.linked(...)
local next = select(i,...)
if next then
if head then
- n_setfield(last,"next",next)
- n_setfield(next,"prev",last)
+ n_setlink(last,next)
else
head = next
end
@@ -287,8 +315,7 @@ function nodes.concat(list) -- consider tail instead of slide
local li = list[i]
if li then
if head then
- n_setfield(tail,"next",li)
- n_setfield(li,"prev",tail)
+ n_setlink(tail,li)
else
head = li
end
@@ -431,8 +458,7 @@ metatable.__concat = function(n1,n2) -- todo: accept nut on one end
return n2 -- or n2 * 2
else
local tail = n_find_tail(n1)
- n_setfield(tail,"next",n2)
- n_setfield(n2,"prev",tail)
+ n_setlink(tail,n2)
return n1
end
end
@@ -449,26 +475,22 @@ metatable.__mul = function(n,multiplier)
local h = n_copy_list(n)
if head then
local t = n_find_tail(h)
- n_setfield(t,"next",head)
- n_setfield(head,"prev",t)
+ n_setlink(t,head)
end
head = h
end
local t = n_find_tail(n)
- n_setfield(t,"next",head)
- n_setfield(head,"prev",t)
+ n_setlink(t,head)
else
local head
for i=2,multiplier do
local c = n_copy_node(n)
if head then
- n_setfield(c,"next",head)
- n_setfield(head,"prev",c)
+ n_setlink(c,head)
end
head = c
end
- n_setfield(n,"next",head)
- n_setfield(head,"prev",n)
+ n_setlink(n,head)
end
return n
end
@@ -477,7 +499,7 @@ metatable.__sub = function(first,second)
if type(second) == "number" then
local tail = n_find_tail(first)
for i=1,second do
- local prev = n_getfield(tail,"prev")
+ local prev = n_getprev(tail)
n_free_node(tail) -- can become flushlist/flushnode
if prev then
tail = prev
@@ -486,7 +508,7 @@ metatable.__sub = function(first,second)
end
end
if tail then
- n_setfield(tail,"next",nil)
+ n_setnext(tail)
return first
else
return nil
@@ -497,15 +519,12 @@ metatable.__sub = function(first,second)
local prev = n_getprev(firsttail)
if prev then
local secondtail = n_find_tail(second)
- n_setfield(secondtail,"next",firsttail)
- n_setfield(firsttail,"prev",ltail)
- n_setfield(prev,"next",second)
- n_setfield(second,"prev",prev)
+ n_setlink(secondtail,firsttail)
+ n_setlink(prev,second)
return first
else
local secondtail = n_find_tail(second)
- n_setfield(secondtail,"next",first)
- n_setfield(first,"prev",ltail)
+ n_setlink(secondtail,first)
return second
end
end
@@ -524,7 +543,7 @@ metatable.__add = function(first,second)
end
end
if head then
- n_setfield(head,"prev",nil)
+ n_setprev(head)
return head
else
return nil
@@ -534,13 +553,10 @@ metatable.__add = function(first,second)
local next = n_getnext(first)
if next then
local secondtail = n_find_tail(second)
- n_setfield(first,"next",second)
- n_setfield(second,"prev",first)
- n_setfield(secondtail,"next",next)
- n_setfield(next,"prev",secondtail)
+ n_setlink(first,second)
+ n_setlink(secondtail,next)
else
- n_setfield(first,"next",second)
- n_setfield(second,"prev",first)
+ n_setlink(first,second)
end
return first
end
@@ -562,7 +578,7 @@ end
metatable.__pow = function(n,multiplier)
local tail = n
local head = nil
- if getnext(n) then
+ if n_getnext(n) then
if multiplier == 1 then
head = n_copy_list(n)
else
@@ -570,8 +586,7 @@ metatable.__pow = function(n,multiplier)
local h = n_copy_list(n)
if head then
local t = n_find_tail(h)
- n_setfield(t,"next",head)
- n_setfield(head,"prev",t)
+ n_setlink(t,head)
end
head = h
end
@@ -583,8 +598,7 @@ metatable.__pow = function(n,multiplier)
for i=2,multiplier do
local c = n_copy_node(n)
if head then
- n_setfield(head,"next",c)
- n_setfield(c,"prev",head)
+ n_setlink(head,c)
end
head = c
end
@@ -600,13 +614,12 @@ metatable.__unm = function(head)
local current = n_getnext(head)
while current do
local next = n_getnext(current)
- n_setfield(first,"prev",current)
- n_setfield(current,"next",first)
+ n_setlink(current,first)
first = current
current = next
end
- n_setfield(first,"prev",nil)
- n_setfield(last,"next",nil)
+ n_setprev(first)
+ n_setnext(last)
return first
end