2 ** $Id: lcode.c,v 2.25.1.4 2009/06/15 14:12:25 roberto Exp $
3 ** Code generator for Lua
4 ** See Copyright Notice in lua.h
27 #define hasjumps(e) ((e)->t != (e)->f)
30 static int isnumeral(expdesc
*e
) {
31 return (e
->k
== VKNUM
&& e
->t
== NO_JUMP
&& e
->f
== NO_JUMP
);
35 void luaK_nil (FuncState
*fs
, int from
, int n
) {
36 Instruction
*previous
;
37 if (fs
->pc
> fs
->lasttarget
) { /* no jumps to current position? */
38 if (fs
->pc
== 0) { /* function start? */
39 if (from
>= fs
->nactvar
)
40 return; /* positions are already clean */
43 previous
= &fs
->f
->code
[fs
->pc
-1];
44 if (GET_OPCODE(*previous
) == OP_LOADNIL
) {
45 int pfrom
= GETARG_A(*previous
);
46 int pto
= GETARG_B(*previous
);
47 if (pfrom
<= from
&& from
<= pto
+1) { /* can connect both? */
49 SETARG_B(*previous
, from
+n
-1);
55 luaK_codeABC(fs
, OP_LOADNIL
, from
, from
+n
-1, 0); /* else no optimization */
59 int luaK_jump (FuncState
*fs
) {
60 int jpc
= fs
->jpc
; /* save list of jumps to here */
63 j
= luaK_codeAsBx(fs
, OP_JMP
, 0, NO_JUMP
);
64 luaK_concat(fs
, &j
, jpc
); /* keep them on hold */
69 void luaK_ret (FuncState
*fs
, int first
, int nret
) {
70 luaK_codeABC(fs
, OP_RETURN
, first
, nret
+1, 0);
74 static int condjump (FuncState
*fs
, OpCode op
, int A
, int B
, int C
) {
75 luaK_codeABC(fs
, op
, A
, B
, C
);
80 static void fixjump (FuncState
*fs
, int pc
, int dest
) {
81 Instruction
*jmp
= &fs
->f
->code
[pc
];
82 int offset
= dest
-(pc
+1);
83 lua_assert(dest
!= NO_JUMP
);
84 if (abs(offset
) > MAXARG_sBx
)
85 luaX_syntaxerror(fs
->ls
, "control structure too long");
86 SETARG_sBx(*jmp
, offset
);
91 ** returns current `pc' and marks it as a jump target (to avoid wrong
92 ** optimizations with consecutive instructions not in the same basic block).
94 int luaK_getlabel (FuncState
*fs
) {
95 fs
->lasttarget
= fs
->pc
;
100 static int getjump (FuncState
*fs
, int pc
) {
101 int offset
= GETARG_sBx(fs
->f
->code
[pc
]);
102 if (offset
== NO_JUMP
) /* point to itself represents end of list */
103 return NO_JUMP
; /* end of list */
105 return (pc
+1)+offset
; /* turn offset into absolute position */
109 static Instruction
*getjumpcontrol (FuncState
*fs
, int pc
) {
110 Instruction
*pi
= &fs
->f
->code
[pc
];
111 if (pc
>= 1 && testTMode(GET_OPCODE(*(pi
-1))))
119 ** check whether list has any jump that do not produce a value
120 ** (or produce an inverted value)
122 static int need_value (FuncState
*fs
, int list
) {
123 for (; list
!= NO_JUMP
; list
= getjump(fs
, list
)) {
124 Instruction i
= *getjumpcontrol(fs
, list
);
125 if (GET_OPCODE(i
) != OP_TESTSET
) return 1;
127 return 0; /* not found */
131 static int patchtestreg (FuncState
*fs
, int node
, int reg
) {
132 Instruction
*i
= getjumpcontrol(fs
, node
);
133 if (GET_OPCODE(*i
) != OP_TESTSET
)
134 return 0; /* cannot patch other instructions */
135 if (reg
!= NO_REG
&& reg
!= GETARG_B(*i
))
137 else /* no register to put value or register already has the value */
138 *i
= CREATE_ABC(OP_TEST
, GETARG_B(*i
), 0, GETARG_C(*i
));
144 static void removevalues (FuncState
*fs
, int list
) {
145 for (; list
!= NO_JUMP
; list
= getjump(fs
, list
))
146 patchtestreg(fs
, list
, NO_REG
);
150 static void patchlistaux (FuncState
*fs
, int list
, int vtarget
, int reg
,
152 while (list
!= NO_JUMP
) {
153 int next
= getjump(fs
, list
);
154 if (patchtestreg(fs
, list
, reg
))
155 fixjump(fs
, list
, vtarget
);
157 fixjump(fs
, list
, dtarget
); /* jump to default target */
163 static void dischargejpc (FuncState
*fs
) {
164 patchlistaux(fs
, fs
->jpc
, fs
->pc
, NO_REG
, fs
->pc
);
169 void luaK_patchlist (FuncState
*fs
, int list
, int target
) {
170 if (target
== fs
->pc
)
171 luaK_patchtohere(fs
, list
);
173 lua_assert(target
< fs
->pc
);
174 patchlistaux(fs
, list
, target
, NO_REG
, target
);
179 void luaK_patchtohere (FuncState
*fs
, int list
) {
181 luaK_concat(fs
, &fs
->jpc
, list
);
185 void luaK_concat (FuncState
*fs
, int *l1
, int l2
) {
186 if (l2
== NO_JUMP
) return;
187 else if (*l1
== NO_JUMP
)
192 while ((next
= getjump(fs
, list
)) != NO_JUMP
) /* find last element */
194 fixjump(fs
, list
, l2
);
199 void luaK_checkstack (FuncState
*fs
, int n
) {
200 int newstack
= fs
->freereg
+ n
;
201 if (newstack
> fs
->f
->maxstacksize
) {
202 if (newstack
>= MAXSTACK
)
203 luaX_syntaxerror(fs
->ls
, "function or expression too complex");
204 fs
->f
->maxstacksize
= cast_byte(newstack
);
209 void luaK_reserveregs (FuncState
*fs
, int n
) {
210 luaK_checkstack(fs
, n
);
215 static void freereg (FuncState
*fs
, int reg
) {
216 if (!ISK(reg
) && reg
>= fs
->nactvar
) {
218 lua_assert(reg
== fs
->freereg
);
223 static void freeexp (FuncState
*fs
, expdesc
*e
) {
224 if (e
->k
== VNONRELOC
)
225 freereg(fs
, e
->u
.s
.info
);
229 static int addk (FuncState
*fs
, TValue
*k
, TValue
*v
) {
230 lua_State
*L
= fs
->L
;
231 TValue
*idx
= luaH_set(L
, fs
->h
, k
);
233 int oldsize
= f
->sizek
;
234 if (ttisnumber(idx
)) {
235 lua_assert(luaO_rawequalObj(&fs
->f
->k
[cast_int(nvalue(idx
))], v
));
236 return cast_int(nvalue(idx
));
238 else { /* constant not found; create a new entry */
239 setnvalue(idx
, cast_num(fs
->nk
));
240 luaM_growvector(L
, f
->k
, fs
->nk
, f
->sizek
, TValue
,
241 MAXARG_Bx
, "constant table overflow");
242 while (oldsize
< f
->sizek
) setnilvalue(&f
->k
[oldsize
++]);
243 setobj(L
, &f
->k
[fs
->nk
], v
);
244 luaC_barrier(L
, f
, v
);
250 int luaK_stringK (FuncState
*fs
, TString
*s
) {
252 setsvalue(fs
->L
, &o
, s
);
253 return addk(fs
, &o
, &o
);
257 int luaK_numberK (FuncState
*fs
, lua_Number r
) {
260 return addk(fs
, &o
, &o
);
264 static int boolK (FuncState
*fs
, int b
) {
267 return addk(fs
, &o
, &o
);
271 static int nilK (FuncState
*fs
) {
274 /* cannot use nil as key; instead use table itself to represent nil */
275 sethvalue(fs
->L
, &k
, fs
->h
);
276 return addk(fs
, &k
, &v
);
280 void luaK_setreturns (FuncState
*fs
, expdesc
*e
, int nresults
) {
281 if (e
->k
== VCALL
) { /* expression is an open function call? */
282 SETARG_C(getcode(fs
, e
), nresults
+1);
284 else if (e
->k
== VVARARG
) {
285 SETARG_B(getcode(fs
, e
), nresults
+1);
286 SETARG_A(getcode(fs
, e
), fs
->freereg
);
287 luaK_reserveregs(fs
, 1);
292 void luaK_setoneret (FuncState
*fs
, expdesc
*e
) {
293 if (e
->k
== VCALL
) { /* expression is an open function call? */
295 e
->u
.s
.info
= GETARG_A(getcode(fs
, e
));
297 else if (e
->k
== VVARARG
) {
298 SETARG_B(getcode(fs
, e
), 2);
299 e
->k
= VRELOCABLE
; /* can relocate its simple result */
304 void luaK_dischargevars (FuncState
*fs
, expdesc
*e
) {
311 e
->u
.s
.info
= luaK_codeABC(fs
, OP_GETUPVAL
, 0, e
->u
.s
.info
, 0);
316 e
->u
.s
.info
= luaK_codeABx(fs
, OP_GETGLOBAL
, 0, e
->u
.s
.info
);
321 freereg(fs
, e
->u
.s
.aux
);
322 freereg(fs
, e
->u
.s
.info
);
323 e
->u
.s
.info
= luaK_codeABC(fs
, OP_GETTABLE
, 0, e
->u
.s
.info
, e
->u
.s
.aux
);
329 luaK_setoneret(fs
, e
);
332 default: break; /* there is one value available (somewhere) */
337 static int code_label (FuncState
*fs
, int A
, int b
, int jump
) {
338 luaK_getlabel(fs
); /* those instructions may be jump targets */
339 return luaK_codeABC(fs
, OP_LOADBOOL
, A
, b
, jump
);
343 static void discharge2reg (FuncState
*fs
, expdesc
*e
, int reg
) {
344 luaK_dischargevars(fs
, e
);
347 luaK_nil(fs
, reg
, 1);
350 case VFALSE
: case VTRUE
: {
351 luaK_codeABC(fs
, OP_LOADBOOL
, reg
, e
->k
== VTRUE
, 0);
355 luaK_codeABx(fs
, OP_LOADK
, reg
, e
->u
.s
.info
);
359 luaK_codeABx(fs
, OP_LOADK
, reg
, luaK_numberK(fs
, e
->u
.nval
));
363 Instruction
*pc
= &getcode(fs
, e
);
368 if (reg
!= e
->u
.s
.info
)
369 luaK_codeABC(fs
, OP_MOVE
, reg
, e
->u
.s
.info
, 0);
373 lua_assert(e
->k
== VVOID
|| e
->k
== VJMP
);
374 return; /* nothing to do... */
382 static void discharge2anyreg (FuncState
*fs
, expdesc
*e
) {
383 if (e
->k
!= VNONRELOC
) {
384 luaK_reserveregs(fs
, 1);
385 discharge2reg(fs
, e
, fs
->freereg
-1);
390 static void exp2reg (FuncState
*fs
, expdesc
*e
, int reg
) {
391 discharge2reg(fs
, e
, reg
);
393 luaK_concat(fs
, &e
->t
, e
->u
.s
.info
); /* put this jump in `t' list */
395 int final
; /* position after whole expression */
396 int p_f
= NO_JUMP
; /* position of an eventual LOAD false */
397 int p_t
= NO_JUMP
; /* position of an eventual LOAD true */
398 if (need_value(fs
, e
->t
) || need_value(fs
, e
->f
)) {
399 int fj
= (e
->k
== VJMP
) ? NO_JUMP
: luaK_jump(fs
);
400 p_f
= code_label(fs
, reg
, 0, 1);
401 p_t
= code_label(fs
, reg
, 1, 0);
402 luaK_patchtohere(fs
, fj
);
404 final
= luaK_getlabel(fs
);
405 patchlistaux(fs
, e
->f
, final
, reg
, p_f
);
406 patchlistaux(fs
, e
->t
, final
, reg
, p_t
);
408 e
->f
= e
->t
= NO_JUMP
;
414 void luaK_exp2nextreg (FuncState
*fs
, expdesc
*e
) {
415 luaK_dischargevars(fs
, e
);
417 luaK_reserveregs(fs
, 1);
418 exp2reg(fs
, e
, fs
->freereg
- 1);
422 int luaK_exp2anyreg (FuncState
*fs
, expdesc
*e
) {
423 luaK_dischargevars(fs
, e
);
424 if (e
->k
== VNONRELOC
) {
425 if (!hasjumps(e
)) return e
->u
.s
.info
; /* exp is already in a register */
426 if (e
->u
.s
.info
>= fs
->nactvar
) { /* reg. is not a local? */
427 exp2reg(fs
, e
, e
->u
.s
.info
); /* put value on it */
431 luaK_exp2nextreg(fs
, e
); /* default */
436 void luaK_exp2val (FuncState
*fs
, expdesc
*e
) {
438 luaK_exp2anyreg(fs
, e
);
440 luaK_dischargevars(fs
, e
);
444 int luaK_exp2RK (FuncState
*fs
, expdesc
*e
) {
451 if (fs
->nk
<= MAXINDEXRK
) { /* constant fit in RK operand? */
452 e
->u
.s
.info
= (e
->k
== VNIL
) ? nilK(fs
) :
453 (e
->k
== VKNUM
) ? luaK_numberK(fs
, e
->u
.nval
) :
454 boolK(fs
, (e
->k
== VTRUE
));
456 return RKASK(e
->u
.s
.info
);
461 if (e
->u
.s
.info
<= MAXINDEXRK
) /* constant fit in argC? */
462 return RKASK(e
->u
.s
.info
);
467 /* not a constant in the right range: put it in a register */
468 return luaK_exp2anyreg(fs
, e
);
472 void luaK_storevar (FuncState
*fs
, expdesc
*var
, expdesc
*ex
) {
476 exp2reg(fs
, ex
, var
->u
.s
.info
);
480 int e
= luaK_exp2anyreg(fs
, ex
);
481 luaK_codeABC(fs
, OP_SETUPVAL
, e
, var
->u
.s
.info
, 0);
485 int e
= luaK_exp2anyreg(fs
, ex
);
486 luaK_codeABx(fs
, OP_SETGLOBAL
, e
, var
->u
.s
.info
);
490 int e
= luaK_exp2RK(fs
, ex
);
491 luaK_codeABC(fs
, OP_SETTABLE
, var
->u
.s
.info
, var
->u
.s
.aux
, e
);
495 lua_assert(0); /* invalid var kind to store */
503 void luaK_self (FuncState
*fs
, expdesc
*e
, expdesc
*key
) {
505 luaK_exp2anyreg(fs
, e
);
508 luaK_reserveregs(fs
, 2);
509 luaK_codeABC(fs
, OP_SELF
, func
, e
->u
.s
.info
, luaK_exp2RK(fs
, key
));
516 static void invertjump (FuncState
*fs
, expdesc
*e
) {
517 Instruction
*pc
= getjumpcontrol(fs
, e
->u
.s
.info
);
518 lua_assert(testTMode(GET_OPCODE(*pc
)) && GET_OPCODE(*pc
) != OP_TESTSET
&&
519 GET_OPCODE(*pc
) != OP_TEST
);
520 SETARG_A(*pc
, !(GETARG_A(*pc
)));
524 static int jumponcond (FuncState
*fs
, expdesc
*e
, int cond
) {
525 if (e
->k
== VRELOCABLE
) {
526 Instruction ie
= getcode(fs
, e
);
527 if (GET_OPCODE(ie
) == OP_NOT
) {
528 fs
->pc
--; /* remove previous OP_NOT */
529 return condjump(fs
, OP_TEST
, GETARG_B(ie
), 0, !cond
);
531 /* else go through */
533 discharge2anyreg(fs
, e
);
535 return condjump(fs
, OP_TESTSET
, NO_REG
, e
->u
.s
.info
, cond
);
539 void luaK_goiftrue (FuncState
*fs
, expdesc
*e
) {
540 int pc
; /* pc of last jump */
541 luaK_dischargevars(fs
, e
);
543 case VK
: case VKNUM
: case VTRUE
: {
544 pc
= NO_JUMP
; /* always true; do nothing */
554 pc
= luaK_jump(fs
); /* always jump */
557 /* else go through */
560 pc
= jumponcond(fs
, e
, 0);
564 luaK_concat(fs
, &e
->f
, pc
); /* insert last jump in `f' list */
565 luaK_patchtohere(fs
, e
->t
);
570 static void luaK_goiffalse (FuncState
*fs
, expdesc
*e
) {
571 int pc
; /* pc of last jump */
572 luaK_dischargevars(fs
, e
);
574 case VNIL
: case VFALSE
: {
575 pc
= NO_JUMP
; /* always false; do nothing */
584 pc
= luaK_jump(fs
); /* always jump */
587 /* else go through */
590 pc
= jumponcond(fs
, e
, 1);
594 luaK_concat(fs
, &e
->t
, pc
); /* insert last jump in `t' list */
595 luaK_patchtohere(fs
, e
->f
);
600 static void codenot (FuncState
*fs
, expdesc
*e
) {
601 luaK_dischargevars(fs
, e
);
603 case VNIL
: case VFALSE
: {
607 case VK
: case VKNUM
: case VTRUE
: {
617 discharge2anyreg(fs
, e
);
619 e
->u
.s
.info
= luaK_codeABC(fs
, OP_NOT
, 0, e
->u
.s
.info
, 0);
624 lua_assert(0); /* cannot happen */
628 /* interchange true and false lists */
629 { int temp
= e
->f
; e
->f
= e
->t
; e
->t
= temp
; }
630 removevalues(fs
, e
->f
);
631 removevalues(fs
, e
->t
);
635 void luaK_indexed (FuncState
*fs
, expdesc
*t
, expdesc
*k
) {
636 t
->u
.s
.aux
= luaK_exp2RK(fs
, k
);
641 static int constfolding (OpCode op
, expdesc
*e1
, expdesc
*e2
) {
642 lua_Number v1
, v2
, r
;
643 if (!isnumeral(e1
) || !isnumeral(e2
)) return 0;
647 case OP_ADD
: r
= luai_numadd(v1
, v2
); break;
648 case OP_SUB
: r
= luai_numsub(v1
, v2
); break;
649 case OP_MUL
: r
= luai_nummul(v1
, v2
); break;
651 if (v2
== 0) return 0; /* do not attempt to divide by 0 */
652 r
= luai_numdiv(v1
, v2
); break;
654 if (v2
== 0) return 0; /* do not attempt to divide by 0 */
655 r
= luai_nummod(v1
, v2
); break;
656 case OP_POW
: r
= luai_numpow(v1
, v2
); break;
657 case OP_UNM
: r
= luai_numunm(v1
); break;
658 case OP_LEN
: return 0; /* no constant folding for 'len' */
659 default: lua_assert(0); r
= 0; break;
661 if (luai_numisnan(r
)) return 0; /* do not attempt to produce NaN */
667 static void codearith (FuncState
*fs
, OpCode op
, expdesc
*e1
, expdesc
*e2
) {
668 if (constfolding(op
, e1
, e2
))
671 int o2
= (op
!= OP_UNM
&& op
!= OP_LEN
) ? luaK_exp2RK(fs
, e2
) : 0;
672 int o1
= luaK_exp2RK(fs
, e1
);
681 e1
->u
.s
.info
= luaK_codeABC(fs
, op
, 0, o1
, o2
);
687 static void codecomp (FuncState
*fs
, OpCode op
, int cond
, expdesc
*e1
,
689 int o1
= luaK_exp2RK(fs
, e1
);
690 int o2
= luaK_exp2RK(fs
, e2
);
693 if (cond
== 0 && op
!= OP_EQ
) {
694 int temp
; /* exchange args to replace by `<' or `<=' */
695 temp
= o1
; o1
= o2
; o2
= temp
; /* o1 <==> o2 */
698 e1
->u
.s
.info
= condjump(fs
, op
, cond
, o1
, o2
);
703 void luaK_prefix (FuncState
*fs
, UnOpr op
, expdesc
*e
) {
705 e2
.t
= e2
.f
= NO_JUMP
; e2
.k
= VKNUM
; e2
.u
.nval
= 0;
709 luaK_exp2anyreg(fs
, e
); /* cannot operate on non-numeric constants */
710 codearith(fs
, OP_UNM
, e
, &e2
);
713 case OPR_NOT
: codenot(fs
, e
); break;
715 luaK_exp2anyreg(fs
, e
); /* cannot operate on constants */
716 codearith(fs
, OP_LEN
, e
, &e2
);
719 default: lua_assert(0);
724 void luaK_infix (FuncState
*fs
, BinOpr op
, expdesc
*v
) {
727 luaK_goiftrue(fs
, v
);
731 luaK_goiffalse(fs
, v
);
735 luaK_exp2nextreg(fs
, v
); /* operand must be on the `stack' */
738 case OPR_ADD
: case OPR_SUB
: case OPR_MUL
: case OPR_DIV
:
739 case OPR_MOD
: case OPR_POW
: {
740 if (!isnumeral(v
)) luaK_exp2RK(fs
, v
);
751 void luaK_posfix (FuncState
*fs
, BinOpr op
, expdesc
*e1
, expdesc
*e2
) {
754 lua_assert(e1
->t
== NO_JUMP
); /* list must be closed */
755 luaK_dischargevars(fs
, e2
);
756 luaK_concat(fs
, &e2
->f
, e1
->f
);
761 lua_assert(e1
->f
== NO_JUMP
); /* list must be closed */
762 luaK_dischargevars(fs
, e2
);
763 luaK_concat(fs
, &e2
->t
, e1
->t
);
768 luaK_exp2val(fs
, e2
);
769 if (e2
->k
== VRELOCABLE
&& GET_OPCODE(getcode(fs
, e2
)) == OP_CONCAT
) {
770 lua_assert(e1
->u
.s
.info
== GETARG_B(getcode(fs
, e2
))-1);
772 SETARG_B(getcode(fs
, e2
), e1
->u
.s
.info
);
773 e1
->k
= VRELOCABLE
; e1
->u
.s
.info
= e2
->u
.s
.info
;
776 luaK_exp2nextreg(fs
, e2
); /* operand must be on the 'stack' */
777 codearith(fs
, OP_CONCAT
, e1
, e2
);
781 case OPR_ADD
: codearith(fs
, OP_ADD
, e1
, e2
); break;
782 case OPR_SUB
: codearith(fs
, OP_SUB
, e1
, e2
); break;
783 case OPR_MUL
: codearith(fs
, OP_MUL
, e1
, e2
); break;
784 case OPR_DIV
: codearith(fs
, OP_DIV
, e1
, e2
); break;
785 case OPR_MOD
: codearith(fs
, OP_MOD
, e1
, e2
); break;
786 case OPR_POW
: codearith(fs
, OP_POW
, e1
, e2
); break;
787 case OPR_EQ
: codecomp(fs
, OP_EQ
, 1, e1
, e2
); break;
788 case OPR_NE
: codecomp(fs
, OP_EQ
, 0, e1
, e2
); break;
789 case OPR_LT
: codecomp(fs
, OP_LT
, 1, e1
, e2
); break;
790 case OPR_LE
: codecomp(fs
, OP_LE
, 1, e1
, e2
); break;
791 case OPR_GT
: codecomp(fs
, OP_LT
, 0, e1
, e2
); break;
792 case OPR_GE
: codecomp(fs
, OP_LE
, 0, e1
, e2
); break;
793 default: lua_assert(0);
798 void luaK_fixline (FuncState
*fs
, int line
) {
799 fs
->f
->lineinfo
[fs
->pc
- 1] = line
;
803 static int luaK_code (FuncState
*fs
, Instruction i
, int line
) {
805 dischargejpc(fs
); /* `pc' will change */
806 /* put new instruction in code array */
807 luaM_growvector(fs
->L
, f
->code
, fs
->pc
, f
->sizecode
, Instruction
,
808 MAX_INT
, "code size overflow");
810 /* save corresponding line information */
811 luaM_growvector(fs
->L
, f
->lineinfo
, fs
->pc
, f
->sizelineinfo
, int,
812 MAX_INT
, "code size overflow");
813 f
->lineinfo
[fs
->pc
] = line
;
818 int luaK_codeABC (FuncState
*fs
, OpCode o
, int a
, int b
, int c
) {
819 lua_assert(getOpMode(o
) == iABC
);
820 lua_assert(getBMode(o
) != OpArgN
|| b
== 0);
821 lua_assert(getCMode(o
) != OpArgN
|| c
== 0);
822 return luaK_code(fs
, CREATE_ABC(o
, a
, b
, c
), fs
->ls
->lastline
);
826 int luaK_codeABx (FuncState
*fs
, OpCode o
, int a
, unsigned int bc
) {
827 lua_assert(getOpMode(o
) == iABx
|| getOpMode(o
) == iAsBx
);
828 lua_assert(getCMode(o
) == OpArgN
);
829 return luaK_code(fs
, CREATE_ABx(o
, a
, bc
), fs
->ls
->lastline
);
833 void luaK_setlist (FuncState
*fs
, int base
, int nelems
, int tostore
) {
834 int c
= (nelems
- 1)/LFIELDS_PER_FLUSH
+ 1;
835 int b
= (tostore
== LUA_MULTRET
) ? 0 : tostore
;
836 lua_assert(tostore
!= 0);
838 luaK_codeABC(fs
, OP_SETLIST
, base
, b
, c
);
840 luaK_codeABC(fs
, OP_SETLIST
, base
, b
, 0);
841 luaK_code(fs
, cast(Instruction
, c
), fs
->ls
->lastline
);
843 fs
->freereg
= base
+ 1; /* free registers with list values */