Lua diffs-lua-5.4.0-alpha-beta-rc1


README

2c2
< This is Lua 5.4.0 (alpha), released on 06 Jun 2019.
> This is Lua 5.4.0 (beta), released on 02 Oct 2019.

doc/contents.html

194a195
> <A HREF="manual.html#pdf-debug.setcstacklimit">debug.setcstacklimit</A><BR>

439a441
> <A HREF="manual.html#lua_setcstacklimit">lua_setcstacklimit</A><BR>

626c628
< Wed Jun  5 21:27:06 -03 2019
> Mon Sep 30 23:54:47 UTC 2019

629c631
< Last change: revised for Lua 5.4.0 (alpha)
> Last change: revised for Lua 5.4.0 (beta)

doc/manual.html

315c315
< the default value for its <code>_ENV</code> upvalue
> the default value for its <code>_ENV</code> variable

325c325
< of its first upvalue.)
> of its first upvalue; see <a href="#lua_setupvalue"><code>lua_setupvalue</code></a>.)

1496c1496
< The resulting function always has <code>_ENV</code> as its only upvalue,
> The resulting function always has <code>_ENV</code> as its only external variable,

1716c1716,1728
< Then the loop body is repeated with the value of the control variable
> 
> 
> <p>
> If both the initial value and the step are integers,
> the loop is done with integers;
> note that the limit may not be an integer.
> Otherwise, the loop is done with floats.
> (Beware of floating-point accuracy in this case.)
> 
> 
> <p>
> After that initialization,
> the loop body is repeated with the value of the control variable

1719,1720c1731
< with a common difference given by the step,
< until that value passes the limit.
> with a common difference given by the step.

1722a1734,1736
> The loop continues while the value is less than
> or equal to the limit
> (greater than or equal to for a negative step).

1729,1734c1743,1745
< If both the initial value and the step are integers,
< the loop is done with integers;
< in this case, the range of the control variable is clipped
< by the range of integers.
< Otherwise, the loop is done with floats.
< (Beware of floating-point accuracy in this case.)
> For integer loops,
> the control variable never wraps around;
> instead, the loop ends in case of an overflow.

1830,1831c1841,1843
< 	stat ::= <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]
< 	stat ::=  <b>local</b> &lsquo;<b>&lt;</b>&rsquo; Name &lsquo;<b>&gt;</b>&rsquo; Name &lsquo;<b>=</b>&rsquo; exp </pre><p>
> 	stat ::= <b>local</b> attnamelist [&lsquo;<b>=</b>&rsquo; explist]
> 	attnamelist ::=  Name attrib {&lsquo;<b>,</b>&rsquo; Name attrib}
> </pre><p>

1835,1837c1847,1855
< The second syntax declares a local with a given attribute,
< which is the name between the angle brackets.
< In this case, there must be an initialization.
> 
> 
> <p>
> Each variable name may be postfixed by an attribute
> (a name between angle brackets):
> 
> <pre>
> 	attrib ::= [&lsquo;<b>&lt;</b>&rsquo; Name &lsquo;<b>&gt;</b>&rsquo;]
> </pre><p>

1842c1860,1861
< and <code>toclose</code>, which declares a to-be-closed variable (see <a href="#3.3.8">&sect;3.3.8</a>).
> and <code>close</code>, which declares a to-be-closed variable (see <a href="#3.3.8">&sect;3.3.8</a>).
> A list of variables can contain at most one to-be-closed variable.

1860,1864d1878
< A local variable can be declared as a <em>to-be-closed</em> variable,
< using the identifier <code>toclose</code> as its attribute:
< 
< <pre>
< 	stat ::=  <b>local</b> &lsquo;<b>&lt;</b>&rsquo; <code>toclose</code> &lsquo;<b>&gt;</b>&rsquo; Name &lsquo;<b>=</b>&rsquo; exp </pre><p>

1875,1878d1888
< If the value is <b>nil</b>, it is ignored;
< otherwise,
< if it does not have a <code>__close</code> metamethod,
< an error is raised.

1881c1891,1892
< and the error object (if any) is passed as a second argument;
> and the error object that caused the exit (if any)
> is passed as a second argument;

1885a1897,1903
> The value assigned to a to-be-closed variable
> must have a <code>__close</code> metamethod
> or be a false value.
> (<b>nil</b> and <b>false</b> are ignored as to-be-closed values.)
> 
> 
> <p>

1893,1895c1911,1915
< where the variable was defined;
< in particular,
< the other pending closing methods will still be called.
> where the variable was defined.
> However, Lua may call the method one more time.
> 
> 
> <p>

1897,1898c1917,1919
< other errors in closing methods
< interrupt the respective method,
> the other pending closing methods will still be called.
> Errors in these methods
> interrupt the respective method and generate a warning,

1900c1921
< the error reported is the original one.
> the error reported is only the original one.

1904,1905c1925,1926
< If a coroutine yields inside a block and is never resumed again,
< the variables visible at that block will never go out of scope,
> If a coroutine yields and is never resumed again,
> some variables may never go out of scope,

1906a1928,1929
> (These variables are the ones created inside the coroutine
> and in scope at the point where the coroutine yielded.)

1911c1934
< you should either use finalizers
> you can either use finalizers

2721,2722c2744,2745
< A local variable used by an inner function is called
< an <em>upvalue</em>, or <em>external local variable</em>,
> A local variable used by an inner function is called an <em>upvalue</em>
> (or <em>external local variable</em>, or simply <em>external variable</em>)

2734c2757
<      for i=1,10 do
>      for i = 1, 10 do

2736c2759
<        a[i] = function () y=y+1; return x+y end
>        a[i] = function () y = y + 1; return x + y end

3538,3539c3561,3563
< Destroys all objects in the given Lua state
< (calling the corresponding garbage-collection metamethods, if any)
> Close all active to-be-closed variables in the main thread,
> release all objects in the given Lua state
> (calling the corresponding garbage-collection metamethods, if any),

5100c5124
< <pre>void lua_setmetatable (lua_State *L, int index);</pre>
> <pre>int lua_setmetatable (lua_State *L, int index);</pre>

5106a5131,5135
> <p>
> (For historical reasons, this function returns an <code>int</code>,
> which now is always 1.)
> 
> 

5277c5306
< that is equal to or below an already marked to-be-closed index.
> that is equal to or below an active to-be-closed index.

5529a5559,5562
> <p>
> See <a href="#pdf-warn"><code>warn</code></a> for more details about warnings.
> 
> 

5542a5576,5579
> <p>
> See <a href="#pdf-warn"><code>warn</code></a> for more details about warnings.
> 
> 

6014,6018c6051
< For C&nbsp;functions, this function uses the empty string <code>""</code>
< as a name for all upvalues.
< (For Lua functions,
< upvalues are the external local variables that the function uses,
< and that are consequently included in its closure.)
> See <a href="#pdf-debug.getupvalue"><code>debug.getupvalue</code></a> for more information about upvalues.

6071a6105,6122
> <hr><h3><a name="lua_setcstacklimit"><code>lua_setcstacklimit</code></a></h3><p>
> <span class="apii">[-0, +0, &ndash;]</span>
> <pre>int (lua_setcstacklimit) (lua_State *L, unsigned int limit);</pre>
> 
> <p>
> Sets a new limit for the C stack.
> This limit controls how deeply nested calls can go in Lua,
> with the intent of avoiding a stack overflow.
> Returns the old limit in case of success,
> or zero in case of error.
> For more details about this function,
> see <a href="#pdf-debug.setcstacklimit"><code>debug.setcstacklimit</code></a>,
> its equivalent in the standard library.
> 
> 
> 
> 
> 

7355c7406
< or <b>nil</b> plus an error message, in case of error.
> or a false value plus an error message, in case of error.

7513a7565,7573
> The notation <b>fail</b> means a return value representing
> some kind of failure or the absence of a better value to return.
> Currently, <b>fail</b> is equal to <b>nil</b>,
> but that may change in future versions.
> The recommendation is to test the success of these functions
> with <code>(not status)</code>, instead of <code>(status == nil)</code>.
> 
> 
> <p>

7757,7758c7817,7818
< returns the compiled chunk as a function;
< otherwise, returns <b>nil</b> plus the error message.
> <code>load</code> returns the compiled chunk as a function;
> otherwise, it returns <b>fail</b> plus the error message.

8015c8075
< otherwise, it returns <b>nil</b>.
> otherwise, it returns <b>fail</b>.

8033c8093
< the function returns <b>nil</b>.
> the function returns <b>fail</b>.

8091a8152,8163
> <p>
> By convention,
> a one-piece message starting with '<code>@</code>'
> is intended to be a <em>control message</em>,
> which is a message to the warning system itself.
> In particular, the standard warning function in Lua
> recognizes the control messages "<code>@off</code>",
> to stop the emission of warnings,
> and "<code>@on</code>", to (re)start the emission;
> it ignores unknown control messages.
> 
> 

8610c8682
< or <b>nil</b> plus an error message if none succeeds.
> or <b>fail</b> plus an error message if none succeeds.

8713c8785
< otherwise, it returns <b>nil</b>.
> otherwise, it returns <b>fail</b>.

8721d8792
< Note that if <code>plain</code> is given, then <code>init</code> must be given as well.

8956c9027
< otherwise it returns <b>nil</b>.
> otherwise it returns <b>fail</b>.

9280c9351
< As a special case, the empty capture <code>()</code> captures
> As a special case, the capture <code>()</code> captures

9519c9590
< returns a false value plus the position of the first invalid byte.
> returns <b>fail</b> plus the position of the first invalid byte.

9539c9610
< the function returns <b>nil</b>.
> the function returns <b>fail</b>.

9974a10046,10054
> 
> 
> <p>
> This function returns the two seed components
> that were effectively used,
> so that setting them again repeats the sequence.
> 
> 
> <p>

10021c10101
< Otherwise, returns <b>nil</b>.
> Otherwise, returns <b>fail</b>.

10033c10113
< or <b>nil</b> if <code>x</code> is not a number.
> or <b>fail</b> if <code>x</code> is not a number.

10087c10167
< all I/O functions return <b>nil</b> on failure,
> all I/O functions return <b>fail</b> on failure,

10090c10170
< and some value different from <b>nil</b> on success.
> and some non-false value on success.

10147,10148c10227,10228
< When the iterator function detects the end of file,
< it returns no values (to finish the loop) and automatically closes the file.
> When the iterator function fails to read any value,
> it automatically closes the file.

10166c10246,10247
< In case of errors this function raises the error,
> In case of errors opening the file,
> this function raises the error,

10261c10342
< or <b>nil</b> if <code>obj</code> is not a file handle.
> or <b>fail</b> if <code>obj</code> is not a file handle.

10326,10330d10406
< <p>
< In case of errors this function raises the error,
< instead of returning an error code.
< 
< 

10342c10418
< or <b>nil</b> if it cannot read data with the specified format.
> or <b>fail</b> if it cannot read data with the specified format.

10364c10440
< it is discarded and the format returns <b>nil</b>.
> it is discarded and the format returns <b>fail</b>.

10369c10445,10446
< On end of file, it returns the empty string.
> On end of file, it returns the empty string;
> this format never fails.

10374c10451
< returning <b>nil</b> on end of file.
> returning <b>fail</b> on end of file.

10380c10457
< returning <b>nil</b> on end of file.
> returning <b>fail</b> on end of file.

10385c10462
< returning <b>nil</b> on end of file.
> returning <b>fail</b> on end of file.

10388c10465
< or <b>nil</b> on end of file.
> or <b>fail</b> on end of file.

10414c10491
< If <code>seek</code> fails, it returns <b>nil</b>,
> If <code>seek</code> fails, it returns <b>fail</b>,

10436c10513
< Sets the buffering mode for an output file.
> Sets the buffering mode for a file.

10439a10517,10520
> <li><b>"<code>no</code>": </b> no buffering.</li>
> <li><b>"<code>full</code>": </b> full buffering.</li>
> <li><b>"<code>line</code>": </b> line buffering.</li>
> </ul>

10441,10457c10522
< <li><b>"<code>no</code>": </b>
< no buffering; the result of any output operation appears immediately.
< </li>
< 
< <li><b>"<code>full</code>": </b>
< full buffering; output operation is performed only
< when the buffer is full or when
< you explicitly <code>flush</code> the file (see <a href="#pdf-io.flush"><code>io.flush</code></a>).
< </li>
< 
< <li><b>"<code>line</code>": </b>
< line buffering; output is buffered until a newline is output
< or there is any input from some special files
< (such as a terminal device).
< </li>
< 
< </ul><p>
> <p>

10462a10528,10533
> <p>
> The specific behavior of each mode is non portable;
> check the underlying ISO&nbsp;C function <code>setvbuf</code> in your platform for
> more details.
> 
> 

10476d10546
< Otherwise it returns <b>nil</b> plus a string describing the error.

10541c10611
< which gives a reasonable date and time representation
> which gives a human-readable date and time representation

10576c10646
< or <b>nil</b> otherwise.
> or <b>fail</b> otherwise.

10630c10700
< or <b>nil</b> if the variable is not defined.
> or <b>fail</b> if the variable is not defined.

10642c10712
< If this function fails, it returns <b>nil</b>,
> If this function fails, it returns <b>fail</b>

10655c10725
< If this function fails, it returns <b>nil</b>,
> If this function fails, it returns <b>fail</b>,

10674c10744
< or <b>nil</b> if the request cannot be honored.
> or <b>fail</b> if the request cannot be honored.

10831a10902,10905
> <p>
> Returns <b>fail</b> if there is no active hook.
> 
> 

10849c10923
< then <code>getinfo</code> returns <b>nil</b>.
> then <code>getinfo</code> returns <b>fail</b>.

10892a10967,10968
> Compile-time constants may not appear in this listing,
> if they were optimized away by the compiler.

10895c10971,10972
< The function returns <b>nil</b> if there is no variable with the given index,
> The function returns <b>fail</b>
> if there is no variable with the given index,

10942c11019,11020
< The function returns <b>nil</b> if there is no upvalue with the given index.
> The function returns <b>fail</b>
> if there is no upvalue with the given index.

10946,10947c11024,11036
< Variable names starting with '<code>(</code>' (open parenthesis) 
< represent variables with no known names
> (For Lua functions,
> upvalues are the external local variables that the function uses,
> and that are consequently included in its closure.)
> 
> 
> <p>
> For C&nbsp;functions, this function uses the empty string <code>""</code>
> as a name for all upvalues.
> 
> 
> <p>
> Variable name '<code>?</code>' (interrogation mark)
> represents variables with no known names

10965a11055,11091
> <hr><h3><a name="pdf-debug.setcstacklimit"><code>debug.setcstacklimit (limit)</code></a></h3>
> 
> 
> <p>
> Sets a new limit for the C stack.
> This limit controls how deeply nested calls can go in Lua,
> with the intent of avoiding a stack overflow.
> A limit too small restricts recursive calls pointlessly;
> a limit too large exposes the interpreter to stack-overflow crashes.
> Unfortunately, there is no way to know a priori
> the maximum safe limit for a platform.
> 
> 
> <p>
> Each call made from Lua code counts one unit.
> Other operations (e.g., calls made from C to Lua or resuming a coroutine)
> may have a higher cost.
> 
> 
> <p>
> This function has the following restrictions:
> 
> <ul>
> <li>It can only be called from the main coroutine (thread);</li>
> <li>It cannot be called while handling a stack-overflow error;</li>
> <li><code>limit</code> must be less than 40000;</li>
> <li><code>limit</code> cannot be less than the amount of C stack in use.</li>
> </ul><p>
> If a call does not respect some restriction,
> it returns <b>false</b>.
> Otherwise,
> the call returns the old limit.
> 
> 
> 
> 
> <p>

11014c11140
< The function returns <b>nil</b> if there is no local
> The function returns <b>fail</b> if there is no local

11047c11173
< The function returns <b>nil</b> if there is no upvalue
> The function returns <b>fail</b> if there is no upvalue

11051a11178,11181
> <p>
> See <a href="#pdf-debug.getupvalue"><code>debug.getupvalue</code></a> for more information about upvalues.
> 
> 

11066c11196
< or <b>nil</b> if the userdata does not have that value.
> or <b>fail</b> if the userdata does not have that value.

11147a11278
> <li><b><code>-W</code>: </b> turn warnings on;</li>

11179c11310,11311
< All options are handled in order, except <code>-i</code> and <code>-E</code>.
> The options <code>-e</code>, <code>-l</code>, and <code>-W</code> are handled in
> the order they appear.

11183c11315
<      $ lua -e'a=1' -e 'print(a)' script.lua
>      $ lua -e 'a=1' -llib1 script.lua

11185c11317
< will first set <code>a</code> to 1, then print the value of <code>a</code>,
> will first set <code>a</code> to 1, then require the library <code>lib1</code>,

11256c11388,11389
< Warnings are simply printed in the standard error output.
> When warnings are on,
> they are simply printed in the standard error output.

11506,11507c11639,11643
< 		 <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist] | 
< 		 <b>local</b> &lsquo;<b>&lt;</b>&rsquo; Name &lsquo;<b>&gt;</b>&rsquo; Name &lsquo;<b>=</b>&rsquo; exp 
> 		 <b>local</b> attnamelist [&lsquo;<b>=</b>&rsquo; explist] 
> 
> 	attnamelist ::=  Name attrib {&lsquo;<b>,</b>&rsquo; Name attrib}
> 
> 	attrib ::= [&lsquo;<b>&lt;</b>&rsquo; Name &lsquo;<b>&gt;</b>&rsquo;]

11565c11701
< Thu Jun  6 15:59:35 -03 2019
> Wed Oct  2 21:30:38 UTC 2019

11568c11704
< Last change: revised for Lua 5.4.0 (alpha)
> Last change: revised for Lua 5.4.0 (beta)

doc/readme.html

113c113
< the top-level directory, which is named <TT>lua-5.4.0-alpha</TT>.
> the top-level directory, which is named <TT>lua-5.4.0-beta</TT>.

332c332
< Thu Jun  6 10:58:49 -03 2019
> Tue Sep 24 16:42:41 UTC 2019

335c335
< Last change: revised for Lua 5.4.0 (alpha)
> Last change: revised for Lua 5.4.0 (beta)

src/Makefile

134a135,145
> llex.o:
> 	$(CC) $(CFLAGS) -Os -c llex.c
> 
> lparser.o:
> 	$(CC) $(CFLAGS) -Os -c lparser.c
> 
> lcode.o:
> 	$(CC) $(CFLAGS) -Os -c lcode.c
> 
> 	
> 

src/lapi.c

173c173,175
<   StkId func = L->ci->func;
>   CallInfo *ci = L->ci;
>   StkId func = ci->func;
>   ptrdiff_t diff;  /* difference for new top */

176,180c178,181
<     StkId newtop = (func + 1) + idx;
<     api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
<     while (L->top < newtop)
<       setnilvalue(s2v(L->top++));
<     L->top = newtop;
>     api_check(L, idx <= ci->top - (func + 1), "new top too large");
>     diff = ((func + 1) + idx) - L->top;
>     for (; diff > 0; diff--)
>       setnilvalue(s2v(L->top++));  /* clear new slots */

184c185
<     L->top += idx+1;  /* 'subtract' index (index is negative) */
>     diff = idx + 1;  /* will "subtract" index (as it is negative) */

186c187,189
<   luaF_close(L, L->top, LUA_OK);
>   if (diff < 0 && hastocloseCfunc(ci->nresults))
>     luaF_close(L, L->top + diff, LUA_OK);
>   L->top += diff;  /* correct top only after closing any upvalue */

src/lapi.h

13a14,15
> 
> /* Increments 'L->top', checking for stack overflows */

16a19,24
> 
> /*
> ** If a call returns too many multiple returns, the callee may not have
> ** stack space to accomodate all results. In this case, this macro
> ** increases its stack space ('L->ci->top').
> */

19a28,29
> 
> /* Ensure the stack has at least 'n' elements */

src/lauxlib.c

65c65
<         lua_replace(L, -3);  /* (in the slot ocupied by table) */
>         lua_replace(L, -3);  /* (in the slot occupied by table) */

252c252
<     lua_pushnil(L);
>     luaL_pushfail(L);

294c294
<       lua_pushnil(L);
>       luaL_pushfail(L);

297c297
<     return 3;  /* return true/nil,what,code */
>     return 3;  /* return true/fail,what,code */

1005,1006c1005,1008
< ** Emit a warning. '*previoustocont' signals whether previous message
< ** was to be continued by the current one.
> ** Emit a warning. '*warnstate' means:
> ** 0 - warning system is off;
> ** 1 - ready to start a new message;
> ** 2 - previous message is to be continued.

1009,1010c1011,1021
<   int *previoustocont = (int *)ud;
<   if (!*previoustocont)  /* previous message was the last? */
>   int *warnstate = (int *)ud;
>   if (*warnstate != 2 && !tocont && *message == '@') {  /* control message? */
>     if (strcmp(message, "@off") == 0)
>       *warnstate = 0;
>     else if (strcmp(message, "@on") == 0)
>       *warnstate = 1;
>     return;
>   }
>   else if (*warnstate == 0)  /* warnings off? */
>     return;
>   if (*warnstate == 1)  /* previous message was the last? */

1013c1024,1026
<   if (!tocont)  /* is this the last part? */
>   if (tocont)  /* not the last part? */
>     *warnstate = 2;  /* to be continued */
>   else {  /* last part */

1015c1028,1029
<   *previoustocont = tocont;
>     *warnstate = 1;  /* ready to start a new message */
>   }

1022c1036
<     int *previoustocont;  /* space for warning state */
>     int *warnstate;  /* space for warning state */

1024c1038
<     previoustocont = (int *)lua_newuserdatauv(L, sizeof(int), 0);
>     warnstate = (int *)lua_newuserdatauv(L, sizeof(int), 0);

1026,1027c1040,1041
<     *previoustocont = 0;  /* next message starts a new warning */
<     lua_setwarnf(L, warnf, previoustocont);
>     *warnstate = 0;  /* default is warnings off */
>     lua_setwarnf(L, warnf, warnstate);

src/lauxlib.h

155a156,159
> /* push the value used to represent failure/error */
> #define luaL_pushfail(L)	lua_pushnil(L)
> 
> 

src/lbaselib.c

51c51
<   for (i = 1; i <= n; i++)  /* compose warning */
>   for (i = 1; i < n; i++)  /* compose warning */

53c53
<   lua_warning(L, "", 0);  /* close warning */
>   lua_warning(L, lua_tostring(L, n), 0);  /* close warning */

109c109
<   lua_pushnil(L);  /* not a number */
>   luaL_pushfail(L);  /* not a number */

311c311
<     lua_pushnil(L);
>     luaL_pushfail(L);

313c313
<     return 2;  /* return nil plus error message */
>     return 2;  /* return fail plus error message */

src/lcode.c

55c55
< static int tonumeral(const expdesc *e, TValue *v) {
> static int tonumeral (const expdesc *e, TValue *v) {

70a71,106
> ** Get the constant value from a constant expression
> */
> static TValue *const2val (FuncState *fs, const expdesc *e) {
>   lua_assert(e->k == VCONST);
>   return &fs->ls->dyd->actvar.arr[e->u.info].k;
> }
> 
> 
> /*
> ** If expression is a constant, fills 'v' with its value
> ** and returns 1. Otherwise, returns 0.
> */
> int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v) {
>   if (hasjumps(e))
>     return 0;  /* not a constant */
>   switch (e->k) {
>     case VFALSE: case VTRUE:
>       setbvalue(v, e->k == VTRUE);
>       return 1;
>     case VNIL:
>       setnilvalue(v);
>       return 1;
>     case VKSTR: {
>       setsvalue(fs->ls->L, v, e->u.strval);
>       return 1;
>     }
>     case VCONST: {
>       setobj(fs->ls->L, v, const2val(fs, e));
>       return 1;
>     }
>     default: return tonumeral(e, v);
>   }
> }
> 
> 
> /*

326,327c362,363
<     fs->previousline -= f->lineinfo[pc];  /* last line saved */
<     fs->iwthabs--;
>     fs->previousline -= f->lineinfo[pc];  /* correct last line saved */
>     fs->iwthabs--;  /* undo previous increment */

329a366
>     lua_assert(f->abslineinfo[fs->nabslineinfo - 1].pc == pc);

331d367
<     lua_assert(f->abslineinfo[fs->nabslineinfo].pc = pc);

351c387
< static int luaK_code (FuncState *fs, Instruction i) {
> int luaK_code (FuncState *fs, Instruction i) {

461c497
<   if (reg >= fs->nactvar) {
>   if (reg >= luaY_nvarstack(fs)) {

540c576
< int luaK_stringK (FuncState *fs, TString *s) {
> static int stringK (FuncState *fs, TString *s) {

593,595c629,631
< ** Check whether 'i' can be stored in an 'sC' operand.
< ** Equivalent to (0 <= i + OFFSET_sC && i + OFFSET_sC <= MAXARG_C)
< ** but without risk of overflows in the addition.
> ** Check whether 'i' can be stored in an 'sC' operand. Equivalent to
> ** (0 <= int2sC(i) && int2sC(i) <= MAXARG_C) but without risk of
> ** overflows in the hidden addition inside 'int2sC'.

598c634
<   return (-OFFSET_sC <= i && i <= MAXARG_C - OFFSET_sC);
>   return (l_castS2U(i) + OFFSET_sC <= cast_uint(MAXARG_C));

618,622d653
< static int floatI (lua_Number f, lua_Integer *fi) {
<   return (luaV_flttointeger(f, fi, 0) && fitsBx(*fi));
< }
< 
< 

625c656
<   if (floatI(f, &fi))
>   if (luaV_flttointeger(f, &fi, 0) && fitsBx(fi))

632a664,688
> ** Convert a constant in 'v' into an expression description 'e'
> */
> static void const2exp (TValue *v, expdesc *e) {
>   switch (ttypetag(v)) {
>     case LUA_TNUMINT:
>       e->k = VKINT; e->u.ival = ivalue(v);
>       break;
>     case LUA_TNUMFLT:
>       e->k = VKFLT; e->u.nval = fltvalue(v);
>       break;
>     case LUA_TBOOLEAN:
>       e->k = bvalue(v) ? VTRUE : VFALSE;
>       break;
>     case LUA_TNIL:
>       e->k = VNIL;
>       break;
>     case LUA_TSHRSTR:  case LUA_TLNGSTR:
>       e->k = VKSTR; e->u.strval = tsvalue(v);
>       break;
>     default: lua_assert(0);
>   }
> }
> 
> 
> /*

650a707,716
> ** Convert a VKSTR to a VK
> */
> static void str2K (FuncState *fs, expdesc *e) {
>   lua_assert(e->k == VKSTR);
>   e->u.info = stringK(fs, e->u.strval);
>   e->k = VK;
> }
> 
> 
> /*

675c741
< ** Ensure that expression 'e' is not a variable.
> ** Ensure that expression 'e' is not a variable (nor a constant).

679a746,749
>     case VCONST: {
>       const2exp(const2val(fs, e), e);
>       break;
>     }

681c751
<       e->u.info = e->u.var.idx;
>       e->u.info = e->u.var.sidx;

686c756
<       e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.var.idx, 0);
>       e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);

737a808,810
>     case VKSTR: {
>       str2K(fs, e);
>     }  /* FALLTHROUGH */

853c926
<     if (e->u.info >= fs->nactvar) {  /* reg. is not a local? */
>     if (e->u.info >= luaY_nvarstack(fs)) {  /* reg. is not a local? */

897a971
>       case VKSTR: info = stringK(fs, e->u.strval); break;

942c1016
<       exp2reg(fs, ex, var->u.var.idx);  /* compute 'ex' into proper place */
>       exp2reg(fs, ex, var->u.var.sidx);  /* compute 'ex' into proper place */

947c1021
<       luaK_codeABC(fs, OP_SETUPVAL, e, var->u.var.idx, 0);
>       luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);

1032c1106
<     case VK: case VKFLT: case VKINT: case VTRUE: {
>     case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: {

1077d1150
<   luaK_dischargevars(fs, e);

1083c1156
<     case VK: case VKFLT: case VKINT: case VTRUE: {
>     case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: {

1146c1219,1220
< static int isSCnumber (expdesc *e, lua_Integer *i, int *isfloat) {
> static int isSCnumber (expdesc *e, int *pi, int *isfloat) {
>   lua_Integer i;

1148,1151c1222,1223
<     *i = e->u.ival;
<   else if (!(e->k == VKFLT && floatI(e->u.nval, i)))
<     return 0;  /* not a number */
<   else
>     i = e->u.ival;
>   else if (e->k == VKFLT && luaV_flttointeger(e->u.nval, &i, 0))

1153,1154c1225,1228
<   if (!hasjumps(e) && fitsC(*i)) {
<     *i += OFFSET_sC;
>   else
>     return 0;  /* not a number */
>   if (!hasjumps(e) && fitsC(i)) {
>     *pi = int2sC(cast_int(i));

1168a1243,1244
>   if (k->k == VKSTR)
>     str2K(fs, k);

1171c1247
<   if (t->k == VUPVAL && !isKstr(fs, k))  /* upvalue indexed by non string? */
>   if (t->k == VUPVAL && !isKstr(fs, k))  /* upvalue indexed by non 'Kstr'? */

1174c1250
<     t->u.ind.t = t->u.var.idx;  /* upvalue index */
>     t->u.ind.t = t->u.info;  /* upvalue index */

1180c1256
<     t->u.ind.t = (t->k == VLOCAL) ? t->u.var.idx: t->u.info;
>     t->u.ind.t = (t->k == VLOCAL) ? t->u.var.sidx: t->u.info;

1221c1297
<                                                 const expdesc *e2) {
>                                         const expdesc *e2) {

1260,1262d1335
< ** Because 'luaK_exp2anyreg' can free registers, its calls must be
< ** in "stack order" (that is, first on 'e2', which may have more
< ** recent registers to be released).

1265c1338,1339
<                              OpCode op, int v2, int k, int line) {
>                              OpCode op, int v2, int flip, int line,
>                              OpCode mmop, TMS event) {

1267c1341
<   int pc = luaK_codeABCk(fs, op, 0, v1, v2, k);
>   int pc = luaK_codeABCk(fs, op, 0, v1, v2, 0);

1271a1346,1347
>   luaK_codeABCk(fs, mmop, v1, v2, event, flip);  /* to call metamethod */
>   luaK_fixline(fs, line);

1282c1358,1360
<   finishbinexpval(fs, e1, e2, op, v2, 0, line);
>   lua_assert(OP_ADD <= op && op <= OP_SHR);
>   finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
>                   cast(TMS, (op - OP_ADD) + TM_ADD));

1287c1365
< ** Code binary operators ('+', '-', ...) with immediate operands.
> ** Code binary operators with immediate operands.

1290,1292c1368,1394
<                        expdesc *e1, expdesc *e2, int k, int line) {
<   int v2 = cast_int(e2->u.ival) + OFFSET_sC;  /* immediate operand */
<   finishbinexpval(fs, e1, e2, op, v2, k, line);
>                        expdesc *e1, expdesc *e2, int flip, int line,
>                        TMS event) {
>   int v2 = int2sC(cast_int(e2->u.ival));  /* immediate operand */
>   lua_assert(e2->k == VKINT);
>   finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINI, event);
> }
> 
> 
> /* Try to code a binary operator negating its second operand.
> ** For the metamethod, 2nd operand must keep its original value.
> */
> static int finishbinexpneg (FuncState *fs, expdesc *e1, expdesc *e2,
>                              OpCode op, int line, TMS event) {
>   if (!luaK_isKint(e2))
>     return 0;  /* not an integer constant */
>   else {
>     lua_Integer i2 = e2->u.ival;
>     if (!(fitsC(i2) && fitsC(-i2)))
>       return 0;  /* not in the proper range */
>     else {  /* operating a small integer constant */
>       int v2 = cast_int(i2);
>       finishbinexpval(fs, e1, e2, op, int2sC(-v2), 0, line, OP_MMBINI, event);
>       /* correct metamethod argument */
>       SETARG_B(fs->f->code[fs->pc - 1], int2sC(v2));
>       return 1;  /* successfully coded */
>     }
>   }

1303,1304c1405
< ** constant in the proper range, use variant opcodes with immediate
< ** operands or K operands.
> ** constant in the proper range, use variant opcodes with K operands.

1306c1407
< static void codearith (FuncState *fs, OpCode op,
> static void codearith (FuncState *fs, BinOpr opr,

1308,1310c1409,1410
<   if (isSCint(e2))  /* immediate operand? */
<     codebini(fs, cast(OpCode, op - OP_ADD + OP_ADDI), e1, e2, flip, line);
<   else if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) {  /* K operand? */
>   TMS event = cast(TMS, opr + TM_ADD);
>   if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) {  /* K operand? */

1312,1313c1412,1413
<     op = cast(OpCode, op - OP_ADD + OP_ADDK);
<     finishbinexpval(fs, e1, e2, op, v2, flip, line);
>     OpCode op = cast(OpCode, opr + OP_ADDK);
>     finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);

1315a1416
>     OpCode op = cast(OpCode, opr + OP_ADD);

1328c1429
< static void codecommutative (FuncState *fs, OpCode op,
> static void codecommutative (FuncState *fs, BinOpr op,

1335c1436,1439
<   codearith(fs, op, e1, e2, flip, line);
>   if (op == OPR_ADD && isSCint(e2))  /* immediate operand? */
>     codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD);
>   else
>     codearith(fs, op, e1, e2, flip, line);

1345c1449
<   int inv = 0;
>   int flip = 0;

1350c1454
<     inv = 1;
>     flip = 1;

1353c1457
<     op = cast(OpCode, opr - OPR_BAND + OP_BAND);
>     op = cast(OpCode, opr + OP_ADD);

1358c1462
<   op = cast(OpCode, opr - OPR_BAND + OP_BANDK);
>   op = cast(OpCode, opr + OP_ADDK);

1360,1379c1464,1465
<   finishbinexpval(fs, e1, e2, op, v2, inv, line);
< }
< 
< 
< /*
< ** Code shift operators. If second operand is constant, use immediate
< ** operand (negating it if shift is in the other direction).
< */
< static void codeshift (FuncState *fs, OpCode op,
<                        expdesc *e1, expdesc *e2, int line) {
<   if (isSCint(e2)) {
<     int changedir = 0;
<     if (op == OP_SHL) {
<       changedir = 1;
<       e2->u.ival = -(e2->u.ival);
<     }
<     codebini(fs, OP_SHRI, e1, e2, changedir, line);
<   }
<   else
<     codebinexpval(fs, op, e1, e2, line);
>   finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK,
>                   cast(TMS, opr + TM_ADD));

1389c1475
<   lua_Integer im;
>   int im;

1394c1480
<     r2 = cast_int(im);
>     r2 = im;

1400c1486
<     r2 = cast_int(im);
>     r2 = im;

1419c1505
<   lua_Integer im;
>   int im;

1429c1515
<     r2 = cast_int(im);  /* immediate operand */
>     r2 = im;  /* immediate operand */

1449a1536
>   luaK_dischargevars(fs, e);

1454c1541
<       /* FALLTHROUGH */
>       /* else */ /* FALLTHROUGH */

1468a1556
>   luaK_dischargevars(fs, v);

1500,1501c1588
<       lua_Integer dummy;
<       int dummy2;
>       int dummy, dummy2;

1537a1625,1627
>   luaK_dischargevars(fs, e2);
>   if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2))
>     return;  /* done by folding */

1540,1541c1630
<       lua_assert(e1->t == NO_JUMP);  /* list closed by 'luK_infix' */
<       luaK_dischargevars(fs, e2);
>       lua_assert(e1->t == NO_JUMP);  /* list closed by 'luaK_infix' */

1547,1548c1636
<       lua_assert(e1->f == NO_JUMP);  /* list closed by 'luK_infix' */
<       luaK_dischargevars(fs, e2);
>       lua_assert(e1->f == NO_JUMP);  /* list closed by 'luaK_infix' */

1559,1560c1647
<       if (!constfolding(fs, opr + LUA_OPADD, e1, e2))
<         codecommutative(fs, cast(OpCode, opr + OP_ADD), e1, e2, line);
>       codecommutative(fs, opr, e1, e2, line);

1563,1566c1650,1656
<     case OPR_SUB: case OPR_DIV:
<     case OPR_IDIV: case OPR_MOD: case OPR_POW: {
<       if (!constfolding(fs, opr + LUA_OPADD, e1, e2))
<         codearith(fs, cast(OpCode, opr + OP_ADD), e1, e2, 0, line);
>     case OPR_SUB: {
>       if (finishbinexpneg(fs, e1, e2, OP_ADDI, line, TM_SUB))
>         break; /* coded as (r1 + -I) */
>       /* ELSE *//* FALLTHROUGH */
>     }
>     case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: {
>       codearith(fs, opr, e1, e2, 0, line);

1570,1571c1660
<       if (!constfolding(fs, opr + LUA_OPADD, e1, e2))
<         codebitwise(fs, opr, e1, e2, line);
>       codebitwise(fs, opr, e1, e2, line);

1575,1581c1664,1669
<       if (!constfolding(fs, LUA_OPSHL, e1, e2)) {
<         if (isSCint(e1)) {
<           swapexps(e1, e2);
<           codebini(fs, OP_SHLI, e1, e2, 1, line);
<         }
<         else
<           codeshift(fs, OP_SHL, e1, e2, line);
>       if (isSCint(e1)) {
>         swapexps(e1, e2);
>         codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL);  /* I << r2 */
>       }
>       else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) {
>         /* coded as (r1 >> -I) */;

1582a1671,1672
>       else  /* regular case (two registers) */
>        codebinexpval(fs, OP_SHL, e1, e2, line);

1586,1587c1676,1679
<       if (!constfolding(fs, LUA_OPSHR, e1, e2))
<         codeshift(fs, OP_SHR, e1, e2, line);
>       if (isSCint(e2))
>         codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR);  /* r1 >> I */
>       else  /* regular case (two registers) */
>         codebinexpval(fs, OP_SHR, e1, e2, line);

1620a1713,1728
> void luaK_settablesize (FuncState *fs, int pc, int ra, int rc, int rb) {
>   Instruction *inst = &fs->f->code[pc];
>   int extra = 0;
>   int k = 0;
>   if (rb != 0)
>     rb = luaO_ceillog2(rb) + 1;  /* hash size */
>   if (rc > MAXARG_C) {  /* does it need the extra argument? */
>     extra = rc / (MAXARG_C + 1);
>     rc %= (MAXARG_C + 1);
>     k = 1;
>   }
>   *inst = CREATE_ABCk(OP_NEWTABLE, ra, rb, rc, k);
>   *(inst + 1) = CREATE_Ax(OP_EXTRAARG, extra);
> }
> 
> 

1629,1630d1736
<   int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;
<   int b = (tostore == LUA_MULTRET) ? 0 : tostore;

1632,1636c1738,1746
<   if (c <= MAXARG_C)
<     luaK_codeABC(fs, OP_SETLIST, base, b, c);
<   else if (c <= MAXARG_Ax) {
<     luaK_codeABC(fs, OP_SETLIST, base, b, 0);
<     codeextraarg(fs, c);
>   if (tostore == LUA_MULTRET)
>     tostore = 0;
>   if (nelems <= MAXARG_C)
>     luaK_codeABC(fs, OP_SETLIST, base, tostore, nelems);
>   else {
>     int extra = nelems / (MAXARG_C + 1);
>     nelems %= (MAXARG_C + 1);
>     luaK_codeABCk(fs, OP_SETLIST, base, tostore, nelems, 1);
>     codeextraarg(fs, extra);

1638,1639d1747
<   else
<     luaX_syntaxerror(fs->ls, "constructor too long");

1678,1681c1786,1789
<         if (fs->needclose || p->is_vararg) {
<           SETARG_C(*pc, p->is_vararg ? p->numparams + 1 : 0);
<           SETARG_k(*pc, 1);  /* signal that there is extra work */
<         }
>         if (fs->needclose)
>           SETARG_k(*pc, 1);  /* signal that it needs to close */
>         if (p->is_vararg)
>           SETARG_C(*pc, p->numparams + 1);  /* signal that it is vararg */

src/lcode.h

26a27
>   /* arithmetic operators */

28,29c29,30
<   OPR_DIV,
<   OPR_IDIV,
>   OPR_DIV, OPR_IDIV,
>   /* bitwise operators */

31a33
>   /* string operator */

32a35
>   /* comparison operators */

34a38
>   /* logical operators */

39a44,47
> /* true if operation is foldable (that is, it is arithmetic or bitwise) */
> #define foldbinop(op)	((op) <= OPR_SHR)
> 
> 

53a62
> LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);

58a68
> LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);

63d72
< LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);

87a97,98
> LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
>                                                  int ra, int rb, int rc);

src/ldblib.c

24,25c24,25
< ** The hook table at registry[&HOOKKEY] maps threads to their current
< ** hook function. (We only need the unique address of 'HOOKKEY'.)
> ** The hook table at registry[HOOKKEY] maps threads to their current
> ** hook function.

27c27
< static const int HOOKKEY = 0;
> static const char* HOOKKEY = "_HOOKKEY";

68c68
<     lua_pushnil(L);
>     luaL_pushfail(L);

83c83
<     lua_pushnil(L);
>     luaL_pushfail(L);

162c162
<       lua_pushnil(L);  /* level out of range */
>       luaL_pushfail(L);  /* level out of range */

226c226
<       lua_pushnil(L);  /* no name (nor value) */
>       luaL_pushfail(L);  /* no name (nor value) */

317c317
<   lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);
>   lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);

370,373c370,371
<   if (lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY) == LUA_TNIL) {
<     lua_createtable(L, 0, 2);  /* create a hook table */
<     lua_pushvalue(L, -1);
<     lua_rawsetp(L, LUA_REGISTRYINDEX, &HOOKKEY);  /* set it in position */
>   if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {
>     /* table just created; initialize it */

377c375
<     lua_setmetatable(L, -2);  /* setmetatable(hooktable) = hooktable */
>     lua_setmetatable(L, -2);  /* metatable(hooktable) = hooktable */

394,395c392,395
<   if (hook == NULL)  /* no hook? */
<     lua_pushnil(L);
>   if (hook == NULL) {  /* no hook? */
>     luaL_pushfail(L);
>     return 1;
>   }

399c399
<     lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);
>     lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);

439a440,450
> static int db_setcstacklimit (lua_State *L) {
>   int limit = (int)luaL_checkinteger(L, 1);
>   int res = lua_setcstacklimit(L, limit);
>   if (res == 0)
>     lua_pushboolean(L, 0);
>   else
>     lua_pushinteger(L, res);
>   return 1;
> }
> 
> 

456a468
>   {"setcstacklimit", db_setcstacklimit},

src/ldebug.c

468c468
< ** try to find last instruction before 'lastpc' that modified register 'reg'
> ** Try to find last instruction before 'lastpc' that modified register 'reg'.

473a474,475
>   if (testMMMode(GET_OPCODE(p->code[lastpc])))
>     lastpc--;  /* previous instruction was not actually executed */

623,640c625,626
<     case OP_ADDI: case OP_SUBI: case OP_MULI: case OP_MODI:
<     case OP_POWI: case OP_DIVI: case OP_IDIVI: {
<       int offset = GET_OPCODE(i) - OP_ADDI;  /* ORDER OP */
<       tm = cast(TMS, offset + TM_ADD);  /* ORDER TM */
<       break;
<     }
<     case OP_ADDK: case OP_SUBK: case OP_MULK: case OP_MODK:
<     case OP_POWK: case OP_DIVK: case OP_IDIVK:
<     case OP_BANDK: case OP_BORK: case OP_BXORK: {
<       int offset = GET_OPCODE(i) - OP_ADDK;  /* ORDER OP */
<       tm = cast(TMS, offset + TM_ADD);  /* ORDER TM */
<       break;
<     }
<     case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:
<     case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:
<     case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {
<       int offset = GET_OPCODE(i) - OP_ADD;  /* ORDER OP */
<       tm = cast(TMS, offset + TM_ADD);  /* ORDER TM */
>     case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
>       tm = cast(TMS, GETARG_C(i));

651,652c637,638
<     case OP_SHRI: case OP_SHLI:
<       *name = "shift";
>     case OP_CLOSE: case OP_RETURN:
>       *name = "close";

src/ldo.c

142c142,143
<   l_uint32 oldnCcalls = L->nCcalls - L->nci;
>   global_State *g = G(L);
>   l_uint32 oldnCcalls = g->Cstacklimit - (L->nCcalls + L->nci);

144d144
<   lua_assert(L->nCcalls >= L->nci);

152c152
<   L->nCcalls = oldnCcalls + L->nci;
>   L->nCcalls = g->Cstacklimit - oldnCcalls - L->nci;

351,353c351,353
< ** Check whether __call metafield of 'func' is a function. If so, put
< ** it in stack below original 'func' so that 'luaD_call' can call
< ** it. Raise an error if __call metafield is not a function.
> ** Check whether 'func' has a '__call' metafield. If so, put it in the
> ** stack, below original 'func', so that 'luaD_call' can call it. Raise
> ** an error if there is no '__call' metafield.

358,360c358,360
<   if (unlikely(!ttisfunction(tm)))
<     luaG_typeerror(L, s2v(func), "call");
<   for (p = L->top; p > func; p--)
>   if (unlikely(ttisnil(tm)))
>     luaG_typeerror(L, s2v(func), "call");  /* nothing to call */
>   for (p = L->top; p > func; p--)  /* open space for metamethod */

362c362
<   L->top++;  /* assume EXTRA_STACK */
>   L->top++;  /* stack space pre-allocated by the caller */

460,461c460,461
<   TValue *funcv = s2v(func);
<   switch (ttypetag(funcv)) {
>  retry:
>   switch (ttypetag(s2v(func))) {

463c463
<       f = clCvalue(funcv)->f;
>       f = clCvalue(s2v(func))->f;

466c466
<       f = fvalue(funcv);
>       f = fvalue(s2v(func));

490c490
<       Proto *p = clLvalue(funcv)->p;
>       Proto *p = clLvalue(s2v(func))->p;

507a508
>       checkstackp(L, 1, func);  /* space for metamethod */

509,510c510
<       luaD_call(L, func, nresults);  /* now it must be a function */
<       break;
>       goto retry;  /* try again with metamethod */

524c524
<   if (getCcalls(L) >= LUAI_MAXCSTACK)  /* possible stack overflow? */
>   if (getCcalls(L) <= CSTACKERR)  /* possible stack overflow? */

675c675
<     L->nCcalls = 1;
>     L->nCcalls = CSTACKTHREAD;

677,678c677,678
<     L->nCcalls = getCcalls(from) - from->nci + L->nci + CSTACKCF;
<   if (L->nCcalls >= LUAI_MAXCSTACK)
>     L->nCcalls = getCcalls(from) + from->nci - L->nci - CSTACKCF;
>   if (L->nCcalls <= CSTACKERR)

src/ldump.c

151a152
>     DumpByte(f->upvalues[i].kind, D);

src/lfunc.c

62,63c62,63
< ** Create a new upvalue with the given tag at the given level,
< ** and link it to the list of open upvalues of 'L' after entry 'prev'.
> ** Create a new upvalue at the given level, and link it to the list of
> ** open upvalues of 'L' after entry 'prev'.

65,66c65,66
< static UpVal *newupval (lua_State *L, int tag, StkId level, UpVal **prev) {
<   GCObject *o = luaC_newobj(L, tag, sizeof(UpVal));
> static UpVal *newupval (lua_State *L, int tbc, StkId level, UpVal **prev) {
>   GCObject *o = luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal));

69a70
>   uv->tbc = tbc;

84c85
< ** Find and reuse, or create if it does not exist, a regular upvalue
> ** Find and reuse, or create if it does not exist, an upvalue

92c93,94
<     if (uplevel(p) == level && !isdead(G(L), p))  /* corresponding upvalue? */
>     lua_assert(!isdead(G(L), p));
>     if (uplevel(p) == level)  /* corresponding upvalue? */

97c99
<   return newupval(L, LUA_TUPVAL, level, pp);
>   return newupval(L, 0, level, pp);

124a127,138
> ** Raise an error with message 'msg', inserting the name of the
> ** local variable at position 'level' in the stack.
> */
> static void varerror (lua_State *L, StkId level, const char *msg) {
>   int idx = cast_int(level - L->ci->func);
>   const char *vname = luaG_findlocal(L, L->ci, idx, NULL);
>   if (vname == NULL) vname = "?";
>   luaG_runerror(L, msg, vname);
> }
> 
> 
> /*

127c141
< ** there. Otherwise, a previous error already activated original
> ** there. Otherwise, a previous error already activated the original

129c143
< ** protected here. (A status = CLOSEPROTECT behaves like a previous
> ** protected here. (A status == CLOSEPROTECT behaves like a previous

136c150,151
< static int callclosemth (lua_State *L, TValue *uv, StkId level, int status) {
> static int callclosemth (lua_State *L, StkId level, int status) {
>   TValue *uv = s2v(level);  /* value being closed */

140,145c155,156
<     else if (!ttisnil(uv)) {  /* non-closable non-nil value? */
<       int idx = cast_int(level - L->ci->func);
<       const char *vname = luaG_findlocal(L, L->ci, idx, NULL);
<       if (vname == NULL) vname = "?";
<       luaG_runerror(L, "attempt to close non-closable variable '%s'", vname);
<     }
>     else if (!l_isfalse(uv))  /* non-closable non-false value? */
>       varerror(L, level, "attempt to close non-closable variable '%s'");

148,150c159,162
<     ptrdiff_t oldtop = savestack(L, level + 1);
<     /* save error message and set stack top to 'level + 1' */
<     luaD_seterrorobj(L, status, level);
>     ptrdiff_t oldtop;
>     level++;  /* space for error message */
>     oldtop = savestack(L, level + 1);  /* top will be after that */
>     luaD_seterrorobj(L, status, level);  /* set error message */

155c167,170
<       else  /* leave original error (or nil) on top */
>       else {
>         if (newstatus != LUA_OK)  /* supressed error? */
>           luaE_warnerror(L, "__close metamethod");
>         /* leave original error (or nil) on top */

156a172
>       }

169,171c185
<   StkId level = cast(StkId, ud);
<   lua_assert(L->openupval == NULL || uplevel(L->openupval) < level);
<   newupval(L, LUA_TUPVALTBC, level, &L->openupval);
>   newupval(L, 1, cast(StkId, ud), &L->openupval);

181,185c195,207
<   int status = luaD_rawrunprotected(L, trynewtbcupval, level);
<   if (unlikely(status != LUA_OK)) {  /* memory error creating upvalue? */
<     lua_assert(status == LUA_ERRMEM);
<     luaD_seterrorobj(L, LUA_ERRMEM, level + 1);  /* save error message */
<     if (prepclosingmethod(L, s2v(level), s2v(level + 1)))
>   TValue *obj = s2v(level);
>   lua_assert(L->openupval == NULL || uplevel(L->openupval) < level);
>   if (!l_isfalse(obj)) {  /* false doesn't need to be closed */
>     int status;
>     const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE);
>     if (ttisnil(tm))  /* no metamethod? */
>       varerror(L, level, "variable '%s' got a non-closable value");
>     status = luaD_rawrunprotected(L, trynewtbcupval, level);
>     if (unlikely(status != LUA_OK)) {  /* memory error creating upvalue? */
>       lua_assert(status == LUA_ERRMEM);
>       luaD_seterrorobj(L, LUA_ERRMEM, level + 1);  /* save error message */
>       /* next call must succeed, as object is closable */
>       prepclosingmethod(L, s2v(level), s2v(level + 1));

187c209,210
<     luaD_throw(L, LUA_ERRMEM);  /* throw memory error */
>       luaD_throw(L, LUA_ERRMEM);  /* throw memory error */
>     }

203d225
<     StkId upl = uplevel(uv);

204a227,233
>     lua_assert(uplevel(uv) < L->top);
>     if (uv->tbc && status != NOCLOSINGMETH) {
>       /* must run closing method, which may change the stack */
>       ptrdiff_t levelrel = savestack(L, level);
>       status = callclosemth(L, uplevel(uv), status);
>       level = restorestack(L, levelrel);
>     }

211,216d239
<     if (uv->tt == LUA_TUPVALTBC && status != NOCLOSINGMETH) {
<       /* must run closing method */
<       ptrdiff_t levelrel = savestack(L, level);
<       status = callclosemth(L, uv->v, upl, status);  /* may change the stack */
<       level = restorestack(L, levelrel);
<     }

src/lgc.c

276,277c276
<     case LUA_TUPVAL:
<     case LUA_TUPVALTBC: {
>     case LUA_TUPVAL: {

417c416
< static int traverseephemeron (global_State *g, Table *h) {
> static int traverseephemeron (global_State *g, Table *h, int inv) {

421d419
<   Node *n, *limit = gnodelast(h);

423a422
>   unsigned int nsize = sizenode(h);

431,432c430,433
<   /* traverse hash part */
<   for (n = gnode(h, 0); n < limit; n++) {
>   /* traverse hash part; if 'inv', traverse descending
>      (see 'convergeephemerons') */
>   for (i = 0; i < nsize; i++) {
>     Node *n = inv ? gnode(h, nsize - 1 - i) : gnode(h, i);

494c495
<       traverseephemeron(g, h);
>       traverseephemeron(g, h, 0);

573,576c574,575
<   for (uv = th->openupval; uv != NULL; uv = uv->u.open.next) {
<     if (uv->tt == LUA_TUPVALTBC)  /* to be closed? */
<       markobject(g, uv);  /* cannot be collected */
<   }
>   for (uv = th->openupval; uv != NULL; uv = uv->u.open.next)
>     markobject(g, uv);  /* open upvalues cannot be collected */

625a625,631
> /*
> ** Traverse all ephemeron tables propagating marks from keys to values.
> ** Repeat until it converges, that is, nothing new is marked. 'dir'
> ** inverts the direction of the traversals, trying to speed up
> ** convergence on chains in the same table.
> **
> */

627a634
>   int dir = 0;

633,635c640,642
<     while ((w = next) != NULL) {
<       next = gco2t(w)->gclist;
<       if (traverseephemeron(g, gco2t(w))) {  /* traverse marked some value? */
>     while ((w = next) != NULL) {  /* for each ephemeron table */
>       next = gco2t(w)->gclist;  /* list is rebuilt during loop */
>       if (traverseephemeron(g, gco2t(w), dir)) {  /* marked some value? */

640c647,648
<   } while (changed);
>     dir = !dir;  /* invert direction next time */
>   } while (changed);  /* repeat until no more changes */

709d716
<     case LUA_TUPVALTBC:

797,798c804,805
<     l_mem olddebt = g->GCdebt;
<     if (g->strt.nuse < g->strt.size / 4)  /* string table too big? */
>     if (g->strt.nuse < g->strt.size / 4) {  /* string table too big? */
>       l_mem olddebt = g->GCdebt;

800c807,808
<     g->GCestimate += g->GCdebt - olddebt;  /* correct estimate */
>       g->GCestimate += g->GCdebt - olddebt;  /* correct estimate */
>     }

841,843c849,850
<     setobj2s(L, L->top, tm);  /* push finalizer... */
<     setobj2s(L, L->top + 1, &v);  /* ... and its argument */
<     L->top += 2;  /* and (next line) call the finalizer */
>     setobj2s(L, L->top++, tm);  /* push finalizer... */
>     setobj2s(L, L->top++, &v);  /* ... and its argument */

849,855c856,858
<     if (status != LUA_OK) {  /* error while running __gc? */
<       const char *msg = (ttisstring(s2v(L->top - 1)))
<                         ? svalue(s2v(L->top - 1))
<                         : "error object is not a string";
<       luaE_warning(L, "error in __gc metamethod (", 1);
<       luaE_warning(L, msg, 1);
<       luaE_warning(L, ")", 0);
>     if (unlikely(status != LUA_OK)) {  /* error while running __gc? */
>       luaE_warnerror(L, "__gc metamethod");
>       L->top--;  /* pops error object */

1253c1256
< ** When the program is building a big struture, it allocates lots of
> ** When the program is building a big structure, it allocates lots of

src/liolib.c

156c156
<     lua_pushnil(L);  /* not a file */
>     luaL_pushfail(L);  /* not a file */

341c341
< ** Auxiliar function to create the iteration function for 'lines'.
> ** Auxiliary function to create the iteration function for 'lines'.

596c596
<     lua_pushnil(L);  /* push nil instead */
>     luaL_pushfail(L);  /* push nil instead */

629c629
<   else {  /* first result is nil: EOF or error */
>   else {  /* first result is false: EOF or error */

745,748c745
< static const luaL_Reg flib[] = {
<   {"close", f_close},
<   {"flush", f_flush},
<   {"lines", f_lines},
> static const luaL_Reg meth[] = {

749a747,749
>   {"write", f_write},
>   {"lines", f_lines},
>   {"flush", f_flush},

750a751
>   {"close", f_close},

752c753,761
<   {"write", f_write},
>   {NULL, NULL}
> };
> 
> 
> /*
> ** metamethods for file handles
> */
> static const luaL_Reg metameth[] = {
>   {"__index", NULL},  /* place holder */

761,765c770,775
<   luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */
<   lua_pushvalue(L, -1);  /* push metatable */
<   lua_setfield(L, -2, "__index");  /* metatable.__index = metatable */
<   luaL_setfuncs(L, flib, 0);  /* add file methods to new metatable */
<   lua_pop(L, 1);  /* pop new metatable */
>   luaL_newmetatable(L, LUA_FILEHANDLE);  /* metatable for file handles */
>   luaL_setfuncs(L, metameth, 0);  /* add metamethods to new metatable */
>   luaL_newlibtable(L, meth);  /* create method table */
>   luaL_setfuncs(L, meth, 0);  /* add file methods to method table */
>   lua_setfield(L, -2, "__index");  /* metatable.__index = method table */
>   lua_pop(L, 1);  /* pop metatable */

775c785
<   lua_pushnil(L);
>   luaL_pushfail(L);

src/ljumptab.h

48,53d47
< &&L_OP_SUBI,
< &&L_OP_MULI,
< &&L_OP_MODI,
< &&L_OP_POWI,
< &&L_OP_DIVI,
< &&L_OP_IDIVI,

77a72,74
> &&L_OP_MMBIN,
> &&L_OP_MMBINI,
> &&L_OP_MMBINK,

src/llex.c

214,215c214,223
< ** this function is quite liberal in what it accepts, as 'luaO_str2num'
< ** will reject ill-formed numerals.
> ** This function is quite liberal in what it accepts, as 'luaO_str2num'
> ** will reject ill-formed numerals. Roughly, it accepts the following
> ** pattern:
> **
> **   %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))*
> **
> ** The only tricky part is to accept [+-] only after a valid exponent
> ** mark, to avoid reading '3-4' or '0xe+1' as a single number.
> **
> ** The caller might have already read an initial dot.

226c234
<     if (check_next2(ls, expo))  /* exponent part? */
>     if (check_next2(ls, expo))  /* exponent mark? */

228,230c236
<     if (lisxdigit(ls->current))
<       save_and_next(ls);
<     else if (ls->current == '.')
>     else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */

234c240
<   if (lislalnum(ls->current))  /* is numeral touching an alpha num? */
>   if (lislalpha(ls->current))  /* is numeral touching a letter? */

src/lmathlib.c

80c80
<     lua_pushnil(L);  /* value is not convertible to integer */
>     luaL_pushfail(L);  /* value is not convertible to integer */

238c238
<     lua_pushnil(L);
>     luaL_pushfail(L);

589c589,590
< static void setseed (Rand64 *state, lua_Unsigned n1, lua_Unsigned n2) {
> static void setseed (lua_State *L, Rand64 *state,
>                      lua_Unsigned n1, lua_Unsigned n2) {

596a598,599
>   lua_pushinteger(L, n1);
>   lua_pushinteger(L, n2);

608c611
<   setseed(state->s, seed1, seed2);
>   setseed(L, state->s, seed1, seed2);

614c617
<   if (lua_isnone(L, 1))
>   if (lua_isnone(L, 1)) {

615a619
>   }

619c623
<     setseed(state->s, n1, n2);
>     setseed(L, state->s, n1, n2);

621c625
<   return 0;
>   return 2;  /* return seeds */

637a642
>   lua_pop(L, 2);  /* remove pushed seeds */

src/lmem.c

26,27c26,36
< #define hardtest(L,os,s)  /* force a GC whenever possible */ \
<   if ((s) > (os) && (G(L))->gcrunning) luaC_fullgc(L, 1);
> /*
> ** First allocation will fail whenever not building initial state
> ** and not shrinking a block. (This fail will trigger 'tryagain' and
> ** a full GC cycle at every alocation.)
> */
> static void *firsttry (global_State *g, void *block, size_t os, size_t ns) {
>   if (ttisnil(&g->nilvalue) && ns > os)
>     return NULL;  /* fail */
>   else  /* normal allocation */
>     return (*g->frealloc)(g->ud, block, os, ns);
> }

29c38
< #define hardtest(L,os,s)  ((void)0)
> #define firsttry(g,block,os,ns)    ((*g->frealloc)(g->ud, block, os, ns))

33a43,44
> 
> 

36c47
< ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
> ** void *frealloc (void *ud, void *ptr, size_t osize, size_t nsize);

39,40c50,52
< ** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no
< ** matter 'x').
> ** - frealloc(ud, p, x, 0) frees the block 'p' and returns NULL.
> ** Particularly, frealloc(ud, NULL, 0, 0) does nothing,
> ** which is equivalent to free(NULL) in ISO C.

42,45c54,55
< ** * frealloc(ud, p, x, 0) frees the block 'p'
< ** (in this specific case, frealloc must return NULL);
< ** particularly, frealloc(ud, NULL, 0, 0) does nothing
< ** (which is equivalent to free(NULL) in ISO C)
> ** - frealloc(ud, NULL, x, s) creates a new block of size 's'
> ** (no matter 'x'). Returns NULL if it cannot create the new block.

47,48c57,59
< ** frealloc returns NULL if it cannot create or reallocate the area
< ** (any reallocation to an equal or smaller size cannot fail!)
> ** - otherwise, frealloc(ud, b, x, y) reallocates the block 'b' from
> ** size 'x' to size 'y'. Returns NULL if it cannot reallocate the
> ** block to the new size.

52a64,75
> 
> /*
> ** {==================================================================
> ** Functions to allocate/deallocate arrays for the Parser
> ** ===================================================================
> */
> 
> /*
> ** Minimum size for arrays during parsing, to avoid overhead of
> ** reallocating to size 1, then 2, and then 4. All these arrays
> ** will be reallocated to exact sizes or erased when parsing ends.
> */

74,77c97,98
<   newblock = luaM_realloc_(L, block, cast_sizet(*psize) * size_elems,
<                                      cast_sizet(size) * size_elems);
<   if (unlikely(newblock == NULL))
<     luaM_error(L);
>   newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems,
>                                          cast_sizet(size) * size_elems);

82a104,109
> /*
> ** In prototypes, the size of the array is also its number of
> ** elements (to save memory). So, if it cannot shrink an array
> ** to its number of elements, the only option is to raise an
> ** error.
> */

85d111
<   global_State *g = G(L);

90,97c116,118
<   newblock = (*g->frealloc)(g->ud, block, oldsize, newsize);
<   if (unlikely(newblock == NULL && final_n > 0))  /* allocation failed? */
<     luaM_error(L);
<   else {
<     g->GCdebt += newsize - oldsize;
<     *size = final_n;
<     return newblock;
<   }
>   newblock = luaM_saferealloc_(L, block, oldsize, newsize);
>   *size = final_n;
>   return newblock;

99a121,122
> /* }================================================================== */
> 

135c158,160
< ** generic allocation routine.
> ** Generic allocation routine.
> ** If allocation fails while shrinking a block, do not try again; the
> ** GC shrinks some blocks and it is not reentrant.

141,142c166
<   hardtest(L, osize, nsize);
<   newblock = (*g->frealloc)(g->ud, block, osize, nsize);
>   newblock = firsttry(g, block, osize, nsize);

147c171
<       return NULL;
>       return NULL;  /* do not update 'GCdebt' */

165d188
<   hardtest(L, 0, size);

170c193
<     void *newblock = (*g->frealloc)(g->ud, NULL, tag, size);
>     void *newblock = firsttry(g, NULL, tag, size);

src/loadlib.c

59c59
< ** unique key for table in the registry that keeps handles
> ** key for table in the registry that keeps handles

62c62
< static const int CLIBS = 0;
> static const char *CLIBS = "_CLIBS";

311c311
<     if (dftmark < path + len - 2) {  /* is there a sufix after ';;'? */
>     if (dftmark < path + len - 2) {  /* is there a suffix after ';;'? */

330c330
<   lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);
>   lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);

343c343
<   lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);
>   lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);

411c411
<     lua_pushnil(L);
>     luaL_pushfail(L);

414c414
<     return 3;  /* return nil, error message, and where */
>     return 3;  /* return fail, error message, and where */

508c508
<     lua_pushnil(L);
>     luaL_pushfail(L);

510c510
<     return 2;  /* return nil + error message */
>     return 2;  /* return fail + error message */

719c719
<   lua_newtable(L);  /* create CLIBS table */
>   luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);  /* create CLIBS table */

724d723
<   lua_rawsetp(L, LUA_REGISTRYINDEX, &CLIBS);  /* set CLIBS table in registry */

src/lobject.c

33,58d32
< ** converts an integer to a "floating point byte", represented as
< ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
< ** eeeee != 0 and (xxx) otherwise.
< */
< int luaO_int2fb (unsigned int x) {
<   int e = 0;  /* exponent */
<   if (x < 8) return x;
<   while (x >= (8 << 4)) {  /* coarse steps */
<     x = (x + 0xf) >> 4;  /* x = ceil(x / 16) */
<     e += 4;
<   }
<   while (x >= (8 << 1)) {  /* fine steps */
<     x = (x + 1) >> 1;  /* x = ceil(x / 2) */
<     e++;
<   }
<   return ((e+1) << 3) | (cast_int(x) - 8);
< }
< 
< 
< /* converts back */
< int luaO_fb2int (int x) {
<   return (x < 8) ? x : ((x & 7) + 8) << ((x >> 3) - 1);
< }
< 
< 
< /*

src/lobject.h

92,93c92,93
< 	lua_longassert(!iscollectable(obj) || \
< 		(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))
> 	((void)L, lua_longassert(!iscollectable(obj) || \
> 		(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj))))))

103c103
< 	  (void)L; checkliveness(L,io1); lua_assert(!isreallyempty(io1)); }
> 	  checkliveness(L,io1); lua_assert(!isreallyempty(io1)); }

462a463
>   lu_byte kind;  /* kind of corresponding variable */

569a571
>   lu_byte tbc;  /* true if it represents a to-be-closed variable */

581,583d582
< /* variant for "To Be Closed" upvalues */
< #define LUA_TUPVALTBC	(LUA_TUPVAL | (1 << 4))
< 

653c652
< 	  (void)L; checkliveness(L,io_); }
> 	  checkliveness(L,io_); }

660c659
< 	  (void)L; checkliveness(L,io_); }
> 	  checkliveness(L,io_); }

736,737d734
< LUAI_FUNC int luaO_int2fb (unsigned int x);
< LUAI_FUNC int luaO_fb2int (int x);

src/lopcodes.c

21,105c21,102
< /*       OT IT T  A  mode		   opcode  */
<   opmode(0, 0, 0, 1, iABC)		/* OP_MOVE */
<  ,opmode(0, 0, 0, 1, iAsBx)		/* OP_LOADI */
<  ,opmode(0, 0, 0, 1, iAsBx)		/* OP_LOADF */
<  ,opmode(0, 0, 0, 1, iABx)		/* OP_LOADK */
<  ,opmode(0, 0, 0, 1, iABx)		/* OP_LOADKX */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_LOADBOOL */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_LOADNIL */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_GETUPVAL */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_SETUPVAL */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_GETTABUP */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_GETTABLE */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_GETI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_GETFIELD */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_SETTABUP */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_SETTABLE */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_SETI */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_SETFIELD */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_NEWTABLE */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_SELF */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_ADDI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_SUBI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_MULI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_MODI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_POWI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_DIVI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_IDIVI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_ADDK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_SUBK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_MULK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_MODK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_POWK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_DIVK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_IDIVK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_BANDK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_BORK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_BXORK */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_SHRI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_SHLI */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_ADD */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_SUB */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_MUL */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_MOD */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_POW */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_DIV */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_IDIV */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_BAND */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_BOR */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_BXOR */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_SHL */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_SHR */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_UNM */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_BNOT */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_NOT */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_LEN */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_CONCAT */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_CLOSE */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_TBC */
<  ,opmode(0, 0, 0, 0, isJ)		/* OP_JMP */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_EQ */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_LT */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_LE */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_EQK */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_EQI */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_LTI */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_LEI */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_GTI */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_GEI */
<  ,opmode(0, 0, 1, 0, iABC)		/* OP_TEST */
<  ,opmode(0, 0, 1, 1, iABC)		/* OP_TESTSET */
<  ,opmode(1, 1, 0, 1, iABC)		/* OP_CALL */
<  ,opmode(1, 1, 0, 1, iABC)		/* OP_TAILCALL */
<  ,opmode(0, 1, 0, 0, iABC)		/* OP_RETURN */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_RETURN0 */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_RETURN1 */
<  ,opmode(0, 0, 0, 1, iABx)		/* OP_FORLOOP */
<  ,opmode(0, 0, 0, 1, iABx)		/* OP_FORPREP */
<  ,opmode(0, 0, 0, 0, iABx)		/* OP_TFORPREP */
<  ,opmode(0, 0, 0, 0, iABC)		/* OP_TFORCALL */
<  ,opmode(0, 0, 0, 1, iABx)		/* OP_TFORLOOP */
<  ,opmode(0, 1, 0, 0, iABC)		/* OP_SETLIST */
<  ,opmode(0, 0, 0, 1, iABx)		/* OP_CLOSURE */
<  ,opmode(1, 0, 0, 1, iABC)		/* OP_VARARG */
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_VARARGPREP */
<  ,opmode(0, 0, 0, 0, iAx)		/* OP_EXTRAARG */
> /*       MM OT IT T  A  mode		   opcode  */
>   opmode(0, 0, 0, 0, 1, iABC)		/* OP_MOVE */
>  ,opmode(0, 0, 0, 0, 1, iAsBx)		/* OP_LOADI */
>  ,opmode(0, 0, 0, 0, 1, iAsBx)		/* OP_LOADF */
>  ,opmode(0, 0, 0, 0, 1, iABx)		/* OP_LOADK */
>  ,opmode(0, 0, 0, 0, 1, iABx)		/* OP_LOADKX */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_LOADBOOL */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_LOADNIL */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_GETUPVAL */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_SETUPVAL */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_GETTABUP */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_GETTABLE */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_GETI */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_GETFIELD */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_SETTABUP */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_SETTABLE */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_SETI */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_SETFIELD */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_NEWTABLE */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_SELF */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_ADDI */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_ADDK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_SUBK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_MULK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_MODK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_POWK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_DIVK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_IDIVK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_BANDK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_BORK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_BXORK */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_SHRI */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_SHLI */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_ADD */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_SUB */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_MUL */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_MOD */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_POW */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_DIV */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_IDIV */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_BAND */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_BOR */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_BXOR */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_SHL */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_SHR */
>  ,opmode(1, 0, 0, 0, 0, iABC)		/* OP_MMBIN */
>  ,opmode(1, 0, 0, 0, 0, iABC)		/* OP_MMBINI*/
>  ,opmode(1, 0, 0, 0, 0, iABC)		/* OP_MMBINK*/
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_UNM */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_BNOT */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_NOT */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_LEN */
>  ,opmode(0, 0, 0, 0, 1, iABC)		/* OP_CONCAT */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_CLOSE */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_TBC */
>  ,opmode(0, 0, 0, 0, 0, isJ)		/* OP_JMP */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_EQ */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_LT */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_LE */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_EQK */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_EQI */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_LTI */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_LEI */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_GTI */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_GEI */
>  ,opmode(0, 0, 0, 1, 0, iABC)		/* OP_TEST */
>  ,opmode(0, 0, 0, 1, 1, iABC)		/* OP_TESTSET */
>  ,opmode(0, 1, 1, 0, 1, iABC)		/* OP_CALL */
>  ,opmode(0, 1, 1, 0, 1, iABC)		/* OP_TAILCALL */
>  ,opmode(0, 0, 1, 0, 0, iABC)		/* OP_RETURN */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_RETURN0 */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_RETURN1 */
>  ,opmode(0, 0, 0, 0, 1, iABx)		/* OP_FORLOOP */
>  ,opmode(0, 0, 0, 0, 1, iABx)		/* OP_FORPREP */
>  ,opmode(0, 0, 0, 0, 0, iABx)		/* OP_TFORPREP */
>  ,opmode(0, 0, 0, 0, 0, iABC)		/* OP_TFORCALL */
>  ,opmode(0, 0, 0, 0, 1, iABx)		/* OP_TFORLOOP */
>  ,opmode(0, 0, 1, 0, 0, iABC)		/* OP_SETLIST */
>  ,opmode(0, 0, 0, 0, 1, iABx)		/* OP_CLOSURE */
>  ,opmode(0, 1, 0, 0, 1, iABC)		/* OP_VARARG */
>  ,opmode(0, 0, 1, 0, 1, iABC)		/* OP_VARARGPREP */
>  ,opmode(0, 0, 0, 0, 0, iAx)		/* OP_EXTRAARG */

src/lopcodes.h

99a100,102
> #define int2sC(i)	((i) + OFFSET_sC)
> #define sC2int(i)	((i) - OFFSET_sC)
> 

126c129
< #define GETARG_sB(i)	(GETARG_B(i) - OFFSET_sC)
> #define GETARG_sB(i)	sC2int(GETARG_B(i))

130c133
< #define GETARG_sC(i)	(GETARG_C(i) - OFFSET_sC)
> #define GETARG_sC(i)	sC2int(GETARG_C(i))

217c220
< OP_NEWTABLE,/*	A B C	R(A) := {} (size = B,C)				*/
> OP_NEWTABLE,/*	A B C	R(A) := {}					*/

221,227c224
< OP_ADDI,/*	A B sC	R(A) := R(B) + C				*/
< OP_SUBI,/*	A B sC	R(A) := R(B) - C				*/
< OP_MULI,/*	A B sC	R(A) := R(B) * C				*/
< OP_MODI,/*	A B sC	R(A) := R(B) % C				*/
< OP_POWI,/*	A B sC	R(A) := R(B) ^ C				*/
< OP_DIVI,/*	A B sC	R(A) := R(B) / C				*/
< OP_IDIVI,/*	A B sC	R(A) := R(B) // C				*/
> OP_ADDI,/*	A B sC	R(A) := R(B) + sC				*/

241,242c238,239
< OP_SHRI,/*	A B sC	R(A) := R(B) >> C				*/
< OP_SHLI,/*	A B sC	R(A) := C << R(B)				*/
> OP_SHRI,/*	A B sC	R(A) := R(B) >> sC				*/
> OP_SHLI,/*	A B sC	R(A) := sC << R(B)				*/

257a255,258
> OP_MMBIN,/*	A B C	call C metamethod over R(A) and R(B)		*/
> OP_MMBINI,/*	A sB C	call C metamethod over R(A) and sB		*/
> OP_MMBINK,/*	A B C	call C metamethod over R(A) and K(B)		*/
> 

289,291c290,292
< OP_FORLOOP,/*	A Bx	R(A)+=R(A+2);
< 			if R(A) <?= R(A+1) then { pc-=Bx; R(A+3)=R(A) }	*/
< OP_FORPREP,/*	A Bx	R(A)-=R(A+2); pc+=Bx				*/
> OP_FORLOOP,/*	A Bx	update counters; if loop continues then pc-=Bx; */
> OP_FORPREP,/*	A Bx	<check values and prepare counters>;
>                         if not to run then pc+=Bx+1;			*/

324,325c325,326
<   (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if (C == 0) then
<   next 'instruction' is EXTRAARG(real C).
>   (*) In OP_LOADKX and OP_NEWTABLE, the next instruction is always
>   EXTRAARG.

327c328,334
<   (*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.
>   (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if k, then
>   real C = EXTRAARG _ C (the bits of EXTRAARG concatenated with the
>   bits of C).
> 
>   (*) In OP_NEWTABLE, B is log2 of the hash size (which is always a
>   power of 2) plus 1, or zero for size zero. If not k, the array size
>   is C. Otherwise, the array size is EXTRAARG _ C.

335,338c342,344
<   function either builds upvalues, which may need to be closed, or is
<   vararg, which must be corrected before returning. When 'k' is true,
<   C > 0 means the function is vararg and (C - 1) is its number of
<   fixed parameters.
>   function builds upvalues, which may need to be closed. C > 0 means
>   the function is vararg, so that its 'func' must be corrected before
>   returning; in this case, (C - 1) is its number of fixed parameters.

352a359
> ** bit 7: instruction is an MM instruction (call a metamethod)

361a369
> #define testMMMode(m)	(luaP_opmodes[m] & (1 << 7))

371c379,380
< #define opmode(ot,it,t,a,m) (((ot)<<6) | ((it)<<5) | ((t)<<4) | ((a)<<3) | (m))
> #define opmode(mm,ot,it,t,a,m)  \
>     (((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m))

377d385
< 

src/lopnames.h

33,38d32
<   "SUBI",
<   "MULI",
<   "MODI",
<   "POWI",
<   "DIVI",
<   "IDIVI",

62a57,59
>   "MMBIN",
>   "MMBINI",
>   "MMBINK",

src/loslib.c

61d60
< #if !defined(l_time_t)		/* { */

64a64,65
> #if !defined(LUA_NUMTIME)	/* { */
> 

66a68
> #define l_gettime(L,arg)	luaL_checkinteger(L, arg)

68,72c70,74
< static time_t l_checktime (lua_State *L, int arg) {
<   lua_Integer t = luaL_checkinteger(L, arg);
<   luaL_argcheck(L, (time_t)t == t, arg, "time out-of-bounds");
<   return (time_t)t;
< }
> #else				/* }{ */
> 
> #define l_timet			lua_Number
> #define l_pushtime(L,t)		lua_pushnumber(L,(lua_Number)(t))
> #define l_gettime(L,arg)	luaL_checknumber(L, arg)

196,197c198,212
< static void setfield (lua_State *L, const char *key, int value) {
<   lua_pushinteger(L, value);
> /*
> ** About the overflow check: an overflow cannot occurr when time
> ** is represented by a lua_Integer, because either lua_Integer is
> ** large enough to represent all int fields or it is not large enough
> ** to represent a time that cause a field to overflow.  However, if
> ** times are represented as doubles and lua_Integer is int, then the
> ** time 0x1.e1853b0d184f6p+55 would cause an overflow when adding 1900
> ** to compute the year.
> */
> static void setfield (lua_State *L, const char *key, int value, int delta) {
>   #if (defined(LUA_NUMTIME) && LUA_MAXINTEGER <= INT_MAX)
>     if (value > LUA_MAXINTEGER - delta)
>       luaL_error(L, "field '%s' is out-of-bound", key);
>   #endif
>   lua_pushinteger(L, (lua_Integer)value + delta);

200a216
> 

213,220c229,236
<   setfield(L, "sec", stm->tm_sec);
<   setfield(L, "min", stm->tm_min);
<   setfield(L, "hour", stm->tm_hour);
<   setfield(L, "day", stm->tm_mday);
<   setfield(L, "month", stm->tm_mon + 1);
<   setfield(L, "year", stm->tm_year + 1900);
<   setfield(L, "wday", stm->tm_wday + 1);
<   setfield(L, "yday", stm->tm_yday + 1);
>   setfield(L, "year", stm->tm_year, 1900);
>   setfield(L, "month", stm->tm_mon, 1);
>   setfield(L, "day", stm->tm_mday, 0);
>   setfield(L, "hour", stm->tm_hour, 0);
>   setfield(L, "min", stm->tm_min, 0);
>   setfield(L, "sec", stm->tm_sec, 0);
>   setfield(L, "yday", stm->tm_yday, 1);
>   setfield(L, "wday", stm->tm_wday, 1);

233,237d248
< /* maximum value for date fields (to avoid arithmetic overflows with 'int') */
< #if !defined(L_MAXDATEFIELD)
< #define L_MAXDATEFIELD	(INT_MAX / 2)
< #endif
< 

250c261,263
<     if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD))
>     /* unsigned avoids overflow when lua_Integer has 32 bits */
>     if (!(res >= 0 ? (lua_Unsigned)res <= (lua_Unsigned)INT_MAX + delta
>                    : (lua_Integer)INT_MIN + delta <= res))

277a291,297
> static time_t l_checktime (lua_State *L, int arg) {
>   l_timet t = l_gettime(L, arg);
>   luaL_argcheck(L, (time_t)t == t, arg, "time out-of-bounds");
>   return (time_t)t;
> }
> 
> 

296c316
<                  "time result cannot be represented in this installation");
>                  "date result cannot be represented in this installation");

332,336d351
<     ts.tm_sec = getfield(L, "sec", 0, 0);
<     ts.tm_min = getfield(L, "min", 0, 0);
<     ts.tm_hour = getfield(L, "hour", 12, 0);
<     ts.tm_mday = getfield(L, "day", -1, 0);
<     ts.tm_mon = getfield(L, "month", -1, 1);

337a353,357
>     ts.tm_mon = getfield(L, "month", -1, 1);
>     ts.tm_mday = getfield(L, "day", -1, 0);
>     ts.tm_hour = getfield(L, "hour", 12, 0);
>     ts.tm_min = getfield(L, "min", 0, 0);
>     ts.tm_sec = getfield(L, "sec", 0, 0);

src/lparser.c

159c159
< static void init_var (expdesc *e, expkind k, int i) {
> static void codestring (expdesc *e, TString *s) {

161,167c161,162
<   e->k = k;
<   e->u.var.idx = i;
< }
< 
< 
< static void codestring (LexState *ls, expdesc *e, TString *s) {
<   init_exp(e, VK, luaK_stringK(ls->fs, s));
>   e->k = VKSTR;
>   e->u.strval = s;

172c167
<   codestring(ls, e, str_checkname(ls));
>   codestring(e, str_checkname(ls));

180,181c175
< static int registerlocalvar (LexState *ls, TString *varname) {
<   FuncState *fs = ls->fs;
> static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) {

184c178
<   luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
>   luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars,

188c182,183
<   f->locvars[fs->nlocvars].varname = varname;
>   f->locvars[fs->ndebugvars].varname = varname;
>   f->locvars[fs->ndebugvars].startpc = fs->pc;

190c185
<   return fs->nlocvars++;
>   return fs->ndebugvars++;

195c190,191
< ** Create a new local variable with the given 'name'.
> ** Create a new local variable with the given 'name'. Return its index
> ** in the function.

197c193,194
< static Vardesc *new_localvar (LexState *ls, TString *name) {
> static int new_localvar (LexState *ls, TString *name) {
>   lua_State *L = ls->L;

201d197
<   int reg = registerlocalvar(ls, name);

203,205c199,201
<                   MAXVARS, "local variables");
<   luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
<                   dyd->actvar.size, Vardesc, MAX_INT, "local variables");
>                  MAXVARS, "local variables");
>   luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1,
>                   dyd->actvar.size, Vardesc, USHRT_MAX, "local variables");

207,210c203,205
<   var->idx = cast(short, reg);
<   var->name = name;
<   var->ro = 0;
<   return var;
>   var->vd.kind = VDKREG;  /* default */
>   var->vd.name = name;
>   return dyd->actvar.n - 1 - fs->firstlocal;

214c209,210
<     new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));
>     new_localvar(ls,  \
>       luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));

225a222
> 

227c224,225
< ** Get the debug-information entry for current variable 'i'.
> ** Convert 'nvar' (number of active variables at some point) to
> ** number of variables in the stack at that point.

229,232c227,235
< static LocVar *getlocvar (FuncState *fs, int i) {
<   int idx = getlocalvardesc(fs, i)->idx;
<   lua_assert(idx < fs->nlocvars);
<   return &fs->f->locvars[idx];
> static int stacklevel (FuncState *fs, int nvar) {
>   while (nvar > 0) {
>     Vardesc *vd = getlocalvardesc(fs, nvar - 1);
>     if (vd->vd.kind != RDKCTC)  /* is in the stack? */
>       return vd->vd.sidx + 1;
>     else
>       nvar--;  /* try previous variable */
>   }
>   return 0;  /* no variables */

237,238c240
< ** Return the "variable description" (Vardesc) of a given
< ** variable or upvalue
> ** Return the number of variables in the stack for function 'fs'

240,258c242,257
< static Vardesc *getvardesc (FuncState *fs, expdesc *e) {
<   if (e->k == VLOCAL)
<     return getlocalvardesc(fs, e->u.var.idx);
<   else if (e->k != VUPVAL)
<     return NULL;  /* not a local variable */
<   else {  /* upvalue: must go up all levels up to the original local */
<     int idx = e->u.var.idx;
<     for (;;) {
<       Upvaldesc *up = &fs->f->upvalues[idx];
<       fs = fs->prev;  /* must look at the previous level */
<       idx = up->idx;  /* at this index */
<       if (fs == NULL) {  /* no more levels? (can happen only with _ENV) */
<         lua_assert(strcmp(getstr(up->name), LUA_ENV) == 0);
<         return NULL;
<       }
<       else if (up->instack)  /* got to the original level? */
<         return getlocalvardesc(fs, idx);
<       /* else repeat for previous level */
<     }
> int luaY_nvarstack (FuncState *fs) {
>   return stacklevel(fs, fs->nactvar);
> }
> 
> 
> /*
> ** Get the debug-information entry for current variable 'i'.
> */
> static LocVar *localdebuginfo (FuncState *fs, int i) {
>   Vardesc *vd = getlocalvardesc(fs, i);
>   if (vd->vd.kind == RDKCTC)
>     return NULL;  /* no debug info. for constants */
>   else {
>     int idx = vd->vd.pidx;
>     lua_assert(idx < fs->ndebugvars);
>     return &fs->f->locvars[idx];

262a262,269
> static void init_var (FuncState *fs, expdesc *e, int i) {
>   e->f = e->t = NO_JUMP;
>   e->k = VLOCAL;
>   e->u.var.vidx = i;
>   e->u.var.sidx = getlocalvardesc(fs, i)->vd.sidx;
> }
> 
> 

264,265c271,293
<   Vardesc *vardesc = getvardesc(ls->fs, e);
<   if (vardesc && vardesc->ro) {  /* is variable local and const? */
>   FuncState *fs = ls->fs;
>   TString *varname = NULL;  /* to be set if variable is const */
>   switch (e->k) {
>     case VCONST: {
>       varname = ls->dyd->actvar.arr[e->u.info].vd.name;
>       break;
>     }
>     case VLOCAL: {
>       Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx);
>       if (vardesc->vd.kind != VDKREG)  /* not a regular variable? */
>         varname = vardesc->vd.name;
>       break;
>     }
>     case VUPVAL: {
>       Upvaldesc *up = &fs->f->upvalues[e->u.info];
>       if (up->kind != VDKREG)
>         varname = up->name;
>       break;
>     }
>     default:
>       return;  /* other cases cannot be read-only */
>   }
>   if (varname) {

267c295
<        "attempt to assign to const variable '%s'", getstr(vardesc->name));
>        "attempt to assign to const variable '%s'", getstr(varname));

275d302
< ** (debug info.)

279,281c306,312
<   fs->nactvar = cast_byte(fs->nactvar + nvars);
<   for (; nvars; nvars--) {
<     getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;
>   int stklevel = luaY_nvarstack(fs);
>   int i;
>   for (i = 0; i < nvars; i++) {
>     int varidx = fs->nactvar++;
>     Vardesc *var = getlocalvardesc(fs, varidx);
>     var->vd.sidx = stklevel++;
>     var->vd.pidx = registerlocalvar(ls, fs, var->vd.name);

292,293c323,327
<   while (fs->nactvar > tolevel)
<     getlocvar(fs, --fs->nactvar)->endpc = fs->pc;
>   while (fs->nactvar > tolevel) {
>     LocVar *var = localdebuginfo(fs, --fs->nactvar);
>     if (var)  /* does it have debug information? */
>       var->endpc = fs->pc;
>   }

311c345
< static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
> static Upvaldesc *allocupvalue (FuncState *fs) {

319,323c353,374
<   f->upvalues[fs->nups].instack = (v->k == VLOCAL);
<   f->upvalues[fs->nups].idx = cast_byte(v->u.var.idx);
<   f->upvalues[fs->nups].name = name;
<   luaC_objbarrier(fs->ls->L, f, name);
<   return fs->nups++;
>   return &f->upvalues[fs->nups++];
> }
> 
> 
> static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
>   Upvaldesc *up = allocupvalue(fs);
>   FuncState *prev = fs->prev;
>   if (v->k == VLOCAL) {
>     up->instack = 1;
>     up->idx = v->u.var.sidx;
>     up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind;
>     lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name));
>   }
>   else {
>     up->instack = 0;
>     up->idx = cast_byte(v->u.info);
>     up->kind = prev->f->upvalues[v->u.info].kind;
>     lua_assert(eqstr(name, prev->f->upvalues[v->u.info].name));
>   }
>   up->name = name;
>   luaC_objbarrier(fs->ls->L, fs->f, name);
>   return fs->nups - 1;

331c382
< static int searchvar (FuncState *fs, TString *n) {
> static int searchvar (FuncState *fs, TString *n, expdesc *var) {

334,335c385,392
<     if (eqstr(n, getlocvar(fs, i)->varname))
<       return i;
>     Vardesc *vd = getlocalvardesc(fs, i);
>     if (eqstr(n, vd->vd.name)) {  /* found? */
>       if (vd->vd.kind == RDKCTC)  /* compile-time constant? */
>         init_exp(var, VCONST, fs->firstlocal + i);
>       else  /* real variable */
>         init_var(fs, var, i);
>       return var->k;
>     }

363c420
<     int v = searchvar(fs, n);  /* look up locals at current level */
>     int v = searchvar(fs, n, var);  /* look up locals at current level */

365,367c422,423
<       init_var(var, VLOCAL, v);  /* variable is local */
<       if (!base)
<         markupval(fs, v);  /* local will be used as an upval */
>       if (v == VLOCAL && !base)
>         markupval(fs, var->u.var.vidx);  /* local will be used as an upval */

373,376c429,432
<         if (var->k == VVOID)  /* not found? */
<           return;  /* it is a global */
<         /* else was LOCAL or UPVAL */
<         idx  = newupvalue(fs, n, var);  /* will be a new upvalue */
>         if (var->k == VLOCAL || var->k == VUPVAL)  /* local or upvalue? */
>           idx  = newupvalue(fs, n, var);  /* will be a new upvalue */
>         else  /* it is a global or a constant */
>           return;  /* don't need to do anything at this level */

378c434
<       init_var(var, VUPVAL, idx);  /* new or old upvalue */
>       init_exp(var, VUPVAL, idx);  /* new or old upvalue */

396c452
<     codestring(ls, &key, varname);  /* key is variable name */
>     codestring(&key, varname);  /* key is variable name */

441c497
<   const char *varname = getstr(getlocvar(ls->fs, gt->nactvar)->varname);
>   const char *varname = getstr(getlocalvardesc(ls->fs, gt->nactvar)->vd.name);

544c600
<     luaK_codeABC(fs, OP_CLOSE, fs->nactvar, 0, 0);
>     luaK_codeABC(fs, OP_CLOSE, luaY_nvarstack(fs), 0, 0);

560,561c616,617
<     if (gt->nactvar > bl->nactvar) {  /* leaving a variable scope? */
<       gt->nactvar = bl->nactvar;  /* update goto level */
>     /* leaving a variable scope? */
>     if (stacklevel(fs, gt->nactvar) > stacklevel(fs, bl->nactvar))

563c619
<     }
>     gt->nactvar = bl->nactvar;  /* update goto level */

577c633
<   lua_assert(fs->freereg == fs->nactvar);
>   lua_assert(fs->freereg == luaY_nvarstack(fs));

601a658
>   int stklevel = stacklevel(fs, bl->nactvar);  /* level outside the block */

605c662
<     luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
>     luaK_codeABC(fs, OP_CLOSE, stklevel, 0, 0);

609c666
<   fs->freereg = fs->nactvar;  /* free registers */
>   fs->freereg = stklevel;  /* free registers */

642c699
< ** The OP_CLOSURE instruction must use the last available register,
> ** The OP_CLOSURE instruction uses the last available register,

644a702
> 

667c725
<   fs->nlocvars = 0;
>   fs->ndebugvars = 0;

683c741
<   luaK_ret(fs, fs->nactvar, 0);  /* final return */
>   luaK_ret(fs, luaY_nvarstack(fs), 0);  /* final return */

693c751
<   luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
>   luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->ndebugvars, LocVar);

761c819
< struct ConsControl {
> typedef struct ConsControl {

765c823
<   int na;  /* total number of array elements */
>   int na;  /* number of array elements already stored */

767c825
< };
> } ConsControl;

770c828
< static void recfield (LexState *ls, struct ConsControl *cc) {
> static void recfield (LexState *ls, ConsControl *cc) {

791c849
< static void closelistfield (FuncState *fs, struct ConsControl *cc) {
> static void closelistfield (FuncState *fs, ConsControl *cc) {

796a855
>     cc->na += cc->tostore;

802c861
< static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
> static void lastlistfield (FuncState *fs, ConsControl *cc) {

813a873
>   cc->na += cc->tostore;

817c877
< static void listfield (LexState *ls, struct ConsControl *cc) {
> static void listfield (LexState *ls, ConsControl *cc) {

820,821d879
<   checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
<   cc->na++;

826c884
< static void field (LexState *ls, struct ConsControl *cc) {
> static void field (LexState *ls, ConsControl *cc) {

854c912,913
<   struct ConsControl cc;
>   ConsControl cc;
>   luaK_code(fs, 0);  /* space for extra arg. */

857c916,917
<   init_exp(t, VRELOC, pc);
>   init_exp(t, VNONRELOC, fs->freereg);  /* table will be at stack top */
>   luaK_reserveregs(fs, 1);

859d918
<   luaK_exp2nextreg(ls->fs, t);  /* fix it at stack top */

869,870c928
<   SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
<   SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh));  /* set initial table size */
>   luaK_settablesize(fs, pc, t->u.info, cc.na, cc.nh);

969c1027
<       codestring(ls, &args, ls->t.seminfo.ts);
>       codestring(&args, ls->t.seminfo.ts);

1077c1135
<       codestring(ls, v, ls->t.seminfo.ts);
>       codestring(v, ls->t.seminfo.ts);

1260c1318
<         if (v->k == VUPVAL && lh->v.u.ind.t == v->u.var.idx) {
>         if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) {

1267c1325
<         if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.idx) {
>         if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.sidx) {

1273c1331
<             lh->v.u.ind.idx == v->u.var.idx) {
>             lh->v.u.ind.idx == v->u.var.sidx) {

1282,1283c1340,1343
<     OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
<     luaK_codeABC(fs, op, extra, v->u.var.idx, 0);
>     if (v->k == VLOCAL)
>       luaK_codeABC(fs, OP_MOVE, extra, v->u.var.sidx, 0);
>     else
>       luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0);

1289c1349
< ** Parse and compile a mulitple assignment. The first "variable"
> ** Parse and compile a multiple assignment. The first "variable"

1346,1347c1406,1408
<     if (fs->nactvar > lb->nactvar)  /* leaving the scope of some variable? */
<       luaK_codeABC(fs, OP_CLOSE, lb->nactvar, 0, 0);
>     int lblevel = stacklevel(fs, lb->nactvar);  /* label level */
>     if (luaY_nvarstack(fs) > lblevel)  /* leaving the scope of a variable? */
>       luaK_codeABC(fs, OP_CLOSE, lblevel, 0, 0);

1422c1483
<     luaK_codeABC(fs, OP_CLOSE, bl2.nactvar, 0, 0);
>     luaK_codeABC(fs, OP_CLOSE, stacklevel(fs, bl2.nactvar), 0, 0);

1481d1541
<     base += 2;  /* base for 'OP_TFORLOOP' (skips function and state) */

1493,1495c1553,1555
<   new_localvarliteral(ls, "(for index)");
<   new_localvarliteral(ls, "(for limit)");
<   new_localvarliteral(ls, "(for step)");
>   new_localvarliteral(ls, "(for state)");
>   new_localvarliteral(ls, "(for state)");
>   new_localvarliteral(ls, "(for state)");

1520d1579
<   new_localvarliteral(ls, "(for generator)");

1522,1524c1581,1583
<   markupval(fs, fs->nactvar);  /* state may create an upvalue */
<   new_localvarliteral(ls, "(for control)");
<   new_localvarliteral(ls, "(for toclose)");
>   new_localvarliteral(ls, "(for state)");
>   new_localvarliteral(ls, "(for state)");
>   new_localvarliteral(ls, "(for state)");

1534a1594
>   markupval(fs, luaY_nvarstack(fs));  /* state may create an upvalue */

1577c1637,1638
<       if (ls->fs->nactvar > lb->nactvar)  /* needs to close variables? */
>       /* does it need to close variables? */
>       if (luaY_nvarstack(ls->fs) > stacklevel(ls->fs, lb->nactvar))

1648a1710
>   int fvar = fs->nactvar;  /* function's variable index */

1653c1715
<   getlocvar(fs, b.u.info)->startpc = fs->pc;
>   localdebuginfo(fs, fvar)->startpc = fs->pc;

1657,1658c1719,1751
< static void commonlocalstat (LexState *ls) {
<   /* stat -> LOCAL NAME {',' NAME} ['=' explist] */
> static int getlocalattribute (LexState *ls) {
>   /* ATTRIB -> ['<' Name '>'] */
>   if (testnext(ls, '<')) {
>     const char *attr = getstr(str_checkname(ls));
>     checknext(ls, '>');
>     if (strcmp(attr, "const") == 0)
>       return RDKCONST;  /* read-only variable */
>     else if (strcmp(attr, "close") == 0)
>       return RDKTOCLOSE;  /* to-be-closed variable */
>     else
>       luaK_semerror(ls,
>         luaO_pushfstring(ls->L, "unknown attribute '%s'", attr));
>   }
>   return VDKREG;
> }
> 
> 
> static void checktoclose (LexState *ls, int level) {
>   if (level != -1) {  /* is there a to-be-closed variable? */
>     FuncState *fs = ls->fs;
>     markupval(fs, level + 1);
>     fs->bl->insidetbc = 1;  /* in the scope of a to-be-closed variable */
>     luaK_codeABC(fs, OP_TBC, level, 0, 0);
>   }
> }
> 
> 
> static void localstat (LexState *ls) {
>   /* stat -> LOCAL ATTRIB NAME {',' ATTRIB NAME} ['=' explist] */
>   FuncState *fs = ls->fs;
>   int toclose = -1;  /* index of to-be-closed variable (if any) */
>   Vardesc *var;  /* last variable */
>   int ivar, kind;  /* index and kind of last variable */

1663c1756,1763
<     new_localvar(ls, str_checkname(ls));
>     ivar = new_localvar(ls, str_checkname(ls));
>     kind = getlocalattribute(ls);
>     getlocalvardesc(fs, ivar)->vd.kind = kind;
>     if (kind == RDKTOCLOSE) {  /* to-be-closed? */
>       if (toclose != -1)  /* one already present? */
>         luaK_semerror(ls, "multiple to-be-closed variables in local list");
>       toclose = luaY_nvarstack(fs) + nvars;
>     }

1672,1710c1772,1784
<   adjust_assign(ls, nvars, nexps, &e);
<   adjustlocalvars(ls, nvars);
< }
< 
< 
< static void tocloselocalstat (LexState *ls, Vardesc *var) {
<   FuncState *fs = ls->fs;
<   var->ro = 1;  /* to-be-closed variables are always read-only */
<   markupval(fs, fs->nactvar);
<   fs->bl->insidetbc = 1;  /* in the scope of a to-be-closed variable */
<   luaK_codeABC(fs, OP_TBC, fs->nactvar - 1, 0, 0);
< }
< 
< 
< static void attriblocalstat (LexState *ls) {
<   Vardesc *var;
<   TString *attr = str_checkname(ls);
<   testnext(ls, '>');
<   var = new_localvar(ls, str_checkname(ls));
<   checknext(ls, '=');
<   exp1(ls);
<   adjustlocalvars(ls, 1);
<   if (strcmp(getstr(attr), "const") == 0)
<     var->ro = 1;  /* set variable as read-only */
<   else if (strcmp(getstr(attr), "toclose") == 0)
<     tocloselocalstat(ls, var);
<   else
<     luaK_semerror(ls,
<       luaO_pushfstring(ls->L, "unknown attribute '%s'", getstr(attr)));
< }
< 
< 
< static void localstat (LexState *ls) {
<   /* stat -> LOCAL NAME {',' NAME} ['=' explist]
<            | LOCAL *toclose NAME '=' exp */
<   if (testnext(ls, '<'))
<     attriblocalstat(ls);
<   else
<     commonlocalstat(ls);
>   var = getlocalvardesc(fs, ivar);  /* get last variable */
>   if (nvars == nexps &&  /* no adjustments? */
>       var->vd.kind == RDKCONST &&  /* last variable is const? */
>       luaK_exp2const(fs, &e, &var->k)) {  /* compile-time constant? */
>     var->vd.kind = RDKCTC;  /* variable is a compile-time constant */
>     adjustlocalvars(ls, nvars - 1);  /* exclude last variable */
>     fs->nactvar++;  /* but count it */
>   }
>   else {
>     adjust_assign(ls, nvars, nexps, &e);
>     adjustlocalvars(ls, nvars);
>   }
>   checktoclose(ls, toclose);

1762c1836
<   int first = fs->nactvar;  /* first slot to be returned */
>   int first = luaY_nvarstack(fs);  /* first slot to be returned */

1771c1845
<         lua_assert(GETARG_A(getinstruction(fs,&e)) == fs->nactvar);
>         lua_assert(GETARG_A(getinstruction(fs,&e)) == luaY_nvarstack(fs));

1856,1857c1930,1931
<              ls->fs->freereg >= ls->fs->nactvar);
<   ls->fs->freereg = ls->fs->nactvar;  /* free registers */
>              ls->fs->freereg >= luaY_nvarstack(ls->fs));
>   ls->fs->freereg = luaY_nvarstack(ls->fs);  /* free registers */

1870c1944
<   expdesc v;
>   Upvaldesc *env;

1873,1874c1947,1951
<   init_var(&v, VLOCAL, 0);  /* create and... */
<   newupvalue(fs, ls->envn, &v);  /* ...set environment upvalue */
>   env = allocupvalue(fs);  /* ...set environment upvalue */
>   env->instack = 1;
>   env->idx = 0;
>   env->kind = VDKREG;
>   env->name = ls->envn;

src/lparser.h

33c33,35
<   VKINT,  /* integer constant; nval = numerical integer value */
>   VKINT,  /* integer constant; ival = numerical integer value */
>   VKSTR,  /* string constant; strval = TString address;
>              (string is fixed by the lexer) */

36,37c38,41
<   VLOCAL,  /* local variable; var.idx = local register */
<   VUPVAL,  /* upvalue variable; var.idx = index of upvalue in 'upvalues' */
>   VLOCAL,  /* local variable; var.ridx = local register;
>               var.vidx = relative index in 'actvar.arr'  */
>   VUPVAL,  /* upvalue variable; info = index of upvalue in 'upvalues' */
>   VCONST,  /* compile-time constant; info = absolute index in 'actvar.arr'  */

67a72
>     TString *strval;  /* for VKSTR */

73,74c78,80
<     struct {  /* for local variables and upvalues */
<       lu_byte idx;  /* index of the variable */
>     struct {  /* for local variables */
>       lu_byte sidx;  /* index in the stack */
>       unsigned short vidx;  /* index in 'actvar.arr'  */

81a88,93
> /* kinds of variables */
> #define VDKREG		0   /* regular */
> #define RDKCONST	1   /* constant */
> #define RDKTOCLOSE	2   /* to-be-closed */
> #define RDKCTC		3   /* compile-time constant */
> 

83,86c95,103
< typedef struct Vardesc {
<   TString *name;
<   short idx;  /* index of the variable in the Proto's 'locvars' array */
<   lu_byte ro;  /* true if variable is 'const' */
> typedef union Vardesc {
>   struct {
>     TValuefields;  /* constant value (if it is a compile-time constant) */
>     lu_byte kind;
>     lu_byte sidx;  /* index of the variable in the stack */
>     short pidx;  /* index of the variable in the Proto's 'locvars' array */
>     TString *name;  /* variable name */
>   } vd;
>   TValue k;  /* constant value (if any) */

89a107
> 

95c113
<   lu_byte nactvar;  /* local level where it appears in current block */
>   lu_byte nactvar;  /* number of active variables in that position */

138c156
<   short nlocvars;  /* number of elements in 'f->locvars' */
>   short ndebugvars;  /* number of elements in 'f->locvars' */

146a165
> LUAI_FUNC int luaY_nvarstack (FuncState *fs);

src/lstate.c

98a99,121
> LUA_API int lua_setcstacklimit (lua_State *L, unsigned int limit) {
>   global_State *g = G(L);
>   int ccalls;
>   luaE_freeCI(L);  /* release unused CIs */
>   ccalls = getCcalls(L);
>   if (limit >= 40000)
>     return 0;  /* out of bounds */
>   limit += CSTACKERR;
>   if (L != g-> mainthread)
>     return 0;  /* only main thread can change the C stack */
>   else if (ccalls <= CSTACKERR)
>     return 0;  /* handling overflow */
>   else {
>     int diff = limit - g->Cstacklimit;
>     if (ccalls + diff <= CSTACKERR)
>       return 0;  /* new limit would cause an overflow */
>     g->Cstacklimit = limit;  /* set new limit */
>     L->nCcalls += diff;  /* correct 'nCcalls' */
>     return limit - diff - CSTACKERR;  /* success; return previous limit */
>   }
> }
> 
> 

100c123
< ** Increment count of "C calls" and check for overflows. In case of
> ** Decrement count of "C calls" and check for overflows. In case of

102,113c125,132
< ** overflow while handling stack overflow).
< ** If 'nCcalls' is larger than LUAI_MAXCSTACK but smaller than
< ** LUAI_MAXCSTACK + CSTACKCF (plus 2 to avoid by-one errors), it means
< ** it has just entered the "overflow zone", so the function raises an
< ** overflow error.
< ** If 'nCcalls' is larger than LUAI_MAXCSTACK + CSTACKCF + 2
< ** (which means it is already handling an overflow) but smaller than
< ** 9/8 of LUAI_MAXCSTACK, does not report an error (to allow message
< ** handling to work).
< ** Otherwise, report a stack overflow while handling a stack overflow
< ** (probably caused by a repeating error in the message handling
< ** function).
> ** overflow while handling stack overflow).  If 'nCcalls' is smaller
> ** than CSTACKERR but larger than CSTACKMARK, it means it has just
> ** entered the "overflow zone", so the function raises an overflow
> ** error.  If 'nCcalls' is smaller than CSTACKMARK (which means it is
> ** already handling an overflow) but larger than CSTACKERRMARK, does
> ** not report an error (to allow message handling to work). Otherwise,
> ** report a stack overflow while handling a stack overflow (probably
> ** caused by a repeating error in the message handling function).

114a134
> 

117,118c137,138
<   L->nCcalls++;
<   if (ncalls >= LUAI_MAXCSTACK) {  /* possible overflow? */
>   L->nCcalls--;
>   if (ncalls <= CSTACKERR) {  /* possible overflow? */

121,124c141,146
<     if (ncalls >= LUAI_MAXCSTACK) {  /* still overflow? */
<       if (ncalls <= LUAI_MAXCSTACK + CSTACKCF + 2) {
<         /* no error before increments; raise the error now */
<         L->nCcalls += (CSTACKCF + 4);  /* avoid raising it again */
>     if (ncalls <= CSTACKERR) {  /* still overflow? */
>       if (ncalls <= CSTACKERRMARK)  /* below error-handling zone? */
>         luaD_throw(L, LUA_ERRERR);  /* error while handling stack error */
>       else if (ncalls >= CSTACKMARK) {
>         /* not in error-handling zone; raise the error now */
>         L->nCcalls = (CSTACKMARK - 1);  /* enter error-handling zone */

127,128c149,150
<       else if (ncalls >= (LUAI_MAXCSTACK + (LUAI_MAXCSTACK >> 3)))
<         luaD_throw(L, LUA_ERRERR);  /* error while handling stack error */
>       /* else stack is in the error-handling zone;
>          allow message handler to work */

156c178
<   L->nCcalls -= L->nci;  /* subtract removed elements from 'nCcalls' */
>   L->nCcalls += L->nci;  /* add removed elements back to 'nCcalls' */

162c184
<   L->nCcalls += L->nci;  /* adjust result */
>   L->nCcalls -= L->nci;  /* adjust result */

172c194
<   L->nCcalls -= L->nci;  /* subtract removed elements from 'nCcalls' */
>   L->nCcalls += L->nci;  /* add removed elements back to 'nCcalls' */

181c203
<   L->nCcalls += L->nci;  /* adjust result */
>   L->nCcalls -= L->nci;  /* adjust result */

267c289
<   L->nCcalls = 0;
>   L->nCcalls = CSTACKTHREAD;

368a391
>   g->Cstacklimit = L->nCcalls = LUAI_MAXCSTACK + CSTACKERR;

422a446,461
> /*
> ** Generate a warning from an error message
> */
> void luaE_warnerror (lua_State *L, const char *where) {
>   TValue *errobj = s2v(L->top - 1);  /* error object */
>   const char *msg = (ttisstring(errobj))
>                   ? svalue(errobj)
>                   : "error object is not a string";
>   /* produce warning "error in %s (%s)" (where, msg) */
>   luaE_warning(L, "error in ", 1);
>   luaE_warning(L, where, 1);
>   luaE_warning(L, " (", 1);
>   luaE_warning(L, msg, 1);
>   luaE_warning(L, ")", 0);
> }
> 

src/lstate.h

67,70c67,71
< ** how many "C calls" it can do in the C stack, to avoid C-stack overflow.
< ** This count is very rough approximation; it considers only recursive
< ** functions inside the interpreter, as non-recursive calls can be
< ** considered using a fixed (although unknown) amount of stack space.
> ** how many "C calls" it still can do in the C stack, to avoid C-stack
> ** overflow.  This count is very rough approximation; it considers only
> ** recursive functions inside the interpreter, as non-recursive calls
> ** can be considered using a fixed (although unknown) amount of stack
> ** space.

72,73c73,75
< ** The count itself has two parts: the lower part is the count itself;
< ** the higher part counts the number of non-yieldable calls in the stack.
> ** The count has two parts: the lower part is the count itself; the
> ** higher part counts the number of non-yieldable calls in the stack.
> ** (They are together so that we can change both with one instruction.)

75c77
< ** Because calls to external C functions can use of unkown amount
> ** Because calls to external C functions can use an unknown amount

77c79
< ** to these functions add more than one to the count.
> ** to these functions add more than one to the count (see CSTACKCF).

79,83c81,84
< ** The proper count also includes the number of CallInfo structures
< ** allocated by Lua, as a kind of "potential" calls. So, when Lua
< ** calls a function (and "consumes" one CallInfo), it needs neither to
< ** increment nor to check 'nCcalls', as its use of C stack is already
< ** accounted for.
> ** The proper count excludes the number of CallInfo structures allocated
> ** by Lua, as a kind of "potential" calls. So, when Lua calls a function
> ** (and "consumes" one CallInfo), it needs neither to decrement nor to
> ** check 'nCcalls', as its use of C stack is already accounted for.

88a90,109
> 
> /*
> ** The C-stack size is sliced in the following zones:
> ** - larger than CSTACKERR: normal stack;
> ** - [CSTACKMARK, CSTACKERR]: buffer zone to signal a stack overflow;
> ** - [CSTACKCF, CSTACKERRMARK]: error-handling zone;
> ** - below CSTACKERRMARK: buffer zone to signal overflow during overflow;
> ** (Because the counter can be decremented CSTACKCF at once, we need
> ** the so called "buffer zones", with at least that size, to properly
> ** detect a change from one zone to the next.)
> */
> #define CSTACKERR	(8 * CSTACKCF)
> #define CSTACKMARK	(CSTACKERR - (CSTACKCF + 2))
> #define CSTACKERRMARK	(CSTACKCF + 2)
> 
> 
> /* initial limit for the C-stack of threads */
> #define CSTACKTHREAD	(2 * CSTACKERR)
> 
> 

102,103c123,124
< /* Increment the number of non-yieldable calls and nCcalls */
< #define incXCcalls(L)	((L)->nCcalls += 0x10000 + CSTACKCF)
> /* Increment the number of non-yieldable calls and decrement nCcalls */
> #define incXCcalls(L)	((L)->nCcalls += 0x10000 - CSTACKCF)

105,106c126,127
< /* Decrement the number of non-yieldable calls and nCcalls */
< #define decXCcalls(L)	((L)->nCcalls -= 0x10000 + CSTACKCF)
> /* Decrement the number of non-yieldable calls and increment nCcalls */
> #define decXCcalls(L)	((L)->nCcalls -= 0x10000 - CSTACKCF)

167,169c188,190
<     struct {  /* info about transfered values (for call/return hooks) */
<       unsigned short ftransfer;  /* offset of first value transfered */
<       unsigned short ntransfer;  /* number of values transfered */
>     struct {  /* info about transferred values (for call/return hooks) */
>       unsigned short ftransfer;  /* offset of first value transferred */
>       unsigned short ntransfer;  /* number of values transferred */

252a274
>   unsigned int Cstacklimit;  /* current limit for the C stack */

316,317c338
< #define gco2upv(o)  \
< 	check_exp(novariant((o)->tt) == LUA_TUPVAL, &((cast_u(o))->upv))
> #define gco2upv(o)	check_exp((o)->tt == LUA_TUPVAL, &((cast_u(o))->upv))

336a358
> LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);

339c361
< #define luaE_exitCcall(L)	((L)->nCcalls--)
> #define luaE_exitCcall(L)	((L)->nCcalls++)

src/lstrlib.c

747c747
<     lua_pushnil(L);  /* cannot find anything */
>     luaL_pushfail(L);  /* cannot find anything */

782c782
<   lua_pushnil(L);  /* not found */
>   luaL_pushfail(L);  /* not found */

1230,1231c1230,1234
<         case 'e': case 'E': case 'f':
<         case 'g': case 'G': {
>         case 'f':
>           maxitem = MAX_ITEMF;  /* extra space for '%f' */
>           buff = luaL_prepbuffsize(&b, maxitem);
>           /* FALLTHROUGH */
>         case 'e': case 'E': case 'g': case 'G': {

1233,1237d1235
<           if (*(strfrmt - 1) == 'f' && l_mathop(fabs)(n) >= 1e100) {
<             /* 'n' needs more than 99 digits */
<             maxitem = MAX_ITEMF;  /* extra space for '%f' */
<             buff = luaL_prepbuffsize(&b, maxitem);
<           }

1239c1237
<           nb = l_sprintf(buff, maxitem, form, (LUAI_UACNUMBER)n);
>           nb = snprintf(buff, maxitem, form, (LUAI_UACNUMBER)n);

src/ltable.c

836,837c836,838
< ** The code starts with 'limit', a position in the array part that may
< ** be a boundary.
> ** The code starts with 'limit = t->alimit', a position in the array
> ** part that may be a boundary.
> **

839c840
< ** As a common case (e.g., after 't[#t]=nil'), check whether 'hint-1'
> ** As a common case (e.g., after 't[#t]=nil'), check whether 'limit-1'

842c843,844
< ** use this boundary as the new 'limit', as a hint for the next call.
> ** use this boundary as the new 'alimit', as a hint for the next call.
> **

847,850c849,853
< ** last element of the array part (set it as a new limit). If it is empty,
< ** there must be a boundary between the old limit (present) and the new
< ** limit (absent), which is found with a binary search. (This boundary
< ** always can be a new limit.)
> ** last element of the array part. If it is empty, there must be a
> ** boundary between the old limit (present) and the last element
> ** (absent), which is found with a binary search. (This boundary always
> ** can be a new limit.)
> **

853,858c856,860
< ** In this case, must check the hash part. If there is no hash part,
< ** the boundary is 0. Otherwise, if 'limit+1' is absent, 'limit' is
< ** a boundary. Finally, if 'limit+1' is present, call 'hash_search'
< ** to find a boundary in the hash part of the table. (In those
< ** cases, the boundary is not inside the array part, and therefore
< ** cannot be used as a new limit.)
> ** In this case, must check the hash part. If there is no hash part
> ** or 'limit+1' is absent, 'limit' is a boundary.  Otherwise, call
> ** 'hash_search' to find a boundary in the hash part of the table.
> ** (In those cases, the boundary is not inside the array part, and
> ** therefore cannot be used as a new limit.)

862,863c864,865
<   if (limit > 0 && isempty(&t->array[limit - 1])) {
<     /* (1) there must be a boundary before 'limit' */
>   if (limit > 0 && isempty(&t->array[limit - 1])) {  /* (1)? */
>     /* there must be a boundary before 'limit' */

868c870
<         setnorealasize(t);
>         setnorealasize(t);  /* now 'alimit' is not the real size */

883,884c885,886
<   if (!limitequalsasize(t)) {
<     /* (2) 'limit' > 0 and array has more elements after 'limit' */
>   if (!limitequalsasize(t)) {  /* (2)? */
>     /* 'limit' > 0 and array has more elements after 'limit' */

902c904
<     return limit;  /* 'limit + 1' is absent... */
>     return limit;  /* 'limit + 1' is absent */

910a913,914
> /* export these functions for the test library */
> 

src/ltablib.c

341c341
< ** QuickSort algorithm (recursive function)
> ** Quicksort algorithm (recursive function)

src/ltm.c

152,154d151
<       case TM_CONCAT:
<         luaG_concaterror(L, p1, p2);
<       /* call never returns, but to avoid warnings: *//* FALLTHROUGH */

169a167,173
> void luaT_tryconcatTM (lua_State *L) {
>   StkId top = L->top;
>   if (!callbinTM(L, s2v(top - 2), s2v(top - 1), top - 2, TM_CONCAT))
>     luaG_concaterror(L, s2v(top - 2), s2v(top - 1));
> }
> 
> 

171,172c175,176
<                                        StkId res, int inv, TMS event) {
<   if (inv)
>                                        int flip, StkId res, TMS event) {
>   if (flip)

180c184
<                                    int inv, StkId res, TMS event) {
>                                    int flip, StkId res, TMS event) {

183c187
<   luaT_trybinassocTM(L, p1, &aux, res, inv, event);
>   luaT_trybinassocTM(L, p1, &aux, flip, res, event);

208c212
<                        int inv, int isfloat, TMS event) {
>                        int flip, int isfloat, TMS event) {

215c219
<   if (inv) {  /* arguments were exchanged? */
>   if (flip) {  /* arguments were exchanged? */

src/ltm.h

77a78
> LUAI_FUNC void luaT_tryconcatTM (lua_State *L);

79c80
<        const TValue *p2, StkId res, int inv, TMS event);
>        const TValue *p2, int inv, StkId res, TMS event);

src/lua.c

75a76
>   "  -W       turn warnings on\n"

262c263
<         if (argv[i][2] != '\0')  /* extra characters after 1st? */
>         if (argv[i][2] != '\0')  /* extra characters? */

265a267,270
>       case 'W':
>         if (argv[i][2] != '\0')  /* extra characters? */
>           return has_error;  /* invalid option */
>         break;

269c274
<         if (argv[i][2] != '\0')  /* extra characters after 1st? */
>         if (argv[i][2] != '\0')  /* extra characters? */

292c297,298
< ** Processes options 'e' and 'l', which involve running Lua code.
> ** Processes options 'e' and 'l', which involve running Lua code, and
> ** 'W', which also affects the state.

300,308c306,320
<     if (option == 'e' || option == 'l') {
<       int status;
<       const char *extra = argv[i] + 2;  /* both options need an argument */
<       if (*extra == '\0') extra = argv[++i];
<       lua_assert(extra != NULL);
<       status = (option == 'e')
<                ? dostring(L, extra, "=(command line)")
<                : dolibrary(L, extra);
<       if (status != LUA_OK) return 0;
>     switch (option) {
>       case 'e':  case 'l': {
>         int status;
>         const char *extra = argv[i] + 2;  /* both options need an argument */
>         if (*extra == '\0') extra = argv[++i];
>         lua_assert(extra != NULL);
>         status = (option == 'e')
>                  ? dostring(L, extra, "=(command line)")
>                  : dolibrary(L, extra);
>         if (status != LUA_OK) return 0;
>         break;
>       }
>       case 'W':
>         lua_warning(L, "@on", 0);  /* warnings on */
>         break;

src/lua.h

464a465
> LUA_API int (lua_setcstacklimit) (lua_State *L, unsigned int limit);

src/luac.c

39a40
> static TString **tmname;

173a175
>  tmname=G(L)->tmname;

216a219
> #define eventname(i) (getstr(tmname[i]))

322a326,327
> #define COMMENT	"\t; "
> 

357c362
< 	printf("\t; "); PrintConstant(f,bx);
> 	printf(COMMENT); PrintConstant(f,bx);

364c369
< 	if (c) printf("\t; to %d",pc+2);
> 	if (c) printf(COMMENT "to %d",pc+2);

368c373
< 	printf("\t; %d out",b+1);
> 	printf(COMMENT "%d out",b+1);

372c377
< 	printf("\t; %s",UPVALNAME(b));
> 	printf(COMMENT "%s",UPVALNAME(b));

376c381
< 	printf("\t; %s",UPVALNAME(b));
> 	printf(COMMENT "%s",UPVALNAME(b));

380c385
< 	printf("\t; %s",UPVALNAME(b));
> 	printf(COMMENT "%s",UPVALNAME(b));

391c396
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

395c400
< 	printf("\t; %s",UPVALNAME(a));
> 	printf(COMMENT "%s",UPVALNAME(a));

401c406
< 	if (isk) { printf("\t; "); PrintConstant(f,c); }
> 	if (isk) { printf(COMMENT); PrintConstant(f,c); }

405c410
< 	if (isk) { printf("\t; "); PrintConstant(f,c); }
> 	if (isk) { printf(COMMENT); PrintConstant(f,c); }

409c414
< 	printf("\t; "); PrintConstant(f,b);
> 	printf(COMMENT); PrintConstant(f,b);

417c422
< 	if (isk) { printf("\t; "); PrintConstant(f,c); }
> 	if (isk) { printf(COMMENT); PrintConstant(f,c); }

420,438c425
< 	printf("%d %d %d",a,b,sc);
< 	break;
<    case OP_SUBI:
< 	printf("%d %d %d",a,b,sc);
< 	break;
<    case OP_MULI:
< 	printf("%d %d %d",a,b,sc);
< 	break;
<    case OP_MODI:
< 	printf("%d %d %d",a,b,sc);
< 	break;
<    case OP_POWI:
< 	printf("%d %d %d",a,b,sc);
< 	break;
<    case OP_DIVI:
< 	printf("%d %d %d",a,b,sc);
< 	break;
<    case OP_IDIVI:
< 	printf("%d %d %d",a,b,sc);
> 	printf("%d %d %d %s",a,b,sc,isk ? "F" : "");

441,442c428,429
< 	printf("%d %d %d",a,b,c);
< 	printf("\t; "); PrintConstant(f,c);
> 	printf("%d %d %d %s",a,b,c,isk ? "F" : "");
> 	printf(COMMENT); PrintConstant(f,c);

446c433
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

449,450c436,437
< 	printf("%d %d %d",a,b,c);
< 	printf("\t; "); PrintConstant(f,c);
> 	printf("%d %d %d %s",a,b,c,isk ? "F" : "");
> 	printf(COMMENT); PrintConstant(f,c);

454c441
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

458c445
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

462c449
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

466c453
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

470c457
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

474c461
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

478c465
< 	printf("\t; "); PrintConstant(f,c);
> 	printf(COMMENT); PrintConstant(f,c);

481c468
< 	printf("%d %d %d",a,b,c);
> 	printf("%d %d %d",a,b,sc);

484c471
< 	printf("%d %d %d",a,b,c);
> 	printf("%d %d %d",a,b,sc);

521a509,520
>    case OP_MMBIN:
> 	printf("%d %d %d",a,b,c);
> 	break;
> 	printf(COMMENT); printf("%s ",eventname(c));
>    case OP_MMBINI:
> 	printf("%d %d %d",a,sb,c);
> 	printf(COMMENT); printf("%s ",eventname(c));
> 	break;
>    case OP_MMBINK:
> 	printf("%d %d %d",a,b,c);
> 	printf(COMMENT); printf("%s ",eventname(c)); PrintConstant(f,b);
> 	break;

545c544
< 	printf("\t; to %d",GETARG_sJ(i)+pc+2);
> 	printf(COMMENT "to %d",GETARG_sJ(i)+pc+2);

558c557
< 	printf("\t; "); PrintConstant(f,b);
> 	printf(COMMENT); PrintConstant(f,b);

583c582
< 	printf("\t; ");
> 	printf(COMMENT);

589c588
< 	printf("\t; %d in",b-1);
> 	printf(COMMENT "%d in",b-1);

593c592
< 	printf("\t; ");
> 	printf(COMMENT);

603c602
< 	printf("\t; to %d",pc-bx+2);
> 	printf(COMMENT "to %d",pc-bx+2);

607c606
< 	printf("\t; to %d",pc+bx+2);
> 	printf(COMMENT "to %d",pc+bx+2);

611c610
< 	printf("\t; to %d",pc+bx+2);
> 	printf(COMMENT "to %d",pc+bx+2);

618c617
< 	printf("\t; to %d",pc-bx+2);
> 	printf(COMMENT "to %d",pc-bx+2);

625c624
< 	printf("\t; %p",VOID(f->p[bx]));
> 	printf(COMMENT "%p",VOID(f->p[bx]));

629c628
< 	printf("\t; ");
> 	printf(COMMENT);

637c636
< 	printf("\t; "); PrintConstant(f,ax);
> 	printf(COMMENT); PrintConstant(f,ax);

src/luaconf.h

50c50
< #define LUAI_MAXCSTACK		2200
> #define LUAI_MAXCSTACK		2000

496c496
< @@ over a lUA_INTEGER.
> @@ over a LUA_INTEGER.

src/lundump.c

201,202d200
<   for (i = 0; i < n; i++)
<     f->upvalues[i].name = NULL;

203a202
>     f->upvalues[i].name = NULL;

205a205
>     f->upvalues[i].kind = LoadByte(S);

src/lutf8lib.c

106c106
<       lua_pushnil(L);  /* return nil ... */
>       luaL_pushfail(L);  /* return fail ... */

219c219
<     lua_pushnil(L);
>     luaL_pushfail(L);

src/lvm.c

518,519c518,521
<   luaT_callTMres(L, tm, t1, t2, L->top);  /* call TM */
<   return !l_isfalse(s2v(L->top));
>   else {
>     luaT_callTMres(L, tm, t1, t2, L->top);  /* call TM */
>     return !l_isfalse(s2v(L->top));
>   }

551c553
<       luaT_trybinTM(L, s2v(top - 2), s2v(top - 1), top - 2, TM_CONCAT);
>       luaT_tryconcatTM(L);

673a676,677
> #define luaV_shiftr(x,y)	luaV_shiftl(x,-(y))
> 

717,725c721,724
<     case OP_ADDI: case OP_SUBI:
<     case OP_MULI: case OP_DIVI: case OP_IDIVI:
<     case OP_MODI: case OP_POWI:
<     case OP_ADD: case OP_SUB:
<     case OP_MUL: case OP_DIV: case OP_IDIV:
<     case OP_BANDK: case OP_BORK: case OP_BXORK:
<     case OP_BAND: case OP_BOR: case OP_BXOR:
<     case OP_SHRI: case OP_SHL: case OP_SHR:
<     case OP_MOD: case OP_POW:
>     case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
>       setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top);
>       break;
>     }

750c749
<       StkId top = L->top - 1;  /* top when 'luaT_trybinTM' was called */
>       StkId top = L->top - 1;  /* top when 'luaT_tryconcatTM' was called */

782,784c781,783
< #define l_band(L,a,b)	intop(&, a, b)
< #define l_bor(L,a,b)	intop(|, a, b)
< #define l_bxor(L,a,b)	intop(^, a, b)
> #define l_band(a,b)	intop(&, a, b)
> #define l_bor(a,b)	intop(|, a, b)
> #define l_bxor(a,b)	intop(^, a, b)

800,803c799,801
<     setfltvalue(s2v(ra), fop(L, nb, cast_num(imm)));  \
<   }  \
<   else  \
<     Protect(luaT_trybiniTM(L, v1, imm, flip, ra, tm)); }
>     lua_Number fimm = cast_num(imm);  \
>     pc++; setfltvalue(s2v(ra), fop(L, nb, fimm));  \
>   }}

822c820,821
<     setivalue(s2v(ra), iop(L, ivalue(v1), imm));  \
>     lua_Integer iv1 = ivalue(v1);  \
>     pc++; setivalue(s2v(ra), iop(L, iv1, imm));  \

831c830
< #define op_arithf_aux(L,v1,v2,fop,tm) {  \
> #define op_arithf_aux(L,v1,v2,fop) {  \

834,837c833,834
<     setfltvalue(s2v(ra), fop(L, n1, n2));  \
<   }  \
<   else  \
<     Protect(luaT_trybinTM(L, v1, v2, ra, tm)); }
>     pc++; setfltvalue(s2v(ra), fop(L, n1, n2));  \
>   }}

843c840
< #define op_arithf(L,fop,tm) {  \
> #define op_arithf(L,fop) {  \

846c843
<   op_arithf_aux(L, v1, v2, fop, tm); }
>   op_arithf_aux(L, v1, v2, fop); }

852c849
< #define op_arith(L,iop,fop,tm) {  \
> #define op_arith(L,iop,fop) {  \

857c854
<     setivalue(s2v(ra), iop(L, i1, i2));  \
>     pc++; setivalue(s2v(ra), iop(L, i1, i2));  \

859c856
<   else op_arithf_aux(L, v1, v2, fop, tm); }
>   else op_arithf_aux(L, v1, v2, fop); }

865c862
< #define op_arithK(L,iop,fop,tm,flip) {  \
> #define op_arithK(L,iop,fop,flip) {  \

870c867
<     setivalue(s2v(ra), iop(L, i1, i2));  \
>     pc++; setivalue(s2v(ra), iop(L, i1, i2));  \

875,878c872,873
<       setfltvalue(s2v(ra), fop(L, n1, n2));  \
<     }  \
<     else  \
<       Protect(luaT_trybinassocTM(L, v1, v2, ra, flip, tm)); } }
>       pc++; setfltvalue(s2v(ra), fop(L, n1, n2));  \
>     }}}

884c879
< #define op_arithfK(L,fop,tm) {  \
> #define op_arithfK(L,fop) {  \

889,892c884,885
<     setfltvalue(s2v(ra), fop(L, n1, n2));  \
<   }  \
<   else  \
<     Protect(luaT_trybinTM(L, v1, v2, ra, tm)); }
>     pc++; setfltvalue(s2v(ra), fop(L, n1, n2));  \
>   }}

898c891
< #define op_bitwiseK(L,op,tm) {  \
> #define op_bitwiseK(L,op) {  \

904,907c897,898
<     setivalue(s2v(ra), op(L, i1, i2));  \
<   }  \
<   else  \
<     Protect(luaT_trybiniTM(L, v1, i2, TESTARG_k(i), ra, tm)); }
>     pc++; setivalue(s2v(ra), op(i1, i2));  \
>   }}

913c904
< #define op_bitwise(L,op,tm) {  \
> #define op_bitwise(L,op) {  \

918,921c909,910
<     setivalue(s2v(ra), op(L, i1, i2));  \
<   }  \
<   else  \
<     Protect(luaT_trybinTM(L, v1, v2, ra, tm)); }
>     pc++; setivalue(s2v(ra), op(i1, i2));  \
>   }}

930,931c919,923
<         if (ttisinteger(s2v(ra)) && ttisinteger(rb))  \
<           cond = opi(ivalue(s2v(ra)), ivalue(rb));  \
>         if (ttisinteger(s2v(ra)) && ttisinteger(rb)) {  \
>           lua_Integer ia = ivalue(s2v(ra));  \
>           lua_Integer ib = ivalue(rb);  \
>           cond = opi(ia, ib);  \
>         }  \

947,948c939,943
<         else if (ttisfloat(s2v(ra)))  \
<           cond = opf(fltvalue(s2v(ra)), cast_num(im));  \
>         else if (ttisfloat(s2v(ra))) {  \
>           lua_Number fa = fltvalue(s2v(ra));  \
>           lua_Number fim = cast_num(im);  \
>           cond = opf(fa, fim);  \
>         }  \

996c991
< #define donextjump(ci)	{ i = *pc; dojump(ci, i, 1); }
> #define donextjump(ci)	{ Instruction ni = *pc; dojump(ci, ni, 1); }

1033c1028,1031
< #define halfProtect(exp)  (savepc(L), (exp))
> #define halfProtect(exp)  (savestate(L,ci), (exp))
> 
> /* idem, but without changing the stack */
> #define halfProtectNT(exp)  (savepc(L), (exp))

1086c1084,1085
<     lua_assert(ci->top < L->stack + L->stacksize);
>     /* invalidate top for instructions not expecting it */
>     lua_assert(isIT(i) || (L->top = base));

1092,1096d1090
<       vmcase(OP_LOADK) {
<         TValue *rb = k + GETARG_Bx(i);
<         setobj2s(L, ra, rb);
<         vmbreak;
<       }

1106a1101,1105
>       vmcase(OP_LOADK) {
>         TValue *rb = k + GETARG_Bx(i);
>         setobj2s(L, ra, rb);
>         vmbreak;
>       }

1242,1243c1241,1242
<         int b = GETARG_B(i);
<         int c = GETARG_C(i);
>         int b = GETARG_B(i);  /* log2(hash size) + 1 */
>         int c = GETARG_C(i);  /* array size */

1245c1244,1249
<         L->top = ci->top;  /* correct top in case of GC */
>         if (b > 0)
>           b = 1 << (b - 1);  /* size is 2^(b - 1) */
>         if (TESTARG_k(i))
>           c += GETARG_Ax(*pc) * (MAXARG_C + 1);
>         pc++;  /* skip extra argument */
>         L->top = ra + 1;  /* correct top in case of emergency GC */

1249c1253
<           luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));  /* idem */
>           luaH_resize(L, t, c, b);  /* idem */

1270,1275c1274,1275
<       vmcase(OP_SUBI) {
<         op_arithI(L, l_subi, luai_numsub, TM_SUB, 0);
<         vmbreak;
<       }
<       vmcase(OP_MULI) {
<         op_arithI(L, l_muli, luai_nummul, TM_MUL, GETARG_k(i));
>       vmcase(OP_ADDK) {
>         op_arithK(L, l_addi, luai_numadd, GETARG_k(i));

1278,1279c1278,1279
<       vmcase(OP_MODI) {
<         op_arithI(L, luaV_mod, luaV_modf, TM_MOD, 0);
>       vmcase(OP_SUBK) {
>         op_arithK(L, l_subi, luai_numsub, 0);

1282,1283c1282,1283
<       vmcase(OP_POWI) {
<         op_arithfI(L, luai_numpow, TM_POW);
>       vmcase(OP_MULK) {
>         op_arithK(L, l_muli, luai_nummul, GETARG_k(i));

1286,1287c1286,1287
<       vmcase(OP_DIVI) {
<         op_arithfI(L, luai_numdiv, TM_DIV);
>       vmcase(OP_MODK) {
>         op_arithK(L, luaV_mod, luaV_modf, 0);

1290,1291c1290,1291
<       vmcase(OP_IDIVI) {
<         op_arithI(L, luaV_idiv, luai_numidiv, TM_IDIV, 0);
>       vmcase(OP_POWK) {
>         op_arithfK(L, luai_numpow);

1294,1295c1294,1295
<       vmcase(OP_ADDK) {
<         op_arithK(L, l_addi, luai_numadd, TM_ADD, GETARG_k(i));
>       vmcase(OP_DIVK) {
>         op_arithfK(L, luai_numdiv);

1298,1299c1298,1299
<       vmcase(OP_SUBK) {
<         op_arithK(L, l_subi, luai_numsub, TM_SUB, 0);
>       vmcase(OP_IDIVK) {
>         op_arithK(L, luaV_idiv, luai_numidiv, 0);

1302,1303c1302,1303
<       vmcase(OP_MULK) {
<         op_arithK(L, l_muli, luai_nummul, TM_MUL, GETARG_k(i));
>       vmcase(OP_BANDK) {
>         op_bitwiseK(L, l_band);

1306,1307c1306,1307
<       vmcase(OP_MODK) {
<         op_arithK(L, luaV_mod, luaV_modf, TM_MOD, 0);
>       vmcase(OP_BORK) {
>         op_bitwiseK(L, l_bor);

1310,1311c1310,1311
<       vmcase(OP_POWK) {
<         op_arithfK(L, luai_numpow, TM_POW);
>       vmcase(OP_BXORK) {
>         op_bitwiseK(L, l_bxor);

1314,1315c1314,1320
<       vmcase(OP_DIVK) {
<         op_arithfK(L, luai_numdiv, TM_DIV);
>       vmcase(OP_SHRI) {
>         TValue *rb = vRB(i);
>         int ic = GETARG_sC(i);
>         lua_Integer ib;
>         if (tointegerns(rb, &ib)) {
>           pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
>         }

1318,1319c1323,1329
<       vmcase(OP_IDIVK) {
<         op_arithK(L, luaV_idiv, luai_numidiv, TM_IDIV, 0);
>       vmcase(OP_SHLI) {
>         TValue *rb = vRB(i);
>         int ic = GETARG_sC(i);
>         lua_Integer ib;
>         if (tointegerns(rb, &ib)) {
>           pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
>         }

1323c1333
<         op_arith(L, l_addi, luai_numadd, TM_ADD);
>         op_arith(L, l_addi, luai_numadd);

1327c1337
<         op_arith(L, l_subi, luai_numsub, TM_SUB);
>         op_arith(L, l_subi, luai_numsub);

1331c1341
<         op_arith(L, l_muli, luai_nummul, TM_MUL);
>         op_arith(L, l_muli, luai_nummul);

1335c1345
<         op_arith(L, luaV_mod, luaV_modf, TM_MOD);
>         op_arith(L, luaV_mod, luaV_modf);

1339c1349
<         op_arithf(L, luai_numpow, TM_POW);
>         op_arithf(L, luai_numpow);

1343c1353
<         op_arithf(L, luai_numdiv, TM_DIV);
>         op_arithf(L, luai_numdiv);

1347,1359c1357
<         op_arith(L, luaV_idiv, luai_numidiv, TM_IDIV);
<         vmbreak;
<       }
<       vmcase(OP_BANDK) {
<         op_bitwiseK(L, l_band, TM_BAND);
<         vmbreak;
<       }
<       vmcase(OP_BORK) {
<         op_bitwiseK(L, l_bor, TM_BOR);
<         vmbreak;
<       }
<       vmcase(OP_BXORK) {
<         op_bitwiseK(L, l_bxor, TM_BXOR);
>         op_arith(L, luaV_idiv, luai_numidiv);

1363c1361
<         op_bitwise(L, l_band, TM_BAND);
>         op_bitwise(L, l_band);

1367c1365
<         op_bitwise(L, l_bor, TM_BOR);
>         op_bitwise(L, l_bor);

1371,1398c1369
<         op_bitwise(L, l_bxor, TM_BXOR);
<         vmbreak;
<       }
<       vmcase(OP_SHRI) {
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Integer ib;
<         if (tointegerns(rb, &ib)) {
<           setivalue(s2v(ra), luaV_shiftl(ib, -ic));
<         }
<         else {
<           TMS ev = TM_SHR;
<           if (TESTARG_k(i)) {
<             ic = -ic;  ev = TM_SHL;
<           }
<           Protect(luaT_trybiniTM(L, rb, ic, 0, ra, ev));
<         }
<         vmbreak;
<       }
<       vmcase(OP_SHLI) {
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Integer ib;
<         if (tointegerns(rb, &ib)) {
<           setivalue(s2v(ra), luaV_shiftl(ic, ib));
<         }
<         else
<           Protect(luaT_trybiniTM(L, rb, ic, 1, ra, TM_SHL));
>         op_bitwise(L, l_bxor);

1402,1409c1373
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Integer ib; lua_Integer ic;
<         if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
<           setivalue(s2v(ra), luaV_shiftl(ib, -ic));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR));
>         op_bitwise(L, luaV_shiftr);

1412a1377,1381
>         op_bitwise(L, luaV_shiftl);
>         vmbreak;
>       }
>       vmcase(OP_MMBIN) {
>         Instruction pi = *(pc - 2);  /* original arith. expression */

1414,1420c1383,1404
<         TValue *rc = vRC(i);
<         lua_Integer ib; lua_Integer ic;
<         if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
<           setivalue(s2v(ra), luaV_shiftl(ib, ic));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL));
>         TMS tm = (TMS)GETARG_C(i);
>         StkId result = RA(pi);
>         lua_assert(OP_ADD <= GET_OPCODE(pi) && GET_OPCODE(pi) <= OP_SHR);
>         Protect(luaT_trybinTM(L, s2v(ra), rb, result, tm));
>         vmbreak;
>       }
>       vmcase(OP_MMBINI) {
>         Instruction pi = *(pc - 2);  /* original arith. expression */
>         int imm = GETARG_sB(i);
>         TMS tm = (TMS)GETARG_C(i);
>         int flip = GETARG_k(i);
>         StkId result = RA(pi);
>         Protect(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm));
>         vmbreak;
>       }
>       vmcase(OP_MMBINK) {
>         Instruction pi = *(pc - 2);  /* original arith. expression */
>         TValue *imm = KB(i);
>         TMS tm = (TMS)GETARG_C(i);
>         int flip = GETARG_k(i);
>         StkId result = RA(pi);
>         Protect(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm));

1465d1448
<         L->top = ra + 1;  /* everything is free after this slot */

1554c1537,1539
<         int delta = 0;  /* virtual 'func' - real 'func' (vararg functions) */
>         int nparams1 = GETARG_C(i);
>         /* delat is virtual 'func' - real 'func' (vararg functions) */
>         int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0;

1561,1563d1545
<           int nparams1 = GETARG_C(i);
<           if (nparams1)  /* vararg function? */
<             delta = ci->u.l.nextraargs + nparams1;

1565c1547,1548
<              that there are no to-be-closed variables here */
>              that there are no to-be-closed variables here, so this
>              call cannot change the stack */

1566a1550
>           lua_assert(base == ci->func + 1);

1588a1573
>         int nparams1 = GETARG_C(i);

1591,1592d1575
<         else
<           L->top = ra + n;  /* set call for 'luaD_poscall' */

1594,1598c1577,1582
<         if (TESTARG_k(i)) {
<           int nparams1 = GETARG_C(i);
<           luaF_close(L, base, LUA_OK);  /* there may be open upvalues */
<           if (nparams1)  /* vararg function? */
<             ci->func -= ci->u.l.nextraargs + nparams1;
>         if (TESTARG_k(i)) {  /* may there be open upvalues? */
>           if (L->top < ci->top)
>             L->top = ci->top;
>           luaF_close(L, base, LUA_OK);
>           updatetrap(ci);
>           updatestack(ci);

1599a1584,1586
>         if (nparams1)  /* vararg function? */
>           ci->func -= ci->u.l.nextraargs + nparams1;
>         L->top = ra + n;  /* set call for 'luaD_poscall' */

1606c1593
<           halfProtect(luaD_poscall(L, ci, 0));  /* no hurry... */
>           halfProtectNT(luaD_poscall(L, ci, 0));  /* no hurry... */

1620c1607
<           halfProtect(luaD_poscall(L, ci, 1));  /* no hurry... */
>           halfProtectNT(luaD_poscall(L, ci, 1));  /* no hurry... */

1719,1722c1706,1707
<         if (!ttisnil(s2v(ra + 3))) {  /* is 'toclose' not nil? */
<           /* create to-be-closed upvalue for it */
<           halfProtect(luaF_newtbcupval(L, ra + 3));
<         }
>         /* create to-be-closed upvalue (if needed) */
>         halfProtect(luaF_newtbcupval(L, ra + 3));

1738c1723
<         Protect(luaD_call(L, ra + 4, GETARG_C(i)));  /* do the call */
>         ProtectNT(luaD_call(L, ra + 4, GETARG_C(i)));  /* do the call */

1741d1725
<         ra += 2;  /* adjust for next instruction */

1747,1748c1731,1732
<         if (!ttisnil(s2v(ra + 2))) {  /* continue loop? */
<           setobjs2s(L, ra, ra + 2);  /* save control variable */
>         if (!ttisnil(s2v(ra + 4))) {  /* continue loop? */
>           setobjs2s(L, ra + 2, ra + 4);  /* save control variable */

1755,1757c1739,1740
<         int c = GETARG_C(i);
<         unsigned int last;
<         Table *h;
>         unsigned int last = GETARG_C(i);
>         Table *h = hvalue(s2v(ra));

1759c1742
<           n = cast_int(L->top - ra) - 1;
>           n = cast_int(L->top - ra) - 1;  /* get up to the top */

1761,1763c1744,1748
<           L->top = ci->top;  /* correct top in case of GC */
<         if (c == 0) {
<           c = GETARG_Ax(*pc); pc++;
>           L->top = ci->top;  /* correct top in case of emergency GC */
>         last += n;
>         if (TESTARG_k(i)) {
>           last += GETARG_Ax(*pc) * (MAXARG_C + 1);
>           pc++;

1765,1766d1749
<         h = hvalue(s2v(ra));
<         last = ((c-1)*LFIELDS_PER_FLUSH) + n;

1807d1789
<