issue #157 more opcode renaming

pull/159/head
Dibyendu Majumdar 6 years ago
parent fc6929aa58
commit 31f4e178ee

@ -219,8 +219,8 @@ OP_RAVI_DIVII, /* A B C R(A) := RK(B) / RK(C) */
OP_RAVI_TOINT, /* A R(A) := toint(R(A)) */
OP_RAVI_TOFLT, /* A R(A) := tofloat(R(A)) */
OP_RAVI_TOARRAYI, /* A R(A) := to_arrayi(R(A)) */
OP_RAVI_TOARRAYF, /* A R(A) := to_arrayf(R(A)) */
OP_RAVI_TOIARRAY, /* A R(A) := to_arrayi(R(A)) */
OP_RAVI_TOFARRAY, /* A R(A) := to_arrayf(R(A)) */
OP_RAVI_TOTAB, /* A R(A) := to_table(R(A)) */
OP_RAVI_TOSTRING,
OP_RAVI_TOCLOSURE,

@ -75,8 +75,8 @@ opcodes_coverage.DIVIF = 0
opcodes_coverage.DIVII = 0
opcodes_coverage.TOINT = 0
opcodes_coverage.TOFLT = 0
opcodes_coverage.TOARRAYI = 0
opcodes_coverage.TOARRAYF = 0
opcodes_coverage.TOIARRAY = 0
opcodes_coverage.TOFARRAY = 0
opcodes_coverage.MOVEI = 0
opcodes_coverage.MOVEF = 0
opcodes_coverage.MOVEAI = 0

@ -77,8 +77,8 @@ opcodes_coverage.DIVIF = 0
opcodes_coverage.DIVII = 0
opcodes_coverage.TOINT = 0
opcodes_coverage.TOFLT = 0
opcodes_coverage.TOARRAYI = 0
opcodes_coverage.TOARRAYF = 0
opcodes_coverage.TOIARRAY = 0
opcodes_coverage.TOFARRAY = 0
opcodes_coverage.MOVEI = 0
opcodes_coverage.MOVEF = 0
opcodes_coverage.MOVEAI = 0
@ -256,5 +256,5 @@ end
assert(ravitype(x()) == 'number[]')
assert(x()[1] == 42.0)
check(x, {'NEW_IARRAY', 'LOADK', 'SETLIST', 'TEST',
'JMP', 'NEW_FARRAY', 'LOADK', 'SETLIST', 'TOARRAYF',
'JMP', 'NEW_FARRAY', 'LOADK', 'SETLIST', 'TOFARRAY',
'RETURN', 'RETURN'})

@ -268,7 +268,7 @@ Parameter lists may have static type annotations as well, so when parsing parame
}
else if (tt == RAVI_TARRAYFLT || tt == RAVI_TARRAYINT) {
/* code an instruction to convert in place */
luaK_codeABC(ls->fs, tt == RAVI_TARRAYFLT ? OP_RAVI_TOARRAYF : OP_RAVI_TOARRAYI, i, 0, 0);
luaK_codeABC(ls->fs, tt == RAVI_TARRAYFLT ? OP_RAVI_TOFARRAY : OP_RAVI_TOIARRAY, i, 0, 0);
}
}
}
@ -415,7 +415,7 @@ The main changes compared to ``explist()`` are the calls to ``ravi_typecheck()``
/* code an instruction to convert in place */
luaK_codeABC(ls->fs,
vars[i] == RAVI_TARRAYFLT ?
OP_RAVI_TOARRAYF : OP_RAVI_TOARRAYI,
OP_RAVI_TOFARRAY : OP_RAVI_TOIARRAY,
a + (i - n), 0, 0);
}
else if ((vars[n] == RAVI_TNUMFLT || vars[n] == RAVI_TNUMINT) &&
@ -435,7 +435,7 @@ The simple case is when the type of the expression matches the variable.
Secondly if the expression is a table initializer then we need to generate specialized opcodes if the target variable is supposed to be ``integer[]`` or ``number[]``. The specialized opcode sets up some information in the ``Table`` structure. The problem is that this requires us to modify ``OP_NEWTABLE`` instruction which has already been emitted. So we scan the generated instructions to find the last ``OP_NEWTABLE`` instruction that assigns to the register associated with the target variable.
Next bit of special handling is for function calls. If the assignment makes a function call then we perform type coercion on return values where these values are being assigned to variables with defined types. This means that if the target variable is ``integer`` or ``number`` we issue opcodes ``TOINT`` and ``TOFLT`` respectively. If the target variable is ``integer[]`` or ``number[]`` then we issue ``TOARRAYI`` and ``TOARRAYF`` respectively. These opcodes ensure that the values are of required type or can be cast to the required type.
Next bit of special handling is for function calls. If the assignment makes a function call then we perform type coercion on return values where these values are being assigned to variables with defined types. This means that if the target variable is ``integer`` or ``number`` we issue opcodes ``TOINT`` and ``TOFLT`` respectively. If the target variable is ``integer[]`` or ``number[]`` then we issue ``TOIARRAY`` and ``TOFARRAY`` respectively. These opcodes ensure that the values are of required type or can be cast to the required type.
Note that any left over variables that are not assigned values, are set to 0 if they are of integer or number type, else they are set to nil as per Lua's default behavior. This is handled in ``localvar_adjust_assign()`` which is described later on.
@ -558,7 +558,7 @@ Note the use of ``register_to_localvar_index()`` in functions below.
OP_RAVI_TOFLT : OP_RAVI_TOINT, i, 0, 0);
else if (ravi_type == RAVI_TARRAYINT || ravi_type == RAVI_TARRAYFLT)
luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ?
OP_RAVI_TOARRAYI : OP_RAVI_TOARRAYF, i, 0, 0);
OP_RAVI_TOIARRAY : OP_RAVI_TOFARRAY, i, 0, 0);
}
}

@ -194,9 +194,9 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_TOFLT | YES | R(A) := tofloat(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_TOARRAYI | YES | R(A) := to_arrayi(R(A)) |
| OP_RAVI_TOIARRAY | YES | R(A) := to_arrayi(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_TOARRAYF | YES | R(A) := to_arrayf(R(A)) |
| OP_RAVI_TOFARRAY | YES | R(A) := to_arrayf(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_MOVEI | YES | R(A) := R(B), check R(B) is integer |
+-------------------------+----------+--------------------------------------------------+

@ -1505,7 +1505,7 @@ static void code_type_assertion(FuncState *fs, UnOpr op, expdesc *e, TString *us
}
return;
}
opcode = OP_RAVI_TOARRAYI;
opcode = OP_RAVI_TOIARRAY;
tt = RAVI_TARRAYINT;
}
else if (op == OPR_TO_NUMARRAY && e->ravi_type != RAVI_TARRAYFLT) {
@ -1518,7 +1518,7 @@ static void code_type_assertion(FuncState *fs, UnOpr op, expdesc *e, TString *us
}
return;
}
opcode = OP_RAVI_TOARRAYF;
opcode = OP_RAVI_TOFARRAY;
tt = RAVI_TARRAYFLT;
}
else if (op == OPR_TO_TABLE && e->ravi_type != RAVI_TTABLE) {

@ -107,8 +107,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"TOINT", /* A R(A) := toint(R(A)) */
"TOFLT", /* A R(A) := tofloat(R(A)) */
"TOARRAYI", /* A R(A) := to_arrayi(R(A)) */
"TOARRAYF", /* A R(A) := to_arrayf(R(A)) */
"TOIARRAY", /* A R(A) := to_arrayi(R(A)) */
"TOFARRAY", /* A R(A) := to_arrayf(R(A)) */
"TOTAB", /* A R(A) := to_table(R(A)) */
"TOSTRING",
"TOCLOSURE",
@ -248,8 +248,8 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOINT A R(A) := toint(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOFLT A R(A) := tonumber(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOARRAYI A R(A) := check_array_of_int(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOARRAYF A R(A) := check_array_of_float(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOIARRAY A R(A) := check_array_of_int(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOFARRAY A R(A) := check_array_of_float(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOTAB A R(A) := check_table(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOSTRING */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOCLOSURE */

@ -584,8 +584,8 @@ static void ravi_code_typecoersion(LexState *ls, int reg, ravitype_t ravi_type,
ravi_type == RAVI_TNUMFLT ? OP_RAVI_TOFLT : OP_RAVI_TOINT, reg,
0, 0);
else if (ravi_type == RAVI_TARRAYINT || ravi_type == RAVI_TARRAYFLT)
luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ? OP_RAVI_TOARRAYI
: OP_RAVI_TOARRAYF,
luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ? OP_RAVI_TOIARRAY
: OP_RAVI_TOFARRAY,
reg, 0, 0);
else if (ravi_type == RAVI_TTABLE)
luaK_codeABC(ls->fs, OP_RAVI_TOTAB,

@ -1211,8 +1211,8 @@ int luaV_execute (lua_State *L) {
&&vmlabel(OP_RAVI_DIVII),
&&vmlabel(OP_RAVI_TOINT),
&&vmlabel(OP_RAVI_TOFLT),
&&vmlabel(OP_RAVI_TOARRAYI),
&&vmlabel(OP_RAVI_TOARRAYF),
&&vmlabel(OP_RAVI_TOIARRAY),
&&vmlabel(OP_RAVI_TOFARRAY),
&&vmlabel(OP_RAVI_TOTAB),
&&vmlabel(OP_RAVI_TOSTRING),
&&vmlabel(OP_RAVI_TOCLOSURE),
@ -2413,12 +2413,12 @@ int luaV_execute (lua_State *L) {
luaG_runerror(L, "table expected");
vmbreak;
}
vmcase(OP_RAVI_TOARRAYI) {
vmcase(OP_RAVI_TOIARRAY) {
if (RAVI_UNLIKELY(!ttisiarray(ra)))
luaG_runerror(L, "integer[] expected");
vmbreak;
}
vmcase(OP_RAVI_TOARRAYF) {
vmcase(OP_RAVI_TOFARRAY) {
if (RAVI_UNLIKELY(!ttisfarray(ra)))
luaG_runerror(L, "number[] expected");
vmbreak;

@ -681,8 +681,8 @@ bool raviJ_cancompile(Proto *p) {
case OP_RAVI_MOVETAB:
case OP_RAVI_TOINT:
case OP_RAVI_TOFLT:
case OP_RAVI_TOARRAYI:
case OP_RAVI_TOARRAYF:
case OP_RAVI_TOIARRAY:
case OP_RAVI_TOFARRAY:
case OP_RAVI_TOTAB:
case OP_RAVI_NEW_IARRAY:
case OP_RAVI_NEW_FARRAY:
@ -2120,10 +2120,10 @@ bool raviJ_codegen(struct lua_State *L, struct Proto *p,
case OP_RAVI_TOTAB: {
emit_op_totab(&fn, A, pc);
} break;
case OP_RAVI_TOARRAYI: {
case OP_RAVI_TOIARRAY: {
emit_op_toai(&fn, A, pc);
} break;
case OP_RAVI_TOARRAYF: {
case OP_RAVI_TOFARRAY: {
emit_op_toaf(&fn, A, pc);
} break;
case OP_RAVI_TOSTRING: {

@ -1707,10 +1707,10 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
case OP_RAVI_TOTAB: {
emit_TOARRAY(def, A, RAVI_TTABLE, "table expected", pc);
} break;
case OP_RAVI_TOARRAYI: {
case OP_RAVI_TOIARRAY: {
emit_TOARRAY(def, A, RAVI_TARRAYINT, "integer[] expected", pc);
} break;
case OP_RAVI_TOARRAYF: {
case OP_RAVI_TOFARRAY: {
emit_TOARRAY(def, A, RAVI_TARRAYFLT, "number[] expected", pc);
} break;
case OP_RAVI_TOSTRING: {

@ -917,11 +917,11 @@ void RaviCodeGenerator::emit_TOARRAY(RaviFunctionDef *def, int A,
LuaTypeCode expectedType = RAVI__TLTABLE;
switch (array_type_expected) {
case RAVI_TARRAYINT:
op = OP_RAVI_TOARRAYI;
op = OP_RAVI_TOIARRAY;
expectedType = RAVI__TIARRAY;
break;
case RAVI_TARRAYFLT:
op = OP_RAVI_TOARRAYF;
op = OP_RAVI_TOFARRAY;
expectedType = RAVI__TFARRAY;
break;
case RAVI_TTABLE:

@ -485,8 +485,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES + 1] =
"TOINT", /* A R(A) := toint(R(A)) */
"TOFLT", /* A R(A) := tofloat(R(A)) */
"TOARRAYI", /* A R(A) := to_arrayi(R(A)) */
"TOARRAYF", /* A R(A) := to_arrayf(R(A)) */
"TOIARRAY", /* A R(A) := to_arrayi(R(A)) */
"TOFARRAY", /* A R(A) := to_arrayf(R(A)) */
"TOTAB", /* A R(A) := to_table(R(A)) */
"TOSTRING",
"TOCLOSURE",

Loading…
Cancel
Save