LCOV - code coverage report
Current view: top level - external/lua/src - lvm.c (source / functions) Hit Total Coverage
Test: rapport Lines: 304 833 36.5 %
Date: 2021-12-10 16:22:55 Functions: 13 32 40.6 %
Branches: 170 1029 16.5 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            : ** $Id: lvm.c $
       3                 :            : ** Lua virtual machine
       4                 :            : ** See Copyright Notice in lua.h
       5                 :            : */
       6                 :            : 
       7                 :            : #define lvm_c
       8                 :            : #define LUA_CORE
       9                 :            : 
      10                 :            : #include "lprefix.h"
      11                 :            : 
      12                 :            : #include <float.h>
      13                 :            : #include <limits.h>
      14                 :            : #include <math.h>
      15                 :            : #include <stdio.h>
      16                 :            : #include <stdlib.h>
      17                 :            : #include <string.h>
      18                 :            : 
      19                 :        652 : #include "lua.h"
      20                 :            : 
      21                 :            : #include "ldebug.h"
      22                 :            : #include "ldo.h"
      23                 :            : #include "lfunc.h"
      24                 :            : #include "lgc.h"
      25                 :            : #include "lobject.h"
      26                 :            : #include "lopcodes.h"
      27                 :            : #include "lstate.h"
      28                 :            : #include "lstring.h"
      29                 :            : #include "ltable.h"
      30                 :            : #include "ltm.h"
      31                 :            : #include "lvm.h"
      32                 :            : 
      33                 :            : 
      34                 :            : /*
      35                 :            : ** By default, use jump tables in the main interpreter loop on gcc
      36                 :            : ** and compatible compilers.
      37                 :            : */
      38                 :            : #if !defined(LUA_USE_JUMPTABLE)
      39                 :            : #if defined(__GNUC__)
      40                 :            : #define LUA_USE_JUMPTABLE       1
      41                 :            : #else
      42                 :            : #define LUA_USE_JUMPTABLE       0
      43                 :            : #endif
      44                 :            : #endif
      45                 :            : 
      46                 :            : 
      47                 :            : 
      48                 :            : /* limit for table tag-method chains (to avoid infinite loops) */
      49                 :            : #define MAXTAGLOOP      2000
      50                 :            : 
      51                 :            : 
      52                 :            : /*
      53                 :            : ** 'l_intfitsf' checks whether a given integer is in the range that
      54                 :            : ** can be converted to a float without rounding. Used in comparisons.
      55                 :            : */
      56                 :            : 
      57                 :            : /* number of bits in the mantissa of a float */
      58                 :            : #define NBM             (l_floatatt(MANT_DIG))
      59                 :            : 
      60                 :            : /*
      61                 :            : ** Check whether some integers may not fit in a float, testing whether
      62                 :            : ** (maxinteger >> NBM) > 0. (That implies (1 << NBM) <= maxinteger.)
      63                 :            : ** (The shifts are done in parts, to avoid shifting by more than the size
      64                 :            : ** of an integer. In a worst case, NBM == 113 for long double and
      65                 :            : ** sizeof(long) == 32.)
      66                 :            : */
      67                 :            : #if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \
      68                 :            :         >> (NBM - (3 * (NBM / 4))))  >  0
      69                 :            : 
      70                 :            : /* limit for integers that fit in a float */
      71                 :            : #define MAXINTFITSF     ((lua_Unsigned)1 << NBM)
      72                 :            : 
      73                 :            : /* check whether 'i' is in the interval [-MAXINTFITSF, MAXINTFITSF] */
      74                 :            : #define l_intfitsf(i)   ((MAXINTFITSF + l_castS2U(i)) <= (2 * MAXINTFITSF))
      75                 :            : 
      76                 :            : #else  /* all integers fit in a float precisely */
      77                 :            : 
      78                 :            : #define l_intfitsf(i)   1
      79                 :            : 
      80                 :            : #endif
      81                 :            : 
      82                 :            : 
      83                 :            : /*
      84                 :            : ** Try to convert a value from string to a number value.
      85                 :            : ** If the value is not a string or is a string not representing
      86                 :            : ** a valid numeral (or if coercions from strings to numbers
      87                 :            : ** are disabled via macro 'cvt2num'), do not modify 'result'
      88                 :            : ** and return 0.
      89                 :            : */
      90                 :        559 : static int l_strton (const TValue *obj, TValue *result) {
      91                 :            :   lua_assert(obj != result);
      92         [ +  + ]:        559 :   if (!cvt2num(obj))  /* is object not a string? */
      93                 :        270 :     return 0;
      94                 :            :   else
      95         [ -  + ]:        289 :     return (luaO_str2num(svalue(obj), result) == vslen(obj) + 1);
      96                 :        559 : }
      97                 :            : 
      98                 :            : 
      99                 :            : /*
     100                 :            : ** Try to convert a value to a float. The float case is already handled
     101                 :            : ** by the macro 'tonumber'.
     102                 :            : */
     103                 :        661 : int luaV_tonumber_ (const TValue *obj, lua_Number *n) {
     104                 :            :   TValue v;
     105         [ +  + ]:        661 :   if (ttisinteger(obj)) {
     106                 :        115 :     *n = cast_num(ivalue(obj));
     107                 :        115 :     return 1;
     108                 :            :   }
     109         [ -  + ]:        546 :   else if (l_strton(obj, &v)) {  /* string coercible to number? */
     110         [ #  # ]:          0 :     *n = nvalue(&v);  /* convert result of 'luaO_str2num' to a float */
     111                 :          0 :     return 1;
     112                 :            :   }
     113                 :            :   else
     114                 :        546 :     return 0;  /* conversion failed */
     115                 :        661 : }
     116                 :            : 
     117                 :            : 
     118                 :            : /*
     119                 :            : ** try to convert a float to an integer, rounding according to 'mode'.
     120                 :            : */
     121                 :          0 : int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) {
     122                 :          0 :   lua_Number f = l_floor(n);
     123         [ #  # ]:          0 :   if (n != f) {  /* not an integral value? */
     124         [ #  # ]:          0 :     if (mode == F2Ieq) return 0;  /* fails if mode demands integral value */
     125         [ #  # ]:          0 :     else if (mode == F2Iceil)  /* needs ceil? */
     126                 :          0 :       f += 1;  /* convert floor to ceil (remember: n != f) */
     127                 :          0 :   }
     128   [ #  #  #  # ]:          0 :   return lua_numbertointeger(f, p);
     129                 :          0 : }
     130                 :            : 
     131                 :            : 
     132                 :            : /*
     133                 :            : ** try to convert a value to an integer, rounding according to 'mode',
     134                 :            : ** without string coercion.
     135                 :            : ** ("Fast track" handled by macro 'tointegerns'.)
     136                 :            : */
     137                 :         13 : int luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode) {
     138         [ -  + ]:         13 :   if (ttisfloat(obj))
     139                 :          0 :     return luaV_flttointeger(fltvalue(obj), p, mode);
     140         [ +  + ]:         13 :   else if (ttisinteger(obj)) {
     141                 :          8 :     *p = ivalue(obj);
     142                 :          8 :     return 1;
     143                 :            :   }
     144                 :            :   else
     145                 :          5 :     return 0;
     146                 :         13 : }
     147                 :            : 
     148                 :            : 
     149                 :            : /*
     150                 :            : ** try to convert a value to an integer.
     151                 :            : */
     152                 :         13 : int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode) {
     153                 :            :   TValue v;
     154         [ -  + ]:         13 :   if (l_strton(obj, &v))  /* does 'obj' point to a numerical string? */
     155                 :          0 :     obj = &v;  /* change it to point to its corresponding number */
     156                 :         13 :   return luaV_tointegerns(obj, p, mode);
     157                 :            : }
     158                 :            : 
     159                 :            : 
     160                 :            : /*
     161                 :            : ** Try to convert a 'for' limit to an integer, preserving the semantics
     162                 :            : ** of the loop. Return true if the loop must not run; otherwise, '*p'
     163                 :            : ** gets the integer limit.
     164                 :            : ** (The following explanation assumes a positive step; it is valid for
     165                 :            : ** negative steps mutatis mutandis.)
     166                 :            : ** If the limit is an integer or can be converted to an integer,
     167                 :            : ** rounding down, that is the limit.
     168                 :            : ** Otherwise, check whether the limit can be converted to a float. If
     169                 :            : ** the float is too large, clip it to LUA_MAXINTEGER.  If the float
     170                 :            : ** is too negative, the loop should not run, because any initial
     171                 :            : ** integer value is greater than such limit; so, the function returns
     172                 :            : ** true to signal that. (For this latter case, no integer limit would be
     173                 :            : ** correct; even a limit of LUA_MININTEGER would run the loop once for
     174                 :            : ** an initial value equal to LUA_MININTEGER.)
     175                 :            : */
     176                 :          8 : static int forlimit (lua_State *L, lua_Integer init, const TValue *lim,
     177                 :            :                                    lua_Integer *p, lua_Integer step) {
     178         [ +  - ]:          8 :   if (!luaV_tointeger(lim, p, (step < 0 ? F2Iceil : F2Ifloor))) {
     179                 :            :     /* not coercible to in integer */
     180                 :            :     lua_Number flim;  /* try to convert to float */
     181   [ #  #  #  # ]:          0 :     if (!tonumber(lim, &flim)) /* cannot convert to float? */
     182                 :          0 :       luaG_forerror(L, lim, "limit");
     183                 :            :     /* else 'flim' is a float out of integer bounds */
     184         [ #  # ]:          0 :     if (luai_numlt(0, flim)) {  /* if it is positive, it is too large */
     185         [ #  # ]:          0 :       if (step < 0) return 1;  /* initial value must be less than it */
     186                 :          0 :       *p = LUA_MAXINTEGER;  /* truncate */
     187                 :          0 :     }
     188                 :            :     else {  /* it is less than min integer */
     189         [ #  # ]:          0 :       if (step > 0) return 1;  /* initial value must be greater than it */
     190                 :          0 :       *p = LUA_MININTEGER;  /* truncate */
     191                 :            :     }
     192                 :          0 :   }
     193         [ +  - ]:          8 :   return (step > 0 ? init > *p : init < *p);  /* not to run? */
     194                 :          8 : }
     195                 :            : 
     196                 :            : 
     197                 :            : /*
     198                 :            : ** Prepare a numerical for loop (opcode OP_FORPREP).
     199                 :            : ** Return true to skip the loop. Otherwise,
     200                 :            : ** after preparation, stack will be as follows:
     201                 :            : **   ra : internal index (safe copy of the control variable)
     202                 :            : **   ra + 1 : loop counter (integer loops) or limit (float loops)
     203                 :            : **   ra + 2 : step
     204                 :            : **   ra + 3 : control variable
     205                 :            : */
     206                 :          8 : static int forprep (lua_State *L, StkId ra) {
     207                 :          8 :   TValue *pinit = s2v(ra);
     208                 :          8 :   TValue *plimit = s2v(ra + 1);
     209                 :          8 :   TValue *pstep = s2v(ra + 2);
     210   [ +  -  -  + ]:          8 :   if (ttisinteger(pinit) && ttisinteger(pstep)) { /* integer loop? */
     211                 :          8 :     lua_Integer init = ivalue(pinit);
     212                 :          8 :     lua_Integer step = ivalue(pstep);
     213                 :            :     lua_Integer limit;
     214         [ -  + ]:          8 :     if (step == 0)
     215                 :          0 :       luaG_runerror(L, "'for' step is zero");
     216                 :          8 :     setivalue(s2v(ra + 3), init);  /* control variable */
     217         [ -  + ]:          8 :     if (forlimit(L, init, plimit, &limit, step))
     218                 :          0 :       return 1;  /* skip the loop */
     219                 :            :     else {  /* prepare loop counter */
     220                 :            :       lua_Unsigned count;
     221         [ +  - ]:          8 :       if (step > 0) {  /* ascending loop? */
     222                 :          8 :         count = l_castS2U(limit) - l_castS2U(init);
     223         [ +  - ]:          8 :         if (step != 1)  /* avoid division in the too common case */
     224                 :          0 :           count /= l_castS2U(step);
     225                 :          8 :       }
     226                 :            :       else {  /* step < 0; descending loop */
     227                 :          0 :         count = l_castS2U(init) - l_castS2U(limit);
     228                 :            :         /* 'step+1' avoids negating 'mininteger' */
     229                 :          0 :         count /= l_castS2U(-(step + 1)) + 1u;
     230                 :            :       }
     231                 :            :       /* store the counter in place of the limit (which won't be
     232                 :            :          needed anymore) */
     233                 :          8 :       setivalue(plimit, l_castU2S(count));
     234                 :            :     }
     235                 :          8 :   }
     236                 :            :   else {  /* try making all values floats */
     237                 :            :     lua_Number init; lua_Number limit; lua_Number step;
     238   [ #  #  #  # ]:          0 :     if (unlikely(!tonumber(plimit, &limit)))
     239                 :          0 :       luaG_forerror(L, plimit, "limit");
     240   [ #  #  #  # ]:          0 :     if (unlikely(!tonumber(pstep, &step)))
     241                 :          0 :       luaG_forerror(L, pstep, "step");
     242   [ #  #  #  # ]:          0 :     if (unlikely(!tonumber(pinit, &init)))
     243                 :          0 :       luaG_forerror(L, pinit, "initial value");
     244         [ #  # ]:          0 :     if (step == 0)
     245                 :          0 :       luaG_runerror(L, "'for' step is zero");
     246   [ #  #  #  # ]:          0 :     if (luai_numlt(0, step) ? luai_numlt(limit, init)
     247                 :          0 :                             : luai_numlt(init, limit))
     248                 :          0 :       return 1;  /* skip the loop */
     249                 :            :     else {
     250                 :            :       /* make sure internal values are all floats */
     251                 :          0 :       setfltvalue(plimit, limit);
     252                 :          0 :       setfltvalue(pstep, step);
     253                 :          0 :       setfltvalue(s2v(ra), init);  /* internal index */
     254                 :          0 :       setfltvalue(s2v(ra + 3), init);  /* control variable */
     255                 :            :     }
     256                 :            :   }
     257                 :          8 :   return 0;
     258                 :          8 : }
     259                 :            : 
     260                 :            : 
     261                 :            : /*
     262                 :            : ** Execute a step of a float numerical for loop, returning
     263                 :            : ** true iff the loop must continue. (The integer case is
     264                 :            : ** written online with opcode OP_FORLOOP, for performance.)
     265                 :            : */
     266                 :          0 : static int floatforloop (StkId ra) {
     267                 :          0 :   lua_Number step = fltvalue(s2v(ra + 2));
     268                 :          0 :   lua_Number limit = fltvalue(s2v(ra + 1));
     269                 :          0 :   lua_Number idx = fltvalue(s2v(ra));  /* internal index */
     270                 :          0 :   idx = luai_numadd(L, idx, step);  /* increment index */
     271   [ #  #  #  # ]:          0 :   if (luai_numlt(0, step) ? luai_numle(idx, limit)
     272                 :          0 :                           : luai_numle(limit, idx)) {
     273                 :          0 :     chgfltvalue(s2v(ra), idx);  /* update internal index */
     274                 :          0 :     setfltvalue(s2v(ra + 3), idx);  /* and control variable */
     275                 :          0 :     return 1;  /* jump back */
     276                 :            :   }
     277                 :            :   else
     278                 :          0 :     return 0;  /* finish the loop */
     279                 :          0 : }
     280                 :            : 
     281                 :            : 
     282                 :            : /*
     283                 :            : ** Finish the table access 'val = t[key]'.
     284                 :            : ** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to
     285                 :            : ** t[k] entry (which must be empty).
     286                 :            : */
     287                 :      11368 : void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
     288                 :            :                       const TValue *slot) {
     289                 :            :   int loop;  /* counter to avoid infinite loops */
     290                 :            :   const TValue *tm;  /* metamethod */
     291         [ +  - ]:      11416 :   for (loop = 0; loop < MAXTAGLOOP; loop++) {
     292         [ +  + ]:      11416 :     if (slot == NULL) {  /* 't' is not a table? */
     293                 :            :       lua_assert(!ttistable(t));
     294                 :         25 :       tm = luaT_gettmbyobj(L, t, TM_INDEX);
     295         [ +  + ]:         25 :       if (unlikely(notm(tm)))
     296                 :          1 :         luaG_typeerror(L, t, "index");  /* no metamethod */
     297                 :            :       /* else will try the metamethod */
     298                 :         24 :     }
     299                 :            :     else {  /* 't' is a table */
     300                 :            :       lua_assert(isempty(slot));
     301   [ -  +  #  # ]:      11391 :       tm = fasttm(L, hvalue(t)->metatable, TM_INDEX);  /* table's metamethod */
     302         [ -  + ]:      11391 :       if (tm == NULL) {  /* no metamethod? */
     303                 :      11391 :         setnilvalue(s2v(val));  /* result is nil */
     304                 :      11391 :         return;
     305                 :            :       }
     306                 :            :       /* else will try the metamethod */
     307                 :            :     }
     308         [ +  - ]:         24 :     if (ttisfunction(tm)) {  /* is metamethod a function? */
     309                 :          0 :       luaT_callTMres(L, tm, t, key, val);  /* call it */
     310                 :          0 :       return;
     311                 :            :     }
     312                 :         24 :     t = tm;  /* else try to access 'tm[key]' */
     313   [ -  +  +  + ]:         24 :     if (luaV_fastget(L, t, key, slot, luaH_get)) {  /* fast track? */
     314                 :         24 :       setobj2s(L, val, slot);  /* done */
     315                 :         24 :       return;
     316                 :            :     }
     317                 :            :     /* else repeat (tail call 'luaV_finishget') */
     318                 :         48 :   }
     319                 :          0 :   luaG_runerror(L, "'__index' chain too long; possible loop");
     320                 :      11415 : }
     321                 :            : 
     322                 :            : 
     323                 :            : /*
     324                 :            : ** Finish a table assignment 't[key] = val'.
     325                 :            : ** If 'slot' is NULL, 't' is not a table.  Otherwise, 'slot' points
     326                 :            : ** to the entry 't[key]', or to a value with an absent key if there
     327                 :            : ** is no such entry.  (The value at 'slot' must be empty, otherwise
     328                 :            : ** 'luaV_fastget' would have done the job.)
     329                 :            : */
     330                 :     155191 : void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
     331                 :            :                      TValue *val, const TValue *slot) {
     332                 :            :   int loop;  /* counter to avoid infinite loops */
     333         [ +  - ]:     155191 :   for (loop = 0; loop < MAXTAGLOOP; loop++) {
     334                 :            :     const TValue *tm;  /* '__newindex' metamethod */
     335         [ +  - ]:     155191 :     if (slot != NULL) {  /* is 't' a table? */
     336                 :     155191 :       Table *h = hvalue(t);  /* save 't' table */
     337                 :            :       lua_assert(isempty(slot));  /* slot must be empty */
     338   [ -  +  #  # ]:     155191 :       tm = fasttm(L, h->metatable, TM_NEWINDEX);  /* get metamethod */
     339         [ -  + ]:     155191 :       if (tm == NULL) {  /* no metamethod? */
     340         [ -  + ]:     155191 :         if (isabstkey(slot))  /* no previous entry? */
     341                 :     155191 :           slot = luaH_newkey(L, h, key);  /* create one */
     342                 :            :         /* no metamethod and (now) there is an entry with given key */
     343                 :     155191 :         setobj2t(L, cast(TValue *, slot), val);  /* set its new value */
     344                 :     155191 :         invalidateTMcache(h);
     345   [ +  +  -  +  :     155191 :         luaC_barrierback(L, obj2gco(h), val);
                   #  # ]
     346                 :     155191 :         return;
     347                 :            :       }
     348                 :            :       /* else will try the metamethod */
     349                 :          0 :     }
     350                 :            :     else {  /* not a table; check metamethod */
     351                 :          0 :       tm = luaT_gettmbyobj(L, t, TM_NEWINDEX);
     352         [ #  # ]:          0 :       if (unlikely(notm(tm)))
     353                 :          0 :         luaG_typeerror(L, t, "index");
     354                 :            :     }
     355                 :            :     /* try the metamethod */
     356         [ #  # ]:          0 :     if (ttisfunction(tm)) {
     357                 :          0 :       luaT_callTM(L, tm, t, key, val);
     358                 :          0 :       return;
     359                 :            :     }
     360                 :          0 :     t = tm;  /* else repeat assignment over 'tm' */
     361   [ #  #  #  # ]:          0 :     if (luaV_fastget(L, t, key, slot, luaH_get)) {
     362   [ #  #  #  #  :          0 :       luaV_finishfastset(L, t, slot, val);
                   #  # ]
     363                 :          0 :       return;  /* done */
     364                 :            :     }
     365                 :            :     /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */
     366                 :          0 :   }
     367                 :          0 :   luaG_runerror(L, "'__newindex' chain too long; possible loop");
     368                 :     155191 : }
     369                 :            : 
     370                 :            : 
     371                 :            : /*
     372                 :            : ** Compare two strings 'ls' x 'rs', returning an integer less-equal-
     373                 :            : ** -greater than zero if 'ls' is less-equal-greater than 'rs'.
     374                 :            : ** The code is a little tricky because it allows '\0' in the strings
     375                 :            : ** and it uses 'strcoll' (to respect locales) for each segments
     376                 :            : ** of the strings.
     377                 :            : */
     378                 :          0 : static int l_strcmp (const TString *ls, const TString *rs) {
     379                 :          0 :   const char *l = getstr(ls);
     380         [ #  # ]:          0 :   size_t ll = tsslen(ls);
     381                 :          0 :   const char *r = getstr(rs);
     382         [ #  # ]:          0 :   size_t lr = tsslen(rs);
     383                 :          0 :   for (;;) {  /* for each segment */
     384                 :          0 :     int temp = strcoll(l, r);
     385         [ #  # ]:          0 :     if (temp != 0)  /* not equal? */
     386                 :          0 :       return temp;  /* done */
     387                 :            :     else {  /* strings are equal up to a '\0' */
     388                 :          0 :       size_t len = strlen(l);  /* index of first '\0' in both strings */
     389         [ #  # ]:          0 :       if (len == lr)  /* 'rs' is finished? */
     390                 :          0 :         return (len == ll) ? 0 : 1;  /* check 'ls' */
     391         [ #  # ]:          0 :       else if (len == ll)  /* 'ls' is finished? */
     392                 :          0 :         return -1;  /* 'ls' is less than 'rs' ('rs' is not finished) */
     393                 :            :       /* both strings longer than 'len'; go on comparing after the '\0' */
     394                 :          0 :       len++;
     395                 :          0 :       l += len; ll -= len; r += len; lr -= len;
     396                 :            :     }
     397                 :            :   }
     398                 :          0 : }
     399                 :            : 
     400                 :            : 
     401                 :            : /*
     402                 :            : ** Check whether integer 'i' is less than float 'f'. If 'i' has an
     403                 :            : ** exact representation as a float ('l_intfitsf'), compare numbers as
     404                 :            : ** floats. Otherwise, use the equivalence 'i < f <=> i < ceil(f)'.
     405                 :            : ** If 'ceil(f)' is out of integer range, either 'f' is greater than
     406                 :            : ** all integers or less than all integers.
     407                 :            : ** (The test with 'l_intfitsf' is only for performance; the else
     408                 :            : ** case is correct for all values, but it is slow due to the conversion
     409                 :            : ** from float to int.)
     410                 :            : ** When 'f' is NaN, comparisons must result in false.
     411                 :            : */
     412                 :          0 : static int LTintfloat (lua_Integer i, lua_Number f) {
     413         [ #  # ]:          0 :   if (l_intfitsf(i))
     414                 :          0 :     return luai_numlt(cast_num(i), f);  /* compare them as floats */
     415                 :            :   else {  /* i < f <=> i < ceil(f) */
     416                 :            :     lua_Integer fi;
     417         [ #  # ]:          0 :     if (luaV_flttointeger(f, &fi, F2Iceil))  /* fi = ceil(f) */
     418                 :          0 :       return i < fi;   /* compare them as integers */
     419                 :            :     else  /* 'f' is either greater or less than all integers */
     420                 :          0 :       return f > 0;  /* greater? */
     421                 :            :   }
     422                 :          0 : }
     423                 :            : 
     424                 :            : 
     425                 :            : /*
     426                 :            : ** Check whether integer 'i' is less than or equal to float 'f'.
     427                 :            : ** See comments on previous function.
     428                 :            : */
     429                 :          0 : static int LEintfloat (lua_Integer i, lua_Number f) {
     430         [ #  # ]:          0 :   if (l_intfitsf(i))
     431                 :          0 :     return luai_numle(cast_num(i), f);  /* compare them as floats */
     432                 :            :   else {  /* i <= f <=> i <= floor(f) */
     433                 :            :     lua_Integer fi;
     434         [ #  # ]:          0 :     if (luaV_flttointeger(f, &fi, F2Ifloor))  /* fi = floor(f) */
     435                 :          0 :       return i <= fi;   /* compare them as integers */
     436                 :            :     else  /* 'f' is either greater or less than all integers */
     437                 :          0 :       return f > 0;  /* greater? */
     438                 :            :   }
     439                 :          0 : }
     440                 :            : 
     441                 :            : 
     442                 :            : /*
     443                 :            : ** Check whether float 'f' is less than integer 'i'.
     444                 :            : ** See comments on previous function.
     445                 :            : */
     446                 :          0 : static int LTfloatint (lua_Number f, lua_Integer i) {
     447         [ #  # ]:          0 :   if (l_intfitsf(i))
     448                 :          0 :     return luai_numlt(f, cast_num(i));  /* compare them as floats */
     449                 :            :   else {  /* f < i <=> floor(f) < i */
     450                 :            :     lua_Integer fi;
     451         [ #  # ]:          0 :     if (luaV_flttointeger(f, &fi, F2Ifloor))  /* fi = floor(f) */
     452                 :          0 :       return fi < i;   /* compare them as integers */
     453                 :            :     else  /* 'f' is either greater or less than all integers */
     454                 :          0 :       return f < 0;  /* less? */
     455                 :            :   }
     456                 :          0 : }
     457                 :            : 
     458                 :            : 
     459                 :            : /*
     460                 :            : ** Check whether float 'f' is less than or equal to integer 'i'.
     461                 :            : ** See comments on previous function.
     462                 :            : */
     463                 :          0 : static int LEfloatint (lua_Number f, lua_Integer i) {
     464         [ #  # ]:          0 :   if (l_intfitsf(i))
     465                 :          0 :     return luai_numle(f, cast_num(i));  /* compare them as floats */
     466                 :            :   else {  /* f <= i <=> ceil(f) <= i */
     467                 :            :     lua_Integer fi;
     468         [ #  # ]:          0 :     if (luaV_flttointeger(f, &fi, F2Iceil))  /* fi = ceil(f) */
     469                 :          0 :       return fi <= i;   /* compare them as integers */
     470                 :            :     else  /* 'f' is either greater or less than all integers */
     471                 :          0 :       return f < 0;  /* less? */
     472                 :            :   }
     473                 :          0 : }
     474                 :            : 
     475                 :            : 
     476                 :            : /*
     477                 :            : ** Return 'l < r', for numbers.
     478                 :            : */
     479                 :          0 : static int LTnum (const TValue *l, const TValue *r) {
     480                 :            :   lua_assert(ttisnumber(l) && ttisnumber(r));
     481         [ #  # ]:          0 :   if (ttisinteger(l)) {
     482                 :          0 :     lua_Integer li = ivalue(l);
     483         [ #  # ]:          0 :     if (ttisinteger(r))
     484                 :          0 :       return li < ivalue(r);  /* both are integers */
     485                 :            :     else  /* 'l' is int and 'r' is float */
     486                 :          0 :       return LTintfloat(li, fltvalue(r));  /* l < r ? */
     487                 :            :   }
     488                 :            :   else {
     489                 :          0 :     lua_Number lf = fltvalue(l);  /* 'l' must be float */
     490         [ #  # ]:          0 :     if (ttisfloat(r))
     491                 :          0 :       return luai_numlt(lf, fltvalue(r));  /* both are float */
     492                 :            :     else  /* 'l' is float and 'r' is int */
     493                 :          0 :       return LTfloatint(lf, ivalue(r));
     494                 :            :   }
     495                 :          0 : }
     496                 :            : 
     497                 :            : 
     498                 :            : /*
     499                 :            : ** Return 'l <= r', for numbers.
     500                 :            : */
     501                 :          0 : static int LEnum (const TValue *l, const TValue *r) {
     502                 :            :   lua_assert(ttisnumber(l) && ttisnumber(r));
     503         [ #  # ]:          0 :   if (ttisinteger(l)) {
     504                 :          0 :     lua_Integer li = ivalue(l);
     505         [ #  # ]:          0 :     if (ttisinteger(r))
     506                 :          0 :       return li <= ivalue(r);  /* both are integers */
     507                 :            :     else  /* 'l' is int and 'r' is float */
     508                 :          0 :       return LEintfloat(li, fltvalue(r));  /* l <= r ? */
     509                 :            :   }
     510                 :            :   else {
     511                 :          0 :     lua_Number lf = fltvalue(l);  /* 'l' must be float */
     512         [ #  # ]:          0 :     if (ttisfloat(r))
     513                 :          0 :       return luai_numle(lf, fltvalue(r));  /* both are float */
     514                 :            :     else  /* 'l' is float and 'r' is int */
     515                 :          0 :       return LEfloatint(lf, ivalue(r));
     516                 :            :   }
     517                 :          0 : }
     518                 :            : 
     519                 :            : 
     520                 :            : /*
     521                 :            : ** return 'l < r' for non-numbers.
     522                 :            : */
     523                 :          0 : static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) {
     524                 :            :   lua_assert(!ttisnumber(l) || !ttisnumber(r));
     525   [ #  #  #  # ]:          0 :   if (ttisstring(l) && ttisstring(r))  /* both are strings? */
     526                 :          0 :     return l_strcmp(tsvalue(l), tsvalue(r)) < 0;
     527                 :            :   else
     528                 :          0 :     return luaT_callorderTM(L, l, r, TM_LT);
     529                 :          0 : }
     530                 :            : 
     531                 :            : 
     532                 :            : /*
     533                 :            : ** Main operation less than; return 'l < r'.
     534                 :            : */
     535                 :          0 : int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
     536   [ #  #  #  # ]:          0 :   if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */
     537                 :          0 :     return LTnum(l, r);
     538                 :          0 :   else return lessthanothers(L, l, r);
     539                 :          0 : }
     540                 :            : 
     541                 :            : 
     542                 :            : /*
     543                 :            : ** return 'l <= r' for non-numbers.
     544                 :            : */
     545                 :          0 : static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) {
     546                 :            :   lua_assert(!ttisnumber(l) || !ttisnumber(r));
     547   [ #  #  #  # ]:          0 :   if (ttisstring(l) && ttisstring(r))  /* both are strings? */
     548                 :          0 :     return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;
     549                 :            :   else
     550                 :          0 :     return luaT_callorderTM(L, l, r, TM_LE);
     551                 :          0 : }
     552                 :            : 
     553                 :            : 
     554                 :            : /*
     555                 :            : ** Main operation less than or equal to; return 'l <= r'.
     556                 :            : */
     557                 :          0 : int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
     558   [ #  #  #  # ]:          0 :   if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */
     559                 :          0 :     return LEnum(l, r);
     560                 :          0 :   else return lessequalothers(L, l, r);
     561                 :          0 : }
     562                 :            : 
     563                 :            : 
     564                 :            : /*
     565                 :            : ** Main operation for equality of Lua values; return 't1 == t2'.
     566                 :            : ** L == NULL means raw equality (no metamethods)
     567                 :            : */
     568                 :        866 : int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
     569                 :            :   const TValue *tm;
     570         [ +  + ]:        866 :   if (ttypetag(t1) != ttypetag(t2)) {  /* not the same variant? */
     571   [ -  +  #  # ]:         37 :     if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER)
     572                 :         37 :       return 0;  /* only numbers can be equal with different variants */
     573                 :            :     else {  /* two numbers with different variants */
     574                 :            :       lua_Integer i1, i2;  /* compare them as integers */
     575   [ #  #  #  #  :          0 :       return (tointegerns(t1, &i1) && tointegerns(t2, &i2) && i1 == i2);
             #  #  #  # ]
     576                 :            :     }
     577                 :            :   }
     578                 :            :   /* values have same type and same variant */
     579   [ +  -  -  -  :        829 :   switch (ttypetag(t1)) {
          -  -  +  -  -  
                      + ]
     580                 :        100 :     case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1;
     581                 :          0 :     case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2));
     582                 :          0 :     case LUA_VNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
     583                 :          0 :     case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
     584                 :          0 :     case LUA_VLCF: return fvalue(t1) == fvalue(t2);
     585                 :        309 :     case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
     586                 :          0 :     case LUA_VLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
     587                 :            :     case LUA_VUSERDATA: {
     588         [ #  # ]:          0 :       if (uvalue(t1) == uvalue(t2)) return 1;
     589         [ #  # ]:          0 :       else if (L == NULL) return 0;
     590   [ #  #  #  # ]:          0 :       tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
     591         [ #  # ]:          0 :       if (tm == NULL)
     592   [ #  #  #  # ]:          0 :         tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
     593                 :          0 :       break;  /* will try TM */
     594                 :            :     }
     595                 :            :     case LUA_VTABLE: {
     596         [ -  + ]:        420 :       if (hvalue(t1) == hvalue(t2)) return 1;
     597         [ #  # ]:          0 :       else if (L == NULL) return 0;
     598   [ #  #  #  # ]:          0 :       tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
     599         [ #  # ]:          0 :       if (tm == NULL)
     600   [ #  #  #  # ]:          0 :         tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);
     601                 :          0 :       break;  /* will try TM */
     602                 :            :     }
     603                 :            :     default:
     604                 :          0 :       return gcvalue(t1) == gcvalue(t2);
     605                 :            :   }
     606         [ #  # ]:          0 :   if (tm == NULL)  /* no TM? */
     607                 :          0 :     return 0;  /* objects are different */
     608                 :            :   else {
     609                 :          0 :     luaT_callTMres(L, tm, t1, t2, L->top);  /* call TM */
     610         [ #  # ]:          0 :     return !l_isfalse(s2v(L->top));
     611                 :            :   }
     612                 :        866 : }
     613                 :            : 
     614                 :            : 
     615                 :            : /* macro used by 'luaV_concat' to ensure that element at 'o' is a string */
     616                 :            : #define tostring(L,o)  \
     617                 :            :         (ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))
     618                 :            : 
     619                 :            : #define isemptystr(o)   (ttisshrstring(o) && tsvalue(o)->shrlen == 0)
     620                 :            : 
     621                 :            : /* copy strings in stack from top - n up to top - 1 to buffer */
     622                 :        301 : static void copy2buff (StkId top, int n, char *buff) {
     623                 :        301 :   size_t tl = 0;  /* size already copied */
     624                 :        301 :   do {
     625         [ +  + ]:        606 :     size_t l = vslen(s2v(top - n));  /* length of string being copied */
     626                 :        606 :     memcpy(buff + tl, svalue(s2v(top - n)), l * sizeof(char));
     627                 :        606 :     tl += l;
     628         [ +  + ]:        606 :   } while (--n > 0);
     629                 :        301 : }
     630                 :            : 
     631                 :            : 
     632                 :            : /*
     633                 :            : ** Main operation for concatenation: concat 'total' values in the stack,
     634                 :            : ** from 'L->top - total' up to 'L->top - 1'.
     635                 :            : */
     636                 :       2674 : void luaV_concat (lua_State *L, int total) {
     637         [ +  + ]:       2674 :   if (total == 1)
     638                 :       2373 :     return;  /* "all" values already concatenated */
     639                 :        301 :   do {
     640                 :        301 :     StkId top = L->top;
     641                 :        301 :     int n = 2;  /* number of elements handled in this pass (at least 2) */
     642   [ +  +  +  - ]:        301 :     if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) ||
     643   [ -  +  #  # ]:        301 :         !tostring(L, s2v(top - 1)))
     644                 :          0 :       luaT_tryconcatTM(L);
     645   [ +  +  +  - ]:        301 :     else if (isemptystr(s2v(top - 1)))  /* second operand is empty? */
     646   [ #  #  #  # ]:          0 :       cast_void(tostring(L, s2v(top - 2)));  /* result is first operand */
     647   [ +  +  +  - ]:        301 :     else if (isemptystr(s2v(top - 2))) {  /* first operand is empty string? */
     648                 :          0 :       setobjs2s(L, top - 2, top - 1);  /* result is second op. */
     649                 :          0 :     }
     650                 :            :     else {
     651                 :            :       /* at least two non-empty string values; get as many as possible */
     652         [ +  + ]:        301 :       size_t tl = vslen(s2v(top - 1));
     653                 :            :       TString *ts;
     654                 :            :       /* collect total length and number of strings */
     655   [ +  +  +  +  :        911 :       for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
             -  +  +  + ]
     656         [ +  + ]:        305 :         size_t l = vslen(s2v(top - n - 1));
     657         [ +  - ]:        305 :         if (unlikely(l >= (MAX_SIZE/sizeof(char)) - tl))
     658                 :          0 :           luaG_runerror(L, "string length overflow");
     659                 :        305 :         tl += l;
     660                 :        305 :       }
     661         [ +  + ]:        301 :       if (tl <= LUAI_MAXSHORTLEN) {  /* is result a short string? */
     662                 :            :         char buff[LUAI_MAXSHORTLEN];
     663                 :         15 :         copy2buff(top, n, buff);  /* copy strings to buffer */
     664                 :         15 :         ts = luaS_newlstr(L, buff, tl);
     665                 :         15 :       }
     666                 :            :       else {  /* long string; copy strings directly to final result */
     667                 :        286 :         ts = luaS_createlngstrobj(L, tl);
     668                 :        286 :         copy2buff(top, n, getstr(ts));
     669                 :            :       }
     670                 :        301 :       setsvalue2s(L, top - n, ts);  /* create result */
     671                 :            :     }
     672                 :        301 :     total -= n-1;  /* got 'n' strings to create 1 new */
     673                 :        301 :     L->top -= n-1;  /* popped 'n' strings and pushed one */
     674         [ -  + ]:        301 :   } while (total > 1);  /* repeat until only 1 result left */
     675                 :       2674 : }
     676                 :            : 
     677                 :            : 
     678                 :            : /*
     679                 :            : ** Main operation 'ra = #rb'.
     680                 :            : */
     681                 :        141 : void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
     682                 :            :   const TValue *tm;
     683   [ +  +  -  - ]:        141 :   switch (ttypetag(rb)) {
     684                 :            :     case LUA_VTABLE: {
     685                 :        139 :       Table *h = hvalue(rb);
     686   [ +  +  -  + ]:        139 :       tm = fasttm(L, h->metatable, TM_LEN);
     687         [ -  + ]:        139 :       if (tm) break;  /* metamethod? break switch to call it */
     688                 :        139 :       setivalue(s2v(ra), luaH_getn(h));  /* else primitive len */
     689                 :        139 :       return;
     690                 :            :     }
     691                 :            :     case LUA_VSHRSTR: {
     692                 :          0 :       setivalue(s2v(ra), tsvalue(rb)->shrlen);
     693                 :          0 :       return;
     694                 :            :     }
     695                 :            :     case LUA_VLNGSTR: {
     696                 :          0 :       setivalue(s2v(ra), tsvalue(rb)->u.lnglen);
     697                 :          0 :       return;
     698                 :            :     }
     699                 :            :     default: {  /* try metamethod */
     700                 :          2 :       tm = luaT_gettmbyobj(L, rb, TM_LEN);
     701         [ -  + ]:          2 :       if (unlikely(notm(tm)))  /* no metamethod? */
     702                 :          2 :         luaG_typeerror(L, rb, "get length of");
     703                 :          0 :       break;
     704                 :            :     }
     705                 :            :   }
     706                 :          0 :   luaT_callTMres(L, tm, rb, rb, ra);
     707                 :        139 : }
     708                 :            : 
     709                 :            : 
     710                 :            : /*
     711                 :            : ** Integer division; return 'm // n', that is, floor(m/n).
     712                 :            : ** C division truncates its result (rounds towards zero).
     713                 :            : ** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer,
     714                 :            : ** otherwise 'floor(q) == trunc(q) - 1'.
     715                 :            : */
     716                 :          0 : lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) {
     717         [ #  # ]:          0 :   if (unlikely(l_castS2U(n) + 1u <= 1u)) {  /* special cases: -1 or 0 */
     718         [ #  # ]:          0 :     if (n == 0)
     719                 :          0 :       luaG_runerror(L, "attempt to divide by zero");
     720                 :          0 :     return intop(-, 0, m);   /* n==-1; avoid overflow with 0x80000...//-1 */
     721                 :            :   }
     722                 :            :   else {
     723                 :          0 :     lua_Integer q = m / n;  /* perform C division */
     724   [ #  #  #  # ]:          0 :     if ((m ^ n) < 0 && m % n != 0)  /* 'm/n' would be negative non-integer? */
     725                 :          0 :       q -= 1;  /* correct result for different rounding */
     726                 :          0 :     return q;
     727                 :            :   }
     728                 :          0 : }
     729                 :            : 
     730                 :            : 
     731                 :            : /*
     732                 :            : ** Integer modulus; return 'm % n'. (Assume that C '%' with
     733                 :            : ** negative operands follows C99 behavior. See previous comment
     734                 :            : ** about luaV_idiv.)
     735                 :            : */
     736                 :          0 : lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {
     737         [ #  # ]:          0 :   if (unlikely(l_castS2U(n) + 1u <= 1u)) {  /* special cases: -1 or 0 */
     738         [ #  # ]:          0 :     if (n == 0)
     739                 :          0 :       luaG_runerror(L, "attempt to perform 'n%%0'");
     740                 :          0 :     return 0;   /* m % -1 == 0; avoid overflow with 0x80000...%-1 */
     741                 :            :   }
     742                 :            :   else {
     743                 :          0 :     lua_Integer r = m % n;
     744   [ #  #  #  # ]:          0 :     if (r != 0 && (r ^ n) < 0)  /* 'm/n' would be non-integer negative? */
     745                 :          0 :       r += n;  /* correct result for different rounding */
     746                 :          0 :     return r;
     747                 :            :   }
     748                 :          0 : }
     749                 :            : 
     750                 :            : 
     751                 :            : /*
     752                 :            : ** Float modulus
     753                 :            : */
     754                 :          0 : lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
     755                 :            :   lua_Number r;
     756   [ #  #  #  #  :          0 :   luai_nummod(L, m, n, r);
                   #  # ]
     757                 :          0 :   return r;
     758                 :            : }
     759                 :            : 
     760                 :            : 
     761                 :            : /* number of bits in an integer */
     762                 :            : #define NBITS   cast_int(sizeof(lua_Integer) * CHAR_BIT)
     763                 :            : 
     764                 :            : /*
     765                 :            : ** Shift left operation. (Shift right just negates 'y'.)
     766                 :            : */
     767                 :            : #define luaV_shiftr(x,y)        luaV_shiftl(x,-(y))
     768                 :            : 
     769                 :          0 : lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
     770         [ #  # ]:          0 :   if (y < 0) {  /* shift right? */
     771         [ #  # ]:          0 :     if (y <= -NBITS) return 0;
     772                 :          0 :     else return intop(>>, x, -y);
     773                 :            :   }
     774                 :            :   else {  /* shift left */
     775         [ #  # ]:          0 :     if (y >= NBITS) return 0;
     776                 :          0 :     else return intop(<<, x, y);
     777                 :            :   }
     778                 :          0 : }
     779                 :            : 
     780                 :            : 
     781                 :            : /*
     782                 :            : ** create a new Lua closure, push it in the stack, and initialize
     783                 :            : ** its upvalues.
     784                 :            : */
     785                 :          0 : static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
     786                 :            :                          StkId ra) {
     787                 :          0 :   int nup = p->sizeupvalues;
     788                 :          0 :   Upvaldesc *uv = p->upvalues;
     789                 :            :   int i;
     790                 :          0 :   LClosure *ncl = luaF_newLclosure(L, nup);
     791                 :          0 :   ncl->p = p;
     792                 :          0 :   setclLvalue2s(L, ra, ncl);  /* anchor new closure in stack */
     793         [ #  # ]:          0 :   for (i = 0; i < nup; i++) {  /* fill in its upvalues */
     794         [ #  # ]:          0 :     if (uv[i].instack)  /* upvalue refers to local variable? */
     795                 :          0 :       ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);
     796                 :            :     else  /* get upvalue from enclosing function */
     797                 :          0 :       ncl->upvals[i] = encup[uv[i].idx];
     798   [ #  #  #  # ]:          0 :     luaC_objbarrier(L, ncl, ncl->upvals[i]);
     799                 :          0 :   }
     800                 :          0 : }
     801                 :            : 
     802                 :            : 
     803                 :            : /*
     804                 :            : ** finish execution of an opcode interrupted by a yield
     805                 :            : */
     806                 :          0 : void luaV_finishOp (lua_State *L) {
     807                 :          0 :   CallInfo *ci = L->ci;
     808                 :          0 :   StkId base = ci->func + 1;
     809                 :          0 :   Instruction inst = *(ci->u.l.savedpc - 1);  /* interrupted instruction */
     810                 :          0 :   OpCode op = GET_OPCODE(inst);
     811   [ #  #  #  #  :          0 :   switch (op) {  /* finish its execution */
                      # ]
     812                 :            :     case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
     813                 :          0 :       setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top);
     814                 :          0 :       break;
     815                 :            :     }
     816                 :            :     case OP_UNM: case OP_BNOT: case OP_LEN:
     817                 :            :     case OP_GETTABUP: case OP_GETTABLE: case OP_GETI:
     818                 :            :     case OP_GETFIELD: case OP_SELF: {
     819                 :          0 :       setobjs2s(L, base + GETARG_A(inst), --L->top);
     820                 :          0 :       break;
     821                 :            :     }
     822                 :            :     case OP_LT: case OP_LE:
     823                 :            :     case OP_LTI: case OP_LEI:
     824                 :            :     case OP_GTI: case OP_GEI:
     825                 :            :     case OP_EQ: {  /* note that 'OP_EQI'/'OP_EQK' cannot yield */
     826         [ #  # ]:          0 :       int res = !l_isfalse(s2v(L->top - 1));
     827                 :          0 :       L->top--;
     828                 :            : #if defined(LUA_COMPAT_LT_LE)
     829                 :            :       if (ci->callstatus & CIST_LEQ) {  /* "<=" using "<" instead? */
     830                 :            :         ci->callstatus ^= CIST_LEQ;  /* clear mark */
     831                 :            :         res = !res;  /* negate result */
     832                 :            :       }
     833                 :            : #endif
     834                 :            :       lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
     835         [ #  # ]:          0 :       if (res != GETARG_k(inst))  /* condition failed? */
     836                 :          0 :         ci->u.l.savedpc++;  /* skip jump instruction */
     837                 :          0 :       break;
     838                 :            :     }
     839                 :            :     case OP_CONCAT: {
     840                 :          0 :       StkId top = L->top - 1;  /* top when 'luaT_tryconcatTM' was called */
     841                 :          0 :       int a = GETARG_A(inst);      /* first element to concatenate */
     842                 :          0 :       int total = cast_int(top - 1 - (base + a));  /* yet to concatenate */
     843                 :          0 :       setobjs2s(L, top - 2, top);  /* put TM result in proper position */
     844                 :          0 :       L->top = top - 1;  /* top is one after last element (at top-2) */
     845                 :          0 :       luaV_concat(L, total);  /* concat them (may yield again) */
     846                 :          0 :       break;
     847                 :            :     }
     848                 :            :     default: {
     849                 :            :       /* only these other opcodes can yield */
     850                 :            :       lua_assert(op == OP_TFORCALL || op == OP_CALL ||
     851                 :            :            op == OP_TAILCALL || op == OP_SETTABUP || op == OP_SETTABLE ||
     852                 :            :            op == OP_SETI || op == OP_SETFIELD);
     853                 :          0 :       break;
     854                 :            :     }
     855                 :            :   }
     856                 :          0 : }
     857                 :            : 
     858                 :            : 
     859                 :            : 
     860                 :            : 
     861                 :            : /*
     862                 :            : ** {==================================================================
     863                 :            : ** Macros for arithmetic/bitwise/comparison opcodes in 'luaV_execute'
     864                 :            : ** ===================================================================
     865                 :            : */
     866                 :            : 
     867                 :            : #define l_addi(L,a,b)   intop(+, a, b)
     868                 :            : #define l_subi(L,a,b)   intop(-, a, b)
     869                 :            : #define l_muli(L,a,b)   intop(*, a, b)
     870                 :            : #define l_band(a,b)     intop(&, a, b)
     871                 :            : #define l_bor(a,b)      intop(|, a, b)
     872                 :            : #define l_bxor(a,b)     intop(^, a, b)
     873                 :            : 
     874                 :            : #define l_lti(a,b)      (a < b)
     875                 :            : #define l_lei(a,b)      (a <= b)
     876                 :            : #define l_gti(a,b)      (a > b)
     877                 :            : #define l_gei(a,b)      (a >= b)
     878                 :            : 
     879                 :            : 
     880                 :            : /*
     881                 :            : ** Arithmetic operations with immediate operands. 'iop' is the integer
     882                 :            : ** operation, 'fop' is the float operation.
     883                 :            : */
     884                 :            : #define op_arithI(L,iop,fop) {  \
     885                 :            :   TValue *v1 = vRB(i);  \
     886                 :            :   int imm = GETARG_sC(i);  \
     887                 :            :   if (ttisinteger(v1)) {  \
     888                 :            :     lua_Integer iv1 = ivalue(v1);  \
     889                 :            :     pc++; setivalue(s2v(ra), iop(L, iv1, imm));  \
     890                 :            :   }  \
     891                 :            :   else if (ttisfloat(v1)) {  \
     892                 :            :     lua_Number nb = fltvalue(v1);  \
     893                 :            :     lua_Number fimm = cast_num(imm);  \
     894                 :            :     pc++; setfltvalue(s2v(ra), fop(L, nb, fimm)); \
     895                 :            :   }}
     896                 :            : 
     897                 :            : 
     898                 :            : /*
     899                 :            : ** Auxiliary function for arithmetic operations over floats and others
     900                 :            : ** with two register operands.
     901                 :            : */
     902                 :            : #define op_arithf_aux(L,v1,v2,fop) {  \
     903                 :            :   lua_Number n1; lua_Number n2;  \
     904                 :            :   if (tonumberns(v1, n1) && tonumberns(v2, n2)) {  \
     905                 :            :     pc++; setfltvalue(s2v(ra), fop(L, n1, n2));  \
     906                 :            :   }}
     907                 :            : 
     908                 :            : 
     909                 :            : /*
     910                 :            : ** Arithmetic operations over floats and others with register operands.
     911                 :            : */
     912                 :            : #define op_arithf(L,fop) {  \
     913                 :            :   TValue *v1 = vRB(i);  \
     914                 :            :   TValue *v2 = vRC(i);  \
     915                 :            :   op_arithf_aux(L, v1, v2, fop); }
     916                 :            : 
     917                 :            : 
     918                 :            : /*
     919                 :            : ** Arithmetic operations with K operands for floats.
     920                 :            : */
     921                 :            : #define op_arithfK(L,fop) {  \
     922                 :            :   TValue *v1 = vRB(i);  \
     923                 :            :   TValue *v2 = KC(i);  \
     924                 :            :   op_arithf_aux(L, v1, v2, fop); }
     925                 :            : 
     926                 :            : 
     927                 :            : /*
     928                 :            : ** Arithmetic operations over integers and floats.
     929                 :            : */
     930                 :            : #define op_arith_aux(L,v1,v2,iop,fop) {  \
     931                 :            :   if (ttisinteger(v1) && ttisinteger(v2)) {  \
     932                 :            :     lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2);  \
     933                 :            :     pc++; setivalue(s2v(ra), iop(L, i1, i2));  \
     934                 :            :   }  \
     935                 :            :   else op_arithf_aux(L, v1, v2, fop); }
     936                 :            : 
     937                 :            : 
     938                 :            : /*
     939                 :            : ** Arithmetic operations with register operands.
     940                 :            : */
     941                 :            : #define op_arith(L,iop,fop) {  \
     942                 :            :   TValue *v1 = vRB(i);  \
     943                 :            :   TValue *v2 = vRC(i);  \
     944                 :            :   op_arith_aux(L, v1, v2, iop, fop); }
     945                 :            : 
     946                 :            : 
     947                 :            : /*
     948                 :            : ** Arithmetic operations with K operands.
     949                 :            : */
     950                 :            : #define op_arithK(L,iop,fop) {  \
     951                 :            :   TValue *v1 = vRB(i);  \
     952                 :            :   TValue *v2 = KC(i);  \
     953                 :            :   op_arith_aux(L, v1, v2, iop, fop); }
     954                 :            : 
     955                 :            : 
     956                 :            : /*
     957                 :            : ** Bitwise operations with constant operand.
     958                 :            : */
     959                 :            : #define op_bitwiseK(L,op) {  \
     960                 :            :   TValue *v1 = vRB(i);  \
     961                 :            :   TValue *v2 = KC(i);  \
     962                 :            :   lua_Integer i1;  \
     963                 :            :   lua_Integer i2 = ivalue(v2);  \
     964                 :            :   if (tointegerns(v1, &i1)) {  \
     965                 :            :     pc++; setivalue(s2v(ra), op(i1, i2));  \
     966                 :            :   }}
     967                 :            : 
     968                 :            : 
     969                 :            : /*
     970                 :            : ** Bitwise operations with register operands.
     971                 :            : */
     972                 :            : #define op_bitwise(L,op) {  \
     973                 :            :   TValue *v1 = vRB(i);  \
     974                 :            :   TValue *v2 = vRC(i);  \
     975                 :            :   lua_Integer i1; lua_Integer i2;  \
     976                 :            :   if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) {  \
     977                 :            :     pc++; setivalue(s2v(ra), op(i1, i2));  \
     978                 :            :   }}
     979                 :            : 
     980                 :            : 
     981                 :            : /*
     982                 :            : ** Order operations with register operands. 'opn' actually works
     983                 :            : ** for all numbers, but the fast track improves performance for
     984                 :            : ** integers.
     985                 :            : */
     986                 :            : #define op_order(L,opi,opn,other) {  \
     987                 :            :         int cond;  \
     988                 :            :         TValue *rb = vRB(i);  \
     989                 :            :         if (ttisinteger(s2v(ra)) && ttisinteger(rb)) {  \
     990                 :            :           lua_Integer ia = ivalue(s2v(ra));  \
     991                 :            :           lua_Integer ib = ivalue(rb);  \
     992                 :            :           cond = opi(ia, ib);  \
     993                 :            :         }  \
     994                 :            :         else if (ttisnumber(s2v(ra)) && ttisnumber(rb))  \
     995                 :            :           cond = opn(s2v(ra), rb);  \
     996                 :            :         else  \
     997                 :            :           Protect(cond = other(L, s2v(ra), rb));  \
     998                 :            :         docondjump(); }
     999                 :            : 
    1000                 :            : 
    1001                 :            : /*
    1002                 :            : ** Order operations with immediate operand. (Immediate operand is
    1003                 :            : ** always small enough to have an exact representation as a float.)
    1004                 :            : */
    1005                 :            : #define op_orderI(L,opi,opf,inv,tm) {  \
    1006                 :            :         int cond;  \
    1007                 :            :         int im = GETARG_sB(i);  \
    1008                 :            :         if (ttisinteger(s2v(ra)))  \
    1009                 :            :           cond = opi(ivalue(s2v(ra)), im);  \
    1010                 :            :         else if (ttisfloat(s2v(ra))) {  \
    1011                 :            :           lua_Number fa = fltvalue(s2v(ra));  \
    1012                 :            :           lua_Number fim = cast_num(im);  \
    1013                 :            :           cond = opf(fa, fim);  \
    1014                 :            :         }  \
    1015                 :            :         else {  \
    1016                 :            :           int isf = GETARG_C(i);  \
    1017                 :            :           Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm));  \
    1018                 :            :         }  \
    1019                 :            :         docondjump(); }
    1020                 :            : 
    1021                 :            : /* }================================================================== */
    1022                 :            : 
    1023                 :            : 
    1024                 :            : /*
    1025                 :            : ** {==================================================================
    1026                 :            : ** Function 'luaV_execute': main interpreter loop
    1027                 :            : ** ===================================================================
    1028                 :            : */
    1029                 :            : 
    1030                 :            : /*
    1031                 :            : ** some macros for common tasks in 'luaV_execute'
    1032                 :            : */
    1033                 :            : 
    1034                 :            : 
    1035                 :            : #define RA(i)   (base+GETARG_A(i))
    1036                 :            : #define RB(i)   (base+GETARG_B(i))
    1037                 :            : #define vRB(i)  s2v(RB(i))
    1038                 :            : #define KB(i)   (k+GETARG_B(i))
    1039                 :            : #define RC(i)   (base+GETARG_C(i))
    1040                 :            : #define vRC(i)  s2v(RC(i))
    1041                 :            : #define KC(i)   (k+GETARG_C(i))
    1042                 :            : #define RKC(i)  ((TESTARG_k(i)) ? k + GETARG_C(i) : s2v(base + GETARG_C(i)))
    1043                 :            : 
    1044                 :            : 
    1045                 :            : 
    1046                 :            : #define updatetrap(ci)  (trap = ci->u.l.trap)
    1047                 :            : 
    1048                 :            : #define updatebase(ci)  (base = ci->func + 1)
    1049                 :            : 
    1050                 :            : 
    1051                 :            : #define updatestack(ci) { if (trap) { updatebase(ci); ra = RA(i); } }
    1052                 :            : 
    1053                 :            : 
    1054                 :            : /*
    1055                 :            : ** Execute a jump instruction. The 'updatetrap' allows signals to stop
    1056                 :            : ** tight loops. (Without it, the local copy of 'trap' could never change.)
    1057                 :            : */
    1058                 :            : #define dojump(ci,i,e)  { pc += GETARG_sJ(i) + e; updatetrap(ci); }
    1059                 :            : 
    1060                 :            : 
    1061                 :            : /* for test instructions, execute the jump instruction that follows it */
    1062                 :            : #define donextjump(ci)  { Instruction ni = *pc; dojump(ci, ni, 1); }
    1063                 :            : 
    1064                 :            : /*
    1065                 :            : ** do a conditional jump: skip next instruction if 'cond' is not what
    1066                 :            : ** was expected (parameter 'k'), else do next instruction, which must
    1067                 :            : ** be a jump.
    1068                 :            : */
    1069                 :            : #define docondjump()    if (cond != GETARG_k(i)) pc++; else donextjump(ci);
    1070                 :            : 
    1071                 :            : 
    1072                 :            : /*
    1073                 :            : ** Correct global 'pc'.
    1074                 :            : */
    1075                 :            : #define savepc(L)       (ci->u.l.savedpc = pc)
    1076                 :            : 
    1077                 :            : 
    1078                 :            : /*
    1079                 :            : ** Whenever code can raise errors, the global 'pc' and the global
    1080                 :            : ** 'top' must be correct to report occasional errors.
    1081                 :            : */
    1082                 :            : #define savestate(L,ci)         (savepc(L), L->top = ci->top)
    1083                 :            : 
    1084                 :            : 
    1085                 :            : /*
    1086                 :            : ** Protect code that, in general, can raise errors, reallocate the
    1087                 :            : ** stack, and change the hooks.
    1088                 :            : */
    1089                 :            : #define Protect(exp)  (savestate(L,ci), (exp), updatetrap(ci))
    1090                 :            : 
    1091                 :            : /* special version that does not change the top */
    1092                 :            : #define ProtectNT(exp)  (savepc(L), (exp), updatetrap(ci))
    1093                 :            : 
    1094                 :            : /*
    1095                 :            : ** Protect code that can only raise errors. (That is, it cannnot change
    1096                 :            : ** the stack or hooks.)
    1097                 :            : */
    1098                 :            : #define halfProtect(exp)  (savestate(L,ci), (exp))
    1099                 :            : 
    1100                 :            : /* 'c' is the limit of live values in the stack */
    1101                 :            : #define checkGC(L,c)  \
    1102                 :            :         { luaC_condGC(L, (savepc(L), L->top = (c)), \
    1103                 :            :                          updatetrap(ci)); \
    1104                 :            :            luai_threadyield(L); }
    1105                 :            : 
    1106                 :            : 
    1107                 :            : /* fetch an instruction and prepare its execution */
    1108                 :            : #define vmfetch()       { \
    1109                 :            :   if (trap) {  /* stack reallocation or hooks? */ \
    1110                 :            :     trap = luaG_traceexec(L, pc);  /* handle hooks */ \
    1111                 :            :     updatebase(ci);  /* correct stack */ \
    1112                 :            :   } \
    1113                 :            :   i = *(pc++); \
    1114                 :            :   ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \
    1115                 :            : }
    1116                 :            : 
    1117                 :            : #define vmdispatch(o)   switch(o)
    1118                 :            : #define vmcase(l)       case l:
    1119                 :            : #define vmbreak         break
    1120                 :            : 
    1121                 :            : 
    1122                 :        652 : void luaV_execute (lua_State *L, CallInfo *ci) {
    1123                 :            :   LClosure *cl;
    1124                 :            :   TValue *k;
    1125                 :            :   StkId base;
    1126                 :            :   const Instruction *pc;
    1127                 :            :   int trap;
    1128                 :            : #if LUA_USE_JUMPTABLE
    1129                 :            : #include "ljumptab.h"
    1130                 :            : #endif
    1131                 :            :  startfunc:
    1132                 :        652 :   trap = L->hookmask;
    1133                 :            :  returning:  /* trap already set */
    1134                 :        778 :   cl = clLvalue(s2v(ci->func));
    1135                 :        778 :   k = cl->p->k;
    1136                 :        778 :   pc = ci->u.l.savedpc;
    1137         [ +  - ]:        778 :   if (trap) {
    1138         [ #  # ]:          0 :     if (pc == cl->p->code) {  /* first instruction (not resuming)? */
    1139         [ #  # ]:          0 :       if (cl->p->is_vararg)
    1140                 :          0 :         trap = 0;  /* hooks will start after VARARGPREP instruction */
    1141                 :            :       else  /* check 'call' hook */
    1142                 :          0 :         luaD_hookcall(L, ci);
    1143                 :          0 :     }
    1144                 :          0 :     ci->u.l.trap = 1;  /* assume trap is on, for now */
    1145                 :          0 :   }
    1146                 :        778 :   base = ci->func + 1;
    1147                 :            :   /* main loop of interpreter */
    1148                 :        778 :   for (;;) {
    1149                 :            :     Instruction i;  /* instruction being executed */
    1150                 :            :     StkId ra;  /* instruction's A register */
    1151         [ +  - ]:        778 :     vmfetch();
    1152                 :            :     lua_assert(base == ci->func + 1);
    1153                 :            :     lua_assert(base <= L->top && L->top < L->stack_last);
    1154                 :            :     /* invalidate top for instructions not expecting it */
    1155                 :            :     lua_assert(isIT(i) || (cast_void(L->top = base), 1));
    1156                 :        778 :     vmdispatch (GET_OPCODE(i)) {
    1157                 :            :       vmcase(OP_MOVE) {
    1158                 :          0 :         setobjs2s(L, ra, RB(i));
    1159         [ #  # ]:          0 :         vmbreak;
    1160                 :            :       }
    1161                 :            :       vmcase(OP_LOADI) {
    1162                 :        320 :         lua_Integer b = GETARG_sBx(i);
    1163                 :        320 :         setivalue(s2v(ra), b);
    1164         [ +  - ]:        320 :         vmbreak;
    1165                 :            :       }
    1166                 :            :       vmcase(OP_LOADF) {
    1167                 :          0 :         int b = GETARG_sBx(i);
    1168                 :          0 :         setfltvalue(s2v(ra), cast_num(b));
    1169         [ #  # ]:          0 :         vmbreak;
    1170                 :            :       }
    1171                 :            :       vmcase(OP_LOADK) {
    1172                 :        551 :         TValue *rb = k + GETARG_Bx(i);
    1173                 :        551 :         setobj2s(L, ra, rb);
    1174         [ +  - ]:        551 :         vmbreak;
    1175                 :            :       }
    1176                 :            :       vmcase(OP_LOADKX) {
    1177                 :            :         TValue *rb;
    1178                 :          0 :         rb = k + GETARG_Ax(*pc); pc++;
    1179                 :          0 :         setobj2s(L, ra, rb);
    1180         [ #  # ]:          0 :         vmbreak;
    1181                 :            :       }
    1182                 :            :       vmcase(OP_LOADFALSE) {
    1183                 :          0 :         setbfvalue(s2v(ra));
    1184         [ #  # ]:          0 :         vmbreak;
    1185                 :            :       }
    1186                 :            :       vmcase(OP_LFALSESKIP) {
    1187                 :          0 :         setbfvalue(s2v(ra));
    1188                 :          0 :         pc++;  /* skip next instruction */
    1189         [ #  # ]:          0 :         vmbreak;
    1190                 :            :       }
    1191                 :            :       vmcase(OP_LOADTRUE) {
    1192                 :          0 :         setbtvalue(s2v(ra));
    1193         [ #  # ]:          0 :         vmbreak;
    1194                 :            :       }
    1195                 :            :       vmcase(OP_LOADNIL) {
    1196                 :          0 :         int b = GETARG_B(i);
    1197                 :          0 :         do {
    1198                 :          0 :           setnilvalue(s2v(ra++));
    1199         [ #  # ]:          0 :         } while (b--);
    1200         [ #  # ]:          0 :         vmbreak;
    1201                 :            :       }
    1202                 :            :       vmcase(OP_GETUPVAL) {
    1203                 :          0 :         int b = GETARG_B(i);
    1204                 :          0 :         setobj2s(L, ra, cl->upvals[b]->v);
    1205         [ #  # ]:          0 :         vmbreak;
    1206                 :            :       }
    1207                 :            :       vmcase(OP_SETUPVAL) {
    1208                 :          0 :         UpVal *uv = cl->upvals[GETARG_B(i)];
    1209                 :          0 :         setobj(L, uv->v, s2v(ra));
    1210   [ #  #  #  #  :          0 :         luaC_barrier(L, uv, s2v(ra));
                   #  # ]
    1211         [ #  # ]:          0 :         vmbreak;
    1212                 :            :       }
    1213                 :            :       vmcase(OP_GETTABUP) {
    1214                 :            :         const TValue *slot;
    1215                 :       1001 :         TValue *upval = cl->upvals[GETARG_B(i)]->v;
    1216                 :       1001 :         TValue *rc = KC(i);
    1217                 :       1001 :         TString *key = tsvalue(rc);  /* key must be a string */
    1218   [ -  +  +  + ]:       1001 :         if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
    1219                 :       1046 :           setobj2s(L, ra, slot);
    1220                 :       1046 :         }
    1221                 :            :         else
    1222                 :         45 :           Protect(luaV_finishget(L, upval, rc, ra, slot));
    1223         [ +  - ]:       1091 :         vmbreak;
    1224                 :            :       }
    1225                 :            :       vmcase(OP_GETTABLE) {
    1226                 :            :         const TValue *slot;
    1227                 :         33 :         TValue *rb = vRB(i);
    1228                 :         33 :         TValue *rc = vRC(i);
    1229                 :            :         lua_Unsigned n;
    1230   [ +  +  +  +  :         65 :         if (ttisinteger(rc)  /* fast track for integers? */
                   -  + ]
    1231   [ +  -  +  - ]:         32 :             ? (cast_void(n = ivalue(rc)), luaV_fastgeti(L, rb, n, slot))
    1232                 :          1 :             : luaV_fastget(L, rb, rc, slot, luaH_get)) {
    1233                 :         32 :           setobj2s(L, ra, slot);
    1234                 :         32 :         }
    1235                 :            :         else
    1236                 :          1 :           Protect(luaV_finishget(L, rb, rc, ra, slot));
    1237         [ +  - ]:         33 :         vmbreak;
    1238                 :            :       }
    1239                 :            :       vmcase(OP_GETI) {
    1240                 :            :         const TValue *slot;
    1241                 :         31 :         TValue *rb = vRB(i);
    1242                 :         31 :         int c = GETARG_C(i);
    1243   [ +  -  #  #  :         31 :         if (luaV_fastgeti(L, rb, c, slot)) {
                   +  - ]
    1244                 :         31 :           setobj2s(L, ra, slot);
    1245                 :         31 :         }
    1246                 :            :         else {
    1247                 :            :           TValue key;
    1248                 :          0 :           setivalue(&key, c);
    1249                 :          0 :           Protect(luaV_finishget(L, rb, &key, ra, slot));
    1250                 :            :         }
    1251         [ +  - ]:         31 :         vmbreak;
    1252                 :            :       }
    1253                 :            :       vmcase(OP_GETFIELD) {
    1254                 :            :         const TValue *slot;
    1255                 :        718 :         TValue *rb = vRB(i);
    1256                 :        718 :         TValue *rc = KC(i);
    1257                 :        718 :         TString *key = tsvalue(rc);  /* key must be a string */
    1258   [ +  +  -  + ]:        718 :         if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) {
    1259                 :        717 :           setobj2s(L, ra, slot);
    1260                 :        717 :         }
    1261                 :            :         else
    1262                 :          1 :           Protect(luaV_finishget(L, rb, rc, ra, slot));
    1263         [ +  - ]:        718 :         vmbreak;
    1264                 :            :       }
    1265                 :            :       vmcase(OP_SETTABUP) {
    1266                 :            :         const TValue *slot;
    1267                 :         94 :         TValue *upval = cl->upvals[GETARG_A(i)]->v;
    1268                 :         94 :         TValue *rb = KB(i);
    1269         [ -  + ]:         94 :         TValue *rc = RKC(i);
    1270                 :         94 :         TString *key = tsvalue(rb);  /* key must be a string */
    1271   [ -  +  +  + ]:         94 :         if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
    1272   [ -  +  #  #  :        196 :           luaV_finishfastset(L, upval, slot, rc);
                   #  # ]
    1273                 :          8 :         }
    1274                 :            :         else
    1275                 :        102 :           Protect(luaV_finishset(L, upval, rb, rc, slot));
    1276         [ +  - ]:        110 :         vmbreak;
    1277                 :            :       }
    1278                 :            :       vmcase(OP_SETTABLE) {
    1279                 :            :         const TValue *slot;
    1280                 :          0 :         TValue *rb = vRB(i);  /* key (table is in 'ra') */
    1281         [ #  # ]:          0 :         TValue *rc = RKC(i);  /* value */
    1282                 :            :         lua_Unsigned n;
    1283   [ #  #  #  #  :          0 :         if (ttisinteger(rb)  /* fast track for integers? */
                   #  # ]
    1284   [ #  #  #  # ]:          0 :             ? (cast_void(n = ivalue(rb)), luaV_fastgeti(L, s2v(ra), n, slot))
    1285                 :          0 :             : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) {
    1286   [ #  #  #  #  :          0 :           luaV_finishfastset(L, s2v(ra), slot, rc);
                   #  # ]
    1287                 :          0 :         }
    1288                 :            :         else
    1289                 :          0 :           Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
    1290         [ #  # ]:          0 :         vmbreak;
    1291                 :            :       }
    1292                 :            :       vmcase(OP_SETI) {
    1293                 :            :         const TValue *slot;
    1294                 :          0 :         int c = GETARG_B(i);
    1295         [ #  # ]:          0 :         TValue *rc = RKC(i);
    1296   [ #  #  #  #  :          0 :         if (luaV_fastgeti(L, s2v(ra), c, slot)) {
                   #  # ]
    1297   [ #  #  #  #  :          0 :           luaV_finishfastset(L, s2v(ra), slot, rc);
                   #  # ]
    1298                 :          0 :         }
    1299                 :            :         else {
    1300                 :            :           TValue key;
    1301                 :          0 :           setivalue(&key, c);
    1302                 :          0 :           Protect(luaV_finishset(L, s2v(ra), &key, rc, slot));
    1303                 :            :         }
    1304         [ #  # ]:          0 :         vmbreak;
    1305                 :            :       }
    1306                 :            :       vmcase(OP_SETFIELD) {
    1307                 :            :         const TValue *slot;
    1308                 :          0 :         TValue *rb = KB(i);
    1309         [ #  # ]:          0 :         TValue *rc = RKC(i);
    1310                 :          0 :         TString *key = tsvalue(rb);  /* key must be a string */
    1311   [ #  #  #  # ]:          0 :         if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) {
    1312   [ #  #  #  #  :          0 :           luaV_finishfastset(L, s2v(ra), slot, rc);
                   #  # ]
    1313                 :          0 :         }
    1314                 :            :         else
    1315                 :          0 :           Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
    1316         [ #  # ]:          0 :         vmbreak;
    1317                 :            :       }
    1318                 :            :       vmcase(OP_NEWTABLE) {
    1319                 :          9 :         int b = GETARG_B(i);  /* log2(hash size) + 1 */
    1320                 :          9 :         int c = GETARG_C(i);  /* array size */
    1321                 :            :         Table *t;
    1322         [ +  - ]:          9 :         if (b > 0)
    1323                 :          0 :           b = 1 << (b - 1);  /* size is 2^(b - 1) */
    1324                 :            :         lua_assert((!TESTARG_k(i)) == (GETARG_Ax(*pc) == 0));
    1325         [ +  - ]:          9 :         if (TESTARG_k(i))  /* non-zero extra argument? */
    1326                 :          0 :           c += GETARG_Ax(*pc) * (MAXARG_C + 1);  /* add it to size */
    1327                 :          9 :         pc++;  /* skip extra argument */
    1328                 :          9 :         L->top = ra + 1;  /* correct top in case of emergency GC */
    1329                 :          9 :         t = luaH_new(L);  /* memory allocation */
    1330                 :          9 :         sethvalue2s(L, ra, t);
    1331   [ +  -  +  - ]:          9 :         if (b != 0 || c != 0)
    1332                 :          9 :           luaH_resize(L, t, c, b);  /* idem */
    1333         [ +  - ]:          9 :         checkGC(L, ra + 1);
    1334         [ +  - ]:          9 :         vmbreak;
    1335                 :            :       }
    1336                 :            :       vmcase(OP_SELF) {
    1337                 :            :         const TValue *slot;
    1338                 :         24 :         TValue *rb = vRB(i);
    1339         [ +  - ]:         24 :         TValue *rc = RKC(i);
    1340                 :         24 :         TString *key = tsvalue(rc);  /* key must be a string */
    1341                 :         24 :         setobj2s(L, ra + 1, rb);
    1342   [ +  -  -  + ]:         24 :         if (luaV_fastget(L, rb, key, slot, luaH_getstr)) {
    1343                 :          0 :           setobj2s(L, ra, slot);
    1344                 :          0 :         }
    1345                 :            :         else
    1346                 :         24 :           Protect(luaV_finishget(L, rb, rc, ra, slot));
    1347         [ +  - ]:         24 :         vmbreak;
    1348                 :            :       }
    1349                 :            :       vmcase(OP_ADDI) {
    1350   [ #  #  #  # ]:          0 :         op_arithI(L, l_addi, luai_numadd);
    1351         [ #  # ]:          0 :         vmbreak;
    1352                 :            :       }
    1353                 :            :       vmcase(OP_ADDK) {
    1354   [ #  #  #  #  :          0 :         op_arithK(L, l_addi, luai_numadd);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1355         [ #  # ]:          0 :         vmbreak;
    1356                 :            :       }
    1357                 :            :       vmcase(OP_SUBK) {
    1358   [ #  #  #  #  :          0 :         op_arithK(L, l_subi, luai_numsub);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1359         [ #  # ]:          0 :         vmbreak;
    1360                 :            :       }
    1361                 :            :       vmcase(OP_MULK) {
    1362   [ #  #  #  #  :          0 :         op_arithK(L, l_muli, luai_nummul);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1363         [ #  # ]:          0 :         vmbreak;
    1364                 :            :       }
    1365                 :            :       vmcase(OP_MODK) {
    1366   [ #  #  #  #  :          0 :         op_arithK(L, luaV_mod, luaV_modf);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1367         [ #  # ]:          0 :         vmbreak;
    1368                 :            :       }
    1369                 :            :       vmcase(OP_POWK) {
    1370   [ #  #  #  #  :          0 :         op_arithfK(L, luai_numpow);
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1371         [ #  # ]:          0 :         vmbreak;
    1372                 :            :       }
    1373                 :            :       vmcase(OP_DIVK) {
    1374   [ #  #  #  #  :          0 :         op_arithfK(L, luai_numdiv);
          #  #  #  #  #  
                #  #  # ]
    1375         [ #  # ]:          0 :         vmbreak;
    1376                 :            :       }
    1377                 :            :       vmcase(OP_IDIVK) {
    1378   [ #  #  #  #  :          0 :         op_arithK(L, luaV_idiv, luai_numidiv);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1379         [ #  # ]:          0 :         vmbreak;
    1380                 :            :       }
    1381                 :            :       vmcase(OP_BANDK) {
    1382   [ #  #  #  # ]:          0 :         op_bitwiseK(L, l_band);
    1383         [ #  # ]:          0 :         vmbreak;
    1384                 :            :       }
    1385                 :            :       vmcase(OP_BORK) {
    1386   [ #  #  #  # ]:          0 :         op_bitwiseK(L, l_bor);
    1387         [ #  # ]:          0 :         vmbreak;
    1388                 :            :       }
    1389                 :            :       vmcase(OP_BXORK) {
    1390   [ #  #  #  # ]:          0 :         op_bitwiseK(L, l_bxor);
    1391         [ #  # ]:          0 :         vmbreak;
    1392                 :            :       }
    1393                 :            :       vmcase(OP_SHRI) {
    1394                 :          0 :         TValue *rb = vRB(i);
    1395                 :          0 :         int ic = GETARG_sC(i);
    1396                 :            :         lua_Integer ib;
    1397   [ #  #  #  # ]:          0 :         if (tointegerns(rb, &ib)) {
    1398                 :          0 :           pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
    1399                 :          0 :         }
    1400         [ #  # ]:          0 :         vmbreak;
    1401                 :            :       }
    1402                 :            :       vmcase(OP_SHLI) {
    1403                 :          0 :         TValue *rb = vRB(i);
    1404                 :          0 :         int ic = GETARG_sC(i);
    1405                 :            :         lua_Integer ib;
    1406   [ #  #  #  # ]:          0 :         if (tointegerns(rb, &ib)) {
    1407                 :          0 :           pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
    1408                 :          0 :         }
    1409         [ #  # ]:          0 :         vmbreak;
    1410                 :            :       }
    1411                 :            :       vmcase(OP_ADD) {
    1412   [ #  #  #  #  :          0 :         op_arith(L, l_addi, luai_numadd);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1413         [ #  # ]:          0 :         vmbreak;
    1414                 :            :       }
    1415                 :            :       vmcase(OP_SUB) {
    1416   [ #  #  #  #  :          0 :         op_arith(L, l_subi, luai_numsub);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1417         [ #  # ]:          0 :         vmbreak;
    1418                 :            :       }
    1419                 :            :       vmcase(OP_MUL) {
    1420   [ #  #  #  #  :          0 :         op_arith(L, l_muli, luai_nummul);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1421         [ #  # ]:          0 :         vmbreak;
    1422                 :            :       }
    1423                 :            :       vmcase(OP_MOD) {
    1424   [ #  #  #  #  :          0 :         op_arith(L, luaV_mod, luaV_modf);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1425         [ #  # ]:          0 :         vmbreak;
    1426                 :            :       }
    1427                 :            :       vmcase(OP_POW) {
    1428   [ #  #  #  #  :          0 :         op_arithf(L, luai_numpow);
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1429         [ #  # ]:          0 :         vmbreak;
    1430                 :            :       }
    1431                 :            :       vmcase(OP_DIV) {  /* float division (always with floats) */
    1432   [ #  #  #  #  :          0 :         op_arithf(L, luai_numdiv);
          #  #  #  #  #  
                #  #  # ]
    1433         [ #  # ]:          0 :         vmbreak;
    1434                 :            :       }
    1435                 :            :       vmcase(OP_IDIV) {  /* floor division */
    1436   [ #  #  #  #  :          0 :         op_arith(L, luaV_idiv, luai_numidiv);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1437         [ #  # ]:          0 :         vmbreak;
    1438                 :            :       }
    1439                 :            :       vmcase(OP_BAND) {
    1440   [ #  #  #  #  :          0 :         op_bitwise(L, l_band);
             #  #  #  # ]
    1441         [ #  # ]:          0 :         vmbreak;
    1442                 :            :       }
    1443                 :            :       vmcase(OP_BOR) {
    1444   [ #  #  #  #  :          0 :         op_bitwise(L, l_bor);
             #  #  #  # ]
    1445         [ #  # ]:          0 :         vmbreak;
    1446                 :            :       }
    1447                 :            :       vmcase(OP_BXOR) {
    1448   [ #  #  #  #  :          0 :         op_bitwise(L, l_bxor);
             #  #  #  # ]
    1449         [ #  # ]:          0 :         vmbreak;
    1450                 :            :       }
    1451                 :            :       vmcase(OP_SHR) {
    1452   [ #  #  #  #  :          0 :         op_bitwise(L, luaV_shiftr);
             #  #  #  # ]
    1453         [ #  # ]:          0 :         vmbreak;
    1454                 :            :       }
    1455                 :            :       vmcase(OP_SHL) {
    1456   [ #  #  #  #  :          0 :         op_bitwise(L, luaV_shiftl);
             #  #  #  # ]
    1457         [ #  # ]:          0 :         vmbreak;
    1458                 :            :       }
    1459                 :            :       vmcase(OP_MMBIN) {
    1460                 :          0 :         Instruction pi = *(pc - 2);  /* original arith. expression */
    1461                 :          0 :         TValue *rb = vRB(i);
    1462                 :          0 :         TMS tm = (TMS)GETARG_C(i);
    1463                 :          0 :         StkId result = RA(pi);
    1464                 :            :         lua_assert(OP_ADD <= GET_OPCODE(pi) && GET_OPCODE(pi) <= OP_SHR);
    1465                 :          0 :         Protect(luaT_trybinTM(L, s2v(ra), rb, result, tm));
    1466         [ #  # ]:          0 :         vmbreak;
    1467                 :            :       }
    1468                 :            :       vmcase(OP_MMBINI) {
    1469                 :          0 :         Instruction pi = *(pc - 2);  /* original arith. expression */
    1470                 :          0 :         int imm = GETARG_sB(i);
    1471                 :          0 :         TMS tm = (TMS)GETARG_C(i);
    1472                 :          0 :         int flip = GETARG_k(i);
    1473                 :          0 :         StkId result = RA(pi);
    1474                 :          0 :         Protect(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm));
    1475         [ #  # ]:          0 :         vmbreak;
    1476                 :            :       }
    1477                 :            :       vmcase(OP_MMBINK) {
    1478                 :          0 :         Instruction pi = *(pc - 2);  /* original arith. expression */
    1479                 :          0 :         TValue *imm = KB(i);
    1480                 :          0 :         TMS tm = (TMS)GETARG_C(i);
    1481                 :          0 :         int flip = GETARG_k(i);
    1482                 :          0 :         StkId result = RA(pi);
    1483                 :          0 :         Protect(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm));
    1484         [ #  # ]:          0 :         vmbreak;
    1485                 :            :       }
    1486                 :            :       vmcase(OP_UNM) {
    1487                 :          0 :         TValue *rb = vRB(i);
    1488                 :            :         lua_Number nb;
    1489         [ #  # ]:          0 :         if (ttisinteger(rb)) {
    1490                 :          0 :           lua_Integer ib = ivalue(rb);
    1491                 :          0 :           setivalue(s2v(ra), intop(-, 0, ib));
    1492                 :          0 :         }
    1493   [ #  #  #  #  :          0 :         else if (tonumberns(rb, nb)) {
                   #  # ]
    1494                 :          0 :           setfltvalue(s2v(ra), luai_numunm(L, nb));
    1495                 :          0 :         }
    1496                 :            :         else
    1497                 :          0 :           Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));
    1498         [ #  # ]:          0 :         vmbreak;
    1499                 :            :       }
    1500                 :            :       vmcase(OP_BNOT) {
    1501                 :          0 :         TValue *rb = vRB(i);
    1502                 :            :         lua_Integer ib;
    1503   [ #  #  #  # ]:          0 :         if (tointegerns(rb, &ib)) {
    1504                 :          0 :           setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));
    1505                 :          0 :         }
    1506                 :            :         else
    1507                 :          0 :           Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
    1508         [ #  # ]:          0 :         vmbreak;
    1509                 :            :       }
    1510                 :            :       vmcase(OP_NOT) {
    1511                 :          0 :         TValue *rb = vRB(i);
    1512   [ #  #  #  # ]:          0 :         if (l_isfalse(rb))
    1513                 :          0 :           setbtvalue(s2v(ra));
    1514                 :            :         else
    1515                 :          0 :           setbfvalue(s2v(ra));
    1516         [ #  # ]:          0 :         vmbreak;
    1517                 :            :       }
    1518                 :            :       vmcase(OP_LEN) {
    1519                 :        101 :         Protect(luaV_objlen(L, ra, vRB(i)));
    1520         [ +  - ]:        101 :         vmbreak;
    1521                 :            :       }
    1522                 :            :       vmcase(OP_CONCAT) {
    1523                 :         19 :         int n = GETARG_B(i);  /* number of elements to concatenate */
    1524                 :         19 :         L->top = ra + n;  /* mark the end of concat operands */
    1525                 :         19 :         ProtectNT(luaV_concat(L, n));
    1526         [ +  - ]:         19 :         checkGC(L, L->top); /* 'luaV_concat' ensures correct top */
    1527         [ +  - ]:         19 :         vmbreak;
    1528                 :            :       }
    1529                 :            :       vmcase(OP_CLOSE) {
    1530                 :          0 :         Protect(luaF_close(L, ra, LUA_OK));
    1531         [ #  # ]:          0 :         vmbreak;
    1532                 :            :       }
    1533                 :            :       vmcase(OP_TBC) {
    1534                 :            :         /* create new to-be-closed upvalue */
    1535                 :          0 :         halfProtect(luaF_newtbcupval(L, ra));
    1536         [ #  # ]:          0 :         vmbreak;
    1537                 :            :       }
    1538                 :            :       vmcase(OP_JMP) {
    1539                 :          0 :         dojump(ci, i, 0);
    1540         [ #  # ]:          0 :         vmbreak;
    1541                 :            :       }
    1542                 :            :       vmcase(OP_EQ) {
    1543                 :            :         int cond;
    1544                 :          8 :         TValue *rb = vRB(i);
    1545                 :          8 :         Protect(cond = luaV_equalobj(L, s2v(ra), rb));
    1546         [ +  + ]:          8 :         docondjump();
    1547         [ +  - ]:          8 :         vmbreak;
    1548                 :            :       }
    1549                 :            :       vmcase(OP_LT) {
    1550   [ #  #  #  #  :          0 :         op_order(L, l_lti, LTnum, lessthanothers);
          #  #  #  #  #  
                      # ]
    1551         [ #  # ]:          0 :         vmbreak;
    1552                 :            :       }
    1553                 :            :       vmcase(OP_LE) {
    1554   [ #  #  #  #  :          0 :         op_order(L, l_lei, LEnum, lessequalothers);
          #  #  #  #  #  
                      # ]
    1555         [ #  # ]:          0 :         vmbreak;
    1556                 :            :       }
    1557                 :            :       vmcase(OP_EQK) {
    1558                 :        137 :         TValue *rb = KB(i);
    1559                 :            :         /* basic types do not use '__eq'; we can use raw equality */
    1560                 :        137 :         int cond = luaV_rawequalobj(s2v(ra), rb);
    1561         [ +  + ]:        137 :         docondjump();
    1562         [ +  - ]:        137 :         vmbreak;
    1563                 :            :       }
    1564                 :            :       vmcase(OP_EQI) {
    1565                 :            :         int cond;
    1566                 :         28 :         int im = GETARG_sB(i);
    1567         [ +  - ]:         28 :         if (ttisinteger(s2v(ra)))
    1568                 :         28 :           cond = (ivalue(s2v(ra)) == im);
    1569         [ #  # ]:          0 :         else if (ttisfloat(s2v(ra)))
    1570                 :          0 :           cond = luai_numeq(fltvalue(s2v(ra)), cast_num(im));
    1571                 :            :         else
    1572                 :          0 :           cond = 0;  /* other types cannot be equal to a number */
    1573         [ +  + ]:         28 :         docondjump();
    1574         [ +  - ]:         28 :         vmbreak;
    1575                 :            :       }
    1576                 :            :       vmcase(OP_LTI) {
    1577   [ #  #  #  #  :          0 :         op_orderI(L, l_lti, luai_numlt, 0, TM_LT);
                   #  # ]
    1578         [ #  # ]:          0 :         vmbreak;
    1579                 :            :       }
    1580                 :            :       vmcase(OP_LEI) {
    1581   [ #  #  #  #  :          0 :         op_orderI(L, l_lei, luai_numle, 0, TM_LE);
                   #  # ]
    1582         [ #  # ]:          0 :         vmbreak;
    1583                 :            :       }
    1584                 :            :       vmcase(OP_GTI) {
    1585   [ #  #  #  #  :          0 :         op_orderI(L, l_gti, luai_numgt, 1, TM_LT);
                   #  # ]
    1586         [ #  # ]:          0 :         vmbreak;
    1587                 :            :       }
    1588                 :            :       vmcase(OP_GEI) {
    1589   [ #  #  #  #  :          0 :         op_orderI(L, l_gei, luai_numge, 1, TM_LE);
                   #  # ]
    1590         [ #  # ]:          0 :         vmbreak;
    1591                 :            :       }
    1592                 :            :       vmcase(OP_TEST) {
    1593         [ +  + ]:         40 :         int cond = !l_isfalse(s2v(ra));
    1594         [ +  + ]:         40 :         docondjump();
    1595         [ +  - ]:         40 :         vmbreak;
    1596                 :            :       }
    1597                 :            :       vmcase(OP_TESTSET) {
    1598                 :          0 :         TValue *rb = vRB(i);
    1599   [ #  #  #  # ]:          0 :         if (l_isfalse(rb) == GETARG_k(i))
    1600                 :          0 :           pc++;
    1601                 :            :         else {
    1602                 :          0 :           setobj2s(L, ra, rb);
    1603                 :          0 :           donextjump(ci);
    1604                 :            :         }
    1605         [ #  # ]:          0 :         vmbreak;
    1606                 :            :       }
    1607                 :            :       vmcase(OP_CALL) {
    1608                 :            :         CallInfo *newci;
    1609                 :        956 :         int b = GETARG_B(i);
    1610                 :        956 :         int nresults = GETARG_C(i) - 1;
    1611         [ +  + ]:        956 :         if (b != 0)  /* fixed number of arguments? */
    1612                 :        699 :           L->top = ra + b;  /* top signals number of arguments */
    1613                 :            :         /* else previous instruction set top */
    1614                 :        956 :         savepc(L);  /* in case of errors */
    1615         [ +  - ]:        956 :         if ((newci = luaD_precall(L, ra, nresults)) == NULL)
    1616                 :        442 :           updatetrap(ci);  /* C call; nothing else to be done */
    1617                 :            :         else {  /* Lua call: run function in this same C frame */
    1618                 :          0 :           ci = newci;
    1619                 :          0 :           ci->callstatus = 0;  /* call re-uses 'luaV_execute' */
    1620                 :          0 :           goto startfunc;
    1621                 :            :         }
    1622         [ +  - ]:        442 :         vmbreak;
    1623                 :            :       }
    1624                 :            :       vmcase(OP_TAILCALL) {
    1625                 :         78 :         int b = GETARG_B(i);  /* number of arguments + 1 (function) */
    1626                 :         78 :         int nparams1 = GETARG_C(i);
    1627                 :            :         /* delta is virtual 'func' - real 'func' (vararg functions) */
    1628         [ +  - ]:         78 :         int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0;
    1629         [ +  - ]:         78 :         if (b != 0)
    1630                 :         78 :           L->top = ra + b;
    1631                 :            :         else  /* previous instruction set top */
    1632                 :          0 :           b = cast_int(L->top - ra);
    1633                 :         78 :         savepc(ci);  /* several calls here can raise errors */
    1634         [ +  - ]:         78 :         if (TESTARG_k(i)) {
    1635                 :            :           /* close upvalues from current call; the compiler ensures
    1636                 :            :              that there are no to-be-closed variables here, so this
    1637                 :            :              call cannot change the stack */
    1638                 :          0 :           luaF_close(L, base, NOCLOSINGMETH);
    1639                 :            :           lua_assert(base == ci->func + 1);
    1640                 :          0 :         }
    1641         [ -  + ]:         78 :         while (!ttisfunction(s2v(ra))) {  /* not a function? */
    1642                 :          0 :           luaD_tryfuncTM(L, ra);  /* try '__call' metamethod */
    1643                 :          0 :           b++;  /* there is now one extra argument */
    1644   [ #  #  #  # ]:          0 :           checkstackGCp(L, 1, ra);
    1645                 :            :         }
    1646         [ +  - ]:         78 :         if (!ttisLclosure(s2v(ra))) {  /* C function? */
    1647                 :         78 :           luaD_precall(L, ra, LUA_MULTRET);  /* call it */
    1648                 :         78 :           updatetrap(ci);
    1649         [ +  - ]:         78 :           updatestack(ci);  /* stack may have been relocated */
    1650                 :         78 :           ci->func -= delta;  /* restore 'func' (if vararg) */
    1651                 :         78 :           luaD_poscall(L, ci, cast_int(L->top - ra));  /* finish caller */
    1652                 :         78 :           updatetrap(ci);  /* 'luaD_poscall' can change hooks */
    1653                 :         78 :           goto ret;  /* caller returns after the tail call */
    1654                 :            :         }
    1655                 :          0 :         ci->func -= delta;  /* restore 'func' (if vararg) */
    1656                 :          0 :         luaD_pretailcall(L, ci, ra, b);  /* prepare call frame */
    1657                 :          0 :         goto startfunc;  /* execute the callee */
    1658                 :            :       }
    1659                 :            :       vmcase(OP_RETURN) {
    1660                 :        292 :         int n = GETARG_B(i) - 1;  /* number of results */
    1661                 :        292 :         int nparams1 = GETARG_C(i);
    1662         [ +  - ]:        292 :         if (n < 0)  /* not fixed? */
    1663                 :          0 :           n = cast_int(L->top - ra);  /* get what is available */
    1664                 :        292 :         savepc(ci);
    1665         [ +  - ]:        292 :         if (TESTARG_k(i)) {  /* may there be open upvalues? */
    1666         [ #  # ]:          0 :           if (L->top < ci->top)
    1667                 :          0 :             L->top = ci->top;
    1668                 :          0 :           luaF_close(L, base, LUA_OK);
    1669                 :          0 :           updatetrap(ci);
    1670         [ #  # ]:          0 :           updatestack(ci);
    1671                 :          0 :         }
    1672         [ -  + ]:        292 :         if (nparams1)  /* vararg function? */
    1673                 :        292 :           ci->func -= ci->u.l.nextraargs + nparams1;
    1674                 :        292 :         L->top = ra + n;  /* set call for 'luaD_poscall' */
    1675                 :        292 :         luaD_poscall(L, ci, n);
    1676                 :        292 :         updatetrap(ci);  /* 'luaD_poscall' can change hooks */
    1677                 :        292 :         goto ret;
    1678                 :            :       }
    1679                 :            :       vmcase(OP_RETURN0) {
    1680         [ #  # ]:          0 :         if (L->hookmask) {
    1681                 :          0 :           L->top = ra;
    1682                 :          0 :           savepc(ci);
    1683                 :          0 :           luaD_poscall(L, ci, 0);  /* no hurry... */
    1684                 :          0 :           trap = 1;
    1685                 :          0 :         }
    1686                 :            :         else {  /* do the 'poscall' here */
    1687                 :          0 :           int nres = ci->nresults;
    1688                 :          0 :           L->ci = ci->previous;  /* back to caller */
    1689                 :          0 :           L->top = base - 1;
    1690         [ #  # ]:          0 :           while (nres-- > 0)
    1691                 :          0 :             setnilvalue(s2v(L->top++));  /* all results are nil */
    1692                 :            :         }
    1693                 :          0 :         goto ret;
    1694                 :            :       }
    1695                 :            :       vmcase(OP_RETURN1) {
    1696         [ #  # ]:          0 :         if (L->hookmask) {
    1697                 :          0 :           L->top = ra + 1;
    1698                 :          0 :           savepc(ci);
    1699                 :          0 :           luaD_poscall(L, ci, 1);  /* no hurry... */
    1700                 :          0 :           trap = 1;
    1701                 :          0 :         }
    1702                 :            :         else {  /* do the 'poscall' here */
    1703                 :          0 :           int nres = ci->nresults;
    1704                 :          0 :           L->ci = ci->previous;  /* back to caller */
    1705         [ #  # ]:          0 :           if (nres == 0)
    1706                 :          0 :             L->top = base - 1;  /* asked for no results */
    1707                 :            :           else {
    1708                 :          0 :             setobjs2s(L, base - 1, ra);  /* at least this result */
    1709                 :          0 :             L->top = base;
    1710         [ #  # ]:          0 :             while (--nres > 0)  /* complete missing results */
    1711                 :          0 :               setnilvalue(s2v(L->top++));
    1712                 :            :           }
    1713                 :            :         }
    1714                 :            :        ret:  /* return from a Lua function */
    1715         [ +  + ]:        370 :         if (ci->callstatus & CIST_FRESH)
    1716                 :        244 :           return;  /* end this frame */
    1717                 :            :         else {
    1718                 :        126 :           ci = ci->previous;
    1719                 :        126 :           goto returning;  /* continue running caller in this frame */
    1720                 :            :         }
    1721                 :            :       }
    1722                 :            :       vmcase(OP_FORLOOP) {
    1723         [ +  - ]:         32 :         if (ttisinteger(s2v(ra + 2))) {  /* integer loop? */
    1724                 :         32 :           lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1)));
    1725         [ +  + ]:         32 :           if (count > 0) {  /* still more iterations? */
    1726                 :         24 :             lua_Integer step = ivalue(s2v(ra + 2));
    1727                 :         24 :             lua_Integer idx = ivalue(s2v(ra));  /* internal index */
    1728                 :         24 :             chgivalue(s2v(ra + 1), count - 1);  /* update counter */
    1729                 :         24 :             idx = intop(+, idx, step);  /* add step to index */
    1730                 :         24 :             chgivalue(s2v(ra), idx);  /* update internal index */
    1731                 :         24 :             setivalue(s2v(ra + 3), idx);  /* and control variable */
    1732                 :         24 :             pc -= GETARG_Bx(i);  /* jump back */
    1733                 :         24 :           }
    1734                 :         32 :         }
    1735         [ #  # ]:          0 :         else if (floatforloop(ra))  /* float loop */
    1736                 :          0 :           pc -= GETARG_Bx(i);  /* jump back */
    1737                 :         32 :         updatetrap(ci);  /* allows a signal to break the loop */
    1738         [ +  - ]:         32 :         vmbreak;
    1739                 :            :       }
    1740                 :            :       vmcase(OP_FORPREP) {
    1741                 :          8 :         savestate(L, ci);  /* in case of errors */
    1742         [ +  - ]:          8 :         if (forprep(L, ra))
    1743                 :          0 :           pc += GETARG_Bx(i) + 1;  /* skip the loop */
    1744         [ +  - ]:          8 :         vmbreak;
    1745                 :            :       }
    1746                 :            :       vmcase(OP_TFORPREP) {
    1747                 :            :         /* create to-be-closed upvalue (if needed) */
    1748                 :          0 :         halfProtect(luaF_newtbcupval(L, ra + 3));
    1749                 :          0 :         pc += GETARG_Bx(i);
    1750                 :          0 :         i = *(pc++);  /* go to next instruction */
    1751                 :            :         lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i));
    1752                 :          0 :         goto l_tforcall;
    1753                 :            :       }
    1754                 :          0 :       vmcase(OP_TFORCALL) {
    1755                 :            :        l_tforcall:
    1756                 :            :         /* 'ra' has the iterator function, 'ra + 1' has the state,
    1757                 :            :            'ra + 2' has the control variable, and 'ra + 3' has the
    1758                 :            :            to-be-closed variable. The call will use the stack after
    1759                 :            :            these values (starting at 'ra + 4')
    1760                 :            :         */
    1761                 :            :         /* push function, state, and control variable */
    1762                 :          0 :         memcpy(ra + 4, ra, 3 * sizeof(*ra));
    1763                 :          0 :         L->top = ra + 4 + 3;
    1764                 :          0 :         ProtectNT(luaD_call(L, ra + 4, GETARG_C(i)));  /* do the call */
    1765         [ #  # ]:          0 :         updatestack(ci);  /* stack may have changed */
    1766                 :          0 :         i = *(pc++);  /* go to next instruction */
    1767                 :            :         lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i));
    1768                 :          0 :         goto l_tforloop;
    1769                 :            :       }
    1770                 :          0 :       vmcase(OP_TFORLOOP) {
    1771                 :            :         l_tforloop:
    1772         [ #  # ]:          0 :         if (!ttisnil(s2v(ra + 4))) {  /* continue loop? */
    1773                 :          0 :           setobjs2s(L, ra + 2, ra + 4);  /* save control variable */
    1774                 :          0 :           pc -= GETARG_Bx(i);  /* jump back */
    1775                 :          0 :         }
    1776         [ #  # ]:          0 :         vmbreak;
    1777                 :            :       }
    1778                 :            :       vmcase(OP_SETLIST) {
    1779                 :          9 :         int n = GETARG_B(i);
    1780                 :          9 :         unsigned int last = GETARG_C(i);
    1781                 :          9 :         Table *h = hvalue(s2v(ra));
    1782         [ +  - ]:          9 :         if (n == 0)
    1783                 :          0 :           n = cast_int(L->top - ra) - 1;  /* get up to the top */
    1784                 :            :         else
    1785                 :          9 :           L->top = ci->top;  /* correct top in case of emergency GC */
    1786                 :          9 :         last += n;
    1787         [ +  - ]:          9 :         if (TESTARG_k(i)) {
    1788                 :          0 :           last += GETARG_Ax(*pc) * (MAXARG_C + 1);
    1789                 :          0 :           pc++;
    1790                 :          0 :         }
    1791         [ +  - ]:          9 :         if (last > luaH_realasize(h))  /* needs more space? */
    1792                 :          0 :           luaH_resizearray(L, h, last);  /* preallocate it at once */
    1793         [ +  + ]:         25 :         for (; n > 0; n--) {
    1794                 :         16 :           TValue *val = s2v(ra + n);
    1795                 :         16 :           setobj2t(L, &h->array[last - 1], val);
    1796                 :         16 :           last--;
    1797   [ +  -  -  +  :         16 :           luaC_barrierback(L, obj2gco(h), val);
                   #  # ]
    1798                 :         16 :         }
    1799         [ +  - ]:          9 :         vmbreak;
    1800                 :            :       }
    1801                 :            :       vmcase(OP_CLOSURE) {
    1802                 :          0 :         Proto *p = cl->p->p[GETARG_Bx(i)];
    1803                 :          0 :         halfProtect(pushclosure(L, p, cl->upvals, base, ra));
    1804         [ #  # ]:          0 :         checkGC(L, ra + 1);
    1805         [ #  # ]:          0 :         vmbreak;
    1806                 :            :       }
    1807                 :            :       vmcase(OP_VARARG) {
    1808                 :          0 :         int n = GETARG_C(i) - 1;  /* required results */
    1809                 :          0 :         Protect(luaT_getvarargs(L, ci, ra, n));
    1810         [ #  # ]:          0 :         vmbreak;
    1811                 :            :       }
    1812                 :            :       vmcase(OP_VARARGPREP) {
    1813                 :        652 :         ProtectNT(luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p));
    1814         [ +  - ]:        652 :         if (trap) {
    1815                 :          0 :           luaD_hookcall(L, ci);
    1816                 :          0 :           L->oldpc = 1;  /* next opcode will be seen as a "new" line */
    1817                 :          0 :         }
    1818                 :        652 :         updatebase(ci);  /* function has new base after adjustment */
    1819         [ +  - ]:        652 :         vmbreak;
    1820                 :            :       }
    1821                 :            :       vmcase(OP_EXTRAARG) {
    1822                 :            :         lua_assert(0);
    1823         [ #  # ]:          0 :         vmbreak;
    1824                 :            :       }
    1825                 :            :     }
    1826                 :            :   }
    1827                 :            : }
    1828                 :            : 
    1829                 :            : /* }================================================================== */

Generated by: LCOV version 1.15