1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-05-17 21:23:22 -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
elseif tt == 'RELLABEL' then
if tok == '+' then
insert(plus_labels, line)
insert(plus_labels, #self.tokens)
elseif tok == '-' then
insert(minus_labels, 1, line)
insert(minus_labels, 1, #self.tokens)
else
error('Internal Error: unexpected token for relative label', 1)
end
@ -1380,29 +1380,28 @@ function Parser:tokenize(asm)
elseif t.tt == 'RELLABEL' then
t.tt = 'LABEL'
-- exploits the fact that user labels can't begin with a number
-- FIXME: can produce bad results with includes, etc
t.tok = tostring(t.line)
t.tok = tostring(i)
elseif t.tt == 'RELLABELSYM' then
t.tt = 'LABELSYM'
local rel = t.tok
local seen = 0
-- TODO: don't iterate over *every* label, just the ones nearby
if rel > 0 then
for i, line in ipairs(plus_labels) do
if line > t.line then
for _, label_i in ipairs(plus_labels) do
if label_i > i then
seen = seen + 1
if seen == rel then
t.tok = tostring(line)
t.tok = tostring(label_i)
break
end
end
end
else
for i, line in ipairs(minus_labels) do
if line < t.line then
for _, label_i in ipairs(minus_labels) do
if label_i < i then
seen = seen - 1
if seen == rel then
t.tok = tostring(line)
t.tok = tostring(label_i)
break
end
end