mirror of
https://github.com/notwa/lips
synced 2024-04-30 00:53:23 -07:00
refactor label resolution into its own method
This commit is contained in:
parent
29ae63ed34
commit
437b816f85
|
@ -36,7 +36,10 @@ function Preproc:lookup(t)
|
|||
if t.tok == nil then
|
||||
self:error('undefined variable', name)
|
||||
end
|
||||
elseif self.do_labels and t.tt == 'RELLABELSYM' or t.tt == 'RELLABEL' then
|
||||
end
|
||||
end
|
||||
|
||||
function Preproc:resolve(t)
|
||||
if t.tt == 'RELLABEL' then
|
||||
t.tt = 'LABEL'
|
||||
-- exploits the fact that user labels can't begin with a number
|
||||
|
@ -82,10 +85,6 @@ function Preproc:lookup(t)
|
|||
self:error('could not find appropriate relative label', t.tok)
|
||||
end
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function Preproc:check(s, i, tt)
|
||||
|
@ -115,7 +114,6 @@ function Preproc:process(statements)
|
|||
self.variables = {}
|
||||
self.plus_labels = {} -- constructed forwards
|
||||
self.minus_labels = {} -- constructed backwards
|
||||
self.do_labels = false
|
||||
|
||||
-- first pass: resolve variables and collect relative labels
|
||||
local new_statements = {}
|
||||
|
@ -152,10 +150,9 @@ function Preproc:process(statements)
|
|||
end
|
||||
|
||||
-- second pass: resolve relative labels
|
||||
self.do_labels = true
|
||||
for s in self:iter(new_statements) do
|
||||
for j, t in ipairs(s) do
|
||||
self:lookup(t)
|
||||
self:resolve(t)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user