1 /* $NetBSD: lcode.c,v 1.1.1.2 2012/03/15 00:08:11 alnsn Exp $ */
4 ** $Id: lcode.c,v 1.1.1.2 2012/03/15 00:08:11 alnsn Exp $
5 ** Code generator for Lua
6 ** See Copyright Notice in lua.h
29 #define hasjumps(e) ((e)->t != (e)->f)
32 static int isnumeral(expdesc
*e
) {
33 return (e
->k
== VKNUM
&& e
->t
== NO_JUMP
&& e
->f
== NO_JUMP
);
37 void luaK_nil (FuncState
*fs
, int from
, int n
) {
38 Instruction
*previous
;
39 if (fs
->pc
> fs
->lasttarget
) { /* no jumps to current position? */
40 if (fs
->pc
== 0) { /* function start? */
41 if (from
>= fs
->nactvar
)
42 return; /* positions are already clean */
45 previous
= &fs
->f
->code
[fs
->pc
-1];
46 if (GET_OPCODE(*previous
) == OP_LOADNIL
) {
47 int pfrom
= GETARG_A(*previous
);
48 int pto
= GETARG_B(*previous
);
49 if (pfrom
<= from
&& from
<= pto
+1) { /* can connect both? */
51 SETARG_B(*previous
, from
+n
-1);
57 luaK_codeABC(fs
, OP_LOADNIL
, from
, from
+n
-1, 0); /* else no optimization */
61 int luaK_jump (FuncState
*fs
) {
62 int jpc
= fs
->jpc
; /* save list of jumps to here */
65 j
= luaK_codeAsBx(fs
, OP_JMP
, 0, NO_JUMP
);
66 luaK_concat(fs
, &j
, jpc
); /* keep them on hold */
71 void luaK_ret (FuncState
*fs
, int first
, int nret
) {
72 luaK_codeABC(fs
, OP_RETURN
, first
, nret
+1, 0);
76 static int condjump (FuncState
*fs
, OpCode op
, int A
, int B
, int C
) {
77 luaK_codeABC(fs
, op
, A
, B
, C
);
82 static void fixjump (FuncState
*fs
, int pc
, int dest
) {
83 Instruction
*jmp
= &fs
->f
->code
[pc
];
84 int offset
= dest
-(pc
+1);
85 lua_assert(dest
!= NO_JUMP
);
86 if (abs(offset
) > MAXARG_sBx
)
87 luaX_syntaxerror(fs
->ls
, "control structure too long");
88 SETARG_sBx(*jmp
, offset
);
93 ** returns current `pc' and marks it as a jump target (to avoid wrong
94 ** optimizations with consecutive instructions not in the same basic block).
96 int luaK_getlabel (FuncState
*fs
) {
97 fs
->lasttarget
= fs
->pc
;
102 static int getjump (FuncState
*fs
, int pc
) {
103 int offset
= GETARG_sBx(fs
->f
->code
[pc
]);
104 if (offset
== NO_JUMP
) /* point to itself represents end of list */
105 return NO_JUMP
; /* end of list */
107 return (pc
+1)+offset
; /* turn offset into absolute position */
111 static Instruction
*getjumpcontrol (FuncState
*fs
, int pc
) {
112 Instruction
*pi
= &fs
->f
->code
[pc
];
113 if (pc
>= 1 && testTMode(GET_OPCODE(*(pi
-1))))
121 ** check whether list has any jump that do not produce a value
122 ** (or produce an inverted value)
124 static int need_value (FuncState
*fs
, int list
) {
125 for (; list
!= NO_JUMP
; list
= getjump(fs
, list
)) {
126 Instruction i
= *getjumpcontrol(fs
, list
);
127 if (GET_OPCODE(i
) != OP_TESTSET
) return 1;
129 return 0; /* not found */
133 static int patchtestreg (FuncState
*fs
, int node
, int reg
) {
134 Instruction
*i
= getjumpcontrol(fs
, node
);
135 if (GET_OPCODE(*i
) != OP_TESTSET
)
136 return 0; /* cannot patch other instructions */
137 if (reg
!= NO_REG
&& reg
!= GETARG_B(*i
))
139 else /* no register to put value or register already has the value */
140 *i
= CREATE_ABC(OP_TEST
, GETARG_B(*i
), 0, GETARG_C(*i
));
146 static void removevalues (FuncState
*fs
, int list
) {
147 for (; list
!= NO_JUMP
; list
= getjump(fs
, list
))
148 patchtestreg(fs
, list
, NO_REG
);
152 static void patchlistaux (FuncState
*fs
, int list
, int vtarget
, int reg
,
154 while (list
!= NO_JUMP
) {
155 int next
= getjump(fs
, list
);
156 if (patchtestreg(fs
, list
, reg
))
157 fixjump(fs
, list
, vtarget
);
159 fixjump(fs
, list
, dtarget
); /* jump to default target */
165 static void dischargejpc (FuncState
*fs
) {
166 patchlistaux(fs
, fs
->jpc
, fs
->pc
, NO_REG
, fs
->pc
);
171 void luaK_patchlist (FuncState
*fs
, int list
, int target
) {
172 if (target
== fs
->pc
)
173 luaK_patchtohere(fs
, list
);
175 lua_assert(target
< fs
->pc
);
176 patchlistaux(fs
, list
, target
, NO_REG
, target
);
181 void luaK_patchtohere (FuncState
*fs
, int list
) {
183 luaK_concat(fs
, &fs
->jpc
, list
);
187 void luaK_concat (FuncState
*fs
, int *l1
, int l2
) {
188 if (l2
== NO_JUMP
) return;
189 else if (*l1
== NO_JUMP
)
194 while ((next
= getjump(fs
, list
)) != NO_JUMP
) /* find last element */
196 fixjump(fs
, list
, l2
);
201 void luaK_checkstack (FuncState
*fs
, int n
) {
202 int newstack
= fs
->freereg
+ n
;
203 if (newstack
> fs
->f
->maxstacksize
) {
204 if (newstack
>= MAXSTACK
)
205 luaX_syntaxerror(fs
->ls
, "function or expression too complex");
206 fs
->f
->maxstacksize
= cast_byte(newstack
);
211 void luaK_reserveregs (FuncState
*fs
, int n
) {
212 luaK_checkstack(fs
, n
);
217 static void freereg (FuncState
*fs
, int reg
) {
218 if (!ISK(reg
) && reg
>= fs
->nactvar
) {
220 lua_assert(reg
== fs
->freereg
);
225 static void freeexp (FuncState
*fs
, expdesc
*e
) {
226 if (e
->k
== VNONRELOC
)
227 freereg(fs
, e
->u
.s
.info
);
231 static int addk (FuncState
*fs
, TValue
*k
, TValue
*v
) {
232 lua_State
*L
= fs
->L
;
233 TValue
*idx
= luaH_set(L
, fs
->h
, k
);
235 int oldsize
= f
->sizek
;
236 if (ttisnumber(idx
)) {
237 lua_assert(luaO_rawequalObj(&fs
->f
->k
[cast_int(nvalue(idx
))], v
));
238 return cast_int(nvalue(idx
));
240 else { /* constant not found; create a new entry */
241 setnvalue(idx
, cast_num(fs
->nk
));
242 luaM_growvector(L
, f
->k
, fs
->nk
, f
->sizek
, TValue
,
243 MAXARG_Bx
, "constant table overflow");
244 while (oldsize
< f
->sizek
) setnilvalue(&f
->k
[oldsize
++]);
245 setobj(L
, &f
->k
[fs
->nk
], v
);
246 luaC_barrier(L
, f
, v
);
252 int luaK_stringK (FuncState
*fs
, TString
*s
) {
254 setsvalue(fs
->L
, &o
, s
);
255 return addk(fs
, &o
, &o
);
259 int luaK_numberK (FuncState
*fs
, lua_Number r
) {
262 return addk(fs
, &o
, &o
);
266 static int boolK (FuncState
*fs
, int b
) {
269 return addk(fs
, &o
, &o
);
273 static int nilK (FuncState
*fs
) {
276 /* cannot use nil as key; instead use table itself to represent nil */
277 sethvalue(fs
->L
, &k
, fs
->h
);
278 return addk(fs
, &k
, &v
);
282 void luaK_setreturns (FuncState
*fs
, expdesc
*e
, int nresults
) {
283 if (e
->k
== VCALL
) { /* expression is an open function call? */
284 SETARG_C(getcode(fs
, e
), nresults
+1);
286 else if (e
->k
== VVARARG
) {
287 SETARG_B(getcode(fs
, e
), nresults
+1);
288 SETARG_A(getcode(fs
, e
), fs
->freereg
);
289 luaK_reserveregs(fs
, 1);
294 void luaK_setoneret (FuncState
*fs
, expdesc
*e
) {
295 if (e
->k
== VCALL
) { /* expression is an open function call? */
297 e
->u
.s
.info
= GETARG_A(getcode(fs
, e
));
299 else if (e
->k
== VVARARG
) {
300 SETARG_B(getcode(fs
, e
), 2);
301 e
->k
= VRELOCABLE
; /* can relocate its simple result */
306 void luaK_dischargevars (FuncState
*fs
, expdesc
*e
) {
313 e
->u
.s
.info
= luaK_codeABC(fs
, OP_GETUPVAL
, 0, e
->u
.s
.info
, 0);
318 e
->u
.s
.info
= luaK_codeABx(fs
, OP_GETGLOBAL
, 0, e
->u
.s
.info
);
323 freereg(fs
, e
->u
.s
.aux
);
324 freereg(fs
, e
->u
.s
.info
);
325 e
->u
.s
.info
= luaK_codeABC(fs
, OP_GETTABLE
, 0, e
->u
.s
.info
, e
->u
.s
.aux
);
331 luaK_setoneret(fs
, e
);
334 default: break; /* there is one value available (somewhere) */
339 static int code_label (FuncState
*fs
, int A
, int b
, int jump
) {
340 luaK_getlabel(fs
); /* those instructions may be jump targets */
341 return luaK_codeABC(fs
, OP_LOADBOOL
, A
, b
, jump
);
345 static void discharge2reg (FuncState
*fs
, expdesc
*e
, int reg
) {
346 luaK_dischargevars(fs
, e
);
349 luaK_nil(fs
, reg
, 1);
352 case VFALSE
: case VTRUE
: {
353 luaK_codeABC(fs
, OP_LOADBOOL
, reg
, e
->k
== VTRUE
, 0);
357 luaK_codeABx(fs
, OP_LOADK
, reg
, e
->u
.s
.info
);
361 luaK_codeABx(fs
, OP_LOADK
, reg
, luaK_numberK(fs
, e
->u
.nval
));
365 Instruction
*pc
= &getcode(fs
, e
);
370 if (reg
!= e
->u
.s
.info
)
371 luaK_codeABC(fs
, OP_MOVE
, reg
, e
->u
.s
.info
, 0);
375 lua_assert(e
->k
== VVOID
|| e
->k
== VJMP
);
376 return; /* nothing to do... */
384 static void discharge2anyreg (FuncState
*fs
, expdesc
*e
) {
385 if (e
->k
!= VNONRELOC
) {
386 luaK_reserveregs(fs
, 1);
387 discharge2reg(fs
, e
, fs
->freereg
-1);
392 static void exp2reg (FuncState
*fs
, expdesc
*e
, int reg
) {
393 discharge2reg(fs
, e
, reg
);
395 luaK_concat(fs
, &e
->t
, e
->u
.s
.info
); /* put this jump in `t' list */
397 int final
; /* position after whole expression */
398 int p_f
= NO_JUMP
; /* position of an eventual LOAD false */
399 int p_t
= NO_JUMP
; /* position of an eventual LOAD true */
400 if (need_value(fs
, e
->t
) || need_value(fs
, e
->f
)) {
401 int fj
= (e
->k
== VJMP
) ? NO_JUMP
: luaK_jump(fs
);
402 p_f
= code_label(fs
, reg
, 0, 1);
403 p_t
= code_label(fs
, reg
, 1, 0);
404 luaK_patchtohere(fs
, fj
);
406 final
= luaK_getlabel(fs
);
407 patchlistaux(fs
, e
->f
, final
, reg
, p_f
);
408 patchlistaux(fs
, e
->t
, final
, reg
, p_t
);
410 e
->f
= e
->t
= NO_JUMP
;
416 void luaK_exp2nextreg (FuncState
*fs
, expdesc
*e
) {
417 luaK_dischargevars(fs
, e
);
419 luaK_reserveregs(fs
, 1);
420 exp2reg(fs
, e
, fs
->freereg
- 1);
424 int luaK_exp2anyreg (FuncState
*fs
, expdesc
*e
) {
425 luaK_dischargevars(fs
, e
);
426 if (e
->k
== VNONRELOC
) {
427 if (!hasjumps(e
)) return e
->u
.s
.info
; /* exp is already in a register */
428 if (e
->u
.s
.info
>= fs
->nactvar
) { /* reg. is not a local? */
429 exp2reg(fs
, e
, e
->u
.s
.info
); /* put value on it */
433 luaK_exp2nextreg(fs
, e
); /* default */
438 void luaK_exp2val (FuncState
*fs
, expdesc
*e
) {
440 luaK_exp2anyreg(fs
, e
);
442 luaK_dischargevars(fs
, e
);
446 int luaK_exp2RK (FuncState
*fs
, expdesc
*e
) {
453 if (fs
->nk
<= MAXINDEXRK
) { /* constant fit in RK operand? */
454 e
->u
.s
.info
= (e
->k
== VNIL
) ? nilK(fs
) :
455 (e
->k
== VKNUM
) ? luaK_numberK(fs
, e
->u
.nval
) :
456 boolK(fs
, (e
->k
== VTRUE
));
458 return RKASK(e
->u
.s
.info
);
463 if (e
->u
.s
.info
<= MAXINDEXRK
) /* constant fit in argC? */
464 return RKASK(e
->u
.s
.info
);
469 /* not a constant in the right range: put it in a register */
470 return luaK_exp2anyreg(fs
, e
);
474 void luaK_storevar (FuncState
*fs
, expdesc
*var
, expdesc
*ex
) {
478 exp2reg(fs
, ex
, var
->u
.s
.info
);
482 int e
= luaK_exp2anyreg(fs
, ex
);
483 luaK_codeABC(fs
, OP_SETUPVAL
, e
, var
->u
.s
.info
, 0);
487 int e
= luaK_exp2anyreg(fs
, ex
);
488 luaK_codeABx(fs
, OP_SETGLOBAL
, e
, var
->u
.s
.info
);
492 int e
= luaK_exp2RK(fs
, ex
);
493 luaK_codeABC(fs
, OP_SETTABLE
, var
->u
.s
.info
, var
->u
.s
.aux
, e
);
497 lua_assert(0); /* invalid var kind to store */
505 void luaK_self (FuncState
*fs
, expdesc
*e
, expdesc
*key
) {
507 luaK_exp2anyreg(fs
, e
);
510 luaK_reserveregs(fs
, 2);
511 luaK_codeABC(fs
, OP_SELF
, func
, e
->u
.s
.info
, luaK_exp2RK(fs
, key
));
518 static void invertjump (FuncState
*fs
, expdesc
*e
) {
519 Instruction
*pc
= getjumpcontrol(fs
, e
->u
.s
.info
);
520 lua_assert(testTMode(GET_OPCODE(*pc
)) && GET_OPCODE(*pc
) != OP_TESTSET
&&
521 GET_OPCODE(*pc
) != OP_TEST
);
522 SETARG_A(*pc
, !(GETARG_A(*pc
)));
526 static int jumponcond (FuncState
*fs
, expdesc
*e
, int cond
) {
527 if (e
->k
== VRELOCABLE
) {
528 Instruction ie
= getcode(fs
, e
);
529 if (GET_OPCODE(ie
) == OP_NOT
) {
530 fs
->pc
--; /* remove previous OP_NOT */
531 return condjump(fs
, OP_TEST
, GETARG_B(ie
), 0, !cond
);
533 /* else go through */
535 discharge2anyreg(fs
, e
);
537 return condjump(fs
, OP_TESTSET
, NO_REG
, e
->u
.s
.info
, cond
);
541 void luaK_goiftrue (FuncState
*fs
, expdesc
*e
) {
542 int pc
; /* pc of last jump */
543 luaK_dischargevars(fs
, e
);
545 case VK
: case VKNUM
: case VTRUE
: {
546 pc
= NO_JUMP
; /* always true; do nothing */
555 pc
= jumponcond(fs
, e
, 0);
559 luaK_concat(fs
, &e
->f
, pc
); /* insert last jump in `f' list */
560 luaK_patchtohere(fs
, e
->t
);
565 static void luaK_goiffalse (FuncState
*fs
, expdesc
*e
) {
566 int pc
; /* pc of last jump */
567 luaK_dischargevars(fs
, e
);
569 case VNIL
: case VFALSE
: {
570 pc
= NO_JUMP
; /* always false; do nothing */
578 pc
= jumponcond(fs
, e
, 1);
582 luaK_concat(fs
, &e
->t
, pc
); /* insert last jump in `t' list */
583 luaK_patchtohere(fs
, e
->f
);
588 static void codenot (FuncState
*fs
, expdesc
*e
) {
589 luaK_dischargevars(fs
, e
);
591 case VNIL
: case VFALSE
: {
595 case VK
: case VKNUM
: case VTRUE
: {
605 discharge2anyreg(fs
, e
);
607 e
->u
.s
.info
= luaK_codeABC(fs
, OP_NOT
, 0, e
->u
.s
.info
, 0);
612 lua_assert(0); /* cannot happen */
616 /* interchange true and false lists */
617 { int temp
= e
->f
; e
->f
= e
->t
; e
->t
= temp
; }
618 removevalues(fs
, e
->f
);
619 removevalues(fs
, e
->t
);
623 void luaK_indexed (FuncState
*fs
, expdesc
*t
, expdesc
*k
) {
624 t
->u
.s
.aux
= luaK_exp2RK(fs
, k
);
629 static int constfolding (OpCode op
, expdesc
*e1
, expdesc
*e2
) {
630 lua_Number v1
, v2
, r
;
631 if (!isnumeral(e1
) || !isnumeral(e2
)) return 0;
635 case OP_ADD
: r
= luai_numadd(v1
, v2
); break;
636 case OP_SUB
: r
= luai_numsub(v1
, v2
); break;
637 case OP_MUL
: r
= luai_nummul(v1
, v2
); break;
639 if (v2
== 0) return 0; /* do not attempt to divide by 0 */
640 r
= luai_numdiv(v1
, v2
); break;
642 if (v2
== 0) return 0; /* do not attempt to divide by 0 */
643 r
= luai_nummod(v1
, v2
); break;
644 case OP_POW
: r
= luai_numpow(v1
, v2
); break;
645 case OP_UNM
: r
= luai_numunm(v1
); break;
646 case OP_LEN
: return 0; /* no constant folding for 'len' */
647 default: lua_assert(0); r
= 0; break;
649 if (luai_numisnan(r
)) return 0; /* do not attempt to produce NaN */
655 static void codearith (FuncState
*fs
, OpCode op
, expdesc
*e1
, expdesc
*e2
) {
656 if (constfolding(op
, e1
, e2
))
659 int o2
= (op
!= OP_UNM
&& op
!= OP_LEN
) ? luaK_exp2RK(fs
, e2
) : 0;
660 int o1
= luaK_exp2RK(fs
, e1
);
669 e1
->u
.s
.info
= luaK_codeABC(fs
, op
, 0, o1
, o2
);
675 static void codecomp (FuncState
*fs
, OpCode op
, int cond
, expdesc
*e1
,
677 int o1
= luaK_exp2RK(fs
, e1
);
678 int o2
= luaK_exp2RK(fs
, e2
);
681 if (cond
== 0 && op
!= OP_EQ
) {
682 int temp
; /* exchange args to replace by `<' or `<=' */
683 temp
= o1
; o1
= o2
; o2
= temp
; /* o1 <==> o2 */
686 e1
->u
.s
.info
= condjump(fs
, op
, cond
, o1
, o2
);
691 void luaK_prefix (FuncState
*fs
, UnOpr op
, expdesc
*e
) {
693 e2
.t
= e2
.f
= NO_JUMP
; e2
.k
= VKNUM
; e2
.u
.nval
= 0;
697 luaK_exp2anyreg(fs
, e
); /* cannot operate on non-numeric constants */
698 codearith(fs
, OP_UNM
, e
, &e2
);
701 case OPR_NOT
: codenot(fs
, e
); break;
703 luaK_exp2anyreg(fs
, e
); /* cannot operate on constants */
704 codearith(fs
, OP_LEN
, e
, &e2
);
707 default: lua_assert(0);
712 void luaK_infix (FuncState
*fs
, BinOpr op
, expdesc
*v
) {
715 luaK_goiftrue(fs
, v
);
719 luaK_goiffalse(fs
, v
);
723 luaK_exp2nextreg(fs
, v
); /* operand must be on the `stack' */
726 case OPR_ADD
: case OPR_SUB
: case OPR_MUL
: case OPR_DIV
:
727 case OPR_MOD
: case OPR_POW
: {
728 if (!isnumeral(v
)) luaK_exp2RK(fs
, v
);
739 void luaK_posfix (FuncState
*fs
, BinOpr op
, expdesc
*e1
, expdesc
*e2
) {
742 lua_assert(e1
->t
== NO_JUMP
); /* list must be closed */
743 luaK_dischargevars(fs
, e2
);
744 luaK_concat(fs
, &e2
->f
, e1
->f
);
749 lua_assert(e1
->f
== NO_JUMP
); /* list must be closed */
750 luaK_dischargevars(fs
, e2
);
751 luaK_concat(fs
, &e2
->t
, e1
->t
);
756 luaK_exp2val(fs
, e2
);
757 if (e2
->k
== VRELOCABLE
&& GET_OPCODE(getcode(fs
, e2
)) == OP_CONCAT
) {
758 lua_assert(e1
->u
.s
.info
== GETARG_B(getcode(fs
, e2
))-1);
760 SETARG_B(getcode(fs
, e2
), e1
->u
.s
.info
);
761 e1
->k
= VRELOCABLE
; e1
->u
.s
.info
= e2
->u
.s
.info
;
764 luaK_exp2nextreg(fs
, e2
); /* operand must be on the 'stack' */
765 codearith(fs
, OP_CONCAT
, e1
, e2
);
769 case OPR_ADD
: codearith(fs
, OP_ADD
, e1
, e2
); break;
770 case OPR_SUB
: codearith(fs
, OP_SUB
, e1
, e2
); break;
771 case OPR_MUL
: codearith(fs
, OP_MUL
, e1
, e2
); break;
772 case OPR_DIV
: codearith(fs
, OP_DIV
, e1
, e2
); break;
773 case OPR_MOD
: codearith(fs
, OP_MOD
, e1
, e2
); break;
774 case OPR_POW
: codearith(fs
, OP_POW
, e1
, e2
); break;
775 case OPR_EQ
: codecomp(fs
, OP_EQ
, 1, e1
, e2
); break;
776 case OPR_NE
: codecomp(fs
, OP_EQ
, 0, e1
, e2
); break;
777 case OPR_LT
: codecomp(fs
, OP_LT
, 1, e1
, e2
); break;
778 case OPR_LE
: codecomp(fs
, OP_LE
, 1, e1
, e2
); break;
779 case OPR_GT
: codecomp(fs
, OP_LT
, 0, e1
, e2
); break;
780 case OPR_GE
: codecomp(fs
, OP_LE
, 0, e1
, e2
); break;
781 default: lua_assert(0);
786 void luaK_fixline (FuncState
*fs
, int line
) {
787 fs
->f
->lineinfo
[fs
->pc
- 1] = line
;
791 static int luaK_code (FuncState
*fs
, Instruction i
, int line
) {
793 dischargejpc(fs
); /* `pc' will change */
794 /* put new instruction in code array */
795 luaM_growvector(fs
->L
, f
->code
, fs
->pc
, f
->sizecode
, Instruction
,
796 MAX_INT
, "code size overflow");
798 /* save corresponding line information */
799 luaM_growvector(fs
->L
, f
->lineinfo
, fs
->pc
, f
->sizelineinfo
, int,
800 MAX_INT
, "code size overflow");
801 f
->lineinfo
[fs
->pc
] = line
;
806 int luaK_codeABC (FuncState
*fs
, OpCode o
, int a
, int b
, int c
) {
807 lua_assert(getOpMode(o
) == iABC
);
808 lua_assert(getBMode(o
) != OpArgN
|| b
== 0);
809 lua_assert(getCMode(o
) != OpArgN
|| c
== 0);
810 return luaK_code(fs
, CREATE_ABC(o
, a
, b
, c
), fs
->ls
->lastline
);
814 int luaK_codeABx (FuncState
*fs
, OpCode o
, int a
, unsigned int bc
) {
815 lua_assert(getOpMode(o
) == iABx
|| getOpMode(o
) == iAsBx
);
816 lua_assert(getCMode(o
) == OpArgN
);
817 return luaK_code(fs
, CREATE_ABx(o
, a
, bc
), fs
->ls
->lastline
);
821 void luaK_setlist (FuncState
*fs
, int base
, int nelems
, int tostore
) {
822 int c
= (nelems
- 1)/LFIELDS_PER_FLUSH
+ 1;
823 int b
= (tostore
== LUA_MULTRET
) ? 0 : tostore
;
824 lua_assert(tostore
!= 0);
826 luaK_codeABC(fs
, OP_SETLIST
, base
, b
, c
);
828 luaK_codeABC(fs
, OP_SETLIST
, base
, b
, 0);
829 luaK_code(fs
, cast(Instruction
, c
), fs
->ls
->lastline
);
831 fs
->freereg
= base
+ 1; /* free registers with list values */