C:\JS_KRESREAL\HBP_konverzia\lua\lcode.c C:\JS_LUA\lua-5.2.0\src\lcode.c
/* /*
** $Id: lcode.c,v 2.60 2011/08/30 16:26:41 roberto Exp $ ** $Id: lcode.c,v 2.60 2011/08/30 16:26:41 roberto Exp $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/  */ 
   
   
#include <stdlib.h> #include <stdlib.h>
   
#define lcode_c #define lcode_c
#define LUA_CORE #define LUA_CORE
   
#include "lua.h" #include "lua.h"
   
#include "lcode.h" #include "lcode.h"
#include "ldebug.h" #include "ldebug.h"
#include "ldo.h" #include "ldo.h"
#include "lgc.h" #include "lgc.h"
#include "llex.h" #include "llex.h"
#include "lmem.h" #include "lmem.h"
#include "lobject.h" #include "lobject.h"
#include "lopcodes.h" #include "lopcodes.h"
#include "lparser.h" #include "lparser.h"
#include "lstring.h" #include "lstring.h"
#include "ltable.h" #include "ltable.h"
#include "lvm.h" #include "lvm.h"
   
   
#define hasjumps(e) ((e)->t != (e)->f) #define hasjumps(e) ((e)->t != (e)->f)
   
   
static int isnumeral(expdesc *e) { static int isnumeral(expdesc *e) {
 return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);  return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
} }
   
   
void luaK_nil (FuncState *fs, int from, int n) { void luaK_nil (FuncState *fs, int from, int n) {
 Instruction *previous;  Instruction *previous;
 int l = from + n - 1;  /* last register to set nil */   int l = from + n - 1;  /* last register to set nil */ 
 if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */   if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */ 
   previous = &fs->f->code[fs->pc-1];    previous = &fs->f->code[fs->pc-1];
   if (GET_OPCODE(*previous) == OP_LOADNIL) {    if (GET_OPCODE(*previous) == OP_LOADNIL) {
     int pfrom = GETARG_A(*previous);      int pfrom = GETARG_A(*previous);
     int pl = pfrom + GETARG_B(*previous);      int pl = pfrom + GETARG_B(*previous);
     if ((pfrom <= from && from <= pl + 1) ||      if ((pfrom <= from && from <= pl + 1) ||
         (from <= pfrom && pfrom <= l + 1)) {  /* can connect both? */           (from <= pfrom && pfrom <= l + 1)) {  /* can connect both? */ 
       if (pfrom < from) from = pfrom;  /* from = min(from, pfrom) */          if (pfrom < from) from = pfrom;  /* from = min(from, pfrom) */ 
       if (pl > l) l = pl;  /* l = max(l, pl) */          if (pl > l) l = pl;  /* l = max(l, pl) */ 
       SETARG_A(*previous, from);        SETARG_A(*previous, from);
       SETARG_B(*previous, l - from);        SETARG_B(*previous, l - from);
       return;        return;
     }      }
   }  /* else go through */     }  /* else go through */ 
 }  }
 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0);  /* else no optimization */   luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0);  /* else no optimization */ 
} }
   
   
int luaK_jump (FuncState *fs) { int luaK_jump (FuncState *fs) {
 int jpc = fs->jpc;  /* save list of jumps to here */   int jpc = fs->jpc;  /* save list of jumps to here */ 
 int j;  int j;
 fs->jpc = NO_JUMP;  fs->jpc = NO_JUMP;
 j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
 luaK_concat(fs, &j, jpc);  /* keep them on hold */   luaK_concat(fs, &j, jpc);  /* keep them on hold */ 
 return j;  return j;
} }
   
   
void luaK_ret (FuncState *fs, int first, int nret) { void luaK_ret (FuncState *fs, int first, int nret) {
 luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);
} }
   
   
static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { static int condjump (FuncState *fs, OpCode op, int A, int B, int C) {
 luaK_codeABC(fs, op, A, B, C);  luaK_codeABC(fs, op, A, B, C);
 return luaK_jump(fs);  return luaK_jump(fs);
} }
   
   
static void fixjump (FuncState *fs, int pc, int dest) { static void fixjump (FuncState *fs, int pc, int dest) {
 Instruction *jmp = &fs->f->code[pc];  Instruction *jmp = &fs->f->code[pc];
 int offset = dest-(pc+1);  int offset = dest-(pc+1);
 lua_assert(dest != NO_JUMP);  lua_assert(dest != NO_JUMP);
 if (abs(offset) > MAXARG_sBx)  if (abs(offset) > MAXARG_sBx)
   luaX_syntaxerror(fs->ls, "control structure too long");    luaX_syntaxerror(fs->ls, "control structure too long");
 SETARG_sBx(*jmp, offset);  SETARG_sBx(*jmp, offset);
} }
   
   
/* /*
** returns current `pc' and marks it as a jump target (to avoid wrong ** returns current `pc' and marks it as a jump target (to avoid wrong
** optimizations with consecutive instructions not in the same basic block). ** optimizations with consecutive instructions not in the same basic block).
*/  */ 
int luaK_getlabel (FuncState *fs) { int luaK_getlabel (FuncState *fs) {
 fs->lasttarget = fs->pc;  fs->lasttarget = fs->pc;
 return fs->pc;  return fs->pc;
} }
   
   
static int getjump (FuncState *fs, int pc) { static int getjump (FuncState *fs, int pc) {
 int offset = GETARG_sBx(fs->f->code[pc]);  int offset = GETARG_sBx(fs->f->code[pc]);
 if (offset == NO_JUMP)  /* point to itself represents end of list */   if (offset == NO_JUMP)  /* point to itself represents end of list */ 
   return NO_JUMP;  /* end of list */     return NO_JUMP;  /* end of list */ 
 else  else
   return (pc+1)+offset;  /* turn offset into absolute position */     return (pc+1)+offset;  /* turn offset into absolute position */ 
} }
   
   
static Instruction *getjumpcontrol (FuncState *fs, int pc) { static Instruction *getjumpcontrol (FuncState *fs, int pc) {
 Instruction *pi = &fs->f->code[pc];  Instruction *pi = &fs->f->code[pc];
 if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
   return pi-1;    return pi-1;
 else  else
   return pi;    return pi;
} }
   
   
/* /*
** check whether list has any jump that do not produce a value ** check whether list has any jump that do not produce a value
** (or produce an inverted value) ** (or produce an inverted value)
*/  */ 
static int need_value (FuncState *fs, int list) { static int need_value (FuncState *fs, int list) {
 for (; list != NO_JUMP; list = getjump(fs, list)) {  for (; list != NO_JUMP; list = getjump(fs, list)) {
   Instruction i = *getjumpcontrol(fs, list);    Instruction i = *getjumpcontrol(fs, list);
   if (GET_OPCODE(i) != OP_TESTSET) return 1;    if (GET_OPCODE(i) != OP_TESTSET) return 1;
 }  }
 return 0;  /* not found */   return 0;  /* not found */ 
} }
   
   
static int patchtestreg (FuncState *fs, int node, int reg) { static int patchtestreg (FuncState *fs, int node, int reg) {
 Instruction *i = getjumpcontrol(fs, node);  Instruction *i = getjumpcontrol(fs, node);
 if (GET_OPCODE(*i) != OP_TESTSET)  if (GET_OPCODE(*i) != OP_TESTSET)
   return 0;  /* cannot patch other instructions */     return 0;  /* cannot patch other instructions */ 
 if (reg != NO_REG && reg != GETARG_B(*i))  if (reg != NO_REG && reg != GETARG_B(*i))
   SETARG_A(*i, reg);    SETARG_A(*i, reg);
 else  /* no register to put value or register already has the value */   else  /* no register to put value or register already has the value */ 
   *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
   
 return 1;  return 1;
} }
   
   
static void removevalues (FuncState *fs, int list) { static void removevalues (FuncState *fs, int list) {
 for (; list != NO_JUMP; list = getjump(fs, list))  for (; list != NO_JUMP; list = getjump(fs, list))
     patchtestreg(fs, list, NO_REG);      patchtestreg(fs, list, NO_REG);
} }
   
   
static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, static void patchlistaux (FuncState *fs, int list, int vtarget, int reg,
                         int dtarget) {                          int dtarget) {
 while (list != NO_JUMP) {  while (list != NO_JUMP) {
   int next = getjump(fs, list);    int next = getjump(fs, list);
   if (patchtestreg(fs, list, reg))    if (patchtestreg(fs, list, reg))
     fixjump(fs, list, vtarget);      fixjump(fs, list, vtarget);
   else    else
     fixjump(fs, list, dtarget);  /* jump to default target */       fixjump(fs, list, dtarget);  /* jump to default target */ 
   list = next;    list = next;
 }  }
} }
   
   
static void dischargejpc (FuncState *fs) { static void dischargejpc (FuncState *fs) {
 patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);  patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
 fs->jpc = NO_JUMP;  fs->jpc = NO_JUMP;
} }
   
   
void luaK_patchlist (FuncState *fs, int list, int target) { void luaK_patchlist (FuncState *fs, int list, int target) {
 if (target == fs->pc)  if (target == fs->pc)
   luaK_patchtohere(fs, list);    luaK_patchtohere(fs, list);
 else {  else {
   lua_assert(target < fs->pc);    lua_assert(target < fs->pc);
   patchlistaux(fs, list, target, NO_REG, target);    patchlistaux(fs, list, target, NO_REG, target);
 }  }
} }
   
   
LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level) { LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level) {
 level++;  /* argument is +1 to reserve 0 as non-op */   level++;  /* argument is +1 to reserve 0 as non-op */ 
 while (list != NO_JUMP) {  while (list != NO_JUMP) {
   int next = getjump(fs, list);    int next = getjump(fs, list);
   lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&    lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&
               (GETARG_A(fs->f->code[list]) == 0 ||                (GETARG_A(fs->f->code[list]) == 0 ||
                GETARG_A(fs->f->code[list]) >= level));                 GETARG_A(fs->f->code[list]) >= level));
   SETARG_A(fs->f->code[list], level);    SETARG_A(fs->f->code[list], level);
   list = next;    list = next;
 }  }
} }
   
   
void luaK_patchtohere (FuncState *fs, int list) { void luaK_patchtohere (FuncState *fs, int list) {
 luaK_getlabel(fs);  luaK_getlabel(fs);
 luaK_concat(fs, &fs->jpc, list);  luaK_concat(fs, &fs->jpc, list);
} }
   
   
void luaK_concat (FuncState *fs, int *l1, int l2) { void luaK_concat (FuncState *fs, int *l1, int l2) {
 if (l2 == NO_JUMP) return;  if (l2 == NO_JUMP) return;
 else if (*l1 == NO_JUMP)  else if (*l1 == NO_JUMP)
   *l1 = l2;    *l1 = l2;
 else {  else {
   int list = *l1;    int list = *l1;
   int next;    int next;
   while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */     while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */ 
     list = next;      list = next;
   fixjump(fs, list, l2);    fixjump(fs, list, l2);
 }  }
} }
   
   
static int luaK_code (FuncState *fs, Instruction i) { static int luaK_code (FuncState *fs, Instruction i) {
 Proto *f = fs->f;  Proto *f = fs->f;
 dischargejpc(fs);  /* `pc' will change */   dischargejpc(fs);  /* `pc' will change */ 
 /* put new instruction in code array */   /* put new instruction in code array */ 
 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,  luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
                 MAX_INT, "opcodes");                  MAX_INT, "opcodes");
 f->code[fs->pc] = i;  f->code[fs->pc] = i;
 /* save corresponding line information */   /* save corresponding line information */ 
 luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,  luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
                 MAX_INT, "opcodes");                  MAX_INT, "opcodes");
 f->lineinfo[fs->pc] = fs->ls->lastline;  f->lineinfo[fs->pc] = fs->ls->lastline;
 return fs->pc++;  return fs->pc++;
} }
   
   
int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {
 lua_assert(getOpMode(o) == iABC);  lua_assert(getOpMode(o) == iABC);
 lua_assert(getBMode(o) != OpArgN || b == 0);  lua_assert(getBMode(o) != OpArgN || b == 0);
 lua_assert(getCMode(o) != OpArgN || c == 0);  lua_assert(getCMode(o) != OpArgN || c == 0);
 lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);  lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);
 return luaK_code(fs, CREATE_ABC(o, a, b, c));  return luaK_code(fs, CREATE_ABC(o, a, b, c));
} }
   
   
int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
 lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
 lua_assert(getCMode(o) == OpArgN);  lua_assert(getCMode(o) == OpArgN);
 lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);  lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);
 return luaK_code(fs, CREATE_ABx(o, a, bc));  return luaK_code(fs, CREATE_ABx(o, a, bc));
} }
   
   
static int codeextraarg (FuncState *fs, int a) { static int codeextraarg (FuncState *fs, int a) {
 lua_assert(a <= MAXARG_Ax);  lua_assert(a <= MAXARG_Ax);
 return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));  return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));
} }
   
   
int luaK_codek (FuncState *fs, int reg, int k) { int luaK_codek (FuncState *fs, int reg, int k) {
 if (k <= MAXARG_Bx)  if (k <= MAXARG_Bx)
   return luaK_codeABx(fs, OP_LOADK, reg, k);    return luaK_codeABx(fs, OP_LOADK, reg, k);
 else {  else {
   int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);    int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);
   codeextraarg(fs, k);    codeextraarg(fs, k);
   return p;    return p;
 }  }
} }
   
   
void luaK_checkstack (FuncState *fs, int n) { void luaK_checkstack (FuncState *fs, int n) {
 int newstack = fs->freereg + n;  int newstack = fs->freereg + n;
 if (newstack > fs->f->maxstacksize) {  if (newstack > fs->f->maxstacksize) {
   if (newstack >= MAXSTACK)    if (newstack >= MAXSTACK)
     luaX_syntaxerror(fs->ls, "function or expression too complex");      luaX_syntaxerror(fs->ls, "function or expression too complex");
   fs->f->maxstacksize = cast_byte(newstack);    fs->f->maxstacksize = cast_byte(newstack);
 }  }
} }
   
   
void luaK_reserveregs (FuncState *fs, int n) { void luaK_reserveregs (FuncState *fs, int n) {
 luaK_checkstack(fs, n);  luaK_checkstack(fs, n);
 fs->freereg += n;  fs->freereg += n;
} }
   
   
static void freereg (FuncState *fs, int reg) { static void freereg (FuncState *fs, int reg) {
 if (!ISK(reg) && reg >= fs->nactvar) {  if (!ISK(reg) && reg >= fs->nactvar) {
   fs->freereg--;    fs->freereg--;
   lua_assert(reg == fs->freereg);    lua_assert(reg == fs->freereg);
 }  }
} }
   
   
static void freeexp (FuncState *fs, expdesc *e) { static void freeexp (FuncState *fs, expdesc *e) {
 if (e->k == VNONRELOC)  if (e->k == VNONRELOC)
   freereg(fs, e->u.info);    freereg(fs, e->u.info);
} }
   
   
static int addk (FuncState *fs, TValue *key, TValue *v) { static int addk (FuncState *fs, TValue *key, TValue *v) {
 lua_State *L = fs->ls->L;  lua_State *L = fs->ls->L;
 TValue *idx = luaH_set(L, fs->h, key);  TValue *idx = luaH_set(L, fs->h, key);
 Proto *f = fs->f;  Proto *f = fs->f;
 int k, oldsize;  int k, oldsize;
 if (ttisnumber(idx)) {  if (ttisnumber(idx)) {
   lua_Number n = nvalue(idx);    lua_Number n = nvalue(idx);
   lua_number2int(k, n);    lua_number2int(k, n);
   if (luaV_rawequalobj(&f->k[k], v))    if (luaV_rawequalobj(&f->k[k], v))
     return k;      return k;
   /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");    /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
      go through and create a new entry for this value */        go through and create a new entry for this value */ 
 }  }
 /* constant not found; create a new entry */   /* constant not found; create a new entry */ 
 oldsize = f->sizek;  oldsize = f->sizek;
 k = fs->nk;  k = fs->nk;
 /* numerical value does not need GC barrier;  /* numerical value does not need GC barrier;
    table has no metatable, so it does not need to invalidate cache */      table has no metatable, so it does not need to invalidate cache */ 
 setnvalue(idx, cast_num(k));  setnvalue(idx, cast_num(k));
 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");  luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);  while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
 setobj(L, &f->k[k], v);  setobj(L, &f->k[k], v);
 fs->nk++;  fs->nk++;
 luaC_barrier(L, f, v);  luaC_barrier(L, f, v);
 return k;  return k;
} }
   
   
int luaK_stringK (FuncState *fs, TString *s) { int luaK_stringK (FuncState *fs, TString *s) {
 TValue o;  TValue o;
 setsvalue(fs->ls->L, &o, s);  setsvalue(fs->ls->L, &o, s);
 return addk(fs, &o, &o);  return addk(fs, &o, &o);
} }
   
   
int luaK_numberK (FuncState *fs, lua_Number r) { int luaK_numberK (FuncState *fs, lua_Number r) {
 int n;  int n;
 lua_State *L = fs->ls->L;  lua_State *L = fs->ls->L;
 TValue o;  TValue o;
 setnvalue(&o, r);  setnvalue(&o, r);
 if (r == 0 || luai_numisnan(NULL, r)) {  /* handle -0 and NaN */   if (r == 0 || luai_numisnan(NULL, r)) {  /* handle -0 and NaN */ 
   /* use raw representation as key to avoid numeric problems */     /* use raw representation as key to avoid numeric problems */ 
   setsvalue(L, L->top, luaS_newlstr(L, (char *)&r, sizeof(r)));    setsvalue(L, L->top, luaS_newlstr(L, (char *)&r, sizeof(r)));
    incr_top(L);     incr_top(L);
    n = addk(fs, L->top - 1, &o);     n = addk(fs, L->top - 1, &o);
    L->top--;     L->top--;
 }  }
 else  else
   n = addk(fs, &o, &o);  /* regular case */     n = addk(fs, &o, &o);  /* regular case */ 
 return n;  return n;
} }
   
   
static int boolK (FuncState *fs, int b) { static int boolK (FuncState *fs, int b) {
 TValue o;  TValue o;
 setbvalue(&o, b);  setbvalue(&o, b);
 return addk(fs, &o, &o);  return addk(fs, &o, &o);
} }
   
   
static int nilK (FuncState *fs) { static int nilK (FuncState *fs) {
 TValue k, v;  TValue k, v;
 setnilvalue(&v);  setnilvalue(&v);
 /* cannot use nil as key; instead use table itself to represent nil */   /* cannot use nil as key; instead use table itself to represent nil */ 
 sethvalue(fs->ls->L, &k, fs->h);  sethvalue(fs->ls->L, &k, fs->h);
 return addk(fs, &k, &v);  return addk(fs, &k, &v);
} }
   
   
void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
 if (e->k == VCALL) {  /* expression is an open function call? */   if (e->k == VCALL) {  /* expression is an open function call? */ 
   SETARG_C(getcode(fs, e), nresults+1);    SETARG_C(getcode(fs, e), nresults+1);
 }  }
 else if (e->k == VVARARG) {  else if (e->k == VVARARG) {
   SETARG_B(getcode(fs, e), nresults+1);    SETARG_B(getcode(fs, e), nresults+1);
   SETARG_A(getcode(fs, e), fs->freereg);    SETARG_A(getcode(fs, e), fs->freereg);
   luaK_reserveregs(fs, 1);    luaK_reserveregs(fs, 1);
 }  }
} }
   
   
void luaK_setoneret (FuncState *fs, expdesc *e) { void luaK_setoneret (FuncState *fs, expdesc *e) {
 if (e->k == VCALL) {  /* expression is an open function call? */   if (e->k == VCALL) {  /* expression is an open function call? */ 
   e->k = VNONRELOC;    e->k = VNONRELOC;
   e->u.info = GETARG_A(getcode(fs, e));    e->u.info = GETARG_A(getcode(fs, e));
 }  }
 else if (e->k == VVARARG) {  else if (e->k == VVARARG) {
   SETARG_B(getcode(fs, e), 2);    SETARG_B(getcode(fs, e), 2);
   e->k = VRELOCABLE;  /* can relocate its simple result */     e->k = VRELOCABLE;  /* can relocate its simple result */ 
 }  }
} }
   
   
void luaK_dischargevars (FuncState *fs, expdesc *e) { void luaK_dischargevars (FuncState *fs, expdesc *e) {
 switch (e->k) {  switch (e->k) {
   case VLOCAL: {    case VLOCAL: {
     e->k = VNONRELOC;      e->k = VNONRELOC;
     break;      break;
   }    }
   case VUPVAL: {    case VUPVAL: {
     e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);      e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
     e->k = VRELOCABLE;      e->k = VRELOCABLE;
     break;      break;
   }    }
   case VINDEXED: {    case VINDEXED: {
     OpCode op = OP_GETTABUP;  /* assume 't' is in an upvalue */       OpCode op = OP_GETTABUP;  /* assume 't' is in an upvalue */ 
     freereg(fs, e->u.ind.idx);      freereg(fs, e->u.ind.idx);
     if (e->u.ind.vt == VLOCAL) {  /* 't' is in a register? */       if (e->u.ind.vt == VLOCAL) {  /* 't' is in a register? */ 
       freereg(fs, e->u.ind.t);        freereg(fs, e->u.ind.t);
       op = OP_GETTABLE;        op = OP_GETTABLE;
     }      }
     e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);      e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);
     e->k = VRELOCABLE;      e->k = VRELOCABLE;
     break;      break;
   }    }
   case VVARARG:    case VVARARG:
   case VCALL: {    case VCALL: {
     luaK_setoneret(fs, e);      luaK_setoneret(fs, e);
     break;      break;
   }    }
   default: break;  /* there is one value available (somewhere) */     default: break;  /* there is one value available (somewhere) */ 
 }  }
} }
   
   
static int code_label (FuncState *fs, int A, int b, int jump) { static int code_label (FuncState *fs, int A, int b, int jump) {
 luaK_getlabel(fs);  /* those instructions may be jump targets */   luaK_getlabel(fs);  /* those instructions may be jump targets */ 
 return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
} }
   
   
static void discharge2reg (FuncState *fs, expdesc *e, int reg) { static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
 luaK_dischargevars(fs, e);  luaK_dischargevars(fs, e);
 switch (e->k) {  switch (e->k) {
   case VNIL: {    case VNIL: {
     luaK_nil(fs, reg, 1);      luaK_nil(fs, reg, 1);
     break;      break;
   }    }
   case VFALSE:  case VTRUE: {    case VFALSE:  case VTRUE: {
     luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
     break;      break;
   }    }
   case VK: {    case VK: {
     luaK_codek(fs, reg, e->u.info);      luaK_codek(fs, reg, e->u.info);
     break;      break;
   }    }
   case VKNUM: {    case VKNUM: {
     luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));      luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));
     break;      break;
   }    }
   case VRELOCABLE: {    case VRELOCABLE: {
     Instruction *pc = &getcode(fs, e);      Instruction *pc = &getcode(fs, e);
     SETARG_A(*pc, reg);      SETARG_A(*pc, reg);
     break;      break;
   }    }
   case VNONRELOC: {    case VNONRELOC: {
     if (reg != e->u.info)      if (reg != e->u.info)
       luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);        luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
     break;      break;
   }    }
   default: {    default: {
     lua_assert(e->k == VVOID || e->k == VJMP);      lua_assert(e->k == VVOID || e->k == VJMP);
     return;  /* nothing to do... */       return;  /* nothing to do... */ 
   }    }
 }  }
 e->u.info = reg;  e->u.info = reg;
 e->k = VNONRELOC;  e->k = VNONRELOC;
} }
   
   
static void discharge2anyreg (FuncState *fs, expdesc *e) { static void discharge2anyreg (FuncState *fs, expdesc *e) {
 if (e->k != VNONRELOC) {  if (e->k != VNONRELOC) {
   luaK_reserveregs(fs, 1);    luaK_reserveregs(fs, 1);
   discharge2reg(fs, e, fs->freereg-1);    discharge2reg(fs, e, fs->freereg-1);
 }  }
} }
   
   
static void exp2reg (FuncState *fs, expdesc *e, int reg) { static void exp2reg (FuncState *fs, expdesc *e, int reg) {
 discharge2reg(fs, e, reg);  discharge2reg(fs, e, reg);
 if (e->k == VJMP)  if (e->k == VJMP)
   luaK_concat(fs, &e->t, e->u.info);  /* put this jump in `t' list */     luaK_concat(fs, &e->t, e->u.info);  /* put this jump in `t' list */ 
 if (hasjumps(e)) {  if (hasjumps(e)) {
   int final;  /* position after whole expression */     int final;  /* position after whole expression */ 
   int p_f = NO_JUMP;  /* position of an eventual LOAD false */     int p_f = NO_JUMP;  /* position of an eventual LOAD false */ 
   int p_t = NO_JUMP;  /* position of an eventual LOAD true */     int p_t = NO_JUMP;  /* position of an eventual LOAD true */ 
   if (need_value(fs, e->t) || need_value(fs, e->f)) {    if (need_value(fs, e->t) || need_value(fs, e->f)) {
     int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
     p_f = code_label(fs, reg, 0, 1);      p_f = code_label(fs, reg, 0, 1);
     p_t = code_label(fs, reg, 1, 0);      p_t = code_label(fs, reg, 1, 0);
     luaK_patchtohere(fs, fj);      luaK_patchtohere(fs, fj);
   }    }
   final = luaK_getlabel(fs);    final = luaK_getlabel(fs);
   patchlistaux(fs, e->f, final, reg, p_f);    patchlistaux(fs, e->f, final, reg, p_f);
   patchlistaux(fs, e->t, final, reg, p_t);    patchlistaux(fs, e->t, final, reg, p_t);
 }  }
 e->f = e->t = NO_JUMP;  e->f = e->t = NO_JUMP;
 e->u.info = reg;  e->u.info = reg;
 e->k = VNONRELOC;  e->k = VNONRELOC;
} }
   
   
void luaK_exp2nextreg (FuncState *fs, expdesc *e) { void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
 luaK_dischargevars(fs, e);  luaK_dischargevars(fs, e);
 freeexp(fs, e);  freeexp(fs, e);
 luaK_reserveregs(fs, 1);  luaK_reserveregs(fs, 1);
 exp2reg(fs, e, fs->freereg - 1);  exp2reg(fs, e, fs->freereg - 1);
} }
   
   
int luaK_exp2anyreg (FuncState *fs, expdesc *e) { int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
 luaK_dischargevars(fs, e);  luaK_dischargevars(fs, e);
 if (e->k == VNONRELOC) {  if (e->k == VNONRELOC) {
   if (!hasjumps(e)) return e->u.info;  /* exp is already in a register */     if (!hasjumps(e)) return e->u.info;  /* exp is already in a register */ 
   if (e->u.info >= fs->nactvar) {  /* reg. is not a local? */     if (e->u.info >= fs->nactvar) {  /* reg. is not a local? */ 
     exp2reg(fs, e, e->u.info);  /* put value on it */       exp2reg(fs, e, e->u.info);  /* put value on it */ 
     return e->u.info;      return e->u.info;
   }    }
 }  }
 luaK_exp2nextreg(fs, e);  /* default */   luaK_exp2nextreg(fs, e);  /* default */ 
 return e->u.info;  return e->u.info;
} }
   
   
void luaK_exp2anyregup (FuncState *fs, expdesc *e) { void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
 if (e->k != VUPVAL || hasjumps(e))  if (e->k != VUPVAL || hasjumps(e))
   luaK_exp2anyreg(fs, e);    luaK_exp2anyreg(fs, e);
} }
   
   
void luaK_exp2val (FuncState *fs, expdesc *e) { void luaK_exp2val (FuncState *fs, expdesc *e) {
 if (hasjumps(e))  if (hasjumps(e))
   luaK_exp2anyreg(fs, e);    luaK_exp2anyreg(fs, e);
 else  else
   luaK_dischargevars(fs, e);    luaK_dischargevars(fs, e);
} }
   
   
int luaK_exp2RK (FuncState *fs, expdesc *e) { int luaK_exp2RK (FuncState *fs, expdesc *e) {
 luaK_exp2val(fs, e);  luaK_exp2val(fs, e);
 switch (e->k) {  switch (e->k) {
   case VTRUE:    case VTRUE:
   case VFALSE:    case VFALSE:
   case VNIL: {    case VNIL: {
     if (fs->nk <= MAXINDEXRK) {  /* constant fits in RK operand? */       if (fs->nk <= MAXINDEXRK) {  /* constant fits in RK operand? */ 
       e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));        e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
       e->k = VK;        e->k = VK;
       return RKASK(e->u.info);        return RKASK(e->u.info);
     }      }
     else break;      else break;
   }    }
   case VKNUM: {    case VKNUM: {
     e->u.info = luaK_numberK(fs, e->u.nval);      e->u.info = luaK_numberK(fs, e->u.nval);
     e->k = VK;      e->k = VK;
     /* go through */       /* go through */ 
   }    }
   case VK: {    case VK: {
     if (e->u.info <= MAXINDEXRK)  /* constant fits in argC? */       if (e->u.info <= MAXINDEXRK)  /* constant fits in argC? */ 
       return RKASK(e->u.info);        return RKASK(e->u.info);
     else break;      else break;
   }    }
   default: break;    default: break;
 }  }
 /* not a constant in the right range: put it in a register */   /* not a constant in the right range: put it in a register */ 
 return luaK_exp2anyreg(fs, e);  return luaK_exp2anyreg(fs, e);
} }
   
   
void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
 switch (var->k) {  switch (var->k) {
   case VLOCAL: {    case VLOCAL: {
     freeexp(fs, ex);      freeexp(fs, ex);
     exp2reg(fs, ex, var->u.info);      exp2reg(fs, ex, var->u.info);
     return;      return;
   }    }
   case VUPVAL: {    case VUPVAL: {
     int e = luaK_exp2anyreg(fs, ex);      int e = luaK_exp2anyreg(fs, ex);
     luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
     break;      break;
   }    }
   case VINDEXED: {    case VINDEXED: {
     OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;      OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;
     int e = luaK_exp2RK(fs, ex);      int e = luaK_exp2RK(fs, ex);
     luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);      luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);
     break;      break;
   }    }
   default: {    default: {
     lua_assert(0);  /* invalid var kind to store */       lua_assert(0);  /* invalid var kind to store */ 
     break;      break;
   }    }
 }  }
 freeexp(fs, ex);  freeexp(fs, ex);
} }
   
   
void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
 int ereg;  int ereg;
 luaK_exp2anyreg(fs, e);  luaK_exp2anyreg(fs, e);
 ereg = e->u.info;  /* register where 'e' was placed */   ereg = e->u.info;  /* register where 'e' was placed */ 
 freeexp(fs, e);  freeexp(fs, e);
 e->u.info = fs->freereg;  /* base register for op_self */   e->u.info = fs->freereg;  /* base register for op_self */ 
 e->k = VNONRELOC;  e->k = VNONRELOC;
 luaK_reserveregs(fs, 2);  /* function and 'self' produced by op_self */   luaK_reserveregs(fs, 2);  /* function and 'self' produced by op_self */ 
 luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));  luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));
 freeexp(fs, key);  freeexp(fs, key);
} }
   
   
static void invertjump (FuncState *fs, expdesc *e) { static void invertjump (FuncState *fs, expdesc *e) {
 Instruction *pc = getjumpcontrol(fs, e->u.info);  Instruction *pc = getjumpcontrol(fs, e->u.info);
 lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
                                          GET_OPCODE(*pc) != OP_TEST);                                           GET_OPCODE(*pc) != OP_TEST);
 SETARG_A(*pc, !(GETARG_A(*pc)));  SETARG_A(*pc, !(GETARG_A(*pc)));
} }
   
   
static int jumponcond (FuncState *fs, expdesc *e, int cond) { static int jumponcond (FuncState *fs, expdesc *e, int cond) {
 if (e->k == VRELOCABLE) {  if (e->k == VRELOCABLE) {
   Instruction ie = getcode(fs, e);    Instruction ie = getcode(fs, e);
   if (GET_OPCODE(ie) == OP_NOT) {    if (GET_OPCODE(ie) == OP_NOT) {
     fs->pc--;  /* remove previous OP_NOT */       fs->pc--;  /* remove previous OP_NOT */ 
     return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);      return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
   }    }
   /* else go through */     /* else go through */ 
 }  }
 discharge2anyreg(fs, e);  discharge2anyreg(fs, e);
 freeexp(fs, e);  freeexp(fs, e);
 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);  return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
} }
   
   
void luaK_goiftrue (FuncState *fs, expdesc *e) { void luaK_goiftrue (FuncState *fs, expdesc *e) {
 int pc;  /* pc of last jump */   int pc;  /* pc of last jump */ 
 luaK_dischargevars(fs, e);  luaK_dischargevars(fs, e);
 switch (e->k) {  switch (e->k) {
   case VJMP: {    case VJMP: {
     invertjump(fs, e);      invertjump(fs, e);
     pc = e->u.info;      pc = e->u.info;
     break;      break;
   }    }
   case VK: case VKNUM: case VTRUE: {    case VK: case VKNUM: case VTRUE: {
     pc = NO_JUMP;  /* always true; do nothing */       pc = NO_JUMP;  /* always true; do nothing */ 
     break;      break;
   }    }
   default: {    default: {
     pc = jumponcond(fs, e, 0);      pc = jumponcond(fs, e, 0);
     break;      break;
   }    }
 }  }
 luaK_concat(fs, &e->f, pc);  /* insert last jump in `f' list */   luaK_concat(fs, &e->f, pc);  /* insert last jump in `f' list */ 
 luaK_patchtohere(fs, e->t);  luaK_patchtohere(fs, e->t);
 e->t = NO_JUMP;  e->t = NO_JUMP;
} }
   
   
void luaK_goiffalse (FuncState *fs, expdesc *e) { void luaK_goiffalse (FuncState *fs, expdesc *e) {
 int pc;  /* pc of last jump */   int pc;  /* pc of last jump */ 
 luaK_dischargevars(fs, e);  luaK_dischargevars(fs, e);
 switch (e->k) {  switch (e->k) {
   case VJMP: {    case VJMP: {
     pc = e->u.info;      pc = e->u.info;
     break;      break;
   }    }
   case VNIL: case VFALSE: {    case VNIL: case VFALSE: {
     pc = NO_JUMP;  /* always false; do nothing */       pc = NO_JUMP;  /* always false; do nothing */ 
     break;      break;
   }    }
   default: {    default: {
     pc = jumponcond(fs, e, 1);      pc = jumponcond(fs, e, 1);
     break;      break;
   }    }
 }  }
 luaK_concat(fs, &e->t, pc);  /* insert last jump in `t' list */   luaK_concat(fs, &e->t, pc);  /* insert last jump in `t' list */ 
 luaK_patchtohere(fs, e->f);  luaK_patchtohere(fs, e->f);
 e->f = NO_JUMP;  e->f = NO_JUMP;
} }
   
   
static void codenot (FuncState *fs, expdesc *e) { static void codenot (FuncState *fs, expdesc *e) {
 luaK_dischargevars(fs, e);  luaK_dischargevars(fs, e);
 switch (e->k) {  switch (e->k) {
   case VNIL: case VFALSE: {    case VNIL: case VFALSE: {
     e->k = VTRUE;      e->k = VTRUE;
     break;      break;
   }    }
   case VK: case VKNUM: case VTRUE: {    case VK: case VKNUM: case VTRUE: {
     e->k = VFALSE;      e->k = VFALSE;
     break;      break;
   }    }
   case VJMP: {    case VJMP: {
     invertjump(fs, e);      invertjump(fs, e);
     break;      break;
   }    }
   case VRELOCABLE:    case VRELOCABLE:
   case VNONRELOC: {    case VNONRELOC: {
     discharge2anyreg(fs, e);      discharge2anyreg(fs, e);
     freeexp(fs, e);      freeexp(fs, e);
     e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);      e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
     e->k = VRELOCABLE;      e->k = VRELOCABLE;
     break;      break;
   }    }
   default: {    default: {
     lua_assert(0);  /* cannot happen */       lua_assert(0);  /* cannot happen */ 
     break;      break;
   }    }
 }  }
 /* interchange true and false lists */   /* interchange true and false lists */ 
 { int temp = e->f; e->f = e->t; e->t = temp; }  { int temp = e->f; e->f = e->t; e->t = temp; }
 removevalues(fs, e->f);  removevalues(fs, e->f);
 removevalues(fs, e->t);  removevalues(fs, e->t);
} }
   
   
void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
 lua_assert(!hasjumps(t));  lua_assert(!hasjumps(t));
 t->u.ind.t = t->u.info;  t->u.ind.t = t->u.info;
 t->u.ind.idx = luaK_exp2RK(fs, k);  t->u.ind.idx = luaK_exp2RK(fs, k);
 t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL  t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL
                                : check_exp(vkisinreg(t->k), VLOCAL);                                 : check_exp(vkisinreg(t->k), VLOCAL);
 t->k = VINDEXED;  t->k = VINDEXED;
} }
   
   
static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
 lua_Number r;  lua_Number r;
 if (!isnumeral(e1) || !isnumeral(e2)) return 0;  if (!isnumeral(e1) || !isnumeral(e2)) return 0;
 if ((op == OP_DIV || op == OP_MOD) && e2->u.nval == 0)  if ((op == OP_DIV || op == OP_MOD) && e2->u.nval == 0)
   return 0;  /* do not attempt to divide by 0 */     return 0;  /* do not attempt to divide by 0 */ 
 r = luaO_arith(op - OP_ADD + LUA_OPADD, e1->u.nval, e2->u.nval);  r = luaO_arith(op - OP_ADD + LUA_OPADD, e1->u.nval, e2->u.nval);
 e1->u.nval = r;  e1->u.nval = r;
 return 1;  return 1;
} }
   
   
static void codearith (FuncState *fs, OpCode op, static void codearith (FuncState *fs, OpCode op,
                      expdesc *e1, expdesc *e2, int line) {                       expdesc *e1, expdesc *e2, int line) {
 if (constfolding(op, e1, e2))  if (constfolding(op, e1, e2))
   return;    return;
 else {  else {
   int o2 = (op != OP_UNM && op != OP_LEN     int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; 
#ifdef GCW_BIT  
&& op != OP_BNOT        && op != OP_LNOT  
#endif  
) ? luaK_exp2RK(fs, e2) : 0;  
   int o1 = luaK_exp2RK(fs, e1);    int o1 = luaK_exp2RK(fs, e1);
   if (o1 > o2) {    if (o1 > o2) {
     freeexp(fs, e1);      freeexp(fs, e1);
     freeexp(fs, e2);      freeexp(fs, e2);
   }    }
   else {    else {
     freeexp(fs, e2);      freeexp(fs, e2);
     freeexp(fs, e1);      freeexp(fs, e1);
   }    }
   e1->u.info = luaK_codeABC(fs, op, 0, o1, o2);    e1->u.info = luaK_codeABC(fs, op, 0, o1, o2);
   e1->k = VRELOCABLE;    e1->k = VRELOCABLE;
   luaK_fixline(fs, line);    luaK_fixline(fs, line);
 }  }
} }
   
   
static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
                                                         expdesc *e2) {                                                          expdesc *e2) {
 int o1 = luaK_exp2RK(fs, e1);  int o1 = luaK_exp2RK(fs, e1);
 int o2 = luaK_exp2RK(fs, e2);  int o2 = luaK_exp2RK(fs, e2);
 freeexp(fs, e2);  freeexp(fs, e2);
 freeexp(fs, e1);  freeexp(fs, e1);
 if (cond == 0 && op != OP_EQ) {  if (cond == 0 && op != OP_EQ) {
   int temp;  /* exchange args to replace by `<' or `<=' */     int temp;  /* exchange args to replace by `<' or `<=' */ 
   temp = o1; o1 = o2; o2 = temp;  /* o1 <==> o2 */     temp = o1; o1 = o2; o2 = temp;  /* o1 <==> o2 */ 
   cond = 1;    cond = 1;
 }  }
 e1->u.info = condjump(fs, op, cond, o1, o2);  e1->u.info = condjump(fs, op, cond, o1, o2);
 e1->k = VJMP;  e1->k = VJMP;
} }
   
   
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) { void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
 expdesc e2;  expdesc e2;
 e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;  e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
 switch (op) {  switch (op) {
   case OPR_MINUS: {    case OPR_MINUS: {
     if (isnumeral(e))  /* minus constant? */       if (isnumeral(e))  /* minus constant? */ 
       e->u.nval = luai_numunm(NULL, e->u.nval);  /* fold it */         e->u.nval = luai_numunm(NULL, e->u.nval);  /* fold it */ 
     else {      else {
       luaK_exp2anyreg(fs, e);        luaK_exp2anyreg(fs, e);
       codearith(fs, OP_UNM, e, &e2, line);        codearith(fs, OP_UNM, e, &e2, line);
     }      }
     break;      break;
   }    }
   case OPR_NOT: codenot(fs, e); break;    case OPR_NOT: codenot(fs, e); break;
   case OPR_LEN: {    case OPR_LEN: {
     luaK_exp2anyreg(fs, e);  /* cannot operate on constants */       luaK_exp2anyreg(fs, e);  /* cannot operate on constants */ 
     codearith(fs, OP_LEN, e, &e2, line);      codearith(fs, OP_LEN, e, &e2, line);
     break;      break;
   }    }
#ifdef GCW_BIT  
  case OPR_BNOT: {  
     if (e->k == VK)  
       luaK_exp2anyreg(fs, e);  /* cannot operate on non-numeric constants */   
     codearith(fs, OP_BNOT, e, &e2, line);  
     break;  
   }  
  case OPR_LNOT: {  
     if (e->k == VK)  
       luaK_exp2anyreg(fs, e);  /* cannot operate on non-numeric constants */   
     codearith(fs, OP_LNOT, e, &e2, line);  
     break;  
   }  
#endif  
   default: lua_assert(0);    default: lua_assert(0);
 }  }
} }
   
   
void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
 switch (op) {  switch (op) {
   case OPR_AND: {    case OPR_AND: {
     luaK_goiftrue(fs, v);      luaK_goiftrue(fs, v);
     break;      break;
   }    }
   case OPR_OR: {    case OPR_OR: {
     luaK_goiffalse(fs, v);      luaK_goiffalse(fs, v);
     break;      break;
   }    }
   case OPR_CONCAT: {    case OPR_CONCAT: {
     luaK_exp2nextreg(fs, v);  /* operand must be on the `stack' */       luaK_exp2nextreg(fs, v);  /* operand must be on the `stack' */ 
     break;      break;
   }    }
   case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
#ifdef GCW_BIT  
   case OPR_MOD: case OPR_POW: case OPR_BAND: case OPR_BOR:  
   case OPR_BXOR: case OPR_BLSH: case OPR_BRSH:    
      
   case OPR_LAND: case OPR_LOR:  
   {  
#else  
   case OPR_MOD: case OPR_POW: {    case OPR_MOD: case OPR_POW: {
#endif  
     if (!isnumeral(v)) luaK_exp2RK(fs, v);      if (!isnumeral(v)) luaK_exp2RK(fs, v);
     break;      break;
   }    }
   default: {    default: {
     luaK_exp2RK(fs, v);      luaK_exp2RK(fs, v);
     break;      break;
   }    }
 }  }
} }
   
   
void luaK_posfix (FuncState *fs, BinOpr op, void luaK_posfix (FuncState *fs, BinOpr op,
                 expdesc *e1, expdesc *e2, int line) {                  expdesc *e1, expdesc *e2, int line) {
 switch (op) {  switch (op) {
   case OPR_AND: {    case OPR_AND: {
     lua_assert(e1->t == NO_JUMP);  /* list must be closed */       lua_assert(e1->t == NO_JUMP);  /* list must be closed */ 
     luaK_dischargevars(fs, e2);      luaK_dischargevars(fs, e2);
     luaK_concat(fs, &e2->f, e1->f);      luaK_concat(fs, &e2->f, e1->f);
     *e1 = *e2;      *e1 = *e2;
     break;      break;
   }    }
   case OPR_OR: {    case OPR_OR: {
     lua_assert(e1->f == NO_JUMP);  /* list must be closed */       lua_assert(e1->f == NO_JUMP);  /* list must be closed */ 
     luaK_dischargevars(fs, e2);      luaK_dischargevars(fs, e2);
     luaK_concat(fs, &e2->t, e1->t);      luaK_concat(fs, &e2->t, e1->t);
     *e1 = *e2;      *e1 = *e2;
     break;      break;
   }    }
   case OPR_CONCAT: {    case OPR_CONCAT: {
     luaK_exp2val(fs, e2);      luaK_exp2val(fs, e2);
     if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {      if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
       lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1);        lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1);
       freeexp(fs, e1);        freeexp(fs, e1);
       SETARG_B(getcode(fs, e2), e1->u.info);        SETARG_B(getcode(fs, e2), e1->u.info);
       e1->k = VRELOCABLE; e1->u.info = e2->u.info;        e1->k = VRELOCABLE; e1->u.info = e2->u.info;
     }      }
     else {      else {
       luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */         luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */ 
       codearith(fs, OP_CONCAT, e1, e2, line);        codearith(fs, OP_CONCAT, e1, e2, line);
     }      }
     break;      break;
   }    }
   case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
   case OPR_MOD: case OPR_POW: {    case OPR_MOD: case OPR_POW: {
     codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line);      codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line);
     break;      break;
   }    }
#ifdef GCW_BIT  
   case OPR_BAND: case OPR_BOR: case OPR_BXOR: case OPR_BLSH: case OPR_BRSH:    
   case OPR_LAND: case OPR_LOR:  
   {  
     codearith(fs, cast(OpCode, op - OPR_BAND + OP_BAND), e1, e2, line);  
     break;  
   }  
#endif  
   case OPR_EQ: case OPR_LT: case OPR_LE: {    case OPR_EQ: case OPR_LT: case OPR_LE: {
     codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);      codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);
     break;      break;
   }    }
   case OPR_NE: case OPR_GT: case OPR_GE: {    case OPR_NE: case OPR_GT: case OPR_GE: {
     codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);      codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);
     break;      break;
   }    }
   default: lua_assert(0);    default: lua_assert(0);
 }  }
} }
   
   
void luaK_fixline (FuncState *fs, int line) { void luaK_fixline (FuncState *fs, int line) {
 fs->f->lineinfo[fs->pc - 1] = line;  fs->f->lineinfo[fs->pc - 1] = line;
} }
   
   
void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {
 int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;  int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;
 int b = (tostore == LUA_MULTRET) ? 0 : tostore;  int b = (tostore == LUA_MULTRET) ? 0 : tostore;
 lua_assert(tostore != 0);  lua_assert(tostore != 0);
 if (c <= MAXARG_C)  if (c <= MAXARG_C)
   luaK_codeABC(fs, OP_SETLIST, base, b, c);    luaK_codeABC(fs, OP_SETLIST, base, b, c);
 else if (c <= MAXARG_Ax) {  else if (c <= MAXARG_Ax) {
   luaK_codeABC(fs, OP_SETLIST, base, b, 0);    luaK_codeABC(fs, OP_SETLIST, base, b, 0);
   codeextraarg(fs, c);    codeextraarg(fs, c);
 }  }
 else  else
   luaX_syntaxerror(fs->ls, "constructor too long");    luaX_syntaxerror(fs->ls, "constructor too long");
 fs->freereg = base + 1;  /* free registers with list values */   fs->freereg = base + 1;  /* free registers with list values */ 
} }