Lines Matching refs:fs
45 static int codesJ (FuncState *fs, OpCode o, int sj, int k);
80 static TValue *const2val (FuncState *fs, const expdesc *e) { in const2val() argument
82 return &fs->ls->dyd->actvar.arr[e->u.info].k; in const2val()
90 int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v) { in luaK_exp2const() argument
104 setsvalue(fs->ls->L, v, e->u.strval); in luaK_exp2const()
108 setobj(fs->ls->L, v, const2val(fs, e)); in luaK_exp2const()
122 static Instruction *previousinstruction (FuncState *fs) { in previousinstruction() argument
124 if (fs->pc > fs->lasttarget) in previousinstruction()
125 return &fs->f->code[fs->pc - 1]; /* previous instruction */ in previousinstruction()
137 void luaK_nil (FuncState *fs, int from, int n) { in luaK_nil() argument
139 Instruction *previous = previousinstruction(fs); in luaK_nil()
152 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ in luaK_nil()
160 static int getjump (FuncState *fs, int pc) { in getjump() argument
161 int offset = GETARG_sJ(fs->f->code[pc]); in getjump()
173 static void fixjump (FuncState *fs, int pc, int dest) { in fixjump() argument
174 Instruction *jmp = &fs->f->code[pc]; in fixjump()
178 luaX_syntaxerror(fs->ls, "control structure too long"); in fixjump()
187 void luaK_concat (FuncState *fs, int *l1, int l2) { in luaK_concat() argument
194 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ in luaK_concat()
196 fixjump(fs, list, l2); /* last element links to 'l2' */ in luaK_concat()
205 int luaK_jump (FuncState *fs) { in luaK_jump() argument
206 return codesJ(fs, OP_JMP, NO_JUMP, 0); in luaK_jump()
213 void luaK_ret (FuncState *fs, int first, int nret) { in luaK_ret() argument
220 luaK_codeABC(fs, op, first, nret + 1, 0); in luaK_ret()
228 static int condjump (FuncState *fs, OpCode op, int A, int B, int C, int k) { in condjump() argument
229 luaK_codeABCk(fs, op, A, B, C, k); in condjump()
230 return luaK_jump(fs); in condjump()
238 int luaK_getlabel (FuncState *fs) { in luaK_getlabel() argument
239 fs->lasttarget = fs->pc; in luaK_getlabel()
240 return fs->pc; in luaK_getlabel()
249 static Instruction *getjumpcontrol (FuncState *fs, int pc) { in getjumpcontrol() argument
250 Instruction *pi = &fs->f->code[pc]; in getjumpcontrol()
265 static int patchtestreg (FuncState *fs, int node, int reg) { in patchtestreg() argument
266 Instruction *i = getjumpcontrol(fs, node); in patchtestreg()
283 static void removevalues (FuncState *fs, int list) { in removevalues() argument
284 for (; list != NO_JUMP; list = getjump(fs, list)) in removevalues()
285 patchtestreg(fs, list, NO_REG); in removevalues()
294 static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, in patchlistaux() argument
297 int next = getjump(fs, list); in patchlistaux()
298 if (patchtestreg(fs, list, reg)) in patchlistaux()
299 fixjump(fs, list, vtarget); in patchlistaux()
301 fixjump(fs, list, dtarget); /* jump to default target */ in patchlistaux()
312 void luaK_patchlist (FuncState *fs, int list, int target) { in luaK_patchlist() argument
313 lua_assert(target <= fs->pc); in luaK_patchlist()
314 patchlistaux(fs, list, target, NO_REG, target); in luaK_patchlist()
318 void luaK_patchtohere (FuncState *fs, int list) { in luaK_patchtohere() argument
319 int hr = luaK_getlabel(fs); /* mark "here" as a jump target */ in luaK_patchtohere()
320 luaK_patchlist(fs, list, hr); in luaK_patchtohere()
335 static void savelineinfo (FuncState *fs, Proto *f, int line) { in savelineinfo() argument
336 int linedif = line - fs->previousline; in savelineinfo()
337 int pc = fs->pc - 1; /* last instruction coded */ in savelineinfo()
338 if (abs(linedif) >= LIMLINEDIFF || fs->iwthabs++ >= MAXIWTHABS) { in savelineinfo()
339 luaM_growvector(fs->ls->L, f->abslineinfo, fs->nabslineinfo, in savelineinfo()
341 f->abslineinfo[fs->nabslineinfo].pc = pc; in savelineinfo()
342 f->abslineinfo[fs->nabslineinfo++].line = line; in savelineinfo()
344 fs->iwthabs = 1; /* restart counter */ in savelineinfo()
346 luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte, in savelineinfo()
349 fs->previousline = line; /* last line saved */ in savelineinfo()
359 static void removelastlineinfo (FuncState *fs) { in removelastlineinfo() argument
360 Proto *f = fs->f; in removelastlineinfo()
361 int pc = fs->pc - 1; /* last instruction coded */ in removelastlineinfo()
363 fs->previousline -= f->lineinfo[pc]; /* correct last line saved */ in removelastlineinfo()
364 fs->iwthabs--; /* undo previous increment */ in removelastlineinfo()
367 lua_assert(f->abslineinfo[fs->nabslineinfo - 1].pc == pc); in removelastlineinfo()
368 fs->nabslineinfo--; /* remove it */ in removelastlineinfo()
369 fs->iwthabs = MAXIWTHABS + 1; /* force next line info to be absolute */ in removelastlineinfo()
378 static void removelastinstruction (FuncState *fs) { in removelastinstruction() argument
379 removelastlineinfo(fs); in removelastinstruction()
380 fs->pc--; in removelastinstruction()
388 int luaK_code (FuncState *fs, Instruction i) { in luaK_code() argument
389 Proto *f = fs->f; in luaK_code()
391 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction, in luaK_code()
393 f->code[fs->pc++] = i; in luaK_code()
394 savelineinfo(fs, f, fs->ls->lastline); in luaK_code()
395 return fs->pc - 1; /* index of new instruction */ in luaK_code()
403 int luaK_codeABCk (FuncState *fs, OpCode o, int a, int b, int c, int k) { in luaK_codeABCk() argument
407 return luaK_code(fs, CREATE_ABCk(o, a, b, c, k)); in luaK_codeABCk()
414 int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { in luaK_codeABx() argument
417 return luaK_code(fs, CREATE_ABx(o, a, bc)); in luaK_codeABx()
424 int luaK_codeAsBx (FuncState *fs, OpCode o, int a, int bc) { in luaK_codeAsBx() argument
428 return luaK_code(fs, CREATE_ABx(o, a, b)); in luaK_codeAsBx()
435 static int codesJ (FuncState *fs, OpCode o, int sj, int k) { in codesJ() argument
439 return luaK_code(fs, CREATE_sJ(o, j, k)); in codesJ()
446 static int codeextraarg (FuncState *fs, int a) { in codeextraarg() argument
448 return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a)); in codeextraarg()
457 static int luaK_codek (FuncState *fs, int reg, int k) { in luaK_codek() argument
459 return luaK_codeABx(fs, OP_LOADK, reg, k); in luaK_codek()
461 int p = luaK_codeABx(fs, OP_LOADKX, reg, 0); in luaK_codek()
462 codeextraarg(fs, k); in luaK_codek()
472 void luaK_checkstack (FuncState *fs, int n) { in luaK_checkstack() argument
473 int newstack = fs->freereg + n; in luaK_checkstack()
474 if (newstack > fs->f->maxstacksize) { in luaK_checkstack()
476 luaX_syntaxerror(fs->ls, in luaK_checkstack()
478 fs->f->maxstacksize = cast_byte(newstack); in luaK_checkstack()
486 void luaK_reserveregs (FuncState *fs, int n) { in luaK_reserveregs() argument
487 luaK_checkstack(fs, n); in luaK_reserveregs()
488 fs->freereg += n; in luaK_reserveregs()
497 static void freereg (FuncState *fs, int reg) { in freereg() argument
498 if (reg >= luaY_nvarstack(fs)) { in freereg()
499 fs->freereg--; in freereg()
500 lua_assert(reg == fs->freereg); in freereg()
508 static void freeregs (FuncState *fs, int r1, int r2) { in freeregs() argument
510 freereg(fs, r1); in freeregs()
511 freereg(fs, r2); in freeregs()
514 freereg(fs, r2); in freeregs()
515 freereg(fs, r1); in freeregs()
523 static void freeexp (FuncState *fs, expdesc *e) { in freeexp() argument
525 freereg(fs, e->u.info); in freeexp()
533 static void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) { in freeexps() argument
536 freeregs(fs, r1, r2); in freeexps()
549 static int addk (FuncState *fs, TValue *key, TValue *v) { in addk() argument
551 lua_State *L = fs->ls->L; in addk()
552 Proto *f = fs->f; in addk()
553 const TValue *idx = luaH_get(fs->ls->h, key); /* query scanner table */ in addk()
558 if (k < fs->nk && ttypetag(&f->k[k]) == ttypetag(v) && in addk()
564 k = fs->nk; in addk()
568 luaH_finishset(L, fs->ls->h, key, idx, &val); in addk()
572 fs->nk++; in addk()
581 static int stringK (FuncState *fs, TString *s) { in stringK() argument
583 setsvalue(fs->ls->L, &o, s); in stringK()
584 return addk(fs, &o, &o); /* use string itself as key */ in stringK()
591 static int luaK_intK (FuncState *fs, lua_Integer n) { in luaK_intK() argument
594 return addk(fs, &o, &o); /* use integer itself as key */ in luaK_intK()
610 static int luaK_numberK (FuncState *fs, lua_Number r) { in luaK_numberK() argument
615 return addk(fs, &o, &o); /* use number itself as key */ in luaK_numberK()
625 return addk(fs, &kv, &o); in luaK_numberK()
634 static int boolF (FuncState *fs) { in boolF() argument
637 return addk(fs, &o, &o); /* use boolean itself as key */ in boolF()
644 static int boolT (FuncState *fs) { in boolT() argument
647 return addk(fs, &o, &o); /* use boolean itself as key */ in boolT()
654 static int nilK (FuncState *fs) { in nilK() argument
658 sethvalue(fs->ls->L, &k, fs->ls->h); in nilK()
659 return addk(fs, &k, &v); in nilK()
681 void luaK_int (FuncState *fs, int reg, lua_Integer i) { in luaK_int() argument
683 luaK_codeAsBx(fs, OP_LOADI, reg, cast_int(i)); in luaK_int()
685 luaK_codek(fs, reg, luaK_intK(fs, i)); in luaK_int()
690 static void luaK_float (FuncState *fs, int reg, lua_Number f) { in luaK_float() argument
693 luaK_codeAsBx(fs, OP_LOADF, reg, cast_int(fi)); in luaK_float()
695 luaK_codek(fs, reg, luaK_numberK(fs, f)); in luaK_float()
734 void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { in luaK_setreturns() argument
735 Instruction *pc = &getinstruction(fs, e); in luaK_setreturns()
741 SETARG_A(*pc, fs->freereg); in luaK_setreturns()
742 luaK_reserveregs(fs, 1); in luaK_setreturns()
750 static void str2K (FuncState *fs, expdesc *e) { in str2K() argument
752 e->u.info = stringK(fs, e->u.strval); in str2K()
767 void luaK_setoneret (FuncState *fs, expdesc *e) { in luaK_setoneret() argument
770 lua_assert(GETARG_C(getinstruction(fs, e)) == 2); in luaK_setoneret()
772 e->u.info = GETARG_A(getinstruction(fs, e)); in luaK_setoneret()
775 SETARG_C(getinstruction(fs, e), 2); in luaK_setoneret()
785 void luaK_dischargevars (FuncState *fs, expdesc *e) { in luaK_dischargevars() argument
788 const2exp(const2val(fs, e), e); in luaK_dischargevars()
797 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0); in luaK_dischargevars()
802 e->u.info = luaK_codeABC(fs, OP_GETTABUP, 0, e->u.ind.t, e->u.ind.idx); in luaK_dischargevars()
807 freereg(fs, e->u.ind.t); in luaK_dischargevars()
808 e->u.info = luaK_codeABC(fs, OP_GETI, 0, e->u.ind.t, e->u.ind.idx); in luaK_dischargevars()
813 freereg(fs, e->u.ind.t); in luaK_dischargevars()
814 e->u.info = luaK_codeABC(fs, OP_GETFIELD, 0, e->u.ind.t, e->u.ind.idx); in luaK_dischargevars()
819 freeregs(fs, e->u.ind.t, e->u.ind.idx); in luaK_dischargevars()
820 e->u.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.ind.t, e->u.ind.idx); in luaK_dischargevars()
825 luaK_setoneret(fs, e); in luaK_dischargevars()
838 static void discharge2reg (FuncState *fs, expdesc *e, int reg) { in discharge2reg() argument
839 luaK_dischargevars(fs, e); in discharge2reg()
842 luaK_nil(fs, reg, 1); in discharge2reg()
846 luaK_codeABC(fs, OP_LOADFALSE, reg, 0, 0); in discharge2reg()
850 luaK_codeABC(fs, OP_LOADTRUE, reg, 0, 0); in discharge2reg()
854 str2K(fs, e); in discharge2reg()
857 luaK_codek(fs, reg, e->u.info); in discharge2reg()
862 luaK_float(fs, reg, e->u.nval); in discharge2reg()
867 luaK_int(fs, reg, e->u.ival); in discharge2reg()
871 Instruction *pc = &getinstruction(fs, e); in discharge2reg()
877 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0); in discharge2reg()
895 static void discharge2anyreg (FuncState *fs, expdesc *e) { in discharge2anyreg() argument
897 luaK_reserveregs(fs, 1); /* get a register */ in discharge2anyreg()
898 discharge2reg(fs, e, fs->freereg-1); /* put value there */ in discharge2anyreg()
903 static int code_loadbool (FuncState *fs, int A, OpCode op) { in code_loadbool() argument
904 luaK_getlabel(fs); /* those instructions may be jump targets */ in code_loadbool()
905 return luaK_codeABC(fs, op, A, 0, 0); in code_loadbool()
913 static int need_value (FuncState *fs, int list) { in need_value() argument
914 for (; list != NO_JUMP; list = getjump(fs, list)) { in need_value()
915 Instruction i = *getjumpcontrol(fs, list); in need_value()
929 static void exp2reg (FuncState *fs, expdesc *e, int reg) { in exp2reg() argument
930 discharge2reg(fs, e, reg); in exp2reg()
932 luaK_concat(fs, &e->t, e->u.info); /* put this jump in 't' list */ in exp2reg()
937 if (need_value(fs, e->t) || need_value(fs, e->f)) { in exp2reg()
938 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); in exp2reg()
939 p_f = code_loadbool(fs, reg, OP_LFALSESKIP); /* skip next inst. */ in exp2reg()
940 p_t = code_loadbool(fs, reg, OP_LOADTRUE); in exp2reg()
942 luaK_patchtohere(fs, fj); in exp2reg()
944 final = luaK_getlabel(fs); in exp2reg()
945 patchlistaux(fs, e->f, final, reg, p_f); in exp2reg()
946 patchlistaux(fs, e->t, final, reg, p_t); in exp2reg()
957 void luaK_exp2nextreg (FuncState *fs, expdesc *e) { in luaK_exp2nextreg() argument
958 luaK_dischargevars(fs, e); in luaK_exp2nextreg()
959 freeexp(fs, e); in luaK_exp2nextreg()
960 luaK_reserveregs(fs, 1); in luaK_exp2nextreg()
961 exp2reg(fs, e, fs->freereg - 1); in luaK_exp2nextreg()
969 int luaK_exp2anyreg (FuncState *fs, expdesc *e) { in luaK_exp2anyreg() argument
970 luaK_dischargevars(fs, e); in luaK_exp2anyreg()
974 if (e->u.info >= luaY_nvarstack(fs)) { /* reg. is not a local? */ in luaK_exp2anyreg()
975 exp2reg(fs, e, e->u.info); /* put final result in it */ in luaK_exp2anyreg()
982 luaK_exp2nextreg(fs, e); /* default: use next available register */ in luaK_exp2anyreg()
991 void luaK_exp2anyregup (FuncState *fs, expdesc *e) { in luaK_exp2anyregup() argument
993 luaK_exp2anyreg(fs, e); in luaK_exp2anyregup()
1001 void luaK_exp2val (FuncState *fs, expdesc *e) { in luaK_exp2val() argument
1003 luaK_exp2anyreg(fs, e); in luaK_exp2val()
1005 luaK_dischargevars(fs, e); in luaK_exp2val()
1013 static int luaK_exp2K (FuncState *fs, expdesc *e) { in luaK_exp2K() argument
1017 case VTRUE: info = boolT(fs); break; in luaK_exp2K()
1018 case VFALSE: info = boolF(fs); break; in luaK_exp2K()
1019 case VNIL: info = nilK(fs); break; in luaK_exp2K()
1020 case VKINT: info = luaK_intK(fs, e->u.ival); break; in luaK_exp2K()
1022 case VKFLT: info = luaK_numberK(fs, e->u.nval); break; in luaK_exp2K()
1024 case VKSTR: info = stringK(fs, e->u.strval); break; in luaK_exp2K()
1045 int luaK_exp2RK (FuncState *fs, expdesc *e) { in luaK_exp2RK() argument
1046 if (luaK_exp2K(fs, e)) in luaK_exp2RK()
1049 luaK_exp2anyreg(fs, e); in luaK_exp2RK()
1055 static void codeABRK (FuncState *fs, OpCode o, int a, int b, in codeABRK() argument
1057 int k = luaK_exp2RK(fs, ec); in codeABRK()
1058 luaK_codeABCk(fs, o, a, b, ec->u.info, k); in codeABRK()
1065 void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { in luaK_storevar() argument
1068 freeexp(fs, ex); in luaK_storevar()
1069 exp2reg(fs, ex, var->u.var.ridx); /* compute 'ex' into proper place */ in luaK_storevar()
1073 int e = luaK_exp2anyreg(fs, ex); in luaK_storevar()
1074 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0); in luaK_storevar()
1078 codeABRK(fs, OP_SETTABUP, var->u.ind.t, var->u.ind.idx, ex); in luaK_storevar()
1082 codeABRK(fs, OP_SETI, var->u.ind.t, var->u.ind.idx, ex); in luaK_storevar()
1086 codeABRK(fs, OP_SETFIELD, var->u.ind.t, var->u.ind.idx, ex); in luaK_storevar()
1090 codeABRK(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, ex); in luaK_storevar()
1095 freeexp(fs, ex); in luaK_storevar()
1102 void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { in luaK_self() argument
1104 luaK_exp2anyreg(fs, e); in luaK_self()
1106 freeexp(fs, e); in luaK_self()
1107 e->u.info = fs->freereg; /* base register for op_self */ in luaK_self()
1109 luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */ in luaK_self()
1110 codeABRK(fs, OP_SELF, e->u.info, ereg, key); in luaK_self()
1111 freeexp(fs, key); in luaK_self()
1118 static void negatecondition (FuncState *fs, expdesc *e) { in negatecondition() argument
1119 Instruction *pc = getjumpcontrol(fs, e->u.info); in negatecondition()
1132 static int jumponcond (FuncState *fs, expdesc *e, int cond) { in jumponcond() argument
1134 Instruction ie = getinstruction(fs, e); in jumponcond()
1136 removelastinstruction(fs); /* remove previous OP_NOT */ in jumponcond()
1137 return condjump(fs, OP_TEST, GETARG_B(ie), 0, 0, !cond); in jumponcond()
1141 discharge2anyreg(fs, e); in jumponcond()
1142 freeexp(fs, e); in jumponcond()
1143 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, 0, cond); in jumponcond()
1150 void luaK_goiftrue (FuncState *fs, expdesc *e) { argument
1152 luaK_dischargevars(fs, e);
1155 negatecondition(fs, e); /* jump when it is false */
1168 pc = jumponcond(fs, e, 0); /* jump when false */
1172 luaK_concat(fs, &e->f, pc); /* insert new jump in false list */
1173 luaK_patchtohere(fs, e->t); /* true list jumps to here (to go through) */
1181 void luaK_goiffalse (FuncState *fs, expdesc *e) { argument
1183 luaK_dischargevars(fs, e);
1194 pc = jumponcond(fs, e, 1); /* jump if true */
1198 luaK_concat(fs, &e->t, pc); /* insert new jump in 't' list */
1199 luaK_patchtohere(fs, e->f); /* false list jumps to here (to go through) */
1207 static void codenot (FuncState *fs, expdesc *e) { argument
1222 negatecondition(fs, e);
1227 discharge2anyreg(fs, e);
1228 freeexp(fs, e);
1229 e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
1237 removevalues(fs, e->f); /* values are useless when negated */
1238 removevalues(fs, e->t);
1245 static int isKstr (FuncState *fs, expdesc *e) { argument
1247 ttisshrstring(&fs->f->k[e->u.info]));
1305 void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { argument
1307 str2K(fs, k);
1310 if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */
1311 luaK_exp2anyreg(fs, t); /* put it in a register */
1320 if (isKstr(fs, k)) {
1329 t->u.ind.idx = luaK_exp2anyreg(fs, k); /* register */
1364 static int constfolding (FuncState *fs, int op, expdesc *e1, argument
1369 luaO_rawarith(fs->ls->L, op, &v1, &v2, &res); /* does operation */
1423 static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) { argument
1424 int r = luaK_exp2anyreg(fs, e); /* opcodes operate only on registers */
1425 freeexp(fs, e);
1426 e->u.info = luaK_codeABC(fs, op, 0, r, 0); /* generate opcode */
1428 luaK_fixline(fs, line);
1438 static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2, argument
1441 int v1 = luaK_exp2anyreg(fs, e1);
1442 int pc = luaK_codeABCk(fs, op, 0, v1, v2, 0);
1443 freeexps(fs, e1, e2);
1446 luaK_fixline(fs, line);
1447 luaK_codeABCk(fs, mmop, v1, v2, event, flip); /* to call metamethod */
1448 luaK_fixline(fs, line);
1456 static void codebinexpval (FuncState *fs, BinOpr opr, argument
1459 int v2 = luaK_exp2anyreg(fs, e2); /* make sure 'e2' is in a register */
1464 finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN, binopr2TM(opr));
1471 static void codebini (FuncState *fs, OpCode op, argument
1476 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINI, event);
1483 static void codebinK (FuncState *fs, BinOpr opr, argument
1488 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
1495 static int finishbinexpneg (FuncState *fs, expdesc *e1, expdesc *e2, argument
1505 finishbinexpval(fs, e1, e2, op, int2sC(-v2), 0, line, OP_MMBINI, event);
1507 SETARG_B(fs->f->code[fs->pc - 1], int2sC(v2));
1522 static void codebinNoK (FuncState *fs, BinOpr opr, argument
1526 codebinexpval(fs, opr, e1, e2, line); /* use standard operators */
1534 static void codearith (FuncState *fs, BinOpr opr, argument
1536 if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) /* K operand? */
1537 codebinK(fs, opr, e1, e2, flip, line);
1539 codebinNoK(fs, opr, e1, e2, flip, line);
1548 static void codecommutative (FuncState *fs, BinOpr op, argument
1556 codebini(fs, OP_ADDI, e1, e2, flip, line, TM_ADD);
1558 codearith(fs, op, e1, e2, flip, line);
1566 static void codebitwise (FuncState *fs, BinOpr opr, argument
1573 if (e2->k == VKINT && luaK_exp2K(fs, e2)) /* K operand? */
1574 codebinK(fs, opr, e1, e2, flip, line);
1576 codebinNoK(fs, opr, e1, e2, flip, line);
1584 static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { argument
1591 r1 = luaK_exp2anyreg(fs, e1);
1597 r1 = luaK_exp2anyreg(fs, e2);
1602 r1 = luaK_exp2anyreg(fs, e1);
1603 r2 = luaK_exp2anyreg(fs, e2);
1606 freeexps(fs, e1, e2);
1607 e1->u.info = condjump(fs, op, r1, r2, isfloat, 1);
1616 static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { argument
1625 r1 = luaK_exp2anyreg(fs, e1); /* 1st expression must be in register */
1630 else if (luaK_exp2RK(fs, e2)) { /* 2nd expression is constant? */
1636 r2 = luaK_exp2anyreg(fs, e2);
1638 freeexps(fs, e1, e2);
1639 e1->u.info = condjump(fs, op, r1, r2, isfloat, (opr == OPR_EQ));
1647 void luaK_prefix (FuncState *fs, UnOpr opr, expdesc *e, int line) { argument
1649 luaK_dischargevars(fs, e);
1652 if (constfolding(fs, opr + LUA_OPUNM, e, &ef))
1656 codeunexpval(fs, unopr2op(opr), e, line);
1658 case OPR_NOT: codenot(fs, e); break;
1668 void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { argument
1669 luaK_dischargevars(fs, v);
1672 luaK_goiftrue(fs, v); /* go ahead only if 'v' is true */
1676 luaK_goiffalse(fs, v); /* go ahead only if 'v' is false */
1680 luaK_exp2nextreg(fs, v); /* operand must be on the stack */
1694 luaK_exp2anyreg(fs, v);
1701 luaK_exp2RK(fs, v);
1709 luaK_exp2anyreg(fs, v);
1722 static void codeconcat (FuncState *fs, expdesc *e1, expdesc *e2, int line) { argument
1723 Instruction *ie2 = previousinstruction(fs);
1727 freeexp(fs, e2);
1732 luaK_codeABC(fs, OP_CONCAT, e1->u.info, 2, 0); /* new concat opcode */
1733 freeexp(fs, e2);
1734 luaK_fixline(fs, line);
1742 void luaK_posfix (FuncState *fs, BinOpr opr, argument
1744 luaK_dischargevars(fs, e2);
1745 if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2))
1750 luaK_concat(fs, &e2->f, e1->f);
1756 luaK_concat(fs, &e2->t, e1->t);
1761 luaK_exp2nextreg(fs, e2);
1762 codeconcat(fs, e1, e2, line);
1766 codecommutative(fs, opr, e1, e2, line);
1770 if (finishbinexpneg(fs, e1, e2, OP_ADDI, line, TM_SUB))
1779 codearith(fs, opr, e1, e2, 0, line);
1783 codebitwise(fs, opr, e1, e2, line);
1789 codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL); /* I << r2 */
1791 else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) {
1795 codebinexpval(fs, opr, e1, e2, line);
1800 codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR); /* r1 >> I */
1802 codebinexpval(fs, opr, e1, e2, line);
1806 codeeq(fs, opr, e1, e2);
1815 codeorder(fs, opr, e1, e2);
1827 void luaK_fixline (FuncState *fs, int line) { argument
1828 removelastlineinfo(fs);
1829 savelineinfo(fs, fs->f, line);
1833 void luaK_settablesize (FuncState *fs, int pc, int ra, int asize, int hsize) { argument
1834 Instruction *inst = &fs->f->code[pc];
1851 void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { argument
1856 luaK_codeABC(fs, OP_SETLIST, base, tostore, nelems);
1860 luaK_codeABCk(fs, OP_SETLIST, base, tostore, nelems, 1);
1861 codeextraarg(fs, extra);
1863 fs->freereg = base + 1; /* free registers with list values */
1887 void luaK_finish (FuncState *fs) { argument
1889 Proto *p = fs->f;
1890 for (i = 0; i < fs->pc; i++) {
1895 if (!(fs->needclose || p->is_vararg))
1901 if (fs->needclose)
1909 fixjump(fs, i, target);