LunaCON: gen. cleaner code, make actor[].movflag internal, update listglobals.sh

git-svn-id: https://svn.eduke32.com/eduke32@3646 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-04-05 17:53:21 +00:00
parent edcef5c3ec
commit e638c38c35
5 changed files with 52 additions and 37 deletions

View file

@ -366,7 +366,7 @@ local SX = function(memb) return "spriteext[%s]"..memb end
-- Generate code to access a signed member as unsigned. -- Generate code to access a signed member as unsigned.
local function s2u(label) local function s2u(label)
return "(_bit.band("..label.."+65536,65535))" return "(_band("..label.."+65536,65535))"
end end
local function S2U(label) local function S2U(label)
@ -408,7 +408,7 @@ local ActorLabels = {
htang = AC".ang", htang = AC".ang",
htextra = AC".extra", htextra = AC".extra",
htowner = { AC".owner", AC":set_owner(%%s)" }, htowner = { AC".owner", AC":set_owner(%%s)" },
htmovflag = AC".movflag", htmovflag = AC"._movflag",
httempang = AC".tempang", httempang = AC".tempang",
htactorstayput = AC".actorstayput", htactorstayput = AC".actorstayput",
htdispicnum = { AC".dispicnum" }, htdispicnum = { AC".dispicnum" },
@ -813,7 +813,7 @@ for member, code in pairs(ProjectileLabels) do
end end
end end
local UD = function(memb) return "gv._ud"..memb end local UD = function(memb) return "_gv._ud"..memb end
local UDRO = function(memb) return { UD(memb) } end local UDRO = function(memb) return { UD(memb) } end
-- NOTE: Only members that actually encountered in existing mods are added here. -- NOTE: Only members that actually encountered in existing mods are added here.

View file

@ -157,7 +157,7 @@ __attribute__((packed)) struct {
const int16_t picnum; const int16_t picnum;
int16_t ang, extra; int16_t ang, extra;
const int16_t owner; const int16_t owner;
int16_t movflag,tempang,timetosleep; //6b int16_t _movflag,tempang,timetosleep; //6b
int16_t actorstayput; int16_t actorstayput;
const int16_t dispicnum; const int16_t dispicnum;

View file

@ -6,7 +6,10 @@ if [ -z "$1" ]; then
exit 1; exit 1;
fi fi
# Lua 5.2 required to parse ::label:: / goto generated by LunaCON.
LUAC=luac
# Strip LuaJIT specific syntax # Strip LuaJIT specific syntax
sed -r -e "s/[0-9]+U?LL/0/g" "$1" | luac -p -l - | grep "$2ETGLOBAL" | sed -r -e "s/[0-9]+U?LL/0/g" "$1" | $LUAC -p -l - | grep "$2ETTABUP.*; _ENV " |
# mark where the new module environment starts # mark where the new module environment starts
sed -e "s/; module/; module ____________________/" sed -e "s/; module/; module ____________________/"

View file

@ -163,17 +163,25 @@ local function new_initial_codetab()
-- NOTE: Keep this one line per line to not confuse the Lua->CON line -- NOTE: Keep this one line per line to not confuse the Lua->CON line
-- mapping system. -- mapping system.
return { return {
"local _con, _bit, _math = require'con', require'bit', require'math';", -- Requires.
"local _xmath, _geom = require'xmath', require'geom';", "local _con, _bit, _math = require'con', require'bit', require'math'",
"local sector, sprite, actor, player = sector, sprite, actor, player;", "local _xmath, _geom = require'xmath', require'geom'",
"local gameactor, gameevent, _gv = gameactor, gameevent, gv;",
"local updatesector, updatesectorz, cansee = updatesector, updatesectorz, cansee;",
"local print = print;",
-- switch function table, indexed by global switch sequence number: -- Cache globals into locals.
"local _SW = {};", "local sector, sprite, wall, spriteext, atsprite = sector, sprite, wall, spriteext, atsprite",
"local actor, player, projectile = actor, player, projectile",
"local gameactor, gameevent, _gv = gameactor, gameevent, gv",
"local updatesector, updatesectorz, cansee = updatesector, updatesectorz, cansee",
"local print, printf = print, printf",
-- Cache a couple of often-used functions.
"local _band, _bor, _bxor = _bit.band, _bit.bor, _bit.bxor",
"local _lsh, _rsh, _arsh = _bit.lshift, _bit.rshift, _bit.arshift",
-- Switch function table, indexed by global switch sequence number:
"local _SW = {}",
-- CON "states" (subroutines), gamevars and gamearrays (see mangle_name()) -- CON "states" (subroutines), gamevars and gamearrays (see mangle_name())
"local _F,_V,_A={},{},{};", "local _F,_V,_A={},{},{}",
-- Static ivec3s so that no allocations need to be made. -- Static ivec3s so that no allocations need to be made.
"local _IVEC = { _geom.ivec3(), _geom.ivec3() }", "local _IVEC = { _geom.ivec3(), _geom.ivec3() }",
@ -400,7 +408,11 @@ local BAD_ID_CHARS1 = "_/\\*-+?" -- allowed following identifier chars
-- Return the Lua code by which the CON object <name> is referenced in the -- Return the Lua code by which the CON object <name> is referenced in the
-- translated code. -- translated code.
local function mangle_name(name, prefix) local function mangle_name(name, prefix)
return format("_%s[%q]", prefix, name) if (name:match("^[A-Za-z_][A-Za-z_0-9]*$")) then
return format("_%s.%s", prefix, name)
else
return format("_%s[%q]", prefix, name)
end
end end
function on.state_begin_Cmt(_subj, _pos, statename) function on.state_begin_Cmt(_subj, _pos, statename)
@ -1735,7 +1747,7 @@ local handle =
end, end,
rotatesprite16 = function(...) -- (orientation|ROTATESPRITE_FULL16) rotatesprite16 = function(...) -- (orientation|ROTATESPRITE_FULL16)
return format("_con.rotatesprite(%s,%s,%s,%s,%s,%s,%s,_bit.bor(%s,2048),0,%s,%s,%s,%s)", ...) return format("_con.rotatesprite(%s,%s,%s,%s,%s,%s,%s,_bor(%s,2048),0,%s,%s,%s,%s)", ...)
end, end,
rotatespritea = function(...) rotatespritea = function(...)
@ -1854,9 +1866,9 @@ local Cinner = {
mulvarvar = varvaropf "*", mulvarvar = varvaropf "*",
divvarvar = varvaropf "_con._div", divvarvar = varvaropf "_con._div",
modvarvar = varvaropf "_con._mod", modvarvar = varvaropf "_con._mod",
andvarvar = varvaropf "_bit.band", andvarvar = varvaropf "_band",
orvarvar = varvaropf "_bit.bor", orvarvar = varvaropf "_bor",
xorvarvar = varvaropf "_bit.bxor", xorvarvar = varvaropf "_bxor",
randvarvar = varvarop / "%1=_con._rand(%2)", randvarvar = varvarop / "%1=_con._rand(%2)",
setvar = varop / "%1=%2", setvar = varop / "%1=%2",
@ -1865,12 +1877,12 @@ local Cinner = {
mulvar = varopf "*", mulvar = varopf "*",
divvar = varopf "_con._div", divvar = varopf "_con._div",
modvar = varopf "_con._mod", modvar = varopf "_con._mod",
andvar = varopf "_bit.band", andvar = varopf "_band",
orvar = varopf "_bit.bor", orvar = varopf "_bor",
xorvar = varopf "_bit.bxor", xorvar = varopf "_bxor",
randvar = varop / "%1=_con._rand(%2)", randvar = varop / "%1=_con._rand(%2)",
shiftvarl = varopf "_bit.lshift", shiftvarl = varopf "_lsh",
shiftvarr = varopf "_bit.arshift", shiftvarr = varopf "_arsh",
--- 2. Math operations --- 2. Math operations
sqrt = cmd(R,W) sqrt = cmd(R,W)
@ -1901,7 +1913,7 @@ local Cinner = {
count = cmd(D) count = cmd(D)
/ ACS":set_count(%1)", / ACS":set_count(%1)",
cstator = cmd(D) cstator = cmd(D)
/ (SPS".cstat=_bit.bor(%1,"..SPS".cstat)"), / (SPS".cstat=_bor(%1,"..SPS".cstat)"),
cstat = cmd(D) cstat = cmd(D)
/ SPS".cstat=%1", / SPS".cstat=%1",
clipdist = cmd(D) clipdist = cmd(D)
@ -2331,11 +2343,11 @@ local Cinner = {
getactorangle = cmd(W) getactorangle = cmd(W)
/ ("%1="..SPS".ang"), / ("%1="..SPS".ang"),
setactorangle = cmd(R) setactorangle = cmd(R)
/ SPS".ang=_bit.band(%1,2047)", / SPS".ang=_band(%1,2047)",
getplayerangle = cmd(W) getplayerangle = cmd(W)
/ ("%1="..PLS".ang"), / ("%1="..PLS".ang"),
setplayerangle = cmd(R) setplayerangle = cmd(R)
/ PLS".ang=_bit.band(%1,2047)", / PLS".ang=_band(%1,2047)",
getangletotarget = cmd(W) getangletotarget = cmd(W)
/ "%1=_con._angtotarget(_aci)", / "%1=_con._angtotarget(_aci)",
@ -2378,7 +2390,7 @@ local Cif = {
ifwasweapon = cmd(D) ifwasweapon = cmd(D)
/ ACS".picnum==%1", / ACS".picnum==%1",
ifgapzl = cmd(D) -- factor into a con.* function? ifgapzl = cmd(D) -- factor into a con.* function?
/ format("_bit.arshift(%s-%s,8)<%%1", ACS".floorz", ACS".ceilingz"), / format("_arsh(%s-%s,8)<%%1", ACS".floorz", ACS".ceilingz"),
iffloordistl = cmd(D) iffloordistl = cmd(D)
/ format("(%s-%s)<=256*%%1", ACS".floorz", SPS".z"), / format("(%s-%s)<=256*%%1", ACS".floorz", SPS".z"),
ifceilingdistl = cmd(D) ifceilingdistl = cmd(D)
@ -2405,11 +2417,11 @@ local Cif = {
ifvarn = cmd(R,D) ifvarn = cmd(R,D)
/ "%1~=%2", / "%1~=%2",
ifvarand = cmd(R,D) ifvarand = cmd(R,D)
/ "_bit.band(%1,%2)~=0", / "_band(%1,%2)~=0",
ifvaror = cmd(R,D) ifvaror = cmd(R,D)
/ "_bit.bor(%1,%2)~=0", / "_bor(%1,%2)~=0",
ifvarxor = cmd(R,D) ifvarxor = cmd(R,D)
/ "_bit.bxor(%1,%2)~=0", / "_bxor(%1,%2)~=0",
ifvareither = cmd(R,D) ifvareither = cmd(R,D)
/ "%1~=0 or %2~=0", / "%1~=0 or %2~=0",
@ -2422,11 +2434,11 @@ local Cif = {
ifvarvarn = cmd(R,R) ifvarvarn = cmd(R,R)
/ "%1~=%2", / "%1~=%2",
ifvarvarand = cmd(R,R) ifvarvarand = cmd(R,R)
/ "_bit.band(%1,%2)~=0", / "_band(%1,%2)~=0",
ifvarvaror = cmd(R,R) ifvarvaror = cmd(R,R)
/ "_bit.bor(%1,%2)~=0", / "_bor(%1,%2)~=0",
ifvarvarxor = cmd(R,R) ifvarvarxor = cmd(R,R)
/ "_bit.bxor(%1,%2)~=0", / "_bxor(%1,%2)~=0",
ifvarvareither = cmd(R,R) ifvarvareither = cmd(R,R)
/ "%1~=0 or %2~=0", / "%1~=0 or %2~=0",
@ -2442,12 +2454,12 @@ local Cif = {
ifrespawn = cmd() ifrespawn = cmd()
/ format("_con._checkrespawn(%s)", SPS""), / format("_con._checkrespawn(%s)", SPS""),
ifoutside = cmd() ifoutside = cmd()
/ format("_bit.band(sector[%s].ceilingstat,1)~=0", SPS".sectnum"), / format("_band(sector[%s].ceilingstat,1)~=0", SPS".sectnum"),
ifonwater = cmd() ifonwater = cmd()
/ format("sector[%s].lotag==1 and _math.abs(%s-sector[%s].floorz)<32*256", / format("sector[%s].lotag==1 and _math.abs(%s-sector[%s].floorz)<32*256",
SPS".sectnum", SPS".z", SPS".sectnum"), SPS".sectnum", SPS".z", SPS".sectnum"),
ifnotmoving = cmd() ifnotmoving = cmd()
/ "_bit.band(actor[_aci].movflag,49152)>16384", / "_band(actor[_aci]._movflag,49152)>16384",
ifnosounds = cmd() ifnosounds = cmd()
/ "not _con._ianysound()", / "not _con._ianysound()",
ifmultiplayer = cmd() ifmultiplayer = cmd()

View file

@ -97,7 +97,7 @@ void El_PrintTimes(void)
buf[n] = ' '; buf[n] = ' ';
buf[maxlen] = 0; buf[maxlen] = 0;
OSD_Printf(" [%s]={ %8d, %9.3f, %9.3f },\n", OSD_Printf(" [%s]={ %8d, %10.3f, %10.3f },\n",
buf, g_eventCalls[i], g_eventTotalMs[i], buf, g_eventCalls[i], g_eventTotalMs[i],
1000*g_eventTotalMs[i]/g_eventCalls[i]); 1000*g_eventTotalMs[i]/g_eventCalls[i]);
} }