|
@@ -307,12 +307,27 @@ static TRef fori_load(jit_State *J, BCReg slot, IRType t, int mode)
|
|
|
mode + conv);
|
|
mode + conv);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* Convert FORI argument to expected target type. */
|
|
|
|
|
+static TRef fori_conv(jit_State *J, TRef tr, IRType t)
|
|
|
|
|
+{
|
|
|
|
|
+ if (t == IRT_INT) {
|
|
|
|
|
+ if (!tref_isinteger(tr))
|
|
|
|
|
+ return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (!tref_isnum(tr))
|
|
|
|
|
+ return emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);
|
|
|
|
|
+ }
|
|
|
|
|
+ return tr;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* Peek before FORI to find a const initializer. Otherwise load from slot. */
|
|
/* Peek before FORI to find a const initializer. Otherwise load from slot. */
|
|
|
static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot,
|
|
static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot,
|
|
|
IRType t, int mode)
|
|
IRType t, int mode)
|
|
|
{
|
|
{
|
|
|
TRef tr = J->base[slot];
|
|
TRef tr = J->base[slot];
|
|
|
- if (!tr) {
|
|
|
|
|
|
|
+ if (tr) {
|
|
|
|
|
+ tr = fori_conv(J, tr, t);
|
|
|
|
|
+ } else {
|
|
|
tr = find_kinit(J, fori, slot, t);
|
|
tr = find_kinit(J, fori, slot, t);
|
|
|
if (!tr)
|
|
if (!tr)
|
|
|
tr = fori_load(J, slot, t, mode);
|
|
tr = fori_load(J, slot, t, mode);
|
|
@@ -458,13 +473,7 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl)
|
|
|
lua_assert(tref_isnumber_str(tr[i]));
|
|
lua_assert(tref_isnumber_str(tr[i]));
|
|
|
if (tref_isstr(tr[i]))
|
|
if (tref_isstr(tr[i]))
|
|
|
tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0);
|
|
tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0);
|
|
|
- if (t == IRT_INT) {
|
|
|
|
|
- if (!tref_isinteger(tr[i]))
|
|
|
|
|
- tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK);
|
|
|
|
|
- } else {
|
|
|
|
|
- if (!tref_isnum(tr[i]))
|
|
|
|
|
- tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ tr[i] = fori_conv(J, tr[i], t);
|
|
|
}
|
|
}
|
|
|
tr[FORL_EXT] = tr[FORL_IDX];
|
|
tr[FORL_EXT] = tr[FORL_IDX];
|
|
|
stop = tr[FORL_STOP];
|
|
stop = tr[FORL_STOP];
|