1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-11-14 23:39:03 -08:00

allow empty words on stack in push/pop

This commit is contained in:
Connor Olding 2015-12-18 16:47:41 -08:00
parent ad93ae9feb
commit dea1955aec

View file

@ -800,6 +800,7 @@ end
function Parser:number() function Parser:number()
if self.tt ~= 'NUM' then if self.tt ~= 'NUM' then
-- FIXME: self.line can be nil in DEFINEs
self:error('expected number') self:error('expected number')
end end
local value = self.tok local value = self.tok
@ -1034,31 +1035,37 @@ function Parser:instruction()
local addi = instructions['ADDI'] local addi = instructions['ADDI']
local w = instructions[h == 'PUSH' and 'SW' or 'LW'] local w = instructions[h == 'PUSH' and 'SW' or 'LW']
local jr = instructions['JR'] local jr = instructions['JR']
local registers = {} local stack = {}
while not self:is_EOL() do while not self:is_EOL() do
local r = self:register() if self.tt == 'NUM' then
table.insert(registers, r) if self.tok < 0 then
self:error("can't push a negative number of spaces")
end
for i=1,self.tok do
table.insert(stack, '')
end
self:advance()
else
table.insert(stack, self:register())
end
if not self:is_EOL() then if not self:is_EOL() then
self:optional_comma() self:optional_comma()
end end
end end
if #registers == 0 then if #stack == 0 then
self:error(h..' requires at least one argument') self:error(h..' requires at least one argument')
end end
if #registers >= 0x8000/4 then
self:error("that's way too many registers bub")
end
local args = {} local args = {}
if h == 'PUSH' then if h == 'PUSH' then
args.rt = 'SP' args.rt = 'SP'
args.rs = 'SP' args.rs = 'SP'
args.immediate = {'NEGATE', {'NUM', #registers*4}} args.immediate = {'NEGATE', {'NUM', #stack*4}}
self:format_out(addi[3], addi[1], args, addi[4], addi[5]) self:format_out(addi[3], addi[1], args, addi[4], addi[5])
end end
args.base = 'SP' args.base = 'SP'
for i, r in ipairs(registers) do for i, r in ipairs(stack) do
args.rt = r args.rt = r
if r ~= 'R0' then if r ~= '' then
args.offset = {'NUM', (i - 1)*4} args.offset = {'NUM', (i - 1)*4}
self:format_out(w[3], w[1], args, w[4], w[5]) self:format_out(w[3], w[1], args, w[4], w[5])
end end
@ -1070,7 +1077,7 @@ function Parser:instruction()
if h == 'POP' or h == 'JPOP' then if h == 'POP' or h == 'JPOP' then
args.rt = 'SP' args.rt = 'SP'
args.rs = 'SP' args.rs = 'SP'
args.immediate = {'NUM', #registers*4} args.immediate = {'NUM', #stack*4}
self:format_out(addi[3], addi[1], args, addi[4], addi[5]) self:format_out(addi[3], addi[1], args, addi[4], addi[5])
end end
elseif h == 'NAND' then elseif h == 'NAND' then