Lines Matching refs:fs

64 void luaK_nil (FuncState *fs, int from, int n) {  in luaK_nil()  argument
67 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ in luaK_nil()
68 previous = &fs->f->code[fs->pc-1]; in luaK_nil()
82 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ in luaK_nil()
90 static int getjump (FuncState *fs, int pc) { in getjump() argument
91 int offset = GETARG_sBx(fs->f->code[pc]); in getjump()
103 static void fixjump (FuncState *fs, int pc, int dest) { in fixjump() argument
104 Instruction *jmp = &fs->f->code[pc]; in fixjump()
108 luaX_syntaxerror(fs->ls, "control structure too long"); in fixjump()
116 void luaK_concat (FuncState *fs, int *l1, int l2) { in luaK_concat() argument
123 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ in luaK_concat()
125 fixjump(fs, list, l2); /* last element links to 'l2' */ in luaK_concat()
136 int luaK_jump (FuncState *fs) { in luaK_jump() argument
137 int jpc = fs->jpc; /* save list of jumps to here */ in luaK_jump()
139 fs->jpc = NO_JUMP; /* no more jumps to here */ in luaK_jump()
140 j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); in luaK_jump()
141 luaK_concat(fs, &j, jpc); /* keep them on hold */ in luaK_jump()
149 void luaK_ret (FuncState *fs, int first, int nret) { in luaK_ret() argument
150 luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); in luaK_ret()
158 static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { in condjump() argument
159 luaK_codeABC(fs, op, A, B, C); in condjump()
160 return luaK_jump(fs); in condjump()
168 int luaK_getlabel (FuncState *fs) { in luaK_getlabel() argument
169 fs->lasttarget = fs->pc; in luaK_getlabel()
170 return fs->pc; in luaK_getlabel()
179 static Instruction *getjumpcontrol (FuncState *fs, int pc) { in getjumpcontrol() argument
180 Instruction *pi = &fs->f->code[pc]; in getjumpcontrol()
195 static int patchtestreg (FuncState *fs, int node, int reg) { in patchtestreg() argument
196 Instruction *i = getjumpcontrol(fs, node); in patchtestreg()
213 static void removevalues (FuncState *fs, int list) { in removevalues() argument
214 for (; list != NO_JUMP; list = getjump(fs, list)) in removevalues()
215 patchtestreg(fs, list, NO_REG); in removevalues()
224 static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, in patchlistaux() argument
227 int next = getjump(fs, list); in patchlistaux()
228 if (patchtestreg(fs, list, reg)) in patchlistaux()
229 fixjump(fs, list, vtarget); in patchlistaux()
231 fixjump(fs, list, dtarget); /* jump to default target */ in patchlistaux()
242 static void dischargejpc (FuncState *fs) { in dischargejpc() argument
243 patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); in dischargejpc()
244 fs->jpc = NO_JUMP; in dischargejpc()
252 void luaK_patchtohere (FuncState *fs, int list) { in luaK_patchtohere() argument
253 luaK_getlabel(fs); /* mark "here" as a jump target */ in luaK_patchtohere()
254 luaK_concat(fs, &fs->jpc, list); in luaK_patchtohere()
263 void luaK_patchlist (FuncState *fs, int list, int target) { in luaK_patchlist() argument
264 if (target == fs->pc) /* 'target' is current position? */ in luaK_patchlist()
265 luaK_patchtohere(fs, list); /* add list to pending jumps */ in luaK_patchlist()
267 lua_assert(target < fs->pc); in luaK_patchlist()
268 patchlistaux(fs, list, target, NO_REG, target); in luaK_patchlist()
278 void luaK_patchclose (FuncState *fs, int list, int level) { in luaK_patchclose() argument
280 for (; list != NO_JUMP; list = getjump(fs, list)) { in luaK_patchclose()
281 lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP && in luaK_patchclose()
282 (GETARG_A(fs->f->code[list]) == 0 || in luaK_patchclose()
283 GETARG_A(fs->f->code[list]) >= level)); in luaK_patchclose()
284 SETARG_A(fs->f->code[list], level); in luaK_patchclose()
293 static int luaK_code (FuncState *fs, Instruction i) { in luaK_code() argument
294 Proto *f = fs->f; in luaK_code()
295 dischargejpc(fs); /* 'pc' will change */ in luaK_code()
297 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction, in luaK_code()
299 f->code[fs->pc] = i; in luaK_code()
301 luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int, in luaK_code()
303 f->lineinfo[fs->pc] = fs->ls->lastline; in luaK_code()
304 return fs->pc++; in luaK_code()
312 int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { in luaK_codeABC() argument
317 return luaK_code(fs, CREATE_ABC(o, a, b, c)); in luaK_codeABC()
324 int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { in luaK_codeABx() argument
328 return luaK_code(fs, CREATE_ABx(o, a, bc)); in luaK_codeABx()
335 static int codeextraarg (FuncState *fs, int a) { in codeextraarg() argument
337 return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a)); in codeextraarg()
346 int luaK_codek (FuncState *fs, int reg, int k) { in luaK_codek() argument
348 return luaK_codeABx(fs, OP_LOADK, reg, k); in luaK_codek()
350 int p = luaK_codeABx(fs, OP_LOADKX, reg, 0); in luaK_codek()
351 codeextraarg(fs, k); in luaK_codek()
361 void luaK_checkstack (FuncState *fs, int n) { in luaK_checkstack() argument
362 int newstack = fs->freereg + n; in luaK_checkstack()
363 if (newstack > fs->f->maxstacksize) { in luaK_checkstack()
365 luaX_syntaxerror(fs->ls, in luaK_checkstack()
367 fs->f->maxstacksize = cast_byte(newstack); in luaK_checkstack()
375 void luaK_reserveregs (FuncState *fs, int n) { in luaK_reserveregs() argument
376 luaK_checkstack(fs, n); in luaK_reserveregs()
377 fs->freereg += n; in luaK_reserveregs()
386 static void freereg (FuncState *fs, int reg) { in freereg() argument
387 if (!ISK(reg) && reg >= fs->nactvar) { in freereg()
388 fs->freereg--; in freereg()
389 lua_assert(reg == fs->freereg); in freereg()
397 static void freeexp (FuncState *fs, expdesc *e) { in freeexp() argument
399 freereg(fs, e->u.info); in freeexp()
407 static void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) { in freeexps() argument
411 freereg(fs, r1); in freeexps()
412 freereg(fs, r2); in freeexps()
415 freereg(fs, r2); in freeexps()
416 freereg(fs, r1); in freeexps()
428 static int addk (FuncState *fs, TValue *key, TValue *v) { in addk() argument
429 lua_State *L = fs->ls->L; in addk()
430 Proto *f = fs->f; in addk()
431 TValue *idx = luaH_set(L, fs->ls->h, key); /* index scanner table */ in addk()
436 if (k < fs->nk && ttype(&f->k[k]) == ttype(v) && in addk()
442 k = fs->nk; in addk()
449 fs->nk++; in addk()
458 int luaK_stringK (FuncState *fs, TString *s) { in luaK_stringK() argument
460 setsvalue(fs->ls->L, &o, s); in luaK_stringK()
461 return addk(fs, &o, &o); /* use string itself as key */ in luaK_stringK()
471 int luaK_intK (FuncState *fs, lua_Integer n) { in luaK_intK() argument
475 return addk(fs, &k, &o); in luaK_intK()
481 static int luaK_numberK (FuncState *fs, lua_Number r) { in luaK_numberK() argument
484 return addk(fs, &o, &o); /* use number itself as key */ in luaK_numberK()
491 static int boolK (FuncState *fs, int b) { in boolK() argument
494 return addk(fs, &o, &o); /* use boolean itself as key */ in boolK()
501 static int nilK (FuncState *fs) { in nilK() argument
505 sethvalue(fs->ls->L, &k, fs->ls->h); in nilK()
506 return addk(fs, &k, &v); in nilK()
515 void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { in luaK_setreturns() argument
517 SETARG_C(getinstruction(fs, e), nresults + 1); in luaK_setreturns()
520 Instruction *pc = &getinstruction(fs, e); in luaK_setreturns()
522 SETARG_A(*pc, fs->freereg); in luaK_setreturns()
523 luaK_reserveregs(fs, 1); in luaK_setreturns()
539 void luaK_setoneret (FuncState *fs, expdesc *e) { in luaK_setoneret() argument
542 lua_assert(GETARG_C(getinstruction(fs, e)) == 2); in luaK_setoneret()
544 e->u.info = GETARG_A(getinstruction(fs, e)); in luaK_setoneret()
547 SETARG_B(getinstruction(fs, e), 2); in luaK_setoneret()
556 void luaK_dischargevars (FuncState *fs, expdesc *e) { in luaK_dischargevars() argument
563 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0); in luaK_dischargevars()
569 freereg(fs, e->u.ind.idx); in luaK_dischargevars()
571 freereg(fs, e->u.ind.t); in luaK_dischargevars()
578 e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx); in luaK_dischargevars()
583 luaK_setoneret(fs, e); in luaK_dischargevars()
595 static void discharge2reg (FuncState *fs, expdesc *e, int reg) { in discharge2reg() argument
596 luaK_dischargevars(fs, e); in discharge2reg()
599 luaK_nil(fs, reg, 1); in discharge2reg()
603 luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); in discharge2reg()
607 luaK_codek(fs, reg, e->u.info); in discharge2reg()
611 luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval)); in discharge2reg()
615 luaK_codek(fs, reg, luaK_intK(fs, e->u.ival)); in discharge2reg()
619 Instruction *pc = &getinstruction(fs, e); in discharge2reg()
625 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0); in discharge2reg()
641 static void discharge2anyreg (FuncState *fs, expdesc *e) { in discharge2anyreg() argument
643 luaK_reserveregs(fs, 1); /* get a register */ in discharge2anyreg()
644 discharge2reg(fs, e, fs->freereg-1); /* put value there */ in discharge2anyreg()
649 static int code_loadbool (FuncState *fs, int A, int b, int jump) { in code_loadbool() argument
650 luaK_getlabel(fs); /* those instructions may be jump targets */ in code_loadbool()
651 return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); in code_loadbool()
659 static int need_value (FuncState *fs, int list) { in need_value() argument
660 for (; list != NO_JUMP; list = getjump(fs, list)) { in need_value()
661 Instruction i = *getjumpcontrol(fs, list); in need_value()
675 static void exp2reg (FuncState *fs, expdesc *e, int reg) { in exp2reg() argument
676 discharge2reg(fs, e, reg); in exp2reg()
678 luaK_concat(fs, &e->t, e->u.info); /* put this jump in 't' list */ in exp2reg()
683 if (need_value(fs, e->t) || need_value(fs, e->f)) { in exp2reg()
684 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); in exp2reg()
685 p_f = code_loadbool(fs, reg, 0, 1); in exp2reg()
686 p_t = code_loadbool(fs, reg, 1, 0); in exp2reg()
687 luaK_patchtohere(fs, fj); in exp2reg()
689 final = luaK_getlabel(fs); in exp2reg()
690 patchlistaux(fs, e->f, final, reg, p_f); in exp2reg()
691 patchlistaux(fs, e->t, final, reg, p_t); in exp2reg()
703 void luaK_exp2nextreg (FuncState *fs, expdesc *e) { in luaK_exp2nextreg() argument
704 luaK_dischargevars(fs, e); in luaK_exp2nextreg()
705 freeexp(fs, e); in luaK_exp2nextreg()
706 luaK_reserveregs(fs, 1); in luaK_exp2nextreg()
707 exp2reg(fs, e, fs->freereg - 1); in luaK_exp2nextreg()
715 int luaK_exp2anyreg (FuncState *fs, expdesc *e) { in luaK_exp2anyreg() argument
716 luaK_dischargevars(fs, e); in luaK_exp2anyreg()
720 if (e->u.info >= fs->nactvar) { /* reg. is not a local? */ in luaK_exp2anyreg()
721 exp2reg(fs, e, e->u.info); /* put final result in it */ in luaK_exp2anyreg()
725 luaK_exp2nextreg(fs, e); /* otherwise, use next available register */ in luaK_exp2anyreg()
734 void luaK_exp2anyregup (FuncState *fs, expdesc *e) { in luaK_exp2anyregup() argument
736 luaK_exp2anyreg(fs, e); in luaK_exp2anyregup()
744 void luaK_exp2val (FuncState *fs, expdesc *e) { in luaK_exp2val() argument
746 luaK_exp2anyreg(fs, e); in luaK_exp2val()
748 luaK_dischargevars(fs, e); in luaK_exp2val()
758 int luaK_exp2RK (FuncState *fs, expdesc *e) { in luaK_exp2RK() argument
759 luaK_exp2val(fs, e); in luaK_exp2RK()
761 case VTRUE: e->u.info = boolK(fs, 1); goto vk; in luaK_exp2RK()
762 case VFALSE: e->u.info = boolK(fs, 0); goto vk; in luaK_exp2RK()
763 case VNIL: e->u.info = nilK(fs); goto vk; in luaK_exp2RK()
764 case VKINT: e->u.info = luaK_intK(fs, e->u.ival); goto vk; in luaK_exp2RK()
765 case VKFLT: e->u.info = luaK_numberK(fs, e->u.nval); goto vk; in luaK_exp2RK()
775 return luaK_exp2anyreg(fs, e); in luaK_exp2RK()
782 void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { in luaK_storevar() argument
785 freeexp(fs, ex); in luaK_storevar()
786 exp2reg(fs, ex, var->u.info); /* compute 'ex' into proper place */ in luaK_storevar()
790 int e = luaK_exp2anyreg(fs, ex); in luaK_storevar()
791 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0); in luaK_storevar()
796 int e = luaK_exp2RK(fs, ex); in luaK_storevar()
797 luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e); in luaK_storevar()
802 freeexp(fs, ex); in luaK_storevar()
809 void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { in luaK_self() argument
811 luaK_exp2anyreg(fs, e); in luaK_self()
813 freeexp(fs, e); in luaK_self()
814 e->u.info = fs->freereg; /* base register for op_self */ in luaK_self()
816 luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */ in luaK_self()
817 luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key)); in luaK_self()
818 freeexp(fs, key); in luaK_self()
825 static void negatecondition (FuncState *fs, expdesc *e) { in negatecondition() argument
826 Instruction *pc = getjumpcontrol(fs, e->u.info); in negatecondition()
839 static int jumponcond (FuncState *fs, expdesc *e, int cond) { in jumponcond() argument
841 Instruction ie = getinstruction(fs, e); in jumponcond()
843 fs->pc--; /* remove previous OP_NOT */ in jumponcond()
844 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); in jumponcond()
848 discharge2anyreg(fs, e); in jumponcond()
849 freeexp(fs, e); in jumponcond()
850 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond); in jumponcond()
857 void luaK_goiftrue (FuncState *fs, expdesc *e) { in luaK_goiftrue() argument
859 luaK_dischargevars(fs, e); in luaK_goiftrue()
862 negatecondition(fs, e); /* jump when it is false */ in luaK_goiftrue()
871 pc = jumponcond(fs, e, 0); /* jump when false */ in luaK_goiftrue()
875 luaK_concat(fs, &e->f, pc); /* insert new jump in false list */ in luaK_goiftrue()
876 luaK_patchtohere(fs, e->t); /* true list jumps to here (to go through) */ in luaK_goiftrue()
884 void luaK_goiffalse (FuncState *fs, expdesc *e) { in luaK_goiffalse() argument
886 luaK_dischargevars(fs, e); in luaK_goiffalse()
897 pc = jumponcond(fs, e, 1); /* jump if true */ in luaK_goiffalse()
901 luaK_concat(fs, &e->t, pc); /* insert new jump in 't' list */ in luaK_goiffalse()
902 luaK_patchtohere(fs, e->f); /* false list jumps to here (to go through) */ in luaK_goiffalse()
910 static void codenot (FuncState *fs, expdesc *e) { in codenot() argument
911 luaK_dischargevars(fs, e); in codenot()
922 negatecondition(fs, e); in codenot()
927 discharge2anyreg(fs, e); in codenot()
928 freeexp(fs, e); in codenot()
929 e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0); in codenot()
937 removevalues(fs, e->f); /* values are useless when negated */ in codenot()
938 removevalues(fs, e->t); in codenot()
946 void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { in luaK_indexed() argument
949 t->u.ind.idx = luaK_exp2RK(fs, k); /* R/K index for key */ in luaK_indexed()
978 static int constfolding (FuncState *fs, int op, expdesc *e1, in constfolding() argument
983 luaO_arith(fs->ls->L, op, &v1, &v2, &res); /* does operation */ in constfolding()
1004 static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) { in codeunexpval() argument
1005 int r = luaK_exp2anyreg(fs, e); /* opcodes operate only on registers */ in codeunexpval()
1006 freeexp(fs, e); in codeunexpval()
1007 e->u.info = luaK_codeABC(fs, op, 0, r, 0); /* generate opcode */ in codeunexpval()
1009 luaK_fixline(fs, line); in codeunexpval()
1022 static void codebinexpval (FuncState *fs, OpCode op, in codebinexpval() argument
1024 int rk2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */ in codebinexpval()
1025 int rk1 = luaK_exp2RK(fs, e1); in codebinexpval()
1026 freeexps(fs, e1, e2); in codebinexpval()
1027 e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2); /* generate opcode */ in codebinexpval()
1029 luaK_fixline(fs, line); in codebinexpval()
1037 static void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { in codecomp() argument
1040 int rk2 = luaK_exp2RK(fs, e2); in codecomp()
1041 freeexps(fs, e1, e2); in codecomp()
1044 e1->u.info = condjump(fs, OP_EQ, 0, rk1, rk2); in codecomp()
1050 e1->u.info = condjump(fs, op, 1, rk2, rk1); /* invert operands */ in codecomp()
1055 e1->u.info = condjump(fs, op, 1, rk1, rk2); in codecomp()
1066 void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) { in luaK_prefix() argument
1070 if (constfolding(fs, op + LUA_OPUNM, e, &ef)) in luaK_prefix()
1074 codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line); in luaK_prefix()
1076 case OPR_NOT: codenot(fs, e); break; in luaK_prefix()
1086 void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { in luaK_infix() argument
1089 luaK_goiftrue(fs, v); /* go ahead only if 'v' is true */ in luaK_infix()
1093 luaK_goiffalse(fs, v); /* go ahead only if 'v' is false */ in luaK_infix()
1097 luaK_exp2nextreg(fs, v); /* operand must be on the 'stack' */ in luaK_infix()
1106 luaK_exp2RK(fs, v); in luaK_infix()
1111 luaK_exp2RK(fs, v); in luaK_infix()
1124 void luaK_posfix (FuncState *fs, BinOpr op, in luaK_posfix() argument
1129 luaK_dischargevars(fs, e2); in luaK_posfix()
1130 luaK_concat(fs, &e2->f, e1->f); in luaK_posfix()
1136 luaK_dischargevars(fs, e2); in luaK_posfix()
1137 luaK_concat(fs, &e2->t, e1->t); in luaK_posfix()
1142 luaK_exp2val(fs, e2); in luaK_posfix()
1144 GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) { in luaK_posfix()
1145 lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1); in luaK_posfix()
1146 freeexp(fs, e1); in luaK_posfix()
1147 SETARG_B(getinstruction(fs, e2), e1->u.info); in luaK_posfix()
1151 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ in luaK_posfix()
1152 codebinexpval(fs, OP_CONCAT, e1, e2, line); in luaK_posfix()
1160 if (!constfolding(fs, op + LUA_OPADD, e1, e2)) in luaK_posfix()
1161 codebinexpval(fs, cast(OpCode, op + OP_ADD), e1, e2, line); in luaK_posfix()
1166 codecomp(fs, op, e1, e2); in luaK_posfix()
1177 void luaK_fixline (FuncState *fs, int line) { in luaK_fixline() argument
1178 fs->f->lineinfo[fs->pc - 1] = line; in luaK_fixline()
1189 void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { in luaK_setlist() argument
1194 luaK_codeABC(fs, OP_SETLIST, base, b, c); in luaK_setlist()
1196 luaK_codeABC(fs, OP_SETLIST, base, b, 0); in luaK_setlist()
1197 codeextraarg(fs, c); in luaK_setlist()
1200 luaX_syntaxerror(fs->ls, "constructor too long"); in luaK_setlist()
1201 fs->freereg = base + 1; /* free registers with list values */ in luaK_setlist()