summaryrefslogtreecommitdiff
path: root/src/lj_ffrecord.c
diff options
context:
space:
mode:
authorMike Pall <mike>2011-03-10 01:57:24 +0100
committerMike Pall <mike>2011-03-10 01:57:24 +0100
commitbfce3c1127fd57fe0c935c92bcf45b4737041edd (patch)
tree2bd2d9e08c70608de63c7a69df7f00cfab07f6be /src/lj_ffrecord.c
parent3f26e3a89d54dfb761ca02fc89aaf15326f5f514 (diff)
downloadluajit2-bfce3c1127fd57fe0c935c92bcf45b4737041edd.tar.gz
DUALNUM: Handle integer type in JIT compiler.
Diffstat (limited to 'src/lj_ffrecord.c')
-rw-r--r--src/lj_ffrecord.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c
index 631321d9..8077bf84 100644
--- a/src/lj_ffrecord.c
+++ b/src/lj_ffrecord.c
@@ -63,9 +63,9 @@ typedef void (LJ_FASTCALL *RecordFunc)(jit_State *J, RecordFFData *rd);
/* Get runtime value of int argument. */
static int32_t argv2int(jit_State *J, TValue *o)
{
- if (!tvisnum(o) && !(tvisstr(o) && lj_str_tonum(strV(o), o)))
+ if (!tvisnumber(o) && !(tvisstr(o) && lj_str_tonumber(strV(o), o)))
lj_trace_err(J, LJ_TRERR_BADTYPE);
- return lj_num2bit(numV(o));
+ return tvisint(o) ? intV(o) : lj_num2int(numV(o));
}
/* Get runtime value of string argument. */
@@ -75,9 +75,12 @@ static GCstr *argv2str(jit_State *J, TValue *o)
return strV(o);
} else {
GCstr *s;
- if (!tvisnum(o))
+ if (!tvisnumber(o))
lj_trace_err(J, LJ_TRERR_BADTYPE);
- s = lj_str_fromnum(J->L, &o->n);
+ if (tvisint(o))
+ s = lj_str_fromint(J->L, intV(o));
+ else
+ s = lj_str_fromnum(J->L, &o->n);
setstrV(J->L, o, s);
return s;
}
@@ -128,7 +131,7 @@ static void LJ_FASTCALL recff_type(jit_State *J, RecordFFData *rd)
{
/* Arguments already specialized. Result is a constant string. Neat, huh? */
uint32_t t;
- if (tvisnum(&rd->argv[0]))
+ if (tvisnumber(&rd->argv[0]))
t = ~LJ_TNUMX;
else if (LJ_64 && tvislightud(&rd->argv[0]))
t = ~LJ_TLIGHTUD;
@@ -255,7 +258,7 @@ static void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd)
TRef tr = J->base[0];
TRef base = J->base[1];
if (tr && base) {
- base = lj_ir_toint(J, base);
+ base = lj_opt_narrow_toint(J, base);
if (!tref_isk(base) || IR(tref_ref(base))->i != 10)
recff_nyiu(J);
}
@@ -332,12 +335,12 @@ static void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd)
RecordIndex ix;
ix.tab = J->base[0];
if (tref_istab(ix.tab)) {
- if (!tvisnum(&rd->argv[1])) /* No support for string coercion. */
+ if (!tvisnumber(&rd->argv[1])) /* No support for string coercion. */
lj_trace_err(J, LJ_TRERR_BADTYPE);
- setnumV(&ix.keyv, numV(&rd->argv[1])+(lua_Number)1);
+ setintV(&ix.keyv, numberVint(&rd->argv[1])+1);
settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));
ix.val = 0; ix.idxchain = 0;
- ix.key = lj_ir_toint(J, J->base[1]);
+ ix.key = lj_opt_narrow_toint(J, J->base[1]);
J->base[0] = ix.key = emitir(IRTI(IR_ADD), ix.key, lj_ir_kint(J, 1));
J->base[1] = lj_record_idx(J, &ix);
rd->nres = tref_isnil(J->base[1]) ? 0 : 2;
@@ -525,26 +528,26 @@ static void LJ_FASTCALL recff_math_random(jit_State *J, RecordFFData *rd)
/* Record unary bit.tobit, bit.bnot, bit.bswap. */
static void LJ_FASTCALL recff_bit_unary(jit_State *J, RecordFFData *rd)
{
- TRef tr = lj_ir_tobit(J, J->base[0]);
+ TRef tr = lj_opt_narrow_tobit(J, J->base[0]);
J->base[0] = (rd->data == IR_TOBIT) ? tr : emitir(IRTI(rd->data), tr, 0);
}
/* Record N-ary bit.band, bit.bor, bit.bxor. */
static void LJ_FASTCALL recff_bit_nary(jit_State *J, RecordFFData *rd)
{
- TRef tr = lj_ir_tobit(J, J->base[0]);
+ TRef tr = lj_opt_narrow_tobit(J, J->base[0]);
uint32_t op = rd->data;
BCReg i;
for (i = 1; J->base[i] != 0; i++)
- tr = emitir(IRTI(op), tr, lj_ir_tobit(J, J->base[i]));
+ tr = emitir(IRTI(op), tr, lj_opt_narrow_tobit(J, J->base[i]));
J->base[0] = tr;
}
/* Record bit shifts. */
static void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd)
{
- TRef tr = lj_ir_tobit(J, J->base[0]);
- TRef tsh = lj_ir_tobit(J, J->base[1]);
+ TRef tr = lj_opt_narrow_tobit(J, J->base[0]);
+ TRef tsh = lj_opt_narrow_tobit(J, J->base[1]);
if (!(rd->data < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&
!tref_isk(tsh))
tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 31));
@@ -570,25 +573,25 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd)
int32_t start, end;
if (rd->data) { /* string.sub(str, start [,end]) */
start = argv2int(J, &rd->argv[1]);
- trstart = lj_ir_toint(J, J->base[1]);
+ trstart = lj_opt_narrow_toint(J, J->base[1]);
trend = J->base[2];
if (tref_isnil(trend)) {
trend = lj_ir_kint(J, -1);
end = -1;
} else {
- trend = lj_ir_toint(J, trend);
+ trend = lj_opt_narrow_toint(J, trend);
end = argv2int(J, &rd->argv[2]);
}
} else { /* string.byte(str, [,start [,end]]) */
if (J->base[1]) {
start = argv2int(J, &rd->argv[1]);
- trstart = lj_ir_toint(J, J->base[1]);
+ trstart = lj_opt_narrow_toint(J, J->base[1]);
trend = J->base[2];
if (tref_isnil(trend)) {
trend = trstart;
end = start;
} else {
- trend = lj_ir_toint(J, trend);
+ trend = lj_opt_narrow_toint(J, trend);
end = argv2int(J, &rd->argv[2]);
}
} else {