Lines Matching full:fs
38 void luaK_nil (FuncState *fs, int from, int n) { in luaK_nil() argument
41 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ in luaK_nil()
42 previous = &fs->f->code[fs->pc-1]; in luaK_nil()
56 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ in luaK_nil()
60 int luaK_jump (FuncState *fs) { in luaK_jump() argument
61 int jpc = fs->jpc; /* save list of jumps to here */ in luaK_jump()
63 fs->jpc = NO_JUMP; in luaK_jump()
64 j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); in luaK_jump()
65 luaK_concat(fs, &j, jpc); /* keep them on hold */ in luaK_jump()
70 void luaK_ret (FuncState *fs, int first, int nret) { in luaK_ret() argument
71 luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); in luaK_ret()
75 static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { in condjump() argument
76 luaK_codeABC(fs, op, A, B, C); in condjump()
77 return luaK_jump(fs); in condjump()
81 static void fixjump (FuncState *fs, int pc, int dest) { in fixjump() argument
82 Instruction *jmp = &fs->f->code[pc]; in fixjump()
86 luaX_syntaxerror(fs->ls, "control structure too long"); in fixjump()
95 int luaK_getlabel (FuncState *fs) { in luaK_getlabel() argument
96 fs->lasttarget = fs->pc; in luaK_getlabel()
97 return fs->pc; in luaK_getlabel()
101 static int getjump (FuncState *fs, int pc) { in getjump() argument
102 int offset = GETARG_sBx(fs->f->code[pc]); in getjump()
110 static Instruction *getjumpcontrol (FuncState *fs, int pc) { in getjumpcontrol() argument
111 Instruction *pi = &fs->f->code[pc]; in getjumpcontrol()
123 static int need_value (FuncState *fs, int list) { in need_value() argument
124 for (; list != NO_JUMP; list = getjump(fs, list)) { in need_value()
125 Instruction i = *getjumpcontrol(fs, list); in need_value()
132 static int patchtestreg (FuncState *fs, int node, int reg) { in patchtestreg() argument
133 Instruction *i = getjumpcontrol(fs, node); in patchtestreg()
145 static void removevalues (FuncState *fs, int list) { in removevalues() argument
146 for (; list != NO_JUMP; list = getjump(fs, list)) in removevalues()
147 patchtestreg(fs, list, NO_REG); in removevalues()
151 static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, in patchlistaux() argument
154 int next = getjump(fs, list); in patchlistaux()
155 if (patchtestreg(fs, list, reg)) in patchlistaux()
156 fixjump(fs, list, vtarget); in patchlistaux()
158 fixjump(fs, list, dtarget); /* jump to default target */ in patchlistaux()
164 static void dischargejpc (FuncState *fs) { in dischargejpc() argument
165 patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); in dischargejpc()
166 fs->jpc = NO_JUMP; in dischargejpc()
170 void luaK_patchlist (FuncState *fs, int list, int target) { in luaK_patchlist() argument
171 if (target == fs->pc) in luaK_patchlist()
172 luaK_patchtohere(fs, list); in luaK_patchlist()
174 lua_assert(target < fs->pc); in luaK_patchlist()
175 patchlistaux(fs, list, target, NO_REG, target); in luaK_patchlist()
180 LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level) { in luaK_patchclose() argument
183 int next = getjump(fs, list); in luaK_patchclose()
184 lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP && in luaK_patchclose()
185 (GETARG_A(fs->f->code[list]) == 0 || in luaK_patchclose()
186 GETARG_A(fs->f->code[list]) >= level)); in luaK_patchclose()
187 SETARG_A(fs->f->code[list], level); in luaK_patchclose()
193 void luaK_patchtohere (FuncState *fs, int list) { in luaK_patchtohere() argument
194 luaK_getlabel(fs); in luaK_patchtohere()
195 luaK_concat(fs, &fs->jpc, list); in luaK_patchtohere()
199 void luaK_concat (FuncState *fs, int *l1, int l2) { in luaK_concat() argument
206 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ in luaK_concat()
208 fixjump(fs, list, l2); in luaK_concat()
213 static int luaK_code (FuncState *fs, Instruction i) { in luaK_code() argument
214 Proto *f = fs->f; in luaK_code()
215 dischargejpc(fs); /* `pc' will change */ in luaK_code()
217 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction, in luaK_code()
219 f->code[fs->pc] = i; in luaK_code()
221 luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int, in luaK_code()
223 f->lineinfo[fs->pc] = fs->ls->lastline; in luaK_code()
224 return fs->pc++; in luaK_code()
228 int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { in luaK_codeABC() argument
233 return luaK_code(fs, CREATE_ABC(o, a, b, c)); in luaK_codeABC()
237 int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { in luaK_codeABx() argument
241 return luaK_code(fs, CREATE_ABx(o, a, bc)); in luaK_codeABx()
245 static int codeextraarg (FuncState *fs, int a) { in codeextraarg() argument
247 return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a)); in codeextraarg()
251 int luaK_codek (FuncState *fs, int reg, int k) { in luaK_codek() argument
253 return luaK_codeABx(fs, OP_LOADK, reg, k); in luaK_codek()
255 int p = luaK_codeABx(fs, OP_LOADKX, reg, 0); in luaK_codek()
256 codeextraarg(fs, k); in luaK_codek()
262 void luaK_checkstack (FuncState *fs, int n) { in luaK_checkstack() argument
263 int newstack = fs->freereg + n; in luaK_checkstack()
264 if (newstack > fs->f->maxstacksize) { in luaK_checkstack()
266 luaX_syntaxerror(fs->ls, "function or expression too complex"); in luaK_checkstack()
267 fs->f->maxstacksize = cast_byte(newstack); in luaK_checkstack()
272 void luaK_reserveregs (FuncState *fs, int n) { in luaK_reserveregs() argument
273 luaK_checkstack(fs, n); in luaK_reserveregs()
274 fs->freereg += n; in luaK_reserveregs()
278 static void freereg (FuncState *fs, int reg) { in freereg() argument
279 if (!ISK(reg) && reg >= fs->nactvar) { in freereg()
280 fs->freereg--; in freereg()
281 lua_assert(reg == fs->freereg); in freereg()
286 static void freeexp (FuncState *fs, expdesc *e) { in freeexp() argument
288 freereg(fs, e->u.info); in freeexp()
292 static int addk (FuncState *fs, TValue *key, TValue *v) { in addk() argument
293 lua_State *L = fs->ls->L; in addk()
294 TValue *idx = luaH_set(L, fs->h, key); in addk()
295 Proto *f = fs->f; in addk()
307 k = fs->nk; in addk()
314 fs->nk++; in addk()
320 int luaK_stringK (FuncState *fs, TString *s) { in luaK_stringK() argument
322 setsvalue(fs->ls->L, &o, s); in luaK_stringK()
323 return addk(fs, &o, &o); in luaK_stringK()
327 int luaK_numberK (FuncState *fs, lua_Number r) { in luaK_numberK() argument
329 lua_State *L = fs->ls->L; in luaK_numberK()
335 n = addk(fs, L->top - 1, &o); in luaK_numberK()
339 n = addk(fs, &o, &o); /* regular case */ in luaK_numberK()
344 static int boolK (FuncState *fs, int b) { in boolK() argument
347 return addk(fs, &o, &o); in boolK()
351 static int nilK (FuncState *fs) { in nilK() argument
355 sethvalue(fs->ls->L, &k, fs->h); in nilK()
356 return addk(fs, &k, &v); in nilK()
360 void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { in luaK_setreturns() argument
362 SETARG_C(getcode(fs, e), nresults+1); in luaK_setreturns()
365 SETARG_B(getcode(fs, e), nresults+1); in luaK_setreturns()
366 SETARG_A(getcode(fs, e), fs->freereg); in luaK_setreturns()
367 luaK_reserveregs(fs, 1); in luaK_setreturns()
372 void luaK_setoneret (FuncState *fs, expdesc *e) { in luaK_setoneret() argument
375 e->u.info = GETARG_A(getcode(fs, e)); in luaK_setoneret()
378 SETARG_B(getcode(fs, e), 2); in luaK_setoneret()
384 void luaK_dischargevars (FuncState *fs, expdesc *e) { in luaK_dischargevars() argument
391 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0); in luaK_dischargevars()
397 freereg(fs, e->u.ind.idx); in luaK_dischargevars()
399 freereg(fs, e->u.ind.t); in luaK_dischargevars()
402 e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx); in luaK_dischargevars()
408 luaK_setoneret(fs, e); in luaK_dischargevars()
416 static int code_label (FuncState *fs, int A, int b, int jump) { in code_label() argument
417 luaK_getlabel(fs); /* those instructions may be jump targets */ in code_label()
418 return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); in code_label()
422 static void discharge2reg (FuncState *fs, expdesc *e, int reg) { in discharge2reg() argument
423 luaK_dischargevars(fs, e); in discharge2reg()
426 luaK_nil(fs, reg, 1); in discharge2reg()
430 luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); in discharge2reg()
434 luaK_codek(fs, reg, e->u.info); in discharge2reg()
438 luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval)); in discharge2reg()
442 Instruction *pc = &getcode(fs, e); in discharge2reg()
448 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0); in discharge2reg()
461 static void discharge2anyreg (FuncState *fs, expdesc *e) { in discharge2anyreg() argument
463 luaK_reserveregs(fs, 1); in discharge2anyreg()
464 discharge2reg(fs, e, fs->freereg-1); in discharge2anyreg()
469 static void exp2reg (FuncState *fs, expdesc *e, int reg) { in exp2reg() argument
470 discharge2reg(fs, e, reg); in exp2reg()
472 luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */ in exp2reg()
477 if (need_value(fs, e->t) || need_value(fs, e->f)) { in exp2reg()
478 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); in exp2reg()
479 p_f = code_label(fs, reg, 0, 1); in exp2reg()
480 p_t = code_label(fs, reg, 1, 0); in exp2reg()
481 luaK_patchtohere(fs, fj); in exp2reg()
483 final = luaK_getlabel(fs); in exp2reg()
484 patchlistaux(fs, e->f, final, reg, p_f); in exp2reg()
485 patchlistaux(fs, e->t, final, reg, p_t); in exp2reg()
493 void luaK_exp2nextreg (FuncState *fs, expdesc *e) { in luaK_exp2nextreg() argument
494 luaK_dischargevars(fs, e); in luaK_exp2nextreg()
495 freeexp(fs, e); in luaK_exp2nextreg()
496 luaK_reserveregs(fs, 1); in luaK_exp2nextreg()
497 exp2reg(fs, e, fs->freereg - 1); in luaK_exp2nextreg()
501 int luaK_exp2anyreg (FuncState *fs, expdesc *e) { in luaK_exp2anyreg() argument
502 luaK_dischargevars(fs, e); in luaK_exp2anyreg()
505 if (e->u.info >= fs->nactvar) { /* reg. is not a local? */ in luaK_exp2anyreg()
506 exp2reg(fs, e, e->u.info); /* put value on it */ in luaK_exp2anyreg()
510 luaK_exp2nextreg(fs, e); /* default */ in luaK_exp2anyreg()
515 void luaK_exp2anyregup (FuncState *fs, expdesc *e) { in luaK_exp2anyregup() argument
517 luaK_exp2anyreg(fs, e); in luaK_exp2anyregup()
521 void luaK_exp2val (FuncState *fs, expdesc *e) { in luaK_exp2val() argument
523 luaK_exp2anyreg(fs, e); in luaK_exp2val()
525 luaK_dischargevars(fs, e); in luaK_exp2val()
529 int luaK_exp2RK (FuncState *fs, expdesc *e) { in luaK_exp2RK() argument
530 luaK_exp2val(fs, e); in luaK_exp2RK()
535 if (fs->nk <= MAXINDEXRK) { /* constant fits in RK operand? */ in luaK_exp2RK()
536 e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE)); in luaK_exp2RK()
543 e->u.info = luaK_numberK(fs, e->u.nval); in luaK_exp2RK()
555 return luaK_exp2anyreg(fs, e); in luaK_exp2RK()
559 void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { in luaK_storevar() argument
562 freeexp(fs, ex); in luaK_storevar()
563 exp2reg(fs, ex, var->u.info); in luaK_storevar()
567 int e = luaK_exp2anyreg(fs, ex); in luaK_storevar()
568 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0); in luaK_storevar()
573 int e = luaK_exp2RK(fs, ex); in luaK_storevar()
574 luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e); in luaK_storevar()
582 freeexp(fs, ex); in luaK_storevar()
586 void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { in luaK_self() argument
588 luaK_exp2anyreg(fs, e); in luaK_self()
590 freeexp(fs, e); in luaK_self()
591 e->u.info = fs->freereg; /* base register for op_self */ in luaK_self()
593 luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */ in luaK_self()
594 luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key)); in luaK_self()
595 freeexp(fs, key); in luaK_self()
599 static void invertjump (FuncState *fs, expdesc *e) { in invertjump() argument
600 Instruction *pc = getjumpcontrol(fs, e->u.info); in invertjump()
607 static int jumponcond (FuncState *fs, expdesc *e, int cond) { in jumponcond() argument
609 Instruction ie = getcode(fs, e); in jumponcond()
611 fs->pc--; /* remove previous OP_NOT */ in jumponcond()
612 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); in jumponcond()
616 discharge2anyreg(fs, e); in jumponcond()
617 freeexp(fs, e); in jumponcond()
618 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond); in jumponcond()
622 void luaK_goiftrue (FuncState *fs, expdesc *e) { in luaK_goiftrue() argument
624 luaK_dischargevars(fs, e); in luaK_goiftrue()
627 invertjump(fs, e); in luaK_goiftrue()
636 pc = jumponcond(fs, e, 0); in luaK_goiftrue()
640 luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ in luaK_goiftrue()
641 luaK_patchtohere(fs, e->t); in luaK_goiftrue()
646 void luaK_goiffalse (FuncState *fs, expdesc *e) { in luaK_goiffalse() argument
648 luaK_dischargevars(fs, e); in luaK_goiffalse()
659 pc = jumponcond(fs, e, 1); in luaK_goiffalse()
663 luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ in luaK_goiffalse()
664 luaK_patchtohere(fs, e->f); in luaK_goiffalse()
669 static void codenot (FuncState *fs, expdesc *e) { in codenot() argument
670 luaK_dischargevars(fs, e); in codenot()
681 invertjump(fs, e); in codenot()
686 discharge2anyreg(fs, e); in codenot()
687 freeexp(fs, e); in codenot()
688 e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0); in codenot()
699 removevalues(fs, e->f); in codenot()
700 removevalues(fs, e->t); in codenot()
704 void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { in luaK_indexed() argument
707 t->u.ind.idx = luaK_exp2RK(fs, k); in luaK_indexed()
730 static void codearith (FuncState *fs, OpCode op, in codearith() argument
735 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; in codearith()
736 int o1 = luaK_exp2RK(fs, e1); in codearith()
738 freeexp(fs, e1); in codearith()
739 freeexp(fs, e2); in codearith()
742 freeexp(fs, e2); in codearith()
743 freeexp(fs, e1); in codearith()
745 e1->u.info = luaK_codeABC(fs, op, 0, o1, o2); in codearith()
747 luaK_fixline(fs, line); in codearith()
752 static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, in codecomp() argument
754 int o1 = luaK_exp2RK(fs, e1); in codecomp()
755 int o2 = luaK_exp2RK(fs, e2); in codecomp()
756 freeexp(fs, e2); in codecomp()
757 freeexp(fs, e1); in codecomp()
763 e1->u.info = condjump(fs, op, cond, o1, o2); in codecomp()
768 void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) { in luaK_prefix() argument
776 luaK_exp2anyreg(fs, e); in luaK_prefix()
777 codearith(fs, OP_UNM, e, &e2, line); in luaK_prefix()
781 case OPR_NOT: codenot(fs, e); break; in luaK_prefix()
783 luaK_exp2anyreg(fs, e); /* cannot operate on constants */ in luaK_prefix()
784 codearith(fs, OP_LEN, e, &e2, line); in luaK_prefix()
792 void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { in luaK_infix() argument
795 luaK_goiftrue(fs, v); in luaK_infix()
799 luaK_goiffalse(fs, v); in luaK_infix()
803 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ in luaK_infix()
808 if (!isnumeral(v)) luaK_exp2RK(fs, v); in luaK_infix()
812 luaK_exp2RK(fs, v); in luaK_infix()
819 void luaK_posfix (FuncState *fs, BinOpr op, in luaK_posfix() argument
824 luaK_dischargevars(fs, e2); in luaK_posfix()
825 luaK_concat(fs, &e2->f, e1->f); in luaK_posfix()
831 luaK_dischargevars(fs, e2); in luaK_posfix()
832 luaK_concat(fs, &e2->t, e1->t); in luaK_posfix()
837 luaK_exp2val(fs, e2); in luaK_posfix()
838 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { in luaK_posfix()
839 lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1); in luaK_posfix()
840 freeexp(fs, e1); in luaK_posfix()
841 SETARG_B(getcode(fs, e2), e1->u.info); in luaK_posfix()
845 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ in luaK_posfix()
846 codearith(fs, OP_CONCAT, e1, e2, line); in luaK_posfix()
852 codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line); in luaK_posfix()
856 codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2); in luaK_posfix()
860 codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2); in luaK_posfix()
868 void luaK_fixline (FuncState *fs, int line) { in luaK_fixline() argument
869 fs->f->lineinfo[fs->pc - 1] = line; in luaK_fixline()
873 void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { in luaK_setlist() argument
878 luaK_codeABC(fs, OP_SETLIST, base, b, c); in luaK_setlist()
880 luaK_codeABC(fs, OP_SETLIST, base, b, 0); in luaK_setlist()
881 codeextraarg(fs, c); in luaK_setlist()
884 luaX_syntaxerror(fs->ls, "constructor too long"); in luaK_setlist()
885 fs->freereg = base + 1; /* free registers with list values */ in luaK_setlist()