aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lj_record.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/lj_record.c b/src/lj_record.c
index 536d7171..5c0f00d9 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -382,12 +382,27 @@ static TRef fori_load(jit_State *J, BCReg slot, IRType t, int mode)
382 mode + conv); 382 mode + conv);
383} 383}
384 384
385/* Convert FORI argument to expected target type. */
386static TRef fori_conv(jit_State *J, TRef tr, IRType t)
387{
388 if (t == IRT_INT) {
389 if (!tref_isinteger(tr))
390 return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK);
391 } else {
392 if (!tref_isnum(tr))
393 return emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);
394 }
395 return tr;
396}
397
385/* Peek before FORI to find a const initializer. Otherwise load from slot. */ 398/* Peek before FORI to find a const initializer. Otherwise load from slot. */
386static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, 399static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot,
387 IRType t, int mode) 400 IRType t, int mode)
388{ 401{
389 TRef tr = J->base[slot]; 402 TRef tr = J->base[slot];
390 if (!tr) { 403 if (tr) {
404 tr = fori_conv(J, tr, t);
405 } else {
391 tr = find_kinit(J, fori, slot, t); 406 tr = find_kinit(J, fori, slot, t);
392 if (!tr) 407 if (!tr)
393 tr = fori_load(J, slot, t, mode); 408 tr = fori_load(J, slot, t, mode);
@@ -534,13 +549,7 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl)
534 lj_assertJ(tref_isnumber_str(tr[i]), "bad FORI argument type"); 549 lj_assertJ(tref_isnumber_str(tr[i]), "bad FORI argument type");
535 if (tref_isstr(tr[i])) 550 if (tref_isstr(tr[i]))
536 tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0); 551 tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0);
537 if (t == IRT_INT) { 552 tr[i] = fori_conv(J, tr[i], t);
538 if (!tref_isinteger(tr[i]))
539 tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK);
540 } else {
541 if (!tref_isnum(tr[i]))
542 tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT);
543 }
544 } 553 }
545 tr[FORL_EXT] = tr[FORL_IDX]; 554 tr[FORL_EXT] = tr[FORL_IDX];
546 stop = tr[FORL_STOP]; 555 stop = tr[FORL_STOP];