Roberto Ierusalimschy 1 년 전
부모
커밋
c31d6774ac
7개의 변경된 파일25개의 추가작업 그리고 24개의 파일을 삭제
  1. 0 4
      config.lua
  2. 1 2
      lapi.c
  3. 2 3
      lapi.h
  4. 16 10
      lobject.c
  5. 3 4
      ltm.c
  6. 1 1
      manual/manual.of
  7. 2 0
      testes/sort.lua

+ 0 - 4
config.lua

@@ -1,4 +0,0 @@
-collectgarbage("setparam", "minormul", 25)
--- collectgarbage("generational")
-
-

+ 1 - 2
lapi.c

@@ -1262,9 +1262,8 @@ LUA_API int lua_next (lua_State *L, int idx) {
   api_checknelems(L, 1);
   api_checknelems(L, 1);
   t = gettable(L, idx);
   t = gettable(L, idx);
   more = luaH_next(L, t, L->top.p - 1);
   more = luaH_next(L, t, L->top.p - 1);
-  if (more) {
+  if (more)
     api_incr_top(L);
     api_incr_top(L);
-  }
   else  /* no more elements */
   else  /* no more elements */
     L->top.p -= 1;  /* remove key */
     L->top.p -= 1;  /* remove key */
   lua_unlock(L);
   lua_unlock(L);

+ 2 - 3
lapi.h

@@ -13,9 +13,8 @@
 
 
 
 
 /* Increments 'L->top.p', checking for stack overflows */
 /* Increments 'L->top.p', checking for stack overflows */
-#define api_incr_top(L)	{L->top.p++; \
-			 api_check(L, L->top.p <= L->ci->top.p, \
-					"stack overflow");}
+#define api_incr_top(L)  \
+    (L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow"))
 
 
 
 
 /*
 /*

+ 16 - 10
lobject.c

@@ -73,17 +73,29 @@ unsigned int luaO_codeparam (unsigned int p) {
 
 
 
 
 /*
 /*
-** Computes 'p' times 'x', where 'p' is a floating-point byte.
+** Computes 'p' times 'x', where 'p' is a floating-point byte. Roughly,
+** we have to multiply 'x' by the mantissa and then shift accordingly to
+** the exponent.  If the exponent is positive, both the multiplication
+** and the shift increase 'x', so we have to care only about overflows.
+** For negative exponents, however, multiplying before the shift keeps
+** more significant bits, as long as the multiplication does not
+** overflow, so we check which order is best.
 */
 */
 l_obj luaO_applyparam (unsigned int p, l_obj x) {
 l_obj luaO_applyparam (unsigned int p, l_obj x) {
   unsigned int m = p & 0xF;  /* mantissa */
   unsigned int m = p & 0xF;  /* mantissa */
   int e = (p >> 4);  /* exponent */
   int e = (p >> 4);  /* exponent */
   if (e > 0) {  /* normalized? */
   if (e > 0) {  /* normalized? */
-    e--;
-    m += 0x10;  /* maximum 'm' is 0x1F */
+    e--;  /* correct exponent */
+    m += 0x10;  /* correct mantissa; maximum value is 0x1F */
   }
   }
   e -= 7;  /* correct excess-7 */
   e -= 7;  /* correct excess-7 */
-  if (e < 0) {
+  if (e >= 0) {
+    if (x < (MAX_LOBJ / 0x1F) >> e)  /* no overflow? */
+      return (x * m) << e;  /* order doesn't matter here */
+    else  /* real overflow */
+      return MAX_LOBJ;
+  }
+  else {  /* negative exponent */
     e = -e;
     e = -e;
     if (x < MAX_LOBJ / 0x1F)  /* multiplication cannot overflow? */
     if (x < MAX_LOBJ / 0x1F)  /* multiplication cannot overflow? */
       return (x * m) >> e;  /* multiplying first gives more precision */
       return (x * m) >> e;  /* multiplying first gives more precision */
@@ -92,12 +104,6 @@ l_obj luaO_applyparam (unsigned int p, l_obj x) {
     else  /* real overflow */
     else  /* real overflow */
       return MAX_LOBJ;
       return MAX_LOBJ;
   }
   }
-  else {
-    if (x < (MAX_LOBJ / 0x1F) >> e)  /* no overflow? */
-      return (x * m) << e;  /* order doesn't matter here */
-    else  /* real overflow */
-      return MAX_LOBJ;
-  }
 }
 }
 
 
 
 

+ 3 - 4
ltm.c

@@ -92,10 +92,9 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) {
   Table *mt;
   Table *mt;
   if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||
   if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||
       (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {
       (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {
-    TValue name;
-    int hres = luaH_getshortstr(mt, luaS_new(L, "__name"), &name);
-    if (hres == HOK && ttisstring(&name))  /* is '__name' a string? */
-      return getstr(tsvalue(&name));  /* use it as type name */
+    const TValue *name = luaH_Hgetshortstr(mt, luaS_new(L, "__name"));
+    if (ttisstring(name))  /* is '__name' a string? */
+      return getstr(tsvalue(name));  /* use it as type name */
   }
   }
   return ttypename(ttype(o));  /* else use standard type name */
   return ttypename(ttype(o));  /* else use standard type name */
 }
 }

+ 1 - 1
manual/manual.of

@@ -6473,7 +6473,7 @@ Otherwise, returns the metatable of the given object.
 
 
 @LibEntry{ipairs (t)|
 @LibEntry{ipairs (t)|
 
 
-Returns three values (an iterator function, the table @id{t}, and 0)
+Returns three values (an iterator function, the value @id{t}, and 0)
 so that the construction
 so that the construction
 @verbatim{
 @verbatim{
 for i,v in ipairs(t) do @rep{body} end
 for i,v in ipairs(t) do @rep{body} end

+ 2 - 0
testes/sort.lua

@@ -13,6 +13,8 @@ do print "testing 'table.create'"
     assert(#t == i - 1)
     assert(#t == i - 1)
     t[i] = 0
     t[i] = 0
   end
   end
+  for i = 1, 20 do  t[#t + 1] = i * 10  end
+  assert(#t == 40 and t[39] == 190)
   assert(not T or T.querytab(t) == 10000)
   assert(not T or T.querytab(t) == 10000)
   t = nil
   t = nil
   collectgarbage()
   collectgarbage()