Lunatic translator: proper Lua->CON line mapping for actor/event/etc. headers.

git-svn-id: https://svn.eduke32.com/eduke32@3604 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-03-24 18:55:27 +00:00
parent 7faffdc674
commit 8d2a60ff70

View file

@ -327,6 +327,10 @@ local function addcodef(fmt, ...)
addcode(format(fmt, ...)) addcode(format(fmt, ...))
end end
local function paddcodef(pos, fmt, ...)
addcodef(fmt.."--"..getlinecol(pos), ...)
end
local function add_code_and_end(codetab, endstr) local function add_code_and_end(codetab, endstr)
assert(type(codetab)=="table") assert(type(codetab)=="table")
addcode(codetab) addcode(codetab)
@ -337,7 +341,8 @@ local function get_cache_sap_code()
return csapp() and "local _spr,_a,_ps=_con._getsap(_aci,_pli)" or "" return csapp() and "local _spr,_a,_ps=_con._getsap(_aci,_pli)" or ""
end end
local function warnprintf() end -- fwd-decl -- fwd-decls
local warnprintf, errprintf, pwarnprintf, perrprintf
local on = {} local on = {}
@ -353,14 +358,13 @@ for i=4,7 do
end end
function on.actor_end(usertype, tsamm, codetab) function on.actor_end(pos, usertype, tsamm, codetab)
local tilenum = tsamm[1] local tilenum = tsamm[1]
local flags = 0 local flags = 0
if (usertype ~= nil) then -- useractor if (usertype ~= nil) then -- useractor
if (not (bit.band(usertype, bit.bnot(7)) == 0)) then if (not (bit.band(usertype, bit.bnot(7)) == 0)) then
-- XXX: position will be that of last command in actor code perrprintf(pos, "invalid usertype: must be bitwise OR of 1, 2 and/or 4")
errprintf("invalid usertype: must be bitwise OR of 1, 2 and/or 4")
else else
flags = MAP_ACTOR_FLAGS[usertype] flags = MAP_ACTOR_FLAGS[usertype]
end end
@ -380,13 +384,12 @@ function on.actor_end(usertype, tsamm, codetab)
str = str .. movflags.."," str = str .. movflags..","
end end
addcodef("gameactor(%d,%sfunction(_aci, _pli, _dist)", tilenum, str) paddcodef(pos, "gameactor(%d,%sfunction(_aci, _pli, _dist)", tilenum, str)
addcode(get_cache_sap_code()) addcode(get_cache_sap_code())
add_code_and_end(codetab, "end)") add_code_and_end(codetab, "end)")
if (g_code.actor[tilenum] ~= nil) then if (g_code.actor[tilenum] ~= nil) then
-- XXX: position will be that of last command in actor code pwarnprintf(pos, "redefined actor %d", tilenum)
warnprintf("redefined actor %d", tilenum)
end end
g_code.actor[tilenum] = codetab g_code.actor[tilenum] = codetab
end end
@ -410,15 +413,15 @@ function on.state_begin_Cmt(_subj, _pos, statename)
return true, ourname return true, ourname
end end
function on.state_end(funcname, codetab) function on.state_end(pos, funcname, codetab)
addcodef("%s=function(_aci, _pli, _dist)", funcname) paddcodef(pos, "%s=function(_aci, _pli, _dist)", funcname)
addcode(get_cache_sap_code()) addcode(get_cache_sap_code())
add_code_and_end(codetab, "end") add_code_and_end(codetab, "end")
end end
function on.event_end(eventidx, codetab) function on.event_end(pos, eventidx, codetab)
assert(type(codetab)=="table") assert(type(codetab)=="table")
addcodef("gameevent(%d, function (_aci, _pli, _dist)", eventidx) paddcodef(pos, "gameevent(%d, function (_aci, _pli, _dist)", eventidx)
addcode(get_cache_sap_code()) addcode(get_cache_sap_code())
addcode(codetab) addcode(codetab)
addcode("end)") addcode("end)")
@ -426,9 +429,9 @@ function on.event_end(eventidx, codetab)
g_code.event[eventidx] = codetab g_code.event[eventidx] = codetab
end end
function on.eventloadactor_end(tilenum, codetab) function on.eventloadactor_end(pos, tilenum, codetab)
-- Translate eventloadactor into a chained EVENT_LOADACTOR block -- Translate eventloadactor into a chained EVENT_LOADACTOR block
addcode("gameevent('LOADACTOR', function (_aci, _pli, _dist)") paddcodef(pos, "gameevent('LOADACTOR', function (_aci, _pli, _dist)")
addcode(get_cache_sap_code()) addcode(get_cache_sap_code())
addcodef("if (%s==%d) then", SPS".picnum", tilenum) addcodef("if (%s==%d) then", SPS".picnum", tilenum)
addcode(codetab) addcode(codetab)
@ -436,7 +439,8 @@ function on.eventloadactor_end(tilenum, codetab)
addcode("end)") addcode("end)")
if (g_code.loadactor[tilenum] ~= nil) then if (g_code.loadactor[tilenum] ~= nil) then
warnprintf("redefined loadactor %d", tilenum) -- NOTE: C-CON redefines loadactor code if encountered multiple times.
pwarnprintf(pos, "chained additional loadactor %d code", tilenum)
end end
g_code.loadactor[tilenum] = codetab g_code.loadactor[tilenum] = codetab
end end
@ -456,12 +460,12 @@ local function increment_numerrors()
end end
end end
local function perrprintf(pos, fmt, ...) function perrprintf(pos, fmt, ...)
printf("%s %s: error: "..fmt, g_filename, linecolstr(pos), ...) printf("%s %s: error: "..fmt, g_filename, linecolstr(pos), ...)
increment_numerrors() increment_numerrors()
end end
local function errprintf(fmt, ...) function errprintf(fmt, ...)
if (g_lastkwpos) then if (g_lastkwpos) then
perrprintf(g_lastkwpos, fmt, ...) perrprintf(g_lastkwpos, fmt, ...)
else else
@ -470,11 +474,11 @@ local function errprintf(fmt, ...)
end end
end end
local function pwarnprintf(pos, fmt, ...) function pwarnprintf(pos, fmt, ...)
printf("%s %s: warning: "..fmt, g_filename, linecolstr(pos), ...) printf("%s %s: warning: "..fmt, g_filename, linecolstr(pos), ...)
end end
function warnprintf(fmt, ...) -- local function warnprintf(fmt, ...)
if (g_lastkwpos) then if (g_lastkwpos) then
pwarnprintf(g_lastkwpos, fmt, ...) pwarnprintf(g_lastkwpos, fmt, ...)
else else
@ -2704,17 +2708,18 @@ end
--== block delimiters (no syntactic recursion) ==-- --== block delimiters (no syntactic recursion) ==--
local Cblock = { local Cblock = {
-- actor (...) -- actor (...)
actor = lpeg.Cc(nil) * common.actor_end / on.actor_end, actor = POS() * lpeg.Cc(nil) * common.actor_end / on.actor_end,
-- useractor <actortype> (...) -- useractor <actortype> (...)
useractor = sp1 * tok.define * common.actor_end / on.actor_end, useractor = POS() * sp1 * tok.define * common.actor_end / on.actor_end,
-- eventloadactor <name/tilenum> -- eventloadactor <name/tilenum>
eventloadactor = sp1 * tok.define * sp1 * stmt_list_or_eps * "enda" eventloadactor = POS() * sp1 * tok.define * sp1 * stmt_list_or_eps * "enda"
/ on.eventloadactor_end, / on.eventloadactor_end,
onevent = sp1 * tok.define * sp1 * stmt_list_or_eps * "endevent" onevent = POS() * sp1 * tok.define * sp1 * stmt_list_or_eps * "endevent"
/ on.event_end, / on.event_end,
state = sp1 * (lpeg.Cmt(tok.identifier, on.state_begin_Cmt)) * sp1 * stmt_list_or_eps * tok.state_ends state = POS() * sp1 * (lpeg.Cmt(tok.identifier, on.state_begin_Cmt))
* sp1 * stmt_list_or_eps * tok.state_ends
/ on.state_end, / on.state_end,
} }