Skip to content

Commit

Permalink
Abolish OP_PREPCALLFIRSTARG, instead implement it using OP_MOVE
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Dec 4, 2023
1 parent 2fd1355 commit d17181d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 25 deletions.
13 changes: 9 additions & 4 deletions src/lcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,18 +1101,23 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {


/*
** Emit PREPCALLFIRSTARG instruction (convert expression 'e' into 'func(e,').
** Convert expression 'e' into 'func(e,'.
*/
void luaK_prepcallfirstarg (FuncState *fs, expdesc *e, expdesc *func) {
luaK_exp2anyreg(fs, e);
luaK_exp2anyreg(fs, func);
int ereg = e->u.reg; /* register where 'e' was placed */
int freg = func->u.reg; /* register where 'func' was placed */
freeexps(fs, e, func);
e->u.reg = fs->freereg; /* base register for op_prepcallfirstarg */
e->u.reg = fs->freereg; /* base register for call */
e->k = VNONRELOC; /* expression has a fixed register */
luaK_reserveregs(fs, 2); /* function and first arg produced by op_prepcallfirstarg */
luaK_codeABCk(fs, OP_PREPCALLFIRSTARG, e->u.reg, ereg, freg, 0);
luaK_reserveregs(fs, 2); /* function and first arg */
if (e->u.reg != freg) { /* ensure function is in correct register */
luaK_codeABC(fs, OP_MOVE, e->u.reg, freg, 0);
}
if (e->u.reg + 1 != ereg) { /* ensure argument is in correct register */
luaK_codeABC(fs, OP_MOVE, e->u.reg + 1, ereg, 0);
}
fs->f->onPlutoOpUsed(0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ldump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static void dumpHeader (DumpState *D) {
dumpByte(D, LUAC_FORMAT);
}
else {
dumpByte(D, 0); /* Pluto 0.8.0 or upwards required for NULL_COALESCE, OP_IN, and/or OP_PREPCALLFIRSTARG */
dumpByte(D, 0);
dumpByte(D, 'P');
}
dumpLiteral(D, LUAC_DATA);
Expand Down
1 change: 0 additions & 1 deletion src/ljumptabgcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,5 @@ static const void *const disptab[NUM_OPCODES + 1] = {
&&L_OP_VARARGPREP,
&&L_OP_EXTRAARG,
&&L_OP_IN,
&&L_OP_PREPCALLFIRSTARG,
&&L_NUM_OPCODES,
};
1 change: 0 additions & 1 deletion src/lopcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */
,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */
,opmode(0, 0, 0, 0, 1, iABC) /* OP_IN */
,opmode(0, 0, 0, 0, 1, iABC) /* OP_PREPCALLFIRSTARG */
};

2 changes: 0 additions & 2 deletions src/lopcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ else
push R(B):contains(R(A)) ~= nil
*/

OP_PREPCALLFIRSTARG,/* A B C R[A+1] := R[B]; R[A] := R[C] */

NUM_OPCODES
} OpCode;

Expand Down
1 change: 0 additions & 1 deletion src/lopnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ static const char *const opnames[] = {
"EXTRAARG",
// end of lua opcodes
"IN",
"PREPCALLFA", /* OP_PREPCALLFIRSTARG */
// end of pluto opcodes
NULL
};
15 changes: 0 additions & 15 deletions src/lvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,21 +1685,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmDumpOut ("; push self to call '" << getstr(key) << "'");
vmbreak;
}
vmcase(OP_PREPCALLFIRSTARG) {
StkId ra = RA(i);
TValue *rb = vRB(i);
TValue *rc = vRC(i);
TValue b;
setobj(L, &b, rb);
setobj2s(L, ra, rc); /* function */
setobj2s(L, ra + 1, &b); /* first arg */
vmDumpInit();
vmDumpAddA();
vmDumpAddB();
vmDumpAddC();
vmDumpOut("; push " << stringify_tvalue(s2v(ra)) << " and first arg " << stringify_tvalue(s2v(ra + 1)));
vmbreak;
}
vmcase(OP_ADDI) {
vmDumpInit();
vmDumpAddA();
Expand Down

0 comments on commit d17181d

Please sign in to comment.