issue #60 more work on implementing specialized bytecode for table get/set

pull/81/head
Dibyendu Majumdar 9 years ago
parent 55df8ea9cd
commit 1362b6dc6d

@ -305,11 +305,12 @@ OP_RAVI_SETTABLEI,/* A B C R(A)[RK(B)] := RK(C), integer key */
OP_RAVI_SETTABLES,/* A B C R(A)[RK(B)] := RK(C), string key */
OP_RAVI_TOTAB, /* A R(A) := to_table(R(A)) */
OP_RAVI_MOVETAB, /* A B R(A) := R(B), check R(B) is a table */
OP_RAVI_SETUPVALT,/* A B UpValue[B] := to_table(R(A)) */
} OpCode;
#define NUM_OPCODES (cast(int, OP_RAVI_MOVETAB) + 1)
#define NUM_OPCODES (cast(int, OP_RAVI_SETUPVALT) + 1)
/*===========================================================================
Notes:

@ -702,7 +702,8 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
static OpCode check_valid_setupval(FuncState *fs, expdesc *var, expdesc *ex) {
OpCode op = OP_SETUPVAL;
if ((var->ravi_type == RAVI_TNUMINT || var->ravi_type == RAVI_TNUMFLT ||
var->ravi_type == RAVI_TARRAYFLT || var->ravi_type == RAVI_TARRAYINT) &&
var->ravi_type == RAVI_TARRAYFLT || var->ravi_type == RAVI_TARRAYINT ||
var->ravi_type == RAVI_TTABLE) &&
var->ravi_type != ex->ravi_type) {
if (var->ravi_type == RAVI_TNUMINT)
op = OP_RAVI_SETUPVALI;
@ -712,6 +713,8 @@ static OpCode check_valid_setupval(FuncState *fs, expdesc *var, expdesc *ex) {
op = OP_RAVI_SETUPVALAI;
else if (var->ravi_type == RAVI_TARRAYFLT)
op = OP_RAVI_SETUPVALAF;
else if (var->ravi_type == RAVI_TTABLE)
op = OP_RAVI_SETUPVALT;
else
luaX_syntaxerror(fs->ls,
luaO_pushfstring(fs->ls->L, "Invalid assignment of "

@ -149,7 +149,7 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"SETTABLES", /* A B C R(A)[RK(B)] := RK(C), string key */
"TOTAB", /* A R(A) := to_table(R(A)) */
"MOVETAB", /* A B R(A) := R(B), check R(B) is a table */
"SETUPVALT", /* A B UpValue[B] := to_table(R(A)) */
NULL
};
@ -281,6 +281,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOTAB A R(A) := check_table(R(A)) */
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVETAB A B R(A) := R(B), check R(B) is a table */
,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RAVI_SETUPVALT */
};

@ -1741,6 +1741,13 @@ newframe: /* reentry point when frame changes (call/return) */
setobj(L, uv->v, ra);
luaC_upvalbarrier(L, uv);
} break;
case OP_RAVI_SETUPVALT: {
if (!ttistable(ra) || hvalue(ra)->ravi_array.array_type != RAVI_TTABLE)
luaG_runerror(L, "upvalue of table type, cannot be set to non table value");
UpVal *uv = cl->upvals[GETARG_B(i)];
setobj(L, uv->v, ra);
luaC_upvalbarrier(L, uv);
} break;
}
}

Loading…
Cancel
Save