mirror of
https://github.com/notwa/lips
synced 2024-11-14 18:19:03 -08:00
actually fix hex and inc directives
This commit is contained in:
parent
33ea629309
commit
5f74f178d3
2 changed files with 23 additions and 1 deletions
|
@ -109,8 +109,24 @@ function Collector:directive()
|
||||||
self:optional_comma()
|
self:optional_comma()
|
||||||
self:push_data(self:const().tok, name)
|
self:push_data(self:const().tok, name)
|
||||||
end
|
end
|
||||||
|
elseif name == 'HEX' then
|
||||||
|
if self.tt ~= 'OPEN' then
|
||||||
|
self:error('expected opening brace for hex directive', self.tt)
|
||||||
|
end
|
||||||
|
self:advance()
|
||||||
|
|
||||||
|
while self.tt ~= 'CLOSE' do
|
||||||
|
if self.tt == 'EOL' then
|
||||||
|
self:advance()
|
||||||
|
else
|
||||||
|
self:push_data(self:const().tok, 'BYTE')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:advance()
|
||||||
elseif name == 'INC' or name == 'INCBIN' then
|
elseif name == 'INC' or name == 'INCBIN' then
|
||||||
-- noop, handled by lexer
|
-- noop, handled by lexer
|
||||||
|
self:string()
|
||||||
|
return -- don't expect EOL
|
||||||
elseif name == 'ASCII' or name == 'ASCIIZ' then
|
elseif name == 'ASCII' or name == 'ASCIIZ' then
|
||||||
local bytes = self:string()
|
local bytes = self:string()
|
||||||
for i, number in ipairs(bytes.tok) do
|
for i, number in ipairs(bytes.tok) do
|
||||||
|
|
|
@ -193,11 +193,13 @@ function Lexer:lex_hex(yield)
|
||||||
end
|
end
|
||||||
self:nextc()
|
self:nextc()
|
||||||
entered = true
|
entered = true
|
||||||
|
yield('OPEN', '{')
|
||||||
elseif self.chr == '}' then
|
elseif self.chr == '}' then
|
||||||
if not entered then
|
if not entered then
|
||||||
self:error('expected opening brace')
|
self:error('expected opening brace')
|
||||||
end
|
end
|
||||||
self:nextc()
|
self:nextc()
|
||||||
|
yield('CLOSE', '}')
|
||||||
break
|
break
|
||||||
elseif self.chr == ',' then
|
elseif self.chr == ',' then
|
||||||
self:error('commas are not allowed in HEX directives')
|
self:error('commas are not allowed in HEX directives')
|
||||||
|
@ -208,7 +210,6 @@ function Lexer:lex_hex(yield)
|
||||||
if self.chr:find(hexmatch) then
|
if self.chr:find(hexmatch) then
|
||||||
self:error('too many hex digits to be a single byte')
|
self:error('too many hex digits to be a single byte')
|
||||||
end
|
end
|
||||||
yield('DIR', 'BYTE')
|
|
||||||
yield('NUM', num)
|
yield('NUM', num)
|
||||||
elseif self.chr:find(hexmatch) then
|
elseif self.chr:find(hexmatch) then
|
||||||
self:error('expected two hex digits to make a byte')
|
self:error('expected two hex digits to make a byte')
|
||||||
|
@ -294,6 +295,8 @@ function Lexer:lex_include(_yield)
|
||||||
self:lex_string_naive(function(tt, tok)
|
self:lex_string_naive(function(tt, tok)
|
||||||
fn = tok
|
fn = tok
|
||||||
end)
|
end)
|
||||||
|
_yield('STRING', fn, self.fn, self.line)
|
||||||
|
|
||||||
if self.options.path then
|
if self.options.path then
|
||||||
fn = self.options.path..fn
|
fn = self.options.path..fn
|
||||||
end
|
end
|
||||||
|
@ -307,6 +310,8 @@ function Lexer:lex_include_binary(_yield)
|
||||||
self:lex_string_naive(function(tt, tok)
|
self:lex_string_naive(function(tt, tok)
|
||||||
fn = tok
|
fn = tok
|
||||||
end)
|
end)
|
||||||
|
_yield('STRING', fn, self.fn, self.line)
|
||||||
|
|
||||||
-- TODO: allow optional offset and size arguments
|
-- TODO: allow optional offset and size arguments
|
||||||
if self.options.path then
|
if self.options.path then
|
||||||
fn = self.options.path..fn
|
fn = self.options.path..fn
|
||||||
|
@ -414,6 +419,7 @@ function Lexer:lex(_yield)
|
||||||
self:nextc()
|
self:nextc()
|
||||||
yield('LABEL', buff)
|
yield('LABEL', buff)
|
||||||
elseif up == 'HEX' then
|
elseif up == 'HEX' then
|
||||||
|
yield('DIR', 'HEX')
|
||||||
self:lex_hex(yield)
|
self:lex_hex(yield)
|
||||||
elseif data.all_registers[up] then
|
elseif data.all_registers[up] then
|
||||||
yield('REG', up)
|
yield('REG', up)
|
||||||
|
|
Loading…
Reference in a new issue