DUALNUM: Handle integer type in x86/x64 interpreter and libraries.

This commit is contained in:
Mike Pall
2011-02-27 01:36:59 +01:00
parent c031d4b6a0
commit cead25f928
16 changed files with 6913 additions and 4238 deletions

View File

@@ -151,13 +151,29 @@ GCstr *lj_lib_optstr(lua_State *L, int narg)
return (o < L->top && !tvisnil(o)) ? lj_lib_checkstr(L, narg) : NULL;
}
#if LJ_DUALNUM
void lj_lib_checknumber(lua_State *L, int narg)
{
TValue *o = L->base + narg-1;
if (!(o < L->top &&
(tvisnumber(o) || (tvisstr(o) && lj_str_tonumber(strV(o), o)))))
lj_err_argt(L, narg, LUA_TNUMBER);
}
#endif
lua_Number lj_lib_checknum(lua_State *L, int narg)
{
TValue *o = L->base + narg-1;
if (!(o < L->top &&
(tvisnumber(o) || (tvisstr(o) && lj_str_tonumber(strV(o), o)))))
lj_err_argt(L, narg, LUA_TNUMBER);
return numberVnum(o);
if (LJ_UNLIKELY(tvisint(o))) {
lua_Number n = (lua_Number)intV(o);
setnumV(o, n);
return n;
} else {
return numV(o);
}
}
int32_t lj_lib_checkint(lua_State *L, int narg)
@@ -166,7 +182,13 @@ int32_t lj_lib_checkint(lua_State *L, int narg)
if (!(o < L->top &&
(tvisnumber(o) || (tvisstr(o) && lj_str_tonumber(strV(o), o)))))
lj_err_argt(L, narg, LUA_TNUMBER);
return numberVint(o);
if (LJ_LIKELY(tvisint(o))) {
return intV(o);
} else {
int32_t i = lj_num2int(numV(o));
if (LJ_DUALNUM) setintV(o, i);
return i;
}
}
int32_t lj_lib_optint(lua_State *L, int narg, int32_t def)
@@ -175,6 +197,21 @@ int32_t lj_lib_optint(lua_State *L, int narg, int32_t def)
return (o < L->top && !tvisnil(o)) ? lj_lib_checkint(L, narg) : def;
}
int32_t lj_lib_checkbit(lua_State *L, int narg)
{
TValue *o = L->base + narg-1;
if (!(o < L->top &&
(tvisnumber(o) || (tvisstr(o) && lj_str_tonumber(strV(o), o)))))
lj_err_argt(L, narg, LUA_TNUMBER);
if (LJ_LIKELY(tvisint(o))) {
return intV(o);
} else {
int32_t i = lj_num2bit(numV(o));
if (LJ_DUALNUM) setintV(o, i);
return i;
}
}
GCfunc *lj_lib_checkfunc(lua_State *L, int narg)
{
TValue *o = L->base + narg-1;