Lines Matching refs:fs
35 void luaK_nil (FuncState *fs, int from, int n) { in luaK_nil() argument
37 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ in luaK_nil()
38 if (fs->pc == 0) { /* function start? */ in luaK_nil()
39 if (from >= fs->nactvar) in luaK_nil()
43 previous = &fs->f->code[fs->pc-1]; in luaK_nil()
55 luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ in luaK_nil()
59 int luaK_jump (FuncState *fs) { in luaK_jump() argument
60 int jpc = fs->jpc; /* save list of jumps to here */ in luaK_jump()
62 fs->jpc = NO_JUMP; in luaK_jump()
63 j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); in luaK_jump()
64 luaK_concat(fs, &j, jpc); /* keep them on hold */ in luaK_jump()
69 void luaK_ret (FuncState *fs, int first, int nret) { in luaK_ret() argument
70 luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); in luaK_ret()
74 static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { in condjump() argument
75 luaK_codeABC(fs, op, A, B, C); in condjump()
76 return luaK_jump(fs); in condjump()
80 static void fixjump (FuncState *fs, int pc, int dest) { in fixjump() argument
81 Instruction *jmp = &fs->f->code[pc]; in fixjump()
85 luaX_syntaxerror(fs->ls, "control structure too long"); in fixjump()
94 int luaK_getlabel (FuncState *fs) { in luaK_getlabel() argument
95 fs->lasttarget = fs->pc; in luaK_getlabel()
96 return fs->pc; in luaK_getlabel()
100 static int getjump (FuncState *fs, int pc) { in getjump() argument
101 int offset = GETARG_sBx(fs->f->code[pc]); in getjump()
109 static Instruction *getjumpcontrol (FuncState *fs, int pc) { in getjumpcontrol() argument
110 Instruction *pi = &fs->f->code[pc]; in getjumpcontrol()
122 static int need_value (FuncState *fs, int list) { in need_value() argument
123 for (; list != NO_JUMP; list = getjump(fs, list)) { in need_value()
124 Instruction i = *getjumpcontrol(fs, list); in need_value()
131 static int patchtestreg (FuncState *fs, int node, int reg) { in patchtestreg() argument
132 Instruction *i = getjumpcontrol(fs, node); in patchtestreg()
144 static void removevalues (FuncState *fs, int list) { in removevalues() argument
145 for (; list != NO_JUMP; list = getjump(fs, list)) in removevalues()
146 patchtestreg(fs, list, NO_REG); in removevalues()
150 static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, in patchlistaux() argument
153 int next = getjump(fs, list); in patchlistaux()
154 if (patchtestreg(fs, list, reg)) in patchlistaux()
155 fixjump(fs, list, vtarget); in patchlistaux()
157 fixjump(fs, list, dtarget); /* jump to default target */ in patchlistaux()
163 static void dischargejpc (FuncState *fs) { in dischargejpc() argument
164 patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); in dischargejpc()
165 fs->jpc = NO_JUMP; in dischargejpc()
169 void luaK_patchlist (FuncState *fs, int list, int target) { in luaK_patchlist() argument
170 if (target == fs->pc) in luaK_patchlist()
171 luaK_patchtohere(fs, list); in luaK_patchlist()
173 lua_assert(target < fs->pc); in luaK_patchlist()
174 patchlistaux(fs, list, target, NO_REG, target); in luaK_patchlist()
179 void luaK_patchtohere (FuncState *fs, int list) { in luaK_patchtohere() argument
180 luaK_getlabel(fs); in luaK_patchtohere()
181 luaK_concat(fs, &fs->jpc, list); in luaK_patchtohere()
185 void luaK_concat (FuncState *fs, int *l1, int l2) { in luaK_concat() argument
192 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ in luaK_concat()
194 fixjump(fs, list, l2); in luaK_concat()
199 void luaK_checkstack (FuncState *fs, int n) { in luaK_checkstack() argument
200 int newstack = fs->freereg + n; in luaK_checkstack()
201 if (newstack > fs->f->maxstacksize) { in luaK_checkstack()
203 luaX_syntaxerror(fs->ls, "function or expression too complex"); in luaK_checkstack()
204 fs->f->maxstacksize = cast_byte(newstack); in luaK_checkstack()
209 void luaK_reserveregs (FuncState *fs, int n) { in luaK_reserveregs() argument
210 luaK_checkstack(fs, n); in luaK_reserveregs()
211 fs->freereg += n; in luaK_reserveregs()
215 static void freereg (FuncState *fs, int reg) { in freereg() argument
216 if (!ISK(reg) && reg >= fs->nactvar) { in freereg()
217 fs->freereg--; in freereg()
218 lua_assert(reg == fs->freereg); in freereg()
223 static void freeexp (FuncState *fs, expdesc *e) { in freeexp() argument
225 freereg(fs, e->u.s.info); in freeexp()
229 static int addk (FuncState *fs, TValue *k, TValue *v) { in addk() argument
230 lua_State *L = fs->L; in addk()
231 TValue *idx = luaH_set(L, fs->h, k); in addk()
232 Proto *f = fs->f; in addk()
235 lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); in addk()
239 setnvalue(idx, cast_num(fs->nk)); in addk()
240 luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, in addk()
243 setobj(L, &f->k[fs->nk], v); in addk()
245 return fs->nk++; in addk()
250 int luaK_stringK (FuncState *fs, TString *s) { in luaK_stringK() argument
252 setsvalue(fs->L, &o, s); in luaK_stringK()
253 return addk(fs, &o, &o); in luaK_stringK()
257 int luaK_numberK (FuncState *fs, lua_Number r) { in luaK_numberK() argument
260 return addk(fs, &o, &o); in luaK_numberK()
264 static int boolK (FuncState *fs, int b) { in boolK() argument
267 return addk(fs, &o, &o); in boolK()
271 static int nilK (FuncState *fs) { in nilK() argument
275 sethvalue(fs->L, &k, fs->h); in nilK()
276 return addk(fs, &k, &v); in nilK()
280 void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { in luaK_setreturns() argument
282 SETARG_C(getcode(fs, e), nresults+1); in luaK_setreturns()
285 SETARG_B(getcode(fs, e), nresults+1); in luaK_setreturns()
286 SETARG_A(getcode(fs, e), fs->freereg); in luaK_setreturns()
287 luaK_reserveregs(fs, 1); in luaK_setreturns()
292 void luaK_setoneret (FuncState *fs, expdesc *e) { in luaK_setoneret() argument
295 e->u.s.info = GETARG_A(getcode(fs, e)); in luaK_setoneret()
298 SETARG_B(getcode(fs, e), 2); in luaK_setoneret()
304 void luaK_dischargevars (FuncState *fs, expdesc *e) { in luaK_dischargevars() argument
311 e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); in luaK_dischargevars()
316 e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); in luaK_dischargevars()
321 freereg(fs, e->u.s.aux); in luaK_dischargevars()
322 freereg(fs, e->u.s.info); in luaK_dischargevars()
323 e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); in luaK_dischargevars()
329 luaK_setoneret(fs, e); in luaK_dischargevars()
337 static int code_label (FuncState *fs, int A, int b, int jump) { in code_label() argument
338 luaK_getlabel(fs); /* those instructions may be jump targets */ in code_label()
339 return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); in code_label()
343 static void discharge2reg (FuncState *fs, expdesc *e, int reg) { in discharge2reg() argument
344 luaK_dischargevars(fs, e); in discharge2reg()
347 luaK_nil(fs, reg, 1); in discharge2reg()
351 luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); in discharge2reg()
355 luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); in discharge2reg()
359 luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); in discharge2reg()
363 Instruction *pc = &getcode(fs, e); in discharge2reg()
369 luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); in discharge2reg()
382 static void discharge2anyreg (FuncState *fs, expdesc *e) { in discharge2anyreg() argument
384 luaK_reserveregs(fs, 1); in discharge2anyreg()
385 discharge2reg(fs, e, fs->freereg-1); in discharge2anyreg()
390 static void exp2reg (FuncState *fs, expdesc *e, int reg) { in exp2reg() argument
391 discharge2reg(fs, e, reg); in exp2reg()
393 luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ in exp2reg()
398 if (need_value(fs, e->t) || need_value(fs, e->f)) { in exp2reg()
399 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); in exp2reg()
400 p_f = code_label(fs, reg, 0, 1); in exp2reg()
401 p_t = code_label(fs, reg, 1, 0); in exp2reg()
402 luaK_patchtohere(fs, fj); in exp2reg()
404 final = luaK_getlabel(fs); in exp2reg()
405 patchlistaux(fs, e->f, final, reg, p_f); in exp2reg()
406 patchlistaux(fs, e->t, final, reg, p_t); in exp2reg()
414 void luaK_exp2nextreg (FuncState *fs, expdesc *e) { in luaK_exp2nextreg() argument
415 luaK_dischargevars(fs, e); in luaK_exp2nextreg()
416 freeexp(fs, e); in luaK_exp2nextreg()
417 luaK_reserveregs(fs, 1); in luaK_exp2nextreg()
418 exp2reg(fs, e, fs->freereg - 1); in luaK_exp2nextreg()
422 int luaK_exp2anyreg (FuncState *fs, expdesc *e) { in luaK_exp2anyreg() argument
423 luaK_dischargevars(fs, e); in luaK_exp2anyreg()
426 if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ in luaK_exp2anyreg()
427 exp2reg(fs, e, e->u.s.info); /* put value on it */ in luaK_exp2anyreg()
431 luaK_exp2nextreg(fs, e); /* default */ in luaK_exp2anyreg()
436 void luaK_exp2val (FuncState *fs, expdesc *e) { in luaK_exp2val() argument
438 luaK_exp2anyreg(fs, e); in luaK_exp2val()
440 luaK_dischargevars(fs, e); in luaK_exp2val()
444 int luaK_exp2RK (FuncState *fs, expdesc *e) { in luaK_exp2RK() argument
445 luaK_exp2val(fs, e); in luaK_exp2RK()
451 if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ in luaK_exp2RK()
452 e->u.s.info = (e->k == VNIL) ? nilK(fs) : in luaK_exp2RK()
453 (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : in luaK_exp2RK()
454 boolK(fs, (e->k == VTRUE)); in luaK_exp2RK()
468 return luaK_exp2anyreg(fs, e); in luaK_exp2RK()
472 void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { in luaK_storevar() argument
475 freeexp(fs, ex); in luaK_storevar()
476 exp2reg(fs, ex, var->u.s.info); in luaK_storevar()
480 int e = luaK_exp2anyreg(fs, ex); in luaK_storevar()
481 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); in luaK_storevar()
485 int e = luaK_exp2anyreg(fs, ex); in luaK_storevar()
486 luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); in luaK_storevar()
490 int e = luaK_exp2RK(fs, ex); in luaK_storevar()
491 luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); in luaK_storevar()
499 freeexp(fs, ex); in luaK_storevar()
503 void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { in luaK_self() argument
505 luaK_exp2anyreg(fs, e); in luaK_self()
506 freeexp(fs, e); in luaK_self()
507 func = fs->freereg; in luaK_self()
508 luaK_reserveregs(fs, 2); in luaK_self()
509 luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); in luaK_self()
510 freeexp(fs, key); in luaK_self()
516 static void invertjump (FuncState *fs, expdesc *e) { in invertjump() argument
517 Instruction *pc = getjumpcontrol(fs, e->u.s.info); in invertjump()
524 static int jumponcond (FuncState *fs, expdesc *e, int cond) { in jumponcond() argument
526 Instruction ie = getcode(fs, e); in jumponcond()
528 fs->pc--; /* remove previous OP_NOT */ in jumponcond()
529 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); in jumponcond()
533 discharge2anyreg(fs, e); in jumponcond()
534 freeexp(fs, e); in jumponcond()
535 return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); in jumponcond()
539 void luaK_goiftrue (FuncState *fs, expdesc *e) { in luaK_goiftrue() argument
541 luaK_dischargevars(fs, e); in luaK_goiftrue()
548 invertjump(fs, e); in luaK_goiftrue()
553 pc = jumponcond(fs, e, 0); in luaK_goiftrue()
557 luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ in luaK_goiftrue()
558 luaK_patchtohere(fs, e->t); in luaK_goiftrue()
563 static void luaK_goiffalse (FuncState *fs, expdesc *e) { in luaK_goiffalse() argument
565 luaK_dischargevars(fs, e); in luaK_goiffalse()
576 pc = jumponcond(fs, e, 1); in luaK_goiffalse()
580 luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ in luaK_goiffalse()
581 luaK_patchtohere(fs, e->f); in luaK_goiffalse()
586 static void codenot (FuncState *fs, expdesc *e) { in codenot() argument
587 luaK_dischargevars(fs, e); in codenot()
598 invertjump(fs, e); in codenot()
603 discharge2anyreg(fs, e); in codenot()
604 freeexp(fs, e); in codenot()
605 e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); in codenot()
616 removevalues(fs, e->f); in codenot()
617 removevalues(fs, e->t); in codenot()
621 void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { in luaK_indexed() argument
622 t->u.s.aux = luaK_exp2RK(fs, k); in luaK_indexed()
653 static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { in codearith() argument
657 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; in codearith()
658 int o1 = luaK_exp2RK(fs, e1); in codearith()
660 freeexp(fs, e1); in codearith()
661 freeexp(fs, e2); in codearith()
664 freeexp(fs, e2); in codearith()
665 freeexp(fs, e1); in codearith()
667 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); in codearith()
673 static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, in codecomp() argument
675 int o1 = luaK_exp2RK(fs, e1); in codecomp()
676 int o2 = luaK_exp2RK(fs, e2); in codecomp()
677 freeexp(fs, e2); in codecomp()
678 freeexp(fs, e1); in codecomp()
684 e1->u.s.info = condjump(fs, op, cond, o1, o2); in codecomp()
689 void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { in luaK_prefix() argument
695 luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ in luaK_prefix()
696 codearith(fs, OP_UNM, e, &e2); in luaK_prefix()
699 case OPR_NOT: codenot(fs, e); break; in luaK_prefix()
701 luaK_exp2anyreg(fs, e); /* cannot operate on constants */ in luaK_prefix()
702 codearith(fs, OP_LEN, e, &e2); in luaK_prefix()
710 void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { in luaK_infix() argument
713 luaK_goiftrue(fs, v); in luaK_infix()
717 luaK_goiffalse(fs, v); in luaK_infix()
721 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ in luaK_infix()
726 if (!isnumeral(v)) luaK_exp2RK(fs, v); in luaK_infix()
730 luaK_exp2RK(fs, v); in luaK_infix()
737 void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { in luaK_posfix() argument
741 luaK_dischargevars(fs, e2); in luaK_posfix()
742 luaK_concat(fs, &e2->f, e1->f); in luaK_posfix()
748 luaK_dischargevars(fs, e2); in luaK_posfix()
749 luaK_concat(fs, &e2->t, e1->t); in luaK_posfix()
754 luaK_exp2val(fs, e2); in luaK_posfix()
755 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { in luaK_posfix()
756 lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); in luaK_posfix()
757 freeexp(fs, e1); in luaK_posfix()
758 SETARG_B(getcode(fs, e2), e1->u.s.info); in luaK_posfix()
762 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ in luaK_posfix()
763 codearith(fs, OP_CONCAT, e1, e2); in luaK_posfix()
767 case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; in luaK_posfix()
768 case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; in luaK_posfix()
769 case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; in luaK_posfix()
770 case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; in luaK_posfix()
771 case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; in luaK_posfix()
772 case OPR_POW: codearith(fs, OP_POW, e1, e2); break; in luaK_posfix()
773 case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; in luaK_posfix()
774 case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; in luaK_posfix()
775 case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; in luaK_posfix()
776 case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; in luaK_posfix()
777 case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; in luaK_posfix()
778 case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; in luaK_posfix()
784 void luaK_fixline (FuncState *fs, int line) { in luaK_fixline() argument
785 fs->f->lineinfo[fs->pc - 1] = line; in luaK_fixline()
789 static int luaK_code (FuncState *fs, Instruction i, int line) { in luaK_code() argument
790 Proto *f = fs->f; in luaK_code()
791 dischargejpc(fs); /* `pc' will change */ in luaK_code()
793 luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, in luaK_code()
795 f->code[fs->pc] = i; in luaK_code()
797 luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, in luaK_code()
799 f->lineinfo[fs->pc] = line; in luaK_code()
800 return fs->pc++; in luaK_code()
804 int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { in luaK_codeABC() argument
808 return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline); in luaK_codeABC()
812 int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { in luaK_codeABx() argument
815 return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); in luaK_codeABx()
819 void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { in luaK_setlist() argument
824 luaK_codeABC(fs, OP_SETLIST, base, b, c); in luaK_setlist()
826 luaK_codeABC(fs, OP_SETLIST, base, b, 0); in luaK_setlist()
827 luaK_code(fs, cast(Instruction, c), fs->ls->lastline); in luaK_setlist()
829 fs->freereg = base + 1; /* free registers with list values */ in luaK_setlist()