issue #60 compile TOTAB and MOVETAB

pull/81/head
Dibyendu Majumdar 9 years ago
parent 2b7a450baf
commit aca5b3ef86

@ -960,7 +960,7 @@ public:
void emit_TOINT(RaviFunctionDef *def, int A, int pc);
void emit_TOFLT(RaviFunctionDef *def, int A, int pc);
void emit_LEN(RaviFunctionDef *def, int A, int B, int pc);
void emit_SETTABLE(RaviFunctionDef *def, int A, int B, int C, int pc);
@ -1040,6 +1040,8 @@ public:
void emit_MOVEAI(RaviFunctionDef *def, int A, int B, int pc);
void emit_MOVEAF(RaviFunctionDef *def, int A, int B, int pc);
void emit_MOVETAB(RaviFunctionDef *def, int A, int B, int pc);
void emit_TOARRAY(RaviFunctionDef *def, int A, int array_type_expected,
const char *errmsg, int pc);

@ -875,6 +875,8 @@ bool RaviCodeGenerator::canCompile(Proto *p) {
case OP_RAVI_GETTABLE_S:
case OP_RAVI_SETTABLE_I:
case OP_RAVI_SETTABLE_S:
case OP_RAVI_TOTAB:
case OP_RAVI_MOVETAB:
break;
default:
return false;
@ -1592,6 +1594,9 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p,
int C = GETARG_C(i);
emit_SETTABLE_AF(def, A, B, C, op == OP_RAVI_SETTABLE_AFF, pc);
} break;
case OP_RAVI_TOTAB: {
emit_TOARRAY(def, A, RAVI_TTABLE, "table expected", pc);
} break;
case OP_RAVI_TOARRAYI: {
emit_TOARRAY(def, A, RAVI_TARRAYINT, "integer[] expected", pc);
} break;
@ -1606,6 +1611,10 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p,
int B = GETARG_B(i);
emit_MOVEAF(def, A, B, pc);
} break;
case OP_RAVI_MOVETAB: {
int B = GETARG_B(i);
emit_MOVETAB(def, A, B, pc);
} break;
case OP_GETTABUP: {
int B = GETARG_B(i);

@ -647,13 +647,16 @@ void RaviCodeGenerator::emit_TOARRAY(RaviFunctionDef *def, int A,
int array_type_expected,
const char *errmsg, int pc) {
// if (!ttistable(ra) || hvalue(ra)->ravi_array.type != RAVI_TARRAYINT)
// luaG_runerror(L, "integer[] expected");
emit_debug_trace(def,
array_type_expected == RAVI_TARRAYINT ? OP_RAVI_TOARRAYI
: OP_RAVI_TOARRAYF,
pc);
OpCode op = OP_RAVI_TOTAB;
switch (array_type_expected) {
case RAVI_TARRAYINT: op = OP_RAVI_TOARRAYI; break;
case RAVI_TARRAYFLT: op = OP_RAVI_TOARRAYF; break;
case RAVI_TTABLE:
default:
break;
}
emit_debug_trace(def, op, pc);
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Instruction *type = emit_load_type(def, ra);
@ -711,4 +714,15 @@ void RaviCodeGenerator::emit_MOVEAF(RaviFunctionDef *def, int A, int B,
llvm::Value *dest = emit_gep_register(def, A);
emit_assign(def, dest, src);
}
void RaviCodeGenerator::emit_MOVETAB(RaviFunctionDef *def, int A, int B,
int pc) {
emit_debug_trace(def, OP_RAVI_MOVETAB, pc);
emit_TOARRAY(def, B, RAVI_TTABLE, "table expected", pc);
llvm::Value *src = emit_gep_register(def, B);
llvm::Value *dest = emit_gep_register(def, A);
emit_assign(def, dest, src);
}
}
Loading…
Cancel
Save