Lines Matching refs:fs

35 void luaK_nil (FuncState *fs, int from, int n) {  in luaK_nil()  argument
38 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ in luaK_nil()
39 previous = &fs->f->code[fs->pc-1]; in luaK_nil()
53 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ in luaK_nil()
57 int luaK_jump (FuncState *fs) { in luaK_jump() argument
58 int jpc = fs->jpc; /* save list of jumps to here */ in luaK_jump()
60 fs->jpc = NO_JUMP; in luaK_jump()
61 j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); in luaK_jump()
62 luaK_concat(fs, &j, jpc); /* keep them on hold */ in luaK_jump()
67 void luaK_ret (FuncState *fs, int first, int nret) { in luaK_ret() argument
68 luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); in luaK_ret()
72 static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { in condjump() argument
73 luaK_codeABC(fs, op, A, B, C); in condjump()
74 return luaK_jump(fs); in condjump()
78 static void fixjump (FuncState *fs, int pc, int dest) { in fixjump() argument
79 Instruction *jmp = &fs->f->code[pc]; in fixjump()
83 luaX_syntaxerror(fs->ls, "control structure too long"); in fixjump()
92 int luaK_getlabel (FuncState *fs) { in luaK_getlabel() argument
93 fs->lasttarget = fs->pc; in luaK_getlabel()
94 return fs->pc; in luaK_getlabel()
98 static int getjump (FuncState *fs, int pc) { in getjump() argument
99 int offset = GETARG_sBx(fs->f->code[pc]); in getjump()
107 static Instruction *getjumpcontrol (FuncState *fs, int pc) { in getjumpcontrol() argument
108 Instruction *pi = &fs->f->code[pc]; in getjumpcontrol()
120 static int need_value (FuncState *fs, int list) { in need_value() argument
121 for (; list != NO_JUMP; list = getjump(fs, list)) { in need_value()
122 Instruction i = *getjumpcontrol(fs, list); in need_value()
129 static int patchtestreg (FuncState *fs, int node, int reg) { in patchtestreg() argument
130 Instruction *i = getjumpcontrol(fs, node); in patchtestreg()
142 static void removevalues (FuncState *fs, int list) { in removevalues() argument
143 for (; list != NO_JUMP; list = getjump(fs, list)) in removevalues()
144 patchtestreg(fs, list, NO_REG); in removevalues()
148 static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, in patchlistaux() argument
151 int next = getjump(fs, list); in patchlistaux()
152 if (patchtestreg(fs, list, reg)) in patchlistaux()
153 fixjump(fs, list, vtarget); in patchlistaux()
155 fixjump(fs, list, dtarget); /* jump to default target */ in patchlistaux()
161 static void dischargejpc (FuncState *fs) { in dischargejpc() argument
162 patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); in dischargejpc()
163 fs->jpc = NO_JUMP; in dischargejpc()
167 void luaK_patchlist (FuncState *fs, int list, int target) { in luaK_patchlist() argument
168 if (target == fs->pc) in luaK_patchlist()
169 luaK_patchtohere(fs, list); in luaK_patchlist()
171 lua_assert(target < fs->pc); in luaK_patchlist()
172 patchlistaux(fs, list, target, NO_REG, target); in luaK_patchlist()
177 LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level) { in luaK_patchclose() argument
180 int next = getjump(fs, list); in luaK_patchclose()
181 lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP && in luaK_patchclose()
182 (GETARG_A(fs->f->code[list]) == 0 || in luaK_patchclose()
183 GETARG_A(fs->f->code[list]) >= level)); in luaK_patchclose()
184 SETARG_A(fs->f->code[list], level); in luaK_patchclose()
190 void luaK_patchtohere (FuncState *fs, int list) { in luaK_patchtohere() argument
191 luaK_getlabel(fs); in luaK_patchtohere()
192 luaK_concat(fs, &fs->jpc, list); in luaK_patchtohere()
196 void luaK_concat (FuncState *fs, int *l1, int l2) { in luaK_concat() argument
203 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ in luaK_concat()
205 fixjump(fs, list, l2); in luaK_concat()
210 static int luaK_code (FuncState *fs, Instruction i) { in luaK_code() argument
211 Proto *f = fs->f; in luaK_code()
212 dischargejpc(fs); /* `pc' will change */ in luaK_code()
214 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction, in luaK_code()
216 f->code[fs->pc] = i; in luaK_code()
218 luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int, in luaK_code()
220 f->lineinfo[fs->pc] = fs->ls->lastline; in luaK_code()
221 return fs->pc++; in luaK_code()
225 int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { in luaK_codeABC() argument
230 return luaK_code(fs, CREATE_ABC(o, a, b, c)); in luaK_codeABC()
234 int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { in luaK_codeABx() argument
238 return luaK_code(fs, CREATE_ABx(o, a, bc)); in luaK_codeABx()
242 static int codeextraarg (FuncState *fs, int a) { in codeextraarg() argument
244 return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a)); in codeextraarg()
248 int luaK_codek (FuncState *fs, int reg, int k) { in luaK_codek() argument
250 return luaK_codeABx(fs, OP_LOADK, reg, k); in luaK_codek()
252 int p = luaK_codeABx(fs, OP_LOADKX, reg, 0); in luaK_codek()
253 codeextraarg(fs, k); in luaK_codek()
259 void luaK_checkstack (FuncState *fs, int n) { in luaK_checkstack() argument
260 int newstack = fs->freereg + n; in luaK_checkstack()
261 if (newstack > fs->f->maxstacksize) { in luaK_checkstack()
263 luaX_syntaxerror(fs->ls, "function or expression too complex"); in luaK_checkstack()
264 fs->f->maxstacksize = cast_byte(newstack); in luaK_checkstack()
269 void luaK_reserveregs (FuncState *fs, int n) { in luaK_reserveregs() argument
270 luaK_checkstack(fs, n); in luaK_reserveregs()
271 fs->freereg += n; in luaK_reserveregs()
275 static void freereg (FuncState *fs, int reg) { in freereg() argument
276 if (!ISK(reg) && reg >= fs->nactvar) { in freereg()
277 fs->freereg--; in freereg()
278 lua_assert(reg == fs->freereg); in freereg()
283 static void freeexp (FuncState *fs, expdesc *e) { in freeexp() argument
285 freereg(fs, e->u.info); in freeexp()
289 static int addk (FuncState *fs, TValue *key, TValue *v) { in addk() argument
290 lua_State *L = fs->ls->L; in addk()
291 TValue *idx = luaH_set(L, fs->h, key); in addk()
292 Proto *f = fs->f; in addk()
304 k = fs->nk; in addk()
311 fs->nk++; in addk()
317 int luaK_stringK (FuncState *fs, TString *s) { in luaK_stringK() argument
319 setsvalue(fs->ls->L, &o, s); in luaK_stringK()
320 return addk(fs, &o, &o); in luaK_stringK()
324 int luaK_numberK (FuncState *fs, lua_Number r) { in luaK_numberK() argument
326 lua_State *L = fs->ls->L; in luaK_numberK()
332 n = addk(fs, L->top - 1, &o); in luaK_numberK()
336 n = addk(fs, &o, &o); /* regular case */ in luaK_numberK()
341 static int boolK (FuncState *fs, int b) { in boolK() argument
344 return addk(fs, &o, &o); in boolK()
348 static int nilK (FuncState *fs) { in nilK() argument
352 sethvalue(fs->ls->L, &k, fs->h); in nilK()
353 return addk(fs, &k, &v); in nilK()
357 void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { in luaK_setreturns() argument
359 SETARG_C(getcode(fs, e), nresults+1); in luaK_setreturns()
362 SETARG_B(getcode(fs, e), nresults+1); in luaK_setreturns()
363 SETARG_A(getcode(fs, e), fs->freereg); in luaK_setreturns()
364 luaK_reserveregs(fs, 1); in luaK_setreturns()
369 void luaK_setoneret (FuncState *fs, expdesc *e) { in luaK_setoneret() argument
372 e->u.info = GETARG_A(getcode(fs, e)); in luaK_setoneret()
375 SETARG_B(getcode(fs, e), 2); in luaK_setoneret()
381 void luaK_dischargevars (FuncState *fs, expdesc *e) { in luaK_dischargevars() argument
388 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0); in luaK_dischargevars()
394 freereg(fs, e->u.ind.idx); in luaK_dischargevars()
396 freereg(fs, e->u.ind.t); in luaK_dischargevars()
399 e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx); in luaK_dischargevars()
405 luaK_setoneret(fs, e); in luaK_dischargevars()
413 static int code_label (FuncState *fs, int A, int b, int jump) { in code_label() argument
414 luaK_getlabel(fs); /* those instructions may be jump targets */ in code_label()
415 return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); in code_label()
419 static void discharge2reg (FuncState *fs, expdesc *e, int reg) { in discharge2reg() argument
420 luaK_dischargevars(fs, e); in discharge2reg()
423 luaK_nil(fs, reg, 1); in discharge2reg()
427 luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); in discharge2reg()
431 luaK_codek(fs, reg, e->u.info); in discharge2reg()
435 luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval)); in discharge2reg()
439 Instruction *pc = &getcode(fs, e); in discharge2reg()
445 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0); in discharge2reg()
458 static void discharge2anyreg (FuncState *fs, expdesc *e) { in discharge2anyreg() argument
460 luaK_reserveregs(fs, 1); in discharge2anyreg()
461 discharge2reg(fs, e, fs->freereg-1); in discharge2anyreg()
466 static void exp2reg (FuncState *fs, expdesc *e, int reg) { in exp2reg() argument
467 discharge2reg(fs, e, reg); in exp2reg()
469 luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */ in exp2reg()
474 if (need_value(fs, e->t) || need_value(fs, e->f)) { in exp2reg()
475 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); in exp2reg()
476 p_f = code_label(fs, reg, 0, 1); in exp2reg()
477 p_t = code_label(fs, reg, 1, 0); in exp2reg()
478 luaK_patchtohere(fs, fj); in exp2reg()
480 final = luaK_getlabel(fs); in exp2reg()
481 patchlistaux(fs, e->f, final, reg, p_f); in exp2reg()
482 patchlistaux(fs, e->t, final, reg, p_t); in exp2reg()
490 void luaK_exp2nextreg (FuncState *fs, expdesc *e) { in luaK_exp2nextreg() argument
491 luaK_dischargevars(fs, e); in luaK_exp2nextreg()
492 freeexp(fs, e); in luaK_exp2nextreg()
493 luaK_reserveregs(fs, 1); in luaK_exp2nextreg()
494 exp2reg(fs, e, fs->freereg - 1); in luaK_exp2nextreg()
498 int luaK_exp2anyreg (FuncState *fs, expdesc *e) { in luaK_exp2anyreg() argument
499 luaK_dischargevars(fs, e); in luaK_exp2anyreg()
502 if (e->u.info >= fs->nactvar) { /* reg. is not a local? */ in luaK_exp2anyreg()
503 exp2reg(fs, e, e->u.info); /* put value on it */ in luaK_exp2anyreg()
507 luaK_exp2nextreg(fs, e); /* default */ in luaK_exp2anyreg()
512 void luaK_exp2anyregup (FuncState *fs, expdesc *e) { in luaK_exp2anyregup() argument
514 luaK_exp2anyreg(fs, e); in luaK_exp2anyregup()
518 void luaK_exp2val (FuncState *fs, expdesc *e) { in luaK_exp2val() argument
520 luaK_exp2anyreg(fs, e); in luaK_exp2val()
522 luaK_dischargevars(fs, e); in luaK_exp2val()
526 int luaK_exp2RK (FuncState *fs, expdesc *e) { in luaK_exp2RK() argument
527 luaK_exp2val(fs, e); in luaK_exp2RK()
532 if (fs->nk <= MAXINDEXRK) { /* constant fits in RK operand? */ in luaK_exp2RK()
533 e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE)); in luaK_exp2RK()
540 e->u.info = luaK_numberK(fs, e->u.nval); in luaK_exp2RK()
552 return luaK_exp2anyreg(fs, e); in luaK_exp2RK()
556 void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { in luaK_storevar() argument
559 freeexp(fs, ex); in luaK_storevar()
560 exp2reg(fs, ex, var->u.info); in luaK_storevar()
564 int e = luaK_exp2anyreg(fs, ex); in luaK_storevar()
565 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0); in luaK_storevar()
570 int e = luaK_exp2RK(fs, ex); in luaK_storevar()
571 luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e); in luaK_storevar()
579 freeexp(fs, ex); in luaK_storevar()
583 void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { in luaK_self() argument
585 luaK_exp2anyreg(fs, e); in luaK_self()
587 freeexp(fs, e); in luaK_self()
588 e->u.info = fs->freereg; /* base register for op_self */ in luaK_self()
590 luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */ in luaK_self()
591 luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key)); in luaK_self()
592 freeexp(fs, key); in luaK_self()
596 static void invertjump (FuncState *fs, expdesc *e) { in invertjump() argument
597 Instruction *pc = getjumpcontrol(fs, e->u.info); in invertjump()
604 static int jumponcond (FuncState *fs, expdesc *e, int cond) { in jumponcond() argument
606 Instruction ie = getcode(fs, e); in jumponcond()
608 fs->pc--; /* remove previous OP_NOT */ in jumponcond()
609 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); in jumponcond()
613 discharge2anyreg(fs, e); in jumponcond()
614 freeexp(fs, e); in jumponcond()
615 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond); in jumponcond()
619 void luaK_goiftrue (FuncState *fs, expdesc *e) { in luaK_goiftrue() argument
621 luaK_dischargevars(fs, e); in luaK_goiftrue()
624 invertjump(fs, e); in luaK_goiftrue()
633 pc = jumponcond(fs, e, 0); in luaK_goiftrue()
637 luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ in luaK_goiftrue()
638 luaK_patchtohere(fs, e->t); in luaK_goiftrue()
643 void luaK_goiffalse (FuncState *fs, expdesc *e) { in luaK_goiffalse() argument
645 luaK_dischargevars(fs, e); in luaK_goiffalse()
656 pc = jumponcond(fs, e, 1); in luaK_goiffalse()
660 luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ in luaK_goiffalse()
661 luaK_patchtohere(fs, e->f); in luaK_goiffalse()
666 static void codenot (FuncState *fs, expdesc *e) { in codenot() argument
667 luaK_dischargevars(fs, e); in codenot()
678 invertjump(fs, e); in codenot()
683 discharge2anyreg(fs, e); in codenot()
684 freeexp(fs, e); in codenot()
685 e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0); in codenot()
696 removevalues(fs, e->f); in codenot()
697 removevalues(fs, e->t); in codenot()
701 void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { in luaK_indexed() argument
704 t->u.ind.idx = luaK_exp2RK(fs, k); in luaK_indexed()
727 static void codearith (FuncState *fs, OpCode op, in codearith() argument
732 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; in codearith()
733 int o1 = luaK_exp2RK(fs, e1); in codearith()
735 freeexp(fs, e1); in codearith()
736 freeexp(fs, e2); in codearith()
739 freeexp(fs, e2); in codearith()
740 freeexp(fs, e1); in codearith()
742 e1->u.info = luaK_codeABC(fs, op, 0, o1, o2); in codearith()
744 luaK_fixline(fs, line); in codearith()
749 static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, in codecomp() argument
751 int o1 = luaK_exp2RK(fs, e1); in codecomp()
752 int o2 = luaK_exp2RK(fs, e2); in codecomp()
753 freeexp(fs, e2); in codecomp()
754 freeexp(fs, e1); in codecomp()
760 e1->u.info = condjump(fs, op, cond, o1, o2); in codecomp()
765 void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) { in luaK_prefix() argument
773 luaK_exp2anyreg(fs, e); in luaK_prefix()
774 codearith(fs, OP_UNM, e, &e2, line); in luaK_prefix()
778 case OPR_NOT: codenot(fs, e); break; in luaK_prefix()
780 luaK_exp2anyreg(fs, e); /* cannot operate on constants */ in luaK_prefix()
781 codearith(fs, OP_LEN, e, &e2, line); in luaK_prefix()
789 void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { in luaK_infix() argument
792 luaK_goiftrue(fs, v); in luaK_infix()
796 luaK_goiffalse(fs, v); in luaK_infix()
800 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ in luaK_infix()
805 if (!isnumeral(v)) luaK_exp2RK(fs, v); in luaK_infix()
809 luaK_exp2RK(fs, v); in luaK_infix()
816 void luaK_posfix (FuncState *fs, BinOpr op, in luaK_posfix() argument
821 luaK_dischargevars(fs, e2); in luaK_posfix()
822 luaK_concat(fs, &e2->f, e1->f); in luaK_posfix()
828 luaK_dischargevars(fs, e2); in luaK_posfix()
829 luaK_concat(fs, &e2->t, e1->t); in luaK_posfix()
834 luaK_exp2val(fs, e2); in luaK_posfix()
835 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { in luaK_posfix()
836 lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1); in luaK_posfix()
837 freeexp(fs, e1); in luaK_posfix()
838 SETARG_B(getcode(fs, e2), e1->u.info); in luaK_posfix()
842 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ in luaK_posfix()
843 codearith(fs, OP_CONCAT, e1, e2, line); in luaK_posfix()
849 codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line); in luaK_posfix()
853 codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2); in luaK_posfix()
857 codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2); in luaK_posfix()
865 void luaK_fixline (FuncState *fs, int line) { in luaK_fixline() argument
866 fs->f->lineinfo[fs->pc - 1] = line; in luaK_fixline()
870 void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { in luaK_setlist() argument
875 luaK_codeABC(fs, OP_SETLIST, base, b, c); in luaK_setlist()
877 luaK_codeABC(fs, OP_SETLIST, base, b, 0); in luaK_setlist()
878 codeextraarg(fs, c); in luaK_setlist()
881 luaX_syntaxerror(fs->ls, "constructor too long"); in luaK_setlist()
882 fs->freereg = base + 1; /* free registers with list values */ in luaK_setlist()