summaryrefslogtreecommitdiff
path: root/src/lib_base.c
diff options
context:
space:
mode:
authorMike Pall <mike>2011-02-17 00:44:14 +0100
committerMike Pall <mike>2011-02-17 00:44:14 +0100
commit03946ac978d9a1a3230619e3da048002e5fda2d1 (patch)
treec0a7b8edaccf789f128468320d451d9a1fee1495 /src/lib_base.c
parent963f05c7e153714921484e0de71a7cb6bab338d9 (diff)
downloadluajit-03946ac978d9a1a3230619e3da048002e5fda2d1.tar.gz
luajit-03946ac978d9a1a3230619e3da048002e5fda2d1.tar.bz2
luajit-03946ac978d9a1a3230619e3da048002e5fda2d1.zip
DUALNUM: Add integer type to core VM.
Diffstat (limited to 'src/lib_base.c')
-rw-r--r--src/lib_base.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/lib_base.c b/src/lib_base.c
index 1a9a6df2..746a4fd6 100644
--- a/src/lib_base.c
+++ b/src/lib_base.c
@@ -190,8 +190,8 @@ LJLIB_ASM(tonumber) LJLIB_REC(.)
190 int32_t base = lj_lib_optint(L, 2, 10); 190 int32_t base = lj_lib_optint(L, 2, 10);
191 if (base == 10) { 191 if (base == 10) {
192 TValue *o = lj_lib_checkany(L, 1); 192 TValue *o = lj_lib_checkany(L, 1);
193 if (tvisnum(o) || (tvisstr(o) && lj_str_tonum(strV(o), o))) { 193 if (tvisnumber(o) || (tvisstr(o) && lj_str_tonumber(strV(o), o))) {
194 setnumV(L->base-1, numV(o)); 194 copyTV(L, L->base-1, o);
195 return FFH_RES(1); 195 return FFH_RES(1);
196 } 196 }
197#if LJ_HASFFI 197#if LJ_HASFFI
@@ -212,7 +212,10 @@ LJLIB_ASM(tonumber) LJLIB_REC(.)
212 if (p != ep) { 212 if (p != ep) {
213 while (lj_char_isspace((unsigned char)(*ep))) ep++; 213 while (lj_char_isspace((unsigned char)(*ep))) ep++;
214 if (*ep == '\0') { 214 if (*ep == '\0') {
215 setnumV(L->base-1, cast_num(ul)); 215 if (LJ_DUALNUM && LJ_LIKELY(ul < 0x80000000u))
216 setintV(L->base-1, (int32_t)ul);
217 else
218 setnumV(L->base-1, (lua_Number)ul);
216 return FFH_RES(1); 219 return FFH_RES(1);
217 } 220 }
218 } 221 }
@@ -234,8 +237,8 @@ LJLIB_ASM(tostring) LJLIB_REC(.)
234 return FFH_TAILCALL; 237 return FFH_TAILCALL;
235 } else { 238 } else {
236 GCstr *s; 239 GCstr *s;
237 if (tvisnum(o)) { 240 if (tvisnumber(o)) {
238 s = lj_str_fromnum(L, &o->n); 241 s = lj_str_fromnumber(L, o);
239 } else if (tvispri(o)) { 242 } else if (tvispri(o)) {
240 s = strV(lj_lib_upvalue(L, -(int32_t)itype(o))); 243 s = strV(lj_lib_upvalue(L, -(int32_t)itype(o)));
241 } else { 244 } else {
@@ -359,7 +362,7 @@ static const char *reader_func(lua_State *L, void *ud, size_t *size)
359 if (tvisnil(L->top)) { 362 if (tvisnil(L->top)) {
360 *size = 0; 363 *size = 0;
361 return NULL; 364 return NULL;
362 } else if (tvisstr(L->top) || tvisnum(L->top)) { 365 } else if (tvisstr(L->top) || tvisnumber(L->top)) {
363 copyTV(L, L->base+2, L->top); /* Anchor string in reserved stack slot. */ 366 copyTV(L, L->base+2, L->top); /* Anchor string in reserved stack slot. */
364 return lua_tolstring(L, 3, size); 367 return lua_tolstring(L, 3, size);
365 } else { 368 } else {
@@ -385,7 +388,7 @@ LJLIB_CF(dofile)
385 if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0) 388 if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0)
386 lua_error(L); 389 lua_error(L);
387 lua_call(L, 0, LUA_MULTRET); 390 lua_call(L, 0, LUA_MULTRET);
388 return cast_int(L->top - L->base) - 1; 391 return (int)(L->top - L->base) - 1;
389} 392}
390 393
391/* -- Base library: GC control -------------------------------------------- */ 394/* -- Base library: GC control -------------------------------------------- */
@@ -402,7 +405,7 @@ LJLIB_CF(collectgarbage)
402 "\4stop\7restart\7collect\5count\1\377\4step\10setpause\12setstepmul"); 405 "\4stop\7restart\7collect\5count\1\377\4step\10setpause\12setstepmul");
403 int32_t data = lj_lib_optint(L, 2, 0); 406 int32_t data = lj_lib_optint(L, 2, 0);
404 if (opt == LUA_GCCOUNT) { 407 if (opt == LUA_GCCOUNT) {
405 setnumV(L->top, cast_num(G(L)->gc.total)/1024.0); 408 setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0);
406 } else { 409 } else {
407 int res = lua_gc(L, opt, data); 410 int res = lua_gc(L, opt, data);
408 if (opt == LUA_GCSTEP) 411 if (opt == LUA_GCSTEP)
@@ -464,8 +467,13 @@ LJLIB_CF(print)
464 if (shortcut && tvisstr(o)) { 467 if (shortcut && tvisstr(o)) {
465 str = strVdata(o); 468 str = strVdata(o);
466 size = strV(o)->len; 469 size = strV(o)->len;
470 } else if (shortcut && tvisint(o)) {
471 char buf[LJ_STR_INTBUF];
472 char *p = lj_str_bufint(buf, intV(o));
473 size = (size_t)(buf+LJ_STR_INTBUF-p);
474 str = p;
467 } else if (shortcut && tvisnum(o)) { 475 } else if (shortcut && tvisnum(o)) {
468 char buf[LUAI_MAXNUMBER2STR]; 476 char buf[LJ_STR_NUMBUF];
469 size = lj_str_bufnum(buf, o); 477 size = lj_str_bufnum(buf, o);
470 str = buf; 478 str = buf;
471 } else { 479 } else {
@@ -604,7 +612,7 @@ static void newproxy_weaktable(lua_State *L)
604 setgcref(t->metatable, obj2gco(t)); 612 setgcref(t->metatable, obj2gco(t));
605 setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")), 613 setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")),
606 lj_str_newlit(L, "kv")); 614 lj_str_newlit(L, "kv"));
607 t->nomm = cast_byte(~(1u<<MM_mode)); 615 t->nomm = (uint8_t)(~(1u<<MM_mode));
608} 616}
609 617
610LUALIB_API int luaopen_base(lua_State *L) 618LUALIB_API int luaopen_base(lua_State *L)