1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-06-16 08:23:06 -07:00

use token index for relative labels

This commit is contained in:
Connor Olding 2016-01-02 04:22:12 -08:00
parent e4ff34e0c0
commit 5653e730aa

View File

@ -1350,9 +1350,9 @@ function Parser:tokenize(asm)
self.defines[tok] = tok2 self.defines[tok] = tok2
elseif tt == 'RELLABEL' then elseif tt == 'RELLABEL' then
if tok == '+' then if tok == '+' then
insert(plus_labels, line) insert(plus_labels, #self.tokens)
elseif tok == '-' then elseif tok == '-' then
insert(minus_labels, 1, line) insert(minus_labels, 1, #self.tokens)
else else
error('Internal Error: unexpected token for relative label', 1) error('Internal Error: unexpected token for relative label', 1)
end end
@ -1380,29 +1380,28 @@ function Parser:tokenize(asm)
elseif t.tt == 'RELLABEL' then elseif t.tt == 'RELLABEL' then
t.tt = 'LABEL' t.tt = 'LABEL'
-- exploits the fact that user labels can't begin with a number -- exploits the fact that user labels can't begin with a number
-- FIXME: can produce bad results with includes, etc t.tok = tostring(i)
t.tok = tostring(t.line)
elseif t.tt == 'RELLABELSYM' then elseif t.tt == 'RELLABELSYM' then
t.tt = 'LABELSYM' t.tt = 'LABELSYM'
local rel = t.tok local rel = t.tok
local seen = 0 local seen = 0
-- TODO: don't iterate over *every* label, just the ones nearby -- TODO: don't iterate over *every* label, just the ones nearby
if rel > 0 then if rel > 0 then
for i, line in ipairs(plus_labels) do for _, label_i in ipairs(plus_labels) do
if line > t.line then if label_i > i then
seen = seen + 1 seen = seen + 1
if seen == rel then if seen == rel then
t.tok = tostring(line) t.tok = tostring(label_i)
break break
end end
end end
end end
else else
for i, line in ipairs(minus_labels) do for _, label_i in ipairs(minus_labels) do
if line < t.line then if label_i < i then
seen = seen - 1 seen = seen - 1
if seen == rel then if seen == rel then
t.tok = tostring(line) t.tok = tostring(label_i)
break break
end end
end end