1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-05-18 16:33:22 -07:00

split out overrides into their own table

This commit is contained in:
Connor Olding 2015-12-26 20:25:06 -08:00
parent 12ca82e40a
commit 5fb0829319

View File

@ -1034,16 +1034,9 @@ function Parser:format_out(outformat, first, args, const, formatconst)
f(self.dumper, self.line, first, out[1], out[2], out[3], out[4], out[5])
end
function Parser:instruction()
local name = self.tok
local h = instructions[name]
self:advance()
local overrides = {}
-- FIXME: errors thrown here probably have the wrong line number (+1)
if h == nil then
self:error('undefined instruction')
elseif h == 'LI' then
function overrides.LI(self, h)
local lui = instructions['LUI']
local ori = instructions['ORI']
local addiu = instructions['ADDIU']
@ -1076,7 +1069,9 @@ function Parser:instruction()
args.immediate = {'LOWER', im}
self:format_out(addiu[3], addiu[1], args, addiu[4], addiu[5])
end
elseif h == 'LA' then
end
function overrides.LA(self, h)
local lui = instructions['LUI']
local addiu = instructions['ADDIU']
local args = {}
@ -1089,7 +1084,9 @@ function Parser:instruction()
self:format_out(lui[3], lui[1], args, lui[4], lui[5])
args.immediate = {'LOWER', im}
self:format_out(addiu[3], addiu[1], args, addiu[4], addiu[5])
elseif h == 'PUSH' or h == 'POP' or h == 'JPOP' then
end
function overrides.PUSH(self, h)
local addi = instructions['ADDI']
local w = instructions[h == 'PUSH' and 'SW' or 'LW']
local jr = instructions['JR']
@ -1138,7 +1135,11 @@ function Parser:instruction()
args.immediate = {'NUM', #stack*4}
self:format_out(addi[3], addi[1], args, addi[4], addi[5])
end
elseif h == 'NAND' then
end
overrides.POP = overrides.PUSH
overrides.JPOP = overrides.PUSH
function overrides.NAND(self, h)
local and_ = instructions['AND']
local nor = instructions['NOR']
local args = {}
@ -1151,7 +1152,9 @@ function Parser:instruction()
args.rs = args.rd
args.rt = 'R0'
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
elseif h == 'NANDI' then
end
function overrides.NANDI(self, h)
local andi = instructions['ANDI']
local nor = instructions['NOR']
local args = {}
@ -1165,7 +1168,9 @@ function Parser:instruction()
args.rs = args.rt
args.rt = 'R0'
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
elseif h == 'NORI' then
end
function overrides.NORI(self, h)
local ori = instructions['ORI']
local nor = instructions['NOR']
local args = {}
@ -1179,7 +1184,9 @@ function Parser:instruction()
args.rs = args.rt
args.rt = 'R0'
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
elseif h == 'ROL' then
end
function overrides.ROL(self, h)
local sll = instructions['SLL']
local srl = instructions['SRL']
local or_ = instructions['OR']
@ -1204,7 +1211,9 @@ function Parser:instruction()
args.rs = left
args.rt = 'AT'
self:format_out(or_[3], or_[1], args, or_[4], or_[5])
elseif h == 'ROR' then
end
function overrides.ROR(self, h)
local sll = instructions['SLL']
local srl = instructions['SRL']
local or_ = instructions['OR']
@ -1229,7 +1238,9 @@ function Parser:instruction()
args.rs = right
args.rt = 'AT'
self:format_out(or_[3], or_[1], args, or_[4], or_[5])
elseif name == 'JR' then
end
function overrides.JR(self, h)
local args = {}
if self:is_EOL() then
args.rs = 'RA'
@ -1237,6 +1248,19 @@ function Parser:instruction()
args.rs = self:register()
end
self:format_out(h[3], h[1], args, h[4], h[5])
end
function Parser:instruction()
local name = self.tok
local h = instructions[name]
self:advance()
-- FIXME: errors thrown here probably have the wrong line number (+1)
if h == nil then
self:error('undefined instruction')
elseif overrides[h] then
overrides[h](self, h)
elseif h[2] == 'tob' then -- or h[2] == 'Tob' then
local lui = instructions['LUI']
local args = {}